Reputation: 677
I'm managing a Facebook page and Have a Facebook validated Node.js ChatBot on it. It works fine and now I would like to know how to duplicate this ChatBot on multiple other Facebook pages. A single App, a single ChatBot and multiple Facebook pages linked on it.
For doing that, If I understood, I have to:
- Collect the page.id :
app.post('/webhook', (req, res) => {
const data = req.body
// Make sure this is a page subscription
if (data.object === 'page') {
// Iterate over each entry
data.entry.forEach((pageEntry) => {
// get the pageId
const pageId = pageEntry.id
...
- Maintain an object mapping page ids to the access token associated with each page id:
const accessTokens = {
myPageId1: 'myPageAccessToken1',
myPageId2: 'myPageAccessToken2',
}
- Then when sending the response, just specify the corresponding page access_token:
const callSendAPI = (pageId, messageData) =>
rp({
uri: 'https://graph.facebook.com/v2.8/me/messages',
qs: { access_token: accessTokens[pageId] },
method: 'POST',
body: messageData,
json: true,
})
Now I only want to know how to ask user permission to manage all their pages and let them subscribe to my app with the Facebook page of their choice.
Can you please explain me more about this procedure please? My goal is to create a platform in which a user can choose among all this Facebook Page and connect my App to his page (like Chatfuel and other platform).
Upvotes: 1
Views: 912