telegrambot

package
v0.0.0-...-e985f82 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MaxInt int = int(MaxUint >> 1)
View Source
const MaxUint uint = ^uint(0)

Variables

View Source
var (
	ErrNoMessageID = errors.New("update does not contain a message ID")
	ErrNoUsername  = errors.New("user does not have a username")
)

Functions

func CommandArgs

func CommandArgs(update tgbotapi.Update) string

CommandArgs returns the arguments to a command as a single string. Alias of update.ChannelPost.CommandArguments

func CommandArgsSplit

func CommandArgsSplit(update tgbotapi.Update) []string

CommandArgsSplit returns the arguments to a command, split by space

func GetFromUser

func GetFromUser(update tgbotapi.Update) *tgbotapi.User

GetFromUser returns the User from whom the update was received, regardless of the true underlying type of the update.

func GetMessageObject

func GetMessageObject(update tgbotapi.Update) *tgbotapi.Message

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

func GetUpdateMessageID(update tgbotapi.Update) (int, error)

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

func GetUserFirstName(update tgbotapi.Update) string

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.

func GetUserID

func GetUserID(update tgbotapi.Update) int

GetUserID returns the ID of the user who sent this update. There is no error returned for this since a first name is required.

func GetUsername

func GetUsername(update tgbotapi.Update) (string, error)

GetUsername returns the ID of the user who sent this update. If the user does not have a username, ErrNoUsername is returned.

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

func (*AllMessageHandler) Handle

func (handler *AllMessageHandler) Handle(bot *Bot, update tgbotapi.Update) error

type Bot

type Bot struct {
	API *tgbotapi.BotAPI
	// contains filtered or unexported fields
}

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 NewBot

func NewBot(apiKey string) (*Bot, error)

func (*Bot) AddHandler

func (bot *Bot) AddHandler(handler Handler)

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

func (bot *Bot) HandleUpdates(poolSize int) error

HandleUpdates is the main method for the bot. It begins the loop of handling updates.

func (*Bot) ReplyToMsg

func (bot *Bot) ReplyToMsg(update tgbotapi.Update, text string, asReply bool) error

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.

func (*Bot) Shutdown

func (bot *Bot) Shutdown()

Shutdown waits for all handlers to finish and then gracefully shuts down the update handler and exits.

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

func (*CommandHandler) Handle

func (handler *CommandHandler) Handle(bot *Bot, update tgbotapi.Update) error

type Filter

type Filter interface {
	Test(tgbotapi.Update) bool
}

Filter represents a generic, reusable object for checking whether an update applies to a handler.

type Handler

type Handler interface {
	Filter() Filter
	Handle(*Bot, tgbotapi.Update) error
}

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.

type HandlerFunc

type HandlerFunc func(*Bot, tgbotapi.Update) error

Jump to

Keyboard shortcuts

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