Skip to content

Client Facebook

Keith Sterling edited this page Feb 26, 2019 · 4 revisions

A great start on how to create a client for Facebook can be found on the Twilio Blog. This describes a full example of how to build a Facebook Messenger Bot using Python. I strongly recommend reading this first, specifically how to:

  • Create a developer account
  • Register a new Bot
  • Create an Access Token
  • Create a Verify Token
  • Use ngrok to test your bot You will notice that the code used in Facebook client is very close to the code shown during this example !

REST Client

The Facebook client is primarily a REST end point that the Facebook platform calls every time some one sends your Facebook bot a message. Therefore the setup and configuration is almost identical to how your set up a REST client. The following configuration should be added to the config.yaml file of your bot

facebook:
  host: 0.0.0.0
  port: 5000
  debug: false

This will then expose the bot on port 5000. If your server is public then it will be available on https://:5000, or if you intend to use ngrok to expose your server, you can use the port number as follows

ngrok http 5000

Remember to cut and paste the ngrok https address back into the Facebook configuration of your bot before you try and use it

In addition the configuration, you need to add to entries to license.keys. These securely provide the Access Token and Verify Token you previously set during the Facebook creation process. These entries are as follows

FACEBOOK_ACCESS_TOKEN = XXXX
FACEBOOK_VERIFY_TOKEN = YYYY

To run the Facebook client, you can use the shell script in Y-Bot scripts folder

./y-bot-facebook.sh

Or you can use the command line

python3 -m programy.clients.rest.flask.facebook.client --config <PATH TO CONFIG> --cformat yaml --logging <PATH TO LOGGING>

HTTPS

Facebook requires your server to run using HTTPS on a server with a DNS entry. More info to follow on this in a future release

Clone this wiki locally