-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_on_twilio_service.rb
44 lines (35 loc) · 1.06 KB
/
send_on_twilio_service.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# source: https://raw.githubusercontent.com/chatwoot/chatwoot/afe31a3156d730955b732fc0c2fdfa5bea040fd4/app/services/twilio/send_on_twilio_service.rb
# docker cp send_on_twilio_service.rb rasachatbot-sidekiq-1:/app/app/services/twilio/send_on_twilio_service.rb
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