chatwoot/spec/factories/channel
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
..
channel_api.rb Feature: API Channel (#1052) 2020-07-21 12:15:24 +05:30
channel_email.rb fix(refactor): Cleanup the specs and the logic for FetchIMAP job (#8766) 2024-02-10 14:03:50 -08:00
channel_instagram.rb feat: Added the ability to create Instagram channel (#11182) 2025-04-03 13:57:14 +05:30
channel_line.rb feat: Line Channel (#2904) 2021-09-11 01:31:17 +05:30
channel_sms.rb chore: Provider APIs for SMS Channel - Bandwidth (#3889) 2022-02-03 15:22:13 -08:00
channel_telegram.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
channel_voice.rb feat(voice): Improved voice call creation flow [EE] (#12268) 2025-08-22 13:38:23 +02:00
channel_whatsapp.rb fix: Handle nil processed_params for WhatsApp templates without params (#12177) 2025-08-12 22:56:53 +05:30
channel_widget.rb Chore: Web widget Inbox Tech Debts (#738) 2020-04-19 23:40:28 +05:30
facebook_pages.rb Chore: Web widget Inbox Tech Debts (#738) 2020-04-19 23:40:28 +05:30
instagram_channel.rb fix: Automatically remove expired story mention (#5300) 2022-12-08 15:55:24 +03:00
twilio_sms.rb fix: Extend phone number normalization to Twilio WhatsApp (#12655) 2025-10-28 18:16:29 +05:30
twitter_profiles.rb Chore: Web widget Inbox Tech Debts (#738) 2020-04-19 23:40:28 +05:30