whatsapp

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Platform

func Platform() platform.Platform

Platform returns the WhatsApp platform for use with cw.OnPlatform.

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

func (e *Emulator) BotAPIURL() string

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) Close

func (e *Emulator) Close()

Close shuts down the emulator's HTTP server.

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

func (e *Emulator) SetWebhook(url string, client *http.Client)

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

func (e *Emulator) SubmitText(chatID int64, user platform.User, text string) error

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

func (e *Emulator) Transcript(chatID int64) string

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

func (e *Emulator) WaitForEdit(int64, int, int, time.Duration) (*platform.Message, bool)

WaitForEdit always reports no edit: the WhatsApp Cloud API has no message-edit endpoint, so a sent text message can never change in place.

func (*Emulator) WaitForMessage

func (e *Emulator) WaitForMessage(chatID int64, consumed int, timeout time.Duration) (*platform.Message, bool)

WaitForMessage waits for the (consumed+1)-th outbound message to chatID.

Jump to

Keyboard shortcuts

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