Documentation
¶
Overview ¶
Package telegram provides a Messenger adapter for the Telegram platform using long-polling for bi-directional communication.
The adapter wraps the github.com/go-telegram/bot library and converts Telegram-native updates into the generic messenger.IncomingMessage type. Outgoing messages are sent via the Telegram Bot API's sendMessage endpoint.
Transport: Long-polling (no public endpoint required).
Authentication ¶
A Bot API token from BotFather is required. Pass it via [Config.Token].
Usage ¶
m, err := telegram.New(telegram.Config{Token: os.Getenv("TELEGRAM_BOT_TOKEN")})
if err != nil { /* handle */ }
if err := m.Connect(ctx); err != nil { /* handle */ }
defer m.Disconnect(ctx)
Package telegram provides a Messenger adapter for the Telegram platform.
This file implements the HTTP webhook handler (webhookHTTPHandler), enabling Telegram to receive updates via HTTP push instead of long-polling. This allows the adapter to be mounted on a shared HTTP mux at a context path (e.g., /agents/{name}/telegram/events) rather than requiring its own polling loop.
Telegram webhooks are set via the Bot API's setWebhook method. Updates arrive as JSON POST requests to the configured URL. See: https://core.telegram.org/bots/api#setwebhook
Index ¶
- type Config
- type Messenger
- func (m *Messenger) Connect(ctx context.Context) (http.Handler, error)
- func (m *Messenger) ConnectionInfo() string
- func (m *Messenger) Disconnect(ctx context.Context) error
- func (m *Messenger) FormatApproval(req messenger.SendRequest, _ messenger.ApprovalInfo) messenger.SendRequest
- func (m *Messenger) FormatClarification(req messenger.SendRequest, _ messenger.ClarificationInfo) messenger.SendRequest
- func (m *Messenger) Platform() messenger.Platform
- func (m *Messenger) Receive(_ context.Context) (<-chan messenger.IncomingMessage, error)
- func (m *Messenger) Send(ctx context.Context, req messenger.SendRequest) (messenger.SendResponse, error)
- func (m *Messenger) UpdateMessage(_ context.Context, _ messenger.UpdateRequest) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Token is the Telegram Bot API token from BotFather.
Token string
}
Config holds Telegram-specific configuration.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger implements the messenger.Messenger interface for Telegram using long-polling. It manages the bot lifecycle, incoming message buffer, and connection state through an internal mutex.
func New ¶
New creates a new Telegram Messenger with the given config and options. Returns an error if the underlying Telegram bot client cannot be initialised (e.g., malformed token).
func (*Messenger) Connect ¶
Connect starts the Telegram bot with long-polling. Returns a nil http.Handler since Telegram long-polling is outbound.
func (*Messenger) ConnectionInfo ¶
ConnectionInfo returns connection instructions for the Telegram adapter.
func (*Messenger) Disconnect ¶
Disconnect gracefully shuts down the Telegram bot.
func (*Messenger) FormatApproval ¶
func (m *Messenger) FormatApproval(req messenger.SendRequest, _ messenger.ApprovalInfo) messenger.SendRequest
FormatApproval returns the request unchanged — Telegram does not use rich card formatting for approval notifications.
func (*Messenger) FormatClarification ¶
func (m *Messenger) FormatClarification(req messenger.SendRequest, _ messenger.ClarificationInfo) messenger.SendRequest
FormatClarification returns the request unchanged — Telegram does not use rich card formatting for clarification notifications.
func (*Messenger) Send ¶
func (m *Messenger) Send(ctx context.Context, req messenger.SendRequest) (messenger.SendResponse, error)
Send delivers a message to a Telegram chat, or adds an emoji reaction when Type is SendTypeReaction.
func (*Messenger) UpdateMessage ¶
UpdateMessage is a no-op for Telegram — the adapter does not currently support editing previously sent messages. Returns nil to satisfy the Messenger interface without error.