diff --git a/README.md b/README.md index 132d07c..8b6d31f 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ async function run () { // Ref: https://core.telegram.org/bots/api#setwebhook webhookSecret: 'secret', + // [optional]: the polling mode requires an health check that slows down the startup + // you can customize the max milliseconds to wait for the health check to pass + waitForHealthPolling: 3_000, // default: app.initialConfig.pluginTimeout / 6 + // [optional] this function is called when an error is not handled // by default it logs the error using `fastify.log.error` // Ref: https://telegrafjs.org/index.html#/?id=error-handling diff --git a/index.js b/index.js index 61f3305..227e546 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const { Telegraf } = require('telegraf') async function fastifyTelegram (app, options) { const { decoratorBotName = 'telegramBot', + waitForHealthPolling = app.initialConfig.pluginTimeout / 6, baseUrl, webhookSecret, botToken, @@ -63,7 +64,7 @@ async function fastifyTelegram (app, options) { // it triggers an error during startup if the config is invalid await Promise.race([ bot.launch({ webhook: undefined }).catch(handleFatalError), - timeout(app.initialConfig.pluginTimeout / 2) + timeout(waitForHealthPolling) ]) if (startError) {