Implement Bot API 6.4 changes

pull/4/head
OvyFlash 2022-12-31 02:15:29 +02:00
parent 26b0a55fe2
commit 5e115c98c7
4 changed files with 268 additions and 33 deletions

View File

@ -323,6 +323,21 @@ func (edit BaseEdit) params() (Params, error) {
return params, err return params, err
} }
// BaseSpoiler is base type of structures with spoilers.
type BaseSpoiler struct {
HasSpoiler bool
}
func (spoiler BaseSpoiler) params() (Params, error) {
params := make(Params)
if spoiler.HasSpoiler {
params.AddBool("has_spoiler", true)
}
return params, nil
}
// MessageConfig contains information about a SendMessage request. // MessageConfig contains information about a SendMessage request.
type MessageConfig struct { type MessageConfig struct {
BaseChat BaseChat
@ -407,6 +422,7 @@ func (config CopyMessageConfig) method() string {
// PhotoConfig contains information about a SendPhoto request. // PhotoConfig contains information about a SendPhoto request.
type PhotoConfig struct { type PhotoConfig struct {
BaseFile BaseFile
BaseSpoiler
Thumb RequestFileData Thumb RequestFileData
Caption string Caption string
ParseMode string ParseMode string
@ -422,6 +438,15 @@ func (config PhotoConfig) params() (Params, error) {
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
if err != nil {
return params, err
}
p1, err := config.BaseSpoiler.params()
if err != nil {
return params, err
}
params.Merge(p1)
return params, err return params, err
} }
@ -557,6 +582,7 @@ func (config StickerConfig) files() []RequestFile {
// VideoConfig contains information about a SendVideo request. // VideoConfig contains information about a SendVideo request.
type VideoConfig struct { type VideoConfig struct {
BaseFile BaseFile
BaseSpoiler
Thumb RequestFileData Thumb RequestFileData
Duration int Duration int
Caption string Caption string
@ -576,6 +602,15 @@ func (config VideoConfig) params() (Params, error) {
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("supports_streaming", config.SupportsStreaming) params.AddBool("supports_streaming", config.SupportsStreaming)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
if err != nil {
return params, err
}
p1, err := config.BaseSpoiler.params()
if err != nil {
return params, err
}
params.Merge(p1)
return params, err return params, err
} }
@ -603,6 +638,7 @@ func (config VideoConfig) files() []RequestFile {
// AnimationConfig contains information about a SendAnimation request. // AnimationConfig contains information about a SendAnimation request.
type AnimationConfig struct { type AnimationConfig struct {
BaseFile BaseFile
BaseSpoiler
Duration int Duration int
Thumb RequestFileData Thumb RequestFileData
Caption string Caption string
@ -620,6 +656,15 @@ func (config AnimationConfig) params() (Params, error) {
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
if err != nil {
return params, err
}
p1, err := config.BaseSpoiler.params()
if err != nil {
return params, err
}
params.Merge(p1)
return params, err return params, err
} }
@ -976,6 +1021,7 @@ func (config GetGameHighScoresConfig) method() string {
// ChatActionConfig contains information about a SendChatAction request. // ChatActionConfig contains information about a SendChatAction request.
type ChatActionConfig struct { type ChatActionConfig struct {
BaseChat BaseChat
MessageThreadID int
Action string // required Action string // required
} }
@ -983,6 +1029,7 @@ func (config ChatActionConfig) params() (Params, error) {
params, err := config.BaseChat.params() params, err := config.BaseChat.params()
params["action"] = config.Action params["action"] = config.Action
params.AddNonZero("message_thread_id", config.MessageThreadID)
return params, err return params, err
} }
@ -2314,14 +2361,27 @@ func (config GetForumTopicIconStickersConfig) params() (Params, error) {
return nil, nil return nil, nil
} }
// BaseForum is a base type for all forum config types.
type BaseForum struct {
ChatID int64
SuperGroupUsername string
}
func (config BaseForum) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
return params, nil
}
// CreateForumTopicConfig allows you to create a topic // CreateForumTopicConfig allows you to create a topic
// in a forum supergroup chat. // in a forum supergroup chat.
type CreateForumTopicConfig struct { type CreateForumTopicConfig struct {
ChatID int64 BaseForum
Name string Name string
IconColor int IconColor int
IconCustomEmojiID string IconCustomEmojiID string
SuperGroupUsername string
} }
func (config CreateForumTopicConfig) method() string { func (config CreateForumTopicConfig) method() string {
@ -2331,22 +2391,23 @@ func (config CreateForumTopicConfig) method() string {
func (config CreateForumTopicConfig) params() (Params, error) { func (config CreateForumTopicConfig) params() (Params, error) {
params := make(Params) params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonEmpty("name", config.Name) params.AddNonEmpty("name", config.Name)
params.AddNonZero("icon_color", config.IconColor) params.AddNonZero("icon_color", config.IconColor)
params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID) params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil return params, nil
} }
// EditForumTopicConfig allows you to edit // EditForumTopicConfig allows you to edit
// name and icon of a topic in a forum supergroup chat. // name and icon of a topic in a forum supergroup chat.
type EditForumTopicConfig struct { type EditForumTopicConfig struct {
ChatID int64 BaseForum
MessageThreadID int MessageThreadID int
Name string Name string
IconCustomEmojiID string IconCustomEmojiID string
SuperGroupUsername string
} }
func (config EditForumTopicConfig) method() string { func (config EditForumTopicConfig) method() string {
@ -2356,20 +2417,21 @@ func (config EditForumTopicConfig) method() string {
func (config EditForumTopicConfig) params() (Params, error) { func (config EditForumTopicConfig) params() (Params, error) {
params := make(Params) params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("message_thread_id", config.MessageThreadID) params.AddNonZero("message_thread_id", config.MessageThreadID)
params.AddNonEmpty("icon_color", config.Name) params.AddNonEmpty("name", config.Name)
params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID) params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil return params, nil
} }
// CloseForumTopicConfig allows you to close // CloseForumTopicConfig allows you to close
// an open topic in a forum supergroup chat. // an open topic in a forum supergroup chat.
type CloseForumTopicConfig struct { type CloseForumTopicConfig struct {
ChatID int64 BaseForum
MessageThreadID int MessageThreadID int
SuperGroupUsername string
} }
func (config CloseForumTopicConfig) method() string { func (config CloseForumTopicConfig) method() string {
@ -2379,18 +2441,19 @@ func (config CloseForumTopicConfig) method() string {
func (config CloseForumTopicConfig) params() (Params, error) { func (config CloseForumTopicConfig) params() (Params, error) {
params := make(Params) params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("message_thread_id", config.MessageThreadID) params.AddNonZero("message_thread_id", config.MessageThreadID)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil return params, nil
} }
// ReopenForumTopicConfig allows you to reopen // ReopenForumTopicConfig allows you to reopen
// an closed topic in a forum supergroup chat. // an closed topic in a forum supergroup chat.
type ReopenForumTopicConfig struct { type ReopenForumTopicConfig struct {
ChatID int64 BaseForum
MessageThreadID int MessageThreadID int
SuperGroupUsername string
} }
func (config ReopenForumTopicConfig) method() string { func (config ReopenForumTopicConfig) method() string {
@ -2403,15 +2466,17 @@ func (config ReopenForumTopicConfig) params() (Params, error) {
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("message_thread_id", config.MessageThreadID) params.AddNonZero("message_thread_id", config.MessageThreadID)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil return params, nil
} }
// DeleteForumTopicConfig allows you to delete a forum topic // DeleteForumTopicConfig allows you to delete a forum topic
// along with all its messages in a forum supergroup chat. // along with all its messages in a forum supergroup chat.
type DeleteForumTopicConfig struct { type DeleteForumTopicConfig struct {
ChatID int64 BaseForum
MessageThreadID int MessageThreadID int
SuperGroupUsername string
} }
func (config DeleteForumTopicConfig) method() string { func (config DeleteForumTopicConfig) method() string {
@ -2421,18 +2486,19 @@ func (config DeleteForumTopicConfig) method() string {
func (config DeleteForumTopicConfig) params() (Params, error) { func (config DeleteForumTopicConfig) params() (Params, error) {
params := make(Params) params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("message_thread_id", config.MessageThreadID) params.AddNonZero("message_thread_id", config.MessageThreadID)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil return params, nil
} }
// UnpinAllForumTopicMessagesConfig allows you to clear the list // UnpinAllForumTopicMessagesConfig allows you to clear the list
// of pinned messages in a forum topic. // of pinned messages in a forum topic.
type UnpinAllForumTopicMessagesConfig struct { type UnpinAllForumTopicMessagesConfig struct {
ChatID int64 BaseForum
MessageThreadID int MessageThreadID int
SuperGroupUsername string
} }
func (config UnpinAllForumTopicMessagesConfig) method() string { func (config UnpinAllForumTopicMessagesConfig) method() string {
@ -2445,15 +2511,84 @@ func (config UnpinAllForumTopicMessagesConfig) params() (Params, error) {
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("message_thread_id", config.MessageThreadID) params.AddNonZero("message_thread_id", config.MessageThreadID)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil return params, nil
} }
// UnpinAllForumTopicMessagesConfig allows you to edit the name of
// the 'General' topic in a forum supergroup chat.
// The bot must be an administrator in the chat for this to work
// and must have can_manage_topics administrator rights. Returns True on success.
type EditGeneralForumTopicConfig struct {
BaseForum
Name string
}
func (config EditGeneralForumTopicConfig) method() string {
return "editGeneralForumTopic"
}
func (config EditGeneralForumTopicConfig) params() (Params, error) {
params := make(Params)
params.AddNonEmpty("name", config.Name)
p1, _ := config.BaseForum.params()
params.Merge(p1)
return params, nil
}
// CloseGeneralForumTopicConfig allows you to to close an open 'General' topic
// in a forum supergroup chat. The bot must be an administrator in the chat
// for this to work and must have the can_manage_topics administrator rights.
// Returns True on success.
type CloseGeneralForumTopicConfig struct{ BaseForum }
func (config CloseGeneralForumTopicConfig) method() string {
return "closeGeneralForumTopic"
}
// CloseGeneralForumTopicConfig allows you to reopen a closed 'General' topic
// in a forum supergroup chat. The bot must be an administrator in the chat
// for this to work and must have the can_manage_topics administrator rights.
// The topic will be automatically unhidden if it was hidden.
// Returns True on success.
type ReopenGeneralForumTopicConfig struct{ BaseForum }
func (config ReopenGeneralForumTopicConfig) method() string {
return "reopenGeneralForumTopic"
}
// HideGeneralForumTopicConfig allows you to hide the 'General' topic
// in a forum supergroup chat. The bot must be an administrator in the chat
// for this to work and must have the can_manage_topics administrator rights.
// The topic will be automatically closed if it was open.
// Returns True on success.
type HideGeneralForumTopicConfig struct{ BaseForum }
func (config HideGeneralForumTopicConfig) method() string {
return "hideGeneralForumTopic"
}
// UnhideGeneralForumTopicConfig allows you to unhide the 'General' topic
// in a forum supergroup chat. The bot must be an administrator in the chat
// for this to work and must have the can_manage_topics administrator rights.
// Returns True on success.
type UnhideGeneralForumTopicConfig struct{ BaseForum }
func (config UnhideGeneralForumTopicConfig) method() string {
return "unhideGeneralForumTopic"
}
// MediaGroupConfig allows you to send a group of media. // MediaGroupConfig allows you to send a group of media.
// //
// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo). // Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
type MediaGroupConfig struct { type MediaGroupConfig struct {
BaseChat BaseChat
Media []interface{} Media []interface{}
} }
func (config MediaGroupConfig) method() string { func (config MediaGroupConfig) method() string {

View File

@ -95,3 +95,10 @@ func (p Params) AddFirstValid(key string, args ...interface{}) error {
return nil return nil
} }
// Merge merges two sets of parameters. Overwrites old fields if present
func (p *Params) Merge(p1 Params) {
for k, v := range p1 {
(*p)[k] = v
}
}

View File

@ -340,6 +340,17 @@ type Chat struct {
// //
// optional // optional
MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"` MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"`
// HasAggressiveAntiSpamEnabled is true if aggressive anti-spam checks are enabled
// in the supergroup. The field is only available to chat administrators.
// Returned only in getChat.
//
// optional
HasAggressiveAntiSpamEnabled bool `json:"has_aggressive_anti_spam_enabled,omitempty"`
// HasHiddenMembers is true if non-administrators can only get
// the list of bots and administrators in the chat.
//
// optional
HasHiddenMembers bool `json:"has_hidden_members,omitempty"`
// HasProtectedContent is true if messages from the chat can't be forwarded // HasProtectedContent is true if messages from the chat can't be forwarded
// to other chats. Returned only in getChat. // to other chats. Returned only in getChat.
// //
@ -535,6 +546,10 @@ type Message struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// HasSpoiler True, if the message media is covered by a spoiler animation
//
// optional
HasMediaSpoiler bool `json:"has_media_spoiler,omitempty"`
// Contact message is a shared contact, information about the contact; // Contact message is a shared contact, information about the contact;
// //
// optional // optional
@ -644,6 +659,11 @@ type Message struct {
// //
// optional // optional
ConnectedWebsite string `json:"connected_website,omitempty"` ConnectedWebsite string `json:"connected_website,omitempty"`
// WriteAccessAllowed is a service message: the user allowed the bot
// added to the attachment menu to write messages
//
// optional
WriteAccessAllowed *WriteAccessAllowed `json:"write_access_allowed,omitempty"`
// PassportData is a Telegram Passport data; // PassportData is a Telegram Passport data;
// //
// optional // optional
@ -657,6 +677,10 @@ type Message struct {
// //
// optional // optional
ForumTopicCreated *ForumTopicCreated `json:"forum_topic_created,omitempty"` ForumTopicCreated *ForumTopicCreated `json:"forum_topic_created,omitempty"`
// ForumTopicClosed is a service message: forum topic edited
//
// optional
ForumTopicEdited *ForumTopicEdited `json:"forum_topic_edited,omitempty"`
// ForumTopicClosed is a service message: forum topic closed // ForumTopicClosed is a service message: forum topic closed
// //
// optional // optional
@ -665,6 +689,14 @@ type Message struct {
// //
// optional // optional
ForumTopicReopened *ForumTopicReopened `json:"forum_topic_reopened,omitempty"` ForumTopicReopened *ForumTopicReopened `json:"forum_topic_reopened,omitempty"`
// GeneralForumTopicHidden is a service message: the 'General' forum topic hidden
//
// optional
GeneralForumTopicHidden *GeneralForumTopicHidden `json:"general_forum_topic_hidden,omitempty"`
// GeneralForumTopicUnhidden is a service message: the 'General' forum topic unhidden
//
// optional
GeneralForumTopicUnhidden *GeneralForumTopicUnhidden `json:"general_forum_topic_unhidden,omitempty"`
// VideoChatScheduled is a service message: video chat scheduled. // VideoChatScheduled is a service message: video chat scheduled.
// //
// optional // optional
@ -1262,11 +1294,41 @@ type ForumTopicCreated struct {
type ForumTopicClosed struct { type ForumTopicClosed struct {
} }
// ForumTopicEdited object represents a service message about an edited forum topic.
type ForumTopicEdited struct {
// Name is the new name of the topic, if it was edited
//
// optional
Name string `json:"name,omitempty"`
// IconCustomEmojiID is the new identifier of the custom emoji
// shown as the topic icon, if it was edited;
// an empty string if the icon was removed
//
// optional
IconCustomEmojiID *string `json:"icon_custom_emoji_id,omitempty"`
}
// ForumTopicReopened represents a service message about a forum topic // ForumTopicReopened represents a service message about a forum topic
// reopened in the chat. Currently holds no information. // reopened in the chat. Currently holds no information.
type ForumTopicReopened struct { type ForumTopicReopened struct {
} }
// GeneralForumTopicHidden represents a service message about General forum topic
// hidden in the chat. Currently holds no information.
type GeneralForumTopicHidden struct {
}
// GeneralForumTopicUnhidden represents a service message about General forum topic
// unhidden in the chat. Currently holds no information.
type GeneralForumTopicUnhidden struct {
}
// WriteAccessAllowed represents a service message about a user
// allowing a bot added to the attachment menu to write messages.
// Currently holds no information.
type WriteAccessAllowed struct {
}
// VideoChatScheduled represents a service message about a voice chat scheduled // VideoChatScheduled represents a service message about a voice chat scheduled
// in the chat. // in the chat.
type VideoChatScheduled struct { type VideoChatScheduled struct {
@ -1345,6 +1407,13 @@ type WebAppInfo struct {
type ReplyKeyboardMarkup struct { type ReplyKeyboardMarkup struct {
// Keyboard is an array of button rows, each represented by an Array of KeyboardButton objects // Keyboard is an array of button rows, each represented by an Array of KeyboardButton objects
Keyboard [][]KeyboardButton `json:"keyboard"` Keyboard [][]KeyboardButton `json:"keyboard"`
// IsPersistent requests clients to always show the keyboard
// when the regular keyboard is hidden.
// Defaults to false, in which case the custom keyboard can be hidden
// and opened with a keyboard icon.
//
// optional
IsPersistent bool `json:"is_persistent"`
// ResizeKeyboard requests clients to resize the keyboard vertically for optimal fit // ResizeKeyboard requests clients to resize the keyboard vertically for optimal fit
// (e.g., make the keyboard smaller if there are just two rows of buttons). // (e.g., make the keyboard smaller if there are just two rows of buttons).
// Defaults to false, in which case the custom keyboard // Defaults to false, in which case the custom keyboard
@ -1769,7 +1838,7 @@ type ChatMember struct {
// True, if the user is allowed to pin messages; groups and supergroups only // True, if the user is allowed to pin messages; groups and supergroups only
// //
// optional // optional
CanPinMessages bool `json:"can_pin_messages,omitempty"` CanPinMessages bool `json:"can_pin_messages,omitempty"`
// CanManageTopics administrators and restricted only. // CanManageTopics administrators and restricted only.
// True, if the user is allowed to create, rename, // True, if the user is allowed to create, rename,
// close, and reopen forum topics; supergroups only // close, and reopen forum topics; supergroups only
@ -2004,6 +2073,10 @@ type BaseInputMedia struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// HasSpoiler pass True, if the photo needs to be covered with a spoiler animation
//
// optional
HasSpoiler bool `json:"has_spoiler,omitempty"`
} }
// InputMediaPhoto is a photo to send as part of a media group. // InputMediaPhoto is a photo to send as part of a media group.
@ -2035,6 +2108,10 @@ type InputMediaVideo struct {
// //
// optional // optional
SupportsStreaming bool `json:"supports_streaming,omitempty"` SupportsStreaming bool `json:"supports_streaming,omitempty"`
// HasSpoiler pass True, if the video needs to be covered with a spoiler animation
//
// optional
HasSpoiler bool `json:"has_spoiler,omitempty"`
} }
// InputMediaAnimation is an animation to send as part of a media group. // InputMediaAnimation is an animation to send as part of a media group.
@ -2057,6 +2134,10 @@ type InputMediaAnimation struct {
// //
// optional // optional
Duration int `json:"duration,omitempty"` Duration int `json:"duration,omitempty"`
// HasSpoiler pass True, if the photo needs to be covered with a spoiler animation
//
// optional
HasSpoiler bool `json:"has_spoiler,omitempty"`
} }
// InputMediaAudio is an audio to send as part of a media group. // InputMediaAudio is an audio to send as part of a media group.

View File

@ -347,6 +347,18 @@ var (
_ Chattable = VideoNoteConfig{} _ Chattable = VideoNoteConfig{}
_ Chattable = VoiceConfig{} _ Chattable = VoiceConfig{}
_ Chattable = WebhookConfig{} _ Chattable = WebhookConfig{}
_ Chattable = CreateForumTopicConfig{}
_ Chattable = EditForumTopicConfig{}
_ Chattable = CloseForumTopicConfig{}
_ Chattable = ReopenForumTopicConfig{}
_ Chattable = DeleteForumTopicConfig{}
_ Chattable = UnpinAllForumTopicMessagesConfig{}
_ Chattable = GetForumTopicIconStickersConfig{}
_ Chattable = EditGeneralForumTopicConfig{}
_ Chattable = CloseGeneralForumTopicConfig{}
_ Chattable = ReopenGeneralForumTopicConfig{}
_ Chattable = HideGeneralForumTopicConfig{}
_ Chattable = UnhideGeneralForumTopicConfig{}
) )
// Ensure all Fileable types are correct. // Ensure all Fileable types are correct.