diff --git a/CHANGELOG.md b/CHANGELOG.md index b6adebe..6f9c5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.7.1 (2024-08-22) + +- add option `UseTestEnvironment` for use test environment in API requests + ## v1.7.0 (2024-08-14) - support API v7.9 diff --git a/README.md b/README.md index 1055b52..12db0c6 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ b, err := bot.New("YOUR_BOT_TOKEN_FROM_BOTFATHER", opts...) - `WithAllowedUpdates(params AllowedUpdates)` - set [allowed_updates](https://core.telegram.org/bots/api#getupdates) for getUpdates method - `WithUpdatesChannelCap(cap int)` - set updates channel capacity, by default 1024 - `WithWebhookSecretToken(webhookSecretToken string)` - set X-Telegram-Bot-Api-Secret-Token header sent from telegram servers to confirm validity of update +- `UseTestEnvironment()` - use test environment ## Message.Text and CallbackQuery.Data handlers diff --git a/bot.go b/bot.go index b9b8247..3e5b0ba 100644 --- a/bot.go +++ b/bot.go @@ -35,6 +35,7 @@ type Bot struct { pollTimeout time.Duration skipGetMe bool webhookSecretToken string + testEnvironment bool defaultHandlerFunc HandlerFunc diff --git a/options.go b/options.go index 667c96d..eb7ca5d 100644 --- a/options.go +++ b/options.go @@ -109,3 +109,10 @@ func WithWebhookSecretToken(webhookSecretToken string) Option { b.webhookSecretToken = webhookSecretToken } } + +// UseTestEnvironment allows to use test environment +func UseTestEnvironment() Option { + return func(b *Bot) { + b.testEnvironment = true + } +} diff --git a/raw_request.go b/raw_request.go index edb401c..ee1e2e0 100644 --- a/raw_request.go +++ b/raw_request.go @@ -48,7 +48,11 @@ func (b *Bot) rawRequest(ctx context.Context, method string, params any, dest an } } - u := b.url + "/bot" + b.token + "/" + method + u := b.url + "/bot" + b.token + "/" + if b.testEnvironment { + u += "test/" + } + u += method if b.isDebug && strings.ToLower(method) != "getupdates" { requestDebugData, _ := json.Marshal(params)