REPOSITORY / ScuroNeko/Laniakea

Wiki

KNOWLEDGE REPOSITORY

Update tgapi wiki naming

Rename request struct examples after the tgapi API cleanup
Align EN and RU overview pages with the new usage
2026-04-06 16:09:09 +03:00
parent 4332f5a7a5
commit a978ca6aea
4 changed files with 24 additions and 7 deletions
+2 -2
@@ -151,12 +151,12 @@ And update direct `tgapi` calls to the renamed close methods.
### What changed ### What changed
- `WithContext` variants were added across more `tgapi` methods. - `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. - Certificate upload now goes through uploader-based webhook APIs.
### What to migrate ### 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. If you maintain infrastructure code around deadlines or cancellation, prefer the newer `WithContext` variants consistently instead of wrapping only some calls.
+1 -1
@@ -123,7 +123,7 @@ plugin.NewCommand(func(ctx *laniakea.MsgContext, db *App) error {
uploader := tgapi.NewUploader(ctx.Api) uploader := tgapi.NewUploader(ctx.Api)
defer uploader.Close() defer uploader.Close()
_, err := uploader.SendPhoto(tgapi.UploadPhotoP{ _, err := uploader.SendPhoto(tgapi.UploadPhoto{
ChatID: ctx.Msg.Chat.ID, ChatID: ctx.Msg.Chat.ID,
}, tgapi.NewUploaderFile("report.jpg", []byte("hello"))) }, tgapi.NewUploaderFile("report.jpg", []byte("hello")))
return err return err
+17
@@ -40,6 +40,11 @@ English version: [[tgapi-Overview]]
```go ```go
api := tgapi.NewAPI(tgapi.NewAPIOpts(token)) api := tgapi.NewAPI(tgapi.NewAPIOpts(token))
defer api.Close() defer api.Close()
msg, err := api.SendMessage(tgapi.SendMessage{
ChatID: chatID,
Text: "Привет",
})
``` ```
Это безопаснее и удобнее, чем вручную собирать raw requests. Это безопаснее и удобнее, чем вручную собирать raw requests.
@@ -65,6 +70,18 @@ defer api.Close()
- multipart file uploads; - multipart file uploads;
- методы, которым нужны binary bodies. - методы, которым нужны binary bodies.
Например:
```go
uploader := tgapi.NewUploader(api)
defer uploader.Close()
_, err := uploader.SendPhoto(tgapi.UploadPhoto{
ChatID: chatID,
Caption: "Кот",
}, tgapi.NewUploaderFile("cat.jpg", data))
```
## `Close()` важен ## `Close()` важен
У `API` и `Uploader` есть собственный жизненный цикл. У `API` и `Uploader` есть собственный жизненный цикл.
+4 -4
@@ -55,7 +55,7 @@ Example:
api := tgapi.NewAPI(tgapi.NewAPIOpts(token)) api := tgapi.NewAPI(tgapi.NewAPIOpts(token))
defer api.Close() defer api.Close()
msg, err := api.SendMessage(tgapi.SendMessageP{ msg, err := api.SendMessage(tgapi.SendMessage{
ChatID: chatID, ChatID: chatID,
Text: "Hello", Text: "Hello",
}) })
@@ -133,7 +133,7 @@ uploader := tgapi.NewUploader(api)
defer uploader.Close() defer uploader.Close()
photo := tgapi.NewUploaderFile("cat.jpg", data) photo := tgapi.NewUploaderFile("cat.jpg", data)
msg, err := uploader.SendPhoto(tgapi.UploadPhotoP{ msg, err := uploader.SendPhoto(tgapi.UploadPhoto{
ChatID: chatID, ChatID: chatID,
Caption: "Cat", Caption: "Cat",
}, photo) }, photo)
@@ -152,7 +152,7 @@ Use `API` when:
Use `Uploader` when: Use `Uploader` when:
- Telegram expects multipart file upload; - Telegram expects multipart file upload;
- you are sending new binary content from memory or disk; - 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 ## File downloads
@@ -199,7 +199,7 @@ Use them only when:
Example: Example:
```go ```go
req := tgapi.NewRequest[bool]("deleteWebhook", tgapi.DeleteWebhookP{ req := tgapi.NewRequest[bool]("deleteWebhook", tgapi.DeleteWebhook{
DropPendingUpdates: true, DropPendingUpdates: true,
}) })
ok, err := req.Do(api) ok, err := req.Do(api)