Merge pull request #8 from OvyFlash/bot-api-6.7

BOT API 6.7 implementation
pull/9/head
OvyFlash 2023-07-05 12:14:19 +03:00 committed by GitHub
commit 3c3091bd33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 149 additions and 13 deletions

View File

@ -1271,6 +1271,20 @@ func (config DeleteWebhookConfig) params() (Params, error) {
return params, nil 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. // InlineConfig contains information on making an InlineQuery response.
type InlineConfig struct { type InlineConfig struct {
InlineQueryID string `json:"inline_query_id"` InlineQueryID string `json:"inline_query_id"`
@ -1278,8 +1292,7 @@ type InlineConfig struct {
CacheTime int `json:"cache_time"` CacheTime int `json:"cache_time"`
IsPersonal bool `json:"is_personal"` IsPersonal bool `json:"is_personal"`
NextOffset string `json:"next_offset"` NextOffset string `json:"next_offset"`
SwitchPMText string `json:"switch_pm_text"` Button *InlineQueryResultsButton `json:"button,omitempty"`
SwitchPMParameter string `json:"switch_pm_parameter"`
} }
func (config InlineConfig) method() string { func (config InlineConfig) method() string {
@ -1293,9 +1306,11 @@ func (config InlineConfig) params() (Params, error) {
params.AddNonZero("cache_time", config.CacheTime) params.AddNonZero("cache_time", config.CacheTime)
params.AddBool("is_personal", config.IsPersonal) params.AddBool("is_personal", config.IsPersonal)
params.AddNonEmpty("next_offset", config.NextOffset) params.AddNonEmpty("next_offset", config.NextOffset)
params.AddNonEmpty("switch_pm_text", config.SwitchPMText) err := params.AddInterface("button", config.Button)
params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter) if err != nil {
err := params.AddInterface("results", config.Results) return params, err
}
err = params.AddInterface("results", config.Results)
return params, err return params, err
} }
@ -2795,6 +2810,41 @@ func (config DeleteMyCommandsConfig) params() (Params, error) {
return params, err 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 // GetMyDescriptionConfig get the current bot description for the given user language
type GetMyDescriptionConfig struct { type GetMyDescriptionConfig struct {
LanguageCode string LanguageCode string

View File

@ -723,6 +723,15 @@ func NewInlineKeyboardButtonWebApp(text string, webapp WebAppInfo) InlineKeyboar
} }
} }
// 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 // NewInlineKeyboardButtonLoginURL creates an inline keyboard button with text
// which goes to a LoginURL. // which goes to a LoginURL.
func NewInlineKeyboardButtonLoginURL(text string, loginURL LoginURL) InlineKeyboardButton { func NewInlineKeyboardButtonLoginURL(text string, loginURL LoginURL) InlineKeyboardButton {
@ -961,6 +970,21 @@ func NewGetMyShortDescription(languageCode string) GetMyShortDescriptionConfig {
} }
} }
// 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,
}
}
// NewGetMyCommandsWithScope allows you to set the registered commands for a // NewGetMyCommandsWithScope allows you to set the registered commands for a
// given scope. // given scope.
func NewGetMyCommandsWithScope(scope BotCommandScope) GetMyCommandsConfig { func NewGetMyCommandsWithScope(scope BotCommandScope) GetMyCommandsConfig {

View File

@ -178,6 +178,25 @@ func TestNewInlineKeyboardButtonLoginURL(t *testing.T) {
} }
} }
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) { func TestNewEditMessageText(t *testing.T) {
edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text") edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")

View File

@ -1349,10 +1349,14 @@ type ChatShared struct {
ChatID int64 `json:"chat_id"` ChatID int64 `json:"chat_id"`
} }
// WriteAccessAllowed represents a service message about a user // WriteAccessAllowed represents a service message about a user allowing a bot
// allowing a bot added to the attachment menu to write messages. // to write messages after adding the bot to the attachment menu or launching
// Currently holds no information. // a Web App from a link.
type WriteAccessAllowed struct { type WriteAccessAllowed struct {
//Name of the Web App which was launched from a link
//
// Optional
WebAppName string `json:"web_app_name,omitempty"`
} }
// VideoChatScheduled represents a service message about a voice chat scheduled // VideoChatScheduled represents a service message about a voice chat scheduled
@ -1677,6 +1681,12 @@ type InlineKeyboardButton struct {
// //
// optional // optional
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` 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. // CallbackGame description of the game that will be launched when the user presses the button.
// //
// optional // optional
@ -2056,6 +2066,11 @@ type ChatMemberUpdated struct {
// //
// optional // optional
InviteLink *ChatInviteLink `json:"invite_link,omitempty"` 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. // ChatJoinRequest represents a join request sent to a chat.
@ -2573,6 +2588,32 @@ type GameHighScore struct {
// CallbackGame is for starting a game in an inline keyboard button. // CallbackGame is for starting a game in an inline keyboard button.
type CallbackGame struct{} 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. // WebhookInfo is information about a currently set webhook.
type WebhookInfo struct { type WebhookInfo struct {
// URL webhook URL, may be empty if webhook is not set up. // URL webhook URL, may be empty if webhook is not set up.

View File

@ -369,6 +369,8 @@ var (
_ Chattable = SetMyDescriptionConfig{} _ Chattable = SetMyDescriptionConfig{}
_ Chattable = GetMyShortDescriptionConfig{} _ Chattable = GetMyShortDescriptionConfig{}
_ Chattable = SetMyShortDescriptionConfig{} _ Chattable = SetMyShortDescriptionConfig{}
_ Chattable = GetMyNameConfig{}
_ Chattable = SetMyNameConfig{}
) )
// Ensure all Fileable types are correct. // Ensure all Fileable types are correct.