iachat/app
Gabriel Coelho d2a0d53fab
feat(whatsapp): get contact profile picture when using Baileys service (#98)
* feat(whatsapp): add profile picture fetching for Baileys provider

- Add `get_profile_pic` method to `WhatsappBaileysService` for fetching contact avatars
- Include `avatar_url` in contact attributes during contact creation
- Update `MessagesUpsert` handler to fetch and set profile pictures
- Add proper error handling and graceful degradation when avatar fetching fails

* test(whatsapp): add test coverage for Baileys profile picture fetching

- Add test suite for `get_profile_pic` method
- Include test scenarios for successful responses, missing avatars, and error handling
- Add profile picture HTTP stubbing and avatar job expectations to message processing tests

* feat(whatsapp): optimize Baileys avatar fetching and update avatar for existing inboxes

Previously, the profile picture was fetched on every incoming message and avatar updates were only attempted for new inboxes.

This change optimizes the process by:
- Only fetching the WhatsApp profile picture if the contact does not already have an avatar.
- Attempting to update the avatar for both new and existing inboxes.

This logic is based on Telegram's version (app/services/telegram/incoming_message_service.rb).

* refactor(whatsapp): remove unnecessary safe navigation when accessing contact

This reverts an unnecessary change introduced in b918a92.

* refactor(whatsapp): manually rollback change introduced in b918a92

* refactor(whatsapp): rename endpoint to profile-picture-url

* refactor(whatsapp): simplify profile picture response handling

Replaced manual JSON parsing with HTTParty's parsed_response and removed redundant JSON parsing tests.

* test(whatsapp): separate avatar processing test from message creation test

* test(whatsapp): update profile picture test to match actual API behavior

Change test to expect a 404 response when no profile picture exists, instead of a 200 response with partial data.

* refactor: move new functions to helper module

* test: more specs

---------

Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
2025-08-27 13:02:04 -03:00
..
actions Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
assets feat: Hide installation identifier (#11722) 2025-06-17 15:45:40 -07:00
builders Merge branch 'main' into chatwoot/develop 2025-07-16 09:37:08 -03:00
channels fix: Move contact events to account stream rather than individual user stream (#11082) 2025-03-13 17:46:48 -07:00
controllers Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
dashboards chore: improve plan-based feature handling with plan hierarchy (#11335) 2025-04-28 14:13:56 -07:00
dispatchers feat: toggle typing status on channel provider (#39) 2025-05-03 00:39:39 -03:00
drops feat: Add the support for custom attributes in message variables (#8511) 2023-12-08 14:13:35 -08:00
fields chore: improve plan-based feature handling with plan hierarchy (#11335) 2025-04-28 14:13:56 -07:00
finders perf: fix notifications duplicate query and add composite index (#12110) 2025-08-07 15:59:40 +05:30
helpers Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
javascript fix: enhance account switcher dropdown styling for better usability (#99) 2025-08-25 12:05:49 -03:00
jobs Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
listeners Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
mailboxes fix: Disable automations on auto-reply emails (#12101) 2025-08-05 13:17:06 +05:30
mailers Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
models fix: update notification setting to clear selected email flags (#100) 2025-08-25 18:11:29 -03:00
policies Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
presenters fix: Disable automations on auto-reply emails (#12101) 2025-08-05 13:17:06 +05:30
services feat(whatsapp): get contact profile picture when using Baileys service (#98) 2025-08-27 13:02:04 -03:00
views Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
workers feat: API Endpoints to update message status (#11387) 2025-04-29 15:33:11 -07:00