Reputation: 1839
I have a general question regarding the setup for a "bot" in the Facebook Messenger Platform. If I understand the architecture right, I can create an App as a developer add the Messenger function and associate 1 Page with the Messenger function. Does this mean I need an app for each page ? Or could I crete a "bot backend" serving multiple / different pages from different users ?
Upvotes: 1
Views: 1325
Reputation: 3854
When you receive a request, you need to map the incoming page id to the access token as described in this answer: How can I use the same bot on multiple facebook pages using bot framework
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
...
const accessTokens = {
myPageId1: 'myPageAccessToken1',
myPageId2: 'myPageAccessToken2',
}
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,
})
Upvotes: 0
Reputation: 2618
Fritak is correct. You can use one app for multiple pages. For each page you will have to subscribe the app to that page and generate a page access token specifically for that page. At your webhook, you'll have to distinguish the callbacks for the specific page.
Upvotes: 0
Reputation: 191
Yes, you can have one robot serving multiple pages. You just have to set <token> for different pages in API call, here is setup for a page. From documentation:
Graph API requires Page access tokens to manage Facebook Pages. They are unique to each Page, admin and app and have an expiration time.
Upvotes: 4