Skip to content

Commit

Permalink
fix(telegram): polling
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX committed Aug 30, 2023
1 parent e60f010 commit a79001f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions adapters/telegram/src/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class HttpPolling extends Adapter.Client<TelegramBot> {
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
Expand All @@ -45,7 +45,7 @@ export class HttpPolling extends Adapter.Client<TelegramBot> {
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
Expand All @@ -60,6 +60,9 @@ export class HttpPolling extends Adapter.Client<TelegramBot> {
bot.error = e
return bot.status = 'offline'
}
if (bot.status === 'offline' || bot.status === 'disconnect') {
return
}
_retryCount++
bot.status = 'reconnect'
this.timeout = setTimeout(() => polling(), retryInterval)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export abstract class Bot<T extends Bot.Config = Bot.Config> {
await this.adapter?.stop(this)
} catch (error) {
this.context.emit('internal/warning', error)
} finally {
this.offline()
}
}
Expand Down

0 comments on commit a79001f

Please sign in to comment.