BOT API 6.7 implementation
stdkhai k.o.zhuk@student.khai,edu
Wed, 05 Jul 2023 11:23:14 +0300
5 files changed,
150 insertions(+),
13 deletions(-)
M
configs.go
→
configs.go
@@ -1271,15 +1271,29 @@
return params, nil } +// InlineQueryResultsButton represents a button to be shown above inline query results. You must use exactly one of the optional fields. +type InlineQueryResultsButton struct { + //Label text on the button + // + Text string `json:"text"` + //Description of the Web App that will be launched when the user presses the button. The Web App will be able to switch back to the inline mode using the method switchInlineQuery inside the Web App. + // + //Optional + WebApp *WebAppInfo `json:"web_app,omitempty"` + // Deep-linking parameter for the /start message sent to the bot when a user presses the button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed. + // + //Optional + StartParam string `json:"start_parameter,omitempty"` +} + // InlineConfig contains information on making an InlineQuery response. type InlineConfig struct { - InlineQueryID string `json:"inline_query_id"` - Results []interface{} `json:"results"` - CacheTime int `json:"cache_time"` - IsPersonal bool `json:"is_personal"` - NextOffset string `json:"next_offset"` - SwitchPMText string `json:"switch_pm_text"` - SwitchPMParameter string `json:"switch_pm_parameter"` + InlineQueryID string `json:"inline_query_id"` + Results []interface{} `json:"results"` + CacheTime int `json:"cache_time"` + IsPersonal bool `json:"is_personal"` + NextOffset string `json:"next_offset"` + Button *InlineQueryResultsButton `json:"button,omitempty"` } func (config InlineConfig) method() string {@@ -1293,9 +1307,11 @@ params["inline_query_id"] = config.InlineQueryID
params.AddNonZero("cache_time", config.CacheTime) params.AddBool("is_personal", config.IsPersonal) params.AddNonEmpty("next_offset", config.NextOffset) - params.AddNonEmpty("switch_pm_text", config.SwitchPMText) - params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter) - err := params.AddInterface("results", config.Results) + err := params.AddInterface("button", config.Button) + if err != nil { + return params, err + } + err = params.AddInterface("results", config.Results) return params, err }@@ -2793,6 +2809,41 @@ err := params.AddInterface("scope", config.Scope)
params.AddNonEmpty("language_code", config.LanguageCode) return params, err +} + +// SetMyNameConfig change the bot's name +type SetMyNameConfig struct { + Name string + LanguageCode string +} + +func (config SetMyNameConfig) method() string { + return "setMyName" +} + +func (config SetMyNameConfig) params() (Params, error) { + params := make(Params) + + params.AddNonEmpty("name", config.Name) + params.AddNonEmpty("language_code", config.LanguageCode) + + return params, nil +} + +type GetMyNameConfig struct { + LanguageCode string +} + +func (config GetMyNameConfig) method() string { + return "getMyName" +} + +func (config GetMyNameConfig) params() (Params, error) { + params := make(Params) + + params.AddNonEmpty("language_code", config.LanguageCode) + + return params, nil } // GetMyDescriptionConfig get the current bot description for the given user language
M
helpers.go
→
helpers.go
@@ -723,6 +723,15 @@ WebApp: &webapp,
} } +// NewInlineKeyboardButtonSwitchInlineQueryChoosenChat creates an inline keyboard button with text +// which goes to a SwitchInlineQueryChosenChat. +func NewInlineKeyboardButtonSwitchInlineQueryChoosenChat(text string, switchInlineQueryChosenChat SwitchInlineQueryChosenChat) InlineKeyboardButton { + return InlineKeyboardButton{ + Text: text, + SwitchInlineQueryChosenChat: &switchInlineQueryChosenChat, + } +} + // NewInlineKeyboardButtonLoginURL creates an inline keyboard button with text // which goes to a LoginURL. func NewInlineKeyboardButtonLoginURL(text string, loginURL LoginURL) InlineKeyboardButton {@@ -957,6 +966,21 @@
// NewGetMyShortDescription returns the current bot short description for the given user language. func NewGetMyShortDescription(languageCode string) GetMyShortDescriptionConfig { return GetMyShortDescriptionConfig{ + LanguageCode: languageCode, + } +} + +// NewGetMyName get the current bot name for the given user language +func NewGetMyName(languageCode string) GetMyNameConfig { + return GetMyNameConfig{ + LanguageCode: languageCode, + } +} + +// NewSetMyName change the bot's name +func NewSetMyName(languageCode, name string) SetMyNameConfig { + return SetMyNameConfig{ + Name: name, LanguageCode: languageCode, } }
M
helpers_test.go
→
helpers_test.go
@@ -178,6 +178,25 @@ t.Fail()
} } +func TestNewInlineKeyboardButtonSwitchInlineQueryChoosenChat(t *testing.T) { + result := NewInlineKeyboardButtonSwitchInlineQueryChoosenChat("text", SwitchInlineQueryChosenChat{ + Query: "query", + AllowUserChats: false, + AllowBotChats: false, + AllowGroupChats: false, + AllowChannelChats: false, + }) + + if result.Text != "text" || + result.SwitchInlineQueryChosenChat.Query != "query" || + result.SwitchInlineQueryChosenChat.AllowUserChats != false || + result.SwitchInlineQueryChosenChat.AllowBotChats != false || + result.SwitchInlineQueryChosenChat.AllowGroupChats != false || + result.SwitchInlineQueryChosenChat.AllowChannelChats != false { + t.Fail() + } +} + func TestNewEditMessageText(t *testing.T) { edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")
M
types.go
→
types.go
@@ -1349,10 +1349,14 @@ // ChatID is an identifier of the shared chat.
ChatID int64 `json:"chat_id"` } -// WriteAccessAllowed represents a service message about a user -// allowing a bot added to the attachment menu to write messages. -// Currently holds no information. +// WriteAccessAllowed represents a service message about a user allowing a bot +// to write messages after adding the bot to the attachment menu or launching +// a Web App from a link. type WriteAccessAllowed struct { + //Name of the Web App which was launched from a link + // + // Optional + WebAppName string `json:"web_app_name"` } // VideoChatScheduled represents a service message about a voice chat scheduled@@ -1677,6 +1681,12 @@ // in the same chat – good for selecting something from multiple options.
// // optional SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` + //SwitchInlineQueryChosenChat If set, pressing the button will prompt the user to + //select one of their chats of the specified type, open that chat and insert the bot's + //username and the specified inline query in the input field + // + //optional + SwitchInlineQueryChosenChat *SwitchInlineQueryChosenChat `json:"switch_inline_query_chosen_chat,omitempty"` // CallbackGame description of the game that will be launched when the user presses the button. // // optional@@ -2056,6 +2066,11 @@ // for joining by invite link events only.
// // optional InviteLink *ChatInviteLink `json:"invite_link,omitempty"` + // ViaChatFolderInviteLink is True, if the user joined the chat + // via a chat folder invite link + // + // optional + ViaChatFolderInviteLink bool `json:"via_chat_folder_invite_link,omitempty"` } // ChatJoinRequest represents a join request sent to a chat.@@ -2572,6 +2587,32 @@ }
// CallbackGame is for starting a game in an inline keyboard button. type CallbackGame struct{} + +// SwitchInlineQueryChosenChat represents an inline button that switches the current +// user to inline mode in a chosen chat, with an optional default inline query. +type SwitchInlineQueryChosenChat struct { + // Query is default inline query to be inserted in the input field. + // If left empty, only the bot's username will be inserted + // + // optional + Query string `json:"query,omitempty"` + // AllowUserChats is True, if private chats with users can be chosen + // + // optional + AllowUserChats bool `json:"allow_user_chats,omitempty"` + // AllowBotChats is True, if private chats with bots can be chosen + // + // optional + AllowBotChats bool `json:"allow_bot_chats,omitempty"` + // AllowGroupChats is True, if group and supergroup chats can be chosen + // + // optional + AllowGroupChats bool `json:"allow_group_chats,omitempty"` + // AllowChannelChats is True, if channel chats can be chosen + // + // optional + AllowChannelChats bool `json:"allow_channel_chats,omitempty"` +} // WebhookInfo is information about a currently set webhook. type WebhookInfo struct {
M
types_test.go
→
types_test.go
@@ -369,6 +369,8 @@ _ Chattable = GetMyDescriptionConfig{}
_ Chattable = SetMyDescriptionConfig{} _ Chattable = GetMyShortDescriptionConfig{} _ Chattable = SetMyShortDescriptionConfig{} + _ Chattable = GetMyNameConfig{} + _ Chattable = SetMyNameConfig{} ) // Ensure all Fileable types are correct.