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
|
2020-04-29 20:11:13 +00:00
|
|
|
twilio_message = client.messages.create(message_params)
|
2020-04-05 16:41:27 +00:00
|
|
|
message.update!(source_id: twilio_message.sid)
|
|
|
|
end
|
|
|
|
|
2020-04-29 20:11:13 +00:00
|
|
|
def message_params
|
|
|
|
params = {
|
|
|
|
body: message.content,
|
|
|
|
from: channel.phone_number,
|
|
|
|
to: contact_inbox.source_id
|
|
|
|
}
|
|
|
|
params[:media_url] = attachments if channel.whatsapp? && message.attachments.present?
|
|
|
|
params
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
message.attachments.map(&:file_url)
|
|
|
|
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
|
|
|
def client
|
|
|
|
::Twilio::REST::Client.new(channel.account_sid, channel.auth_token)
|
|
|
|
end
|
|
|
|
end
|