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
- type Config
- type InlineButton
- type Telegram
- 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) 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
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 {
// 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) Disconnect ¶
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 ¶
IsConnected returns true if the bot is connected.
func (*Telegram) Receive ¶
func (t *Telegram) Receive() <-chan *channels.IncomingMessage
Receive returns the incoming messages channel.
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+).