Documentation
¶
Index ¶
- Constants
- type ConversationPersistence
- type FilterFunc
- type HandleFunc
- type Handler
- func NewCommandHandler(command string, handles ...HandleFunc) *Handler
- func NewConversationHandler(persistence ConversationPersistence, states StateMap, ...) *Handler
- func NewHandler(filter FilterFunc, handles ...HandleFunc) *Handler
- func NewMessageHandler(filter FilterFunc, handles ...HandleFunc) *Handler
- type KeyLock
- type LocalPersistence
- type PersistenceKey
- type StateMap
- type UpdateDispatcher
Constants ¶
const ( HandleFailed = -2 HandleSuccess = -1 )
const (
BufferSize = 1000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConversationPersistence ¶
type ConversationPersistence interface {
// GetState & SetState tell conversation handlers how to retrieve & set conversation state.
GetState(pk PersistenceKey) (int, bool)
SetState(pk PersistenceKey, state int)
}
ConversationPersistence interface tells conversation where to store & how to retrieve the current state of the conversation, i. e. which "step" the given user is currently at.
type FilterFunc ¶
type FilterFunc func(u *types.TelegramUpdate) bool
FilterFunc is used to check if this update should be processed by handler.
func And ¶
func And(filters ...FilterFunc) FilterFunc
And filters updates that pass ALL of the provided filters.
func IsAnyCommandMessage ¶
func IsAnyCommandMessage() FilterFunc
IsAnyCommandMessage filters updates that contain a message and look like a command, i. e. have some text and start with a slash ("/"). If command contains bot username, it is also checked.
func IsCommandMessage ¶
func IsCommandMessage(cmd string) FilterFunc
IsCommandMessage filters updates that contain a specific command. For example, IsCommandMessage("start") will handle a "/start" command. This will also allow the user to pass arguments, e. g. "/start foo bar". Commands in format "/start@bot_name" and "/start@bot_name foo bar" are also supported. If command contains bot username, it is also checked.
func IsMessage ¶
func IsMessage() FilterFunc
IsMessage filters updates that look like message (text, photo, location etc.)
func Not ¶
func Not(filter FilterFunc) FilterFunc
Not filters updates that do not pass the provided filter.
func Or ¶
func Or(filters ...FilterFunc) FilterFunc
Or filters updates that pass ANY of the provided filters.
type Handler ¶
type Handler struct {
Filter FilterFunc
Handles []HandleFunc
}
Handler defines a function that will handle updates that pass the filtering.
func NewCommandHandler ¶
func NewCommandHandler(command string, handles ...HandleFunc) *Handler
NewCommandHandler is an extension for NewMessageHandler that creates a handler for updates that contain message with command.
func NewConversationHandler ¶
func NewConversationHandler( persistence ConversationPersistence, states StateMap, cancelHandlers []*Handler, ) *Handler
NewConversationHandler creates a conversation handler.
func NewHandler ¶
func NewHandler(filter FilterFunc, handles ...HandleFunc) *Handler
NewHandler creates a new generic handler.
func NewMessageHandler ¶
func NewMessageHandler(filter FilterFunc, handles ...HandleFunc) *Handler
NewMessageHandler creates a handler for updates that contain message.
type KeyLock ¶
type KeyLock struct {
// contains filtered or unexported fields
}
func NewKeyLock ¶
func NewKeyLock() *KeyLock
func (*KeyLock) Lock ¶
func (l *KeyLock) Lock(key PersistenceKey)
func (*KeyLock) Unlock ¶
func (l *KeyLock) Unlock(key PersistenceKey)
type LocalPersistence ¶
type LocalPersistence struct {
States *safemap.SafeMap[PersistenceKey, int]
}
func NewLocalPersistence ¶
func NewLocalPersistence() *LocalPersistence
NewLocalPersistence creates new instance of LocalPersistence.
func (*LocalPersistence) GetState ¶
func (p *LocalPersistence) GetState(pk PersistenceKey) (int, bool)
func (*LocalPersistence) SetState ¶
func (p *LocalPersistence) SetState(pk PersistenceKey, state int)
type PersistenceKey ¶
PersistenceKey contains user & chat IDs. It is used to identify conversations with different users in different chats.
type UpdateDispatcher ¶
type UpdateDispatcher struct {
// contains filtered or unexported fields
}
func NewUpdateDispatcher ¶
func NewUpdateDispatcher() *UpdateDispatcher
func (*UpdateDispatcher) AddHandler ¶
func (u *UpdateDispatcher) AddHandler(h *Handler) *UpdateDispatcher
func (*UpdateDispatcher) Dispatch ¶
func (u *UpdateDispatcher) Dispatch(tu *types.TelegramUpdate)