Skip to content
Open
Changes from all commits
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
@@ -1,4 +1,4 @@
import { getCollectionsDto } from '@api/dto/business.dto';

Check failure on line 1 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Run autofix to sort these imports!
import { OfferCallDto } from '@api/dto/call.dto';
import {
ArchiveChatDto,
Expand Down Expand Up @@ -436,7 +436,7 @@
qrcodeTerminal.generate(qr, { small: true }, (qrcode) =>
this.logger.log(
`\n{ instance: ${this.instance.name} pairingCode: ${this.instance.qrcode.pairingCode}, qrcodeCount: ${this.instance.qrcode.count} }\n` +
qrcode,

Check failure on line 439 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
),
);

Expand All @@ -462,16 +462,16 @@

const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];

Check failure on line 465 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Delete `······`
// FIX: Do not reconnect if it's the initial connection (waiting for QR code)
// This prevents infinite loop that blocks QR code generation
const isInitialConnection = !this.instance.wuid && (this.instance.qrcode?.count ?? 0) === 0;

Check failure on line 469 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Delete `······`
if (isInitialConnection) {
this.logger.info('Initial connection closed, waiting for QR code generation...');
return;
}

Check failure on line 474 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Delete `······`
const shouldReconnect = !codesToNotReconnect.includes(statusCode);

this.logger.info({
Expand All @@ -488,7 +488,7 @@
await this.connectToWhatsapp(this.phoneNumber);
}, 3000);
} else {
this.logger.info(

Check failure on line 491 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Replace `⏎··········`Skipping·reconnection·for·status·code·${statusCode}·(code·is·in·codesToNotReconnect·list)`,⏎········` with ``Skipping·reconnection·for·status·code·${statusCode}·(code·is·in·codesToNotReconnect·list)``
`Skipping reconnection for status code ${statusCode} (code is in codesToNotReconnect list)`,
);
this.sendDataWebhook(Events.STATUS_INSTANCE, {
Expand Down Expand Up @@ -680,7 +680,7 @@
try {
const response = await axios.get(this.localProxy?.host);
const text = response.data;
const proxyUrls = text.split('\r\n');
const proxyUrls = text.split('\r\n').filter(Boolean);
Comment on lines 682 to +683
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use a more robust line-splitting strategy for different newline conventions.

Splitting only on "\r\n" assumes Windows line endings. If the list is served with Unix-style "\n" only, you’ll get a single, newline-containing entry and filter(Boolean) won’t fix it. Using something like text.split(/\r?\n/).filter(Boolean) will correctly handle both CRLF and LF cases.

Suggested change
const text = response.data;
const proxyUrls = text.split('\r\n');
const proxyUrls = text.split('\r\n').filter(Boolean);
const text = response.data;
const proxyUrls = text.split(/\r?\n/).filter(Boolean);

const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
const proxyUrl = 'http://' + proxyUrls[rand];
this.logger.info('Proxy url: ' + proxyUrl);
Expand Down Expand Up @@ -1113,10 +1113,10 @@

const messagesRepository: Set<string> = new Set(
chatwootImport.getRepositoryMessagesCache(instance) ??
(

Check failure on line 1116 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
await this.prismaRepository.message.findMany({

Check failure on line 1117 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
select: { key: true },

Check failure on line 1118 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Replace `··············` with `················`
where: { instanceId: this.instanceId },

Check failure on line 1119 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
})
).map((message) => {
const key = message.key as { id: string };
Expand Down
Loading