(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
+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(