Skip to content

Commit

Permalink
feat: add waitForHealthPolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Oct 15, 2023
1 parent 8e75f2a commit a7a8df2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { Telegraf } = require('telegraf')
async function fastifyTelegram (app, options) {
const {
decoratorBotName = 'telegramBot',
waitForHealthPolling = app.initialConfig.pluginTimeout / 6,
baseUrl,
webhookSecret,
botToken,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a7a8df2

Please sign in to comment.