Documentation
¶
Index ¶
- Variables
- func NewSession[T any](userId UserId, chatId ChatId, appState T, bot *Bot[T], botCtx context.Context, ...) *session[T]
- func RunTemplate(tpl string, values ...KeyValue) (string, error)
- func RunTemplateMap(tpl string, valueMap map[string]any) (string, error)
- type AppStateManager
- type Bot
- type Button
- type ButtonRow
- type CallbackQuery
- type ChatId
- type ChatMessage
- type CommandHandler
- type Config
- type DynamicKeyboard
- type FuncCommandHandler
- type GlobalMessageHandler
- type HandlerMap
- type InlineButton
- type InlineButtonAction
- type InlineKeyboard
- type InlineMessageHandler
- type InlineRow
- type KeyValue
- type KeyValues
- type Keyboard
- type Message
- type MessageId
- type MockBot
- type PromptOption
- type SendMessageOption
- type Session
- type State
- func NewMessageHandler[T any](handleQuery InlineMessageHandler[T]) State[T]
- func NewMultiMessageHandler[T any](handlers ...InlineMessageHandler[T]) State[T]
- func PromptState[T any](yesHandler func(), options ...PromptOption) State[T]
- func SelectState[O, T any](text string, items []O, accept func(bs Session[T], item O)) State[T]
- func SelectToDeleteUser[T any](uStorage UserManager, users []User) State[T]
- func UsersList[T any](uStorage UserManager) State[T]
- type StateBuilder
- func (sb *StateBuilder[T]) Build() State[T]
- func (sb *StateBuilder[T]) OnActivate(activator func(bs Session[T])) *StateBuilder[T]
- func (sb *StateBuilder[T]) OnBeforeLeave(handler func(bs Session[T])) *StateBuilder[T]
- func (sb *StateBuilder[T]) OnButton(button Button, handler func(bs Session[T], message ChatMessage)) *StateBuilder[T]
- func (sb *StateBuilder[T]) OnCallbackQuery(handler func(bs Session[T], query CallbackQuery) bool) *StateBuilder[T]
- func (sb *StateBuilder[T]) OnInlineButton(button InlineButton, handler func(bs Session[T], query CallbackQuery) bool) *StateBuilder[T]
- func (sb *StateBuilder[T]) OnMessage(handleMessage func(bs Session[T], message ChatMessage)) *StateBuilder[T]
- type StateFactory
- type StoredSessionState
- type TGApi
- type User
- type UserId
- type UserManager
Constants ¶
This section is empty.
Variables ¶
View Source
var ( CommandReload = tgbotapi.BotCommand{ Command: "reload", Description: "Reloads the current state", } CommandCancel = tgbotapi.BotCommand{ Command: "back", Description: "stop the current operation, go to the previous state", } CommandHelp = tgbotapi.BotCommand{ Command: "help", Description: "Show general help", } CommandMain = tgbotapi.BotCommand{ Command: "home", Description: "Go back to root state", } CommandUsers = tgbotapi.BotCommand{ Command: "users", Description: "Goes to the user management", } )
View Source
var NoButtons buttonKeyboard = nil
Functions ¶
func NewSession ¶
Types ¶
type AppStateManager ¶
type AppStateManager[T any] interface { CreateAppState(userId UserId, chatId ChatId) T StoreSessionState(state StoredSessionState[T]) error // rename to list sessions LoadSessionStates() ([]StoredSessionState[T], error) }
type Bot ¶
type Bot[T any] struct { // contains filtered or unexported fields }
func (*Bot[T]) AcceptUsers ¶
func (*Bot[T]) ForeachSessionAsync ¶
type CallbackQuery ¶
type ChatMessage ¶
type ChatMessage interface {
Text() string
}
type CommandHandler ¶
type Config ¶
type Config[T any] struct { // bot token Token string AppStateManager AppStateManager[T] RootState StateFactory[T] UserManager UserManager Connect func(token string) (TGApi, error) }
func NewConfig ¶
func NewConfig[T any](token string, appStateManager AppStateManager[T], userManager UserManager, rootState StateFactory[T]) *Config[T]
type DynamicKeyboard ¶
type DynamicKeyboard[T any] struct { // contains filtered or unexported fields }
func NewDynamicKeyboard ¶
func NewDynamicKeyboard[T any]() *DynamicKeyboard[T]
func (*DynamicKeyboard[T]) AddButton ¶
func (d *DynamicKeyboard[T]) AddButton(label string, handler func(bs Session[T]), startRowAfter int)
func (*DynamicKeyboard[T]) Handle ¶
func (d *DynamicKeyboard[T]) Handle(bs Session[T], button Button) bool
func (*DynamicKeyboard[T]) Reset ¶
func (d *DynamicKeyboard[T]) Reset()
func (*DynamicKeyboard[T]) Rows ¶
func (d *DynamicKeyboard[T]) Rows() []ButtonRow
type FuncCommandHandler ¶
type GlobalMessageHandler ¶
type HandlerMap ¶
type HandlerMap[T any] map[string]CommandHandler[T]
func (HandlerMap[T]) Handle ¶
func (hm HandlerMap[T]) Handle(bs Session[T], command string, args ...string) bool
func (HandlerMap[T]) Set ¶
func (hm HandlerMap[T]) Set(command string, sc CommandHandler[T])
type InlineButton ¶
func NewInlineButton ¶
func NewInlineButton(label, data string) InlineButton
func TernaryButton ¶
func TernaryButton(cond bool, trueButton, falseButton InlineButton) InlineButton
type InlineButtonAction ¶
func NewInlineButtonAction ¶
func NewInlineButtonAction[T any](label, data string, action func(param T) error) *InlineButtonAction[T]
type InlineKeyboard ¶
type InlineKeyboard []InlineRow
func NewInlineKeyboard ¶
func NewInlineKeyboard(rows ...InlineRow) InlineKeyboard
type InlineMessageHandler ¶
type InlineRow ¶
type InlineRow []InlineButton
func NewInlineRow ¶
func NewInlineRow(buttons ...InlineButton) InlineRow
type Message ¶
type Message interface {
UpdateMessage(queryId string, text string, opts ...SendMessageOption)
RemoveKeyboardForMessage()
ID() int
}
remove that type. It indicates we could use it outside of a session but we shouldn't. Instead the context should have an updater-interface that modifies a messsage and the message-id becomes its own (int)-type
type MockBot ¶
type MockBot[T any] struct { LastMessage tgbotapi.MessageConfig NumMsgSent int // contains filtered or unexported fields }
func (*MockBot[T]) CreateSession ¶
func (*MockBot[T]) LastMessageButtons ¶
func (*MockBot[T]) LastMessageText ¶
type PromptOption ¶
type PromptOption func(opts *promptOptions)
func PromptDropStates ¶
func PromptDropStates(states int) PromptOption
func PromptMessagef ¶
func PromptMessagef(format string, args ...interface{}) PromptOption
type SendMessageOption ¶
type SendMessageOption func(options *sendMessageOptions)
func SendMessageInlineKeyboard ¶
func SendMessageInlineKeyboard(keyboard InlineKeyboard) SendMessageOption
func SendMessageKeepKeyboard ¶
func SendMessageKeepKeyboard() SendMessageOption
func SendMessageWithKeyboard ¶
func SendMessageWithKeyboard(keyboard Keyboard) SendMessageOption
func SendMessageWithNotification ¶
func SendMessageWithNotification() SendMessageOption
type Session ¶
type Session[T any] interface { SendMessage(text string, opts ...SendMessageOption) Message SendTemplateMessage(template string, values KeyValues, opts ...SendMessageOption) Message UpdateMessageForCallback(queryId string, messageId MessageId, text string, opts ...SendMessageOption) Fail(message string, formatErrorMsg string, args ...interface{}) RootState() State[T] PushState(state State[T]) PopState() ReplaceState(state State[T]) ResetToState(state State[T]) DropStates(n int) SendError(err error) CurrentState() State[T] RemoveKeyboardForMessage(messageId MessageId) // returns the current user ID UserId() UserId AcceptUsers(duration time.Duration) BotName() (string, error) Context() context.Context State() T LastUserAction() time.Time }
type State ¶
type State[T any] interface { Activate(bs Session[T]) Return(bs Session[T]) HandleMessage(bs Session[T], msg ChatMessage) bool HandleCommand(bs Session[T], command string, args ...string) bool HandleCallbackQuery(bs Session[T], query CallbackQuery) bool // called before leaving the state (either by pushing another state on top of it or popping it) BeforeLeave(bs Session[T]) }
func NewMessageHandler ¶
func NewMessageHandler[T any](handleQuery InlineMessageHandler[T]) State[T]
func NewMultiMessageHandler ¶
func NewMultiMessageHandler[T any](handlers ...InlineMessageHandler[T]) State[T]
func PromptState ¶
func PromptState[T any](yesHandler func(), options ...PromptOption) State[T]
func SelectState ¶
func SelectToDeleteUser ¶
func SelectToDeleteUser[T any](uStorage UserManager, users []User) State[T]
func UsersList ¶
func UsersList[T any](uStorage UserManager) State[T]
type StateBuilder ¶
type StateBuilder[T any] struct { // contains filtered or unexported fields }
func NewStateBuilder ¶
func NewStateBuilder[T any]() *StateBuilder[T]
func (*StateBuilder[T]) Build ¶
func (sb *StateBuilder[T]) Build() State[T]
func (*StateBuilder[T]) OnActivate ¶
func (sb *StateBuilder[T]) OnActivate(activator func(bs Session[T])) *StateBuilder[T]
func (*StateBuilder[T]) OnBeforeLeave ¶
func (sb *StateBuilder[T]) OnBeforeLeave(handler func(bs Session[T])) *StateBuilder[T]
func (*StateBuilder[T]) OnButton ¶
func (sb *StateBuilder[T]) OnButton(button Button, handler func(bs Session[T], message ChatMessage)) *StateBuilder[T]
func (*StateBuilder[T]) OnCallbackQuery ¶
func (sb *StateBuilder[T]) OnCallbackQuery(handler func(bs Session[T], query CallbackQuery) bool) *StateBuilder[T]
func (*StateBuilder[T]) OnInlineButton ¶
func (sb *StateBuilder[T]) OnInlineButton(button InlineButton, handler func(bs Session[T], query CallbackQuery) bool) *StateBuilder[T]
func (*StateBuilder[T]) OnMessage ¶
func (sb *StateBuilder[T]) OnMessage(handleMessage func(bs Session[T], message ChatMessage)) *StateBuilder[T]
type StateFactory ¶
type StoredSessionState ¶
Click to show internal directories.
Click to hide internal directories.