From 89c173ff61d9e33c6db1c9903493f5ab3b4754be Mon Sep 17 00:00:00 2001 From: Daniel Apatin Date: Sun, 3 Mar 2024 11:50:22 +0300 Subject: [PATCH 1/2] add WithAllowedUpdates option --- bot.go | 2 ++ get_updates.go | 14 ++++++++++---- options.go | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bot.go b/bot.go index 07b1c47..313d4df 100644 --- a/bot.go +++ b/bot.go @@ -51,6 +51,8 @@ type Bot struct { isDebug bool checkInitTimeout time.Duration + allowedUpdates AllowedUpdates + updates chan *models.Update } diff --git a/get_updates.go b/get_updates.go index 6ce96b6..005cd6e 100644 --- a/get_updates.go +++ b/get_updates.go @@ -15,12 +15,14 @@ const ( ) type getUpdatesParams struct { - Offset int64 `json:"offset,omitempty"` - Limit int `json:"limit,omitempty"` - Timeout int `json:"timeout,omitempty"` - AllowedUpdates []string `json:"allowed_updates,omitempty"` + Offset int64 `json:"offset,omitempty"` + Limit int `json:"limit,omitempty"` + Timeout int `json:"timeout,omitempty"` + AllowedUpdates AllowedUpdates `json:"allowed_updates,omitempty"` } +type AllowedUpdates []string + // GetUpdates https://core.telegram.org/bots/api#getupdates func (b *Bot) getUpdates(ctx context.Context, wg *sync.WaitGroup) { defer wg.Done() @@ -50,6 +52,10 @@ func (b *Bot) getUpdates(ctx context.Context, wg *sync.WaitGroup) { Offset: atomic.LoadInt64(&b.lastUpdateID) + 1, } + if b.allowedUpdates != nil { + params.AllowedUpdates = b.allowedUpdates + } + var updates []*models.Update errRequest := b.rawRequest(ctx, "getUpdates", params, &updates) diff --git a/options.go b/options.go index b864294..73ce550 100644 --- a/options.go +++ b/options.go @@ -86,3 +86,10 @@ func WithSkipGetMe() Option { b.skipGetMe = true } } + +// WithAllowedUpdates allows to set custom params for getUpdates method +func WithAllowedUpdates(params AllowedUpdates) Option { + return func(b *Bot) { + b.allowedUpdates = params + } +} From c0dd14dc6bdbcdc52a1e5a40446c294bdd1d5337 Mon Sep 17 00:00:00 2001 From: Daniel Apatin Date: Mon, 4 Mar 2024 16:24:07 +0300 Subject: [PATCH 2/2] Add WithAllowedUpdates method description to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ef2c079..690f92c 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ b, err := bot.New("YOUR_BOT_TOKEN_FROM_BOTFATHER", opts...) - `WithHTTPClient(pollTimeout time.Duration, client HttpClient)` - set custom http client - `WithServerURL(serverURL string)` - set server url - `WithSkipGetMe()` - skip call GetMe on bot init +- `WithAllowedUpdates(params AllowedUpdates)` - set [allowed_updates](https://core.telegram.org/bots/api#getupdates) for getUpdates method ## Message.Text and CallbackQuery.Data handlers