Skip to content

Commit

Permalink
add WithAllowedUpdates option
Browse files Browse the repository at this point in the history
  • Loading branch information
ad committed Mar 3, 2024
1 parent a84712f commit 89c173f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Bot struct {
isDebug bool
checkInitTimeout time.Duration

allowedUpdates AllowedUpdates

updates chan *models.Update
}

Expand Down
14 changes: 10 additions & 4 deletions get_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 89c173f

Please sign in to comment.