From e88fd6d70caba4a5c37961acb235ca94e3d65f57 Mon Sep 17 00:00:00 2001 From: OvyFlash Date: Wed, 30 Apr 2025 13:17:15 +0300 Subject: [PATCH] BotAPI 8.2 implementation --- configs.go | 75 +++++++++++++++++++++++++++++++++++++++++++++++ helper_methods.go | 34 +++++++++++++++++++++ types.go | 17 ++++++----- types_test.go | 67 ++++++++++++++++++++++-------------------- 4 files changed, 154 insertions(+), 39 deletions(-) diff --git a/configs.go b/configs.go index 272de59a..28690213 100644 --- a/configs.go +++ b/configs.go @@ -2369,6 +2369,81 @@ func (config SendGiftConfig) params() (Params, error) { return params, nil } +// VerifyUserConfig verifies a user on behalf of the organization +// which is represented by the bot. +// Returns True on success. +type VerifyUserConfig struct { + UserID int64 // required + CustomDescription string +} + +func (config VerifyUserConfig) method() string { + return "verifyUser" +} + +func (config VerifyUserConfig) params() (Params, error) { + params := make(Params) + params.AddNonZero64("user_id", config.UserID) + params.AddNonEmpty("custom_description", config.CustomDescription) + + return params, nil +} + +// VerifyChatConfig verifies a chat on behalf of the organization +// which is represented by the bot. +// Returns True on success. +type VerifyChatConfig struct { + Chat ChatConfig + CustomDescription string +} + +func (config VerifyChatConfig) method() string { + return "verifyChat" +} + +func (config VerifyChatConfig) params() (Params, error) { + params, err := config.Chat.params() + if err != nil { + return params, err + } + params.AddNonEmpty("custom_description", config.CustomDescription) + + return params, nil +} + +// RemoveUserVerificationConfig removes verification from a user who is currently +// verified on behalf of the organization represented by the bot. +// Returns True on success. +type RemoveUserVerificationConfig struct { + UserID int64 // required +} + +func (config RemoveUserVerificationConfig) method() string { + return "removeUserVerification" +} + +func (config RemoveUserVerificationConfig) params() (Params, error) { + params := make(Params) + params.AddNonZero64("user_id", config.UserID) + + return params, nil +} + +// RemoveChatVerificationConfig removes verification from a chat who is currently +// verified on behalf of the organization represented by the bot. +// Returns True on success. +type RemoveChatVerificationConfig struct { + Chat ChatConfig +} + +func (config RemoveChatVerificationConfig) method() string { + return "removeChatVerification" +} + +func (config RemoveChatVerificationConfig) params() (Params, error) { + return config.Chat.params() +} + // PinChatMessageConfig contains information of a message in a chat to pin. type PinChatMessageConfig struct { BaseChatMessage diff --git a/helper_methods.go b/helper_methods.go index 05dda45f..fbffbdb5 100644 --- a/helper_methods.go +++ b/helper_methods.go @@ -53,6 +53,40 @@ func NewDeleteMessages(chatID int64, messageIDs []int) DeleteMessagesConfig { } } +// NewVerifyUser verifies user on behalf of the organization +// which is represented by the bot +func NewVerifyUser(userID int64, customDescription string) VerifyUserConfig { + return VerifyUserConfig{ + UserID: userID, + CustomDescription: customDescription, + } +} + +// NewVerifyChat verifies chat on behalf of the organization +// which is represented by the bot +func NewVerifyChat(chat ChatConfig, customDescription string) VerifyChatConfig { + return VerifyChatConfig{ + Chat: chat, + CustomDescription: customDescription, + } +} + +// NewRemoveUserVerification removes verification from a user who is currently +// verified on behalf of the organization represented by the bot. +func NewRemoveUserVerification(userID int64) RemoveUserVerificationConfig { + return RemoveUserVerificationConfig{ + UserID: userID, + } +} + +// NewRemoveChatVerification removes verification from a chat that is currently +// verified on behalf of the organization represented by the bot. +func NewRemoveChatVerification(chat ChatConfig) RemoveChatVerificationConfig { + return RemoveChatVerificationConfig{ + Chat: chat, + } +} + // NewMessageToChannel creates a new Message that is sent to a channel // by username. // diff --git a/types.go b/types.go index 161bb182..7c18b5fa 100644 --- a/types.go +++ b/types.go @@ -4370,6 +4370,7 @@ type InlineQueryResultArticle struct { // HideURL pass True, if you don't want the URL to be shown in the message. // // optional + // Deprecated in 8.2: Pass an empty string as url instead. HideURL bool `json:"hide_url,omitempty"` // Description short description of the result. // @@ -5319,26 +5320,26 @@ type RevenueWithdrawalState struct { // AffiliateInfo contains information about the affiliate that // received a commission via this transaction. type AffiliateInfo struct { - // AffiliateUser is the bot or the user that received an + // AffiliateUser is the bot or the user that received an // affiliate commission if it was received by a bot or a user // // optional AffiliateUser *User `json:"affiliate_user,omitempty"` - // AffiliateChat is the chat that received an affiliate commission + // AffiliateChat is the chat that received an affiliate commission // if it was received by a chat // // optional AffiliateChat *Chat `json:"affiliate_chat,omitempty"` - // CommissionPerMile is the number of Telegram Stars received by - // the affiliate for each 1000 Telegram Stars received by + // CommissionPerMile is the number of Telegram Stars received by + // the affiliate for each 1000 Telegram Stars received by // the bot from referred users CommissionPerMile int `json:"commission_per_mille"` - // Amount is the integer amount of Telegram Stars received by - // the affiliate from the transaction, rounded to 0; + // Amount is the integer amount of Telegram Stars received by + // the affiliate from the transaction, rounded to 0; // can be negative for refunds Amount int64 `json:"amount"` - // NanostarAmount is the number of 1/1000000000 shares of Telegram Stars - // received by the affiliate; from -999999999 to 999999999; + // NanostarAmount is the number of 1/1000000000 shares of Telegram Stars + // received by the affiliate; from -999999999 to 999999999; // can be negative for refunds // // optional diff --git a/types_test.go b/types_test.go index 485dcf06..0babb140 100644 --- a/types_test.go +++ b/types_test.go @@ -279,6 +279,7 @@ func TestFileLink(t *testing.T) { // Ensure all configs are sendable var ( + _ Chattable = AddStickerConfig{} _ Chattable = AnimationConfig{} _ Chattable = AnswerWebAppQueryConfig{} _ Chattable = AudioConfig{} @@ -290,19 +291,25 @@ var ( _ Chattable = ChatInfoConfig{} _ Chattable = ChatInviteLinkConfig{} _ Chattable = CloseConfig{} + _ Chattable = CloseForumTopicConfig{} + _ Chattable = CloseGeneralForumTopicConfig{} _ Chattable = ContactConfig{} _ Chattable = CopyMessageConfig{} _ Chattable = CreateChatInviteLinkConfig{} _ Chattable = CreateChatSubscriptionLinkConfig{} + _ Chattable = CreateForumTopicConfig{} _ Chattable = DeleteChatPhotoConfig{} _ Chattable = DeleteChatStickerSetConfig{} + _ Chattable = DeleteForumTopicConfig{} _ Chattable = DeleteMessageConfig{} - _ Chattable = GetAvailableGiftsConfig{} _ Chattable = DeleteMyCommandsConfig{} + _ Chattable = DeleteStickerSetConfig{} _ Chattable = DeleteWebhookConfig{} _ Chattable = DocumentConfig{} _ Chattable = EditChatInviteLinkConfig{} _ Chattable = EditChatSubscriptionLinkConfig{} + _ Chattable = EditForumTopicConfig{} + _ Chattable = EditGeneralForumTopicConfig{} _ Chattable = EditMessageCaptionConfig{} _ Chattable = EditMessageLiveLocationConfig{} _ Chattable = EditMessageMediaConfig{} @@ -311,11 +318,18 @@ var ( _ Chattable = FileConfig{} _ Chattable = ForwardConfig{} _ Chattable = GameConfig{} + _ Chattable = GetAvailableGiftsConfig{} _ Chattable = GetBusinessConnectionConfig{} _ Chattable = GetChatMemberConfig{} _ Chattable = GetChatMenuButtonConfig{} + _ Chattable = GetForumTopicIconStickersConfig{} _ Chattable = GetGameHighScoresConfig{} _ Chattable = GetMyDefaultAdministratorRightsConfig{} + _ Chattable = GetMyDescriptionConfig{} + _ Chattable = GetMyNameConfig{} + _ Chattable = GetMyShortDescriptionConfig{} + _ Chattable = GetStarTransactionsConfig{} + _ Chattable = HideGeneralForumTopicConfig{} _ Chattable = InlineConfig{} _ Chattable = InvoiceConfig{} _ Chattable = KickChatMemberConfig{} @@ -324,10 +338,16 @@ var ( _ Chattable = LogOutConfig{} _ Chattable = MediaGroupConfig{} _ Chattable = MessageConfig{} + _ Chattable = PaidMediaConfig{} _ Chattable = PhotoConfig{} _ Chattable = PinChatMessageConfig{} _ Chattable = PreCheckoutConfig{} _ Chattable = PromoteChatMemberConfig{} + _ Chattable = RefundStarPaymentConfig{} + _ Chattable = RemoveChatVerificationConfig{} + _ Chattable = RemoveUserVerificationConfig{} + _ Chattable = ReopenForumTopicConfig{} + _ Chattable = ReopenGeneralForumTopicConfig{} _ Chattable = ReplaceStickerInSetConfig{} _ Chattable = RestrictChatMemberConfig{} _ Chattable = RevokeChatInviteLinkConfig{} @@ -336,52 +356,37 @@ var ( _ Chattable = SetChatMenuButtonConfig{} _ Chattable = SetChatPhotoConfig{} _ Chattable = SetChatTitleConfig{} + _ Chattable = SetCustomEmojiStickerSetThumbnailConfig{} _ Chattable = SetGameScoreConfig{} + _ Chattable = SetMessageReactionConfig{} _ Chattable = SetMyDefaultAdministratorRightsConfig{} + _ Chattable = SetMyDescriptionConfig{} + _ Chattable = SetMyNameConfig{} + _ Chattable = SetMyShortDescriptionConfig{} + _ Chattable = SetStickerEmojiListConfig{} + _ Chattable = SetStickerKeywordsConfig{} + _ Chattable = SetStickerMaskPositionConfig{} + _ Chattable = SetStickerSetTitleConfig{} + _ Chattable = SetUserEmojiStatusConfig{} _ Chattable = ShippingConfig{} _ Chattable = StickerConfig{} _ Chattable = StopMessageLiveLocationConfig{} _ Chattable = StopPollConfig{} _ Chattable = UnbanChatMemberConfig{} _ Chattable = UnbanChatSenderChatConfig{} + _ Chattable = UnhideGeneralForumTopicConfig{} + _ Chattable = UnpinAllForumTopicMessagesConfig{} + _ Chattable = UnpinAllGeneralForumTopicMessagesConfig{} _ Chattable = UnpinChatMessageConfig{} _ Chattable = UpdateConfig{} - _ Chattable = SetMessageReactionConfig{} _ Chattable = UserProfilePhotosConfig{} - _ Chattable = SetUserEmojiStatusConfig{} _ Chattable = VenueConfig{} + _ Chattable = VerifyChatConfig{} + _ Chattable = VerifyUserConfig{} _ 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{} - _ Chattable = UnpinAllGeneralForumTopicMessagesConfig{} - _ Chattable = SetCustomEmojiStickerSetThumbnailConfig{} - _ Chattable = SetStickerSetTitleConfig{} - _ Chattable = DeleteStickerSetConfig{} - _ Chattable = SetStickerEmojiListConfig{} - _ Chattable = SetStickerKeywordsConfig{} - _ Chattable = SetStickerMaskPositionConfig{} - _ Chattable = GetMyDescriptionConfig{} - _ Chattable = SetMyDescriptionConfig{} - _ Chattable = GetMyShortDescriptionConfig{} - _ Chattable = SetMyShortDescriptionConfig{} - _ Chattable = GetMyNameConfig{} - _ Chattable = SetMyNameConfig{} - _ Chattable = RefundStarPaymentConfig{} - _ Chattable = GetStarTransactionsConfig{} - _ Chattable = PaidMediaConfig{} ) // Ensure all Fileable types are correct.