To start sending SMS with Ruby you need to do the following:
- Create a 46elks account
- Purchase some credits. (The minimum purchase is 10 EUR, which is more than enough to get started.)
- Locate your API-credentials
Write your code with Ruby
Finally, it's time to write some Ruby. Your code needs to be able to do the following:
- Define the content of the SMS, who will receive it and who is the sender
- Set your username and password
- Send all this information to 46elks by an HTTP POST to https://api.46elks.com/a1/SMS
- Receive the response and handle any errors that might occur
There are many ways to implement this in Ruby. This is an example of how it can be done using only the standard libraries:
The example is tested in Ruby 2.1.2
Use the Ruby example by creating a send.rb file and copy/paste the example code above to the file. Change the following variables to your own values:
usernameon row 3 (Your API-username).
passwordon row 4 (Your API-password).
toon row 11 (Your phone number).
- You can also change
messageon row 10 and 12, or leave it as it is.
Some tips on SMS parameter formatting:
The basic API request to send an SMS must contain these three key:value pairs: to, from and message.
toparameter should be the E.164 formatted number of the recipient.
messageparameter is the content of the SMS itself and can consist of numbers, letters, and other characters. You can even send emojis.
Exemple: How was this interview, 👌🏽 or 👎🏽 ?
Now, execute you script by using the command
ruby send.rband your phone will buzz. Congratulations, you've just sent an SMS from Ruby.
You've just sent a text message with a text sender (i.e. not from a phone number). By doing this you can use SMS to remind customers of reservations, send confirmations of new orders, etc.
To send an SMS is the easiest way to get started with 46elks, but you can do so much more. For example you can receive SMS, automatically respond to an incoming SMS or handle voice calls. For this and more there are a load of Ruby code examples at GitHub.
If you have any questions then get in touch, we love talking to our users!