iachat/app/services
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
..
account fix: account email validation during signup (#11307) 2025-05-20 20:45:39 -07:00
auto_assignment chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00
automation_rules feat: Add private note action to automations (#11926) 2025-07-16 09:57:35 +05:30
base chore: Add cache to improve widget performance (#11163) 2025-03-24 16:04:49 -07:00
contacts fix: Add support for named parameter templates in WhatsApp (#11198) 2025-03-28 14:07:03 -07:00
conversations Merge branch 'main' into chore/merge-upstream 2025-05-30 11:03:07 -03:00
crm feat: save timezone from leadsquared API (#11583) 2025-05-28 09:46:59 +05:30
data_import chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00
email_templates chore: Fix emails being sent with the wrong translations (#2236) 2021-06-08 22:45:01 +05:30
facebook feat: hide CSAT survey URLs from agents in dashboard (#11622) 2025-06-11 23:39:47 +05:30
geocoder fix: ip-lookup database lazy loading for all environments (#8052) 2024-10-22 23:18:30 -07:00
google feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
imap feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
instagram fix: Creates contact when Instagram returns No matching Instagram user (#11496) 2025-07-28 13:49:13 +04:00
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 Merge branch 'main' into chatwoot/develop 2025-07-16 09:37:08 -03:00
linear feat: Add activity messages for linear actions (#11654) 2025-06-13 11:57:11 +05:30
liquid feat: Add liquid processing for SMS campaigns (#10981) 2025-06-11 13:16:44 -04:00
llm_formatter feat: captain should be able to access private notes (#11768) 2025-06-24 19:00:20 -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 feat: Add the ability to mention team in private message (#11758) 2025-07-02 19:57:59 +05:30
microsoft feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
notification chore: Handle WebPush rate limiting in push notification service (#12184) 2025-08-13 13:32:22 +05:30
sms fix: Error shouldn't halt the campaign for entire audience (#11980) 2025-08-11 12:03:48 +05:30
telegram feat(channel): add support for Telegram Business bots (#10181) (#11663) 2025-06-16 20:35:23 -07:00
twilio Merge branch 'main' into chore/merge-upstream-4.5.0 2025-08-20 11:20:31 -03:00
twitter feat: hide CSAT survey URLs from agents in dashboard (#11622) 2025-06-11 23:39:47 +05:30
whatsapp feat(whatsapp): get contact profile picture when using Baileys service (#98) 2025-08-27 13:02:04 -03:00
widget chore: Update method to access "secret_key_base" (#7337) 2023-06-19 16:11:19 +05:30
account_deletion_service.rb feat: automate account deletion (#11406) 2025-05-23 12:58:13 +05:30
action_service.rb Merge branch 'main' into chatwoot/develop 2025-07-16 09:37:08 -03:00
base_refresh_oauth_token_service.rb feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
csat_survey_service.rb fix: Send CSAT survey only when agent can reply in conversation (#11637) 2025-06-11 22:45:32 +05:30
filter_service.rb chore: Ability to filter conversations with priority (#10967) 2025-03-03 16:38:22 +05:30
ip_lookup_service.rb feat(poc): Disable widget based on country (#6658) 2023-03-14 09:09:57 -07:00
search_service.rb feat: skip inbox filter if the user has access to all inboxes (#12043) 2025-07-25 15:29:10 +05:30