chore: Move Facebook event processing to worker (#2988)

This commit is contained in:
Sojan Jose
2021-09-13 18:05:14 +05:30
committed by GitHub
parent 26a3150fd8
commit 328edd24de
7 changed files with 56 additions and 21 deletions

View File

@@ -22,6 +22,7 @@ class Integrations::Facebook::MessageCreator
private
def agent_message_via_echo?
# TODO : check and remove send_from_chatwoot_app if not working
response.echo? && !response.sent_from_chatwoot_app?
# this means that it is an agent message from page, but not sent from chatwoot.
# User can send from fb page directly on mobile / web messenger, so this case should be handled as agent message

View File

@@ -2,45 +2,47 @@
class Integrations::Facebook::MessageParser
def initialize(response_json)
@response = response_json
@response = JSON.parse(response_json)
end
def sender_id
@response.sender['id']
@response.dig 'messaging', 'sender', 'id'
end
def recipient_id
@response.recipient['id']
@response.dig 'messaging', 'recipient', 'id'
end
def time_stamp
@response.sent_at
@response.dig 'messaging', 'timestamp'
end
def content
@response.text
@response.dig 'messaging', 'message', 'text'
end
def sequence
@response.seq
@response.dig 'messaging', 'message', 'seq'
end
def attachments
@response.attachments
@response.dig 'messaging', 'message', 'attachments'
end
def identifier
@response.id
@response.dig 'messaging', 'message', 'mid'
end
def echo?
@response.echo?
@response.dig 'messaging', 'message', 'is_echo'
end
# TODO : i don't think the payload contains app_id. if not remove
def app_id
@response.app_id
@response.dig 'messaging', 'message', 'app_id'
end
# TODO : does this work ?
def sent_from_chatwoot_app?
app_id && app_id == ENV['FB_APP_ID'].to_i
end