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 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 + } +}