Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

What Does It Take to Get Your Chatbot Published on Messenger?

DZone's Guide to

What Does It Take to Get Your Chatbot Published on Messenger?

The post reviews the requirements you need to meet to get your chatbot published on the Facebook Messenger app step by step.

· Mobile Zone ·
Free Resource

I covered the steps to developing a conversational chatbot in my previous few posts. Like submission guidelines on respective app stores on mobile platforms (iOS and Android), chatbot platforms like Messenger also have strict guidelines regarding which chatbot gets published and which doesn’t.

Moreover, there are prerequisites over what you need to do in order to get your chatbot published on Messenger. For example, you must own or admin a Facebook Page to get started. Otherwise, you have to create a new page.

1. A Facebook Page Is Mandatory

The bot is accessed through a Facebook Page. If your Facebook account neither has a page associated with it nor is an admin of a page, you must create a new Facebook Page. Once created, you must copy the page ID from the About page.

The name and image of your Facebook Page are what the bot will be recognized by, so create a Facebook Page while keeping your patience level to create a bot in check. You just add basic info. The rest of the info, you can add later.

2. Create a Facebook App

Facebook for Developers is a separate website dedicated to people developing apps using Facebook APIs or one of the platforms, including Messenger.

You’ve to become a developer to access the website and generate an App ID. To create a new App ID, click Skip and Create App ID on the top right-hand corner.

create-facebook-app

Create an App ID and you’ll be asked to add a product. Since we are building a chatbot for Messenger, click the Set Up button below it.

You’ll be presented with the App Dashboard. You have to generate a Token. Under Token Generation, select the page and a popup will emerge. Authenticate your Facebook profile and click continue; the Page Access Token will be beside the page name. Click to copy it.

Create-and-Enable-Webhook

3. Create and Enable Webhooks

To set up Webhooks, you need a Callback URL and Verify Token. Facebook uses Webhooks. Webhook endpoints are URLs defined by users to which Facebook sends events. A single event may be sent to many webhook endpoints.

You need to have a working endpoint that responds with a 200 code and calls back some info in order to validate your bot with Facebook.

To proceed with the step, I am going to clone this GitHub repository by hartleybrody.

 git clone git@github.com:hartleybrody/fb-messenger-bot.git 

bot-built-in-python

Then, cd into it and install python dependencies:

python-dependencies-code

For simplicity, I’ll deploy this to Heroku and recommend that you do so, too.

I have the Heroku CLI Toolbelt installed, so I run

 heroku create 

to get your new chatbot setup. I will verify the thing on a local server with Heroku:

 heroku local 

Then, in your browser, visit http://localhost:3000/ and you should see “Hello world.” http://localhost:3000/facebook/receive should be your Facebook Webhook URL, except Facebook only accepts public URLs.

Hello words

Interrupt the local server with Ctrl+C. To deploy this endpoint to Heroku, run

 git push heroku master 

Open it in your browser with

 heroku open 

Now you’ve got a “working” webhook URL that you can use to setup your bot. Enter it under Callback URL.

setup-webhook-annotated

The Verification Token is a secret value that a bot receives to validate the origin of a request. Whatever value you enter under it, you assure it reflects in your Heroku environment using  heroku config:add VERIFY_TOKEN=your_verification_token_here 

4. Chat With the Bot

Your newly created bot should appear as any of your friends on Messenger. Otherwise, you can click Message on your Facebook Page to chat with the bot.

heroku logs -t  will give you chatbot logs. You should see the POST data that Facebook is sending to your endpoint every time the bot receives a new message.

An instance of JSON POST body that I receive when I send “does this work?” to my bot:

chatbot code

The bot is programmed to respond to everything with “got it, thanks!”

5. Submit the Chatbot to Messenger for Review

While you’re testing your bot, only admins of the Facebook Page can message the bot directly. To make the bot available to everyone over the Messenger Platform, it has to go through a review process.

Facebook seems to be highly systematic in their review process, and for a noble purpose. The code for a Messenger chatbot runs on your own servers and could change at any time, without Facebook learning about it. They appear to be trying hard to assure you’re a policy abider, and not submitting a chatbot for the sake of submitting, only to change it at some point into a spam bot. Imagine the bot that used to give you horoscope alert every day selling you some random Chinese electronics. Of course, Facebook can always revoke API access tokens to a spam chatbot, but Facebook wants a clean platform with their Messenger.

Go to the Messenger App Settings page. Under “App Review for Messenger,” click “Request Permissions.”

app-review

Seek the permissions your bot requires. You’ll enter the “Review Status” page. This page requires you to enter a lot of information to make sure you as a developer will not abuse the platform.

It requires you to do the following:

  • Check several boxes confirming that you’ve gone through their policies and rules.
  • Promise you won’t get involved in uninvited, outbound messaging.
  • Define how your chatbot will converse with users.
  • Provide a test case for the review team.
  • Upload a screencast of your chatbot's conversation flow.
  • Draft a privacy policy.

On this page, you can also request to be allowed to access extra info about users, like their electronic mail or personal information.

At the end of the day, it’s up to the team at Facebook to approve the permissions you seek. The review team can honor a few of your requests and reject some, give you full access, or disapprove of the chatbot altogether. More information about the approval process here.

Topics:
mobile ,mobile app development ,chatbots ,facebook ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}