Before starting, ensure you have a Facebook Page. If you don't have one, create a Facebook Page first.
Ensure you have Node.js installed, then run:
npm install express body-parser fs axios
-
Navigate to Facebook Developers:
- Open your web browser and go to developers.facebook.com.
-
Create a Developer Account (if you don’t have one):
- Log in with your Facebook credentials and follow the prompts to set up a developer account.
- Create an App:
- Click on "My Apps" in the top-right corner.
- Select "Create App".
- Choose "Business" as the app type.
- Fill out the required details such as the app display name and contact email, then click "Create App ID".
- Set Up Messenger:
- In the left sidebar of your app's dashboard, click on "Add Product".
- Locate "Messenger" and click the "Set Up" button.
- Generate a Page Access Token:
- Scroll to the "Access Tokens" section.
- Click on "Add or Remove Pages".
- Follow the prompts to connect your Facebook Page.
- Once connected, click "Generate Token" and copy the token for later use.
- Configure Webhooks:
- Scroll down to the "Webhooks" section in Messenger settings.
- Click "Setup Webhooks".
- Enter the following details:
- Callback URL:
https://your_hosting.site/webhook
- Verify Token:
pagebot-v3
- Callback URL:
- Subscribe to the following fields:
messages
messaging_optins
messaging_postbacks
- Click "Verify and Save".
- Subscribe to Page Events:
- Under "Webhooks", navigate to "Page Subscriptions".
- Select the page you connected earlier.
- Ensure that
messages
,messaging_optins
, andmessaging_postbacks
are selected.
- Copy the Token:
- Go back to "Access Tokens".
- Copy the generated Page Access Token.
- Enter the Token:
- Paste the Page Access Token into
configure.json
.
- Paste the Page Access Token into
- Test Bot Functionality:
- Open your Facebook Page.
- Send a message (e.g., "help") to verify if the bot responds correctly.
- Ensure that the account used for testing has a role in the app.
Note: The bot will only respond to accounts assigned specific roles within the app.
-
Deployment Instructions:
- Ensure your server is set up with Node.js.
- Deploy the app to your server or cloud platform (e.g., Heroku, Render, Vercel).
-
Run Your App:
- Navigate to your project directory and install any additional dependencies:
npm install
- Start your server:
node index.js
- To ensure your server restarts when code changes, consider using
nodemon
(optional):npm install -g nodemon nodemon index.js
- Navigate to your project directory and install any additional dependencies:
-
Navigate to developers.facebook.com:
- Go to developers.facebook.com.
-
Access Your App:
- Log in and navigate to "My Apps".
-
Select "App Roles":
- Find the "App Roles" section in your app's dashboard.
-
Add Roles:
- Click on "Add Role" to start the process.
-
Define Role Details:
- Specify role name and permissions as needed.
-
Assign Roles to Users:
- Assign the role to specific users by providing their name or user ID.
- This guide was created by Clarence, Kyle, Christel, and Akira.
- Thanks to Deku (https://api.joshweb.click) for their APIs.
- Thanks to Kaiz-Api and Hiroshi for their contributions.
Note: Feel free to modify this file as needed.
Feel free to contact French Clarence Mangigo if you have any concerns: https://www.facebook.com/frenchclarence.mangigo.9