Documentation
¶
Overview ¶
Package whatsapp is the WhatsApp adapter for botbooter. It receives messages from the Meta WhatsApp Business Cloud API over an inbound webhook and sends replies back through the Cloud API. It implements core.Adapter.
Unlike the dial-out adapters (Slack, Discord), the Cloud API delivers inbound messages as HTTP webhook callbacks, so this adapter runs its own HTTP server: Connect binds a listener and serves until the run context is canceled, and Disconnect shuts the server down. Bind a local Addr, put a TLS-terminating reverse proxy in front, and register the public HTTPS URL in Meta's webhook settings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMissingConfig = errors.New("whatsapp: missing required config field")
ErrMissingConfig is returned by New when a required Config field is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Token is the Cloud API access token sent as a Bearer credential on
// outbound calls. Prefer a long-lived system-user token; short-lived user
// tokens expire in ~24h, after which Send fails.
Token string
PhoneNumberID string
// AppSecret verifies the X-Hub-Signature-256 HMAC on inbound webhook
// requests. Required: without it the endpoint would accept spoofed payloads.
AppSecret string
VerifyToken string
// Addr is the local TCP address the webhook server binds, e.g. ":8080". A
// bare port ("8080") is accepted as shorthand for ":8080".
Addr string
Path string
GraphVersion string
HTTPClient *http.Client
}
Config configures a WhatsApp Cloud API bot.
type Media ¶
Media is a media object attached to a WhatsApp message. The Cloud API delivers media by ID, not URL: resolve the bytes with GET /{ID} using your access token.
type Message ¶
type Message struct {
From string
ID string
Type string
Text string
AuthorName string
Timestamp time.Time
Media *Media
Raw json.RawMessage
}
Message is the parsed payload of a WhatsApp Cloud API webhook message. AuthorName and Timestamp are enriched, not lifted from Raw: AuthorName is correlated from the webhook's sibling contacts list and Timestamp is parsed from the message's unix-seconds field. Raw holds the original message JSON for callers that need more.