2019-10-16 06:52:30 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
class Integrations::Facebook::MessageParser
|
|
|
|
def initialize(response_json)
|
|
|
|
@response = response_json
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def sender_id
|
|
|
|
@response.sender['id']
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def recipient_id
|
|
|
|
@response.recipient['id']
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def time_stamp
|
|
|
|
@response.sent_at
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def content
|
|
|
|
@response.text
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def sequence
|
|
|
|
@response.seq
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def attachments
|
|
|
|
@response.attachments
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def identifier
|
|
|
|
@response.id
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def echo?
|
|
|
|
@response.echo?
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def app_id
|
|
|
|
@response.app_id
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def sent_from_chatwoot_app?
|
|
|
|
app_id && app_id == ENV['FB_APP_ID'].to_i
|
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"
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|