feat: Add support for Instagram delivery reports (#8125)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
28
app/services/instagram/read_status_service.rb
Normal file
28
app/services/instagram/read_status_service.rb
Normal 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
|
||||
Reference in New Issue
Block a user