Documentation
¶
Overview ¶
Package telegram implements the Telegram Platform for Chatwright: an emulated Telegram Bot API server that delivers updates and captures the bot's outbound calls, normalized to Chatwright's neutral platform types.
The Telegram wire types come from the bots-go-framework platform adapter github.com/bots-go-framework/bots-api-telegram (tgbotapi), so Chatwright parses and builds messages exactly as the framework does. The bot under test remains free to be written in any language or framework — this server only speaks the Telegram Bot API over HTTP.
Index ¶
- func Platform() platform.Platform
- type Emulator
- func (e *Emulator) BotAPIURL() string
- func (e *Emulator) Close()
- 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(chatID int64, messageID int, afterVersion int, timeout 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 Telegram Bot API. It owns delivery of updates to the bot-under-test: SubmitText/SubmitClick build the platform-native update and either push it to a configured webhook or queue it for the bot to retrieve via getUpdates — the harness never builds wire bytes or POSTs them itself.
func NewEmulator ¶
func NewEmulator() *Emulator
NewEmulator starts a fake Telegram Bot API server on a random local port.
func (*Emulator) BotAPIURL ¶
BotAPIURL is the base URL the bot-under-test should use as its Telegram Bot API host, in place of https://api.telegram.org.
func (*Emulator) SetWebhook ¶
SetWebhook registers the URL (and HTTP client) the emulator pushes updates to. Passing an empty url clears it, switching delivery back to queuing updates for getUpdates.
func (*Emulator) SubmitClick ¶
func (e *Emulator) SubmitClick(chatID int64, user platform.User, data string, targetMessageID int) error
SubmitClick delivers a user's button click (an interactive action activation) to the bot-under-test as a Telegram callback query. It does not reserve a message ID: a callback query 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 Telegram update, and delivers it.
func (*Emulator) Transcript ¶
Transcript renders a chronological, human-readable dump of everything recorded for chatID — inbound user messages, outbound bot messages (shown at their current, possibly-edited text) and button clicks — for inclusion in assertion failure messages. It is the emulator's own record, independent of what any BotMessage handle has consumed or asserted on.