Ruby
Send SMS or MMS with Ruby
Learn how to send your first SMS or MMS using the CCAI Ruby SDK
Prerequisites
To get the most out of this guide, you'll need to:
- Sign up for a CCAI Paid Plan
- Create an API Key
- Get your Client ID
- Watch this video if you need help
-
1. Install
Get the CCAI Ruby SDK.
Requirements: Ruby 2.6 or higher
gem install ccai
Or add your Gemfile:
gem 'ccai'
2. Send SMS message
require 'ccai'
# Initialize the client
client = CCAI.new(
client_id: 'YOUR-CLIENT-ID',
api_key: 'YOUR-API-KEY'
)
# Send a single SMS
response = client.sms.send_single(
'John',
'Doe',
'+15551234567',
'Hello ${firstName}, this is a test message!',
'Test Campaign'
)
puts "Message sent with ID: #{response.id}"
# Send to multiple recipients
accounts = [
CCAI::SMS::Account.new(
first_name: 'John',
last_name: 'Doe',
phone: '+15551234567'
),
CCAI::SMS::Account.new(
first_name: 'Jane',
last_name: 'Smith',
phone: '+15559876543'
)
]
campaign_response = client.sms.send(
accounts,
'Hello ${firstName} ${lastName}, this is a test message!',
'Bulk Test Campaign'
)
puts "Campaign sent with ID: #{campaign_response.campaign_id}"
3. Send MMS message
require 'ccai'
# Initialize the client
client = CCAI.new(
client_id: 'YOUR-CLIENT-ID',
api_key: 'YOUR-API-KEY'
)
# Define progress tracking
options = CCAI::SMS::Options.new(
timeout: 60,
on_progress: ->(status) {
puts "Progress: #{status}"
}
)
# Complete MMS workflow (get URL, upload image, send MMS)
image_path = 'path/to/your/image.jpg'
content_type = 'image/jpeg'
# Define recipient
account = CCAI::SMS::Account.new(
first_name: 'John',
last_name: 'Doe',
phone: '+15551234567' # Use E.164 format
)
# Send MMS with image in one step
response = client.mms.send_with_image(
image_path,
content_type,
[account],
'Hello ${firstName}, check out this image!',
'MMS Campaign Example',
options
)
puts "MMS sent! Campaign ID: #{response.campaign_id}"
4. Try it yourself
See the full source code here.
Updated 1 day ago