Merge pull request #374 from bcmk/upstream-my-commands
getMyCommands / setMyCommands implementedbot-api-6.1
commit
05e04b526c
29
bot.go
29
bot.go
|
@ -1036,3 +1036,32 @@ func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error)
|
||||||
}
|
}
|
||||||
return stickerSet, nil
|
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
|
||||||
|
}
|
||||||
|
|
6
types.go
6
types.go
|
@ -1005,3 +1005,9 @@ type Error struct {
|
||||||
func (e Error) Error() string {
|
func (e Error) Error() string {
|
||||||
return e.Message
|
return e.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BotCommand represents a bot command.
|
||||||
|
type BotCommand struct {
|
||||||
|
Command string `json:"command"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue