From 88a4eda77ae8853614d5b7f50c5fbe09faef5585 Mon Sep 17 00:00:00 2001 From: Paul Larsen Date: Sun, 17 Nov 2024 17:55:20 +0000 Subject: [PATCH] Update to latest bot API version --- gen_helpers.go | 15 ++++ gen_methods.go | 229 +++++++++++++++++++++++++++++++++++++++++++++++++ gen_types.go | 72 ++++++++++++++-- spec_commit | 2 +- 4 files changed, 308 insertions(+), 10 deletions(-) diff --git a/gen_helpers.go b/gen_helpers.go index c3f34a5..9a987e0 100755 --- a/gen_helpers.go +++ b/gen_helpers.go @@ -199,6 +199,11 @@ func (c Chat) UnpinMessage(b *Bot, opts *UnpinChatMessageOpts) (bool, error) { return b.UnpinChatMessage(c.Id, opts) } +// Send Helper method for Bot.SendGift. +func (g Gift) Send(b *Bot, userId int64, opts *SendGiftOpts) (bool, error) { + return b.SendGift(userId, g.Id, opts) +} + // Copy Helper method for Bot.CopyMessage. func (im InaccessibleMessage) Copy(b *Bot, chatId int64, opts *CopyMessageOpts) (*MessageId, error) { return b.CopyMessage(chatId, im.Chat.Id, im.MessageId, opts) @@ -482,6 +487,11 @@ func (sq ShippingQuery) Answer(b *Bot, ok bool, opts *AnswerShippingQueryOpts) ( return b.AnswerShippingQuery(sq.Id, ok, opts) } +// EditStarSubscription Helper method for Bot.EditUserStarSubscription. +func (u User) EditStarSubscription(b *Bot, telegramPaymentChargeId string, isCanceled bool, opts *EditUserStarSubscriptionOpts) (bool, error) { + return b.EditUserStarSubscription(u.Id, telegramPaymentChargeId, isCanceled, opts) +} + // GetChatBoosts Helper method for Bot.GetUserChatBoosts. func (u User) GetChatBoosts(b *Bot, chatId int64, opts *GetUserChatBoostsOpts) (*UserChatBoosts, error) { return b.GetUserChatBoosts(chatId, u.Id, opts) @@ -491,3 +501,8 @@ func (u User) GetChatBoosts(b *Bot, chatId int64, opts *GetUserChatBoostsOpts) ( func (u User) GetProfilePhotos(b *Bot, opts *GetUserProfilePhotosOpts) (*UserProfilePhotos, error) { return b.GetUserProfilePhotos(u.Id, opts) } + +// SetEmojiStatus Helper method for Bot.SetUserEmojiStatus. +func (u User) SetEmojiStatus(b *Bot, opts *SetUserEmojiStatusOpts) (bool, error) { + return b.SetUserEmojiStatus(u.Id, opts) +} diff --git a/gen_methods.go b/gen_methods.go index f7bebb7..76b7498 100755 --- a/gen_methods.go +++ b/gen_methods.go @@ -814,8 +814,12 @@ func (bot *Bot) CreateForumTopicWithContext(ctx context.Context, chatId int64, n // CreateInvoiceLinkOpts is the set of optional fields for Bot.CreateInvoiceLink and Bot.CreateInvoiceLinkWithContext. type CreateInvoiceLinkOpts struct { + // Unique identifier of the business connection on behalf of which the link will be created + BusinessConnectionId string // Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. ProviderToken string + // The number of seconds the subscription will be active for before the next payment. The currency must be set to "XTR" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. + SubscriptionPeriod int64 // The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars. MaxTipAmount int64 // A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. @@ -876,7 +880,11 @@ func (bot *Bot) CreateInvoiceLinkWithContext(ctx context.Context, title string, v["prices"] = string(bs) } if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId v["provider_token"] = opts.ProviderToken + if opts.SubscriptionPeriod != 0 { + v["subscription_period"] = strconv.FormatInt(opts.SubscriptionPeriod, 10) + } if opts.MaxTipAmount != 0 { v["max_tip_amount"] = strconv.FormatInt(opts.MaxTipAmount, 10) } @@ -1935,6 +1943,44 @@ func (bot *Bot) EditMessageTextWithContext(ctx context.Context, text string, opt } +// EditUserStarSubscriptionOpts is the set of optional fields for Bot.EditUserStarSubscription and Bot.EditUserStarSubscriptionWithContext. +type EditUserStarSubscriptionOpts struct { + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// EditUserStarSubscription (https://core.telegram.org/bots/api#edituserstarsubscription) +// +// Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. Returns True on success. +// - userId (type int64): Identifier of the user whose subscription will be edited +// - telegramPaymentChargeId (type string): Telegram payment identifier for the subscription +// - isCanceled (type bool): Pass True to cancel extension of the user subscription; the subscription must be active up to the end of the current subscription period. Pass False to allow the user to re-enable a subscription that was previously canceled by the bot. +// - opts (type EditUserStarSubscriptionOpts): All optional parameters. +func (bot *Bot) EditUserStarSubscription(userId int64, telegramPaymentChargeId string, isCanceled bool, opts *EditUserStarSubscriptionOpts) (bool, error) { + return bot.EditUserStarSubscriptionWithContext(context.Background(), userId, telegramPaymentChargeId, isCanceled, opts) +} + +// EditUserStarSubscriptionWithContext is the same as Bot.EditUserStarSubscription, but with a context.Context parameter +func (bot *Bot) EditUserStarSubscriptionWithContext(ctx context.Context, userId int64, telegramPaymentChargeId string, isCanceled bool, opts *EditUserStarSubscriptionOpts) (bool, error) { + v := map[string]string{} + v["user_id"] = strconv.FormatInt(userId, 10) + v["telegram_payment_charge_id"] = telegramPaymentChargeId + v["is_canceled"] = strconv.FormatBool(isCanceled) + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "editUserStarSubscription", v, nil, reqOpts) + if err != nil { + return false, err + } + + var b bool + return b, json.Unmarshal(r, &b) +} + // ExportChatInviteLinkOpts is the set of optional fields for Bot.ExportChatInviteLink and Bot.ExportChatInviteLinkWithContext. type ExportChatInviteLinkOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests @@ -2077,6 +2123,38 @@ func (bot *Bot) ForwardMessagesWithContext(ctx context.Context, chatId int64, fr return m, json.Unmarshal(r, &m) } +// GetAvailableGiftsOpts is the set of optional fields for Bot.GetAvailableGifts and Bot.GetAvailableGiftsWithContext. +type GetAvailableGiftsOpts struct { + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// GetAvailableGifts (https://core.telegram.org/bots/api#getavailablegifts) +// +// Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object. +// - opts (type GetAvailableGiftsOpts): All optional parameters. +func (bot *Bot) GetAvailableGifts(opts *GetAvailableGiftsOpts) (*Gifts, error) { + return bot.GetAvailableGiftsWithContext(context.Background(), opts) +} + +// GetAvailableGiftsWithContext is the same as Bot.GetAvailableGifts, but with a context.Context parameter +func (bot *Bot) GetAvailableGiftsWithContext(ctx context.Context, opts *GetAvailableGiftsOpts) (*Gifts, error) { + v := map[string]string{} + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "getAvailableGifts", v, nil, reqOpts) + if err != nil { + return nil, err + } + + var g Gifts + return &g, json.Unmarshal(r, &g) +} + // GetBusinessConnectionOpts is the set of optional fields for Bot.GetBusinessConnection and Bot.GetBusinessConnectionWithContext. type GetBusinessConnectionOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests @@ -3381,6 +3459,60 @@ func (bot *Bot) RevokeChatInviteLinkWithContext(ctx context.Context, chatId int6 return &c, json.Unmarshal(r, &c) } +// SavePreparedInlineMessageOpts is the set of optional fields for Bot.SavePreparedInlineMessage and Bot.SavePreparedInlineMessageWithContext. +type SavePreparedInlineMessageOpts struct { + // Pass True if the message can be sent to private chats with users + AllowUserChats bool + // Pass True if the message can be sent to private chats with bots + AllowBotChats bool + // Pass True if the message can be sent to group and supergroup chats + AllowGroupChats bool + // Pass True if the message can be sent to channel chats + AllowChannelChats bool + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// SavePreparedInlineMessage (https://core.telegram.org/bots/api#savepreparedinlinemessage) +// +// Stores a message that can be sent by a user of a Mini App. Returns a PreparedInlineMessage object. +// - userId (type int64): Unique identifier of the target user that can use the prepared message +// - result (type InlineQueryResult): A JSON-serialized object describing the message to be sent +// - opts (type SavePreparedInlineMessageOpts): All optional parameters. +func (bot *Bot) SavePreparedInlineMessage(userId int64, result InlineQueryResult, opts *SavePreparedInlineMessageOpts) (*PreparedInlineMessage, error) { + return bot.SavePreparedInlineMessageWithContext(context.Background(), userId, result, opts) +} + +// SavePreparedInlineMessageWithContext is the same as Bot.SavePreparedInlineMessage, but with a context.Context parameter +func (bot *Bot) SavePreparedInlineMessageWithContext(ctx context.Context, userId int64, result InlineQueryResult, opts *SavePreparedInlineMessageOpts) (*PreparedInlineMessage, error) { + v := map[string]string{} + v["user_id"] = strconv.FormatInt(userId, 10) + bs, err := json.Marshal(result) + if err != nil { + return nil, fmt.Errorf("failed to marshal field result: %w", err) + } + v["result"] = string(bs) + if opts != nil { + v["allow_user_chats"] = strconv.FormatBool(opts.AllowUserChats) + v["allow_bot_chats"] = strconv.FormatBool(opts.AllowBotChats) + v["allow_group_chats"] = strconv.FormatBool(opts.AllowGroupChats) + v["allow_channel_chats"] = strconv.FormatBool(opts.AllowChannelChats) + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "savePreparedInlineMessage", v, nil, reqOpts) + if err != nil { + return nil, err + } + + var p PreparedInlineMessage + return &p, json.Unmarshal(r, &p) +} + // SendAnimationOpts is the set of optional fields for Bot.SendAnimation and Bot.SendAnimationWithContext. type SendAnimationOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent @@ -4020,6 +4152,59 @@ func (bot *Bot) SendGameWithContext(ctx context.Context, chatId int64, gameShort return &m, json.Unmarshal(r, &m) } +// SendGiftOpts is the set of optional fields for Bot.SendGift and Bot.SendGiftWithContext. +type SendGiftOpts struct { + // Text that will be shown along with the gift; 0-255 characters + Text string + // Mode for parsing entities in the text. See formatting options for more details. Entities other than "bold", "italic", "underline", "strikethrough", "spoiler", and "custom_emoji" are ignored. + TextParseMode string + // A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than "bold", "italic", "underline", "strikethrough", "spoiler", and "custom_emoji" are ignored. + TextEntities []MessageEntity + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// SendGift (https://core.telegram.org/bots/api#sendgift) +// +// Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success. +// - userId (type int64): Unique identifier of the target user that will receive the gift +// - giftId (type string): Identifier of the gift +// - opts (type SendGiftOpts): All optional parameters. +func (bot *Bot) SendGift(userId int64, giftId string, opts *SendGiftOpts) (bool, error) { + return bot.SendGiftWithContext(context.Background(), userId, giftId, opts) +} + +// SendGiftWithContext is the same as Bot.SendGift, but with a context.Context parameter +func (bot *Bot) SendGiftWithContext(ctx context.Context, userId int64, giftId string, opts *SendGiftOpts) (bool, error) { + v := map[string]string{} + v["user_id"] = strconv.FormatInt(userId, 10) + v["gift_id"] = giftId + if opts != nil { + v["text"] = opts.Text + v["text_parse_mode"] = opts.TextParseMode + if opts.TextEntities != nil { + bs, err := json.Marshal(opts.TextEntities) + if err != nil { + return false, fmt.Errorf("failed to marshal field text_entities: %w", err) + } + v["text_entities"] = string(bs) + } + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "sendGift", v, nil, reqOpts) + if err != nil { + return false, err + } + + var b bool + return b, json.Unmarshal(r, &b) +} + // SendInvoiceOpts is the set of optional fields for Bot.SendInvoice and Bot.SendInvoiceWithContext. type SendInvoiceOpts struct { // Unique identifier for the target message thread (topic) of the forum; for forum supergroups only @@ -6261,6 +6446,50 @@ func (bot *Bot) SetStickerSetTitleWithContext(ctx context.Context, name string, return b, json.Unmarshal(r, &b) } +// SetUserEmojiStatusOpts is the set of optional fields for Bot.SetUserEmojiStatus and Bot.SetUserEmojiStatusWithContext. +type SetUserEmojiStatusOpts struct { + // Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status. + EmojiStatusCustomEmojiId string + // Expiration date of the emoji status, if any + EmojiStatusExpirationDate int64 + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// SetUserEmojiStatus (https://core.telegram.org/bots/api#setuseremojistatus) +// +// Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. Returns True on success. +// - userId (type int64): Unique identifier of the target user +// - opts (type SetUserEmojiStatusOpts): All optional parameters. +func (bot *Bot) SetUserEmojiStatus(userId int64, opts *SetUserEmojiStatusOpts) (bool, error) { + return bot.SetUserEmojiStatusWithContext(context.Background(), userId, opts) +} + +// SetUserEmojiStatusWithContext is the same as Bot.SetUserEmojiStatus, but with a context.Context parameter +func (bot *Bot) SetUserEmojiStatusWithContext(ctx context.Context, userId int64, opts *SetUserEmojiStatusOpts) (bool, error) { + v := map[string]string{} + v["user_id"] = strconv.FormatInt(userId, 10) + if opts != nil { + v["emoji_status_custom_emoji_id"] = opts.EmojiStatusCustomEmojiId + if opts.EmojiStatusExpirationDate != 0 { + v["emoji_status_expiration_date"] = strconv.FormatInt(opts.EmojiStatusExpirationDate, 10) + } + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "setUserEmojiStatus", v, nil, reqOpts) + if err != nil { + return false, err + } + + var b bool + return b, json.Unmarshal(r, &b) +} + // SetWebhookOpts is the set of optional fields for Bot.SetWebhook and Bot.SetWebhookWithContext. type SetWebhookOpts struct { // Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details. diff --git a/gen_types.go b/gen_types.go index 70ea6c7..a26074c 100755 --- a/gen_types.go +++ b/gen_types.go @@ -2843,6 +2843,30 @@ type GeneralForumTopicHidden struct{} // This object represents a service message about General forum topic unhidden in the chat. Currently holds no information. type GeneralForumTopicUnhidden struct{} +// Gift (https://core.telegram.org/bots/api#gift) +// +// This object represents a gift that can be sent by the bot. +type Gift struct { + // Unique identifier of the gift + Id string `json:"id"` + // The sticker that represents the gift + Sticker Sticker `json:"sticker"` + // The number of Telegram Stars that must be paid to send the sticker + StarCount int64 `json:"star_count"` + // Optional. The total number of the gifts of this type that can be sent; for limited gifts only + TotalCount int64 `json:"total_count,omitempty"` + // Optional. The number of remaining gifts of this type that can be sent; for limited gifts only + RemainingCount int64 `json:"remaining_count,omitempty"` +} + +// Gifts (https://core.telegram.org/bots/api#gifts) +// +// This object represent a list of gifts. +type Gifts struct { + // The list of gifts + Gifts []Gift `json:"gifts,omitempty"` +} + // Giveaway (https://core.telegram.org/bots/api#giveaway) // // This object represents a message about a scheduled giveaway. @@ -7694,6 +7718,16 @@ type PreCheckoutQuery struct { OrderInfo *OrderInfo `json:"order_info,omitempty"` } +// PreparedInlineMessage (https://core.telegram.org/bots/api#preparedinlinemessage) +// +// Describes an inline message to be sent by a user of a Mini App. +type PreparedInlineMessage struct { + // Unique identifier of the prepared message + Id string `json:"id"` + // Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used + ExpirationDate int64 `json:"expiration_date"` +} + // ProximityAlertTriggered (https://core.telegram.org/bots/api#proximityalerttriggered) // // This object represents the content of a service message, sent whenever a user in the chat triggers a proximity alert set by another user. @@ -8452,6 +8486,12 @@ type SuccessfulPayment struct { TotalAmount int64 `json:"total_amount"` // Bot-specified invoice payload InvoicePayload string `json:"invoice_payload"` + // Optional. Expiration date of the subscription, in Unix time; for recurring payments only + SubscriptionExpirationDate int64 `json:"subscription_expiration_date,omitempty"` + // Optional. True, if the payment is a recurring payment for a subscription + IsRecurring bool `json:"is_recurring,omitempty"` + // Optional. True, if the payment is the first payment for a subscription + IsFirstRecurring bool `json:"is_first_recurring,omitempty"` // Optional. Identifier of the shipping option chosen by the user ShippingOptionId string `json:"shipping_option_id,omitempty"` // Optional. Order information provided by the user @@ -8525,10 +8565,14 @@ type MergedTransactionPartner struct { User *User `json:"user,omitempty"` // Optional. Bot-specified invoice payload (Only for user) InvoicePayload string `json:"invoice_payload,omitempty"` + // Optional. The duration of the paid subscription (Only for user) + SubscriptionPeriod int64 `json:"subscription_period,omitempty"` // Optional. Information about the paid media bought by the user (Only for user) PaidMedia []PaidMedia `json:"paid_media,omitempty"` // Optional. Bot-specified paid media payload (Only for user) PaidMediaPayload string `json:"paid_media_payload,omitempty"` + // Optional. The gift sent to the user by the bot (Only for user) + Gift string `json:"gift,omitempty"` // Optional. State of the transaction if the transaction is outgoing (Only for fragment) WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"` // Optional. The number of successful requests that exceeded regular limits and were therefore billed (Only for telegram_api) @@ -8801,20 +8845,26 @@ type TransactionPartnerUser struct { User User `json:"user"` // Optional. Bot-specified invoice payload InvoicePayload string `json:"invoice_payload,omitempty"` + // Optional. The duration of the paid subscription + SubscriptionPeriod int64 `json:"subscription_period,omitempty"` // Optional. Information about the paid media bought by the user PaidMedia []PaidMedia `json:"paid_media,omitempty"` // Optional. Bot-specified paid media payload PaidMediaPayload string `json:"paid_media_payload,omitempty"` + // Optional. The gift sent to the user by the bot + Gift string `json:"gift,omitempty"` } // UnmarshalJSON is a custom JSON unmarshaller to use the helpers which allow for unmarshalling structs into interfaces. func (v *TransactionPartnerUser) UnmarshalJSON(b []byte) error { // All fields in TransactionPartnerUser, with interface fields as json.RawMessage type tmp struct { - User User `json:"user"` - InvoicePayload string `json:"invoice_payload"` - PaidMedia json.RawMessage `json:"paid_media"` - PaidMediaPayload string `json:"paid_media_payload"` + User User `json:"user"` + InvoicePayload string `json:"invoice_payload"` + SubscriptionPeriod int64 `json:"subscription_period"` + PaidMedia json.RawMessage `json:"paid_media"` + PaidMediaPayload string `json:"paid_media_payload"` + Gift string `json:"gift"` } t := tmp{} err := json.Unmarshal(b, &t) @@ -8824,11 +8874,13 @@ func (v *TransactionPartnerUser) UnmarshalJSON(b []byte) error { v.User = t.User v.InvoicePayload = t.InvoicePayload + v.SubscriptionPeriod = t.SubscriptionPeriod v.PaidMedia, err = unmarshalPaidMediaArray(t.PaidMedia) if err != nil { return fmt.Errorf("failed to unmarshal custom JSON field PaidMedia: %w", err) } v.PaidMediaPayload = t.PaidMediaPayload + v.Gift = t.Gift return nil } @@ -8841,11 +8893,13 @@ func (v TransactionPartnerUser) GetType() string { // MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with types in a non-generic world. func (v TransactionPartnerUser) MergeTransactionPartner() MergedTransactionPartner { return MergedTransactionPartner{ - Type: "user", - User: &v.User, - InvoicePayload: v.InvoicePayload, - PaidMedia: v.PaidMedia, - PaidMediaPayload: v.PaidMediaPayload, + Type: "user", + User: &v.User, + InvoicePayload: v.InvoicePayload, + SubscriptionPeriod: v.SubscriptionPeriod, + PaidMedia: v.PaidMedia, + PaidMediaPayload: v.PaidMediaPayload, + Gift: v.Gift, } } diff --git a/spec_commit b/spec_commit index b6ac426..5975230 100644 --- a/spec_commit +++ b/spec_commit @@ -1 +1 @@ -15b6cd15658668b7017f3c069e27405ca4f4428e \ No newline at end of file +ab9a754dd14125ce02510a1d2adec6312ce456e4 \ No newline at end of file