Created
February 12, 2019 22:56
-
-
Save kraftwerk28/e82273e1faea2d3c2a41a296fdcb91bd to your computer and use it in GitHub Desktop.
U know whit it is for...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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