Documentation
¶
Index ¶
- Constants
- type ChatStateMachineInterface
- type InMenoryCsm
- func (c *InMenoryCsm) ClearData(update tgbotapi.Update)
- func (c *InMenoryCsm) Get(key string, create bool) map[string]interface{}
- func (c *InMenoryCsm) GetData(update tgbotapi.Update) map[string]interface{}
- func (c *InMenoryCsm) GetOrCreate(key string) map[string]interface{}
- func (c *InMenoryCsm) GetState(update tgbotapi.Update) string
- func (c *InMenoryCsm) Key(update tgbotapi.Update) string
- func (c *InMenoryCsm) Set(key string, value string)
- func (c *InMenoryCsm) UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{}
- func (c *InMenoryCsm) UpdateState(update tgbotapi.Update, state string) map[string]interface{}
- type RedisCsm
- func (csm *RedisCsm) ClearData(update tgbotapi.Update)
- func (csm *RedisCsm) Flush()
- func (csm *RedisCsm) Get(key string, create bool) map[string]interface{}
- func (csm *RedisCsm) GetData(update tgbotapi.Update) map[string]interface{}
- func (csm *RedisCsm) GetOrCreate(key string) map[string]interface{}
- func (csm *RedisCsm) GetState(update tgbotapi.Update) string
- func (csm *RedisCsm) Key(update tgbotapi.Update) string
- func (csm *RedisCsm) Set(key string, value string)
- func (csm *RedisCsm) UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{}
- func (csm *RedisCsm) UpdateState(update tgbotapi.Update, state string) map[string]interface{}
Constants ¶
const ( DefaultExpirationTime int64 = 0 // records won't expire RecordPrefix string = "user_data" // prefix for redis records InitialState string = "~" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatStateMachineInterface ¶
type ChatStateMachineInterface interface { UpdateState(update tgbotapi.Update, state string) map[string]interface{} GetState(update tgbotapi.Update) string UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{} GetData(update tgbotapi.Update) map[string]interface{} ClearData(update tgbotapi.Update) }
type InMenoryCsm ¶
type InMenoryCsm struct {
// contains filtered or unexported fields
}
func (*InMenoryCsm) ClearData ¶
func (c *InMenoryCsm) ClearData(update tgbotapi.Update)
update data bucket
func (*InMenoryCsm) Get ¶
func (c *InMenoryCsm) Get(key string, create bool) map[string]interface{}
get data from key use `create=true` case you want to create new bucket with `key: {"__state__": INITIAL_VALUE}` if it was not found by `key`
func (*InMenoryCsm) GetData ¶
func (c *InMenoryCsm) GetData(update tgbotapi.Update) map[string]interface{}
get user's saved data if no user found - will create new bucket
func (*InMenoryCsm) GetOrCreate ¶
func (c *InMenoryCsm) GetOrCreate(key string) map[string]interface{}
will create new record if can't get one with particular key
func (*InMenoryCsm) Key ¶
func (c *InMenoryCsm) Key(update tgbotapi.Update) string
get user identifier by most usable telegram update TODO: make all updates identifier
func (*InMenoryCsm) Set ¶
func (c *InMenoryCsm) Set(key string, value string)
base set reimplementation with err handling
func (*InMenoryCsm) UpdateData ¶
func (c *InMenoryCsm) UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{}
update data bucket
func (*InMenoryCsm) UpdateState ¶
func (c *InMenoryCsm) UpdateState(update tgbotapi.Update, state string) map[string]interface{}
sets new state TODO: discuss if __state__ key must be array of database and renamed to __states__
type RedisCsm ¶
func (*RedisCsm) Flush ¶
func (csm *RedisCsm) Flush()
remove all stored data and database (flush db)
func (*RedisCsm) Get ¶
get data from key use `create=true` case you want to create new bucket with `key: {"__state__": INITIAL_VALUE}` if it was not found by `key`
func (*RedisCsm) GetOrCreate ¶
will create new record if can't get one with particular key
func (*RedisCsm) Key ¶
get user identifier by most usable telegram update TODO: make all updates identifier