Merge pull request #374 from bcmk/upstream-my-commands getMyCommands / setMyCommands implemented
TJ Horner me@tjhorner.com
Fri, 02 Oct 2020 21:17:27 -0700
M
bot.go
→
bot.go
@@ -1036,3 +1036,32 @@ return StickerSet{}, err
} 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{} + 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 +}