bot: implement menu button

pull/558/head
Demian 2 years ago
parent 4da4605bec
commit dc27c6cb4c

@ -971,13 +971,13 @@ func (b *Bot) EditMedia(msg Editable, media Inputtable, opts ...interface{}) (*M
// Delete removes the message, including service messages.
// This function will panic upon nil Editable.
//
// * A message can only be deleted if it was sent less than 48 hours ago.
// * A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
// * Bots can delete outgoing messages in private chats, groups, and supergroups.
// * Bots can delete incoming messages in private chats.
// * Bots granted can_post_messages permissions can delete outgoing messages in channels.
// * If the bot is an administrator of a group, it can delete any message there.
// * If the bot has can_delete_messages permission in a supergroup or a
// - A message can only be deleted if it was sent less than 48 hours ago.
// - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
// - Bots can delete outgoing messages in private chats, groups, and supergroups.
// - Bots can delete incoming messages in private chats.
// - Bots granted can_post_messages permissions can delete outgoing messages in channels.
// - If the bot is an administrator of a group, it can delete any message there.
// - If the bot has can_delete_messages permission in a supergroup or a
// channel, it can delete any message there.
//
func (b *Bot) Delete(msg Editable) error {
@ -1525,6 +1525,51 @@ func (b *Bot) DeleteCommands(opts ...interface{}) error {
return err
}
// MenuButton returns the current value of the bot's menu button in a private chat,
// or the default menu button.
func (b *Bot) MenuButton(chat *User) (*MenuButton, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
}
data, err := b.Raw("getChatMenuButton", params)
if err != nil {
return nil, err
}
var resp struct {
Result *MenuButton
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}
// SetMenuButton changes the bot's menu button in a private chat,
// or the default menu button.
//
// It accepts two kinds of menu button arguments:
//
// - MenuButtonType for simple menu buttons (default, commands)
// - MenuButton complete structure for web_app menu button type
//
func (b *Bot) SetMenuButton(chat *User, mb interface{}) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
switch v := mb.(type) {
case MenuButtonType:
params["menu_button"] = MenuButton{Type: v}
case *MenuButton:
params["menu_button"] = v
}
_, err := b.Raw("setChatMenuButton", params)
return err
}
// Logout logs out from the cloud Bot API server before launching the bot locally.
func (b *Bot) Logout() (bool, error) {
data, err := b.Raw("logOut", nil)

@ -336,18 +336,36 @@ type CommandParams struct {
// CommandScope object represents a scope to which bot commands are applied.
type CommandScope struct {
Type string `json:"type"`
ChatID int64 `json:"chat_id,omitempty"`
UserID int64 `json:"user_id,omitempty"`
Type CommandScopeType `json:"type"`
ChatID int64 `json:"chat_id,omitempty"`
UserID int64 `json:"user_id,omitempty"`
}
// CommandScope types
type CommandScopeType = string
// CommandScope types.
const (
CommandScopeDefault CommandScopeType = "default"
CommandScopeAllPrivateChats CommandScopeType = "all_private_chats"
CommandScopeAllGroupChats CommandScopeType = "all_group_chats"
CommandScopeAllChatAdmin CommandScopeType = "all_chat_administrators"
CommandScopeChat CommandScopeType = "chat"
CommandScopeChatAdmin CommandScopeType = "chat_administrators"
CommandScopeChatMember CommandScopeType = "chat_member"
)
// MenuButton describes the bot's menu button in a private chat.
type MenuButton struct {
Type MenuButtonType `json:"type"`
Text string `json:"text,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
}
type MenuButtonType = string
// MenuButton types.
const (
CommandScopeDefault = "default"
CommandScopeAllPrivateChats = "all_private_chats"
CommandScopeAllGroupChats = "all_group_chats"
CommandScopeAllChatAdmin = "all_chat_administrators"
CommandScopeChat = "chat"
CommandScopeChatAdmin = "chat_administrators"
CommandScopeChatMember = "chat_member"
MenuButtonDefault MenuButtonType = "default"
MenuButtonCommands MenuButtonType = "commands"
MenuButtonWebApp MenuButtonType = "web_app"
)

Loading…
Cancel
Save