Updates for Bot API 5.3.
parent
fb1de2fb48
commit
66dc9e8246
4
bot.go
4
bot.go
|
@ -667,9 +667,7 @@ func (bot *BotAPI) StopPoll(config StopPollConfig) (Poll, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMyCommands gets the currently registered commands.
|
// GetMyCommands gets the currently registered commands.
|
||||||
func (bot *BotAPI) GetMyCommands() ([]BotCommand, error) {
|
func (bot *BotAPI) GetMyCommands(config GetMyCommandsConfig) ([]BotCommand, error) {
|
||||||
config := GetMyCommandsConfig{}
|
|
||||||
|
|
||||||
resp, err := bot.Request(config)
|
resp, err := bot.Request(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
26
bot_test.go
26
bot_test.go
|
@ -953,7 +953,7 @@ func TestSendDice(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCommands(t *testing.T) {
|
func TestCommands(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
setCommands := NewSetMyCommands(BotCommand{
|
setCommands := NewSetMyCommands(BotCommand{
|
||||||
|
@ -965,7 +965,7 @@ func TestSetCommands(t *testing.T) {
|
||||||
t.Error("Unable to set commands")
|
t.Error("Unable to set commands")
|
||||||
}
|
}
|
||||||
|
|
||||||
commands, err := bot.GetMyCommands()
|
commands, err := bot.GetMyCommands(NewGetMyCommands())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Unable to get commands")
|
t.Error("Unable to get commands")
|
||||||
}
|
}
|
||||||
|
@ -977,6 +977,28 @@ func TestSetCommands(t *testing.T) {
|
||||||
if commands[0].Command != "test" || commands[0].Description != "a test command" {
|
if commands[0].Command != "test" || commands[0].Description != "a test command" {
|
||||||
t.Error("Commands were incorrectly set")
|
t.Error("Commands were incorrectly set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCommands = NewSetMyCommandsWithScope(NewBotCommandScopeAllPrivateChats(), BotCommand{
|
||||||
|
Command: "private",
|
||||||
|
Description: "a private command",
|
||||||
|
})
|
||||||
|
|
||||||
|
if _, err := bot.Request(setCommands); err != nil {
|
||||||
|
t.Error("Unable to set commands")
|
||||||
|
}
|
||||||
|
|
||||||
|
commands, err = bot.GetMyCommands(NewGetMyCommandsWithScope(NewBotCommandScopeAllPrivateChats()))
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Unable to get commands")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commands) != 1 {
|
||||||
|
t.Error("Incorrect number of commands returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
if commands[0].Command != "private" || commands[0].Description != "a private command" {
|
||||||
|
t.Error("Commands were incorrectly set")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEditMessageMedia(t *testing.T) {
|
func TestEditMessageMedia(t *testing.T) {
|
||||||
|
|
40
configs.go
40
configs.go
|
@ -2062,19 +2062,29 @@ func (config DiceConfig) params() (Params, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMyCommandsConfig gets a list of the currently registered commands.
|
// GetMyCommandsConfig gets a list of the currently registered commands.
|
||||||
type GetMyCommandsConfig struct{}
|
type GetMyCommandsConfig struct {
|
||||||
|
Scope *BotCommandScope
|
||||||
|
LanguageCode string
|
||||||
|
}
|
||||||
|
|
||||||
func (config GetMyCommandsConfig) method() string {
|
func (config GetMyCommandsConfig) method() string {
|
||||||
return "getMyCommands"
|
return "getMyCommands"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config GetMyCommandsConfig) params() (Params, error) {
|
func (config GetMyCommandsConfig) params() (Params, error) {
|
||||||
return nil, nil
|
params := make(Params)
|
||||||
|
|
||||||
|
err := params.AddInterface("scope", config.Scope)
|
||||||
|
params.AddNonEmpty("language_code", config.LanguageCode)
|
||||||
|
|
||||||
|
return params, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMyCommandsConfig sets a list of commands the bot understands.
|
// SetMyCommandsConfig sets a list of commands the bot understands.
|
||||||
type SetMyCommandsConfig struct {
|
type SetMyCommandsConfig struct {
|
||||||
commands []BotCommand
|
Commands []BotCommand
|
||||||
|
Scope *BotCommandScope
|
||||||
|
LanguageCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config SetMyCommandsConfig) method() string {
|
func (config SetMyCommandsConfig) method() string {
|
||||||
|
@ -2084,7 +2094,29 @@ func (config SetMyCommandsConfig) method() string {
|
||||||
func (config SetMyCommandsConfig) params() (Params, error) {
|
func (config SetMyCommandsConfig) params() (Params, error) {
|
||||||
params := make(Params)
|
params := make(Params)
|
||||||
|
|
||||||
err := params.AddInterface("commands", config.commands)
|
if err := params.AddInterface("commands", config.Commands); err != nil {
|
||||||
|
return params, err
|
||||||
|
}
|
||||||
|
err := params.AddInterface("scope", config.Scope)
|
||||||
|
params.AddNonEmpty("language_code", config.LanguageCode)
|
||||||
|
|
||||||
|
return params, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteMyCommandsConfig struct {
|
||||||
|
Scope *BotCommandScope
|
||||||
|
LanguageCode string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config DeleteMyCommandsConfig) method() string {
|
||||||
|
return "deleteMyCommands"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config DeleteMyCommandsConfig) params() (Params, error) {
|
||||||
|
params := make(Params)
|
||||||
|
|
||||||
|
err := params.AddInterface("scope", config.Scope)
|
||||||
|
params.AddNonEmpty("language_code", config.LanguageCode)
|
||||||
|
|
||||||
return params, err
|
return params, err
|
||||||
}
|
}
|
||||||
|
|
98
helpers.go
98
helpers.go
|
@ -837,7 +837,103 @@ func NewDiceWithEmoji(chatID int64, emoji string) DiceConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeDefault represents the default scope of bot commands.
|
||||||
|
func NewBotCommandScopeDefault() BotCommandScope {
|
||||||
|
return BotCommandScope{Type: "default"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeAllPrivateChats represents the scope of bot commands,
|
||||||
|
// covering all private chats.
|
||||||
|
func NewBotCommandScopeAllPrivateChats() BotCommandScope {
|
||||||
|
return BotCommandScope{Type: "all_private_chats"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeAllGroupChats represents the scope of bot commands,
|
||||||
|
// covering all group and supergroup chats.
|
||||||
|
func NewBotCommandScopeAllGroupChats() BotCommandScope {
|
||||||
|
return BotCommandScope{Type: "all_group_chats"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeAllChatAdministrators represents the scope of bot commands,
|
||||||
|
// covering all group and supergroup chat administrators.
|
||||||
|
func NewBotCommandScopeAllChatAdministrators() BotCommandScope {
|
||||||
|
return BotCommandScope{Type: "all_chat_administrators"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeChat represents the scope of bot commands, covering a
|
||||||
|
// specific chat.
|
||||||
|
func NewBotCommandScopeChat(chatID int64) BotCommandScope {
|
||||||
|
return BotCommandScope{
|
||||||
|
Type: "chat",
|
||||||
|
ChatID: chatID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeChatAdministrators represents the scope of bot commands,
|
||||||
|
// covering all administrators of a specific group or supergroup chat.
|
||||||
|
func NewBotCommandScopeChatAdministrators(chatID int64) BotCommandScope {
|
||||||
|
return BotCommandScope{
|
||||||
|
Type: "chat_administrators",
|
||||||
|
ChatID: chatID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBotCommandScopeChatMember represents the scope of bot commands, covering a
|
||||||
|
// specific member of a group or supergroup chat.
|
||||||
|
func NewBotCommandScopeChatMember(chatID, userID int64) BotCommandScope {
|
||||||
|
return BotCommandScope{
|
||||||
|
Type: "chat_member",
|
||||||
|
ChatID: chatID,
|
||||||
|
UserID: userID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGetMyCommands allows you to set the registered commands.
|
||||||
|
func NewGetMyCommands() GetMyCommandsConfig {
|
||||||
|
return GetMyCommandsConfig{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGetMyCommandsWithScope allows you to set the registered commands for a
|
||||||
|
// given scope.
|
||||||
|
func NewGetMyCommandsWithScope(scope BotCommandScope) GetMyCommandsConfig {
|
||||||
|
return GetMyCommandsConfig{Scope: &scope}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGetMyCommandsWithScopeAndLanguage allows you to set the registered
|
||||||
|
// commands for a given scope and language code.
|
||||||
|
func NewGetMyCommandsWithScopeAndLanguage(scope BotCommandScope, languageCode string) GetMyCommandsConfig {
|
||||||
|
return GetMyCommandsConfig{Scope: &scope, LanguageCode: languageCode}
|
||||||
|
}
|
||||||
|
|
||||||
// NewSetMyCommands allows you to set the registered commands.
|
// NewSetMyCommands allows you to set the registered commands.
|
||||||
func NewSetMyCommands(commands ...BotCommand) SetMyCommandsConfig {
|
func NewSetMyCommands(commands ...BotCommand) SetMyCommandsConfig {
|
||||||
return SetMyCommandsConfig{commands: commands}
|
return SetMyCommandsConfig{Commands: commands}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSetMyCommands allows you to set the registered commands for a given scope.
|
||||||
|
func NewSetMyCommandsWithScope(scope BotCommandScope, commands ...BotCommand) SetMyCommandsConfig {
|
||||||
|
return SetMyCommandsConfig{Commands: commands, Scope: &scope}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSetMyCommands allows you to set the registered commands for a given scope
|
||||||
|
// and language code.
|
||||||
|
func NewSetMyCommandsWithScopeAndLanguage(scope BotCommandScope, languageCode string, commands ...BotCommand) SetMyCommandsConfig {
|
||||||
|
return SetMyCommandsConfig{Commands: commands, Scope: &scope, LanguageCode: languageCode}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDeleteMyCommands allows you to delete the registered commands.
|
||||||
|
func NewDeleteMyCommands() DeleteMyCommandsConfig {
|
||||||
|
return DeleteMyCommandsConfig{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDeleteMyCommands allows you to delete the registered commands for a given
|
||||||
|
// scope.
|
||||||
|
func NewDeleteMyCommandsWithScope(scope BotCommandScope) DeleteMyCommandsConfig {
|
||||||
|
return DeleteMyCommandsConfig{Scope: &scope}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDeleteMyCommands allows you to delete the registered commands for a given
|
||||||
|
// scope and language code.
|
||||||
|
func NewDeleteMyCommandsWithScopeAndLanguage(scope BotCommandScope, languageCode string) DeleteMyCommandsConfig {
|
||||||
|
return DeleteMyCommandsConfig{Scope: &scope, LanguageCode: languageCode}
|
||||||
}
|
}
|
||||||
|
|
20
types.go
20
types.go
|
@ -1158,6 +1158,11 @@ type ReplyKeyboardMarkup struct {
|
||||||
//
|
//
|
||||||
// optional
|
// optional
|
||||||
OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`
|
OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`
|
||||||
|
// InputFieldPlaceholder is the placeholder to be shown in the input field when
|
||||||
|
// the keyboard is active; 1-64 characters.
|
||||||
|
//
|
||||||
|
// optional
|
||||||
|
InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"`
|
||||||
// Selective use this parameter if you want to show the keyboard to specific users only.
|
// Selective use this parameter if you want to show the keyboard to specific users only.
|
||||||
// Targets:
|
// Targets:
|
||||||
// 1) users that are @mentioned in the text of the Message object;
|
// 1) users that are @mentioned in the text of the Message object;
|
||||||
|
@ -1375,6 +1380,11 @@ type ForceReply struct {
|
||||||
// ForceReply shows reply interface to the user,
|
// ForceReply shows reply interface to the user,
|
||||||
// as if they manually selected the bot's message and tapped 'Reply'.
|
// as if they manually selected the bot's message and tapped 'Reply'.
|
||||||
ForceReply bool `json:"force_reply"`
|
ForceReply bool `json:"force_reply"`
|
||||||
|
// InputFieldPlaceholder is the placeholder to be shown in the input field when
|
||||||
|
// the reply is active; 1-64 characters.
|
||||||
|
//
|
||||||
|
// optional
|
||||||
|
InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"`
|
||||||
// Selective use this parameter if you want to force reply from specific users only.
|
// Selective use this parameter if you want to force reply from specific users only.
|
||||||
// Targets:
|
// Targets:
|
||||||
// 1) users that are @mentioned in the text of the Message object;
|
// 1) users that are @mentioned in the text of the Message object;
|
||||||
|
@ -1643,6 +1653,16 @@ type BotCommand struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BotCommandScope represents the scope to which bot commands are applied.
|
||||||
|
//
|
||||||
|
// It contains the fields for all types of scopes, different types only support
|
||||||
|
// specific (or no) fields.
|
||||||
|
type BotCommandScope struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
ChatID int64 `json:"chat_id,omitempty"`
|
||||||
|
UserID int64 `json:"user_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// ResponseParameters are various errors that can be returned in APIResponse.
|
// ResponseParameters are various errors that can be returned in APIResponse.
|
||||||
type ResponseParameters struct {
|
type ResponseParameters struct {
|
||||||
// The group has been migrated to a supergroup with the specified identifier.
|
// The group has been migrated to a supergroup with the specified identifier.
|
||||||
|
|
|
@ -293,6 +293,7 @@ var (
|
||||||
_ Chattable = DeleteChatPhotoConfig{}
|
_ Chattable = DeleteChatPhotoConfig{}
|
||||||
_ Chattable = DeleteChatStickerSetConfig{}
|
_ Chattable = DeleteChatStickerSetConfig{}
|
||||||
_ Chattable = DeleteMessageConfig{}
|
_ Chattable = DeleteMessageConfig{}
|
||||||
|
_ Chattable = DeleteMyCommandsConfig{}
|
||||||
_ Chattable = DeleteWebhookConfig{}
|
_ Chattable = DeleteWebhookConfig{}
|
||||||
_ Chattable = DocumentConfig{}
|
_ Chattable = DocumentConfig{}
|
||||||
_ Chattable = EditChatInviteLinkConfig{}
|
_ Chattable = EditChatInviteLinkConfig{}
|
||||||
|
|
Loading…
Reference in New Issue