Skip to content

Add WhatsApp adapter via Twilio #15

Description

@joamag

Problem (Why)

WhatsApp is a primary messaging channel in many markets, but pushi cannot deliver to it today. Teams wanting WhatsApp notifications must integrate Twilio's WhatsApp API themselves, re-implementing the subscription and routing pushi already provides. A first-class WhatsApp adapter—reusing the Twilio integration introduced for SMS—lets pushi apps reach WhatsApp recipients with the same subscribe/publish model as every other channel.

Description (What)

Introduce a WhatsAppHandler adapter that delivers pushi events to WhatsApp through Twilio's WhatsApp Messages API, with a WhatsApp subscription model, REST controller and API client mirroring the other adapters. Destination WhatsApp numbers are stored per subscription and overridable per published event. It reuses the Twilio credential configuration from the SMS adapter, adding a WhatsApp-specific from-number.

Implementation (How)

  1. Add WhatsAppHandler(handler.Handler) in src/pushi/base/whatsapp.py implementing load, add, remove, subscribe, unsubscribe, send(app_id, event, json_d, invalid={}) and a direct send_to_numbers(...); reuse the Twilio backend, formatting recipients/sender as whatsapp:+<number>.
  2. Send via the Twilio Messages REST API using netius.clients.HTTPClient with basic auth, honoring per-event number overrides over the stored subscription number.
  3. Reuse the Twilio config from the SMS work and add a WhatsApp from-number field (twilio_whatsapp_from) on the App model in src/pushi/app/models/app.py, with an env-var fallback via appier.conf.
  4. Add the WhatsApp subscription model in src/pushi/app/models/whatsapp.py with fields (number, event) and handler-sync lifecycle hooks.
  5. API: add a WhatsAppController in src/pushi/app/controllers/whatsapp.py exposing GET/POST /whatsapps and DELETE /whatsapps/<number>.
  6. API client: add WhatsAppAPI in src/pushi/api/whatsapp.py with create_whatsapp / delete_whatsapp / subscribe_whatsapp / unsubscribe_whatsapp.
  7. Register the handler in State.load_handlers() in src/pushi/base/state.py and export new symbols from the four __init__.py files.
  8. Add tests in src/pushi/test/whatsapp.py (WhatsApp address formatting, Twilio payload/auth, per-event override, subscription sync).
  9. Note the dependency/ordering on the SMS/Twilio issue so the shared backend lands first.
  10. Update README.md, add an examples/whatsapp/ example, and add a [Unreleased] CHANGELOG entry.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions