whatsapp

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 19 Imported by: 0

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

View Source
var ErrMissingConfig = errors.New("whatsapp: missing required config field")

ErrMissingConfig is returned by New when a required Config field is empty.

Functions

func New

func New(cfg Config) (*core.Bot, error)

New creates a WhatsApp bot backed by the Meta Cloud API. It returns ErrMissingConfig if a required credential is absent, and otherwise applies defaults for Path, GraphVersion and HTTPClient. The webhook server is not started until the bot connects.

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

type Media struct {
	ID       string
	MimeType string
	Filename string
}

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.

func RawMessage

func RawMessage(m *core.Message) (*Message, bool)

RawMessage returns the parsed WhatsApp message carried on m, reporting whether m originated from WhatsApp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL