fix(telegram): avoid awaiting long-running polling start
This commit is contained in:
@@ -463,8 +463,9 @@ export class TelegramAdapter implements ChannelAdapter {
|
|||||||
|
|
||||||
// ── Start long polling ──
|
// ── Start long polling ──
|
||||||
|
|
||||||
try {
|
// bot.start() is a long-running method that resolves only when the bot stops.
|
||||||
await bot.start({
|
// Do NOT await it — fire-and-forget so connect() resolves immediately.
|
||||||
|
bot.start({
|
||||||
onStart: (botInfo) => {
|
onStart: (botInfo) => {
|
||||||
console.log(`Telegram bot started: @${botInfo.username}`);
|
console.log(`Telegram bot started: @${botInfo.username}`);
|
||||||
this.botInfo = { id: botInfo.id, username: botInfo.username };
|
this.botInfo = { id: botInfo.id, username: botInfo.username };
|
||||||
@@ -473,16 +474,16 @@ export class TelegramAdapter implements ChannelAdapter {
|
|||||||
this._lastError = undefined;
|
this._lastError = undefined;
|
||||||
this._lastErrorAt = undefined;
|
this._lastErrorAt = undefined;
|
||||||
},
|
},
|
||||||
});
|
}).catch((error) => {
|
||||||
if (this._status === 'connecting') {
|
|
||||||
// For mocked/runtime environments where onStart is not surfaced synchronously.
|
|
||||||
this._status = 'connected';
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
const description = error instanceof Error ? error.message : String(error);
|
const description = error instanceof Error ? error.message : String(error);
|
||||||
this.recordAdapterError(`Telegram connect failed: ${description}`);
|
this.recordAdapterError(`Telegram connect failed: ${description}`);
|
||||||
this.scheduleReconnect();
|
this.scheduleReconnect();
|
||||||
throw error;
|
});
|
||||||
|
|
||||||
|
// Set connected optimistically for mocked/runtime environments
|
||||||
|
// where onStart is not surfaced synchronously.
|
||||||
|
if (this._status === 'connecting') {
|
||||||
|
this._status = 'connected';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,7 +633,7 @@ export class TelegramAdapter implements ChannelAdapter {
|
|||||||
|
|
||||||
this._status = 'connecting';
|
this._status = 'connecting';
|
||||||
await bot.stop();
|
await bot.stop();
|
||||||
await bot.start({
|
bot.start({
|
||||||
onStart: (botInfo) => {
|
onStart: (botInfo) => {
|
||||||
console.log(`Telegram bot reconnected: @${botInfo.username}`);
|
console.log(`Telegram bot reconnected: @${botInfo.username}`);
|
||||||
this.botInfo = { id: botInfo.id, username: botInfo.username };
|
this.botInfo = { id: botInfo.id, username: botInfo.username };
|
||||||
@@ -641,6 +642,10 @@ export class TelegramAdapter implements ChannelAdapter {
|
|||||||
this._lastError = undefined;
|
this._lastError = undefined;
|
||||||
this._lastErrorAt = undefined;
|
this._lastErrorAt = undefined;
|
||||||
},
|
},
|
||||||
|
}).catch((error) => {
|
||||||
|
const description = error instanceof Error ? error.message : String(error);
|
||||||
|
this.recordAdapterError(`Telegram reconnect polling error: ${description}`);
|
||||||
|
this.scheduleReconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this._status === 'connecting') {
|
if (this._status === 'connecting') {
|
||||||
|
|||||||
Reference in New Issue
Block a user