BOT API 6.7 implementation

pull/8/head
stdkhai 2023-07-05 11:23:14 +03:00
parent c33a1d7c56
commit 7d82083b03
5 changed files with 150 additions and 13 deletions

View File

@ -1271,15 +1271,29 @@ func (config DeleteWebhookConfig) params() (Params, error) {
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 @@ func (config InlineConfig) params() (Params, error) {
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
}
@ -2795,6 +2811,41 @@ func (config DeleteMyCommandsConfig) params() (Params, error) {
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
type GetMyDescriptionConfig struct {
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
// which goes to a LoginURL.
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
// given scope.
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) {
edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")

View File

@ -1349,10 +1349,14 @@ type ChatShared struct {
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 @@ type InlineKeyboardButton struct {
//
// 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 @@ type ChatMemberUpdated struct {
//
// 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.
@ -2573,6 +2588,32 @@ type GameHighScore struct {
// 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 {
// URL webhook URL, may be empty if webhook is not set up.

View File

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