REPOSITORY / ScuroNeko/Laniakea
Wiki
Update tgapi wiki naming
Rename request struct examples after the tgapi API cleanup Align EN and RU overview pages with the new usage
+2
-2
@@ -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.
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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` есть собственный жизненный цикл.
|
||||
|
||||
+4
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user