Handing the conversation over to FB Page Inbox or to another bot
A chatbot deployed on Facebook will manage all conversations initiated through Facebook Messenger on the integrated Facebook Page.
By using the Facebook Handover Protocol, you can enhance the Messenger experience by allowing the chatbot and the Page owner or administrator to share control of the conversation. This lets you seamlessly pass control between the chatbot and the Facebook Page Inbox, enabling users to interact directly with the Page administrator when needed.
This is especially useful when you want to allow users to communicate with the Page Inbox administrator while still having a chatbot deployed.
Prerequisite
- You need the access token you generated when connecting the Facebook page with you app.
To handover the conversation from a chatbot to a Facebook page Inbox or to another bot:
Step 1. Adjust your Facebook Page app webhook subscriptions
- In Facebook Developer Portal, go to your app details.
- On the main, click Messenger > API Settings.
- In the Generate access tokens section, hover the mouse over the info icon below Webhook Subscription and click the Edit button. The Edit Page Subscriptions pop-up appears.
- Select messaging_handovers and click Confirm.
Step 2. Assign the FB app as the Primary Receiver for your FB page
To assign the Facebook app as the Primary Receiver for your Facebook page:
- Access the Facebook page and go to the page settings.
- On the Audience and visibility menu, click Page setup.
- Click the View button next to Advanced Messaging.
- In the App settings - Handover Protocol sections, click the Configure button next to the Messenger receiver. A pop-up appears.
- Select your Facebook app as the primary receiver for the handover protocol.
- Close the pop-up.
Step 3. Configure the integration for passing thread control
Create an integration task with a POST request to the Facebook Handover API endpoint and place the integration for passing thread control on the flow step where you do the handover.
This section provides you with the information needed to configure the integration for passing thread control.
Prerequisite
- Create a REST connector app, which has the https://graph.facebook.com as Base URL and in the variable section has PageAccessToken (the access token of the Facebook page where the bot was deployed).
Create a REST connector action for passing thread control and select [[ChatUser]] as Request and Response entity.
Create a REST integration task and configure the Request for passing thread control as described below.
Make a POST request to Facebook pass_thread_control endpoint: /v2.6/me/pass_thread_control?access_token={access_token}
In the Parameters tab, map the access_token parameter to DRUID local variable @PageAccessToken.
Select UseBodyTemplate as RequestType and in the BodyTemplate field, enter the following code:
{
"recipient":{"id":"{{userId}}"},
"target_app_id":263902037430900
}
Set the target_app_id property of the request to specific value as follows:
- To handover the conversations to the Facebook Page Inbox, enter “263902037430900”
- To hand over the conversations to another bot, enter the App ID of the Facebook app created for that bot.
Click the Body tab and map the userId provided in the request (BodyTemplate field) to [[ChatUser]].UserId, which will store the values returned by the API call.
Place the integration for passing thread control on the flow step where you do the handover.
Step 4. (Optional) Author the bot to handle the conversation hand over back to it
Whenever the conversation is handed back to the bot, DRUID Platform triggers the Welcome flow and sets [[ChatUser]].ReturningFromFacebookHandover = true.
You can create a dedicated branch in the Welcome flow to address the cases when you want to let the users know that they’re talking to the bot again, a branch step that will be executed when [[ChatUser]].ReturningFromFacebookHandover = true (set condition on step).
If you don’t want to let the user know, add an empty step to the Welcome flow or simply do nothing.
[[ChatUser]].ReturningFromFacebookHandover = false
).