Number Duplication Issue on the Platform: Solution for Handling DDD in Brazil
Jonas Souza
#1
Jonas Souza
Number Duplication Issue on the Platform: Solution for Handling DDD in Brazil
Hello, team,

I would like to report a recurring issue we are facing on the platform related to the duplication of phone numbers in Brazil. I will detail the problem, present the code I developed as a personal solution, and explain why this cannot be implemented for customers at the moment.

In Brazil, phone numbers have a peculiarity: in addition to the DDI (55) and DDD (area code), there is an additional digit (9) positioned before the last eight digits of the number. For example, a number would look like this: 5591912345678, where:

55 is the DDI,
91 is the DDD, and
9 is the required fifth digit before the last eight digits of the number.
The issue arises as follows:

When the DDD is 30 or less, the WhatsApp Business API correctly recognizes the number with the extra 9 after the DDD.

However, for numbers with a DDD greater than 30, the WhatsApp Business API does not recognize the number when the extra 9 is added after the DDD. This results in the creation of new conversations and new contact registrations, as if they were different customers, causing duplication.

This issue has affected both me and my clients for over a year. Recently, I discovered the cause and implemented a solution in the webhook I use to prevent this duplication. The applied logic is as follows:

If the DDD is less than or equal to 30, the number should include the 9 after the DDD.
If the DDD is greater than 30, the number should be adjusted by removing the 9 after the DDD.
Here is a sample of the code I use to solve this issue:

___________________________________

// Verifica se o número possui ao menos 12 dígitos (incluindo "55" + DDD + número)
if (number.length >= 12 && number.startsWith('55')) {
const ddd = number.substring(2, 4); // Extrai o DDD
let remaining = number.substring(4); // Extrai o restante do número

// Se o DDD for menor ou igual a 30, adiciona o "9" se não estiver presente
if (parseInt(ddd)