Merge pull request #4 from OvyFlash/bot-api-6.4 Implement Bot API 6.4 changes
@@ -323,6 +323,21 @@
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. type MessageConfig struct { BaseChat@@ -407,6 +422,7 @@
// PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { BaseFile + BaseSpoiler Thumb RequestFileData Caption string ParseMode string@@ -422,6 +438,15 @@
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) 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 }@@ -557,6 +582,7 @@
// VideoConfig contains information about a SendVideo request. type VideoConfig struct { BaseFile + BaseSpoiler Thumb RequestFileData Duration int Caption string@@ -576,6 +602,15 @@ params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddBool("supports_streaming", config.SupportsStreaming) 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 }@@ -603,6 +638,7 @@
// AnimationConfig contains information about a SendAnimation request. type AnimationConfig struct { BaseFile + BaseSpoiler Duration int Thumb RequestFileData Caption string@@ -620,6 +656,15 @@ params.AddNonZero("duration", config.Duration)
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) 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 }@@ -976,6 +1021,7 @@
// ChatActionConfig contains information about a SendChatAction request. type ChatActionConfig struct { BaseChat + MessageThreadID int Action string // required }@@ -983,6 +1029,7 @@ func (config ChatActionConfig) params() (Params, error) {
params, err := config.BaseChat.params() params["action"] = config.Action + params.AddNonZero("message_thread_id", config.MessageThreadID) return params, err }@@ -2314,14 +2361,27 @@ func (config GetForumTopicIconStickersConfig) params() (Params, error) {
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 // in a forum supergroup chat. type CreateForumTopicConfig struct { - ChatID int64 - Name string - IconColor int - IconCustomEmojiID string - SuperGroupUsername string + BaseForum + Name string + IconColor int + IconCustomEmojiID string } func (config CreateForumTopicConfig) method() string {@@ -2331,10 +2391,12 @@
func (config CreateForumTopicConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonEmpty("name", config.Name) params.AddNonZero("icon_color", config.IconColor) params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID) + + p1, _ := config.BaseForum.params() + params.Merge(p1) return params, nil }@@ -2342,11 +2404,10 @@
// EditForumTopicConfig allows you to edit // name and icon of a topic in a forum supergroup chat. type EditForumTopicConfig struct { - ChatID int64 - MessageThreadID int - Name string - IconCustomEmojiID string - SuperGroupUsername string + BaseForum + MessageThreadID int + Name string + IconCustomEmojiID string } func (config EditForumTopicConfig) method() string {@@ -2356,10 +2417,12 @@
func (config EditForumTopicConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) 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) + + p1, _ := config.BaseForum.params() + params.Merge(p1) return params, nil }@@ -2367,9 +2430,8 @@
// CloseForumTopicConfig allows you to close // an open topic in a forum supergroup chat. type CloseForumTopicConfig struct { - ChatID int64 - MessageThreadID int - SuperGroupUsername string + BaseForum + MessageThreadID int } func (config CloseForumTopicConfig) method() string {@@ -2379,18 +2441,19 @@
func (config CloseForumTopicConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonZero("message_thread_id", config.MessageThreadID) + p1, _ := config.BaseForum.params() + params.Merge(p1) + return params, nil } // ReopenForumTopicConfig allows you to reopen // an closed topic in a forum supergroup chat. type ReopenForumTopicConfig struct { - ChatID int64 - MessageThreadID int - SuperGroupUsername string + BaseForum + MessageThreadID int } func (config ReopenForumTopicConfig) method() string {@@ -2403,15 +2466,17 @@
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonZero("message_thread_id", config.MessageThreadID) + p1, _ := config.BaseForum.params() + params.Merge(p1) + return params, nil } // DeleteForumTopicConfig allows you to delete a forum topic // along with all its messages in a forum supergroup chat. type DeleteForumTopicConfig struct { - ChatID int64 - MessageThreadID int - SuperGroupUsername string + BaseForum + MessageThreadID int } func (config DeleteForumTopicConfig) method() string {@@ -2421,8 +2486,10 @@
func (config DeleteForumTopicConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonZero("message_thread_id", config.MessageThreadID) + + p1, _ := config.BaseForum.params() + params.Merge(p1) return params, nil }@@ -2430,9 +2497,8 @@
// UnpinAllForumTopicMessagesConfig allows you to clear the list // of pinned messages in a forum topic. type UnpinAllForumTopicMessagesConfig struct { - ChatID int64 - MessageThreadID int - SuperGroupUsername string + BaseForum + MessageThreadID int } func (config UnpinAllForumTopicMessagesConfig) method() string {@@ -2445,15 +2511,84 @@
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonZero("message_thread_id", config.MessageThreadID) + p1, _ := config.BaseForum.params() + params.Merge(p1) + 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. // // Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo). type MediaGroupConfig struct { BaseChat - Media []interface{} + Media []interface{} } func (config MediaGroupConfig) method() string {
@@ -276,7 +276,7 @@ // for private chats, supergroups and channels. Returned only in getChat.
// // optional ActiveUsernames []string `json:"active_usernames,omitempty"` - // Custom emoji identifier of emoji status of the other party + // Custom emoji identifier of emoji status of the other party // in a private chat. Returned only in getChat. // // optional@@ -292,8 +292,8 @@ // with the user. Returned only in getChat.
// // optional HasPrivateForwards bool `json:"has_private_forwards,omitempty"` - // HasRestrictedVoiceAndVideoMessages if the privacy settings of the other party - // restrict sending voice and video note messages + // HasRestrictedVoiceAndVideoMessages if the privacy settings of the other party + // restrict sending voice and video note messages // in the private chat. Returned only in getChat. // // optional@@ -340,6 +340,17 @@ // chat will be automatically deleted; in seconds. Returned only in getChat.
// // optional 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 // to other chats. Returned only in getChat. //@@ -535,6 +546,10 @@ // CaptionEntities;
// // optional 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; // // optional@@ -644,6 +659,11 @@ // logged in;
// // optional 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; // // optional@@ -657,6 +677,10 @@ // ForumTopicCreated is a service message: forum topic created
// // optional 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 // // optional@@ -665,6 +689,14 @@ // ForumTopicReopened is a service message: forum topic reopened
// // optional 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. // // optional@@ -1262,9 +1294,39 @@ // closed in the chat. Currently holds no information.
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 // reopened in the chat. Currently holds no information. 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@@ -1345,6 +1407,13 @@ // ReplyKeyboardMarkup represents a custom keyboard with reply options.
type ReplyKeyboardMarkup struct { // Keyboard is an array of button rows, each represented by an Array of KeyboardButton objects 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 // (e.g., make the keyboard smaller if there are just two rows of buttons). // Defaults to false, in which case the custom keyboard@@ -1769,9 +1838,9 @@ // CanPinMessages administrators and restricted only.
// True, if the user is allowed to pin messages; groups and supergroups only // // optional - CanPinMessages bool `json:"can_pin_messages,omitempty"` + CanPinMessages bool `json:"can_pin_messages,omitempty"` // 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 // // optional@@ -2004,6 +2073,10 @@ // which can be specified instead of parse_mode
// // optional 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.@@ -2035,6 +2108,10 @@ // SupportsStreaming pass True, if the uploaded video is suitable for streaming.
// // optional 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.@@ -2057,6 +2134,10 @@ // Duration video duration
// // optional 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.
@@ -347,6 +347,18 @@ _ Chattable = VideoConfig{}
_ Chattable = VideoNoteConfig{} _ Chattable = VoiceConfig{} _ 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.