telegram

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package telegram sends notification batches through the Telegram Bot API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig indicates invalid client settings.
	ErrInvalidConfig = errors.New("invalid telegram configuration")
	// ErrInvalidChat indicates an invalid chat destination.
	ErrInvalidChat = errors.New("invalid telegram chat")
)

Functions

This section is empty.

Types

type Client

type Client[T any] struct {
	// contains filtered or unexported fields
}

Client is a shared Telegram bot client.

func NewClient

func NewClient[T any](cfg Config) (*Client[T], error)

NewClient validates cfg and creates a Client without network I/O.

func (*Client[T]) Chat

func (c *Client[T]) Chat(id, chat string, renderer Renderer[T], opts ...SendOption) (notifier.Destination[T], error)

Chat creates a destination for a Telegram chat. opts customize every SendMessage call, e.g. WithParseMode(models.ParseModeMarkdown) or setting fields directly.

func (*Client[T]) Routes

func (c *Client[T]) Routes() []Route

Routes returns the webhook route, or an empty slice in polling mode, without network I/O.

func (*Client[T]) Run

func (c *Client[T]) Run(ctx context.Context) error

Run registers the webhook when configured and blocks until shutdown or worker failure.

type Config

type Config struct {
	// Token is the required BotFather token. Errors do not include it.
	Token string
	// APIBase overrides the Bot API endpoint.
	APIBase string

	// WebhookURL receives updates in webhook mode.
	WebhookURL string
	// WebhookPattern is the ServeMux pattern returned by Routes.
	WebhookPattern string
	// WebhookSecret authenticates webhook callbacks.
	WebhookSecret string

	// Polling selects long polling instead of webhook mode.
	Polling bool
	// HTTPClient overrides the default HTTP client used for Bot API requests (i.e. for proxy).
	// Callers must not mutate it while in use.
	HTTPClient *http.Client

	// ProxyCACertPath adds a trusted CA for the Bot API connection.
	ProxyCACertPath string
	// ClientCertPath and ClientKeyPath configure mTLS and must be set together.
	ClientCertPath string
	ClientKeyPath  string
}

Config defines Telegram API and update-delivery settings.

type Renderer

type Renderer[T any] func(batch []T) string

Renderer renders a notification batch as one Telegram message.

type Route

type Route struct {
	// Pattern is a net/http ServeMux pattern.
	Pattern string
	// Handler serves Pattern.
	Handler http.Handler
}

Route describes an HTTP endpoint required by a Client.

type SendOption added in v0.2.0

type SendOption func(*bot.SendMessageParams)

SendOption customizes the bot.SendMessageParams used for a Chat's messages.

func WithParseMode added in v0.2.0

func WithParseMode(mode models.ParseMode) SendOption

WithParseMode sets the message parse mode, e.g. models.ParseModeMarkdown or models.ParseModeHTML.

func WithoutLinkPreview added in v0.2.0

func WithoutLinkPreview() SendOption

WithoutLinkPreview disables the link preview for URLs found in the message text.

func WithoutNotification added in v0.2.0

func WithoutNotification() SendOption

WithoutNotification delivers the message silently: no sound or vibration on the recipient's device.

Jump to

Keyboard shortcuts

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