iachat/spec/services
Muhsin Keloth 26ea87a6cb
fix: Extend phone number normalization to Twilio WhatsApp (#12655)
### Problem
WhatsApp Cloud channels already handle Brazil/Argentina phone number
format mismatches (PRs #12492, #11173), but Twilio WhatsApp channels
were creating duplicate contacts
  when:
  - Template sent to new format: `whatsapp:+5541988887777` (13 digits)
  - User responds from old format: `whatsapp:+554188887777` (12 digits)

### Solution

The solution extends the existing phone number normalization
infrastructure to support both WhatsApp providers while handling their
different payload formats:

  ### Provider Format Differences
  - **WhatsApp Cloud**: `wa_id: "919745786257"` (clean number)
- **Twilio WhatsApp**: `From: "whatsapp:+919745786257"` (prefixed
format)
  
  
 ### Test Coverage

#### Brazil Phone Number Tests
  **Case 1: New Format (13 digits with "9")**
- **Test 1**: No existing contact → Creates new contact with original
format
- **Test 2**: Contact exists in same format → Appends to existing
conversation

  **Case 2: Old Format (12 digits without "9")**
- **Test 3**: Contact exists in old format → Appends to existing
conversation
- **Test 4** *(Critical)*: Contact exists in new format, message in old
format → Finds existing contact, prevents duplicate
- **Test 5**: No contact exists → Creates new contact with incoming
format

#### Argentina Phone Number Tests
  **Case 3: With "9" after country code**
  - **Test 6**: No existing contact → Creates new contact
- **Test 7**: Contact exists in normalized format → Uses existing
contact

  **Case 4: Without "9" after country code**
  - **Test 8**: Contact exists in same format → Appends to existing
  - **Test 9**: No contact exists → Creates new contact

Fixes
https://linear.app/chatwoot/issue/CW-5565/inconsistencies-for-mobile-numbersargentina-brazil-and-mexico-numbers
2025-10-28 18:16:29 +05:30
..
account fix: account email validation during signup (#11307) 2025-05-20 20:45:39 -07:00
auto_assignment chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
automation_rules feat: Add support for labels in automations (#11658) 2025-09-18 14:17:54 +05:30
contacts feat: Use resolved contacts as base relation for filtering (#12520) 2025-09-25 15:26:44 +05:30
conversations feat: move Slack config to installation settings (#11548) 2025-05-23 01:07:35 -07:00
crm/leadsquared feat: save timezone from leadsquared API (#11583) 2025-05-28 09:46:59 +05:30
email chore: Migrate mailers from the worker to jobs (#12331) 2025-10-21 16:36:37 -07:00
facebook feat: Add message support for input_select type in Facebook (#11627) 2025-06-10 16:15:11 +05:30
google feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
imap feat: Add configurable interval for IMAP sync (#9302) 2024-04-25 18:58:20 -07:00
instagram feat: Handle instagram test service (#11244) 2025-04-11 19:11:29 +05:30
internal feat: add job to remove stale contacts and contact_inboxes (#11186) 2025-03-28 12:18:39 +05:30
labels fix: Update associations when a label is updated (#3046) 2021-09-21 10:16:32 +05:30
line fix: Ensure messages go to correct conversation when receive multi user in 1 LINE webhook (#12322) 2025-09-22 17:05:25 +05:30
linear feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
liquid feat: Add liquid processing for SMS campaigns (#10981) 2025-06-11 13:16:44 -04:00
llm_formatter feat: Expose custom attributes in conversation to Captain (#11769) 2025-06-20 10:58:00 -07:00
macros feat: Add webhook event support for macros (#11235) 2025-04-02 20:26:55 -07:00
message_templates fix: Disable automations on auto-reply emails (#12101) 2025-08-05 13:17:06 +05:30
messages chore(sidekiq): log ActiveJob class and job_id on dequeue (#12704) 2025-10-22 20:20:37 -07:00
mfa feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
microsoft chore: Refactor RefreshOauthTokenService to improve readability (#8820) 2024-01-31 12:24:12 +04:00
notification chore: Disable email notifications for unconfirmed users (#10964) 2025-02-24 12:14:40 -08:00
sms fix: Error shouldn't halt the campaign for entire audience (#11980) 2025-08-11 12:03:48 +05:30
telegram feat: Enable lock to single thread settings for Telegram (#12367) 2025-09-24 11:35:14 +05:30
twilio fix: Extend phone number normalization to Twilio WhatsApp (#12655) 2025-10-28 18:16:29 +05:30
twitter chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
whatsapp fix: Duplicate contacts creating for Argentina numbers (#11173) 2025-10-13 11:07:07 +05:30
widget feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
account_deletion_service_spec.rb feat: automate account deletion (#11406) 2025-05-23 12:58:13 +05:30
action_service_spec.rb chore: Add open conversation option (#11828) 2025-07-02 10:01:50 +05:30
base_token_service_spec.rb feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
csat_survey_service_spec.rb feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
search_service_spec.rb feat: skip inbox filter if the user has access to all inboxes (#12043) 2025-07-25 15:29:10 +05:30