node-telegram-bot-api
node-telegram-bot-api copied to clipboard
how to use startPolling with offset option
Bug Report
I have read:
I am using the latest version of the library.
Expected Behavior
const bot = new TelegramBot(Env.TELEGRAM_BOT_TOKEN, { polling: false })
// Ignore all previous updates
const updates = await bot.getUpdates()
const pollingOffset = updates.pop()?.update_id + 1 || 0
const pollingOptions = { params: { offset: pollingOffset } }
bot.startPolling(pollingOptions)
Expecting bot to ignore stacked updates and to start polling from new ones
Actual Behavior
Bot keeps receiving previous updates on starting, thoses sent when the script was not running
Question
Since I get the last update_id when script starts
const bot = new TelegramBot(Env.TELEGRAM_BOT_TOKEN, { polling: { params: { offset: pollingOffset } } }) can't be used.
Is it possible to startPolling manually with an offset param ? Thanks you
It seems options.polling.params does not work as described in the documentation. You can use this method to customize offset parameter when sending a getUpdates request.
let originalGetUpdates = bot.getUpdates;
bot.getUpdates = function (form){
form.offset = pollingOffset;
return originalGetUpdates.call(bot, form);
}