A ruby gem for using the Msg91 REST API
Installation
Add this line to your application's Gemfile:
gem 'msg91sms'
And then execute:
$ bundle
Or install it yourself as:
$ gem install msg91sms
In the initialiser add authkey:
You can find your authkey here https://control.msg91.com/user/index.php#api
Msg91sms.configure do |config|
config.authkey = "Put your msg94 authkey here"
end
Usage
Transactional sms
Msg91sms::TransactionalSms.deliver(sender, country_code, mobile, message)
sender: 6 digit sender name eg:"PTSHOP"
country_code: country code without + or zeros EG: "91"
for india
mobile: mobile number without starting zeros or country code eg: "7234567891"
message: message, eg: "hi"
Example
#returns response in json format
response=Msg91sms::TransactionalSms.deliver("RDTEST", "91", "7234567891", "message")
#success response
#if type=='success' message will contain just an id from msg91
{"message"=>"37666d6d4b4a364443303836", "type"=>"success"}
#error response
#if type=='error' message will contain the reason for error
{"message":"Please Enter Valid Sender ID","type":"error"}
Otp
- Otp Generation
Msg91sms::OtpSms.generate(sender, country_code, mobile, message, otp)
or if want to autogenerate otp
Msg91sms::OtpSms.generate(sender, country_code, mobile)
sender: 6 digit sender name eg:"PTSHOP"
country_code: country code without + or zeros EG: "91"
for india
mobile: mobile number without starting zeros or country code eg: "7234567891"
message: message, eg: "2277 is your otp for this transaction"
(optional)
otp: otp code, eg: "2277"
(optional)
Example
#returns response in json format
response=Msg91sms::OtpSms.generate("RDTEST", "91", "7234567891", "Your otp is 2222", "2222")
#success response
#if type=='success' message will contain just an id from msg91
{"message"=>"37666d6d4b4a364443303836", "type"=>"success"}
#error response
#if type=='error' message will contain the reason for error
{"message":"Please Enter Valid Sender ID","type":"error"}
Note: If no message and otp provided it will be autogenerated.
- Otp Verification
Msg91sms::OtpSms.verification(country_code, mobile, otp_to_verify)
country_code: country code without + or zeros EG: "91"
for india
mobile: mobile number without starting zeros or country code eg: "7234567891"
otp_to_verify: otp recieved from user for verifying, eg: "2277"
Example
#returns response in json format
response=Msg91sms::OtpSms.verification("91", "7234567891", "2222")
#success response
#if type=='success' message will contain just an id from msg91
{"message":"otp_verified","type":"success"}
#error response
#if type=='error' message will contain the reason for error
{"message":"otp_not_verified","type":"error"}
Development
We hope that you will consider contributing to Msg91sms. Please read this short overview for some information about how to get started:
-
provide tests and documentation whenever possible. It is very unlikely that we will accept new features or functionality into Msg91sms without the proper testing and documentation. When fixing a bug, provide a failing test case that your patch solves.
-
open a GitHub Pull Request with your patches and we will review your contribution and respond as quickly as possible. Keep in mind that this is an open source project, and it may take me some time to get back to you. Your patience is very much appreciated.
You will usually want to write tests for your changes. To run the test suite, go into top-level directory and run "bundle install" and "bundle exec rspec".
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/flyingboy007/msg91sms. 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.