From 4a2c8c4547a868841c1ec088302b23b59443de2b Mon Sep 17 00:00:00 2001 From: bcmk <45658475+bcmk@users.noreply.github.com> Date: Sun, 27 Sep 2020 00:55:26 +0400 Subject: [PATCH 1/2] setMyCommands implemented --- bot.go | 15 +++++++++++++++ types.go | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/bot.go b/bot.go index e8e1a7c..83903d4 100644 --- a/bot.go +++ b/bot.go @@ -1036,3 +1036,18 @@ func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) } return stickerSet, nil } + +// SetMyCommands changes the list of the bot's commands. +func (bot *BotAPI) SetMyCommands(commands []BotCommand) error { + v := url.Values{} + data, err := json.Marshal(commands) + if err != nil { + return err + } + v.Add("commands", string(data)) + _, err = bot.MakeRequest("setMyCommands", v) + if err != nil { + return err + } + return nil +} diff --git a/types.go b/types.go index 5e95678..a4a9625 100644 --- a/types.go +++ b/types.go @@ -1005,3 +1005,9 @@ type Error struct { func (e Error) Error() string { return e.Message } + +// BotCommand represents a bot command. +type BotCommand struct { + Command string `json:"command"` + Description string `json:"description"` +} From e7590a0638df29ec1e28568b1195362642daf74a Mon Sep 17 00:00:00 2001 From: bcmk <45658475+bcmk@users.noreply.github.com> Date: Sun, 27 Sep 2020 01:54:11 +0400 Subject: [PATCH 2/2] getMyCommands implemented --- bot.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bot.go b/bot.go index 83903d4..cffe4c2 100644 --- a/bot.go +++ b/bot.go @@ -1037,6 +1037,20 @@ func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) return stickerSet, nil } +// GetMyCommands gets the current list of the bot's commands. +func (bot *BotAPI) GetMyCommands() ([]BotCommand, error) { + res, err := bot.MakeRequest("getMyCommands", nil) + if err != nil { + return nil, err + } + var commands []BotCommand + err = json.Unmarshal(res.Result, &commands) + if err != nil { + return nil, err + } + return commands, nil +} + // SetMyCommands changes the list of the bot's commands. func (bot *BotAPI) SetMyCommands(commands []BotCommand) error { v := url.Values{}