Class: InstagramConnect::SyncConversationsJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/instagram_connect/sync_conversations_job.rb

Overview

Pulls the threads that already exist on the account.

Webhooks only ever announce NEW activity, so a freshly connected account shows an empty inbox until somebody happens to message in — even though the operator has years of conversations sitting in Instagram. This fetches what Meta will give us: every thread, and the 20 most recent messages in each, which is the entire history the API exposes to any app.

Safe to re-run. Threads are located by igsid and messages are deduped on ig_message_id, so a second pass updates rather than duplicates.

Instance Method Summary collapse

Instance Method Details

#perform(account_id) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'app/jobs/instagram_connect/sync_conversations_job.rb', line 15

def perform()
   = Account.find_by(id: )
  return if .nil? || !.active?

  threads = .client.list_conversations
  return unless threads.success?

  Array(threads.data["data"]).each { |thread| sync_thread(, thread["id"]) }
end