This tutorial teaches you how to use the Telesign Ruby SDK to send an SMS. The complete sample code for this tutorial is available on GitHub here.
Make sure you have the following before you start:
- Authentication credentials: Your Customer ID and API Key. If you need help finding these items, go to the support article How do I find my Customer ID and API Key.
- Testing device: A mobile phone on which you can receive SMS.
- Telesign Self-service Ruby SDK: Install the Self-service Ruby SDK. Source code and installation instructions are on GitHub.
This tutorial uses Ruby 2.7. Please modify accordingly if you are using a different version of Ruby.
This tutorial uses a Mac, please modify accordingly if you are using a different system.
Create a new directory for your project and then enter it. If you plan to create multiple Ruby projects that use Telesign, we recommend that you group them within a
cd telesign_integrations mkdir sms cd sms
Create a new file called send_sms.rb and open it in your editor:
Import the Telesign SDK as a dependency.
Define variables to store your authentication credentials. For testing purposes, you can just overwrite the default values below or use environment variables.
customer_id = ENV['CUSTOMER_ID'] || 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890' api_key = ENV['API_KEY'] || 'ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=='
Define a variable to hold the recipient's phone number. For this tutorial, hardcode your testing device's phone number or pull it from an environment variable.
phone_number = ENV['PHONE_NUMBER'] || '11234567890'
Define variables for the message text and the Telesign abbreviation describing the message type. For purposes of this tutorial, use the "ARN" abbreviation (alerts, reminders, and notifications).
message = 'Your package has shipped! Follow your delivery at https://vero-finto.com/orders/3456' message_type = 'ARN'
Instantiate a Telesign messaging client object with your authentication credentials.
client = Telesign::MessagingClient.new(customer_id, api_key)
Make the request and capture the response.
response = client.message(phone_number, message, message_type)
Display the response body in the console for debugging purposes. In your production code, you would likely remove this.
print "\nResponse HTTP status: ", response.status_code, "\n" print "Response body: ", response.body, "\n\n"
The complete sample code for this tutorial can be found on GitHub.
Updated about 2 months ago