Skip to content

Commit 05e04b5

Browse files
authored
Merge pull request #374 from bcmk/upstream-my-commands
getMyCommands / setMyCommands implemented
2 parents b263943 + e7590a0 commit 05e04b5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

bot.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,32 @@ func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error)
10361036
}
10371037
return stickerSet, nil
10381038
}
1039+
1040+
// GetMyCommands gets the current list of the bot's commands.
1041+
func (bot *BotAPI) GetMyCommands() ([]BotCommand, error) {
1042+
res, err := bot.MakeRequest("getMyCommands", nil)
1043+
if err != nil {
1044+
return nil, err
1045+
}
1046+
var commands []BotCommand
1047+
err = json.Unmarshal(res.Result, &commands)
1048+
if err != nil {
1049+
return nil, err
1050+
}
1051+
return commands, nil
1052+
}
1053+
1054+
// SetMyCommands changes the list of the bot's commands.
1055+
func (bot *BotAPI) SetMyCommands(commands []BotCommand) error {
1056+
v := url.Values{}
1057+
data, err := json.Marshal(commands)
1058+
if err != nil {
1059+
return err
1060+
}
1061+
v.Add("commands", string(data))
1062+
_, err = bot.MakeRequest("setMyCommands", v)
1063+
if err != nil {
1064+
return err
1065+
}
1066+
return nil
1067+
}

types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,3 +1005,9 @@ type Error struct {
10051005
func (e Error) Error() string {
10061006
return e.Message
10071007
}
1008+
1009+
// BotCommand represents a bot command.
1010+
type BotCommand struct {
1011+
Command string `json:"command"`
1012+
Description string `json:"description"`
1013+
}

0 commit comments

Comments
 (0)