grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.37k stars 117 forks source link

feat: detect concurrent polling/webhook setups and throw error #646

Closed KnorpelSenf closed 4 weeks ago

KnorpelSenf commented 1 month ago

People sometimes do

webhookCallback(bot)
bot.start()

or

bot.start()
webhookCallback(bot)

and in 99 % of cases, this is just wrong.

This PQ interdicts this type of usage and throws a helpful error message.

If this is actually desired (run the bot on built-in polling but then also supply old updates from a webhook queue, whatever) then it can be done anyway:

const middleware = new Composer()
middleware.use(..) // etc

const pollingBot = new Bot(token)
const webhookBot = new Bot(token)
pollingBot.use(middleware)
webhookBot.use(middleware)

pollingBot.start()
webhookCallback(webhookBot)