Documentation
¶
Index ¶
- Constants
- type Attachment
- type Audio
- type Bot
- func (b *Bot) Delete(msg Editable) error
- func (b *Bot) DeleteCommands() error
- func (b *Bot) DeleteWebhook() error
- func (b *Bot) DemoteChatMember(chatID int64, userID int64) error
- func (b *Bot) Edit(msg Editable, what interface{}, opts ...interface{}) (*Message, error)
- func (b *Bot) GetChat(chatID int64) (*Chat, error)
- func (b *Bot) GetChatAdmins(chatID int64) ([]ChatMember, error)
- func (b *Bot) GetChatMember(chatID int64, userID int64) (*ChatMember, error)
- func (b *Bot) GetPinnedMessage(chatID int64) (*Message, error)
- func (b *Bot) GetUploadURL(fileType string) (*UploadInfo, error)
- func (b *Bot) GetWebhook() (*WebhookInfo, error)
- func (b *Bot) Handle(endpoint interface{}, handler HandlerFunc, m ...MiddlewareFunc)
- func (b *Bot) InviteChatMembers(chatID int64, userIDs []int64) error
- func (b *Bot) KickChatMember(chatID int64, userID int64) error
- func (b *Bot) LeaveChat(chatID int64) error
- func (b *Bot) Me() (*User, error)
- func (b *Bot) PinMessage(chatID int64, messageID string) error
- func (b *Bot) ProcessUpdate(u Update)
- func (b *Bot) PromoteChatMember(chatID int64, userID int64) error
- func (b *Bot) Raw(method, endpoint string, payload interface{}) ([]byte, error)
- func (b *Bot) Send(to Recipient, what interface{}, opts ...interface{}) (*Message, error)
- func (b *Bot) SendChatAction(chatID int64, action ChatAction) error
- func (b *Bot) SetCommands(commands []BotCommand) error
- func (b *Bot) SetWebhook(url string, updateTypes []string, secret string) error
- func (b *Bot) Start()
- func (b *Bot) UnpinMessage(chatID int64) error
- func (b *Bot) UploadFile(fileType string, fileName string, fileData []byte) (string, error)
- type BotCommand
- type CallbackQuery
- type CallbackResponse
- type Chat
- type ChatAction
- type ChatMember
- type Context
- type Document
- type EditMessage
- type Editable
- type HandlerFunc
- type InlineButton
- type LinkedMessage
- type LongPoller
- type MarkupElement
- type Message
- type MessageAttachment
- type MessageBody
- type MiddlewareFunc
- type Photo
- type Poller
- type Recipient
- type RecipientInfo
- type ReplyMarkup
- type SendMessage
- type SendOptions
- type Sendable
- type Settings
- type StoredMessage
- type Update
- type UploadInfo
- type User
- type Video
- type Webhook
- type WebhookInfo
Constants ¶
const ( DefaultAPIURL = "https://platform-api.max.ru" DefaultTimeout = 10 * time.Second )
const ( OnMessage = "\amessage" // любое входящее сообщение OnText = "\atext" // текстовое сообщение (без команд) OnCallback = "\acallback" // нажатие inline-кнопки OnPhoto = "\aphoto" OnVideo = "\avideo" OnAudio = "\aaudio" OnDocument = "\adocument" )
Common endpoint constants for message routing.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
Type string `json:"type"`
Payload map[string]interface{} `json:"payload,omitempty"`
}
Attachment represents a message attachment (keyboard, file, etc).
type Audio ¶
type Audio struct {
FileID string `json:"file_id"`
Duration int `json:"duration"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
Token string `json:"token,omitempty"`
}
Audio represents an audio file.
type Bot ¶
type Bot struct {
Token string
URL string
Poller Poller
Client *http.Client
Logger *log.Logger
// contains filtered or unexported fields
}
Bot represents a MAX bot instance.
func (*Bot) DeleteCommands ¶
DeleteCommands removes all bot commands.
func (*Bot) DeleteWebhook ¶
DeleteWebhook removes the webhook subscription.
func (*Bot) DemoteChatMember ¶
DemoteChatMember removes administrator rights from a user.
func (*Bot) GetChatAdmins ¶
func (b *Bot) GetChatAdmins(chatID int64) ([]ChatMember, error)
GetChatAdmins gets the list of chat administrators.
func (*Bot) GetChatMember ¶
func (b *Bot) GetChatMember(chatID int64, userID int64) (*ChatMember, error)
GetChatMember gets information about a specific chat member.
func (*Bot) GetPinnedMessage ¶
GetPinnedMessage retrieves the pinned message.
func (*Bot) GetUploadURL ¶
func (b *Bot) GetUploadURL(fileType string) (*UploadInfo, error)
GetUploadURL gets a URL for uploading files. fileType can be: "image", "video", "audio", "file"
func (*Bot) GetWebhook ¶
func (b *Bot) GetWebhook() (*WebhookInfo, error)
GetWebhook returns current webhook information.
func (*Bot) Handle ¶
func (b *Bot) Handle(endpoint interface{}, handler HandlerFunc, m ...MiddlewareFunc)
Handle registers a handler for the specified endpoint. Endpoint can be a string (command or endpoint constant) or *InlineButton. Middleware is applied in the order provided.
func (*Bot) InviteChatMembers ¶
InviteChatMembers adds users to the chat.
func (*Bot) KickChatMember ¶
KickChatMember removes a user from the chat.
func (*Bot) PinMessage ¶
PinMessage pins a message in the chat.
func (*Bot) ProcessUpdate ¶
ProcessUpdate processes a single update by finding and executing the appropriate handler.
func (*Bot) PromoteChatMember ¶
PromoteChatMember promotes a user to administrator.
func (*Bot) Send ¶
Send sends a message to the specified recipient. Returns the sent message or an error.
func (*Bot) SendChatAction ¶
func (b *Bot) SendChatAction(chatID int64, action ChatAction) error
SendChatAction sends a chat action (typing, sending photo, etc).
func (*Bot) SetCommands ¶
func (b *Bot) SetCommands(commands []BotCommand) error
SetCommands sets the bot's command list.
func (*Bot) SetWebhook ¶
SetWebhook registers a webhook URL with MAX API.
func (*Bot) Start ¶
func (b *Bot) Start()
Start begins the bot polling loop and blocks until stopped.
func (*Bot) UnpinMessage ¶
UnpinMessage unpins the pinned message.
type BotCommand ¶
BotCommand represents a bot command with description.
type CallbackQuery ¶
type CallbackQuery struct {
CallbackID string `json:"callback_id"`
Timestamp int64 `json:"timestamp"`
User *User `json:"user"`
Payload string `json:"payload"`
}
CallbackQuery represents a callback button press.
type CallbackResponse ¶
type CallbackResponse struct {
Text string `json:"text,omitempty"`
ShowAlert bool `json:"show_alert,omitempty"`
URL string `json:"url,omitempty"`
}
CallbackResponse represents a response to callback query.
type Chat ¶
type Chat struct {
ID int64 `json:"chat_id"`
Type string `json:"type"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
}
Chat represents a MAX chat.
type ChatAction ¶
type ChatAction string
ChatAction represents a bot action in chat (typing, sending media, etc).
const ( ActionTyping ChatAction = "typing_on" ActionSendingPhoto ChatAction = "sending_photo" ActionSendingVideo ChatAction = "sending_video" ActionSendingAudio ChatAction = "sending_audio" ActionSendingFile ChatAction = "sending_file" ActionMarkSeen ChatAction = "mark_seen" )
type ChatMember ¶
ChatMember represents a chat member with their status.
type Context ¶
type Context interface {
Bot() *Bot
Update() Update
Message() *Message
Callback() *CallbackQuery
Sender() *User
Chat() *Chat
Text() string
Args() []string
Payload() string
Send(what interface{}, opts ...interface{}) error
Reply(what interface{}, opts ...interface{}) error
Edit(what interface{}, opts ...interface{}) error
Delete() error
Respond(opts ...*CallbackResponse) error
Get(key string) interface{}
Set(key string, val interface{})
}
Context represents the context of an incoming update. It provides convenient methods to access update data and respond to users.
type Document ¶
type Document struct {
FileID string `json:"file_id"`
FileName string `json:"file_name"`
FileSize int `json:"file_size"`
Token string `json:"token,omitempty"`
}
Document represents a document file.
type EditMessage ¶
type EditMessage struct {
MessageID int `json:"message_id"`
ChatID int64 `json:"chat_id"`
Text string `json:"text"`
}
EditMessage represents a message edit request.
type HandlerFunc ¶
HandlerFunc represents a handler function for processing updates.
type InlineButton ¶
type InlineButton struct {
Text string `json:"text"`
Type string `json:"type"`
Payload string `json:"payload,omitempty"`
URL string `json:"url,omitempty"`
Data string `json:"-"` // используется для роутинга
}
InlineButton represents an inline keyboard button.
type LinkedMessage ¶ added in v0.1.1
type LinkedMessage struct {
// type может быть "reply" или "forward"
Type string `json:"type"`
Sender *User `json:"sender,omitempty"`
ChatID int64 `json:"chat_id,omitempty"`
Message *MessageBody `json:"message,omitempty"`
}
LinkedMessage представляет цитируемое или пересланное сообщение.
type LongPoller ¶
LongPoller implements long polling for receiving updates.
func (*LongPoller) Poll ¶
func (p *LongPoller) Poll(b *Bot, updates chan Update, stop chan struct{})
Poll starts the long polling loop.
type MarkupElement ¶ added in v0.1.1
type MarkupElement struct {
From int `json:"from"`
Length int `json:"length"`
Type string `json:"type"` // "emphasized", "strong", "strikethrough", etc.
}
MarkupElement представляет элемент форматирования текста (bold, italic и т.д.).
type Message ¶
type Message struct {
RecipientInfo *RecipientInfo `json:"recipient,omitempty"`
Sender *User `json:"sender,omitempty"`
Timestamp int64 `json:"timestamp"`
Body *MessageBody `json:"body,omitempty"`
}
Message represents a MAX message.
func (*Message) IsReply ¶ added in v0.1.1
IsReply reports whether the message is a reply to another message.
func (*Message) MessageSig ¶
MessageSig returns message signature for compatibility with Editable interface. Note: MAX API uses string mid, so message_id is always 0.
func (*Message) ReplyTo ¶ added in v0.1.1
func (m *Message) ReplyTo() *LinkedMessage
ReplyTo returns the message this message is a reply to, or nil.
type MessageAttachment ¶ added in v0.1.1
type MessageAttachment struct {
Type string `json:"type"`
CallbackID string `json:"callback_id,omitempty"`
Payload map[string]interface{} `json:"payload,omitempty"`
}
MessageAttachment представляет вложение в полученном сообщении.
type MessageBody ¶
type MessageBody struct {
Mid string `json:"mid"`
Seq int64 `json:"seq"`
Text string `json:"text"`
Attachments []MessageAttachment `json:"attachments,omitempty"`
Markup []MarkupElement `json:"markup,omitempty"`
// link содержит информацию о цитируемом сообщении (reply/forward).
// в MAX API это поле называется "link".
Link *LinkedMessage `json:"link,omitempty"`
}
MessageBody represents message content.
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc represents middleware that wraps a handler.
type Photo ¶
type Photo struct {
FileID string `json:"file_id"`
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url,omitempty"`
}
Photo represents a photo attachment.
type Recipient ¶
type Recipient interface {
Recipient() string
}
Recipient is any object that can receive messages.
type RecipientInfo ¶
type RecipientInfo struct {
ChatID int64 `json:"chat_id"`
ChatType string `json:"chat_type"`
UserID int64 `json:"user_id"`
}
RecipientInfo contains message recipient information.
type ReplyMarkup ¶
type ReplyMarkup struct {
InlineKeyboard [][]InlineButton `json:"inline_keyboard,omitempty"`
}
ReplyMarkup represents inline keyboard markup.
func (*ReplyMarkup) Data ¶
func (r *ReplyMarkup) Data(text, data string, payload ...interface{}) InlineButton
Data creates a callback button. If payload is provided as structured data, it will be marshaled to JSON.
func (*ReplyMarkup) Row ¶
func (r *ReplyMarkup) Row(buttons ...InlineButton)
Row adds a row of buttons to the keyboard.
func (*ReplyMarkup) URL ¶
func (r *ReplyMarkup) URL(text, url string) InlineButton
URL creates a link button.
type SendMessage ¶
type SendMessage struct {
ChatID string `json:"chat_id"`
Text string `json:"text"`
Format string `json:"format,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
}
SendMessage represents an outgoing message request.
type SendOptions ¶
type SendOptions struct {
Text string
Format string
Attachments []Attachment
}
SendOptions represents message sending options.
type Sendable ¶
type Sendable interface {
Send(*Bot, Recipient, *SendOptions) (*Message, error)
}
Sendable is any object that can send itself (photos, videos, etc).
type Settings ¶
type Settings struct {
URL string
Token string
Poller Poller
Logger *log.Logger
OnError func(error, Context)
}
Settings represents bot configuration.
type StoredMessage ¶
StoredMessage is a lightweight message reference for database storage.
func (*StoredMessage) MessageSig ¶
func (sm *StoredMessage) MessageSig() (int, int64)
type Update ¶
type Update struct {
UpdateType string `json:"update_type"`
Timestamp int64 `json:"timestamp"`
UserLocale string `json:"user_locale,omitempty"`
Message *Message `json:"message,omitempty"`
CallbackQuery *CallbackQuery `json:"callback,omitempty"`
}
Update represents an incoming update from MAX API.
type UploadInfo ¶
UploadInfo represents upload URL information from MAX API.
type User ¶
type User struct {
ID int64 `json:"user_id"`
Name string `json:"name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username,omitempty"`
IsBot bool `json:"is_bot"`
LastActivityAt int64 `json:"last_activity_time"`
}
User represents a MAX user.
type Video ¶
type Video struct {
FileID string `json:"file_id"`
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration"`
Token string `json:"token,omitempty"`
}
Video represents a video attachment.
type Webhook ¶
type Webhook struct {
Listen string // адрес для прослушивания, например ":8443"
Endpoint string // endpoint для webhook, например "/webhook"
URL string // публичный URL бота для регистрации
Secret string // секретный ключ для проверки
// contains filtered or unexported fields
}
Webhook implements webhook receiver for getting updates.
type WebhookInfo ¶
type WebhookInfo struct {
URL string `json:"url"`
UpdateTypes []string `json:"update_types,omitempty"`
Secret string `json:"secret,omitempty"`
}
WebhookInfo represents webhook subscription information.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package middleware provides common middleware implementations for maxbot.
|
Package middleware provides common middleware implementations for maxbot. |