Anu.Webhook.Plug (Anu v0.2.1)

Copy Markdown View Source

A Plug that handles incoming WhatsApp webhook requests.

This Plug handles two types of requests:

  • GET - Meta's webhook verification challenge. Compares the hub.verify_token query parameter against the configured verify token and returns the hub.challenge value.

  • POST - Incoming webhook events. Verifies the x-hub-signature-256 header, parses the payload, and dispatches events to the configured handler.

Usage

In a Phoenix router:

forward "/webhook/whatsapp", Anu.Webhook.Plug, handler: MyApp.WhatsAppHandler

In a plain Plug router:

forward "/webhook/whatsapp", to: Anu.Webhook.Plug, init_opts: [handler: MyApp.WhatsAppHandler]

Options

Multi-app setups (several WABAs in one node) can mount one forward per app, each with its own :secret and :verify_token.