xtelebot

package module
v0.0.0-...-3876231 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 15 Imported by: 0

README

xtelebot

Dependencies

  • github.com/Aoi-hosizora/ahlib
  • gopkg.in/tucnak/telebot.v2
  • github.com/sirupsen/logrus

Documents

Types
  • type InlineRow []*telebot.InlineButton
  • type ReplyRow []*telebot.ReplyButton
  • type ChatState uint64
  • type StateHandlerSet struct
  • type BotData struct
  • type BotWrapper struct
  • type MessageHandler func
  • type CallbackHandler func
  • type RespondEventType string
  • type RespondEvent struct
  • type LoggerOption func
  • type ReceiveLoggerParam struct
  • type RespondLoggerParam struct
Variables
  • var FormatReceiveFunc func(p *ReceiveLoggerParam) string
  • var FieldifyReceiveFunc func(p *ReceiveLoggerParam) logrus.Fields
  • var FormatRespondFunc func(p *RespondLoggerParam) string
  • var FieldifyRespondFunc func(p *RespondLoggerParam) logrus.Fields
Constants
  • const RespondSendEvent RespondEventType
  • const RespondReplyEvent RespondEventType
  • const RespondEditEvent RespondEventType
  • const RespondDeleteEvent RespondEventType
  • const RespondCallbackEvent RespondEventType
Functions
  • func DataBtn(text, unique string, data ...string) *telebot.InlineButton
  • func TextBtn(text string) *telebot.ReplyButton
  • func URLBtn(text, url string) *telebot.InlineButton
  • func InlineKeyboard(rows ...InlineRow) [][]telebot.InlineButton
  • func ReplyKeyboard(rows ...ReplyRow) [][]telebot.ReplyButton
  • func SetInlineKeyboard(keyboard [][]telebot.InlineButton) *telebot.ReplyMarkup
  • func SetReplyKeyboard(keyboard [][]telebot.ReplyButton) *telebot.ReplyMarkup
  • func RemoveInlineKeyboard() *telebot.ReplyMarkup
  • func RemoveReplyKeyboard() *telebot.ReplyMarkup
  • func CallbackShowAlert(text string, showAlert bool) *telebot.CallbackResponse
  • func LongPoller(second int) *telebot.LongPoller
  • func IsEntityParseError(err error) bool
  • func IsTelebotSupportedOption(option interface{}) bool
  • func NewStateHandlerSet() *StateHandlerSet
  • func NewBotData() *BotData
  • func NewBotWrapper(bot *telebot.Bot) *BotWrapper
  • func WithExtraText(text string) LoggerOption
  • func WithMoreExtraText(text string) LoggerOption
  • func WithExtraFields(fields map[string]interface{}) LoggerOption
  • func WithMoreExtraFields(fields map[string]interface{}) LoggerOption
  • func WithExtraFieldsV(fields ...interface{}) LoggerOption
  • func WithMoreExtraFieldsV(fields ...interface{}) LoggerOption
  • func LogReceiveToLogrus(logger *logrus.Logger, endpoint interface{}, received *telebot.Message, options ...LoggerOption)
  • func LogReceiveToLogger(logger logrus.StdLogger, endpoint interface{}, received *telebot.Message, options ...LoggerOption)
  • func LogRespondToLogrus(logger *logrus.Logger, typ RespondEventType, ev *RespondEvent, options ...LoggerOption)
  • func LogRespondToLogger(logger logrus.StdLogger, typ RespondEventType, ev *RespondEvent, options ...LoggerOption)
Methods
  • func (s *StateHandlerSet) IsRegistered(state ChatState) bool
  • func (s *StateHandlerSet) GetHandler(state ChatState) MessageHandler
  • func (s *StateHandlerSet) Register(state ChatState, handler MessageHandler)
  • func (s *StateHandlerSet) Unregister(state ChatState)
  • func (b *BotData) GetStateChats() []int64
  • func (b *BotData) GetState(chatID int64) (ChatState, bool)
  • func (b *BotData) GetStateOr(chatID int64, fallbackState ChatState) ChatState
  • func (b *BotData) GetStateOrInit(chatID int64) ChatState
  • func (b *BotData) InitialState() ChatState
  • func (b *BotData) SetInitialState(s ChatState)
  • func (b *BotData) SetState(chatID int64, state ChatState)
  • func (b *BotData) ResetState(chatID int64)
  • func (b *BotData) DeleteState(chatID int64)
  • func (b *BotData) GetCacheChats() []int64
  • func (b *BotData) GetCache(chatID int64, key string) (interface{}, bool)
  • func (b *BotData) GetCacheOr(chatID int64, key string, fallbackValue interface{}) interface{}
  • func (b *BotData) GetChatCaches(chatID int64) (map[string]interface{}, bool)
  • func (b *BotData) SetCache(chatID int64, key string, value interface{})
  • func (b *BotData) RemoveCache(chatID int64, key string)
  • func (b *BotData) ClearCaches(chatID int64)
  • func (b *BotWrapper) Bot() *telebot.Bot
  • func (b *BotWrapper) Data() *BotData
  • func (b *BotWrapper) Shs() *StateHandlerSet
  • func (b *BotWrapper) IsHandled(endpoint interface{}) bool
  • func (b *BotWrapper) RemoveHandler(endpoint interface{})
  • func (b *BotWrapper) HandleCommand(command string, handler MessageHandler)
  • func (b *BotWrapper) HandleReplyButton(button *telebot.ReplyButton, handler MessageHandler)
  • func (b *BotWrapper) HandleInlineButton(button *telebot.InlineButton, handler CallbackHandler)
  • func (b *BotWrapper) RespondSend(source *telebot.Chat, what interface{}, options ...interface{}) (*telebot.Message, error)
  • func (b *BotWrapper) RespondSendCtx(ctx context.Context, source *telebot.Chat, what interface{}, options ...interface{}) (*telebot.Message, error)
  • func (b *BotWrapper) RespondReply(source *telebot.Message, explicit bool, what interface{}, options ...interface{}) (*telebot.Message, error)
  • func (b *BotWrapper) RespondReplyCtx(ctx context.Context, source *telebot.Message, explicit bool, what interface{}, options ...interface{}) (*telebot.Message, error)
  • func (b *BotWrapper) RespondEdit(source *telebot.Message, what interface{}, options ...interface{}) (*telebot.Message, error)
  • func (b *BotWrapper) RespondEditCtx(ctx context.Context, source *telebot.Message, what interface{}, options ...interface{}) (*telebot.Message, error)
  • func (b *BotWrapper) RespondDelete(source *telebot.Message) error
  • func (b *BotWrapper) RespondDeleteCtx(ctx context.Context, source *telebot.Message) error
  • func (b *BotWrapper) RespondCallback(source *telebot.Callback, answer *telebot.CallbackResponse) error
  • func (b *BotWrapper) RespondCallbackCtx(ctx context.Context, source *telebot.Callback, answer *telebot.CallbackResponse) error
  • func (b *BotWrapper) SetHandledCallback(f func(endpoint interface{}, formattedEndpoint string, handlerName string))
  • func (b *BotWrapper) SetReceivedCallback(cb func(endpoint interface{}, received *telebot.Message))
  • func (b *BotWrapper) SetRespondedCallback(cb func(typ RespondEventType, event *RespondEvent))
  • func (b *BotWrapper) SetPanicHandler(handler func(endpoint, source, value interface{}))

Documentation

Index

Constants

View Source
const (
	// NAME represents ahlib-mx package's name.
	NAME = "ahlib-mx/xtelebot"

	// VERSION represents ahlib-mx package's current version.
	VERSION = "1.6.0"
)

Variables

View Source
var (
	// FormatReceiveFunc is a custom ReceiveLoggerParam's format function for LogReceiveToLogrus and LogReceiveToLogger.
	FormatReceiveFunc func(p *ReceiveLoggerParam) string

	// FieldifyReceiveFunc is a custom ReceiveLoggerParam's fieldify function for LogReceiveToLogrus.
	FieldifyReceiveFunc func(p *ReceiveLoggerParam) logrus.Fields
)
View Source
var (
	// FormatRespondFunc is a custom RespondLoggerParam's format function for LogRespondToLogrus and LogRespondToLogger.
	FormatRespondFunc func(p *RespondLoggerParam) string

	// FieldifyRespondFunc is a custom RespondLoggerParam's fieldify function for LogRespondToLogrus.
	FieldifyRespondFunc func(p *RespondLoggerParam) logrus.Fields
)

Functions

func CallbackShowAlert

func CallbackShowAlert(text string, showAlert bool) *telebot.CallbackResponse

CallbackShowAlert creates a telebot.CallbackResponse for showing alert in telebot.Callback.

func DataBtn

func DataBtn(text, unique string, data ...string) *telebot.InlineButton

DataBtn creates a telebot.InlineButton using given button text, callback unique and callback data.

func DefaultColorizedHandledCallback

func DefaultColorizedHandledCallback(_ interface{}, formattedEndpoint string, handlerName string)

DefaultColorizedHandledCallback is the DefaultAddedCallback (BotWrapper's handledCallback) in color.

The default callback logs like (just like gin.DebugPrintRouteFunc):

[Telebot] /test-endpoint               --> ...
[Telebot] $on_text                     --> ...
[Telebot] $rep_btn:button_text         --> ...
[Telebot] $inl_btn:button_unique       --> ...
         |----------------------------|   |---|
                   28 (blue)               ...

func DefaultHandledCallback

func DefaultHandledCallback(_ interface{}, formattedEndpoint string, handlerName string)

DefaultHandledCallback is the default BotWrapper's handledCallback, can be modified by BotWrapper.SetHandledCallback.

The default callback logs like (just like gin.DebugPrintRouteFunc):

[Telebot] /test-endpoint               --> ...
[Telebot] $on_text                     --> ...
[Telebot] $rep_btn:button_text         --> ...
[Telebot] $inl_btn:button_unique       --> ...
         |----------------------------|   |---|
                       28                  ...

func InlineKeyboard

func InlineKeyboard(rows ...InlineRow) [][]telebot.InlineButton

InlineKeyboard creates a telebot.InlineButton keyboard with given InlineRow-s.

Example:

markup := &telebot.ReplyMarkup{
	InlineKeyboard: xtelebot.InlineKeyboard(
		xtelebot.InlineRow{button.InlineBtn1},
		xtelebot.InlineRow{button.InlineBtn2, button.InlineBtn3},
	),
}

func IsEntityParseError

func IsEntityParseError(err error) bool

IsEntityParseError checks whether given error is "can't parse entities" error, such as "character must be escaped" or "Can't find end of the entity".

func IsTelebotSupportedOption

func IsTelebotSupportedOption(option interface{}) bool

IsTelebotSupportedOption checks whether given single option is supported by telebot.Bot.

func LogReceiveToLogger

func LogReceiveToLogger(logger logrus.StdLogger, endpoint interface{}, received *telebot.Message, options ...LoggerOption)

LogReceiveToLogger logs a receive-event message to logrus.StdLogger using given endpoint and telebot.Message received from handler.

func LogReceiveToLogrus

func LogReceiveToLogrus(logger *logrus.Logger, endpoint interface{}, received *telebot.Message, options ...LoggerOption)

LogReceiveToLogrus logs a receive-event message to logrus.Logger using given endpoint and telebot.Message received from handler.

func LogRespondToLogger

func LogRespondToLogger(logger logrus.StdLogger, typ RespondEventType, ev *RespondEvent, options ...LoggerOption)

LogRespondToLogger logs a respond-event message to logrus.StdLogger using given RespondEventType and RespondEvent.

func LogRespondToLogrus

func LogRespondToLogrus(logger *logrus.Logger, typ RespondEventType, ev *RespondEvent, options ...LoggerOption)

LogRespondToLogrus logs a respond-event message to logrus.Logger using given RespondEventType and RespondEvent.

func LongPoller

func LongPoller(second int) *telebot.LongPoller

LongPoller creates a telebot.LongPoller with given second.

func RemoveInlineKeyboard

func RemoveInlineKeyboard() *telebot.ReplyMarkup

RemoveInlineKeyboard creates a telebot.ReplyMarkup for removing telebot.InlineButton keyboard.

func RemoveReplyKeyboard

func RemoveReplyKeyboard() *telebot.ReplyMarkup

RemoveReplyKeyboard creates a telebot.ReplyMarkup for removing telebot.ReplyButton keyboard.

func ReplyKeyboard

func ReplyKeyboard(rows ...ReplyRow) [][]telebot.ReplyButton

ReplyKeyboard creates a telebot.ReplyButton keyboard with given ReplyRow-s.

Example:

markup := &telebot.ReplyMarkup{
	ResizeReplyKeyboard: true,
	ReplyKeyboard: xtelebot.ReplyKeyboard(
		xtelebot.ReplyRow{button.ReplyBtn1, button.ReplyBtn2},
		xtelebot.ReplyRow{button.ReplyBtn3},
	),
}

func SetInlineKeyboard

func SetInlineKeyboard(keyboard [][]telebot.InlineButton) *telebot.ReplyMarkup

SetInlineKeyboard creates a telebot.ReplyMarkup for setting telebot.InlineButton keyboard.

func SetReplyKeyboard

func SetReplyKeyboard(keyboard [][]telebot.ReplyButton) *telebot.ReplyMarkup

SetReplyKeyboard creates a telebot.ReplyMarkup for setting telebot.ReplyButton keyboard with ResizeReplyKeyboard enabled.

func TextBtn

func TextBtn(text string) *telebot.ReplyButton

TextBtn creates a telebot.ReplyButton using given button text.

func URLBtn

func URLBtn(text, url string) *telebot.InlineButton

URLBtn creates a telebot.InlineButton using given button text and url.

Types

type BotData

type BotData struct {
	// contains filtered or unexported fields
}

BotData represents a set of chats data in a telegram bot, including states and caches.

func NewBotData

func NewBotData() *BotData

NewBotData creates a default BotData, with zero initial ChatState.

func (*BotData) ClearCaches

func (b *BotData) ClearCaches(chatID int64)

ClearCaches clears a chat's all caches.

func (*BotData) DeleteState

func (b *BotData) DeleteState(chatID int64)

DeleteState deletes a chat's state.

func (*BotData) GetCache

func (b *BotData) GetCache(chatID int64, key string) (interface{}, bool)

GetCache returns a chat's cache data, returns false if no cache is set or the key is not found.

func (*BotData) GetCacheChats

func (b *BotData) GetCacheChats() []int64

GetCacheChats returns all ids from chats which has been set cache. Note that returned slice has no order.

func (*BotData) GetCacheOr

func (b *BotData) GetCacheOr(chatID int64, key string, fallbackValue interface{}) interface{}

GetCacheOr returns a chat's cache data, returns fallback value if no cache is set or the key is not found.

func (*BotData) GetChatCaches

func (b *BotData) GetChatCaches(chatID int64) (map[string]interface{}, bool)

GetChatCaches returns a chat's all caches data (without any copy), returns false if no cache is set.

func (*BotData) GetState

func (b *BotData) GetState(chatID int64) (ChatState, bool)

GetState returns a chat's state, returns false if no state is set.

func (*BotData) GetStateChats

func (b *BotData) GetStateChats() []int64

GetStateChats returns all ids from chats which has been set state. Note that returned slice has no order.

func (*BotData) GetStateOr

func (b *BotData) GetStateOr(chatID int64, fallbackState ChatState) ChatState

GetStateOr returns a chat's state, returns the fallback state if no state is set.

func (*BotData) GetStateOrInit

func (b *BotData) GetStateOrInit(chatID int64) ChatState

GetStateOrInit returns a chat's state, sets to the initial state and returns it if no state is set.

func (*BotData) InitialState

func (b *BotData) InitialState() ChatState

InitialState returns the initial ChatState from BotData/

func (*BotData) RemoveCache

func (b *BotData) RemoveCache(chatID int64, key string)

RemoveCache removes a key from chat's cache.

func (*BotData) ResetState

func (b *BotData) ResetState(chatID int64)

ResetState resets a chat's state to the initial state.

func (*BotData) SetCache

func (b *BotData) SetCache(chatID int64, key string, value interface{})

SetCache sets a chat's cache data using given key and value.

func (*BotData) SetInitialState

func (b *BotData) SetInitialState(s ChatState)

SetInitialState sets initial ChatState to BotData.

func (*BotData) SetState

func (b *BotData) SetState(chatID int64, state ChatState)

SetState sets a chat's state.

type BotWrapper

type BotWrapper struct {
	// contains filtered or unexported fields
}

BotWrapper represents a telebot.Bot wrapper type with some custom handling and sending behaviors. For more details about telegram bot api, please visit https://core.telegram.org/bots/api.

func NewBotWrapper

func NewBotWrapper(bot *telebot.Bot) *BotWrapper

NewBotWrapper creates a new BotWrapper with given telebot.Bot and new BotData and StateHandlerSet, panics when using nil telebot.Bot.

func (*BotWrapper) Bot

func (b *BotWrapper) Bot() *telebot.Bot

Bot returns the inner telebot.Bot from BotWrapper.

func (*BotWrapper) Data

func (b *BotWrapper) Data() *BotData

Data returns the inner BotData from BotWrapper.

func (*BotWrapper) HandleCommand

func (b *BotWrapper) HandleCommand(command string, handler MessageHandler)

HandleCommand handles string command with MessageHandler to telebot.Bot, panics when using invalid command or nil handler, visit https://github.com/tucnak/telebot/tree/v2#commands for more details.

func (*BotWrapper) HandleInlineButton

func (b *BotWrapper) HandleInlineButton(button *telebot.InlineButton, handler CallbackHandler)

HandleInlineButton handles telebot.InlineButton with CallbackHandler to telebot.Bot, panics when using nil button, invalid button or nil handler, visit https://github.com/tucnak/telebot/tree/v2#keyboards for more details.

func (*BotWrapper) HandleReplyButton

func (b *BotWrapper) HandleReplyButton(button *telebot.ReplyButton, handler MessageHandler)

HandleReplyButton handles telebot.ReplyButton with MessageHandler to telebot.Bot, panics when using nil button, invalid button or nil handler, visit https://github.com/tucnak/telebot/tree/v2#keyboards for more details.

func (*BotWrapper) IsHandled

func (b *BotWrapper) IsHandled(endpoint interface{}) bool

IsHandled checks whether given endpoint's handler has been handled or registered, panics when using invalid endpoint, that is neither string nor telebot.CallbackEndpoint.

func (*BotWrapper) RemoveHandler

func (b *BotWrapper) RemoveHandler(endpoint interface{})

RemoveHandler removes the handler of given endpoint, panics when using invalid endpoint, that is neither string nor telebot.CallbackEndpoint.

func (*BotWrapper) RespondCallback

func (b *BotWrapper) RespondCallback(source *telebot.Callback, answer *telebot.CallbackResponse) error

RespondCallback is a convenient form of RespondCallbackCtx without context.Context.

func (*BotWrapper) RespondCallbackCtx

func (b *BotWrapper) RespondCallbackCtx(ctx context.Context, source *telebot.Callback, answer *telebot.CallbackResponse) error

RespondCallbackCtx responds and answers to given telebot.Callback, if error returned is not caused by arguments, it will also invoke responded callback.

func (*BotWrapper) RespondDelete

func (b *BotWrapper) RespondDelete(source *telebot.Message) error

RespondDelete is a convenient form of RespondDeleteCtx without context.Context.

func (*BotWrapper) RespondDeleteCtx

func (b *BotWrapper) RespondDeleteCtx(ctx context.Context, source *telebot.Message) error

RespondDeleteCtx responds and deletes given telebot.Message, if error returned is not caused by arguments, it will also invoke responded callback.

func (*BotWrapper) RespondEdit

func (b *BotWrapper) RespondEdit(source *telebot.Message, what interface{}, options ...interface{}) (*telebot.Message, error)

RespondEdit is a convenient form of RespondEditCtx without context.Context.

func (*BotWrapper) RespondEditCtx

func (b *BotWrapper) RespondEditCtx(ctx context.Context, source *telebot.Message, what interface{}, options ...interface{}) (*telebot.Message, error)

RespondEditCtx responds and edits given telebot.Message with value, if error returned is not caused by arguments, it will also invoke responded callback.

func (*BotWrapper) RespondReply

func (b *BotWrapper) RespondReply(source *telebot.Message, explicit bool, what interface{}, options ...interface{}) (*telebot.Message, error)

RespondReply is a convenient form of RespondReplyCtx without context.Context.

func (*BotWrapper) RespondReplyCtx

func (b *BotWrapper) RespondReplyCtx(ctx context.Context, source *telebot.Message, explicit bool, what interface{}, options ...interface{}) (*telebot.Message, error)

RespondReplyCtx responds and replies message to given telebot.Message explicitly or implicitly, if error returned is not caused by arguments, it will also invoke responded callback.

func (*BotWrapper) RespondSend

func (b *BotWrapper) RespondSend(source *telebot.Chat, what interface{}, options ...interface{}) (*telebot.Message, error)

RespondSend is a convenient form of RespondSendCtx without context.Context.

func (*BotWrapper) RespondSendCtx

func (b *BotWrapper) RespondSendCtx(ctx context.Context, source *telebot.Chat, what interface{}, options ...interface{}) (*telebot.Message, error)

RespondSendCtx responds and sends message to given telebot.Chat, if error returned is not caused by arguments, it will also invoke responded callback.

func (*BotWrapper) SetHandledCallback

func (b *BotWrapper) SetHandledCallback(f func(endpoint interface{}, formattedEndpoint string, handlerName string))

SetHandledCallback sets endpoint handled callback, callback will be invoked in handling methods, defaults to DefaultHandledCallback.

func (*BotWrapper) SetPanicHandler

func (b *BotWrapper) SetPanicHandler(handler func(endpoint, messageOrCallback, value interface{}))

SetPanicHandler sets panic handler to all handlers. Note that the `messageOrCallback` parameter means handler's parameter, that is telebot.Message for MessageHandler and telebot.Callback for CallbackHandler, defaults to print warning message with given panicked value.

func (*BotWrapper) SetReceivedCallback

func (b *BotWrapper) SetReceivedCallback(cb func(endpoint interface{}, received *telebot.Message))

SetReceivedCallback sets received callback, callback will be invoked after receiving consumed messages which has been handled, defaults to do nothing.

func (*BotWrapper) SetRespondedCallback

func (b *BotWrapper) SetRespondedCallback(cb func(typ RespondEventType, event *RespondEvent))

SetRespondedCallback sets responded callback, callback will be invoked in respond methods, defaults to do nothing.

func (*BotWrapper) Shs

func (b *BotWrapper) Shs() *StateHandlerSet

Shs returns the inner StateHandlerSet from BotWrapper.

type CallbackHandler

type CallbackHandler func(*BotWrapper, *telebot.Callback)

CallbackHandler represents a handler type for telebot.InlineButton.

type ChatState

type ChatState uint64

ChatState is a type of chat state, is used in StateHandlerSet and BotData, also can be used in custom finite state machine.

type InlineRow

type InlineRow []*telebot.InlineButton

InlineRow is a collection type represents a row of telebot.InlineButton, used in InlineKeyboard.

type LoggerOption

type LoggerOption func(*loggerOptions)

LoggerOption represents an option type for some logger functions' option, can be created by WithXXX functions.

func WithExtraFields

func WithExtraFields(fields map[string]interface{}) LoggerOption

WithExtraFields creates a LoggerOption to specify logging with extra fields. Note that if you use this multiple times, only the last one will be retained.

func WithExtraFieldsV

func WithExtraFieldsV(fields ...interface{}) LoggerOption

WithExtraFieldsV creates a LoggerOption to specify logging with extra fields in variadic. Note that if you use this multiple times, only the last one will be retained.

func WithExtraText

func WithExtraText(text string) LoggerOption

WithExtraText creates a LoggerOption to specify extra text logging in "...extra_text" style. Note that if you use this multiple times, only the last one will be retained.

func WithMoreExtraFields

func WithMoreExtraFields(fields map[string]interface{}) LoggerOption

WithMoreExtraFields creates a LoggerOption to specify logging with extra fields. Note that if you use this multiple times, all previous contents will be retained.

func WithMoreExtraFieldsV

func WithMoreExtraFieldsV(fields ...interface{}) LoggerOption

WithMoreExtraFieldsV creates a LoggerOption to specify logging with extra fields in variadic. Note that if you use this multiple times, all previous contents will be retained.

func WithMoreExtraText

func WithMoreExtraText(text string) LoggerOption

WithMoreExtraText creates a LoggerOption to specify extra text logging in "...extra_text" style. Note that if you use this multiple times, all previous contents will be retained.

type MessageHandler

type MessageHandler func(*BotWrapper, *telebot.Message)

MessageHandler represents a handler type for string command and telebot.ReplyButton.

type ReceiveLoggerParam

type ReceiveLoggerParam struct {
	// origin
	Endpoint interface{}
	Chat     *telebot.Chat
	Message  *telebot.Message

	// field
	FormattedEp string
	ChatID      int64
	ChatName    string
	MessageID   int
	MessageTime time.Time
}

ReceiveLoggerParam stores some receive-event logger parameters and is used by LogReceiveToLogrus and LogReceiveToLogger.

type ReplyRow

type ReplyRow []*telebot.ReplyButton

ReplyRow is a collection type represents a row of telebot.ReplyButton, used in ReplyKeyboard.

type RespondEvent

type RespondEvent struct {
	// for RespondSendEvent
	SendSource  *telebot.Chat
	SendWhat    interface{}
	SendOptions []interface{}
	SendResult  *telebot.Message

	// for RespondReplyEvent
	ReplySource   *telebot.Message
	ReplyExplicit bool
	ReplyWhat     interface{}
	ReplyOptions  []interface{}
	ReplyResult   *telebot.Message

	// for RespondEditEvent
	EditSource  *telebot.Message
	EditWhat    interface{}
	EditOptions []interface{}
	EditResult  *telebot.Message

	// for RespondDeleteEvent
	DeleteSource *telebot.Message
	DeleteResult *telebot.Message // fake

	// for RespondCallbackEvent
	CallbackSource *telebot.Callback
	CallbackAnswer *telebot.CallbackResponse
	CallbackResult *telebot.CallbackResponse // fake

	// ctx and error
	RespondContext context.Context
	ReturnedError  error
}

RespondEvent is a type of respond event, containing arguments of respond method (such as BotWrapper.RespondSend) and responded result and error, this will be used in responded callback, LogRespondToLogrus and LogRespondToLogger.

type RespondEventType

type RespondEventType string

RespondEventType is a type of respond event type (such as "send", "reply", "edit", "delete" and "callback"), will be used in respondedCallback, LogRespondToLogrus and LogRespondToLogger.

const (
	RespondSendEvent     RespondEventType = "send"     // RespondEventType for BotWrapper.RespondSend.
	RespondReplyEvent    RespondEventType = "reply"    // RespondEventType for BotWrapper.RespondReply.
	RespondEditEvent     RespondEventType = "edit"     // RespondEventType for BotWrapper.RespondEdit.
	RespondDeleteEvent   RespondEventType = "delete"   // RespondEventType for BotWrapper.RespondDelete.
	RespondCallbackEvent RespondEventType = "callback" // RespondEventType for BotWrapper.RespondCallback.
)

type RespondLoggerParam

type RespondLoggerParam struct {
	// origin
	EventType RespondEventType
	Event     *RespondEvent

	// extracted origin
	SourceChat     *telebot.Chat             // sc: send, rep, edit, del, call
	SourceMessage  *telebot.Message          // sm:       rep, edit, del, call
	SourceCallback *telebot.Callback         // sl:                       call
	ResultMessage  *telebot.Message          // rm: send, rep, edit, del
	ResultAnswer   *telebot.CallbackResponse // ra:                       call
	ReturnedError  error                     // -

	// field
	SourceChatID       int64          // sc: send, rep, edit, del, call
	SourceChatName     string         // sc: send, rep, edit, del, call
	SourceMessageID    int            // sm:       rep, edit, del, call
	SourceMessageTime  time.Time      // sm:       rep, edit, del, call
	SourceCallbackID   string         // sl:                       call
	ResultMessageID    int            // rm: send, rep, edit, del
	ResultMessageChars int            // rm: send, rep, edit, del
	ResultMessageTime  time.Time      // rm: send, rep, edit, del
	ReplyLatency       *time.Duration // *:        rep
	CallbackAlert      *string        // *:                        call
	ReturnedErrorMsg   string         // -
}

RespondLoggerParam stores some respond-event (RespondEvent) logger parameters and is used by LogRespondToLogrus and LogRespondToLogger.

type StateHandlerSet

type StateHandlerSet struct {
	// contains filtered or unexported fields
}

StateHandlerSet is a container for ChatState and MessageHandler pairs, can be used to get MessageHandler for specific ChatState, with using finite state machine, in telebot.OnText handler.

func NewStateHandlerSet

func NewStateHandlerSet() *StateHandlerSet

NewStateHandlerSet create an empty StateHandlerSet.

func (*StateHandlerSet) GetHandler

func (s *StateHandlerSet) GetHandler(state ChatState) MessageHandler

GetHandler returns the registered MessageHandler for given ChatState, returns nil if handler for given ChatState has not registered yet.

func (*StateHandlerSet) IsRegistered

func (s *StateHandlerSet) IsRegistered(state ChatState) bool

IsRegistered checks whether given ChatState has registered a MessageHandler.

func (*StateHandlerSet) Register

func (s *StateHandlerSet) Register(state ChatState, handler MessageHandler)

Register registers a MessageHandler for given ChatState, panics when using nil handler.

func (*StateHandlerSet) Unregister

func (s *StateHandlerSet) Unregister(state ChatState)

Unregister unregisters the MessageHandler for given ChatState.

Jump to

Keyboard shortcuts

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