Skip to content

Commit 17f98b6

Browse files
committed
fix: corrige verificação de usuários @lid no envio de mensagens no WhatsApp - Closes #186
Adiciona verificação específica para JIDs @lid na função whatsappNumber, marcando-os como existentes para permitir envio. Isso resolve o erro 400 retornado ao tentar enviar mensagens para JIDs com sufixo @lid.
1 parent a0e7dd2 commit 17f98b6

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/whatsapp/dto/chat.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class OnWhatsAppDto {
4343
constructor(
4444
public readonly jid: string,
4545
public readonly exists: boolean,
46+
public readonly lid?: string,
4647
public readonly name?: string,
4748
) {}
4849
}

src/whatsapp/services/whatsapp.service.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import makeWASocket, {
5454
GroupMetadata,
5555
isJidGroup,
5656
isJidUser,
57+
isLidUser,
5758
makeCacheableSignalKeyStore,
5859
MessageUpsertType,
5960
ParticipantAction,
@@ -844,7 +845,7 @@ export class WAStartupService {
844845
}) => {
845846
for (const received of messages) {
846847
if (!received?.message) {
847-
await this.client.waitForMessage(received.key.id)
848+
await this.client.waitForMessage(received.key.id);
848849
continue;
849850
}
850851

@@ -1172,7 +1173,11 @@ export class WAStartupService {
11721173
}
11731174

11741175
private createJid(number: string): string {
1175-
if (number.includes('@g.us') || number.includes('@s.whatsapp.net') || number.includes('@lid')) {
1176+
if (
1177+
number.includes('@g.us') ||
1178+
number.includes('@s.whatsapp.net') ||
1179+
number.includes('@lid')
1180+
) {
11761181
return number;
11771182
}
11781183

@@ -1355,7 +1360,7 @@ export class WAStartupService {
13551360

13561361
this.ws.send(this.instance.name, 'send.message', messageSent);
13571362
this.ws.send(this.instance.name, 'messages.upsert', messageSent);
1358-
1363+
13591364
this.sendDataWebhook('sendMessage', messageSent).catch((error) =>
13601365
this.logger.error(error),
13611366
);
@@ -1960,15 +1965,20 @@ export class WAStartupService {
19601965
const onWhatsapp: OnWhatsAppDto[] = [];
19611966
for await (const number of data.numbers) {
19621967
const jid = this.createJid(number);
1968+
if (isLidUser(jid)) {
1969+
onWhatsapp.push(new OnWhatsAppDto(jid, !!true, jid as string));
1970+
}
19631971
if (isJidGroup(jid)) {
19641972
const group = await this.findGroup({ groupJid: jid }, 'inner');
1965-
onWhatsapp.push(new OnWhatsAppDto(group.id, !!group?.id, group?.subject));
1973+
onWhatsapp.push(new OnWhatsAppDto(group.id, !!group?.id, '', group?.subject));
19661974
} else if (jid.includes('@broadcast')) {
19671975
onWhatsapp.push(new OnWhatsAppDto(jid, true));
19681976
} else {
19691977
try {
19701978
const result = (await this.client.onWhatsApp(jid))[0];
1971-
onWhatsapp.push(new OnWhatsAppDto(result.jid, !!result.exists));
1979+
onWhatsapp.push(
1980+
new OnWhatsAppDto(result.jid, !!result.exists, result.lid as string),
1981+
);
19721982
} catch (error) {
19731983
onWhatsapp.push(new OnWhatsAppDto(number, false));
19741984
}

0 commit comments

Comments
 (0)