handlers

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 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 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

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 // should be lowercase for case-insensitivity
	Response     Response
}

func NewCommand

func NewCommand(c string, r Response) Command

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

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
}

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 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
}

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

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 Response

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

Jump to

Keyboard shortcuts

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