Adding your Facebook page to RapidPro
This document is intended to guide the process of including, validating and publishing a Facebook channel on RapidPro.
To add the bot to Facebook chat it is necessary first to understand the tools involved in establishing communication:
- Creating a Facebook Page – Unlike a profile, a page is linked to an establishment, entity, body, or service. This page is where users will have access to chatbot through Facebook Messenger. Posts, comments, posts sharing or markings will not be interpreted by the chatbot.
- Creating an App – In the site for Facebook developers should be created an application that will function as a messaging gateway. During development/testing the app gives access to chatbot only to its administrators, to make the app public access it needs to go through an evaluation process and fulfill some Facebook requirements.
- Link app with chat – You need to configure app-supplied tokens as well as webhooks with callback URLs.
Step 1 – Creating the page
Skip to step 2 if you already have a configured page.
Select the Create Page option and follow the steps presented according to the characteristics of your goal. At this point, it is important to provide as much information as possible because Facebook can block your access if it detects that it may be a fake page.
Step 2 – Creating the app
Go to https://developers.facebook.com to create your app
Select the option Add a new application and follow the steps that will appear according to your goal.
Give a name and place the email that will be responsible for the app.
At this point you may receive a validation request.
On the main management screen of your new app add Messenger by clicking Configure in the Messenger section.
Select the Basic option under Settings, fill out the form and save your changes.
Now we will generate the token to configure the channel in RapidPro. To do this, select Settings inside the Messenger section and choose the page that will be linked to this app. After selecting the page you will be asked permission of the app to the page, just confirm.
The profile that generates the Token cannot have its permission to the app changed or be removed. Should this occur the Token will become invalid and the app will stop working until the process is run again.
After this procedure, an Access Token will be generated, which will be configured in RapidPro.
Step 3 – Linking the app to RapidPro to create the channel
With the Page Access Token, open the properties of your Org in RapidPro (click the Org name in the upper right corner of the screen) and then select the add channel option.
Scroll down to the social media channels section and select the Facebook option.
On the add channel screen fill in the Access Token (identifier you generated in the app), Page Name (for channel ID in RapidPro), and Page ID (this number can be purchased in the About section of your page).
The user who creates the channel must not have their permission in RapidPro changed nor removed. Should this occur the Token will become invalid and the app will stop working until the process is run again.
This procedure will generate the callback URLs to be configured in the Webhooks section in the app.
Go back to the App on the Facebook developer site and go to Configure Webhooks within the messenger settings.
Fill in the information according to the data generated in the addition of your channel in RapidPro, check the Messages, Messaging_postbacks, Messaging_optins, Message_deliveries and Messanging_referrals options and click Check and Save.
When you complete this procedure, make sure that the parameters have been correctly selected and that the page has been properly entered in the Webhooks.
Finishing channel functionality
Now all we need is to configure how the conversation will be interpreted by the chatbot. This is done in RapidPro through a trigger that only appears after adding a Facebook channel successfully. To do this go to the Triggers section in RapidPro and click Create trigger.
From the available options select the one as shown in the figure below, which will cause a Get Started button to appear on the chat once a new conversation with the page is started and thus allow the user to approve the exchange of messages with the chatbot.
Select the Facebook channel you just created in RapidPro, the flow that will be triggered when you the conversation is started, and click Create Trigger.
The screen will return to the triggers creation page and display the one you just created.
That’s all it takes to add your Facebook page as a channel to RapidPro. Completing the above steps the chat will appear as follows when clicking the button to send message.
And clicking on Get Started chatbot takes over.
Perform all bot functionality tests and make any necessary adjustments. Only after everything is OK, start the approval process to make the app public.