REPOSITORY / ScuroNeko/Laniakea
Compare commits
Compare commits
4 Commits
v2.0.0-rc.1
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3e4276b97 | ||
|
|
4d95bd0574 | ||
|
|
f4117c143e | ||
|
|
07ce1ccda0 |
@@ -1,46 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## v2.0.0-rc.1 (Unreleased)
|
||||
|
||||
### Added
|
||||
- Added Bot API 10.3 rich buttons: `RichMessageButton`, `RichTextButton`, `RichBlockButtons`, and `InputRichBlockButtons`, including inline-query chat selection, login, clipboard, and disabled actions. Empty inline queries are preserved through pointer fields; `RichMessageButtonStyleLink` supports borderless callback buttons.
|
||||
- Added incoming and outgoing expandable block quotations and document blocks, with `tgrich.Button`, `Buttons`, `ButtonsWithAlign`, `ExpandableBlockquote`, `ExpandableBlockquoteWithCredit`, `Document`, and `DocumentWithCaption` helpers.
|
||||
- Added compact rich tables through `IsCompact` and `RichTable.SetCompact`, including JSON decoding and HTML rendering.
|
||||
- Added rich-button validation for a single action, permitted label entities and styles, callback byte limits, copy-text length, row size, and alignment. Invalid values return `ErrRichInvalidButton` from `tgrich` builders.
|
||||
- Added HTML rendering for rich buttons, expandable quotations, and documents. Document media is collected into `InputRichMessage.Media` with `tg://document?id=` references and supports multipart attachments through the existing rich-message uploader.
|
||||
- Added `EphemeralMessageParameters`, including `ReplaceCallbackQueryMessage`, to JSON and multipart send parameters for text, rich messages, animation, audio, documents, live photos, photos, stickers, video, video notes, voice, contacts, locations, and venues. Ephemeral media editing now supports multipart attachments through `Uploader.EditEphemeralMessageMedia`.
|
||||
- Added `RichMessage` to `EditEphemeralMessageText` and `ShowCaptionAboveMedia` to `EditEphemeralMessageCaption`.
|
||||
- Added `CanStop` and `KeepOnStop` to message and rich-message draft parameters. Stopped-generation updates are decoded as `UpdateTypeMessageGenerationStopped` and expose their chat through normalized message context.
|
||||
- Added disabled inline buttons and `SetDisabled`, plus `ForceReply` support on specialized inline and reply keyboard markup.
|
||||
- Added `CommunityChatJoined` service messages; `UniqueGiftInfo.Text`, `Entities`, and `IsPrivate`; and `CanSendWelcomeMessages` to administrator members, rights, and promotion parameters.
|
||||
- Added `RichTextUnknown` and `RichBlockUnknown` to preserve unrecognized Telegram rich objects without losing fields.
|
||||
- Added explicit `InlineKeyboard.SetUnlimitedRows` configuration.
|
||||
|
||||
### Breaking changes
|
||||
- Changed the Go module and import path to `git.scuroneko.dev/scuroneko/laniakea/v2`, raised the minimum Go version to 1.27, and removed the v1-only retraction directive.
|
||||
- `PollAnswer.User` and `VoterChat` are now pointers; removed `VoterUser` and `VoterChatInfo`. Update-context normalization and tests use the pointer fields.
|
||||
- `RunnerFn` and `NewRunner` now require callbacks with `context.Context`; removed `ContextRunnerFn` and `NewContextRunner`.
|
||||
- `InlineKeyboard.Get` now validates and returns `(*tgapi.ReplyMarkup, error)`; removed `GetValidated` and keyboard-level `Validate`. Message-context helpers reject invalid keyboards before sending or editing. Previously built rows exceeding a subsequently lowered row limit now fail final validation.
|
||||
- `CallbackData.Encode` now returns `(string, error)` and validates encoding and payload length; removed `EncodeValidated`.
|
||||
- Moved custom request execution from `TelegramRequest.Do` / `DoWithContext` to `API.Do` / `DoWithContext`, and from `UploaderRequest` methods to the corresponding `Uploader` methods.
|
||||
- Renamed `ChatFullInfo.AvailableReaction` to `AvailableReactions`, `ReplyParameters.QuoteParsingMode` to `QuoteParseMode`, and `InputChecklist.OtherCanAddTasks` / `OtherCanMarkTasksAsDone` to `OthersCanAddTasks` / `OthersCanMarkTasksAsDone`; JSON keys remain unchanged.
|
||||
- Removed `DeleteAllMessageReactionWithContext`; use `DeleteAllMessageReactionsWithContext`.
|
||||
- The JSON and multipart send parameter structs listed above replace top-level `ReceiverUserID` and `CallbackQueryID` with `EphemeralMessageParameters`.
|
||||
- `UnmarshalRichMessage` now requires a non-null `blocks` array. Unknown rich objects use lossless raw wrappers instead of lossy text wrappers or errors.
|
||||
- Removed the unbounded `API.GetFileByLink` and `GetFileByLinkWithContext`; use `GetFileByLinkLimit*` with an explicit byte limit or `OpenFileByLink*` for streaming.
|
||||
- Non-positive inline-keyboard row limits are invalid by default; call `SetUnlimitedRows` to disable automatic wrapping explicitly.
|
||||
|
||||
### Changed
|
||||
- Prepared the declared version and user-agent metadata for `v2.0.0-rc.1`.
|
||||
- Updated English and Russian README runner and keyboard examples for the final v2 contracts, and generalized the prerelease policy for the v2 RC cycle.
|
||||
|
||||
### Fixed
|
||||
- Fixed nested rich-text validation skipping children of formatting and link entities, which could bypass text-size and nesting limits.
|
||||
|
||||
### Tests
|
||||
- Migrated runner, poll-voter, keyboard, message-context, and wire-format tests to the new contracts.
|
||||
- Added rich-button action round trips, malformed-input and nesting cases, row and callback boundaries, HTML escaping, compact tables, expandable quotations, document media, multipart attachments, draft-upload coverage, Bot API 10.3 wire fields, stopped-generation routing, strict root parsing, lossless unknown objects, bounded downloads, explicit unlimited rows, and compile-focused v1-to-v2 migration coverage.
|
||||
|
||||
## v1.2.0
|
||||
|
||||
### Added
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
[](https://go.dev/)
|
||||
[](https://go.dev/)
|
||||
[](LICENSE)
|
||||

|
||||
|
||||
@@ -30,7 +30,13 @@ A lightweight, easy-to-use, and performant Telegram Bot API wrapper for Go. It s
|
||||
## 📦 Installation
|
||||
|
||||
```bash
|
||||
go get git.scuroneko.dev/scuroneko/laniakea/v2@v2.0.0-rc.1
|
||||
go get git.scuroneko.dev/scuroneko/laniakea
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
go get github.com/scuroneko/laniakea
|
||||
```
|
||||
|
||||
## 🚀 Quick Start (with step-by-step explanation)
|
||||
@@ -42,7 +48,7 @@ package main
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2" // Import the Laniakea library
|
||||
"git.scuroneko.dev/scuroneko/laniakea" // Import the Laniakea library
|
||||
)
|
||||
|
||||
// echo is a command handler function.
|
||||
@@ -282,32 +288,32 @@ import (
|
||||
|
||||
// One-shot runner — fires once in a goroutine when the bot starts (default).
|
||||
bot.AddRunner(
|
||||
laniakea.NewRunner("seed-cache", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().SeedCache(ctx)
|
||||
}),
|
||||
laniakea.NewRunner("seed-cache", func(b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().SeedCache()
|
||||
}),
|
||||
)
|
||||
|
||||
// Periodic runner — fires every 10 minutes in a goroutine.
|
||||
bot.AddRunner(
|
||||
laniakea.NewRunner("refresh-stats", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().RefreshStats(ctx)
|
||||
}).Every(10 * time.Minute),
|
||||
laniakea.NewContextRunner("refresh-stats", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().RefreshStats(ctx)
|
||||
}).Every(10 * time.Minute),
|
||||
)
|
||||
|
||||
// Synchronous one-shot — blocks runtime startup until it completes.
|
||||
bot.AddRunner(
|
||||
laniakea.NewRunner("migrate", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().Migrate(ctx)
|
||||
}).Async(false),
|
||||
laniakea.NewRunner("migrate", func(b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().Migrate()
|
||||
}).Async(false),
|
||||
)
|
||||
```
|
||||
|
||||
Builder methods:
|
||||
- `Async(bool) Runner[T]` — if `true` (default), runs in a goroutine; if `false`, blocks runtime startup.
|
||||
- `Every(time.Duration) Runner[T]` — sets the repeat interval. Zero (default) means run once; positive value repeats. Periodic runners require `Async(true)`.
|
||||
- `Async(bool) *Runner[T]` — if `true` (default), runs in a goroutine; if `false`, blocks runtime startup.
|
||||
- `Every(time.Duration) *Runner[T]` — sets the repeat interval. Zero (default) means run once; positive value repeats. Periodic runners require `Async(true)`.
|
||||
|
||||
Every runner receives a context that is canceled when polling or webhook
|
||||
execution stops. I/O and blocking work should pass it to downstream calls.
|
||||
Prefer `NewContextRunner` for I/O and blocking work. Its context is canceled
|
||||
when polling or webhook execution stops, allowing shutdown to complete.
|
||||
|
||||
## 🧩 Middleware
|
||||
Middleware are functions that run before a command handler. They are perfect for cross-cutting concerns like logging, access control, rate limiting, or modifying the context.
|
||||
@@ -358,7 +364,7 @@ func adminOnlyMiddleware(ctx *laniakea.MessageContext, db *MyDB) bool {
|
||||
|
||||
## ⚙️ Advanced Configuration
|
||||
- **Inline Keyboards**: Build keyboards using `laniakea.NewInlineKeyboardJSON`, `laniakea.NewInlineKeyboardBase64`, or `laniakea.NewInlineKeyboard`. `Bot.SetPayloadType(...)` defines the default payload format, and `InlineKeyboard.SetPayloadType(...)` overrides it for one keyboard.
|
||||
- **Keyboard Validation**: `InlineKeyboard.Get()` validates every button and row before returning markup; Telegram limits `callback_data` to 1–64 bytes. Use `SetUnlimitedRows()` when automatic wrapping must be disabled explicitly.
|
||||
- **Keyboard Validation**: Call `InlineKeyboard.GetValidated()` before sending untrusted or dynamically generated callback payloads; Telegram limits `callback_data` to 1–64 bytes.
|
||||
- **Rate Limiting**: Pass a configured utils.RateLimiter via BotOpts to handle Telegram's rate limits gracefully.
|
||||
- **Observers**: Runtime observer callbacks are dispatched asynchronously in order through a bounded queue. Slow observers do not block handlers; overload drops events with sampled warnings, and shutdown drains queued events.
|
||||
- **Localization**: `L10n` is safe for concurrent use once attached to the bot.
|
||||
@@ -376,7 +382,7 @@ func adminOnlyMiddleware(ctx *laniakea.MessageContext, db *MyDB) bool {
|
||||
This project is licensed under the GNU General Public License v3.0 — see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
## 📚 Learn More
|
||||
[GoDoc](https://pkg.go.dev/git.scuroneko.dev/scuroneko/laniakea/v2)
|
||||
[GoDoc](https://pkg.go.dev/git.scuroneko.dev/scuroneko/laniakea)
|
||||
|
||||
[Wiki](https://git.scuroneko.dev/ScuroNeko/Laniakea/wiki)
|
||||
|
||||
|
||||
+23
-17
@@ -31,7 +31,13 @@
|
||||
## 📦 Установка
|
||||
|
||||
```bash
|
||||
go get git.scuroneko.dev/scuroneko/laniakea/v2@v2.0.0-rc.1
|
||||
go get git.scuroneko.dev/scuroneko/laniakea
|
||||
```
|
||||
|
||||
или
|
||||
|
||||
```bash
|
||||
go get github.com/scuroneko/laniakea
|
||||
```
|
||||
|
||||
## 🚀 Быстрый старт (с пошаговыми комментариями)
|
||||
@@ -43,7 +49,7 @@ package main
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2" // Импортируем библиотеку Laniakea
|
||||
"git.scuroneko.dev/scuroneko/laniakea" // Импортируем библиотеку Laniakea
|
||||
)
|
||||
|
||||
// echo — это функция-обработчик команды.
|
||||
@@ -264,32 +270,32 @@ import (
|
||||
|
||||
// Одноразовый раннер — запускается один раз в горутине при старте (по умолчанию).
|
||||
bot.AddRunner(
|
||||
laniakea.NewRunner("seed-cache", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().SeedCache(ctx)
|
||||
}),
|
||||
laniakea.NewRunner("seed-cache", func(b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().SeedCache()
|
||||
}),
|
||||
)
|
||||
|
||||
// Периодический раннер — запускается каждые 10 минут в горутине.
|
||||
bot.AddRunner(
|
||||
laniakea.NewRunner("refresh-stats", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().RefreshStats(ctx)
|
||||
}).Every(10 * time.Minute),
|
||||
laniakea.NewContextRunner("refresh-stats", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().RefreshStats(ctx)
|
||||
}).Every(10 * time.Minute),
|
||||
)
|
||||
|
||||
// Синхронный одноразовый — блокирует запуск runtime до завершения.
|
||||
bot.AddRunner(
|
||||
laniakea.NewRunner("migrate", func(ctx context.Context, b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().Migrate(ctx)
|
||||
}).Async(false),
|
||||
laniakea.NewRunner("migrate", func(b *laniakea.Bot[*MyDB]) error {
|
||||
return b.GetAppData().Migrate()
|
||||
}).Async(false),
|
||||
)
|
||||
```
|
||||
|
||||
Методы builder:
|
||||
- `Async(bool) Runner[T]` — если `true` (по умолчанию), запускается в горутине; если `false`, блокирует запуск runtime.
|
||||
- `Every(time.Duration) Runner[T]` — задаёт интервал повторного запуска. Ноль (по умолчанию) означает одноразовый запуск; положительное значение — периодический. Периодические раннеры требуют `Async(true)`.
|
||||
- `Async(bool) *Runner[T]` — если `true` (по умолчанию), запускается в горутине; если `false`, блокирует запуск runtime.
|
||||
- `Every(time.Duration) *Runner[T]` — задаёт интервал повторного запуска. Ноль (по умолчанию) означает одноразовый запуск; положительное значение — периодический. Периодические раннеры требуют `Async(true)`.
|
||||
|
||||
Каждый runner получает context, который отменяется при остановке polling или
|
||||
webhook runtime. I/O и блокирующие операции должны передавать его во вложенные вызовы.
|
||||
Для I/O и блокирующей работы предпочитайте `NewContextRunner`. Его context
|
||||
отменяется при остановке polling или webhook runtime, поэтому shutdown может завершиться.
|
||||
|
||||
### tgapi: API и Uploader
|
||||
|
||||
@@ -356,7 +362,7 @@ func adminOnlyMiddleware(ctx *laniakea.MessageContext, db *MyDB) bool {
|
||||
|
||||
## ⚙️ Расширенная настройка
|
||||
- **Инлайн-клавиатуры**: Создавайте клавиатуры с помощью `laniakea.NewInlineKeyboardJSON`, `laniakea.NewInlineKeyboardBase64` или `laniakea.NewInlineKeyboard`. `Bot.SetPayloadType(...)` задаёт payload format по умолчанию, а `InlineKeyboard.SetPayloadType(...)` переопределяет его для конкретной клавиатуры.
|
||||
- **Валидация клавиатур**: `InlineKeyboard.Get()` проверяет все кнопки и строки перед возвратом markup; Telegram ограничивает `callback_data` диапазоном 1–64 байта. Для явного отключения автоматического переноса используйте `SetUnlimitedRows()`.
|
||||
- **Валидация клавиатур**: Вызывайте `InlineKeyboard.GetValidated()` перед отправкой недоверенных или динамически собранных callback payload; Telegram ограничивает `callback_data` диапазоном 1–64 байта.
|
||||
- **Ограничение запросов**: Передайте настроенный `utils.RateLimiter` через `BotOpts` для корректной обработки лимитов Telegram.
|
||||
- **Observer**: Во время runtime callbacks observer выполняются асинхронно и по порядку через ограниченную очередь. Медленный observer не блокирует handlers; при переполнении события отбрасываются с редкими предупреждениями, а shutdown обрабатывает уже поставленные в очередь события.
|
||||
- **Локализация**: `L10n` безопасен для конкурентного использования после подключения к боту.
|
||||
@@ -373,7 +379,7 @@ func adminOnlyMiddleware(ctx *laniakea.MessageContext, db *MyDB) bool {
|
||||
Этот проект лицензирован под GNU General Public License v3.0 - подробности см. в файле [LICENSE](LICENSE).
|
||||
|
||||
## 📚 Дополнительная информация
|
||||
[GoDoc Laniakea](https://pkg.go.dev/git.scuroneko.dev/scuroneko/laniakea/v2)
|
||||
[GoDoc Laniakea](https://pkg.go.dev/git.scuroneko.dev/scuroneko/laniakea)
|
||||
|
||||
[Wiki](https://git.scuroneko.dev/ScuroNeko/Laniakea/wiki)
|
||||
|
||||
|
||||
@@ -41,5 +41,5 @@ A release uses a patch version bump for backward-compatible fixes:
|
||||
|
||||
## Pre-Releases
|
||||
|
||||
`-rc.N` builds may still correct release-blocking API defects before the corresponding stable release.
|
||||
After a stable release, breaking changes require a new major version.
|
||||
`-rc.N` builds may still adjust API details before `v1.0.0`.
|
||||
Once `v1.0.0` is released, breaking changes require a new major version.
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/extypes"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
// ConfigVersion is the current version of the built-in JSON BotOpts file format.
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestBotOptsFileJSONCodecRoundTrip(t *testing.T) {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestLoadOptsFromEnvIgnoresEmptyUpdateTypes(t *testing.T) {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
// AddPlugins registers one or more plugins.
|
||||
|
||||
+5
-5
@@ -12,7 +12,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
@@ -966,8 +966,8 @@ func TestAddPluginsAndRuntimeRegistrationsNoOpAfterRunStarts(t *testing.T) {
|
||||
bot := &Bot[NoData]{
|
||||
logger: sneklog.NewLogger(),
|
||||
prefixes: []string{"/"},
|
||||
middlewares: []Middleware[NoData]{NewMiddleware("base", func(*MessageContext, NoData) bool { return true })},
|
||||
runners: []Runner[NoData]{NewRunner("base", func(context.Context, *Bot[NoData]) error { return nil })},
|
||||
middlewares: []Middleware[NoData]{NewMiddleware("base", func(ctx *MessageContext, db NoData) bool { return true })},
|
||||
runners: []Runner[NoData]{NewRunner("base", func(bot *Bot[NoData]) error { return nil })},
|
||||
}
|
||||
plugin := NewPlugin[NoData]("late")
|
||||
|
||||
@@ -977,8 +977,8 @@ func TestAddPluginsAndRuntimeRegistrationsNoOpAfterRunStarts(t *testing.T) {
|
||||
defer bot.finishRun()
|
||||
|
||||
bot.AddPlugins(plugin)
|
||||
bot.AddMiddleware(NewMiddleware("late", func(*MessageContext, NoData) bool { return true }))
|
||||
bot.AddRunner(NewRunner("late", func(context.Context, *Bot[NoData]) error { return nil }))
|
||||
bot.AddMiddleware(NewMiddleware("late", func(ctx *MessageContext, db NoData) bool { return true }))
|
||||
bot.AddRunner(NewRunner("late", func(bot *Bot[NoData]) error { return nil }))
|
||||
|
||||
if len(bot.plugins) != 0 {
|
||||
t.Fatalf("expected AddPlugins to be ignored after configuration freeze, got %d plugins", len(bot.plugins))
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/extypes"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
"github.com/alitto/pond/v2"
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
// BotWebhookOpts configures Telegram webhook registration and the local HTTP server.
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestRunWebhookRuntimeExecutesRunners(t *testing.T) {
|
||||
updateQueue: make(chan *tgapi.Update, 1),
|
||||
maxWorkers: 1,
|
||||
runners: []Runner[NoData]{
|
||||
NewRunner("runner", func(context.Context, *Bot[NoData]) error {
|
||||
NewRunner("runner", func(bot *Bot[NoData]) error {
|
||||
calls.Add(1)
|
||||
return nil
|
||||
}).Async(false),
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
var cmdRegexp = regexp.MustCompile("^[_a-z0-9]{1,32}$")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
type draftIDGenerator interface {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
@@ -76,8 +76,6 @@ var (
|
||||
ErrCallbackDataLength = errors.New("callback data must be between 1 and 64 bytes")
|
||||
// ErrInlineKeyboardRowTooLong reports a row exceeding the configured maximum.
|
||||
ErrInlineKeyboardRowTooLong = errors.New("inline keyboard row exceeds maximum size")
|
||||
// ErrInlineKeyboardMaxRow reports a non-positive row limit without explicit unlimited mode.
|
||||
ErrInlineKeyboardMaxRow = errors.New("inline keyboard maximum row size must be positive")
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
module git.scuroneko.dev/scuroneko/laniakea/v2
|
||||
module git.scuroneko.dev/scuroneko/laniakea
|
||||
|
||||
go 1.27
|
||||
go 1.26
|
||||
|
||||
retract v1.0.0-rc.5
|
||||
|
||||
require (
|
||||
git.scuroneko.dev/scuroneko/extypes v1.2.3
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
// ErrInvalidPayloadType is returned when callback payload encoding type is unknown.
|
||||
|
||||
+3
-15
@@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
@@ -317,7 +317,7 @@ func TestPrepareUpdateCtxContract(t *testing.T) {
|
||||
name: "poll answer",
|
||||
update: &tgapi.Update{
|
||||
Type: tgapi.UpdateTypePollAnswer,
|
||||
PollAnswer: &tgapi.PollAnswer{User: &tgapi.User{ID: 115}},
|
||||
PollAnswer: &tgapi.PollAnswer{User: tgapi.User{ID: 115}},
|
||||
},
|
||||
wantFrom: true,
|
||||
wantFromID: 115,
|
||||
@@ -326,7 +326,7 @@ func TestPrepareUpdateCtxContract(t *testing.T) {
|
||||
name: "anonymous poll answer",
|
||||
update: &tgapi.Update{
|
||||
Type: tgapi.UpdateTypePollAnswer,
|
||||
PollAnswer: &tgapi.PollAnswer{VoterChat: &tgapi.Chat{ID: -2007}},
|
||||
PollAnswer: &tgapi.PollAnswer{VoterChat: tgapi.Chat{ID: -2007}},
|
||||
},
|
||||
wantChat: true,
|
||||
wantChatID: -2007,
|
||||
@@ -428,18 +428,6 @@ func TestPrepareUpdateCtxContract(t *testing.T) {
|
||||
wantFrom: true,
|
||||
wantFromID: 121,
|
||||
},
|
||||
{
|
||||
name: "stopped message generation",
|
||||
update: &tgapi.Update{
|
||||
Type: tgapi.UpdateTypeMessageGenerationStopped,
|
||||
StoppedMessageGeneration: &tgapi.MessageGenerationStopped{
|
||||
Chat: tgapi.Chat{ID: -2012},
|
||||
DraftID: 7,
|
||||
},
|
||||
},
|
||||
wantChat: true,
|
||||
wantChatID: -2012,
|
||||
},
|
||||
{
|
||||
name: "giveaway chat boost has no user",
|
||||
update: &tgapi.Update{
|
||||
|
||||
+61
-82
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/extypes"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,9 +31,8 @@ type InlineKeyboardButtonBuilder struct {
|
||||
emojiID string
|
||||
style tgapi.KeyboardButtonStyle
|
||||
|
||||
url string
|
||||
data string
|
||||
disabled bool
|
||||
url string
|
||||
data string
|
||||
|
||||
payloadType BotPayloadType
|
||||
}
|
||||
@@ -65,21 +64,10 @@ func (b InlineKeyboardButtonBuilder) SetURL(url string) InlineKeyboardButtonBuil
|
||||
b.url = url
|
||||
if url != "" {
|
||||
b.data = ""
|
||||
b.disabled = false
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// SetDisabled makes the button inert and clears URL and callback actions.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func (b InlineKeyboardButtonBuilder) SetDisabled() InlineKeyboardButtonBuilder {
|
||||
b.url = ""
|
||||
b.data = ""
|
||||
b.disabled = true
|
||||
return b
|
||||
}
|
||||
|
||||
// SetPayloadType sets the encoding used by SetCallbackData.
|
||||
func (b InlineKeyboardButtonBuilder) SetPayloadType(t BotPayloadType) InlineKeyboardButtonBuilder {
|
||||
b.payloadType = t
|
||||
@@ -95,7 +83,6 @@ func (b InlineKeyboardButtonBuilder) SetPayloadType(t BotPayloadType) InlineKeyb
|
||||
// Example: SetCallbackDataJSON("delete_user", 123, "confirm") → {"cmd":"delete_user","args":["123","confirm"]}.
|
||||
func (b InlineKeyboardButtonBuilder) SetCallbackDataJSON(cmd string, args ...any) InlineKeyboardButtonBuilder {
|
||||
b.url = ""
|
||||
b.disabled = false
|
||||
b.data = NewCallbackData(cmd, args...).ToJSON()
|
||||
return b
|
||||
}
|
||||
@@ -104,7 +91,6 @@ func (b InlineKeyboardButtonBuilder) SetCallbackDataJSON(cmd string, args ...any
|
||||
// Base64 does not bypass Telegram's 64-byte callback-data limit.
|
||||
func (b InlineKeyboardButtonBuilder) SetCallbackDataBase64(cmd string, args ...any) InlineKeyboardButtonBuilder {
|
||||
b.url = ""
|
||||
b.disabled = false
|
||||
b.data = NewCallbackData(cmd, args...).ToBase64()
|
||||
return b
|
||||
}
|
||||
@@ -112,7 +98,6 @@ func (b InlineKeyboardButtonBuilder) SetCallbackDataBase64(cmd string, args ...a
|
||||
// SetCallbackDataCompact sets a structured callback payload encoded as compact text.
|
||||
func (b InlineKeyboardButtonBuilder) SetCallbackDataCompact(cmd string, args ...any) InlineKeyboardButtonBuilder {
|
||||
b.url = ""
|
||||
b.disabled = false
|
||||
b.data = NewCallbackData(cmd, args...).ToCompact()
|
||||
return b
|
||||
}
|
||||
@@ -120,7 +105,6 @@ func (b InlineKeyboardButtonBuilder) SetCallbackDataCompact(cmd string, args ...
|
||||
// SetCallbackDataCompactBase64 sets a compact callback payload encoded as Base64.
|
||||
func (b InlineKeyboardButtonBuilder) SetCallbackDataCompactBase64(cmd string, args ...any) InlineKeyboardButtonBuilder {
|
||||
b.url = ""
|
||||
b.disabled = false
|
||||
b.data = NewCallbackData(cmd, args...).ToCompactBase64()
|
||||
return b
|
||||
}
|
||||
@@ -129,7 +113,6 @@ func (b InlineKeyboardButtonBuilder) SetCallbackDataCompactBase64(cmd string, ar
|
||||
// The default payload type is JSON.
|
||||
func (b InlineKeyboardButtonBuilder) SetCallbackData(cmd string, args ...any) InlineKeyboardButtonBuilder {
|
||||
b.url = ""
|
||||
b.disabled = false
|
||||
switch b.payloadType {
|
||||
case BotPayloadJSON:
|
||||
b.data = NewCallbackData(cmd, args...).ToJSON()
|
||||
@@ -145,32 +128,27 @@ func (b InlineKeyboardButtonBuilder) SetCallbackData(cmd string, args ...any) In
|
||||
return b
|
||||
}
|
||||
|
||||
func (b InlineKeyboardButtonBuilder) validate() error { return validateButton(b.build()) }
|
||||
|
||||
func (b InlineKeyboardButtonBuilder) build() tgapi.InlineKeyboardButton {
|
||||
var disabled *tgapi.DisabledButton
|
||||
if b.disabled {
|
||||
disabled = &tgapi.DisabledButton{}
|
||||
}
|
||||
return tgapi.InlineKeyboardButton{
|
||||
Text: b.text,
|
||||
URL: b.url,
|
||||
Style: b.style,
|
||||
IconCustomEmojiID: b.emojiID,
|
||||
CallbackData: b.data,
|
||||
Disabled: disabled,
|
||||
}
|
||||
}
|
||||
|
||||
// Validate checks that the button has exactly one action and valid callback data.
|
||||
func (b InlineKeyboardButtonBuilder) Validate() error { return b.validate() }
|
||||
func (b InlineKeyboardButtonBuilder) Validate() error {
|
||||
return validateInlineKeyboardButton(b.build())
|
||||
}
|
||||
|
||||
// Build validates and returns the configured inline keyboard button.
|
||||
func (b InlineKeyboardButtonBuilder) Build() (tgapi.InlineKeyboardButton, error) {
|
||||
if err := b.validate(); err != nil {
|
||||
button := b.build()
|
||||
if err := validateInlineKeyboardButton(button); err != nil {
|
||||
return tgapi.InlineKeyboardButton{}, err
|
||||
}
|
||||
button := b.build()
|
||||
return button, nil
|
||||
}
|
||||
|
||||
@@ -184,14 +162,13 @@ type InlineKeyboard struct {
|
||||
// CurrentLine is the row currently being built.
|
||||
CurrentLine extypes.Slice[tgapi.InlineKeyboardButton]
|
||||
// Lines contains completed keyboard rows.
|
||||
Lines [][]tgapi.InlineKeyboardButton
|
||||
maxRow int // Max buttons per row (e.g., 3 or 4)
|
||||
unlimitedRows bool
|
||||
Lines [][]tgapi.InlineKeyboardButton
|
||||
maxRow int // Max buttons per row (e.g., 3 or 4)
|
||||
|
||||
payloadType BotPayloadType // Serialization format for callback data (JSON or Base64)
|
||||
}
|
||||
|
||||
// NewInlineKeyboardJSON creates a keyboard builder with a positive maximum
|
||||
// NewInlineKeyboardJSON creates a new keyboard builder with the specified maximum
|
||||
// number of buttons per row.
|
||||
//
|
||||
// Example: NewInlineKeyboardJSON(3) creates a keyboard with at most 3 buttons per line.
|
||||
@@ -199,7 +176,7 @@ func NewInlineKeyboardJSON(maxRow int) *InlineKeyboard {
|
||||
return NewInlineKeyboard(BotPayloadJSON, maxRow)
|
||||
}
|
||||
|
||||
// NewInlineKeyboardBase64 creates a keyboard builder with a positive maximum
|
||||
// NewInlineKeyboardBase64 creates a new keyboard builder with the specified maximum
|
||||
// number of buttons per row, using Base64 encoding for button payloads.
|
||||
//
|
||||
// Example: NewInlineKeyboardBase64(3) creates a keyboard with at most 3 buttons per line.
|
||||
@@ -217,8 +194,8 @@ func NewInlineKeyboardCompactBase64(maxRow int) *InlineKeyboard {
|
||||
return NewInlineKeyboard(BotPayloadCompactBase64, maxRow)
|
||||
}
|
||||
|
||||
// NewInlineKeyboard creates a keyboard builder with the specified payload encoding
|
||||
// and a positive maximum number of buttons per row.
|
||||
// NewInlineKeyboard creates a new keyboard builder with the specified payload encoding
|
||||
// type and maximum number of buttons per row.
|
||||
//
|
||||
// Use NewInlineKeyboardJSON or NewInlineKeyboardBase64 for the common cases.
|
||||
func NewInlineKeyboard(payloadType BotPayloadType, maxRow int) *InlineKeyboard {
|
||||
@@ -241,27 +218,19 @@ func (in *InlineKeyboard) SetPayloadType(t BotPayloadType) *InlineKeyboard {
|
||||
// GetPayloadType returns the keyboard-local callback payload encoding type.
|
||||
func (in *InlineKeyboard) GetPayloadType() BotPayloadType { return in.payloadType }
|
||||
|
||||
// SetMaxRow sets the positive number of buttons appended to a row before the
|
||||
// keyboard automatically starts a new line. Get returns ErrInlineKeyboardMaxRow
|
||||
// when maxRow is not positive.
|
||||
// SetMaxRow sets the maximum number of buttons appended to a row before the
|
||||
// keyboard automatically starts a new line. Values <= 0 retain the legacy
|
||||
// unlimited-row behavior; this convention is subject to change in v2.
|
||||
func (in *InlineKeyboard) SetMaxRow(maxRow int) *InlineKeyboard {
|
||||
in.maxRow = maxRow
|
||||
in.unlimitedRows = false
|
||||
return in
|
||||
}
|
||||
|
||||
// SetUnlimitedRows disables automatic row wrapping explicitly.
|
||||
func (in *InlineKeyboard) SetUnlimitedRows() *InlineKeyboard {
|
||||
in.maxRow = 0
|
||||
in.unlimitedRows = true
|
||||
return in
|
||||
}
|
||||
|
||||
// GetMaxRow returns the maximum number of buttons per row, or zero in explicit unlimited mode.
|
||||
// GetMaxRow returns the maximum number of buttons per row.
|
||||
func (in *InlineKeyboard) GetMaxRow() int { return in.maxRow }
|
||||
|
||||
func (in *InlineKeyboard) append(button tgapi.InlineKeyboardButton) *InlineKeyboard {
|
||||
if !in.unlimitedRows && in.maxRow > 0 && in.CurrentLine.Len() >= in.maxRow {
|
||||
if in.maxRow > 0 && in.CurrentLine.Len() >= in.maxRow {
|
||||
in.AddLine()
|
||||
}
|
||||
in.CurrentLine = in.CurrentLine.Push(button)
|
||||
@@ -285,7 +254,7 @@ func (in *InlineKeyboard) AddURLButtonStyle(text string, style tgapi.KeyboardBut
|
||||
func (in *InlineKeyboard) AddCallbackButton(text, cmd string, args ...any) *InlineKeyboard {
|
||||
return in.append(tgapi.InlineKeyboardButton{
|
||||
Text: text,
|
||||
CallbackData: NewCallbackData(cmd, args...).encode(in.payloadType),
|
||||
CallbackData: NewCallbackData(cmd, args...).Encode(in.payloadType),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -295,7 +264,7 @@ func (in *InlineKeyboard) AddCallbackButtonStyle(text string, style tgapi.Keyboa
|
||||
return in.append(tgapi.InlineKeyboardButton{
|
||||
Text: text,
|
||||
Style: style,
|
||||
CallbackData: NewCallbackData(cmd, args...).encode(in.payloadType),
|
||||
CallbackData: NewCallbackData(cmd, args...).Encode(in.payloadType),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -320,7 +289,7 @@ func (in *InlineKeyboard) AddLine() *InlineKeyboard {
|
||||
// Automatically flushes the current line if not empty.
|
||||
//
|
||||
// Returns a pointer to a ReplyMarkup suitable for use with tgapi.SendMessage.
|
||||
func (in *InlineKeyboard) Get() (*tgapi.ReplyMarkup, error) {
|
||||
func (in *InlineKeyboard) Get() *tgapi.ReplyMarkup {
|
||||
if in.CurrentLine.Len() > 0 {
|
||||
in.AddLine()
|
||||
}
|
||||
@@ -328,26 +297,38 @@ func (in *InlineKeyboard) Get() (*tgapi.ReplyMarkup, error) {
|
||||
for i := range in.Lines {
|
||||
lines[i] = append([]tgapi.InlineKeyboardButton(nil), in.Lines[i]...)
|
||||
}
|
||||
markup := &tgapi.ReplyMarkup{InlineKeyboard: lines}
|
||||
if err := in.validate(); err != nil {
|
||||
return &tgapi.ReplyMarkup{InlineKeyboard: lines}
|
||||
}
|
||||
|
||||
// GetValidated finalizes and validates the keyboard before returning it.
|
||||
//
|
||||
// Existing fluent Add* methods remain error-free for v1 compatibility. Their
|
||||
// signatures are subject to change in v2; new code should use GetValidated.
|
||||
func (in *InlineKeyboard) GetValidated() (*tgapi.ReplyMarkup, error) {
|
||||
markup := in.Get()
|
||||
if err := in.validateMarkup(markup); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return markup, nil
|
||||
}
|
||||
|
||||
func (in *InlineKeyboard) validate() error {
|
||||
if !in.unlimitedRows && in.maxRow <= 0 {
|
||||
return fmt.Errorf("%w: got %d", ErrInlineKeyboardMaxRow, in.maxRow)
|
||||
// Validate checks completed and pending rows without finalizing the keyboard.
|
||||
func (in *InlineKeyboard) Validate() error {
|
||||
lines := make([][]tgapi.InlineKeyboardButton, 0, len(in.Lines)+1)
|
||||
lines = append(lines, in.Lines...)
|
||||
if len(in.CurrentLine) > 0 {
|
||||
lines = append(lines, in.CurrentLine)
|
||||
}
|
||||
for rowIndex, row := range in.Lines {
|
||||
if !in.unlimitedRows && len(row) > in.maxRow {
|
||||
return fmt.Errorf(
|
||||
"%w: row %d has %d buttons, limit %d",
|
||||
ErrInlineKeyboardRowTooLong, rowIndex, len(row), in.maxRow,
|
||||
)
|
||||
return in.validateMarkup(&tgapi.ReplyMarkup{InlineKeyboard: lines})
|
||||
}
|
||||
|
||||
func (in *InlineKeyboard) validateMarkup(markup *tgapi.ReplyMarkup) error {
|
||||
for rowIndex, row := range markup.InlineKeyboard {
|
||||
if in.maxRow > 0 && len(row) > in.maxRow {
|
||||
return fmt.Errorf("%w: row %d has %d buttons, limit %d", ErrInlineKeyboardRowTooLong, rowIndex, len(row), in.maxRow)
|
||||
}
|
||||
for columnIndex, button := range row {
|
||||
if err := validateButton(button); err != nil {
|
||||
if err := validateInlineKeyboardButton(button); err != nil {
|
||||
return fmt.Errorf("row %d button %d: %w", rowIndex, columnIndex, err)
|
||||
}
|
||||
}
|
||||
@@ -355,22 +336,19 @@ func (in *InlineKeyboard) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateButton(b tgapi.InlineKeyboardButton) error {
|
||||
func validateInlineKeyboardButton(button tgapi.InlineKeyboardButton) error {
|
||||
actions := 0
|
||||
if b.URL != "" {
|
||||
if button.URL != "" {
|
||||
actions++
|
||||
}
|
||||
if b.CallbackData != "" {
|
||||
actions++
|
||||
}
|
||||
if b.Disabled != nil {
|
||||
if button.CallbackData != "" {
|
||||
actions++
|
||||
}
|
||||
if actions != 1 {
|
||||
return ErrInlineKeyboardButtonAction
|
||||
}
|
||||
if b.CallbackData != "" {
|
||||
length := len([]byte(b.CallbackData))
|
||||
if button.CallbackData != "" {
|
||||
length := len([]byte(button.CallbackData))
|
||||
if length < 1 || length > 64 {
|
||||
return fmt.Errorf("%w: got %d", ErrCallbackDataLength, length)
|
||||
}
|
||||
@@ -458,7 +436,10 @@ func (d CallbackData) ToCompactBase64() string {
|
||||
return data
|
||||
}
|
||||
|
||||
func (d CallbackData) encode(t BotPayloadType) string {
|
||||
// Encode serializes the CallbackData according to the specified payload type.
|
||||
// Supported types: BotPayloadJSON, BotPayloadBase64, BotPayloadCompact, and BotPayloadCompactBase64.
|
||||
// For unknown types, returns an empty string.
|
||||
func (d CallbackData) Encode(t BotPayloadType) string {
|
||||
switch t {
|
||||
case BotPayloadBase64:
|
||||
return d.ToBase64()
|
||||
@@ -472,15 +453,13 @@ func (d CallbackData) encode(t BotPayloadType) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Encode serializes the CallbackData according to the specified payload type.
|
||||
// Supported types: BotPayloadJSON, BotPayloadBase64, BotPayloadCompact, and BotPayloadCompactBase64.
|
||||
// For unknown types, returns an empty string.
|
||||
func (d CallbackData) Encode(t BotPayloadType) (string, error) {
|
||||
if t != BotPayloadBase64 && t != BotPayloadJSON && t != BotPayloadCompact && t != BotPayloadCompactBase64 {
|
||||
return "", ErrInvalidPayloadType
|
||||
}
|
||||
encoded := d.encode(t)
|
||||
// EncodeValidated serializes callback data and enforces Telegram's 1-64 byte limit.
|
||||
func (d CallbackData) EncodeValidated(t BotPayloadType) (string, error) {
|
||||
encoded := d.Encode(t)
|
||||
if encoded == "" {
|
||||
if t != BotPayloadBase64 && t != BotPayloadJSON && t != BotPayloadCompact && t != BotPayloadCompactBase64 {
|
||||
return "", ErrInvalidPayloadType
|
||||
}
|
||||
return "", ErrCallbackDataLength
|
||||
}
|
||||
if length := len([]byte(encoded)); length > 64 {
|
||||
|
||||
+19
-107
@@ -13,10 +13,7 @@ func TestInlineKeyboardWrapsRowsAndEncodesJSONPayloads(t *testing.T) {
|
||||
AddCallbackButton("B", "cmd", 2).
|
||||
AddCallbackButton("C", "cmd", 3)
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("keyboard encoding error: %s", err)
|
||||
}
|
||||
markup := kb.Get()
|
||||
if got := len(markup.InlineKeyboard); got != 2 {
|
||||
t.Fatalf("unexpected row count: %d", got)
|
||||
}
|
||||
@@ -39,11 +36,7 @@ func TestInlineKeyboardBuilderPreservesConfiguredButtonFields(t *testing.T) {
|
||||
SetURL("https://example.test"),
|
||||
)
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
button := markup.InlineKeyboard[0][0]
|
||||
button := kb.Get().InlineKeyboard[0][0]
|
||||
if button.Style != ButtonStylePrimary {
|
||||
t.Fatalf("unexpected style: %q", button.Style)
|
||||
}
|
||||
@@ -56,11 +49,7 @@ func TestInlineKeyboardButtonBuilderSetCallbackDataDefaultsToJSON(t *testing.T)
|
||||
kb := NewInlineKeyboardBase64(1).
|
||||
AddButton(NewInlineKeyboardButton("A").SetCallbackData("cmd", 1, "two"))
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
button := markup.InlineKeyboard[0][0]
|
||||
button := kb.Get().InlineKeyboard[0][0]
|
||||
if !strings.Contains(button.CallbackData, `"cmd":"cmd"`) {
|
||||
t.Fatalf("expected JSON callback payload, got %q", button.CallbackData)
|
||||
}
|
||||
@@ -73,12 +62,7 @@ func TestInlineKeyboardButtonBuilderSetCallbackDataUsesConfiguredPayloadType(t *
|
||||
SetCallbackData("cmd", 1, "two"),
|
||||
)
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
button := markup.InlineKeyboard[0][0]
|
||||
got, _, err := decodePayload(BotPayloadJSON, button.CallbackData, false)
|
||||
got, _, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, false)
|
||||
if err != nil {
|
||||
t.Fatalf("decodePayload returned error: %v", err)
|
||||
}
|
||||
@@ -109,16 +93,10 @@ func TestInlineKeyboardButtonBuilderKeepsExactlyOneAction(t *testing.T) {
|
||||
|
||||
func TestInlineKeyboardGetReturnsIndependentMarkup(t *testing.T) {
|
||||
keyboard := NewInlineKeyboardJSON(1).AddURLButton("Docs", "https://example.test")
|
||||
first, err := keyboard.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
first := keyboard.Get()
|
||||
first.InlineKeyboard[0][0].Text = "mutated"
|
||||
|
||||
second, err := keyboard.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
second := keyboard.Get()
|
||||
if got := second.InlineKeyboard[0][0].Text; got != "Docs" {
|
||||
t.Fatalf("Get exposed builder state for mutation: got %q", got)
|
||||
}
|
||||
@@ -139,11 +117,7 @@ func TestDecodePayloadAcceptsBase64KeyboardPayloadWhenBotPrefersJSON(t *testing.
|
||||
kb := NewInlineKeyboardBase64(1).
|
||||
AddCallbackButton("A", "cmd", 1, "two")
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
got, _, err := decodePayload(BotPayloadJSON, markup.InlineKeyboard[0][0].CallbackData, false)
|
||||
got, _, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, false)
|
||||
if err != nil {
|
||||
t.Fatalf("decodePayload returned error: %v", err)
|
||||
}
|
||||
@@ -158,11 +132,7 @@ func TestDecodePayloadAcceptsJSONKeyboardPayloadWhenBotPrefersBase64(t *testing.
|
||||
kb := NewInlineKeyboardJSON(1).
|
||||
AddCallbackButton("A", "cmd", 1, "two")
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
got, _, err := decodePayload(BotPayloadBase64, markup.InlineKeyboard[0][0].CallbackData, false)
|
||||
got, _, err := decodePayload(BotPayloadBase64, kb.Get().InlineKeyboard[0][0].CallbackData, false)
|
||||
if err != nil {
|
||||
t.Fatalf("decodePayload returned error: %v", err)
|
||||
}
|
||||
@@ -177,11 +147,7 @@ func TestDecodePayloadAcceptsCompactKeyboardPayloadWhenBotPrefersJSON(t *testing
|
||||
kb := NewInlineKeyboardCompact(1).
|
||||
AddCallbackButton("A", "cmd", 1, "two")
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
got, decodedType, err := decodePayload(BotPayloadJSON, markup.InlineKeyboard[0][0].CallbackData, false)
|
||||
got, decodedType, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, false)
|
||||
if err != nil {
|
||||
t.Fatalf("decodePayload returned error: %v", err)
|
||||
}
|
||||
@@ -199,11 +165,7 @@ func TestDecodePayloadAcceptsCompactBase64KeyboardPayloadWhenBotPrefersJSON(t *t
|
||||
kb := NewInlineKeyboardCompactBase64(1).
|
||||
AddCallbackButton("A", "cmd", 1, "two")
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
got, decodedType, err := decodePayload(BotPayloadJSON, markup.InlineKeyboard[0][0].CallbackData, false)
|
||||
got, decodedType, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, false)
|
||||
if err != nil {
|
||||
t.Fatalf("decodePayload returned error: %v", err)
|
||||
}
|
||||
@@ -275,11 +237,7 @@ func TestDecodePayloadStrictRejectsCompactMismatchedType(t *testing.T) {
|
||||
kb := NewInlineKeyboardCompact(1).
|
||||
AddCallbackButton("A", "cmd", 1)
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
_, _, err = decodePayload(BotPayloadJSON, markup.InlineKeyboard[0][0].CallbackData, true)
|
||||
_, _, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, true)
|
||||
if !errors.Is(err, ErrPayloadTypeMismatch) {
|
||||
t.Fatalf("expected ErrPayloadTypeMismatch, got %v", err)
|
||||
}
|
||||
@@ -289,11 +247,7 @@ func TestDecodePayloadStrictRejectsMismatchedType(t *testing.T) {
|
||||
kb := NewInlineKeyboardBase64(1).
|
||||
AddCallbackButton("A", "cmd", 1)
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
_, _, err = decodePayload(BotPayloadJSON, markup.InlineKeyboard[0][0].CallbackData, true)
|
||||
_, _, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, true)
|
||||
if !errors.Is(err, ErrPayloadTypeMismatch) {
|
||||
t.Fatalf("expected ErrPayloadTypeMismatch, got %v", err)
|
||||
}
|
||||
@@ -311,12 +265,12 @@ func TestInlineKeyboardValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
keyboard := NewInlineKeyboardCompact(1).AddButton(button)
|
||||
if _, err := keyboard.Get(); !errors.Is(err, ErrCallbackDataLength) {
|
||||
if _, err := keyboard.GetValidated(); !errors.Is(err, ErrCallbackDataLength) {
|
||||
t.Fatalf("expected validated keyboard to reject callback data, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallbackDataEncodeBoundaries(t *testing.T) {
|
||||
func TestCallbackDataEncodeValidatedBoundaries(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
command string
|
||||
@@ -329,7 +283,7 @@ func TestCallbackDataEncodeBoundaries(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
encoded, err := (CallbackData{Command: tt.command}).Encode(BotPayloadCompact)
|
||||
encoded, err := (CallbackData{Command: tt.command}).EncodeValidated(BotPayloadCompact)
|
||||
if !errors.Is(err, tt.wantErr) {
|
||||
t.Fatalf("expected %v, got %v", tt.wantErr, err)
|
||||
}
|
||||
@@ -338,7 +292,7 @@ func TestCallbackDataEncodeBoundaries(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
if _, err := (CallbackData{Command: "ok"}).Encode(BotPayloadType("unknown")); !errors.Is(err, ErrInvalidPayloadType) {
|
||||
if _, err := (CallbackData{Command: "ok"}).EncodeValidated(BotPayloadType("unknown")); !errors.Is(err, ErrInvalidPayloadType) {
|
||||
t.Fatalf("expected ErrInvalidPayloadType, got %v", err)
|
||||
}
|
||||
}
|
||||
@@ -350,50 +304,8 @@ func TestInlineKeyboardLoweredMaxRowStillWraps(t *testing.T) {
|
||||
SetMaxRow(1).
|
||||
AddURLButton("C", "https://example.test/c")
|
||||
|
||||
markup, err := keyboard.Get()
|
||||
if !errors.Is(err, ErrInlineKeyboardRowTooLong) || markup != nil {
|
||||
t.Fatalf("expected strict validation failure for the existing oversized row: %v", err)
|
||||
}
|
||||
if len(keyboard.Lines) != 2 || len(keyboard.Lines[0]) != 2 || len(keyboard.Lines[1]) != 1 {
|
||||
t.Fatalf("lowered maxRow stopped automatic wrapping: %#v", keyboard.Lines)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInlineKeyboardUnlimitedRowsMustBeExplicit(t *testing.T) {
|
||||
for _, maxRow := range []int{0, -1} {
|
||||
keyboard := NewInlineKeyboardJSON(maxRow).AddURLButton("A", "https://example.test/a")
|
||||
if markup, err := keyboard.Get(); !errors.Is(err, ErrInlineKeyboardMaxRow) || markup != nil {
|
||||
t.Fatalf("expected invalid row limit %d, markup=%#v err=%v", maxRow, markup, err)
|
||||
}
|
||||
}
|
||||
|
||||
keyboard := NewInlineKeyboardJSON(1).
|
||||
SetUnlimitedRows().
|
||||
AddURLButton("A", "https://example.test/a").
|
||||
AddURLButton("B", "https://example.test/b")
|
||||
markup, err := keyboard.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("explicit unlimited rows failed: %v", err)
|
||||
}
|
||||
if len(markup.InlineKeyboard) != 1 || len(markup.InlineKeyboard[0]) != 2 {
|
||||
t.Fatalf("unexpected unlimited keyboard: %#v", markup.InlineKeyboard)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInlineKeyboardDisabledButton(t *testing.T) {
|
||||
button, err := NewInlineKeyboardButton("Unavailable").SetDisabled().Build()
|
||||
if err != nil {
|
||||
t.Fatalf("Build returned error: %v", err)
|
||||
}
|
||||
if button.Disabled == nil || button.URL != "" || button.CallbackData != "" {
|
||||
t.Fatalf("unexpected disabled button: %#v", button)
|
||||
}
|
||||
|
||||
button, err = NewInlineKeyboardButton("Open").SetDisabled().SetURL("https://example.test").Build()
|
||||
if err != nil {
|
||||
t.Fatalf("SetURL didn't replace disabled action: %v", err)
|
||||
}
|
||||
if button.Disabled != nil || button.URL == "" {
|
||||
t.Fatalf("unexpected URL button: %#v", button)
|
||||
markup := keyboard.Get()
|
||||
if len(markup.InlineKeyboard) != 2 || len(markup.InlineKeyboard[0]) != 2 || len(markup.InlineKeyboard[1]) != 1 {
|
||||
t.Fatalf("lowered maxRow stopped automatic wrapping: %#v", markup.InlineKeyboard)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"iter"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
// Updates fetches new updates from Telegram API using long polling.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestUpdatesIterYieldsFetchError(t *testing.T) {
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package laniakea
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestV2MigrationSurfaceCompiles(t *testing.T) {
|
||||
runner := NewRunner[NoData]("sync", func(ctx context.Context, bot *Bot[NoData]) error {
|
||||
return ctx.Err()
|
||||
})
|
||||
if runner.name != "sync" {
|
||||
t.Fatalf("unexpected runner: %+v", runner)
|
||||
}
|
||||
|
||||
if _, err := NewCallbackData("open", 42).Encode(BotPayloadCompact); err != nil {
|
||||
t.Fatalf("Encode returned error: %v", err)
|
||||
}
|
||||
|
||||
keyboard := NewInlineKeyboardJSON(2).AddCallbackButton("Open", "open", 42)
|
||||
if _, err := keyboard.Get(); err != nil {
|
||||
t.Fatalf("Get returned error: %v", err)
|
||||
}
|
||||
|
||||
unlimited := NewInlineKeyboardJSON(1).
|
||||
SetUnlimitedRows().
|
||||
AddURLButton("A", "https://example.test/a").
|
||||
AddURLButton("B", "https://example.test/b")
|
||||
if _, err := unlimited.Get(); err != nil {
|
||||
t.Fatalf("explicit unlimited keyboard failed: %v", err)
|
||||
}
|
||||
}
|
||||
+7
-31
@@ -9,8 +9,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgrich"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgrich"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
@@ -106,11 +106,7 @@ func (ctx *MessageContext) buildEditMessageTextParams(messageID int, keyboard *I
|
||||
params.ParseMode = parseMode
|
||||
}
|
||||
if keyboard != nil {
|
||||
markup, err := keyboard.Get()
|
||||
if err != nil {
|
||||
return params, fmt.Errorf("keyboard get error: %w", err)
|
||||
}
|
||||
params.ReplyMarkup = markup
|
||||
params.ReplyMarkup = keyboard.Get()
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
@@ -222,12 +218,7 @@ func (ctx *MessageContext) editPhotoText(messageID int, text string, kb *InlineK
|
||||
return nil
|
||||
}
|
||||
if kb != nil {
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
ctx.Logger.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
params.ReplyMarkup = markup
|
||||
params.ReplyMarkup = kb.Get()
|
||||
}
|
||||
|
||||
msg, _, err := ctx.API.EditMessageCaptionWithContext(ctx.Context(), params)
|
||||
@@ -284,12 +275,7 @@ func (ctx *MessageContext) answer(text string, keyboard *InlineKeyboard, parseMo
|
||||
ParseMode: parseMode,
|
||||
}
|
||||
if keyboard != nil {
|
||||
markup, err := keyboard.Get()
|
||||
if err != nil {
|
||||
ctx.Logger.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
params.ReplyMarkup = markup
|
||||
params.ReplyMarkup = keyboard.Get()
|
||||
}
|
||||
if ctx.Msg.MessageThreadID > 0 {
|
||||
params.MessageThreadID = ctx.Msg.MessageThreadID
|
||||
@@ -420,12 +406,7 @@ func (ctx *MessageContext) answerPhoto(photoID, text string, kb *InlineKeyboard,
|
||||
Photo: photoID,
|
||||
}
|
||||
if kb != nil {
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
ctx.Logger.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
params.ReplyMarkup = markup
|
||||
params.ReplyMarkup = kb.Get()
|
||||
}
|
||||
if ctx.Msg.MessageThreadID > 0 {
|
||||
params.MessageThreadID = ctx.Msg.MessageThreadID
|
||||
@@ -874,12 +855,7 @@ func (ctx *MessageContext) richAnswer(rich tgapi.InputRichMessage, keyboard *Inl
|
||||
RichMessage: rich,
|
||||
}
|
||||
if keyboard != nil {
|
||||
markup, err := keyboard.Get()
|
||||
if err != nil {
|
||||
ctx.Logger.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
params.ReplyMarkup = markup
|
||||
params.ReplyMarkup = keyboard.Get()
|
||||
}
|
||||
if ctx.Msg.MessageThreadID > 0 {
|
||||
params.MessageThreadID = int64(ctx.Msg.MessageThreadID)
|
||||
|
||||
+3
-7
@@ -9,8 +9,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgrich"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgrich"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
@@ -442,11 +442,7 @@ func TestNewInlineKeyboardButtonUsesContextPayloadType(t *testing.T) {
|
||||
kb := NewInlineKeyboardJSON(1).
|
||||
AddButton(ctx.NewInlineKeyboardButton("A").SetCallbackData("cmd", 1, "two"))
|
||||
|
||||
markup, err := kb.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
got, _, err := decodePayload(BotPayloadJSON, markup.InlineKeyboard[0][0].CallbackData, false)
|
||||
got, _, err := decodePayload(BotPayloadJSON, kb.Get().InlineKeyboard[0][0].CallbackData, false)
|
||||
if err != nil {
|
||||
t.Fatalf("decodePayload returned error: %v", err)
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func (bot *Bot[T]) handleMessage(update *tgapi.Update, ctx *MessageContext) bool {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
// HandlerEventKind identifies the kind of handler observed by runtime events.
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/extypes"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
type middlewareErrorObserver struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
// Policy defines a reusable authorization rule for the current update context.
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
+34
-14
@@ -6,8 +6,16 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// RunnerFn is a cancelable task executed by a Bot runtime.
|
||||
type RunnerFn[T AppData] func(context.Context, *Bot[T]) error
|
||||
// RunnerFn is the legacy function type for a runner. It receives a pointer to
|
||||
// the Bot and returns an error if execution fails. New blocking or I/O work
|
||||
// should use ContextRunnerFn so runtime cancellation can stop the callback.
|
||||
//
|
||||
// Subject to change in v2: runner callbacks may require context.Context.
|
||||
type RunnerFn[T AppData] func(*Bot[T]) error
|
||||
|
||||
// ContextRunnerFn is a cancelable runner function.
|
||||
// The runtime context is canceled when polling or webhook execution stops.
|
||||
type ContextRunnerFn[T AppData] func(context.Context, *Bot[T]) error
|
||||
|
||||
// Runner represents a configurable background or one-time task to be
|
||||
// executed by a Bot.
|
||||
@@ -25,6 +33,22 @@ type Runner[T AppData] struct {
|
||||
async bool // If true, runs in a goroutine; else, runs synchronously
|
||||
every time.Duration // Interval between periodic executions; zero means one-shot
|
||||
fn RunnerFn[T] // The function to execute
|
||||
ctxFn ContextRunnerFn[T]
|
||||
}
|
||||
|
||||
func executeRunnerWithContext[T AppData](ctx context.Context, runner Runner[T], bot *Bot[T]) (err error) {
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
err = fmt.Errorf("runner %q panicked: %v", runner.name, recovered)
|
||||
}
|
||||
}()
|
||||
if runner.ctxFn != nil {
|
||||
return runner.ctxFn(ctx, bot)
|
||||
}
|
||||
if runner.fn == nil {
|
||||
return fmt.Errorf("runner %q has no function", runner.name)
|
||||
}
|
||||
return runner.fn(bot)
|
||||
}
|
||||
|
||||
// NewRunner creates a new Runner with the given name and function.
|
||||
@@ -33,10 +57,18 @@ type Runner[T AppData] struct {
|
||||
// goroutine that fires once when the bot runtime starts. Use Async and Every
|
||||
// to customize this. Do not call builder methods concurrently or after the
|
||||
// bot runtime has begun executing runners.
|
||||
//
|
||||
// Subject to change in v2: NewContextRunner may become the primary constructor.
|
||||
func NewRunner[T AppData](name string, fn RunnerFn[T]) Runner[T] {
|
||||
return Runner[T]{name: name, fn: fn, async: true, every: 0}
|
||||
}
|
||||
|
||||
// NewContextRunner creates a runner whose callback observes runtime cancellation.
|
||||
// It is the preferred constructor for I/O, blocking, and periodic work.
|
||||
func NewContextRunner[T AppData](name string, fn ContextRunnerFn[T]) Runner[T] {
|
||||
return Runner[T]{name: name, ctxFn: fn, async: true, every: 0}
|
||||
}
|
||||
|
||||
// Async sets whether the runner executes synchronously or asynchronously.
|
||||
// If true, the runner runs in a goroutine (non-blocking).
|
||||
// If false, the runner blocks the caller during execution.
|
||||
@@ -166,15 +198,3 @@ func (bot *Bot[T]) ExecRunners(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func executeRunnerWithContext[T AppData](ctx context.Context, runner Runner[T], bot *Bot[T]) (err error) {
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
err = fmt.Errorf("runner %q panicked: %v", runner.name, recovered)
|
||||
}
|
||||
}()
|
||||
if runner.fn == nil {
|
||||
return fmt.Errorf("runner %q has no function", runner.name)
|
||||
}
|
||||
return runner.fn(ctx, bot)
|
||||
}
|
||||
|
||||
+5
-5
@@ -19,7 +19,7 @@ func TestExecRunnersRunsOnceSyncRunner(t *testing.T) {
|
||||
bot := &Bot[NoData]{
|
||||
logger: sneklog.NewLogger(),
|
||||
runners: []Runner[NoData]{
|
||||
NewRunner("sync-once", func(context.Context, *Bot[NoData]) error {
|
||||
NewRunner("sync-once", func(*Bot[NoData]) error {
|
||||
calls.Add(1)
|
||||
return nil
|
||||
}).Async(false),
|
||||
@@ -41,7 +41,7 @@ func TestExecRunnersStopsBackgroundRunnerOnCancel(t *testing.T) {
|
||||
bot := &Bot[NoData]{
|
||||
logger: sneklog.NewLogger(),
|
||||
runners: []Runner[NoData]{
|
||||
NewRunner("background", func(context.Context, *Bot[NoData]) error {
|
||||
NewRunner("background", func(*Bot[NoData]) error {
|
||||
if calls.Add(1) == 1 {
|
||||
triggered <- struct{}{}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func TestExecRunnersEmitObserverEvents(t *testing.T) {
|
||||
logger: sneklog.NewLogger(),
|
||||
observer: observer,
|
||||
runners: []Runner[NoData]{
|
||||
NewRunner("sync-once", func(context.Context, *Bot[NoData]) error {
|
||||
NewRunner("sync-once", func(*Bot[NoData]) error {
|
||||
return wantErr
|
||||
}).Async(false),
|
||||
},
|
||||
@@ -102,7 +102,7 @@ func TestExecRunnersRecoversRunnerPanic(t *testing.T) {
|
||||
logger: sneklog.NewLogger(),
|
||||
observer: observer,
|
||||
runners: []Runner[NoData]{
|
||||
NewRunner("panic", func(context.Context, *Bot[NoData]) error {
|
||||
NewRunner("panic", func(*Bot[NoData]) error {
|
||||
panic("boom")
|
||||
}).Async(false),
|
||||
},
|
||||
@@ -130,7 +130,7 @@ func TestContextRunnerStopsActiveCallbackOnCancel(t *testing.T) {
|
||||
bot := &Bot[NoData]{
|
||||
logger: sneklog.NewLogger(),
|
||||
runners: []Runner[NoData]{
|
||||
NewRunner("cancelable", func(ctx context.Context, _ *Bot[NoData]) error {
|
||||
NewContextRunner("cancelable", func(ctx context.Context, _ *Bot[NoData]) error {
|
||||
close(started)
|
||||
<-ctx.Done()
|
||||
close(stopped)
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
|
||||
+6
-6
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/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 (api *API) doRequest[R, P any](ctx context.Context, r TelegramRequest[R, P]) (R, error) {
|
||||
func (r TelegramRequest[R, P]) doRequest(ctx context.Context, api *API) (R, error) {
|
||||
var zero R
|
||||
reqData, err := json.Marshal(r.params)
|
||||
if err != nil {
|
||||
@@ -336,11 +336,11 @@ func (api *API) doRequest[R, P any](ctx context.Context, r TelegramRequest[R, P]
|
||||
|
||||
// DoWithContext executes the request asynchronously via the worker pool.
|
||||
// Returns result or error via channel. Respects context cancellation.
|
||||
func (api *API) DoWithContext[R, P any](ctx context.Context, r TelegramRequest[R, P]) (R, error) {
|
||||
func (r TelegramRequest[R, P]) DoWithContext(ctx context.Context, api *API) (R, error) {
|
||||
var zero R
|
||||
|
||||
resultChan, err := api.pool.submit(ctx, func(ctx context.Context) (any, error) {
|
||||
return api.doRequest(ctx, r)
|
||||
return r.doRequest(ctx, api)
|
||||
})
|
||||
if err != nil {
|
||||
return zero, err
|
||||
@@ -362,8 +362,8 @@ func (api *API) DoWithContext[R, P any](ctx context.Context, r TelegramRequest[R
|
||||
|
||||
// Do executes the request synchronously with a background context.
|
||||
// Use only for simple, non-critical calls.
|
||||
func (api *API) Do[R, P any](r TelegramRequest[R, P]) (R, error) {
|
||||
return api.DoWithContext(context.Background(), r)
|
||||
func (r TelegramRequest[R, P]) Do(api *API) (R, error) {
|
||||
return r.DoWithContext(context.Background(), api)
|
||||
}
|
||||
|
||||
func readBody(body io.ReadCloser) ([]byte, error) {
|
||||
|
||||
+13
-162
@@ -38,15 +38,13 @@ 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*"}`, `"can_stop":true`, `"keep_on_stop":true`} {
|
||||
for _, want := range []string{`"chat_id":1`, `"draft_id":7`, `"rich_message":{"markdown":"*hi*"}`} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("missing %s in sendRichMessageDraft JSON: %s", want, got)
|
||||
}
|
||||
@@ -133,18 +131,18 @@ func TestEphemeralSendParametersMarshal(t *testing.T) {
|
||||
name string
|
||||
params any
|
||||
}{
|
||||
{"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"}}},
|
||||
{"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"}},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
@@ -153,19 +151,6 @@ 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)
|
||||
}
|
||||
@@ -173,140 +158,6 @@ 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)
|
||||
|
||||
@@ -18,8 +18,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -70,7 +72,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendPhotoWithContext is the context-aware variant of SendPhoto.
|
||||
@@ -79,7 +81,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendAudio holds parameters for the sendAudio method.
|
||||
@@ -98,8 +100,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -156,7 +160,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendAudioWithContext is the context-aware variant of SendAudio.
|
||||
@@ -165,7 +169,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendDocument holds parameters for the sendDocument method.
|
||||
@@ -184,8 +188,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -240,7 +246,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendDocumentWithContext is the context-aware variant of SendDocument.
|
||||
@@ -249,7 +255,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVideo holds parameters for the sendVideo method.
|
||||
@@ -268,8 +274,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -341,7 +349,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVideoWithContext is the context-aware variant of SendVideo.
|
||||
@@ -350,7 +358,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendAnimation holds parameters for the sendAnimation method.
|
||||
@@ -369,8 +377,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -432,7 +442,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendAnimationWithContext is the context-aware variant of SendAnimation.
|
||||
@@ -441,7 +451,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVoice holds parameters for the sendVoice method.
|
||||
@@ -460,8 +470,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -506,7 +518,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVoiceWithContext is the context-aware variant of SendVoice.
|
||||
@@ -515,7 +527,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVideoNote holds parameters for the sendVideoNote method.
|
||||
@@ -534,8 +546,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -581,7 +595,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVideoNoteWithContext is the context-aware variant of SendVideoNote.
|
||||
@@ -590,7 +604,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendPaidMedia holds parameters for the sendPaidMedia method.
|
||||
@@ -654,7 +668,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendPaidMediaWithContext is the context-aware variant of SendPaidMedia.
|
||||
@@ -663,7 +677,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendMediaGroup holds parameters for the sendMediaGroup method.
|
||||
@@ -705,7 +719,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendMediaGroupWithContext is the context-aware variant of SendMediaGroup.
|
||||
@@ -714,7 +728,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendLivePhoto holds parameters for the sendLivePhoto method.
|
||||
@@ -734,8 +748,10 @@ type SendLivePhoto struct {
|
||||
// sent; required if the message is sent to a direct messages chat
|
||||
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
|
||||
// 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
|
||||
// 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 ».
|
||||
@@ -786,7 +802,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendLivePhotoWithContext is the context-aware variant of SendLivePhoto.
|
||||
@@ -795,5 +811,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -355,22 +355,44 @@ const (
|
||||
|
||||
// PollAnswer represents an answer submitted by a poll voter.
|
||||
//
|
||||
// Exactly one of User and VoterChat is present.
|
||||
// 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.
|
||||
// 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
|
||||
@@ -527,11 +549,13 @@ type InputChecklist struct {
|
||||
TitleEntities []MessageEntity `json:"title_entities,omitempty"`
|
||||
// Tasks List of 1-30 tasks in the checklist
|
||||
Tasks []InputChecklistTask `json:"tasks"`
|
||||
// OthersCanAddTasks Optional. Pass True if other users can add tasks to the checklist
|
||||
OthersCanAddTasks bool `json:"others_can_add_tasks,omitempty"`
|
||||
// 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"`
|
||||
// OtherCanMarkTasksAsDone Optional. Pass True if other users can mark tasks as done or not done in the
|
||||
// checklist
|
||||
OthersCanMarkTasksAsDone bool `json:"others_can_mark_tasks_as_done,omitempty"`
|
||||
// Subject to change in v2: the Go field name may be corrected to OthersCanMarkTasksAsDone.
|
||||
OtherCanMarkTasksAsDone bool `json:"others_can_mark_tasks_as_done,omitempty"`
|
||||
}
|
||||
|
||||
// ChecklistTaskDone describes a service message about checklist tasks being marked as done.
|
||||
|
||||
@@ -3,18 +3,18 @@ package tgapi
|
||||
import "testing"
|
||||
|
||||
func TestPollAnswerVoterHelpers(t *testing.T) {
|
||||
userAnswer := PollAnswer{User: &User{ID: 42}}
|
||||
user := userAnswer.User
|
||||
if user.ID != 42 {
|
||||
t.Fatalf("unexpected voter user: %#v", user)
|
||||
userAnswer := PollAnswer{User: User{ID: 42}}
|
||||
user, ok := userAnswer.VoterUser()
|
||||
if !ok || user.ID != 42 {
|
||||
t.Fatalf("unexpected voter user: %#v, %v", user, ok)
|
||||
}
|
||||
if chat := userAnswer.VoterChat; chat != nil {
|
||||
t.Fatalf("unexpected voter chat: %#v", chat)
|
||||
if chat, ok := userAnswer.VoterChatInfo(); ok || chat != nil {
|
||||
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)
|
||||
chatAnswer := PollAnswer{VoterChat: Chat{ID: -100}}
|
||||
chat, ok := chatAnswer.VoterChatInfo()
|
||||
if !ok || chat.ID != -100 {
|
||||
t.Fatalf("unexpected voter chat: %#v, %v", chat, ok)
|
||||
}
|
||||
}
|
||||
|
||||
+40
-40
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
+46
-46
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
+69
-71
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// PromoteChatMember holds parameters for the promoteChatMember method.
|
||||
@@ -167,8 +167,6 @@ 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.
|
||||
@@ -177,7 +175,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// PromoteChatMemberWithContext is the context-aware variant of PromoteChatMember.
|
||||
@@ -186,7 +184,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatAdministratorCustomTitle holds parameters for the setChatAdministratorCustomTitle method.
|
||||
@@ -208,7 +206,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatAdministratorCustomTitleWithContext is the context-aware variant of SetChatAdministratorCustomTitle.
|
||||
@@ -217,7 +215,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatMemberTag holds parameters for the setChatMemberTag method.
|
||||
@@ -239,7 +237,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatMemberTagWithContext is the context-aware variant of SetChatMemberTag.
|
||||
@@ -248,7 +246,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// BanChatSenderChat holds parameters for the banChatSenderChat method.
|
||||
@@ -268,7 +266,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// BanChatSenderChatWithContext is the context-aware variant of BanChatSenderChat.
|
||||
@@ -277,7 +275,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// UnbanChatSenderChat holds parameters for the unbanChatSenderChat method.
|
||||
@@ -297,7 +295,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// UnbanChatSenderChatWithContext is the context-aware variant of UnbanChatSenderChat.
|
||||
@@ -306,7 +304,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatPermissions holds parameters for the setChatPermissions method.
|
||||
@@ -332,7 +330,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatPermissionsWithContext is the context-aware variant of SetChatPermissions.
|
||||
@@ -341,7 +339,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ExportChatInviteLink holds parameters for the exportChatInviteLink method.
|
||||
@@ -359,7 +357,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// ExportChatInviteLinkWithContext is the context-aware variant of ExportChatInviteLink.
|
||||
@@ -368,7 +366,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// CreateChatInviteLink holds parameters for the createChatInviteLink method.
|
||||
@@ -396,7 +394,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// CreateChatInviteLinkWithContext is the context-aware variant of CreateChatInviteLink.
|
||||
@@ -405,7 +403,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditChatInviteLink holds parameters for the editChatInviteLink method.
|
||||
@@ -436,7 +434,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditChatInviteLinkWithContext is the context-aware variant of EditChatInviteLink.
|
||||
@@ -445,7 +443,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// CreateChatSubscriptionInviteLink holds parameters for the createChatSubscriptionInviteLink method.
|
||||
@@ -471,7 +469,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// CreateChatSubscriptionInviteLinkWithContext is the context-aware variant of CreateChatSubscriptionInviteLink.
|
||||
@@ -480,7 +478,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditChatSubscriptionInviteLink holds parameters for the editChatSubscriptionInviteLink method.
|
||||
@@ -502,7 +500,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditChatSubscriptionInviteLinkWithContext is the context-aware variant of EditChatSubscriptionInviteLink.
|
||||
@@ -511,7 +509,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// RevokeChatInviteLink holds parameters for the revokeChatInviteLink method.
|
||||
@@ -531,7 +529,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// RevokeChatInviteLinkWithContext is the context-aware variant of RevokeChatInviteLink.
|
||||
@@ -540,7 +538,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ApproveChatJoinRequest holds parameters for the approveChatJoinRequest method.
|
||||
@@ -560,7 +558,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// ApproveChatJoinRequestWithContext is the context-aware variant of ApproveChatJoinRequest.
|
||||
@@ -569,7 +567,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeclineChatJoinRequest holds parameters for the declineChatJoinRequest method.
|
||||
@@ -589,7 +587,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeclineChatJoinRequestWithContext is the context-aware variant of DeclineChatJoinRequest.
|
||||
@@ -598,7 +596,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ChatJoinRequestQueryResult is the verdict passed to answerChatJoinRequestQuery.
|
||||
@@ -630,7 +628,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// AnswerChatJoinRequestQueryWithContext is the context-aware variant of AnswerChatJoinRequestQuery.
|
||||
@@ -639,7 +637,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendChatJoinRequestWebApp holds parameters for the sendChatJoinRequestWebApp method.
|
||||
@@ -660,7 +658,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendChatJoinRequestWebAppWithContext is the context-aware variant of SendChatJoinRequestWebApp.
|
||||
@@ -669,7 +667,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatPhoto holds parameters for the setChatPhoto method.
|
||||
@@ -701,7 +699,7 @@ func (api *API) SetChatPhotoWithContext(ctx context.Context, params SetChatPhoto
|
||||
_ = uploader.Close()
|
||||
}()
|
||||
req := NewUploaderRequestWithChatID[bool]("setChatPhoto", params, params.ChatID, photo.SetType(UploaderPhotoType))
|
||||
return uploader.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, uploader)
|
||||
}
|
||||
|
||||
// DeleteChatPhoto holds parameters for the deleteChatPhoto method.
|
||||
@@ -719,7 +717,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteChatPhotoWithContext is the context-aware variant of DeleteChatPhoto.
|
||||
@@ -728,7 +726,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatTitle holds parameters for the setChatTitle method.
|
||||
@@ -748,7 +746,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatTitleWithContext is the context-aware variant of SetChatTitle.
|
||||
@@ -757,7 +755,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatDescription holds parameters for the setChatDescription method.
|
||||
@@ -777,7 +775,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatDescriptionWithContext is the context-aware variant of SetChatDescription.
|
||||
@@ -786,7 +784,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// PinChatMessage holds parameters for the pinChatMessage method.
|
||||
@@ -812,7 +810,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// PinChatMessageWithContext is the context-aware variant of PinChatMessage.
|
||||
@@ -821,7 +819,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// UnpinChatMessage holds parameters for the unpinChatMessage method.
|
||||
@@ -845,7 +843,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// UnpinChatMessageWithContext is the context-aware variant of UnpinChatMessage.
|
||||
@@ -854,7 +852,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// UnpinAllChatMessages holds parameters for the unpinAllChatMessages method.
|
||||
@@ -872,7 +870,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// UnpinAllChatMessagesWithContext is the context-aware variant of UnpinAllChatMessages.
|
||||
@@ -881,7 +879,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// LeaveChat holds parameters for the leaveChat method.
|
||||
@@ -900,7 +898,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// LeaveChatWithContext is the context-aware variant of LeaveChat.
|
||||
@@ -909,7 +907,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetChat holds parameters for the getChat method.
|
||||
@@ -926,7 +924,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetChatWithContext is the context-aware variant of GetChat.
|
||||
@@ -935,7 +933,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetChatAdministrators holds parameters for the getChatAdministrators method.
|
||||
@@ -955,7 +953,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetChatAdministratorsWithContext is the context-aware variant of GetChatAdministrators.
|
||||
@@ -964,7 +962,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetChatMemberCount holds parameters for the getChatMemberCount method.
|
||||
@@ -981,7 +979,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetChatMemberCountWithContext is the context-aware variant of GetChatMemberCount.
|
||||
@@ -990,7 +988,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetChatMember holds parameters for the getChatMember method.
|
||||
@@ -1009,7 +1007,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetChatMemberWithContext is the context-aware variant of GetChatMember.
|
||||
@@ -1018,7 +1016,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatStickerSet holds parameters for the setChatStickerSet method.
|
||||
@@ -1038,7 +1036,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatStickerSetWithContext is the context-aware variant of SetChatStickerSet.
|
||||
@@ -1047,7 +1045,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteChatStickerSet holds parameters for the deleteChatStickerSet method.
|
||||
@@ -1065,7 +1063,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteChatStickerSetWithContext is the context-aware variant of DeleteChatStickerSet.
|
||||
@@ -1074,7 +1072,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetUserChatBoosts holds parameters for the getUserChatBoosts method.
|
||||
@@ -1092,7 +1090,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetUserChatBoostsWithContext is the context-aware variant of GetUserChatBoosts.
|
||||
@@ -1101,7 +1099,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetChatGifts holds parameters for the getChatGifts method.
|
||||
@@ -1145,7 +1143,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetChatGiftsWithContext is the context-aware variant of GetChatGifts.
|
||||
@@ -1154,5 +1152,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
+2
-13
@@ -90,7 +90,8 @@ type ChatFullInfo struct {
|
||||
|
||||
// AvailableReaction Optional. List of available reactions allowed in the chat. If omitted, then all emoji
|
||||
// reactions are allowed.
|
||||
AvailableReactions []ReactionType `json:"available_reactions,omitempty"`
|
||||
// Subject to change in v2: the Go field name may be pluralized to AvailableReactions.
|
||||
AvailableReaction []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
|
||||
@@ -357,8 +358,6 @@ 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
|
||||
@@ -535,8 +534,6 @@ 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.
|
||||
@@ -581,14 +578,6 @@ 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
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("setGameScore", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("setGameScore", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
+116
-112
@@ -18,8 +18,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Text Required. Text of the message to be sent, 1-4096 characters after entities parsing
|
||||
Text string `json:"text"`
|
||||
@@ -60,7 +62,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendMessageWithContext is the context-aware variant of SendMessage.
|
||||
@@ -69,7 +71,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ForwardMessage holds parameters for the forwardMessage method.
|
||||
@@ -112,7 +114,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// ForwardMessageWithContext is the context-aware variant of ForwardMessage.
|
||||
@@ -121,7 +123,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ForwardMessages holds parameters for the forwardMessages method.
|
||||
@@ -157,7 +159,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// ForwardMessagesWithContext is the context-aware variant of ForwardMessages.
|
||||
@@ -166,7 +168,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// CopyMessage holds parameters for the copyMessage method.
|
||||
@@ -232,7 +234,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 := api.Do(NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID))
|
||||
msgID, err := NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID).Do(api)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -244,7 +246,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 := api.DoWithContext(ctx, NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID))
|
||||
msgID, err := NewRequestWithChatID[MessageID]("copyMessage", params, params.ChatID).DoWithContext(ctx, api)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -286,7 +288,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// CopyMessagesWithContext is the context-aware variant of CopyMessages.
|
||||
@@ -295,7 +297,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendLocation holds parameters for the sendLocation method.
|
||||
@@ -314,8 +316,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Latitude Required. Latitude of the location
|
||||
Latitude float64 `json:"latitude"`
|
||||
@@ -363,7 +367,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendLocationWithContext is the context-aware variant of SendLocation.
|
||||
@@ -372,7 +376,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVenue holds parameters for the sendVenue method.
|
||||
@@ -391,8 +395,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Latitude Required. Latitude of the venue
|
||||
Latitude float64 `json:"latitude"`
|
||||
@@ -441,7 +447,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVenueWithContext is the context-aware variant of SendVenue.
|
||||
@@ -450,7 +456,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendContact holds parameters for the sendContact method.
|
||||
@@ -469,8 +475,10 @@ 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"`
|
||||
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// PhoneNumber Required. Contact's phone number
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
@@ -510,7 +518,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendContactWithContext is the context-aware variant of SendContact.
|
||||
@@ -519,7 +527,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendPoll holds parameters for the sendPoll method.
|
||||
@@ -630,7 +638,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendPollWithContext is the context-aware variant of SendPoll.
|
||||
@@ -639,7 +647,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendChecklist holds parameters for the sendChecklist method.
|
||||
@@ -674,7 +682,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendChecklistWithContext is the context-aware variant of SendChecklist.
|
||||
@@ -683,7 +691,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendDice holds parameters for the sendDice method.
|
||||
@@ -737,7 +745,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendDiceWithContext is the context-aware variant of SendDice.
|
||||
@@ -746,7 +754,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendMessageDraft holds parameters for the sendMessageDraft method.
|
||||
@@ -769,11 +777,6 @@ 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.
|
||||
@@ -782,7 +785,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendMessageDraftWithContext is the context-aware variant of SendMessageDraft.
|
||||
@@ -791,7 +794,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendChatAction holds parameters for the sendChatAction method.
|
||||
@@ -820,7 +823,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendChatActionWithContext is the context-aware variant of SendChatAction.
|
||||
@@ -829,7 +832,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetMessageReaction holds parameters for the setMessageReaction method.
|
||||
@@ -857,7 +860,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMessageReactionWithContext is the context-aware variant of SetMessageReaction.
|
||||
@@ -866,7 +869,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditMessageText holds parameters for the editMessageText method.
|
||||
@@ -910,11 +913,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 := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageText", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -926,11 +929,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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageText", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -973,11 +976,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 := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageCaption", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -989,11 +992,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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageCaption", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1027,11 +1030,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 := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageMedia", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1043,11 +1046,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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageMedia", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1097,11 +1100,11 @@ func (api *API) EditMessageLiveLocation(params EditMessageLiveLocation) (Message
|
||||
var zero Message
|
||||
if params.InlineMessageID != "" {
|
||||
req := NewRequestWithChatID[bool]("editMessageLiveLocation", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageLiveLocation", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1113,11 +1116,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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageLiveLocation", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1150,11 +1153,11 @@ func (api *API) StopMessageLiveLocation(params StopMessageLiveLocation) (Message
|
||||
var zero Message
|
||||
if params.InlineMessageID != "" {
|
||||
req := NewRequestWithChatID[bool]("stopMessageLiveLocation", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("stopMessageLiveLocation", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1166,11 +1169,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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("stopMessageLiveLocation", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1197,7 +1200,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditMessageChecklistWithContext is the context-aware variant of EditMessageChecklist.
|
||||
@@ -1206,7 +1209,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditMessageReplyMarkup holds parameters for the editMessageReplyMarkup method.
|
||||
@@ -1237,11 +1240,11 @@ func (api *API) EditMessageReplyMarkup(params EditMessageReplyMarkup) (Message,
|
||||
var zero Message
|
||||
if params.InlineMessageID != "" {
|
||||
req := NewRequestWithChatID[bool]("editMessageReplyMarkup", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageReplyMarkup", params, params.ChatID)
|
||||
res, err := api.Do(req)
|
||||
res, err := req.Do(api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1253,11 +1256,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 := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return zero, res, err
|
||||
}
|
||||
req := NewRequestWithChatID[Message]("editMessageReplyMarkup", params, params.ChatID)
|
||||
res, err := api.DoWithContext(ctx, req)
|
||||
res, err := req.DoWithContext(ctx, api)
|
||||
return res, false, err
|
||||
}
|
||||
|
||||
@@ -1283,7 +1286,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// StopPollWithContext is the context-aware variant of StopPoll.
|
||||
@@ -1292,7 +1295,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ApproveSuggestedPost holds parameters for the approveSuggestedPost method.
|
||||
@@ -1315,7 +1318,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// ApproveSuggestedPostWithContext is the context-aware variant of ApproveSuggestedPost.
|
||||
@@ -1324,7 +1327,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeclineSuggestedPost holds parameters for the declineSuggestedPost method.
|
||||
@@ -1345,7 +1348,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeclineSuggestedPostWithContext is the context-aware variant of DeclineSuggestedPost.
|
||||
@@ -1354,7 +1357,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteMessage holds parameters for the deleteMessage method.
|
||||
@@ -1374,7 +1377,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteMessageWithContext is the context-aware variant of DeleteMessage.
|
||||
@@ -1383,7 +1386,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteMessages holds parameters for the deleteMessages method.
|
||||
@@ -1404,7 +1407,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteMessagesWithContext is the context-aware variant of DeleteMessages.
|
||||
@@ -1413,7 +1416,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// AnswerCallbackQuery holds parameters for the answerCallbackQuery method.
|
||||
@@ -1444,7 +1447,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// AnswerCallbackQueryWithContext is the context-aware variant of AnswerCallbackQuery.
|
||||
@@ -1453,7 +1456,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// AnswerGuestQuery holds parameters for the answerGuestQuery method.
|
||||
@@ -1471,7 +1474,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// AnswerGuestQueryWithContext is the context-aware variant of AnswerGuestQuery.
|
||||
@@ -1480,7 +1483,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteAllMessageReactions holds parameters for the deleteAllMessageReactions method.
|
||||
@@ -1504,7 +1507,18 @@ 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 api.Do(req)
|
||||
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)
|
||||
}
|
||||
|
||||
// DeleteAllMessageReactionsWithContext is the context-aware variant of DeleteAllMessageReactions.
|
||||
@@ -1513,7 +1527,7 @@ func (api *API) DeleteAllMessageReactions(params DeleteAllMessageReactions) (boo
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteMessageReaction holds parameters for the deleteMessageReaction method.
|
||||
@@ -1539,7 +1553,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteMessageReactionWithContext is the context-aware variant of DeleteMessageReaction.
|
||||
@@ -1548,7 +1562,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendRichMessage holds parameters for the sendRichMessage method.
|
||||
@@ -1564,8 +1578,6 @@ 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.
|
||||
@@ -1589,7 +1601,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendRichMessageWithContext is the context-aware variant of SendRichMessage.
|
||||
@@ -1598,7 +1610,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendRichMessageDraft holds parameters for the sendRichMessageDraft method.
|
||||
@@ -1614,11 +1626,6 @@ 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
|
||||
@@ -1629,7 +1636,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendRichMessageDraftWithContext is the context-aware variant of SendRichMessageDraft.
|
||||
@@ -1638,7 +1645,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageText holds parameters for editing an ephemeral text message.
|
||||
@@ -1652,13 +1659,12 @@ 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,omitempty"`
|
||||
Text string `json:"text"`
|
||||
|
||||
// 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"`
|
||||
RichMessage *InputRichMessage `json:"rich_message,omitempty"` // Since: Bot API 10.3
|
||||
Entities []MessageEntity `json:"entities,omitempty"`
|
||||
// LinkPreviewOptions controls link preview generation for Text.
|
||||
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
|
||||
// ReplyMarkup defines the message's inline keyboard.
|
||||
@@ -1670,7 +1676,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageTextWithContext is the context-aware variant of EditEphemeralMessageText.
|
||||
@@ -1678,11 +1684,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageMedia holds parameters for editing ephemeral message media.
|
||||
// Use Uploader.EditEphemeralMessageMedia to upload files referenced through attach:// names.
|
||||
// New files cannot be uploaded; use a file ID or URL.
|
||||
//
|
||||
// Since: Bot API 10.2
|
||||
type EditEphemeralMessageMedia struct {
|
||||
@@ -1703,7 +1709,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageMediaWithContext is the context-aware variant of EditEphemeralMessageMedia.
|
||||
@@ -1711,7 +1717,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageCaption holds parameters for editing an ephemeral message caption.
|
||||
@@ -1727,8 +1733,6 @@ 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.
|
||||
@@ -1742,7 +1746,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageCaptionWithContext is the context-aware variant of EditEphemeralMessageCaption.
|
||||
@@ -1750,7 +1754,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageReplyMarkup holds parameters for editing an ephemeral message's inline keyboard.
|
||||
@@ -1772,7 +1776,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// EditEphemeralMessageReplyMarkupWithContext is the context-aware variant of EditEphemeralMessageReplyMarkup.
|
||||
@@ -1780,7 +1784,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteEphemeralMessage holds parameters for deleting an ephemeral message.
|
||||
@@ -1800,7 +1804,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteEphemeralMessageWithContext is the context-aware variant of DeleteEphemeralMessage.
|
||||
@@ -1808,5 +1812,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
+2
-64
@@ -423,8 +423,6 @@ 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
|
||||
@@ -685,7 +683,8 @@ type ReplyParameters struct {
|
||||
Quote string `json:"quote,omitempty"`
|
||||
// QuoteParsingMode Optional. Mode for parsing entities in the quote. See formatting options for more
|
||||
// details.
|
||||
QuoteParseMode string `json:"quote_parse_mode,omitempty"`
|
||||
// Subject to change in v2: the Go field name may be corrected to QuoteParseMode.
|
||||
QuoteParsingMode 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"`
|
||||
@@ -759,8 +758,6 @@ 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.
|
||||
@@ -919,8 +916,6 @@ 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.
|
||||
@@ -950,8 +945,6 @@ 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.
|
||||
@@ -977,49 +970,6 @@ 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
|
||||
|
||||
@@ -1338,15 +1288,3 @@ 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"`
|
||||
}
|
||||
|
||||
+50
-21
@@ -7,7 +7,7 @@ import (
|
||||
"math"
|
||||
"net/http"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetFileWithContext is the context-aware variant of GetFile.
|
||||
@@ -244,7 +244,25 @@ 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 api.DoWithContext(ctx, req)
|
||||
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)
|
||||
}
|
||||
|
||||
// GetFileByLinkLimit downloads at most maxBytes from Telegram's file server.
|
||||
@@ -292,6 +310,17 @@ 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 {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetFileByLinkLimitUsesConfiguredAPIURL(t *testing.T) {
|
||||
func TestGetFileByLinkUsesConfiguredAPIURL(t *testing.T) {
|
||||
var gotPath string
|
||||
|
||||
client := &http.Client{
|
||||
@@ -33,9 +33,9 @@ func TestGetFileByLinkLimitUsesConfiguredAPIURL(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
data, err := api.GetFileByLinkLimit("files/report.txt", 1024)
|
||||
data, err := api.GetFileByLink("files/report.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("GetFileByLinkLimit returned error: %v", err)
|
||||
t.Fatalf("GetFileByLink 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 TestGetFileByLinkLimitReturnsHTTPStatusError(t *testing.T) {
|
||||
func TestGetFileByLinkReturnsHTTPStatusError(t *testing.T) {
|
||||
client := &http.Client{
|
||||
Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
@@ -104,7 +104,7 @@ func TestGetFileByLinkLimitReturnsHTTPStatusError(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
_, err := api.GetFileByLinkLimit("files/report.txt", 1024)
|
||||
_, err := api.GetFileByLink("files/report.txt")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for non-2xx response")
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
+3
-103
@@ -2,20 +2,6 @@ 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
|
||||
@@ -23,22 +9,6 @@ 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
|
||||
@@ -415,8 +385,6 @@ 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
|
||||
}
|
||||
@@ -432,9 +400,8 @@ 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.IsCompact, b.Caption})
|
||||
}{"table", b.Cells, b.IsBordered, b.IsStriped, b.Caption})
|
||||
}
|
||||
|
||||
// RichBlockMap is a location map block.
|
||||
@@ -453,6 +420,8 @@ type RichBlockMap struct {
|
||||
Caption *RichBlockCaption
|
||||
}
|
||||
|
||||
func (RichBlockMap) isRichBlock() {}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
//
|
||||
// Since: Bot API 10.1
|
||||
@@ -466,29 +435,6 @@ 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.
|
||||
//
|
||||
@@ -669,49 +615,3 @@ 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)})
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ 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.
|
||||
@@ -301,8 +297,6 @@ 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"`
|
||||
}
|
||||
@@ -345,20 +339,6 @@ 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.
|
||||
//
|
||||
@@ -445,41 +425,3 @@ 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() {}
|
||||
|
||||
@@ -24,22 +24,6 @@ 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
|
||||
@@ -252,83 +236,6 @@ 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
|
||||
@@ -509,8 +416,3 @@ 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"
|
||||
|
||||
+29
-62
@@ -13,20 +13,11 @@ 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 are preserved as RichTextUnknown without
|
||||
// discarding fields.
|
||||
// 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.
|
||||
//
|
||||
// Since: Bot API 10.1
|
||||
func UnmarshalRichText(data []byte) (RichText, error) {
|
||||
@@ -66,12 +57,6 @@ 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
|
||||
@@ -219,23 +204,21 @@ 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:
|
||||
return nil, fmt.Errorf("richtext: unsupported type %q", head.Type)
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalRichBlock parses a single RichBlock from JSON, dispatching on the
|
||||
// type tag. Unknown object types are preserved as RichBlockUnknown without
|
||||
// discarding fields.
|
||||
// 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.
|
||||
//
|
||||
// Since: Bot API 10.1
|
||||
func UnmarshalRichBlock(data []byte) (RichBlock, error) {
|
||||
@@ -253,9 +236,6 @@ 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)
|
||||
@@ -310,7 +290,7 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
|
||||
}
|
||||
return RichBlockQuotation{blocks, credit}, nil
|
||||
|
||||
case "expandable_blockquote", "pullquote":
|
||||
case "pullquote":
|
||||
var raw struct {
|
||||
Credit json.RawMessage `json:"credit"`
|
||||
}
|
||||
@@ -325,9 +305,6 @@ 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":
|
||||
@@ -391,7 +368,6 @@ 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 {
|
||||
@@ -401,7 +377,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, raw.IsCompact, caption}, nil
|
||||
return RichBlockTable{raw.Cells, raw.IsBordered, raw.IsStriped, caption}, nil
|
||||
|
||||
case "map":
|
||||
var v struct {
|
||||
@@ -416,18 +392,6 @@ 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"`
|
||||
@@ -503,15 +467,26 @@ func unmarshalRichBlock(data []byte) (RichBlock, error) {
|
||||
return RichBlockAnchor{v.Name}, nil
|
||||
|
||||
default:
|
||||
return RichBlockUnknown{Raw: cloneRawJSON(data)}, nil
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalRichMessage parses a RichMessage and requires a non-null blocks array.
|
||||
// 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.
|
||||
//
|
||||
// Since: Bot API 10.1
|
||||
func UnmarshalRichMessage(data []byte) (RichMessage, error) {
|
||||
return unmarshalRichMessageStrict(data)
|
||||
if err := validateRichJSON(data); err != nil {
|
||||
return RichMessage{}, err
|
||||
}
|
||||
return unmarshalRichMessage(data)
|
||||
}
|
||||
|
||||
func unmarshalRichMessage(data []byte) (RichMessage, error) {
|
||||
@@ -533,10 +508,6 @@ 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
|
||||
}
|
||||
@@ -579,10 +550,6 @@ 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
|
||||
|
||||
+15
-93
@@ -3,7 +3,6 @@ package tgapi
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -234,98 +233,23 @@ func TestRichBlockDividerHasNoContent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
},
|
||||
},
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
w, ok := b.(RichBlockWrap)
|
||||
if !ok || w.Tag != "future_tag" {
|
||||
t.Fatalf("expected RichBlockWrap{future_tag}, got %T", b)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,10 +271,8 @@ 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) {
|
||||
for _, parse := range []func([]byte) (RichMessage, error){UnmarshalRichMessage, UnmarshalRichMessageStrict} {
|
||||
if _, err := parse([]byte(raw)); err == nil {
|
||||
t.Fatal("expected strict decoder error")
|
||||
}
|
||||
if _, err := UnmarshalRichMessageStrict([]byte(raw)); err == nil {
|
||||
t.Fatal("expected strict decoder error")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
+36
-34
@@ -18,8 +18,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// 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
|
||||
@@ -57,7 +59,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendStickerWithContext is the context-aware variant of SendSticker.
|
||||
@@ -66,7 +68,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetStickerSet holds parameters for the getStickerSet method.
|
||||
@@ -82,7 +84,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetStickerSetWithContext is the context-aware variant of GetStickerSet.
|
||||
@@ -91,7 +93,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetCustomEmojiStickers holds parameters for the getCustomEmojiStickers method.
|
||||
@@ -108,7 +110,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetCustomEmojiStickersWithContext is the context-aware variant of GetCustomEmojiStickers.
|
||||
@@ -117,7 +119,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// UploadStickerFile holds parameters for the uploadStickerFile method.
|
||||
@@ -140,7 +142,7 @@ func (api *API) UploadStickerFile(params UploadStickerFile, sticker UploaderFile
|
||||
_ = uploader.Close()
|
||||
}()
|
||||
req := NewUploaderRequest[File]("uploadStickerFile", params, sticker.SetType(UploaderStickerType))
|
||||
return uploader.Do(req)
|
||||
return req.Do(uploader)
|
||||
}
|
||||
|
||||
// UploadStickerFileWithContext is the context-aware variant of UploadStickerFile.
|
||||
@@ -153,7 +155,7 @@ func (api *API) UploadStickerFileWithContext(ctx context.Context, params UploadS
|
||||
_ = uploader.Close()
|
||||
}()
|
||||
req := NewUploaderRequest[File]("uploadStickerFile", params, sticker.SetType(UploaderStickerType))
|
||||
return uploader.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, uploader)
|
||||
}
|
||||
|
||||
// CreateNewStickerSet holds parameters for the createNewStickerSet method.
|
||||
@@ -186,7 +188,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// CreateNewStickerSetWithContext is the context-aware variant of CreateNewStickerSet.
|
||||
@@ -195,7 +197,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// AddStickerToSet holds parameters for the addStickerToSet method.
|
||||
@@ -217,7 +219,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// AddStickerToSetWithContext is the context-aware variant of AddStickerToSet.
|
||||
@@ -226,7 +228,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetStickerPositionInSet holds parameters for the setStickerPositionInSet method.
|
||||
@@ -245,7 +247,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetStickerPositionInSetWithContext is the context-aware variant of SetStickerPositionInSet.
|
||||
@@ -254,7 +256,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteStickerFromSet holds parameters for the deleteStickerFromSet method.
|
||||
@@ -271,7 +273,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteStickerFromSetWithContext is the context-aware variant of DeleteStickerFromSet.
|
||||
@@ -280,7 +282,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// ReplaceStickerInSet holds parameters for the replaceStickerInSet method.
|
||||
@@ -304,7 +306,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// ReplaceStickerInSetWithContext is the context-aware variant of ReplaceStickerInSet.
|
||||
@@ -313,7 +315,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetStickerEmojiList holds parameters for the setStickerEmojiList method.
|
||||
@@ -332,7 +334,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetStickerEmojiListWithContext is the context-aware variant of SetStickerEmojiList.
|
||||
@@ -341,7 +343,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetStickerKeywords holds parameters for the setStickerKeywords method.
|
||||
@@ -361,7 +363,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetStickerKeywordsWithContext is the context-aware variant of SetStickerKeywords.
|
||||
@@ -370,7 +372,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetStickerMaskPosition holds parameters for the setStickerMaskPosition method.
|
||||
@@ -390,7 +392,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetStickerMaskPositionWithContext is the context-aware variant of SetStickerMaskPosition.
|
||||
@@ -399,7 +401,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetStickerSetTitle holds parameters for the setStickerSetTitle method.
|
||||
@@ -418,7 +420,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetStickerSetTitleWithContext is the context-aware variant of SetStickerSetTitle.
|
||||
@@ -427,7 +429,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetStickerSetThumbnail holds parameters for the setStickerSetThumbnail method.
|
||||
@@ -459,7 +461,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetStickerSetThumbnailWithContext is the context-aware variant of SetStickerSetThumbnail.
|
||||
@@ -468,7 +470,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetCustomEmojiStickerSetThumbnail holds parameters for the setCustomEmojiStickerSetThumbnail method.
|
||||
@@ -488,7 +490,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetCustomEmojiStickerSetThumbnailWithContext is the context-aware variant of SetCustomEmojiStickerSetThumbnail.
|
||||
@@ -497,7 +499,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteStickerSet holds parameters for the deleteStickerSet method.
|
||||
@@ -514,7 +516,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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteStickerSetWithContext is the context-aware variant of DeleteStickerSet.
|
||||
@@ -523,5 +525,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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -68,10 +68,6 @@ 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.
|
||||
@@ -166,9 +162,6 @@ 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.
|
||||
@@ -238,8 +231,6 @@ 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
|
||||
}
|
||||
@@ -686,12 +677,6 @@ 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"`
|
||||
@@ -989,15 +974,3 @@ 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
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/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 (u *Uploader) doRequest[R, P any](ctx context.Context, r UploaderRequest[R, P]) (R, error) {
|
||||
func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R, error) {
|
||||
var zero R
|
||||
|
||||
methodPrefix := ""
|
||||
if u.api.useTestServer {
|
||||
if up.api.useTestServer {
|
||||
methodPrefix = "/test"
|
||||
}
|
||||
url := fmt.Sprintf("%s/bot%s%s/%s", u.api.apiURL, u.api.token, methodPrefix, r.method)
|
||||
url := fmt.Sprintf("%s/bot%s%s/%s", up.api.apiURL, up.api.token, methodPrefix, r.method)
|
||||
|
||||
retries := 0
|
||||
for {
|
||||
if u.api.Limiter != nil {
|
||||
if err := u.api.Limiter.Check(ctx, u.api.dropOverflowLimit, r.chatID); err != nil {
|
||||
if up.api.Limiter != nil {
|
||||
if err := up.api.Limiter.Check(ctx, up.api.dropOverflowLimit, r.chatID); err != nil {
|
||||
return zero, err
|
||||
}
|
||||
}
|
||||
@@ -152,11 +152,11 @@ func (u *Uploader) doRequest[R, P any](ctx context.Context, r UploaderRequest[R,
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("User-Agent", fmt.Sprintf("Laniakea/%s", utils.VersionString))
|
||||
|
||||
u.logger.Debugln("UPLOADER REQ", url)
|
||||
resp, err := u.api.client.Do(req)
|
||||
up.logger.Debugln("UPLOADER REQ", url)
|
||||
resp, err := up.api.client.Do(req)
|
||||
_ = requestBody.Close()
|
||||
if err != nil {
|
||||
return zero, fmt.Errorf("HTTP upload request failed: %w", redactHTTPError(err, u.api.token))
|
||||
return zero, fmt.Errorf("HTTP upload request failed: %w", redactHTTPError(err, up.api.token))
|
||||
}
|
||||
|
||||
body, err := readBody(resp.Body)
|
||||
@@ -164,7 +164,7 @@ func (u *Uploader) doRequest[R, P any](ctx context.Context, r UploaderRequest[R,
|
||||
if err != nil {
|
||||
return zero, err
|
||||
}
|
||||
u.logger.Debugln("UPLOADER RES", responseLogSummary(r.method, len(body)))
|
||||
up.logger.Debugln("UPLOADER RES", responseLogSummary(r.method, len(body)))
|
||||
|
||||
response, err := parseBody[R](body)
|
||||
if err != nil {
|
||||
@@ -179,15 +179,15 @@ func (u *Uploader) doRequest[R, P any](ctx context.Context, r UploaderRequest[R,
|
||||
}
|
||||
if response.ErrorCode == 429 && response.Parameters != nil && response.Parameters.RetryAfter != nil {
|
||||
after := *response.Parameters.RetryAfter
|
||||
u.logger.Warnf("Rate limited, retry after %d seconds (chat: %d)", after, r.chatID)
|
||||
if u.api.Limiter != nil {
|
||||
up.logger.Warnf("Rate limited, retry after %d seconds (chat: %d)", after, r.chatID)
|
||||
if up.api.Limiter != nil {
|
||||
if r.chatID != 0 {
|
||||
u.api.Limiter.SetChatLock(r.chatID, after)
|
||||
up.api.Limiter.SetChatLock(r.chatID, after)
|
||||
} else {
|
||||
u.api.Limiter.SetGlobalLock(after)
|
||||
up.api.Limiter.SetGlobalLock(after)
|
||||
}
|
||||
}
|
||||
if retries >= u.api.maxRetries {
|
||||
if retries >= up.api.maxRetries {
|
||||
return zero, fmt.Errorf("%w after %d retries: %w", ErrRetryLimit, retries, responseErr)
|
||||
}
|
||||
retries++
|
||||
@@ -207,11 +207,11 @@ func (u *Uploader) doRequest[R, P any](ctx context.Context, r UploaderRequest[R,
|
||||
|
||||
// DoWithContext executes the upload request asynchronously via the worker pool.
|
||||
// Returns the result or error. Respects context cancellation.
|
||||
func (u *Uploader) DoWithContext[R, P any](ctx context.Context, r UploaderRequest[R, P]) (R, error) {
|
||||
func (r UploaderRequest[R, P]) DoWithContext(ctx context.Context, up *Uploader) (R, error) {
|
||||
var zero R
|
||||
|
||||
result, err := u.api.pool.submit(ctx, func(ctx context.Context) (any, error) {
|
||||
return u.doRequest(ctx, r)
|
||||
result, err := up.api.pool.submit(ctx, func(ctx context.Context) (any, error) {
|
||||
return r.doRequest(ctx, up)
|
||||
})
|
||||
if err != nil {
|
||||
return zero, err
|
||||
@@ -233,8 +233,8 @@ func (u *Uploader) DoWithContext[R, P any](ctx context.Context, r UploaderReques
|
||||
|
||||
// Do executes the upload request synchronously with a background context.
|
||||
// Use only for simple, non-critical uploads.
|
||||
func (u *Uploader) Do[R, P any](r UploaderRequest[R, P]) (R, error) {
|
||||
return u.DoWithContext(context.Background(), r)
|
||||
func (r UploaderRequest[R, P]) Do(up *Uploader) (R, error) {
|
||||
return r.DoWithContext(context.Background(), up)
|
||||
}
|
||||
|
||||
func prepareMultipartStream[P any](files []UploaderFile, params P) (io.ReadCloser, string) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package tgapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -107,66 +106,6 @@ 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(
|
||||
|
||||
+54
-56
@@ -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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendRichMessageWithContext uploads files referenced by attach:// names in params.RichMessage
|
||||
@@ -17,25 +17,7 @@ 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 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)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// SendRichMessageDraft streams a rich-message draft without direct file uploads.
|
||||
@@ -75,8 +57,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Caption Optional. Photo caption (may also be used when resending photos by file_id), 0-1024 characters
|
||||
// after entities parsing
|
||||
@@ -122,7 +106,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendPhotoWithContext is the context-aware variant of SendPhoto.
|
||||
@@ -131,7 +115,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadAudio holds parameters for uploading an audio file using the Uploader.
|
||||
@@ -150,8 +134,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Caption Optional. Audio caption, 0-1024 characters after entities parsing
|
||||
Caption string `json:"caption,omitempty"`
|
||||
@@ -199,7 +185,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendAudioWithContext is the context-aware variant of SendAudio.
|
||||
@@ -208,7 +194,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadDocument holds parameters for uploading a document using the Uploader.
|
||||
@@ -227,8 +213,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Caption Optional. Document caption (may also be used when resending documents by file_id), 0-1024
|
||||
// characters after entities parsing
|
||||
@@ -273,7 +261,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendDocumentWithContext is the context-aware variant of SendDocument.
|
||||
@@ -282,7 +270,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadVideo holds parameters for uploading a video using the Uploader.
|
||||
@@ -301,8 +289,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Duration Optional. Duration of sent video in seconds
|
||||
Duration int `json:"duration,omitempty"`
|
||||
@@ -359,7 +349,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendVideoWithContext is the context-aware variant of SendVideo.
|
||||
@@ -368,7 +358,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadAnimation holds parameters for uploading an animation using the Uploader.
|
||||
@@ -387,8 +377,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Duration Optional. Duration of sent animation in seconds
|
||||
Duration int `json:"duration,omitempty"`
|
||||
@@ -441,7 +433,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendAnimationWithContext is the context-aware variant of SendAnimation.
|
||||
@@ -450,7 +442,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadVoice holds parameters for uploading a voice note using the Uploader.
|
||||
@@ -469,8 +461,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Caption Optional. Voice message caption, 0-1024 characters after entities parsing
|
||||
Caption string `json:"caption,omitempty"`
|
||||
@@ -513,7 +507,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendVoiceWithContext is the context-aware variant of SendVoice.
|
||||
@@ -522,7 +516,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadVideoNote holds parameters for uploading a video note (rounded video) using the Uploader.
|
||||
@@ -541,8 +535,10 @@ 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"`
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
|
||||
// Duration Optional. Duration of sent video in seconds
|
||||
Duration int `json:"duration,omitempty"`
|
||||
@@ -579,7 +575,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendVideoNoteWithContext is the context-aware variant of SendVideoNote.
|
||||
@@ -588,7 +584,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadChatPhoto holds parameters for uploading a chat photo using the Uploader.
|
||||
@@ -606,7 +602,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SetChatPhotoWithContext is the context-aware variant of SetChatPhoto.
|
||||
@@ -615,7 +611,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadSetWebhook holds multipart parameters for the setWebhook method.
|
||||
@@ -654,7 +650,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 u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SetWebhookWithContext is the context-aware variant of SetWebhook.
|
||||
@@ -663,7 +659,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 u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
// UploadLivePhoto holds parameters for uploading a live photo using the Uploader.
|
||||
@@ -683,8 +679,10 @@ type UploadLivePhoto struct {
|
||||
// sent; required if the message is sent to a direct messages chat
|
||||
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
|
||||
|
||||
// EphemeralMessageParameters configures an ephemeral response.
|
||||
EphemeralMessageParameters *EphemeralMessageParameters `json:"ephemeral_message_parameters,omitempty"` // Since: Bot API 10.3
|
||||
// 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
|
||||
// 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"`
|
||||
@@ -733,7 +731,7 @@ func (u *Uploader) SendLivePhoto(params UploadLivePhoto, livePhoto, photo Upload
|
||||
livePhoto.SetType(UploaderLivePhotoType),
|
||||
photo.SetType(UploaderPhotoType),
|
||||
)
|
||||
return u.Do(req)
|
||||
return req.Do(u)
|
||||
}
|
||||
|
||||
// SendLivePhotoWithContext uploads a live-photo video and its static image via
|
||||
@@ -748,5 +746,5 @@ func (u *Uploader) SendLivePhotoWithContext(
|
||||
livePhoto.SetType(UploaderLivePhotoType),
|
||||
photo.SetType(UploaderPhotoType),
|
||||
)
|
||||
return u.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, u)
|
||||
}
|
||||
|
||||
+10
-10
@@ -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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// 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 api.Do(req)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// 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 api.DoWithContext(ctx, req)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
@@ -34,21 +34,21 @@ func TestTelegramWireFieldNames(t *testing.T) {
|
||||
{
|
||||
name: "input checklist permissions",
|
||||
value: InputChecklist{
|
||||
OthersCanAddTasks: true,
|
||||
OthersCanMarkTasksAsDone: true,
|
||||
OtherCanAddTasks: true,
|
||||
OtherCanMarkTasksAsDone: 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{AvailableReactions: []ReactionType{{Type: "emoji"}}},
|
||||
value: ChatFullInfo{AvailableReaction: []ReactionType{{Type: "emoji"}}},
|
||||
keys: []string{"available_reactions"},
|
||||
bad: []string{"available_reaction"},
|
||||
},
|
||||
{
|
||||
name: "reply quote parse mode",
|
||||
value: ReplyParameters{QuoteParseMode: "HTML"},
|
||||
value: ReplyParameters{QuoteParsingMode: "HTML"},
|
||||
keys: []string{"quote_parse_mode"},
|
||||
bad: []string{"quote_parsing_mode"},
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/extypes"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
// MessageBuilder builds Telegram message text with explicit message entities.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestMessageBuilder_BuildPlainText(t *testing.T) {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package tgrich
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestRenderText(t *testing.T) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestBuildHTMLBlocks(t *testing.T) {
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
package tgrich
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
)
|
||||
|
||||
func (v *richValidator) button(b tgapi.RichMessageButton, depth int) error {
|
||||
actions := 0
|
||||
for _, set := range []bool{b.URL != "", b.CallbackData != "", b.WebApp != nil, b.LoginURL != nil, b.SwitchInlineQuery != nil, b.SwitchInlineQueryCurrentChat != nil, b.SwitchInlineQueryChosenChat != nil, b.CopyText != nil, b.Disabled != nil} {
|
||||
if set {
|
||||
actions++
|
||||
}
|
||||
}
|
||||
if actions != 1 {
|
||||
return fmt.Errorf("%w: exactly one action is required", ErrRichInvalidButton)
|
||||
}
|
||||
switch b.Style {
|
||||
case "", "danger", "success", "primary":
|
||||
case "link":
|
||||
if b.CallbackData == "" {
|
||||
return fmt.Errorf("%w: link style requires callback data", ErrRichInvalidButton)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("%w: unsupported style", ErrRichInvalidButton)
|
||||
}
|
||||
if len(b.CallbackData) > 64 {
|
||||
return fmt.Errorf("%w: callback data exceeds 64 bytes", ErrRichInvalidButton)
|
||||
}
|
||||
if b.CopyText != nil && (utf8.RuneCountInString(b.CopyText.Text) < 1 || utf8.RuneCountInString(b.CopyText.Text) > 256) {
|
||||
return fmt.Errorf("%w: copy text must contain 1-256 characters", ErrRichInvalidButton)
|
||||
}
|
||||
if b.LoginURL != nil && b.LoginURL.BotUsername != "" {
|
||||
return fmt.Errorf("%w: login bot username is unsupported", ErrRichInvalidButton)
|
||||
}
|
||||
return v.buttonText(b.Text, depth)
|
||||
}
|
||||
|
||||
func (v *richValidator) buttonText(text tgapi.RichText, depth int) error {
|
||||
if depth >= maxRichDepth {
|
||||
return ErrRichNestingTooDeep
|
||||
}
|
||||
switch el := text.(type) {
|
||||
case tgapi.RichTextPlain:
|
||||
return v.addChars(string(el))
|
||||
case tgapi.RichTextCustomEmoji:
|
||||
return v.addChars(el.AlternativeText)
|
||||
case tgapi.RichTextDateTime:
|
||||
return v.buttonText(el.Text, depth+1)
|
||||
case tgapi.RichTextArray:
|
||||
for _, item := range el {
|
||||
if err := v.buttonText(item, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%w: label allows only plain text, custom emoji, and date-time entities", ErrRichInvalidButton)
|
||||
}
|
||||
}
|
||||
|
||||
func renderButton(b tgapi.RichMessageButton, step int) (string, error) {
|
||||
if step >= maxRichDepth {
|
||||
return "", ErrRichNestingTooDeep
|
||||
}
|
||||
text, err := renderText(b.Text, step+1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
attrs := map[string]string{}
|
||||
if b.Style != "" {
|
||||
attrs["style"] = string(b.Style)
|
||||
}
|
||||
// Empty query values are significant; render them explicitly below.
|
||||
var query *string
|
||||
switch {
|
||||
case b.URL != "":
|
||||
attrs["type"], attrs["url"] = "url", b.URL
|
||||
case b.CallbackData != "":
|
||||
attrs["type"], attrs["data"] = "callback_data", b.CallbackData
|
||||
case b.WebApp != nil:
|
||||
attrs["type"], attrs["url"] = "web_app", b.WebApp.URL
|
||||
case b.LoginURL != nil:
|
||||
attrs["type"], attrs["url"] = "login_url", b.LoginURL.URL
|
||||
if b.LoginURL.ForwardText != "" {
|
||||
attrs["forward-text"] = b.LoginURL.ForwardText
|
||||
}
|
||||
if b.LoginURL.RequestWriteAccess {
|
||||
attrs["request-write-access"] = ""
|
||||
}
|
||||
case b.SwitchInlineQuery != nil:
|
||||
attrs["type"], query = "switch_inline_query", b.SwitchInlineQuery
|
||||
case b.SwitchInlineQueryCurrentChat != nil:
|
||||
attrs["type"], query = "switch_inline_query_current_chat", b.SwitchInlineQueryCurrentChat
|
||||
case b.SwitchInlineQueryChosenChat != nil:
|
||||
c := b.SwitchInlineQueryChosenChat
|
||||
attrs["type"], query = "switch_inline_query_chosen_chat", &c.Query
|
||||
for key, enabled := range map[string]bool{"allow-user-chats": c.AllowUserChats, "allow-bot-chats": c.AllowBotChats, "allow-group-chats": c.AllowGroupChats, "allow-channel-chats": c.AllowChannelChats} {
|
||||
if enabled {
|
||||
attrs[key] = ""
|
||||
}
|
||||
}
|
||||
case b.CopyText != nil:
|
||||
attrs["type"], attrs["text"] = "copy_text", b.CopyText.Text
|
||||
case b.Disabled != nil:
|
||||
attrs["type"] = "disabled"
|
||||
default:
|
||||
return "", ErrRichInvalidButton
|
||||
}
|
||||
formatted := formatAttrs(attrs)
|
||||
if query != nil {
|
||||
formatted = append(formatted, `query="`+escapeHTML(*query)+`"`)
|
||||
}
|
||||
return openTag("tg-button", formatted) + text + "</tg-button>", nil
|
||||
}
|
||||
|
||||
func renderButtons(row tgapi.InputRichBlockButtons, step int) (string, error) {
|
||||
var content strings.Builder
|
||||
for _, button := range row.Buttons {
|
||||
html, err := renderButton(button, step+1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
content.WriteString(html)
|
||||
}
|
||||
attrs := map[string]string{}
|
||||
if row.Align != "" {
|
||||
attrs["align"] = string(row.Align)
|
||||
}
|
||||
return openTag("tg-button-row", formatAttrs(attrs)) + content.String() + "</tg-button-row>", nil
|
||||
}
|
||||
@@ -3,8 +3,6 @@ package tgrich
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrRichInvalidButton indicates an invalid rich-button action, label, style, or row.
|
||||
ErrRichInvalidButton = errors.New("invalid rich button")
|
||||
// ErrRichTextTooLong indicates that rich-message text exceeds 32768 UTF-8 characters.
|
||||
ErrRichTextTooLong = errors.New("rich text too long")
|
||||
// ErrRichTooManyBlocks indicates that a rich message exceeds 500 blocks and counted nested items.
|
||||
|
||||
+1
-26
@@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
type buildState struct {
|
||||
@@ -61,8 +61,6 @@ func (s *buildState) addMedia(media tgapi.InputMedia) (string, error) {
|
||||
}
|
||||
var kind string
|
||||
switch media.Type {
|
||||
case tgapi.InputMediaTypeDocument:
|
||||
kind = "document"
|
||||
case tgapi.InputMediaTypePhoto:
|
||||
kind = "photo"
|
||||
case tgapi.InputMediaTypeAnimation, tgapi.InputMediaTypeVideo:
|
||||
@@ -79,8 +77,6 @@ func (s *buildState) addMedia(media tgapi.InputMedia) (string, error) {
|
||||
|
||||
func renderText(t tgapi.RichText, step int) (string, error) {
|
||||
switch el := t.(type) {
|
||||
case tgapi.RichTextButton:
|
||||
return renderButton(el.Button, step+1)
|
||||
case tgapi.RichTextPlain:
|
||||
return escapeHTML(string(el)), nil
|
||||
case tgapi.RichTextArray:
|
||||
@@ -207,9 +203,6 @@ func renderHTMLTable(t tgapi.InputRichBlockTable, step int, state *buildState) (
|
||||
if t.IsBordered {
|
||||
attrs["bordered"] = ""
|
||||
}
|
||||
if t.IsCompact {
|
||||
attrs["compact"] = ""
|
||||
}
|
||||
if t.IsStriped {
|
||||
attrs["striped"] = ""
|
||||
}
|
||||
@@ -477,20 +470,6 @@ func renderBlockHTMLState(block tgapi.InputRichBlock, step int, state *buildStat
|
||||
credit = "<cite>" + credit + "</cite>"
|
||||
}
|
||||
return "<blockquote>" + strings.Join(content, "") + credit + "</blockquote>", nil
|
||||
case tgapi.InputRichBlockExpandableBlockQuotation:
|
||||
text, err := renderText(el.Text, step+1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
credit := ""
|
||||
if el.Credit != nil {
|
||||
credit, err = renderText(*el.Credit, step+1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
credit = "<cite>" + credit + "</cite>"
|
||||
}
|
||||
return "<blockquote expandable>" + text + credit + "</blockquote>", nil
|
||||
case tgapi.InputRichBlockPullQuotation:
|
||||
text, err := renderText(el.Text, step+1)
|
||||
if err != nil {
|
||||
@@ -553,10 +532,6 @@ func renderBlockHTMLState(block tgapi.InputRichBlock, step int, state *buildStat
|
||||
return renderHTMLMap(el, step)
|
||||
case tgapi.InputRichBlockAnimation:
|
||||
return renderHTMLMedia(el.Animation, el.Caption, "video", step, state)
|
||||
case tgapi.InputRichBlockDocument:
|
||||
return renderHTMLMedia(el.Document, el.Caption, "tg-document", step, state)
|
||||
case tgapi.InputRichBlockButtons:
|
||||
return renderButtons(el, step)
|
||||
case tgapi.InputRichBlockAudio:
|
||||
return renderHTMLMedia(el.Audio, el.Caption, "audio", step, state)
|
||||
case tgapi.InputRichBlockPhoto:
|
||||
|
||||
+1
-66
@@ -1,6 +1,6 @@
|
||||
package tgrich
|
||||
|
||||
import "git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
import "git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
|
||||
// Caption creates a media-block caption without a credit.
|
||||
//
|
||||
@@ -390,8 +390,6 @@ type RichTable struct {
|
||||
IsBordered bool
|
||||
// IsStriped reports whether the table has striped rows.
|
||||
IsStriped bool
|
||||
// IsCompact requests smaller table-cell padding.
|
||||
IsCompact bool
|
||||
// Caption is the optional table caption.
|
||||
Caption *tgapi.RichText
|
||||
}
|
||||
@@ -427,14 +425,6 @@ func (t *RichTable) SetStriped(b bool) *RichTable {
|
||||
return t
|
||||
}
|
||||
|
||||
// SetCompact requests smaller table-cell padding.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func (t *RichTable) SetCompact(b bool) *RichTable {
|
||||
t.IsCompact = b
|
||||
return t
|
||||
}
|
||||
|
||||
// SetCaption sets the table caption.
|
||||
//
|
||||
// Since: Bot API 10.2
|
||||
@@ -452,7 +442,6 @@ func (t *RichTable) Build() tgapi.InputRichBlockTable {
|
||||
Cells: t.Cells,
|
||||
IsBordered: t.IsBordered,
|
||||
IsStriped: t.IsStriped,
|
||||
IsCompact: t.IsCompact,
|
||||
Caption: t.Caption,
|
||||
}
|
||||
}
|
||||
@@ -488,20 +477,6 @@ func MapWithCaption(loc tgapi.Location, zoom uint8, width, height uint16, captio
|
||||
return tgapi.InputRichBlockMap{Type: tgapi.InputRichTypeMap, Location: loc, Zoom: zoom, Width: width, Height: height, Caption: &caption}
|
||||
}
|
||||
|
||||
// Buttons creates a row of 1-8 rich buttons.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func Buttons(buttons []tgapi.RichMessageButton) tgapi.InputRichBlockButtons {
|
||||
return tgapi.InputRichBlockButtons{Type: tgapi.InputRichTypeButtons, Buttons: buttons}
|
||||
}
|
||||
|
||||
// ButtonsWithAlign creates a button row aligned left, center, or right.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func ButtonsWithAlign(buttons []tgapi.RichMessageButton, align tgapi.RichBlockButtonAlign) tgapi.InputRichBlockButtons {
|
||||
return tgapi.InputRichBlockButtons{Type: tgapi.InputRichTypeButtons, Buttons: buttons, Align: align}
|
||||
}
|
||||
|
||||
// Animation creates an animation block without a caption.
|
||||
//
|
||||
// Since: Bot API 10.2
|
||||
@@ -593,43 +568,3 @@ func VoiceNoteWithCaption(voiceNote tgapi.InputMedia, caption tgapi.RichBlockCap
|
||||
func Thinking(text tgapi.RichText) tgapi.InputRichBlockThinking {
|
||||
return tgapi.InputRichBlockThinking{Type: tgapi.InputRichTypeThinking, Text: text}
|
||||
}
|
||||
|
||||
// Button embeds a button in rich text.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func Button(button tgapi.RichMessageButton) tgapi.RichTextButton {
|
||||
return tgapi.RichTextButton{Button: button}
|
||||
}
|
||||
|
||||
// ExpandableBlockquote creates a quotation corresponding to <blockquote expandable>.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func ExpandableBlockquote(text tgapi.RichText) tgapi.InputRichBlockExpandableBlockQuotation {
|
||||
return tgapi.InputRichBlockExpandableBlockQuotation{Type: tgapi.InputRichTypeExpandableBlockQuotation, Text: text}
|
||||
}
|
||||
|
||||
// ExpandableBlockquoteWithCredit creates an expandable quotation with its source.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func ExpandableBlockquoteWithCredit(text, credit tgapi.RichText) tgapi.InputRichBlockExpandableBlockQuotation {
|
||||
block := ExpandableBlockquote(text)
|
||||
block.Credit = &credit
|
||||
return block
|
||||
}
|
||||
|
||||
// Document creates a general-file block corresponding to <tg-document>.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func Document(document tgapi.InputMedia) tgapi.InputRichBlockDocument {
|
||||
document.Type = tgapi.InputMediaTypeDocument
|
||||
return tgapi.InputRichBlockDocument{Type: tgapi.InputRichTypeDocument, Document: document}
|
||||
}
|
||||
|
||||
// DocumentWithCaption creates a general-file block with a caption.
|
||||
//
|
||||
// Since: Bot API 10.3
|
||||
func DocumentWithCaption(document tgapi.InputMedia, caption tgapi.RichBlockCaption) tgapi.InputRichBlockDocument {
|
||||
block := Document(document)
|
||||
block.Caption = &caption
|
||||
return block
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package tgrich
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func TestMediaConstructorsSetTypes(t *testing.T) {
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
package tgrich
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
)
|
||||
|
||||
func TestRich103HTML(t *testing.T) {
|
||||
empty := ""
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
button tgapi.RichMessageButton
|
||||
fragment string
|
||||
}{
|
||||
{"url", tgapi.RichMessageButton{URL: "https://example.com/?a=1&b=2"}, `url="https://example.com/?a=1&b=2"`},
|
||||
{"callback", tgapi.RichMessageButton{CallbackData: `a"<&`, Style: tgapi.RichMessageButtonStyleLink}, `data="a"<&"`},
|
||||
{"web app", tgapi.RichMessageButton{WebApp: &tgapi.WebAppInfo{URL: "https://example.com"}}, `type="web_app"`},
|
||||
{"login", tgapi.RichMessageButton{LoginURL: &tgapi.LoginURL{URL: "https://example.com", ForwardText: "Forward", RequestWriteAccess: true}}, `request-write-access`},
|
||||
{"inline", tgapi.RichMessageButton{SwitchInlineQuery: &empty}, `query=""`},
|
||||
{"current", tgapi.RichMessageButton{SwitchInlineQueryCurrentChat: &empty}, `type="switch_inline_query_current_chat"`},
|
||||
{"chosen", tgapi.RichMessageButton{SwitchInlineQueryChosenChat: &tgapi.SwitchInlineQueryChosenChat{AllowUserChats: true}}, `allow-user-chats`},
|
||||
{"copy", tgapi.RichMessageButton{CopyText: &tgapi.CopyTextButton{Text: "copy"}}, `text="copy"`},
|
||||
{"disabled", tgapi.RichMessageButton{Disabled: &tgapi.DisabledButton{}}, `type="disabled"`},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.button.Text = Text("<Go>")
|
||||
for _, block := range []tgapi.InputRichBlock{P(Button(tc.button)), ButtonsWithAlign([]tgapi.RichMessageButton{tc.button}, tgapi.RichBlockButtonCenter)} {
|
||||
msg, err := BuildHTML(block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(msg.HTML, tc.fragment) || !strings.Contains(msg.HTML, "<Go></tg-button>") {
|
||||
t.Fatalf("unexpected HTML: %s", msg.HTML)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
msg, err := BuildHTML(ExpandableBlockquoteWithCredit(Bold(Text("Quote")), Text("Author")), DocumentWithCaption(tgapi.InputMedia{Media: "attach://notes"}, Caption(Text("Notes"))), NewTable().SetCompact(true).Build())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, fragment := range []string{"<blockquote expandable><b>Quote</b><cite>Author</cite></blockquote>", `<tg-document src="tg://document?id=media_1"></tg-document>`, "<table compact>"} {
|
||||
if !strings.Contains(msg.HTML, fragment) {
|
||||
t.Fatalf("missing %s in %s", fragment, msg.HTML)
|
||||
}
|
||||
}
|
||||
if len(msg.Media) != 1 || msg.Media[0].Media.Type != tgapi.InputMediaTypeDocument || msg.Media[0].Media.Media != "attach://notes" {
|
||||
t.Fatalf("bad media: %#v", msg.Media)
|
||||
}
|
||||
if _, err := BuildDraftHTML(Document(tgapi.InputMedia{Media: "attach://notes"})); !errors.Is(err, tgapi.ErrRichMessageDraftUploadUnsupported) {
|
||||
t.Fatalf("draft: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRich103Validation(t *testing.T) {
|
||||
good := tgapi.RichMessageButton{Text: Text("Go"), CallbackData: "x"}
|
||||
for _, n := range []int{0, 1, 8, 9} {
|
||||
buttons := make([]tgapi.RichMessageButton, n)
|
||||
for i := range buttons {
|
||||
buttons[i] = good
|
||||
}
|
||||
_, err := BuildHTML(Buttons(buttons))
|
||||
if (err == nil) != (n >= 1 && n <= 8) {
|
||||
t.Fatalf("row %d: %v", n, err)
|
||||
}
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
change func(*tgapi.RichMessageButton)
|
||||
}{
|
||||
{"no action", func(b *tgapi.RichMessageButton) { b.CallbackData = "" }},
|
||||
{"two actions", func(b *tgapi.RichMessageButton) { b.URL = "https://example.com" }},
|
||||
{"long callback", func(b *tgapi.RichMessageButton) { b.CallbackData = strings.Repeat("я", 33) }},
|
||||
{"formatting", func(b *tgapi.RichMessageButton) { b.Text = Bold(Text("Go")) }},
|
||||
{"style", func(b *tgapi.RichMessageButton) { b.Style = "disable" }},
|
||||
{"link url", func(b *tgapi.RichMessageButton) { b.CallbackData = ""; b.URL = "https://example.com"; b.Style = "link" }},
|
||||
{"login bot", func(b *tgapi.RichMessageButton) {
|
||||
b.CallbackData = ""
|
||||
b.LoginURL = &tgapi.LoginURL{URL: "https://example.com", BotUsername: "other"}
|
||||
}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
b := good
|
||||
tc.change(&b)
|
||||
if _, err := BuildHTML(P(Button(b))); !errors.Is(err, ErrRichInvalidButton) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
good.CallbackData = strings.Repeat("я", 32)
|
||||
if _, err := BuildHTML(P(Button(good))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := BuildHTML(ButtonsWithAlign([]tgapi.RichMessageButton{good}, "bottom")); !errors.Is(err, ErrRichInvalidButton) {
|
||||
t.Fatalf("alignment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRich103InputJSON(t *testing.T) {
|
||||
for _, block := range []tgapi.InputRichBlock{ExpandableBlockquote(Text("quote")), Document(tgapi.InputMedia{Media: "file"}), Buttons([]tgapi.RichMessageButton{{Text: Text("Off"), Disabled: &tgapi.DisabledButton{}}})} {
|
||||
data, err := json.Marshal(block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var fields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &fields); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(fields["type"]) == 0 {
|
||||
t.Fatalf("missing discriminator: %s", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRichButtonLabelEntitiesAndLimits(t *testing.T) {
|
||||
label := tgapi.RichTextArray{
|
||||
Text("At "),
|
||||
tgapi.RichTextDateTime{Text: Text("noon"), UnixTime: 1000, DateTimeFormat: "t"},
|
||||
tgapi.RichTextCustomEmoji{CustomEmojiID: "123", AlternativeText: "!"},
|
||||
}
|
||||
if _, err := BuildHTML(P(Button(tgapi.RichMessageButton{Text: label, Disabled: &tgapi.DisabledButton{}}))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, n := range []int{0, 1, 256, 257} {
|
||||
_, err := BuildHTML(P(Button(tgapi.RichMessageButton{Text: Text("Copy"), CopyText: &tgapi.CopyTextButton{Text: strings.Repeat("я", n)}})))
|
||||
if (err == nil) != (n >= 1 && n <= 256) {
|
||||
t.Fatalf("copy length %d: %v", n, err)
|
||||
}
|
||||
}
|
||||
for _, text := range []tgapi.RichText{
|
||||
Bold(Text(strings.Repeat("я", maxRichTextChars+1))),
|
||||
URL(Text(strings.Repeat("я", maxRichTextChars+1)), "https://example.com"),
|
||||
} {
|
||||
if _, err := BuildHTML(P(text)); !errors.Is(err, ErrRichTextTooLong) {
|
||||
t.Fatalf("nested text bypassed limit: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-51
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
type richValidator struct {
|
||||
@@ -132,8 +132,6 @@ func (v *richValidator) text(text tgapi.RichText, depth int) error {
|
||||
return v.addChars(el.AlternativeText)
|
||||
case tgapi.RichTextMathematicalExpression:
|
||||
return v.addChars(el.Expression)
|
||||
case tgapi.RichTextButton:
|
||||
return v.button(el.Button, depth+1)
|
||||
case tgapi.RichTextAnchor:
|
||||
return nil
|
||||
}
|
||||
@@ -145,46 +143,33 @@ func (v *richValidator) text(text tgapi.RichText, depth int) error {
|
||||
var child tgapi.RichText
|
||||
switch el := text.(type) {
|
||||
case tgapi.RichTextWrap:
|
||||
child = el.Text
|
||||
case tgapi.RichTextURL:
|
||||
child = el.Text
|
||||
case tgapi.RichTextEmailAddress:
|
||||
child = el.Text
|
||||
case tgapi.RichTextPhoneNumber:
|
||||
child = el.Text
|
||||
case tgapi.RichTextBankCardNumber:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, el.BankCardNumber); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextMention:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "@"+strings.TrimPrefix(el.Username, "@")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextHashtag:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "#"+strings.TrimPrefix(el.Hashtag, "#")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextCashtag:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "$"+strings.TrimPrefix(el.Cashtag, "$")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextBotCommand:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "/"+strings.TrimPrefix(el.BotCommand, "/")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextAnchorLink:
|
||||
child = el.Text
|
||||
case tgapi.RichTextReference:
|
||||
child = el.Text
|
||||
case tgapi.RichTextReferenceLink:
|
||||
child = el.Text
|
||||
case tgapi.RichTextDateTime:
|
||||
child = el.Text
|
||||
case tgapi.RichTextTextMention:
|
||||
child = el.Text
|
||||
default:
|
||||
@@ -365,40 +350,6 @@ func (v *richValidator) block(block tgapi.InputRichBlock, depth int) error {
|
||||
return err
|
||||
}
|
||||
return v.nested(el.Blocks, depth+1)
|
||||
case tgapi.InputRichBlockButtons:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypeButtons); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(el.Buttons) < 1 || len(el.Buttons) > 8 {
|
||||
return ErrRichInvalidButton
|
||||
}
|
||||
switch el.Align {
|
||||
case "", tgapi.RichBlockButtonLeft, tgapi.RichBlockButtonCenter, tgapi.RichBlockButtonRight:
|
||||
default:
|
||||
return ErrRichInvalidButton
|
||||
}
|
||||
for _, button := range el.Buttons {
|
||||
if err := v.button(button, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case tgapi.InputRichBlockExpandableBlockQuotation:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypeExpandableBlockQuotation); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.text(el.Text, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
return v.textValue(el.Credit, depth+1)
|
||||
case tgapi.InputRichBlockDocument:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypeDocument); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.addMedia(el.Document, tgapi.InputMediaTypeDocument); err != nil {
|
||||
return err
|
||||
}
|
||||
return v.caption(el.Caption, depth+1)
|
||||
case tgapi.InputRichBlockPullQuotation:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypePullQuotation); err != nil {
|
||||
return err
|
||||
@@ -439,7 +390,10 @@ func (v *richValidator) block(block tgapi.InputRichBlock, depth int) error {
|
||||
if err := validateTableCell(cell); err != nil {
|
||||
return err
|
||||
}
|
||||
span := max(cell.ColSpan, 1)
|
||||
span := cell.ColSpan
|
||||
if span < 1 {
|
||||
span = 1
|
||||
}
|
||||
columns += span
|
||||
if err := v.text(cell.Text, depth+1); err != nil {
|
||||
return err
|
||||
|
||||
+5
-10
@@ -3,7 +3,7 @@ package laniakea
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
)
|
||||
|
||||
func (bot *Bot[T]) handleUpdate(u *tgapi.Update, ctx *MessageContext) bool {
|
||||
@@ -201,11 +201,10 @@ func (bot *Bot[T]) prepareUpdateCtx(u *tgapi.Update, ctx *MessageContext) {
|
||||
}
|
||||
case tgapi.UpdateTypePollAnswer:
|
||||
if u.PollAnswer != nil {
|
||||
if u.PollAnswer.User != nil {
|
||||
from = u.PollAnswer.User
|
||||
}
|
||||
if u.PollAnswer.VoterChat != nil {
|
||||
chat = u.PollAnswer.VoterChat
|
||||
if voter, ok := u.PollAnswer.VoterUser(); ok {
|
||||
from = voter
|
||||
} else if voterChat, ok := u.PollAnswer.VoterChatInfo(); ok {
|
||||
chat = voterChat
|
||||
}
|
||||
}
|
||||
case tgapi.UpdateTypeMessageReaction:
|
||||
@@ -239,10 +238,6 @@ func (bot *Bot[T]) prepareUpdateCtx(u *tgapi.Update, ctx *MessageContext) {
|
||||
if u.Subscription != nil {
|
||||
from = &u.Subscription.User
|
||||
}
|
||||
case tgapi.UpdateTypeMessageGenerationStopped:
|
||||
if u.StoppedMessageGeneration != nil {
|
||||
chat = &u.StoppedMessageGeneration.Chat
|
||||
}
|
||||
}
|
||||
if ctx.Msg != nil && from == nil {
|
||||
from = ctx.Msg.From
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
// Ptr returns a pointer to v.
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"mime/multipart"
|
||||
"testing"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
type multipartEncodeParams struct {
|
||||
|
||||
+4
-4
@@ -2,13 +2,13 @@ package utils
|
||||
|
||||
const (
|
||||
// VersionString is the module version string.
|
||||
VersionString = "2.0.0-rc.1"
|
||||
VersionString = "1.2.0"
|
||||
// VersionMajor is the module major version.
|
||||
VersionMajor = 2
|
||||
VersionMajor = 1
|
||||
// VersionMinor is the module minor version.
|
||||
VersionMinor = 0
|
||||
VersionMinor = 2
|
||||
// VersionPatch is the module patch version.
|
||||
VersionPatch = 0
|
||||
// VersionBeta is the prerelease counter for the current version.
|
||||
VersionBeta = 1
|
||||
VersionBeta = 0
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user