Skip to content

Commit

Permalink
feat: detect concurrent polling/webhook setups and throw error (#646)
Browse files Browse the repository at this point in the history
* feat: detect concurrent polling/webhook setups and print warning

* feat: throw an error instead of warning people

* 100 %
  • Loading branch information
KnorpelSenf authored Oct 21, 2024
1 parent 237889c commit f31feed
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/convenience/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ export function webhookCallback<C extends Context = Context>(
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
) {
if (bot.isRunning()) {
throw new Error(
"Bot is already running via long polling, the webhook setup won't receive any updates!",
);
} else {
bot.start = () => {
throw new Error(
"You already started the bot via webhooks, calling `bot.start()` starts the bot with long polling and this will prevent your webhook setup from receiving any updates!",
);
};
}
const {
onTimeout: timeout = "throw",
timeoutMilliseconds: ms = 10_000,
Expand Down

0 comments on commit f31feed

Please sign in to comment.