Documentation
¶
Overview ¶
Package whatsapp implements the WhatsApp Platform for Chatwright: an emulated WhatsApp Cloud API (Graph) server that delivers inbound webhooks and captures the bot's outbound calls, normalized to Chatwright's neutral platform types.
This is the MVP-scope, text-first WhatsApp platform. It reuses the bots-go-framework WhatsApp adapter github.com/bots-go-framework/bots-api-whatsapp (wabotapi) for outbound message decoding. Interactive replies are a planned extension; the seam is identical to Telegram's, so a text scenario written once runs on either platform.
Index ¶
- func Platform() platform.Platform
- type Emulator
- func (e *Emulator) BotAPIURL() string
- func (e *Emulator) Close()
- func (e *Emulator) Journal(chatID int64) ([]platform.JournalEntry, error)
- func (e *Emulator) SetWebhook(url string, client *http.Client)
- func (e *Emulator) SubmitClick(chatID int64, user platform.User, data string, targetMessageID int) error
- func (e *Emulator) SubmitText(chatID int64, user platform.User, text string) error
- func (e *Emulator) Transcript(chatID int64) string
- func (e *Emulator) WaitForEdit(int64, int, int, time.Duration) (*platform.Message, bool)
- func (e *Emulator) WaitForMessage(chatID int64, consumed int, timeout time.Duration) (*platform.Message, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Emulator ¶
type Emulator struct {
// contains filtered or unexported fields
}
Emulator is an in-process HTTP server emulating the WhatsApp Cloud API. It owns delivery of updates to the bot-under-test: SubmitText/SubmitClick build the inbound webhook payload and push it to the configured webhook — the harness never builds wire bytes or POSTs them itself. Unlike Telegram, the WhatsApp Cloud API has no polling mode, so a webhook is required.
func NewEmulator ¶
func NewEmulator() *Emulator
NewEmulator starts a fake WhatsApp Cloud API server on a random local port.
func (*Emulator) BotAPIURL ¶
BotAPIURL is the base URL the bot-under-test should use as its WhatsApp Cloud API host, in place of https://graph.facebook.com.
func (*Emulator) Journal ¶
func (e *Emulator) Journal(chatID int64) ([]platform.JournalEntry, error)
Journal returns chatID's chronological, structured journal entries — the same events Transcript renders as prose. The WhatsApp Cloud API has no message-edit endpoint and this text-first MVP-scope emulator does not yet capture outbound interactive actions (see the package doc), so Version is always 0, Actions is always empty and JournalEntryUncaptured never occurs.
func (*Emulator) SetWebhook ¶
SetWebhook registers the URL (and HTTP client) the emulator pushes inbound webhooks to. The WhatsApp Cloud API has no polling mode: Submit* calls return an error until a webhook is set.
func (*Emulator) SubmitClick ¶
func (e *Emulator) SubmitClick(chatID int64, user platform.User, data string, targetMessageID int) error
SubmitClick delivers a user's interactive-reply click to the bot-under-test. It does not reserve a message ID: the click references an existing message (targetMessageID) rather than creating a new one.
func (*Emulator) SubmitText ¶
SubmitText delivers a user's text message to the bot-under-test: it reserves the message's ID from chatID's shared sequence, journals the inbound event, builds the WhatsApp inbound webhook payload, and pushes it. The wabotapi adapter does not yet model inbound text bodies, so the text object is built here per the documented WhatsApp Cloud API webhook shape.
func (*Emulator) Transcript ¶
Transcript renders a chronological, human-readable dump of everything recorded for chatID — inbound user messages, outbound bot messages and interactive-reply clicks — for inclusion in assertion failure messages. It renders from the same structured entries Journal returns, so the two never drift.
func (*Emulator) WaitForEdit ¶
WaitForEdit always reports no edit: the WhatsApp Cloud API has no message-edit endpoint, so a sent text message can never change in place.