Hertz::Twilio
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:
$ bundleOr install it yourself as:
$ gem install hertz-twilioThen, run the installer generator:
$ rails g hertz:twilio:installThe 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
endIf #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
endUsage
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
endAll 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