Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Profile pictures missing in facebook inbox [CW-1976] #9212

Merged
merged 3 commits into from May 9, 2024

Conversation

imtoanle
Copy link
Contributor

@imtoanle imtoanle commented Apr 8, 2024

Pull Request Template

Description

Related to #6138 #6761

I found an issue here, as detailed in the logs below. The ActiveJob FacebookEventsJob created a Contact and then enqueued Avatar::AvatarFromUrlJob in another process. However, since the Contact was created within a transaction, when AvatarFromUrlJob was executed immediately afterward, the Contact was not actually present in the database at that time. My workaround was simply to wait for FacebookEventsJob to finish first.

I, [2024-04-08T22:54:51.825149 #1]  INFO -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d] Performing Webhooks::FacebookEventsJob (Job ID: 34b46017-28c8-4ee5-a210-c93ce096670d) from Sidekiq(default) enqueued at 2024-04-08T22:54:51Z with arguments: "{\"messaging\":{\"sender\":{\"id\":\"5689791144460501\"},\"recipient\":{\"id\":\"122425870844291\"},\"timestamp\":1712616890157,\"message\":{\"mid\":\"m_8ZYdcXx18XkVOXw2i8goB1pNBpkaQa8fOnE5pJRnCmPczNL9tljhclCTvZr99Pb9pePOJNHMYFsxbauB9ATvXg\",\"text\":\"chào bạn\",\"nlp\":{\"intents\":[],\"entities\":{},\"traits\":{\"wit$sentiment\":[{\"id\":\"5ac2b50a-44e4-466e-9d49-bad6bd40092c\",\"value\":\"positive\",\"confidence\":0.7825}]},\"detected_locales\":[{\"locale\":\"vi_VN\",\"confidence\":0.9998}]}}}}"
I, [2024-04-08T22:54:51.827408 #1]  INFO -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d] [Webhooks::FacebookEventsJob] Acquired lock for: FB_MESSAGE_CREATE_LOCK::5689791144460501::122425870844291 on attempt 1
D, [2024-04-08T22:54:51.831960 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Channel::FacebookPage Load (0.4ms)  SELECT "channel_facebook_pages".* FROM "channel_facebook_pages" WHERE "channel_facebook_pages"."page_id" = $1  [["page_id", "122425870844291"]]
D, [2024-04-08T22:54:51.840695 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Inbox Load (0.8ms)  SELECT "inboxes".* FROM "inboxes" WHERE "inboxes"."channel_id" = $1 AND "inboxes"."channel_type" = $2 LIMIT $3  [["channel_id", 3], ["channel_type", "Channel::FacebookPage"], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.332981 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   TRANSACTION (0.3ms)  BEGIN
D, [2024-04-08T22:54:52.334358 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   ContactInbox Load (0.7ms)  SELECT "contact_inboxes".* FROM "contact_inboxes" WHERE "contact_inboxes"."inbox_id" = $1 AND "contact_inboxes"."source_id" = $2 LIMIT $3  [["inbox_id", 3], ["source_id", "5689791144460501"], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.335211 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   TRANSACTION (0.2ms)  SAVEPOINT active_record_1
D, [2024-04-08T22:54:52.340333 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Account Load (0.4ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT $2  [["id", 2], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.361664 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Contact Create (1.4ms)  INSERT INTO "contacts" ("name", "email", "phone_number", "account_id", "created_at", "updated_at", "additional_attributes", "identifier", "custom_attributes", "last_activity_at", "contact_type", "middle_name", "last_name", "location", "country_code", "blocked") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) RETURNING "id"  [["name", "Toàn Lê"], ["email", nil], ["phone_number", nil], ["account_id", 2], ["created_at", "2024-04-08 22:54:52.356831"], ["updated_at", "2024-04-08 22:54:52.356831"], ["additional_attributes", "{}"], ["identifier", nil], ["custom_attributes", "{}"], ["last_activity_at", nil], ["contact_type", 0], ["middle_name", ""], ["last_name", ""], ["location", nil], ["country_code", nil], ["blocked", false]]
D, [2024-04-08T22:54:52.366669 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   ActsAsTaggableOn::Tagging Load (0.7ms)  SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2  [["taggable_id", 21], ["taggable_type", "Contact"]]
D, [2024-04-08T22:54:52.369760 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   ContactInbox Load (0.5ms)  SELECT "contact_inboxes".* FROM "contact_inboxes" WHERE "contact_inboxes"."contact_id" = $1 AND "contact_inboxes"."inbox_id" = $2 AND "contact_inboxes"."source_id" = $3 LIMIT $4  [["contact_id", 21], ["inbox_id", 3], ["source_id", "5689791144460501"], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.374249 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Inbox Load (0.4ms)  SELECT "inboxes".* FROM "inboxes" WHERE "inboxes"."id" = $1 LIMIT $2  [["id", 3], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.377409 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Contact Load (0.6ms)  SELECT "contacts".* FROM "contacts" WHERE "contacts"."id" = $1 LIMIT $2  [["id", 21], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.380836 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   ContactInbox Create (0.5ms)  INSERT INTO "contact_inboxes" ("contact_id", "inbox_id", "source_id", "created_at", "updated_at", "hmac_verified", "pubsub_token") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["contact_id", 21], ["inbox_id", 3], ["source_id", "5689791144460501"], ["created_at", "2024-04-08 22:54:52.377831"], ["updated_at", "2024-04-08 22:54:52.377831"], ["hmac_verified", false], ["pubsub_token", "ovywfxCw2PpW5etfEaqYKmTy"]]
I, [2024-04-08T22:54:52.384745 #1]  INFO -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d] Enqueued Avatar::AvatarFromUrlJob (Job ID: 6a21a4de-f8ec-4d8d-b2a0-60ecfa8ea57a) to Sidekiq(low) at 2024-04-08 22:55:52 UTC with arguments: #<GlobalID:0x00007f478d48e370 @uri=#<URI::GID gid://chatwoot/Contact/21>>, "https://platform-lookaside.fbsbx.com/platform/profilepic/?eai=AXGMUfE6E2Ugsv4PlJmbqH_xKu86djIewD2P8bngOug_LaMR0u8-1sBkLGJsrt85nvI_CGITO9c2&psid=5689791144460501&width=1024&ext=1715208892&hash=AfrhXVAflxC-Asrf656Rzq_5JuyF9hqEPPOlxLNR-ArrCQ"
D, [2024-04-08T22:54:52.385350 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   TRANSACTION (0.4ms)  RELEASE SAVEPOINT active_record_1
D, [2024-04-08T22:54:52.386962 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Conversation Load (0.5ms)  SELECT "conversations".* FROM "conversations" WHERE "conversations"."account_id" = $1 AND "conversations"."inbox_id" = $2 AND "conversations"."contact_id" = $3 LIMIT $4  [["account_id", 2], ["inbox_id", 3], ["contact_id", 21], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.392617 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Conversation Exists? (0.4ms)  SELECT 1 AS one FROM "conversations" WHERE "conversations"."uuid" IS NULL LIMIT $1  [["LIMIT", 1]]
D, [2024-04-08T22:54:52.440624 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Account Load (0.4ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT $2  [["id", 2], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.443714 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Inbox Load (0.6ms)  SELECT "inboxes".* FROM "inboxes" WHERE "inboxes"."id" = $1 LIMIT $2  [["id", 3], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.446768 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Contact Load (0.4ms)  SELECT "contacts".* FROM "contacts" WHERE "contacts"."id" = $1 LIMIT $2  [["id", 21], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.450952 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   ContactInbox Load (0.3ms)  SELECT "contact_inboxes".* FROM "contact_inboxes" WHERE "contact_inboxes"."id" = $1 LIMIT $2  [["id", 19], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.463039 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   AgentBotInbox Load (0.7ms)  SELECT "agent_bot_inboxes".* FROM "agent_bot_inboxes" WHERE "agent_bot_inboxes"."inbox_id" = $1 LIMIT $2  [["inbox_id", 3], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.481228 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Conversation Create (2.4ms)  INSERT INTO "conversations" ("account_id", "inbox_id", "status", "assignee_id", "created_at", "updated_at", "contact_id", "display_id", "contact_last_seen_at", "agent_last_seen_at", "additional_attributes", "contact_inbox_id", "identifier", "team_id", "campaign_id", "snoozed_until", "custom_attributes", "assignee_last_seen_at", "first_reply_created_at", "priority", "sla_policy_id", "waiting_since", "cached_label_list") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23) RETURNING "id"  [["account_id", 2], ["inbox_id", 3], ["status", 2], ["assignee_id", nil], ["created_at", "2024-04-08 22:54:52.452979"], ["updated_at", "2024-04-08 22:54:52.452979"], ["contact_id", 21], ["display_id", nil], ["contact_last_seen_at", nil], ["agent_last_seen_at", nil], ["additional_attributes", "{}"], ["contact_inbox_id", 19], ["identifier", nil], ["team_id", nil], ["campaign_id", nil], ["snoozed_until", nil], ["custom_attributes", "{}"], ["assignee_last_seen_at", nil], ["first_reply_created_at", nil], ["priority", nil], ["sla_policy_id", nil], ["waiting_since", "2024-04-08 22:54:52.452979"], ["cached_label_list", nil]]
D, [2024-04-08T22:54:52.484295 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   ActsAsTaggableOn::Tagging Load (0.4ms)  SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2  [["taggable_id", 19], ["taggable_type", "Conversation"]]
D, [2024-04-08T22:54:52.492504 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Account Load (0.4ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT $2  [["id", 2], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.493947 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Inbox Load (0.4ms)  SELECT "inboxes".* FROM "inboxes" WHERE "inboxes"."id" = $1 LIMIT $2  [["id", 3], ["LIMIT", 1]]
D, [2024-04-08T22:54:52.540759 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Message Create (0.7ms)  INSERT INTO "messages" ("content", "account_id", "inbox_id", "conversation_id", "message_type", "created_at", "updated_at", "private", "status", "source_id", "content_type", "content_attributes", "sender_type", "sender_id", "external_source_ids", "additional_attributes", "processed_message_content", "sentiment") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) RETURNING "id"  [["content", "chào bạn"], ["account_id", 2], ["inbox_id", 3], ["conversation_id", 19], ["message_type", 0], ["created_at", "2024-04-08 22:54:52.495268"], ["updated_at", "2024-04-08 22:54:52.495268"], ["private", false], ["status", 0], ["source_id", "m_8ZYdcXx18XkVOXw2i8goB1pNBpkaQa8fOnE5pJRnCmPczNL9tljhclCTvZr99Pb9pePOJNHMYFsxbauB9ATvXg"], ["content_type", 0], ["content_attributes", "\"{\\\"in_reply_to_external_id\\\":null}\""], ["sender_type", "Contact"], ["sender_id", 21], ["external_source_ids", nil], ["additional_attributes", "{}"], ["processed_message_content", "chào bạn"], ["sentiment", "{}"]]
D, [2024-04-08T22:54:52.544201 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   Conversation Update (0.6ms)  UPDATE "conversations" SET "updated_at" = $1 WHERE "conversations"."id" = $2  [["updated_at", "2024-04-08 22:54:52.542963"], ["id", 19]]
D, [2024-04-08T22:54:52.547474 #1] DEBUG -- : [ActiveJob] [Webhooks::FacebookEventsJob] [34b46017-28c8-4ee5-a210-c93ce096670d]   TRANSACTION (3.1ms)  COMMIT

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@imtoanle imtoanle changed the title [CW-1976] Facebook inbox not grabbing Facebook profile pictures fix: [CW-1976] Facebook inbox not grabbing Facebook profile pictures Apr 8, 2024
@sojan-official
Copy link
Member

@imtoanle Thanks for spotting this. Made some slight tweaks to the PR. We will tested and get this merged.

@sojan-official sojan-official changed the title fix: [CW-1976] Facebook inbox not grabbing Facebook profile pictures fix: Profile pictures missing in facebook inbox [CW-1976] May 9, 2024
@sojan-official sojan-official merged commit 4eec0aa into chatwoot:develop May 9, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants