Chatwoot/lib/integrations/facebook/message_creator.rb
Sojan Jose 04dfb034cc
chore: Upgrade Exception tracking (#4638)
- Upgrade Sentry Libraries
- Enable provision for account and user info in error tracking
- Add ChatwootExceptionTracker

fixes: #4375
2022-05-09 14:23:19 +05:30

44 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class Integrations::Facebook::MessageCreator
attr_reader :response
def initialize(response)
@response = response
end
def perform
# begin
if agent_message_via_echo?
create_agent_message
else
create_contact_message
end
# rescue => e
# ChatwootExceptionTracker.new(e).capture_exception
# end
end
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
end
def create_agent_message
Channel::FacebookPage.where(page_id: response.sender_id).each do |page|
mb = Messages::Facebook::MessageBuilder.new(response, page.inbox, outgoing_echo: true)
mb.perform
end
end
def create_contact_message
Channel::FacebookPage.where(page_id: response.recipient_id).each do |page|
mb = Messages::Facebook::MessageBuilder.new(response, page.inbox)
mb.perform
end
end
end