diff --git a/Migration.md b/Migration.md index ca57c8a..986ddfe 100644 --- a/Migration.md +++ b/Migration.md @@ -151,12 +151,12 @@ And update direct `tgapi` calls to the renamed close methods. ### What changed - `WithContext` variants were added across more `tgapi` methods. -- Webhook certificate upload moved away from the JSON `SetWebhookP.Certificate` path. +- Webhook certificate upload moved away from the JSON `SetWebhook.Certificate` path. - Certificate upload now goes through uploader-based webhook APIs. ### What to migrate -If you were sending webhook certificates through `SetWebhookP.Certificate`, switch to `Uploader.SetWebhook(...)` or `Uploader.SetWebhookWithContext(...)`. +If you were sending webhook certificates through `SetWebhook.Certificate`, switch to `Uploader.SetWebhook(...)` or `Uploader.SetWebhookWithContext(...)`. If you maintain infrastructure code around deadlines or cancellation, prefer the newer `WithContext` variants consistently instead of wrapping only some calls. diff --git a/Recipes.md b/Recipes.md index 11d4c94..27cf2b4 100644 --- a/Recipes.md +++ b/Recipes.md @@ -123,7 +123,7 @@ plugin.NewCommand(func(ctx *laniakea.MsgContext, db *App) error { uploader := tgapi.NewUploader(ctx.Api) defer uploader.Close() - _, err := uploader.SendPhoto(tgapi.UploadPhotoP{ + _, err := uploader.SendPhoto(tgapi.UploadPhoto{ ChatID: ctx.Msg.Chat.ID, }, tgapi.NewUploaderFile("report.jpg", []byte("hello"))) return err diff --git a/tgapi-Overview-RU.md b/tgapi-Overview-RU.md index b885181..ea3f897 100644 --- a/tgapi-Overview-RU.md +++ b/tgapi-Overview-RU.md @@ -40,6 +40,11 @@ English version: [[tgapi-Overview]] ```go api := tgapi.NewAPI(tgapi.NewAPIOpts(token)) defer api.Close() + +msg, err := api.SendMessage(tgapi.SendMessage{ + ChatID: chatID, + Text: "Привет", +}) ``` Это безопаснее и удобнее, чем вручную собирать raw requests. @@ -65,6 +70,18 @@ defer api.Close() - multipart file uploads; - методы, которым нужны binary bodies. +Например: + +```go +uploader := tgapi.NewUploader(api) +defer uploader.Close() + +_, err := uploader.SendPhoto(tgapi.UploadPhoto{ + ChatID: chatID, + Caption: "Кот", +}, tgapi.NewUploaderFile("cat.jpg", data)) +``` + ## `Close()` важен У `API` и `Uploader` есть собственный жизненный цикл. diff --git a/tgapi-Overview.md b/tgapi-Overview.md index 9838124..4a6009a 100644 --- a/tgapi-Overview.md +++ b/tgapi-Overview.md @@ -55,7 +55,7 @@ Example: api := tgapi.NewAPI(tgapi.NewAPIOpts(token)) defer api.Close() -msg, err := api.SendMessage(tgapi.SendMessageP{ +msg, err := api.SendMessage(tgapi.SendMessage{ ChatID: chatID, Text: "Hello", }) @@ -133,7 +133,7 @@ uploader := tgapi.NewUploader(api) defer uploader.Close() photo := tgapi.NewUploaderFile("cat.jpg", data) -msg, err := uploader.SendPhoto(tgapi.UploadPhotoP{ +msg, err := uploader.SendPhoto(tgapi.UploadPhoto{ ChatID: chatID, Caption: "Cat", }, photo) @@ -152,7 +152,7 @@ Use `API` when: Use `Uploader` when: - Telegram expects multipart file upload; - you are sending new binary content from memory or disk; -- the method has an `Upload*P` parameter type. +- the method has an `Upload*` parameter type. ## File downloads @@ -199,7 +199,7 @@ Use them only when: Example: ```go -req := tgapi.NewRequest[bool]("deleteWebhook", tgapi.DeleteWebhookP{ +req := tgapi.NewRequest[bool]("deleteWebhook", tgapi.DeleteWebhook{ DropPendingUpdates: true, }) ok, err := req.Do(api)