state

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotState

type BotState interface {
	RemoveConverastionState(conversationID int64) error // removes record about a current conversation. Should be called after a high-level handler is done
	LoadState() error                                   // Load state from a file
	Close() error                                       // Forbid furter savings

	GetConversationIDs() []int64                                        // get list of conversationsIDs, if several IDs have the same ChatID, only the latest conversationID will be listed
	GetConversatonFirstUpdate(conversationID int64) *tgbotapi.Update    // get first update of the conversation
	GetConversationStepAndData(conversationID int64) (int, interface{}) // get data and state of the conversation
	GetConversationChatID(conversationID int64) int64                   // get ChatID of the conversation

	StartConversationWithUpdate(conversationID int64, chatID int64, firstUpdate *tgbotapi.Update) error // create state for a conversation with first update
	SaveConversationStepAndData(conversationID int64, step int, data interface{}) error                 // save new conversation step and data, save all states to a file
}

BotState is an interface for object that records current state of all ongoing conversations

func NewBotState

func NewBotState(io StateIO) BotState

NewBotState method constructs a new BotState object

type ConversationState

type ConversationState struct {
	FirstUpdate *tgbotapi.Update `json:"first_update"` // initial message for a handler
	Step        int              `json:"step"`         // the index of the stap that should be processed
	Data        interface{}      `json:"data"`         // user-data
	ChatID      int64            `json:"chat_id"`      // chat_id of the conversation
}

ConversationState reflects the current state of a conversation handler with "step" granularity. The exact handler should be deduced from the firstMessage

type StateIO added in v0.13.4

type StateIO interface {
	Load() ([]byte, error)
	Save([]byte) error
}

func NewFileState added in v0.13.4

func NewFileState(filename string) StateIO

Jump to

Keyboard shortcuts

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