telegram

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 18 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]) (notifier.Destination[T], error)

Chat creates a destination for a Telegram chat.

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.

Jump to

Keyboard shortcuts

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