Skip to main content

Module rest

Module rest 

Source
Expand description

WhatsApp Cloud API REST client — outbound message send only.

Mirrors Discord’s rest.rs shape (a single send_message function, no client struct), with one addition Discord doesn’t need: the 24-hour customer service window (spec §3.3/§3.4). Outside the window, Meta rejects a free-form text send (error code 131047); rather than round-trip to the API to discover that, send_message checks the local window state first and fails fast (or falls back to a configured template) before making the HTTP call at all.

Constants§

GRAPH_API_VERSION 🔒
TWENTY_FOUR_HOURS_MS 🔒

Functions§

flatten_text 🔒
WhatsApp’s Cloud API has no rich embed support (spec §5.3) — if OutboundMsg.embed is set, flatten it to plain text rather than dropping it silently.
normalize_phone 🔒
Strips everything but ASCII digits, so the same phone number in different formats — Meta’s inbound from (no +) vs. a caller-supplied to in E.164 (+-prefixed) or with spaces/dashes — normalizes to one 24h-window state key. WhatsAppBridge::record_inbound (mod.rs) applies this same normalization when storing, so the two call sites always agree.
send_message
POST /{phone_number_id}/messages
window_ok 🔒
True if now_ms is within 24h of last_inbound_ms. Pulled out as a pure function so the boundary condition (spec §10’s “24h window edge case”) is unit-testable without a clock or network call.