Chatwoot/app/services/twilio/send_on_twilio_service.rb
Jordan Brough 49d08a6773
feat: Support Twilio Messaging Services (#4242)
This allows sending and receiving from multiple phone numbers using Twilio messaging services

Fixes: #4204
2022-07-08 18:20:07 +05:30

40 lines
825 B
Ruby

class Twilio::SendOnTwilioService < Base::SendOnChannelService
private
def channel_class
Channel::TwilioSms
end
def perform_reply
begin
twilio_message = channel.send_message(**message_params)
rescue Twilio::REST::TwilioError => e
ChatwootExceptionTracker.new(e, user: message.sender, account: message.account).capture_exception
end
message.update!(source_id: twilio_message.sid) if twilio_message
end
def message_params
{
body: message.content,
to: contact_inbox.source_id,
media_url: attachments
}
end
def attachments
message.attachments.map(&:download_url)
end
def inbox
@inbox ||= message.inbox
end
def channel
@channel ||= inbox.channel
end
def outgoing_message?
message.outgoing? || message.template?
end
end