Send text (SMS) messages via the HTTP API of CM Telecom from your Ruby app.
For Rails integration, please see: https://github.com/HitFox/cm-sms-rails.
Create a class that is inherited from CmSms::Messenger.
class TextMessageNotifier < CmSms::Messenger
endNow you can add methods to send messages. For example, send a welcome message with:
class TextMessageNotifier < CmSms::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
endUse the public class method default to set default values that will be used in every method of your CmSms::Messenger subclass.
This method accepts a Hash as the parameter with possible keys :from, :to and :body. You may override these defaults inside
the methods themselves.
Example:
class TextMessageNotifier < CmSms::Messenger
default from: 'Quentin', '00491710000000'
...
endTo send your SMS, call the desired method and then call deliver_now on the return value.
Calling the method returns a CmSms::Message object:
message = TextMessageNotifier.new.welcome(User.first) # => Returns a CmSms::Message object
message.deliver_nowCm-Sms will look for the presence of either Phony or Phonelib and use one of these libraries to perform a basic check of receiver number. This check does not consider whether the number is a mobile number.
If you user bundler, then just add
$ gem 'cm-sms'to your Gemfile and execute
$ bundle install
or without bundler
$ gem install cms-sms
$ bundle update cms-sms
or without bundler
$ gem update cms-sms
Bug reports and pull requests are welcome on GitHub at https://github.com/HitFox/cm-sms. 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.
The gem is available as open source under the terms of the MIT License.
