1

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 ?

jona jürgen
  • 1,789
  • 4
  • 22
  • 31

3 Answers3

4

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.

fritak
  • 191
  • 3
  • Does this mean that the user would see a new conversation for each page, and that this conversation could be fully customized depending on the page´s context ? – jona jürgen Apr 16 '16 at 17:04
  • Yes, you don't have separate "bot" chat. You have to "subscribe" specific page and then in every communication with facebook you have to set token for that page. – fritak Apr 16 '16 at 18:47
  • It's a good practice to verify the request signature to make sure that the callback comes from the facebook page. Here, the App Secret is used, so make sure you take this into account when serving multiple pages. – Carlos Araya Sep 16 '16 at 11:35
0

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.

pschang
  • 2,568
  • 3
  • 28
  • 23
  • 1
    How to distinguish this callback from different pages? does page-id come with every call? – rusty Oct 19 '16 at 08:29
0

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,
     })
Danny Sullivan
  • 3,626
  • 3
  • 30
  • 39