Documentation
¶
Overview ¶
Package telegram – errors.go defines structured error types for the Telegram Bot API, enabling callers to classify and handle API failures.
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
- type Config
- type InlineButton
- type Telegram
- func (t *Telegram) BaseType() string
- func (t *Telegram) BotID() int64
- func (t *Telegram) BotUsername() string
- func (t *Telegram) Connect(ctx context.Context) error
- func (t *Telegram) Disconnect() error
- func (t *Telegram) DownloadMedia(ctx context.Context, msg *channels.IncomingMessage) ([]byte, string, error)
- func (t *Telegram) Health() channels.HealthStatus
- func (t *Telegram) InstanceID() string
- func (t *Telegram) IsBotMessage(chatID, messageID string) bool
- func (t *Telegram) IsConnected() bool
- func (t *Telegram) MarkRead(ctx context.Context, chatID string, messageIDs []string) error
- func (t *Telegram) Name() string
- func (t *Telegram) Receive() <-chan *channels.IncomingMessage
- func (t *Telegram) Send(ctx context.Context, to string, message *channels.OutgoingMessage) error
- func (t *Telegram) SendMedia(ctx context.Context, to string, media *channels.MediaMessage) error
- func (t *Telegram) SendPresence(ctx context.Context, available bool) error
- func (t *Telegram) SendReaction(ctx context.Context, chatID, messageID, emoji string) error
- func (t *Telegram) SendTyping(ctx context.Context, to string) error
- func (t *Telegram) SetReactionNotifications(v string)
- func (t *Telegram) SetRespondToDMs(v bool)
- func (t *Telegram) SetRespondToGroups(v bool)
- func (t *Telegram) SetSendTyping(v bool)
- type TelegramAPIError
Constants ¶
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 {
// InstanceID identifies this instance ("" for default, e.g. "alerts" for named).
// Set automatically from the config key in telegram_instances.
InstanceID string `yaml:"instance_id,omitempty"`
// 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 (*Telegram) BotID ¶ added in v1.16.5
BotID returns the bot's numeric user ID (available after Connect).
func (*Telegram) BotUsername ¶ added in v1.16.5
BotUsername returns the bot's @username (available after Connect).
func (*Telegram) Disconnect ¶
Disconnect stops the polling loop and closes the messages channel.
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) InstanceID ¶ added in v1.16.0
InstanceID returns the instance identifier ("" for default).
func (*Telegram) IsBotMessage ¶ added in v1.16.0
IsBotMessage returns true if the given message was sent by the bot. Implements channels.SentMessageTracker.
func (*Telegram) IsConnected ¶
IsConnected returns true if the bot is connected.
func (*Telegram) Name ¶
Name returns the channel name. For the default instance this is "telegram"; for named instances it returns "telegram:<instance_id>".
func (*Telegram) Receive ¶
func (t *Telegram) Receive() <-chan *channels.IncomingMessage
Receive returns the incoming messages channel.
func (*Telegram) Send ¶
Send sends a text message to the specified chat. If message.EditMessageID is set, edits the existing message instead.
func (*Telegram) SendPresence ¶
SendPresence is a no-op for Telegram.
func (*Telegram) SendReaction ¶
SendReaction sends a reaction emoji to a specific message (Bot API 7.0+).
func (*Telegram) SendTyping ¶
SendTyping sends a "typing..." chat action. Implements a circuit breaker: after 10 consecutive auth errors, typing indicators are silently suspended to prevent hammering the API with an invalid token and triggering bot exclusion.
func (*Telegram) SetReactionNotifications ¶ added in v1.16.5
SetReactionNotifications updates the reaction notifications setting on the live instance.
func (*Telegram) SetRespondToDMs ¶ added in v1.16.5
SetRespondToDMs updates the respond-to-DMs setting on the live instance.
func (*Telegram) SetRespondToGroups ¶ added in v1.16.5
SetRespondToGroups updates the respond-to-groups setting on the live instance.
func (*Telegram) SetSendTyping ¶ added in v1.16.5
SetSendTyping updates the typing indicator setting on the live instance.
type TelegramAPIError ¶ added in v1.16.0
type TelegramAPIError struct {
// Method is the Bot API method that failed (e.g. "sendMessage").
Method string
// HTTPStatus is the HTTP response status code.
HTTPStatus int
// ErrorCode is the Telegram-specific error code from the JSON response.
ErrorCode int
// Description is the human-readable error description from Telegram.
Description string
}
TelegramAPIError represents a structured error from the Telegram Bot API.
func (*TelegramAPIError) Error ¶ added in v1.16.0
func (e *TelegramAPIError) Error() string
Error implements the error interface.