Module: TwilioService

Extended by:
TwilioService
Included in:
TwilioService
Defined in:
lib/templates/twilio/twilio_service.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject



18
19
20
# File 'lib/templates/twilio/twilio_service.rb', line 18

def logger
  @logger ||= Rails.logger
end

#send_text_message(phone_to, message) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/templates/twilio/twilio_service.rb', line 4

def send_text_message(phone_to, message)
  client = Twilio::REST::Client.new
  client.messages.create(
    from: ENV['TWILIO_PHONE_FROM'],
    to: phone_to,
    body: message
  )
  @logger.info { "Sent SMS to #{phone_to}." }
rescue Twilio::REST::RequestError => err
  @logger.error do
    "ERROR in Twilio call for sending message to number #{phone_to}. Error: #{err.message}"
  end
end