Documentation ¶
Index ¶
- type Bot
- func (b *Bot) Client() *tgbotapi.BotAPI
- func (b *Bot) Off(updateType UpdateType, handler *UpdateHandler)
- func (b *Bot) On(updateType UpdateType, handler UpdateCallback, filters ...UpdateFilter) *UpdateHandler
- func (b *Bot) Start(ctx context.Context, offset int)
- func (b *Bot) Use(handler UpdateCallback)
- func (b *Bot) Wait()
- type ChatType
- type UpdateCallback
- type UpdateContext
- type UpdateFilter
- type UpdateHandler
- type UpdateType
- type WrappedUpdate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot is a Telegram bot using go-telegram-bot-api and long polling.
func (*Bot) Off ¶
func (b *Bot) Off(updateType UpdateType, handler *UpdateHandler)
Off unregisters a handler for a specific update type.
func (*Bot) On ¶
func (b *Bot) On(updateType UpdateType, handler UpdateCallback, filters ...UpdateFilter) *UpdateHandler
On registers a handler for a specific update type.
type UpdateCallback ¶
type UpdateCallback func(ctx UpdateContext) error
UpdateCallback is a function that handles an update.
type UpdateContext ¶
type UpdateContext struct { *WrappedUpdate // contains filtered or unexported fields }
func NewUpdateContext ¶
func NewUpdateContext(bot *Bot, update *WrappedUpdate, ctx context.Context) UpdateContext
NewUpdateContext creates a new update context.
func (UpdateContext) Client ¶
func (ctx UpdateContext) Client() *tgbotapi.BotAPI
Client returns the Telegram client.
func (UpdateContext) Context ¶
func (ctx UpdateContext) Context() context.Context
Context returns the context of the update.
func (UpdateContext) StopPropagation ¶
func (ctx UpdateContext) StopPropagation()
StopPropagation stops the propagation of the update to the next handlers.
type UpdateFilter ¶
type UpdateFilter func(update *WrappedUpdate) (bool, error)
func AnyFilter ¶
func AnyFilter(filters ...UpdateFilter) UpdateFilter
AnyFilter combines multiple filters into one, which returns true if any of the filters return true.
func FilterByChatType ¶
func FilterByChatType(t ChatType) UpdateFilter
FilterByChatType returns a filter that filters updates by chat type.
func FilterByCommand ¶
func FilterByCommand(command string) UpdateFilter
FilterByCommand returns a filter that filters updates by command.
type UpdateHandler ¶
type UpdateHandler struct { ID uuid.UUID Callback UpdateCallback Filters []UpdateFilter }
func NewUpdateHandler ¶
func NewUpdateHandler(handler UpdateCallback, filters ...UpdateFilter) *UpdateHandler
func (*UpdateHandler) ApplyFilters ¶
func (h *UpdateHandler) ApplyFilters(update *WrappedUpdate) (bool, error)
ApplyFilters applies all filters to the update.
type UpdateType ¶
type UpdateType int
const ( UpdateTypeMessage UpdateType = iota UpdateTypeEditedMessage UpdateTypeChannelPost UpdateTypeEditedChannelPost UpdateTypeInlineQuery UpdateTypeChosenInlineResult UpdateTypeCallbackQuery UpdateTypeShippingQuery UpdateTypePreCheckoutQuery UpdateTypePoll UpdateTypePollAnswer UpdateTypeMyChatMember UpdateTypeChatMember UpdateTypeChatJoinRequest )
func (UpdateType) String ¶
func (u UpdateType) String() string
String returns the string representation of the update type.
type WrappedUpdate ¶
type WrappedUpdate struct { // Update is the original update. tgbotapi.Update // Type is the type of the update. Type UpdateType }
func NewWrappedUpdate ¶
func NewWrappedUpdate(update tgbotapi.Update) (wrappedUpdate *WrappedUpdate)
NewWrappedUpdate creates a new wrapped update.
func (*WrappedUpdate) String ¶
func (w *WrappedUpdate) String() string
String returns the string representation of the wrapped update.