Class: MessageSmsNotification

Inherits:
Object
  • Object
show all
Defined in:
app/models/message_sms_notification.rb

Overview

SMS notification service for Messages and Notifications sent to Participants.

Constant Summary collapse

BLACKLIST_MESSAGE =
"The message From/To pair violates a blacklist rule."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, phone_number:) ⇒ MessageSmsNotification

Returns a new instance of MessageSmsNotification.



8
9
10
11
# File 'app/models/message_sms_notification.rb', line 8

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'app/models/message_sms_notification.rb', line 4

def body
  @body
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



4
5
6
# File 'app/models/message_sms_notification.rb', line 4

def phone_number
  @phone_number
end

Instance Method Details

#deliverObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/message_sms_notification.rb', line 13

def deliver
  if environment.staging? || environment.production?
    sms_client..messages.create message
  else
    message
  end
rescue Twilio::REST::RequestError => e
  if e.message == BLACKLIST_MESSAGE
    record_delivery_error!(e.message)
  else
    capture_message(e.message)
  end
end