Documentation
¶
Index ¶
- Constants
- Variables
- func CommandArgs(update tgbotapi.Update) string
- func CommandArgsSplit(update tgbotapi.Update) []string
- func GetFromUser(update tgbotapi.Update) *tgbotapi.User
- func GetMessageObject(update tgbotapi.Update) *tgbotapi.Message
- func GetUpdateMessageID(update tgbotapi.Update) (int, error)
- func GetUserFirstName(update tgbotapi.Update) string
- func GetUserID(update tgbotapi.Update) int
- func GetUsername(update tgbotapi.Update) (string, error)
- type AllMessageHandler
- type Bot
- func (bot *Bot) AddHandler(handler Handler)
- func (bot *Bot) GetContext() interface{}
- func (bot *Bot) GetUpdatesChan() (tgbotapi.UpdatesChannel, error)
- func (bot *Bot) HandleUpdates(poolSize int) error
- func (bot *Bot) ReplyToMsg(update tgbotapi.Update, text string, asReply bool) error
- func (bot *Bot) SetContext(context interface{})
- func (bot *Bot) Shutdown()
- type CommandHandler
- type Filter
- type Handler
- type HandlerFunc
Constants ¶
const MaxInt int = int(MaxUint >> 1)
const MaxUint uint = ^uint(0)
Variables ¶
var ( ErrNoMessageID = errors.New("update does not contain a message ID") ErrNoUsername = errors.New("user does not have a username") )
Functions ¶
func CommandArgs ¶
CommandArgs returns the arguments to a command as a single string. Alias of update.ChannelPost.CommandArguments
func CommandArgsSplit ¶
CommandArgsSplit returns the arguments to a command, split by space
func GetFromUser ¶
GetFromUser returns the User from whom the update was received, regardless of the true underlying type of the update.
func GetMessageObject ¶
GetMessageObject will return the main message object from an update. This excludes the message objects for when a message has been edited. If there are no main message objects (for example, if the update is an InlineQuery), then nil is returned.
func GetUpdateMessageID ¶
GetUpdateMessageID extracts the ID of the message that triggered an update. If the update does not contain a message ID, ErrNoMessageID is returned.
func GetUserFirstName ¶
GetUserFirstName returns the first name of the user who sent this update. There is no error returned for this since a first name is required in Telegram.
Types ¶
type AllMessageHandler ¶
type AllMessageHandler struct {
// contains filtered or unexported fields
}
AllMessageHandler is a handler that matches all message-like updates.
func NewAllMessageHandler ¶
func NewAllMessageHandler(handler HandlerFunc) *AllMessageHandler
NewAllMessageHandler creates a new handler that matches all message-like updates.
func (*AllMessageHandler) Filter ¶
func (handler *AllMessageHandler) Filter() Filter
type Bot ¶
Bot represents the bot itself, stores the necessary variables for the functioning of the bot, and exposes the necessary methods for the bot's operation.
func (*Bot) AddHandler ¶
AddHandler adds a new update handler to the bot. The order in which handlers are added sets their priorities; handlers are checked to see whether an update applies in the order they are added here, so if a filter could match multiple commands, this order is important.
func (*Bot) GetContext ¶
func (bot *Bot) GetContext() interface{}
GetContext returns the stored context object, ready for the user to cast back to its original type.
func (*Bot) GetUpdatesChan ¶
func (bot *Bot) GetUpdatesChan() (tgbotapi.UpdatesChannel, error)
GetUpdatesChan returns the updates channel for the bot, using the bot's stored API.
func (*Bot) HandleUpdates ¶
HandleUpdates is the main method for the bot. It begins the loop of handling updates.
func (*Bot) ReplyToMsg ¶
ReplyToMsg sends a message of a given text as a reply to the message in the update. The Markdown parser is assumed. If asReply is false or the update does not contain a message that can be replied to, the message is sent without specifically replying to the update.
func (*Bot) SetContext ¶
func (bot *Bot) SetContext(context interface{})
SetContext stores an object that holds application-specific information in the bot object. It can be any user-defined object, and then must be cast back to the original type.
type CommandHandler ¶
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler runs a particular function in response to a particular command, prefixed with a slash.
func NewCommandHandler ¶
func NewCommandHandler(command string, handler HandlerFunc) *CommandHandler
NewCommandHandler creates a new handler for a particular command.
func (*CommandHandler) Filter ¶
func (handler *CommandHandler) Filter() Filter
type Filter ¶
Filter represents a generic, reusable object for checking whether an update applies to a handler.
type Handler ¶
Handler represents a way of handling an update. It must implement:
Filter() *Filter This method returns the filter responsible for checking whether the handler applies to this update. If the filter returns true, Handle will be called with the update as its arg Handle(*Bot, tgbotapi.Update) error This method is responsible for handling the update, including sending of any messages.