From 64f77319b2a21f27e19cfa2745f47eae476a6827 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 23:37:14 +0000 Subject: [PATCH] chore(deps): bump github.com/PaulSonOfLars/gotgbot/v2 Bumps [github.com/PaulSonOfLars/gotgbot/v2](https://github.com/PaulSonOfLars/gotgbot) from 2.0.0-rc.27 to 2.0.0-rc.30. - [Release notes](https://github.com/PaulSonOfLars/gotgbot/releases) - [Commits](https://github.com/PaulSonOfLars/gotgbot/compare/v2.0.0-rc.27...v2.0.0-rc.30) --- updated-dependencies: - dependency-name: github.com/PaulSonOfLars/gotgbot/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../PaulSonOfLars/gotgbot/v2/bot.go | 35 +- .../PaulSonOfLars/gotgbot/v2/file.go | 94 + .../PaulSonOfLars/gotgbot/v2/formatting.go | 38 +- .../PaulSonOfLars/gotgbot/v2/gen_consts.go | 19 + .../PaulSonOfLars/gotgbot/v2/gen_helpers.go | 10 + .../PaulSonOfLars/gotgbot/v2/gen_methods.go | 2022 ++++++++++++----- .../PaulSonOfLars/gotgbot/v2/gen_types.go | 1917 +++++++++++++--- .../PaulSonOfLars/gotgbot/v2/request.go | 100 +- .../PaulSonOfLars/gotgbot/v2/spec_commit | 2 +- vendor/modules.txt | 2 +- 12 files changed, 3208 insertions(+), 1037 deletions(-) create mode 100644 vendor/github.com/PaulSonOfLars/gotgbot/v2/file.go diff --git a/go.mod b/go.mod index 98f5b87ff..d2c19595a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/AlecAivazis/survey/v2 v2.3.7 - github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27 + github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.30 github.com/alecthomas/kong v0.9.0 github.com/bmatcuk/doublestar/v3 v3.0.0 github.com/containerd/platforms v0.2.1 diff --git a/go.sum b/go.sum index d447a022a..44acf924a 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= -github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27 h1:rOlGzmYC3jPVPLVLWKMiiYuePQ6MV8Cyw5qJYBoMnkY= -github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27/go.mod h1:kL1v4iIjlalwm3gCYGvF4NLa3hs+aKEfRkNJvj4aoDU= +github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.30 h1:kPFkEzqg3+5gu077Zrg+24d0rO0Iwdx/ZUUHFFprfsc= +github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.30/go.mod h1:kL1v4iIjlalwm3gCYGvF4NLa3hs+aKEfRkNJvj4aoDU= github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg= github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/bot.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/bot.go index 6c63e792f..7f6ab2fdd 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/bot.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/bot.go @@ -1,15 +1,23 @@ package gotgbot import ( + "context" "encoding/json" "errors" "fmt" "net/http" + "strconv" + "strings" "time" ) //go:generate go run ./scripts/generate +var ( + ErrNilBotClient = errors.New("nil BotClient") + ErrInvalidTokenFormat = errors.New("invalid token format") +) + // Bot is the default Bot struct used to send and receive messages to the telegram API. type Bot struct { // Token stores the bot's secret token obtained from t.me/BotFather, and used to interact with telegram's API. @@ -75,6 +83,24 @@ func NewBot(token string, opts *BotOpts) (*Bot, error) { return nil, fmt.Errorf("failed to check bot token: %w", err) } b.User = *botUser + } else { + // If token checks are disabled, we populate the bot's ID from the token. + split := strings.Split(token, ":") + if len(split) != 2 { + return nil, fmt.Errorf("%w: expected '123:abcd', got %s", ErrInvalidTokenFormat, token) + } + + id, err := strconv.ParseInt(split[0], 10, 64) + if err != nil { + return nil, fmt.Errorf("failed to parse bot ID from token: %w", err) + } + b.User = User{ + Id: id, + IsBot: true, + // We mark these fields as missing so we can know why they're not available + FirstName: "", + Username: "", + } } return &b, nil @@ -88,15 +114,14 @@ func (bot *Bot) UseMiddleware(mw func(client BotClient) BotClient) *Bot { return bot } -var ErrNilBotClient = errors.New("nil BotClient") +func (bot *Bot) Request(method string, params map[string]string, data map[string]FileReader, opts *RequestOpts) (json.RawMessage, error) { + return bot.RequestWithContext(context.Background(), method, params, data, opts) +} -func (bot *Bot) Request(method string, params map[string]string, data map[string]NamedReader, opts *RequestOpts) (json.RawMessage, error) { +func (bot *Bot) RequestWithContext(ctx context.Context, method string, params map[string]string, data map[string]FileReader, opts *RequestOpts) (json.RawMessage, error) { if bot.BotClient == nil { return nil, ErrNilBotClient } - ctx, cancel := bot.BotClient.TimeoutContext(opts) - defer cancel() - return bot.BotClient.RequestWithContext(ctx, bot.Token, method, params, data, opts) } diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/file.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/file.go new file mode 100644 index 000000000..bb2a98369 --- /dev/null +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/file.go @@ -0,0 +1,94 @@ +package gotgbot + +import ( + "encoding/json" + "errors" + "io" +) + +// InputFile (https://core.telegram.org/bots/api#inputfile) +// +// This object represents the contents of a file to be uploaded. +// Must be posted using multipart/form-data in the usual way that files are uploaded via the browser. +type InputFile interface { + InputFileOrString + justFiles() +} + +// InputFileOrString (https://core.telegram.org/bots/api#inputfile) +// +// This object represents the contents of a file to be uploaded, or a publicly accessible URL to be reused. +// Files must be posted using multipart/form-data in the usual way that files are uploaded via the browser. +type InputFileOrString interface { + Attach(name string, data map[string]FileReader) error + getValue() string +} + +var ( + _ InputFileOrString = &FileReader{} + _ InputFile = &FileReader{} +) + +type FileReader struct { + Name string + Data io.Reader + + value string +} + +func (f *FileReader) MarshalJSON() ([]byte, error) { + return json.Marshal(f.getValue()) +} + +var ErrAttachmentKeyAlreadyExists = errors.New("key already exists") + +func (f *FileReader) justFiles() {} + +func (f *FileReader) Attach(key string, data map[string]FileReader) error { + if f.Data == nil { + // if no data, this must be a string; nothing to "attach". + return nil + } + + if _, ok := data[key]; ok { + return ErrAttachmentKeyAlreadyExists + } + f.value = "attach://" + key + data[key] = *f + return nil +} + +// getValue returns the file attach reference for the relevant multipart form. +// Make sure to only call getValue after having called Attach(), to ensure any files have been included. +func (f *FileReader) getValue() string { + return f.value +} + +// InputFileByURL is used to send a file on the internet via a publicly accessible HTTP URL. +func InputFileByURL(url string) InputFileOrString { + return &FileReader{value: url} +} + +// InputFileByID is used to send a file that is already present on telegram's servers, using its telegram file_id. +func InputFileByID(fileID string) InputFileOrString { + return &FileReader{value: fileID} +} + +// InputFileByReader is used to send a file by a reader interface; such as a filehandle from os.Open(), or from a byte +// buffer. +// +// For example: +// +// f, err := os.Open("some_file.go") +// if err != nil { +// return fmt.Errorf("failed to open file: %w", err) +// } +// +// m, err := b.SendDocument(, gotgbot.InputFileByReader("source.go", f), nil) +// +// Or +// +// m, err := b.SendDocument(, gotgbot.InputFileByReader("file.txt", strings.NewReader("Some file contents")), nil) +func InputFileByReader(name string, r io.Reader) InputFile { + return &FileReader{Name: name, Data: r} +} diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/formatting.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/formatting.go index a2c47be43..2909b6472 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/formatting.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/formatting.go @@ -15,25 +15,27 @@ var mdMap = map[string]string{ } var mdV2Map = map[string]string{ - "bold": "*", - "italic": "_", - "code": "`", - "pre": "```", - "underline": "__", - "strikethrough": "~", - "spoiler": "||", - "blockquote": ">", + "bold": "*", + "italic": "_", + "code": "`", + "pre": "```", + "underline": "__", + "strikethrough": "~", + "spoiler": "||", + "blockquote": ">", + "expandable_blockquote": "**>", } var htmlMap = map[string]string{ - "bold": "b", - "italic": "i", - "code": "code", - "pre": "pre", - "underline": "u", - "strikethrough": "s", - "spoiler": "span class=\"tg-spoiler\"", - "blockquote": "blockquote", + "bold": "b", + "italic": "i", + "code": "code", + "pre": "pre", + "underline": "u", + "strikethrough": "s", + "spoiler": "span class=\"tg-spoiler\"", + "blockquote": "blockquote", + "expandable_blockquote": "blockquote expandable", } // OriginalMD gets the original markdown formatting of a message text. @@ -209,6 +211,8 @@ func writeFinalHTML(data []uint16, ent MessageEntity, start int64, cntnt string) return prevText + `` + cntnt + "" case "blockquote": return prevText + `
` + cntnt + "
" + case "expandable_blockquote": + return prevText + `
` + cntnt + "
" default: return prevText + cntnt } @@ -243,6 +247,8 @@ func writeFinalMarkdownV2(data []uint16, ent MessageEntity, start int64, cntnt s return prevText + pre + "[" + cleanCntnt + "](" + ent.Url + ")" + post case "blockquote": return prevText + pre + ">" + strings.Join(strings.Split(cleanCntnt, "\n"), "\n>") + post + case "expandable_blockquote": + return prevText + pre + "**>" + strings.Join(strings.Split(cleanCntnt, "\n"), "\n>") + "||" + post default: return prevText + cntnt } diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_consts.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_consts.go index a118f151d..9dcf0cf43 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_consts.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_consts.go @@ -20,6 +20,7 @@ const ( UpdateTypeCallbackQuery = "callback_query" UpdateTypeShippingQuery = "shipping_query" UpdateTypePreCheckoutQuery = "pre_checkout_query" + UpdateTypePurchasedPaidMedia = "purchased_paid_media" UpdateTypePoll = "poll" UpdateTypePollAnswer = "poll_answer" UpdateTypeMyChatMember = "my_chat_member" @@ -77,6 +78,9 @@ func (u Update) GetType() string { case u.PreCheckoutQuery != nil: return UpdateTypePreCheckoutQuery + case u.PurchasedPaidMedia != nil: + return UpdateTypePurchasedPaidMedia + case u.Poll != nil: return UpdateTypePoll @@ -111,6 +115,21 @@ const ( ParseModeNone = "" ) +// The consts listed below represent all the chat action options that can be sent to telegram. +const ( + ChatActionTyping = "typing" + ChatActionUploadPhoto = "upload_photo" + ChatActionRecordVideo = "record_video" + ChatActionUploadVideo = "upload_video" + ChatActionRecordVoice = "record_voice" + ChatActionUploadVoice = "upload_voice" + ChatActionUploadDocument = "upload_document" + ChatActionChooseSticker = "choose_sticker" + ChatActionFindLocation = "find_location" + ChatActionRecordVideoNote = "record_video_note" + ChatActionUploadVideoNote = "upload_video_note" +) + // The consts listed below represent all the sticker types that can be obtained from telegram. const ( StickerTypeRegular = "regular" diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_helpers.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_helpers.go index 1c1bcd3dd..c3f34a5bf 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_helpers.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_helpers.go @@ -33,6 +33,11 @@ func (c Chat) CreateInviteLink(b *Bot, opts *CreateChatInviteLinkOpts) (*ChatInv return b.CreateChatInviteLink(c.Id, opts) } +// CreateSubscriptionInviteLink Helper method for Bot.CreateChatSubscriptionInviteLink. +func (c Chat) CreateSubscriptionInviteLink(b *Bot, subscriptionPeriod int64, subscriptionPrice int64, opts *CreateChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) { + return b.CreateChatSubscriptionInviteLink(c.Id, subscriptionPeriod, subscriptionPrice, opts) +} + // DeclineJoinRequest Helper method for Bot.DeclineChatJoinRequest. func (c Chat) DeclineJoinRequest(b *Bot, userId int64, opts *DeclineChatJoinRequestOpts) (bool, error) { return b.DeclineChatJoinRequest(c.Id, userId, opts) @@ -53,6 +58,11 @@ func (c Chat) EditInviteLink(b *Bot, inviteLink string, opts *EditChatInviteLink return b.EditChatInviteLink(c.Id, inviteLink, opts) } +// EditSubscriptionInviteLink Helper method for Bot.EditChatSubscriptionInviteLink. +func (c Chat) EditSubscriptionInviteLink(b *Bot, inviteLink string, opts *EditChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) { + return b.EditChatSubscriptionInviteLink(c.Id, inviteLink, opts) +} + // ExportInviteLink Helper method for Bot.ExportChatInviteLink. func (c Chat) ExportInviteLink(b *Bot, opts *ExportChatInviteLinkOpts) (string, error) { return b.ExportChatInviteLink(c.Id, opts) diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_methods.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_methods.go index 64d11f195..f7bebb768 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_methods.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_methods.go @@ -4,14 +4,13 @@ package gotgbot import ( - "bytes" + "context" "encoding/json" "fmt" - "io" "strconv" ) -// AddStickerToSetOpts is the set of optional fields for Bot.AddStickerToSet. +// AddStickerToSetOpts is the set of optional fields for Bot.AddStickerToSet and Bot.AddStickerToSetWithContext. type AddStickerToSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -25,8 +24,13 @@ type AddStickerToSetOpts struct { // - sticker (type InputSticker): A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn't changed. // - opts (type AddStickerToSetOpts): All optional parameters. func (bot *Bot) AddStickerToSet(userId int64, name string, sticker InputSticker, opts *AddStickerToSetOpts) (bool, error) { + return bot.AddStickerToSetWithContext(context.Background(), userId, name, sticker, opts) +} + +// AddStickerToSetWithContext is the same as Bot.AddStickerToSet, but with a context.Context parameter +func (bot *Bot) AddStickerToSetWithContext(ctx context.Context, userId int64, name string, sticker InputSticker, opts *AddStickerToSetOpts) (bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["user_id"] = strconv.FormatInt(userId, 10) v["name"] = name inputBs, err := sticker.InputParams("sticker", data) @@ -40,7 +44,7 @@ func (bot *Bot) AddStickerToSet(userId int64, name string, sticker InputSticker, reqOpts = opts.RequestOpts } - r, err := bot.Request("addStickerToSet", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "addStickerToSet", v, data, reqOpts) if err != nil { return false, err } @@ -49,7 +53,7 @@ func (bot *Bot) AddStickerToSet(userId int64, name string, sticker InputSticker, return b, json.Unmarshal(r, &b) } -// AnswerCallbackQueryOpts is the set of optional fields for Bot.AnswerCallbackQuery. +// AnswerCallbackQueryOpts is the set of optional fields for Bot.AnswerCallbackQuery and Bot.AnswerCallbackQueryWithContext. type AnswerCallbackQueryOpts struct { // Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters Text string @@ -69,6 +73,11 @@ type AnswerCallbackQueryOpts struct { // - callbackQueryId (type string): Unique identifier for the query to be answered // - opts (type AnswerCallbackQueryOpts): All optional parameters. func (bot *Bot) AnswerCallbackQuery(callbackQueryId string, opts *AnswerCallbackQueryOpts) (bool, error) { + return bot.AnswerCallbackQueryWithContext(context.Background(), callbackQueryId, opts) +} + +// AnswerCallbackQueryWithContext is the same as Bot.AnswerCallbackQuery, but with a context.Context parameter +func (bot *Bot) AnswerCallbackQueryWithContext(ctx context.Context, callbackQueryId string, opts *AnswerCallbackQueryOpts) (bool, error) { v := map[string]string{} v["callback_query_id"] = callbackQueryId if opts != nil { @@ -85,7 +94,7 @@ func (bot *Bot) AnswerCallbackQuery(callbackQueryId string, opts *AnswerCallback reqOpts = opts.RequestOpts } - r, err := bot.Request("answerCallbackQuery", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "answerCallbackQuery", v, nil, reqOpts) if err != nil { return false, err } @@ -94,7 +103,7 @@ func (bot *Bot) AnswerCallbackQuery(callbackQueryId string, opts *AnswerCallback return b, json.Unmarshal(r, &b) } -// AnswerInlineQueryOpts is the set of optional fields for Bot.AnswerInlineQuery. +// AnswerInlineQueryOpts is the set of optional fields for Bot.AnswerInlineQuery and Bot.AnswerInlineQueryWithContext. type AnswerInlineQueryOpts struct { // The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300. CacheTime int64 @@ -116,6 +125,11 @@ type AnswerInlineQueryOpts struct { // - results (type []InlineQueryResult): A JSON-serialized array of results for the inline query // - opts (type AnswerInlineQueryOpts): All optional parameters. func (bot *Bot) AnswerInlineQuery(inlineQueryId string, results []InlineQueryResult, opts *AnswerInlineQueryOpts) (bool, error) { + return bot.AnswerInlineQueryWithContext(context.Background(), inlineQueryId, results, opts) +} + +// AnswerInlineQueryWithContext is the same as Bot.AnswerInlineQuery, but with a context.Context parameter +func (bot *Bot) AnswerInlineQueryWithContext(ctx context.Context, inlineQueryId string, results []InlineQueryResult, opts *AnswerInlineQueryOpts) (bool, error) { v := map[string]string{} v["inline_query_id"] = inlineQueryId if results != nil { @@ -145,7 +159,7 @@ func (bot *Bot) AnswerInlineQuery(inlineQueryId string, results []InlineQueryRes reqOpts = opts.RequestOpts } - r, err := bot.Request("answerInlineQuery", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "answerInlineQuery", v, nil, reqOpts) if err != nil { return false, err } @@ -154,7 +168,7 @@ func (bot *Bot) AnswerInlineQuery(inlineQueryId string, results []InlineQueryRes return b, json.Unmarshal(r, &b) } -// AnswerPreCheckoutQueryOpts is the set of optional fields for Bot.AnswerPreCheckoutQuery. +// AnswerPreCheckoutQueryOpts is the set of optional fields for Bot.AnswerPreCheckoutQuery and Bot.AnswerPreCheckoutQueryWithContext. type AnswerPreCheckoutQueryOpts struct { // Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. ErrorMessage string @@ -169,6 +183,11 @@ type AnswerPreCheckoutQueryOpts struct { // - ok (type bool): Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. // - opts (type AnswerPreCheckoutQueryOpts): All optional parameters. func (bot *Bot) AnswerPreCheckoutQuery(preCheckoutQueryId string, ok bool, opts *AnswerPreCheckoutQueryOpts) (bool, error) { + return bot.AnswerPreCheckoutQueryWithContext(context.Background(), preCheckoutQueryId, ok, opts) +} + +// AnswerPreCheckoutQueryWithContext is the same as Bot.AnswerPreCheckoutQuery, but with a context.Context parameter +func (bot *Bot) AnswerPreCheckoutQueryWithContext(ctx context.Context, preCheckoutQueryId string, ok bool, opts *AnswerPreCheckoutQueryOpts) (bool, error) { v := map[string]string{} v["pre_checkout_query_id"] = preCheckoutQueryId v["ok"] = strconv.FormatBool(ok) @@ -181,7 +200,7 @@ func (bot *Bot) AnswerPreCheckoutQuery(preCheckoutQueryId string, ok bool, opts reqOpts = opts.RequestOpts } - r, err := bot.Request("answerPreCheckoutQuery", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "answerPreCheckoutQuery", v, nil, reqOpts) if err != nil { return false, err } @@ -190,7 +209,7 @@ func (bot *Bot) AnswerPreCheckoutQuery(preCheckoutQueryId string, ok bool, opts return b, json.Unmarshal(r, &b) } -// AnswerShippingQueryOpts is the set of optional fields for Bot.AnswerShippingQuery. +// AnswerShippingQueryOpts is the set of optional fields for Bot.AnswerShippingQuery and Bot.AnswerShippingQueryWithContext. type AnswerShippingQueryOpts struct { // Required if ok is True. A JSON-serialized array of available shipping options. ShippingOptions []ShippingOption @@ -207,6 +226,11 @@ type AnswerShippingQueryOpts struct { // - ok (type bool): Pass True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible) // - opts (type AnswerShippingQueryOpts): All optional parameters. func (bot *Bot) AnswerShippingQuery(shippingQueryId string, ok bool, opts *AnswerShippingQueryOpts) (bool, error) { + return bot.AnswerShippingQueryWithContext(context.Background(), shippingQueryId, ok, opts) +} + +// AnswerShippingQueryWithContext is the same as Bot.AnswerShippingQuery, but with a context.Context parameter +func (bot *Bot) AnswerShippingQueryWithContext(ctx context.Context, shippingQueryId string, ok bool, opts *AnswerShippingQueryOpts) (bool, error) { v := map[string]string{} v["shipping_query_id"] = shippingQueryId v["ok"] = strconv.FormatBool(ok) @@ -226,7 +250,7 @@ func (bot *Bot) AnswerShippingQuery(shippingQueryId string, ok bool, opts *Answe reqOpts = opts.RequestOpts } - r, err := bot.Request("answerShippingQuery", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "answerShippingQuery", v, nil, reqOpts) if err != nil { return false, err } @@ -235,7 +259,7 @@ func (bot *Bot) AnswerShippingQuery(shippingQueryId string, ok bool, opts *Answe return b, json.Unmarshal(r, &b) } -// AnswerWebAppQueryOpts is the set of optional fields for Bot.AnswerWebAppQuery. +// AnswerWebAppQueryOpts is the set of optional fields for Bot.AnswerWebAppQuery and Bot.AnswerWebAppQueryWithContext. type AnswerWebAppQueryOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -248,6 +272,11 @@ type AnswerWebAppQueryOpts struct { // - result (type InlineQueryResult): A JSON-serialized object describing the message to be sent // - opts (type AnswerWebAppQueryOpts): All optional parameters. func (bot *Bot) AnswerWebAppQuery(webAppQueryId string, result InlineQueryResult, opts *AnswerWebAppQueryOpts) (*SentWebAppMessage, error) { + return bot.AnswerWebAppQueryWithContext(context.Background(), webAppQueryId, result, opts) +} + +// AnswerWebAppQueryWithContext is the same as Bot.AnswerWebAppQuery, but with a context.Context parameter +func (bot *Bot) AnswerWebAppQueryWithContext(ctx context.Context, webAppQueryId string, result InlineQueryResult, opts *AnswerWebAppQueryOpts) (*SentWebAppMessage, error) { v := map[string]string{} v["web_app_query_id"] = webAppQueryId bs, err := json.Marshal(result) @@ -261,7 +290,7 @@ func (bot *Bot) AnswerWebAppQuery(webAppQueryId string, result InlineQueryResult reqOpts = opts.RequestOpts } - r, err := bot.Request("answerWebAppQuery", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "answerWebAppQuery", v, nil, reqOpts) if err != nil { return nil, err } @@ -270,7 +299,7 @@ func (bot *Bot) AnswerWebAppQuery(webAppQueryId string, result InlineQueryResult return &s, json.Unmarshal(r, &s) } -// ApproveChatJoinRequestOpts is the set of optional fields for Bot.ApproveChatJoinRequest. +// ApproveChatJoinRequestOpts is the set of optional fields for Bot.ApproveChatJoinRequest and Bot.ApproveChatJoinRequestWithContext. type ApproveChatJoinRequestOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -283,6 +312,11 @@ type ApproveChatJoinRequestOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type ApproveChatJoinRequestOpts): All optional parameters. func (bot *Bot) ApproveChatJoinRequest(chatId int64, userId int64, opts *ApproveChatJoinRequestOpts) (bool, error) { + return bot.ApproveChatJoinRequestWithContext(context.Background(), chatId, userId, opts) +} + +// ApproveChatJoinRequestWithContext is the same as Bot.ApproveChatJoinRequest, but with a context.Context parameter +func (bot *Bot) ApproveChatJoinRequestWithContext(ctx context.Context, chatId int64, userId int64, opts *ApproveChatJoinRequestOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -292,7 +326,7 @@ func (bot *Bot) ApproveChatJoinRequest(chatId int64, userId int64, opts *Approve reqOpts = opts.RequestOpts } - r, err := bot.Request("approveChatJoinRequest", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "approveChatJoinRequest", v, nil, reqOpts) if err != nil { return false, err } @@ -301,7 +335,7 @@ func (bot *Bot) ApproveChatJoinRequest(chatId int64, userId int64, opts *Approve return b, json.Unmarshal(r, &b) } -// BanChatMemberOpts is the set of optional fields for Bot.BanChatMember. +// BanChatMemberOpts is the set of optional fields for Bot.BanChatMember and Bot.BanChatMemberWithContext. type BanChatMemberOpts struct { // Date when the user will be unbanned; Unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only. UntilDate int64 @@ -318,6 +352,11 @@ type BanChatMemberOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type BanChatMemberOpts): All optional parameters. func (bot *Bot) BanChatMember(chatId int64, userId int64, opts *BanChatMemberOpts) (bool, error) { + return bot.BanChatMemberWithContext(context.Background(), chatId, userId, opts) +} + +// BanChatMemberWithContext is the same as Bot.BanChatMember, but with a context.Context parameter +func (bot *Bot) BanChatMemberWithContext(ctx context.Context, chatId int64, userId int64, opts *BanChatMemberOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -333,7 +372,7 @@ func (bot *Bot) BanChatMember(chatId int64, userId int64, opts *BanChatMemberOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("banChatMember", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "banChatMember", v, nil, reqOpts) if err != nil { return false, err } @@ -342,7 +381,7 @@ func (bot *Bot) BanChatMember(chatId int64, userId int64, opts *BanChatMemberOpt return b, json.Unmarshal(r, &b) } -// BanChatSenderChatOpts is the set of optional fields for Bot.BanChatSenderChat. +// BanChatSenderChatOpts is the set of optional fields for Bot.BanChatSenderChat and Bot.BanChatSenderChatWithContext. type BanChatSenderChatOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -355,6 +394,11 @@ type BanChatSenderChatOpts struct { // - senderChatId (type int64): Unique identifier of the target sender chat // - opts (type BanChatSenderChatOpts): All optional parameters. func (bot *Bot) BanChatSenderChat(chatId int64, senderChatId int64, opts *BanChatSenderChatOpts) (bool, error) { + return bot.BanChatSenderChatWithContext(context.Background(), chatId, senderChatId, opts) +} + +// BanChatSenderChatWithContext is the same as Bot.BanChatSenderChat, but with a context.Context parameter +func (bot *Bot) BanChatSenderChatWithContext(ctx context.Context, chatId int64, senderChatId int64, opts *BanChatSenderChatOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["sender_chat_id"] = strconv.FormatInt(senderChatId, 10) @@ -364,7 +408,7 @@ func (bot *Bot) BanChatSenderChat(chatId int64, senderChatId int64, opts *BanCha reqOpts = opts.RequestOpts } - r, err := bot.Request("banChatSenderChat", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "banChatSenderChat", v, nil, reqOpts) if err != nil { return false, err } @@ -373,7 +417,7 @@ func (bot *Bot) BanChatSenderChat(chatId int64, senderChatId int64, opts *BanCha return b, json.Unmarshal(r, &b) } -// CloseOpts is the set of optional fields for Bot.Close. +// CloseOpts is the set of optional fields for Bot.Close and Bot.CloseWithContext. type CloseOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -384,6 +428,11 @@ type CloseOpts struct { // Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters. // - opts (type CloseOpts): All optional parameters. func (bot *Bot) Close(opts *CloseOpts) (bool, error) { + return bot.CloseWithContext(context.Background(), opts) +} + +// CloseWithContext is the same as Bot.Close, but with a context.Context parameter +func (bot *Bot) CloseWithContext(ctx context.Context, opts *CloseOpts) (bool, error) { v := map[string]string{} var reqOpts *RequestOpts @@ -391,7 +440,7 @@ func (bot *Bot) Close(opts *CloseOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("close", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "close", v, nil, reqOpts) if err != nil { return false, err } @@ -400,7 +449,7 @@ func (bot *Bot) Close(opts *CloseOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// CloseForumTopicOpts is the set of optional fields for Bot.CloseForumTopic. +// CloseForumTopicOpts is the set of optional fields for Bot.CloseForumTopic and Bot.CloseForumTopicWithContext. type CloseForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -413,6 +462,11 @@ type CloseForumTopicOpts struct { // - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic // - opts (type CloseForumTopicOpts): All optional parameters. func (bot *Bot) CloseForumTopic(chatId int64, messageThreadId int64, opts *CloseForumTopicOpts) (bool, error) { + return bot.CloseForumTopicWithContext(context.Background(), chatId, messageThreadId, opts) +} + +// CloseForumTopicWithContext is the same as Bot.CloseForumTopic, but with a context.Context parameter +func (bot *Bot) CloseForumTopicWithContext(ctx context.Context, chatId int64, messageThreadId int64, opts *CloseForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10) @@ -422,7 +476,7 @@ func (bot *Bot) CloseForumTopic(chatId int64, messageThreadId int64, opts *Close reqOpts = opts.RequestOpts } - r, err := bot.Request("closeForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "closeForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -431,7 +485,7 @@ func (bot *Bot) CloseForumTopic(chatId int64, messageThreadId int64, opts *Close return b, json.Unmarshal(r, &b) } -// CloseGeneralForumTopicOpts is the set of optional fields for Bot.CloseGeneralForumTopic. +// CloseGeneralForumTopicOpts is the set of optional fields for Bot.CloseGeneralForumTopic and Bot.CloseGeneralForumTopicWithContext. type CloseGeneralForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -443,6 +497,11 @@ type CloseGeneralForumTopicOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type CloseGeneralForumTopicOpts): All optional parameters. func (bot *Bot) CloseGeneralForumTopic(chatId int64, opts *CloseGeneralForumTopicOpts) (bool, error) { + return bot.CloseGeneralForumTopicWithContext(context.Background(), chatId, opts) +} + +// CloseGeneralForumTopicWithContext is the same as Bot.CloseGeneralForumTopic, but with a context.Context parameter +func (bot *Bot) CloseGeneralForumTopicWithContext(ctx context.Context, chatId int64, opts *CloseGeneralForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -451,7 +510,7 @@ func (bot *Bot) CloseGeneralForumTopic(chatId int64, opts *CloseGeneralForumTopi reqOpts = opts.RequestOpts } - r, err := bot.Request("closeGeneralForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "closeGeneralForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -460,7 +519,7 @@ func (bot *Bot) CloseGeneralForumTopic(chatId int64, opts *CloseGeneralForumTopi return b, json.Unmarshal(r, &b) } -// CopyMessageOpts is the set of optional fields for Bot.CopyMessage. +// CopyMessageOpts is the set of optional fields for Bot.CopyMessage and Bot.CopyMessageWithContext. type CopyMessageOpts struct { // Unique identifier for the target message thread (topic) of the forum; for forum supergroups only MessageThreadId int64 @@ -470,10 +529,14 @@ type CopyMessageOpts struct { ParseMode string // A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity + // Pass True, if the caption must be shown above the message media. Ignored if a new caption isn't specified. + ShowCaptionAboveMedia bool // Sends the message silently. Users will receive a notification with no sound. DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -484,12 +547,17 @@ type CopyMessageOpts struct { // CopyMessage (https://core.telegram.org/bots/api#copymessage) // -// Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. +// Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. // - chatId (type int64): Unique identifier for the target chat // - fromChatId (type int64): Unique identifier for the chat where the original message was sent // - messageId (type int64): Message identifier in the chat specified in from_chat_id // - opts (type CopyMessageOpts): All optional parameters. func (bot *Bot) CopyMessage(chatId int64, fromChatId int64, messageId int64, opts *CopyMessageOpts) (*MessageId, error) { + return bot.CopyMessageWithContext(context.Background(), chatId, fromChatId, messageId, opts) +} + +// CopyMessageWithContext is the same as Bot.CopyMessage, but with a context.Context parameter +func (bot *Bot) CopyMessageWithContext(ctx context.Context, chatId int64, fromChatId int64, messageId int64, opts *CopyMessageOpts) (*MessageId, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["from_chat_id"] = strconv.FormatInt(fromChatId, 10) @@ -509,8 +577,10 @@ func (bot *Bot) CopyMessage(chatId int64, fromChatId int64, messageId int64, opt } v["caption_entities"] = string(bs) } + v["show_caption_above_media"] = strconv.FormatBool(opts.ShowCaptionAboveMedia) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -532,7 +602,7 @@ func (bot *Bot) CopyMessage(chatId int64, fromChatId int64, messageId int64, opt reqOpts = opts.RequestOpts } - r, err := bot.Request("copyMessage", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "copyMessage", v, nil, reqOpts) if err != nil { return nil, err } @@ -541,7 +611,7 @@ func (bot *Bot) CopyMessage(chatId int64, fromChatId int64, messageId int64, opt return &m, json.Unmarshal(r, &m) } -// CopyMessagesOpts is the set of optional fields for Bot.CopyMessages. +// CopyMessagesOpts is the set of optional fields for Bot.CopyMessages and Bot.CopyMessagesWithContext. type CopyMessagesOpts struct { // Unique identifier for the target message thread (topic) of the forum; for forum supergroups only MessageThreadId int64 @@ -557,12 +627,17 @@ type CopyMessagesOpts struct { // CopyMessages (https://core.telegram.org/bots/api#copymessages) // -// Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. +// Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. // - chatId (type int64): Unique identifier for the target chat // - fromChatId (type int64): Unique identifier for the chat where the original messages were sent // - messageIds (type []int64): A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. // - opts (type CopyMessagesOpts): All optional parameters. func (bot *Bot) CopyMessages(chatId int64, fromChatId int64, messageIds []int64, opts *CopyMessagesOpts) ([]MessageId, error) { + return bot.CopyMessagesWithContext(context.Background(), chatId, fromChatId, messageIds, opts) +} + +// CopyMessagesWithContext is the same as Bot.CopyMessages, but with a context.Context parameter +func (bot *Bot) CopyMessagesWithContext(ctx context.Context, chatId int64, fromChatId int64, messageIds []int64, opts *CopyMessagesOpts) ([]MessageId, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["from_chat_id"] = strconv.FormatInt(fromChatId, 10) @@ -587,7 +662,7 @@ func (bot *Bot) CopyMessages(chatId int64, fromChatId int64, messageIds []int64, reqOpts = opts.RequestOpts } - r, err := bot.Request("copyMessages", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "copyMessages", v, nil, reqOpts) if err != nil { return nil, err } @@ -596,7 +671,7 @@ func (bot *Bot) CopyMessages(chatId int64, fromChatId int64, messageIds []int64, return m, json.Unmarshal(r, &m) } -// CreateChatInviteLinkOpts is the set of optional fields for Bot.CreateChatInviteLink. +// CreateChatInviteLinkOpts is the set of optional fields for Bot.CreateChatInviteLink and Bot.CreateChatInviteLinkWithContext. type CreateChatInviteLinkOpts struct { // Invite link name; 0-32 characters Name string @@ -616,6 +691,11 @@ type CreateChatInviteLinkOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type CreateChatInviteLinkOpts): All optional parameters. func (bot *Bot) CreateChatInviteLink(chatId int64, opts *CreateChatInviteLinkOpts) (*ChatInviteLink, error) { + return bot.CreateChatInviteLinkWithContext(context.Background(), chatId, opts) +} + +// CreateChatInviteLinkWithContext is the same as Bot.CreateChatInviteLink, but with a context.Context parameter +func (bot *Bot) CreateChatInviteLinkWithContext(ctx context.Context, chatId int64, opts *CreateChatInviteLinkOpts) (*ChatInviteLink, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) if opts != nil { @@ -634,7 +714,50 @@ func (bot *Bot) CreateChatInviteLink(chatId int64, opts *CreateChatInviteLinkOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("createChatInviteLink", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "createChatInviteLink", v, nil, reqOpts) + if err != nil { + return nil, err + } + + var c ChatInviteLink + return &c, json.Unmarshal(r, &c) +} + +// CreateChatSubscriptionInviteLinkOpts is the set of optional fields for Bot.CreateChatSubscriptionInviteLink and Bot.CreateChatSubscriptionInviteLinkWithContext. +type CreateChatSubscriptionInviteLinkOpts struct { + // Invite link name; 0-32 characters + Name string + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// CreateChatSubscriptionInviteLink (https://core.telegram.org/bots/api#createchatsubscriptioninvitelink) +// +// Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object. +// - chatId (type int64): Unique identifier for the target channel chat +// - subscriptionPeriod (type int64): The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days). +// - subscriptionPrice (type int64): The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500 +// - opts (type CreateChatSubscriptionInviteLinkOpts): All optional parameters. +func (bot *Bot) CreateChatSubscriptionInviteLink(chatId int64, subscriptionPeriod int64, subscriptionPrice int64, opts *CreateChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) { + return bot.CreateChatSubscriptionInviteLinkWithContext(context.Background(), chatId, subscriptionPeriod, subscriptionPrice, opts) +} + +// CreateChatSubscriptionInviteLinkWithContext is the same as Bot.CreateChatSubscriptionInviteLink, but with a context.Context parameter +func (bot *Bot) CreateChatSubscriptionInviteLinkWithContext(ctx context.Context, chatId int64, subscriptionPeriod int64, subscriptionPrice int64, opts *CreateChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) { + v := map[string]string{} + v["chat_id"] = strconv.FormatInt(chatId, 10) + v["subscription_period"] = strconv.FormatInt(subscriptionPeriod, 10) + v["subscription_price"] = strconv.FormatInt(subscriptionPrice, 10) + if opts != nil { + v["name"] = opts.Name + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "createChatSubscriptionInviteLink", v, nil, reqOpts) if err != nil { return nil, err } @@ -643,7 +766,7 @@ func (bot *Bot) CreateChatInviteLink(chatId int64, opts *CreateChatInviteLinkOpt return &c, json.Unmarshal(r, &c) } -// CreateForumTopicOpts is the set of optional fields for Bot.CreateForumTopic. +// CreateForumTopicOpts is the set of optional fields for Bot.CreateForumTopic and Bot.CreateForumTopicWithContext. type CreateForumTopicOpts struct { // Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) IconColor int64 @@ -660,6 +783,11 @@ type CreateForumTopicOpts struct { // - name (type string): Topic name, 1-128 characters // - opts (type CreateForumTopicOpts): All optional parameters. func (bot *Bot) CreateForumTopic(chatId int64, name string, opts *CreateForumTopicOpts) (*ForumTopic, error) { + return bot.CreateForumTopicWithContext(context.Background(), chatId, name, opts) +} + +// CreateForumTopicWithContext is the same as Bot.CreateForumTopic, but with a context.Context parameter +func (bot *Bot) CreateForumTopicWithContext(ctx context.Context, chatId int64, name string, opts *CreateForumTopicOpts) (*ForumTopic, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["name"] = name @@ -675,7 +803,7 @@ func (bot *Bot) CreateForumTopic(chatId int64, name string, opts *CreateForumTop reqOpts = opts.RequestOpts } - r, err := bot.Request("createForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "createForumTopic", v, nil, reqOpts) if err != nil { return nil, err } @@ -684,9 +812,11 @@ func (bot *Bot) CreateForumTopic(chatId int64, name string, opts *CreateForumTop return &f, json.Unmarshal(r, &f) } -// CreateInvoiceLinkOpts is the set of optional fields for Bot.CreateInvoiceLink. +// CreateInvoiceLinkOpts is the set of optional fields for Bot.CreateInvoiceLink and Bot.CreateInvoiceLinkWithContext. type CreateInvoiceLinkOpts struct { - // 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 + // Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. + ProviderToken string + // 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. SuggestedTipAmounts []int64 @@ -700,19 +830,19 @@ type CreateInvoiceLinkOpts struct { PhotoWidth int64 // Photo height PhotoHeight int64 - // Pass True if you require the user's full name to complete the order + // Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars. NeedName bool - // Pass True if you require the user's phone number to complete the order + // Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars. NeedPhoneNumber bool - // Pass True if you require the user's email address to complete the order + // Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars. NeedEmail bool - // Pass True if you require the user's shipping address to complete the order + // Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars. NeedShippingAddress bool - // Pass True if the user's phone number should be sent to the provider + // Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars. SendPhoneNumberToProvider bool - // Pass True if the user's email address should be sent to the provider + // Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars. SendEmailToProvider bool - // Pass True if the final price depends on the shipping method + // Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars. IsFlexible bool // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -723,17 +853,20 @@ type CreateInvoiceLinkOpts struct { // Use this method to create a link for an invoice. Returns the created invoice link as String on success. // - title (type string): Product name, 1-32 characters // - description (type string): Product description, 1-255 characters -// - payload (type string): Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. -// - providerToken (type string): Payment provider token, obtained via BotFather -// - currency (type string): Three-letter ISO 4217 currency code, see more on currencies -// - prices (type []LabeledPrice): Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) +// - payload (type string): Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. +// - currency (type string): Three-letter ISO 4217 currency code, see more on currencies. Pass "XTR" for payments in Telegram Stars. +// - prices (type []LabeledPrice): Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars. // - opts (type CreateInvoiceLinkOpts): All optional parameters. -func (bot *Bot) CreateInvoiceLink(title string, description string, payload string, providerToken string, currency string, prices []LabeledPrice, opts *CreateInvoiceLinkOpts) (string, error) { +func (bot *Bot) CreateInvoiceLink(title string, description string, payload string, currency string, prices []LabeledPrice, opts *CreateInvoiceLinkOpts) (string, error) { + return bot.CreateInvoiceLinkWithContext(context.Background(), title, description, payload, currency, prices, opts) +} + +// CreateInvoiceLinkWithContext is the same as Bot.CreateInvoiceLink, but with a context.Context parameter +func (bot *Bot) CreateInvoiceLinkWithContext(ctx context.Context, title string, description string, payload string, currency string, prices []LabeledPrice, opts *CreateInvoiceLinkOpts) (string, error) { v := map[string]string{} v["title"] = title v["description"] = description v["payload"] = payload - v["provider_token"] = providerToken v["currency"] = currency if prices != nil { bs, err := json.Marshal(prices) @@ -743,6 +876,7 @@ func (bot *Bot) CreateInvoiceLink(title string, description string, payload stri v["prices"] = string(bs) } if opts != nil { + v["provider_token"] = opts.ProviderToken if opts.MaxTipAmount != 0 { v["max_tip_amount"] = strconv.FormatInt(opts.MaxTipAmount, 10) } @@ -778,7 +912,7 @@ func (bot *Bot) CreateInvoiceLink(title string, description string, payload stri reqOpts = opts.RequestOpts } - r, err := bot.Request("createInvoiceLink", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "createInvoiceLink", v, nil, reqOpts) if err != nil { return "", err } @@ -787,7 +921,7 @@ func (bot *Bot) CreateInvoiceLink(title string, description string, payload stri return s, json.Unmarshal(r, &s) } -// CreateNewStickerSetOpts is the set of optional fields for Bot.CreateNewStickerSet. +// CreateNewStickerSetOpts is the set of optional fields for Bot.CreateNewStickerSet and Bot.CreateNewStickerSetWithContext. type CreateNewStickerSetOpts struct { // Type of stickers in the set, pass "regular", "mask", or "custom_emoji". By default, a regular sticker set is created. StickerType string @@ -806,8 +940,13 @@ type CreateNewStickerSetOpts struct { // - stickers (type []InputSticker): A JSON-serialized list of 1-50 initial stickers to be added to the sticker set // - opts (type CreateNewStickerSetOpts): All optional parameters. func (bot *Bot) CreateNewStickerSet(userId int64, name string, title string, stickers []InputSticker, opts *CreateNewStickerSetOpts) (bool, error) { + return bot.CreateNewStickerSetWithContext(context.Background(), userId, name, title, stickers, opts) +} + +// CreateNewStickerSetWithContext is the same as Bot.CreateNewStickerSet, but with a context.Context parameter +func (bot *Bot) CreateNewStickerSetWithContext(ctx context.Context, userId int64, name string, title string, stickers []InputSticker, opts *CreateNewStickerSetOpts) (bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["user_id"] = strconv.FormatInt(userId, 10) v["name"] = name v["title"] = title @@ -836,7 +975,7 @@ func (bot *Bot) CreateNewStickerSet(userId int64, name string, title string, sti reqOpts = opts.RequestOpts } - r, err := bot.Request("createNewStickerSet", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "createNewStickerSet", v, data, reqOpts) if err != nil { return false, err } @@ -845,7 +984,7 @@ func (bot *Bot) CreateNewStickerSet(userId int64, name string, title string, sti return b, json.Unmarshal(r, &b) } -// DeclineChatJoinRequestOpts is the set of optional fields for Bot.DeclineChatJoinRequest. +// DeclineChatJoinRequestOpts is the set of optional fields for Bot.DeclineChatJoinRequest and Bot.DeclineChatJoinRequestWithContext. type DeclineChatJoinRequestOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -858,6 +997,11 @@ type DeclineChatJoinRequestOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type DeclineChatJoinRequestOpts): All optional parameters. func (bot *Bot) DeclineChatJoinRequest(chatId int64, userId int64, opts *DeclineChatJoinRequestOpts) (bool, error) { + return bot.DeclineChatJoinRequestWithContext(context.Background(), chatId, userId, opts) +} + +// DeclineChatJoinRequestWithContext is the same as Bot.DeclineChatJoinRequest, but with a context.Context parameter +func (bot *Bot) DeclineChatJoinRequestWithContext(ctx context.Context, chatId int64, userId int64, opts *DeclineChatJoinRequestOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -867,7 +1011,7 @@ func (bot *Bot) DeclineChatJoinRequest(chatId int64, userId int64, opts *Decline reqOpts = opts.RequestOpts } - r, err := bot.Request("declineChatJoinRequest", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "declineChatJoinRequest", v, nil, reqOpts) if err != nil { return false, err } @@ -876,7 +1020,7 @@ func (bot *Bot) DeclineChatJoinRequest(chatId int64, userId int64, opts *Decline return b, json.Unmarshal(r, &b) } -// DeleteChatPhotoOpts is the set of optional fields for Bot.DeleteChatPhoto. +// DeleteChatPhotoOpts is the set of optional fields for Bot.DeleteChatPhoto and Bot.DeleteChatPhotoWithContext. type DeleteChatPhotoOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -888,6 +1032,11 @@ type DeleteChatPhotoOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type DeleteChatPhotoOpts): All optional parameters. func (bot *Bot) DeleteChatPhoto(chatId int64, opts *DeleteChatPhotoOpts) (bool, error) { + return bot.DeleteChatPhotoWithContext(context.Background(), chatId, opts) +} + +// DeleteChatPhotoWithContext is the same as Bot.DeleteChatPhoto, but with a context.Context parameter +func (bot *Bot) DeleteChatPhotoWithContext(ctx context.Context, chatId int64, opts *DeleteChatPhotoOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -896,7 +1045,7 @@ func (bot *Bot) DeleteChatPhoto(chatId int64, opts *DeleteChatPhotoOpts) (bool, reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteChatPhoto", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteChatPhoto", v, nil, reqOpts) if err != nil { return false, err } @@ -905,7 +1054,7 @@ func (bot *Bot) DeleteChatPhoto(chatId int64, opts *DeleteChatPhotoOpts) (bool, return b, json.Unmarshal(r, &b) } -// DeleteChatStickerSetOpts is the set of optional fields for Bot.DeleteChatStickerSet. +// DeleteChatStickerSetOpts is the set of optional fields for Bot.DeleteChatStickerSet and Bot.DeleteChatStickerSetWithContext. type DeleteChatStickerSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -917,6 +1066,11 @@ type DeleteChatStickerSetOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type DeleteChatStickerSetOpts): All optional parameters. func (bot *Bot) DeleteChatStickerSet(chatId int64, opts *DeleteChatStickerSetOpts) (bool, error) { + return bot.DeleteChatStickerSetWithContext(context.Background(), chatId, opts) +} + +// DeleteChatStickerSetWithContext is the same as Bot.DeleteChatStickerSet, but with a context.Context parameter +func (bot *Bot) DeleteChatStickerSetWithContext(ctx context.Context, chatId int64, opts *DeleteChatStickerSetOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -925,7 +1079,7 @@ func (bot *Bot) DeleteChatStickerSet(chatId int64, opts *DeleteChatStickerSetOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteChatStickerSet", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteChatStickerSet", v, nil, reqOpts) if err != nil { return false, err } @@ -934,7 +1088,7 @@ func (bot *Bot) DeleteChatStickerSet(chatId int64, opts *DeleteChatStickerSetOpt return b, json.Unmarshal(r, &b) } -// DeleteForumTopicOpts is the set of optional fields for Bot.DeleteForumTopic. +// DeleteForumTopicOpts is the set of optional fields for Bot.DeleteForumTopic and Bot.DeleteForumTopicWithContext. type DeleteForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -947,6 +1101,11 @@ type DeleteForumTopicOpts struct { // - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic // - opts (type DeleteForumTopicOpts): All optional parameters. func (bot *Bot) DeleteForumTopic(chatId int64, messageThreadId int64, opts *DeleteForumTopicOpts) (bool, error) { + return bot.DeleteForumTopicWithContext(context.Background(), chatId, messageThreadId, opts) +} + +// DeleteForumTopicWithContext is the same as Bot.DeleteForumTopic, but with a context.Context parameter +func (bot *Bot) DeleteForumTopicWithContext(ctx context.Context, chatId int64, messageThreadId int64, opts *DeleteForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10) @@ -956,7 +1115,7 @@ func (bot *Bot) DeleteForumTopic(chatId int64, messageThreadId int64, opts *Dele reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -965,7 +1124,7 @@ func (bot *Bot) DeleteForumTopic(chatId int64, messageThreadId int64, opts *Dele return b, json.Unmarshal(r, &b) } -// DeleteMessageOpts is the set of optional fields for Bot.DeleteMessage. +// DeleteMessageOpts is the set of optional fields for Bot.DeleteMessage and Bot.DeleteMessageWithContext. type DeleteMessageOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -988,6 +1147,11 @@ type DeleteMessageOpts struct { // - messageId (type int64): Identifier of the message to delete // - opts (type DeleteMessageOpts): All optional parameters. func (bot *Bot) DeleteMessage(chatId int64, messageId int64, opts *DeleteMessageOpts) (bool, error) { + return bot.DeleteMessageWithContext(context.Background(), chatId, messageId, opts) +} + +// DeleteMessageWithContext is the same as Bot.DeleteMessage, but with a context.Context parameter +func (bot *Bot) DeleteMessageWithContext(ctx context.Context, chatId int64, messageId int64, opts *DeleteMessageOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_id"] = strconv.FormatInt(messageId, 10) @@ -997,7 +1161,7 @@ func (bot *Bot) DeleteMessage(chatId int64, messageId int64, opts *DeleteMessage reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteMessage", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteMessage", v, nil, reqOpts) if err != nil { return false, err } @@ -1006,7 +1170,7 @@ func (bot *Bot) DeleteMessage(chatId int64, messageId int64, opts *DeleteMessage return b, json.Unmarshal(r, &b) } -// DeleteMessagesOpts is the set of optional fields for Bot.DeleteMessages. +// DeleteMessagesOpts is the set of optional fields for Bot.DeleteMessages and Bot.DeleteMessagesWithContext. type DeleteMessagesOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1019,6 +1183,11 @@ type DeleteMessagesOpts struct { // - messageIds (type []int64): A JSON-serialized list of 1-100 identifiers of messages to delete. See deleteMessage for limitations on which messages can be deleted // - opts (type DeleteMessagesOpts): All optional parameters. func (bot *Bot) DeleteMessages(chatId int64, messageIds []int64, opts *DeleteMessagesOpts) (bool, error) { + return bot.DeleteMessagesWithContext(context.Background(), chatId, messageIds, opts) +} + +// DeleteMessagesWithContext is the same as Bot.DeleteMessages, but with a context.Context parameter +func (bot *Bot) DeleteMessagesWithContext(ctx context.Context, chatId int64, messageIds []int64, opts *DeleteMessagesOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) if messageIds != nil { @@ -1034,7 +1203,7 @@ func (bot *Bot) DeleteMessages(chatId int64, messageIds []int64, opts *DeleteMes reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteMessages", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteMessages", v, nil, reqOpts) if err != nil { return false, err } @@ -1043,7 +1212,7 @@ func (bot *Bot) DeleteMessages(chatId int64, messageIds []int64, opts *DeleteMes return b, json.Unmarshal(r, &b) } -// DeleteMyCommandsOpts is the set of optional fields for Bot.DeleteMyCommands. +// DeleteMyCommandsOpts is the set of optional fields for Bot.DeleteMyCommands and Bot.DeleteMyCommandsWithContext. type DeleteMyCommandsOpts struct { // A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault. Scope BotCommandScope @@ -1058,6 +1227,11 @@ type DeleteMyCommandsOpts struct { // Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success. // - opts (type DeleteMyCommandsOpts): All optional parameters. func (bot *Bot) DeleteMyCommands(opts *DeleteMyCommandsOpts) (bool, error) { + return bot.DeleteMyCommandsWithContext(context.Background(), opts) +} + +// DeleteMyCommandsWithContext is the same as Bot.DeleteMyCommands, but with a context.Context parameter +func (bot *Bot) DeleteMyCommandsWithContext(ctx context.Context, opts *DeleteMyCommandsOpts) (bool, error) { v := map[string]string{} if opts != nil { bs, err := json.Marshal(opts.Scope) @@ -1073,7 +1247,7 @@ func (bot *Bot) DeleteMyCommands(opts *DeleteMyCommandsOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteMyCommands", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteMyCommands", v, nil, reqOpts) if err != nil { return false, err } @@ -1082,7 +1256,7 @@ func (bot *Bot) DeleteMyCommands(opts *DeleteMyCommandsOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// DeleteStickerFromSetOpts is the set of optional fields for Bot.DeleteStickerFromSet. +// DeleteStickerFromSetOpts is the set of optional fields for Bot.DeleteStickerFromSet and Bot.DeleteStickerFromSetWithContext. type DeleteStickerFromSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1094,6 +1268,11 @@ type DeleteStickerFromSetOpts struct { // - sticker (type string): File identifier of the sticker // - opts (type DeleteStickerFromSetOpts): All optional parameters. func (bot *Bot) DeleteStickerFromSet(sticker string, opts *DeleteStickerFromSetOpts) (bool, error) { + return bot.DeleteStickerFromSetWithContext(context.Background(), sticker, opts) +} + +// DeleteStickerFromSetWithContext is the same as Bot.DeleteStickerFromSet, but with a context.Context parameter +func (bot *Bot) DeleteStickerFromSetWithContext(ctx context.Context, sticker string, opts *DeleteStickerFromSetOpts) (bool, error) { v := map[string]string{} v["sticker"] = sticker @@ -1102,7 +1281,7 @@ func (bot *Bot) DeleteStickerFromSet(sticker string, opts *DeleteStickerFromSetO reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteStickerFromSet", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteStickerFromSet", v, nil, reqOpts) if err != nil { return false, err } @@ -1111,7 +1290,7 @@ func (bot *Bot) DeleteStickerFromSet(sticker string, opts *DeleteStickerFromSetO return b, json.Unmarshal(r, &b) } -// DeleteStickerSetOpts is the set of optional fields for Bot.DeleteStickerSet. +// DeleteStickerSetOpts is the set of optional fields for Bot.DeleteStickerSet and Bot.DeleteStickerSetWithContext. type DeleteStickerSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1123,6 +1302,11 @@ type DeleteStickerSetOpts struct { // - name (type string): Sticker set name // - opts (type DeleteStickerSetOpts): All optional parameters. func (bot *Bot) DeleteStickerSet(name string, opts *DeleteStickerSetOpts) (bool, error) { + return bot.DeleteStickerSetWithContext(context.Background(), name, opts) +} + +// DeleteStickerSetWithContext is the same as Bot.DeleteStickerSet, but with a context.Context parameter +func (bot *Bot) DeleteStickerSetWithContext(ctx context.Context, name string, opts *DeleteStickerSetOpts) (bool, error) { v := map[string]string{} v["name"] = name @@ -1131,7 +1315,7 @@ func (bot *Bot) DeleteStickerSet(name string, opts *DeleteStickerSetOpts) (bool, reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteStickerSet", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteStickerSet", v, nil, reqOpts) if err != nil { return false, err } @@ -1140,7 +1324,7 @@ func (bot *Bot) DeleteStickerSet(name string, opts *DeleteStickerSetOpts) (bool, return b, json.Unmarshal(r, &b) } -// DeleteWebhookOpts is the set of optional fields for Bot.DeleteWebhook. +// DeleteWebhookOpts is the set of optional fields for Bot.DeleteWebhook and Bot.DeleteWebhookWithContext. type DeleteWebhookOpts struct { // Pass True to drop all pending updates DropPendingUpdates bool @@ -1153,6 +1337,11 @@ type DeleteWebhookOpts struct { // Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. // - opts (type DeleteWebhookOpts): All optional parameters. func (bot *Bot) DeleteWebhook(opts *DeleteWebhookOpts) (bool, error) { + return bot.DeleteWebhookWithContext(context.Background(), opts) +} + +// DeleteWebhookWithContext is the same as Bot.DeleteWebhook, but with a context.Context parameter +func (bot *Bot) DeleteWebhookWithContext(ctx context.Context, opts *DeleteWebhookOpts) (bool, error) { v := map[string]string{} if opts != nil { v["drop_pending_updates"] = strconv.FormatBool(opts.DropPendingUpdates) @@ -1163,7 +1352,7 @@ func (bot *Bot) DeleteWebhook(opts *DeleteWebhookOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("deleteWebhook", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "deleteWebhook", v, nil, reqOpts) if err != nil { return false, err } @@ -1172,7 +1361,7 @@ func (bot *Bot) DeleteWebhook(opts *DeleteWebhookOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// EditChatInviteLinkOpts is the set of optional fields for Bot.EditChatInviteLink. +// EditChatInviteLinkOpts is the set of optional fields for Bot.EditChatInviteLink and Bot.EditChatInviteLinkWithContext. type EditChatInviteLinkOpts struct { // Invite link name; 0-32 characters Name string @@ -1193,6 +1382,11 @@ type EditChatInviteLinkOpts struct { // - inviteLink (type string): The invite link to edit // - opts (type EditChatInviteLinkOpts): All optional parameters. func (bot *Bot) EditChatInviteLink(chatId int64, inviteLink string, opts *EditChatInviteLinkOpts) (*ChatInviteLink, error) { + return bot.EditChatInviteLinkWithContext(context.Background(), chatId, inviteLink, opts) +} + +// EditChatInviteLinkWithContext is the same as Bot.EditChatInviteLink, but with a context.Context parameter +func (bot *Bot) EditChatInviteLinkWithContext(ctx context.Context, chatId int64, inviteLink string, opts *EditChatInviteLinkOpts) (*ChatInviteLink, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["invite_link"] = inviteLink @@ -1212,7 +1406,48 @@ func (bot *Bot) EditChatInviteLink(chatId int64, inviteLink string, opts *EditCh reqOpts = opts.RequestOpts } - r, err := bot.Request("editChatInviteLink", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editChatInviteLink", v, nil, reqOpts) + if err != nil { + return nil, err + } + + var c ChatInviteLink + return &c, json.Unmarshal(r, &c) +} + +// EditChatSubscriptionInviteLinkOpts is the set of optional fields for Bot.EditChatSubscriptionInviteLink and Bot.EditChatSubscriptionInviteLinkWithContext. +type EditChatSubscriptionInviteLinkOpts struct { + // Invite link name; 0-32 characters + Name string + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// EditChatSubscriptionInviteLink (https://core.telegram.org/bots/api#editchatsubscriptioninvitelink) +// +// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object. +// - chatId (type int64): Unique identifier for the target chat +// - inviteLink (type string): The invite link to edit +// - opts (type EditChatSubscriptionInviteLinkOpts): All optional parameters. +func (bot *Bot) EditChatSubscriptionInviteLink(chatId int64, inviteLink string, opts *EditChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) { + return bot.EditChatSubscriptionInviteLinkWithContext(context.Background(), chatId, inviteLink, opts) +} + +// EditChatSubscriptionInviteLinkWithContext is the same as Bot.EditChatSubscriptionInviteLink, but with a context.Context parameter +func (bot *Bot) EditChatSubscriptionInviteLinkWithContext(ctx context.Context, chatId int64, inviteLink string, opts *EditChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) { + v := map[string]string{} + v["chat_id"] = strconv.FormatInt(chatId, 10) + v["invite_link"] = inviteLink + if opts != nil { + v["name"] = opts.Name + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "editChatSubscriptionInviteLink", v, nil, reqOpts) if err != nil { return nil, err } @@ -1221,7 +1456,7 @@ func (bot *Bot) EditChatInviteLink(chatId int64, inviteLink string, opts *EditCh return &c, json.Unmarshal(r, &c) } -// EditForumTopicOpts is the set of optional fields for Bot.EditForumTopic. +// EditForumTopicOpts is the set of optional fields for Bot.EditForumTopic and Bot.EditForumTopicWithContext. type EditForumTopicOpts struct { // New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept Name string @@ -1233,11 +1468,16 @@ type EditForumTopicOpts struct { // EditForumTopic (https://core.telegram.org/bots/api#editforumtopic) // -// Use this method to edit name and icon of a 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, unless it is the creator of the topic. Returns True on success. +// Use this method to edit name and icon of a 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, unless it is the creator of the topic. Returns True on success. // - chatId (type int64): Unique identifier for the target chat // - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic // - opts (type EditForumTopicOpts): All optional parameters. func (bot *Bot) EditForumTopic(chatId int64, messageThreadId int64, opts *EditForumTopicOpts) (bool, error) { + return bot.EditForumTopicWithContext(context.Background(), chatId, messageThreadId, opts) +} + +// EditForumTopicWithContext is the same as Bot.EditForumTopic, but with a context.Context parameter +func (bot *Bot) EditForumTopicWithContext(ctx context.Context, chatId int64, messageThreadId int64, opts *EditForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10) @@ -1253,7 +1493,7 @@ func (bot *Bot) EditForumTopic(chatId int64, messageThreadId int64, opts *EditFo reqOpts = opts.RequestOpts } - r, err := bot.Request("editForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -1262,7 +1502,7 @@ func (bot *Bot) EditForumTopic(chatId int64, messageThreadId int64, opts *EditFo return b, json.Unmarshal(r, &b) } -// EditGeneralForumTopicOpts is the set of optional fields for Bot.EditGeneralForumTopic. +// EditGeneralForumTopicOpts is the set of optional fields for Bot.EditGeneralForumTopic and Bot.EditGeneralForumTopicWithContext. type EditGeneralForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1270,11 +1510,16 @@ type EditGeneralForumTopicOpts struct { // EditGeneralForumTopic (https://core.telegram.org/bots/api#editgeneralforumtopic) // -// Use this method 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. +// Use this method 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 the can_manage_topics administrator rights. Returns True on success. // - chatId (type int64): Unique identifier for the target chat // - name (type string): New topic name, 1-128 characters // - opts (type EditGeneralForumTopicOpts): All optional parameters. func (bot *Bot) EditGeneralForumTopic(chatId int64, name string, opts *EditGeneralForumTopicOpts) (bool, error) { + return bot.EditGeneralForumTopicWithContext(context.Background(), chatId, name, opts) +} + +// EditGeneralForumTopicWithContext is the same as Bot.EditGeneralForumTopic, but with a context.Context parameter +func (bot *Bot) EditGeneralForumTopicWithContext(ctx context.Context, chatId int64, name string, opts *EditGeneralForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["name"] = name @@ -1284,7 +1529,7 @@ func (bot *Bot) EditGeneralForumTopic(chatId int64, name string, opts *EditGener reqOpts = opts.RequestOpts } - r, err := bot.Request("editGeneralForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editGeneralForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -1293,8 +1538,10 @@ func (bot *Bot) EditGeneralForumTopic(chatId int64, name string, opts *EditGener return b, json.Unmarshal(r, &b) } -// EditMessageCaptionOpts is the set of optional fields for Bot.EditMessageCaption. +// EditMessageCaptionOpts is the set of optional fields for Bot.EditMessageCaption and Bot.EditMessageCaptionWithContext. type EditMessageCaptionOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 // Required if inline_message_id is not specified. Identifier of the message to edit @@ -1307,6 +1554,8 @@ type EditMessageCaptionOpts struct { ParseMode string // A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity + // Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages. + ShowCaptionAboveMedia bool // A JSON-serialized object for an inline keyboard. ReplyMarkup InlineKeyboardMarkup // RequestOpts are an additional optional field to configure timeouts for individual requests @@ -1315,11 +1564,17 @@ type EditMessageCaptionOpts struct { // EditMessageCaption (https://core.telegram.org/bots/api#editmessagecaption) // -// Use this method to edit captions of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. +// Use this method to edit captions of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. // - opts (type EditMessageCaptionOpts): All optional parameters. func (bot *Bot) EditMessageCaption(opts *EditMessageCaptionOpts) (*Message, bool, error) { + return bot.EditMessageCaptionWithContext(context.Background(), opts) +} + +// EditMessageCaptionWithContext is the same as Bot.EditMessageCaption, but with a context.Context parameter +func (bot *Bot) EditMessageCaptionWithContext(ctx context.Context, opts *EditMessageCaptionOpts) (*Message, bool, error) { v := map[string]string{} if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.ChatId != 0 { v["chat_id"] = strconv.FormatInt(opts.ChatId, 10) } @@ -1336,6 +1591,7 @@ func (bot *Bot) EditMessageCaption(opts *EditMessageCaptionOpts) (*Message, bool } v["caption_entities"] = string(bs) } + v["show_caption_above_media"] = strconv.FormatBool(opts.ShowCaptionAboveMedia) bs, err := json.Marshal(opts.ReplyMarkup) if err != nil { return nil, false, fmt.Errorf("failed to marshal field reply_markup: %w", err) @@ -1348,7 +1604,7 @@ func (bot *Bot) EditMessageCaption(opts *EditMessageCaptionOpts) (*Message, bool reqOpts = opts.RequestOpts } - r, err := bot.Request("editMessageCaption", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editMessageCaption", v, nil, reqOpts) if err != nil { return nil, false, err } @@ -1365,8 +1621,10 @@ func (bot *Bot) EditMessageCaption(opts *EditMessageCaptionOpts) (*Message, bool } -// EditMessageLiveLocationOpts is the set of optional fields for Bot.EditMessageLiveLocation. +// EditMessageLiveLocationOpts is the set of optional fields for Bot.EditMessageLiveLocation and Bot.EditMessageLiveLocationWithContext. type EditMessageLiveLocationOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 // Required if inline_message_id is not specified. Identifier of the message to edit @@ -1394,10 +1652,16 @@ type EditMessageLiveLocationOpts struct { // - longitude (type float64): Longitude of new location // - opts (type EditMessageLiveLocationOpts): All optional parameters. func (bot *Bot) EditMessageLiveLocation(latitude float64, longitude float64, opts *EditMessageLiveLocationOpts) (*Message, bool, error) { + return bot.EditMessageLiveLocationWithContext(context.Background(), latitude, longitude, opts) +} + +// EditMessageLiveLocationWithContext is the same as Bot.EditMessageLiveLocation, but with a context.Context parameter +func (bot *Bot) EditMessageLiveLocationWithContext(ctx context.Context, latitude float64, longitude float64, opts *EditMessageLiveLocationOpts) (*Message, bool, error) { v := map[string]string{} v["latitude"] = strconv.FormatFloat(latitude, 'f', -1, 64) v["longitude"] = strconv.FormatFloat(longitude, 'f', -1, 64) if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.ChatId != 0 { v["chat_id"] = strconv.FormatInt(opts.ChatId, 10) } @@ -1429,7 +1693,7 @@ func (bot *Bot) EditMessageLiveLocation(latitude float64, longitude float64, opt reqOpts = opts.RequestOpts } - r, err := bot.Request("editMessageLiveLocation", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editMessageLiveLocation", v, nil, reqOpts) if err != nil { return nil, false, err } @@ -1446,8 +1710,10 @@ func (bot *Bot) EditMessageLiveLocation(latitude float64, longitude float64, opt } -// EditMessageMediaOpts is the set of optional fields for Bot.EditMessageMedia. +// EditMessageMediaOpts is the set of optional fields for Bot.EditMessageMedia and Bot.EditMessageMediaWithContext. type EditMessageMediaOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 // Required if inline_message_id is not specified. Identifier of the message to edit @@ -1462,18 +1728,24 @@ type EditMessageMediaOpts struct { // EditMessageMedia (https://core.telegram.org/bots/api#editmessagemedia) // -// Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. +// Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. // - media (type InputMedia): A JSON-serialized object for a new media content of the message // - opts (type EditMessageMediaOpts): All optional parameters. func (bot *Bot) EditMessageMedia(media InputMedia, opts *EditMessageMediaOpts) (*Message, bool, error) { + return bot.EditMessageMediaWithContext(context.Background(), media, opts) +} + +// EditMessageMediaWithContext is the same as Bot.EditMessageMedia, but with a context.Context parameter +func (bot *Bot) EditMessageMediaWithContext(ctx context.Context, media InputMedia, opts *EditMessageMediaOpts) (*Message, bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} inputBs, err := media.InputParams("media", data) if err != nil { return nil, false, fmt.Errorf("failed to marshal field media: %w", err) } v["media"] = string(inputBs) if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.ChatId != 0 { v["chat_id"] = strconv.FormatInt(opts.ChatId, 10) } @@ -1493,7 +1765,7 @@ func (bot *Bot) EditMessageMedia(media InputMedia, opts *EditMessageMediaOpts) ( reqOpts = opts.RequestOpts } - r, err := bot.Request("editMessageMedia", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "editMessageMedia", v, data, reqOpts) if err != nil { return nil, false, err } @@ -1510,8 +1782,10 @@ func (bot *Bot) EditMessageMedia(media InputMedia, opts *EditMessageMediaOpts) ( } -// EditMessageReplyMarkupOpts is the set of optional fields for Bot.EditMessageReplyMarkup. +// EditMessageReplyMarkupOpts is the set of optional fields for Bot.EditMessageReplyMarkup and Bot.EditMessageReplyMarkupWithContext. type EditMessageReplyMarkupOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 // Required if inline_message_id is not specified. Identifier of the message to edit @@ -1526,11 +1800,17 @@ type EditMessageReplyMarkupOpts struct { // EditMessageReplyMarkup (https://core.telegram.org/bots/api#editmessagereplymarkup) // -// Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. +// Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. // - opts (type EditMessageReplyMarkupOpts): All optional parameters. func (bot *Bot) EditMessageReplyMarkup(opts *EditMessageReplyMarkupOpts) (*Message, bool, error) { + return bot.EditMessageReplyMarkupWithContext(context.Background(), opts) +} + +// EditMessageReplyMarkupWithContext is the same as Bot.EditMessageReplyMarkup, but with a context.Context parameter +func (bot *Bot) EditMessageReplyMarkupWithContext(ctx context.Context, opts *EditMessageReplyMarkupOpts) (*Message, bool, error) { v := map[string]string{} if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.ChatId != 0 { v["chat_id"] = strconv.FormatInt(opts.ChatId, 10) } @@ -1550,7 +1830,7 @@ func (bot *Bot) EditMessageReplyMarkup(opts *EditMessageReplyMarkupOpts) (*Messa reqOpts = opts.RequestOpts } - r, err := bot.Request("editMessageReplyMarkup", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editMessageReplyMarkup", v, nil, reqOpts) if err != nil { return nil, false, err } @@ -1567,8 +1847,10 @@ func (bot *Bot) EditMessageReplyMarkup(opts *EditMessageReplyMarkupOpts) (*Messa } -// EditMessageTextOpts is the set of optional fields for Bot.EditMessageText. +// EditMessageTextOpts is the set of optional fields for Bot.EditMessageText and Bot.EditMessageTextWithContext. type EditMessageTextOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 // Required if inline_message_id is not specified. Identifier of the message to edit @@ -1589,13 +1871,19 @@ type EditMessageTextOpts struct { // EditMessageText (https://core.telegram.org/bots/api#editmessagetext) // -// Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. +// Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. // - text (type string): New text of the message, 1-4096 characters after entities parsing // - opts (type EditMessageTextOpts): All optional parameters. func (bot *Bot) EditMessageText(text string, opts *EditMessageTextOpts) (*Message, bool, error) { + return bot.EditMessageTextWithContext(context.Background(), text, opts) +} + +// EditMessageTextWithContext is the same as Bot.EditMessageText, but with a context.Context parameter +func (bot *Bot) EditMessageTextWithContext(ctx context.Context, text string, opts *EditMessageTextOpts) (*Message, bool, error) { v := map[string]string{} v["text"] = text if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.ChatId != 0 { v["chat_id"] = strconv.FormatInt(opts.ChatId, 10) } @@ -1630,7 +1918,7 @@ func (bot *Bot) EditMessageText(text string, opts *EditMessageTextOpts) (*Messag reqOpts = opts.RequestOpts } - r, err := bot.Request("editMessageText", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "editMessageText", v, nil, reqOpts) if err != nil { return nil, false, err } @@ -1647,7 +1935,7 @@ func (bot *Bot) EditMessageText(text string, opts *EditMessageTextOpts) (*Messag } -// ExportChatInviteLinkOpts is the set of optional fields for Bot.ExportChatInviteLink. +// 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 RequestOpts *RequestOpts @@ -1659,6 +1947,11 @@ type ExportChatInviteLinkOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type ExportChatInviteLinkOpts): All optional parameters. func (bot *Bot) ExportChatInviteLink(chatId int64, opts *ExportChatInviteLinkOpts) (string, error) { + return bot.ExportChatInviteLinkWithContext(context.Background(), chatId, opts) +} + +// ExportChatInviteLinkWithContext is the same as Bot.ExportChatInviteLink, but with a context.Context parameter +func (bot *Bot) ExportChatInviteLinkWithContext(ctx context.Context, chatId int64, opts *ExportChatInviteLinkOpts) (string, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -1667,7 +1960,7 @@ func (bot *Bot) ExportChatInviteLink(chatId int64, opts *ExportChatInviteLinkOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("exportChatInviteLink", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "exportChatInviteLink", v, nil, reqOpts) if err != nil { return "", err } @@ -1676,7 +1969,7 @@ func (bot *Bot) ExportChatInviteLink(chatId int64, opts *ExportChatInviteLinkOpt return s, json.Unmarshal(r, &s) } -// ForwardMessageOpts is the set of optional fields for Bot.ForwardMessage. +// ForwardMessageOpts is the set of optional fields for Bot.ForwardMessage and Bot.ForwardMessageWithContext. type ForwardMessageOpts struct { // Unique identifier for the target message thread (topic) of the forum; for forum supergroups only MessageThreadId int64 @@ -1696,6 +1989,11 @@ type ForwardMessageOpts struct { // - messageId (type int64): Message identifier in the chat specified in from_chat_id // - opts (type ForwardMessageOpts): All optional parameters. func (bot *Bot) ForwardMessage(chatId int64, fromChatId int64, messageId int64, opts *ForwardMessageOpts) (*Message, error) { + return bot.ForwardMessageWithContext(context.Background(), chatId, fromChatId, messageId, opts) +} + +// ForwardMessageWithContext is the same as Bot.ForwardMessage, but with a context.Context parameter +func (bot *Bot) ForwardMessageWithContext(ctx context.Context, chatId int64, fromChatId int64, messageId int64, opts *ForwardMessageOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["from_chat_id"] = strconv.FormatInt(fromChatId, 10) @@ -1713,7 +2011,7 @@ func (bot *Bot) ForwardMessage(chatId int64, fromChatId int64, messageId int64, reqOpts = opts.RequestOpts } - r, err := bot.Request("forwardMessage", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "forwardMessage", v, nil, reqOpts) if err != nil { return nil, err } @@ -1722,7 +2020,7 @@ func (bot *Bot) ForwardMessage(chatId int64, fromChatId int64, messageId int64, return &m, json.Unmarshal(r, &m) } -// ForwardMessagesOpts is the set of optional fields for Bot.ForwardMessages. +// ForwardMessagesOpts is the set of optional fields for Bot.ForwardMessages and Bot.ForwardMessagesWithContext. type ForwardMessagesOpts struct { // Unique identifier for the target message thread (topic) of the forum; for forum supergroups only MessageThreadId int64 @@ -1742,6 +2040,11 @@ type ForwardMessagesOpts struct { // - messageIds (type []int64): A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order. // - opts (type ForwardMessagesOpts): All optional parameters. func (bot *Bot) ForwardMessages(chatId int64, fromChatId int64, messageIds []int64, opts *ForwardMessagesOpts) ([]MessageId, error) { + return bot.ForwardMessagesWithContext(context.Background(), chatId, fromChatId, messageIds, opts) +} + +// ForwardMessagesWithContext is the same as Bot.ForwardMessages, but with a context.Context parameter +func (bot *Bot) ForwardMessagesWithContext(ctx context.Context, chatId int64, fromChatId int64, messageIds []int64, opts *ForwardMessagesOpts) ([]MessageId, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["from_chat_id"] = strconv.FormatInt(fromChatId, 10) @@ -1765,7 +2068,7 @@ func (bot *Bot) ForwardMessages(chatId int64, fromChatId int64, messageIds []int reqOpts = opts.RequestOpts } - r, err := bot.Request("forwardMessages", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "forwardMessages", v, nil, reqOpts) if err != nil { return nil, err } @@ -1774,7 +2077,7 @@ func (bot *Bot) ForwardMessages(chatId int64, fromChatId int64, messageIds []int return m, json.Unmarshal(r, &m) } -// GetBusinessConnectionOpts is the set of optional fields for Bot.GetBusinessConnection. +// 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 RequestOpts *RequestOpts @@ -1786,6 +2089,11 @@ type GetBusinessConnectionOpts struct { // - businessConnectionId (type string): Unique identifier of the business connection // - opts (type GetBusinessConnectionOpts): All optional parameters. func (bot *Bot) GetBusinessConnection(businessConnectionId string, opts *GetBusinessConnectionOpts) (*BusinessConnection, error) { + return bot.GetBusinessConnectionWithContext(context.Background(), businessConnectionId, opts) +} + +// GetBusinessConnectionWithContext is the same as Bot.GetBusinessConnection, but with a context.Context parameter +func (bot *Bot) GetBusinessConnectionWithContext(ctx context.Context, businessConnectionId string, opts *GetBusinessConnectionOpts) (*BusinessConnection, error) { v := map[string]string{} v["business_connection_id"] = businessConnectionId @@ -1794,7 +2102,7 @@ func (bot *Bot) GetBusinessConnection(businessConnectionId string, opts *GetBusi reqOpts = opts.RequestOpts } - r, err := bot.Request("getBusinessConnection", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getBusinessConnection", v, nil, reqOpts) if err != nil { return nil, err } @@ -1803,7 +2111,7 @@ func (bot *Bot) GetBusinessConnection(businessConnectionId string, opts *GetBusi return &b, json.Unmarshal(r, &b) } -// GetChatOpts is the set of optional fields for Bot.GetChat. +// GetChatOpts is the set of optional fields for Bot.GetChat and Bot.GetChatWithContext. type GetChatOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1815,6 +2123,11 @@ type GetChatOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type GetChatOpts): All optional parameters. func (bot *Bot) GetChat(chatId int64, opts *GetChatOpts) (*ChatFullInfo, error) { + return bot.GetChatWithContext(context.Background(), chatId, opts) +} + +// GetChatWithContext is the same as Bot.GetChat, but with a context.Context parameter +func (bot *Bot) GetChatWithContext(ctx context.Context, chatId int64, opts *GetChatOpts) (*ChatFullInfo, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -1823,7 +2136,7 @@ func (bot *Bot) GetChat(chatId int64, opts *GetChatOpts) (*ChatFullInfo, error) reqOpts = opts.RequestOpts } - r, err := bot.Request("getChat", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getChat", v, nil, reqOpts) if err != nil { return nil, err } @@ -1832,7 +2145,7 @@ func (bot *Bot) GetChat(chatId int64, opts *GetChatOpts) (*ChatFullInfo, error) return &c, json.Unmarshal(r, &c) } -// GetChatAdministratorsOpts is the set of optional fields for Bot.GetChatAdministrators. +// GetChatAdministratorsOpts is the set of optional fields for Bot.GetChatAdministrators and Bot.GetChatAdministratorsWithContext. type GetChatAdministratorsOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1844,6 +2157,11 @@ type GetChatAdministratorsOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type GetChatAdministratorsOpts): All optional parameters. func (bot *Bot) GetChatAdministrators(chatId int64, opts *GetChatAdministratorsOpts) ([]ChatMember, error) { + return bot.GetChatAdministratorsWithContext(context.Background(), chatId, opts) +} + +// GetChatAdministratorsWithContext is the same as Bot.GetChatAdministrators, but with a context.Context parameter +func (bot *Bot) GetChatAdministratorsWithContext(ctx context.Context, chatId int64, opts *GetChatAdministratorsOpts) ([]ChatMember, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -1852,7 +2170,7 @@ func (bot *Bot) GetChatAdministrators(chatId int64, opts *GetChatAdministratorsO reqOpts = opts.RequestOpts } - r, err := bot.Request("getChatAdministrators", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getChatAdministrators", v, nil, reqOpts) if err != nil { return nil, err } @@ -1860,7 +2178,7 @@ func (bot *Bot) GetChatAdministrators(chatId int64, opts *GetChatAdministratorsO return unmarshalChatMemberArray(r) } -// GetChatMemberOpts is the set of optional fields for Bot.GetChatMember. +// GetChatMemberOpts is the set of optional fields for Bot.GetChatMember and Bot.GetChatMemberWithContext. type GetChatMemberOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1873,6 +2191,11 @@ type GetChatMemberOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type GetChatMemberOpts): All optional parameters. func (bot *Bot) GetChatMember(chatId int64, userId int64, opts *GetChatMemberOpts) (ChatMember, error) { + return bot.GetChatMemberWithContext(context.Background(), chatId, userId, opts) +} + +// GetChatMemberWithContext is the same as Bot.GetChatMember, but with a context.Context parameter +func (bot *Bot) GetChatMemberWithContext(ctx context.Context, chatId int64, userId int64, opts *GetChatMemberOpts) (ChatMember, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -1882,7 +2205,7 @@ func (bot *Bot) GetChatMember(chatId int64, userId int64, opts *GetChatMemberOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("getChatMember", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getChatMember", v, nil, reqOpts) if err != nil { return nil, err } @@ -1890,7 +2213,7 @@ func (bot *Bot) GetChatMember(chatId int64, userId int64, opts *GetChatMemberOpt return unmarshalChatMember(r) } -// GetChatMemberCountOpts is the set of optional fields for Bot.GetChatMemberCount. +// GetChatMemberCountOpts is the set of optional fields for Bot.GetChatMemberCount and Bot.GetChatMemberCountWithContext. type GetChatMemberCountOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1902,6 +2225,11 @@ type GetChatMemberCountOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type GetChatMemberCountOpts): All optional parameters. func (bot *Bot) GetChatMemberCount(chatId int64, opts *GetChatMemberCountOpts) (int64, error) { + return bot.GetChatMemberCountWithContext(context.Background(), chatId, opts) +} + +// GetChatMemberCountWithContext is the same as Bot.GetChatMemberCount, but with a context.Context parameter +func (bot *Bot) GetChatMemberCountWithContext(ctx context.Context, chatId int64, opts *GetChatMemberCountOpts) (int64, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -1910,7 +2238,7 @@ func (bot *Bot) GetChatMemberCount(chatId int64, opts *GetChatMemberCountOpts) ( reqOpts = opts.RequestOpts } - r, err := bot.Request("getChatMemberCount", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getChatMemberCount", v, nil, reqOpts) if err != nil { return 0, err } @@ -1919,7 +2247,7 @@ func (bot *Bot) GetChatMemberCount(chatId int64, opts *GetChatMemberCountOpts) ( return i, json.Unmarshal(r, &i) } -// GetChatMenuButtonOpts is the set of optional fields for Bot.GetChatMenuButton. +// GetChatMenuButtonOpts is the set of optional fields for Bot.GetChatMenuButton and Bot.GetChatMenuButtonWithContext. type GetChatMenuButtonOpts struct { // Unique identifier for the target private chat. If not specified, default bot's menu button will be returned ChatId *int64 @@ -1932,6 +2260,11 @@ type GetChatMenuButtonOpts struct { // Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success. // - opts (type GetChatMenuButtonOpts): All optional parameters. func (bot *Bot) GetChatMenuButton(opts *GetChatMenuButtonOpts) (MenuButton, error) { + return bot.GetChatMenuButtonWithContext(context.Background(), opts) +} + +// GetChatMenuButtonWithContext is the same as Bot.GetChatMenuButton, but with a context.Context parameter +func (bot *Bot) GetChatMenuButtonWithContext(ctx context.Context, opts *GetChatMenuButtonOpts) (MenuButton, error) { v := map[string]string{} if opts != nil { if opts.ChatId != nil { @@ -1944,7 +2277,7 @@ func (bot *Bot) GetChatMenuButton(opts *GetChatMenuButtonOpts) (MenuButton, erro reqOpts = opts.RequestOpts } - r, err := bot.Request("getChatMenuButton", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getChatMenuButton", v, nil, reqOpts) if err != nil { return nil, err } @@ -1952,7 +2285,7 @@ func (bot *Bot) GetChatMenuButton(opts *GetChatMenuButtonOpts) (MenuButton, erro return unmarshalMenuButton(r) } -// GetCustomEmojiStickersOpts is the set of optional fields for Bot.GetCustomEmojiStickers. +// GetCustomEmojiStickersOpts is the set of optional fields for Bot.GetCustomEmojiStickers and Bot.GetCustomEmojiStickersWithContext. type GetCustomEmojiStickersOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -1964,6 +2297,11 @@ type GetCustomEmojiStickersOpts struct { // - customEmojiIds (type []string): A JSON-serialized list of custom emoji identifiers. At most 200 custom emoji identifiers can be specified. // - opts (type GetCustomEmojiStickersOpts): All optional parameters. func (bot *Bot) GetCustomEmojiStickers(customEmojiIds []string, opts *GetCustomEmojiStickersOpts) ([]Sticker, error) { + return bot.GetCustomEmojiStickersWithContext(context.Background(), customEmojiIds, opts) +} + +// GetCustomEmojiStickersWithContext is the same as Bot.GetCustomEmojiStickers, but with a context.Context parameter +func (bot *Bot) GetCustomEmojiStickersWithContext(ctx context.Context, customEmojiIds []string, opts *GetCustomEmojiStickersOpts) ([]Sticker, error) { v := map[string]string{} if customEmojiIds != nil { bs, err := json.Marshal(customEmojiIds) @@ -1978,7 +2316,7 @@ func (bot *Bot) GetCustomEmojiStickers(customEmojiIds []string, opts *GetCustomE reqOpts = opts.RequestOpts } - r, err := bot.Request("getCustomEmojiStickers", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getCustomEmojiStickers", v, nil, reqOpts) if err != nil { return nil, err } @@ -1987,7 +2325,7 @@ func (bot *Bot) GetCustomEmojiStickers(customEmojiIds []string, opts *GetCustomE return s, json.Unmarshal(r, &s) } -// GetFileOpts is the set of optional fields for Bot.GetFile. +// GetFileOpts is the set of optional fields for Bot.GetFile and Bot.GetFileWithContext. type GetFileOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2000,6 +2338,11 @@ type GetFileOpts struct { // - fileId (type string): File identifier to get information about // - opts (type GetFileOpts): All optional parameters. func (bot *Bot) GetFile(fileId string, opts *GetFileOpts) (*File, error) { + return bot.GetFileWithContext(context.Background(), fileId, opts) +} + +// GetFileWithContext is the same as Bot.GetFile, but with a context.Context parameter +func (bot *Bot) GetFileWithContext(ctx context.Context, fileId string, opts *GetFileOpts) (*File, error) { v := map[string]string{} v["file_id"] = fileId @@ -2008,7 +2351,7 @@ func (bot *Bot) GetFile(fileId string, opts *GetFileOpts) (*File, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("getFile", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getFile", v, nil, reqOpts) if err != nil { return nil, err } @@ -2017,7 +2360,7 @@ func (bot *Bot) GetFile(fileId string, opts *GetFileOpts) (*File, error) { return &f, json.Unmarshal(r, &f) } -// GetForumTopicIconStickersOpts is the set of optional fields for Bot.GetForumTopicIconStickers. +// GetForumTopicIconStickersOpts is the set of optional fields for Bot.GetForumTopicIconStickers and Bot.GetForumTopicIconStickersWithContext. type GetForumTopicIconStickersOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2028,6 +2371,11 @@ type GetForumTopicIconStickersOpts struct { // Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects. // - opts (type GetForumTopicIconStickersOpts): All optional parameters. func (bot *Bot) GetForumTopicIconStickers(opts *GetForumTopicIconStickersOpts) ([]Sticker, error) { + return bot.GetForumTopicIconStickersWithContext(context.Background(), opts) +} + +// GetForumTopicIconStickersWithContext is the same as Bot.GetForumTopicIconStickers, but with a context.Context parameter +func (bot *Bot) GetForumTopicIconStickersWithContext(ctx context.Context, opts *GetForumTopicIconStickersOpts) ([]Sticker, error) { v := map[string]string{} var reqOpts *RequestOpts @@ -2035,7 +2383,7 @@ func (bot *Bot) GetForumTopicIconStickers(opts *GetForumTopicIconStickersOpts) ( reqOpts = opts.RequestOpts } - r, err := bot.Request("getForumTopicIconStickers", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getForumTopicIconStickers", v, nil, reqOpts) if err != nil { return nil, err } @@ -2044,7 +2392,7 @@ func (bot *Bot) GetForumTopicIconStickers(opts *GetForumTopicIconStickersOpts) ( return s, json.Unmarshal(r, &s) } -// GetGameHighScoresOpts is the set of optional fields for Bot.GetGameHighScores. +// GetGameHighScoresOpts is the set of optional fields for Bot.GetGameHighScores and Bot.GetGameHighScoresWithContext. type GetGameHighScoresOpts struct { // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 @@ -2062,6 +2410,11 @@ type GetGameHighScoresOpts struct { // - userId (type int64): Target user id // - opts (type GetGameHighScoresOpts): All optional parameters. func (bot *Bot) GetGameHighScores(userId int64, opts *GetGameHighScoresOpts) ([]GameHighScore, error) { + return bot.GetGameHighScoresWithContext(context.Background(), userId, opts) +} + +// GetGameHighScoresWithContext is the same as Bot.GetGameHighScores, but with a context.Context parameter +func (bot *Bot) GetGameHighScoresWithContext(ctx context.Context, userId int64, opts *GetGameHighScoresOpts) ([]GameHighScore, error) { v := map[string]string{} v["user_id"] = strconv.FormatInt(userId, 10) if opts != nil { @@ -2079,7 +2432,7 @@ func (bot *Bot) GetGameHighScores(userId int64, opts *GetGameHighScoresOpts) ([] reqOpts = opts.RequestOpts } - r, err := bot.Request("getGameHighScores", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getGameHighScores", v, nil, reqOpts) if err != nil { return nil, err } @@ -2088,7 +2441,7 @@ func (bot *Bot) GetGameHighScores(userId int64, opts *GetGameHighScoresOpts) ([] return g, json.Unmarshal(r, &g) } -// GetMeOpts is the set of optional fields for Bot.GetMe. +// GetMeOpts is the set of optional fields for Bot.GetMe and Bot.GetMeWithContext. type GetMeOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2099,6 +2452,11 @@ type GetMeOpts struct { // A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object. // - opts (type GetMeOpts): All optional parameters. func (bot *Bot) GetMe(opts *GetMeOpts) (*User, error) { + return bot.GetMeWithContext(context.Background(), opts) +} + +// GetMeWithContext is the same as Bot.GetMe, but with a context.Context parameter +func (bot *Bot) GetMeWithContext(ctx context.Context, opts *GetMeOpts) (*User, error) { v := map[string]string{} var reqOpts *RequestOpts @@ -2106,7 +2464,7 @@ func (bot *Bot) GetMe(opts *GetMeOpts) (*User, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("getMe", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getMe", v, nil, reqOpts) if err != nil { return nil, err } @@ -2115,7 +2473,7 @@ func (bot *Bot) GetMe(opts *GetMeOpts) (*User, error) { return &u, json.Unmarshal(r, &u) } -// GetMyCommandsOpts is the set of optional fields for Bot.GetMyCommands. +// GetMyCommandsOpts is the set of optional fields for Bot.GetMyCommands and Bot.GetMyCommandsWithContext. type GetMyCommandsOpts struct { // A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault. Scope BotCommandScope @@ -2130,6 +2488,11 @@ type GetMyCommandsOpts struct { // Use this method to get the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned. // - opts (type GetMyCommandsOpts): All optional parameters. func (bot *Bot) GetMyCommands(opts *GetMyCommandsOpts) ([]BotCommand, error) { + return bot.GetMyCommandsWithContext(context.Background(), opts) +} + +// GetMyCommandsWithContext is the same as Bot.GetMyCommands, but with a context.Context parameter +func (bot *Bot) GetMyCommandsWithContext(ctx context.Context, opts *GetMyCommandsOpts) ([]BotCommand, error) { v := map[string]string{} if opts != nil { bs, err := json.Marshal(opts.Scope) @@ -2145,7 +2508,7 @@ func (bot *Bot) GetMyCommands(opts *GetMyCommandsOpts) ([]BotCommand, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("getMyCommands", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getMyCommands", v, nil, reqOpts) if err != nil { return nil, err } @@ -2154,7 +2517,7 @@ func (bot *Bot) GetMyCommands(opts *GetMyCommandsOpts) ([]BotCommand, error) { return b, json.Unmarshal(r, &b) } -// GetMyDefaultAdministratorRightsOpts is the set of optional fields for Bot.GetMyDefaultAdministratorRights. +// GetMyDefaultAdministratorRightsOpts is the set of optional fields for Bot.GetMyDefaultAdministratorRights and Bot.GetMyDefaultAdministratorRightsWithContext. type GetMyDefaultAdministratorRightsOpts struct { // Pass True to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned. ForChannels bool @@ -2167,6 +2530,11 @@ type GetMyDefaultAdministratorRightsOpts struct { // Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success. // - opts (type GetMyDefaultAdministratorRightsOpts): All optional parameters. func (bot *Bot) GetMyDefaultAdministratorRights(opts *GetMyDefaultAdministratorRightsOpts) (*ChatAdministratorRights, error) { + return bot.GetMyDefaultAdministratorRightsWithContext(context.Background(), opts) +} + +// GetMyDefaultAdministratorRightsWithContext is the same as Bot.GetMyDefaultAdministratorRights, but with a context.Context parameter +func (bot *Bot) GetMyDefaultAdministratorRightsWithContext(ctx context.Context, opts *GetMyDefaultAdministratorRightsOpts) (*ChatAdministratorRights, error) { v := map[string]string{} if opts != nil { v["for_channels"] = strconv.FormatBool(opts.ForChannels) @@ -2177,7 +2545,7 @@ func (bot *Bot) GetMyDefaultAdministratorRights(opts *GetMyDefaultAdministratorR reqOpts = opts.RequestOpts } - r, err := bot.Request("getMyDefaultAdministratorRights", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getMyDefaultAdministratorRights", v, nil, reqOpts) if err != nil { return nil, err } @@ -2186,7 +2554,7 @@ func (bot *Bot) GetMyDefaultAdministratorRights(opts *GetMyDefaultAdministratorR return &c, json.Unmarshal(r, &c) } -// GetMyDescriptionOpts is the set of optional fields for Bot.GetMyDescription. +// GetMyDescriptionOpts is the set of optional fields for Bot.GetMyDescription and Bot.GetMyDescriptionWithContext. type GetMyDescriptionOpts struct { // A two-letter ISO 639-1 language code or an empty string LanguageCode string @@ -2199,6 +2567,11 @@ type GetMyDescriptionOpts struct { // Use this method to get the current bot description for the given user language. Returns BotDescription on success. // - opts (type GetMyDescriptionOpts): All optional parameters. func (bot *Bot) GetMyDescription(opts *GetMyDescriptionOpts) (*BotDescription, error) { + return bot.GetMyDescriptionWithContext(context.Background(), opts) +} + +// GetMyDescriptionWithContext is the same as Bot.GetMyDescription, but with a context.Context parameter +func (bot *Bot) GetMyDescriptionWithContext(ctx context.Context, opts *GetMyDescriptionOpts) (*BotDescription, error) { v := map[string]string{} if opts != nil { v["language_code"] = opts.LanguageCode @@ -2209,7 +2582,7 @@ func (bot *Bot) GetMyDescription(opts *GetMyDescriptionOpts) (*BotDescription, e reqOpts = opts.RequestOpts } - r, err := bot.Request("getMyDescription", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getMyDescription", v, nil, reqOpts) if err != nil { return nil, err } @@ -2218,7 +2591,7 @@ func (bot *Bot) GetMyDescription(opts *GetMyDescriptionOpts) (*BotDescription, e return &b, json.Unmarshal(r, &b) } -// GetMyNameOpts is the set of optional fields for Bot.GetMyName. +// GetMyNameOpts is the set of optional fields for Bot.GetMyName and Bot.GetMyNameWithContext. type GetMyNameOpts struct { // A two-letter ISO 639-1 language code or an empty string LanguageCode string @@ -2231,6 +2604,11 @@ type GetMyNameOpts struct { // Use this method to get the current bot name for the given user language. Returns BotName on success. // - opts (type GetMyNameOpts): All optional parameters. func (bot *Bot) GetMyName(opts *GetMyNameOpts) (*BotName, error) { + return bot.GetMyNameWithContext(context.Background(), opts) +} + +// GetMyNameWithContext is the same as Bot.GetMyName, but with a context.Context parameter +func (bot *Bot) GetMyNameWithContext(ctx context.Context, opts *GetMyNameOpts) (*BotName, error) { v := map[string]string{} if opts != nil { v["language_code"] = opts.LanguageCode @@ -2241,7 +2619,7 @@ func (bot *Bot) GetMyName(opts *GetMyNameOpts) (*BotName, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("getMyName", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getMyName", v, nil, reqOpts) if err != nil { return nil, err } @@ -2250,7 +2628,7 @@ func (bot *Bot) GetMyName(opts *GetMyNameOpts) (*BotName, error) { return &b, json.Unmarshal(r, &b) } -// GetMyShortDescriptionOpts is the set of optional fields for Bot.GetMyShortDescription. +// GetMyShortDescriptionOpts is the set of optional fields for Bot.GetMyShortDescription and Bot.GetMyShortDescriptionWithContext. type GetMyShortDescriptionOpts struct { // A two-letter ISO 639-1 language code or an empty string LanguageCode string @@ -2263,6 +2641,11 @@ type GetMyShortDescriptionOpts struct { // Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success. // - opts (type GetMyShortDescriptionOpts): All optional parameters. func (bot *Bot) GetMyShortDescription(opts *GetMyShortDescriptionOpts) (*BotShortDescription, error) { + return bot.GetMyShortDescriptionWithContext(context.Background(), opts) +} + +// GetMyShortDescriptionWithContext is the same as Bot.GetMyShortDescription, but with a context.Context parameter +func (bot *Bot) GetMyShortDescriptionWithContext(ctx context.Context, opts *GetMyShortDescriptionOpts) (*BotShortDescription, error) { v := map[string]string{} if opts != nil { v["language_code"] = opts.LanguageCode @@ -2273,7 +2656,7 @@ func (bot *Bot) GetMyShortDescription(opts *GetMyShortDescriptionOpts) (*BotShor reqOpts = opts.RequestOpts } - r, err := bot.Request("getMyShortDescription", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getMyShortDescription", v, nil, reqOpts) if err != nil { return nil, err } @@ -2282,7 +2665,51 @@ func (bot *Bot) GetMyShortDescription(opts *GetMyShortDescriptionOpts) (*BotShor return &b, json.Unmarshal(r, &b) } -// GetStickerSetOpts is the set of optional fields for Bot.GetStickerSet. +// GetStarTransactionsOpts is the set of optional fields for Bot.GetStarTransactions and Bot.GetStarTransactionsWithContext. +type GetStarTransactionsOpts struct { + // Number of transactions to skip in the response + Offset int64 + // The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100. + Limit int64 + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// GetStarTransactions (https://core.telegram.org/bots/api#getstartransactions) +// +// Returns the bot's Telegram Star transactions in chronological order. On success, returns a StarTransactions object. +// - opts (type GetStarTransactionsOpts): All optional parameters. +func (bot *Bot) GetStarTransactions(opts *GetStarTransactionsOpts) (*StarTransactions, error) { + return bot.GetStarTransactionsWithContext(context.Background(), opts) +} + +// GetStarTransactionsWithContext is the same as Bot.GetStarTransactions, but with a context.Context parameter +func (bot *Bot) GetStarTransactionsWithContext(ctx context.Context, opts *GetStarTransactionsOpts) (*StarTransactions, error) { + v := map[string]string{} + if opts != nil { + if opts.Offset != 0 { + v["offset"] = strconv.FormatInt(opts.Offset, 10) + } + if opts.Limit != 0 { + v["limit"] = strconv.FormatInt(opts.Limit, 10) + } + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "getStarTransactions", v, nil, reqOpts) + if err != nil { + return nil, err + } + + var s StarTransactions + return &s, json.Unmarshal(r, &s) +} + +// GetStickerSetOpts is the set of optional fields for Bot.GetStickerSet and Bot.GetStickerSetWithContext. type GetStickerSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2294,6 +2721,11 @@ type GetStickerSetOpts struct { // - name (type string): Name of the sticker set // - opts (type GetStickerSetOpts): All optional parameters. func (bot *Bot) GetStickerSet(name string, opts *GetStickerSetOpts) (*StickerSet, error) { + return bot.GetStickerSetWithContext(context.Background(), name, opts) +} + +// GetStickerSetWithContext is the same as Bot.GetStickerSet, but with a context.Context parameter +func (bot *Bot) GetStickerSetWithContext(ctx context.Context, name string, opts *GetStickerSetOpts) (*StickerSet, error) { v := map[string]string{} v["name"] = name @@ -2302,7 +2734,7 @@ func (bot *Bot) GetStickerSet(name string, opts *GetStickerSetOpts) (*StickerSet reqOpts = opts.RequestOpts } - r, err := bot.Request("getStickerSet", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getStickerSet", v, nil, reqOpts) if err != nil { return nil, err } @@ -2311,7 +2743,7 @@ func (bot *Bot) GetStickerSet(name string, opts *GetStickerSetOpts) (*StickerSet return &s, json.Unmarshal(r, &s) } -// GetUpdatesOpts is the set of optional fields for Bot.GetUpdates. +// GetUpdatesOpts is the set of optional fields for Bot.GetUpdates and Bot.GetUpdatesWithContext. type GetUpdatesOpts struct { // Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will be forgotten. Offset int64 @@ -2330,6 +2762,11 @@ type GetUpdatesOpts struct { // Use this method to receive incoming updates using long polling (wiki). Returns an Array of Update objects. // - opts (type GetUpdatesOpts): All optional parameters. func (bot *Bot) GetUpdates(opts *GetUpdatesOpts) ([]Update, error) { + return bot.GetUpdatesWithContext(context.Background(), opts) +} + +// GetUpdatesWithContext is the same as Bot.GetUpdates, but with a context.Context parameter +func (bot *Bot) GetUpdatesWithContext(ctx context.Context, opts *GetUpdatesOpts) ([]Update, error) { v := map[string]string{} if opts != nil { if opts.Offset != 0 { @@ -2355,7 +2792,7 @@ func (bot *Bot) GetUpdates(opts *GetUpdatesOpts) ([]Update, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("getUpdates", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getUpdates", v, nil, reqOpts) if err != nil { return nil, err } @@ -2364,7 +2801,7 @@ func (bot *Bot) GetUpdates(opts *GetUpdatesOpts) ([]Update, error) { return u, json.Unmarshal(r, &u) } -// GetUserChatBoostsOpts is the set of optional fields for Bot.GetUserChatBoosts. +// GetUserChatBoostsOpts is the set of optional fields for Bot.GetUserChatBoosts and Bot.GetUserChatBoostsWithContext. type GetUserChatBoostsOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2377,6 +2814,11 @@ type GetUserChatBoostsOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type GetUserChatBoostsOpts): All optional parameters. func (bot *Bot) GetUserChatBoosts(chatId int64, userId int64, opts *GetUserChatBoostsOpts) (*UserChatBoosts, error) { + return bot.GetUserChatBoostsWithContext(context.Background(), chatId, userId, opts) +} + +// GetUserChatBoostsWithContext is the same as Bot.GetUserChatBoosts, but with a context.Context parameter +func (bot *Bot) GetUserChatBoostsWithContext(ctx context.Context, chatId int64, userId int64, opts *GetUserChatBoostsOpts) (*UserChatBoosts, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -2386,7 +2828,7 @@ func (bot *Bot) GetUserChatBoosts(chatId int64, userId int64, opts *GetUserChatB reqOpts = opts.RequestOpts } - r, err := bot.Request("getUserChatBoosts", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getUserChatBoosts", v, nil, reqOpts) if err != nil { return nil, err } @@ -2395,7 +2837,7 @@ func (bot *Bot) GetUserChatBoosts(chatId int64, userId int64, opts *GetUserChatB return &u, json.Unmarshal(r, &u) } -// GetUserProfilePhotosOpts is the set of optional fields for Bot.GetUserProfilePhotos. +// GetUserProfilePhotosOpts is the set of optional fields for Bot.GetUserProfilePhotos and Bot.GetUserProfilePhotosWithContext. type GetUserProfilePhotosOpts struct { // Sequential number of the first photo to be returned. By default, all photos are returned. Offset int64 @@ -2411,6 +2853,11 @@ type GetUserProfilePhotosOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type GetUserProfilePhotosOpts): All optional parameters. func (bot *Bot) GetUserProfilePhotos(userId int64, opts *GetUserProfilePhotosOpts) (*UserProfilePhotos, error) { + return bot.GetUserProfilePhotosWithContext(context.Background(), userId, opts) +} + +// GetUserProfilePhotosWithContext is the same as Bot.GetUserProfilePhotos, but with a context.Context parameter +func (bot *Bot) GetUserProfilePhotosWithContext(ctx context.Context, userId int64, opts *GetUserProfilePhotosOpts) (*UserProfilePhotos, error) { v := map[string]string{} v["user_id"] = strconv.FormatInt(userId, 10) if opts != nil { @@ -2427,7 +2874,7 @@ func (bot *Bot) GetUserProfilePhotos(userId int64, opts *GetUserProfilePhotosOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("getUserProfilePhotos", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getUserProfilePhotos", v, nil, reqOpts) if err != nil { return nil, err } @@ -2436,7 +2883,7 @@ func (bot *Bot) GetUserProfilePhotos(userId int64, opts *GetUserProfilePhotosOpt return &u, json.Unmarshal(r, &u) } -// GetWebhookInfoOpts is the set of optional fields for Bot.GetWebhookInfo. +// GetWebhookInfoOpts is the set of optional fields for Bot.GetWebhookInfo and Bot.GetWebhookInfoWithContext. type GetWebhookInfoOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2447,6 +2894,11 @@ type GetWebhookInfoOpts struct { // Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty. // - opts (type GetWebhookInfoOpts): All optional parameters. func (bot *Bot) GetWebhookInfo(opts *GetWebhookInfoOpts) (*WebhookInfo, error) { + return bot.GetWebhookInfoWithContext(context.Background(), opts) +} + +// GetWebhookInfoWithContext is the same as Bot.GetWebhookInfo, but with a context.Context parameter +func (bot *Bot) GetWebhookInfoWithContext(ctx context.Context, opts *GetWebhookInfoOpts) (*WebhookInfo, error) { v := map[string]string{} var reqOpts *RequestOpts @@ -2454,7 +2906,7 @@ func (bot *Bot) GetWebhookInfo(opts *GetWebhookInfoOpts) (*WebhookInfo, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("getWebhookInfo", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "getWebhookInfo", v, nil, reqOpts) if err != nil { return nil, err } @@ -2463,7 +2915,7 @@ func (bot *Bot) GetWebhookInfo(opts *GetWebhookInfoOpts) (*WebhookInfo, error) { return &w, json.Unmarshal(r, &w) } -// HideGeneralForumTopicOpts is the set of optional fields for Bot.HideGeneralForumTopic. +// HideGeneralForumTopicOpts is the set of optional fields for Bot.HideGeneralForumTopic and Bot.HideGeneralForumTopicWithContext. type HideGeneralForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2475,6 +2927,11 @@ type HideGeneralForumTopicOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type HideGeneralForumTopicOpts): All optional parameters. func (bot *Bot) HideGeneralForumTopic(chatId int64, opts *HideGeneralForumTopicOpts) (bool, error) { + return bot.HideGeneralForumTopicWithContext(context.Background(), chatId, opts) +} + +// HideGeneralForumTopicWithContext is the same as Bot.HideGeneralForumTopic, but with a context.Context parameter +func (bot *Bot) HideGeneralForumTopicWithContext(ctx context.Context, chatId int64, opts *HideGeneralForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -2483,7 +2940,7 @@ func (bot *Bot) HideGeneralForumTopic(chatId int64, opts *HideGeneralForumTopicO reqOpts = opts.RequestOpts } - r, err := bot.Request("hideGeneralForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "hideGeneralForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -2492,7 +2949,7 @@ func (bot *Bot) HideGeneralForumTopic(chatId int64, opts *HideGeneralForumTopicO return b, json.Unmarshal(r, &b) } -// LeaveChatOpts is the set of optional fields for Bot.LeaveChat. +// LeaveChatOpts is the set of optional fields for Bot.LeaveChat and Bot.LeaveChatWithContext. type LeaveChatOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2504,6 +2961,11 @@ type LeaveChatOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type LeaveChatOpts): All optional parameters. func (bot *Bot) LeaveChat(chatId int64, opts *LeaveChatOpts) (bool, error) { + return bot.LeaveChatWithContext(context.Background(), chatId, opts) +} + +// LeaveChatWithContext is the same as Bot.LeaveChat, but with a context.Context parameter +func (bot *Bot) LeaveChatWithContext(ctx context.Context, chatId int64, opts *LeaveChatOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -2512,7 +2974,7 @@ func (bot *Bot) LeaveChat(chatId int64, opts *LeaveChatOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("leaveChat", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "leaveChat", v, nil, reqOpts) if err != nil { return false, err } @@ -2521,7 +2983,7 @@ func (bot *Bot) LeaveChat(chatId int64, opts *LeaveChatOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// LogOutOpts is the set of optional fields for Bot.LogOut. +// LogOutOpts is the set of optional fields for Bot.LogOut and Bot.LogOutWithContext. type LogOutOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2532,6 +2994,11 @@ type LogOutOpts struct { // Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success. Requires no parameters. // - opts (type LogOutOpts): All optional parameters. func (bot *Bot) LogOut(opts *LogOutOpts) (bool, error) { + return bot.LogOutWithContext(context.Background(), opts) +} + +// LogOutWithContext is the same as Bot.LogOut, but with a context.Context parameter +func (bot *Bot) LogOutWithContext(ctx context.Context, opts *LogOutOpts) (bool, error) { v := map[string]string{} var reqOpts *RequestOpts @@ -2539,7 +3006,7 @@ func (bot *Bot) LogOut(opts *LogOutOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("logOut", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "logOut", v, nil, reqOpts) if err != nil { return false, err } @@ -2548,8 +3015,10 @@ func (bot *Bot) LogOut(opts *LogOutOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// PinChatMessageOpts is the set of optional fields for Bot.PinChatMessage. +// PinChatMessageOpts is the set of optional fields for Bot.PinChatMessage and Bot.PinChatMessageWithContext. type PinChatMessageOpts struct { + // Unique identifier of the business connection on behalf of which the message will be pinned + BusinessConnectionId string // Pass True if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats. DisableNotification bool // RequestOpts are an additional optional field to configure timeouts for individual requests @@ -2563,10 +3032,16 @@ type PinChatMessageOpts struct { // - messageId (type int64): Identifier of a message to pin // - opts (type PinChatMessageOpts): All optional parameters. func (bot *Bot) PinChatMessage(chatId int64, messageId int64, opts *PinChatMessageOpts) (bool, error) { + return bot.PinChatMessageWithContext(context.Background(), chatId, messageId, opts) +} + +// PinChatMessageWithContext is the same as Bot.PinChatMessage, but with a context.Context parameter +func (bot *Bot) PinChatMessageWithContext(ctx context.Context, chatId int64, messageId int64, opts *PinChatMessageOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_id"] = strconv.FormatInt(messageId, 10) if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) } @@ -2575,7 +3050,7 @@ func (bot *Bot) PinChatMessage(chatId int64, messageId int64, opts *PinChatMessa reqOpts = opts.RequestOpts } - r, err := bot.Request("pinChatMessage", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "pinChatMessage", v, nil, reqOpts) if err != nil { return false, err } @@ -2584,7 +3059,7 @@ func (bot *Bot) PinChatMessage(chatId int64, messageId int64, opts *PinChatMessa return b, json.Unmarshal(r, &b) } -// PromoteChatMemberOpts is the set of optional fields for Bot.PromoteChatMember. +// PromoteChatMemberOpts is the set of optional fields for Bot.PromoteChatMember and Bot.PromoteChatMemberWithContext. type PromoteChatMemberOpts struct { // Pass True if the administrator's presence in the chat is hidden IsAnonymous bool @@ -2627,6 +3102,11 @@ type PromoteChatMemberOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type PromoteChatMemberOpts): All optional parameters. func (bot *Bot) PromoteChatMember(chatId int64, userId int64, opts *PromoteChatMemberOpts) (bool, error) { + return bot.PromoteChatMemberWithContext(context.Background(), chatId, userId, opts) +} + +// PromoteChatMemberWithContext is the same as Bot.PromoteChatMember, but with a context.Context parameter +func (bot *Bot) PromoteChatMemberWithContext(ctx context.Context, chatId int64, userId int64, opts *PromoteChatMemberOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -2653,7 +3133,7 @@ func (bot *Bot) PromoteChatMember(chatId int64, userId int64, opts *PromoteChatM reqOpts = opts.RequestOpts } - r, err := bot.Request("promoteChatMember", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "promoteChatMember", v, nil, reqOpts) if err != nil { return false, err } @@ -2662,7 +3142,43 @@ func (bot *Bot) PromoteChatMember(chatId int64, userId int64, opts *PromoteChatM return b, json.Unmarshal(r, &b) } -// ReopenForumTopicOpts is the set of optional fields for Bot.ReopenForumTopic. +// RefundStarPaymentOpts is the set of optional fields for Bot.RefundStarPayment and Bot.RefundStarPaymentWithContext. +type RefundStarPaymentOpts struct { + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// RefundStarPayment (https://core.telegram.org/bots/api#refundstarpayment) +// +// Refunds a successful payment in Telegram Stars. Returns True on success. +// - userId (type int64): Identifier of the user whose payment will be refunded +// - telegramPaymentChargeId (type string): Telegram payment identifier +// - opts (type RefundStarPaymentOpts): All optional parameters. +func (bot *Bot) RefundStarPayment(userId int64, telegramPaymentChargeId string, opts *RefundStarPaymentOpts) (bool, error) { + return bot.RefundStarPaymentWithContext(context.Background(), userId, telegramPaymentChargeId, opts) +} + +// RefundStarPaymentWithContext is the same as Bot.RefundStarPayment, but with a context.Context parameter +func (bot *Bot) RefundStarPaymentWithContext(ctx context.Context, userId int64, telegramPaymentChargeId string, opts *RefundStarPaymentOpts) (bool, error) { + v := map[string]string{} + v["user_id"] = strconv.FormatInt(userId, 10) + v["telegram_payment_charge_id"] = telegramPaymentChargeId + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "refundStarPayment", v, nil, reqOpts) + if err != nil { + return false, err + } + + var b bool + return b, json.Unmarshal(r, &b) +} + +// ReopenForumTopicOpts is the set of optional fields for Bot.ReopenForumTopic and Bot.ReopenForumTopicWithContext. type ReopenForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2675,6 +3191,11 @@ type ReopenForumTopicOpts struct { // - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic // - opts (type ReopenForumTopicOpts): All optional parameters. func (bot *Bot) ReopenForumTopic(chatId int64, messageThreadId int64, opts *ReopenForumTopicOpts) (bool, error) { + return bot.ReopenForumTopicWithContext(context.Background(), chatId, messageThreadId, opts) +} + +// ReopenForumTopicWithContext is the same as Bot.ReopenForumTopic, but with a context.Context parameter +func (bot *Bot) ReopenForumTopicWithContext(ctx context.Context, chatId int64, messageThreadId int64, opts *ReopenForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10) @@ -2684,7 +3205,7 @@ func (bot *Bot) ReopenForumTopic(chatId int64, messageThreadId int64, opts *Reop reqOpts = opts.RequestOpts } - r, err := bot.Request("reopenForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "reopenForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -2693,7 +3214,7 @@ func (bot *Bot) ReopenForumTopic(chatId int64, messageThreadId int64, opts *Reop return b, json.Unmarshal(r, &b) } -// ReopenGeneralForumTopicOpts is the set of optional fields for Bot.ReopenGeneralForumTopic. +// ReopenGeneralForumTopicOpts is the set of optional fields for Bot.ReopenGeneralForumTopic and Bot.ReopenGeneralForumTopicWithContext. type ReopenGeneralForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2705,6 +3226,11 @@ type ReopenGeneralForumTopicOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type ReopenGeneralForumTopicOpts): All optional parameters. func (bot *Bot) ReopenGeneralForumTopic(chatId int64, opts *ReopenGeneralForumTopicOpts) (bool, error) { + return bot.ReopenGeneralForumTopicWithContext(context.Background(), chatId, opts) +} + +// ReopenGeneralForumTopicWithContext is the same as Bot.ReopenGeneralForumTopic, but with a context.Context parameter +func (bot *Bot) ReopenGeneralForumTopicWithContext(ctx context.Context, chatId int64, opts *ReopenGeneralForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -2713,7 +3239,7 @@ func (bot *Bot) ReopenGeneralForumTopic(chatId int64, opts *ReopenGeneralForumTo reqOpts = opts.RequestOpts } - r, err := bot.Request("reopenGeneralForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "reopenGeneralForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -2722,7 +3248,7 @@ func (bot *Bot) ReopenGeneralForumTopic(chatId int64, opts *ReopenGeneralForumTo return b, json.Unmarshal(r, &b) } -// ReplaceStickerInSetOpts is the set of optional fields for Bot.ReplaceStickerInSet. +// ReplaceStickerInSetOpts is the set of optional fields for Bot.ReplaceStickerInSet and Bot.ReplaceStickerInSetWithContext. type ReplaceStickerInSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2737,8 +3263,13 @@ type ReplaceStickerInSetOpts struct { // - sticker (type InputSticker): A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged. // - opts (type ReplaceStickerInSetOpts): All optional parameters. func (bot *Bot) ReplaceStickerInSet(userId int64, name string, oldSticker string, sticker InputSticker, opts *ReplaceStickerInSetOpts) (bool, error) { + return bot.ReplaceStickerInSetWithContext(context.Background(), userId, name, oldSticker, sticker, opts) +} + +// ReplaceStickerInSetWithContext is the same as Bot.ReplaceStickerInSet, but with a context.Context parameter +func (bot *Bot) ReplaceStickerInSetWithContext(ctx context.Context, userId int64, name string, oldSticker string, sticker InputSticker, opts *ReplaceStickerInSetOpts) (bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["user_id"] = strconv.FormatInt(userId, 10) v["name"] = name v["old_sticker"] = oldSticker @@ -2753,7 +3284,7 @@ func (bot *Bot) ReplaceStickerInSet(userId int64, name string, oldSticker string reqOpts = opts.RequestOpts } - r, err := bot.Request("replaceStickerInSet", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "replaceStickerInSet", v, data, reqOpts) if err != nil { return false, err } @@ -2762,7 +3293,7 @@ func (bot *Bot) ReplaceStickerInSet(userId int64, name string, oldSticker string return b, json.Unmarshal(r, &b) } -// RestrictChatMemberOpts is the set of optional fields for Bot.RestrictChatMember. +// RestrictChatMemberOpts is the set of optional fields for Bot.RestrictChatMember and Bot.RestrictChatMemberWithContext. type RestrictChatMemberOpts struct { // Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission. UseIndependentChatPermissions bool @@ -2780,6 +3311,11 @@ type RestrictChatMemberOpts struct { // - permissions (type ChatPermissions): A JSON-serialized object for new user permissions // - opts (type RestrictChatMemberOpts): All optional parameters. func (bot *Bot) RestrictChatMember(chatId int64, userId int64, permissions ChatPermissions, opts *RestrictChatMemberOpts) (bool, error) { + return bot.RestrictChatMemberWithContext(context.Background(), chatId, userId, permissions, opts) +} + +// RestrictChatMemberWithContext is the same as Bot.RestrictChatMember, but with a context.Context parameter +func (bot *Bot) RestrictChatMemberWithContext(ctx context.Context, chatId int64, userId int64, permissions ChatPermissions, opts *RestrictChatMemberOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -2800,7 +3336,7 @@ func (bot *Bot) RestrictChatMember(chatId int64, userId int64, permissions ChatP reqOpts = opts.RequestOpts } - r, err := bot.Request("restrictChatMember", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "restrictChatMember", v, nil, reqOpts) if err != nil { return false, err } @@ -2809,7 +3345,7 @@ func (bot *Bot) RestrictChatMember(chatId int64, userId int64, permissions ChatP return b, json.Unmarshal(r, &b) } -// RevokeChatInviteLinkOpts is the set of optional fields for Bot.RevokeChatInviteLink. +// RevokeChatInviteLinkOpts is the set of optional fields for Bot.RevokeChatInviteLink and Bot.RevokeChatInviteLinkWithContext. type RevokeChatInviteLinkOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -2822,6 +3358,11 @@ type RevokeChatInviteLinkOpts struct { // - inviteLink (type string): The invite link to revoke // - opts (type RevokeChatInviteLinkOpts): All optional parameters. func (bot *Bot) RevokeChatInviteLink(chatId int64, inviteLink string, opts *RevokeChatInviteLinkOpts) (*ChatInviteLink, error) { + return bot.RevokeChatInviteLinkWithContext(context.Background(), chatId, inviteLink, opts) +} + +// RevokeChatInviteLinkWithContext is the same as Bot.RevokeChatInviteLink, but with a context.Context parameter +func (bot *Bot) RevokeChatInviteLinkWithContext(ctx context.Context, chatId int64, inviteLink string, opts *RevokeChatInviteLinkOpts) (*ChatInviteLink, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["invite_link"] = inviteLink @@ -2831,7 +3372,7 @@ func (bot *Bot) RevokeChatInviteLink(chatId int64, inviteLink string, opts *Revo reqOpts = opts.RequestOpts } - r, err := bot.Request("revokeChatInviteLink", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "revokeChatInviteLink", v, nil, reqOpts) if err != nil { return nil, err } @@ -2840,7 +3381,7 @@ func (bot *Bot) RevokeChatInviteLink(chatId int64, inviteLink string, opts *Revo return &c, json.Unmarshal(r, &c) } -// SendAnimationOpts is the set of optional fields for Bot.SendAnimation. +// 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 BusinessConnectionId string @@ -2860,12 +3401,18 @@ type SendAnimationOpts struct { ParseMode string // A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity + // Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool // Pass True if the animation needs to be covered with a spoiler animation HasSpoiler bool // Sends the message silently. Users will receive a notification with no sound. DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -2878,32 +3425,23 @@ type SendAnimationOpts struct { // // Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. // - chatId (type int64): Unique identifier for the target chat -// - animation (type InputFile): Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files +// - animation (type InputFileOrString): Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files // - opts (type SendAnimationOpts): All optional parameters. -func (bot *Bot) SendAnimation(chatId int64, animation InputFile, opts *SendAnimationOpts) (*Message, error) { +func (bot *Bot) SendAnimation(chatId int64, animation InputFileOrString, opts *SendAnimationOpts) (*Message, error) { + return bot.SendAnimationWithContext(context.Background(), chatId, animation, opts) +} + +// SendAnimationWithContext is the same as Bot.SendAnimation, but with a context.Context parameter +func (bot *Bot) SendAnimationWithContext(ctx context.Context, chatId int64, animation InputFileOrString, opts *SendAnimationOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if animation != nil { - switch m := animation.(type) { - case string: - v["animation"] = m - - case NamedReader: - v["animation"] = "attach://animation" - data["animation"] = m - - case io.Reader: - v["animation"] = "attach://animation" - data["animation"] = NamedFile{File: m} - - case []byte: - v["animation"] = "attach://animation" - data["animation"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", animation) + err := animation.Attach("animation", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'animation' input file: %w", err) } + v["animation"] = animation.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -2920,25 +3458,11 @@ func (bot *Bot) SendAnimation(chatId int64, animation InputFile, opts *SendAnima v["height"] = strconv.FormatInt(opts.Height, 10) } if opts.Thumbnail != nil { - switch m := opts.Thumbnail.(type) { - case string: - v["thumbnail"] = m - - case NamedReader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = m - - case io.Reader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: m} - - case []byte: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", opts.Thumbnail) + err := opts.Thumbnail.Attach("thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file: %w", err) } + v["thumbnail"] = opts.Thumbnail.getValue() } v["caption"] = opts.Caption v["parse_mode"] = opts.ParseMode @@ -2949,9 +3473,12 @@ func (bot *Bot) SendAnimation(chatId int64, animation InputFile, opts *SendAnima } v["caption_entities"] = string(bs) } + v["show_caption_above_media"] = strconv.FormatBool(opts.ShowCaptionAboveMedia) v["has_spoiler"] = strconv.FormatBool(opts.HasSpoiler) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -2973,7 +3500,7 @@ func (bot *Bot) SendAnimation(chatId int64, animation InputFile, opts *SendAnima reqOpts = opts.RequestOpts } - r, err := bot.Request("sendAnimation", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendAnimation", v, data, reqOpts) if err != nil { return nil, err } @@ -2982,7 +3509,7 @@ func (bot *Bot) SendAnimation(chatId int64, animation InputFile, opts *SendAnima return &m, json.Unmarshal(r, &m) } -// SendAudioOpts is the set of optional fields for Bot.SendAudio. +// SendAudioOpts is the set of optional fields for Bot.SendAudio and Bot.SendAudioWithContext. type SendAudioOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3006,6 +3533,10 @@ type SendAudioOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3019,32 +3550,23 @@ type SendAudioOpts struct { // Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. // For sending voice messages, use the sendVoice method instead. // - chatId (type int64): Unique identifier for the target chat -// - audio (type InputFile): Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files +// - audio (type InputFileOrString): Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files // - opts (type SendAudioOpts): All optional parameters. -func (bot *Bot) SendAudio(chatId int64, audio InputFile, opts *SendAudioOpts) (*Message, error) { +func (bot *Bot) SendAudio(chatId int64, audio InputFileOrString, opts *SendAudioOpts) (*Message, error) { + return bot.SendAudioWithContext(context.Background(), chatId, audio, opts) +} + +// SendAudioWithContext is the same as Bot.SendAudio, but with a context.Context parameter +func (bot *Bot) SendAudioWithContext(ctx context.Context, chatId int64, audio InputFileOrString, opts *SendAudioOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if audio != nil { - switch m := audio.(type) { - case string: - v["audio"] = m - - case NamedReader: - v["audio"] = "attach://audio" - data["audio"] = m - - case io.Reader: - v["audio"] = "attach://audio" - data["audio"] = NamedFile{File: m} - - case []byte: - v["audio"] = "attach://audio" - data["audio"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", audio) + err := audio.Attach("audio", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'audio' input file: %w", err) } + v["audio"] = audio.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -3066,28 +3588,16 @@ func (bot *Bot) SendAudio(chatId int64, audio InputFile, opts *SendAudioOpts) (* v["performer"] = opts.Performer v["title"] = opts.Title if opts.Thumbnail != nil { - switch m := opts.Thumbnail.(type) { - case string: - v["thumbnail"] = m - - case NamedReader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = m - - case io.Reader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: m} - - case []byte: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", opts.Thumbnail) + err := opts.Thumbnail.Attach("thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file: %w", err) } + v["thumbnail"] = opts.Thumbnail.getValue() } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3109,7 +3619,7 @@ func (bot *Bot) SendAudio(chatId int64, audio InputFile, opts *SendAudioOpts) (* reqOpts = opts.RequestOpts } - r, err := bot.Request("sendAudio", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendAudio", v, data, reqOpts) if err != nil { return nil, err } @@ -3118,7 +3628,7 @@ func (bot *Bot) SendAudio(chatId int64, audio InputFile, opts *SendAudioOpts) (* return &m, json.Unmarshal(r, &m) } -// SendChatActionOpts is the set of optional fields for Bot.SendChatAction. +// SendChatActionOpts is the set of optional fields for Bot.SendChatAction and Bot.SendChatActionWithContext. type SendChatActionOpts struct { // Unique identifier of the business connection on behalf of which the action will be sent BusinessConnectionId string @@ -3136,6 +3646,11 @@ type SendChatActionOpts struct { // - action (type string): Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes. // - opts (type SendChatActionOpts): All optional parameters. func (bot *Bot) SendChatAction(chatId int64, action string, opts *SendChatActionOpts) (bool, error) { + return bot.SendChatActionWithContext(context.Background(), chatId, action, opts) +} + +// SendChatActionWithContext is the same as Bot.SendChatAction, but with a context.Context parameter +func (bot *Bot) SendChatActionWithContext(ctx context.Context, chatId int64, action string, opts *SendChatActionOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["action"] = action @@ -3151,7 +3666,7 @@ func (bot *Bot) SendChatAction(chatId int64, action string, opts *SendChatAction reqOpts = opts.RequestOpts } - r, err := bot.Request("sendChatAction", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendChatAction", v, nil, reqOpts) if err != nil { return false, err } @@ -3160,7 +3675,7 @@ func (bot *Bot) SendChatAction(chatId int64, action string, opts *SendChatAction return b, json.Unmarshal(r, &b) } -// SendContactOpts is the set of optional fields for Bot.SendContact. +// SendContactOpts is the set of optional fields for Bot.SendContact and Bot.SendContactWithContext. type SendContactOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3174,6 +3689,10 @@ type SendContactOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3190,6 +3709,11 @@ type SendContactOpts struct { // - firstName (type string): Contact's first name // - opts (type SendContactOpts): All optional parameters. func (bot *Bot) SendContact(chatId int64, phoneNumber string, firstName string, opts *SendContactOpts) (*Message, error) { + return bot.SendContactWithContext(context.Background(), chatId, phoneNumber, firstName, opts) +} + +// SendContactWithContext is the same as Bot.SendContact, but with a context.Context parameter +func (bot *Bot) SendContactWithContext(ctx context.Context, chatId int64, phoneNumber string, firstName string, opts *SendContactOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["phone_number"] = phoneNumber @@ -3203,6 +3727,8 @@ func (bot *Bot) SendContact(chatId int64, phoneNumber string, firstName string, v["vcard"] = opts.Vcard v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3224,7 +3750,7 @@ func (bot *Bot) SendContact(chatId int64, phoneNumber string, firstName string, reqOpts = opts.RequestOpts } - r, err := bot.Request("sendContact", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendContact", v, nil, reqOpts) if err != nil { return nil, err } @@ -3233,7 +3759,7 @@ func (bot *Bot) SendContact(chatId int64, phoneNumber string, firstName string, return &m, json.Unmarshal(r, &m) } -// SendDiceOpts is the set of optional fields for Bot.SendDice. +// SendDiceOpts is the set of optional fields for Bot.SendDice and Bot.SendDiceWithContext. type SendDiceOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3245,6 +3771,10 @@ type SendDiceOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3259,6 +3789,11 @@ type SendDiceOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type SendDiceOpts): All optional parameters. func (bot *Bot) SendDice(chatId int64, opts *SendDiceOpts) (*Message, error) { + return bot.SendDiceWithContext(context.Background(), chatId, opts) +} + +// SendDiceWithContext is the same as Bot.SendDice, but with a context.Context parameter +func (bot *Bot) SendDiceWithContext(ctx context.Context, chatId int64, opts *SendDiceOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) if opts != nil { @@ -3269,6 +3804,8 @@ func (bot *Bot) SendDice(chatId int64, opts *SendDiceOpts) (*Message, error) { v["emoji"] = opts.Emoji v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3290,7 +3827,7 @@ func (bot *Bot) SendDice(chatId int64, opts *SendDiceOpts) (*Message, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("sendDice", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendDice", v, nil, reqOpts) if err != nil { return nil, err } @@ -3299,7 +3836,7 @@ func (bot *Bot) SendDice(chatId int64, opts *SendDiceOpts) (*Message, error) { return &m, json.Unmarshal(r, &m) } -// SendDocumentOpts is the set of optional fields for Bot.SendDocument. +// SendDocumentOpts is the set of optional fields for Bot.SendDocument and Bot.SendDocumentWithContext. type SendDocumentOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3319,6 +3856,10 @@ type SendDocumentOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3331,32 +3872,23 @@ type SendDocumentOpts struct { // // Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. // - chatId (type int64): Unique identifier for the target chat -// - document (type InputFile): File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files +// - document (type InputFileOrString): File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files // - opts (type SendDocumentOpts): All optional parameters. -func (bot *Bot) SendDocument(chatId int64, document InputFile, opts *SendDocumentOpts) (*Message, error) { +func (bot *Bot) SendDocument(chatId int64, document InputFileOrString, opts *SendDocumentOpts) (*Message, error) { + return bot.SendDocumentWithContext(context.Background(), chatId, document, opts) +} + +// SendDocumentWithContext is the same as Bot.SendDocument, but with a context.Context parameter +func (bot *Bot) SendDocumentWithContext(ctx context.Context, chatId int64, document InputFileOrString, opts *SendDocumentOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if document != nil { - switch m := document.(type) { - case string: - v["document"] = m - - case NamedReader: - v["document"] = "attach://document" - data["document"] = m - - case io.Reader: - v["document"] = "attach://document" - data["document"] = NamedFile{File: m} - - case []byte: - v["document"] = "attach://document" - data["document"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", document) + err := document.Attach("document", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'document' input file: %w", err) } + v["document"] = document.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -3364,25 +3896,11 @@ func (bot *Bot) SendDocument(chatId int64, document InputFile, opts *SendDocumen v["message_thread_id"] = strconv.FormatInt(opts.MessageThreadId, 10) } if opts.Thumbnail != nil { - switch m := opts.Thumbnail.(type) { - case string: - v["thumbnail"] = m - - case NamedReader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = m - - case io.Reader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: m} - - case []byte: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", opts.Thumbnail) + err := opts.Thumbnail.Attach("thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file: %w", err) } + v["thumbnail"] = opts.Thumbnail.getValue() } v["caption"] = opts.Caption v["parse_mode"] = opts.ParseMode @@ -3396,6 +3914,8 @@ func (bot *Bot) SendDocument(chatId int64, document InputFile, opts *SendDocumen v["disable_content_type_detection"] = strconv.FormatBool(opts.DisableContentTypeDetection) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3417,7 +3937,7 @@ func (bot *Bot) SendDocument(chatId int64, document InputFile, opts *SendDocumen reqOpts = opts.RequestOpts } - r, err := bot.Request("sendDocument", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendDocument", v, data, reqOpts) if err != nil { return nil, err } @@ -3426,7 +3946,7 @@ func (bot *Bot) SendDocument(chatId int64, document InputFile, opts *SendDocumen return &m, json.Unmarshal(r, &m) } -// SendGameOpts is the set of optional fields for Bot.SendGame. +// SendGameOpts is the set of optional fields for Bot.SendGame and Bot.SendGameWithContext. type SendGameOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3436,6 +3956,10 @@ type SendGameOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // A JSON-serialized object for an inline keyboard. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game. @@ -3451,6 +3975,11 @@ type SendGameOpts struct { // - gameShortName (type string): Short name of the game, serves as the unique identifier for the game. Set up your games via @BotFather. // - opts (type SendGameOpts): All optional parameters. func (bot *Bot) SendGame(chatId int64, gameShortName string, opts *SendGameOpts) (*Message, error) { + return bot.SendGameWithContext(context.Background(), chatId, gameShortName, opts) +} + +// SendGameWithContext is the same as Bot.SendGame, but with a context.Context parameter +func (bot *Bot) SendGameWithContext(ctx context.Context, chatId int64, gameShortName string, opts *SendGameOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["game_short_name"] = gameShortName @@ -3461,6 +3990,8 @@ func (bot *Bot) SendGame(chatId int64, gameShortName string, opts *SendGameOpts) } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3480,7 +4011,7 @@ func (bot *Bot) SendGame(chatId int64, gameShortName string, opts *SendGameOpts) reqOpts = opts.RequestOpts } - r, err := bot.Request("sendGame", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendGame", v, nil, reqOpts) if err != nil { return nil, err } @@ -3489,11 +4020,13 @@ func (bot *Bot) SendGame(chatId int64, gameShortName string, opts *SendGameOpts) return &m, json.Unmarshal(r, &m) } -// SendInvoiceOpts is the set of optional fields for Bot.SendInvoice. +// 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 MessageThreadId 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 + // Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. + ProviderToken string + // 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. SuggestedTipAmounts []int64 @@ -3509,24 +4042,28 @@ type SendInvoiceOpts struct { PhotoWidth int64 // Photo height PhotoHeight int64 - // Pass True if you require the user's full name to complete the order + // Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars. NeedName bool - // Pass True if you require the user's phone number to complete the order + // Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars. NeedPhoneNumber bool - // Pass True if you require the user's email address to complete the order + // Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars. NeedEmail bool - // Pass True if you require the user's shipping address to complete the order + // Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars. NeedShippingAddress bool - // Pass True if the user's phone number should be sent to provider + // Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars. SendPhoneNumberToProvider bool - // Pass True if the user's email address should be sent to provider + // Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars. SendEmailToProvider bool - // Pass True if the final price depends on the shipping method + // Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars. IsFlexible bool // Sends the message silently. Users will receive a notification with no sound. DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. @@ -3541,18 +4078,21 @@ type SendInvoiceOpts struct { // - chatId (type int64): Unique identifier for the target chat // - title (type string): Product name, 1-32 characters // - description (type string): Product description, 1-255 characters -// - payload (type string): Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. -// - providerToken (type string): Payment provider token, obtained via @BotFather -// - currency (type string): Three-letter ISO 4217 currency code, see more on currencies -// - prices (type []LabeledPrice): Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) +// - payload (type string): Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. +// - currency (type string): Three-letter ISO 4217 currency code, see more on currencies. Pass "XTR" for payments in Telegram Stars. +// - prices (type []LabeledPrice): Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars. // - opts (type SendInvoiceOpts): All optional parameters. -func (bot *Bot) SendInvoice(chatId int64, title string, description string, payload string, providerToken string, currency string, prices []LabeledPrice, opts *SendInvoiceOpts) (*Message, error) { +func (bot *Bot) SendInvoice(chatId int64, title string, description string, payload string, currency string, prices []LabeledPrice, opts *SendInvoiceOpts) (*Message, error) { + return bot.SendInvoiceWithContext(context.Background(), chatId, title, description, payload, currency, prices, opts) +} + +// SendInvoiceWithContext is the same as Bot.SendInvoice, but with a context.Context parameter +func (bot *Bot) SendInvoiceWithContext(ctx context.Context, chatId int64, title string, description string, payload string, currency string, prices []LabeledPrice, opts *SendInvoiceOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["title"] = title v["description"] = description v["payload"] = payload - v["provider_token"] = providerToken v["currency"] = currency if prices != nil { bs, err := json.Marshal(prices) @@ -3565,6 +4105,7 @@ func (bot *Bot) SendInvoice(chatId int64, title string, description string, payl if opts.MessageThreadId != 0 { v["message_thread_id"] = strconv.FormatInt(opts.MessageThreadId, 10) } + v["provider_token"] = opts.ProviderToken if opts.MaxTipAmount != 0 { v["max_tip_amount"] = strconv.FormatInt(opts.MaxTipAmount, 10) } @@ -3596,6 +4137,8 @@ func (bot *Bot) SendInvoice(chatId int64, title string, description string, payl v["is_flexible"] = strconv.FormatBool(opts.IsFlexible) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3615,7 +4158,7 @@ func (bot *Bot) SendInvoice(chatId int64, title string, description string, payl reqOpts = opts.RequestOpts } - r, err := bot.Request("sendInvoice", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendInvoice", v, nil, reqOpts) if err != nil { return nil, err } @@ -3624,7 +4167,7 @@ func (bot *Bot) SendInvoice(chatId int64, title string, description string, payl return &m, json.Unmarshal(r, &m) } -// SendLocationOpts is the set of optional fields for Bot.SendLocation. +// SendLocationOpts is the set of optional fields for Bot.SendLocation and Bot.SendLocationWithContext. type SendLocationOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3642,6 +4185,10 @@ type SendLocationOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3658,6 +4205,11 @@ type SendLocationOpts struct { // - longitude (type float64): Longitude of the location // - opts (type SendLocationOpts): All optional parameters. func (bot *Bot) SendLocation(chatId int64, latitude float64, longitude float64, opts *SendLocationOpts) (*Message, error) { + return bot.SendLocationWithContext(context.Background(), chatId, latitude, longitude, opts) +} + +// SendLocationWithContext is the same as Bot.SendLocation, but with a context.Context parameter +func (bot *Bot) SendLocationWithContext(ctx context.Context, chatId int64, latitude float64, longitude float64, opts *SendLocationOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["latitude"] = strconv.FormatFloat(latitude, 'f', -1, 64) @@ -3681,6 +4233,8 @@ func (bot *Bot) SendLocation(chatId int64, latitude float64, longitude float64, } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3702,7 +4256,7 @@ func (bot *Bot) SendLocation(chatId int64, latitude float64, longitude float64, reqOpts = opts.RequestOpts } - r, err := bot.Request("sendLocation", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendLocation", v, nil, reqOpts) if err != nil { return nil, err } @@ -3711,7 +4265,7 @@ func (bot *Bot) SendLocation(chatId int64, latitude float64, longitude float64, return &m, json.Unmarshal(r, &m) } -// SendMediaGroupOpts is the set of optional fields for Bot.SendMediaGroup. +// SendMediaGroupOpts is the set of optional fields for Bot.SendMediaGroup and Bot.SendMediaGroupWithContext. type SendMediaGroupOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3721,6 +4275,10 @@ type SendMediaGroupOpts struct { DisableNotification bool // Protects the contents of the sent messages from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // RequestOpts are an additional optional field to configure timeouts for individual requests @@ -3734,8 +4292,13 @@ type SendMediaGroupOpts struct { // - media (type []InputMedia): A JSON-serialized array describing messages to be sent, must include 2-10 items // - opts (type SendMediaGroupOpts): All optional parameters. func (bot *Bot) SendMediaGroup(chatId int64, media []InputMedia, opts *SendMediaGroupOpts) ([]Message, error) { + return bot.SendMediaGroupWithContext(context.Background(), chatId, media, opts) +} + +// SendMediaGroupWithContext is the same as Bot.SendMediaGroup, but with a context.Context parameter +func (bot *Bot) SendMediaGroupWithContext(ctx context.Context, chatId int64, media []InputMedia, opts *SendMediaGroupOpts) ([]Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if media != nil { var rawList []json.RawMessage @@ -3759,6 +4322,8 @@ func (bot *Bot) SendMediaGroup(chatId int64, media []InputMedia, opts *SendMedia } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3773,7 +4338,7 @@ func (bot *Bot) SendMediaGroup(chatId int64, media []InputMedia, opts *SendMedia reqOpts = opts.RequestOpts } - r, err := bot.Request("sendMediaGroup", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendMediaGroup", v, data, reqOpts) if err != nil { return nil, err } @@ -3782,7 +4347,7 @@ func (bot *Bot) SendMediaGroup(chatId int64, media []InputMedia, opts *SendMedia return m, json.Unmarshal(r, &m) } -// SendMessageOpts is the set of optional fields for Bot.SendMessage. +// SendMessageOpts is the set of optional fields for Bot.SendMessage and Bot.SendMessageWithContext. type SendMessageOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3798,6 +4363,10 @@ type SendMessageOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3813,6 +4382,11 @@ type SendMessageOpts struct { // - text (type string): Text of the message to be sent, 1-4096 characters after entities parsing // - opts (type SendMessageOpts): All optional parameters. func (bot *Bot) SendMessage(chatId int64, text string, opts *SendMessageOpts) (*Message, error) { + return bot.SendMessageWithContext(context.Background(), chatId, text, opts) +} + +// SendMessageWithContext is the same as Bot.SendMessage, but with a context.Context parameter +func (bot *Bot) SendMessageWithContext(ctx context.Context, chatId int64, text string, opts *SendMessageOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["text"] = text @@ -3838,6 +4412,114 @@ func (bot *Bot) SendMessage(chatId int64, text string, opts *SendMessageOpts) (* } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId + if opts.ReplyParameters != nil { + bs, err := json.Marshal(opts.ReplyParameters) + if err != nil { + return nil, fmt.Errorf("failed to marshal field reply_parameters: %w", err) + } + v["reply_parameters"] = string(bs) + } + if opts.ReplyMarkup != nil { + bs, err := json.Marshal(opts.ReplyMarkup) + if err != nil { + return nil, fmt.Errorf("failed to marshal field reply_markup: %w", err) + } + v["reply_markup"] = string(bs) + } + } + + var reqOpts *RequestOpts + if opts != nil { + reqOpts = opts.RequestOpts + } + + r, err := bot.RequestWithContext(ctx, "sendMessage", v, nil, reqOpts) + if err != nil { + return nil, err + } + + var m Message + return &m, json.Unmarshal(r, &m) +} + +// SendPaidMediaOpts is the set of optional fields for Bot.SendPaidMedia and Bot.SendPaidMediaWithContext. +type SendPaidMediaOpts struct { + // Unique identifier of the business connection on behalf of which the message will be sent + BusinessConnectionId string + // Bot-defined paid media payload, 0-128 bytes. This will not be displayed to the user, use it for your internal processes. + Payload string + // Media caption, 0-1024 characters after entities parsing + Caption string + // Mode for parsing entities in the media caption. See formatting options for more details. + ParseMode string + // A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode + CaptionEntities []MessageEntity + // Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool + // Sends the message silently. Users will receive a notification with no sound. + DisableNotification bool + // Protects the contents of the sent message from forwarding and saving + ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Description of the message to reply to + ReplyParameters *ReplyParameters + // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user + ReplyMarkup ReplyMarkup + // RequestOpts are an additional optional field to configure timeouts for individual requests + RequestOpts *RequestOpts +} + +// SendPaidMedia (https://core.telegram.org/bots/api#sendpaidmedia) +// +// Use this method to send paid media. On success, the sent Message is returned. +// - chatId (type int64): Unique identifier for the target chat. If the chat is a channel, all Telegram Star proceeds from this media will be credited to the chat's balance. Otherwise, they will be credited to the bot's balance. +// - starCount (type int64): The number of Telegram Stars that must be paid to buy access to the media; 1-2500 +// - media (type []InputPaidMedia): A JSON-serialized array describing the media to be sent; up to 10 items +// - opts (type SendPaidMediaOpts): All optional parameters. +func (bot *Bot) SendPaidMedia(chatId int64, starCount int64, media []InputPaidMedia, opts *SendPaidMediaOpts) (*Message, error) { + return bot.SendPaidMediaWithContext(context.Background(), chatId, starCount, media, opts) +} + +// SendPaidMediaWithContext is the same as Bot.SendPaidMedia, but with a context.Context parameter +func (bot *Bot) SendPaidMediaWithContext(ctx context.Context, chatId int64, starCount int64, media []InputPaidMedia, opts *SendPaidMediaOpts) (*Message, error) { + v := map[string]string{} + data := map[string]FileReader{} + v["chat_id"] = strconv.FormatInt(chatId, 10) + v["star_count"] = strconv.FormatInt(starCount, 10) + if media != nil { + var rawList []json.RawMessage + for idx, im := range media { + inputBs, err := im.InputParams("media"+strconv.Itoa(idx), data) + if err != nil { + return nil, fmt.Errorf("failed to marshal list item %d for field media: %w", idx, err) + } + rawList = append(rawList, inputBs) + } + bs, err := json.Marshal(rawList) + if err != nil { + return nil, fmt.Errorf("failed to marshal raw json list for field: media %w", err) + } + v["media"] = string(bs) + } + if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId + v["payload"] = opts.Payload + v["caption"] = opts.Caption + v["parse_mode"] = opts.ParseMode + if opts.CaptionEntities != nil { + bs, err := json.Marshal(opts.CaptionEntities) + if err != nil { + return nil, fmt.Errorf("failed to marshal field caption_entities: %w", err) + } + v["caption_entities"] = string(bs) + } + v["show_caption_above_media"] = strconv.FormatBool(opts.ShowCaptionAboveMedia) + v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) + v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3859,7 +4541,7 @@ func (bot *Bot) SendMessage(chatId int64, text string, opts *SendMessageOpts) (* reqOpts = opts.RequestOpts } - r, err := bot.Request("sendMessage", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendPaidMedia", v, data, reqOpts) if err != nil { return nil, err } @@ -3868,7 +4550,7 @@ func (bot *Bot) SendMessage(chatId int64, text string, opts *SendMessageOpts) (* return &m, json.Unmarshal(r, &m) } -// SendPhotoOpts is the set of optional fields for Bot.SendPhoto. +// SendPhotoOpts is the set of optional fields for Bot.SendPhoto and Bot.SendPhotoWithContext. type SendPhotoOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -3880,12 +4562,18 @@ type SendPhotoOpts struct { ParseMode string // A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity + // Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool // Pass True if the photo needs to be covered with a spoiler animation HasSpoiler bool // Sends the message silently. Users will receive a notification with no sound. DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -3898,32 +4586,23 @@ type SendPhotoOpts struct { // // Use this method to send photos. On success, the sent Message is returned. // - chatId (type int64): Unique identifier for the target chat -// - photo (type InputFile): Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. More information on Sending Files: https://core.telegram.org/bots/api#sending-files +// - photo (type InputFileOrString): Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. More information on Sending Files: https://core.telegram.org/bots/api#sending-files // - opts (type SendPhotoOpts): All optional parameters. -func (bot *Bot) SendPhoto(chatId int64, photo InputFile, opts *SendPhotoOpts) (*Message, error) { +func (bot *Bot) SendPhoto(chatId int64, photo InputFileOrString, opts *SendPhotoOpts) (*Message, error) { + return bot.SendPhotoWithContext(context.Background(), chatId, photo, opts) +} + +// SendPhotoWithContext is the same as Bot.SendPhoto, but with a context.Context parameter +func (bot *Bot) SendPhotoWithContext(ctx context.Context, chatId int64, photo InputFileOrString, opts *SendPhotoOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if photo != nil { - switch m := photo.(type) { - case string: - v["photo"] = m - - case NamedReader: - v["photo"] = "attach://photo" - data["photo"] = m - - case io.Reader: - v["photo"] = "attach://photo" - data["photo"] = NamedFile{File: m} - - case []byte: - v["photo"] = "attach://photo" - data["photo"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", photo) + err := photo.Attach("photo", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'photo' input file: %w", err) } + v["photo"] = photo.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -3939,9 +4618,12 @@ func (bot *Bot) SendPhoto(chatId int64, photo InputFile, opts *SendPhotoOpts) (* } v["caption_entities"] = string(bs) } + v["show_caption_above_media"] = strconv.FormatBool(opts.ShowCaptionAboveMedia) v["has_spoiler"] = strconv.FormatBool(opts.HasSpoiler) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -3963,7 +4645,7 @@ func (bot *Bot) SendPhoto(chatId int64, photo InputFile, opts *SendPhotoOpts) (* reqOpts = opts.RequestOpts } - r, err := bot.Request("sendPhoto", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendPhoto", v, data, reqOpts) if err != nil { return nil, err } @@ -3972,7 +4654,7 @@ func (bot *Bot) SendPhoto(chatId int64, photo InputFile, opts *SendPhotoOpts) (* return &m, json.Unmarshal(r, &m) } -// SendPollOpts is the set of optional fields for Bot.SendPoll. +// SendPollOpts is the set of optional fields for Bot.SendPoll and Bot.SendPollWithContext. type SendPollOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -4006,6 +4688,10 @@ type SendPollOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -4022,6 +4708,11 @@ type SendPollOpts struct { // - options (type []InputPollOption): A JSON-serialized list of 2-10 answer options // - opts (type SendPollOpts): All optional parameters. func (bot *Bot) SendPoll(chatId int64, question string, options []InputPollOption, opts *SendPollOpts) (*Message, error) { + return bot.SendPollWithContext(context.Background(), chatId, question, options, opts) +} + +// SendPollWithContext is the same as Bot.SendPoll, but with a context.Context parameter +func (bot *Bot) SendPollWithContext(ctx context.Context, chatId int64, question string, options []InputPollOption, opts *SendPollOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["question"] = question @@ -4070,6 +4761,8 @@ func (bot *Bot) SendPoll(chatId int64, question string, options []InputPollOptio v["is_closed"] = strconv.FormatBool(opts.IsClosed) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -4091,7 +4784,7 @@ func (bot *Bot) SendPoll(chatId int64, question string, options []InputPollOptio reqOpts = opts.RequestOpts } - r, err := bot.Request("sendPoll", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendPoll", v, nil, reqOpts) if err != nil { return nil, err } @@ -4100,7 +4793,7 @@ func (bot *Bot) SendPoll(chatId int64, question string, options []InputPollOptio return &m, json.Unmarshal(r, &m) } -// SendStickerOpts is the set of optional fields for Bot.SendSticker. +// SendStickerOpts is the set of optional fields for Bot.SendSticker and Bot.SendStickerWithContext. type SendStickerOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -4112,6 +4805,10 @@ type SendStickerOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -4124,32 +4821,23 @@ type SendStickerOpts struct { // // Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned. // - chatId (type int64): Unique identifier for the target chat -// - sticker (type InputFile): Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP, .TGS, or .WEBM sticker using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Video and animated stickers can't be sent via an HTTP URL. +// - sticker (type InputFileOrString): Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP, .TGS, or .WEBM sticker using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Video and animated stickers can't be sent via an HTTP URL. // - opts (type SendStickerOpts): All optional parameters. -func (bot *Bot) SendSticker(chatId int64, sticker InputFile, opts *SendStickerOpts) (*Message, error) { +func (bot *Bot) SendSticker(chatId int64, sticker InputFileOrString, opts *SendStickerOpts) (*Message, error) { + return bot.SendStickerWithContext(context.Background(), chatId, sticker, opts) +} + +// SendStickerWithContext is the same as Bot.SendSticker, but with a context.Context parameter +func (bot *Bot) SendStickerWithContext(ctx context.Context, chatId int64, sticker InputFileOrString, opts *SendStickerOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if sticker != nil { - switch m := sticker.(type) { - case string: - v["sticker"] = m - - case NamedReader: - v["sticker"] = "attach://sticker" - data["sticker"] = m - - case io.Reader: - v["sticker"] = "attach://sticker" - data["sticker"] = NamedFile{File: m} - - case []byte: - v["sticker"] = "attach://sticker" - data["sticker"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", sticker) + err := sticker.Attach("sticker", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'sticker' input file: %w", err) } + v["sticker"] = sticker.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -4159,6 +4847,8 @@ func (bot *Bot) SendSticker(chatId int64, sticker InputFile, opts *SendStickerOp v["emoji"] = opts.Emoji v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -4180,7 +4870,7 @@ func (bot *Bot) SendSticker(chatId int64, sticker InputFile, opts *SendStickerOp reqOpts = opts.RequestOpts } - r, err := bot.Request("sendSticker", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendSticker", v, data, reqOpts) if err != nil { return nil, err } @@ -4189,7 +4879,7 @@ func (bot *Bot) SendSticker(chatId int64, sticker InputFile, opts *SendStickerOp return &m, json.Unmarshal(r, &m) } -// SendVenueOpts is the set of optional fields for Bot.SendVenue. +// SendVenueOpts is the set of optional fields for Bot.SendVenue and Bot.SendVenueWithContext. type SendVenueOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -4207,6 +4897,10 @@ type SendVenueOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -4225,6 +4919,11 @@ type SendVenueOpts struct { // - address (type string): Address of the venue // - opts (type SendVenueOpts): All optional parameters. func (bot *Bot) SendVenue(chatId int64, latitude float64, longitude float64, title string, address string, opts *SendVenueOpts) (*Message, error) { + return bot.SendVenueWithContext(context.Background(), chatId, latitude, longitude, title, address, opts) +} + +// SendVenueWithContext is the same as Bot.SendVenue, but with a context.Context parameter +func (bot *Bot) SendVenueWithContext(ctx context.Context, chatId int64, latitude float64, longitude float64, title string, address string, opts *SendVenueOpts) (*Message, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["latitude"] = strconv.FormatFloat(latitude, 'f', -1, 64) @@ -4242,6 +4941,8 @@ func (bot *Bot) SendVenue(chatId int64, latitude float64, longitude float64, tit v["google_place_type"] = opts.GooglePlaceType v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -4263,7 +4964,7 @@ func (bot *Bot) SendVenue(chatId int64, latitude float64, longitude float64, tit reqOpts = opts.RequestOpts } - r, err := bot.Request("sendVenue", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendVenue", v, nil, reqOpts) if err != nil { return nil, err } @@ -4272,7 +4973,7 @@ func (bot *Bot) SendVenue(chatId int64, latitude float64, longitude float64, tit return &m, json.Unmarshal(r, &m) } -// SendVideoOpts is the set of optional fields for Bot.SendVideo. +// SendVideoOpts is the set of optional fields for Bot.SendVideo and Bot.SendVideoWithContext. type SendVideoOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -4292,6 +4993,8 @@ type SendVideoOpts struct { ParseMode string // A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity + // Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool // Pass True if the video needs to be covered with a spoiler animation HasSpoiler bool // Pass True if the uploaded video is suitable for streaming @@ -4300,6 +5003,10 @@ type SendVideoOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -4312,32 +5019,23 @@ type SendVideoOpts struct { // // Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. // - chatId (type int64): Unique identifier for the target chat -// - video (type InputFile): Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files +// - video (type InputFileOrString): Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files // - opts (type SendVideoOpts): All optional parameters. -func (bot *Bot) SendVideo(chatId int64, video InputFile, opts *SendVideoOpts) (*Message, error) { +func (bot *Bot) SendVideo(chatId int64, video InputFileOrString, opts *SendVideoOpts) (*Message, error) { + return bot.SendVideoWithContext(context.Background(), chatId, video, opts) +} + +// SendVideoWithContext is the same as Bot.SendVideo, but with a context.Context parameter +func (bot *Bot) SendVideoWithContext(ctx context.Context, chatId int64, video InputFileOrString, opts *SendVideoOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if video != nil { - switch m := video.(type) { - case string: - v["video"] = m - - case NamedReader: - v["video"] = "attach://video" - data["video"] = m - - case io.Reader: - v["video"] = "attach://video" - data["video"] = NamedFile{File: m} - - case []byte: - v["video"] = "attach://video" - data["video"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", video) + err := video.Attach("video", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'video' input file: %w", err) } + v["video"] = video.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -4354,25 +5052,11 @@ func (bot *Bot) SendVideo(chatId int64, video InputFile, opts *SendVideoOpts) (* v["height"] = strconv.FormatInt(opts.Height, 10) } if opts.Thumbnail != nil { - switch m := opts.Thumbnail.(type) { - case string: - v["thumbnail"] = m - - case NamedReader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = m - - case io.Reader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: m} - - case []byte: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", opts.Thumbnail) + err := opts.Thumbnail.Attach("thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file: %w", err) } + v["thumbnail"] = opts.Thumbnail.getValue() } v["caption"] = opts.Caption v["parse_mode"] = opts.ParseMode @@ -4383,10 +5067,13 @@ func (bot *Bot) SendVideo(chatId int64, video InputFile, opts *SendVideoOpts) (* } v["caption_entities"] = string(bs) } + v["show_caption_above_media"] = strconv.FormatBool(opts.ShowCaptionAboveMedia) v["has_spoiler"] = strconv.FormatBool(opts.HasSpoiler) v["supports_streaming"] = strconv.FormatBool(opts.SupportsStreaming) v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -4408,7 +5095,7 @@ func (bot *Bot) SendVideo(chatId int64, video InputFile, opts *SendVideoOpts) (* reqOpts = opts.RequestOpts } - r, err := bot.Request("sendVideo", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendVideo", v, data, reqOpts) if err != nil { return nil, err } @@ -4417,7 +5104,7 @@ func (bot *Bot) SendVideo(chatId int64, video InputFile, opts *SendVideoOpts) (* return &m, json.Unmarshal(r, &m) } -// SendVideoNoteOpts is the set of optional fields for Bot.SendVideoNote. +// SendVideoNoteOpts is the set of optional fields for Bot.SendVideoNote and Bot.SendVideoNoteWithContext. type SendVideoNoteOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -4433,6 +5120,10 @@ type SendVideoNoteOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -4445,32 +5136,23 @@ type SendVideoNoteOpts struct { // // As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned. // - chatId (type int64): Unique identifier for the target chat -// - videoNote (type InputFile): Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Sending video notes by a URL is currently unsupported +// - videoNote (type InputFileOrString): Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Sending video notes by a URL is currently unsupported // - opts (type SendVideoNoteOpts): All optional parameters. -func (bot *Bot) SendVideoNote(chatId int64, videoNote InputFile, opts *SendVideoNoteOpts) (*Message, error) { +func (bot *Bot) SendVideoNote(chatId int64, videoNote InputFileOrString, opts *SendVideoNoteOpts) (*Message, error) { + return bot.SendVideoNoteWithContext(context.Background(), chatId, videoNote, opts) +} + +// SendVideoNoteWithContext is the same as Bot.SendVideoNote, but with a context.Context parameter +func (bot *Bot) SendVideoNoteWithContext(ctx context.Context, chatId int64, videoNote InputFileOrString, opts *SendVideoNoteOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if videoNote != nil { - switch m := videoNote.(type) { - case string: - v["video_note"] = m - - case NamedReader: - v["video_note"] = "attach://video_note" - data["video_note"] = m - - case io.Reader: - v["video_note"] = "attach://video_note" - data["video_note"] = NamedFile{File: m} - - case []byte: - v["video_note"] = "attach://video_note" - data["video_note"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", videoNote) + err := videoNote.Attach("video_note", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'video_note' input file: %w", err) } + v["video_note"] = videoNote.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -4484,28 +5166,16 @@ func (bot *Bot) SendVideoNote(chatId int64, videoNote InputFile, opts *SendVideo v["length"] = strconv.FormatInt(opts.Length, 10) } if opts.Thumbnail != nil { - switch m := opts.Thumbnail.(type) { - case string: - v["thumbnail"] = m - - case NamedReader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = m - - case io.Reader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: m} - - case []byte: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", opts.Thumbnail) + err := opts.Thumbnail.Attach("thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file: %w", err) } + v["thumbnail"] = opts.Thumbnail.getValue() } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -4527,7 +5197,7 @@ func (bot *Bot) SendVideoNote(chatId int64, videoNote InputFile, opts *SendVideo reqOpts = opts.RequestOpts } - r, err := bot.Request("sendVideoNote", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendVideoNote", v, data, reqOpts) if err != nil { return nil, err } @@ -4536,7 +5206,7 @@ func (bot *Bot) SendVideoNote(chatId int64, videoNote InputFile, opts *SendVideo return &m, json.Unmarshal(r, &m) } -// SendVoiceOpts is the set of optional fields for Bot.SendVoice. +// SendVoiceOpts is the set of optional fields for Bot.SendVoice and Bot.SendVoiceWithContext. type SendVoiceOpts struct { // Unique identifier of the business connection on behalf of which the message will be sent BusinessConnectionId string @@ -4554,6 +5224,10 @@ type SendVoiceOpts struct { DisableNotification bool // Protects the contents of the sent message from forwarding and saving ProtectContent bool + // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance + AllowPaidBroadcast bool + // Unique identifier of the message effect to be added to the message; for private chats only + MessageEffectId string // Description of the message to reply to ReplyParameters *ReplyParameters // Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user @@ -4566,32 +5240,23 @@ type SendVoiceOpts struct { // // Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. // - chatId (type int64): Unique identifier for the target chat -// - voice (type InputFile): Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files +// - voice (type InputFileOrString): Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files // - opts (type SendVoiceOpts): All optional parameters. -func (bot *Bot) SendVoice(chatId int64, voice InputFile, opts *SendVoiceOpts) (*Message, error) { +func (bot *Bot) SendVoice(chatId int64, voice InputFileOrString, opts *SendVoiceOpts) (*Message, error) { + return bot.SendVoiceWithContext(context.Background(), chatId, voice, opts) +} + +// SendVoiceWithContext is the same as Bot.SendVoice, but with a context.Context parameter +func (bot *Bot) SendVoiceWithContext(ctx context.Context, chatId int64, voice InputFileOrString, opts *SendVoiceOpts) (*Message, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if voice != nil { - switch m := voice.(type) { - case string: - v["voice"] = m - - case NamedReader: - v["voice"] = "attach://voice" - data["voice"] = m - - case io.Reader: - v["voice"] = "attach://voice" - data["voice"] = NamedFile{File: m} - - case []byte: - v["voice"] = "attach://voice" - data["voice"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", voice) + err := voice.Attach("voice", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'voice' input file: %w", err) } + v["voice"] = voice.getValue() } if opts != nil { v["business_connection_id"] = opts.BusinessConnectionId @@ -4612,6 +5277,8 @@ func (bot *Bot) SendVoice(chatId int64, voice InputFile, opts *SendVoiceOpts) (* } v["disable_notification"] = strconv.FormatBool(opts.DisableNotification) v["protect_content"] = strconv.FormatBool(opts.ProtectContent) + v["allow_paid_broadcast"] = strconv.FormatBool(opts.AllowPaidBroadcast) + v["message_effect_id"] = opts.MessageEffectId if opts.ReplyParameters != nil { bs, err := json.Marshal(opts.ReplyParameters) if err != nil { @@ -4633,7 +5300,7 @@ func (bot *Bot) SendVoice(chatId int64, voice InputFile, opts *SendVoiceOpts) (* reqOpts = opts.RequestOpts } - r, err := bot.Request("sendVoice", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "sendVoice", v, data, reqOpts) if err != nil { return nil, err } @@ -4642,7 +5309,7 @@ func (bot *Bot) SendVoice(chatId int64, voice InputFile, opts *SendVoiceOpts) (* return &m, json.Unmarshal(r, &m) } -// SetChatAdministratorCustomTitleOpts is the set of optional fields for Bot.SetChatAdministratorCustomTitle. +// SetChatAdministratorCustomTitleOpts is the set of optional fields for Bot.SetChatAdministratorCustomTitle and Bot.SetChatAdministratorCustomTitleWithContext. type SetChatAdministratorCustomTitleOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -4656,6 +5323,11 @@ type SetChatAdministratorCustomTitleOpts struct { // - customTitle (type string): New custom title for the administrator; 0-16 characters, emoji are not allowed // - opts (type SetChatAdministratorCustomTitleOpts): All optional parameters. func (bot *Bot) SetChatAdministratorCustomTitle(chatId int64, userId int64, customTitle string, opts *SetChatAdministratorCustomTitleOpts) (bool, error) { + return bot.SetChatAdministratorCustomTitleWithContext(context.Background(), chatId, userId, customTitle, opts) +} + +// SetChatAdministratorCustomTitleWithContext is the same as Bot.SetChatAdministratorCustomTitle, but with a context.Context parameter +func (bot *Bot) SetChatAdministratorCustomTitleWithContext(ctx context.Context, chatId int64, userId int64, customTitle string, opts *SetChatAdministratorCustomTitleOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -4666,7 +5338,7 @@ func (bot *Bot) SetChatAdministratorCustomTitle(chatId int64, userId int64, cust reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatAdministratorCustomTitle", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatAdministratorCustomTitle", v, nil, reqOpts) if err != nil { return false, err } @@ -4675,7 +5347,7 @@ func (bot *Bot) SetChatAdministratorCustomTitle(chatId int64, userId int64, cust return b, json.Unmarshal(r, &b) } -// SetChatDescriptionOpts is the set of optional fields for Bot.SetChatDescription. +// SetChatDescriptionOpts is the set of optional fields for Bot.SetChatDescription and Bot.SetChatDescriptionWithContext. type SetChatDescriptionOpts struct { // New chat description, 0-255 characters Description string @@ -4689,6 +5361,11 @@ type SetChatDescriptionOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type SetChatDescriptionOpts): All optional parameters. func (bot *Bot) SetChatDescription(chatId int64, opts *SetChatDescriptionOpts) (bool, error) { + return bot.SetChatDescriptionWithContext(context.Background(), chatId, opts) +} + +// SetChatDescriptionWithContext is the same as Bot.SetChatDescription, but with a context.Context parameter +func (bot *Bot) SetChatDescriptionWithContext(ctx context.Context, chatId int64, opts *SetChatDescriptionOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) if opts != nil { @@ -4700,7 +5377,7 @@ func (bot *Bot) SetChatDescription(chatId int64, opts *SetChatDescriptionOpts) ( reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatDescription", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatDescription", v, nil, reqOpts) if err != nil { return false, err } @@ -4709,7 +5386,7 @@ func (bot *Bot) SetChatDescription(chatId int64, opts *SetChatDescriptionOpts) ( return b, json.Unmarshal(r, &b) } -// SetChatMenuButtonOpts is the set of optional fields for Bot.SetChatMenuButton. +// SetChatMenuButtonOpts is the set of optional fields for Bot.SetChatMenuButton and Bot.SetChatMenuButtonWithContext. type SetChatMenuButtonOpts struct { // Unique identifier for the target private chat. If not specified, default bot's menu button will be changed ChatId *int64 @@ -4724,6 +5401,11 @@ type SetChatMenuButtonOpts struct { // Use this method to change the bot's menu button in a private chat, or the default menu button. Returns True on success. // - opts (type SetChatMenuButtonOpts): All optional parameters. func (bot *Bot) SetChatMenuButton(opts *SetChatMenuButtonOpts) (bool, error) { + return bot.SetChatMenuButtonWithContext(context.Background(), opts) +} + +// SetChatMenuButtonWithContext is the same as Bot.SetChatMenuButton, but with a context.Context parameter +func (bot *Bot) SetChatMenuButtonWithContext(ctx context.Context, opts *SetChatMenuButtonOpts) (bool, error) { v := map[string]string{} if opts != nil { if opts.ChatId != nil { @@ -4741,7 +5423,7 @@ func (bot *Bot) SetChatMenuButton(opts *SetChatMenuButtonOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatMenuButton", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatMenuButton", v, nil, reqOpts) if err != nil { return false, err } @@ -4750,7 +5432,7 @@ func (bot *Bot) SetChatMenuButton(opts *SetChatMenuButtonOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// SetChatPermissionsOpts is the set of optional fields for Bot.SetChatPermissions. +// SetChatPermissionsOpts is the set of optional fields for Bot.SetChatPermissions and Bot.SetChatPermissionsWithContext. type SetChatPermissionsOpts struct { // Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission. UseIndependentChatPermissions bool @@ -4765,6 +5447,11 @@ type SetChatPermissionsOpts struct { // - permissions (type ChatPermissions): A JSON-serialized object for new default chat permissions // - opts (type SetChatPermissionsOpts): All optional parameters. func (bot *Bot) SetChatPermissions(chatId int64, permissions ChatPermissions, opts *SetChatPermissionsOpts) (bool, error) { + return bot.SetChatPermissionsWithContext(context.Background(), chatId, permissions, opts) +} + +// SetChatPermissionsWithContext is the same as Bot.SetChatPermissions, but with a context.Context parameter +func (bot *Bot) SetChatPermissionsWithContext(ctx context.Context, chatId int64, permissions ChatPermissions, opts *SetChatPermissionsOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) bs, err := json.Marshal(permissions) @@ -4781,7 +5468,7 @@ func (bot *Bot) SetChatPermissions(chatId int64, permissions ChatPermissions, op reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatPermissions", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatPermissions", v, nil, reqOpts) if err != nil { return false, err } @@ -4790,7 +5477,7 @@ func (bot *Bot) SetChatPermissions(chatId int64, permissions ChatPermissions, op return b, json.Unmarshal(r, &b) } -// SetChatPhotoOpts is the set of optional fields for Bot.SetChatPhoto. +// SetChatPhotoOpts is the set of optional fields for Bot.SetChatPhoto and Bot.SetChatPhotoWithContext. type SetChatPhotoOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -4803,26 +5490,20 @@ type SetChatPhotoOpts struct { // - photo (type InputFile): New chat photo, uploaded using multipart/form-data // - opts (type SetChatPhotoOpts): All optional parameters. func (bot *Bot) SetChatPhoto(chatId int64, photo InputFile, opts *SetChatPhotoOpts) (bool, error) { + return bot.SetChatPhotoWithContext(context.Background(), chatId, photo, opts) +} + +// SetChatPhotoWithContext is the same as Bot.SetChatPhoto, but with a context.Context parameter +func (bot *Bot) SetChatPhotoWithContext(ctx context.Context, chatId int64, photo InputFile, opts *SetChatPhotoOpts) (bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["chat_id"] = strconv.FormatInt(chatId, 10) if photo != nil { - switch m := photo.(type) { - case NamedReader: - v["photo"] = "attach://photo" - data["photo"] = m - - case io.Reader: - v["photo"] = "attach://photo" - data["photo"] = NamedFile{File: m} - - case []byte: - v["photo"] = "attach://photo" - data["photo"] = NamedFile{File: bytes.NewReader(m)} - - default: - return false, fmt.Errorf("unknown type for InputFile: %T", photo) + err := photo.Attach("photo", data) + if err != nil { + return false, fmt.Errorf("failed to attach 'photo' input file: %w", err) } + v["photo"] = photo.getValue() } var reqOpts *RequestOpts @@ -4830,7 +5511,7 @@ func (bot *Bot) SetChatPhoto(chatId int64, photo InputFile, opts *SetChatPhotoOp reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatPhoto", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatPhoto", v, data, reqOpts) if err != nil { return false, err } @@ -4839,7 +5520,7 @@ func (bot *Bot) SetChatPhoto(chatId int64, photo InputFile, opts *SetChatPhotoOp return b, json.Unmarshal(r, &b) } -// SetChatStickerSetOpts is the set of optional fields for Bot.SetChatStickerSet. +// SetChatStickerSetOpts is the set of optional fields for Bot.SetChatStickerSet and Bot.SetChatStickerSetWithContext. type SetChatStickerSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -4852,6 +5533,11 @@ type SetChatStickerSetOpts struct { // - stickerSetName (type string): Name of the sticker set to be set as the group sticker set // - opts (type SetChatStickerSetOpts): All optional parameters. func (bot *Bot) SetChatStickerSet(chatId int64, stickerSetName string, opts *SetChatStickerSetOpts) (bool, error) { + return bot.SetChatStickerSetWithContext(context.Background(), chatId, stickerSetName, opts) +} + +// SetChatStickerSetWithContext is the same as Bot.SetChatStickerSet, but with a context.Context parameter +func (bot *Bot) SetChatStickerSetWithContext(ctx context.Context, chatId int64, stickerSetName string, opts *SetChatStickerSetOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["sticker_set_name"] = stickerSetName @@ -4861,7 +5547,7 @@ func (bot *Bot) SetChatStickerSet(chatId int64, stickerSetName string, opts *Set reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatStickerSet", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatStickerSet", v, nil, reqOpts) if err != nil { return false, err } @@ -4870,7 +5556,7 @@ func (bot *Bot) SetChatStickerSet(chatId int64, stickerSetName string, opts *Set return b, json.Unmarshal(r, &b) } -// SetChatTitleOpts is the set of optional fields for Bot.SetChatTitle. +// SetChatTitleOpts is the set of optional fields for Bot.SetChatTitle and Bot.SetChatTitleWithContext. type SetChatTitleOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -4883,6 +5569,11 @@ type SetChatTitleOpts struct { // - title (type string): New chat title, 1-128 characters // - opts (type SetChatTitleOpts): All optional parameters. func (bot *Bot) SetChatTitle(chatId int64, title string, opts *SetChatTitleOpts) (bool, error) { + return bot.SetChatTitleWithContext(context.Background(), chatId, title, opts) +} + +// SetChatTitleWithContext is the same as Bot.SetChatTitle, but with a context.Context parameter +func (bot *Bot) SetChatTitleWithContext(ctx context.Context, chatId int64, title string, opts *SetChatTitleOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["title"] = title @@ -4892,7 +5583,7 @@ func (bot *Bot) SetChatTitle(chatId int64, title string, opts *SetChatTitleOpts) reqOpts = opts.RequestOpts } - r, err := bot.Request("setChatTitle", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setChatTitle", v, nil, reqOpts) if err != nil { return false, err } @@ -4901,7 +5592,7 @@ func (bot *Bot) SetChatTitle(chatId int64, title string, opts *SetChatTitleOpts) return b, json.Unmarshal(r, &b) } -// SetCustomEmojiStickerSetThumbnailOpts is the set of optional fields for Bot.SetCustomEmojiStickerSetThumbnail. +// SetCustomEmojiStickerSetThumbnailOpts is the set of optional fields for Bot.SetCustomEmojiStickerSetThumbnail and Bot.SetCustomEmojiStickerSetThumbnailWithContext. type SetCustomEmojiStickerSetThumbnailOpts struct { // Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail. CustomEmojiId string @@ -4915,6 +5606,11 @@ type SetCustomEmojiStickerSetThumbnailOpts struct { // - name (type string): Sticker set name // - opts (type SetCustomEmojiStickerSetThumbnailOpts): All optional parameters. func (bot *Bot) SetCustomEmojiStickerSetThumbnail(name string, opts *SetCustomEmojiStickerSetThumbnailOpts) (bool, error) { + return bot.SetCustomEmojiStickerSetThumbnailWithContext(context.Background(), name, opts) +} + +// SetCustomEmojiStickerSetThumbnailWithContext is the same as Bot.SetCustomEmojiStickerSetThumbnail, but with a context.Context parameter +func (bot *Bot) SetCustomEmojiStickerSetThumbnailWithContext(ctx context.Context, name string, opts *SetCustomEmojiStickerSetThumbnailOpts) (bool, error) { v := map[string]string{} v["name"] = name if opts != nil { @@ -4926,7 +5622,7 @@ func (bot *Bot) SetCustomEmojiStickerSetThumbnail(name string, opts *SetCustomEm reqOpts = opts.RequestOpts } - r, err := bot.Request("setCustomEmojiStickerSetThumbnail", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setCustomEmojiStickerSetThumbnail", v, nil, reqOpts) if err != nil { return false, err } @@ -4935,7 +5631,7 @@ func (bot *Bot) SetCustomEmojiStickerSetThumbnail(name string, opts *SetCustomEm return b, json.Unmarshal(r, &b) } -// SetGameScoreOpts is the set of optional fields for Bot.SetGameScore. +// SetGameScoreOpts is the set of optional fields for Bot.SetGameScore and Bot.SetGameScoreWithContext. type SetGameScoreOpts struct { // Pass True if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters Force bool @@ -4958,6 +5654,11 @@ type SetGameScoreOpts struct { // - score (type int64): New score, must be non-negative // - opts (type SetGameScoreOpts): All optional parameters. func (bot *Bot) SetGameScore(userId int64, score int64, opts *SetGameScoreOpts) (*Message, bool, error) { + return bot.SetGameScoreWithContext(context.Background(), userId, score, opts) +} + +// SetGameScoreWithContext is the same as Bot.SetGameScore, but with a context.Context parameter +func (bot *Bot) SetGameScoreWithContext(ctx context.Context, userId int64, score int64, opts *SetGameScoreOpts) (*Message, bool, error) { v := map[string]string{} v["user_id"] = strconv.FormatInt(userId, 10) v["score"] = strconv.FormatInt(score, 10) @@ -4978,7 +5679,7 @@ func (bot *Bot) SetGameScore(userId int64, score int64, opts *SetGameScoreOpts) reqOpts = opts.RequestOpts } - r, err := bot.Request("setGameScore", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setGameScore", v, nil, reqOpts) if err != nil { return nil, false, err } @@ -4995,9 +5696,9 @@ func (bot *Bot) SetGameScore(userId int64, score int64, opts *SetGameScoreOpts) } -// SetMessageReactionOpts is the set of optional fields for Bot.SetMessageReaction. +// SetMessageReactionOpts is the set of optional fields for Bot.SetMessageReaction and Bot.SetMessageReactionWithContext. type SetMessageReactionOpts struct { - // A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. + // A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots. Reaction []ReactionType // Pass True to set the reaction with a big animation IsBig bool @@ -5007,11 +5708,16 @@ type SetMessageReactionOpts struct { // SetMessageReaction (https://core.telegram.org/bots/api#setmessagereaction) // -// Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Returns True on success. +// Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success. // - chatId (type int64): Unique identifier for the target chat // - messageId (type int64): Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead. // - opts (type SetMessageReactionOpts): All optional parameters. func (bot *Bot) SetMessageReaction(chatId int64, messageId int64, opts *SetMessageReactionOpts) (bool, error) { + return bot.SetMessageReactionWithContext(context.Background(), chatId, messageId, opts) +} + +// SetMessageReactionWithContext is the same as Bot.SetMessageReaction, but with a context.Context parameter +func (bot *Bot) SetMessageReactionWithContext(ctx context.Context, chatId int64, messageId int64, opts *SetMessageReactionOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_id"] = strconv.FormatInt(messageId, 10) @@ -5031,7 +5737,7 @@ func (bot *Bot) SetMessageReaction(chatId int64, messageId int64, opts *SetMessa reqOpts = opts.RequestOpts } - r, err := bot.Request("setMessageReaction", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setMessageReaction", v, nil, reqOpts) if err != nil { return false, err } @@ -5040,7 +5746,7 @@ func (bot *Bot) SetMessageReaction(chatId int64, messageId int64, opts *SetMessa return b, json.Unmarshal(r, &b) } -// SetMyCommandsOpts is the set of optional fields for Bot.SetMyCommands. +// SetMyCommandsOpts is the set of optional fields for Bot.SetMyCommands and Bot.SetMyCommandsWithContext. type SetMyCommandsOpts struct { // A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault. Scope BotCommandScope @@ -5056,6 +5762,11 @@ type SetMyCommandsOpts struct { // - commands (type []BotCommand): A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified. // - opts (type SetMyCommandsOpts): All optional parameters. func (bot *Bot) SetMyCommands(commands []BotCommand, opts *SetMyCommandsOpts) (bool, error) { + return bot.SetMyCommandsWithContext(context.Background(), commands, opts) +} + +// SetMyCommandsWithContext is the same as Bot.SetMyCommands, but with a context.Context parameter +func (bot *Bot) SetMyCommandsWithContext(ctx context.Context, commands []BotCommand, opts *SetMyCommandsOpts) (bool, error) { v := map[string]string{} if commands != nil { bs, err := json.Marshal(commands) @@ -5078,7 +5789,7 @@ func (bot *Bot) SetMyCommands(commands []BotCommand, opts *SetMyCommandsOpts) (b reqOpts = opts.RequestOpts } - r, err := bot.Request("setMyCommands", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setMyCommands", v, nil, reqOpts) if err != nil { return false, err } @@ -5087,7 +5798,7 @@ func (bot *Bot) SetMyCommands(commands []BotCommand, opts *SetMyCommandsOpts) (b return b, json.Unmarshal(r, &b) } -// SetMyDefaultAdministratorRightsOpts is the set of optional fields for Bot.SetMyDefaultAdministratorRights. +// SetMyDefaultAdministratorRightsOpts is the set of optional fields for Bot.SetMyDefaultAdministratorRights and Bot.SetMyDefaultAdministratorRightsWithContext. type SetMyDefaultAdministratorRightsOpts struct { // A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared. Rights *ChatAdministratorRights @@ -5102,6 +5813,11 @@ type SetMyDefaultAdministratorRightsOpts struct { // Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are free to modify the list before adding the bot. Returns True on success. // - opts (type SetMyDefaultAdministratorRightsOpts): All optional parameters. func (bot *Bot) SetMyDefaultAdministratorRights(opts *SetMyDefaultAdministratorRightsOpts) (bool, error) { + return bot.SetMyDefaultAdministratorRightsWithContext(context.Background(), opts) +} + +// SetMyDefaultAdministratorRightsWithContext is the same as Bot.SetMyDefaultAdministratorRights, but with a context.Context parameter +func (bot *Bot) SetMyDefaultAdministratorRightsWithContext(ctx context.Context, opts *SetMyDefaultAdministratorRightsOpts) (bool, error) { v := map[string]string{} if opts != nil { if opts.Rights != nil { @@ -5119,7 +5835,7 @@ func (bot *Bot) SetMyDefaultAdministratorRights(opts *SetMyDefaultAdministratorR reqOpts = opts.RequestOpts } - r, err := bot.Request("setMyDefaultAdministratorRights", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setMyDefaultAdministratorRights", v, nil, reqOpts) if err != nil { return false, err } @@ -5128,7 +5844,7 @@ func (bot *Bot) SetMyDefaultAdministratorRights(opts *SetMyDefaultAdministratorR return b, json.Unmarshal(r, &b) } -// SetMyDescriptionOpts is the set of optional fields for Bot.SetMyDescription. +// SetMyDescriptionOpts is the set of optional fields for Bot.SetMyDescription and Bot.SetMyDescriptionWithContext. type SetMyDescriptionOpts struct { // New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language. Description string @@ -5143,6 +5859,11 @@ type SetMyDescriptionOpts struct { // Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. Returns True on success. // - opts (type SetMyDescriptionOpts): All optional parameters. func (bot *Bot) SetMyDescription(opts *SetMyDescriptionOpts) (bool, error) { + return bot.SetMyDescriptionWithContext(context.Background(), opts) +} + +// SetMyDescriptionWithContext is the same as Bot.SetMyDescription, but with a context.Context parameter +func (bot *Bot) SetMyDescriptionWithContext(ctx context.Context, opts *SetMyDescriptionOpts) (bool, error) { v := map[string]string{} if opts != nil { v["description"] = opts.Description @@ -5154,7 +5875,7 @@ func (bot *Bot) SetMyDescription(opts *SetMyDescriptionOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("setMyDescription", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setMyDescription", v, nil, reqOpts) if err != nil { return false, err } @@ -5163,7 +5884,7 @@ func (bot *Bot) SetMyDescription(opts *SetMyDescriptionOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// SetMyNameOpts is the set of optional fields for Bot.SetMyName. +// SetMyNameOpts is the set of optional fields for Bot.SetMyName and Bot.SetMyNameWithContext. type SetMyNameOpts struct { // New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language. Name string @@ -5178,6 +5899,11 @@ type SetMyNameOpts struct { // Use this method to change the bot's name. Returns True on success. // - opts (type SetMyNameOpts): All optional parameters. func (bot *Bot) SetMyName(opts *SetMyNameOpts) (bool, error) { + return bot.SetMyNameWithContext(context.Background(), opts) +} + +// SetMyNameWithContext is the same as Bot.SetMyName, but with a context.Context parameter +func (bot *Bot) SetMyNameWithContext(ctx context.Context, opts *SetMyNameOpts) (bool, error) { v := map[string]string{} if opts != nil { v["name"] = opts.Name @@ -5189,7 +5915,7 @@ func (bot *Bot) SetMyName(opts *SetMyNameOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("setMyName", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setMyName", v, nil, reqOpts) if err != nil { return false, err } @@ -5198,7 +5924,7 @@ func (bot *Bot) SetMyName(opts *SetMyNameOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// SetMyShortDescriptionOpts is the set of optional fields for Bot.SetMyShortDescription. +// SetMyShortDescriptionOpts is the set of optional fields for Bot.SetMyShortDescription and Bot.SetMyShortDescriptionWithContext. type SetMyShortDescriptionOpts struct { // New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language. ShortDescription string @@ -5213,6 +5939,11 @@ type SetMyShortDescriptionOpts struct { // Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. Returns True on success. // - opts (type SetMyShortDescriptionOpts): All optional parameters. func (bot *Bot) SetMyShortDescription(opts *SetMyShortDescriptionOpts) (bool, error) { + return bot.SetMyShortDescriptionWithContext(context.Background(), opts) +} + +// SetMyShortDescriptionWithContext is the same as Bot.SetMyShortDescription, but with a context.Context parameter +func (bot *Bot) SetMyShortDescriptionWithContext(ctx context.Context, opts *SetMyShortDescriptionOpts) (bool, error) { v := map[string]string{} if opts != nil { v["short_description"] = opts.ShortDescription @@ -5224,7 +5955,7 @@ func (bot *Bot) SetMyShortDescription(opts *SetMyShortDescriptionOpts) (bool, er reqOpts = opts.RequestOpts } - r, err := bot.Request("setMyShortDescription", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setMyShortDescription", v, nil, reqOpts) if err != nil { return false, err } @@ -5233,7 +5964,7 @@ func (bot *Bot) SetMyShortDescription(opts *SetMyShortDescriptionOpts) (bool, er return b, json.Unmarshal(r, &b) } -// SetPassportDataErrorsOpts is the set of optional fields for Bot.SetPassportDataErrors. +// SetPassportDataErrorsOpts is the set of optional fields for Bot.SetPassportDataErrors and Bot.SetPassportDataErrorsWithContext. type SetPassportDataErrorsOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5247,6 +5978,11 @@ type SetPassportDataErrorsOpts struct { // - errors (type []PassportElementError): A JSON-serialized array describing the errors // - opts (type SetPassportDataErrorsOpts): All optional parameters. func (bot *Bot) SetPassportDataErrors(userId int64, errors []PassportElementError, opts *SetPassportDataErrorsOpts) (bool, error) { + return bot.SetPassportDataErrorsWithContext(context.Background(), userId, errors, opts) +} + +// SetPassportDataErrorsWithContext is the same as Bot.SetPassportDataErrors, but with a context.Context parameter +func (bot *Bot) SetPassportDataErrorsWithContext(ctx context.Context, userId int64, errors []PassportElementError, opts *SetPassportDataErrorsOpts) (bool, error) { v := map[string]string{} v["user_id"] = strconv.FormatInt(userId, 10) if errors != nil { @@ -5262,7 +5998,7 @@ func (bot *Bot) SetPassportDataErrors(userId int64, errors []PassportElementErro reqOpts = opts.RequestOpts } - r, err := bot.Request("setPassportDataErrors", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setPassportDataErrors", v, nil, reqOpts) if err != nil { return false, err } @@ -5271,7 +6007,7 @@ func (bot *Bot) SetPassportDataErrors(userId int64, errors []PassportElementErro return b, json.Unmarshal(r, &b) } -// SetStickerEmojiListOpts is the set of optional fields for Bot.SetStickerEmojiList. +// SetStickerEmojiListOpts is the set of optional fields for Bot.SetStickerEmojiList and Bot.SetStickerEmojiListWithContext. type SetStickerEmojiListOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5284,6 +6020,11 @@ type SetStickerEmojiListOpts struct { // - emojiList (type []string): A JSON-serialized list of 1-20 emoji associated with the sticker // - opts (type SetStickerEmojiListOpts): All optional parameters. func (bot *Bot) SetStickerEmojiList(sticker string, emojiList []string, opts *SetStickerEmojiListOpts) (bool, error) { + return bot.SetStickerEmojiListWithContext(context.Background(), sticker, emojiList, opts) +} + +// SetStickerEmojiListWithContext is the same as Bot.SetStickerEmojiList, but with a context.Context parameter +func (bot *Bot) SetStickerEmojiListWithContext(ctx context.Context, sticker string, emojiList []string, opts *SetStickerEmojiListOpts) (bool, error) { v := map[string]string{} v["sticker"] = sticker if emojiList != nil { @@ -5299,7 +6040,7 @@ func (bot *Bot) SetStickerEmojiList(sticker string, emojiList []string, opts *Se reqOpts = opts.RequestOpts } - r, err := bot.Request("setStickerEmojiList", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setStickerEmojiList", v, nil, reqOpts) if err != nil { return false, err } @@ -5308,7 +6049,7 @@ func (bot *Bot) SetStickerEmojiList(sticker string, emojiList []string, opts *Se return b, json.Unmarshal(r, &b) } -// SetStickerKeywordsOpts is the set of optional fields for Bot.SetStickerKeywords. +// SetStickerKeywordsOpts is the set of optional fields for Bot.SetStickerKeywords and Bot.SetStickerKeywordsWithContext. type SetStickerKeywordsOpts struct { // A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters Keywords []string @@ -5322,6 +6063,11 @@ type SetStickerKeywordsOpts struct { // - sticker (type string): File identifier of the sticker // - opts (type SetStickerKeywordsOpts): All optional parameters. func (bot *Bot) SetStickerKeywords(sticker string, opts *SetStickerKeywordsOpts) (bool, error) { + return bot.SetStickerKeywordsWithContext(context.Background(), sticker, opts) +} + +// SetStickerKeywordsWithContext is the same as Bot.SetStickerKeywords, but with a context.Context parameter +func (bot *Bot) SetStickerKeywordsWithContext(ctx context.Context, sticker string, opts *SetStickerKeywordsOpts) (bool, error) { v := map[string]string{} v["sticker"] = sticker if opts != nil { @@ -5339,7 +6085,7 @@ func (bot *Bot) SetStickerKeywords(sticker string, opts *SetStickerKeywordsOpts) reqOpts = opts.RequestOpts } - r, err := bot.Request("setStickerKeywords", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setStickerKeywords", v, nil, reqOpts) if err != nil { return false, err } @@ -5348,7 +6094,7 @@ func (bot *Bot) SetStickerKeywords(sticker string, opts *SetStickerKeywordsOpts) return b, json.Unmarshal(r, &b) } -// SetStickerMaskPositionOpts is the set of optional fields for Bot.SetStickerMaskPosition. +// SetStickerMaskPositionOpts is the set of optional fields for Bot.SetStickerMaskPosition and Bot.SetStickerMaskPositionWithContext. type SetStickerMaskPositionOpts struct { // A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position. MaskPosition *MaskPosition @@ -5362,6 +6108,11 @@ type SetStickerMaskPositionOpts struct { // - sticker (type string): File identifier of the sticker // - opts (type SetStickerMaskPositionOpts): All optional parameters. func (bot *Bot) SetStickerMaskPosition(sticker string, opts *SetStickerMaskPositionOpts) (bool, error) { + return bot.SetStickerMaskPositionWithContext(context.Background(), sticker, opts) +} + +// SetStickerMaskPositionWithContext is the same as Bot.SetStickerMaskPosition, but with a context.Context parameter +func (bot *Bot) SetStickerMaskPositionWithContext(ctx context.Context, sticker string, opts *SetStickerMaskPositionOpts) (bool, error) { v := map[string]string{} v["sticker"] = sticker if opts != nil { @@ -5379,7 +6130,7 @@ func (bot *Bot) SetStickerMaskPosition(sticker string, opts *SetStickerMaskPosit reqOpts = opts.RequestOpts } - r, err := bot.Request("setStickerMaskPosition", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setStickerMaskPosition", v, nil, reqOpts) if err != nil { return false, err } @@ -5388,7 +6139,7 @@ func (bot *Bot) SetStickerMaskPosition(sticker string, opts *SetStickerMaskPosit return b, json.Unmarshal(r, &b) } -// SetStickerPositionInSetOpts is the set of optional fields for Bot.SetStickerPositionInSet. +// SetStickerPositionInSetOpts is the set of optional fields for Bot.SetStickerPositionInSet and Bot.SetStickerPositionInSetWithContext. type SetStickerPositionInSetOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5401,6 +6152,11 @@ type SetStickerPositionInSetOpts struct { // - position (type int64): New sticker position in the set, zero-based // - opts (type SetStickerPositionInSetOpts): All optional parameters. func (bot *Bot) SetStickerPositionInSet(sticker string, position int64, opts *SetStickerPositionInSetOpts) (bool, error) { + return bot.SetStickerPositionInSetWithContext(context.Background(), sticker, position, opts) +} + +// SetStickerPositionInSetWithContext is the same as Bot.SetStickerPositionInSet, but with a context.Context parameter +func (bot *Bot) SetStickerPositionInSetWithContext(ctx context.Context, sticker string, position int64, opts *SetStickerPositionInSetOpts) (bool, error) { v := map[string]string{} v["sticker"] = sticker v["position"] = strconv.FormatInt(position, 10) @@ -5410,7 +6166,7 @@ func (bot *Bot) SetStickerPositionInSet(sticker string, position int64, opts *Se reqOpts = opts.RequestOpts } - r, err := bot.Request("setStickerPositionInSet", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setStickerPositionInSet", v, nil, reqOpts) if err != nil { return false, err } @@ -5419,9 +6175,9 @@ func (bot *Bot) SetStickerPositionInSet(sticker string, position int64, opts *Se return b, json.Unmarshal(r, &b) } -// SetStickerSetThumbnailOpts is the set of optional fields for Bot.SetStickerSetThumbnail. +// SetStickerSetThumbnailOpts is the set of optional fields for Bot.SetStickerSetThumbnail and Bot.SetStickerSetThumbnailWithContext. type SetStickerSetThumbnailOpts struct { - // A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. + // A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animation-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. Thumbnail InputFile // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5435,32 +6191,23 @@ type SetStickerSetThumbnailOpts struct { // - format (type string): Format of the thumbnail, must be one of "static" for a .WEBP or .PNG image, "animated" for a .TGS animation, or "video" for a WEBM video // - opts (type SetStickerSetThumbnailOpts): All optional parameters. func (bot *Bot) SetStickerSetThumbnail(name string, userId int64, format string, opts *SetStickerSetThumbnailOpts) (bool, error) { + return bot.SetStickerSetThumbnailWithContext(context.Background(), name, userId, format, opts) +} + +// SetStickerSetThumbnailWithContext is the same as Bot.SetStickerSetThumbnail, but with a context.Context parameter +func (bot *Bot) SetStickerSetThumbnailWithContext(ctx context.Context, name string, userId int64, format string, opts *SetStickerSetThumbnailOpts) (bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["name"] = name v["user_id"] = strconv.FormatInt(userId, 10) v["format"] = format if opts != nil { if opts.Thumbnail != nil { - switch m := opts.Thumbnail.(type) { - case string: - v["thumbnail"] = m - - case NamedReader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = m - - case io.Reader: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: m} - - case []byte: - v["thumbnail"] = "attach://thumbnail" - data["thumbnail"] = NamedFile{File: bytes.NewReader(m)} - - default: - return false, fmt.Errorf("unknown type for InputFile: %T", opts.Thumbnail) + err := opts.Thumbnail.Attach("thumbnail", data) + if err != nil { + return false, fmt.Errorf("failed to attach 'thumbnail' input file: %w", err) } + v["thumbnail"] = opts.Thumbnail.getValue() } } @@ -5469,7 +6216,7 @@ func (bot *Bot) SetStickerSetThumbnail(name string, userId int64, format string, reqOpts = opts.RequestOpts } - r, err := bot.Request("setStickerSetThumbnail", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "setStickerSetThumbnail", v, data, reqOpts) if err != nil { return false, err } @@ -5478,7 +6225,7 @@ func (bot *Bot) SetStickerSetThumbnail(name string, userId int64, format string, return b, json.Unmarshal(r, &b) } -// SetStickerSetTitleOpts is the set of optional fields for Bot.SetStickerSetTitle. +// SetStickerSetTitleOpts is the set of optional fields for Bot.SetStickerSetTitle and Bot.SetStickerSetTitleWithContext. type SetStickerSetTitleOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5491,6 +6238,11 @@ type SetStickerSetTitleOpts struct { // - title (type string): Sticker set title, 1-64 characters // - opts (type SetStickerSetTitleOpts): All optional parameters. func (bot *Bot) SetStickerSetTitle(name string, title string, opts *SetStickerSetTitleOpts) (bool, error) { + return bot.SetStickerSetTitleWithContext(context.Background(), name, title, opts) +} + +// SetStickerSetTitleWithContext is the same as Bot.SetStickerSetTitle, but with a context.Context parameter +func (bot *Bot) SetStickerSetTitleWithContext(ctx context.Context, name string, title string, opts *SetStickerSetTitleOpts) (bool, error) { v := map[string]string{} v["name"] = name v["title"] = title @@ -5500,7 +6252,7 @@ func (bot *Bot) SetStickerSetTitle(name string, title string, opts *SetStickerSe reqOpts = opts.RequestOpts } - r, err := bot.Request("setStickerSetTitle", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "setStickerSetTitle", v, nil, reqOpts) if err != nil { return false, err } @@ -5509,7 +6261,7 @@ func (bot *Bot) SetStickerSetTitle(name string, title string, opts *SetStickerSe return b, json.Unmarshal(r, &b) } -// SetWebhookOpts is the set of optional fields for Bot.SetWebhook. +// 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. Certificate InputFile @@ -5534,27 +6286,21 @@ type SetWebhookOpts struct { // - url (type string): HTTPS URL to send updates to. Use an empty string to remove webhook integration // - opts (type SetWebhookOpts): All optional parameters. func (bot *Bot) SetWebhook(url string, opts *SetWebhookOpts) (bool, error) { + return bot.SetWebhookWithContext(context.Background(), url, opts) +} + +// SetWebhookWithContext is the same as Bot.SetWebhook, but with a context.Context parameter +func (bot *Bot) SetWebhookWithContext(ctx context.Context, url string, opts *SetWebhookOpts) (bool, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["url"] = url if opts != nil { if opts.Certificate != nil { - switch m := opts.Certificate.(type) { - case NamedReader: - v["certificate"] = "attach://certificate" - data["certificate"] = m - - case io.Reader: - v["certificate"] = "attach://certificate" - data["certificate"] = NamedFile{File: m} - - case []byte: - v["certificate"] = "attach://certificate" - data["certificate"] = NamedFile{File: bytes.NewReader(m)} - - default: - return false, fmt.Errorf("unknown type for InputFile: %T", opts.Certificate) + err := opts.Certificate.Attach("certificate", data) + if err != nil { + return false, fmt.Errorf("failed to attach 'certificate' input file: %w", err) } + v["certificate"] = opts.Certificate.getValue() } v["ip_address"] = opts.IpAddress if opts.MaxConnections != 0 { @@ -5576,7 +6322,7 @@ func (bot *Bot) SetWebhook(url string, opts *SetWebhookOpts) (bool, error) { reqOpts = opts.RequestOpts } - r, err := bot.Request("setWebhook", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "setWebhook", v, data, reqOpts) if err != nil { return false, err } @@ -5585,8 +6331,10 @@ func (bot *Bot) SetWebhook(url string, opts *SetWebhookOpts) (bool, error) { return b, json.Unmarshal(r, &b) } -// StopMessageLiveLocationOpts is the set of optional fields for Bot.StopMessageLiveLocation. +// StopMessageLiveLocationOpts is the set of optional fields for Bot.StopMessageLiveLocation and Bot.StopMessageLiveLocationWithContext. type StopMessageLiveLocationOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // Required if inline_message_id is not specified. Unique identifier for the target chat ChatId int64 // Required if inline_message_id is not specified. Identifier of the message with live location to stop @@ -5604,8 +6352,14 @@ type StopMessageLiveLocationOpts struct { // Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. // - opts (type StopMessageLiveLocationOpts): All optional parameters. func (bot *Bot) StopMessageLiveLocation(opts *StopMessageLiveLocationOpts) (*Message, bool, error) { + return bot.StopMessageLiveLocationWithContext(context.Background(), opts) +} + +// StopMessageLiveLocationWithContext is the same as Bot.StopMessageLiveLocation, but with a context.Context parameter +func (bot *Bot) StopMessageLiveLocationWithContext(ctx context.Context, opts *StopMessageLiveLocationOpts) (*Message, bool, error) { v := map[string]string{} if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.ChatId != 0 { v["chat_id"] = strconv.FormatInt(opts.ChatId, 10) } @@ -5625,7 +6379,7 @@ func (bot *Bot) StopMessageLiveLocation(opts *StopMessageLiveLocationOpts) (*Mes reqOpts = opts.RequestOpts } - r, err := bot.Request("stopMessageLiveLocation", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "stopMessageLiveLocation", v, nil, reqOpts) if err != nil { return nil, false, err } @@ -5642,8 +6396,10 @@ func (bot *Bot) StopMessageLiveLocation(opts *StopMessageLiveLocationOpts) (*Mes } -// StopPollOpts is the set of optional fields for Bot.StopPoll. +// StopPollOpts is the set of optional fields for Bot.StopPoll and Bot.StopPollWithContext. type StopPollOpts struct { + // Unique identifier of the business connection on behalf of which the message to be edited was sent + BusinessConnectionId string // A JSON-serialized object for a new message inline keyboard. ReplyMarkup InlineKeyboardMarkup // RequestOpts are an additional optional field to configure timeouts for individual requests @@ -5657,10 +6413,16 @@ type StopPollOpts struct { // - messageId (type int64): Identifier of the original message with the poll // - opts (type StopPollOpts): All optional parameters. func (bot *Bot) StopPoll(chatId int64, messageId int64, opts *StopPollOpts) (*Poll, error) { + return bot.StopPollWithContext(context.Background(), chatId, messageId, opts) +} + +// StopPollWithContext is the same as Bot.StopPoll, but with a context.Context parameter +func (bot *Bot) StopPollWithContext(ctx context.Context, chatId int64, messageId int64, opts *StopPollOpts) (*Poll, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_id"] = strconv.FormatInt(messageId, 10) if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId bs, err := json.Marshal(opts.ReplyMarkup) if err != nil { return nil, fmt.Errorf("failed to marshal field reply_markup: %w", err) @@ -5673,7 +6435,7 @@ func (bot *Bot) StopPoll(chatId int64, messageId int64, opts *StopPollOpts) (*Po reqOpts = opts.RequestOpts } - r, err := bot.Request("stopPoll", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "stopPoll", v, nil, reqOpts) if err != nil { return nil, err } @@ -5682,7 +6444,7 @@ func (bot *Bot) StopPoll(chatId int64, messageId int64, opts *StopPollOpts) (*Po return &p, json.Unmarshal(r, &p) } -// UnbanChatMemberOpts is the set of optional fields for Bot.UnbanChatMember. +// UnbanChatMemberOpts is the set of optional fields for Bot.UnbanChatMember and Bot.UnbanChatMemberWithContext. type UnbanChatMemberOpts struct { // Do nothing if the user is not banned OnlyIfBanned bool @@ -5697,6 +6459,11 @@ type UnbanChatMemberOpts struct { // - userId (type int64): Unique identifier of the target user // - opts (type UnbanChatMemberOpts): All optional parameters. func (bot *Bot) UnbanChatMember(chatId int64, userId int64, opts *UnbanChatMemberOpts) (bool, error) { + return bot.UnbanChatMemberWithContext(context.Background(), chatId, userId, opts) +} + +// UnbanChatMemberWithContext is the same as Bot.UnbanChatMember, but with a context.Context parameter +func (bot *Bot) UnbanChatMemberWithContext(ctx context.Context, chatId int64, userId int64, opts *UnbanChatMemberOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["user_id"] = strconv.FormatInt(userId, 10) @@ -5709,7 +6476,7 @@ func (bot *Bot) UnbanChatMember(chatId int64, userId int64, opts *UnbanChatMembe reqOpts = opts.RequestOpts } - r, err := bot.Request("unbanChatMember", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unbanChatMember", v, nil, reqOpts) if err != nil { return false, err } @@ -5718,7 +6485,7 @@ func (bot *Bot) UnbanChatMember(chatId int64, userId int64, opts *UnbanChatMembe return b, json.Unmarshal(r, &b) } -// UnbanChatSenderChatOpts is the set of optional fields for Bot.UnbanChatSenderChat. +// UnbanChatSenderChatOpts is the set of optional fields for Bot.UnbanChatSenderChat and Bot.UnbanChatSenderChatWithContext. type UnbanChatSenderChatOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5731,6 +6498,11 @@ type UnbanChatSenderChatOpts struct { // - senderChatId (type int64): Unique identifier of the target sender chat // - opts (type UnbanChatSenderChatOpts): All optional parameters. func (bot *Bot) UnbanChatSenderChat(chatId int64, senderChatId int64, opts *UnbanChatSenderChatOpts) (bool, error) { + return bot.UnbanChatSenderChatWithContext(context.Background(), chatId, senderChatId, opts) +} + +// UnbanChatSenderChatWithContext is the same as Bot.UnbanChatSenderChat, but with a context.Context parameter +func (bot *Bot) UnbanChatSenderChatWithContext(ctx context.Context, chatId int64, senderChatId int64, opts *UnbanChatSenderChatOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["sender_chat_id"] = strconv.FormatInt(senderChatId, 10) @@ -5740,7 +6512,7 @@ func (bot *Bot) UnbanChatSenderChat(chatId int64, senderChatId int64, opts *Unba reqOpts = opts.RequestOpts } - r, err := bot.Request("unbanChatSenderChat", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unbanChatSenderChat", v, nil, reqOpts) if err != nil { return false, err } @@ -5749,7 +6521,7 @@ func (bot *Bot) UnbanChatSenderChat(chatId int64, senderChatId int64, opts *Unba return b, json.Unmarshal(r, &b) } -// UnhideGeneralForumTopicOpts is the set of optional fields for Bot.UnhideGeneralForumTopic. +// UnhideGeneralForumTopicOpts is the set of optional fields for Bot.UnhideGeneralForumTopic and Bot.UnhideGeneralForumTopicWithContext. type UnhideGeneralForumTopicOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5761,6 +6533,11 @@ type UnhideGeneralForumTopicOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type UnhideGeneralForumTopicOpts): All optional parameters. func (bot *Bot) UnhideGeneralForumTopic(chatId int64, opts *UnhideGeneralForumTopicOpts) (bool, error) { + return bot.UnhideGeneralForumTopicWithContext(context.Background(), chatId, opts) +} + +// UnhideGeneralForumTopicWithContext is the same as Bot.UnhideGeneralForumTopic, but with a context.Context parameter +func (bot *Bot) UnhideGeneralForumTopicWithContext(ctx context.Context, chatId int64, opts *UnhideGeneralForumTopicOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -5769,7 +6546,7 @@ func (bot *Bot) UnhideGeneralForumTopic(chatId int64, opts *UnhideGeneralForumTo reqOpts = opts.RequestOpts } - r, err := bot.Request("unhideGeneralForumTopic", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unhideGeneralForumTopic", v, nil, reqOpts) if err != nil { return false, err } @@ -5778,7 +6555,7 @@ func (bot *Bot) UnhideGeneralForumTopic(chatId int64, opts *UnhideGeneralForumTo return b, json.Unmarshal(r, &b) } -// UnpinAllChatMessagesOpts is the set of optional fields for Bot.UnpinAllChatMessages. +// UnpinAllChatMessagesOpts is the set of optional fields for Bot.UnpinAllChatMessages and Bot.UnpinAllChatMessagesWithContext. type UnpinAllChatMessagesOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5790,6 +6567,11 @@ type UnpinAllChatMessagesOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type UnpinAllChatMessagesOpts): All optional parameters. func (bot *Bot) UnpinAllChatMessages(chatId int64, opts *UnpinAllChatMessagesOpts) (bool, error) { + return bot.UnpinAllChatMessagesWithContext(context.Background(), chatId, opts) +} + +// UnpinAllChatMessagesWithContext is the same as Bot.UnpinAllChatMessages, but with a context.Context parameter +func (bot *Bot) UnpinAllChatMessagesWithContext(ctx context.Context, chatId int64, opts *UnpinAllChatMessagesOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -5798,7 +6580,7 @@ func (bot *Bot) UnpinAllChatMessages(chatId int64, opts *UnpinAllChatMessagesOpt reqOpts = opts.RequestOpts } - r, err := bot.Request("unpinAllChatMessages", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unpinAllChatMessages", v, nil, reqOpts) if err != nil { return false, err } @@ -5807,7 +6589,7 @@ func (bot *Bot) UnpinAllChatMessages(chatId int64, opts *UnpinAllChatMessagesOpt return b, json.Unmarshal(r, &b) } -// UnpinAllForumTopicMessagesOpts is the set of optional fields for Bot.UnpinAllForumTopicMessages. +// UnpinAllForumTopicMessagesOpts is the set of optional fields for Bot.UnpinAllForumTopicMessages and Bot.UnpinAllForumTopicMessagesWithContext. type UnpinAllForumTopicMessagesOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5820,6 +6602,11 @@ type UnpinAllForumTopicMessagesOpts struct { // - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic // - opts (type UnpinAllForumTopicMessagesOpts): All optional parameters. func (bot *Bot) UnpinAllForumTopicMessages(chatId int64, messageThreadId int64, opts *UnpinAllForumTopicMessagesOpts) (bool, error) { + return bot.UnpinAllForumTopicMessagesWithContext(context.Background(), chatId, messageThreadId, opts) +} + +// UnpinAllForumTopicMessagesWithContext is the same as Bot.UnpinAllForumTopicMessages, but with a context.Context parameter +func (bot *Bot) UnpinAllForumTopicMessagesWithContext(ctx context.Context, chatId int64, messageThreadId int64, opts *UnpinAllForumTopicMessagesOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10) @@ -5829,7 +6616,7 @@ func (bot *Bot) UnpinAllForumTopicMessages(chatId int64, messageThreadId int64, reqOpts = opts.RequestOpts } - r, err := bot.Request("unpinAllForumTopicMessages", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unpinAllForumTopicMessages", v, nil, reqOpts) if err != nil { return false, err } @@ -5838,7 +6625,7 @@ func (bot *Bot) UnpinAllForumTopicMessages(chatId int64, messageThreadId int64, return b, json.Unmarshal(r, &b) } -// UnpinAllGeneralForumTopicMessagesOpts is the set of optional fields for Bot.UnpinAllGeneralForumTopicMessages. +// UnpinAllGeneralForumTopicMessagesOpts is the set of optional fields for Bot.UnpinAllGeneralForumTopicMessages and Bot.UnpinAllGeneralForumTopicMessagesWithContext. type UnpinAllGeneralForumTopicMessagesOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5850,6 +6637,11 @@ type UnpinAllGeneralForumTopicMessagesOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type UnpinAllGeneralForumTopicMessagesOpts): All optional parameters. func (bot *Bot) UnpinAllGeneralForumTopicMessages(chatId int64, opts *UnpinAllGeneralForumTopicMessagesOpts) (bool, error) { + return bot.UnpinAllGeneralForumTopicMessagesWithContext(context.Background(), chatId, opts) +} + +// UnpinAllGeneralForumTopicMessagesWithContext is the same as Bot.UnpinAllGeneralForumTopicMessages, but with a context.Context parameter +func (bot *Bot) UnpinAllGeneralForumTopicMessagesWithContext(ctx context.Context, chatId int64, opts *UnpinAllGeneralForumTopicMessagesOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) @@ -5858,7 +6650,7 @@ func (bot *Bot) UnpinAllGeneralForumTopicMessages(chatId int64, opts *UnpinAllGe reqOpts = opts.RequestOpts } - r, err := bot.Request("unpinAllGeneralForumTopicMessages", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unpinAllGeneralForumTopicMessages", v, nil, reqOpts) if err != nil { return false, err } @@ -5867,9 +6659,11 @@ func (bot *Bot) UnpinAllGeneralForumTopicMessages(chatId int64, opts *UnpinAllGe return b, json.Unmarshal(r, &b) } -// UnpinChatMessageOpts is the set of optional fields for Bot.UnpinChatMessage. +// UnpinChatMessageOpts is the set of optional fields for Bot.UnpinChatMessage and Bot.UnpinChatMessageWithContext. type UnpinChatMessageOpts struct { - // Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. + // Unique identifier of the business connection on behalf of which the message will be unpinned + BusinessConnectionId string + // Identifier of the message to unpin. Required if business_connection_id is specified. If not specified, the most recent pinned message (by sending date) will be unpinned. MessageId *int64 // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5881,9 +6675,15 @@ type UnpinChatMessageOpts struct { // - chatId (type int64): Unique identifier for the target chat // - opts (type UnpinChatMessageOpts): All optional parameters. func (bot *Bot) UnpinChatMessage(chatId int64, opts *UnpinChatMessageOpts) (bool, error) { + return bot.UnpinChatMessageWithContext(context.Background(), chatId, opts) +} + +// UnpinChatMessageWithContext is the same as Bot.UnpinChatMessage, but with a context.Context parameter +func (bot *Bot) UnpinChatMessageWithContext(ctx context.Context, chatId int64, opts *UnpinChatMessageOpts) (bool, error) { v := map[string]string{} v["chat_id"] = strconv.FormatInt(chatId, 10) if opts != nil { + v["business_connection_id"] = opts.BusinessConnectionId if opts.MessageId != nil { v["message_id"] = strconv.FormatInt(*opts.MessageId, 10) } @@ -5894,7 +6694,7 @@ func (bot *Bot) UnpinChatMessage(chatId int64, opts *UnpinChatMessageOpts) (bool reqOpts = opts.RequestOpts } - r, err := bot.Request("unpinChatMessage", v, nil, reqOpts) + r, err := bot.RequestWithContext(ctx, "unpinChatMessage", v, nil, reqOpts) if err != nil { return false, err } @@ -5903,7 +6703,7 @@ func (bot *Bot) UnpinChatMessage(chatId int64, opts *UnpinChatMessageOpts) (bool return b, json.Unmarshal(r, &b) } -// UploadStickerFileOpts is the set of optional fields for Bot.UploadStickerFile. +// UploadStickerFileOpts is the set of optional fields for Bot.UploadStickerFile and Bot.UploadStickerFileWithContext. type UploadStickerFileOpts struct { // RequestOpts are an additional optional field to configure timeouts for individual requests RequestOpts *RequestOpts @@ -5917,26 +6717,20 @@ type UploadStickerFileOpts struct { // - stickerFormat (type string): Format of the sticker, must be one of "static", "animated", "video" // - opts (type UploadStickerFileOpts): All optional parameters. func (bot *Bot) UploadStickerFile(userId int64, sticker InputFile, stickerFormat string, opts *UploadStickerFileOpts) (*File, error) { + return bot.UploadStickerFileWithContext(context.Background(), userId, sticker, stickerFormat, opts) +} + +// UploadStickerFileWithContext is the same as Bot.UploadStickerFile, but with a context.Context parameter +func (bot *Bot) UploadStickerFileWithContext(ctx context.Context, userId int64, sticker InputFile, stickerFormat string, opts *UploadStickerFileOpts) (*File, error) { v := map[string]string{} - data := map[string]NamedReader{} + data := map[string]FileReader{} v["user_id"] = strconv.FormatInt(userId, 10) if sticker != nil { - switch m := sticker.(type) { - case NamedReader: - v["sticker"] = "attach://sticker" - data["sticker"] = m - - case io.Reader: - v["sticker"] = "attach://sticker" - data["sticker"] = NamedFile{File: m} - - case []byte: - v["sticker"] = "attach://sticker" - data["sticker"] = NamedFile{File: bytes.NewReader(m)} - - default: - return nil, fmt.Errorf("unknown type for InputFile: %T", sticker) + err := sticker.Attach("sticker", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'sticker' input file: %w", err) } + v["sticker"] = sticker.getValue() } v["sticker_format"] = stickerFormat @@ -5945,7 +6739,7 @@ func (bot *Bot) UploadStickerFile(userId int64, sticker InputFile, stickerFormat reqOpts = opts.RequestOpts } - r, err := bot.Request("uploadStickerFile", v, data, reqOpts) + r, err := bot.RequestWithContext(ctx, "uploadStickerFile", v, data, reqOpts) if err != nil { return nil, err } diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_types.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_types.go index 098dd5870..70ea6c70a 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_types.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/gen_types.go @@ -6,7 +6,6 @@ package gotgbot import ( "encoding/json" "fmt" - "io" ) type ReplyMarkup interface { @@ -30,17 +29,17 @@ type Animation struct { FileId string `json:"file_id"` // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. FileUniqueId string `json:"file_unique_id"` - // Video width as defined by sender + // Video width as defined by the sender Width int64 `json:"width"` - // Video height as defined by sender + // Video height as defined by the sender Height int64 `json:"height"` - // Duration of the video in seconds as defined by sender + // Duration of the video in seconds as defined by the sender Duration int64 `json:"duration"` - // Optional. Animation thumbnail as defined by sender + // Optional. Animation thumbnail as defined by the sender Thumbnail *PhotoSize `json:"thumbnail,omitempty"` - // Optional. Original animation filename as defined by sender + // Optional. Original animation filename as defined by the sender FileName string `json:"file_name,omitempty"` - // Optional. MIME type of the file as defined by sender + // Optional. MIME type of the file as defined by the sender MimeType string `json:"mime_type,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. FileSize int64 `json:"file_size,omitempty"` @@ -54,15 +53,15 @@ type Audio struct { FileId string `json:"file_id"` // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. FileUniqueId string `json:"file_unique_id"` - // Duration of the audio in seconds as defined by sender + // Duration of the audio in seconds as defined by the sender Duration int64 `json:"duration"` - // Optional. Performer of the audio as defined by sender or by audio tags + // Optional. Performer of the audio as defined by the sender or by audio tags Performer string `json:"performer,omitempty"` - // Optional. Title of the audio as defined by sender or by audio tags + // Optional. Title of the audio as defined by the sender or by audio tags Title string `json:"title,omitempty"` - // Optional. Original filename as defined by sender + // Optional. Original filename as defined by the sender FileName string `json:"file_name,omitempty"` - // Optional. MIME type of the file as defined by sender + // Optional. MIME type of the file as defined by the sender MimeType string `json:"mime_type,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. FileSize int64 `json:"file_size,omitempty"` @@ -1337,6 +1336,8 @@ type MergedChatBoostSource struct { User *User `json:"user,omitempty"` // Optional. Identifier of a message in the chat with the giveaway; the message could have been deleted already. May be 0 if the message isn't sent yet. (Only for giveaway) GiveawayMessageId int64 `json:"giveaway_message_id,omitempty"` + // Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only (Only for giveaway) + PrizeStarCount int64 `json:"prize_star_count,omitempty"` // Optional. True, if the giveaway was completed, but there was no user to win the prize (Only for giveaway) IsUnclaimed bool `json:"is_unclaimed,omitempty"` } @@ -1462,12 +1463,14 @@ func (v ChatBoostSourceGiftCode) chatBoostSource() {} // ChatBoostSourceGiveaway (https://core.telegram.org/bots/api#chatboostsourcegiveaway) // -// The boost was obtained by the creation of a Telegram Premium giveaway. This boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription. +// The boost was obtained by the creation of a Telegram Premium or a Telegram Star giveaway. This boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription for Telegram Premium giveaways and prize_star_count / 500 times for one year for Telegram Star giveaways. type ChatBoostSourceGiveaway struct { // Identifier of a message in the chat with the giveaway; the message could have been deleted already. May be 0 if the message isn't sent yet. GiveawayMessageId int64 `json:"giveaway_message_id"` - // Optional. User that won the prize in the giveaway if any + // Optional. User that won the prize in the giveaway if any; for Telegram Premium giveaways only User *User `json:"user,omitempty"` + // Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only + PrizeStarCount int64 `json:"prize_star_count,omitempty"` // Optional. True, if the giveaway was completed, but there was no user to win the prize IsUnclaimed bool `json:"is_unclaimed,omitempty"` } @@ -1483,6 +1486,7 @@ func (v ChatBoostSourceGiveaway) MergeChatBoostSource() MergedChatBoostSource { Source: "giveaway", GiveawayMessageId: v.GiveawayMessageId, User: v.User, + PrizeStarCount: v.PrizeStarCount, IsUnclaimed: v.IsUnclaimed, } } @@ -1616,6 +1620,8 @@ type ChatFullInfo struct { PinnedMessage *Message `json:"pinned_message,omitempty"` // Optional. Default chat member permissions, for groups and supergroups Permissions *ChatPermissions `json:"permissions,omitempty"` + // Optional. True, if paid media messages can be sent or forwarded to the channel chat. The field is available only for channel chats. + CanSendPaidMedia bool `json:"can_send_paid_media,omitempty"` // Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unprivileged user; in seconds SlowModeDelay int64 `json:"slow_mode_delay,omitempty"` // Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions @@ -1677,6 +1683,7 @@ func (v *ChatFullInfo) UnmarshalJSON(b []byte) error { InviteLink string `json:"invite_link"` PinnedMessage *Message `json:"pinned_message"` Permissions *ChatPermissions `json:"permissions"` + CanSendPaidMedia bool `json:"can_send_paid_media"` SlowModeDelay int64 `json:"slow_mode_delay"` UnrestrictBoostCount int64 `json:"unrestrict_boost_count"` MessageAutoDeleteTime int64 `json:"message_auto_delete_time"` @@ -1730,6 +1737,7 @@ func (v *ChatFullInfo) UnmarshalJSON(b []byte) error { v.InviteLink = t.InviteLink v.PinnedMessage = t.PinnedMessage v.Permissions = t.Permissions + v.CanSendPaidMedia = t.CanSendPaidMedia v.SlowModeDelay = t.SlowModeDelay v.UnrestrictBoostCount = t.UnrestrictBoostCount v.MessageAutoDeleteTime = t.MessageAutoDeleteTime @@ -1768,6 +1776,10 @@ type ChatInviteLink struct { MemberLimit int64 `json:"member_limit,omitempty"` // Optional. Number of pending join requests created using this link PendingJoinRequestCount int64 `json:"pending_join_request_count,omitempty"` + // Optional. The number of seconds the subscription will be active for before the next payment + SubscriptionPeriod int64 `json:"subscription_period,omitempty"` + // Optional. The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat using the link + SubscriptionPrice int64 `json:"subscription_price,omitempty"` } // ChatJoinRequest (https://core.telegram.org/bots/api#chatjoinrequest) @@ -1866,6 +1878,8 @@ type MergedChatMember struct { CanPinMessages bool `json:"can_pin_messages,omitempty"` // Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only (Only for administrator, restricted) CanManageTopics bool `json:"can_manage_topics,omitempty"` + // Optional. Date when the user's subscription will expire; Unix time (Only for member, restricted, kicked) + UntilDate int64 `json:"until_date,omitempty"` // Optional. True, if the user is a member of the chat at the moment of the request (Only for restricted) IsMember bool `json:"is_member,omitempty"` // Optional. True, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues (Only for restricted) @@ -1888,8 +1902,6 @@ type MergedChatMember struct { CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // Optional. True, if the user is allowed to add web page previews to their messages (Only for restricted) CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` - // Optional. Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted forever (Only for restricted, kicked) - UntilDate int64 `json:"until_date,omitempty"` } // GetStatus is a helper method to easily access the common fields of an interface. @@ -2189,6 +2201,8 @@ func (v ChatMemberLeft) chatMember() {} type ChatMemberMember struct { // Information about the user User User `json:"user"` + // Optional. Date when the user's subscription will expire; Unix time + UntilDate int64 `json:"until_date,omitempty"` } // GetStatus is a helper method to easily access the common fields of an interface. @@ -2204,8 +2218,9 @@ func (v ChatMemberMember) GetUser() User { // MergeChatMember returns a MergedChatMember struct to simplify working with types in a non-generic world. func (v ChatMemberMember) MergeChatMember() MergedChatMember { return MergedChatMember{ - Status: "member", - User: v.User, + Status: "member", + User: v.User, + UntilDate: v.UntilDate, } } @@ -2519,6 +2534,14 @@ type Contact struct { Vcard string `json:"vcard,omitempty"` } +// CopyTextButton (https://core.telegram.org/bots/api#copytextbutton) +// +// This object represents an inline keyboard button that copies specified text to the clipboard. +type CopyTextButton struct { + // The text to be copied to the clipboard; 1-256 characters + Text string `json:"text"` +} + // Dice (https://core.telegram.org/bots/api#dice) // // This object represents an animated emoji that displays a random value. @@ -2537,11 +2560,11 @@ type Document struct { FileId string `json:"file_id"` // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. FileUniqueId string `json:"file_unique_id"` - // Optional. Document thumbnail as defined by sender + // Optional. Document thumbnail as defined by the sender Thumbnail *PhotoSize `json:"thumbnail,omitempty"` - // Optional. Original filename as defined by sender + // Optional. Original filename as defined by the sender FileName string `json:"file_name,omitempty"` - // Optional. MIME type of the file as defined by sender + // Optional. MIME type of the file as defined by the sender MimeType string `json:"mime_type,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. FileSize int64 `json:"file_size,omitempty"` @@ -2603,6 +2626,8 @@ type ExternalReplyInfo struct { Audio *Audio `json:"audio,omitempty"` // Optional. Message is a general file, information about the file Document *Document `json:"document,omitempty"` + // Optional. Message contains paid media; information about the paid media + PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"` // Optional. Message is a photo, available sizes of the photo Photo []PhotoSize `json:"photo,omitempty"` // Optional. Message is a sticker, information about the sticker @@ -2648,6 +2673,7 @@ func (v *ExternalReplyInfo) UnmarshalJSON(b []byte) error { Animation *Animation `json:"animation"` Audio *Audio `json:"audio"` Document *Document `json:"document"` + PaidMedia *PaidMediaInfo `json:"paid_media"` Photo []PhotoSize `json:"photo"` Sticker *Sticker `json:"sticker"` Story *Story `json:"story"` @@ -2681,6 +2707,7 @@ func (v *ExternalReplyInfo) UnmarshalJSON(b []byte) error { v.Animation = t.Animation v.Audio = t.Audio v.Document = t.Document + v.PaidMedia = t.PaidMedia v.Photo = t.Photo v.Sticker = t.Sticker v.Story = t.Story @@ -2834,7 +2861,9 @@ type Giveaway struct { PrizeDescription string `json:"prize_description,omitempty"` // Optional. A list of two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which eligible users for the giveaway must come. If empty, then all users can participate in the giveaway. Users with a phone number that was bought on Fragment can always participate in giveaways. CountryCodes []string `json:"country_codes,omitempty"` - // Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + // Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only + PrizeStarCount int64 `json:"prize_star_count,omitempty"` + // Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for; for Telegram Premium giveaways only PremiumSubscriptionMonthCount int64 `json:"premium_subscription_month_count,omitempty"` } @@ -2848,12 +2877,17 @@ type GiveawayCompleted struct { UnclaimedPrizeCount int64 `json:"unclaimed_prize_count,omitempty"` // Optional. Message with the giveaway that was completed, if it wasn't deleted GiveawayMessage *Message `json:"giveaway_message,omitempty"` + // Optional. True, if the giveaway is a Telegram Star giveaway. Otherwise, currently, the giveaway is a Telegram Premium giveaway. + IsStarGiveaway bool `json:"is_star_giveaway,omitempty"` } // GiveawayCreated (https://core.telegram.org/bots/api#giveawaycreated) // -// This object represents a service message about the creation of a scheduled giveaway. Currently holds no information. -type GiveawayCreated struct{} +// This object represents a service message about the creation of a scheduled giveaway. +type GiveawayCreated struct { + // Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only + PrizeStarCount int64 `json:"prize_star_count,omitempty"` +} // GiveawayWinners (https://core.telegram.org/bots/api#giveawaywinners) // @@ -2871,7 +2905,9 @@ type GiveawayWinners struct { Winners []User `json:"winners,omitempty"` // Optional. The number of other chats the user had to join in order to be eligible for the giveaway AdditionalChatCount int64 `json:"additional_chat_count,omitempty"` - // Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + // Optional. The number of Telegram Stars that were split between giveaway winners; for Telegram Star giveaways only + PrizeStarCount int64 `json:"prize_star_count,omitempty"` + // Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for; for Telegram Premium giveaways only PremiumSubscriptionMonthCount int64 `json:"premium_subscription_month_count,omitempty"` // Optional. Number of undistributed prizes UnclaimedPrizeCount int64 `json:"unclaimed_prize_count,omitempty"` @@ -2915,13 +2951,13 @@ func (v InaccessibleMessage) maybeInaccessibleMessage() {} // InlineKeyboardButton (https://core.telegram.org/bots/api#inlinekeyboardbutton) // -// This object represents one button of an inline keyboard. You must use exactly one of the optional fields. +// This object represents one button of an inline keyboard. Exactly one of the optional fields must be used to specify type of the button. type InlineKeyboardButton struct { // Label text on the button Text string `json:"text"` // Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id= can be used to mention a user by their identifier without using a username, if this is allowed by their privacy settings. Url string `json:"url,omitempty"` - // Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes. Not supported for messages sent on behalf of a Telegram Business account. + // Optional. Data to be sent in a callback query to the bot when the button is pressed, 1-64 bytes CallbackData string `json:"callback_data,omitempty"` // Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot. Not supported for messages sent on behalf of a Telegram Business account. WebApp *WebAppInfo `json:"web_app,omitempty"` @@ -2933,9 +2969,11 @@ type InlineKeyboardButton struct { SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field. Not supported for messages sent on behalf of a Telegram Business account. SwitchInlineQueryChosenChat *SwitchInlineQueryChosenChat `json:"switch_inline_query_chosen_chat,omitempty"` + // Optional. Description of the button that copies the specified text to the clipboard. + CopyText *CopyTextButton `json:"copy_text,omitempty"` // Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row. CallbackGame *CallbackGame `json:"callback_game,omitempty"` - // Optional. Specify True, to send a Pay button. NOTE: This type of button must always be the first button in the first row and can only be used in invoice messages. + // Optional. Specify True, to send a Pay button. Substrings "⭐" and "XTR" in the buttons's text will be replaced with a Telegram Star icon. NOTE: This type of button must always be the first button in the first row and can only be used in invoice messages. Pay bool `json:"pay,omitempty"` } @@ -3052,6 +3090,8 @@ type MergedInlineQueryResult struct { Description string `json:"description,omitempty"` // Optional. A valid file identifier for the GIF file (Only for gif) GifFileId string `json:"gif_file_id,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media (Only for gif, mpeg4_gif, photo, video, gif, mpeg4_gif, photo, video) + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. A valid file identifier for the MPEG4 file (Only for mpeg4_gif) Mpeg4FileId string `json:"mpeg4_file_id,omitempty"` // Optional. A valid file identifier of the photo (Only for photo) @@ -3450,6 +3490,8 @@ type InlineQueryResultCachedGif struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the GIF animation @@ -3469,15 +3511,16 @@ func (v InlineQueryResultCachedGif) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultCachedGif) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "gif", - Id: v.Id, - GifFileId: v.GifFileId, - Title: v.Title, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "gif", + Id: v.Id, + GifFileId: v.GifFileId, + Title: v.Title, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -3513,6 +3556,8 @@ type InlineQueryResultCachedMpeg4Gif struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the video animation @@ -3532,15 +3577,16 @@ func (v InlineQueryResultCachedMpeg4Gif) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultCachedMpeg4Gif) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "mpeg4_gif", - Id: v.Id, - Mpeg4FileId: v.Mpeg4FileId, - Title: v.Title, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "mpeg4_gif", + Id: v.Id, + Mpeg4FileId: v.Mpeg4FileId, + Title: v.Title, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -3578,6 +3624,8 @@ type InlineQueryResultCachedPhoto struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the photo @@ -3597,16 +3645,17 @@ func (v InlineQueryResultCachedPhoto) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultCachedPhoto) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "photo", - Id: v.Id, - PhotoFileId: v.PhotoFileId, - Title: v.Title, - Description: v.Description, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "photo", + Id: v.Id, + PhotoFileId: v.PhotoFileId, + Title: v.Title, + Description: v.Description, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -3695,6 +3744,8 @@ type InlineQueryResultCachedVideo struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the video @@ -3714,16 +3765,17 @@ func (v InlineQueryResultCachedVideo) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultCachedVideo) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "video", - Id: v.Id, - VideoFileId: v.VideoFileId, - Title: v.Title, - Description: v.Description, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "video", + Id: v.Id, + VideoFileId: v.VideoFileId, + Title: v.Title, + Description: v.Description, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -4027,6 +4079,8 @@ type InlineQueryResultGif struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the GIF animation @@ -4046,20 +4100,21 @@ func (v InlineQueryResultGif) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultGif) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "gif", - Id: v.Id, - GifUrl: v.GifUrl, - GifWidth: v.GifWidth, - GifHeight: v.GifHeight, - GifDuration: v.GifDuration, - ThumbnailUrl: v.ThumbnailUrl, - ThumbnailMimeType: v.ThumbnailMimeType, - Title: v.Title, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "gif", + Id: v.Id, + GifUrl: v.GifUrl, + GifWidth: v.GifWidth, + GifHeight: v.GifHeight, + GifDuration: v.GifDuration, + ThumbnailUrl: v.ThumbnailUrl, + ThumbnailMimeType: v.ThumbnailMimeType, + Title: v.Title, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -4183,6 +4238,8 @@ type InlineQueryResultMpeg4Gif struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the video animation @@ -4202,20 +4259,21 @@ func (v InlineQueryResultMpeg4Gif) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultMpeg4Gif) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "mpeg4_gif", - Id: v.Id, - Mpeg4Url: v.Mpeg4Url, - Mpeg4Width: v.Mpeg4Width, - Mpeg4Height: v.Mpeg4Height, - Mpeg4Duration: v.Mpeg4Duration, - ThumbnailUrl: v.ThumbnailUrl, - ThumbnailMimeType: v.ThumbnailMimeType, - Title: v.Title, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "mpeg4_gif", + Id: v.Id, + Mpeg4Url: v.Mpeg4Url, + Mpeg4Width: v.Mpeg4Width, + Mpeg4Height: v.Mpeg4Height, + Mpeg4Duration: v.Mpeg4Duration, + ThumbnailUrl: v.ThumbnailUrl, + ThumbnailMimeType: v.ThumbnailMimeType, + Title: v.Title, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -4259,6 +4317,8 @@ type InlineQueryResultPhoto struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Inline keyboard attached to the message ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Content of the message to be sent instead of the photo @@ -4278,19 +4338,20 @@ func (v InlineQueryResultPhoto) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultPhoto) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "photo", - Id: v.Id, - PhotoUrl: v.PhotoUrl, - ThumbnailUrl: v.ThumbnailUrl, - PhotoWidth: v.PhotoWidth, - PhotoHeight: v.PhotoHeight, - Title: v.Title, - Description: v.Description, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "photo", + Id: v.Id, + PhotoUrl: v.PhotoUrl, + ThumbnailUrl: v.ThumbnailUrl, + PhotoWidth: v.PhotoWidth, + PhotoHeight: v.PhotoHeight, + Title: v.Title, + Description: v.Description, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -4411,6 +4472,8 @@ type InlineQueryResultVideo struct { ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Video width VideoWidth int64 `json:"video_width,omitempty"` // Optional. Video height @@ -4438,21 +4501,22 @@ func (v InlineQueryResultVideo) GetId() string { // MergeInlineQueryResult returns a MergedInlineQueryResult struct to simplify working with types in a non-generic world. func (v InlineQueryResultVideo) MergeInlineQueryResult() MergedInlineQueryResult { return MergedInlineQueryResult{ - Type: "video", - Id: v.Id, - VideoUrl: v.VideoUrl, - MimeType: v.MimeType, - ThumbnailUrl: v.ThumbnailUrl, - Title: v.Title, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - VideoWidth: v.VideoWidth, - VideoHeight: v.VideoHeight, - VideoDuration: v.VideoDuration, - Description: v.Description, - ReplyMarkup: v.ReplyMarkup, - InputMessageContent: v.InputMessageContent, + Type: "video", + Id: v.Id, + VideoUrl: v.VideoUrl, + MimeType: v.MimeType, + ThumbnailUrl: v.ThumbnailUrl, + Title: v.Title, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + VideoWidth: v.VideoWidth, + VideoHeight: v.VideoHeight, + VideoDuration: v.VideoDuration, + Description: v.Description, + ReplyMarkup: v.ReplyMarkup, + InputMessageContent: v.InputMessageContent, } } @@ -4570,8 +4634,6 @@ func (v InputContactMessageContent) inputMessageContent() {} // InputFile (https://core.telegram.org/bots/api#inputfile) // // This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser. -type InputFile interface{} - // InputInvoiceMessageContent (https://core.telegram.org/bots/api#inputinvoicemessagecontent) // // Represents the content of an invoice message to be sent as the result of an inline query. @@ -4580,15 +4642,15 @@ type InputInvoiceMessageContent struct { Title string `json:"title"` // Product description, 1-255 characters Description string `json:"description"` - // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. Payload string `json:"payload"` - // Payment provider token, obtained via @BotFather - ProviderToken string `json:"provider_token"` - // Three-letter ISO 4217 currency code, see more on currencies + // Optional. Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. + ProviderToken string `json:"provider_token,omitempty"` + // Three-letter ISO 4217 currency code, see more on currencies. Pass "XTR" for payments in Telegram Stars. Currency string `json:"currency"` - // Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + // Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars. Prices []LabeledPrice `json:"prices,omitempty"` - // Optional. 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 + // Optional. 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 `json:"max_tip_amount,omitempty"` // Optional. A JSON-serialized array of suggested amounts of tip 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. SuggestedTipAmounts []int64 `json:"suggested_tip_amounts,omitempty"` @@ -4602,19 +4664,19 @@ type InputInvoiceMessageContent struct { PhotoWidth int64 `json:"photo_width,omitempty"` // Optional. Photo height PhotoHeight int64 `json:"photo_height,omitempty"` - // Optional. Pass True if you require the user's full name to complete the order + // Optional. Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars. NeedName bool `json:"need_name,omitempty"` - // Optional. Pass True if you require the user's phone number to complete the order + // Optional. Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars. NeedPhoneNumber bool `json:"need_phone_number,omitempty"` - // Optional. Pass True if you require the user's email address to complete the order + // Optional. Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars. NeedEmail bool `json:"need_email,omitempty"` - // Optional. Pass True if you require the user's shipping address to complete the order + // Optional. Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars. NeedShippingAddress bool `json:"need_shipping_address,omitempty"` - // Optional. Pass True if the user's phone number should be sent to provider + // Optional. Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars. SendPhoneNumberToProvider bool `json:"send_phone_number_to_provider,omitempty"` - // Optional. Pass True if the user's email address should be sent to provider + // Optional. Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars. SendEmailToProvider bool `json:"send_email_to_provider,omitempty"` - // Optional. Pass True if the final price depends on the shipping method + // Optional. Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars. IsFlexible bool `json:"is_flexible,omitempty"` } @@ -4652,9 +4714,9 @@ func (v InputLocationMessageContent) inputMessageContent() {} // - InputMediaVideo type InputMedia interface { GetType() string - GetMedia() InputFile + GetMedia() InputFileOrString // InputParams allows for uploading attachments with files. - InputParams(string, map[string]NamedReader) ([]byte, error) + InputParams(string, map[string]FileReader) ([]byte, error) // MergeInputMedia returns a MergedInputMedia struct to simplify working with complex telegram types in a non-generic world. MergeInputMedia() MergedInputMedia // inputMedia exists to avoid external types implementing this interface. @@ -4675,15 +4737,17 @@ type MergedInputMedia struct { // Type of the result Type string `json:"type"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Media InputFile `json:"media"` + Media InputFileOrString `json:"media"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files (Only for animation, document, audio, video) - Thumbnail *InputFile `json:"thumbnail,omitempty"` + Thumbnail InputFile `json:"thumbnail,omitempty"` // Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing Caption string `json:"caption,omitempty"` // Optional. Mode for parsing entities in the animation caption. See formatting options for more details. ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media (Only for animation, photo, video) + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Animation width (Only for animation, video) Width int64 `json:"width,omitempty"` // Optional. Animation height (Only for animation, video) @@ -4708,7 +4772,7 @@ func (v MergedInputMedia) GetType() string { } // GetMedia is a helper method to easily access the common fields of an interface. -func (v MergedInputMedia) GetMedia() InputFile { +func (v MergedInputMedia) GetMedia() InputFileOrString { return v.Media } @@ -4725,15 +4789,17 @@ func (v MergedInputMedia) MergeInputMedia() MergedInputMedia { // Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. type InputMediaAnimation struct { // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Media InputFile `json:"media"` + Media InputFileOrString `json:"media"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Thumbnail *InputFile `json:"thumbnail,omitempty"` + Thumbnail InputFile `json:"thumbnail,omitempty"` // Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing Caption string `json:"caption,omitempty"` // Optional. Mode for parsing entities in the animation caption. See formatting options for more details. ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Animation width Width int64 `json:"width,omitempty"` // Optional. Animation height @@ -4750,23 +4816,24 @@ func (v InputMediaAnimation) GetType() string { } // GetMedia is a helper method to easily access the common fields of an interface. -func (v InputMediaAnimation) GetMedia() InputFile { +func (v InputMediaAnimation) GetMedia() InputFileOrString { return v.Media } // MergeInputMedia returns a MergedInputMedia struct to simplify working with types in a non-generic world. func (v InputMediaAnimation) MergeInputMedia() MergedInputMedia { return MergedInputMedia{ - Type: "animation", - Media: v.Media, - Thumbnail: v.Thumbnail, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - Width: v.Width, - Height: v.Height, - Duration: v.Duration, - HasSpoiler: v.HasSpoiler, + Type: "animation", + Media: v.Media, + Thumbnail: v.Thumbnail, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + Width: v.Width, + Height: v.Height, + Duration: v.Duration, + HasSpoiler: v.HasSpoiler, } } @@ -4786,22 +4853,18 @@ func (v InputMediaAnimation) MarshalJSON() ([]byte, error) { // InputMediaAnimation.inputMedia is a dummy method to avoid interface implementation. func (v InputMediaAnimation) inputMedia() {} -func (v InputMediaAnimation) InputParams(mediaName string, data map[string]NamedReader) ([]byte, error) { +func (v InputMediaAnimation) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { if v.Media != nil { - switch m := v.Media.(type) { - case string: - // ok, noop - - case NamedReader: - v.Media = "attach://" + mediaName - data[mediaName] = m - - case io.Reader: - v.Media = "attach://" + mediaName - data[mediaName] = NamedFile{File: m} + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) + } + } - default: - return nil, fmt.Errorf("unknown type: %T", v.Media) + if v.Thumbnail != nil { + err := v.Thumbnail.Attach(mediaName+"-thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file for %s: %w", mediaName, err) } } @@ -4813,9 +4876,9 @@ func (v InputMediaAnimation) InputParams(mediaName string, data map[string]Named // Represents an audio file to be treated as music to be sent. type InputMediaAudio struct { // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Media InputFile `json:"media"` + Media InputFileOrString `json:"media"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Thumbnail *InputFile `json:"thumbnail,omitempty"` + Thumbnail InputFile `json:"thumbnail,omitempty"` // Optional. Caption of the audio to be sent, 0-1024 characters after entities parsing Caption string `json:"caption,omitempty"` // Optional. Mode for parsing entities in the audio caption. See formatting options for more details. @@ -4836,7 +4899,7 @@ func (v InputMediaAudio) GetType() string { } // GetMedia is a helper method to easily access the common fields of an interface. -func (v InputMediaAudio) GetMedia() InputFile { +func (v InputMediaAudio) GetMedia() InputFileOrString { return v.Media } @@ -4871,22 +4934,18 @@ func (v InputMediaAudio) MarshalJSON() ([]byte, error) { // InputMediaAudio.inputMedia is a dummy method to avoid interface implementation. func (v InputMediaAudio) inputMedia() {} -func (v InputMediaAudio) InputParams(mediaName string, data map[string]NamedReader) ([]byte, error) { +func (v InputMediaAudio) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { if v.Media != nil { - switch m := v.Media.(type) { - case string: - // ok, noop - - case NamedReader: - v.Media = "attach://" + mediaName - data[mediaName] = m - - case io.Reader: - v.Media = "attach://" + mediaName - data[mediaName] = NamedFile{File: m} + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) + } + } - default: - return nil, fmt.Errorf("unknown type: %T", v.Media) + if v.Thumbnail != nil { + err := v.Thumbnail.Attach(mediaName+"-thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file for %s: %w", mediaName, err) } } @@ -4898,9 +4957,9 @@ func (v InputMediaAudio) InputParams(mediaName string, data map[string]NamedRead // Represents a general file to be sent. type InputMediaDocument struct { // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Media InputFile `json:"media"` + Media InputFileOrString `json:"media"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Thumbnail *InputFile `json:"thumbnail,omitempty"` + Thumbnail InputFile `json:"thumbnail,omitempty"` // Optional. Caption of the document to be sent, 0-1024 characters after entities parsing Caption string `json:"caption,omitempty"` // Optional. Mode for parsing entities in the document caption. See formatting options for more details. @@ -4917,7 +4976,7 @@ func (v InputMediaDocument) GetType() string { } // GetMedia is a helper method to easily access the common fields of an interface. -func (v InputMediaDocument) GetMedia() InputFile { +func (v InputMediaDocument) GetMedia() InputFileOrString { return v.Media } @@ -4950,22 +5009,18 @@ func (v InputMediaDocument) MarshalJSON() ([]byte, error) { // InputMediaDocument.inputMedia is a dummy method to avoid interface implementation. func (v InputMediaDocument) inputMedia() {} -func (v InputMediaDocument) InputParams(mediaName string, data map[string]NamedReader) ([]byte, error) { +func (v InputMediaDocument) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { if v.Media != nil { - switch m := v.Media.(type) { - case string: - // ok, noop - - case NamedReader: - v.Media = "attach://" + mediaName - data[mediaName] = m - - case io.Reader: - v.Media = "attach://" + mediaName - data[mediaName] = NamedFile{File: m} + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) + } + } - default: - return nil, fmt.Errorf("unknown type: %T", v.Media) + if v.Thumbnail != nil { + err := v.Thumbnail.Attach(mediaName+"-thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file for %s: %w", mediaName, err) } } @@ -4977,13 +5032,15 @@ func (v InputMediaDocument) InputParams(mediaName string, data map[string]NamedR // Represents a photo to be sent. type InputMediaPhoto struct { // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Media InputFile `json:"media"` + Media InputFileOrString `json:"media"` // Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing Caption string `json:"caption,omitempty"` // Optional. Mode for parsing entities in the photo caption. See formatting options for more details. ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True if the photo needs to be covered with a spoiler animation HasSpoiler bool `json:"has_spoiler,omitempty"` } @@ -4994,19 +5051,20 @@ func (v InputMediaPhoto) GetType() string { } // GetMedia is a helper method to easily access the common fields of an interface. -func (v InputMediaPhoto) GetMedia() InputFile { +func (v InputMediaPhoto) GetMedia() InputFileOrString { return v.Media } // MergeInputMedia returns a MergedInputMedia struct to simplify working with types in a non-generic world. func (v InputMediaPhoto) MergeInputMedia() MergedInputMedia { return MergedInputMedia{ - Type: "photo", - Media: v.Media, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - HasSpoiler: v.HasSpoiler, + Type: "photo", + Media: v.Media, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + HasSpoiler: v.HasSpoiler, } } @@ -5026,22 +5084,11 @@ func (v InputMediaPhoto) MarshalJSON() ([]byte, error) { // InputMediaPhoto.inputMedia is a dummy method to avoid interface implementation. func (v InputMediaPhoto) inputMedia() {} -func (v InputMediaPhoto) InputParams(mediaName string, data map[string]NamedReader) ([]byte, error) { +func (v InputMediaPhoto) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { if v.Media != nil { - switch m := v.Media.(type) { - case string: - // ok, noop - - case NamedReader: - v.Media = "attach://" + mediaName - data[mediaName] = m - - case io.Reader: - v.Media = "attach://" + mediaName - data[mediaName] = NamedFile{File: m} - - default: - return nil, fmt.Errorf("unknown type: %T", v.Media) + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) } } @@ -5053,15 +5100,17 @@ func (v InputMediaPhoto) InputParams(mediaName string, data map[string]NamedRead // Represents a video to be sent. type InputMediaVideo struct { // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Media InputFile `json:"media"` + Media InputFileOrString `json:"media"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Thumbnail *InputFile `json:"thumbnail,omitempty"` + Thumbnail InputFile `json:"thumbnail,omitempty"` // Optional. Caption of the video to be sent, 0-1024 characters after entities parsing Caption string `json:"caption,omitempty"` // Optional. Mode for parsing entities in the video caption. See formatting options for more details. ParseMode string `json:"parse_mode,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. Pass True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Video width Width int64 `json:"width,omitempty"` // Optional. Video height @@ -5080,24 +5129,25 @@ func (v InputMediaVideo) GetType() string { } // GetMedia is a helper method to easily access the common fields of an interface. -func (v InputMediaVideo) GetMedia() InputFile { +func (v InputMediaVideo) GetMedia() InputFileOrString { return v.Media } // MergeInputMedia returns a MergedInputMedia struct to simplify working with types in a non-generic world. func (v InputMediaVideo) MergeInputMedia() MergedInputMedia { return MergedInputMedia{ - Type: "video", - Media: v.Media, - Thumbnail: v.Thumbnail, - Caption: v.Caption, - ParseMode: v.ParseMode, - CaptionEntities: v.CaptionEntities, - Width: v.Width, - Height: v.Height, - Duration: v.Duration, - SupportsStreaming: v.SupportsStreaming, - HasSpoiler: v.HasSpoiler, + Type: "video", + Media: v.Media, + Thumbnail: v.Thumbnail, + Caption: v.Caption, + ParseMode: v.ParseMode, + CaptionEntities: v.CaptionEntities, + ShowCaptionAboveMedia: v.ShowCaptionAboveMedia, + Width: v.Width, + Height: v.Height, + Duration: v.Duration, + SupportsStreaming: v.SupportsStreaming, + HasSpoiler: v.HasSpoiler, } } @@ -5117,22 +5167,18 @@ func (v InputMediaVideo) MarshalJSON() ([]byte, error) { // InputMediaVideo.inputMedia is a dummy method to avoid interface implementation. func (v InputMediaVideo) inputMedia() {} -func (v InputMediaVideo) InputParams(mediaName string, data map[string]NamedReader) ([]byte, error) { +func (v InputMediaVideo) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { if v.Media != nil { - switch m := v.Media.(type) { - case string: - // ok, noop - - case NamedReader: - v.Media = "attach://" + mediaName - data[mediaName] = m - - case io.Reader: - v.Media = "attach://" + mediaName - data[mediaName] = NamedFile{File: m} + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) + } + } - default: - return nil, fmt.Errorf("unknown type: %T", v.Media) + if v.Thumbnail != nil { + err := v.Thumbnail.Attach(mediaName+"-thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file for %s: %w", mediaName, err) } } @@ -5161,9 +5207,195 @@ var ( _ InputMessageContent = InputInvoiceMessageContent{} ) +// InputPaidMedia (https://core.telegram.org/bots/api#inputpaidmedia) +// +// This object describes the paid media to be sent. Currently, it can be one of +// - InputPaidMediaPhoto +// - InputPaidMediaVideo +type InputPaidMedia interface { + GetType() string + GetMedia() InputFileOrString + // InputParams allows for uploading attachments with files. + InputParams(string, map[string]FileReader) ([]byte, error) + // MergeInputPaidMedia returns a MergedInputPaidMedia struct to simplify working with complex telegram types in a non-generic world. + MergeInputPaidMedia() MergedInputPaidMedia + // inputPaidMedia exists to avoid external types implementing this interface. + inputPaidMedia() +} + +// Ensure that all subtypes correctly implement the parent interface. +var ( + _ InputPaidMedia = InputPaidMediaPhoto{} + _ InputPaidMedia = InputPaidMediaVideo{} +) + +// MergedInputPaidMedia is a helper type to simplify interactions with the various InputPaidMedia subtypes. +type MergedInputPaidMedia struct { + // Type of the media + Type string `json:"type"` + // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files + Media InputFileOrString `json:"media"` + // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files (Only for video) + Thumbnail InputFile `json:"thumbnail,omitempty"` + // Optional. Video width (Only for video) + Width int64 `json:"width,omitempty"` + // Optional. Video height (Only for video) + Height int64 `json:"height,omitempty"` + // Optional. Video duration in seconds (Only for video) + Duration int64 `json:"duration,omitempty"` + // Optional. Pass True if the uploaded video is suitable for streaming (Only for video) + SupportsStreaming bool `json:"supports_streaming,omitempty"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v MergedInputPaidMedia) GetType() string { + return v.Type +} + +// GetMedia is a helper method to easily access the common fields of an interface. +func (v MergedInputPaidMedia) GetMedia() InputFileOrString { + return v.Media +} + +// MergedInputPaidMedia.inputPaidMedia is a dummy method to avoid interface implementation. +func (v MergedInputPaidMedia) inputPaidMedia() {} + +// MergeInputPaidMedia returns a MergedInputPaidMedia struct to simplify working with types in a non-generic world. +func (v MergedInputPaidMedia) MergeInputPaidMedia() MergedInputPaidMedia { + return v +} + +// InputPaidMediaPhoto (https://core.telegram.org/bots/api#inputpaidmediaphoto) +// +// The paid media to send is a photo. +type InputPaidMediaPhoto struct { + // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files + Media InputFileOrString `json:"media"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v InputPaidMediaPhoto) GetType() string { + return "photo" +} + +// GetMedia is a helper method to easily access the common fields of an interface. +func (v InputPaidMediaPhoto) GetMedia() InputFileOrString { + return v.Media +} + +// MergeInputPaidMedia returns a MergedInputPaidMedia struct to simplify working with types in a non-generic world. +func (v InputPaidMediaPhoto) MergeInputPaidMedia() MergedInputPaidMedia { + return MergedInputPaidMedia{ + Type: "photo", + Media: v.Media, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v InputPaidMediaPhoto) MarshalJSON() ([]byte, error) { + type alias InputPaidMediaPhoto + a := struct { + Type string `json:"type"` + alias + }{ + Type: "photo", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// InputPaidMediaPhoto.inputPaidMedia is a dummy method to avoid interface implementation. +func (v InputPaidMediaPhoto) inputPaidMedia() {} + +func (v InputPaidMediaPhoto) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { + if v.Media != nil { + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) + } + } + + return json.Marshal(v) +} + +// InputPaidMediaVideo (https://core.telegram.org/bots/api#inputpaidmediavideo) +// +// The paid media to send is a video. +type InputPaidMediaVideo struct { + // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. More information on Sending Files: https://core.telegram.org/bots/api#sending-files + Media InputFileOrString `json:"media"` + // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass "attach://" if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files: https://core.telegram.org/bots/api#sending-files + Thumbnail InputFile `json:"thumbnail,omitempty"` + // Optional. Video width + Width int64 `json:"width,omitempty"` + // Optional. Video height + Height int64 `json:"height,omitempty"` + // Optional. Video duration in seconds + Duration int64 `json:"duration,omitempty"` + // Optional. Pass True if the uploaded video is suitable for streaming + SupportsStreaming bool `json:"supports_streaming,omitempty"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v InputPaidMediaVideo) GetType() string { + return "video" +} + +// GetMedia is a helper method to easily access the common fields of an interface. +func (v InputPaidMediaVideo) GetMedia() InputFileOrString { + return v.Media +} + +// MergeInputPaidMedia returns a MergedInputPaidMedia struct to simplify working with types in a non-generic world. +func (v InputPaidMediaVideo) MergeInputPaidMedia() MergedInputPaidMedia { + return MergedInputPaidMedia{ + Type: "video", + Media: v.Media, + Thumbnail: v.Thumbnail, + Width: v.Width, + Height: v.Height, + Duration: v.Duration, + SupportsStreaming: v.SupportsStreaming, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v InputPaidMediaVideo) MarshalJSON() ([]byte, error) { + type alias InputPaidMediaVideo + a := struct { + Type string `json:"type"` + alias + }{ + Type: "video", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// InputPaidMediaVideo.inputPaidMedia is a dummy method to avoid interface implementation. +func (v InputPaidMediaVideo) inputPaidMedia() {} + +func (v InputPaidMediaVideo) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { + if v.Media != nil { + err := v.Media.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) + } + } + + if v.Thumbnail != nil { + err := v.Thumbnail.Attach(mediaName+"-thumbnail", data) + if err != nil { + return nil, fmt.Errorf("failed to attach 'thumbnail' input file for %s: %w", mediaName, err) + } + } + + return json.Marshal(v) +} + // InputPollOption (https://core.telegram.org/bots/api#inputpolloption) // -// This object contains information about one answer option in a poll to send. +// This object contains information about one answer option in a poll to be sent. type InputPollOption struct { // Option text, 1-100 characters Text string `json:"text"` @@ -5178,7 +5410,7 @@ type InputPollOption struct { // This object describes a sticker to be added to a sticker set. type InputSticker struct { // The added sticker. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, upload a new one using multipart/form-data, or pass "attach://" to upload a new one using multipart/form-data under name. Animated and video stickers can't be uploaded via HTTP URL. More information on Sending Files: https://core.telegram.org/bots/api#sending-files - Sticker InputFile `json:"sticker"` + Sticker InputFileOrString `json:"sticker"` // Format of the added sticker, must be one of "static" for a .WEBP or .PNG image, "animated" for a .TGS animation, "video" for a WEBM video Format string `json:"format"` // List of 1-20 emoji associated with the sticker @@ -5189,22 +5421,11 @@ type InputSticker struct { Keywords []string `json:"keywords,omitempty"` } -func (v InputSticker) InputParams(mediaName string, data map[string]NamedReader) ([]byte, error) { +func (v InputSticker) InputParams(mediaName string, data map[string]FileReader) ([]byte, error) { if v.Sticker != nil { - switch m := v.Sticker.(type) { - case string: - // ok, noop - - case NamedReader: - v.Sticker = "attach://" + mediaName - data[mediaName] = m - - case io.Reader: - v.Sticker = "attach://" + mediaName - data[mediaName] = NamedFile{File: m} - - default: - return nil, fmt.Errorf("unknown type: %T", v.Sticker) + err := v.Sticker.Attach(mediaName, data) + if err != nil { + return nil, fmt.Errorf("failed to attach input file for %s: %w", mediaName, err) } } @@ -5263,7 +5484,7 @@ type Invoice struct { Description string `json:"description"` // Unique bot deep-linking parameter that can be used to generate this invoice StartParameter string `json:"start_parameter"` - // Three-letter ISO 4217 currency code + // Three-letter ISO 4217 currency code, or "XTR" for payments in Telegram Stars Currency string `json:"currency"` // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass 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). TotalAmount int64 `json:"total_amount"` @@ -5271,7 +5492,7 @@ type Invoice struct { // KeyboardButton (https://core.telegram.org/bots/api#keyboardbutton) // -// This object represents one button of the reply keyboard. For simple text buttons, String can be used instead of this object to specify the button text. The optional fields web_app, request_users, request_chat, request_contact, request_location, and request_poll are mutually exclusive. +// This object represents one button of the reply keyboard. At most one of the optional fields must be used to specify type of the button. For simple text buttons, String can be used instead of this object to specify the button text. // Note: request_users and request_chat options will only work in Telegram versions released after 3 February, 2023. Older clients will display unsupported message. type KeyboardButton struct { // Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed @@ -5376,9 +5597,9 @@ type LinkPreviewOptions struct { // // This object represents a point on the map. type Location struct { - // Latitude as defined by sender + // Latitude as defined by the sender Latitude float64 `json:"latitude"` - // Longitude as defined by sender + // Longitude as defined by the sender Longitude float64 `json:"longitude"` // Optional. The radius of uncertainty for the location, measured in meters; 0-1500 HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` @@ -5493,7 +5714,7 @@ type MergedMenuButton struct { Type string `json:"type"` // Optional. Text on the button (Only for web_app) Text string `json:"text,omitempty"` - // Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. (Only for web_app) + // Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Alternatively, a t.me link to a Web App of the bot can be specified in the object instead of the Web App's URL, in which case the Web App will be opened as if the user pressed the link. (Only for web_app) WebApp *WebAppInfo `json:"web_app,omitempty"` } @@ -5651,7 +5872,7 @@ func (v MenuButtonDefault) menuButton() {} type MenuButtonWebApp struct { // Text on the button Text string `json:"text"` - // Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. + // Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Alternatively, a t.me link to a Web App of the bot can be specified in the object instead of the Web App's URL, in which case the Web App will be opened as if the user pressed the link. WebApp WebAppInfo `json:"web_app"` } @@ -5689,13 +5910,13 @@ func (v MenuButtonWebApp) menuButton() {} // // This object represents a message. type Message struct { - // Unique message identifier inside this chat + // Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent MessageId int64 `json:"message_id"` // Optional. Unique identifier of a message thread to which the message belongs; for supergroups only MessageThreadId int64 `json:"message_thread_id,omitempty"` - // Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. + // Optional. Sender of the message; may be empty for messages sent to channels. For backward compatibility, if the message was sent on behalf of a chat, the field contains a fake sender user in non-channel chats From *User `json:"from,omitempty"` - // Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. + // Optional. Sender of the message when sent on behalf of a chat. For example, the supergroup itself for messages sent by its anonymous administrators or a linked channel for messages automatically forwarded to the channel's discussion group. For backward compatibility, if the message was sent on behalf of a chat, the field from contains a fake sender user in non-channel chats. SenderChat *Chat `json:"sender_chat,omitempty"` // Optional. If the sender of the message boosted the chat, the number of boosts added by the user SenderBoostCount int64 `json:"sender_boost_count,omitempty"` @@ -5739,12 +5960,16 @@ type Message struct { Entities []MessageEntity `json:"entities,omitempty"` // Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"` + // Optional. Unique identifier of the message effect added to the message + EffectId string `json:"effect_id,omitempty"` // Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set Animation *Animation `json:"animation,omitempty"` // Optional. Message is an audio file, information about the file Audio *Audio `json:"audio,omitempty"` // Optional. Message is a general file, information about the file Document *Document `json:"document,omitempty"` + // Optional. Message contains paid media; information about the paid media + PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"` // Optional. Message is a photo, available sizes of the photo Photo []PhotoSize `json:"photo,omitempty"` // Optional. Message is a sticker, information about the sticker @@ -5757,10 +5982,12 @@ type Message struct { VideoNote *VideoNote `json:"video_note,omitempty"` // Optional. Message is a voice message, information about the file Voice *Voice `json:"voice,omitempty"` - // Optional. Caption for the animation, audio, document, photo, video or voice + // Optional. Caption for the animation, audio, document, paid media, photo, video or voice Caption string `json:"caption,omitempty"` // Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Optional. True, if the caption must be shown above the message media + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. True, if the message media is covered by a spoiler animation HasMediaSpoiler bool `json:"has_media_spoiler,omitempty"` // Optional. Message is a shared contact, information about the contact @@ -5803,6 +6030,8 @@ type Message struct { Invoice *Invoice `json:"invoice,omitempty"` // Optional. Message is a service message about a successful payment, information about the payment. More about payments: https://core.telegram.org/bots/api#payments SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` + // Optional. Message is a service message about a refunded payment, information about the payment. More about payments: https://core.telegram.org/bots/api#payments + RefundedPayment *RefundedPayment `json:"refunded_payment,omitempty"` // Optional. Service message: users were shared with the bot UsersShared *UsersShared `json:"users_shared,omitempty"` // Optional. Service message: a chat was shared with the bot @@ -5882,9 +6111,11 @@ func (v *Message) UnmarshalJSON(b []byte) error { Text string `json:"text"` Entities []MessageEntity `json:"entities"` LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options"` + EffectId string `json:"effect_id"` Animation *Animation `json:"animation"` Audio *Audio `json:"audio"` Document *Document `json:"document"` + PaidMedia *PaidMediaInfo `json:"paid_media"` Photo []PhotoSize `json:"photo"` Sticker *Sticker `json:"sticker"` Story *Story `json:"story"` @@ -5893,6 +6124,7 @@ func (v *Message) UnmarshalJSON(b []byte) error { Voice *Voice `json:"voice"` Caption string `json:"caption"` CaptionEntities []MessageEntity `json:"caption_entities"` + ShowCaptionAboveMedia bool `json:"show_caption_above_media"` HasMediaSpoiler bool `json:"has_media_spoiler"` Contact *Contact `json:"contact"` Dice *Dice `json:"dice"` @@ -5914,6 +6146,7 @@ func (v *Message) UnmarshalJSON(b []byte) error { PinnedMessage json.RawMessage `json:"pinned_message"` Invoice *Invoice `json:"invoice"` SuccessfulPayment *SuccessfulPayment `json:"successful_payment"` + RefundedPayment *RefundedPayment `json:"refunded_payment"` UsersShared *UsersShared `json:"users_shared"` ChatShared *ChatShared `json:"chat_shared"` ConnectedWebsite string `json:"connected_website"` @@ -5973,9 +6206,11 @@ func (v *Message) UnmarshalJSON(b []byte) error { v.Text = t.Text v.Entities = t.Entities v.LinkPreviewOptions = t.LinkPreviewOptions + v.EffectId = t.EffectId v.Animation = t.Animation v.Audio = t.Audio v.Document = t.Document + v.PaidMedia = t.PaidMedia v.Photo = t.Photo v.Sticker = t.Sticker v.Story = t.Story @@ -5984,6 +6219,7 @@ func (v *Message) UnmarshalJSON(b []byte) error { v.Voice = t.Voice v.Caption = t.Caption v.CaptionEntities = t.CaptionEntities + v.ShowCaptionAboveMedia = t.ShowCaptionAboveMedia v.HasMediaSpoiler = t.HasMediaSpoiler v.Contact = t.Contact v.Dice = t.Dice @@ -6008,6 +6244,7 @@ func (v *Message) UnmarshalJSON(b []byte) error { } v.Invoice = t.Invoice v.SuccessfulPayment = t.SuccessfulPayment + v.RefundedPayment = t.RefundedPayment v.UsersShared = t.UsersShared v.ChatShared = t.ChatShared v.ConnectedWebsite = t.ConnectedWebsite @@ -6066,7 +6303,7 @@ type MessageAutoDeleteTimerChanged struct { // // This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. type MessageEntity struct { - // Type of the entity. Currently, can be "mention" (@username), "hashtag" (#hashtag), "cashtag" ($USD), "bot_command" (/start@jobs_bot), "url" (https://telegram.org), "email" (do-not-reply@telegram.org), "phone_number" (+1-212-555-0123), "bold" (bold text), "italic" (italic text), "underline" (underlined text), "strikethrough" (strikethrough text), "spoiler" (spoiler message), "blockquote" (block quotation), "code" (monowidth string), "pre" (monowidth block), "text_link" (for clickable text URLs), "text_mention" (for users without usernames), "custom_emoji" (for inline custom emoji stickers) + // Type of the entity. Currently, can be "mention" (@username), "hashtag" (#hashtag or #hashtag@chatusername), "cashtag" ($USD or $USD@chatusername), "bot_command" (/start@jobs_bot), "url" (https://telegram.org), "email" (do-not-reply@telegram.org), "phone_number" (+1-212-555-0123), "bold" (bold text), "italic" (italic text), "underline" (underlined text), "strikethrough" (strikethrough text), "spoiler" (spoiler message), "blockquote" (block quotation), "expandable_blockquote" (collapsed-by-default block quotation), "code" (monowidth string), "pre" (monowidth block), "text_link" (for clickable text URLs), "text_mention" (for users without usernames), "custom_emoji" (for inline custom emoji stickers) Type string `json:"type"` // Offset in UTF-16 code units to the start of the entity Offset int64 `json:"offset"` @@ -6086,7 +6323,7 @@ type MessageEntity struct { // // This object represents a unique message identifier. type MessageId struct { - // Unique message identifier + // Unique message identifier. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent MessageId int64 `json:"message_id"` } @@ -6501,12 +6738,290 @@ type OrderInfo struct { ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` } -// PassportData (https://core.telegram.org/bots/api#passportdata) +// PaidMedia (https://core.telegram.org/bots/api#paidmedia) // -// Describes Telegram Passport data shared with the bot by the user. -type PassportData struct { - // Array with information about documents and other Telegram Passport elements that was shared with the bot - Data []EncryptedPassportElement `json:"data,omitempty"` +// This object describes paid media. Currently, it can be one of +// - PaidMediaPreview +// - PaidMediaPhoto +// - PaidMediaVideo +type PaidMedia interface { + GetType() string + // MergePaidMedia returns a MergedPaidMedia struct to simplify working with complex telegram types in a non-generic world. + MergePaidMedia() MergedPaidMedia + // paidMedia exists to avoid external types implementing this interface. + paidMedia() +} + +// Ensure that all subtypes correctly implement the parent interface. +var ( + _ PaidMedia = PaidMediaPreview{} + _ PaidMedia = PaidMediaPhoto{} + _ PaidMedia = PaidMediaVideo{} +) + +// MergedPaidMedia is a helper type to simplify interactions with the various PaidMedia subtypes. +type MergedPaidMedia struct { + // Type of the paid media + Type string `json:"type"` + // Optional. Media width as defined by the sender (Only for preview) + Width int64 `json:"width,omitempty"` + // Optional. Media height as defined by the sender (Only for preview) + Height int64 `json:"height,omitempty"` + // Optional. Duration of the media in seconds as defined by the sender (Only for preview) + Duration int64 `json:"duration,omitempty"` + // Optional. The photo (Only for photo) + Photo []PhotoSize `json:"photo,omitempty"` + // Optional. The video (Only for video) + Video *Video `json:"video,omitempty"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v MergedPaidMedia) GetType() string { + return v.Type +} + +// MergedPaidMedia.paidMedia is a dummy method to avoid interface implementation. +func (v MergedPaidMedia) paidMedia() {} + +// MergePaidMedia returns a MergedPaidMedia struct to simplify working with types in a non-generic world. +func (v MergedPaidMedia) MergePaidMedia() MergedPaidMedia { + return v +} + +// unmarshalPaidMediaArray is a JSON unmarshalling helper which allows unmarshalling an array of interfaces +// using unmarshalPaidMedia. +func unmarshalPaidMediaArray(d json.RawMessage) ([]PaidMedia, error) { + if len(d) == 0 { + return nil, nil + } + + var ds []json.RawMessage + err := json.Unmarshal(d, &ds) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal initial PaidMedia JSON into an array: %w", err) + } + + var vs []PaidMedia + for idx, d := range ds { + v, err := unmarshalPaidMedia(d) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal PaidMedia on array item %d: %w", idx, err) + } + vs = append(vs, v) + } + + return vs, nil +} + +// unmarshalPaidMedia is a JSON unmarshal helper to marshal the right structs into a PaidMedia interface +// based on the Type field. +func unmarshalPaidMedia(d json.RawMessage) (PaidMedia, error) { + if len(d) == 0 { + return nil, nil + } + + t := struct { + Type string + }{} + err := json.Unmarshal(d, &t) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal PaidMedia for constant field 'Type': %w", err) + } + + switch t.Type { + case "preview": + s := PaidMediaPreview{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal PaidMedia for value 'preview': %w", err) + } + return s, nil + + case "photo": + s := PaidMediaPhoto{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal PaidMedia for value 'photo': %w", err) + } + return s, nil + + case "video": + s := PaidMediaVideo{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal PaidMedia for value 'video': %w", err) + } + return s, nil + + } + return nil, fmt.Errorf("unknown interface for PaidMedia with Type %v", t.Type) +} + +// PaidMediaInfo (https://core.telegram.org/bots/api#paidmediainfo) +// +// Describes the paid media added to a message. +type PaidMediaInfo struct { + // The number of Telegram Stars that must be paid to buy access to the media + StarCount int64 `json:"star_count"` + // Information about the paid media + PaidMedia []PaidMedia `json:"paid_media,omitempty"` +} + +// UnmarshalJSON is a custom JSON unmarshaller to use the helpers which allow for unmarshalling structs into interfaces. +func (v *PaidMediaInfo) UnmarshalJSON(b []byte) error { + // All fields in PaidMediaInfo, with interface fields as json.RawMessage + type tmp struct { + StarCount int64 `json:"star_count"` + PaidMedia json.RawMessage `json:"paid_media"` + } + t := tmp{} + err := json.Unmarshal(b, &t) + if err != nil { + return fmt.Errorf("failed to unmarshal PaidMediaInfo JSON into tmp struct: %w", err) + } + + v.StarCount = t.StarCount + v.PaidMedia, err = unmarshalPaidMediaArray(t.PaidMedia) + if err != nil { + return fmt.Errorf("failed to unmarshal custom JSON field PaidMedia: %w", err) + } + + return nil +} + +// PaidMediaPhoto (https://core.telegram.org/bots/api#paidmediaphoto) +// +// The paid media is a photo. +type PaidMediaPhoto struct { + // The photo + Photo []PhotoSize `json:"photo,omitempty"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v PaidMediaPhoto) GetType() string { + return "photo" +} + +// MergePaidMedia returns a MergedPaidMedia struct to simplify working with types in a non-generic world. +func (v PaidMediaPhoto) MergePaidMedia() MergedPaidMedia { + return MergedPaidMedia{ + Type: "photo", + Photo: v.Photo, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v PaidMediaPhoto) MarshalJSON() ([]byte, error) { + type alias PaidMediaPhoto + a := struct { + Type string `json:"type"` + alias + }{ + Type: "photo", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// PaidMediaPhoto.paidMedia is a dummy method to avoid interface implementation. +func (v PaidMediaPhoto) paidMedia() {} + +// PaidMediaPreview (https://core.telegram.org/bots/api#paidmediapreview) +// +// The paid media isn't available before the payment. +type PaidMediaPreview struct { + // Optional. Media width as defined by the sender + Width int64 `json:"width,omitempty"` + // Optional. Media height as defined by the sender + Height int64 `json:"height,omitempty"` + // Optional. Duration of the media in seconds as defined by the sender + Duration int64 `json:"duration,omitempty"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v PaidMediaPreview) GetType() string { + return "preview" +} + +// MergePaidMedia returns a MergedPaidMedia struct to simplify working with types in a non-generic world. +func (v PaidMediaPreview) MergePaidMedia() MergedPaidMedia { + return MergedPaidMedia{ + Type: "preview", + Width: v.Width, + Height: v.Height, + Duration: v.Duration, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v PaidMediaPreview) MarshalJSON() ([]byte, error) { + type alias PaidMediaPreview + a := struct { + Type string `json:"type"` + alias + }{ + Type: "preview", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// PaidMediaPreview.paidMedia is a dummy method to avoid interface implementation. +func (v PaidMediaPreview) paidMedia() {} + +// PaidMediaPurchased (https://core.telegram.org/bots/api#paidmediapurchased) +// +// This object contains information about a paid media purchase. +type PaidMediaPurchased struct { + // User who purchased the media + From User `json:"from"` + // Bot-specified paid media payload + PaidMediaPayload string `json:"paid_media_payload"` +} + +// PaidMediaVideo (https://core.telegram.org/bots/api#paidmediavideo) +// +// The paid media is a video. +type PaidMediaVideo struct { + // The video + Video Video `json:"video"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v PaidMediaVideo) GetType() string { + return "video" +} + +// MergePaidMedia returns a MergedPaidMedia struct to simplify working with types in a non-generic world. +func (v PaidMediaVideo) MergePaidMedia() MergedPaidMedia { + return MergedPaidMedia{ + Type: "video", + Video: &v.Video, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v PaidMediaVideo) MarshalJSON() ([]byte, error) { + type alias PaidMediaVideo + a := struct { + Type string `json:"type"` + alias + }{ + Type: "video", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// PaidMediaVideo.paidMedia is a dummy method to avoid interface implementation. +func (v PaidMediaVideo) paidMedia() {} + +// PassportData (https://core.telegram.org/bots/api#passportdata) +// +// Describes Telegram Passport data shared with the bot by the user. +type PassportData struct { + // Array with information about documents and other Telegram Passport elements that was shared with the bot + Data []EncryptedPassportElement `json:"data,omitempty"` // Encrypted credentials required to decrypt the data Credentials EncryptedCredentials `json:"credentials"` } @@ -7167,11 +7682,11 @@ type PreCheckoutQuery struct { Id string `json:"id"` // User who sent the query From User `json:"from"` - // Three-letter ISO 4217 currency code + // Three-letter ISO 4217 currency code, or "XTR" for payments in Telegram Stars Currency string `json:"currency"` // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass 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). TotalAmount int64 `json:"total_amount"` - // Bot specified invoice payload + // Bot-specified invoice payload InvoicePayload string `json:"invoice_payload"` // Optional. Identifier of the shipping option chosen by the user ShippingOptionId string `json:"shipping_option_id,omitempty"` @@ -7228,6 +7743,7 @@ func (v *ReactionCount) UnmarshalJSON(b []byte) error { // This object describes the type of a reaction. Currently, it can be one of // - ReactionTypeEmoji // - ReactionTypeCustomEmoji +// - ReactionTypePaid type ReactionType interface { GetType() string // MergeReactionType returns a MergedReactionType struct to simplify working with complex telegram types in a non-generic world. @@ -7240,6 +7756,7 @@ type ReactionType interface { var ( _ ReactionType = ReactionTypeEmoji{} _ ReactionType = ReactionTypeCustomEmoji{} + _ ReactionType = ReactionTypePaid{} ) // MergedReactionType is a helper type to simplify interactions with the various ReactionType subtypes. @@ -7322,6 +7839,14 @@ func unmarshalReactionType(d json.RawMessage) (ReactionType, error) { } return s, nil + case "paid": + s := ReactionTypePaid{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal ReactionType for value 'paid': %w", err) + } + return s, nil + } return nil, fmt.Errorf("unknown interface for ReactionType with Type %v", t.Type) } @@ -7400,6 +7925,55 @@ func (v ReactionTypeEmoji) MarshalJSON() ([]byte, error) { // ReactionTypeEmoji.reactionType is a dummy method to avoid interface implementation. func (v ReactionTypeEmoji) reactionType() {} +// ReactionTypePaid (https://core.telegram.org/bots/api#reactiontypepaid) +// +// The reaction is paid. +type ReactionTypePaid struct{} + +// GetType is a helper method to easily access the common fields of an interface. +func (v ReactionTypePaid) GetType() string { + return "paid" +} + +// MergeReactionType returns a MergedReactionType struct to simplify working with types in a non-generic world. +func (v ReactionTypePaid) MergeReactionType() MergedReactionType { + return MergedReactionType{ + Type: "paid", + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v ReactionTypePaid) MarshalJSON() ([]byte, error) { + type alias ReactionTypePaid + a := struct { + Type string `json:"type"` + alias + }{ + Type: "paid", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// ReactionTypePaid.reactionType is a dummy method to avoid interface implementation. +func (v ReactionTypePaid) reactionType() {} + +// RefundedPayment (https://core.telegram.org/bots/api#refundedpayment) +// +// This object contains basic information about a refunded payment. +type RefundedPayment struct { + // Three-letter ISO 4217 currency code, or "XTR" for payments in Telegram Stars. Currently, always "XTR" + Currency string `json:"currency"` + // Total refunded price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45, total_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). + TotalAmount int64 `json:"total_amount"` + // Bot-specified invoice payload + InvoicePayload string `json:"invoice_payload"` + // Telegram payment identifier + TelegramPaymentChargeId string `json:"telegram_payment_charge_id"` + // Optional. Provider payment identifier + ProviderPaymentChargeId string `json:"provider_payment_charge_id,omitempty"` +} + // ReplyKeyboardMarkup (https://core.telegram.org/bots/api#replykeyboardmarkup) // // This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). Not supported in channels and for messages sent on behalf of a Telegram Business account. @@ -7464,57 +8038,276 @@ type ResponseParameters struct { RetryAfter int64 `json:"retry_after,omitempty"` } -// SentWebAppMessage (https://core.telegram.org/bots/api#sentwebappmessage) +// RevenueWithdrawalState (https://core.telegram.org/bots/api#revenuewithdrawalstate) // -// Describes an inline message sent by a Web App on behalf of a user. -type SentWebAppMessage struct { - // Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. - InlineMessageId string `json:"inline_message_id,omitempty"` +// This object describes the state of a revenue withdrawal operation. Currently, it can be one of +// - RevenueWithdrawalStatePending +// - RevenueWithdrawalStateSucceeded +// - RevenueWithdrawalStateFailed +type RevenueWithdrawalState interface { + GetType() string + // MergeRevenueWithdrawalState returns a MergedRevenueWithdrawalState struct to simplify working with complex telegram types in a non-generic world. + MergeRevenueWithdrawalState() MergedRevenueWithdrawalState + // revenueWithdrawalState exists to avoid external types implementing this interface. + revenueWithdrawalState() } -// SharedUser (https://core.telegram.org/bots/api#shareduser) -// -// This object contains information about a user that was shared with the bot using a KeyboardButtonRequestUsers button. -type SharedUser struct { - // Identifier of the shared user. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so 64-bit integers or double-precision float types are safe for storing these identifiers. The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means. - UserId int64 `json:"user_id"` - // Optional. First name of the user, if the name was requested by the bot - FirstName string `json:"first_name,omitempty"` - // Optional. Last name of the user, if the name was requested by the bot - LastName string `json:"last_name,omitempty"` - // Optional. Username of the user, if the username was requested by the bot - Username string `json:"username,omitempty"` - // Optional. Available sizes of the chat photo, if the photo was requested by the bot - Photo []PhotoSize `json:"photo,omitempty"` +// Ensure that all subtypes correctly implement the parent interface. +var ( + _ RevenueWithdrawalState = RevenueWithdrawalStatePending{} + _ RevenueWithdrawalState = RevenueWithdrawalStateSucceeded{} + _ RevenueWithdrawalState = RevenueWithdrawalStateFailed{} +) + +// MergedRevenueWithdrawalState is a helper type to simplify interactions with the various RevenueWithdrawalState subtypes. +type MergedRevenueWithdrawalState struct { + // Type of the state + Type string `json:"type"` + // Optional. Date the withdrawal was completed in Unix time (Only for succeeded) + Date int64 `json:"date,omitempty"` + // Optional. An HTTPS URL that can be used to see transaction details (Only for succeeded) + Url string `json:"url,omitempty"` } -// ShippingAddress (https://core.telegram.org/bots/api#shippingaddress) -// -// This object represents a shipping address. -type ShippingAddress struct { - // Two-letter ISO 3166-1 alpha-2 country code - CountryCode string `json:"country_code"` - // State, if applicable - State string `json:"state"` - // City - City string `json:"city"` - // First line for the address - StreetLine1 string `json:"street_line1"` - // Second line for the address - StreetLine2 string `json:"street_line2"` - // Address post code - PostCode string `json:"post_code"` +// GetType is a helper method to easily access the common fields of an interface. +func (v MergedRevenueWithdrawalState) GetType() string { + return v.Type } -// ShippingOption (https://core.telegram.org/bots/api#shippingoption) -// -// This object represents one shipping option. -type ShippingOption struct { - // Shipping option identifier - Id string `json:"id"` - // Option title - Title string `json:"title"` - // List of price portions +// MergedRevenueWithdrawalState.revenueWithdrawalState is a dummy method to avoid interface implementation. +func (v MergedRevenueWithdrawalState) revenueWithdrawalState() {} + +// MergeRevenueWithdrawalState returns a MergedRevenueWithdrawalState struct to simplify working with types in a non-generic world. +func (v MergedRevenueWithdrawalState) MergeRevenueWithdrawalState() MergedRevenueWithdrawalState { + return v +} + +// unmarshalRevenueWithdrawalStateArray is a JSON unmarshalling helper which allows unmarshalling an array of interfaces +// using unmarshalRevenueWithdrawalState. +func unmarshalRevenueWithdrawalStateArray(d json.RawMessage) ([]RevenueWithdrawalState, error) { + if len(d) == 0 { + return nil, nil + } + + var ds []json.RawMessage + err := json.Unmarshal(d, &ds) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal initial RevenueWithdrawalState JSON into an array: %w", err) + } + + var vs []RevenueWithdrawalState + for idx, d := range ds { + v, err := unmarshalRevenueWithdrawalState(d) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal RevenueWithdrawalState on array item %d: %w", idx, err) + } + vs = append(vs, v) + } + + return vs, nil +} + +// unmarshalRevenueWithdrawalState is a JSON unmarshal helper to marshal the right structs into a RevenueWithdrawalState interface +// based on the Type field. +func unmarshalRevenueWithdrawalState(d json.RawMessage) (RevenueWithdrawalState, error) { + if len(d) == 0 { + return nil, nil + } + + t := struct { + Type string + }{} + err := json.Unmarshal(d, &t) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal RevenueWithdrawalState for constant field 'Type': %w", err) + } + + switch t.Type { + case "pending": + s := RevenueWithdrawalStatePending{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal RevenueWithdrawalState for value 'pending': %w", err) + } + return s, nil + + case "succeeded": + s := RevenueWithdrawalStateSucceeded{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal RevenueWithdrawalState for value 'succeeded': %w", err) + } + return s, nil + + case "failed": + s := RevenueWithdrawalStateFailed{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal RevenueWithdrawalState for value 'failed': %w", err) + } + return s, nil + + } + return nil, fmt.Errorf("unknown interface for RevenueWithdrawalState with Type %v", t.Type) +} + +// RevenueWithdrawalStateFailed (https://core.telegram.org/bots/api#revenuewithdrawalstatefailed) +// +// The withdrawal failed and the transaction was refunded. +type RevenueWithdrawalStateFailed struct{} + +// GetType is a helper method to easily access the common fields of an interface. +func (v RevenueWithdrawalStateFailed) GetType() string { + return "failed" +} + +// MergeRevenueWithdrawalState returns a MergedRevenueWithdrawalState struct to simplify working with types in a non-generic world. +func (v RevenueWithdrawalStateFailed) MergeRevenueWithdrawalState() MergedRevenueWithdrawalState { + return MergedRevenueWithdrawalState{ + Type: "failed", + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v RevenueWithdrawalStateFailed) MarshalJSON() ([]byte, error) { + type alias RevenueWithdrawalStateFailed + a := struct { + Type string `json:"type"` + alias + }{ + Type: "failed", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// RevenueWithdrawalStateFailed.revenueWithdrawalState is a dummy method to avoid interface implementation. +func (v RevenueWithdrawalStateFailed) revenueWithdrawalState() {} + +// RevenueWithdrawalStatePending (https://core.telegram.org/bots/api#revenuewithdrawalstatepending) +// +// The withdrawal is in progress. +type RevenueWithdrawalStatePending struct{} + +// GetType is a helper method to easily access the common fields of an interface. +func (v RevenueWithdrawalStatePending) GetType() string { + return "pending" +} + +// MergeRevenueWithdrawalState returns a MergedRevenueWithdrawalState struct to simplify working with types in a non-generic world. +func (v RevenueWithdrawalStatePending) MergeRevenueWithdrawalState() MergedRevenueWithdrawalState { + return MergedRevenueWithdrawalState{ + Type: "pending", + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v RevenueWithdrawalStatePending) MarshalJSON() ([]byte, error) { + type alias RevenueWithdrawalStatePending + a := struct { + Type string `json:"type"` + alias + }{ + Type: "pending", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// RevenueWithdrawalStatePending.revenueWithdrawalState is a dummy method to avoid interface implementation. +func (v RevenueWithdrawalStatePending) revenueWithdrawalState() {} + +// RevenueWithdrawalStateSucceeded (https://core.telegram.org/bots/api#revenuewithdrawalstatesucceeded) +// +// The withdrawal succeeded. +type RevenueWithdrawalStateSucceeded struct { + // Date the withdrawal was completed in Unix time + Date int64 `json:"date"` + // An HTTPS URL that can be used to see transaction details + Url string `json:"url"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v RevenueWithdrawalStateSucceeded) GetType() string { + return "succeeded" +} + +// MergeRevenueWithdrawalState returns a MergedRevenueWithdrawalState struct to simplify working with types in a non-generic world. +func (v RevenueWithdrawalStateSucceeded) MergeRevenueWithdrawalState() MergedRevenueWithdrawalState { + return MergedRevenueWithdrawalState{ + Type: "succeeded", + Date: v.Date, + Url: v.Url, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v RevenueWithdrawalStateSucceeded) MarshalJSON() ([]byte, error) { + type alias RevenueWithdrawalStateSucceeded + a := struct { + Type string `json:"type"` + alias + }{ + Type: "succeeded", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// RevenueWithdrawalStateSucceeded.revenueWithdrawalState is a dummy method to avoid interface implementation. +func (v RevenueWithdrawalStateSucceeded) revenueWithdrawalState() {} + +// SentWebAppMessage (https://core.telegram.org/bots/api#sentwebappmessage) +// +// Describes an inline message sent by a Web App on behalf of a user. +type SentWebAppMessage struct { + // Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. + InlineMessageId string `json:"inline_message_id,omitempty"` +} + +// SharedUser (https://core.telegram.org/bots/api#shareduser) +// +// This object contains information about a user that was shared with the bot using a KeyboardButtonRequestUsers button. +type SharedUser struct { + // Identifier of the shared user. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so 64-bit integers or double-precision float types are safe for storing these identifiers. The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means. + UserId int64 `json:"user_id"` + // Optional. First name of the user, if the name was requested by the bot + FirstName string `json:"first_name,omitempty"` + // Optional. Last name of the user, if the name was requested by the bot + LastName string `json:"last_name,omitempty"` + // Optional. Username of the user, if the username was requested by the bot + Username string `json:"username,omitempty"` + // Optional. Available sizes of the chat photo, if the photo was requested by the bot + Photo []PhotoSize `json:"photo,omitempty"` +} + +// ShippingAddress (https://core.telegram.org/bots/api#shippingaddress) +// +// This object represents a shipping address. +type ShippingAddress struct { + // Two-letter ISO 3166-1 alpha-2 country code + CountryCode string `json:"country_code"` + // State, if applicable + State string `json:"state"` + // City + City string `json:"city"` + // First line for the address + StreetLine1 string `json:"street_line1"` + // Second line for the address + StreetLine2 string `json:"street_line2"` + // Address post code + PostCode string `json:"post_code"` +} + +// ShippingOption (https://core.telegram.org/bots/api#shippingoption) +// +// This object represents one shipping option. +type ShippingOption struct { + // Shipping option identifier + Id string `json:"id"` + // Option title + Title string `json:"title"` + // List of price portions Prices []LabeledPrice `json:"prices,omitempty"` } @@ -7526,12 +8319,67 @@ type ShippingQuery struct { Id string `json:"id"` // User who sent the query From User `json:"from"` - // Bot specified invoice payload + // Bot-specified invoice payload InvoicePayload string `json:"invoice_payload"` // User specified shipping address ShippingAddress ShippingAddress `json:"shipping_address"` } +// StarTransaction (https://core.telegram.org/bots/api#startransaction) +// +// Describes a Telegram Star transaction. +type StarTransaction struct { + // Unique identifier of the transaction. Coincides with the identifier of the original transaction for refund transactions. Coincides with SuccessfulPayment.telegram_payment_charge_id for successful incoming payments from users. + Id string `json:"id"` + // Number of Telegram Stars transferred by the transaction + Amount int64 `json:"amount"` + // Date the transaction was created in Unix time + Date int64 `json:"date"` + // Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal). Only for incoming transactions + Source TransactionPartner `json:"source,omitempty"` + // Optional. Receiver of an outgoing transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for outgoing transactions + Receiver TransactionPartner `json:"receiver,omitempty"` +} + +// UnmarshalJSON is a custom JSON unmarshaller to use the helpers which allow for unmarshalling structs into interfaces. +func (v *StarTransaction) UnmarshalJSON(b []byte) error { + // All fields in StarTransaction, with interface fields as json.RawMessage + type tmp struct { + Id string `json:"id"` + Amount int64 `json:"amount"` + Date int64 `json:"date"` + Source json.RawMessage `json:"source"` + Receiver json.RawMessage `json:"receiver"` + } + t := tmp{} + err := json.Unmarshal(b, &t) + if err != nil { + return fmt.Errorf("failed to unmarshal StarTransaction JSON into tmp struct: %w", err) + } + + v.Id = t.Id + v.Amount = t.Amount + v.Date = t.Date + v.Source, err = unmarshalTransactionPartner(t.Source) + if err != nil { + return fmt.Errorf("failed to unmarshal custom JSON field Source: %w", err) + } + v.Receiver, err = unmarshalTransactionPartner(t.Receiver) + if err != nil { + return fmt.Errorf("failed to unmarshal custom JSON field Receiver: %w", err) + } + + return nil +} + +// StarTransactions (https://core.telegram.org/bots/api#startransactions) +// +// Contains a list of Telegram Star transactions. +type StarTransactions struct { + // The list of transactions + Transactions []StarTransaction `json:"transactions,omitempty"` +} + // Sticker (https://core.telegram.org/bots/api#sticker) // // This object represents a sticker. @@ -7598,11 +8446,11 @@ type Story struct { // // This object contains basic information about a successful payment. type SuccessfulPayment struct { - // Three-letter ISO 4217 currency code + // Three-letter ISO 4217 currency code, or "XTR" for payments in Telegram Stars Currency string `json:"currency"` // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass 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). TotalAmount int64 `json:"total_amount"` - // Bot specified invoice payload + // Bot-specified invoice payload InvoicePayload string `json:"invoice_payload"` // Optional. Identifier of the shipping option chosen by the user ShippingOptionId string `json:"shipping_option_id,omitempty"` @@ -7644,6 +8492,379 @@ type TextQuote struct { IsManual bool `json:"is_manual,omitempty"` } +// TransactionPartner (https://core.telegram.org/bots/api#transactionpartner) +// +// This object describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of +// - TransactionPartnerUser +// - TransactionPartnerFragment +// - TransactionPartnerTelegramAds +// - TransactionPartnerTelegramApi +// - TransactionPartnerOther +type TransactionPartner interface { + GetType() string + // MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with complex telegram types in a non-generic world. + MergeTransactionPartner() MergedTransactionPartner + // transactionPartner exists to avoid external types implementing this interface. + transactionPartner() +} + +// Ensure that all subtypes correctly implement the parent interface. +var ( + _ TransactionPartner = TransactionPartnerUser{} + _ TransactionPartner = TransactionPartnerFragment{} + _ TransactionPartner = TransactionPartnerTelegramAds{} + _ TransactionPartner = TransactionPartnerTelegramApi{} + _ TransactionPartner = TransactionPartnerOther{} +) + +// MergedTransactionPartner is a helper type to simplify interactions with the various TransactionPartner subtypes. +type MergedTransactionPartner struct { + // Type of the transaction partner + Type string `json:"type"` + // Optional. Information about the user (Only for user) + User *User `json:"user,omitempty"` + // Optional. Bot-specified invoice payload (Only for user) + InvoicePayload string `json:"invoice_payload,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. 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) + RequestCount int64 `json:"request_count,omitempty"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v MergedTransactionPartner) GetType() string { + return v.Type +} + +// MergedTransactionPartner.transactionPartner is a dummy method to avoid interface implementation. +func (v MergedTransactionPartner) transactionPartner() {} + +// MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with types in a non-generic world. +func (v MergedTransactionPartner) MergeTransactionPartner() MergedTransactionPartner { + return v +} + +// unmarshalTransactionPartnerArray is a JSON unmarshalling helper which allows unmarshalling an array of interfaces +// using unmarshalTransactionPartner. +func unmarshalTransactionPartnerArray(d json.RawMessage) ([]TransactionPartner, error) { + if len(d) == 0 { + return nil, nil + } + + var ds []json.RawMessage + err := json.Unmarshal(d, &ds) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal initial TransactionPartner JSON into an array: %w", err) + } + + var vs []TransactionPartner + for idx, d := range ds { + v, err := unmarshalTransactionPartner(d) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner on array item %d: %w", idx, err) + } + vs = append(vs, v) + } + + return vs, nil +} + +// unmarshalTransactionPartner is a JSON unmarshal helper to marshal the right structs into a TransactionPartner interface +// based on the Type field. +func unmarshalTransactionPartner(d json.RawMessage) (TransactionPartner, error) { + if len(d) == 0 { + return nil, nil + } + + t := struct { + Type string + }{} + err := json.Unmarshal(d, &t) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner for constant field 'Type': %w", err) + } + + switch t.Type { + case "user": + s := TransactionPartnerUser{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner for value 'user': %w", err) + } + return s, nil + + case "fragment": + s := TransactionPartnerFragment{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner for value 'fragment': %w", err) + } + return s, nil + + case "telegram_ads": + s := TransactionPartnerTelegramAds{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner for value 'telegram_ads': %w", err) + } + return s, nil + + case "telegram_api": + s := TransactionPartnerTelegramApi{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner for value 'telegram_api': %w", err) + } + return s, nil + + case "other": + s := TransactionPartnerOther{} + err := json.Unmarshal(d, &s) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal TransactionPartner for value 'other': %w", err) + } + return s, nil + + } + return nil, fmt.Errorf("unknown interface for TransactionPartner with Type %v", t.Type) +} + +// TransactionPartnerFragment (https://core.telegram.org/bots/api#transactionpartnerfragment) +// +// Describes a withdrawal transaction with Fragment. +type TransactionPartnerFragment struct { + // Optional. State of the transaction if the transaction is outgoing + WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"` +} + +// UnmarshalJSON is a custom JSON unmarshaller to use the helpers which allow for unmarshalling structs into interfaces. +func (v *TransactionPartnerFragment) UnmarshalJSON(b []byte) error { + // All fields in TransactionPartnerFragment, with interface fields as json.RawMessage + type tmp struct { + WithdrawalState json.RawMessage `json:"withdrawal_state"` + } + t := tmp{} + err := json.Unmarshal(b, &t) + if err != nil { + return fmt.Errorf("failed to unmarshal TransactionPartnerFragment JSON into tmp struct: %w", err) + } + + v.WithdrawalState, err = unmarshalRevenueWithdrawalState(t.WithdrawalState) + if err != nil { + return fmt.Errorf("failed to unmarshal custom JSON field WithdrawalState: %w", err) + } + + return nil +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v TransactionPartnerFragment) GetType() string { + return "fragment" +} + +// MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with types in a non-generic world. +func (v TransactionPartnerFragment) MergeTransactionPartner() MergedTransactionPartner { + return MergedTransactionPartner{ + Type: "fragment", + WithdrawalState: v.WithdrawalState, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v TransactionPartnerFragment) MarshalJSON() ([]byte, error) { + type alias TransactionPartnerFragment + a := struct { + Type string `json:"type"` + alias + }{ + Type: "fragment", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// TransactionPartnerFragment.transactionPartner is a dummy method to avoid interface implementation. +func (v TransactionPartnerFragment) transactionPartner() {} + +// TransactionPartnerOther (https://core.telegram.org/bots/api#transactionpartnerother) +// +// Describes a transaction with an unknown source or recipient. +type TransactionPartnerOther struct{} + +// GetType is a helper method to easily access the common fields of an interface. +func (v TransactionPartnerOther) GetType() string { + return "other" +} + +// MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with types in a non-generic world. +func (v TransactionPartnerOther) MergeTransactionPartner() MergedTransactionPartner { + return MergedTransactionPartner{ + Type: "other", + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v TransactionPartnerOther) MarshalJSON() ([]byte, error) { + type alias TransactionPartnerOther + a := struct { + Type string `json:"type"` + alias + }{ + Type: "other", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// TransactionPartnerOther.transactionPartner is a dummy method to avoid interface implementation. +func (v TransactionPartnerOther) transactionPartner() {} + +// TransactionPartnerTelegramAds (https://core.telegram.org/bots/api#transactionpartnertelegramads) +// +// Describes a withdrawal transaction to the Telegram Ads platform. +type TransactionPartnerTelegramAds struct{} + +// GetType is a helper method to easily access the common fields of an interface. +func (v TransactionPartnerTelegramAds) GetType() string { + return "telegram_ads" +} + +// MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with types in a non-generic world. +func (v TransactionPartnerTelegramAds) MergeTransactionPartner() MergedTransactionPartner { + return MergedTransactionPartner{ + Type: "telegram_ads", + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v TransactionPartnerTelegramAds) MarshalJSON() ([]byte, error) { + type alias TransactionPartnerTelegramAds + a := struct { + Type string `json:"type"` + alias + }{ + Type: "telegram_ads", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// TransactionPartnerTelegramAds.transactionPartner is a dummy method to avoid interface implementation. +func (v TransactionPartnerTelegramAds) transactionPartner() {} + +// TransactionPartnerTelegramApi (https://core.telegram.org/bots/api#transactionpartnertelegramapi) +// +// Describes a transaction with payment for paid broadcasting. +type TransactionPartnerTelegramApi struct { + // The number of successful requests that exceeded regular limits and were therefore billed + RequestCount int64 `json:"request_count"` +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v TransactionPartnerTelegramApi) GetType() string { + return "telegram_api" +} + +// MergeTransactionPartner returns a MergedTransactionPartner struct to simplify working with types in a non-generic world. +func (v TransactionPartnerTelegramApi) MergeTransactionPartner() MergedTransactionPartner { + return MergedTransactionPartner{ + Type: "telegram_api", + RequestCount: v.RequestCount, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v TransactionPartnerTelegramApi) MarshalJSON() ([]byte, error) { + type alias TransactionPartnerTelegramApi + a := struct { + Type string `json:"type"` + alias + }{ + Type: "telegram_api", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// TransactionPartnerTelegramApi.transactionPartner is a dummy method to avoid interface implementation. +func (v TransactionPartnerTelegramApi) transactionPartner() {} + +// TransactionPartnerUser (https://core.telegram.org/bots/api#transactionpartneruser) +// +// Describes a transaction with a user. +type TransactionPartnerUser struct { + // Information about the user + User User `json:"user"` + // Optional. Bot-specified invoice payload + InvoicePayload string `json:"invoice_payload,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"` +} + +// 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"` + } + t := tmp{} + err := json.Unmarshal(b, &t) + if err != nil { + return fmt.Errorf("failed to unmarshal TransactionPartnerUser JSON into tmp struct: %w", err) + } + + v.User = t.User + v.InvoicePayload = t.InvoicePayload + 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 + + return nil +} + +// GetType is a helper method to easily access the common fields of an interface. +func (v TransactionPartnerUser) GetType() string { + return "user" +} + +// 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, + } +} + +// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value. +func (v TransactionPartnerUser) MarshalJSON() ([]byte, error) { + type alias TransactionPartnerUser + a := struct { + Type string `json:"type"` + alias + }{ + Type: "user", + alias: (alias)(v), + } + return json.Marshal(a) +} + +// TransactionPartnerUser.transactionPartner is a dummy method to avoid interface implementation. +func (v TransactionPartnerUser) transactionPartner() {} + // Update (https://core.telegram.org/bots/api#update) // // This object represents an incoming update. @@ -7681,6 +8902,8 @@ type Update struct { ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"` // Optional. New incoming pre-checkout query. Contains full information about checkout PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"` + // Optional. A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat + PurchasedPaidMedia *PaidMediaPurchased `json:"purchased_paid_media,omitempty"` // Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot Poll *Poll `json:"poll,omitempty"` // Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. @@ -7725,6 +8948,8 @@ type User struct { SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` // Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe. CanConnectToBusiness bool `json:"can_connect_to_business,omitempty"` + // Optional. True, if the bot has a main Web App. Returned only in getMe. + HasMainWebApp bool `json:"has_main_web_app,omitempty"` } // UserChatBoosts (https://core.telegram.org/bots/api#userchatboosts) @@ -7783,17 +9008,17 @@ type Video struct { FileId string `json:"file_id"` // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. FileUniqueId string `json:"file_unique_id"` - // Video width as defined by sender + // Video width as defined by the sender Width int64 `json:"width"` - // Video height as defined by sender + // Video height as defined by the sender Height int64 `json:"height"` - // Duration of the video in seconds as defined by sender + // Duration of the video in seconds as defined by the sender Duration int64 `json:"duration"` // Optional. Video thumbnail Thumbnail *PhotoSize `json:"thumbnail,omitempty"` - // Optional. Original filename as defined by sender + // Optional. Original filename as defined by the sender FileName string `json:"file_name,omitempty"` - // Optional. MIME type of the file as defined by sender + // Optional. MIME type of the file as defined by the sender MimeType string `json:"mime_type,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. FileSize int64 `json:"file_size,omitempty"` @@ -7836,9 +9061,9 @@ type VideoNote struct { FileId string `json:"file_id"` // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. FileUniqueId string `json:"file_unique_id"` - // Video width and height (diameter of the video message) as defined by sender + // Video width and height (diameter of the video message) as defined by the sender Length int64 `json:"length"` - // Duration of the video in seconds as defined by sender + // Duration of the video in seconds as defined by the sender Duration int64 `json:"duration"` // Optional. Video thumbnail Thumbnail *PhotoSize `json:"thumbnail,omitempty"` @@ -7854,9 +9079,9 @@ type Voice struct { FileId string `json:"file_id"` // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. FileUniqueId string `json:"file_unique_id"` - // Duration of the audio in seconds as defined by sender + // Duration of the audio in seconds as defined by the sender Duration int64 `json:"duration"` - // Optional. MIME type of the file as defined by sender + // Optional. MIME type of the file as defined by the sender MimeType string `json:"mime_type,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. FileSize int64 `json:"file_size,omitempty"` diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/request.go b/vendor/github.com/PaulSonOfLars/gotgbot/v2/request.go index 1dafe4569..41c12e129 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/request.go +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/request.go @@ -21,9 +21,7 @@ const ( type BotClient interface { // RequestWithContext submits a POST HTTP request a bot API instance. - RequestWithContext(ctx context.Context, token string, method string, params map[string]string, data map[string]NamedReader, opts *RequestOpts) (json.RawMessage, error) - // TimeoutContext calculates the required timeout contect required given the passed RequestOpts, and any default opts defined by the BotClient. - TimeoutContext(opts *RequestOpts) (context.Context, context.CancelFunc) + RequestWithContext(ctx context.Context, token string, method string, params map[string]string, data map[string]FileReader, opts *RequestOpts) (json.RawMessage, error) // GetAPIURL gets the URL of the API either in use by the bot or defined in the request opts. GetAPIURL(opts *RequestOpts) string // FileURL gets the URL of a file at the API address that the bot is interacting with. @@ -74,24 +72,6 @@ func (t *TelegramError) Error() string { return fmt.Sprintf("unable to %s: %s", t.Method, t.Description) } -type NamedReader interface { - Name() string - io.Reader -} - -type NamedFile struct { - File io.Reader - FileName string -} - -func (nf NamedFile) Read(p []byte) (n int, err error) { - return nf.File.Read(p) -} - -func (nf NamedFile) Name() string { - return nf.FileName -} - // RequestOpts defines any request-specific options used to interact with the telegram API. type RequestOpts struct { // Timeout for the HTTP request to the telegram API. @@ -100,38 +80,45 @@ type RequestOpts struct { APIURL string } -// TimeoutContext returns the appropriate context for the current settings. -func (bot *BaseBotClient) TimeoutContext(opts *RequestOpts) (context.Context, context.CancelFunc) { +// getTimeoutContext returns the appropriate context for the current settings. +func (bot *BaseBotClient) getTimeoutContext(parentCtx context.Context, opts *RequestOpts) (context.Context, context.CancelFunc) { + if parentCtx == nil { + parentCtx = context.Background() + } + if opts != nil { - ctx, cancelFunc := timeoutFromOpts(opts) + ctx, cancelFunc := timeoutFromOpts(parentCtx, opts) if ctx != nil { return ctx, cancelFunc } } if bot.DefaultRequestOpts != nil { - ctx, cancelFunc := timeoutFromOpts(bot.DefaultRequestOpts) + ctx, cancelFunc := timeoutFromOpts(parentCtx, bot.DefaultRequestOpts) if ctx != nil { return ctx, cancelFunc } } - return context.WithTimeout(context.Background(), DefaultTimeout) + return context.WithTimeout(parentCtx, DefaultTimeout) } -func timeoutFromOpts(opts *RequestOpts) (context.Context, context.CancelFunc) { +func timeoutFromOpts(parentCtx context.Context, opts *RequestOpts) (context.Context, context.CancelFunc) { // nothing? no timeout. if opts == nil { return nil, nil } + if parentCtx == nil { + parentCtx = context.Background() + } + if opts.Timeout > 0 { - // > 0 timeout defined. - return context.WithTimeout(context.Background(), opts.Timeout) + return context.WithTimeout(parentCtx, opts.Timeout) } else if opts.Timeout < 0 { // < 0 no timeout; infinite. - return context.Background(), func() {} + return parentCtx, func() {} } // 0 == nothing defined, use defaults. return nil, nil @@ -142,28 +129,40 @@ func timeoutFromOpts(opts *RequestOpts) (context.Context, context.CancelFunc) { // - method: the telegram API method to call. // - params: map of parameters to be sending to the telegram API. eg: chat_id, user_id, etc. // - data: map of any files to be sending to the telegram API. -// - opts: request opts to use. Note: Timeout opts are ignored when used in RequestWithContext. Timeout handling is the -// responsibility of the caller/context owner. -func (bot *BaseBotClient) RequestWithContext(ctx context.Context, token string, method string, params map[string]string, data map[string]NamedReader, opts *RequestOpts) (json.RawMessage, error) { - b := &bytes.Buffer{} +// - opts: request opts to use. +func (bot *BaseBotClient) RequestWithContext(parentCtx context.Context, token string, method string, params map[string]string, data map[string]FileReader, opts *RequestOpts) (json.RawMessage, error) { + ctx, cancel := bot.getTimeoutContext(parentCtx, opts) + defer cancel() + + var requestBody io.Reader var contentType string // Check if there are any files to upload. If yes, use multipart; else, use JSON. if len(data) > 0 { - var err error - contentType, err = fillBuffer(b, params, data) - if err != nil { - return nil, fmt.Errorf("failed to fill buffer with parameters and file data: %w", err) - } + pr, pw := io.Pipe() + defer pr.Close() // avoid writer goroutine leak + mw := multipart.NewWriter(pw) + contentType = mw.FormDataContentType() + requestBody = pr + // Write the request data asynchronously from another goroutine + // to the multipart.Writer which will be piped into the pipe reader + // which is tied to the request to be sent + go func() { + writerError := fillBuffer(mw, params, data) + // Close the writer with error of multipart writer. + // If the error is nil, this will act just like pw.Close() + _ = pw.CloseWithError(writerError) + }() } else { contentType = "application/json" - err := json.NewEncoder(b).Encode(params) + bodyBytes, err := json.Marshal(params) if err != nil { return nil, fmt.Errorf("failed to encode parameters as JSON: %w", err) } + requestBody = bytes.NewReader(bodyBytes) } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, bot.methodEndpoint(token, method, opts), b) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, bot.methodEndpoint(token, method, opts), requestBody) if err != nil { return nil, fmt.Errorf("failed to build POST request to %s: %w", method, err) } @@ -194,38 +193,37 @@ func (bot *BaseBotClient) RequestWithContext(ctx context.Context, token string, return r.Result, nil } -func fillBuffer(b *bytes.Buffer, params map[string]string, data map[string]NamedReader) (string, error) { - w := multipart.NewWriter(b) - +// Fill the buffer of multipart.Writer with data which is going to be sent. +func fillBuffer(w *multipart.Writer, params map[string]string, data map[string]FileReader) error { for k, v := range params { err := w.WriteField(k, v) if err != nil { - return "", fmt.Errorf("failed to write multipart field %s with value %s: %w", k, v, err) + return fmt.Errorf("failed to write multipart field %s with value %s: %w", k, v, err) } } for field, file := range data { - fileName := file.Name() + fileName := file.Name if fileName == "" { fileName = field } part, err := w.CreateFormFile(field, fileName) if err != nil { - return "", fmt.Errorf("failed to create form file for field %s and fileName %s: %w", field, fileName, err) + return fmt.Errorf("failed to create form file for field %s and fileName %s: %w", field, fileName, err) } - _, err = io.Copy(part, file) + _, err = io.Copy(part, file.Data) if err != nil { - return "", fmt.Errorf("failed to copy file contents of field %s to form: %w", field, err) + return fmt.Errorf("failed to copy file contents of field %s to form: %w", field, err) } } if err := w.Close(); err != nil { - return "", fmt.Errorf("failed to close multipart form writer: %w", err) + return fmt.Errorf("failed to close multipart form writer: %w", err) } - return w.FormDataContentType(), nil + return nil } // GetAPIURL returns the currently used API endpoint. diff --git a/vendor/github.com/PaulSonOfLars/gotgbot/v2/spec_commit b/vendor/github.com/PaulSonOfLars/gotgbot/v2/spec_commit index 1b7715e62..b6ac42614 100644 --- a/vendor/github.com/PaulSonOfLars/gotgbot/v2/spec_commit +++ b/vendor/github.com/PaulSonOfLars/gotgbot/v2/spec_commit @@ -1 +1 @@ -68843d1ae456b90a494bfee92253f30a8204b2a7 \ No newline at end of file +15b6cd15658668b7017f3c069e27405ca4f4428e \ No newline at end of file diff --git a/vendor/modules.txt b/vendor/modules.txt index 1b40cd020..9ba7415a9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -22,7 +22,7 @@ github.com/Microsoft/go-winio/internal/fs github.com/Microsoft/go-winio/internal/socket github.com/Microsoft/go-winio/internal/stringbuffer github.com/Microsoft/go-winio/pkg/guid -# github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27 +# github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.30 ## explicit; go 1.19 github.com/PaulSonOfLars/gotgbot/v2 # github.com/PuerkitoBio/goquery v1.8.1