Skip to content

Commit

Permalink
add option UseTestEnvironment #89
Browse files Browse the repository at this point in the history
  • Loading branch information
negasus committed Aug 22, 2024
1 parent b3b73e9 commit 09743b3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Bot struct {
pollTimeout time.Duration
skipGetMe bool
webhookSecretToken string
testEnvironment bool

defaultHandlerFunc HandlerFunc

Expand Down
7 changes: 7 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 5 additions & 1 deletion raw_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 09743b3

Please sign in to comment.