Skip to content

Messaging platforms

Matúš Žilinec edited this page Jun 23, 2018 · 3 revisions

Golem provides integrations for the most widely used chat platforms. Additionally, it is extensible and you can provide your own endpoint if needed. (Contributions are welcome!)

Facebook Messenger

Facebook sends an HTTP request each time there is a new message. For this to work, you need a public IP address. If you don't have one, we recommend using ngrok. You can start it like this:

ngrok http 8000  # will forward port 8000 to a subdomain of ngrok.io

You will need:

  • a Facebook page - your users will message it and the chatbot will reply
  • a Facebook application - responsible for connecting Messenger to your chatbot

Creating the facebook app

  1. Create an app @ https://developers.facebook.com/apps.
  2. Under Products, activate Messenger, generate an access token for your page and add it to settings.py. Then click Edit events, check messages and messaging_postbacks and subscribe your bot to the page.
  3. Open golem_settings.py and add the following to GOLEM_CONFIG:
  • FB_PAGE_TOKEN: the access token from step 1
  • WEBHOOK_VERIFY_TOKEN: (any) password used by Facebook to verify it's your bot
  • WEBHOOK_SECRET_URL: (any) secret URL used to hide the endpoint
  1. Start the chatbot.
  2. In FB's console, under Products, activate Webhooks, select your Page from the dropdown, click Edit Subscription and set your endpoint URL in format https://xxx.ngrok.io/chatbot/messenger/SECRET_URL/. The verify token must match the one in your settings.
  3. Try sending a message to your page. It should now get through to your bot.

Example

# golem_settings.py
GOLEM_CONFIG = {
    ...
    'FB_PAGE_TOKEN': 'THE_TOKEN_YOU_GOT_FROM_FACEBOOK',
    'WEBHOOK_SECRET_URL': 'my_secret_url',  # used to hide endpoint url from 3rd party
    'WEBHOOK_VERIFY_TOKEN': 'my_password',  # used by FB to verify it's you
   ...

We recommend using os.environ.get("VARIABLE") to avoid committing your secret codes to version control.

Telegram

TODO

Actions on Google

TODO