Hertz::Twilio

Build Status Coverage Status Maintainability

This is a Hertz courier for sending notifications to your users via SMS by leveraging the Twilio API.

Installation

Add this line to your application's Gemfile:

gem 'hertz-twilio'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hertz-twilio

Then, run the installer generator:

$ rails g hertz:twilio:install

The courier will use ActiveJob to asynchronously deliver the text messages, so make sure that you're executing background jobs with some adapter (inline will work, even though it's not recommended). Jobs are pushed to the default queue.

Finally, you will have to expose a #hertz_phone_number method in your receiver class:

class User
  include Hertz::Notifiable

  def hertz_phone_number
    phone_number
  end
end

If #hertz_phone_number returns an empty value (i.e. false, nil or an empty string) at the time the job is executed, the notification will not be delivered. This allows you to programmatically enable/disable SMS notifications for a user:

class User
  include Hertz::Notifiable

  def hertz_phone_number
    phone_number if phone_number_verified?
  end
end

Usage

All you need to do in order to start delivering notifications by SMS is add twilio to the notification's #deliver_by statement and provide an SMS body:

class CommentNotification < Hertz::Notification
  deliver_by :twilio

  def sms_body
    'You received a new comment!'
  end
end

All CommentNotifications will now be delivered by SMS! :)

NOTE: This courier uses the deliveries API to prevent double deliveries.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/aldesantis/hertz-twilio.

License

The gem is available as open source under the terms of the MIT License.

To do

  • [ ] Allow changing the job's queue