conv

package
v1.0.0-beta24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

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

func DefaultFilter(msg *types.Message) bool

DefaultFilter accepts any non-nil message.

Types

type EndOpts

type EndOpts struct {
	Reply bool
}

type Filter

type Filter func(*types.Message) bool

Filter determines whether an incoming message should be delivered to the waiter.

type Key

type Key struct {
	ChatID int64
	UserID int64
}

Key identifies a conversation via chat+user pair.

func (Key) String

func (k Key) String() string

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

func (m *Manager) ClearFilter(key Key)

ClearFilter removes the filter for a conversation key.

func (*Manager) ClearState

func (m *Manager) ClearState(key Key) error

ClearState removes the conversation state for the given key.

func (*Manager) GetFilter

func (m *Manager) GetFilter(key Key) Filter

GetFilter retrieves the current filter for a conversation key.

func (*Manager) GetState

func (m *Manager) GetState(key Key) (*storage.ConvState, error)

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) LoadState

func (m *Manager) LoadState(key Key, msg *types.Message, update any) (*State, error)

LoadState retrieves and wraps the conversation state for a key.

func (*Manager) RegisterStep

func (m *Manager) RegisterStep(name string, handler StepHandler)

RegisterStep registers a handler for a specific conversation step.

func (*Manager) SaveState

func (m *Manager) SaveState(state *State) error

SaveState persists a State object.

func (*Manager) SetState

func (m *Manager) SetState(key Key, step string, payload []byte, timeout ...time.Duration) error

SetState persists a conversation state for the given key.

func (*Manager) SetStateWithOpts

func (m *Manager) SetStateWithOpts(key Key, step string, payload []byte, timeout time.Duration, filter Filter) error

SetStateWithOpts persists a conversation state for the given key.

type NextOpts

type NextOpts struct {
	Filter  Filter
	Timeout time.Duration
	Reply   bool
}

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
}

func (*State) ChatID

func (s *State) ChatID() int64

func (*State) Delete

func (s *State) Delete(key string)

func (*State) End

func (s *State) End(text string, opts ...*EndOpts) error

func (*State) Get

func (s *State) Get(key string) any

func (*State) GetInt

func (s *State) GetInt(key string) int

func (*State) GetString

func (s *State) GetString(key string) string

func (*State) Key

func (s *State) Key() Key

func (*State) Next

func (s *State) Next(step string, text string, opts ...*NextOpts) error

func (*State) NextMedia

func (s *State) NextMedia(step string, media tg.InputMediaClass, caption string, opts ...*NextOpts) error

func (*State) Set

func (s *State) Set(key string, value any)

func (*State) Step

func (s *State) Step() string

func (*State) Text

func (s *State) Text() string

func (*State) UserID

func (s *State) UserID() int64

type StepHandler

type StepHandler func(state *State) error

StepHandler handles a conversation step response. The handler receives the State, and should return an error or nil.

Jump to

Keyboard shortcuts

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