From 89c173ff61d9e33c6db1c9903493f5ab3b4754be Mon Sep 17 00:00:00 2001 From: Daniel Apatin Date: Sun, 3 Mar 2024 11:50:22 +0300 Subject: [PATCH] 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 + } +}