Skip to content

feat: WhatsApp Business API notification sink (I-011, scaffold) - #68

Open
lopster568 wants to merge 1 commit into
mainfrom
feat/whatsapp-notify
Open

feat: WhatsApp Business API notification sink (I-011, scaffold)#68
lopster568 wants to merge 1 commit into
mainfrom
feat/whatsapp-notify

Conversation

@lopster568

Copy link
Copy Markdown
Collaborator

What

Adds internal/notify/whatsapp: a notification sink backed by the Meta WhatsApp Business (Cloud) API, so alert and report paths can deliver messages over WhatsApp.

  • Notifier interface (Notify(ctx, message) + Enabled()) for callers to depend on.
  • Client that POSTs to https://graph.facebook.com/v.../{phone_number_id}/messages with a bearer token.
  • Text messages (Notify) and pre-approved template messages (NotifyTemplate).
  • Config from WHATSAPP_TOKEN, WHATSAPP_PHONE_ID, WHATSAPP_TO via ConfigFromEnv / NewFromEnv.

Why

Indian SMBs, schools and hospitals live on WhatsApp; delivering security alerts and daily reports there is far more actionable than email. This lands the integration wiring now so it can be switched on with credentials once approved.

How

  • Config.Enabled() requires all three of token, phone ID and recipient; if any is empty the sink is a no-op.
  • Graph API version (default v20.0) and base URL are overridable, the latter purely as a test injection point.
  • post() marshals the payload, sets Authorization: Bearer <token> and Content-Type: application/json, and treats non-2xx as an error (surfacing status + body).
  • No existing code paths are modified; the Notifier is exposed for later wiring to keep scope tight.

Tests

Hermetic, no real Meta API — an httptest server stands in:

  • Text payload shape (messaging_product, recipient_type, to, type, text.body).
  • Template payload shape (name, language default en_US, body component parameters).
  • POST hits the right path with the correct bearer + content-type headers.
  • Disabled (no creds) = no-op, server never contacted.
  • Error handling: empty message, empty template name, non-2xx response, transport failure.
  • Enabled() matrix and ConfigFromEnv env parsing.

gofmt, go build ./..., go vet ./..., go test ./... all green.

Note

Scaffolding. This is disabled by default and completely inert without credentials. Actually delivering messages requires an approved WhatsApp Business Account (WABA) and, for templates, a pre-approved message template from Meta. The sink stays a no-op until that approval is in place and credentials are configured.

🤖 Generated with Claude Code

Add internal/notify/whatsapp: a Notifier for the Meta WhatsApp Business
Cloud API. Disabled by default and inert until WHATSAPP_TOKEN,
WHATSAPP_PHONE_ID and WHATSAPP_TO are set. Supports text and pre-approved
template messages; fully unit-tested against httptest, no live Meta API.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant