feat: Add support for Instagram delivery reports (#8125)

This commit is contained in:
Muhsin Keloth
2023-10-19 12:12:34 +05:30
committed by GitHub
parent 04c874fe35
commit 78ce8a4652
6 changed files with 118 additions and 2 deletions

View File

@@ -231,7 +231,11 @@ export default {
return contactLastSeenAt >= this.createdAt;
}
if (this.isAWhatsAppChannel || this.isATwilioChannel) {
if (
this.isAWhatsAppChannel ||
this.isATwilioChannel ||
this.isAFacebookInbox
) {
return this.sourceId && this.isRead;
}

View File

@@ -7,7 +7,7 @@ class Webhooks::InstagramEventsJob < MutexApplicationJob
base_uri 'https://graph.facebook.com/v11.0/me'
# @return [Array] We will support further events like reaction or seen in future
SUPPORTED_EVENTS = [:message].freeze
SUPPORTED_EVENTS = [:message, :read].freeze
def perform(entries)
@entries = entries
@@ -45,6 +45,10 @@ class Webhooks::InstagramEventsJob < MutexApplicationJob
::Instagram::MessageText.new(messaging).perform
end
def read(messaging)
::Instagram::ReadStatusService.new(params: messaging).perform
end
def messages(entry)
(entry[:messaging].presence || entry[:standby] || [])
end

View File

@@ -0,0 +1,28 @@
class Instagram::ReadStatusService
pattr_initialize [:params!]
def perform
return if instagram_channel.blank?
process_status if message.present?
end
def process_status
@message.status = 'read'
@message.save!
end
def instagram_id
params[:recipient][:id]
end
def instagram_channel
@instagram_channel ||= Channel::FacebookPage.find_by(instagram_id: instagram_id)
end
def message
return unless params[:read][:mid]
@message ||= @instagram_channel.inbox.messages.find_by(source_id: params[:read][:mid])
end
end