handlers

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndConversation

func EndConversation() error

EndConversation ends the current conversation.

func EndConversationToParentState

func EndConversationToParentState(parentState *ConversationStateChange) error

EndConversationToParentState ends the current conversation and moves the parent conversation to the new state.

func NextConversationStateAndParentState

func NextConversationStateAndParentState(nextState string, parentState *ConversationStateChange) error

NextConversationStateAndParentState moves both the current conversation state and the parent conversation state. Can be helpful in the case of certain circular conversations.

func NextParentConversationState

func NextParentConversationState(parentState *ConversationStateChange) error

NextParentConversationState moves to the defined state in the parent conversation, without changing the state of the current one.

Types

type BusinessConnection added in v2.1.0

type BusinessConnection struct {
	Filter   filters.BusinessConnection
	Response Response
}

func (BusinessConnection) CheckUpdate added in v2.1.0

func (bc BusinessConnection) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (BusinessConnection) HandleUpdate added in v2.1.0

func (bc BusinessConnection) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (BusinessConnection) Name added in v2.1.0

func (bc BusinessConnection) Name() string

type CallbackQuery

type CallbackQuery struct {
	AllowChannel bool
	Filter       filters.CallbackQuery
	Response     Response
}

func NewCallback

func NewCallback(filter filters.CallbackQuery, r Response) CallbackQuery

func (CallbackQuery) CheckUpdate

func (cb CallbackQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (CallbackQuery) HandleUpdate

func (cb CallbackQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (CallbackQuery) Name

func (cb CallbackQuery) Name() string

func (CallbackQuery) SetAllowChannel added in v2.1.0

func (cb CallbackQuery) SetAllowChannel(allow bool) CallbackQuery

SetAllowChannel Enables channel messages for this handler.

type ChatJoinRequest

type ChatJoinRequest struct {
	Filter   filters.ChatJoinRequest
	Response Response
}

func (ChatJoinRequest) CheckUpdate

func (r ChatJoinRequest) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (ChatJoinRequest) HandleUpdate

func (r ChatJoinRequest) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (ChatJoinRequest) Name

func (r ChatJoinRequest) Name() string

type ChatMember

type ChatMember struct {
	Response Response
	Filter   filters.ChatMember
}

func NewChatMember

func NewChatMember(f filters.ChatMember, r Response) ChatMember

func (ChatMember) CheckUpdate

func (c ChatMember) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (ChatMember) HandleUpdate

func (c ChatMember) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (ChatMember) Name

func (c ChatMember) Name() string

type ChosenInlineResult

type ChosenInlineResult struct {
	Filter   filters.ChosenInlineResult
	Response Response
}

func NewChosenInlineResult

func NewChosenInlineResult(filter filters.ChosenInlineResult, r Response) ChosenInlineResult

func (ChosenInlineResult) CheckUpdate

func (i ChosenInlineResult) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (ChosenInlineResult) HandleUpdate

func (i ChosenInlineResult) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (ChosenInlineResult) Name

func (i ChosenInlineResult) Name() string

type Command

type Command struct {
	Triggers     []rune
	AllowEdited  bool
	AllowChannel bool
	Command      string // set to a lowercase value for case-insensitivity
	Response     Response
}

Command is the go-to handler for setting up Commands in your bot. By default, it will use telegram-native commands that start with a forward-slash (/), but it can be customised to react to any message starting with a character.

For example, a command handler on "help" with the triggers []rune("/!,") would trigger for "/help", "!help", or ",help".

func NewCommand

func NewCommand(c string, r Response) Command

NewCommand creates a new case-insensitive command. By default, commands do not work on edited messages, or channel posts. These can be enabled by setting the AllowEdited and AllowChannel fields respectively.

func (Command) CheckUpdate

func (c Command) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (Command) HandleUpdate

func (c Command) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (Command) Name

func (c Command) Name() string

func (Command) SetAllowChannel added in v2.1.0

func (c Command) SetAllowChannel(allow bool) Command

SetAllowChannel Enables channel messages for this handler.

func (Command) SetAllowEdited added in v2.1.0

func (c Command) SetAllowEdited(allow bool) Command

SetAllowEdited Enables edited messages for this handler.

func (Command) SetTriggers added in v2.1.0

func (c Command) SetTriggers(triggers []rune) Command

SetTriggers sets the list of triggers to be used with this command.

type Conversation

type Conversation struct {
	// EntryPoints is the list of handlers to start the conversation.
	EntryPoints []ext.Handler
	// States is the map of possible states, with a list of possible handlers for each one.
	States map[string][]ext.Handler
	// StateStorage is responsible for storing all running conversations.
	StateStorage conversation.Storage

	// The following are all optional fields:
	// Exits is the list of handlers to exit the current conversation partway (eg /cancel commands)
	Exits []ext.Handler
	// Fallbacks is the list of handlers to handle updates which haven't been matched by any states.
	Fallbacks []ext.Handler
	// If True, a user can restart the conversation by hitting one of the entry points.
	AllowReEntry bool
	// Filter allows users to set a conversation-wide filter to any incoming updates. This can be useful to only target
	// one specific chat, or to avoid unwanted updates which may interfere with the conversation key strategy
	// (eg polls).
	Filter ConversationFilter
}

The Conversation handler is an advanced handler which allows for running a sequence of commands in a stateful manner. An example of this flow can be found at t.me/Botfather; upon receiving the "/newbot" command, the user is asked for the name of their bot, which is sent as a separate message.

The bot's internal state allows it to check at which point of the conversation the user is, and decide how to handle the next update.

func NewConversation

func NewConversation(entryPoints []ext.Handler, states map[string][]ext.Handler, opts *ConversationOpts) Conversation

func (Conversation) CheckUpdate

func (c Conversation) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (Conversation) HandleUpdate

func (c Conversation) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (Conversation) Name

func (c Conversation) Name() string

type ConversationFilter added in v2.1.0

type ConversationFilter func(ctx *ext.Context) bool

ConversationFilter is much wider than regular filters, because it allows for any kind of update; we may want messages, commands, callbacks, etc.

type ConversationOpts

type ConversationOpts struct {
	// Exits is the list of handlers to exit the current conversation partway (eg /cancel commands). This returns
	// EndConversation() by default, unless otherwise specified.
	Exits []ext.Handler
	// Fallbacks is the list of handlers to handle updates which haven't been matched by any other handlers.
	Fallbacks []ext.Handler
	// If True, a user can restart the conversation at any time by hitting one of the entry points again.
	AllowReEntry bool
	// StateStorage is responsible for storing all running conversations.
	StateStorage conversation.Storage
	// Filter allows users to set a conversation-wide filter to any incoming updates. This can be useful to only target
	// one specific chat, or to avoid unwanted updates which may interfere with the conversation key strategy
	// (eg polls).
	Filter ConversationFilter
}

type ConversationStateChange

type ConversationStateChange struct {
	// The next state to handle in the current conversation.
	NextState *string
	// End the current conversation
	End bool
	// Move the parent conversation (if any) to the desired state.
	ParentState *ConversationStateChange
}

ConversationStateChange handles all the possible states that can be returned from a conversation.

func NextConversationState

func NextConversationState(nextState string) *ConversationStateChange

NextConversationState moves to the defined state in the current conversation.

func (*ConversationStateChange) Error

func (s *ConversationStateChange) Error() string

type InlineQuery

type InlineQuery struct {
	Filter   filters.InlineQuery
	Response Response
}

func NewInlineQuery

func NewInlineQuery(f filters.InlineQuery, r Response) InlineQuery

func (InlineQuery) CheckUpdate

func (i InlineQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (InlineQuery) HandleUpdate

func (i InlineQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (InlineQuery) Name

func (i InlineQuery) Name() string

type Message

type Message struct {
	AllowEdited   bool
	AllowChannel  bool
	AllowBusiness bool
	Filter        filters.Message
	Response      Response
}

func NewMessage

func NewMessage(f filters.Message, r Response) Message

func (Message) CheckUpdate

func (m Message) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (Message) HandleUpdate

func (m Message) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (Message) Name

func (m Message) Name() string

func (Message) SetAllowBusiness added in v2.1.0

func (m Message) SetAllowBusiness(allow bool) Message

SetAllowBusiness Enables business messages for this handler.

func (Message) SetAllowChannel added in v2.1.0

func (m Message) SetAllowChannel(allow bool) Message

SetAllowChannel Enables channel messages for this handler.

func (Message) SetAllowEdited added in v2.1.0

func (m Message) SetAllowEdited(allow bool) Message

SetAllowEdited Enables edited messages for this handler.

type MyChatMember

type MyChatMember struct {
	Response Response
	Filter   filters.ChatMember
}

func NewMyChatMember

func NewMyChatMember(f filters.ChatMember, r Response) MyChatMember

func (MyChatMember) CheckUpdate

func (m MyChatMember) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (MyChatMember) HandleUpdate

func (m MyChatMember) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (MyChatMember) Name

func (m MyChatMember) Name() string

type Named

type Named struct {
	// Custom name to identify handler by
	CustomName string
	// Inlined version of parent handler to inherit methods.
	ext.Handler
}

func NewNamedhandler

func NewNamedhandler(name string, handler ext.Handler) Named

func (Named) Name

func (n Named) Name() string

type Poll

type Poll struct {
	Filter   filters.Poll
	Response Response
}

func NewPoll

func NewPoll(f filters.Poll, r Response) Poll

func (Poll) CheckUpdate

func (r Poll) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (Poll) HandleUpdate

func (r Poll) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (Poll) Name

func (r Poll) Name() string

type PollAnswer

type PollAnswer struct {
	Filter   filters.PollAnswer
	Response Response
}

func NewPollAnswer

func NewPollAnswer(f filters.PollAnswer, r Response) PollAnswer

func (PollAnswer) CheckUpdate

func (r PollAnswer) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (PollAnswer) HandleUpdate

func (r PollAnswer) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (PollAnswer) Name

func (r PollAnswer) Name() string

type PreCheckoutQuery added in v2.1.0

type PreCheckoutQuery struct {
	Filter   filters.PreCheckoutQuery
	Response Response
}

func NewPreCheckoutQuery added in v2.1.0

func NewPreCheckoutQuery(f filters.PreCheckoutQuery, r Response) PreCheckoutQuery

func (PreCheckoutQuery) CheckUpdate added in v2.1.0

func (r PreCheckoutQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (PreCheckoutQuery) HandleUpdate added in v2.1.0

func (r PreCheckoutQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (PreCheckoutQuery) Name added in v2.1.0

func (r PreCheckoutQuery) Name() string

type Reaction added in v2.1.0

type Reaction struct {
	Filter   filters.Reaction
	Response Response
}

func NewReaction added in v2.1.0

func NewReaction(f filters.Reaction, r Response) Reaction

func (Reaction) CheckUpdate added in v2.1.0

func (r Reaction) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (Reaction) HandleUpdate added in v2.1.0

func (r Reaction) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (Reaction) Name added in v2.1.0

func (r Reaction) Name() string

type Response

type Response func(b *gotgbot.Bot, ctx *ext.Context) error

type ShippingQuery added in v2.1.0

type ShippingQuery struct {
	Filter   filters.ShippingQuery
	Response Response
}

func NewShippingQuery added in v2.1.0

func NewShippingQuery(f filters.ShippingQuery, r Response) ShippingQuery

func (ShippingQuery) CheckUpdate added in v2.1.0

func (r ShippingQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool

func (ShippingQuery) HandleUpdate added in v2.1.0

func (r ShippingQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error

func (ShippingQuery) Name added in v2.1.0

func (r ShippingQuery) Name() string

Jump to

Keyboard shortcuts

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