Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class BaileysStartupService extends ChannelStartupService {
private endSession = false;
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
private eventProcessingQueue: Promise<void> = Promise.resolve();
private _lastStream515At = 0;

// Cache TTL constants (in seconds)
private readonly MESSAGE_CACHE_TTL_SECONDS = 5 * 60; // 5 minutes - avoid duplicate message processing
Expand Down Expand Up @@ -426,7 +427,10 @@ export class BaileysStartupService extends ChannelStartupService {
if (connection === 'close') {
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
const recentStream515 = Date.now() - this._lastStream515At < 30_000;
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
const shouldReconnect =
!codesToNotReconnect.includes(statusCode) ||
(statusCode === DisconnectReason.loggedOut && recentStream515);
if (shouldReconnect) {
await this.connectToWhatsapp(this.phoneNumber);
} else {
Expand Down Expand Up @@ -715,6 +719,12 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CALL, payload, true, ['websocket']);
});

this.client.ws.on('CB:stream:error', (node: any) => {
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
if (node?.attrs?.code === '515') {
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
this._lastStream515At = Date.now();
}
});

this.phoneNumber = number;

return this.client;
Expand Down