Documentation
¶
Overview ¶
Package telegram implements the Telegram Bot channel.
Package telegram provides webhook handling for Telegram Bot.
Index ¶
- Constants
- func ExtractChatID(update *tgbotapi.Update) string
- func ExtractUserID(update *tgbotapi.Update) string
- type TelegramChannel
- func (t *TelegramChannel) Close() error
- func (t *TelegramChannel) DownloadMedia(ctx context.Context, fileID string) ([]byte, string, error)
- func (t *TelegramChannel) Name() chat_apps.Platform
- func (t *TelegramChannel) ParseMessage(ctx context.Context, payload []byte) (*chat_apps.IncomingMessage, error)
- func (t *TelegramChannel) SendChunkedMessage(ctx context.Context, chatID string, chunks <-chan string) error
- func (t *TelegramChannel) SendMessage(ctx context.Context, msg *chat_apps.OutgoingMessage) error
- func (t *TelegramChannel) ValidateWebhook(ctx context.Context, headers map[string]string, body []byte) error
- type TelegramConfig
- type WebhookHandler
- func (h *WebhookHandler) DeleteWebhook(ctx context.Context) error
- func (h *WebhookHandler) GetWebhookInfo(ctx context.Context) (tgbotapi.WebhookInfo, error)
- func (h *WebhookHandler) HandleWebhook(ctx context.Context, r *http.Request) (*chat_apps.IncomingMessage, error)
- func (h *WebhookHandler) SetWebhook(ctx context.Context, webhookURL string, dropPendingUpdates bool) error
- func (h *WebhookHandler) VerifyRequest(r *http.Request) bool
Constants ¶
const ( MaxPhotoSizeMB = 20 // Telegram photo size limit MaxDocumentSizeMB = 50 // Telegram document size limit MaxAudioSizeMB = 50 // Telegram audio file size limit DefaultParseMode = "Markdown" )
Variables ¶
This section is empty.
Functions ¶
func ExtractChatID ¶
ExtractChatID extracts the chat ID from a Telegram update.
func ExtractUserID ¶
ExtractUserID extracts the user ID from a Telegram update.
Types ¶
type TelegramChannel ¶
type TelegramChannel struct {
// contains filtered or unexported fields
}
TelegramChannel implements ChatChannel for Telegram Bot API.
func NewTelegramChannel ¶
func NewTelegramChannel(config *TelegramConfig) (*TelegramChannel, error)
NewTelegramChannel creates a new Telegram channel.
func (*TelegramChannel) Close ¶
func (t *TelegramChannel) Close() error
Close closes the Telegram channel.
func (*TelegramChannel) DownloadMedia ¶
DownloadMedia downloads a file from Telegram.
func (*TelegramChannel) Name ¶
func (t *TelegramChannel) Name() chat_apps.Platform
Name returns the platform name.
func (*TelegramChannel) ParseMessage ¶
func (t *TelegramChannel) ParseMessage(ctx context.Context, payload []byte) (*chat_apps.IncomingMessage, error)
ParseMessage parses the incoming webhook payload into an IncomingMessage.
func (*TelegramChannel) SendChunkedMessage ¶
func (t *TelegramChannel) SendChunkedMessage(ctx context.Context, chatID string, chunks <-chan string) error
SendChunkedMessage sends streaming content chunks.
func (*TelegramChannel) SendMessage ¶
func (t *TelegramChannel) SendMessage(ctx context.Context, msg *chat_apps.OutgoingMessage) error
SendMessage sends a message to Telegram.
func (*TelegramChannel) ValidateWebhook ¶
func (t *TelegramChannel) ValidateWebhook(ctx context.Context, headers map[string]string, body []byte) error
ValidateWebhook verifies the incoming webhook request.
type TelegramConfig ¶
type TelegramConfig struct {
BotToken string
}
TelegramConfig holds configuration for the Telegram channel.
type WebhookHandler ¶
type WebhookHandler struct {
// contains filtered or unexported fields
}
WebhookHandler handles incoming Telegram webhooks.
func NewWebhookHandler ¶
func NewWebhookHandler(channel *TelegramChannel) *WebhookHandler
NewWebhookHandler creates a new webhook handler.
func (*WebhookHandler) DeleteWebhook ¶
func (h *WebhookHandler) DeleteWebhook(ctx context.Context) error
DeleteWebhook removes the webhook for the Telegram bot.
func (*WebhookHandler) GetWebhookInfo ¶
func (h *WebhookHandler) GetWebhookInfo(ctx context.Context) (tgbotapi.WebhookInfo, error)
GetWebhookInfo returns information about the current webhook.
func (*WebhookHandler) HandleWebhook ¶
func (h *WebhookHandler) HandleWebhook(ctx context.Context, r *http.Request) (*chat_apps.IncomingMessage, error)
HandleWebhook handles an incoming webhook request from Telegram.
func (*WebhookHandler) SetWebhook ¶
func (h *WebhookHandler) SetWebhook(ctx context.Context, webhookURL string, dropPendingUpdates bool) error
SetWebhook sets the webhook for the Telegram bot.
func (*WebhookHandler) VerifyRequest ¶
func (h *WebhookHandler) VerifyRequest(r *http.Request) bool
VerifyRequest verifies that the request came from Telegram. Telegram Bot API doesn't sign webhooks, so we validate: 1. HTTP method is POST 2. Content-Type is JSON or empty (Telegram sometimes doesn't send it) 3. The request contains a valid update structure