telegram

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

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

func New(cfg Config, opts ...messenger.Option) (*Messenger, error)

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

func (m *Messenger) Connect(ctx context.Context) (http.Handler, error)

Connect starts the Telegram bot with long-polling. Returns a nil http.Handler since Telegram long-polling is outbound.

func (*Messenger) ConnectionInfo

func (m *Messenger) ConnectionInfo() string

ConnectionInfo returns connection instructions for the Telegram adapter.

func (*Messenger) Disconnect

func (m *Messenger) Disconnect(ctx context.Context) error

Disconnect gracefully shuts down the Telegram bot.

func (*Messenger) FormatApproval

FormatApproval returns the request unchanged — Telegram does not use rich card formatting for approval notifications.

func (*Messenger) FormatClarification

FormatClarification returns the request unchanged — Telegram does not use rich card formatting for clarification notifications.

func (*Messenger) Platform

func (m *Messenger) Platform() messenger.Platform

Platform returns the Telegram platform identifier.

func (*Messenger) Receive

func (m *Messenger) Receive(_ context.Context) (<-chan messenger.IncomingMessage, error)

Receive returns a channel of incoming messages from Telegram.

func (*Messenger) Send

Send delivers a message to a Telegram chat, or adds an emoji reaction when Type is SendTypeReaction.

func (*Messenger) UpdateMessage

func (m *Messenger) UpdateMessage(_ context.Context, _ messenger.UpdateRequest) error

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.

Jump to

Keyboard shortcuts

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