all repos — telegram-bot-api @ 05e04b526c693e3e104feaa0be23611836af3dcc

Golang bindings for the Telegram Bot API

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
commit

05e04b526c693e3e104feaa0be23611836af3dcc

parent

b2639432203d8b46127b037f03475c18846becf3

2 files changed, 35 insertions(+), 0 deletions(-)

jump to
M bot.gobot.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 +}
M types.gotypes.go

@@ -1005,3 +1005,9 @@

func (e Error) Error() string { return e.Message } + +// BotCommand represents a bot command. +type BotCommand struct { + Command string `json:"command"` + Description string `json:"description"` +}