tgbot

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageLengthLimit = 4096
)

Variables

This section is empty.

Functions

func EscapeHTMLSymbols

func EscapeHTMLSymbols(str string) string

EscapeHTMLSymbols

< with &lt;
> with &gt;
& with &amp;

func EscapeStringForMarkdownV2

func EscapeStringForMarkdownV2(src string) string

EscapeForMarkdownV2

1. 任何字符码表在 1 到 126 之间的字符都可以加前缀 '\' 字符来转义,在这种情况下,它被视为一个普通字符,而不是标记的一部分。这意味着 '\' 字符通常必须加前缀 '\' 字符来转义。 2. 在 pre 和 code 的实体中,所有 '`' 和 '\' 字符都必须加前缀 '\' 字符转义。 3. 在所有其他地方,字符 '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!' 必须加前缀字符 '\' 转义。

https://core.telegram.org/bots/api#formatting-options

func FullNameFromFirstAndLastName

func FullNameFromFirstAndLastName(firstName, lastName string) string

func MapChatTypeToChineseText

func MapChatTypeToChineseText(chatType telegram.ChatType) string

func MapMemberStatusToChineseText

func MapMemberStatusToChineseText(memberStatus telegram.MemberStatus) string

func NewDispatcher

func NewDispatcher() func(logger *logger.Logger) *Dispatcher

func RemoveHTMLBlocksFromString added in v0.14.0

func RemoveHTMLBlocksFromString(str string) string

RemoveHTMLBlocksFromString

<any> with ""
</any> with ""

func ReplaceMarkdownTitlesToTelegramBoldElement

func ReplaceMarkdownTitlesToTelegramBoldElement(text string) string

func SplitMessagesAgainstLengthLimitIntoMessageGroups

func SplitMessagesAgainstLengthLimitIntoMessageGroups(originalSlice []string) [][]string

Types

type Bot

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

func (*Bot) AssignOneCallbackQueryData added in v0.14.0

func (b *Bot) AssignOneCallbackQueryData(route string, data any) (string, error)

func (*Bot) AssignOneNopCallbackQueryData added in v0.23.0

func (b *Bot) AssignOneNopCallbackQueryData() (string, error)

func (*Bot) DeleteAllDeleteLaterMessages added in v0.14.0

func (b *Bot) DeleteAllDeleteLaterMessages(forUserID int64) error

func (*Bot) IsBotAdministrator added in v0.14.0

func (b *Bot) IsBotAdministrator(chatID int64) (bool, error)

func (*Bot) IsBotWasBlockedByTheUserErr added in v0.14.0

func (b *Bot) IsBotWasBlockedByTheUserErr(err error) bool

func (*Bot) IsCannotInitiateChatWithUserErr added in v0.14.0

func (b *Bot) IsCannotInitiateChatWithUserErr(err error) bool

func (*Bot) IsGroupAnonymousBot added in v0.14.0

func (b *Bot) IsGroupAnonymousBot(user *tgbotapi.User) bool

func (*Bot) IsUserMemberStatus added in v0.14.0

func (b *Bot) IsUserMemberStatus(chatID int64, userID int64, status []telegram.MemberStatus) (bool, error)

func (*Bot) MayRequest added in v0.14.0

func (b *Bot) MayRequest(chattable tgbotapi.Chattable) *tgbotapi.APIResponse

func (*Bot) MaySend added in v0.14.0

func (b *Bot) MaySend(chattable tgbotapi.Chattable) *tgbotapi.Message

func (*Bot) PushOneDeleteLaterMessage added in v0.14.0

func (b *Bot) PushOneDeleteLaterMessage(forUserID int64, chatID int64, messageID int) error

func (*Bot) RateLimitForCommand added in v0.16.0

func (b *Bot) RateLimitForCommand(chatID int64, command string, rate int64, perDuration time.Duration) (int64, time.Duration, bool, error)

func (*Bot) RemoveInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith added in v0.19.0

func (b *Bot) RemoveInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith(inlineKeyboardMarkup tgbotapi.InlineKeyboardMarkup, callbackData string) tgbotapi.InlineKeyboardMarkup

func (*Bot) ReplaceInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith added in v0.19.0

func (b *Bot) ReplaceInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith(inlineKeyboardMarkup tgbotapi.InlineKeyboardMarkup, callbackData string, replacedButton tgbotapi.InlineKeyboardButton) tgbotapi.InlineKeyboardMarkup

type BotService

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

func NewBotService

func NewBotService(callOpts ...CallOption) (*BotService, error)

func (*BotService) Bot added in v0.14.0

func (b *BotService) Bot() *Bot

func (*BotService) Check

func (b *BotService) Check(ctx context.Context) error

func (*BotService) Start

func (b *BotService) Start(ctx context.Context) error

func (*BotService) Stop

func (b *BotService) Stop(ctx context.Context) error

type BotServiceOptions

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

type CallOption

type CallOption func(*BotServiceOptions)

func WithAPIEndpoint added in v0.16.0

func WithAPIEndpoint(endpoint string) CallOption

func WithDispatcher

func WithDispatcher(dispatcher *Dispatcher) CallOption

func WithLogger

func WithLogger(logger *logger.Logger) CallOption

func WithRueidisClient added in v0.14.0

func WithRueidisClient(client rueidis.Client) CallOption

func WithToken

func WithToken(token string) CallOption

func WithWebhookPort

func WithWebhookPort(port string) CallOption

func WithWebhookURL

func WithWebhookURL(url string) CallOption

type Command added in v0.14.0

type Command struct {
	Command     string
	HelpMessage string
	Handler     Handler
}

type Context

type Context struct {
	Bot    *Bot
	Update tgbotapi.Update
	Logger *logger.Logger
	// contains filtered or unexported fields
}

func NewContext

func NewContext(bot *tgbotapi.BotAPI, update tgbotapi.Update, logger *logger.Logger, rueidisClient rueidis.Client) *Context

func (*Context) Abort added in v0.14.0

func (c *Context) Abort()

func (*Context) BindFromCallbackQueryData added in v0.14.0

func (c *Context) BindFromCallbackQueryData(dst any) error

func (*Context) IsAborted added in v0.14.0

func (c *Context) IsAborted() bool

func (*Context) IsBotAdministrator added in v0.14.0

func (c *Context) IsBotAdministrator() (bool, error)

func (*Context) IsUserMemberStatus added in v0.14.0

func (c *Context) IsUserMemberStatus(userID int64, status []telegram.MemberStatus) (bool, error)

func (*Context) NewEditMessageReplyMarkup added in v0.14.0

func (c *Context) NewEditMessageReplyMarkup(messageID int, replyMarkup tgbotapi.InlineKeyboardMarkup) EditMessageResponse

func (*Context) NewEditMessageText

func (c *Context) NewEditMessageText(messageID int, text string) EditMessageResponse

func (*Context) NewEditMessageTextAndReplyMarkup

func (c *Context) NewEditMessageTextAndReplyMarkup(messageID int, text string, replyMarkup tgbotapi.InlineKeyboardMarkup) EditMessageResponse

func (*Context) NewMessage

func (c *Context) NewMessage(message string) MessageResponse

func (*Context) NewMessageReplyTo

func (c *Context) NewMessageReplyTo(message string, replyToMessageID int) MessageResponse

func (*Context) RateLimitForCommand added in v0.16.0

func (c *Context) RateLimitForCommand(chatID int64, command string, rate int64, perDuration time.Duration) (int64, time.Duration, bool, error)

func (*Context) UpdateType

func (c *Context) UpdateType() UpdateType

type Dispatcher

type Dispatcher struct {
	Logger *logger.Logger
	// contains filtered or unexported fields
}

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(bot *tgbotapi.BotAPI, update tgbotapi.Update, rueidisClient rueidis.Client)

func (*Dispatcher) OnCallbackQuery

func (d *Dispatcher) OnCallbackQuery(route string, h Handler)

func (*Dispatcher) OnCancelCommand added in v0.14.0

func (d *Dispatcher) OnCancelCommand(cancelHandler func(c *Context) (bool, error), handler Handler)

func (*Dispatcher) OnChannelPost

func (d *Dispatcher) OnChannelPost(handler Handler)

func (*Dispatcher) OnChatMigrationFrom added in v0.20.0

func (d *Dispatcher) OnChatMigrationFrom(h Handler)

func (*Dispatcher) OnCommand

func (d *Dispatcher) OnCommand(cmd, commandHelp string, h Handler)

func (*Dispatcher) OnCommandGroup added in v0.14.0

func (d *Dispatcher) OnCommandGroup(groupName string, group []Command)

func (*Dispatcher) OnLeftChatMember added in v0.17.0

func (d *Dispatcher) OnLeftChatMember(h Handler)

func (*Dispatcher) OnMyChatMember added in v0.17.0

func (d *Dispatcher) OnMyChatMember(handler Handler)

func (*Dispatcher) OnNewChatMember added in v0.17.0

func (d *Dispatcher) OnNewChatMember(h Handler)

func (*Dispatcher) OnStartCommand added in v0.14.0

func (d *Dispatcher) OnStartCommand(h Handler)

func (*Dispatcher) Use

func (d *Dispatcher) Use(middleware MiddlewareFunc)

type EditMessageResponse

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

func NewEditMessageReplyMarkup added in v0.14.0

func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup tgbotapi.InlineKeyboardMarkup) EditMessageResponse

func NewEditMessageText

func NewEditMessageText(chatID int64, messageID int, text string) EditMessageResponse

func NewEditMessageTextAndReplyMarkup

func NewEditMessageTextAndReplyMarkup(chatID int64, messageID int, text string, replyMarkup tgbotapi.InlineKeyboardMarkup) EditMessageResponse

func (EditMessageResponse) WithEditMessageCaptionConfig

func (r EditMessageResponse) WithEditMessageCaptionConfig(config tgbotapi.EditMessageCaptionConfig) EditMessageResponse

func (EditMessageResponse) WithEditMessageLiveLocationConfig

func (r EditMessageResponse) WithEditMessageLiveLocationConfig(config tgbotapi.EditMessageLiveLocationConfig) EditMessageResponse

func (EditMessageResponse) WithEditMessageMediaConfig

func (r EditMessageResponse) WithEditMessageMediaConfig(config tgbotapi.EditMessageMediaConfig) EditMessageResponse

func (EditMessageResponse) WithEditMessageReplyMarkupConfig

func (r EditMessageResponse) WithEditMessageReplyMarkupConfig(config tgbotapi.EditMessageReplyMarkupConfig) EditMessageResponse

func (EditMessageResponse) WithEditMessageTextConfig

func (r EditMessageResponse) WithEditMessageTextConfig(config tgbotapi.EditMessageTextConfig) EditMessageResponse

func (EditMessageResponse) WithInlineReplyMarkup added in v0.14.0

func (r EditMessageResponse) WithInlineReplyMarkup(inlineMarkup tgbotapi.InlineKeyboardMarkup) EditMessageResponse

func (EditMessageResponse) WithParseModeHTML

func (r EditMessageResponse) WithParseModeHTML() EditMessageResponse

type ExceptionError

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

func NewExceptionError

func NewExceptionError(err error) ExceptionError

func (ExceptionError) Error

func (e ExceptionError) Error() string

func (ExceptionError) WithDeleteLater added in v0.14.0

func (e ExceptionError) WithDeleteLater(userID int64, chatID int64) ExceptionError

func (ExceptionError) WithEdit

func (e ExceptionError) WithEdit(message *tgbotapi.Message) ExceptionError

func (ExceptionError) WithMessage

func (e ExceptionError) WithMessage(message string) ExceptionError

func (ExceptionError) WithReply

func (e ExceptionError) WithReply(message *tgbotapi.Message) ExceptionError

func (ExceptionError) WithReplyMarkup added in v0.14.0

func (e ExceptionError) WithReplyMarkup(replyMarkup tgbotapi.InlineKeyboardMarkup) ExceptionError

type HandleFunc

type HandleFunc func(ctx *Context) (Response, error)

type Handler

type Handler interface {
	Handle(c *Context) (Response, error)
}

func NewHandler

func NewHandler(h HandleFunc) Handler

type HandlerGroup

type HandlerGroup interface {
	Install(dispatcher *Dispatcher)
}

type MessageError

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

func NewMessageError

func NewMessageError(message string) MessageError

func (MessageError) Error

func (e MessageError) Error() string

func (MessageError) WithDeleteLater added in v0.14.0

func (e MessageError) WithDeleteLater(userID int64, chatID int64) MessageError

func (MessageError) WithEdit

func (e MessageError) WithEdit(message *tgbotapi.Message) MessageError

func (MessageError) WithParseModeHTML added in v0.14.0

func (e MessageError) WithParseModeHTML() MessageError

func (MessageError) WithReply

func (e MessageError) WithReply(message *tgbotapi.Message) MessageError

func (MessageError) WithReplyMarkup added in v0.14.0

func (e MessageError) WithReplyMarkup(replyMarkup tgbotapi.InlineKeyboardMarkup) MessageError

type MessageResponse

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

func NewMessage

func NewMessage(chatID int64, message string) MessageResponse

func NewMessageReplyTo

func NewMessageReplyTo(chatID int64, message string, replyToMessageID int) MessageResponse

func (MessageResponse) WithDeleteLater added in v0.14.0

func (r MessageResponse) WithDeleteLater(userID int64, chatID int64) MessageResponse

func (MessageResponse) WithMessageConfig

func (r MessageResponse) WithMessageConfig(config tgbotapi.MessageConfig) MessageResponse

func (MessageResponse) WithParseModeHTML

func (r MessageResponse) WithParseModeHTML() MessageResponse

func (MessageResponse) WithReplyMarkup

func (r MessageResponse) WithReplyMarkup(replyMarkup any) MessageResponse

type MiddlewareFunc

type MiddlewareFunc func(ctx *Context, next func())

type Response

type Response interface{}

type UpdateType

type UpdateType string
const (
	UpdateTypeUnknown            UpdateType = "unknown"
	UpdateTypeMessage            UpdateType = "message"
	UpdateTypeEditedMessage      UpdateType = "edited_message"
	UpdateTypeChannelPost        UpdateType = "channel_post"
	UpdateTypeEditedChannelPost  UpdateType = "edited_channel_post"
	UpdateTypeInlineQuery        UpdateType = "inline_query"
	UpdateTypeChosenInlineResult UpdateType = "chosen_inline_result"
	UpdateTypeCallbackQuery      UpdateType = "callback_query"
	UpdateTypeShippingQuery      UpdateType = "shipping_query"
	UpdateTypePreCheckoutQuery   UpdateType = "pre_checkout_query"
	UpdateTypePoll               UpdateType = "poll"
	UpdateTypePollAnswer         UpdateType = "poll_answer"
	UpdateTypeMyChatMember       UpdateType = "my_chat_member"
	UpdateTypeChatMember         UpdateType = "chat_member"
	UpdateTypeLeftChatMember     UpdateType = "left_chat_member"
	UpdateTypeNewChatMembers     UpdateType = "new_chat_members"
	UpdateTypeChatJoinRequest    UpdateType = "chat_join_request"
	UpdateTypeChatMigrationFrom  UpdateType = "chat_migration_from"
	UpdateTypeChatMigrationTo    UpdateType = "chat_migration_to"
)

Jump to

Keyboard shortcuts

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