mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 04:22:02 -06:00
Added new validation on the 9 digit
This is to prevent returning another jid when only one digit is different and not the 9 digit
This commit is contained in:
parent
ed6c50621c
commit
eb96c9fece
@ -3173,10 +3173,15 @@ export class WAStartupService {
|
||||
...jids.users.map(({ jid }) => (!jid.startsWith('+') ? `+${jid}` : jid)),
|
||||
);
|
||||
const users: OnWhatsAppDto[] = jids.users.map((user) => {
|
||||
const MAX_SIMILARITY_THRESHOLD = 0.0358;
|
||||
const numberVerified = verify.find(
|
||||
(v) => levenshtein.get(user.jid, v.jid) / Math.max(user.jid.length, v.jid.length) <= MAX_SIMILARITY_THRESHOLD,
|
||||
);
|
||||
const MAX_SIMILARITY_THRESHOLD = 0.01;
|
||||
const isBrWithDigit = user.jid.startsWith('55') && user.jid.slice(4, 5) === '9' && user.jid.length === 28;
|
||||
const jid = isBrWithDigit ? user.jid.slice(0, 4) + user.jid.slice(5) : user.jid;
|
||||
|
||||
const numberVerified = verify.find((v) => {
|
||||
const mainJidSimilarity = levenshtein.get(user.jid, v.jid) / Math.max(user.jid.length, v.jid.length);
|
||||
const jidSimilarity = levenshtein.get(jid, v.jid) / Math.max(jid.length, v.jid.length);
|
||||
return mainJidSimilarity <= MAX_SIMILARITY_THRESHOLD || jidSimilarity <= MAX_SIMILARITY_THRESHOLD;
|
||||
});
|
||||
return {
|
||||
exists: !!numberVerified?.exists,
|
||||
jid: numberVerified?.jid || user.jid,
|
||||
|
Loading…
Reference in New Issue
Block a user