dispatcher

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyTechnicalMessageFunc added in v0.18.0

func EmptyTechnicalMessageFunc(chatID int64, messageID MessageIDType) string

EmptyTechnicalMessageFunc returns empty string for all messages

Types

type Config

type Config struct {
	MaxOpenConversations         int                       // the maximum number of open conversations
	SingleMessageTrySendInterval int                       // interval between several tries of send single message to a user
	ConversationConfig           conversation.Config       // configuration for a conversation
	Handlers                     *handlers.CommandHandlers // list of handlers for command handling
	GlobalHandlers               []handlers.CommandHandler // list of handlers that can be started at any point of conversation
	TechnicalMessageFunc         TechnicalMessageFuncType  // Function that provides global messages that should be send to a user in special cases
	GloabalKeyboardFunc          GlobalKeyboardFuncType    // Function that provides global keyboard that would be attached to each global message
}

Config contains configuration parameters for a new dispatcher

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher is an object that manages conversations and routers input messsages to needed conversations

func NewDispatcher

func NewDispatcher(ctx context.Context, config Config, bot *tgbotapi.BotAPI, stateIO state.StateIO) (*Dispatcher, error)

NewDispatcher creates a new Dispatcher objects and starts a separate thread to clear old conversations

func (*Dispatcher) DispatchUpdate

func (d *Dispatcher) DispatchUpdate(update *tgbotapi.Update)

DispatchUpdate routes an update to the target conversation, or creates a new conversation

func (*Dispatcher) SendSingleMessage

func (d *Dispatcher) SendSingleMessage(ctx context.Context, chatID int64, text string, keyboard *buttons.ButtonSet) error

SendSingleMessage waits until the conversation with chatID is closed and sends a single message from bot to a user

func (*Dispatcher) SendSingleMessageWithMarkup added in v1.21.1

func (d *Dispatcher) SendSingleMessageWithMarkup(ctx context.Context, chatID int64, text string, keyboard *buttons.ButtonSet) error

SendSingleMessageWithMarkup waits until the conversation with chatID is closed and sends a single message with HTML markup from bot to a user

func (*Dispatcher) SendSinglePhoto added in v1.20.0

func (d *Dispatcher) SendSinglePhoto(ctx context.Context, chatID int64, photo []byte, caption string, keyboard *buttons.ButtonSet) error

type GlobalKeyboardFuncType added in v0.16.0

type GlobalKeyboardFuncType func(chatID int64) GlobalKeyboardType

GlobalKeyboardFuncType is a type for function that generates a global keyboard for a specific chat

type GlobalKeyboardType added in v0.16.0

type GlobalKeyboardType interface{}

GlobalKeyboardType is a alias for interface{}

func NewGlobalKeyboard added in v0.16.0

func NewGlobalKeyboard(resize bool, buttonText [][]string) GlobalKeyboardType

NewGlobalKeyboard generates a Global Keyboard from a two dimentional array of strings

func RemoveKeyboard added in v0.16.0

func RemoveKeyboard() GlobalKeyboardType

RemoveKeyboard is a Global Keyboard function that removes an permanent keyboard

func SingleColumnGlobalKeyboard added in v0.16.0

func SingleColumnGlobalKeyboard(resize bool, columnText ...string) GlobalKeyboardType

SingleColumnGlobalKeyboard generates a single-column Global Keyboard from slice of strings

func SingleRowGlobalKeyboard added in v0.16.0

func SingleRowGlobalKeyboard(resize bool, rowText ...string) GlobalKeyboardType

SingleRowGlobalKeyboard generates a single-row Global Keyboard from slice of strings

type MessageIDType added in v0.16.0

type MessageIDType int

MessageIDType is an enum type for global message ID

const (
	TooManyMessages          MessageIDType = iota // a message to send to user in case if there are to many unprocessed messages from them
	TooManyConversations                          // a message to send to user in case if there are to many open conversations
	UserError                                     // a message to send to user in case of an error in a handler
	ConversationClosedByBot                       // a message to send to user if a conversation was cancelled by the bot
	ConversationClosedByUser                      // a message to send to user if them switched to another global command
	ConversationEnded                             // a message to send to user after conversation was ended successfully
)

type TechnicalMessageFuncType added in v0.18.0

type TechnicalMessageFuncType func(chatID int64, messageID MessageIDType) string

TechnicalMessageFuncType type of a function that should return technical messages for a dedicated user

Jump to

Keyboard shortcuts

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