Documentation
¶
Index ¶
- Variables
- type Application
- func (app *Application) AddHandler(handler Handler)
- func (app *Application) Bot() *tg.Bot
- func (app *Application) ProcessUpdate(ctx context.Context, update *Update) error
- func (app *Application) RunPolling(ctx context.Context, opts ...PollingOption) error
- func (app *Application) SetErrorHandler(handler ErrorHandler)
- func (app *Application) WebhookHandler(secretToken string) http.Handler
- type Context
- type ErrorHandler
- type Filter
- type FilterFunc
- type Handler
- func NewAnyHandler(fn HandlerFunc) Handler
- func NewCallbackQueryHandler(pattern *regexp.Regexp, fn HandlerFunc) Handler
- func NewCommandHandler(command string, fn HandlerFunc) Handler
- func NewMessageHandler(filter Filter, fn HandlerFunc) Handler
- func NewTypeHandler(updateType UpdateType, fn HandlerFunc) Handler
- type HandlerFunc
- type Option
- type PollingOption
- type Update
- type UpdateType
Constants ¶
This section is empty.
Variables ¶
var AllUpdateTypes = []UpdateType{ UpdateTypeMessage, UpdateTypeEditedMessage, UpdateTypeChannelPost, UpdateTypeEditedChannelPost, UpdateTypeBusinessConnection, UpdateTypeBusinessMessage, UpdateTypeEditedBusinessMessage, UpdateTypeDeletedBusinessMessages, UpdateTypeMessageReaction, UpdateTypeMessageReactionCount, UpdateTypeInlineQuery, UpdateTypeChosenInlineResult, UpdateTypeCallbackQuery, UpdateTypeShippingQuery, UpdateTypePreCheckoutQuery, UpdateTypePurchasedPaidMedia, UpdateTypePoll, UpdateTypePollAnswer, UpdateTypeMyChatMember, UpdateTypeChatMember, UpdateTypeChatJoinRequest, UpdateTypeChatBoost, UpdateTypeRemovedChatBoost, }
AllUpdateTypes lists every currently supported Telegram update type.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application provides PTB-like update routing on top of tg.Bot.
func NewApplication ¶
func NewApplication(bot *tg.Bot, opts ...Option) (*Application, error)
NewApplication creates an update dispatcher bound to a bot instance.
func (*Application) AddHandler ¶
func (app *Application) AddHandler(handler Handler)
AddHandler appends a handler to the routing chain.
func (*Application) ProcessUpdate ¶
func (app *Application) ProcessUpdate(ctx context.Context, update *Update) error
ProcessUpdate routes an update through all matching handlers.
func (*Application) RunPolling ¶
func (app *Application) RunPolling(ctx context.Context, opts ...PollingOption) error
RunPolling starts long polling in the background and routes updates through the application.
func (*Application) SetErrorHandler ¶
func (app *Application) SetErrorHandler(handler ErrorHandler)
SetErrorHandler updates the global handler error callback.
func (*Application) WebhookHandler ¶
func (app *Application) WebhookHandler(secretToken string) http.Handler
WebhookHandler returns an http.Handler for Telegram webhook callbacks. If secretToken is non-empty, requests must pass X-Telegram-Bot-Api-Secret-Token.
type Context ¶
Context holds routing state for handlers.
func (*Context) EffectiveMessage ¶
EffectiveMessage returns the first message-like payload.
func (*Context) UpdateType ¶
func (ctx *Context) UpdateType() UpdateType
UpdateType returns the concrete update type.
type ErrorHandler ¶
ErrorHandler handles errors produced by routed handlers.
type Filter ¶
Filter decides whether a message-like update should be handled.
func CommandFilter ¶
func CommandFilter() Filter
CommandFilter matches updates whose effective message contains a command.
func RegexFilter ¶
RegexFilter matches updates whose effective message text matches the regexp.
func TextFilter ¶
func TextFilter() Filter
TextFilter matches updates whose effective message has non-empty text.
func UpdateTypeFilter ¶
func UpdateTypeFilter(updateTypes ...UpdateType) Filter
UpdateTypeFilter matches the provided update types.
type FilterFunc ¶
FilterFunc is an adapter for inline filter callbacks.
type Handler ¶
Handler is the routing contract used by Application.
func NewAnyHandler ¶
func NewAnyHandler(fn HandlerFunc) Handler
NewAnyHandler registers a handler that receives all updates.
func NewCallbackQueryHandler ¶
func NewCallbackQueryHandler(pattern *regexp.Regexp, fn HandlerFunc) Handler
NewCallbackQueryHandler registers a callback query handler. If pattern is nil, every callback query will match.
func NewCommandHandler ¶
func NewCommandHandler(command string, fn HandlerFunc) Handler
NewCommandHandler registers a handler for a specific command name.
func NewMessageHandler ¶
func NewMessageHandler(filter Filter, fn HandlerFunc) Handler
NewMessageHandler registers a handler for message-like updates.
func NewTypeHandler ¶
func NewTypeHandler(updateType UpdateType, fn HandlerFunc) Handler
NewTypeHandler registers a handler for a specific update type.
type HandlerFunc ¶
HandlerFunc is an adapter for handler callbacks.
type Option ¶
type Option func(*Application)
Option configures Application.
func WithContinueOnError ¶
WithContinueOnError controls whether dispatcher continues after a handler error.
func WithErrorHandler ¶
func WithErrorHandler(handler ErrorHandler) Option
WithErrorHandler sets a global error callback.
func WithWebhookBodyLimit ¶
WithWebhookBodyLimit overrides max webhook body size.
type PollingOption ¶
type PollingOption = tg.UpdatePollerOption
PollingOption configures Application.RunPolling.
func WithPollingAllowedUpdates ¶
func WithPollingAllowedUpdates(updateTypes ...UpdateType) PollingOption
WithPollingAllowedUpdates converts ext update types into poller allowed_updates values.
func WithPollingNonBlockingDispatch ¶
func WithPollingNonBlockingDispatch() PollingOption
WithPollingNonBlockingDispatch enables non-blocking dispatch for Application.RunPolling.
type Update ¶
type Update struct {
UpdateID int64 `json:"update_id"`
Message *tg.Message `json:"message,omitempty"`
EditedMessage *tg.Message `json:"edited_message,omitempty"`
ChannelPost *tg.Message `json:"channel_post,omitempty"`
EditedChannelPost *tg.Message `json:"edited_channel_post,omitempty"`
BusinessConnection *tg.BusinessConnection `json:"business_connection,omitempty"`
BusinessMessage *tg.Message `json:"business_message,omitempty"`
EditedBusinessMessage *tg.Message `json:"edited_business_message,omitempty"`
DeletedBusinessMessages *tg.BusinessMessagesDeleted `json:"deleted_business_messages,omitempty"`
MessageReaction *tg.MessageReactionUpdated `json:"message_reaction,omitempty"`
MessageReactionCount *tg.MessageReactionCountUpdated `json:"message_reaction_count,omitempty"`
InlineQuery *tg.InlineQuery `json:"inline_query,omitempty"`
ChosenInlineResult *tg.ChosenInlineResult `json:"chosen_inline_result,omitempty"`
CallbackQuery *tg.CallbackQuery `json:"callback_query,omitempty"`
ShippingQuery *tg.ShippingQuery `json:"shipping_query,omitempty"`
PreCheckoutQuery *tg.PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
PurchasedPaidMedia *tg.PaidMediaPurchased `json:"purchased_paid_media,omitempty"`
Poll *tg.Poll `json:"poll,omitempty"`
PollAnswer *tg.PollAnswer `json:"poll_answer,omitempty"`
MyChatMember *tg.ChatMemberUpdated `json:"my_chat_member,omitempty"`
ChatMember *tg.ChatMemberUpdated `json:"chat_member,omitempty"`
ChatJoinRequest *tg.ChatJoinRequest `json:"chat_join_request,omitempty"`
ChatBoost *tg.ChatBoostUpdated `json:"chat_boost,omitempty"`
RemovedChatBoost *tg.ChatBoostRemoved `json:"removed_chat_boost,omitempty"`
}
Update is the complete Telegram update envelope used by the application layer.
func DecodeUpdate ¶
DecodeUpdate parses a Telegram update payload.
func DecodeUpdateFromReader ¶
DecodeUpdateFromReader parses a Telegram update payload from a reader.
func WrapUpdate ¶
WrapUpdate converts a root tgbot.Update into an ext.Update.
func (*Update) EffectiveMessage ¶
EffectiveMessage returns the first message-like payload for routing helpers.
func (*Update) Type ¶
func (update *Update) Type() UpdateType
Type returns the concrete type of the update.
type UpdateType ¶
type UpdateType string
UpdateType is Telegram update discriminator used by the application dispatcher.
const ( UpdateTypeUnknown UpdateType = "" UpdateTypeMessage UpdateType = "message" UpdateTypeEditedMessage UpdateType = "edited_message" UpdateTypeChannelPost UpdateType = "channel_post" UpdateTypeEditedChannelPost UpdateType = "edited_channel_post" UpdateTypeBusinessConnection UpdateType = "business_connection" UpdateTypeBusinessMessage UpdateType = "business_message" UpdateTypeEditedBusinessMessage UpdateType = "edited_business_message" UpdateTypeDeletedBusinessMessages UpdateType = "deleted_business_messages" UpdateTypeMessageReaction UpdateType = "message_reaction" UpdateTypeMessageReactionCount UpdateType = "message_reaction_count" UpdateTypeInlineQuery UpdateType = "inline_query" UpdateTypeChosenInlineResult UpdateType = "chosen_inline_result" UpdateTypeCallbackQuery UpdateType = "callback_query" UpdateTypeShippingQuery UpdateType = "shipping_query" UpdateTypePreCheckoutQuery UpdateType = "pre_checkout_query" UpdateTypePurchasedPaidMedia UpdateType = "purchased_paid_media" UpdateTypePoll UpdateType = "poll" UpdateTypePollAnswer UpdateType = "poll_answer" UpdateTypeMyChatMember UpdateType = "my_chat_member" UpdateTypeChatMember UpdateType = "chat_member" UpdateTypeChatJoinRequest UpdateType = "chat_join_request" UpdateTypeChatBoost UpdateType = "chat_boost" UpdateTypeRemovedChatBoost UpdateType = "removed_chat_boost" )