(new): support Bot API 10.3
Golang lint / lint (push) Failing after 1m37s

(fix): finalize v2 contracts
(tests): cover v2 migration
(doc): prepare release guidance
This commit is contained in:
2026-09-08 23:21:38 +03:00
parent 24040fe164
commit d78526242b
88 changed files with 2321 additions and 918 deletions
+6 -6
View File
@@ -9,7 +9,7 @@ import (
"net/http"
"time"
"git.scuroneko.dev/scuroneko/laniakea/utils"
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
"git.scuroneko.dev/scuroneko/sneklog/v2"
)
@@ -236,7 +236,7 @@ func NewRequestWithChatID[R, P any](method string, params P, chatID int64) Teleg
return TelegramRequest[R, P]{method, params, chatID}
}
func (r TelegramRequest[R, P]) doRequest(ctx context.Context, api *API) (R, error) {
func (api *API) doRequest[R, P any](ctx context.Context, r TelegramRequest[R, P]) (R, error) {
var zero R
reqData, err := json.Marshal(r.params)
if err != nil {
@@ -336,11 +336,11 @@ func (r TelegramRequest[R, P]) doRequest(ctx context.Context, api *API) (R, erro
// DoWithContext executes the request asynchronously via the worker pool.
// Returns result or error via channel. Respects context cancellation.
func (r TelegramRequest[R, P]) DoWithContext(ctx context.Context, api *API) (R, error) {
func (api *API) DoWithContext[R, P any](ctx context.Context, r TelegramRequest[R, P]) (R, error) {
var zero R
resultChan, err := api.pool.submit(ctx, func(ctx context.Context) (any, error) {
return r.doRequest(ctx, api)
return api.doRequest(ctx, r)
})
if err != nil {
return zero, err
@@ -362,8 +362,8 @@ func (r TelegramRequest[R, P]) DoWithContext(ctx context.Context, api *API) (R,
// Do executes the request synchronously with a background context.
// Use only for simple, non-critical calls.
func (r TelegramRequest[R, P]) Do(api *API) (R, error) {
return r.DoWithContext(context.Background(), api)
func (api *API) Do[R, P any](r TelegramRequest[R, P]) (R, error) {
return api.DoWithContext(context.Background(), r)
}
func readBody(body io.ReadCloser) ([]byte, error) {
+162 -13
View File
@@ -38,13 +38,15 @@ func TestSendRichMessageDraftMarshal(t *testing.T) {
ChatID: 1,
DraftID: 7,
RichMessage: InputRichMessage{Markdown: "*hi*"},
CanStop: true,
KeepOnStop: true,
}
data, err := json.Marshal(params)
if err != nil {
t.Fatalf("Marshal returned error: %v", err)
}
got := string(data)
for _, want := range []string{`"chat_id":1`, `"draft_id":7`, `"rich_message":{"markdown":"*hi*"}`} {
for _, want := range []string{`"chat_id":1`, `"draft_id":7`, `"rich_message":{"markdown":"*hi*"}`, `"can_stop":true`, `"keep_on_stop":true`} {
if !strings.Contains(got, want) {
t.Fatalf("missing %s in sendRichMessageDraft JSON: %s", want, got)
}
@@ -131,18 +133,18 @@ func TestEphemeralSendParametersMarshal(t *testing.T) {
name string
params any
}{
{"message", SendMessage{ChatID: 1, Text: "text", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"animation", SendAnimation{ChatID: 1, Animation: "animation", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"audio", SendAudio{ChatID: 1, Audio: "audio", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"document", SendDocument{ChatID: 1, Document: "document", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"photo", SendPhoto{ChatID: 1, Photo: "photo", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"sticker", SendSticker{ChatID: 1, Sticker: "sticker", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"video", SendVideo{ChatID: 1, Video: "video", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"video note", SendVideoNote{ChatID: 1, VideoNote: "video-note", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"voice", SendVoice{ChatID: 1, Voice: "voice", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"contact", SendContact{ChatID: 1, PhoneNumber: "+10000000000", FirstName: "A", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"location", SendLocation{ChatID: 1, Latitude: 1, Longitude: 2, ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"venue", SendVenue{ChatID: 1, Latitude: 1, Longitude: 2, Title: "Venue", Address: "Address", ReceiverUserID: 2, CallbackQueryID: "callback"}},
{"message", SendMessage{ChatID: 1, Text: "text", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"animation", SendAnimation{ChatID: 1, Animation: "animation", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"audio", SendAudio{ChatID: 1, Audio: "audio", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"document", SendDocument{ChatID: 1, Document: "document", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"photo", SendPhoto{ChatID: 1, Photo: "photo", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"sticker", SendSticker{ChatID: 1, Sticker: "sticker", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"video", SendVideo{ChatID: 1, Video: "video", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"video note", SendVideoNote{ChatID: 1, VideoNote: "video-note", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"voice", SendVoice{ChatID: 1, Voice: "voice", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"contact", SendContact{ChatID: 1, PhoneNumber: "+10000000000", FirstName: "A", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"location", SendLocation{ChatID: 1, Latitude: 1, Longitude: 2, EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
{"venue", SendVenue{ChatID: 1, Latitude: 1, Longitude: 2, Title: "Venue", Address: "Address", EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}}},
}
for _, tt := range cases {
@@ -151,6 +153,19 @@ func TestEphemeralSendParametersMarshal(t *testing.T) {
if err != nil {
t.Fatalf("Marshal returned error: %v", err)
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
t.Fatal(err)
}
if _, old := fields["receiver_user_id"]; old {
t.Fatalf("legacy receiver field remains: %s", data)
}
if _, old := fields["callback_query_id"]; old {
t.Fatalf("legacy callback field remains: %s", data)
}
if len(fields["ephemeral_message_parameters"]) == 0 {
t.Fatalf("missing nested parameters: %s", data)
}
if !strings.Contains(string(data), `"receiver_user_id":2`) || !strings.Contains(string(data), `"callback_query_id":"callback"`) {
t.Fatalf("missing ephemeral parameters in %s", data)
}
@@ -158,6 +173,140 @@ func TestEphemeralSendParametersMarshal(t *testing.T) {
}
}
func TestEphemeralUploadParametersMarshal(t *testing.T) {
ephemeral := &EphemeralMessageParameters{ReceiverUserID: 2, CallbackQueryID: "callback"}
cases := []struct {
name string
params any
}{
{"photo", UploadPhoto{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"animation", UploadAnimation{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"audio", UploadAudio{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"document", UploadDocument{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"live photo", UploadLivePhoto{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"video", UploadVideo{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"video note", UploadVideoNote{ChatID: 1, EphemeralMessageParameters: ephemeral}},
{"voice", UploadVoice{ChatID: 1, EphemeralMessageParameters: ephemeral}},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
data, err := json.Marshal(tt.params)
if err != nil {
t.Fatalf("Marshal returned error: %v", err)
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
t.Fatal(err)
}
if _, old := fields["receiver_user_id"]; old {
t.Fatalf("legacy receiver field remains: %s", data)
}
if _, old := fields["callback_query_id"]; old {
t.Fatalf("legacy callback field remains: %s", data)
}
if !strings.Contains(string(fields["ephemeral_message_parameters"]), `"receiver_user_id":2`) {
t.Fatalf("missing nested parameters: %s", data)
}
})
}
}
func TestBotAPI103KeyboardAndAdministratorFieldsMarshal(t *testing.T) {
trueValue := true
cases := []struct {
name string
value any
fields []string
}{
{"inline keyboard force reply", InlineKeyboardMarkup{ForceReply: true}, []string{`"force_reply":true`}},
{"reply keyboard force reply", ReplyKeyboardMarkup{Keyboard: [][]KeyboardButton{}, ForceReply: true}, []string{`"force_reply":true`}},
{"disabled inline button", InlineKeyboardButton{Text: "Wait", Disabled: &DisabledButton{}}, []string{`"disabled":{}`}},
{"administrator member", ChatMember{CanSendWelcomeMessages: &trueValue}, []string{`"can_send_welcome_messages":true`}},
{"administrator rights", ChatAdministratorRights{CanSendWelcomeMessages: &trueValue}, []string{`"can_send_welcome_messages":true`}},
{"promote administrator", PromoteChatMember{ChatID: 1, UserID: 2, CanSendWelcomeMessages: true}, []string{`"can_send_welcome_messages":true`}},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
data, err := json.Marshal(tt.value)
if err != nil {
t.Fatalf("Marshal returned error: %v", err)
}
for _, field := range tt.fields {
if !strings.Contains(string(data), field) {
t.Fatalf("missing %s in %s", field, data)
}
}
if strings.Contains(string(data), "melcome") {
t.Fatalf("misspelled welcome field in %s", data)
}
})
}
}
func TestMessageGenerationStoppedUpdateUnmarshal(t *testing.T) {
var update Update
err := json.Unmarshal([]byte(`{"update_id":1,"stopped_message_generation":{"chat":{"id":42,"type":"private"},"message_thread_id":3,"draft_id":7}}`), &update)
if err != nil {
t.Fatalf("Unmarshal returned error: %v", err)
}
if update.Type != UpdateTypeMessageGenerationStopped || update.StoppedMessageGeneration == nil {
t.Fatalf("unexpected update routing: type=%q payload=%+v", update.Type, update.StoppedMessageGeneration)
}
if update.StoppedMessageGeneration.Chat.ID != 42 || update.StoppedMessageGeneration.DraftID != 7 {
t.Fatalf("unexpected stopped-generation payload: %+v", update.StoppedMessageGeneration)
}
}
func TestBotAPI103AdditionalFieldsMarshal(t *testing.T) {
params := []struct {
name string
value any
want []string
}{
{
"ephemeral replacement",
EphemeralMessageParameters{ReceiverUserID: 2, ReplaceCallbackQueryMessage: true},
[]string{`"receiver_user_id":2`, `"replace_callback_query_message":true`},
},
{
"message draft controls",
SendMessageDraft{ChatID: 1, DraftID: 7, CanStop: true, KeepOnStop: true},
[]string{`"can_stop":true`, `"keep_on_stop":true`},
},
{
"ephemeral rich text",
EditEphemeralMessageText{ChatID: 1, ReceiverUserID: 2, EphemeralMessageID: 3, RichMessage: &InputRichMessage{HTML: "<b>x</b>"}},
[]string{`"rich_message":{`, `"html":`},
},
{
"ephemeral caption position",
EditEphemeralMessageCaption{ChatID: 1, ReceiverUserID: 2, EphemeralMessageID: 3, ShowCaptionAboveMedia: true},
[]string{`"show_caption_above_media":true`},
},
{
"unique gift privacy",
UniqueGiftInfo{Text: "gift", Entities: []MessageEntity{{Type: MessageEntityBold, Length: 4}}, IsPrivate: true},
[]string{`"text":"gift"`, `"entities":[`, `"is_private":true`},
},
}
for _, tt := range params {
t.Run(tt.name, func(t *testing.T) {
data, err := json.Marshal(tt.value)
if err != nil {
t.Fatalf("Marshal returned error: %v", err)
}
for _, want := range tt.want {
if !strings.Contains(string(data), want) {
t.Fatalf("missing %s in %s", want, data)
}
}
})
}
}
func TestInputPollOptionMediaLinkMarshal(t *testing.T) {
media := InputPollOptionMedia{Type: "link", URL: "https://example.com"}
data, err := json.Marshal(media)
+36 -52
View File
@@ -18,10 +18,8 @@ type SendPhoto struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Photo Required. 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
@@ -72,7 +70,7 @@ type SendPhoto struct {
// See https://core.telegram.org/bots/api#sendphoto
func (api *API) SendPhoto(params SendPhoto) (Message, error) {
req := NewRequestWithChatID[Message]("sendPhoto", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendPhotoWithContext is the context-aware variant of SendPhoto.
@@ -81,7 +79,7 @@ func (api *API) SendPhoto(params SendPhoto) (Message, error) {
// See https://core.telegram.org/bots/api#sendphoto
func (api *API) SendPhotoWithContext(ctx context.Context, params SendPhoto) (Message, error) {
req := NewRequestWithChatID[Message]("sendPhoto", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendAudio holds parameters for the sendAudio method.
@@ -100,10 +98,8 @@ type SendAudio struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Audio Required. 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
@@ -160,7 +156,7 @@ type SendAudio struct {
// See https://core.telegram.org/bots/api#sendaudio
func (api *API) SendAudio(params SendAudio) (Message, error) {
req := NewRequestWithChatID[Message]("sendAudio", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendAudioWithContext is the context-aware variant of SendAudio.
@@ -169,7 +165,7 @@ func (api *API) SendAudio(params SendAudio) (Message, error) {
// See https://core.telegram.org/bots/api#sendaudio
func (api *API) SendAudioWithContext(ctx context.Context, params SendAudio) (Message, error) {
req := NewRequestWithChatID[Message]("sendAudio", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendDocument holds parameters for the sendDocument method.
@@ -188,10 +184,8 @@ type SendDocument struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Document Required. 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
@@ -246,7 +240,7 @@ type SendDocument struct {
// See https://core.telegram.org/bots/api#senddocument
func (api *API) SendDocument(params SendDocument) (Message, error) {
req := NewRequestWithChatID[Message]("sendDocument", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendDocumentWithContext is the context-aware variant of SendDocument.
@@ -255,7 +249,7 @@ func (api *API) SendDocument(params SendDocument) (Message, error) {
// See https://core.telegram.org/bots/api#senddocument
func (api *API) SendDocumentWithContext(ctx context.Context, params SendDocument) (Message, error) {
req := NewRequestWithChatID[Message]("sendDocument", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendVideo holds parameters for the sendVideo method.
@@ -274,10 +268,8 @@ type SendVideo struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Video Required. 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
@@ -349,7 +341,7 @@ type SendVideo struct {
// See https://core.telegram.org/bots/api#sendvideo
func (api *API) SendVideo(params SendVideo) (Message, error) {
req := NewRequestWithChatID[Message]("sendVideo", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendVideoWithContext is the context-aware variant of SendVideo.
@@ -358,7 +350,7 @@ func (api *API) SendVideo(params SendVideo) (Message, error) {
// See https://core.telegram.org/bots/api#sendvideo
func (api *API) SendVideoWithContext(ctx context.Context, params SendVideo) (Message, error) {
req := NewRequestWithChatID[Message]("sendVideo", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendAnimation holds parameters for the sendAnimation method.
@@ -377,10 +369,8 @@ type SendAnimation struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Animation Required. 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
@@ -442,7 +432,7 @@ type SendAnimation struct {
// See https://core.telegram.org/bots/api#sendanimation
func (api *API) SendAnimation(params SendAnimation) (Message, error) {
req := NewRequestWithChatID[Message]("sendAnimation", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendAnimationWithContext is the context-aware variant of SendAnimation.
@@ -451,7 +441,7 @@ func (api *API) SendAnimation(params SendAnimation) (Message, error) {
// See https://core.telegram.org/bots/api#sendanimation
func (api *API) SendAnimationWithContext(ctx context.Context, params SendAnimation) (Message, error) {
req := NewRequestWithChatID[Message]("sendAnimation", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendVoice holds parameters for the sendVoice method.
@@ -470,10 +460,8 @@ type SendVoice struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Voice Required. 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
@@ -518,7 +506,7 @@ type SendVoice struct {
// See https://core.telegram.org/bots/api#sendvoice
func (api *API) SendVoice(params SendVoice) (Message, error) {
req := NewRequestWithChatID[Message]("sendVoice", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendVoiceWithContext is the context-aware variant of SendVoice.
@@ -527,7 +515,7 @@ func (api *API) SendVoice(params SendVoice) (Message, error) {
// See https://core.telegram.org/bots/api#sendvoice
func (api *API) SendVoiceWithContext(ctx context.Context, params SendVoice) (Message, error) {
req := NewRequestWithChatID[Message]("sendVoice", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendVideoNote holds parameters for the sendVideoNote method.
@@ -546,10 +534,8 @@ type SendVideoNote struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// VideoNote Required. 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
@@ -595,7 +581,7 @@ type SendVideoNote struct {
// See https://core.telegram.org/bots/api#sendvideonote
func (api *API) SendVideoNote(params SendVideoNote) (Message, error) {
req := NewRequestWithChatID[Message]("sendVideoNote", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendVideoNoteWithContext is the context-aware variant of SendVideoNote.
@@ -604,7 +590,7 @@ func (api *API) SendVideoNote(params SendVideoNote) (Message, error) {
// See https://core.telegram.org/bots/api#sendvideonote
func (api *API) SendVideoNoteWithContext(ctx context.Context, params SendVideoNote) (Message, error) {
req := NewRequestWithChatID[Message]("sendVideoNote", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendPaidMedia holds parameters for the sendPaidMedia method.
@@ -668,7 +654,7 @@ type SendPaidMedia struct {
// See https://core.telegram.org/bots/api#sendpaidmedia
func (api *API) SendPaidMedia(params SendPaidMedia) (Message, error) {
req := NewRequestWithChatID[Message]("sendPaidMedia", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendPaidMediaWithContext is the context-aware variant of SendPaidMedia.
@@ -677,7 +663,7 @@ func (api *API) SendPaidMedia(params SendPaidMedia) (Message, error) {
// See https://core.telegram.org/bots/api#sendpaidmedia
func (api *API) SendPaidMediaWithContext(ctx context.Context, params SendPaidMedia) (Message, error) {
req := NewRequestWithChatID[Message]("sendPaidMedia", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendMediaGroup holds parameters for the sendMediaGroup method.
@@ -719,7 +705,7 @@ type SendMediaGroup struct {
// See https://core.telegram.org/bots/api#sendmediagroup
func (api *API) SendMediaGroup(params SendMediaGroup) ([]Message, error) {
req := NewRequestWithChatID[[]Message]("sendMediaGroup", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendMediaGroupWithContext is the context-aware variant of SendMediaGroup.
@@ -728,7 +714,7 @@ func (api *API) SendMediaGroup(params SendMediaGroup) ([]Message, error) {
// See https://core.telegram.org/bots/api#sendmediagroup
func (api *API) SendMediaGroupWithContext(ctx context.Context, params SendMediaGroup) ([]Message, error) {
req := NewRequestWithChatID[[]Message]("sendMediaGroup", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendLivePhoto holds parameters for the sendLivePhoto method.
@@ -748,10 +734,8 @@ type SendLivePhoto struct {
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// LivePhoto Required. Live photo video to send. The video must be no longer than 10 seconds and must not
// exceed 10 MB in size. Pass a file_id as String to send a video that exists on the Telegram servers
// (recommended) or upload a new video using multipart/form-data. More information on Sending Files ».
@@ -802,7 +786,7 @@ type SendLivePhoto struct {
// See https://core.telegram.org/bots/api#sendlivephoto
func (api *API) SendLivePhoto(params SendLivePhoto) (Message, error) {
req := NewRequestWithChatID[Message]("sendLivePhoto", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendLivePhotoWithContext is the context-aware variant of SendLivePhoto.
@@ -811,5 +795,5 @@ func (api *API) SendLivePhoto(params SendLivePhoto) (Message, error) {
// See https://core.telegram.org/bots/api#sendlivephoto
func (api *API) SendLivePhotoWithContext(ctx context.Context, params SendLivePhoto) (Message, error) {
req := NewRequestWithChatID[Message]("sendLivePhoto", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+6 -30
View File
@@ -355,44 +355,22 @@ const (
// PollAnswer represents an answer submitted by a poll voter.
//
// User and VoterChat remain value fields for v1 compatibility. Their pointer
// representation is subject to change in v2; use VoterUser and VoterChatInfo
// when presence matters.
// Exactly one of User and VoterChat is present.
// Since: Bot API 4.6
// See https://core.telegram.org/bots/api#pollanswer
type PollAnswer struct {
// PollID identifies the poll.
PollID string `json:"poll_id"`
// VoterChat is the chat that changed the answer, when the voter is anonymous.
VoterChat Chat `json:"voter_chat,omitempty"` // Since: Bot API 6.8
VoterChat *Chat `json:"voter_chat,omitempty"` // Since: Bot API 6.8
// User is the user that changed the answer, when the voter is not anonymous.
User User `json:"user,omitempty"`
User *User `json:"user,omitempty"`
// OptionIDs contains the chosen option indices and is empty for a retracted vote.
OptionIDs []int `json:"option_ids"`
// OptionPersistentIDs contains the persistent identifiers of the chosen options.
OptionPersistentIDs []string `json:"option_persistent_ids"` // Since: Bot API 9.6
}
// VoterUser returns the non-anonymous voter when it is present.
//
// Since: Bot API 4.6
func (a PollAnswer) VoterUser() (*User, bool) {
if a.User.ID == 0 {
return nil, false
}
return &a.User, true
}
// VoterChatInfo returns the anonymous voter chat when it is present.
//
// Since: Bot API 6.8
func (a PollAnswer) VoterChatInfo() (*Chat, bool) {
if a.VoterChat.ID == 0 {
return nil, false
}
return &a.VoterChat, true
}
// Poll contains information about a poll.
// Since: Bot API 4.2
// See https://core.telegram.org/bots/api#poll
@@ -549,13 +527,11 @@ type InputChecklist struct {
TitleEntities []MessageEntity `json:"title_entities,omitempty"`
// Tasks List of 1-30 tasks in the checklist
Tasks []InputChecklistTask `json:"tasks"`
// OtherCanAddTasks Optional. Pass True if other users can add tasks to the checklist
// Subject to change in v2: the Go field name may be corrected to OthersCanAddTasks.
OtherCanAddTasks bool `json:"others_can_add_tasks,omitempty"`
// OthersCanAddTasks Optional. Pass True if other users can add tasks to the checklist
OthersCanAddTasks bool `json:"others_can_add_tasks,omitempty"`
// OtherCanMarkTasksAsDone Optional. Pass True if other users can mark tasks as done or not done in the
// checklist
// Subject to change in v2: the Go field name may be corrected to OthersCanMarkTasksAsDone.
OtherCanMarkTasksAsDone bool `json:"others_can_mark_tasks_as_done,omitempty"`
OthersCanMarkTasksAsDone bool `json:"others_can_mark_tasks_as_done,omitempty"`
}
// ChecklistTaskDone describes a service message about checklist tasks being marked as done.
+10 -10
View File
@@ -3,18 +3,18 @@ package tgapi
import "testing"
func TestPollAnswerVoterHelpers(t *testing.T) {
userAnswer := PollAnswer{User: User{ID: 42}}
user, ok := userAnswer.VoterUser()
if !ok || user.ID != 42 {
t.Fatalf("unexpected voter user: %#v, %v", user, ok)
userAnswer := PollAnswer{User: &User{ID: 42}}
user := userAnswer.User
if user.ID != 42 {
t.Fatalf("unexpected voter user: %#v", user)
}
if chat, ok := userAnswer.VoterChatInfo(); ok || chat != nil {
t.Fatalf("unexpected voter chat: %#v, %v", chat, ok)
if chat := userAnswer.VoterChat; chat != nil {
t.Fatalf("unexpected voter chat: %#v", chat)
}
chatAnswer := PollAnswer{VoterChat: Chat{ID: -100}}
chat, ok := chatAnswer.VoterChatInfo()
if !ok || chat.ID != -100 {
t.Fatalf("unexpected voter chat: %#v, %v", chat, ok)
chatAnswer := PollAnswer{VoterChat: &Chat{ID: -100}}
chat := chatAnswer.VoterChat
if chat.ID != -100 {
t.Fatalf("unexpected voter chat: %#v", chat)
}
}
+40 -40
View File
@@ -23,7 +23,7 @@ type SetMyCommands struct {
// See https://core.telegram.org/bots/api#setmycommands
func (api *API) SetMyCommands(params SetMyCommands) (bool, error) {
req := NewRequest[bool]("setMyCommands", params)
return req.Do(api)
return api.Do(req)
}
// SetMyCommandsWithContext is the context-aware variant of SetMyCommands.
@@ -32,7 +32,7 @@ func (api *API) SetMyCommands(params SetMyCommands) (bool, error) {
// See https://core.telegram.org/bots/api#setmycommands
func (api *API) SetMyCommandsWithContext(ctx context.Context, params SetMyCommands) (bool, error) {
req := NewRequest[bool]("setMyCommands", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteMyCommands holds parameters for the deleteMyCommands method.
@@ -53,7 +53,7 @@ type DeleteMyCommands struct {
// See https://core.telegram.org/bots/api#deletemycommands
func (api *API) DeleteMyCommands(params DeleteMyCommands) (bool, error) {
req := NewRequest[bool]("deleteMyCommands", params)
return req.Do(api)
return api.Do(req)
}
// DeleteMyCommandsWithContext is the context-aware variant of DeleteMyCommands.
@@ -62,7 +62,7 @@ func (api *API) DeleteMyCommands(params DeleteMyCommands) (bool, error) {
// See https://core.telegram.org/bots/api#deletemycommands
func (api *API) DeleteMyCommandsWithContext(ctx context.Context, params DeleteMyCommands) (bool, error) {
req := NewRequest[bool]("deleteMyCommands", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetMyCommands holds parameters for the getMyCommands method.
@@ -80,7 +80,7 @@ type GetMyCommands struct {
// See https://core.telegram.org/bots/api#getmycommands
func (api *API) GetMyCommands(params GetMyCommands) ([]BotCommand, error) {
req := NewRequest[[]BotCommand]("getMyCommands", params)
return req.Do(api)
return api.Do(req)
}
// GetMyCommandsWithContext is the context-aware variant of GetMyCommands.
@@ -89,7 +89,7 @@ func (api *API) GetMyCommands(params GetMyCommands) ([]BotCommand, error) {
// See https://core.telegram.org/bots/api#getmycommands
func (api *API) GetMyCommandsWithContext(ctx context.Context, params GetMyCommands) ([]BotCommand, error) {
req := NewRequest[[]BotCommand]("getMyCommands", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetMyName holds parameters for the setMyName method.
@@ -110,7 +110,7 @@ type SetMyName struct {
// See https://core.telegram.org/bots/api#setmyname
func (api *API) SetMyName(params SetMyName) (bool, error) {
req := NewRequest[bool]("setMyName", params)
return req.Do(api)
return api.Do(req)
}
// SetMyNameWithContext is the context-aware variant of SetMyName.
@@ -119,7 +119,7 @@ func (api *API) SetMyName(params SetMyName) (bool, error) {
// See https://core.telegram.org/bots/api#setmyname
func (api *API) SetMyNameWithContext(ctx context.Context, params SetMyName) (bool, error) {
req := NewRequest[bool]("setMyName", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetMyName holds parameters for the getMyName method.
@@ -135,7 +135,7 @@ type GetMyName struct {
// See https://core.telegram.org/bots/api#getmyname
func (api *API) GetMyName(params GetMyName) (BotName, error) {
req := NewRequest[BotName]("getMyName", params)
return req.Do(api)
return api.Do(req)
}
// GetMyNameWithContext is the context-aware variant of GetMyName.
@@ -144,7 +144,7 @@ func (api *API) GetMyName(params GetMyName) (BotName, error) {
// See https://core.telegram.org/bots/api#getmyname
func (api *API) GetMyNameWithContext(ctx context.Context, params GetMyName) (BotName, error) {
req := NewRequest[BotName]("getMyName", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetMyDescription holds parameters for the setMyDescription method.
@@ -165,7 +165,7 @@ type SetMyDescription struct {
// See https://core.telegram.org/bots/api#setmydescription
func (api *API) SetMyDescription(params SetMyDescription) (bool, error) {
req := NewRequest[bool]("setMyDescription", params)
return req.Do(api)
return api.Do(req)
}
// SetMyDescriptionWithContext is the context-aware variant of SetMyDescription.
@@ -174,7 +174,7 @@ func (api *API) SetMyDescription(params SetMyDescription) (bool, error) {
// See https://core.telegram.org/bots/api#setmydescription
func (api *API) SetMyDescriptionWithContext(ctx context.Context, params SetMyDescription) (bool, error) {
req := NewRequest[bool]("setMyDescription", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetMyDescription holds parameters for the getMyDescription method.
@@ -190,7 +190,7 @@ type GetMyDescription struct {
// See https://core.telegram.org/bots/api#getmydescription
func (api *API) GetMyDescription(params GetMyDescription) (BotDescription, error) {
req := NewRequest[BotDescription]("getMyDescription", params)
return req.Do(api)
return api.Do(req)
}
// GetMyDescriptionWithContext is the context-aware variant of GetMyDescription.
@@ -199,7 +199,7 @@ func (api *API) GetMyDescription(params GetMyDescription) (BotDescription, error
// See https://core.telegram.org/bots/api#getmydescription
func (api *API) GetMyDescriptionWithContext(ctx context.Context, params GetMyDescription) (BotDescription, error) {
req := NewRequest[BotDescription]("getMyDescription", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetMyShortDescription holds parameters for the setMyShortDescription method.
@@ -220,7 +220,7 @@ type SetMyShortDescription struct {
// See https://core.telegram.org/bots/api#setmyshortdescription
func (api *API) SetMyShortDescription(params SetMyShortDescription) (bool, error) {
req := NewRequest[bool]("setMyShortDescription", params)
return req.Do(api)
return api.Do(req)
}
// SetMyShortDescriptionWithContext is the context-aware variant of SetMyShortDescription.
@@ -229,7 +229,7 @@ func (api *API) SetMyShortDescription(params SetMyShortDescription) (bool, error
// See https://core.telegram.org/bots/api#setmyshortdescription
func (api *API) SetMyShortDescriptionWithContext(ctx context.Context, params SetMyShortDescription) (bool, error) {
req := NewRequest[bool]("setMyShortDescription", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetMyShortDescription holds parameters for the getMyShortDescription method.
@@ -245,7 +245,7 @@ type GetMyShortDescription struct {
// See https://core.telegram.org/bots/api#getmyshortdescription
func (api *API) GetMyShortDescription(params GetMyShortDescription) (BotShortDescription, error) {
req := NewRequest[BotShortDescription]("getMyShortDescription", params)
return req.Do(api)
return api.Do(req)
}
// GetMyShortDescriptionWithContext is the context-aware variant of GetMyShortDescription.
@@ -254,7 +254,7 @@ func (api *API) GetMyShortDescription(params GetMyShortDescription) (BotShortDes
// See https://core.telegram.org/bots/api#getmyshortdescription
func (api *API) GetMyShortDescriptionWithContext(ctx context.Context, params GetMyShortDescription) (BotShortDescription, error) {
req := NewRequest[BotShortDescription]("getMyShortDescription", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetMyProfilePhoto holds parameters for the setMyProfilePhoto method.
@@ -271,7 +271,7 @@ type SetMyProfilePhoto struct {
// See https://core.telegram.org/bots/api#setmyprofilephoto
func (api *API) SetMyProfilePhoto(params SetMyProfilePhoto) (bool, error) {
req := NewRequest[bool]("setMyProfilePhoto", params)
return req.Do(api)
return api.Do(req)
}
// SetMyProfilePhotoWithContext is the context-aware variant of SetMyProfilePhoto.
@@ -280,7 +280,7 @@ func (api *API) SetMyProfilePhoto(params SetMyProfilePhoto) (bool, error) {
// See https://core.telegram.org/bots/api#setmyprofilephoto
func (api *API) SetMyProfilePhotoWithContext(ctx context.Context, params SetMyProfilePhoto) (bool, error) {
req := NewRequest[bool]("setMyProfilePhoto", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RemoveMyProfilePhoto removes the bot's profile photo.
@@ -289,7 +289,7 @@ func (api *API) SetMyProfilePhotoWithContext(ctx context.Context, params SetMyPr
// See https://core.telegram.org/bots/api#removemyprofilephoto
func (api *API) RemoveMyProfilePhoto() (bool, error) {
req := NewRequest[bool]("removeMyProfilePhoto", NoParams)
return req.Do(api)
return api.Do(req)
}
// RemoveMyProfilePhotoWithContext is the context-aware variant of RemoveMyProfilePhoto.
@@ -298,7 +298,7 @@ func (api *API) RemoveMyProfilePhoto() (bool, error) {
// See https://core.telegram.org/bots/api#removemyprofilephoto
func (api *API) RemoveMyProfilePhotoWithContext(ctx context.Context) (bool, error) {
req := NewRequest[bool]("removeMyProfilePhoto", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatMenuButton holds parameters for the setChatMenuButton method.
@@ -319,7 +319,7 @@ type SetChatMenuButton struct {
// See https://core.telegram.org/bots/api#setchatmenubutton
func (api *API) SetChatMenuButton(params SetChatMenuButton) (bool, error) {
req := NewRequest[bool]("setChatMenuButton", params)
return req.Do(api)
return api.Do(req)
}
// SetChatMenuButtonWithContext is the context-aware variant of SetChatMenuButton.
@@ -328,7 +328,7 @@ func (api *API) SetChatMenuButton(params SetChatMenuButton) (bool, error) {
// See https://core.telegram.org/bots/api#setchatmenubutton
func (api *API) SetChatMenuButtonWithContext(ctx context.Context, params SetChatMenuButton) (bool, error) {
req := NewRequest[bool]("setChatMenuButton", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetChatMenuButton holds parameters for the getChatMenuButton method.
@@ -345,7 +345,7 @@ type GetChatMenuButton struct {
// See https://core.telegram.org/bots/api#getchatmenubutton
func (api *API) GetChatMenuButton(params GetChatMenuButton) (MenuButton, error) {
req := NewRequest[MenuButton]("getChatMenuButton", params)
return req.Do(api)
return api.Do(req)
}
// GetChatMenuButtonWithContext is the context-aware variant of GetChatMenuButton.
@@ -354,7 +354,7 @@ func (api *API) GetChatMenuButton(params GetChatMenuButton) (MenuButton, error)
// See https://core.telegram.org/bots/api#getchatmenubutton
func (api *API) GetChatMenuButtonWithContext(ctx context.Context, params GetChatMenuButton) (MenuButton, error) {
req := NewRequest[MenuButton]("getChatMenuButton", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetMyDefaultAdministratorRights holds parameters for the setMyDefaultAdministratorRights method.
@@ -375,7 +375,7 @@ type SetMyDefaultAdministratorRights struct {
// See https://core.telegram.org/bots/api#setmydefaultadministratorrights
func (api *API) SetMyDefaultAdministratorRights(params SetMyDefaultAdministratorRights) (bool, error) {
req := NewRequest[bool]("setMyDefaultAdministratorRights", params)
return req.Do(api)
return api.Do(req)
}
// SetMyDefaultAdministratorRightsWithContext is the context-aware variant of SetMyDefaultAdministratorRights.
@@ -384,7 +384,7 @@ func (api *API) SetMyDefaultAdministratorRights(params SetMyDefaultAdministrator
// See https://core.telegram.org/bots/api#setmydefaultadministratorrights
func (api *API) SetMyDefaultAdministratorRightsWithContext(ctx context.Context, params SetMyDefaultAdministratorRights) (bool, error) {
req := NewRequest[bool]("setMyDefaultAdministratorRights", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetMyDefaultAdministratorRights holds parameters for the getMyDefaultAdministratorRights method.
@@ -401,7 +401,7 @@ type GetMyDefaultAdministratorRights struct {
// See https://core.telegram.org/bots/api#getmydefaultadministratorrights
func (api *API) GetMyDefaultAdministratorRights(params GetMyDefaultAdministratorRights) (ChatAdministratorRights, error) {
req := NewRequest[ChatAdministratorRights]("getMyDefaultAdministratorRights", params)
return req.Do(api)
return api.Do(req)
}
// GetMyDefaultAdministratorRightsWithContext is the context-aware variant of GetMyDefaultAdministratorRights.
@@ -410,7 +410,7 @@ func (api *API) GetMyDefaultAdministratorRights(params GetMyDefaultAdministrator
// See https://core.telegram.org/bots/api#getmydefaultadministratorrights
func (api *API) GetMyDefaultAdministratorRightsWithContext(ctx context.Context, params GetMyDefaultAdministratorRights) (ChatAdministratorRights, error) {
req := NewRequest[ChatAdministratorRights]("getMyDefaultAdministratorRights", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetAvailableGifts returns the list of gifts that can be sent by the bot.
@@ -418,7 +418,7 @@ func (api *API) GetMyDefaultAdministratorRightsWithContext(ctx context.Context,
// See https://core.telegram.org/bots/api#getavailablegifts
func (api *API) GetAvailableGifts() (Gifts, error) {
req := NewRequest[Gifts]("getAvailableGifts", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetAvailableGiftsWithContext is the context-aware variant of GetAvailableGifts.
@@ -427,7 +427,7 @@ func (api *API) GetAvailableGifts() (Gifts, error) {
// See https://core.telegram.org/bots/api#getavailablegifts
func (api *API) GetAvailableGiftsWithContext(ctx context.Context) (Gifts, error) {
req := NewRequest[Gifts]("getAvailableGifts", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendGift holds parameters for the sendGift method.
@@ -463,7 +463,7 @@ type SendGift struct {
// See https://core.telegram.org/bots/api#sendgift
func (api *API) SendGift(params SendGift) (bool, error) {
req := NewRequest[bool]("sendGift", params)
return req.Do(api)
return api.Do(req)
}
// SendGiftWithContext is the context-aware variant of SendGift.
@@ -472,7 +472,7 @@ func (api *API) SendGift(params SendGift) (bool, error) {
// See https://core.telegram.org/bots/api#sendgift
func (api *API) SendGiftWithContext(ctx context.Context, params SendGift) (bool, error) {
req := NewRequest[bool]("sendGift", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GiftPremiumSubscription holds parameters for the giftPremiumSubscription method.
@@ -506,7 +506,7 @@ type GiftPremiumSubscription struct {
// See https://core.telegram.org/bots/api#giftpremiumsubscription
func (api *API) GiftPremiumSubscription(params GiftPremiumSubscription) (bool, error) {
req := NewRequest[bool]("giftPremiumSubscription", params)
return req.Do(api)
return api.Do(req)
}
// GiftPremiumSubscriptionWithContext is the context-aware variant of GiftPremiumSubscription.
@@ -515,7 +515,7 @@ func (api *API) GiftPremiumSubscription(params GiftPremiumSubscription) (bool, e
// See https://core.telegram.org/bots/api#giftpremiumsubscription
func (api *API) GiftPremiumSubscriptionWithContext(ctx context.Context, params GiftPremiumSubscription) (bool, error) {
req := NewRequest[bool]("giftPremiumSubscription", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetManagedBotAccessSettings holds parameters for the getManagedBotAccessSettings method.
@@ -531,7 +531,7 @@ type GetManagedBotAccessSettings struct {
// See https://core.telegram.org/bots/api#getmanagedbotaccesssettings
func (api *API) GetManagedBotAccessSettings(params GetManagedBotAccessSettings) (BotAccessSettings, error) {
req := NewRequest[BotAccessSettings]("getManagedBotAccessSettings", params)
return req.Do(api)
return api.Do(req)
}
// GetManagedBotAccessSettingsWithContext is the context-aware variant of GetManagedBotAccessSettings.
@@ -540,7 +540,7 @@ func (api *API) GetManagedBotAccessSettings(params GetManagedBotAccessSettings)
// See https://core.telegram.org/bots/api#getmanagedbotaccesssettings
func (api *API) GetManagedBotAccessSettingsWithContext(ctx context.Context, params GetManagedBotAccessSettings) (BotAccessSettings, error) {
req := NewRequest[BotAccessSettings]("getManagedBotAccessSettings", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetManagedBotAccessSettings holds parameters for the setManagedBotAccessSettings method.
@@ -559,7 +559,7 @@ type SetManagedBotAccessSettings struct {
// See https://core.telegram.org/bots/api#setmanagedbotaccesssettings
func (api *API) SetManagedBotAccessSettings(params SetManagedBotAccessSettings) (bool, error) {
req := NewRequest[bool]("setManagedBotAccessSettings", params)
return req.Do(api)
return api.Do(req)
}
// SetManagedBotAccessSettingsWithContext is the context-aware variant of SetManagedBotAccessSettings.
@@ -568,5 +568,5 @@ func (api *API) SetManagedBotAccessSettings(params SetManagedBotAccessSettings)
// See https://core.telegram.org/bots/api#setmanagedbotaccesssettings
func (api *API) SetManagedBotAccessSettingsWithContext(ctx context.Context, params SetManagedBotAccessSettings) (bool, error) {
req := NewRequest[bool]("setManagedBotAccessSettings", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+46 -46
View File
@@ -19,7 +19,7 @@ type VerifyUser struct {
// See https://core.telegram.org/bots/api#verifyuser
func (api *API) VerifyUser(params VerifyUser) (bool, error) {
req := NewRequest[bool]("verifyUser", params)
return req.Do(api)
return api.Do(req)
}
// VerifyUserWithContext is the context-aware variant of VerifyUser.
@@ -28,7 +28,7 @@ func (api *API) VerifyUser(params VerifyUser) (bool, error) {
// See https://core.telegram.org/bots/api#verifyuser
func (api *API) VerifyUserWithContext(ctx context.Context, params VerifyUser) (bool, error) {
req := NewRequest[bool]("verifyUser", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// VerifyChat holds parameters for the verifyChat method.
@@ -49,7 +49,7 @@ type VerifyChat struct {
// See https://core.telegram.org/bots/api#verifychat
func (api *API) VerifyChat(params VerifyChat) (bool, error) {
req := NewRequest[bool]("verifyChat", params)
return req.Do(api)
return api.Do(req)
}
// VerifyChatWithContext is the context-aware variant of VerifyChat.
@@ -58,7 +58,7 @@ func (api *API) VerifyChat(params VerifyChat) (bool, error) {
// See https://core.telegram.org/bots/api#verifychat
func (api *API) VerifyChatWithContext(ctx context.Context, params VerifyChat) (bool, error) {
req := NewRequest[bool]("verifyChat", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RemoveUserVerification holds parameters for the removeUserVerification method.
@@ -75,7 +75,7 @@ type RemoveUserVerification struct {
// See https://core.telegram.org/bots/api#removeuserverification
func (api *API) RemoveUserVerification(params RemoveUserVerification) (bool, error) {
req := NewRequest[bool]("removeUserVerification", params)
return req.Do(api)
return api.Do(req)
}
// RemoveUserVerificationWithContext is the context-aware variant of RemoveUserVerification.
@@ -84,7 +84,7 @@ func (api *API) RemoveUserVerification(params RemoveUserVerification) (bool, err
// See https://core.telegram.org/bots/api#removeuserverification
func (api *API) RemoveUserVerificationWithContext(ctx context.Context, params RemoveUserVerification) (bool, error) {
req := NewRequest[bool]("removeUserVerification", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RemoveChatVerification holds parameters for the removeChatVerification method.
@@ -102,7 +102,7 @@ type RemoveChatVerification struct {
// See https://core.telegram.org/bots/api#removechatverification
func (api *API) RemoveChatVerification(params RemoveChatVerification) (bool, error) {
req := NewRequest[bool]("removeChatVerification", params)
return req.Do(api)
return api.Do(req)
}
// RemoveChatVerificationWithContext is the context-aware variant of RemoveChatVerification.
@@ -111,7 +111,7 @@ func (api *API) RemoveChatVerification(params RemoveChatVerification) (bool, err
// See https://core.telegram.org/bots/api#removechatverification
func (api *API) RemoveChatVerificationWithContext(ctx context.Context, params RemoveChatVerification) (bool, error) {
req := NewRequest[bool]("removeChatVerification", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ReadBusinessMessage holds parameters for the readBusinessMessage method.
@@ -134,7 +134,7 @@ type ReadBusinessMessage struct {
// See https://core.telegram.org/bots/api#readbusinessmessage
func (api *API) ReadBusinessMessage(params ReadBusinessMessage) (bool, error) {
req := NewRequest[bool]("readBusinessMessage", params)
return req.Do(api)
return api.Do(req)
}
// ReadBusinessMessageWithContext is the context-aware variant of ReadBusinessMessage.
@@ -143,7 +143,7 @@ func (api *API) ReadBusinessMessage(params ReadBusinessMessage) (bool, error) {
// See https://core.telegram.org/bots/api#readbusinessmessage
func (api *API) ReadBusinessMessageWithContext(ctx context.Context, params ReadBusinessMessage) (bool, error) {
req := NewRequest[bool]("readBusinessMessage", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetBusinessConnection holds parameters for the getBusinessConnection method.
@@ -159,7 +159,7 @@ type GetBusinessConnection struct {
// See https://core.telegram.org/bots/api#getbusinessconnection
func (api *API) GetBusinessConnection(params GetBusinessConnection) (BusinessConnection, error) {
req := NewRequest[BusinessConnection]("getBusinessConnection", params)
return req.Do(api)
return api.Do(req)
}
// GetBusinessConnectionWithContext is the context-aware variant of GetBusinessConnection.
@@ -168,7 +168,7 @@ func (api *API) GetBusinessConnection(params GetBusinessConnection) (BusinessCon
// See https://core.telegram.org/bots/api#getbusinessconnection
func (api *API) GetBusinessConnectionWithContext(ctx context.Context, params GetBusinessConnection) (BusinessConnection, error) {
req := NewRequest[BusinessConnection]("getBusinessConnection", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteBusinessMessages holds parameters for the deleteBusinessMessages method.
@@ -189,7 +189,7 @@ type DeleteBusinessMessages struct {
// See https://core.telegram.org/bots/api#deletebusinessmessages
func (api *API) DeleteBusinessMessages(params DeleteBusinessMessages) (bool, error) {
req := NewRequest[bool]("deleteBusinessMessages", params)
return req.Do(api)
return api.Do(req)
}
// DeleteBusinessMessagesWithContext is the context-aware variant of DeleteBusinessMessages.
@@ -198,7 +198,7 @@ func (api *API) DeleteBusinessMessages(params DeleteBusinessMessages) (bool, err
// See https://core.telegram.org/bots/api#deletebusinessmessages
func (api *API) DeleteBusinessMessagesWithContext(ctx context.Context, params DeleteBusinessMessages) (bool, error) {
req := NewRequest[bool]("deleteBusinessMessages", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetBusinessAccountName holds parameters for the setBusinessAccountName method.
@@ -219,7 +219,7 @@ type SetBusinessAccountName struct {
// See https://core.telegram.org/bots/api#setbusinessaccountname
func (api *API) SetBusinessAccountName(params SetBusinessAccountName) (bool, error) {
req := NewRequest[bool]("setBusinessAccountName", params)
return req.Do(api)
return api.Do(req)
}
// SetBusinessAccountNameWithContext is the context-aware variant of SetBusinessAccountName.
@@ -228,7 +228,7 @@ func (api *API) SetBusinessAccountName(params SetBusinessAccountName) (bool, err
// See https://core.telegram.org/bots/api#setbusinessaccountname
func (api *API) SetBusinessAccountNameWithContext(ctx context.Context, params SetBusinessAccountName) (bool, error) {
req := NewRequest[bool]("setBusinessAccountName", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetBusinessAccountUsername holds parameters for the setBusinessAccountUsername method.
@@ -247,7 +247,7 @@ type SetBusinessAccountUsername struct {
// See https://core.telegram.org/bots/api#setbusinessaccountusername
func (api *API) SetBusinessAccountUsername(params SetBusinessAccountUsername) (bool, error) {
req := NewRequest[bool]("setBusinessAccountUsername", params)
return req.Do(api)
return api.Do(req)
}
// SetBusinessAccountUsernameWithContext is the context-aware variant of SetBusinessAccountUsername.
@@ -256,7 +256,7 @@ func (api *API) SetBusinessAccountUsername(params SetBusinessAccountUsername) (b
// See https://core.telegram.org/bots/api#setbusinessaccountusername
func (api *API) SetBusinessAccountUsernameWithContext(ctx context.Context, params SetBusinessAccountUsername) (bool, error) {
req := NewRequest[bool]("setBusinessAccountUsername", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetBusinessAccountBio holds parameters for the setBusinessAccountBio method.
@@ -275,7 +275,7 @@ type SetBusinessAccountBio struct {
// See https://core.telegram.org/bots/api#setbusinessaccountbio
func (api *API) SetBusinessAccountBio(params SetBusinessAccountBio) (bool, error) {
req := NewRequest[bool]("setBusinessAccountBio", params)
return req.Do(api)
return api.Do(req)
}
// SetBusinessAccountBioWithContext is the context-aware variant of SetBusinessAccountBio.
@@ -284,7 +284,7 @@ func (api *API) SetBusinessAccountBio(params SetBusinessAccountBio) (bool, error
// See https://core.telegram.org/bots/api#setbusinessaccountbio
func (api *API) SetBusinessAccountBioWithContext(ctx context.Context, params SetBusinessAccountBio) (bool, error) {
req := NewRequest[bool]("setBusinessAccountBio", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetBusinessAccountProfilePhoto holds parameters for the setBusinessAccountProfilePhoto method.
@@ -306,7 +306,7 @@ type SetBusinessAccountProfilePhoto struct {
// See https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
func (api *API) SetBusinessAccountProfilePhoto(params SetBusinessAccountProfilePhoto) (bool, error) {
req := NewRequest[bool]("setBusinessAccountProfilePhoto", params)
return req.Do(api)
return api.Do(req)
}
// SetBusinessAccountProfilePhotoWithContext is the context-aware variant of SetBusinessAccountProfilePhoto.
@@ -315,7 +315,7 @@ func (api *API) SetBusinessAccountProfilePhoto(params SetBusinessAccountProfileP
// See https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
func (api *API) SetBusinessAccountProfilePhotoWithContext(ctx context.Context, params SetBusinessAccountProfilePhoto) (bool, error) {
req := NewRequest[bool]("setBusinessAccountProfilePhoto", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RemoveBusinessAccountProfilePhoto holds parameters for the removeBusinessAccountProfilePhoto method.
@@ -336,7 +336,7 @@ type RemoveBusinessAccountProfilePhoto struct {
// See https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
func (api *API) RemoveBusinessAccountProfilePhoto(params RemoveBusinessAccountProfilePhoto) (bool, error) {
req := NewRequest[bool]("removeBusinessAccountProfilePhoto", params)
return req.Do(api)
return api.Do(req)
}
// RemoveBusinessAccountProfilePhotoWithContext is the context-aware variant of RemoveBusinessAccountProfilePhoto.
@@ -345,7 +345,7 @@ func (api *API) RemoveBusinessAccountProfilePhoto(params RemoveBusinessAccountPr
// See https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
func (api *API) RemoveBusinessAccountProfilePhotoWithContext(ctx context.Context, params RemoveBusinessAccountProfilePhoto) (bool, error) {
req := NewRequest[bool]("removeBusinessAccountProfilePhoto", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetBusinessAccountGiftSettings holds parameters for the setBusinessAccountGiftSettings method.
@@ -367,7 +367,7 @@ type SetBusinessAccountGiftSettings struct {
// See https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
func (api *API) SetBusinessAccountGiftSettings(params SetBusinessAccountGiftSettings) (bool, error) {
req := NewRequest[bool]("setBusinessAccountGiftSettings", params)
return req.Do(api)
return api.Do(req)
}
// SetBusinessAccountGiftSettingsWithContext is the context-aware variant of SetBusinessAccountGiftSettings.
@@ -376,7 +376,7 @@ func (api *API) SetBusinessAccountGiftSettings(params SetBusinessAccountGiftSett
// See https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
func (api *API) SetBusinessAccountGiftSettingsWithContext(ctx context.Context, params SetBusinessAccountGiftSettings) (bool, error) {
req := NewRequest[bool]("setBusinessAccountGiftSettings", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetBusinessAccountStarBalance holds parameters for the getBusinessAccountStarBalance method.
@@ -392,7 +392,7 @@ type GetBusinessAccountStarBalance struct {
// See https://core.telegram.org/bots/api#getbusinessaccountstarbalance
func (api *API) GetBusinessAccountStarBalance(params GetBusinessAccountStarBalance) (StarAmount, error) {
req := NewRequest[StarAmount]("getBusinessAccountStarBalance", params)
return req.Do(api)
return api.Do(req)
}
// GetBusinessAccountStarBalanceWithContext is the context-aware variant of GetBusinessAccountStarBalance.
@@ -401,7 +401,7 @@ func (api *API) GetBusinessAccountStarBalance(params GetBusinessAccountStarBalan
// See https://core.telegram.org/bots/api#getbusinessaccountstarbalance
func (api *API) GetBusinessAccountStarBalanceWithContext(ctx context.Context, params GetBusinessAccountStarBalance) (StarAmount, error) {
req := NewRequest[StarAmount]("getBusinessAccountStarBalance", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// TransferBusinessAccountStars holds parameters for the transferBusinessAccountStars method.
@@ -420,7 +420,7 @@ type TransferBusinessAccountStars struct {
// See https://core.telegram.org/bots/api#transferbusinessaccountstars
func (api *API) TransferBusinessAccountStars(params TransferBusinessAccountStars) (bool, error) {
req := NewRequest[bool]("transferBusinessAccountStars", params)
return req.Do(api)
return api.Do(req)
}
// TransferBusinessAccountStarsWithContext is the context-aware variant of TransferBusinessAccountStars.
@@ -429,7 +429,7 @@ func (api *API) TransferBusinessAccountStars(params TransferBusinessAccountStars
// See https://core.telegram.org/bots/api#transferbusinessaccountstars
func (api *API) TransferBusinessAccountStarsWithContext(ctx context.Context, params TransferBusinessAccountStars) (bool, error) {
req := NewRequest[bool]("transferBusinessAccountStars", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetBusinessAccountGifts holds parameters for the getBusinessAccountGifts method.
@@ -470,7 +470,7 @@ type GetBusinessAccountGifts struct {
// See https://core.telegram.org/bots/api#getbusinessaccountgifts
func (api *API) GetBusinessAccountGifts(params GetBusinessAccountGifts) (OwnedGifts, error) {
req := NewRequest[OwnedGifts]("getBusinessAccountGifts", params)
return req.Do(api)
return api.Do(req)
}
// GetBusinessAccountGiftsWithContext is the context-aware variant of GetBusinessAccountGifts.
@@ -479,7 +479,7 @@ func (api *API) GetBusinessAccountGifts(params GetBusinessAccountGifts) (OwnedGi
// See https://core.telegram.org/bots/api#getbusinessaccountgifts
func (api *API) GetBusinessAccountGiftsWithContext(ctx context.Context, params GetBusinessAccountGifts) (OwnedGifts, error) {
req := NewRequest[OwnedGifts]("getBusinessAccountGifts", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ConvertGiftToStars holds parameters for the convertGiftToStars method.
@@ -498,7 +498,7 @@ type ConvertGiftToStars struct {
// See https://core.telegram.org/bots/api#convertgifttostars
func (api *API) ConvertGiftToStars(params ConvertGiftToStars) (bool, error) {
req := NewRequest[bool]("convertGiftToStars", params)
return req.Do(api)
return api.Do(req)
}
// ConvertGiftToStarsWithContext is the context-aware variant of ConvertGiftToStars.
@@ -507,7 +507,7 @@ func (api *API) ConvertGiftToStars(params ConvertGiftToStars) (bool, error) {
// See https://core.telegram.org/bots/api#convertgifttostars
func (api *API) ConvertGiftToStarsWithContext(ctx context.Context, params ConvertGiftToStars) (bool, error) {
req := NewRequest[bool]("convertGiftToStars", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UpgradeGift holds parameters for the upgradeGift method.
@@ -533,7 +533,7 @@ type UpgradeGift struct {
// See https://core.telegram.org/bots/api#upgradegift
func (api *API) UpgradeGift(params UpgradeGift) (bool, error) {
req := NewRequest[bool]("upgradeGift", params)
return req.Do(api)
return api.Do(req)
}
// UpgradeGiftWithContext is the context-aware variant of UpgradeGift.
@@ -542,7 +542,7 @@ func (api *API) UpgradeGift(params UpgradeGift) (bool, error) {
// See https://core.telegram.org/bots/api#upgradegift
func (api *API) UpgradeGiftWithContext(ctx context.Context, params UpgradeGift) (bool, error) {
req := NewRequest[bool]("upgradeGift", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// TransferGift holds parameters for the transferGift method.
@@ -567,7 +567,7 @@ type TransferGift struct {
// See https://core.telegram.org/bots/api#transfergift
func (api *API) TransferGift(params TransferGift) (bool, error) {
req := NewRequest[bool]("transferGift", params)
return req.Do(api)
return api.Do(req)
}
// TransferGiftWithContext is the context-aware variant of TransferGift.
@@ -576,7 +576,7 @@ func (api *API) TransferGift(params TransferGift) (bool, error) {
// See https://core.telegram.org/bots/api#transfergift
func (api *API) TransferGiftWithContext(ctx context.Context, params TransferGift) (bool, error) {
req := NewRequest[bool]("transferGift", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// PostStory holds parameters for the postStory method.
@@ -614,7 +614,7 @@ type PostStory struct {
// See https://core.telegram.org/bots/api#poststory
func (api *API) PostStory(params PostStory) (Story, error) {
req := NewRequest[Story]("postStory", params)
return req.Do(api)
return api.Do(req)
}
// PostStoryWithContext is the context-aware variant of PostStory.
@@ -623,7 +623,7 @@ func (api *API) PostStory(params PostStory) (Story, error) {
// See https://core.telegram.org/bots/api#poststory
func (api *API) PostStoryWithContext(ctx context.Context, params PostStory) (Story, error) {
req := NewRequest[Story]("postStory", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RepostStory holds parameters for the repostStory method.
@@ -652,7 +652,7 @@ type RepostStory struct {
// See https://core.telegram.org/bots/api#repoststory
func (api *API) RepostStory(params RepostStory) (Story, error) {
req := NewRequest[Story]("repostStory", params)
return req.Do(api)
return api.Do(req)
}
// RepostStoryWithContext is the context-aware variant of RepostStory.
@@ -661,7 +661,7 @@ func (api *API) RepostStory(params RepostStory) (Story, error) {
// See https://core.telegram.org/bots/api#repoststory
func (api *API) RepostStoryWithContext(ctx context.Context, params RepostStory) (Story, error) {
req := NewRequest[Story]("repostStory", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditStory holds parameters for the editStory method.
@@ -693,7 +693,7 @@ type EditStory struct {
// See https://core.telegram.org/bots/api#editstory
func (api *API) EditStory(params EditStory) (Story, error) {
req := NewRequest[Story]("editStory", params)
return req.Do(api)
return api.Do(req)
}
// EditStoryWithContext is the context-aware variant of EditStory.
@@ -702,7 +702,7 @@ func (api *API) EditStory(params EditStory) (Story, error) {
// See https://core.telegram.org/bots/api#editstory
func (api *API) EditStoryWithContext(ctx context.Context, params EditStory) (Story, error) {
req := NewRequest[Story]("editStory", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteStory holds parameters for the deleteStory method.
@@ -721,7 +721,7 @@ type DeleteStory struct {
// See https://core.telegram.org/bots/api#deletestory
func (api *API) DeleteStory(params DeleteStory) (bool, error) {
req := NewRequest[bool]("deleteStory", params)
return req.Do(api)
return api.Do(req)
}
// DeleteStoryWithContext is the context-aware variant of DeleteStory.
@@ -730,5 +730,5 @@ func (api *API) DeleteStory(params DeleteStory) (bool, error) {
// See https://core.telegram.org/bots/api#deletestory
func (api *API) DeleteStoryWithContext(ctx context.Context, params DeleteStory) (bool, error) {
req := NewRequest[bool]("deleteStory", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+71 -69
View File
@@ -27,7 +27,7 @@ type BanChatMember struct {
// See https://core.telegram.org/bots/api#banchatmember
func (api *API) BanChatMember(params BanChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("banChatMember", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// BanChatMemberWithContext is the context-aware variant of BanChatMember.
@@ -36,7 +36,7 @@ func (api *API) BanChatMember(params BanChatMember) (bool, error) {
// See https://core.telegram.org/bots/api#banchatmember
func (api *API) BanChatMemberWithContext(ctx context.Context, params BanChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("banChatMember", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnbanChatMember holds parameters for the unbanChatMember method.
@@ -58,7 +58,7 @@ type UnbanChatMember struct {
// See https://core.telegram.org/bots/api#unbanchatmember
func (api *API) UnbanChatMember(params UnbanChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("unbanChatMember", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnbanChatMemberWithContext is the context-aware variant of UnbanChatMember.
@@ -67,7 +67,7 @@ func (api *API) UnbanChatMember(params UnbanChatMember) (bool, error) {
// See https://core.telegram.org/bots/api#unbanchatmember
func (api *API) UnbanChatMemberWithContext(ctx context.Context, params UnbanChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("unbanChatMember", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RestrictChatMember holds parameters for the restrictChatMember method.
@@ -99,7 +99,7 @@ type RestrictChatMember struct {
// See https://core.telegram.org/bots/api#restrictchatmember
func (api *API) RestrictChatMember(params RestrictChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("restrictChatMember", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// RestrictChatMemberWithContext is the context-aware variant of RestrictChatMember.
@@ -108,7 +108,7 @@ func (api *API) RestrictChatMember(params RestrictChatMember) (bool, error) {
// See https://core.telegram.org/bots/api#restrictchatmember
func (api *API) RestrictChatMemberWithContext(ctx context.Context, params RestrictChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("restrictChatMember", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// PromoteChatMember holds parameters for the promoteChatMember method.
@@ -167,6 +167,8 @@ type PromoteChatMember struct {
// CanManageTags Optional. Pass True if the administrator can edit the tags of regular members; for groups
// and supergroups only
CanManageTags bool `json:"can_manage_tags,omitempty"` // Since: Bot API 9.5
// CanSendWelcomeMessages allows the administrator to manage chat welcome messages or send them as a bot.
CanSendWelcomeMessages bool `json:"can_send_welcome_messages,omitempty"` // Since: Bot API 10.3
}
// PromoteChatMember promotes or demotes a user in a chat.
@@ -175,7 +177,7 @@ type PromoteChatMember struct {
// See https://core.telegram.org/bots/api#promotechatmember
func (api *API) PromoteChatMember(params PromoteChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("promoteChatMember", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// PromoteChatMemberWithContext is the context-aware variant of PromoteChatMember.
@@ -184,7 +186,7 @@ func (api *API) PromoteChatMember(params PromoteChatMember) (bool, error) {
// See https://core.telegram.org/bots/api#promotechatmember
func (api *API) PromoteChatMemberWithContext(ctx context.Context, params PromoteChatMember) (bool, error) {
req := NewRequestWithChatID[bool]("promoteChatMember", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatAdministratorCustomTitle holds parameters for the setChatAdministratorCustomTitle method.
@@ -206,7 +208,7 @@ type SetChatAdministratorCustomTitle struct {
// See https://core.telegram.org/bots/api#setchatadministratorcustomtitle
func (api *API) SetChatAdministratorCustomTitle(params SetChatAdministratorCustomTitle) (bool, error) {
req := NewRequestWithChatID[bool]("setChatAdministratorCustomTitle", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetChatAdministratorCustomTitleWithContext is the context-aware variant of SetChatAdministratorCustomTitle.
@@ -215,7 +217,7 @@ func (api *API) SetChatAdministratorCustomTitle(params SetChatAdministratorCusto
// See https://core.telegram.org/bots/api#setchatadministratorcustomtitle
func (api *API) SetChatAdministratorCustomTitleWithContext(ctx context.Context, params SetChatAdministratorCustomTitle) (bool, error) {
req := NewRequestWithChatID[bool]("setChatAdministratorCustomTitle", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatMemberTag holds parameters for the setChatMemberTag method.
@@ -237,7 +239,7 @@ type SetChatMemberTag struct {
// See https://core.telegram.org/bots/api#setchatmembertag
func (api *API) SetChatMemberTag(params SetChatMemberTag) (bool, error) {
req := NewRequestWithChatID[bool]("setChatMemberTag", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetChatMemberTagWithContext is the context-aware variant of SetChatMemberTag.
@@ -246,7 +248,7 @@ func (api *API) SetChatMemberTag(params SetChatMemberTag) (bool, error) {
// See https://core.telegram.org/bots/api#setchatmembertag
func (api *API) SetChatMemberTagWithContext(ctx context.Context, params SetChatMemberTag) (bool, error) {
req := NewRequestWithChatID[bool]("setChatMemberTag", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// BanChatSenderChat holds parameters for the banChatSenderChat method.
@@ -266,7 +268,7 @@ type BanChatSenderChat struct {
// See https://core.telegram.org/bots/api#banchatsenderchat
func (api *API) BanChatSenderChat(params BanChatSenderChat) (bool, error) {
req := NewRequestWithChatID[bool]("banChatSenderChat", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// BanChatSenderChatWithContext is the context-aware variant of BanChatSenderChat.
@@ -275,7 +277,7 @@ func (api *API) BanChatSenderChat(params BanChatSenderChat) (bool, error) {
// See https://core.telegram.org/bots/api#banchatsenderchat
func (api *API) BanChatSenderChatWithContext(ctx context.Context, params BanChatSenderChat) (bool, error) {
req := NewRequestWithChatID[bool]("banChatSenderChat", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnbanChatSenderChat holds parameters for the unbanChatSenderChat method.
@@ -295,7 +297,7 @@ type UnbanChatSenderChat struct {
// See https://core.telegram.org/bots/api#unbanchatsenderchat
func (api *API) UnbanChatSenderChat(params UnbanChatSenderChat) (bool, error) {
req := NewRequestWithChatID[bool]("unbanChatSenderChat", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnbanChatSenderChatWithContext is the context-aware variant of UnbanChatSenderChat.
@@ -304,7 +306,7 @@ func (api *API) UnbanChatSenderChat(params UnbanChatSenderChat) (bool, error) {
// See https://core.telegram.org/bots/api#unbanchatsenderchat
func (api *API) UnbanChatSenderChatWithContext(ctx context.Context, params UnbanChatSenderChat) (bool, error) {
req := NewRequestWithChatID[bool]("unbanChatSenderChat", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatPermissions holds parameters for the setChatPermissions method.
@@ -330,7 +332,7 @@ type SetChatPermissions struct {
// See https://core.telegram.org/bots/api#setchatpermissions
func (api *API) SetChatPermissions(params SetChatPermissions) (bool, error) {
req := NewRequestWithChatID[bool]("setChatPermissions", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetChatPermissionsWithContext is the context-aware variant of SetChatPermissions.
@@ -339,7 +341,7 @@ func (api *API) SetChatPermissions(params SetChatPermissions) (bool, error) {
// See https://core.telegram.org/bots/api#setchatpermissions
func (api *API) SetChatPermissionsWithContext(ctx context.Context, params SetChatPermissions) (bool, error) {
req := NewRequestWithChatID[bool]("setChatPermissions", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ExportChatInviteLink holds parameters for the exportChatInviteLink method.
@@ -357,7 +359,7 @@ type ExportChatInviteLink struct {
// See https://core.telegram.org/bots/api#exportchatinvitelink
func (api *API) ExportChatInviteLink(params ExportChatInviteLink) (string, error) {
req := NewRequestWithChatID[string]("exportChatInviteLink", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ExportChatInviteLinkWithContext is the context-aware variant of ExportChatInviteLink.
@@ -366,7 +368,7 @@ func (api *API) ExportChatInviteLink(params ExportChatInviteLink) (string, error
// See https://core.telegram.org/bots/api#exportchatinvitelink
func (api *API) ExportChatInviteLinkWithContext(ctx context.Context, params ExportChatInviteLink) (string, error) {
req := NewRequestWithChatID[string]("exportChatInviteLink", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CreateChatInviteLink holds parameters for the createChatInviteLink method.
@@ -394,7 +396,7 @@ type CreateChatInviteLink struct {
// See https://core.telegram.org/bots/api#createchatinvitelink
func (api *API) CreateChatInviteLink(params CreateChatInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("createChatInviteLink", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// CreateChatInviteLinkWithContext is the context-aware variant of CreateChatInviteLink.
@@ -403,7 +405,7 @@ func (api *API) CreateChatInviteLink(params CreateChatInviteLink) (ChatInviteLin
// See https://core.telegram.org/bots/api#createchatinvitelink
func (api *API) CreateChatInviteLinkWithContext(ctx context.Context, params CreateChatInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("createChatInviteLink", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditChatInviteLink holds parameters for the editChatInviteLink method.
@@ -434,7 +436,7 @@ type EditChatInviteLink struct {
// See https://core.telegram.org/bots/api#editchatinvitelink
func (api *API) EditChatInviteLink(params EditChatInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("editChatInviteLink", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditChatInviteLinkWithContext is the context-aware variant of EditChatInviteLink.
@@ -443,7 +445,7 @@ func (api *API) EditChatInviteLink(params EditChatInviteLink) (ChatInviteLink, e
// See https://core.telegram.org/bots/api#editchatinvitelink
func (api *API) EditChatInviteLinkWithContext(ctx context.Context, params EditChatInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("editChatInviteLink", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CreateChatSubscriptionInviteLink holds parameters for the createChatSubscriptionInviteLink method.
@@ -469,7 +471,7 @@ type CreateChatSubscriptionInviteLink struct {
// See https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
func (api *API) CreateChatSubscriptionInviteLink(params CreateChatSubscriptionInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("createChatSubscriptionInviteLink", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// CreateChatSubscriptionInviteLinkWithContext is the context-aware variant of CreateChatSubscriptionInviteLink.
@@ -478,7 +480,7 @@ func (api *API) CreateChatSubscriptionInviteLink(params CreateChatSubscriptionIn
// See https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
func (api *API) CreateChatSubscriptionInviteLinkWithContext(ctx context.Context, params CreateChatSubscriptionInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("createChatSubscriptionInviteLink", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditChatSubscriptionInviteLink holds parameters for the editChatSubscriptionInviteLink method.
@@ -500,7 +502,7 @@ type EditChatSubscriptionInviteLink struct {
// See https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
func (api *API) EditChatSubscriptionInviteLink(params EditChatSubscriptionInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("editChatSubscriptionInviteLink", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditChatSubscriptionInviteLinkWithContext is the context-aware variant of EditChatSubscriptionInviteLink.
@@ -509,7 +511,7 @@ func (api *API) EditChatSubscriptionInviteLink(params EditChatSubscriptionInvite
// See https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
func (api *API) EditChatSubscriptionInviteLinkWithContext(ctx context.Context, params EditChatSubscriptionInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("editChatSubscriptionInviteLink", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RevokeChatInviteLink holds parameters for the revokeChatInviteLink method.
@@ -529,7 +531,7 @@ type RevokeChatInviteLink struct {
// See https://core.telegram.org/bots/api#revokechatinvitelink
func (api *API) RevokeChatInviteLink(params RevokeChatInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("revokeChatInviteLink", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// RevokeChatInviteLinkWithContext is the context-aware variant of RevokeChatInviteLink.
@@ -538,7 +540,7 @@ func (api *API) RevokeChatInviteLink(params RevokeChatInviteLink) (ChatInviteLin
// See https://core.telegram.org/bots/api#revokechatinvitelink
func (api *API) RevokeChatInviteLinkWithContext(ctx context.Context, params RevokeChatInviteLink) (ChatInviteLink, error) {
req := NewRequestWithChatID[ChatInviteLink]("revokeChatInviteLink", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ApproveChatJoinRequest holds parameters for the approveChatJoinRequest method.
@@ -558,7 +560,7 @@ type ApproveChatJoinRequest struct {
// See https://core.telegram.org/bots/api#approvechatjoinrequest
func (api *API) ApproveChatJoinRequest(params ApproveChatJoinRequest) (bool, error) {
req := NewRequestWithChatID[bool]("approveChatJoinRequest", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ApproveChatJoinRequestWithContext is the context-aware variant of ApproveChatJoinRequest.
@@ -567,7 +569,7 @@ func (api *API) ApproveChatJoinRequest(params ApproveChatJoinRequest) (bool, err
// See https://core.telegram.org/bots/api#approvechatjoinrequest
func (api *API) ApproveChatJoinRequestWithContext(ctx context.Context, params ApproveChatJoinRequest) (bool, error) {
req := NewRequestWithChatID[bool]("approveChatJoinRequest", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeclineChatJoinRequest holds parameters for the declineChatJoinRequest method.
@@ -587,7 +589,7 @@ type DeclineChatJoinRequest struct {
// See https://core.telegram.org/bots/api#declinechatjoinrequest
func (api *API) DeclineChatJoinRequest(params DeclineChatJoinRequest) (bool, error) {
req := NewRequestWithChatID[bool]("declineChatJoinRequest", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeclineChatJoinRequestWithContext is the context-aware variant of DeclineChatJoinRequest.
@@ -596,7 +598,7 @@ func (api *API) DeclineChatJoinRequest(params DeclineChatJoinRequest) (bool, err
// See https://core.telegram.org/bots/api#declinechatjoinrequest
func (api *API) DeclineChatJoinRequestWithContext(ctx context.Context, params DeclineChatJoinRequest) (bool, error) {
req := NewRequestWithChatID[bool]("declineChatJoinRequest", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ChatJoinRequestQueryResult is the verdict passed to answerChatJoinRequestQuery.
@@ -628,7 +630,7 @@ type AnswerChatJoinRequestQuery struct {
// See https://core.telegram.org/bots/api#answerchatjoinrequestquery
func (api *API) AnswerChatJoinRequestQuery(params AnswerChatJoinRequestQuery) (bool, error) {
req := NewRequest[bool]("answerChatJoinRequestQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerChatJoinRequestQueryWithContext is the context-aware variant of AnswerChatJoinRequestQuery.
@@ -637,7 +639,7 @@ func (api *API) AnswerChatJoinRequestQuery(params AnswerChatJoinRequestQuery) (b
// See https://core.telegram.org/bots/api#answerchatjoinrequestquery
func (api *API) AnswerChatJoinRequestQueryWithContext(ctx context.Context, params AnswerChatJoinRequestQuery) (bool, error) {
req := NewRequest[bool]("answerChatJoinRequestQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendChatJoinRequestWebApp holds parameters for the sendChatJoinRequestWebApp method.
@@ -658,7 +660,7 @@ type SendChatJoinRequestWebApp struct {
// See https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
func (api *API) SendChatJoinRequestWebApp(params SendChatJoinRequestWebApp) (bool, error) {
req := NewRequest[bool]("sendChatJoinRequestWebApp", params)
return req.Do(api)
return api.Do(req)
}
// SendChatJoinRequestWebAppWithContext is the context-aware variant of SendChatJoinRequestWebApp.
@@ -667,7 +669,7 @@ func (api *API) SendChatJoinRequestWebApp(params SendChatJoinRequestWebApp) (boo
// See https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
func (api *API) SendChatJoinRequestWebAppWithContext(ctx context.Context, params SendChatJoinRequestWebApp) (bool, error) {
req := NewRequest[bool]("sendChatJoinRequestWebApp", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatPhoto holds parameters for the setChatPhoto method.
@@ -699,7 +701,7 @@ func (api *API) SetChatPhotoWithContext(ctx context.Context, params SetChatPhoto
_ = uploader.Close()
}()
req := NewUploaderRequestWithChatID[bool]("setChatPhoto", params, params.ChatID, photo.SetType(UploaderPhotoType))
return req.DoWithContext(ctx, uploader)
return uploader.DoWithContext(ctx, req)
}
// DeleteChatPhoto holds parameters for the deleteChatPhoto method.
@@ -717,7 +719,7 @@ type DeleteChatPhoto struct {
// See https://core.telegram.org/bots/api#deletechatphoto
func (api *API) DeleteChatPhoto(params DeleteChatPhoto) (bool, error) {
req := NewRequestWithChatID[bool]("deleteChatPhoto", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeleteChatPhotoWithContext is the context-aware variant of DeleteChatPhoto.
@@ -726,7 +728,7 @@ func (api *API) DeleteChatPhoto(params DeleteChatPhoto) (bool, error) {
// See https://core.telegram.org/bots/api#deletechatphoto
func (api *API) DeleteChatPhotoWithContext(ctx context.Context, params DeleteChatPhoto) (bool, error) {
req := NewRequestWithChatID[bool]("deleteChatPhoto", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatTitle holds parameters for the setChatTitle method.
@@ -746,7 +748,7 @@ type SetChatTitle struct {
// See https://core.telegram.org/bots/api#setchattitle
func (api *API) SetChatTitle(params SetChatTitle) (bool, error) {
req := NewRequestWithChatID[bool]("setChatTitle", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetChatTitleWithContext is the context-aware variant of SetChatTitle.
@@ -755,7 +757,7 @@ func (api *API) SetChatTitle(params SetChatTitle) (bool, error) {
// See https://core.telegram.org/bots/api#setchattitle
func (api *API) SetChatTitleWithContext(ctx context.Context, params SetChatTitle) (bool, error) {
req := NewRequestWithChatID[bool]("setChatTitle", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatDescription holds parameters for the setChatDescription method.
@@ -775,7 +777,7 @@ type SetChatDescription struct {
// See https://core.telegram.org/bots/api#setchatdescription
func (api *API) SetChatDescription(params SetChatDescription) (bool, error) {
req := NewRequestWithChatID[bool]("setChatDescription", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetChatDescriptionWithContext is the context-aware variant of SetChatDescription.
@@ -784,7 +786,7 @@ func (api *API) SetChatDescription(params SetChatDescription) (bool, error) {
// See https://core.telegram.org/bots/api#setchatdescription
func (api *API) SetChatDescriptionWithContext(ctx context.Context, params SetChatDescription) (bool, error) {
req := NewRequestWithChatID[bool]("setChatDescription", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// PinChatMessage holds parameters for the pinChatMessage method.
@@ -810,7 +812,7 @@ type PinChatMessage struct {
// See https://core.telegram.org/bots/api#pinchatmessage
func (api *API) PinChatMessage(params PinChatMessage) (bool, error) {
req := NewRequestWithChatID[bool]("pinChatMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// PinChatMessageWithContext is the context-aware variant of PinChatMessage.
@@ -819,7 +821,7 @@ func (api *API) PinChatMessage(params PinChatMessage) (bool, error) {
// See https://core.telegram.org/bots/api#pinchatmessage
func (api *API) PinChatMessageWithContext(ctx context.Context, params PinChatMessage) (bool, error) {
req := NewRequestWithChatID[bool]("pinChatMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnpinChatMessage holds parameters for the unpinChatMessage method.
@@ -843,7 +845,7 @@ type UnpinChatMessage struct {
// See https://core.telegram.org/bots/api#unpinchatmessage
func (api *API) UnpinChatMessage(params UnpinChatMessage) (bool, error) {
req := NewRequestWithChatID[bool]("unpinChatMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnpinChatMessageWithContext is the context-aware variant of UnpinChatMessage.
@@ -852,7 +854,7 @@ func (api *API) UnpinChatMessage(params UnpinChatMessage) (bool, error) {
// See https://core.telegram.org/bots/api#unpinchatmessage
func (api *API) UnpinChatMessageWithContext(ctx context.Context, params UnpinChatMessage) (bool, error) {
req := NewRequestWithChatID[bool]("unpinChatMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnpinAllChatMessages holds parameters for the unpinAllChatMessages method.
@@ -870,7 +872,7 @@ type UnpinAllChatMessages struct {
// See https://core.telegram.org/bots/api#unpinallchatmessages
func (api *API) UnpinAllChatMessages(params UnpinAllChatMessages) (bool, error) {
req := NewRequestWithChatID[bool]("unpinAllChatMessages", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnpinAllChatMessagesWithContext is the context-aware variant of UnpinAllChatMessages.
@@ -879,7 +881,7 @@ func (api *API) UnpinAllChatMessages(params UnpinAllChatMessages) (bool, error)
// See https://core.telegram.org/bots/api#unpinallchatmessages
func (api *API) UnpinAllChatMessagesWithContext(ctx context.Context, params UnpinAllChatMessages) (bool, error) {
req := NewRequestWithChatID[bool]("unpinAllChatMessages", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// LeaveChat holds parameters for the leaveChat method.
@@ -898,7 +900,7 @@ type LeaveChat struct {
// See https://core.telegram.org/bots/api#leavechat
func (api *API) LeaveChat(params LeaveChat) (bool, error) {
req := NewRequestWithChatID[bool]("leaveChat", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// LeaveChatWithContext is the context-aware variant of LeaveChat.
@@ -907,7 +909,7 @@ func (api *API) LeaveChat(params LeaveChat) (bool, error) {
// See https://core.telegram.org/bots/api#leavechat
func (api *API) LeaveChatWithContext(ctx context.Context, params LeaveChat) (bool, error) {
req := NewRequestWithChatID[bool]("leaveChat", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetChat holds parameters for the getChat method.
@@ -924,7 +926,7 @@ type GetChat struct {
// See https://core.telegram.org/bots/api#getchat
func (api *API) GetChat(params GetChat) (ChatFullInfo, error) {
req := NewRequestWithChatID[ChatFullInfo]("getChat", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetChatWithContext is the context-aware variant of GetChat.
@@ -933,7 +935,7 @@ func (api *API) GetChat(params GetChat) (ChatFullInfo, error) {
// See https://core.telegram.org/bots/api#getchat
func (api *API) GetChatWithContext(ctx context.Context, params GetChat) (ChatFullInfo, error) {
req := NewRequestWithChatID[ChatFullInfo]("getChat", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetChatAdministrators holds parameters for the getChatAdministrators method.
@@ -953,7 +955,7 @@ type GetChatAdministrators struct {
// See https://core.telegram.org/bots/api#getchatadministrators
func (api *API) GetChatAdministrators(params GetChatAdministrators) ([]ChatMember, error) {
req := NewRequestWithChatID[[]ChatMember]("getChatAdministrators", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetChatAdministratorsWithContext is the context-aware variant of GetChatAdministrators.
@@ -962,7 +964,7 @@ func (api *API) GetChatAdministrators(params GetChatAdministrators) ([]ChatMembe
// See https://core.telegram.org/bots/api#getchatadministrators
func (api *API) GetChatAdministratorsWithContext(ctx context.Context, params GetChatAdministrators) ([]ChatMember, error) {
req := NewRequestWithChatID[[]ChatMember]("getChatAdministrators", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetChatMemberCount holds parameters for the getChatMemberCount method.
@@ -979,7 +981,7 @@ type GetChatMemberCount struct {
// See https://core.telegram.org/bots/api#getchatmembercount
func (api *API) GetChatMemberCount(params GetChatMemberCount) (int, error) {
req := NewRequestWithChatID[int]("getChatMemberCount", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetChatMemberCountWithContext is the context-aware variant of GetChatMemberCount.
@@ -988,7 +990,7 @@ func (api *API) GetChatMemberCount(params GetChatMemberCount) (int, error) {
// See https://core.telegram.org/bots/api#getchatmembercount
func (api *API) GetChatMemberCountWithContext(ctx context.Context, params GetChatMemberCount) (int, error) {
req := NewRequestWithChatID[int]("getChatMemberCount", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetChatMember holds parameters for the getChatMember method.
@@ -1007,7 +1009,7 @@ type GetChatMember struct {
// See https://core.telegram.org/bots/api#getchatmember
func (api *API) GetChatMember(params GetChatMember) (ChatMember, error) {
req := NewRequestWithChatID[ChatMember]("getChatMember", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetChatMemberWithContext is the context-aware variant of GetChatMember.
@@ -1016,7 +1018,7 @@ func (api *API) GetChatMember(params GetChatMember) (ChatMember, error) {
// See https://core.telegram.org/bots/api#getchatmember
func (api *API) GetChatMemberWithContext(ctx context.Context, params GetChatMember) (ChatMember, error) {
req := NewRequestWithChatID[ChatMember]("getChatMember", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetChatStickerSet holds parameters for the setChatStickerSet method.
@@ -1036,7 +1038,7 @@ type SetChatStickerSet struct {
// See https://core.telegram.org/bots/api#setchatstickerset
func (api *API) SetChatStickerSet(params SetChatStickerSet) (bool, error) {
req := NewRequestWithChatID[bool]("setChatStickerSet", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetChatStickerSetWithContext is the context-aware variant of SetChatStickerSet.
@@ -1045,7 +1047,7 @@ func (api *API) SetChatStickerSet(params SetChatStickerSet) (bool, error) {
// See https://core.telegram.org/bots/api#setchatstickerset
func (api *API) SetChatStickerSetWithContext(ctx context.Context, params SetChatStickerSet) (bool, error) {
req := NewRequestWithChatID[bool]("setChatStickerSet", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteChatStickerSet holds parameters for the deleteChatStickerSet method.
@@ -1063,7 +1065,7 @@ type DeleteChatStickerSet struct {
// See https://core.telegram.org/bots/api#deletechatstickerset
func (api *API) DeleteChatStickerSet(params DeleteChatStickerSet) (bool, error) {
req := NewRequestWithChatID[bool]("deleteChatStickerSet", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeleteChatStickerSetWithContext is the context-aware variant of DeleteChatStickerSet.
@@ -1072,7 +1074,7 @@ func (api *API) DeleteChatStickerSet(params DeleteChatStickerSet) (bool, error)
// See https://core.telegram.org/bots/api#deletechatstickerset
func (api *API) DeleteChatStickerSetWithContext(ctx context.Context, params DeleteChatStickerSet) (bool, error) {
req := NewRequestWithChatID[bool]("deleteChatStickerSet", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetUserChatBoosts holds parameters for the getUserChatBoosts method.
@@ -1090,7 +1092,7 @@ type GetUserChatBoosts struct {
// See https://core.telegram.org/bots/api#getuserchatboosts
func (api *API) GetUserChatBoosts(params GetUserChatBoosts) (UserChatBoosts, error) {
req := NewRequestWithChatID[UserChatBoosts]("getUserChatBoosts", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetUserChatBoostsWithContext is the context-aware variant of GetUserChatBoosts.
@@ -1099,7 +1101,7 @@ func (api *API) GetUserChatBoosts(params GetUserChatBoosts) (UserChatBoosts, err
// See https://core.telegram.org/bots/api#getuserchatboosts
func (api *API) GetUserChatBoostsWithContext(ctx context.Context, params GetUserChatBoosts) (UserChatBoosts, error) {
req := NewRequestWithChatID[UserChatBoosts]("getUserChatBoosts", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetChatGifts holds parameters for the getChatGifts method.
@@ -1143,7 +1145,7 @@ type GetChatGifts struct {
// See https://core.telegram.org/bots/api#getchatgifts
func (api *API) GetChatGifts(params GetChatGifts) (OwnedGifts, error) {
req := NewRequestWithChatID[OwnedGifts]("getChatGifts", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetChatGiftsWithContext is the context-aware variant of GetChatGifts.
@@ -1152,5 +1154,5 @@ func (api *API) GetChatGifts(params GetChatGifts) (OwnedGifts, error) {
// See https://core.telegram.org/bots/api#getchatgifts
func (api *API) GetChatGiftsWithContext(ctx context.Context, params GetChatGifts) (OwnedGifts, error) {
req := NewRequestWithChatID[OwnedGifts]("getChatGifts", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+13 -2
View File
@@ -90,8 +90,7 @@ type ChatFullInfo struct {
// AvailableReaction Optional. List of available reactions allowed in the chat. If omitted, then all emoji
// reactions are allowed.
// Subject to change in v2: the Go field name may be pluralized to AvailableReactions.
AvailableReaction []ReactionType `json:"available_reactions,omitempty"`
AvailableReactions []ReactionType `json:"available_reactions,omitempty"`
// BackgroundCustomEmojiID Optional. Custom emoji identifier of the emoji chosen by the chat for the reply
// header and link preview background
@@ -358,6 +357,8 @@ type ChatMember struct {
CanEditStories *bool `json:"can_edit_stories,omitempty"` // Since: Bot API 6.9
// CanDeleteStories True, if the administrator can delete stories posted by other users
CanDeleteStories *bool `json:"can_delete_stories,omitempty"` // Since: Bot API 6.9
// CanSendWelcomeMessages reports whether the administrator can manage chat welcome messages or send them as a bot.
CanSendWelcomeMessages *bool `json:"can_send_welcome_messages,omitempty"` // Since: Bot API 10.3
// CanPostMessages Optional. True, if the administrator can post messages in the channel, approve suggested
// posts, or access channel statistics; for channels only
@@ -534,6 +535,8 @@ type ChatAdministratorRights struct {
// CanManageTags Optional. True, if the administrator can edit the tags of regular members; for groups and
// supergroups only. If omitted, defaults to the value of can_pin_messages.
CanManageTags *bool `json:"can_manage_tags,omitempty"`
// CanSendWelcomeMessages reports whether the administrator can manage chat welcome messages or send them as a bot.
CanSendWelcomeMessages *bool `json:"can_send_welcome_messages,omitempty"` // Since: Bot API 10.3
}
// ChatBoostUpdated represents a boost added to a chat or changed.
@@ -578,6 +581,14 @@ type CommunityChatAdded struct {
Community Community `json:"community"`
}
// CommunityChatJoined describes a service message about a chat being joined by a user from a community.
//
// Since: Bot API 10.3
type CommunityChatJoined struct {
// Community contains information about the community from which the user joined the chat.
Community Community `json:"community"`
}
// CommunityChatRemoved describes a service message about a chat leaving a community.
//
// Since: Bot API 10.2
+26 -26
View File
@@ -16,7 +16,7 @@ type BaseForumTopic struct {
// See https://core.telegram.org/bots/api#getforumtopiciconstickers
func (api *API) GetForumTopicIconStickers() ([]Sticker, error) {
req := NewRequest[[]Sticker]("getForumTopicIconStickers", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetForumTopicIconStickersWithContext is the context-aware variant of GetForumTopicIconStickers.
@@ -25,7 +25,7 @@ func (api *API) GetForumTopicIconStickers() ([]Sticker, error) {
// See https://core.telegram.org/bots/api#getforumtopiciconstickers
func (api *API) GetForumTopicIconStickersWithContext(ctx context.Context) ([]Sticker, error) {
req := NewRequest[[]Sticker]("getForumTopicIconStickers", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CreateForumTopic holds parameters for the createForumTopic method.
@@ -52,7 +52,7 @@ type CreateForumTopic struct {
// See https://core.telegram.org/bots/api#createforumtopic
func (api *API) CreateForumTopic(params CreateForumTopic) (ForumTopic, error) {
req := NewRequestWithChatID[ForumTopic]("createForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// CreateForumTopicWithContext is the context-aware variant of CreateForumTopic.
@@ -61,7 +61,7 @@ func (api *API) CreateForumTopic(params CreateForumTopic) (ForumTopic, error) {
// See https://core.telegram.org/bots/api#createforumtopic
func (api *API) CreateForumTopicWithContext(ctx context.Context, params CreateForumTopic) (ForumTopic, error) {
req := NewRequestWithChatID[ForumTopic]("createForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditForumTopic holds parameters for the editForumTopic method.
@@ -84,7 +84,7 @@ type EditForumTopic struct {
// See https://core.telegram.org/bots/api#editforumtopic
func (api *API) EditForumTopic(params EditForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("editForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditForumTopicWithContext is the context-aware variant of EditForumTopic.
@@ -93,7 +93,7 @@ func (api *API) EditForumTopic(params EditForumTopic) (bool, error) {
// See https://core.telegram.org/bots/api#editforumtopic
func (api *API) EditForumTopicWithContext(ctx context.Context, params EditForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("editForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CloseForumTopic closes an open forum topic.
@@ -102,7 +102,7 @@ func (api *API) EditForumTopicWithContext(ctx context.Context, params EditForumT
// See https://core.telegram.org/bots/api#closeforumtopic
func (api *API) CloseForumTopic(params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("closeForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// CloseForumTopicWithContext is the context-aware variant of CloseForumTopic.
@@ -111,7 +111,7 @@ func (api *API) CloseForumTopic(params BaseForumTopic) (bool, error) {
// See https://core.telegram.org/bots/api#closeforumtopic
func (api *API) CloseForumTopicWithContext(ctx context.Context, params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("closeForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ReopenForumTopic reopens a closed forum topic.
@@ -120,7 +120,7 @@ func (api *API) CloseForumTopicWithContext(ctx context.Context, params BaseForum
// See https://core.telegram.org/bots/api#reopenforumtopic
func (api *API) ReopenForumTopic(params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("reopenForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ReopenForumTopicWithContext is the context-aware variant of ReopenForumTopic.
@@ -129,7 +129,7 @@ func (api *API) ReopenForumTopic(params BaseForumTopic) (bool, error) {
// See https://core.telegram.org/bots/api#reopenforumtopic
func (api *API) ReopenForumTopicWithContext(ctx context.Context, params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("reopenForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteForumTopic deletes a forum topic.
@@ -138,7 +138,7 @@ func (api *API) ReopenForumTopicWithContext(ctx context.Context, params BaseForu
// See https://core.telegram.org/bots/api#deleteforumtopic
func (api *API) DeleteForumTopic(params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("deleteForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeleteForumTopicWithContext is the context-aware variant of DeleteForumTopic.
@@ -147,7 +147,7 @@ func (api *API) DeleteForumTopic(params BaseForumTopic) (bool, error) {
// See https://core.telegram.org/bots/api#deleteforumtopic
func (api *API) DeleteForumTopicWithContext(ctx context.Context, params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("deleteForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnpinAllForumTopicMessages clears the list of pinned messages in a forum topic.
@@ -156,7 +156,7 @@ func (api *API) DeleteForumTopicWithContext(ctx context.Context, params BaseForu
// See https://core.telegram.org/bots/api#unpinallforumtopicmessages
func (api *API) UnpinAllForumTopicMessages(params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("unpinAllForumTopicMessages", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnpinAllForumTopicMessagesWithContext is the context-aware variant of UnpinAllForumTopicMessages.
@@ -165,7 +165,7 @@ func (api *API) UnpinAllForumTopicMessages(params BaseForumTopic) (bool, error)
// See https://core.telegram.org/bots/api#unpinallforumtopicmessages
func (api *API) UnpinAllForumTopicMessagesWithContext(ctx context.Context, params BaseForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("unpinAllForumTopicMessages", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// BaseGeneralForumTopic contains common fields for general forum topic operations that require a chat ID.
@@ -192,7 +192,7 @@ type EditGeneralForumTopic struct {
// See https://core.telegram.org/bots/api#editgeneralforumtopic
func (api *API) EditGeneralForumTopic(params EditGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("editGeneralForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditGeneralForumTopicWithContext is the context-aware variant of EditGeneralForumTopic.
@@ -201,7 +201,7 @@ func (api *API) EditGeneralForumTopic(params EditGeneralForumTopic) (bool, error
// See https://core.telegram.org/bots/api#editgeneralforumtopic
func (api *API) EditGeneralForumTopicWithContext(ctx context.Context, params EditGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("editGeneralForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CloseGeneralForumTopic closes the 'General' topic in a forum supergroup.
@@ -210,7 +210,7 @@ func (api *API) EditGeneralForumTopicWithContext(ctx context.Context, params Edi
// See https://core.telegram.org/bots/api#closegeneralforumtopic
func (api *API) CloseGeneralForumTopic(params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("closeGeneralForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// CloseGeneralForumTopicWithContext is the context-aware variant of CloseGeneralForumTopic.
@@ -219,7 +219,7 @@ func (api *API) CloseGeneralForumTopic(params BaseGeneralForumTopic) (bool, erro
// See https://core.telegram.org/bots/api#closegeneralforumtopic
func (api *API) CloseGeneralForumTopicWithContext(ctx context.Context, params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("closeGeneralForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ReopenGeneralForumTopic reopens the 'General' topic in a forum supergroup.
@@ -228,7 +228,7 @@ func (api *API) CloseGeneralForumTopicWithContext(ctx context.Context, params Ba
// See https://core.telegram.org/bots/api#reopengeneralforumtopic
func (api *API) ReopenGeneralForumTopic(params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("reopenGeneralForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ReopenGeneralForumTopicWithContext is the context-aware variant of ReopenGeneralForumTopic.
@@ -237,7 +237,7 @@ func (api *API) ReopenGeneralForumTopic(params BaseGeneralForumTopic) (bool, err
// See https://core.telegram.org/bots/api#reopengeneralforumtopic
func (api *API) ReopenGeneralForumTopicWithContext(ctx context.Context, params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("reopenGeneralForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// HideGeneralForumTopic hides the 'General' topic in a forum supergroup.
@@ -246,7 +246,7 @@ func (api *API) ReopenGeneralForumTopicWithContext(ctx context.Context, params B
// See https://core.telegram.org/bots/api#hidegeneralforumtopic
func (api *API) HideGeneralForumTopic(params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("hideGeneralForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// HideGeneralForumTopicWithContext is the context-aware variant of HideGeneralForumTopic.
@@ -255,7 +255,7 @@ func (api *API) HideGeneralForumTopic(params BaseGeneralForumTopic) (bool, error
// See https://core.telegram.org/bots/api#hidegeneralforumtopic
func (api *API) HideGeneralForumTopicWithContext(ctx context.Context, params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("hideGeneralForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnhideGeneralForumTopic unhides the 'General' topic in a forum supergroup.
@@ -264,7 +264,7 @@ func (api *API) HideGeneralForumTopicWithContext(ctx context.Context, params Bas
// See https://core.telegram.org/bots/api#unhidegeneralforumtopic
func (api *API) UnhideGeneralForumTopic(params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("unhideGeneralForumTopic", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnhideGeneralForumTopicWithContext is the context-aware variant of UnhideGeneralForumTopic.
@@ -273,7 +273,7 @@ func (api *API) UnhideGeneralForumTopic(params BaseGeneralForumTopic) (bool, err
// See https://core.telegram.org/bots/api#unhidegeneralforumtopic
func (api *API) UnhideGeneralForumTopicWithContext(ctx context.Context, params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("unhideGeneralForumTopic", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UnpinAllGeneralForumTopicMessages clears the list of pinned messages in the 'General' topic.
@@ -282,7 +282,7 @@ func (api *API) UnhideGeneralForumTopicWithContext(ctx context.Context, params B
// See https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
func (api *API) UnpinAllGeneralForumTopicMessages(params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("unpinAllGeneralForumTopicMessages", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// UnpinAllGeneralForumTopicMessagesWithContext is the context-aware variant of UnpinAllGeneralForumTopicMessages.
@@ -291,5 +291,5 @@ func (api *API) UnpinAllGeneralForumTopicMessages(params BaseGeneralForumTopic)
// See https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
func (api *API) UnpinAllGeneralForumTopicMessagesWithContext(ctx context.Context, params BaseGeneralForumTopic) (bool, error) {
req := NewRequestWithChatID[bool]("unpinAllGeneralForumTopicMessages", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+8 -8
View File
@@ -44,7 +44,7 @@ type SendGame struct {
// See https://core.telegram.org/bots/api#sendgame
func (api *API) SendGame(params SendGame) (Message, error) {
req := NewRequestWithChatID[Message]("sendGame", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendGameWithContext is the context-aware variant of SendGame.
@@ -53,7 +53,7 @@ func (api *API) SendGame(params SendGame) (Message, error) {
// See https://core.telegram.org/bots/api#sendgame
func (api *API) SendGameWithContext(ctx context.Context, params SendGame) (Message, error) {
req := NewRequestWithChatID[Message]("sendGame", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetGameScore holds parameters for the setGameScore method.
@@ -88,11 +88,11 @@ func (api *API) SetGameScore(params SetGameScore) (Message, bool, error) {
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("setGameScore", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("setGameScore", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -104,11 +104,11 @@ func (api *API) SetGameScoreWithContext(ctx context.Context, params SetGameScore
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("setGameScore", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("setGameScore", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -132,7 +132,7 @@ type GetGameHighScores struct {
// See https://core.telegram.org/bots/api#getgamehighscores
func (api *API) GetGameHighScores(params GetGameHighScores) ([]GameHighScore, error) {
req := NewRequestWithChatID[[]GameHighScore]("getGameHighScores", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// GetGameHighScoresWithContext is the context-aware variant of GetGameHighScores.
@@ -141,5 +141,5 @@ func (api *API) GetGameHighScores(params GetGameHighScores) ([]GameHighScore, er
// See https://core.telegram.org/bots/api#getgamehighscores
func (api *API) GetGameHighScoresWithContext(ctx context.Context, params GetGameHighScores) ([]GameHighScore, error) {
req := NewRequestWithChatID[[]GameHighScore]("getGameHighScores", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+8 -8
View File
@@ -30,7 +30,7 @@ type AnswerInlineQuery struct {
// See https://core.telegram.org/bots/api#answerinlinequery
func (api *API) AnswerInlineQuery(params AnswerInlineQuery) (bool, error) {
req := NewRequest[bool]("answerInlineQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerInlineQueryWithContext is the context-aware variant of AnswerInlineQuery.
@@ -39,7 +39,7 @@ func (api *API) AnswerInlineQuery(params AnswerInlineQuery) (bool, error) {
// See https://core.telegram.org/bots/api#answerinlinequery
func (api *API) AnswerInlineQueryWithContext(ctx context.Context, params AnswerInlineQuery) (bool, error) {
req := NewRequest[bool]("answerInlineQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// AnswerWebAppQuery holds parameters for the answerWebAppQuery method.
@@ -57,7 +57,7 @@ type AnswerWebAppQuery struct {
// See https://core.telegram.org/bots/api#answerwebappquery
func (api *API) AnswerWebAppQuery(params AnswerWebAppQuery) (SentWebAppMessage, error) {
req := NewRequest[SentWebAppMessage]("answerWebAppQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerWebAppQueryWithContext is the context-aware variant of AnswerWebAppQuery.
@@ -66,7 +66,7 @@ func (api *API) AnswerWebAppQuery(params AnswerWebAppQuery) (SentWebAppMessage,
// See https://core.telegram.org/bots/api#answerwebappquery
func (api *API) AnswerWebAppQueryWithContext(ctx context.Context, params AnswerWebAppQuery) (SentWebAppMessage, error) {
req := NewRequest[SentWebAppMessage]("answerWebAppQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SavePreparedInlineMessage holds parameters for the savePreparedInlineMessage method.
@@ -92,7 +92,7 @@ type SavePreparedInlineMessage struct {
// See https://core.telegram.org/bots/api#savepreparedinlinemessage
func (api *API) SavePreparedInlineMessage(params SavePreparedInlineMessage) (PreparedInlineMessage, error) {
req := NewRequest[PreparedInlineMessage]("savePreparedInlineMessage", params)
return req.Do(api)
return api.Do(req)
}
// SavePreparedInlineMessageWithContext is the context-aware variant of SavePreparedInlineMessage.
@@ -101,7 +101,7 @@ func (api *API) SavePreparedInlineMessage(params SavePreparedInlineMessage) (Pre
// See https://core.telegram.org/bots/api#savepreparedinlinemessage
func (api *API) SavePreparedInlineMessageWithContext(ctx context.Context, params SavePreparedInlineMessage) (PreparedInlineMessage, error) {
req := NewRequest[PreparedInlineMessage]("savePreparedInlineMessage", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SavePreparedKeyboardButton holds parameters for the savePreparedKeyboardButton method.
@@ -120,7 +120,7 @@ type SavePreparedKeyboardButton struct {
// See https://core.telegram.org/bots/api#savepreparedkeyboardbutton
func (api *API) SavePreparedKeyboardButton(params SavePreparedKeyboardButton) (PreparedKeyboardButton, error) {
req := NewRequest[PreparedKeyboardButton]("savePreparedKeyboardButton", params)
return req.Do(api)
return api.Do(req)
}
// SavePreparedKeyboardButtonWithContext is the context-aware variant of SavePreparedKeyboardButton.
@@ -129,5 +129,5 @@ func (api *API) SavePreparedKeyboardButton(params SavePreparedKeyboardButton) (P
// See https://core.telegram.org/bots/api#savepreparedkeyboardbutton
func (api *API) SavePreparedKeyboardButtonWithContext(ctx context.Context, params SavePreparedKeyboardButton) (PreparedKeyboardButton, error) {
req := NewRequest[PreparedKeyboardButton]("savePreparedKeyboardButton", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+112 -116
View File
@@ -18,10 +18,8 @@ type SendMessage struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int64 `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Text Required. Text of the message to be sent, 1-4096 characters after entities parsing
Text string `json:"text"`
@@ -62,7 +60,7 @@ type SendMessage struct {
// See https://core.telegram.org/bots/api#sendmessage
func (api *API) SendMessage(params SendMessage) (Message, error) {
req := NewRequestWithChatID[Message]("sendMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendMessageWithContext is the context-aware variant of SendMessage.
@@ -71,7 +69,7 @@ func (api *API) SendMessage(params SendMessage) (Message, error) {
// See https://core.telegram.org/bots/api#sendmessage
func (api *API) SendMessageWithContext(ctx context.Context, params SendMessage) (Message, error) {
req := NewRequestWithChatID[Message]("sendMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ForwardMessage holds parameters for the forwardMessage method.
@@ -114,7 +112,7 @@ type ForwardMessage struct {
// See https://core.telegram.org/bots/api#forwardmessage
func (api *API) ForwardMessage(params ForwardMessage) (Message, error) {
req := NewRequestWithChatID[Message]("forwardMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ForwardMessageWithContext is the context-aware variant of ForwardMessage.
@@ -123,7 +121,7 @@ func (api *API) ForwardMessage(params ForwardMessage) (Message, error) {
// See https://core.telegram.org/bots/api#forwardmessage
func (api *API) ForwardMessageWithContext(ctx context.Context, params ForwardMessage) (Message, error) {
req := NewRequestWithChatID[Message]("forwardMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ForwardMessages holds parameters for the forwardMessages method.
@@ -159,7 +157,7 @@ type ForwardMessages struct {
// See https://core.telegram.org/bots/api#forwardmessages
func (api *API) ForwardMessages(params ForwardMessages) ([]MessageID, error) {
req := NewRequestWithChatID[[]MessageID]("forwardMessages", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ForwardMessagesWithContext is the context-aware variant of ForwardMessages.
@@ -168,7 +166,7 @@ func (api *API) ForwardMessages(params ForwardMessages) ([]MessageID, error) {
// See https://core.telegram.org/bots/api#forwardmessages
func (api *API) ForwardMessagesWithContext(ctx context.Context, params ForwardMessages) ([]MessageID, error) {
req := NewRequestWithChatID[[]MessageID]("forwardMessages", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CopyMessage holds parameters for the copyMessage method.
@@ -234,7 +232,7 @@ type CopyMessage struct {
// Returns the MessageID of the sent copy.
// See https://core.telegram.org/bots/api#copymessage
func (api *API) CopyMessage(params CopyMessage) (int, error) {
msgID, err := NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID).Do(api)
msgID, err := api.Do(NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID))
if err != nil {
return 0, err
}
@@ -246,7 +244,7 @@ func (api *API) CopyMessage(params CopyMessage) (int, error) {
// It executes the same request but uses ctx for cancellation and deadlines.
// See https://core.telegram.org/bots/api#copymessage
func (api *API) CopyMessageWithContext(ctx context.Context, params CopyMessage) (int, error) {
msgID, err := NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID).DoWithContext(ctx, api)
msgID, err := api.DoWithContext(ctx, NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID))
if err != nil {
return 0, err
}
@@ -288,7 +286,7 @@ type CopyMessages struct {
// See https://core.telegram.org/bots/api#copymessages
func (api *API) CopyMessages(params CopyMessages) ([]MessageID, error) {
req := NewRequestWithChatID[[]MessageID]("copyMessages", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// CopyMessagesWithContext is the context-aware variant of CopyMessages.
@@ -297,7 +295,7 @@ func (api *API) CopyMessages(params CopyMessages) ([]MessageID, error) {
// See https://core.telegram.org/bots/api#copymessages
func (api *API) CopyMessagesWithContext(ctx context.Context, params CopyMessages) ([]MessageID, error) {
req := NewRequestWithChatID[[]MessageID]("copyMessages", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendLocation holds parameters for the sendLocation method.
@@ -316,10 +314,8 @@ type SendLocation struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Latitude Required. Latitude of the location
Latitude float64 `json:"latitude"`
@@ -367,7 +363,7 @@ type SendLocation struct {
// See https://core.telegram.org/bots/api#sendlocation
func (api *API) SendLocation(params SendLocation) (Message, error) {
req := NewRequestWithChatID[Message]("sendLocation", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendLocationWithContext is the context-aware variant of SendLocation.
@@ -376,7 +372,7 @@ func (api *API) SendLocation(params SendLocation) (Message, error) {
// See https://core.telegram.org/bots/api#sendlocation
func (api *API) SendLocationWithContext(ctx context.Context, params SendLocation) (Message, error) {
req := NewRequestWithChatID[Message]("sendLocation", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendVenue holds parameters for the sendVenue method.
@@ -395,10 +391,8 @@ type SendVenue struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Latitude Required. Latitude of the venue
Latitude float64 `json:"latitude"`
@@ -447,7 +441,7 @@ type SendVenue struct {
// See https://core.telegram.org/bots/api#sendvenue
func (api *API) SendVenue(params SendVenue) (Message, error) {
req := NewRequestWithChatID[Message]("sendVenue", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendVenueWithContext is the context-aware variant of SendVenue.
@@ -456,7 +450,7 @@ func (api *API) SendVenue(params SendVenue) (Message, error) {
// See https://core.telegram.org/bots/api#sendvenue
func (api *API) SendVenueWithContext(ctx context.Context, params SendVenue) (Message, error) {
req := NewRequestWithChatID[Message]("sendVenue", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendContact holds parameters for the sendContact method.
@@ -475,10 +469,8 @@ type SendContact struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// PhoneNumber Required. Contact's phone number
PhoneNumber string `json:"phone_number"`
@@ -518,7 +510,7 @@ type SendContact struct {
// See https://core.telegram.org/bots/api#sendcontact
func (api *API) SendContact(params SendContact) (Message, error) {
req := NewRequestWithChatID[Message]("sendContact", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendContactWithContext is the context-aware variant of SendContact.
@@ -527,7 +519,7 @@ func (api *API) SendContact(params SendContact) (Message, error) {
// See https://core.telegram.org/bots/api#sendcontact
func (api *API) SendContactWithContext(ctx context.Context, params SendContact) (Message, error) {
req := NewRequestWithChatID[Message]("sendContact", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendPoll holds parameters for the sendPoll method.
@@ -638,7 +630,7 @@ type SendPoll struct {
// See https://core.telegram.org/bots/api#sendpoll
func (api *API) SendPoll(params SendPoll) (Message, error) {
req := NewRequestWithChatID[Message]("sendPoll", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendPollWithContext is the context-aware variant of SendPoll.
@@ -647,7 +639,7 @@ func (api *API) SendPoll(params SendPoll) (Message, error) {
// See https://core.telegram.org/bots/api#sendpoll
func (api *API) SendPollWithContext(ctx context.Context, params SendPoll) (Message, error) {
req := NewRequestWithChatID[Message]("sendPoll", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendChecklist holds parameters for the sendChecklist method.
@@ -682,7 +674,7 @@ type SendChecklist struct {
// See https://core.telegram.org/bots/api#sendchecklist
func (api *API) SendChecklist(params SendChecklist) (Message, error) {
req := NewRequestWithChatID[Message]("sendChecklist", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendChecklistWithContext is the context-aware variant of SendChecklist.
@@ -691,7 +683,7 @@ func (api *API) SendChecklist(params SendChecklist) (Message, error) {
// See https://core.telegram.org/bots/api#sendchecklist
func (api *API) SendChecklistWithContext(ctx context.Context, params SendChecklist) (Message, error) {
req := NewRequestWithChatID[Message]("sendChecklist", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendDice holds parameters for the sendDice method.
@@ -745,7 +737,7 @@ type SendDice struct {
// See https://core.telegram.org/bots/api#senddice
func (api *API) SendDice(params SendDice) (Message, error) {
req := NewRequestWithChatID[Message]("sendDice", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendDiceWithContext is the context-aware variant of SendDice.
@@ -754,7 +746,7 @@ func (api *API) SendDice(params SendDice) (Message, error) {
// See https://core.telegram.org/bots/api#senddice
func (api *API) SendDiceWithContext(ctx context.Context, params SendDice) (Message, error) {
req := NewRequestWithChatID[Message]("sendDice", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendMessageDraft holds parameters for the sendMessageDraft method.
@@ -777,6 +769,11 @@ type SendMessageDraft struct {
// Entities Optional. A JSON-serialized list of special entities that appear in message text, which can be
// specified instead of parse_mode
Entities []MessageEntity `json:"entities,omitempty"`
// CanStop allows the user to stop message generation while the draft is shown.
CanStop bool `json:"can_stop,omitempty"` // Since: Bot API 10.3
// KeepOnStop preserves the draft as an ephemeral message when generation is stopped.
KeepOnStop bool `json:"keep_on_stop,omitempty"` // Since: Bot API 10.3
}
// SendMessageDraft sends or updates a draft message in the target chat.
@@ -785,7 +782,7 @@ type SendMessageDraft struct {
// See https://core.telegram.org/bots/api#sendmessagedraft
func (api *API) SendMessageDraft(params SendMessageDraft) (bool, error) {
req := NewRequestWithChatID[bool]("sendMessageDraft", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendMessageDraftWithContext is the context-aware variant of SendMessageDraft.
@@ -794,7 +791,7 @@ func (api *API) SendMessageDraft(params SendMessageDraft) (bool, error) {
// See https://core.telegram.org/bots/api#sendmessagedraft
func (api *API) SendMessageDraftWithContext(ctx context.Context, params SendMessageDraft) (bool, error) {
req := NewRequestWithChatID[bool]("sendMessageDraft", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendChatAction holds parameters for the sendChatAction method.
@@ -823,7 +820,7 @@ type SendChatAction struct {
// See https://core.telegram.org/bots/api#sendchataction
func (api *API) SendChatAction(params SendChatAction) (bool, error) {
req := NewRequestWithChatID[bool]("sendChatAction", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendChatActionWithContext is the context-aware variant of SendChatAction.
@@ -832,7 +829,7 @@ func (api *API) SendChatAction(params SendChatAction) (bool, error) {
// See https://core.telegram.org/bots/api#sendchataction
func (api *API) SendChatActionWithContext(ctx context.Context, params SendChatAction) (bool, error) {
req := NewRequestWithChatID[bool]("sendChatAction", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetMessageReaction holds parameters for the setMessageReaction method.
@@ -860,7 +857,7 @@ type SetMessageReaction struct {
// See https://core.telegram.org/bots/api#setmessagereaction
func (api *API) SetMessageReaction(params SetMessageReaction) (bool, error) {
req := NewRequestWithChatID[bool]("setMessageReaction", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SetMessageReactionWithContext is the context-aware variant of SetMessageReaction.
@@ -869,7 +866,7 @@ func (api *API) SetMessageReaction(params SetMessageReaction) (bool, error) {
// See https://core.telegram.org/bots/api#setmessagereaction
func (api *API) SetMessageReactionWithContext(ctx context.Context, params SetMessageReaction) (bool, error) {
req := NewRequestWithChatID[bool]("setMessageReaction", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditMessageText holds parameters for the editMessageText method.
@@ -913,11 +910,11 @@ func (api *API) EditMessageText(params EditMessageText) (Message, bool, error) {
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageText", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageText", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -929,11 +926,11 @@ func (api *API) EditMessageTextWithContext(ctx context.Context, params EditMessa
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageText", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageText", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -976,11 +973,11 @@ func (api *API) EditMessageCaption(params EditMessageCaption) (Message, bool, er
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageCaption", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageCaption", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -992,11 +989,11 @@ func (api *API) EditMessageCaptionWithContext(ctx context.Context, params EditMe
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageCaption", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageCaption", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -1030,11 +1027,11 @@ func (api *API) EditMessageMedia(params EditMessageMedia) (Message, bool, error)
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageMedia", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageMedia", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -1046,11 +1043,11 @@ func (api *API) EditMessageMediaWithContext(ctx context.Context, params EditMess
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageMedia", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageMedia", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -1100,11 +1097,11 @@ func (api *API) EditMessageLiveLocation(params EditMessageLiveLocation) (Message
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageLiveLocation", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageLiveLocation", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -1116,11 +1113,11 @@ func (api *API) EditMessageLiveLocationWithContext(ctx context.Context, params E
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageLiveLocation", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageLiveLocation", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -1153,11 +1150,11 @@ func (api *API) StopMessageLiveLocation(params StopMessageLiveLocation) (Message
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("stopMessageLiveLocation", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("stopMessageLiveLocation", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -1169,11 +1166,11 @@ func (api *API) StopMessageLiveLocationWithContext(ctx context.Context, params S
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("stopMessageLiveLocation", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("stopMessageLiveLocation", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -1200,7 +1197,7 @@ type EditMessageChecklist struct {
// See https://core.telegram.org/bots/api#editmessagechecklist
func (api *API) EditMessageChecklist(params EditMessageChecklist) (Message, error) {
req := NewRequestWithChatID[Message]("editMessageChecklist", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditMessageChecklistWithContext is the context-aware variant of EditMessageChecklist.
@@ -1209,7 +1206,7 @@ func (api *API) EditMessageChecklist(params EditMessageChecklist) (Message, erro
// See https://core.telegram.org/bots/api#editmessagechecklist
func (api *API) EditMessageChecklistWithContext(ctx context.Context, params EditMessageChecklist) (Message, error) {
req := NewRequestWithChatID[Message]("editMessageChecklist", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditMessageReplyMarkup holds parameters for the editMessageReplyMarkup method.
@@ -1240,11 +1237,11 @@ func (api *API) EditMessageReplyMarkup(params EditMessageReplyMarkup) (Message,
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageReplyMarkup", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageReplyMarkup", params, params.ChatID)
res, err := req.Do(api)
res, err := api.Do(req)
return res, false, err
}
@@ -1256,11 +1253,11 @@ func (api *API) EditMessageReplyMarkupWithContext(ctx context.Context, params Ed
var zero Message
if params.InlineMessageID != "" {
req := NewRequestWithChatID[bool]("editMessageReplyMarkup", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return zero, res, err
}
req := NewRequestWithChatID[Message]("editMessageReplyMarkup", params, params.ChatID)
res, err := req.DoWithContext(ctx, api)
res, err := api.DoWithContext(ctx, req)
return res, false, err
}
@@ -1286,7 +1283,7 @@ type StopPoll struct {
// See https://core.telegram.org/bots/api#stoppoll
func (api *API) StopPoll(params StopPoll) (Poll, error) {
req := NewRequestWithChatID[Poll]("stopPoll", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// StopPollWithContext is the context-aware variant of StopPoll.
@@ -1295,7 +1292,7 @@ func (api *API) StopPoll(params StopPoll) (Poll, error) {
// See https://core.telegram.org/bots/api#stoppoll
func (api *API) StopPollWithContext(ctx context.Context, params StopPoll) (Poll, error) {
req := NewRequestWithChatID[Poll]("stopPoll", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ApproveSuggestedPost holds parameters for the approveSuggestedPost method.
@@ -1318,7 +1315,7 @@ type ApproveSuggestedPost struct {
// See https://core.telegram.org/bots/api#approvesuggestedpost
func (api *API) ApproveSuggestedPost(params ApproveSuggestedPost) (bool, error) {
req := NewRequestWithChatID[bool]("approveSuggestedPost", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// ApproveSuggestedPostWithContext is the context-aware variant of ApproveSuggestedPost.
@@ -1327,7 +1324,7 @@ func (api *API) ApproveSuggestedPost(params ApproveSuggestedPost) (bool, error)
// See https://core.telegram.org/bots/api#approvesuggestedpost
func (api *API) ApproveSuggestedPostWithContext(ctx context.Context, params ApproveSuggestedPost) (bool, error) {
req := NewRequestWithChatID[bool]("approveSuggestedPost", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeclineSuggestedPost holds parameters for the declineSuggestedPost method.
@@ -1348,7 +1345,7 @@ type DeclineSuggestedPost struct {
// See https://core.telegram.org/bots/api#declinesuggestedpost
func (api *API) DeclineSuggestedPost(params DeclineSuggestedPost) (bool, error) {
req := NewRequestWithChatID[bool]("declineSuggestedPost", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeclineSuggestedPostWithContext is the context-aware variant of DeclineSuggestedPost.
@@ -1357,7 +1354,7 @@ func (api *API) DeclineSuggestedPost(params DeclineSuggestedPost) (bool, error)
// See https://core.telegram.org/bots/api#declinesuggestedpost
func (api *API) DeclineSuggestedPostWithContext(ctx context.Context, params DeclineSuggestedPost) (bool, error) {
req := NewRequestWithChatID[bool]("declineSuggestedPost", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteMessage holds parameters for the deleteMessage method.
@@ -1377,7 +1374,7 @@ type DeleteMessage struct {
// See https://core.telegram.org/bots/api#deletemessage
func (api *API) DeleteMessage(params DeleteMessage) (bool, error) {
req := NewRequestWithChatID[bool]("deleteMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeleteMessageWithContext is the context-aware variant of DeleteMessage.
@@ -1386,7 +1383,7 @@ func (api *API) DeleteMessage(params DeleteMessage) (bool, error) {
// See https://core.telegram.org/bots/api#deletemessage
func (api *API) DeleteMessageWithContext(ctx context.Context, params DeleteMessage) (bool, error) {
req := NewRequestWithChatID[bool]("deleteMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteMessages holds parameters for the deleteMessages method.
@@ -1407,7 +1404,7 @@ type DeleteMessages struct {
// See https://core.telegram.org/bots/api#deletemessages
func (api *API) DeleteMessages(params DeleteMessages) (bool, error) {
req := NewRequestWithChatID[bool]("deleteMessages", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeleteMessagesWithContext is the context-aware variant of DeleteMessages.
@@ -1416,7 +1413,7 @@ func (api *API) DeleteMessages(params DeleteMessages) (bool, error) {
// See https://core.telegram.org/bots/api#deletemessages
func (api *API) DeleteMessagesWithContext(ctx context.Context, params DeleteMessages) (bool, error) {
req := NewRequestWithChatID[bool]("deleteMessages", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// AnswerCallbackQuery holds parameters for the answerCallbackQuery method.
@@ -1447,7 +1444,7 @@ type AnswerCallbackQuery struct {
// See https://core.telegram.org/bots/api#answercallbackquery
func (api *API) AnswerCallbackQuery(params AnswerCallbackQuery) (bool, error) {
req := NewRequest[bool]("answerCallbackQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerCallbackQueryWithContext is the context-aware variant of AnswerCallbackQuery.
@@ -1456,7 +1453,7 @@ func (api *API) AnswerCallbackQuery(params AnswerCallbackQuery) (bool, error) {
// See https://core.telegram.org/bots/api#answercallbackquery
func (api *API) AnswerCallbackQueryWithContext(ctx context.Context, params AnswerCallbackQuery) (bool, error) {
req := NewRequest[bool]("answerCallbackQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// AnswerGuestQuery holds parameters for the answerGuestQuery method.
@@ -1474,7 +1471,7 @@ type AnswerGuestQuery struct {
// See https://core.telegram.org/bots/api#answerguestquery
func (api *API) AnswerGuestQuery(params AnswerGuestQuery) (SentGuestMessage, error) {
req := NewRequest[SentGuestMessage]("answerGuestQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerGuestQueryWithContext is the context-aware variant of AnswerGuestQuery.
@@ -1483,7 +1480,7 @@ func (api *API) AnswerGuestQuery(params AnswerGuestQuery) (SentGuestMessage, err
// See https://core.telegram.org/bots/api#answerguestquery
func (api *API) AnswerGuestQueryWithContext(ctx context.Context, params AnswerGuestQuery) (SentGuestMessage, error) {
req := NewRequest[SentGuestMessage]("answerGuestQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteAllMessageReactions holds parameters for the deleteAllMessageReactions method.
@@ -1507,18 +1504,7 @@ type DeleteAllMessageReactions struct {
// See https://core.telegram.org/bots/api#deleteallmessagereactions
func (api *API) DeleteAllMessageReactions(params DeleteAllMessageReactions) (bool, error) {
req := NewRequest[bool]("deleteAllMessageReactions", params)
return req.Do(api)
}
// DeleteAllMessageReactionWithContext is the context-aware variant of DeleteAllMessageReactions.
//
// Deprecated: use DeleteAllMessageReactionsWithContext. The misspelled alias is
// retained for v1 compatibility and is subject to removal in v2.
// Since: Bot API 10.0
// It executes the same request but uses ctx for cancellation and deadlines.
// See https://core.telegram.org/bots/api#deleteallmessagereactions
func (api *API) DeleteAllMessageReactionWithContext(ctx context.Context, params DeleteAllMessageReactions) (bool, error) {
return api.DeleteAllMessageReactionsWithContext(ctx, params)
return api.Do(req)
}
// DeleteAllMessageReactionsWithContext is the context-aware variant of DeleteAllMessageReactions.
@@ -1527,7 +1513,7 @@ func (api *API) DeleteAllMessageReactionWithContext(ctx context.Context, params
// See https://core.telegram.org/bots/api#deleteallmessagereactions
func (api *API) DeleteAllMessageReactionsWithContext(ctx context.Context, params DeleteAllMessageReactions) (bool, error) {
req := NewRequest[bool]("deleteAllMessageReactions", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteMessageReaction holds parameters for the deleteMessageReaction method.
@@ -1553,7 +1539,7 @@ type DeleteMessageReaction struct {
// See https://core.telegram.org/bots/api#deletemessagereaction
func (api *API) DeleteMessageReaction(params DeleteMessageReaction) (bool, error) {
req := NewRequest[bool]("deleteMessageReaction", params)
return req.Do(api)
return api.Do(req)
}
// DeleteMessageReactionWithContext is the context-aware variant of DeleteMessageReaction.
@@ -1562,7 +1548,7 @@ func (api *API) DeleteMessageReaction(params DeleteMessageReaction) (bool, error
// See https://core.telegram.org/bots/api#deletemessagereaction
func (api *API) DeleteMessageReactionWithContext(ctx context.Context, params DeleteMessageReaction) (bool, error) {
req := NewRequest[bool]("deleteMessageReaction", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendRichMessage holds parameters for the sendRichMessage method.
@@ -1578,6 +1564,8 @@ type SendRichMessage struct {
// DirectMessagesTopicID identifies the target direct-messages topic.
DirectMessagesTopicID int64 `json:"direct_messages_topic_id,omitempty"`
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// RichMessage contains structured rich-message content.
RichMessage InputRichMessage `json:"rich_message"`
// DisableNotification requests delivery without a notification sound.
@@ -1601,7 +1589,7 @@ type SendRichMessage struct {
// See https://core.telegram.org/bots/api#sendrichmessage
func (api *API) SendRichMessage(params SendRichMessage) (Message, error) {
req := NewRequestWithChatID[Message]("sendRichMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendRichMessageWithContext is the context-aware variant of SendRichMessage.
@@ -1610,7 +1598,7 @@ func (api *API) SendRichMessage(params SendRichMessage) (Message, error) {
// See https://core.telegram.org/bots/api#sendrichmessage
func (api *API) SendRichMessageWithContext(ctx context.Context, params SendRichMessage) (Message, error) {
req := NewRequestWithChatID[Message]("sendRichMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SendRichMessageDraft holds parameters for the sendRichMessageDraft method.
@@ -1626,6 +1614,11 @@ type SendRichMessageDraft struct {
DraftID int64 `json:"draft_id"`
// RichMessage contains structured rich-message content.
RichMessage InputRichMessage `json:"rich_message"`
// CanStop allows the user to stop message generation while the draft is shown.
CanStop bool `json:"can_stop,omitempty"` // Since: Bot API 10.3
// KeepOnStop preserves the draft as an ephemeral message when generation is stopped.
KeepOnStop bool `json:"keep_on_stop,omitempty"` // Since: Bot API 10.3
}
// SendRichMessageDraft streams a partial rich message to a private chat while
@@ -1636,7 +1629,7 @@ type SendRichMessageDraft struct {
// See https://core.telegram.org/bots/api#sendrichmessagedraft
func (api *API) SendRichMessageDraft(params SendRichMessageDraft) (bool, error) {
req := NewRequestWithChatID[bool]("sendRichMessageDraft", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendRichMessageDraftWithContext is the context-aware variant of SendRichMessageDraft.
@@ -1645,7 +1638,7 @@ func (api *API) SendRichMessageDraft(params SendRichMessageDraft) (bool, error)
// See https://core.telegram.org/bots/api#sendrichmessagedraft
func (api *API) SendRichMessageDraftWithContext(ctx context.Context, params SendRichMessageDraft) (bool, error) {
req := NewRequestWithChatID[bool]("sendRichMessageDraft", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditEphemeralMessageText holds parameters for editing an ephemeral text message.
@@ -1659,12 +1652,13 @@ type EditEphemeralMessageText struct {
// EphemeralMessageID identifies the ephemeral message.
EphemeralMessageID int64 `json:"ephemeral_message_id"`
// Text contains the formatted or plain text content.
Text string `json:"text"`
Text string `json:"text,omitempty"`
// ParseMode selects the formatting syntax used by the text or caption.
ParseMode ParseMode `json:"parse_mode,omitempty"`
// Entities describes explicit formatting entities in Text.
Entities []MessageEntity `json:"entities,omitempty"`
Entities []MessageEntity `json:"entities,omitempty"`
RichMessage *InputRichMessage `json:"rich_message,omitempty"` // Since: Bot API 10.3
// LinkPreviewOptions controls link preview generation for Text.
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
// ReplyMarkup defines the message's inline keyboard.
@@ -1676,7 +1670,7 @@ type EditEphemeralMessageText struct {
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageText(params EditEphemeralMessageText) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageText", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditEphemeralMessageTextWithContext is the context-aware variant of EditEphemeralMessageText.
@@ -1684,11 +1678,11 @@ func (api *API) EditEphemeralMessageText(params EditEphemeralMessageText) (bool,
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageTextWithContext(ctx context.Context, params EditEphemeralMessageText) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageText", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditEphemeralMessageMedia holds parameters for editing ephemeral message media.
// New files cannot be uploaded; use a file ID or URL.
// Use Uploader.EditEphemeralMessageMedia to upload files referenced through attach:// names.
//
// Since: Bot API 10.2
type EditEphemeralMessageMedia struct {
@@ -1709,7 +1703,7 @@ type EditEphemeralMessageMedia struct {
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageMedia(params EditEphemeralMessageMedia) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageMedia", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditEphemeralMessageMediaWithContext is the context-aware variant of EditEphemeralMessageMedia.
@@ -1717,7 +1711,7 @@ func (api *API) EditEphemeralMessageMedia(params EditEphemeralMessageMedia) (boo
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageMediaWithContext(ctx context.Context, params EditEphemeralMessageMedia) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageMedia", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditEphemeralMessageCaption holds parameters for editing an ephemeral message caption.
@@ -1733,6 +1727,8 @@ type EditEphemeralMessageCaption struct {
// Caption contains the media or block caption.
Caption string `json:"caption,omitempty"`
// ShowCaptionAboveMedia places the caption above the media.
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Since: Bot API 10.3
// ParseMode selects the formatting syntax used by the text or caption.
ParseMode ParseMode `json:"parse_mode,omitempty"`
// CaptionEntities describes formatting entities in Caption.
@@ -1746,7 +1742,7 @@ type EditEphemeralMessageCaption struct {
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageCaption(params EditEphemeralMessageCaption) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageCaption", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditEphemeralMessageCaptionWithContext is the context-aware variant of EditEphemeralMessageCaption.
@@ -1754,7 +1750,7 @@ func (api *API) EditEphemeralMessageCaption(params EditEphemeralMessageCaption)
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageCaptionWithContext(ctx context.Context, params EditEphemeralMessageCaption) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageCaption", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditEphemeralMessageReplyMarkup holds parameters for editing an ephemeral message's inline keyboard.
@@ -1776,7 +1772,7 @@ type EditEphemeralMessageReplyMarkup struct {
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageReplyMarkup(params EditEphemeralMessageReplyMarkup) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageReplyMarkup", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// EditEphemeralMessageReplyMarkupWithContext is the context-aware variant of EditEphemeralMessageReplyMarkup.
@@ -1784,7 +1780,7 @@ func (api *API) EditEphemeralMessageReplyMarkup(params EditEphemeralMessageReply
// Since: Bot API 10.2
func (api *API) EditEphemeralMessageReplyMarkupWithContext(ctx context.Context, params EditEphemeralMessageReplyMarkup) (bool, error) {
req := NewRequestWithChatID[bool]("editEphemeralMessageReplyMarkup", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteEphemeralMessage holds parameters for deleting an ephemeral message.
@@ -1804,7 +1800,7 @@ type DeleteEphemeralMessage struct {
// Since: Bot API 10.2
func (api *API) DeleteEphemeralMessage(params DeleteEphemeralMessage) (bool, error) {
req := NewRequestWithChatID[bool]("deleteEphemeralMessage", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// DeleteEphemeralMessageWithContext is the context-aware variant of DeleteEphemeralMessage.
@@ -1812,5 +1808,5 @@ func (api *API) DeleteEphemeralMessage(params DeleteEphemeralMessage) (bool, err
// Since: Bot API 10.2
func (api *API) DeleteEphemeralMessageWithContext(ctx context.Context, params DeleteEphemeralMessage) (bool, error) {
req := NewRequestWithChatID[bool]("deleteEphemeralMessage", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+64 -2
View File
@@ -423,6 +423,8 @@ type Message struct {
ChecklistTasksAdded *ChecklistTasksAdded `json:"checklist_tasks_added,omitempty"` // Since: Bot API 9.1
// CommunityChatAdded describes a community chat addition service message.
CommunityChatAdded *CommunityChatAdded `json:"community_chat_added,omitempty"` // Since: Bot API 10.2
// CommunityChatJoined Optional. Service message: a chat was joined by a user from a community.
CommunityChatJoined *CommunityChatJoined `json:"community_chat_joined,omitempty"` // Since: Bot API 10.3
// CommunityChatRemoved describes a community chat removal service message.
CommunityChatRemoved *CommunityChatRemoved `json:"community_chat_removed,omitempty"` // Since: Bot API 10.2
// DirectMessagePriceChanged Optional. Service message: the price for paid messages in the corresponding
@@ -683,8 +685,7 @@ type ReplyParameters struct {
Quote string `json:"quote,omitempty"`
// QuoteParsingMode Optional. Mode for parsing entities in the quote. See formatting options for more
// details.
// Subject to change in v2: the Go field name may be corrected to QuoteParseMode.
QuoteParsingMode string `json:"quote_parse_mode,omitempty"`
QuoteParseMode string `json:"quote_parse_mode,omitempty"`
// QuoteEntities Optional. A JSON-serialized list of special entities that appear in the quote. It can be
// specified instead of quote_parse_mode.
QuoteEntities []MessageEntity `json:"quote_entities,omitempty"`
@@ -758,6 +759,8 @@ type ReplyMarkup struct {
type InlineKeyboardMarkup struct {
// InlineKeyboard Array of button rows, each represented by an Array of InlineKeyboardButton objects
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard,omitempty"`
// ForceReply opens the reply interface for the user.
ForceReply bool `json:"force_reply,omitempty"` // Since: Bot API 10.3
}
// KeyboardButtonStyle represents the style of a keyboard button.
@@ -916,6 +919,8 @@ type InlineKeyboardButton struct {
// by the bot to private, group and supergroup chats if the owner of the bot has a Telegram Premium
// subscription.
IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"` // Since: Bot API 9.4
// Disabled makes the button do nothing. It must be the button's only action.
Disabled *DisabledButton `json:"disabled,omitempty"` // Since: Bot API 10.3
}
// ReplyKeyboardMarkup represents a custom keyboard with reply options.
@@ -945,6 +950,8 @@ type ReplyKeyboardMarkup struct {
// change the bot's language, bot replies to the request with a keyboard to select the new language. Other
// users in the group don't see the keyboard.
Selective bool `json:"selective,omitempty"`
// ForceReply opens the reply interface for the user.
ForceReply bool `json:"force_reply,omitempty"` // Since: Bot API 10.3
}
// CallbackQuery represents an incoming callback query from a callback button in an inline keyboard.
@@ -970,6 +977,49 @@ type CallbackQuery struct {
GameShortName string `json:"game_short_name,omitempty"`
}
// LoginURL configures HTTPS authorization through Telegram Login.
//
// Since: Bot API 4.3
type LoginURL struct {
// URL is the HTTPS authorization destination with a domain linked to the bot.
URL string `json:"url"`
// ForwardText optionally replaces the button label in forwarded messages.
ForwardText string `json:"forward_text,omitempty"`
// BotUsername optionally selects the authorization bot; unsupported in rich buttons.
BotUsername string `json:"bot_username,omitempty"`
// RequestWriteAccess asks permission for the bot to message the user.
RequestWriteAccess bool `json:"request_write_access,omitempty"`
}
// SwitchInlineQueryChosenChat restricts the chat picker for an inline query.
//
// Since: Bot API 6.7
type SwitchInlineQueryChosenChat struct {
// Query is the initial query; an empty value inserts only the bot username.
Query string `json:"query,omitempty"`
// AllowUserChats permits private chats with users.
AllowUserChats bool `json:"allow_user_chats,omitempty"`
// AllowBotChats permits private chats with bots.
AllowBotChats bool `json:"allow_bot_chats,omitempty"`
// AllowGroupChats permits groups and supergroups.
AllowGroupChats bool `json:"allow_group_chats,omitempty"`
// AllowChannelChats permits channels.
AllowChannelChats bool `json:"allow_channel_chats,omitempty"`
}
// CopyTextButton describes text copied to the clipboard when pressed.
//
// Since: Bot API 7.11
type CopyTextButton struct {
// Text contains 1-256 characters to copy.
Text string `json:"text"`
}
// DisabledButton represents a button without an action.
//
// Since: Bot API 10.3
type DisabledButton struct{}
// ChatActionType represents the type of chat action.
type ChatActionType string
@@ -1288,3 +1338,15 @@ type InputRichMessage struct {
// SkipEntityDetection disables automatic detection of links, mentions, hashtags, commands, phone numbers, and bank cards.
SkipEntityDetection bool `json:"skip_entity_detection,omitempty"`
}
// EphemeralMessageParameters identifies the recipient and callback context of an ephemeral message.
//
// Since: Bot API 10.3
type EphemeralMessageParameters struct {
// ReceiverUserID identifies the user who may receive the message.
ReceiverUserID int64 `json:"receiver_user_id"`
// CallbackQueryID identifies the callback query that triggered the message.
CallbackQueryID string `json:"callback_query_id,omitempty"`
// ReplaceCallbackQueryMessage shows the ephemeral message in place of the original callback message.
ReplaceCallbackQueryMessage bool `json:"replace_callback_query_message,omitempty"`
}
+21 -50
View File
@@ -7,7 +7,7 @@ import (
"math"
"net/http"
"git.scuroneko.dev/scuroneko/laniakea/utils"
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
)
// UpdateParams holds parameters for the getUpdates method.
@@ -38,7 +38,7 @@ type UpdateParams struct {
// See https://core.telegram.org/bots/api#getme
func (api *API) GetMe() (User, error) {
req := NewRequest[User]("getMe", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetMeWithContext is the context-aware variant of GetMe.
@@ -46,7 +46,7 @@ func (api *API) GetMe() (User, error) {
// See https://core.telegram.org/bots/api#getme
func (api *API) GetMeWithContext(ctx context.Context) (User, error) {
req := NewRequest[User]("getMe", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetManagedBotToken holds parameters for the getManagedBotToken method.
@@ -60,7 +60,7 @@ type GetManagedBotToken struct {
// See https://core.telegram.org/bots/api#getmanagedbottoken
func (api *API) GetManagedBotToken(params GetManagedBotToken) (string, error) {
req := NewRequest[string]("getManagedBotToken", params)
return req.Do(api)
return api.Do(req)
}
// GetManagedBotTokenWithContext is the context-aware variant of GetManagedBotToken.
@@ -68,7 +68,7 @@ func (api *API) GetManagedBotToken(params GetManagedBotToken) (string, error) {
// See https://core.telegram.org/bots/api#getmanagedbottoken
func (api *API) GetManagedBotTokenWithContext(ctx context.Context, params GetManagedBotToken) (string, error) {
req := NewRequest[string]("getManagedBotToken", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ReplaceManagedBotToken holds parameters for the replaceManagedBotToken method.
@@ -82,7 +82,7 @@ type ReplaceManagedBotToken struct {
// See https://core.telegram.org/bots/api#replacemanagedbottoken
func (api *API) ReplaceManagedBotToken(params ReplaceManagedBotToken) (string, error) {
req := NewRequest[string]("replaceManagedBotToken", params)
return req.Do(api)
return api.Do(req)
}
// ReplaceManagedBotTokenWithContext is the context-aware variant of ReplaceManagedBotToken.
@@ -90,7 +90,7 @@ func (api *API) ReplaceManagedBotToken(params ReplaceManagedBotToken) (string, e
// See https://core.telegram.org/bots/api#replacemanagedbottoken
func (api *API) ReplaceManagedBotTokenWithContext(ctx context.Context, params ReplaceManagedBotToken) (string, error) {
req := NewRequest[string]("replaceManagedBotToken", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// LogOut logs the bot out from the cloud Bot API server.
@@ -98,7 +98,7 @@ func (api *API) ReplaceManagedBotTokenWithContext(ctx context.Context, params Re
// See https://core.telegram.org/bots/api#logout
func (api *API) LogOut() (bool, error) {
req := NewRequest[bool]("logOut", NoParams)
return req.Do(api)
return api.Do(req)
}
// LogOutWithContext is the context-aware variant of LogOut.
@@ -106,7 +106,7 @@ func (api *API) LogOut() (bool, error) {
// See https://core.telegram.org/bots/api#logout
func (api *API) LogOutWithContext(ctx context.Context) (bool, error) {
req := NewRequest[bool]("logOut", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CloseRemote closes the bot instance on the local server.
@@ -114,7 +114,7 @@ func (api *API) LogOutWithContext(ctx context.Context) (bool, error) {
// See https://core.telegram.org/bots/api#close
func (api *API) CloseRemote() (bool, error) {
req := NewRequest[bool]("close", NoParams)
return req.Do(api)
return api.Do(req)
}
// CloseRemoteWithContext is the context-aware variant of CloseRemote.
@@ -122,14 +122,14 @@ func (api *API) CloseRemote() (bool, error) {
// See https://core.telegram.org/bots/api#close
func (api *API) CloseRemoteWithContext(ctx context.Context) (bool, error) {
req := NewRequest[bool]("close", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetUpdates receives incoming updates using long polling.
// See https://core.telegram.org/bots/api#getupdates
func (api *API) GetUpdates(params UpdateParams) ([]Update, error) {
req := NewRequest[[]Update]("getUpdates", params)
return req.Do(api)
return api.Do(req)
}
// GetUpdatesWithContext is the context-aware variant of GetUpdates.
@@ -137,7 +137,7 @@ func (api *API) GetUpdates(params UpdateParams) ([]Update, error) {
// See https://core.telegram.org/bots/api#getupdates
func (api *API) GetUpdatesWithContext(ctx context.Context, params UpdateParams) ([]Update, error) {
req := NewRequest[[]Update]("getUpdates", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetWebhook holds parameters for the setWebhook method.
@@ -175,7 +175,7 @@ type SetWebhook struct {
// See https://core.telegram.org/bots/api#setwebhook
func (api *API) SetWebhook(params SetWebhook) (bool, error) {
req := NewRequest[bool]("setWebhook", params)
return req.Do(api)
return api.Do(req)
}
// SetWebhookWithContext is the context-aware variant of SetWebhook.
@@ -184,7 +184,7 @@ func (api *API) SetWebhook(params SetWebhook) (bool, error) {
// See https://core.telegram.org/bots/api#setwebhook
func (api *API) SetWebhookWithContext(ctx context.Context, params SetWebhook) (bool, error) {
req := NewRequest[bool]("setWebhook", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteWebhook holds parameters for the deleteWebhook method.
@@ -199,7 +199,7 @@ type DeleteWebhook struct {
// See https://core.telegram.org/bots/api#deletewebhook
func (api *API) DeleteWebhook(params DeleteWebhook) (bool, error) {
req := NewRequest[bool]("deleteWebhook", params)
return req.Do(api)
return api.Do(req)
}
// DeleteWebhookWithContext is the context-aware variant of DeleteWebhook.
@@ -207,14 +207,14 @@ func (api *API) DeleteWebhook(params DeleteWebhook) (bool, error) {
// See https://core.telegram.org/bots/api#deletewebhook
func (api *API) DeleteWebhookWithContext(ctx context.Context, params DeleteWebhook) (bool, error) {
req := NewRequest[bool]("deleteWebhook", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetWebhookInfo returns the current webhook status.
// See https://core.telegram.org/bots/api#getwebhookinfo
func (api *API) GetWebhookInfo() (WebhookInfo, error) {
req := NewRequest[WebhookInfo]("getWebhookInfo", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetWebhookInfoWithContext is the context-aware variant of GetWebhookInfo.
@@ -222,7 +222,7 @@ func (api *API) GetWebhookInfo() (WebhookInfo, error) {
// See https://core.telegram.org/bots/api#getwebhookinfo
func (api *API) GetWebhookInfoWithContext(ctx context.Context) (WebhookInfo, error) {
req := NewRequest[WebhookInfo]("getWebhookInfo", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetFile holds parameters for the getFile method.
@@ -236,7 +236,7 @@ type GetFile struct {
// See https://core.telegram.org/bots/api#getfile
func (api *API) GetFile(params GetFile) (File, error) {
req := NewRequest[File]("getFile", params)
return req.Do(api)
return api.Do(req)
}
// GetFileWithContext is the context-aware variant of GetFile.
@@ -244,25 +244,7 @@ func (api *API) GetFile(params GetFile) (File, error) {
// See https://core.telegram.org/bots/api#getfile
func (api *API) GetFileWithContext(ctx context.Context, params GetFile) (File, error) {
req := NewRequest[File]("getFile", params)
return req.DoWithContext(ctx, api)
}
// GetFileByLink downloads a file from Telegram's file server using the provided file link.
// The link is usually obtained from File.FilePath.
// For large files, prefer OpenFileByLink or OpenFileByLinkWithContext to stream the response body.
// This unbounded helper is retained for v1 compatibility and is subject to change in v2;
// prefer GetFileByLinkLimit for untrusted or potentially large files.
// See https://core.telegram.org/bots/api#file
func (api *API) GetFileByLink(link string) ([]byte, error) {
return api.getFileByLink(context.Background(), link)
}
// GetFileByLinkWithContext is the context-aware variant of GetFileByLink.
// It executes the same request but uses ctx for cancellation and deadlines.
// For large files, prefer OpenFileByLinkWithContext to stream the response body.
// See https://core.telegram.org/bots/api#file
func (api *API) GetFileByLinkWithContext(ctx context.Context, link string) ([]byte, error) {
return api.getFileByLink(ctx, link)
return api.DoWithContext(ctx, req)
}
// GetFileByLinkLimit downloads at most maxBytes from Telegram's file server.
@@ -310,17 +292,6 @@ func (api *API) OpenFileByLinkWithContext(ctx context.Context, link string) (io.
return api.openFileByLink(ctx, link)
}
func (api *API) getFileByLink(ctx context.Context, link string) ([]byte, error) {
body, err := api.openFileByLink(ctx, link)
if err != nil {
return nil, err
}
defer func() {
_ = body.Close()
}()
return io.ReadAll(body)
}
func (api *API) openFileByLink(ctx context.Context, link string) (io.ReadCloser, error) {
methodPrefix := ""
if api.useTestServer {
+5 -5
View File
@@ -9,7 +9,7 @@ import (
"testing"
)
func TestGetFileByLinkUsesConfiguredAPIURL(t *testing.T) {
func TestGetFileByLinkLimitUsesConfiguredAPIURL(t *testing.T) {
var gotPath string
client := &http.Client{
@@ -33,9 +33,9 @@ func TestGetFileByLinkUsesConfiguredAPIURL(t *testing.T) {
}
}()
data, err := api.GetFileByLink("files/report.txt")
data, err := api.GetFileByLinkLimit("files/report.txt", 1024)
if err != nil {
t.Fatalf("GetFileByLink returned error: %v", err)
t.Fatalf("GetFileByLinkLimit returned error: %v", err)
}
if string(data) != "payload" {
t.Fatalf("unexpected payload: %q", string(data))
@@ -83,7 +83,7 @@ func TestOpenFileByLinkStreamsResponseBody(t *testing.T) {
}
}
func TestGetFileByLinkReturnsHTTPStatusError(t *testing.T) {
func TestGetFileByLinkLimitReturnsHTTPStatusError(t *testing.T) {
client := &http.Client{
Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{
@@ -104,7 +104,7 @@ func TestGetFileByLinkReturnsHTTPStatusError(t *testing.T) {
}
}()
_, err := api.GetFileByLink("files/report.txt")
_, err := api.GetFileByLinkLimit("files/report.txt", 1024)
if err == nil {
t.Fatal("expected error for non-2xx response")
}
+32
View File
@@ -0,0 +1,32 @@
package tgapi
import (
"context"
"testing"
)
func TestV2MigrationSurfaceCompiles(t *testing.T) {
answer := PollAnswer{User: &User{ID: 1}}
if answer.User == nil {
t.Fatal("poll voter is missing")
}
_ = ChatFullInfo{AvailableReactions: []ReactionType{}}
_ = ReplyParameters{QuoteParseMode: string(ParseHTML)}
_ = InputChecklist{OthersCanAddTasks: true, OthersCanMarkTasksAsDone: true}
_ = SendMessage{EphemeralMessageParameters: &EphemeralMessageParameters{ReceiverUserID: 1}}
request := NewRequest[bool]("customMethod", NoParams)
upload := NewUploaderRequest[bool]("customUpload", NoParams)
var api *API
var uploader *Uploader
if false {
_, _ = api.Do(request)
_, _ = api.DoWithContext(context.Background(), request)
_, _ = uploader.Do(upload)
_, _ = uploader.DoWithContext(context.Background(), upload)
_, _ = api.DeleteAllMessageReactions(DeleteAllMessageReactions{})
_, _ = api.GetFileByLinkLimit("file/path", 1<<20)
_, _ = api.OpenFileByLinkWithContext(context.Background(), "file/path")
}
}
+2 -2
View File
@@ -18,7 +18,7 @@ type SetPassportDataErrors struct {
// See https://core.telegram.org/bots/api#setpassportdataerrors
func (api *API) SetPassportDataErrors(params SetPassportDataErrors) (bool, error) {
req := NewRequest[bool]("setPassportDataErrors", params)
return req.Do(api)
return api.Do(req)
}
// SetPassportDataErrorsWithContext is the context-aware variant of SetPassportDataErrors.
@@ -27,5 +27,5 @@ func (api *API) SetPassportDataErrors(params SetPassportDataErrors) (bool, error
// See https://core.telegram.org/bots/api#setpassportdataerrors
func (api *API) SetPassportDataErrorsWithContext(ctx context.Context, params SetPassportDataErrors) (bool, error) {
req := NewRequest[bool]("setPassportDataErrors", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+8 -8
View File
@@ -111,7 +111,7 @@ type SendInvoice struct {
// See https://core.telegram.org/bots/api#sendinvoice
func (api *API) SendInvoice(params SendInvoice) (Message, error) {
req := NewRequestWithChatID[Message]("sendInvoice", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendInvoiceWithContext is the context-aware variant of SendInvoice.
@@ -120,7 +120,7 @@ func (api *API) SendInvoice(params SendInvoice) (Message, error) {
// See https://core.telegram.org/bots/api#sendinvoice
func (api *API) SendInvoiceWithContext(ctx context.Context, params SendInvoice) (Message, error) {
req := NewRequestWithChatID[Message]("sendInvoice", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CreateInvoiceLink holds parameters for the createInvoiceLink method.
@@ -205,7 +205,7 @@ type CreateInvoiceLink struct {
// See https://core.telegram.org/bots/api#createinvoicelink
func (api *API) CreateInvoiceLink(params CreateInvoiceLink) (string, error) {
req := NewRequest[string]("createInvoiceLink", params)
return req.Do(api)
return api.Do(req)
}
// CreateInvoiceLinkWithContext is the context-aware variant of CreateInvoiceLink.
@@ -214,7 +214,7 @@ func (api *API) CreateInvoiceLink(params CreateInvoiceLink) (string, error) {
// See https://core.telegram.org/bots/api#createinvoicelink
func (api *API) CreateInvoiceLinkWithContext(ctx context.Context, params CreateInvoiceLink) (string, error) {
req := NewRequest[string]("createInvoiceLink", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// AnswerShippingQuery holds parameters for the answerShippingQuery method.
@@ -240,7 +240,7 @@ type AnswerShippingQuery struct {
// See https://core.telegram.org/bots/api#answershippingquery
func (api *API) AnswerShippingQuery(params AnswerShippingQuery) (bool, error) {
req := NewRequest[bool]("answerShippingQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerShippingQueryWithContext is the context-aware variant of AnswerShippingQuery.
@@ -249,7 +249,7 @@ func (api *API) AnswerShippingQuery(params AnswerShippingQuery) (bool, error) {
// See https://core.telegram.org/bots/api#answershippingquery
func (api *API) AnswerShippingQueryWithContext(ctx context.Context, params AnswerShippingQuery) (bool, error) {
req := NewRequest[bool]("answerShippingQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// AnswerPreCheckoutQuery holds parameters for the answerPreCheckoutQuery method.
@@ -274,7 +274,7 @@ type AnswerPreCheckoutQuery struct {
// See https://core.telegram.org/bots/api#answerprecheckoutquery
func (api *API) AnswerPreCheckoutQuery(params AnswerPreCheckoutQuery) (bool, error) {
req := NewRequest[bool]("answerPreCheckoutQuery", params)
return req.Do(api)
return api.Do(req)
}
// AnswerPreCheckoutQueryWithContext is the context-aware variant of AnswerPreCheckoutQuery.
@@ -283,5 +283,5 @@ func (api *API) AnswerPreCheckoutQuery(params AnswerPreCheckoutQuery) (bool, err
// See https://core.telegram.org/bots/api#answerprecheckoutquery
func (api *API) AnswerPreCheckoutQueryWithContext(ctx context.Context, params AnswerPreCheckoutQuery) (bool, error) {
req := NewRequest[bool]("answerPreCheckoutQuery", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+156
View File
@@ -0,0 +1,156 @@
package tgapi
import (
"encoding/json"
"io"
"mime"
"mime/multipart"
"reflect"
"strings"
"testing"
)
func TestRich103RoundTrip(t *testing.T) {
for _, tc := range []struct {
name, data string
want any
}{
{"inline button", `{"blocks":[{"type":"paragraph","text":{"type":"button","button":{"text":["Go",{"type":"custom_emoji","custom_emoji_id":"123","alternative_text":"!"}],"switch_inline_query":""}}}]}`, RichBlockWrap{}},
{"button row", `{"blocks":[{"type":"buttons","align":"right","buttons":[{"text":"Go","switch_inline_query_current_chat":""},{"text":"Choose","switch_inline_query_chosen_chat":{"query":"x","allow_user_chats":true}}]}]}`, RichBlockButtons{}},
{"expandable quote", `{"blocks":[{"type":"expandable_blockquote","text":{"type":"bold","text":"quote"},"credit":"source"}]}`, RichBlockExpandableBlockQuotation{}},
{"document", `{"blocks":[{"type":"document","document":{"file_id":"file","file_unique_id":"unique","file_name":"notes.txt"},"caption":{"text":"Notes","credit":"Author"}}]}`, RichBlockDocument{}},
{"compact table", `{"blocks":[{"type":"table","cells":[],"is_compact":true}]}`, RichBlockTable{}},
} {
t.Run(tc.name, func(t *testing.T) {
msg, err := UnmarshalRichMessage([]byte(tc.data))
if err != nil {
t.Fatal(err)
}
if reflect.TypeOf(msg.Blocks[0]) != reflect.TypeOf(tc.want) {
t.Fatalf("got %T", msg.Blocks[0])
}
data, err := json.Marshal(msg)
if err != nil {
t.Fatal(err)
}
// Compare the second decode to avoid unrelated omitted zero-value media fields.
again, err := UnmarshalRichMessage(data)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(msg, again) {
t.Fatalf("round trip lost data: %s", data)
}
if strings.Contains(tc.data, `"switch_inline_query":""`) && !strings.Contains(string(data), `"switch_inline_query":""`) {
t.Fatalf("lost empty query: %s", data)
}
})
}
}
func TestRichButtonActionsRoundTrip(t *testing.T) {
for _, action := range []string{
`"url":"https://example.com"`, `"callback_data":"callback","style":"link"`,
`"web_app":{"url":"https://example.com"}`, `"login_url":{"url":"https://example.com","forward_text":"Forward","request_write_access":true}`,
`"switch_inline_query":""`, `"switch_inline_query_current_chat":""`,
`"switch_inline_query_chosen_chat":{"allow_user_chats":true}`, `"copy_text":{"text":"Copy"}`, `"disabled":{}`,
} {
raw := `{"text":"Button",` + action + `}`
var button RichMessageButton
if err := json.Unmarshal([]byte(raw), &button); err != nil {
t.Fatal(err)
}
encoded, err := json.Marshal(button)
if err != nil {
t.Fatal(err)
}
var expected, actual any
if err := json.Unmarshal([]byte(raw), &expected); err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(encoded, &actual); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("wire fields changed: %s -> %s", raw, encoded)
}
var again RichMessageButton
if err := json.Unmarshal(encoded, &again); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(button, again) {
t.Fatalf("action lost: %s", encoded)
}
if button.Text != RichTextPlain("Button") {
t.Fatalf("label lost: %#v", button)
}
}
}
func TestRich103Malformed(t *testing.T) {
for _, raw := range []string{
`{"type":"button","button":{"text":null,"disabled":{}}}`,
} {
if _, err := UnmarshalRichText([]byte(raw)); err == nil {
t.Fatalf("accepted %s", raw)
}
}
for _, raw := range []string{
`{"type":"buttons","buttons":[{"text":null,"disabled":{}}]}`,
`{"type":"document","document":42}`,
} {
if _, err := UnmarshalRichBlock([]byte(raw)); err == nil {
t.Fatalf("accepted %s", raw)
}
}
raw := `"x"`
for range 70 {
raw = `{"type":"button","button":{"text":` + raw + `,"disabled":{}}}`
}
if _, err := UnmarshalRichText([]byte(raw)); err == nil {
t.Fatal("accepted excessive nesting")
}
}
func TestRichDocumentMultipart(t *testing.T) {
params := SendRichMessage{ChatID: 42, RichMessage: InputRichMessage{
HTML: `<tg-document src="tg://document?id=notes"></tg-document>`,
Media: []InputRichMessageMedia{{ID: "notes", Media: InputMedia{Type: InputMediaTypeDocument, Media: "attach://notes"}}},
}}
body, contentType := prepareMultipartStream([]UploaderFile{NewUploaderFile("notes.txt", []byte("hello")).SetAttachName("notes")}, params)
defer func() { _ = body.Close() }()
_, attrs, err := mime.ParseMediaType(contentType)
if err != nil {
t.Fatal(err)
}
reader := multipart.NewReader(body, attrs["boundary"])
gotFile, gotMessage := false, false
for {
part, err := reader.NextPart()
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
data, err := io.ReadAll(part)
if err != nil {
t.Fatal(err)
}
switch part.FormName() {
case "notes":
gotFile = true
if part.FileName() != "notes.txt" || string(data) != "hello" {
t.Fatalf("bad file part: %s", data)
}
case "rich_message":
gotMessage = true
if !strings.Contains(string(data), `"media":"attach://notes"`) || !strings.Contains(string(data), `"type":"document"`) {
t.Fatalf("bad rich payload: %s", data)
}
}
}
if !gotFile || !gotMessage {
t.Fatal("missing multipart parts")
}
}
+103 -3
View File
@@ -2,6 +2,20 @@ package tgapi
import "encoding/json"
// RichBlockButtonAlign selects horizontal alignment of a button row.
//
// Since: Bot API 10.3
type RichBlockButtonAlign string
const (
// RichBlockButtonLeft aligns buttons to left.
RichBlockButtonLeft RichBlockButtonAlign = "left"
// RichBlockButtonCenter aligns buttons to center.
RichBlockButtonCenter RichBlockButtonAlign = "center"
// RichBlockButtonRight aligns buttons to right.
RichBlockButtonRight RichBlockButtonAlign = "right"
)
// RichBlock is a block in a structured rich message.
//
// Since: Bot API 10.1
@@ -9,6 +23,22 @@ type RichBlock interface {
isRichBlock()
}
// RichBlockUnknown preserves an unrecognized rich-block object for lossless forwarding.
type RichBlockUnknown struct {
// Raw contains the complete JSON object received from Telegram.
Raw json.RawMessage
}
func (RichBlockUnknown) isRichBlock() {}
// MarshalJSON implements json.Marshaler.
func (u RichBlockUnknown) MarshalJSON() ([]byte, error) {
if !json.Valid(u.Raw) {
return nil, errInvalidUnknownRichJSON
}
return append([]byte(nil), u.Raw...), nil
}
// RichBlockCaption is the caption of a media block or container.
//
// Since: Bot API 10.1
@@ -385,6 +415,8 @@ type RichBlockTable struct {
IsBordered bool
// IsStriped requests alternating table row styling.
IsStriped bool
// IsCompact requests smaller table-cell padding.
IsCompact bool // Since: Bot API 10.3
// Caption contains the media or block caption.
Caption RichText
}
@@ -400,8 +432,9 @@ func (b RichBlockTable) MarshalJSON() ([]byte, error) {
Cells [][]RichBlockTableCell `json:"cells"`
IsBordered bool `json:"is_bordered,omitempty"`
IsStriped bool `json:"is_striped,omitempty"`
IsCompact bool `json:"is_compact,omitempty"`
Caption RichText `json:"caption,omitempty"`
}{"table", b.Cells, b.IsBordered, b.IsStriped, b.Caption})
}{"table", b.Cells, b.IsBordered, b.IsStriped, b.IsCompact, b.Caption})
}
// RichBlockMap is a location map block.
@@ -420,8 +453,6 @@ type RichBlockMap struct {
Caption *RichBlockCaption
}
func (RichBlockMap) isRichBlock() {}
// MarshalJSON implements json.Marshaler.
//
// Since: Bot API 10.1
@@ -435,6 +466,29 @@ func (b RichBlockMap) MarshalJSON() ([]byte, error) {
Caption *RichBlockCaption `json:"caption,omitempty"`
}{"map", b.Location, b.Zoom, b.Width, b.Height, b.Caption})
}
func (RichBlockMap) isRichBlock() {}
// RichBlockButtons is a row of buttons corresponding to <tg-button-row>.
//
// Since: Bot API 10.3
type RichBlockButtons struct {
// Buttons contains the row contents.
Buttons []RichMessageButton `json:"buttons"`
// Align optionally selects left, center, or right alignment.
Align RichBlockButtonAlign `json:"align,omitempty"`
}
// MarshalJSON adds the buttons type discriminator.
//
// Since: Bot API 10.3
func (b RichBlockButtons) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Type string `json:"type"`
Buttons []RichMessageButton `json:"buttons"`
Align RichBlockButtonAlign `json:"align,omitempty"`
}{"buttons", b.Buttons, b.Align})
}
func (RichBlockButtons) isRichBlock() {}
// RichBlockPhoto is a photo block.
//
@@ -615,3 +669,49 @@ func (b RichBlockAnchor) MarshalJSON() ([]byte, error) {
Name string `json:"name"`
}{"anchor", b.Name})
}
// RichBlockExpandableBlockQuotation corresponds to <blockquote expandable>.
//
// Since: Bot API 10.3
type RichBlockExpandableBlockQuotation struct {
// Text is the quotation content.
Text RichText `json:"text"`
// Credit optionally identifies the source.
Credit RichText `json:"credit,omitempty"`
}
func (RichBlockExpandableBlockQuotation) isRichBlock() {}
// MarshalJSON adds the expandable_blockquote type discriminator.
//
// Since: Bot API 10.3
func (b RichBlockExpandableBlockQuotation) MarshalJSON() ([]byte, error) {
type plain RichBlockExpandableBlockQuotation
return json.Marshal(struct {
Type string `json:"type"`
plain
}{"expandable_blockquote", plain(b)})
}
// RichBlockDocument is a general-file block corresponding to <tg-document>.
//
// Since: Bot API 10.3
type RichBlockDocument struct {
// Document is the attached file.
Document Document `json:"document"`
// Caption optionally supplies the block caption.
Caption *RichBlockCaption `json:"caption,omitempty"`
}
func (RichBlockDocument) isRichBlock() {}
// MarshalJSON adds the document type discriminator.
//
// Since: Bot API 10.3
func (b RichBlockDocument) MarshalJSON() ([]byte, error) {
type plain RichBlockDocument
return json.Marshal(struct {
Type string `json:"type"`
plain
}{"document", plain(b)})
}
+58
View File
@@ -36,6 +36,10 @@ const (
InputRichTypeDetails InputRichType = "details"
// InputRichTypeMap identifies a map block.
InputRichTypeMap InputRichType = "map"
// InputRichTypeButtons identifies a button row.
//
// Since: Bot API 10.3
InputRichTypeButtons InputRichType = "buttons"
// InputRichTypeAnimation identifies an animation block.
InputRichTypeAnimation InputRichType = "animation"
// InputRichTypeAudio identifies an audio block.
@@ -297,6 +301,8 @@ type InputRichBlockTable struct {
IsBordered bool `json:"is_bordered,omitempty"`
// IsStriped requests alternating table row styling.
IsStriped bool `json:"is_striped,omitempty"`
// IsCompact requests smaller table-cell padding.
IsCompact bool `json:"is_compact,omitempty"` // Since: Bot API 10.3
// Caption contains the media or block caption.
Caption *RichText `json:"caption,omitempty"`
}
@@ -339,6 +345,20 @@ type InputRichBlockMap struct {
func (InputRichBlockMap) isInputRichBlock() {}
// InputRichBlockButtons is a block containing a list of buttons that are shown in one row.
//
// Since: Bot API 10.3
type InputRichBlockButtons struct {
// Type is always buttons.
Type InputRichType `json:"type"`
// Buttons contains 1-8 buttons in one row.
Buttons []RichMessageButton `json:"buttons"`
// Align optionally selects left, center, or right alignment.
Align RichBlockButtonAlign `json:"align,omitempty"`
}
func (InputRichBlockButtons) isInputRichBlock() {}
// InputRichBlockAnimation is an animation block corresponding to the HTML <video> tag.
// The animation caption is ignored; use Caption instead.
//
@@ -425,3 +445,41 @@ type InputRichBlockThinking struct {
}
func (InputRichBlockThinking) isInputRichBlock() {}
// InputRichTypeExpandableBlockQuotation identifies an expandable quotation.
//
// Since: Bot API 10.3
const InputRichTypeExpandableBlockQuotation InputRichType = "expandable_blockquote"
// InputRichTypeDocument identifies a general-file block.
//
// Since: Bot API 10.3
const InputRichTypeDocument InputRichType = "document"
// InputRichBlockExpandableBlockQuotation corresponds to <blockquote expandable>.
//
// Since: Bot API 10.3
type InputRichBlockExpandableBlockQuotation struct {
// Type is always expandable_blockquote.
Type InputRichType `json:"type"`
// Text is the quotation content.
Text RichText `json:"text"`
// Credit optionally identifies the source.
Credit *RichText `json:"credit,omitempty"`
}
func (InputRichBlockExpandableBlockQuotation) isInputRichBlock() {}
// InputRichBlockDocument corresponds to <tg-document>.
//
// Since: Bot API 10.3
type InputRichBlockDocument struct {
// Type is always document.
Type InputRichType `json:"type"`
// Document contains document media; its caption is ignored in favor of Caption.
Document InputMedia `json:"document"`
// Caption optionally supplies the block caption.
Caption *RichBlockCaption `json:"caption,omitempty"`
}
func (InputRichBlockDocument) isInputRichBlock() {}
+98
View File
@@ -24,6 +24,22 @@ type RichTextArray []RichText
func (RichTextArray) isRichText() {}
// RichTextUnknown preserves an unrecognized rich-text object for lossless forwarding.
type RichTextUnknown struct {
// Raw contains the complete JSON object received from Telegram.
Raw json.RawMessage
}
func (RichTextUnknown) isRichText() {}
// MarshalJSON implements json.Marshaler.
func (u RichTextUnknown) MarshalJSON() ([]byte, error) {
if !json.Valid(u.Raw) {
return nil, errInvalidUnknownRichJSON
}
return append([]byte(nil), u.Raw...), nil
}
// RichTextWrap covers all "pure" wrapper nodes with a single type.
//
// Since: Bot API 10.1
@@ -236,6 +252,83 @@ func (v RichTextBotCommand) MarshalJSON() ([]byte, error) {
}{"bot_command", v.Text, v.BotCommand})
}
// RichMessageButton describes a rich-message button with exactly one action.
//
// Since: Bot API 10.3
type RichMessageButton struct {
// Text allows plain text, custom emoji, and date-time entities only.
Text RichText `json:"text"`
// Style selects danger, success, primary, or link; link requires a callback action.
Style KeyboardButtonStyle `json:"style,omitempty"`
// URL opens an HTTP or tg:// link.
URL string `json:"url,omitempty"`
// CallbackData sends 1-64 bytes to the bot when pressed.
CallbackData string `json:"callback_data,omitempty"`
// WebApp opens a Mini App in private chats; unavailable for business messages.
WebApp *WebAppInfo `json:"web_app,omitempty"`
// LoginURL opens an HTTPS authorization link; unavailable for ephemeral messages.
// Its BotUsername field is not supported in rich buttons.
LoginURL *LoginURL `json:"login_url,omitempty"`
// SwitchInlineQuery selects a chat for an inline query; a pointer to an empty string is valid.
// Unavailable for channel direct messages and business messages.
SwitchInlineQuery *string `json:"switch_inline_query,omitempty"`
// SwitchInlineQueryCurrentChat inserts an inline query in the current chat; an empty query is valid.
// Unavailable in channels, channel direct messages, and business messages.
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"`
// SwitchInlineQueryChosenChat selects a permitted chat for an inline query.
// Unavailable for channel direct messages and business messages.
SwitchInlineQueryChosenChat *SwitchInlineQueryChosenChat `json:"switch_inline_query_chosen_chat,omitempty"`
// CopyText copies the specified text to the clipboard.
CopyText *CopyTextButton `json:"copy_text,omitempty"`
// Disabled makes the button do nothing.
Disabled *DisabledButton `json:"disabled,omitempty"`
}
// UnmarshalJSON decodes the button's nested rich-text label.
//
// Since: Bot API 10.3
func (b *RichMessageButton) UnmarshalJSON(data []byte) error {
if err := validateRichJSON(data); err != nil {
return err
}
type plain RichMessageButton
var raw struct {
Text json.RawMessage `json:"text"`
*plain
}
var result RichMessageButton
raw.plain = (*plain)(&result)
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
text, err := unmarshalRichText(raw.Text)
if err != nil {
return err
}
result.Text = text
*b = result
return nil
}
// RichTextButton embeds a button in rich text.
//
// Since: Bot API 10.3
type RichTextButton struct {
// Button is the embedded button.
Button RichMessageButton `json:"button"`
}
// MarshalJSON adds the button type discriminator.
//
// Since: Bot API 10.3
func (v RichTextButton) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Type string `json:"type"`
Button RichMessageButton `json:"button"`
}{"button", v.Button})
}
func (v RichTextButton) isRichText() {}
// RichTextAnchorLink is rich text linking to a named anchor in the same message.
//
// Since: Bot API 10.1
@@ -416,3 +509,8 @@ func (v RichTextAnchor) MarshalJSON() ([]byte, error) {
Name string `json:"name"`
}{"anchor", v.Name})
}
// RichMessageButtonStyleLink renders a callback button as a borderless link.
//
// Since: Bot API 10.3
const RichMessageButtonStyleLink KeyboardButtonStyle = "link"
+62 -29
View File
@@ -13,11 +13,20 @@ const (
maximumRichJSONNodes = 10_000
)
var errInvalidUnknownRichJSON = errors.New("invalid JSON in unknown rich object")
var knownRichTextTypes = map[string]bool{
"url": true, "email_address": true, "phone_number": true,
"bank_card_number": true, "mention": true, "hashtag": true,
"cashtag": true, "bot_command": true, "anchor_link": true,
"reference": true, "reference_link": true, "date_time": true,
"text_mention": true, "custom_emoji": true,
"mathematical_expression": true, "anchor": true, "button": true,
}
// UnmarshalRichText parses a RichText tree from JSON: a string, an array, or
// a typed object. Unknown object types that carry a text field are preserved
// as RichTextWrap so their nested text remains usable; unmodeled fields are
// discarded. The fallback representation is subject to change in v2 so unknown
// fields can be preserved losslessly.
// a typed object. Unknown object types are preserved as RichTextUnknown without
// discarding fields.
//
// Since: Bot API 10.1
func UnmarshalRichText(data []byte) (RichText, error) {
@@ -57,6 +66,12 @@ func unmarshalRichText(data []byte) (RichText, error) {
if err := json.Unmarshal(data, &head); err != nil {
return nil, fmt.Errorf("richtext: not a string, array or object: %w", err)
}
if head.Type == "" {
return nil, errors.New("richtext: object type is required")
}
if !richTextWrapTags[head.Type] && !knownRichTextTypes[head.Type] {
return RichTextUnknown{Raw: cloneRawJSON(data)}, nil
}
// Recursively parse the nested text, if any.
var inner RichText
@@ -204,21 +219,23 @@ func unmarshalRichText(data []byte) (RichText, error) {
return nil, err
}
return RichTextAnchor{v.Name}, nil
case "button":
var raw struct {
Button RichMessageButton `json:"button"`
}
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
return RichTextButton{Button: raw.Button}, nil
default:
// forward-compat: keep an unknown tag with a text field as
// RichTextWrap; without text it is an error (the shape cannot be guessed).
if inner != nil {
return RichTextWrap{Tag: head.Type, Text: inner}, nil
}
return nil, fmt.Errorf("richtext: unknown type %q", head.Type)
return nil, fmt.Errorf("richtext: unsupported type %q", head.Type)
}
}
// UnmarshalRichBlock parses a single RichBlock from JSON, dispatching on the
// type tag. Unknown types that carry a text field are decoded as RichBlockWrap
// so their nested text remains usable; unmodeled fields are discarded. The
// fallback representation is subject to change in v2 for lossless round trips.
// type tag. Unknown object types are preserved as RichBlockUnknown without
// discarding fields.
//
// Since: Bot API 10.1
func UnmarshalRichBlock(data []byte) (RichBlock, error) {
@@ -236,6 +253,9 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
if err := json.Unmarshal(data, &head); err != nil {
return nil, fmt.Errorf("richblock: %w", err)
}
if head.Type == "" {
return nil, errors.New("richblock: object type is required")
}
if richBlockWrapTags[head.Type] {
text, err := parseOptRichText(head.Text)
@@ -290,7 +310,7 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
}
return RichBlockQuotation{blocks, credit}, nil
case "pullquote":
case "expandable_blockquote", "pullquote":
var raw struct {
Credit json.RawMessage `json:"credit"`
}
@@ -305,6 +325,9 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
if err != nil {
return nil, fmt.Errorf("richblock %q: credit: %w", head.Type, err)
}
if head.Type == "expandable_blockquote" {
return RichBlockExpandableBlockQuotation{text, credit}, nil
}
return RichBlockPullQuotation{text, credit}, nil
case "list":
@@ -368,6 +391,7 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
Cells [][]RichBlockTableCell `json:"cells"`
IsBordered bool `json:"is_bordered"`
IsStriped bool `json:"is_striped"`
IsCompact bool `json:"is_compact"`
Caption json.RawMessage `json:"caption"`
}
if err := json.Unmarshal(data, &raw); err != nil {
@@ -377,7 +401,7 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
if err != nil {
return nil, fmt.Errorf("richblock %q: caption: %w", head.Type, err)
}
return RichBlockTable{raw.Cells, raw.IsBordered, raw.IsStriped, caption}, nil
return RichBlockTable{raw.Cells, raw.IsBordered, raw.IsStriped, raw.IsCompact, caption}, nil
case "map":
var v struct {
@@ -392,6 +416,18 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
}
return RichBlockMap{v.Location, v.Zoom, v.Width, v.Height, v.Caption}, nil
case "buttons":
var block RichBlockButtons
if err := json.Unmarshal(data, &block); err != nil {
return nil, err
}
return block, nil
case "document":
var block RichBlockDocument
if err := json.Unmarshal(data, &block); err != nil {
return nil, err
}
return block, nil
case "photo":
var v struct {
Photo []PhotoSize `json:"photo"`
@@ -467,26 +503,15 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
return RichBlockAnchor{v.Name}, nil
default:
// forward-compat: unknown type with text -> RichBlockWrap, without text -> error.
if text, err := parseOptRichText(head.Text); err == nil && text != nil {
return RichBlockWrap{Tag: head.Type, Text: text}, nil
}
return nil, fmt.Errorf("richblock: unknown type %q", head.Type)
return RichBlockUnknown{Raw: cloneRawJSON(data)}, nil
}
}
// UnmarshalRichMessage parses a root RichMessage from JSON.
//
// For v1 compatibility, missing and null blocks are accepted as an empty
// message. This permissive behavior is subject to change in v2; use
// UnmarshalRichMessageStrict when validating untrusted input.
// UnmarshalRichMessage parses a RichMessage and requires a non-null blocks array.
//
// Since: Bot API 10.1
func UnmarshalRichMessage(data []byte) (RichMessage, error) {
if err := validateRichJSON(data); err != nil {
return RichMessage{}, err
}
return unmarshalRichMessage(data)
return unmarshalRichMessageStrict(data)
}
func unmarshalRichMessage(data []byte) (RichMessage, error) {
@@ -508,6 +533,10 @@ func unmarshalRichMessage(data []byte) (RichMessage, error) {
//
// Since: Bot API 10.1
func UnmarshalRichMessageStrict(data []byte) (RichMessage, error) {
return unmarshalRichMessageStrict(data)
}
func unmarshalRichMessageStrict(data []byte) (RichMessage, error) {
if err := validateRichJSON(data); err != nil {
return RichMessage{}, err
}
@@ -550,6 +579,10 @@ func parseOptRichText(raw json.RawMessage) (RichText, error) {
return unmarshalRichText(raw)
}
func cloneRawJSON(raw []byte) json.RawMessage {
return append(json.RawMessage(nil), raw...)
}
func unmarshalRichBlocks(raw json.RawMessage) ([]RichBlock, error) {
if len(raw) == 0 || string(raw) == "null" {
return nil, nil
+93 -15
View File
@@ -3,6 +3,7 @@ package tgapi
import (
"encoding/json"
"errors"
"reflect"
"strings"
"testing"
)
@@ -233,23 +234,98 @@ func TestRichBlockDividerHasNoContent(t *testing.T) {
}
}
func TestRichBlockUnknownTypeWithTextIsForwardCompat(t *testing.T) {
raw := []byte(`{"type":"future_tag","text":"hello"}`)
b, err := UnmarshalRichBlock(raw)
if err != nil {
t.Fatalf("forward-compat failed: %v", err)
func TestUnknownRichObjectsRoundTripLosslessly(t *testing.T) {
tests := []struct {
name string
raw string
parse func([]byte) (any, error)
}{
{
name: "text",
raw: `{"type":"future_text","text":"hello","metadata":{"flag":true},"items":[1,2]}`,
parse: func(data []byte) (any, error) {
return UnmarshalRichText(data)
},
},
{
name: "block",
raw: `{"type":"future_block","value":42,"metadata":{"flag":true},"items":[1,2]}`,
parse: func(data []byte) (any, error) {
return UnmarshalRichBlock(data)
},
},
}
w, ok := b.(RichBlockWrap)
if !ok || w.Tag != "future_tag" {
t.Fatalf("expected RichBlockWrap{future_tag}, got %T", b)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
input := []byte(tt.raw)
value, err := tt.parse(input)
if err != nil {
t.Fatalf("parse failed: %v", err)
}
for i := range input {
input[i] = ' '
}
encoded, err := json.Marshal(value)
if err != nil {
t.Fatalf("Marshal failed: %v", err)
}
var got, want any
if err := json.Unmarshal(encoded, &got); err != nil {
t.Fatal(err)
}
if err := json.Unmarshal([]byte(tt.raw), &want); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("unknown object changed: got %s want %s", encoded, tt.raw)
}
switch v := value.(type) {
case RichTextUnknown:
if len(v.Raw) == 0 {
t.Fatal("empty preserved rich text")
}
case RichBlockUnknown:
if len(v.Raw) == 0 {
t.Fatal("empty preserved rich block")
}
default:
t.Fatalf("unexpected fallback type %T", value)
}
})
}
}
func TestRichBlockUnknownTypeWithoutTextIsError(t *testing.T) {
raw := []byte(`{"type":"mystery_leaf","value":42}`)
_, err := UnmarshalRichBlock(raw)
if err == nil {
t.Fatal("expected error for unknown type without text")
func TestUnknownRichObjectsRoundTripInsideMessage(t *testing.T) {
raw := []byte(`{"blocks":[{"type":"future_block","metadata":{"version":2}},{"type":"paragraph","text":{"type":"future_text","payload":[1,2,3]}}],"is_rtl":true}`)
message, err := UnmarshalRichMessage(raw)
if err != nil {
t.Fatalf("UnmarshalRichMessage failed: %v", err)
}
if _, ok := message.Blocks[0].(RichBlockUnknown); !ok {
t.Fatalf("first block type = %T, want RichBlockUnknown", message.Blocks[0])
}
paragraph, ok := message.Blocks[1].(RichBlockWrap)
if !ok {
t.Fatalf("second block type = %T, want RichBlockWrap", message.Blocks[1])
}
if _, ok := paragraph.Text.(RichTextUnknown); !ok {
t.Fatalf("paragraph text type = %T, want RichTextUnknown", paragraph.Text)
}
encoded, err := json.Marshal(message)
if err != nil {
t.Fatalf("Marshal failed: %v", err)
}
var got, want any
if err := json.Unmarshal(encoded, &got); err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(raw, &want); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("message changed: got %s want %s", encoded, raw)
}
}
@@ -271,8 +347,10 @@ func TestUnmarshalRichBlockRejectsMalformedFields(t *testing.T) {
func TestUnmarshalRichMessageStrict(t *testing.T) {
for _, raw := range []string{`null`, `{}`, `{"blocks":null}`, `{"blocks":{}}`} {
t.Run(raw, func(t *testing.T) {
if _, err := UnmarshalRichMessageStrict([]byte(raw)); err == nil {
t.Fatal("expected strict decoder error")
for _, parse := range []func([]byte) (RichMessage, error){UnmarshalRichMessage, UnmarshalRichMessageStrict} {
if _, err := parse([]byte(raw)); err == nil {
t.Fatal("expected strict decoder error")
}
}
})
}
+8 -8
View File
@@ -18,7 +18,7 @@ type GetStarTransactions struct {
// See https://core.telegram.org/bots/api#getmystarbalance
func (api *API) GetMyStarBalance() (StarAmount, error) {
req := NewRequest[StarAmount]("getMyStarBalance", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetMyStarBalanceWithContext is the context-aware variant of GetMyStarBalance.
@@ -27,7 +27,7 @@ func (api *API) GetMyStarBalance() (StarAmount, error) {
// See https://core.telegram.org/bots/api#getmystarbalance
func (api *API) GetMyStarBalanceWithContext(ctx context.Context) (StarAmount, error) {
req := NewRequest[StarAmount]("getMyStarBalance", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetStarTransactions returns Telegram Star transactions for the bot.
@@ -35,7 +35,7 @@ func (api *API) GetMyStarBalanceWithContext(ctx context.Context) (StarAmount, er
// See https://core.telegram.org/bots/api#getstartransactions
func (api *API) GetStarTransactions(params GetStarTransactions) (StarTransactions, error) {
req := NewRequest[StarTransactions]("getStarTransactions", params)
return req.Do(api)
return api.Do(req)
}
// GetStarTransactionsWithContext is the context-aware variant of GetStarTransactions.
@@ -44,7 +44,7 @@ func (api *API) GetStarTransactions(params GetStarTransactions) (StarTransaction
// See https://core.telegram.org/bots/api#getstartransactions
func (api *API) GetStarTransactionsWithContext(ctx context.Context, params GetStarTransactions) (StarTransactions, error) {
req := NewRequest[StarTransactions]("getStarTransactions", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// RefundStarPayment holds parameters for the refundStarPayment method.
@@ -63,7 +63,7 @@ type RefundStarPayment struct {
// See https://core.telegram.org/bots/api#refundstarpayment
func (api *API) RefundStarPayment(params RefundStarPayment) (bool, error) {
req := NewRequest[bool]("refundStarPayment", params)
return req.Do(api)
return api.Do(req)
}
// RefundStarPaymentWithContext is the context-aware variant of RefundStarPayment.
@@ -72,7 +72,7 @@ func (api *API) RefundStarPayment(params RefundStarPayment) (bool, error) {
// See https://core.telegram.org/bots/api#refundstarpayment
func (api *API) RefundStarPaymentWithContext(ctx context.Context, params RefundStarPayment) (bool, error) {
req := NewRequest[bool]("refundStarPayment", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// EditUserStarSubscription holds parameters for the editUserStarSubscription method.
@@ -95,7 +95,7 @@ type EditUserStarSubscription struct {
// See https://core.telegram.org/bots/api#edituserstarsubscription
func (api *API) EditUserStarSubscription(params EditUserStarSubscription) (bool, error) {
req := NewRequest[bool]("editUserStarSubscription", params)
return req.Do(api)
return api.Do(req)
}
// EditUserStarSubscriptionWithContext is the context-aware variant of EditUserStarSubscription.
@@ -104,5 +104,5 @@ func (api *API) EditUserStarSubscription(params EditUserStarSubscription) (bool,
// See https://core.telegram.org/bots/api#edituserstarsubscription
func (api *API) EditUserStarSubscriptionWithContext(ctx context.Context, params EditUserStarSubscription) (bool, error) {
req := NewRequest[bool]("editUserStarSubscription", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+34 -36
View File
@@ -18,10 +18,8 @@ type SendSticker struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Sticker Required. 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
@@ -59,7 +57,7 @@ type SendSticker struct {
// See https://core.telegram.org/bots/api#sendsticker
func (api *API) SendSticker(params SendSticker) (Message, error) {
req := NewRequestWithChatID[Message]("sendSticker", params, params.ChatID)
return req.Do(api)
return api.Do(req)
}
// SendStickerWithContext is the context-aware variant of SendSticker.
@@ -68,7 +66,7 @@ func (api *API) SendSticker(params SendSticker) (Message, error) {
// See https://core.telegram.org/bots/api#sendsticker
func (api *API) SendStickerWithContext(ctx context.Context, params SendSticker) (Message, error) {
req := NewRequestWithChatID[Message]("sendSticker", params, params.ChatID)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetStickerSet holds parameters for the getStickerSet method.
@@ -84,7 +82,7 @@ type GetStickerSet struct {
// See https://core.telegram.org/bots/api#getstickerset
func (api *API) GetStickerSet(params GetStickerSet) (StickerSet, error) {
req := NewRequest[StickerSet]("getStickerSet", params)
return req.Do(api)
return api.Do(req)
}
// GetStickerSetWithContext is the context-aware variant of GetStickerSet.
@@ -93,7 +91,7 @@ func (api *API) GetStickerSet(params GetStickerSet) (StickerSet, error) {
// See https://core.telegram.org/bots/api#getstickerset
func (api *API) GetStickerSetWithContext(ctx context.Context, params GetStickerSet) (StickerSet, error) {
req := NewRequest[StickerSet]("getStickerSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetCustomEmojiStickers holds parameters for the getCustomEmojiStickers method.
@@ -110,7 +108,7 @@ type GetCustomEmojiStickers struct {
// See https://core.telegram.org/bots/api#getcustomemojistickers
func (api *API) GetCustomEmojiStickers(params GetCustomEmojiStickers) ([]Sticker, error) {
req := NewRequest[[]Sticker]("getCustomEmojiStickers", params)
return req.Do(api)
return api.Do(req)
}
// GetCustomEmojiStickersWithContext is the context-aware variant of GetCustomEmojiStickers.
@@ -119,7 +117,7 @@ func (api *API) GetCustomEmojiStickers(params GetCustomEmojiStickers) ([]Sticker
// See https://core.telegram.org/bots/api#getcustomemojistickers
func (api *API) GetCustomEmojiStickersWithContext(ctx context.Context, params GetCustomEmojiStickers) ([]Sticker, error) {
req := NewRequest[[]Sticker]("getCustomEmojiStickers", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// UploadStickerFile holds parameters for the uploadStickerFile method.
@@ -142,7 +140,7 @@ func (api *API) UploadStickerFile(params UploadStickerFile, sticker UploaderFile
_ = uploader.Close()
}()
req := NewUploaderRequest[File]("uploadStickerFile", params, sticker.SetType(UploaderStickerType))
return req.Do(uploader)
return uploader.Do(req)
}
// UploadStickerFileWithContext is the context-aware variant of UploadStickerFile.
@@ -155,7 +153,7 @@ func (api *API) UploadStickerFileWithContext(ctx context.Context, params UploadS
_ = uploader.Close()
}()
req := NewUploaderRequest[File]("uploadStickerFile", params, sticker.SetType(UploaderStickerType))
return req.DoWithContext(ctx, uploader)
return uploader.DoWithContext(ctx, req)
}
// CreateNewStickerSet holds parameters for the createNewStickerSet method.
@@ -188,7 +186,7 @@ type CreateNewStickerSet struct {
// See https://core.telegram.org/bots/api#createnewstickerset
func (api *API) CreateNewStickerSet(params CreateNewStickerSet) (bool, error) {
req := NewRequest[bool]("createNewStickerSet", params)
return req.Do(api)
return api.Do(req)
}
// CreateNewStickerSetWithContext is the context-aware variant of CreateNewStickerSet.
@@ -197,7 +195,7 @@ func (api *API) CreateNewStickerSet(params CreateNewStickerSet) (bool, error) {
// See https://core.telegram.org/bots/api#createnewstickerset
func (api *API) CreateNewStickerSetWithContext(ctx context.Context, params CreateNewStickerSet) (bool, error) {
req := NewRequest[bool]("createNewStickerSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// AddStickerToSet holds parameters for the addStickerToSet method.
@@ -219,7 +217,7 @@ type AddStickerToSet struct {
// See https://core.telegram.org/bots/api#addstickertoset
func (api *API) AddStickerToSet(params AddStickerToSet) (bool, error) {
req := NewRequest[bool]("addStickerToSet", params)
return req.Do(api)
return api.Do(req)
}
// AddStickerToSetWithContext is the context-aware variant of AddStickerToSet.
@@ -228,7 +226,7 @@ func (api *API) AddStickerToSet(params AddStickerToSet) (bool, error) {
// See https://core.telegram.org/bots/api#addstickertoset
func (api *API) AddStickerToSetWithContext(ctx context.Context, params AddStickerToSet) (bool, error) {
req := NewRequest[bool]("addStickerToSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetStickerPositionInSet holds parameters for the setStickerPositionInSet method.
@@ -247,7 +245,7 @@ type SetStickerPositionInSet struct {
// See https://core.telegram.org/bots/api#setstickerpositioninset
func (api *API) SetStickerPositionInSet(params SetStickerPositionInSet) (bool, error) {
req := NewRequest[bool]("setStickerPositionInSet", params)
return req.Do(api)
return api.Do(req)
}
// SetStickerPositionInSetWithContext is the context-aware variant of SetStickerPositionInSet.
@@ -256,7 +254,7 @@ func (api *API) SetStickerPositionInSet(params SetStickerPositionInSet) (bool, e
// See https://core.telegram.org/bots/api#setstickerpositioninset
func (api *API) SetStickerPositionInSetWithContext(ctx context.Context, params SetStickerPositionInSet) (bool, error) {
req := NewRequest[bool]("setStickerPositionInSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteStickerFromSet holds parameters for the deleteStickerFromSet method.
@@ -273,7 +271,7 @@ type DeleteStickerFromSet struct {
// See https://core.telegram.org/bots/api#deletestickerfromset
func (api *API) DeleteStickerFromSet(params DeleteStickerFromSet) (bool, error) {
req := NewRequest[bool]("deleteStickerFromSet", params)
return req.Do(api)
return api.Do(req)
}
// DeleteStickerFromSetWithContext is the context-aware variant of DeleteStickerFromSet.
@@ -282,7 +280,7 @@ func (api *API) DeleteStickerFromSet(params DeleteStickerFromSet) (bool, error)
// See https://core.telegram.org/bots/api#deletestickerfromset
func (api *API) DeleteStickerFromSetWithContext(ctx context.Context, params DeleteStickerFromSet) (bool, error) {
req := NewRequest[bool]("deleteStickerFromSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ReplaceStickerInSet holds parameters for the replaceStickerInSet method.
@@ -306,7 +304,7 @@ type ReplaceStickerInSet struct {
// See https://core.telegram.org/bots/api#replacestickerinset
func (api *API) ReplaceStickerInSet(params ReplaceStickerInSet) (bool, error) {
req := NewRequest[bool]("replaceStickerInSet", params)
return req.Do(api)
return api.Do(req)
}
// ReplaceStickerInSetWithContext is the context-aware variant of ReplaceStickerInSet.
@@ -315,7 +313,7 @@ func (api *API) ReplaceStickerInSet(params ReplaceStickerInSet) (bool, error) {
// See https://core.telegram.org/bots/api#replacestickerinset
func (api *API) ReplaceStickerInSetWithContext(ctx context.Context, params ReplaceStickerInSet) (bool, error) {
req := NewRequest[bool]("replaceStickerInSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetStickerEmojiList holds parameters for the setStickerEmojiList method.
@@ -334,7 +332,7 @@ type SetStickerEmojiList struct {
// See https://core.telegram.org/bots/api#setstickeremojilist
func (api *API) SetStickerEmojiList(params SetStickerEmojiList) (bool, error) {
req := NewRequest[bool]("setStickerEmojiList", params)
return req.Do(api)
return api.Do(req)
}
// SetStickerEmojiListWithContext is the context-aware variant of SetStickerEmojiList.
@@ -343,7 +341,7 @@ func (api *API) SetStickerEmojiList(params SetStickerEmojiList) (bool, error) {
// See https://core.telegram.org/bots/api#setstickeremojilist
func (api *API) SetStickerEmojiListWithContext(ctx context.Context, params SetStickerEmojiList) (bool, error) {
req := NewRequest[bool]("setStickerEmojiList", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetStickerKeywords holds parameters for the setStickerKeywords method.
@@ -363,7 +361,7 @@ type SetStickerKeywords struct {
// See https://core.telegram.org/bots/api#setstickerkeywords
func (api *API) SetStickerKeywords(params SetStickerKeywords) (bool, error) {
req := NewRequest[bool]("setStickerKeywords", params)
return req.Do(api)
return api.Do(req)
}
// SetStickerKeywordsWithContext is the context-aware variant of SetStickerKeywords.
@@ -372,7 +370,7 @@ func (api *API) SetStickerKeywords(params SetStickerKeywords) (bool, error) {
// See https://core.telegram.org/bots/api#setstickerkeywords
func (api *API) SetStickerKeywordsWithContext(ctx context.Context, params SetStickerKeywords) (bool, error) {
req := NewRequest[bool]("setStickerKeywords", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetStickerMaskPosition holds parameters for the setStickerMaskPosition method.
@@ -392,7 +390,7 @@ type SetStickerMaskPosition struct {
// See https://core.telegram.org/bots/api#setstickermaskposition
func (api *API) SetStickerMaskPosition(params SetStickerMaskPosition) (bool, error) {
req := NewRequest[bool]("setStickerMaskPosition", params)
return req.Do(api)
return api.Do(req)
}
// SetStickerMaskPositionWithContext is the context-aware variant of SetStickerMaskPosition.
@@ -401,7 +399,7 @@ func (api *API) SetStickerMaskPosition(params SetStickerMaskPosition) (bool, err
// See https://core.telegram.org/bots/api#setstickermaskposition
func (api *API) SetStickerMaskPositionWithContext(ctx context.Context, params SetStickerMaskPosition) (bool, error) {
req := NewRequest[bool]("setStickerMaskPosition", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetStickerSetTitle holds parameters for the setStickerSetTitle method.
@@ -420,7 +418,7 @@ type SetStickerSetTitle struct {
// See https://core.telegram.org/bots/api#setstickersettitle
func (api *API) SetStickerSetTitle(params SetStickerSetTitle) (bool, error) {
req := NewRequest[bool]("setStickerSetTitle", params)
return req.Do(api)
return api.Do(req)
}
// SetStickerSetTitleWithContext is the context-aware variant of SetStickerSetTitle.
@@ -429,7 +427,7 @@ func (api *API) SetStickerSetTitle(params SetStickerSetTitle) (bool, error) {
// See https://core.telegram.org/bots/api#setstickersettitle
func (api *API) SetStickerSetTitleWithContext(ctx context.Context, params SetStickerSetTitle) (bool, error) {
req := NewRequest[bool]("setStickerSetTitle", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetStickerSetThumbnail holds parameters for the setStickerSetThumbnail method.
@@ -461,7 +459,7 @@ type SetStickerSetThumbnail struct {
// See https://core.telegram.org/bots/api#setstickersetthumbnail
func (api *API) SetStickerSetThumbnail(params SetStickerSetThumbnail) (bool, error) {
req := NewRequest[bool]("setStickerSetThumbnail", params)
return req.Do(api)
return api.Do(req)
}
// SetStickerSetThumbnailWithContext is the context-aware variant of SetStickerSetThumbnail.
@@ -470,7 +468,7 @@ func (api *API) SetStickerSetThumbnail(params SetStickerSetThumbnail) (bool, err
// See https://core.telegram.org/bots/api#setstickersetthumbnail
func (api *API) SetStickerSetThumbnailWithContext(ctx context.Context, params SetStickerSetThumbnail) (bool, error) {
req := NewRequest[bool]("setStickerSetThumbnail", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetCustomEmojiStickerSetThumbnail holds parameters for the setCustomEmojiStickerSetThumbnail method.
@@ -490,7 +488,7 @@ type SetCustomEmojiStickerSetThumbnail struct {
// See https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
func (api *API) SetCustomEmojiStickerSetThumbnail(params SetCustomEmojiStickerSetThumbnail) (bool, error) {
req := NewRequest[bool]("setCustomEmojiStickerSetThumbnail", params)
return req.Do(api)
return api.Do(req)
}
// SetCustomEmojiStickerSetThumbnailWithContext is the context-aware variant of SetCustomEmojiStickerSetThumbnail.
@@ -499,7 +497,7 @@ func (api *API) SetCustomEmojiStickerSetThumbnail(params SetCustomEmojiStickerSe
// See https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
func (api *API) SetCustomEmojiStickerSetThumbnailWithContext(ctx context.Context, params SetCustomEmojiStickerSetThumbnail) (bool, error) {
req := NewRequest[bool]("setCustomEmojiStickerSetThumbnail", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteStickerSet holds parameters for the deleteStickerSet method.
@@ -516,7 +514,7 @@ type DeleteStickerSet struct {
// See https://core.telegram.org/bots/api#deletestickerset
func (api *API) DeleteStickerSet(params DeleteStickerSet) (bool, error) {
req := NewRequest[bool]("deleteStickerSet", params)
return req.Do(api)
return api.Do(req)
}
// DeleteStickerSetWithContext is the context-aware variant of DeleteStickerSet.
@@ -525,5 +523,5 @@ func (api *API) DeleteStickerSet(params DeleteStickerSet) (bool, error) {
// See https://core.telegram.org/bots/api#deletestickerset
func (api *API) DeleteStickerSetWithContext(ctx context.Context, params DeleteStickerSet) (bool, error) {
req := NewRequest[bool]("deleteStickerSet", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+27
View File
@@ -68,6 +68,10 @@ const (
//
// Since: Bot API 10.2
UpdateTypeSubscription UpdateType = "subscription"
// UpdateTypeMessageGenerationStopped identifies a request to stop message generation.
//
// Since: Bot API 10.3
UpdateTypeMessageGenerationStopped UpdateType = "stopped_message_generation"
)
// Update represents an incoming update from Telegram.
@@ -162,6 +166,9 @@ type Update struct {
ManagedBot *ManagedBotUpdated `json:"managed_bot,omitempty"` // Since: Bot API 9.6
// Subscription contains a bot subscription update.
Subscription *BotSubscriptionUpdated `json:"subscription,omitempty"` // Since: Bot API 10.2
// StoppedMessageGeneration describes a request to stop a message draft.
StoppedMessageGeneration *MessageGenerationStopped `json:"stopped_message_generation,omitempty"` // Since: Bot API 10.3
}
// UnmarshalJSON decodes an update and derives its Type from the populated payload field.
@@ -231,6 +238,8 @@ func (u *Update) UnmarshalJSON(data []byte) error {
u.Type = UpdateTypeManagedBot
case u.Subscription != nil:
u.Type = UpdateTypeSubscription
case u.StoppedMessageGeneration != nil:
u.Type = UpdateTypeMessageGenerationStopped
default:
u.Type = UpdateTypeUnknown
}
@@ -677,6 +686,12 @@ type UniqueGiftInfo struct {
// other users, “gifted_upgrade” for upgrades purchased after the gift was sent, or “offer” for
// gifts bought or sold through gift purchase offers.
Origin string `json:"origin"`
// Text contains the text shown with the gift.
Text string `json:"text,omitempty"` // Since: Bot API 10.3
// Entities contains special entities appearing in Text.
Entities []MessageEntity `json:"entities,omitempty"` // Since: Bot API 10.3
// IsPrivate reports whether the sender and gift text are visible only to the gift receiver.
IsPrivate bool `json:"is_private,omitempty"` // Since: Bot API 10.3
// LastResaleCurrency Optional. For gifts bought from other users, the currency in which the payment for the
// gift was done. Currently, one of “XTR” for Telegram Stars or “TON” for TON grams.
LastResaleCurrency string `json:"last_resale_currency,omitempty"`
@@ -974,3 +989,15 @@ type BotSubscriptionUpdated struct {
// State is the new subscription state.
State BotSubscriptionState `json:"state"`
}
// MessageGenerationStopped describes an update about a user stopping message generation.
//
// Since: Bot API 10.3
type MessageGenerationStopped struct {
// Chat is the chat in which the message was being generated.
Chat Chat `json:"chat"`
// MessageThreadID optionally identifies the message thread.
MessageThreadID int `json:"message_thread_id,omitempty"`
// DraftID identifies the stopped draft.
DraftID int `json:"draft_id"`
}
+20 -20
View File
@@ -11,7 +11,7 @@ import (
"strings"
"time"
"git.scuroneko.dev/scuroneko/laniakea/utils"
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
"git.scuroneko.dev/scuroneko/sneklog/v2"
)
@@ -125,19 +125,19 @@ func NewUploaderRequestWithChatID[R, P any](method string, params P, chatID int6
return UploaderRequest[R, P]{method: method, files: files, params: params, chatID: chatID}
}
func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R, error) {
func (u *Uploader) doRequest[R, P any](ctx context.Context, r UploaderRequest[R, P]) (R, error) {
var zero R
methodPrefix := ""
if up.api.useTestServer {
if u.api.useTestServer {
methodPrefix = "/test"
}
url := fmt.Sprintf("%s/bot%s%s/%s", up.api.apiURL, up.api.token, methodPrefix, r.method)
url := fmt.Sprintf("%s/bot%s%s/%s", u.api.apiURL, u.api.token, methodPrefix, r.method)
retries := 0
for {
if up.api.Limiter != nil {
if err := up.api.Limiter.Check(ctx, up.api.dropOverflowLimit, r.chatID); err != nil {
if u.api.Limiter != nil {
if err := u.api.Limiter.Check(ctx, u.api.dropOverflowLimit, r.chatID); err != nil {
return zero, err
}
}
@@ -152,11 +152,11 @@ func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R,
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", fmt.Sprintf("Laniakea/%s", utils.VersionString))
up.logger.Debugln("UPLOADER REQ", url)
resp, err := up.api.client.Do(req)
u.logger.Debugln("UPLOADER REQ", url)
resp, err := u.api.client.Do(req)
_ = requestBody.Close()
if err != nil {
return zero, fmt.Errorf("HTTP upload request failed: %w", redactHTTPError(err, up.api.token))
return zero, fmt.Errorf("HTTP upload request failed: %w", redactHTTPError(err, u.api.token))
}
body, err := readBody(resp.Body)
@@ -164,7 +164,7 @@ func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R,
if err != nil {
return zero, err
}
up.logger.Debugln("UPLOADER RES", responseLogSummary(r.method, len(body)))
u.logger.Debugln("UPLOADER RES", responseLogSummary(r.method, len(body)))
response, err := parseBody[R](body)
if err != nil {
@@ -179,15 +179,15 @@ func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R,
}
if response.ErrorCode == 429 && response.Parameters != nil && response.Parameters.RetryAfter != nil {
after := *response.Parameters.RetryAfter
up.logger.Warnf("Rate limited, retry after %d seconds (chat: %d)", after, r.chatID)
if up.api.Limiter != nil {
u.logger.Warnf("Rate limited, retry after %d seconds (chat: %d)", after, r.chatID)
if u.api.Limiter != nil {
if r.chatID != 0 {
up.api.Limiter.SetChatLock(r.chatID, after)
u.api.Limiter.SetChatLock(r.chatID, after)
} else {
up.api.Limiter.SetGlobalLock(after)
u.api.Limiter.SetGlobalLock(after)
}
}
if retries >= up.api.maxRetries {
if retries >= u.api.maxRetries {
return zero, fmt.Errorf("%w after %d retries: %w", ErrRetryLimit, retries, responseErr)
}
retries++
@@ -207,11 +207,11 @@ func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R,
// DoWithContext executes the upload request asynchronously via the worker pool.
// Returns the result or error. Respects context cancellation.
func (r UploaderRequest[R, P]) DoWithContext(ctx context.Context, up *Uploader) (R, error) {
func (u *Uploader) DoWithContext[R, P any](ctx context.Context, r UploaderRequest[R, P]) (R, error) {
var zero R
result, err := up.api.pool.submit(ctx, func(ctx context.Context) (any, error) {
return r.doRequest(ctx, up)
result, err := u.api.pool.submit(ctx, func(ctx context.Context) (any, error) {
return u.doRequest(ctx, r)
})
if err != nil {
return zero, err
@@ -233,8 +233,8 @@ func (r UploaderRequest[R, P]) DoWithContext(ctx context.Context, up *Uploader)
// Do executes the upload request synchronously with a background context.
// Use only for simple, non-critical uploads.
func (r UploaderRequest[R, P]) Do(up *Uploader) (R, error) {
return r.DoWithContext(context.Background(), up)
func (u *Uploader) Do[R, P any](r UploaderRequest[R, P]) (R, error) {
return u.DoWithContext(context.Background(), r)
}
func prepareMultipartStream[P any](files []UploaderFile, params P) (io.ReadCloser, string) {
+61
View File
@@ -2,6 +2,7 @@ package tgapi
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
@@ -106,6 +107,66 @@ func TestUploaderEncodesJSONFieldsAndLeavesAcceptEncodingToHTTPTransport(t *test
}
}
func TestUploaderEditEphemeralMessageMediaUploadsAttachment(t *testing.T) {
var (
gotPath string
gotFields map[string]string
gotFileName string
gotFileData []byte
roundTripErr error
)
client := &http.Client{
Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
gotPath = req.URL.Path
gotFields, gotFileName, gotFileData, roundTripErr = readMultipartRequest(req)
return &http.Response{
StatusCode: http.StatusOK,
Header: http.Header{"Content-Type": []string{"application/json"}},
Body: io.NopCloser(strings.NewReader(`{"ok":true,"result":true}`)),
}, nil
}),
}
api := NewAPI(NewAPIOpts("token").SetAPIURL("https://example.test").SetHTTPClient(client))
defer func() { _ = api.Close() }()
uploader := NewUploader(api)
defer func() { _ = uploader.Close() }()
ok, err := uploader.EditEphemeralMessageMedia(
EditEphemeralMessageMedia{
ChatID: 42,
ReceiverUserID: 7,
EphemeralMessageID: 9,
Media: InputMedia{
Type: InputMediaTypePhoto,
Media: "attach://replacement",
},
},
NewUploaderFile("replacement.jpg", []byte("image")).SetAttachName("replacement"),
)
if err != nil {
t.Fatalf("EditEphemeralMessageMedia returned error: %v", err)
}
if !ok {
t.Fatal("EditEphemeralMessageMedia returned false")
}
if roundTripErr != nil {
t.Fatalf("multipart parse failed: %v", roundTripErr)
}
if gotPath != "/bottoken/editEphemeralMessageMedia" {
t.Fatalf("unexpected request path: %q", gotPath)
}
var media InputMedia
if err := json.Unmarshal([]byte(gotFields["media"]), &media); err != nil {
t.Fatalf("decode media field: %v", err)
}
if media.Type != InputMediaTypePhoto || media.Media != "attach://replacement" {
t.Fatalf("unexpected media field: %q", gotFields["media"])
}
if gotFileName != "replacement.jpg" || string(gotFileData) != "image" {
t.Fatalf("unexpected upload: filename=%q data=%q", gotFileName, gotFileData)
}
}
func TestUploaderRejectsDirectRichMessageDraftUpload(t *testing.T) {
uploader := &Uploader{}
_, err := uploader.SendRichMessageDraft(
+56 -54
View File
@@ -8,7 +8,7 @@ import "context"
// Since: Bot API 10.2
func (u *Uploader) SendRichMessage(params SendRichMessage, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendRichMessage", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendRichMessageWithContext uploads files referenced by attach:// names in params.RichMessage
@@ -17,7 +17,25 @@ func (u *Uploader) SendRichMessage(params SendRichMessage, files ...UploaderFile
// Since: Bot API 10.2
func (u *Uploader) SendRichMessageWithContext(ctx context.Context, params SendRichMessage, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendRichMessage", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// EditEphemeralMessageMedia edits ephemeral media and uploads files referenced through attach:// names.
//
// Since: Bot API 10.3
func (u *Uploader) EditEphemeralMessageMedia(params EditEphemeralMessageMedia, files ...UploaderFile) (bool, error) {
req := NewUploaderRequestWithChatID[bool]("editEphemeralMessageMedia", params, params.ChatID, files...)
return u.Do(req)
}
// EditEphemeralMessageMediaWithContext is the context-aware variant of EditEphemeralMessageMedia.
//
// Since: Bot API 10.3
func (u *Uploader) EditEphemeralMessageMediaWithContext(
ctx context.Context, params EditEphemeralMessageMedia, files ...UploaderFile,
) (bool, error) {
req := NewUploaderRequestWithChatID[bool]("editEphemeralMessageMedia", params, params.ChatID, files...)
return u.DoWithContext(ctx, req)
}
// SendRichMessageDraft streams a rich-message draft without direct file uploads.
@@ -57,10 +75,8 @@ type UploadPhoto struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Caption Optional. Photo caption (may also be used when resending photos by file_id), 0-1024 characters
// after entities parsing
@@ -106,7 +122,7 @@ type UploadPhoto struct {
// See https://core.telegram.org/bots/api#sendphoto
func (u *Uploader) SendPhoto(params UploadPhoto, file UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendPhoto", params, params.ChatID, file)
return req.Do(u)
return u.Do(req)
}
// SendPhotoWithContext is the context-aware variant of SendPhoto.
@@ -115,7 +131,7 @@ func (u *Uploader) SendPhoto(params UploadPhoto, file UploaderFile) (Message, er
// See https://core.telegram.org/bots/api#sendphoto
func (u *Uploader) SendPhotoWithContext(ctx context.Context, params UploadPhoto, file UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendPhoto", params, params.ChatID, file)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadAudio holds parameters for uploading an audio file using the Uploader.
@@ -134,10 +150,8 @@ type UploadAudio struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Caption Optional. Audio caption, 0-1024 characters after entities parsing
Caption string `json:"caption,omitempty"`
@@ -185,7 +199,7 @@ type UploadAudio struct {
// See https://core.telegram.org/bots/api#sendaudio
func (u *Uploader) SendAudio(params UploadAudio, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendAudio", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendAudioWithContext is the context-aware variant of SendAudio.
@@ -194,7 +208,7 @@ func (u *Uploader) SendAudio(params UploadAudio, files ...UploaderFile) (Message
// See https://core.telegram.org/bots/api#sendaudio
func (u *Uploader) SendAudioWithContext(ctx context.Context, params UploadAudio, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendAudio", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadDocument holds parameters for uploading a document using the Uploader.
@@ -213,10 +227,8 @@ type UploadDocument struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Caption Optional. Document caption (may also be used when resending documents by file_id), 0-1024
// characters after entities parsing
@@ -261,7 +273,7 @@ type UploadDocument struct {
// See https://core.telegram.org/bots/api#senddocument
func (u *Uploader) SendDocument(params UploadDocument, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendDocument", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendDocumentWithContext is the context-aware variant of SendDocument.
@@ -270,7 +282,7 @@ func (u *Uploader) SendDocument(params UploadDocument, files ...UploaderFile) (M
// See https://core.telegram.org/bots/api#senddocument
func (u *Uploader) SendDocumentWithContext(ctx context.Context, params UploadDocument, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendDocument", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadVideo holds parameters for uploading a video using the Uploader.
@@ -289,10 +301,8 @@ type UploadVideo struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Duration Optional. Duration of sent video in seconds
Duration int `json:"duration,omitempty"`
@@ -349,7 +359,7 @@ type UploadVideo struct {
// See https://core.telegram.org/bots/api#sendvideo
func (u *Uploader) SendVideo(params UploadVideo, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendVideo", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendVideoWithContext is the context-aware variant of SendVideo.
@@ -358,7 +368,7 @@ func (u *Uploader) SendVideo(params UploadVideo, files ...UploaderFile) (Message
// See https://core.telegram.org/bots/api#sendvideo
func (u *Uploader) SendVideoWithContext(ctx context.Context, params UploadVideo, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendVideo", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadAnimation holds parameters for uploading an animation using the Uploader.
@@ -377,10 +387,8 @@ type UploadAnimation struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Duration Optional. Duration of sent animation in seconds
Duration int `json:"duration,omitempty"`
@@ -433,7 +441,7 @@ type UploadAnimation struct {
// See https://core.telegram.org/bots/api#sendanimation
func (u *Uploader) SendAnimation(params UploadAnimation, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendAnimation", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendAnimationWithContext is the context-aware variant of SendAnimation.
@@ -442,7 +450,7 @@ func (u *Uploader) SendAnimation(params UploadAnimation, files ...UploaderFile)
// See https://core.telegram.org/bots/api#sendanimation
func (u *Uploader) SendAnimationWithContext(ctx context.Context, params UploadAnimation, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendAnimation", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadVoice holds parameters for uploading a voice note using the Uploader.
@@ -461,10 +469,8 @@ type UploadVoice struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Caption Optional. Voice message caption, 0-1024 characters after entities parsing
Caption string `json:"caption,omitempty"`
@@ -507,7 +513,7 @@ type UploadVoice struct {
// See https://core.telegram.org/bots/api#sendvoice
func (u *Uploader) SendVoice(params UploadVoice, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendVoice", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendVoiceWithContext is the context-aware variant of SendVoice.
@@ -516,7 +522,7 @@ func (u *Uploader) SendVoice(params UploadVoice, files ...UploaderFile) (Message
// See https://core.telegram.org/bots/api#sendvoice
func (u *Uploader) SendVoiceWithContext(ctx context.Context, params UploadVoice, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendVoice", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadVideoNote holds parameters for uploading a video note (rounded video) using the Uploader.
@@ -535,10 +541,8 @@ type UploadVideoNote struct {
// DirectMessagesTopicID Optional. Identifier of the direct messages topic to which the message will be
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Duration Optional. Duration of sent video in seconds
Duration int `json:"duration,omitempty"`
@@ -575,7 +579,7 @@ type UploadVideoNote struct {
// See https://core.telegram.org/bots/api#sendvideonote
func (u *Uploader) SendVideoNote(params UploadVideoNote, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendVideoNote", params, params.ChatID, files...)
return req.Do(u)
return u.Do(req)
}
// SendVideoNoteWithContext is the context-aware variant of SendVideoNote.
@@ -584,7 +588,7 @@ func (u *Uploader) SendVideoNote(params UploadVideoNote, files ...UploaderFile)
// See https://core.telegram.org/bots/api#sendvideonote
func (u *Uploader) SendVideoNoteWithContext(ctx context.Context, params UploadVideoNote, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendVideoNote", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadChatPhoto holds parameters for uploading a chat photo using the Uploader.
@@ -602,7 +606,7 @@ type UploadChatPhoto struct {
// See https://core.telegram.org/bots/api#setchatphoto
func (u *Uploader) SetChatPhoto(params UploadChatPhoto, photo UploaderFile) (bool, error) {
req := NewUploaderRequestWithChatID[bool]("setChatPhoto", params, params.ChatID, photo)
return req.Do(u)
return u.Do(req)
}
// SetChatPhotoWithContext is the context-aware variant of SetChatPhoto.
@@ -611,7 +615,7 @@ func (u *Uploader) SetChatPhoto(params UploadChatPhoto, photo UploaderFile) (boo
// See https://core.telegram.org/bots/api#setchatphoto
func (u *Uploader) SetChatPhotoWithContext(ctx context.Context, params UploadChatPhoto, photo UploaderFile) (bool, error) {
req := NewUploaderRequestWithChatID[bool]("setChatPhoto", params, params.ChatID, photo)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadSetWebhook holds multipart parameters for the setWebhook method.
@@ -650,7 +654,7 @@ type UploadSetWebhook struct {
// See https://core.telegram.org/bots/api#setwebhook
func (u *Uploader) SetWebhook(params UploadSetWebhook, certificate UploaderFile) (bool, error) {
req := NewUploaderRequest[bool]("setWebhook", params, certificate.SetType(UploaderCertificateType))
return req.Do(u)
return u.Do(req)
}
// SetWebhookWithContext is the context-aware variant of SetWebhook.
@@ -659,7 +663,7 @@ func (u *Uploader) SetWebhook(params UploadSetWebhook, certificate UploaderFile)
// See https://core.telegram.org/bots/api#setwebhook
func (u *Uploader) SetWebhookWithContext(ctx context.Context, params UploadSetWebhook, certificate UploaderFile) (bool, error) {
req := NewUploaderRequest[bool]("setWebhook", params, certificate.SetType(UploaderCertificateType))
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
// UploadLivePhoto holds parameters for uploading a live photo using the Uploader.
@@ -679,10 +683,8 @@ type UploadLivePhoto struct {
// sent; required if the message is sent to a direct messages chat
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
// EphemeralMessageParameters configures an ephemeral response.
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
// Caption Optional. Video caption (may also be used when resending videos by file_id), 0-1024 characters
// after entities parsing
Caption string `json:"caption,omitempty"`
@@ -731,7 +733,7 @@ func (u *Uploader) SendLivePhoto(params UploadLivePhoto, livePhoto, photo Upload
livePhoto.SetType(UploaderLivePhotoType),
photo.SetType(UploaderPhotoType),
)
return req.Do(u)
return u.Do(req)
}
// SendLivePhotoWithContext uploads a live-photo video and its static image via
@@ -746,5 +748,5 @@ func (u *Uploader) SendLivePhotoWithContext(
livePhoto.SetType(UploaderLivePhotoType),
photo.SetType(UploaderPhotoType),
)
return req.DoWithContext(ctx, u)
return u.DoWithContext(ctx, req)
}
+10 -10
View File
@@ -21,7 +21,7 @@ type GetUserProfilePhotos struct {
// See https://core.telegram.org/bots/api#getuserprofilephotos
func (api *API) GetUserProfilePhotos(params GetUserProfilePhotos) (UserProfilePhotos, error) {
req := NewRequest[UserProfilePhotos]("getUserProfilePhotos", params)
return req.Do(api)
return api.Do(req)
}
// GetUserProfilePhotosWithContext is the context-aware variant of GetUserProfilePhotos.
@@ -30,7 +30,7 @@ func (api *API) GetUserProfilePhotos(params GetUserProfilePhotos) (UserProfilePh
// See https://core.telegram.org/bots/api#getuserprofilephotos
func (api *API) GetUserProfilePhotosWithContext(ctx context.Context, params GetUserProfilePhotos) (UserProfilePhotos, error) {
req := NewRequest[UserProfilePhotos]("getUserProfilePhotos", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetUserProfileAudios holds parameters for the GetUserProfileAudios method.
@@ -52,7 +52,7 @@ type GetUserProfileAudios struct {
// See https://core.telegram.org/bots/api#getuserprofileaudios
func (api *API) GetUserProfileAudios(params GetUserProfileAudios) (UserProfileAudios, error) {
req := NewRequest[UserProfileAudios]("getUserProfileAudios", params)
return req.Do(api)
return api.Do(req)
}
// GetUserProfileAudiosWithContext is the context-aware variant of GetUserProfileAudios.
@@ -61,7 +61,7 @@ func (api *API) GetUserProfileAudios(params GetUserProfileAudios) (UserProfileAu
// See https://core.telegram.org/bots/api#getuserprofileaudios
func (api *API) GetUserProfileAudiosWithContext(ctx context.Context, params GetUserProfileAudios) (UserProfileAudios, error) {
req := NewRequest[UserProfileAudios]("getUserProfileAudios", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetUserEmojiStatus holds parameters for the SetUserEmojiStatus method.
@@ -83,7 +83,7 @@ type SetUserEmojiStatus struct {
// See https://core.telegram.org/bots/api#setuseremojistatus
func (api *API) SetUserEmojiStatus(params SetUserEmojiStatus) (bool, error) {
req := NewRequest[bool]("setUserEmojiStatus", params)
return req.Do(api)
return api.Do(req)
}
// SetUserEmojiStatusWithContext is the context-aware variant of SetUserEmojiStatus.
@@ -92,7 +92,7 @@ func (api *API) SetUserEmojiStatus(params SetUserEmojiStatus) (bool, error) {
// See https://core.telegram.org/bots/api#setuseremojistatus
func (api *API) SetUserEmojiStatusWithContext(ctx context.Context, params SetUserEmojiStatus) (bool, error) {
req := NewRequest[bool]("setUserEmojiStatus", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetUserGifts holds parameters for the GetUserGifts method.
@@ -129,7 +129,7 @@ type GetUserGifts struct {
// See https://core.telegram.org/bots/api#getusergifts
func (api *API) GetUserGifts(params GetUserGifts) (OwnedGifts, error) {
req := NewRequest[OwnedGifts]("getUserGifts", params)
return req.Do(api)
return api.Do(req)
}
// GetUserGiftsWithContext is the context-aware variant of GetUserGifts.
@@ -138,7 +138,7 @@ func (api *API) GetUserGifts(params GetUserGifts) (OwnedGifts, error) {
// See https://core.telegram.org/bots/api#getusergifts
func (api *API) GetUserGiftsWithContext(ctx context.Context, params GetUserGifts) (OwnedGifts, error) {
req := NewRequest[OwnedGifts]("getUserGifts", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetUserPersonalChatMessages holds parameters for the getUserPersonalChatMessages method.
@@ -158,7 +158,7 @@ type GetUserPersonalChatMessages struct {
// See https://core.telegram.org/bots/api#getuserpersonalchatmessages
func (api *API) GetUserPersonalChatMessages(params GetUserPersonalChatMessages) ([]Message, error) {
req := NewRequest[[]Message]("getUserPersonalChatMessages", params)
return req.Do(api)
return api.Do(req)
}
// GetUserPersonalChatMessagesWithContext is the context-aware variant of GetUserPersonalChatMessages.
@@ -167,5 +167,5 @@ func (api *API) GetUserPersonalChatMessages(params GetUserPersonalChatMessages)
// See https://core.telegram.org/bots/api#getuserpersonalchatmessages
func (api *API) GetUserPersonalChatMessagesWithContext(ctx context.Context, params GetUserPersonalChatMessages) ([]Message, error) {
req := NewRequest[[]Message]("getUserPersonalChatMessages", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
+4 -4
View File
@@ -34,21 +34,21 @@ func TestTelegramWireFieldNames(t *testing.T) {
{
name: "input checklist permissions",
value: InputChecklist{
OtherCanAddTasks: true,
OtherCanMarkTasksAsDone: true,
OthersCanAddTasks: true,
OthersCanMarkTasksAsDone: true,
},
keys: []string{"others_can_add_tasks", "others_can_mark_tasks_as_done"},
bad: []string{"other_can_add_tasks", "other_can_mark_tasks_as_done"},
},
{
name: "available reactions",
value: ChatFullInfo{AvailableReaction: []ReactionType{{Type: "emoji"}}},
value: ChatFullInfo{AvailableReactions: []ReactionType{{Type: "emoji"}}},
keys: []string{"available_reactions"},
bad: []string{"available_reaction"},
},
{
name: "reply quote parse mode",
value: ReplyParameters{QuoteParsingMode: "HTML"},
value: ReplyParameters{QuoteParseMode: "HTML"},
keys: []string{"quote_parse_mode"},
bad: []string{"quote_parsing_mode"},
},