2019-10-16 06:52:30 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
module Integrations
|
|
|
|
module Facebook
|
|
|
|
class MessageParser
|
|
|
|
def initialize(response_json)
|
|
|
|
@response = response_json
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def sender_id
|
|
|
|
@response.sender['id']
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def recipient_id
|
|
|
|
@response.recipient['id']
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def time_stamp
|
|
|
|
@response.sent_at
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def content
|
|
|
|
@response.text
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def sequence
|
|
|
|
@response.seq
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def attachments
|
|
|
|
@response.attachments
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def identifier
|
|
|
|
@response.id
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def echo?
|
|
|
|
@response.echo?
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def app_id
|
|
|
|
@response.app_id
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-20 19:10:18 +00:00
|
|
|
def sent_from_chatwoot_app?
|
2019-11-23 19:57:39 +00:00
|
|
|
app_id && app_id == ENV['FB_APP_ID'].to_i
|
2019-10-20 19:10:18 +00:00
|
|
|
end
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sample Reponse
|
|
|
|
# {
|
|
|
|
# "sender":{
|
|
|
|
# "id":"USER_ID"
|
|
|
|
# },
|
|
|
|
# "recipient":{
|
|
|
|
# "id":"PAGE_ID"
|
|
|
|
# },
|
|
|
|
# "timestamp":1458692752478,
|
|
|
|
# "message":{
|
|
|
|
# "mid":"mid.1457764197618:41d102a3e1ae206a38",
|
|
|
|
# "seq":73,
|
|
|
|
# "text":"hello, world!",
|
|
|
|
# "quick_reply": {
|
|
|
|
# "payload": "DEVELOPER_DEFINED_PAYLOAD"
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|