Documentation
¶
Index ¶
- type History
- func (h *History) Add(c telebot.Context, uniq string)
- func (h *History) Back()
- func (h *History) Clear()
- func (h *History) ExtractValues(keys map[string]any) bool
- func (h *History) Get(key string) (any, bool)
- func (h *History) GetPrevStep() *HistoryStep
- func (h *History) GetStep() *HistoryStep
- func (h *History) Set(key string, val any)
- type HistoryStep
- type Scene
- func (s *Scene) AddMessage(msg *telebot.Message)
- func (s *Scene) Delete(key string)
- func (s *Scene) DeleteMessages(c telebot.Context, skipLast ...bool)
- func (s *Scene) ExtractValues(keys map[string]any) bool
- func (s *Scene) Get(key string) (any, bool)
- func (s *Scene) GetMessages() []telebot.Message
- func (s *Scene) Name() string
- func (s *Scene) Set(key string, value any)
- type SceneType
- type Session
- func (s *Session) Delete(key string)
- func (s *Session) EnterScene(name string) *Scene
- func (s *Session) ExtractValues(keys map[string]any) bool
- func (s *Session) Get(key string) (any, bool)
- func (s *Session) GetScene() *Scene
- func (s *Session) GetTranslator() i18n.Translator
- func (s *Session) LeaveScene()
- func (s *Session) Set(key string, val any)
- type Wizard
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type History ¶
type History struct {
// contains filtered or unexported fields
}
History model. It contains all the steps of the user in the chat with the bot. The history is used to keep track of the user's actions and to be able to go back to the previous steps.
func (*History) Add ¶
Add add a new step to the history and clears the history if the message is sent without a callback. The history is cleared when the callback is nil, indicating the start of a new sequence or action.
func (*History) Back ¶
func (h *History) Back()
Back removes the last step from the history. It is used to go back to the previous step in the sequence.
func (*History) ExtractValues ¶
ExtractValues extracts values from the current step and writes them to the specified variables. It returns false if at least one parameter was not found or could not be converted.
func (*History) GetPrevStep ¶
func (h *History) GetPrevStep() *HistoryStep
GetPrevStep get previous step. If not exists return nil.
func (*History) GetStep ¶
func (h *History) GetStep() *HistoryStep
Get current step. If not exists return nil.
type HistoryStep ¶
type HistoryStep struct {
// Unique is the unique identifier of the step.
// It is used to identify the step in the history and to
// be able to go back to the previous steps.
Unique string
// contains filtered or unexported fields
}
HistoryStep model. It contains the unique identifier of the step and the data of the step.
type Scene ¶
type Scene struct {
// Wizard data for scenes of type wizard.
Wizard Wizard
// contains filtered or unexported fields
}
Scene represents a scene model.
func (*Scene) AddMessage ¶
AddMessage adds a message to the scene's message store It appends the provided message to the Messages slice.
func (*Scene) DeleteMessages ¶
DeleteMessages deletes all stored messages from both the chat and the scene It clears the Messages slice after deleting messages.
func (*Scene) ExtractValues ¶
ExtractValues extracts values from the scene's data and writes them to the specified variables. It returns false if at least one parameter was not found or could not be converted.
func (*Scene) GetMessages ¶
GetMessages retrieves all the messages stored in the scene It returns the slice of messages.
type Session ¶
type Session struct {
// History is a list of steps that the user has taken.
// It is used to keep track of the user's progress through a scene.
History *History
// Scene is a pointer to the user's current scene.
// It is used to store the user's current scene, which is used to determine the next step in the scene.
Scene *Scene
// Language is a string that represents the user's language.
Language string
// contains filtered or unexported fields
}
Session model. It contains data of user session. Data is stored in the cache with the user's ID as the key. The session is updated every time the user interacts with the bot.
func FromContext ¶
Extract session data from context. If session not exist it create scene.
func (*Session) Delete ¶
Delete delete value by `key`. if `key` not exists it will work without error.
func (*Session) EnterScene ¶
If scene already exists it will return exist scene instance. It can accept onExpire func to handle scene expiration event. Scene expiration event will be triggered when user leave from scene.
func (*Session) ExtractValues ¶
ExtractValues extracts values from the session storage and writes them to the specified variables. It returns false if at least one parameter was not found or could not be converted.
func (*Session) GetScene ¶
GetScene retrieves the current scene from the session. If the session does not contain a scene, or the scene is empty (i.e. the current scene is an empty string), it returns nil. Otherwise, it returns the current scene.
func (*Session) GetTranslator ¶
func (s *Session) GetTranslator() i18n.Translator
GetTranslator returns translator function based on the user's language preference. If the user's language preference is not set, it uses the bot's default language. If the user's language preference is set, it overrides the bot's default language.
func (*Session) LeaveScene ¶
func (s *Session) LeaveScene()
LeaveScene clears the current scene from the session. It sets the scene to nil, effectively leaving the scene.
type Wizard ¶
type Wizard struct {
// contains filtered or unexported fields
}
Wizard represents a wizard model for step management in scenes.
func (*Wizard) Back ¶
func (w *Wizard) Back()
Back moves the cursor to the previous step in the wizard. If the current step is the first step, it does nothing.