Skip to content

Instantly share code, notes, and snippets.

@kraftwerk28
Created February 12, 2019 22:56
Show Gist options
  • Save kraftwerk28/e82273e1faea2d3c2a41a296fdcb91bd to your computer and use it in GitHub Desktop.
Save kraftwerk28/e82273e1faea2d3c2a41a296fdcb91bd to your computer and use it in GitHub Desktop.
U know whit it is for...
// eating old updates
(async () => {
if (bot.hasOpenWebHook()) {
await bot.deleteWebHook()
}
let lastUpdateID = 0
lastUpdateID = await bot.getUpdates({})
.then(updates => updates[updates.length - 1].update_id)
const recursiveReq = async () => {
const newUpdate = await bot.getUpdates({ offset: lastUpdateID + 1 })
if (newUpdate.length) {
console.log('Fetched old updates...')
lastUpdateID = newUpdate[newUpdate.length - 1].update_id
getUpdateRec()
} else {
// STARTING
bot.setWebHook(`${URL}/${TOKEN}`).then(() => {
console.log('Bot summoned')
});
// ...or set your polling mode
}
}
recursiveReq();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment