Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var KeyNotFound = errors.New("conversation key not found")
Functions ¶
Types ¶
type InMemoryStorage ¶
type InMemoryStorage struct {
// contains filtered or unexported fields
}
InMemoryStorage is a thread-safe in-memory implementation of the Storage interface.
func NewInMemoryStorage ¶
func NewInMemoryStorage(strategy KeyStrategy) *InMemoryStorage
type KeyStrategy ¶
type KeyStrategy int64
const ( // KeyStrategySenderAndChat ensures that each sender get a unique conversation in each chats. KeyStrategySenderAndChat KeyStrategy = iota // KeyStrategySender gives a unique conversation to each sender, but that conversation is available in all chats. KeyStrategySender // KeyStrategyChat gives a unique conversation to each chat, which all senders can interact in together. KeyStrategyChat )
Note: If you add a new keystrategy here, make sure to add it to the getStateKey method!
type State ¶
type State struct { // Key represents the name of the current state, as defined in the States map of handlers.Conversation. Key string }
State stores all the variables relevant to the current conversation state.
Note: More keys may be added in the future to support additional features. As such, any storage implementations should be flexible, and allow for storing the entire struct rather than individual fields.
type Storage ¶
type Storage interface { // Get returns the state for the specified conversation key. // Note that this is checked at each incoming message, so may be a bottleneck for some implementations. // // If the key is not found (and as such, this conversation has not yet started), this method should return the // ConversationKeyNotFound error. // Get(key string) (*State, error) Get(ctx *ext.Context) (*State, error) // Set updates the conversation state. Set(ctx *ext.Context, state State) error // Delete ends the conversation, removing the key from the storage. Delete(ctx *ext.Context) error }
Storage allows you to define custom backends for retaining conversation conversations. If you are looking to persist conversation data, you should implement this interface with you backend of choice. Note: Make sure to store the entire State struct; future changes may add new fields.