action-texter
Description
Send text messages by means of the HTTP protocol with the service of https://www.messagebird.com, from your ruby app.
Usage
Configuration
Use ActionTexter.configure
to set product_token
, endpoint
and path
ActionTexter.configure do |config|
config.product_token = 'YOUR_MESSAGEBIRD_API_TOKEN'
config.endpoint = 'https://rest.messagebird.com' # Messagebird default
config.path = '/messages' # Messagebird default
end
Create a class that is inherited from ActionTexter::Messenger
.
class TextMessageNotifier < ActionTexter::Messenger
end
Now you can add your first welcome message. This can be as simple as:
class TextMessageNotifier < ActionTexter::Messenger
default from: 'some string or mobile number'
def welcome(recipient)
@recipient = recipient
content(to: recipient.mobile_number, body: 'Some text, reference: recipient.id)
end
end
Setting defaults
It is possible to set default values that will be used in every method in your ActionTexter Messenger class. To implement this functionality, you just call the public class method default which is inherited from ActionTexter::Messenger. This method accepts a Hash as the parameter. You can use :from, :to and :body as the key.
Note that every value you set with this method will get overwritten if you use the same key in your mailer method.
Example:
class TextMessageNotifier < ActionTexter::Messenger
default from: "Quentin", "00491710000000"
.....
end
Deliver messages
In order to send your sms, you simply call the method and then call deliver_now
on the return value.
Calling the method returns a ActionTexter Message object:
= TextMessageNotifier.welcome(User.first) # => Returns a ActionTexter::Message object
.deliver_now
Installation
If you user bundler, then just add
$ gem 'action-texter'
to your Gemfile and execute
$ bundle install
or without bundler
$ gem install action-texter
Upgrade
$ bundle update action-texter
or without bundler
$ gem update action-texter
Changelog
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/HitFox/action-texter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.