telegramtest

package
v0.136.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package telegramtest is a stand-in for the Telegram Bot API, for tests and preview stands: nothing in the suite ever talks to api.telegram.org.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Token    string
	Username string
	// contains filtered or unexported fields
}

Bot is a fake Bot API serving one bot.

func New

func New(token, username string) *Bot

New starts a fake for a bot with this token and username. Close it when done.

func (*Bot) Answers

func (b *Bot) Answers() []string

Answers returns the texts of every answerCallbackQuery, in order.

func (*Bot) Calls

func (b *Bot) Calls() []string

Calls returns every method called, in order.

func (*Bot) Close

func (b *Bot) Close()

Close stops the server.

func (*Bot) Messages

func (b *Bot) Messages() []Sent

Messages returns only the messages sent (no edits or reactions).

func (*Bot) Pending

func (b *Bot) Pending() int

Pending is how many queued updates have not been confirmed.

func (*Bot) Press

func (b *Bot) Press(chatID, msgID int64, data string)

Press queues a press of a button with data under the bot's message msgID.

func (*Bot) RateLimit

func (b *Bot) RateLimit(n, retryAfter int)

RateLimit makes the next n calls answer 429 with retry_after seconds.

func (*Bot) RefuseURLButtons

func (b *Bot) RefuseURLButtons()

RefuseURLButtons makes a message with a URL button fail as Telegram fails one whose address it will not open.

func (*Bot) Reply

func (b *Bot) Reply(chatID int64, replyTo int64, text string)

Reply queues a message sent with Telegram's Reply to the bot's message replyTo.

func (*Bot) Say

func (b *Bot) Say(chatID int64, firstName, text string)

Say queues a text message from a private chat, as if someone typed it to the bot.

func (*Bot) SayIn

func (b *Bot) SayIn(chatID int64, chatType, firstName, text string, replyTo int64)

SayIn queues a message from a chat of a given type ("private", "group").

func (*Bot) SayOld

func (b *Bot) SayOld(chatID int64, text string, age time.Duration)

SayOld queues a message dated age ago, as one sent while nobody read.

func (*Bot) Sent

func (b *Bot) Sent() []Sent

Sent returns every message, edit and reaction so far.

func (*Bot) URL

func (b *Bot) URL() string

URL is the base to give a telegram.Client.

type Sent

type Sent struct {
	Method    string
	ChatID    string
	Text      string
	ParseMode string
	MessageID int64
	// ReplyTo is the message a sent one is threaded under; for an edit or a
	// reaction, the message it changes.
	ReplyTo int64
	// Buttons are the inline buttons' callback data (or "url:" + the URL),
	// row by row flattened.
	Buttons []string
	// ForceReply says the message asked for a reply.
	ForceReply bool
	Emoji      string
	// Photo is a sendPhoto's file; Text is then its caption.
	Photo []byte
	At    time.Time
}

Sent is one call the fake received that changes the chat: a message, an edit of its buttons, or a reaction.

Jump to

Keyboard shortcuts

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