Meta API Callback

Introduction

To use the Meta API, you need to create a callback server to receive updates from WhatsApp. This server must have a secure HTTPS endpoint that can accept both POST and GET requests.

Register callback endpoint

Steps:
  1. Go to your apps in Facebook Developers Apps and select respective app.

  2. Left menu, click on Whatsapp -> Config.

  3. Under the Webhook section, set your callback URL and your verification token.

Verification token

The verification token are a secret key that Meta will GET from the webhook URL and use as a challenge. So configure the same token used in whatsapp.bot.WhatsappBot.verify_token.

Localhost testing

For testing your webhook in a local development environment, you’ll need a tool to create a reverse proxy to your localhost. My personal favorite is Ngrok, as it is easy to use and widely supported.

Warning

However, be aware that Meta might occasionally block Ngrok. In such cases, you can use alternative tools like Serveo.

Alternatively, you can implement a publish-subscribe architecture by using an online server with a public IP. This server can register callback data into a shared database like Redis, allowing you to consume the data directly from your localhost. For more details on this method, refer to Deploying Bots in Production.