How to build a chatbot in Facebook Messenger

Create your own chatbot for facebook from scratch with this guide and an account on ChatCompose.

Create your own Chatbot for Facebook with Chat Compose

Chatbots are magical. Bots can be an incredible product that allows people to create new experiences, from reporting news to delivering information from customer support.

Facebook allows its users to create chatbots for their Facebook pages through their Facebook Developers platform. In this article, I'm going to show you exactly how to do it. The best part? It will take us less than one hour.

Steps to Create a Chatbot on Facebook

1. Sign up in Facebook Developers

Sign up on Facebook Developers and create a new application. You will need a Facebook account so if you do not have it create one.

Once the application is created, we will add the Messenger product. Since the chatbot will communicate by this mean it is necessary to make some configurations.

Click on Products on the left bar and then select Messenger.

2. Generate the Token

To enable a chatbot in messenger we will need a token. This token is generated through the application that you created in Facebook Developers, associated with a Facebook page. If you do not have a Facebook page for your service or product, create it.(How to create a facebook page)

These Facebook pages are necessary to generate the token and it is where you can see and enable your chatbots.

To generate the token go to the Access Token section and link your page to your app. Then click on generate token.

3. Get the route to connect Messenger to ChatCompose

To complete this step you need to have an active ChatCompose account. You can register here.

Once registered, access your account and click on Install> Integrations. In this section you will find the information to make the connection between ChatCompose and Messenger.

Copy your token generated in step 2 to your Chatcompose panel. You will also need a secret phrase, for security reasons and for Facebook to ensure that you have control over the connection.

Enter the Facebook token in "ACCESS_TOKEN" and create a security phrase in "VERIFY_TOKEN". Save your changes.

In "ROUTE" you will find the route of your ChatCompose account, you need it to integrate your bot to Messenger.

4. Enter the route and the secret phrase

Back in Facebook Developers, in the webhooks section of your Messenger Product, click on "Configure Webhooks". In the pop-up window we will copy the path of step 3 and the security phrase.

Enter the route and the "VERIFY_TOKEN" phrase, then press Verify and Save.

Now press "Add Subscriptions" and select: "messages", "messaging_postbacks", "message_deliveries" and "messaging_pre_checkouts".

5. Test it

Note: After saving your tokens you will need to set your Facebook Bot to "ON" on the platform. Whenever you want to stop the chatbot just switch it to "OFF". You can find the button on the Install>Facebook section.

Visit your Facebook page and talk with your bot to check that it is working well.

To send messages to the chatbot you will have to add messenger to your page, and include the button Send Message. Send a message (Test Button) to your page to check the responses of your chatbot.

Components and Limitations

You can use the components images, links and downloads to show media.

The html component cannot be loaded. Messenger is not a browser and it cannot render html.

6. Review of the app

To make the bot public you will need to follow the Facebook guidelines for making an app public. The approval should not take more than 2 days.

7. Menu Configuration

After saving your facebook keys in ChatCompose, a new button will appear (Settings). Press it to set your initial Menu Configuration. Messenger can show a persistent menu where your users can load components or answers (see Persistent Menu).

The menu access buttons allows you to load specific components and scripts. You can use it to show your privacy policy or important tasks for your bot.

Would you like to know more?

Get more information