forked from c0re100/go-tdlib
/
botCommands.go
55 lines (46 loc) · 1.6 KB
/
botCommands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package tdlib
import (
"encoding/json"
"fmt"
)
// BotCommands Contains a list of bot commands
type BotCommands struct {
tdCommon
BotUserId int64 `json:"bot_user_id"` // Bot's user identifier
Commands []BotCommand `json:"commands"` // List of bot commands
}
// MessageType return the string telegram-type of BotCommands
func (botCommands *BotCommands) MessageType() string {
return "botCommands"
}
// NewBotCommands creates a new BotCommands
//
// @param botUserId Bot's user identifier
// @param commands List of bot commands
func NewBotCommands(botUserId int64, commands []BotCommand) *BotCommands {
botCommandsTemp := BotCommands{
tdCommon: tdCommon{Type: "botCommands"},
BotUserId: botUserId,
Commands: commands,
}
return &botCommandsTemp
}
// GetCommands Returns the list of commands supported by the bot for the given user scope and language; for bots only
// @param scope The scope to which the commands are relevant; pass null to get commands in the default bot command scope
// @param languageCode A two-letter ISO 639-1 country code or an empty string
func (client *Client) GetCommands(scope BotCommandScope, languageCode string) (*BotCommands, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getCommands",
"scope": scope,
"language_code": languageCode,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %v msg: %s", result.Data["code"], result.Data["message"])
}
var botCommands BotCommands
err = json.Unmarshal(result.Raw, &botCommands)
return &botCommands, err
}