telegram

package
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package telegram implements the Telegram channel for DevClaw using the Telegram Bot API directly via HTTP — no external dependencies.

Features:

  • Long polling for updates (getUpdates)
  • Send/receive text, images, audio, video, documents, voice notes
  • Typing indicators (sendChatAction)
  • Reactions (setMessageReaction, Bot API 7.0+)
  • Media download via getFile
  • HTML formatting for rich messages
  • Group and DM support

Index

Constants

View Source
const (
	ButtonStyleDefault = ""
	ButtonStylePrimary = "primary" // blue
	ButtonStyleSuccess = "success" // green
	ButtonStyleDanger  = "danger"  // red
)

ButtonStyle is the visual style of an inline keyboard button. Telegram Bot API 9.4+ supports native styles; older clients may fall back to emoji prefixes.

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 `yaml:"token"`

	// AllowedChats restricts which chat IDs the bot responds to.
	// Empty means respond to all chats.
	AllowedChats []int64 `yaml:"allowed_chats"`

	// RespondToGroups enables responding in group chats.
	RespondToGroups bool `yaml:"respond_to_groups"`

	// RespondToDMs enables responding in direct messages.
	RespondToDMs bool `yaml:"respond_to_dms"`

	// SendTyping sends "typing..." indicators while processing.
	SendTyping bool `yaml:"send_typing"`

	// ParseMode sets the default parse mode for outgoing messages ("HTML" or "Markdown").
	ParseMode string `yaml:"parse_mode"`

	// ReactionNotifications controls when user reactions are surfaced as system events.
	// "off" (default): ignore reactions
	// "own": only reactions to bot messages
	// "all": all reactions in allowed chats
	ReactionNotifications string `yaml:"reaction_notifications"`
}

Config holds Telegram channel configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type InlineButton

type InlineButton struct {
	Text         string `json:"text"`
	CallbackData string `json:"callback_data,omitempty"`
	URL          string `json:"url,omitempty"`
	Style        string `json:"style,omitempty"` // "primary", "success", "danger", or ""
}

InlineButton represents an inline keyboard button. Use via OutgoingMessage.Metadata["telegram_buttons"] as []InlineButton. Each button needs either CallbackData or URL; Style is optional.

type Telegram

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

Telegram implements channels.Channel, channels.MediaChannel, channels.PresenceChannel, and channels.ReactionChannel.

func New

func New(cfg Config, logger *slog.Logger) *Telegram

New creates a new Telegram channel instance.

func (*Telegram) Connect

func (t *Telegram) Connect(ctx context.Context) error

Connect starts the long-polling loop for receiving updates.

func (*Telegram) Disconnect

func (t *Telegram) Disconnect() error

Disconnect stops the polling loop.

func (*Telegram) DownloadMedia

func (t *Telegram) DownloadMedia(ctx context.Context, msg *channels.IncomingMessage) ([]byte, string, error)

DownloadMedia downloads media from an incoming message.

func (*Telegram) Health

func (t *Telegram) Health() channels.HealthStatus

Health returns the channel health status.

func (*Telegram) IsConnected

func (t *Telegram) IsConnected() bool

IsConnected returns true if the bot is connected.

func (*Telegram) MarkRead

func (t *Telegram) MarkRead(ctx context.Context, chatID string, messageIDs []string) error

MarkRead is a no-op for Telegram (bots can't mark messages as read).

func (*Telegram) Name

func (t *Telegram) Name() string

Name returns "telegram".

func (*Telegram) Receive

func (t *Telegram) Receive() <-chan *channels.IncomingMessage

Receive returns the incoming messages channel.

func (*Telegram) Send

func (t *Telegram) Send(ctx context.Context, to string, message *channels.OutgoingMessage) error

Send sends a text message to the specified chat.

func (*Telegram) SendMedia

func (t *Telegram) SendMedia(ctx context.Context, to string, media *channels.MediaMessage) error

SendMedia sends a media message to the specified chat.

func (*Telegram) SendPresence

func (t *Telegram) SendPresence(ctx context.Context, available bool) error

SendPresence is a no-op for Telegram.

func (*Telegram) SendReaction

func (t *Telegram) SendReaction(ctx context.Context, chatID, messageID, emoji string) error

SendReaction sends a reaction emoji to a specific message (Bot API 7.0+).

func (*Telegram) SendTyping

func (t *Telegram) SendTyping(ctx context.Context, to string) error

SendTyping sends a "typing..." chat action.

Jump to

Keyboard shortcuts

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