From 1ad852c7652bb1c0226da1214678f9dc70dcf3d5 Mon Sep 17 00:00:00 2001 From: stdkhai Date: Tue, 7 May 2024 17:32:47 +0300 Subject: [PATCH] Bot API 7.3 implementation --- bot.go | 6 +-- bot_test.go | 2 +- configs.go | 10 ++++- helper_methods.go | 9 +++- types.go | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 6 deletions(-) diff --git a/bot.go b/bot.go index 7a282fc..1a16c27 100644 --- a/bot.go +++ b/bot.go @@ -553,13 +553,13 @@ func WriteToHTTPResponse(w http.ResponseWriter, c Chattable) error { } // GetChat gets information about a chat. -func (bot *BotAPI) GetChat(config ChatInfoConfig) (Chat, error) { +func (bot *BotAPI) GetChat(config ChatInfoConfig) (ChatFullInfo, error) { resp, err := bot.Request(config) if err != nil { - return Chat{}, err + return ChatFullInfo{}, err } - var chat Chat + var chat ChatFullInfo err = json.Unmarshal(resp.Result, &chat) return chat, err diff --git a/bot_test.go b/bot_test.go index 40633d6..d61a73b 100644 --- a/bot_test.go +++ b/bot_test.go @@ -933,7 +933,7 @@ func TestUnpinAllChatMessages(t *testing.T) { func TestPolls(t *testing.T) { bot, _ := getBot(t) - poll := NewPoll(SupergroupChatID, "Are polls working?", "Yes", "No") + poll := NewPoll(SupergroupChatID, "Are polls working?", NewPollOption("Yes"), NewPollOption("No")) msg, err := bot.Send(poll) if err != nil { diff --git a/configs.go b/configs.go index 030d3c6..b11a584 100644 --- a/configs.go +++ b/configs.go @@ -829,6 +829,7 @@ type EditMessageLiveLocationConfig struct { BaseEdit Latitude float64 // required Longitude float64 // required + LivePeriod int //optional HorizontalAccuracy float64 // optional Heading int // optional ProximityAlertRadius int // optional @@ -841,6 +842,7 @@ func (config EditMessageLiveLocationConfig) params() (Params, error) { params.AddNonZeroFloat("longitude", config.Longitude) params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy) params.AddNonZero("heading", config.Heading) + params.AddNonZero("live_period", config.LivePeriod) params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius) return params, err @@ -924,7 +926,9 @@ func (config ContactConfig) method() string { type SendPollConfig struct { BaseChat Question string - Options []string + QuestionParseMode string // optional + QuestionEntities []MessageEntity // optional + Options []InputPollOption IsAnonymous bool Type string AllowsMultipleAnswers bool @@ -944,6 +948,10 @@ func (config SendPollConfig) params() (Params, error) { } params["question"] = config.Question + params.AddNonEmpty("question_parse_mode", config.QuestionParseMode) + if err = params.AddInterface("question_entities", config.QuestionEntities); err != nil { + return params, err + } if err = params.AddInterface("options", config.Options); err != nil { return params, err } diff --git a/helper_methods.go b/helper_methods.go index db78644..747d4a0 100644 --- a/helper_methods.go +++ b/helper_methods.go @@ -933,7 +933,7 @@ func NewDeleteChatPhoto(chatID int64) DeleteChatPhotoConfig { } // NewPoll allows you to create a new poll. -func NewPoll(chatID int64, question string, options ...string) SendPollConfig { +func NewPoll(chatID int64, question string, options ...InputPollOption) SendPollConfig { return SendPollConfig{ BaseChat: BaseChat{ ChatConfig: ChatConfig{ChatID: chatID}, @@ -944,6 +944,13 @@ func NewPoll(chatID int64, question string, options ...string) SendPollConfig { } } +// NewPollOption allows you to create poll option +func NewPollOption(text string) InputPollOption { + return InputPollOption{ + Text: text, + } +} + // NewStopPoll allows you to stop a poll. func NewStopPoll(chatID int64, messageID int) StopPollConfig { return StopPollConfig{ diff --git a/types.go b/types.go index 51aa333..ec75ffe 100644 --- a/types.go +++ b/types.go @@ -311,6 +311,11 @@ type Chat struct { // // optional IsForum bool `json:"is_forum,omitempty"` +} + +// ChatFullInfo contains full information about a chat. +type ChatFullInfo struct { + Chat // Photo is a chat photo Photo *ChatPhoto `json:"photo"` // If non-empty, the list of all active chat usernames; @@ -355,6 +360,8 @@ type Chat struct { // // optional AccentColorID int `json:"accent_color_id,omitempty"` + // The maximum number of reactions that can be set on a message in the chat + MaxReactionCount int `json:"max_reaction_count"` // BackgroundCustomEmojiID is a custom emoji identifier of emoji chosen by // the chat for the reply header and link preview background. // Returned only in getChat. @@ -833,6 +840,10 @@ type Message struct { // // optional BoostAdded *ChatBoostAdded `json:"boost_added,omitempty"` + // Service message: chat background set + // + // optional + ChatBackgroundSet *ChatBackground `json:"chat_background_set,omitempty"` // ForumTopicCreated is a service message: forum topic created // // optional @@ -1528,10 +1539,31 @@ type Dice struct { type PollOption struct { // Text is the option text, 1-100 characters Text string `json:"text"` + // Special entities that appear in the option text. + // Currently, only custom emoji entities are allowed in poll option texts + // + // optional + TextEntities []MessageEntity `json:"text_entities"` // VoterCount is the number of users that voted for this option VoterCount int `json:"voter_count"` } +// InputPollOption contains information about one answer option in a poll to send. +type InputPollOption struct { + // Option text, 1-100 characters + Text string `json:"text"` + // Mode for parsing entities in the text. See formatting options for more details. + // Currently, only custom emoji entities are allowed + // + // optional + TextParseMode string `json:"text_parse_mode"` + // A JSON-serialized list of special entities that appear in the poll option text. + // It can be specified instead of text_parse_mode + // + // optional + TextEntities []MessageEntity `json:"text_entities"` +} + // PollAnswer represents an answer of a user in a non-anonymous poll. type PollAnswer struct { // PollID is the unique poll identifier @@ -1557,6 +1589,11 @@ type Poll struct { ID string `json:"id"` // Question is the poll question, 1-255 characters Question string `json:"question"` + // Special entities that appear in the question. + // Currently, only custom emoji entities are allowed in poll questions + // + // optional + QuestionEntities []MessageEntity `json:"question_entities"` // Options is the list of poll options Options []PollOption `json:"options"` // TotalVoterCount is the total numbers of users who voted in the poll @@ -1610,6 +1647,7 @@ type Location struct { HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` // LivePeriod is time relative to the message sending date, during which the // location can be updated, in seconds. For active live locations only. + // Use 0x7FFFFFFF (2147483647 - max positive Int) to edit indefinitely // // optional LivePeriod int `json:"live_period,omitempty"` @@ -1684,6 +1722,73 @@ type ChatBoostAdded struct { BoostCount int `json:"boost_count"` } +// BackgroundFill describes the way a background is filled based on the selected colors. +// Currently, it can be one of: +// - BackgroundFillSolid +// - BackgroundFillGradient +// - BackgroundFillFreeformGradient +type BackgroundFill struct { + // Type of the background fill, can be: + // - solid + // - gradient + // - freeform_gradient + Type string `json:"type"` + // The color of the background fill in the RGB24 format + Color int `json:"color"` + // Top color of the gradient in the RGB24 format + TopColor int `json:"top_color"` + // Bottom color of the gradient in the RGB24 format + BottomColor int `json:"bottom_color"` + // Clockwise rotation angle of the background fill in degrees; 0-359 + RotationAngle int `json:"rotation_angle"` + // A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format + Colors []int `json:"colors"` +} + +// BackgroundType describes the type of a background. Currently, it can be one of: +// - BackgroundTypeFill +// - BackgroundTypeWallpaper +// - BackgroundTypePattern +// - BackgroundTypeChatTheme +type BackgroundType struct { + // Type of the background. + // Currently, it can be one of: + // - fill + // - wallpaper + // - pattern + // - chat_theme + Type string `json:"type"` + // The background fill or fill that is combined with the pattern + Fill BackgroundFill `json:"fill"` + // Dimming of the background in dark themes, as a percentage; 0-100 + DarkThemeDimming int `json:"dark_theme_dimming"` + // Document with the wallpaper / pattern + Document Document `json:"document"` + // True, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with radius 12 + // + // optional + IsBlurred bool `json:"is_blurred"` + // True, if the background moves slightly when the device is tilted + // + // optional + IsMoving bool `json:"is_moving"` + // Intensity of the pattern when it is shown above the filled background; 0-100 + Intensity int `json:"intensity"` + // True, if the background fill must be applied only to the pattern itself. + // All other pixels are black in this case. For dark themes only + // + // optional + IsInverted bool `json:"is_inverted"` + // Name of the chat theme, which is usually an emoji + ThemeName string `json:"theme_name"` +} + +// ChatBackground represents a chat background. +type ChatBackground struct { + // Type of the background + Type BackgroundType `json:"type"` +} + // ForumTopicCreated represents a service message about a new forum topic // created in the chat. type ForumTopicCreated struct { @@ -2702,6 +2807,12 @@ type ChatMemberUpdated struct { // // optional InviteLink *ChatInviteLink `json:"invite_link,omitempty"` + // ViaJoinRequest is true, if the user joined the chat + // after sending a direct join request + // and being approved by an administrator + // + // optional + ViaJoinRequest bool `json:"via_join_request,omitempty"` // ViaChatFolderInviteLink is True, if the user joined the chat // via a chat folder invite link //