diff --git a/adapters/telegram/src/polling.ts b/adapters/telegram/src/polling.ts index b49ae986..d0f64b79 100644 --- a/adapters/telegram/src/polling.ts +++ b/adapters/telegram/src/polling.ts @@ -34,8 +34,8 @@ export class HttpPolling extends Adapter.Client { offset: this.offset + 1, timeout: Math.ceil(bot.config.pollingTimeout / 1000), // in seconds }) - if (bot.status === 'disconnect') { - return bot.offline() + if (bot.status === 'offline' || bot.status === 'disconnect') { + return } bot.online() _retryCount = 0 @@ -45,7 +45,7 @@ export class HttpPolling extends Adapter.Client { this.offset = Math.max(this.offset, e.update_id) handleUpdate(e, bot) } - setTimeout(polling, 0) + this.timeout = setTimeout(polling, 0) } catch (e) { if (!Quester.isAxiosError(e) || !e.response?.data) { // Other error @@ -60,6 +60,9 @@ export class HttpPolling extends Adapter.Client { bot.error = e return bot.status = 'offline' } + if (bot.status === 'offline' || bot.status === 'disconnect') { + return + } _retryCount++ bot.status = 'reconnect' this.timeout = setTimeout(() => polling(), retryInterval) diff --git a/packages/core/src/bot.ts b/packages/core/src/bot.ts index 4b0c566f..6f945726 100644 --- a/packages/core/src/bot.ts +++ b/packages/core/src/bot.ts @@ -94,6 +94,7 @@ export abstract class Bot { await this.adapter?.stop(this) } catch (error) { this.context.emit('internal/warning', error) + } finally { this.offline() } }