Skip to content

Commit

Permalink
Merge pull request #1058 from Richards0nd/newPhoneNumberContent
Browse files Browse the repository at this point in the history
Correção: Número de telefone apresentado no nome do contato (CW Service)
  • Loading branch information
DavidsonGomes authored Nov 14, 2024
2 parents 52cf4fa + 7ef8afa commit 7bf0fd1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1970,11 +1970,16 @@ export class ChatwootService {

if (body.key.remoteJid.includes('@g.us')) {
const participantName = body.pushName;
const rawPhoneNumber = body.key.remoteJid.split('@')[0];
const formattedPhoneNumber = `+${rawPhoneNumber.slice(0, 2)} (${rawPhoneNumber.slice(
2,
4,
)}) ${rawPhoneNumber.slice(4, 8)}-${rawPhoneNumber.slice(8)}`;
const rawPhoneNumber = body.key.participant.split('@')[0];
const phoneMatch = rawPhoneNumber.match(/^(\d{2})(\d{2})(\d{4})(\d{4})$/);

let formattedPhoneNumber: string;

if (phoneMatch) {
formattedPhoneNumber = `+${phoneMatch[1]} (${phoneMatch[2]}) ${phoneMatch[3]}-${phoneMatch[4]}`;
} else {
formattedPhoneNumber = `+${rawPhoneNumber}`;
}

let content: string;

Expand Down Expand Up @@ -2104,11 +2109,16 @@ export class ChatwootService {

if (body.key.remoteJid.includes('@g.us')) {
const participantName = body.pushName;
const rawPhoneNumber = body.key.remoteJid.split('@')[0];
const formattedPhoneNumber = `+${rawPhoneNumber.slice(0, 2)} (${rawPhoneNumber.slice(
2,
4,
)}) ${rawPhoneNumber.slice(4, 8)}-${rawPhoneNumber.slice(8)}`;
const rawPhoneNumber = body.key.participant.split('@')[0];
const phoneMatch = rawPhoneNumber.match(/^(\d{2})(\d{2})(\d{4})(\d{4})$/);

let formattedPhoneNumber: string;

if (phoneMatch) {
formattedPhoneNumber = `+${phoneMatch[1]} (${phoneMatch[2]}) ${phoneMatch[3]}-${phoneMatch[4]}`;
} else {
formattedPhoneNumber = `+${rawPhoneNumber}`;
}

let content: string;

Expand Down

0 comments on commit 7bf0fd1

Please sign in to comment.