chore: Move Facebook event processing to worker (#2988)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user