Documentation
¶
Index ¶
- func FormatMarkdown(text string) string
- type ApprovalProvider
- func (p *ApprovalProvider) CanHandle(sessionKey string) bool
- func (p *ApprovalProvider) HandleCallback(query *tgbotapi.CallbackQuery)
- func (p *ApprovalProvider) Name() string
- func (p *ApprovalProvider) RequestApproval(ctx context.Context, req approval.ApprovalRequest) (approval.ApprovalResponse, error)
- type BotAPI
- type Channel
- func (c *Channel) DownloadFile(fileID string) ([]byte, error)
- func (c *Channel) GetApprovalProvider() *ApprovalProvider
- func (c *Channel) Name() string
- func (c *Channel) Send(chatID int64, msg *OutgoingMessage) error
- func (c *Channel) SetHandler(handler MessageHandler)
- func (c *Channel) Start(ctx context.Context) error
- func (c *Channel) StartTyping(ctx context.Context, chatID int64) func()
- func (c *Channel) Stop(ctx context.Context) error
- type Config
- type IncomingMessage
- type MessageHandler
- type OutgoingMessage
- type TelegramBot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatMarkdown ¶
FormatMarkdown converts standard Markdown to Telegram Markdown v1.
Telegram v1 supports: *bold*, _italic_, `code`, ```pre```, [text](url). Standard Markdown features not in v1 (e.g. ~~strike~~) are stripped. Content inside code blocks (```) is preserved without transformation.
Types ¶
type ApprovalProvider ¶
type ApprovalProvider struct {
// contains filtered or unexported fields
}
ApprovalProvider implements approval.Provider for Telegram using InlineKeyboard buttons.
func NewApprovalProvider ¶
func NewApprovalProvider(bot BotAPI, timeout time.Duration) *ApprovalProvider
NewApprovalProvider creates a Telegram approval provider.
func (*ApprovalProvider) CanHandle ¶
func (p *ApprovalProvider) CanHandle(sessionKey string) bool
CanHandle returns true for session keys starting with "telegram:".
func (*ApprovalProvider) HandleCallback ¶
func (p *ApprovalProvider) HandleCallback(query *tgbotapi.CallbackQuery)
HandleCallback processes an InlineKeyboard callback query for approval.
func (*ApprovalProvider) Name ¶ added in v0.7.0
func (p *ApprovalProvider) Name() string
func (*ApprovalProvider) RequestApproval ¶
func (p *ApprovalProvider) RequestApproval(ctx context.Context, req approval.ApprovalRequest) (approval.ApprovalResponse, error)
RequestApproval sends an InlineKeyboard message to the chat and waits for a callback.
type BotAPI ¶
type BotAPI interface {
GetUpdatesChan(config tgbotapi.UpdateConfig) tgbotapi.UpdatesChannel
Send(c tgbotapi.Chattable) (tgbotapi.Message, error)
Request(c tgbotapi.Chattable) (*tgbotapi.APIResponse, error)
GetFile(config tgbotapi.FileConfig) (tgbotapi.File, error)
StopReceivingUpdates()
GetSelf() tgbotapi.User
}
BotAPI defines the interface for Telegram Bot API operations.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel implements Telegram bot
func (*Channel) DownloadFile ¶
DownloadFile downloads a file by file ID
func (*Channel) GetApprovalProvider ¶
func (c *Channel) GetApprovalProvider() *ApprovalProvider
GetApprovalProvider returns the channel's approval provider for composite registration.
func (*Channel) Send ¶
func (c *Channel) Send(chatID int64, msg *OutgoingMessage) error
Send sends a message. When ParseMode is not set, standard Markdown is auto-converted to Telegram v1 and sent with ParseMode "Markdown". If the API rejects the formatted text, the original text is re-sent as plain text.
func (*Channel) SetHandler ¶
func (c *Channel) SetHandler(handler MessageHandler)
SetHandler sets the message handler
func (*Channel) StartTyping ¶
StartTyping sends a typing indicator to the chat and refreshes it periodically until the returned stop function is called or ctx is cancelled. The returned stop function is safe to call multiple times.
type Config ¶
type Config struct {
BotToken string
Allowlist []int64 // allowed user/chat IDs (empty = all)
ApprovalTimeoutSec int // 0 = default 30s
APIEndpoint string // optional, for testing
HTTPClient *http.Client // optional, for testing
Bot BotAPI // optional, for testing
}
Config holds Telegram channel configuration
type IncomingMessage ¶
type IncomingMessage struct {
MessageID int
ChatID int64
UserID int64
Username string
Text string
ReplyToID int
HasMedia bool
MediaType string
MediaFileID string
}
IncomingMessage represents a message from Telegram
type MessageHandler ¶
type MessageHandler func(ctx context.Context, msg *IncomingMessage) (*OutgoingMessage, error)
MessageHandler handles incoming messages
type OutgoingMessage ¶
type OutgoingMessage struct {
Text string
ReplyToID int
ParseMode string // "Markdown", "HTML"
DisablePreview bool
}
OutgoingMessage represents a message to send
type TelegramBot ¶
TelegramBot is an adapter for *tgbotapi.BotAPI.
func NewTelegramBot ¶
func NewTelegramBot(b *tgbotapi.BotAPI) *TelegramBot
NewTelegramBot creates a new TelegramBot adapter.
func (*TelegramBot) GetSelf ¶
func (b *TelegramBot) GetSelf() tgbotapi.User
GetSelf returns the bot user.