Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest bot API version 8.0 #205

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions gen_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
229 changes: 229 additions & 0 deletions gen_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading