handlers

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Entry = "Entry"
)

Variables

This section is empty.

Functions

func EndConversation

func EndConversation() error

EndConversation ends the current conversation.

Types

type Conversation

type Conversation struct {
	ServiceName string
	// EntryHandler is the handler to start the conversation.
	EntryHandler tele.IHandler
	// SubHandlers is the map of possible states, with a list of possible handlers for each one.
	SubHandlers map[string][]tele.IHandler

	ExitName string
	// The following are all optional fields:
	// ExitHandler is the handler to exit the current conversation partway (eg /cancel commands)
	ExitHandler tele.IHandler
	// 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(entryName string, entryPoint tele.IHandler, subHandlers map[string][]tele.IHandler, opts *ConversationOpts) Conversation

func (Conversation) CheckUpdate

func (c Conversation) CheckUpdate(ctx tele.Context) bool

func (Conversation) HandleUpdate

func (c Conversation) HandleUpdate(ctx tele.Context) error

func (Conversation) Name

func (c Conversation) Name() string

type ConversationOpts

type ConversationOpts struct {
	ExitName string
	// ExitHandler is the list of handlers to exit the current conversation partway (eg /cancel commands). This returns
	// EndConversation() by default, unless otherwise specified.
	ExitHandler tele.IHandler
	// If True, a user can restart the conversation at any time by hitting one of the entry points again.
	AllowReEntry bool
}

type StateChange added in v0.1.16

type StateChange struct {
	// The next state to handle in the current conversation.
	NextState *string
	// End the current conversation
	End bool
}

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

func NextConversationState

func NextConversationState(nextState string) *StateChange

NextConversationState moves to the defined state in the current conversation.

func (*StateChange) Error added in v0.1.16

func (s *StateChange) Error() string

Jump to

Keyboard shortcuts

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