问题
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 his pages and let him subscribe to my app with the Facebook page of his choice.
Can you please explain me more about this procedure please ? My goal is to create a platform in wich a user can choose among all this Facebook Page and connect my App to his page (like Chatfuel and other platform).
来源:https://stackoverflow.com/questions/45770548/connect-multiple-messenger-chatbot-on-single-facebook-app