Closed dani0854 closed 10 months ago
If I understand correctly you need to discard all updates with a timestamp older than the bot start time.
I solved this using MiddlewarePoller
...
var startTime = time.now()
...
func main() {
...
// discards updates older than client start time
poller := &tele.MiddlewarePoller {
Poller: &tele.LongPoller{ Timeout: 10 * time.Second },
Filter: func(u *tele.Update) bool {
return u.Message.Time().After(startTime)
},
}
b, err := tele.NewBot(tele.Settings{
Token: <token>,
Poller: poller,
})
...
I hope it fits your use case
If I understand correctly you need to discard all updates with a timestamp older than the bot start time. I solved this using
MiddlewarePoller
... var startTime = time.now() ... func main() { ... // discards updates older than client start time poller := &tele.MiddlewarePoller { Poller: &tele.LongPoller{ Timeout: 10 * time.Second }, Filter: func(u *tele.Update) bool { return u.Message.Time().After(startTime) }, } b, err := tele.NewBot(tele.Settings{ Token: <token>, Poller: poller, }) ...
I hope it fits your use case
That is actually a neat solution, thanks
Sometimes for bots behavior when it doesn't process pending updates since its last
getUpdates
request is desired.I could find a clean way to do it using
telebot.LongPoller
It hasLastUpdateID
, but no matter what values it set to, it still processes at least 1 update (minimum at value-2
, since it passes-1
tooffset
)According to bot api docs, the best way to do it, is to request
getUpdates
withoffset=-1
, same asLastUpdateID=-2
. And ignore the 1st update while long polling.Can this be achieved in current veriosn of library? If not, then this is a feature request.