Build a Facebook Chatbot in Python

Jeongsoo Park
Aug 15, 2017 · 3 min read
Image for post
Image for post

Nowadays there are many articles like ‘’. But somebody still feels comfortable with codes. I’ll tell you here about to build a Facebook Messenger chatbot rapidly with BotHub.Studio.

Image for post
Image for post

Creating a Facebook Messenger Bot

Let’s create an app. Move to Facebook developer site.

Image for post
Image for post

Create a new app.

Image for post
Image for post

Enter a bot name and contact email.

Image for post
Image for post

Now you can see a dashboard like below. You can find an and here.

Image for post
Image for post

Add a product to the app. Click Set Up button in Messenger section.

Image for post
Image for post

Link it to your Facebook page. Then you can find a there.

Image for post
Image for post

Note three entries below to deploy your chatbot to hosting service later.

Setup Hosting for Bot

First, create an account on BotHub.Studio, , and install CLI tool using the command below:

$ pip install bothub-cli

Run configure next:

$ bothub configure

Create a project directory:

$ mkdir MyBot
$ cd MyBot
$ bothub init

A template code will be generated after init finished:

|-- bothub
| |-- bot.py
| `-- __init__.py
|-- bothub.yml
|-- requirements.txt
`-- tests

Primary template code, specifically bot.py contains an code which mimics a user message.

Now we use the facebook credentials you note:

$ bothub channel add facebook --page-access-token=<token> \
--app-secret=<secret> \
--app-id=<id>

And deploy the project to server:

$ bothub deploy

Send a message to your chatbot and see it works well. Search your Facebook page name on Facebook Messenger, then you can talk to your chatbot.

BotHub.Studio

News, tutorials about BotHub.Studio chatbot hosting service

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store