2020-06-25 18:05:16 +00:00
|
|
|
class Twilio::SendOnTwilioService < Base::SendOnChannelService
|
|
|
|
private
|
2020-04-05 16:41:27 +00:00
|
|
|
|
2020-06-25 18:05:16 +00:00
|
|
|
def channel_class
|
|
|
|
Channel::TwilioSms
|
|
|
|
end
|
2020-04-05 16:41:27 +00:00
|
|
|
|
2020-06-25 18:05:16 +00:00
|
|
|
def perform_reply
|
2021-09-06 18:35:14 +00:00
|
|
|
begin
|
2022-07-08 12:50:07 +00:00
|
|
|
twilio_message = channel.send_message(**message_params)
|
2021-09-06 18:35:14 +00:00
|
|
|
rescue Twilio::REST::TwilioError => e
|
2022-05-09 08:53:19 +00:00
|
|
|
ChatwootExceptionTracker.new(e, user: message.sender, account: message.account).capture_exception
|
2021-09-06 18:35:14 +00:00
|
|
|
end
|
2021-09-21 17:32:45 +00:00
|
|
|
message.update!(source_id: twilio_message.sid) if twilio_message
|
2020-04-05 16:41:27 +00:00
|
|
|
end
|
|
|
|
|
2020-04-29 20:11:13 +00:00
|
|
|
def message_params
|
2022-07-08 12:50:07 +00:00
|
|
|
{
|
2020-04-29 20:11:13 +00:00
|
|
|
body: message.content,
|
2022-07-08 12:50:07 +00:00
|
|
|
to: contact_inbox.source_id,
|
|
|
|
media_url: attachments
|
2020-04-29 20:11:13 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
2022-04-20 17:12:13 +00:00
|
|
|
message.attachments.map(&:download_url)
|
2020-04-29 20:11:13 +00:00
|
|
|
end
|
2020-04-05 16:41:27 +00:00
|
|
|
|
|
|
|
def inbox
|
|
|
|
@inbox ||= message.inbox
|
|
|
|
end
|
|
|
|
|
|
|
|
def channel
|
|
|
|
@channel ||= inbox.channel
|
|
|
|
end
|
|
|
|
|
2020-06-09 18:24:35 +00:00
|
|
|
def outgoing_message?
|
|
|
|
message.outgoing? || message.template?
|
|
|
|
end
|
2020-04-05 16:41:27 +00:00
|
|
|
end
|