chatwoot/app/services/whatsapp
JoseGrdar 7acbe8b3ff
fix(whatsapp): truncate location fallback_title to 255 chars to avoid silent message drop (#14517)
## Summary

`Whatsapp::IncomingMessageBaseService#attach_location` builds a
`fallback_title` by concatenating `location['name']` and
`location['address']` with no length cap, then stores it directly into
`Attachment#fallback_title`. `ApplicationRecord` enforces a generic
255-character limit on string columns, so any WhatsApp location whose
`"#{name}, #{address}"` exceeds 255 chars (a common case for Google
Places that include a long full address) raises
`ActiveRecord::RecordInvalid` deep inside the Sidekiq job. The message
and attachment INSERTs are part of the same transaction, so the whole
thing rolls back. Sidekiq retries once; the retry dedup-skips the wamid
silently and exits without an error. **Result: the message is
irrecoverably lost — no row in `messages`, no entry in the UI, no
outgoing webhook, no clue for the operator.**

Confirmed in `v4.13.0`, `v4.14.0`, and `develop` (commit `f33e469`,
2026-05-20). No upstream issue found before opening this PR.

## How to reproduce

1. From WhatsApp, share a Google Place whose `name + ", " + address` is
> 255 chars. The Spanish business address `Gremi de Fusters, 33,
Edificio VIP Asima, Piso 2, Local 2, Norte, 07009 Polígon industrial de
Son Castelló, Illes Balears, España` (132 chars) used as both `name` and
`address` is enough.
2. Sidekiq logs:
   ```
   ERROR ActiveRecord::RecordInvalid: Validation failed:
   Attachments fallback title is too long (maximum is 255 characters)
   ```
3. The `messages` table has no row. The conversation UI shows nothing
for that timestamp.
4. The first retry "Performed" successfully but creates nothing — the
dedup-by-source-id silently swallows the failure.

## Fix

Cap the existing concatenated title at 255 chars via `.first(255)`.
Minimal change, no behavioural difference for any message shorter than
the limit, prevents the silent data loss for any longer ones.

```diff
-    location_name = location['name'] ? "#{location['name']}, #{location['address']}" : ''
+    location_name = (location['name'] ? "#{location['name']}, #{location['address']}" : '').first(255)
```

## Alternatives considered

- **Increase the validation limit on `Attachment#fallback_title`**: more
invasive; would touch other inbound channels and possibly require a DB
column change.
- **Use `name` alone (no concat)**: cleaner semantically (in many real
payloads `name == address`), but changes user-visible behaviour. Left as
a follow-up if desired.
- **Truncate with ellipsis**: cosmetic only; deferred.

This PR is intentionally minimal so it can be merged on its own.

---------

Co-authored-by: Sony Mathew <sony@chatwoot.com>
Co-authored-by: Sony Mathew <2040199+sony-mathew@users.noreply.github.com>
2026-06-03 12:50:21 +05:30
..
phone_normalizers fix: Duplicate contacts creating for Argentina numbers (#11173) 2025-10-13 11:07:07 +05:30
providers feat(whatsapp): Add support for voice messages (#14606) 2026-06-02 15:33:32 +04:00
channel_creation_service.rb fix: Remove the same account validation for whatsapp channels (#12811) 2025-11-06 21:18:52 +05:30
csat_template_service.rb feat(csat): Add WhatsApp utility template analyzer with rewrite guidance (#13575) 2026-02-24 15:11:04 +04:00
embedded_signup_service.rb fix(whatsapp): skip health check during reauthorization flow (#13911) 2026-03-26 15:00:09 +05:30
facebook_api_client.rb feat(voice): WhatsApp Cloud Calling — UI [6] (#14346) 2026-05-22 18:42:39 +05:30
health_service.rb feat(whatsapp): add webhook registration and status endpoints (#13551) 2026-03-16 12:48:16 +05:30
identifier_sync_service.rb feat: Store WhatsApp BSUID identifiers from inbound webhooks (#14436) 2026-05-20 13:36:43 +04:00
incoming_message_base_service.rb fix(whatsapp): truncate location fallback_title to 255 chars to avoid silent message drop (#14517) 2026-06-03 12:50:21 +05:30
incoming_message_identifier_helper.rb feat: Store WhatsApp BSUID identifiers from inbound webhooks (#14436) 2026-05-20 13:36:43 +04:00
incoming_message_service_helpers.rb fix(whatsapp): store and surface unavailable coexistence messages (CW-7166) (#14547) 2026-05-25 18:13:59 +05:30
incoming_message_service.rb feat: Support for Whatsapp Cloud API (#4938) 2022-07-06 21:45:03 +02:00
incoming_message_whatsapp_cloud_service.rb fix: Remove phone_number_id param from WhatsApp media retrieval for incoming messages (#13319) 2026-01-20 20:32:23 +04:00
liquid_template_processor_service.rb feat(campaigns): Add variable support to WhatsApp campaigns (#13649) 2026-04-28 21:57:30 +04:00
message_dedup_lock.rb fix: duplicate message_created webhooks for WhatsApp messages (#13523) 2026-02-17 14:01:10 +05:30
oneoff_campaign_service.rb feat: show processing status for one-off campaigns (#14592) 2026-06-01 16:47:17 +05:30
phone_info_service.rb feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
phone_number_normalization_service.rb fix: Extend phone number normalization to Twilio WhatsApp (#12655) 2025-10-28 18:16:29 +05:30
populate_template_parameters_service.rb fix: Normalize URLs with spaces in WhatsApp template parameters (#12594) 2025-10-08 15:33:06 +05:30
reauthorization_service.rb feat: add reauth flow for wa embedded signup (#11940) 2025-08-08 01:48:45 +05:30
send_on_whatsapp_service.rb fix: Improve WhatsApp template message error handling (#12168) 2025-08-12 16:31:56 +05:30
template_parameter_converter_service.rb fix: Handle nil processed_params for WhatsApp templates without params (#12177) 2025-08-12 22:56:53 +05:30
template_processor_service.rb fix: Case-insensitive language matching for WhatsApp template messages (#13269) 2026-01-14 17:33:02 +04:00
token_exchange_service.rb feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
token_validation_service.rb feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
webhook_setup_service.rb feat(voice): WhatsApp Cloud Calling — UI [6] (#14346) 2026-05-22 18:42:39 +05:30
webhook_teardown_service.rb feat: Remove subscription on WhatsApp inbox delete (#11977) 2025-07-24 14:04:19 +04:00