Documentation
¶
Index ¶
- Variables
- func DefaultFilter(msg *types.Message) bool
- type EndOpts
- type Filter
- type Key
- type Manager
- func (m *Manager) ClearFilter(key Key)
- func (m *Manager) ClearState(key Key) error
- func (m *Manager) GetFilter(key Key) Filter
- func (m *Manager) GetState(key Key) (*storage.ConvState, error)
- func (m *Manager) GetStepHandler(name string) (StepHandler, bool)
- func (m *Manager) LoadState(key Key, msg *types.Message, update any) (*State, error)
- func (m *Manager) RegisterStep(name string, handler StepHandler)
- func (m *Manager) SaveState(state *State) error
- func (m *Manager) SetState(key Key, step string, payload []byte, timeout ...time.Duration) error
- func (m *Manager) SetStateWithOpts(key Key, step string, payload []byte, timeout time.Duration, filter Filter) error
- type NextOpts
- type State
- func (s *State) ChatID() int64
- func (s *State) Delete(key string)
- func (s *State) End(text string, opts ...*EndOpts) error
- func (s *State) Get(key string) any
- func (s *State) GetInt(key string) int
- func (s *State) GetString(key string) string
- func (s *State) Key() Key
- func (s *State) Next(step string, text string, opts ...*NextOpts) error
- func (s *State) NextMedia(step string, media tg.InputMediaClass, caption string, opts ...*NextOpts) error
- func (s *State) Set(key string, value any)
- func (s *State) Step() string
- func (s *State) Text() string
- func (s *State) UserID() int64
- type StepHandler
Constants ¶
This section is empty.
Variables ¶
View Source
var Filters = struct { Text Filter Photo Filter Video Filter Audio Filter Voice Filter Media Filter Any Filter }{ Text: func(m *types.Message) bool { return m != nil && m.Message != nil && m.Text != "" && m.Media == nil }, Photo: func(m *types.Message) bool { if m == nil || m.Message == nil || m.Media == nil { return false } ph := m.Photo() return ph != nil }, Video: func(m *types.Message) bool { return m != nil && m.Message != nil && m.Video() != nil }, Audio: func(m *types.Message) bool { return m != nil && m.Message != nil && m.Audio() != nil }, Voice: func(m *types.Message) bool { return m != nil && m.Message != nil && m.Voice() != nil }, Media: func(m *types.Message) bool { return m != nil && m.Message != nil && m.Media != nil }, Any: func(m *types.Message) bool { return m != nil }, }
Functions ¶
func DefaultFilter ¶
DefaultFilter accepts any non-nil message.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps track of pending asks per peer.
func NewManager ¶
func NewManager(p *storage.PeerStorage, defaultTimeout time.Duration) *Manager
NewManager creates a new conversation manager.
func (*Manager) ClearFilter ¶
ClearFilter removes the filter for a conversation key.
func (*Manager) ClearState ¶
ClearState removes the conversation state for the given key.
func (*Manager) GetState ¶
GetState retrieves the conversation state for the given key. Returns nil if no state exists or if it has expired.
func (*Manager) GetStepHandler ¶
func (m *Manager) GetStepHandler(name string) (StepHandler, bool)
GetStepHandler retrieves a registered step handler by name.
func (*Manager) RegisterStep ¶
func (m *Manager) RegisterStep(name string, handler StepHandler)
RegisterStep registers a handler for a specific conversation step.
type State ¶
type State struct {
Update any
Message *types.Message
SendFn func(text string) error
ReplyFn func(text string) error
MediaFn func(media tg.InputMediaClass, caption string) error
// contains filtered or unexported fields
}
type StepHandler ¶
StepHandler handles a conversation step response. The handler receives the State, and should return an error or nil.
Click to show internal directories.
Click to hide internal directories.