telegram

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package telegram adapts the Telegram Bot API to the inbox Source and Sink ports. It receives messages by long-polling getUpdates and replies with sendMessage, using only the standard library so it ships in the single static binary with no extra dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot is a Telegram bot adapted to the inbox ports: it is both a Source (inbound messages) and a Sink (outbound replies). Construct it with New.

func New

func New(token string, opts ...Option) (*Bot, error)

New builds a Telegram bot for the given token. The token is required and is never logged or wrapped into an error.

func (*Bot) Name

func (b *Bot) Name() string

Name identifies the source and its paired sink.

func (*Bot) Receive

func (b *Bot) Receive(ctx context.Context) (<-chan inbox.Spec, error)

Receive long-polls getUpdates and streams each text message as an inbox.Spec until ctx is cancelled, then closes the returned channel. Transient request failures are retried after a short backoff rather than ending the stream. The Spec's Source is left for the ingester to stamp.

func (*Bot) Send

func (b *Bot) Send(ctx context.Context, conversation, text string) error

Send delivers a reply to a conversation with sendMessage, splitting an over-long reply into several messages so a large answer is delivered in full.

type Option

type Option func(*Bot)

Option configures a Bot.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the API root (for tests).

func WithClock

func WithClock(clk clock.Timing) Option

WithClock sets the clock that paces reconnect backoff, so a test drives retry timing with a Manual clock instead of sleeping. Production leaves the default System clock.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client used for API calls. The default client has no timeout because getUpdates long-polls; per-request deadlines are applied internally instead.

func WithPollTimeout

func WithPollTimeout(d time.Duration) Option

WithPollTimeout overrides how long each getUpdates call waits for a message.

Jump to

Keyboard shortcuts

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