Skip to content

Commit

Permalink
Merge pull request #20 from Jorgelig-Labs/bugfix/mexican-and-argentin…
Browse files Browse the repository at this point in the history
…ian-numbers-createjid

bugfix: Fixed parsing issue for Mexican and Argentine numbers
  • Loading branch information
jrCleber authored May 9, 2023
2 parents f5cf865 + 83cf895 commit 168bac3
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,21 @@ export class WAStartupService {
});
}

private createJid(number: string) {
if (number.includes('@g.us') || number.includes('@s.whatsapp.net')) {
return number;
// Check if the number is MX or AR
private formatMXOrARNumber(jid: string): string {
const regexp = new RegExp(/^(\d{2})(\d{2})\d{1}(\d{8})$/);
if (regexp.test(jid)) {
const match = regexp.exec(jid);
if (match && (match[1] === '52' || match[1] === '54')) {
const joker = Number.parseInt(match[3][0]);
const ddd = Number.parseInt(match[2]);
if (joker < 7 || ddd < 11) {
return match[0];
}
return (match[1] === '52') ? '52' + match[3] : '54' + match[3];
}
}
return number.includes('-')
? `${number}@g.us`
: `${this.formatBRNumber(number)}@s.whatsapp.net`;
return jid;
}

// Check if the number is br
Expand All @@ -792,6 +800,28 @@ export class WAStartupService {
}
}

private createJid(number: string): string {
if (number.includes('@g.us') || number.includes('@s.whatsapp.net')) {
return number;
}

const formattedBRNumber = this.formatBRNumber(number);
if (formattedBRNumber !== number) {
return `${formattedBRNumber}@s.whatsapp.net`;
}

const formattedMXARNumber = this.formatMXOrARNumber(number);
if (formattedMXARNumber !== number) {
return `${formattedMXARNumber}@s.whatsapp.net`;
}

if (number.includes('-')) {
return `${number}@g.us`;
}

return `${number}@s.whatsapp.net`;
}

public async profilePicture(number: string) {
const jid = this.createJid(number);
try {
Expand Down

0 comments on commit 168bac3

Please sign in to comment.