mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
fix: Duplicate contacts creating for Argentina numbers (#11173)
This commit is contained in:
@@ -47,6 +47,15 @@ module Whatsapp::IncomingMessageServiceHelpers
|
||||
%w[reaction ephemeral unsupported request_welcome].include?(message_type)
|
||||
end
|
||||
|
||||
def argentina_phone_number?(phone_number)
|
||||
phone_number.match(/^54/)
|
||||
end
|
||||
|
||||
def normalised_argentina_mobil_number(phone_number)
|
||||
# Remove 9 before country code
|
||||
phone_number.sub(/^549/, '54')
|
||||
end
|
||||
|
||||
def processed_waid(waid)
|
||||
Whatsapp::PhoneNumberNormalizationService.new(inbox).normalize_and_find_contact(waid)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Handles Argentina phone number normalization
|
||||
#
|
||||
# Argentina phone numbers can appear with or without "9" after country code
|
||||
# This normalizer removes the "9" when present to create consistent format: 54 + area + number
|
||||
class Whatsapp::PhoneNormalizers::ArgentinaPhoneNormalizer < Whatsapp::PhoneNormalizers::BasePhoneNormalizer
|
||||
def normalize(waid)
|
||||
return waid unless handles_country?(waid)
|
||||
|
||||
# Remove "9" after country code if present (549 → 54)
|
||||
waid.sub(/^549/, '54')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def country_code_pattern
|
||||
/^54/
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Service to handle phone number normalization for WhatsApp messages
|
||||
# Currently supports Brazil phone number format variations
|
||||
# Currently supports Brazil and Argentina phone number format variations
|
||||
# Designed to be extensible for additional countries in future PRs
|
||||
#
|
||||
# Usage: Whatsapp::PhoneNumberNormalizationService.new(inbox).normalize_and_find_contact(waid)
|
||||
@@ -34,6 +34,7 @@ class Whatsapp::PhoneNumberNormalizationService
|
||||
end
|
||||
|
||||
NORMALIZERS = [
|
||||
Whatsapp::PhoneNormalizers::BrazilPhoneNormalizer
|
||||
Whatsapp::PhoneNormalizers::BrazilPhoneNormalizer,
|
||||
Whatsapp::PhoneNormalizers::ArgentinaPhoneNormalizer
|
||||
].freeze
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user