commit
8c46c34868
169
configs.go
169
configs.go
|
@ -323,6 +323,21 @@ func (edit BaseEdit) params() (Params, error) {
|
|||
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 @@ func (config CopyMessageConfig) method() string {
|
|||
// PhotoConfig contains information about a SendPhoto request.
|
||||
type PhotoConfig struct {
|
||||
BaseFile
|
||||
BaseSpoiler
|
||||
Thumb RequestFileData
|
||||
Caption string
|
||||
ParseMode string
|
||||
|
@ -422,6 +438,15 @@ func (config PhotoConfig) params() (Params, error) {
|
|||
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 @@ func (config StickerConfig) files() []RequestFile {
|
|||
// VideoConfig contains information about a SendVideo request.
|
||||
type VideoConfig struct {
|
||||
BaseFile
|
||||
BaseSpoiler
|
||||
Thumb RequestFileData
|
||||
Duration int
|
||||
Caption string
|
||||
|
@ -576,6 +602,15 @@ func (config VideoConfig) params() (Params, error) {
|
|||
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 @@ func (config VideoConfig) files() []RequestFile {
|
|||
// AnimationConfig contains information about a SendAnimation request.
|
||||
type AnimationConfig struct {
|
||||
BaseFile
|
||||
BaseSpoiler
|
||||
Duration int
|
||||
Thumb RequestFileData
|
||||
Caption string
|
||||
|
@ -620,6 +656,15 @@ func (config AnimationConfig) params() (Params, error) {
|
|||
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 @@ func (config GetGameHighScoresConfig) method() string {
|
|||
// 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
|
||||
BaseForum
|
||||
Name string
|
||||
IconColor int
|
||||
IconCustomEmojiID string
|
||||
SuperGroupUsername string
|
||||
}
|
||||
|
||||
func (config CreateForumTopicConfig) method() string {
|
||||
|
@ -2331,22 +2391,23 @@ func (config CreateForumTopicConfig) method() string {
|
|||
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
|
||||
}
|
||||
|
||||
// EditForumTopicConfig allows you to edit
|
||||
// name and icon of a topic in a forum supergroup chat.
|
||||
type EditForumTopicConfig struct {
|
||||
ChatID int64
|
||||
BaseForum
|
||||
MessageThreadID int
|
||||
Name string
|
||||
IconCustomEmojiID string
|
||||
SuperGroupUsername string
|
||||
}
|
||||
|
||||
func (config EditForumTopicConfig) method() string {
|
||||
|
@ -2356,20 +2417,21 @@ func (config EditForumTopicConfig) method() string {
|
|||
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
|
||||
}
|
||||
|
||||
// CloseForumTopicConfig allows you to close
|
||||
// an open topic in a forum supergroup chat.
|
||||
type CloseForumTopicConfig struct {
|
||||
ChatID int64
|
||||
BaseForum
|
||||
MessageThreadID int
|
||||
SuperGroupUsername string
|
||||
}
|
||||
|
||||
func (config CloseForumTopicConfig) method() string {
|
||||
|
@ -2379,18 +2441,19 @@ func (config CloseForumTopicConfig) method() string {
|
|||
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
|
||||
BaseForum
|
||||
MessageThreadID int
|
||||
SuperGroupUsername 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.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
|
||||
BaseForum
|
||||
MessageThreadID int
|
||||
SuperGroupUsername string
|
||||
}
|
||||
|
||||
func (config DeleteForumTopicConfig) method() string {
|
||||
|
@ -2421,18 +2486,19 @@ func (config DeleteForumTopicConfig) method() string {
|
|||
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
|
||||
}
|
||||
|
||||
// UnpinAllForumTopicMessagesConfig allows you to clear the list
|
||||
// of pinned messages in a forum topic.
|
||||
type UnpinAllForumTopicMessagesConfig struct {
|
||||
ChatID int64
|
||||
BaseForum
|
||||
MessageThreadID int
|
||||
SuperGroupUsername string
|
||||
}
|
||||
|
||||
func (config UnpinAllForumTopicMessagesConfig) method() string {
|
||||
|
@ -2445,9 +2511,78 @@ func (config UnpinAllForumTopicMessagesConfig) params() (Params, error) {
|
|||
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).
|
||||
|
|
|
@ -95,3 +95,10 @@ func (p Params) AddFirstValid(key string, args ...interface{}) error {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
81
types.go
81
types.go
|
@ -340,6 +340,17 @@ type Chat struct {
|
|||
//
|
||||
// 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 @@ type Message struct {
|
|||
//
|
||||
// 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 @@ type Message struct {
|
|||
//
|
||||
// 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 @@ type Message struct {
|
|||
//
|
||||
// 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 @@ type Message struct {
|
|||
//
|
||||
// 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,11 +1294,41 @@ type ForumTopicCreated 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
|
||||
// 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
|
||||
// in the chat.
|
||||
type VideoChatScheduled struct {
|
||||
|
@ -1345,6 +1407,13 @@ type WebAppInfo struct {
|
|||
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
|
||||
|
@ -2004,6 +2073,10 @@ type BaseInputMedia struct {
|
|||
//
|
||||
// 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 @@ type InputMediaVideo struct {
|
|||
//
|
||||
// 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 @@ type InputMediaAnimation struct {
|
|||
//
|
||||
// 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 @@ var (
|
|||
_ 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.
|
||||
|
|
Loading…
Reference in New Issue