Class: SmsNotification

Inherits:
Notification show all
Defined in:
lib/app/models/sms_notification.rb

Overview

SmsNotification is a concrete class of Notification, sending sms to both members and users, or in the case of eCommerce, customers.

This object allows you to create an SmsNotification object, set it's property and tell it send_notification. It'll handle everything from there including

  1. Running in the background thread
  2. Error recovery
  3. Retry on failure

The SMS object also uses the templating engine to allow the specification of a template and a set of local variables for dynamic content.

Usage:

sms = SmsNotification.new sms.to = '5713326267' sms.message = 'Day is today!' sms.send_notification

You are done! Go about your business of creating awesome software!

Constant Summary

Constants inherited from Notification

Notification::ALL_STATES, Notification::DELIVERY_EMAIL, Notification::DELIVERY_SLACK, Notification::DELIVERY_SMS, Notification::STATE_INVALID, Notification::STATE_NEW, Notification::STATE_PROCESSED, Notification::STATE_PROCESSING, Notification::STATE_RESUBMITTED, Notification::STATE_RETRYING, Notification::STATE_SUBMITTED, Notification::STATE_VIEWED

Instance Method Summary collapse

Methods inherited from Notification

#account_message_template, #default_message_template, #deletable?, #deliver_message, #finish_processing, #from_template, #message_from_haml_file, #message_from_haml_text, #message_from_liquid_text, #message_from_template, #render_liquid_text, #retry_delivery, #send_notification, #sendable?, #start_processing, #stringify_all, #successful?, #template_from_file, #viewed

Methods included from StandardModel

#clear_cache, included, #remove_blank_secure_fields, #secure_fields, #update, #update!

Methods included from App47Logger

#clean_params, #delete_parameter_keys, #log_controller_error, #log_debug, log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, #mask_parameter_keys, #update_flash_messages

Instance Method Details

#deliver_message! ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/app/models/sms_notification.rb', line 33

def deliver_message!
  return unless SystemConfiguration.twilio_configured?

  config = SystemConfiguration.configuration
   = config.
  auth_token = config.twilio_auth_token
  client = Twilio::REST::Client.new , auth_token

  message = client..messages.create(
    body: self.message,
    to: self.to,
    from: config.twilio_phone_number
  )
  # We are saved in the calling class, no reason to save again
  set sid: message.sid
end

#delivery_channel ⇒ Object

set the delivery channel for the templates



53
54
55
# File 'lib/app/models/sms_notification.rb', line 53

def delivery_channel
  DELIVERY_SMS
end