Sha256: 3a8a7d8cb886ceab173ee204c336db886df129fb45b012ef1050f751c78cc696

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
# SMS notification service for Messages and Notifications sent to Participants.
class MessageSmsNotification
  attr_reader :body, :phone_number

  def initialize(body:, phone_number:)
    @body = body
    @phone_number = phone_number
  end

  def deliver
    if environment.staging? || environment.production?
      sms_client.account.messages.create message
    else
      message
    end
  end

  private

  def config
    Rails.application.config
  end

  def environment
    Rails.env
  end

  def status_callback_url
    config.try(:status_callback_url)
  end

  def from_telephone_number
    config.try(:twilio_account_telephone_number)
  end

  def message
    params = {
      to: "+1#{phone_number}",
      from: from_telephone_number,
      body: body
    }

    params[:status_callback] = status_callback_url if status_callback_url

    params
  end

  def sms_client
    @sms_client ||= Twilio::REST::Client.new(
      config.twilio_account_sid,
      config.twilio_auth_token
    )
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
think_feel_do_engine-3.21.2 app/models/message_sms_notification.rb
think_feel_do_engine-3.21.1 app/models/message_sms_notification.rb