grammyjs / grammY

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

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

Open KnorpelSenf opened 2 days ago

KnorpelSenf commented 2 days 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)