iachat/spec
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 fix: Disable enqueueing Avatar jobs if the URL is invalid (#12035) 2025-07-24 12:56:39 +04:00
assets feat: Move email attachments from links to file attachments (#11304) 2025-04-15 23:43:12 -07:00
builders Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
channels fix: Move contact events to account stream rather than individual user stream (#11082) 2025-03-13 17:46:48 -07:00
config feat: move embedding config to a yaml file (#11611) 2025-05-30 16:26:40 +05:30
configs chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
controllers Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
dispatchers Non blocking event dispatch (#652) 2020-03-29 19:18:30 +05:30
drops feat: Add the support for custom attributes in message variables (#8511) 2023-12-08 14:13:35 -08:00
enterprise Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
factories Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
finders Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
fixtures chore: Add a condition to handle bounced email (#11873) 2025-08-01 14:43:46 +05:30
helpers Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
integration Fix url in emails, add frontendURL helper (#19) 2019-08-25 19:59:28 +05:30
jobs Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
lib 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 Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
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 feat: Add conversation delete feature (#11677) 2025-06-05 15:53:17 -05:00
presenters fix: Disable automations on auto-reply emails (#12101) 2025-08-05 13:17:06 +05:30
requests/api/v1 chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00
services feat(whatsapp): get contact profile picture when using Baileys service (#98) 2025-08-27 13:02:04 -03:00
support fix: resolve mutex conflicts in Instagram webhook specs (#12154) 2025-08-11 23:31:25 +05:30
workers fix: Capture delivery errors to avoid false positives (#8790) 2024-01-26 14:22:18 +04:00
rails_helper.rb fix: resolve mutex conflicts in Instagram webhook specs (#12154) 2025-08-11 23:31:25 +05:30
spec_helper.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
test_helper.rb Chore: Setup test coverage in codeclimate [#332] (#333) 2019-12-02 08:57:11 +05:30