telegram

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package telegram provides a tiny, testable wrapper around github.com/go-telegram/bot.

It defines a minimal Bot interface (register handlers, send messages, process single updates, start polling, get ID) so application code depends on an interface and can be unit‑tested with mocks. NewBot returns an adapter that forwards calls to the real *bot.Bot while adapting handler + middleware signatures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(f HandlerFunc) bot.HandlerFunc

Handler converts a HandlerFunc to a bot.HandlerFunc by injecting the Bot instance.

func LogChat

func LogChat(c *models.Chat) slog.Value

LogChat returns a slog.Value for models.Chat for structured logging

func LogMessage

func LogMessage(m *models.Message) slog.Value

LogMessage returns a slog.Value for models.Message for structured logging

func LogUpdate

func LogUpdate(u *models.Update) slog.Value

LogUpdate returns a slog.Value for models.Update for structured logging

func LogUser

func LogUser(u *models.User) slog.Value

LogUser returns a slog.Value for models.User for structured logging

func Middlewares

func Middlewares(m ...Middleware) []bot.Middleware

Middlewares converts a slice of Middleware to a slice of bot.Middleware by injecting the Bot instance.

Types

type API

type API interface {
	// SendMessage sends a message to a chat and returns the created message.
	SendMessage(ctx context.Context, p *bot.SendMessageParams) (*models.Message, error)
}

API defines the subset of the Telegram Bot API methods used in this project.

type Bot

type Bot interface {
	API

	// ID returns the bot's Telegram ID.
	ID() int64

	// RegisterHandler registers a new handler with a string pattern.
	RegisterHandler(handlerType bot.HandlerType, pattern string, matchType bot.MatchType, f HandlerFunc, m ...Middleware) string

	// RegisterHandlerRegexp registers a new handler with a regexp pattern.
	RegisterHandlerRegexp(handlerType bot.HandlerType, re *regexp.Regexp, f HandlerFunc, m ...Middleware) string

	// RegisterHandlerMatchFunc registers a new handler with a custom match function.
	RegisterHandlerMatchFunc(matchFunc bot.MatchFunc, f HandlerFunc, m ...Middleware) string

	// UnregisterHandler removes a previously registered handler by its ID.
	UnregisterHandler(id string)

	// ProcessUpdate passes a single update through the bot’s handler chain.
	ProcessUpdate(ctx context.Context, upd *models.Update)

	// Start begins receiving updates and dispatching them to handlers.
	Start(ctx context.Context)
}

Bot is a minimal abstraction over github.com/go-telegram/bot. It defines the subset of functionality needed in this project and enables replacing the real bot with a mock for convenient testing.

func NewBot

func NewBot(token string, opts ...bot.Option) (Bot, error)

NewBot creates a new transparent adapter over *bot.Bot.

type HandlerFunc

type HandlerFunc func(ctx context.Context, api API, update *models.Update)

HandlerFunc defines a function to handle a Telegram update.

type Middleware

type Middleware func(next HandlerFunc) HandlerFunc

Middleware defines a function to process middleware.

type Option

type Option func(b *Bot)

Jump to

Keyboard shortcuts

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