telegram

package
v0.93.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package telegram implements the Telegram Bot channel.

Package telegram provides webhook handling for Telegram Bot.

Index

Constants

View Source
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

func ExtractChatID(update *tgbotapi.Update) string

ExtractChatID extracts the chat ID from a Telegram update.

func ExtractUserID

func ExtractUserID(update *tgbotapi.Update) string

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

func (t *TelegramChannel) DownloadMedia(ctx context.Context, fileID string) ([]byte, string, error)

DownloadMedia downloads a file from Telegram.

func (*TelegramChannel) Name

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

Jump to

Keyboard shortcuts

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