https://github.com/twilio/twilio-ruby
A Ruby gem for communicating with the Twilio API and generating TwiML
https://github.com/twilio/twilio-ruby
Keywords
twilio twilio-api twiml
Keywords from Contributors
activerecord activejob mvc sendgrid transactional-emails sidekiq rubygems rack background-jobs jobs
Last synced: about 7 hours ago
JSON representation
Repository metadata
A Ruby gem for communicating with the Twilio API and generating TwiML
- Host: GitHub
- URL: https://github.com/twilio/twilio-ruby
- Owner: twilio
- License: mit
- Created: 2009-09-15T06:17:02.000Z (about 16 years ago)
- Default Branch: main
- Last Pushed: 2025-11-26T17:43:27.000Z (14 days ago)
- Last Synced: 2025-11-27T17:13:27.688Z (13 days ago)
- Topics: twilio, twilio-api, twiml
- Language: Ruby
- Homepage:
- Size: 18.7 MB
- Stars: 1,378
- Watchers: 79
- Forks: 472
- Open Issues: 39
- Releases: 248
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Authors: AUTHORS.md
README.md
twilio-ruby
Documentation
The documentation for the Twilio API can be found here.
The individual releases here.
Versions
twilio-ruby uses a modified version of Semantic Versioning for all changes. See this document for details.
Supported Ruby Versions
This library supports the following Ruby implementations:
-
Ruby 2.4
-
Ruby 2.5
-
Ruby 2.6
-
Ruby 2.7
-
Ruby 3.0
-
Ruby 3.1
-
Ruby 3.2
-
JRuby 9.2
-
JRuby 9.3
-
JRuby 9.4
Migrating from 5.x
Installation
To install using Bundler grab the latest stable version:
gem 'twilio-ruby', '~> 7.8.8'
To manually install twilio-ruby via Rubygems simply gem install:
gem install twilio-ruby -v 7.8.8
To build and install the development branch yourself from the latest source:
git clone git@github.com:twilio/twilio-ruby.git
cd twilio-ruby
make install
Info
If the command line gives you an error message that says Permission Denied, try running the above commands with sudo.For example:
sudo gem install twilio-ruby
Test your installation
To make sure the installation was successful, try sending yourself an SMS message, like this:
require "twilio-ruby"
# Your Account SID and Auth Token from console.twilio.com
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
@client = Twilio::REST::Client.new account_sid, auth_token
message = @client.messages.create(
body: "Hello from Ruby",
to: "+12345678901", # Text this number
from: "+15005550006", # From a valid Twilio number
)
puts message.sid
Warning
It's okay to hardcode your credentials when testing locally, but you should use environment variables to keep them secret before committing any code or deploying to production. Check out How to Set Environment Variables for more information.
Usage
Authenticate the Client
require 'twilio-ruby'
# Your Account SID and Auth Token from console.twilio.com
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
# Initialize the Twilio Client with your credentials
@client = Twilio::REST::Client.new account_sid, auth_token
Use An API Key
require 'twilio-ruby'
# Your Account SID from console.twilio.com
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# API Key from twilio.com/console/project/api-keys
api_key_sid = 'zzzzzzzzzzzzzzzzzzzzzz'
api_key_secret = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
# set up a client to talk to the Twilio REST API using an API Key
@client = Twilio::REST::Client.new api_key_sid, api_key_secret, account_sid
Specify a Region and/or Edge
To take advantage of Twilio's Global Infrastructure, specify the target Region and/or Edge for the client:
# set up a client to talk to the Twilio REST API over a specific region and edge
@client = Twilio::REST::Client.new account_sid, auth_token, nil, 'au1'
@client.edge = 'sydney'
# you may also specify the region and/or edge after client creation
@client = Twilio::REST::Client.new account_sid, auth_token
@client.region = 'au1'
@client.edge = 'sydney'
This will result in the hostname transforming from api.twilio.com to api.sydney.au1.twilio.com.
Make a Call
@client.calls.create(
from: '+14159341234',
to: '+16105557069',
url: 'http://example.com'
)
Send an SMS
@client.messages.create(
from: '+14159341234',
to: '+16105557069',
body: 'Hey there!'
)
List your SMS Messages
@client.messages.list(limit: 20)
Fetch a single SMS message by Sid
# put the message sid you want to retrieve here:
message_sid = 'SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
@client.messages(message_sid).fetch
Iterate through records
The library automatically handles paging for you. Collections, such as calls and messages, have list and stream methods that page under the hood. With both list and stream, you can specify the number of records you want to receive (limit) and the maximum size you want each page fetch to be (page_size). The library will then handle the task for you.
list eagerly fetches all records and returns them as a list, whereas stream returns an enumerator and lazily retrieves pages of records as you iterate over the collection. You can also page manually using the page method.
For more information about these methods, view the auto-generated library docs.
require 'twilio-ruby'
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)
@client.calls.list
.each do |call|
puts call.direction
end
Enable Debug logging
In order to enable debug logging, pass in a 'logger' instance to the client with the level set to at least 'DEBUG'
@client = Twilio::REST::Client.new account_sid, auth_token
myLogger = Logger.new(STDOUT)
myLogger.level = Logger::DEBUG
@client.logger = myLogger
@client = Twilio::REST::Client.new account_sid, auth_token
myLogger = Logger.new('my_log.log')
myLogger.level = Logger::DEBUG
@client.logger = myLogger
Handle Exceptions {#exceptions}
If the Twilio API returns a 400 or a 500 level HTTP response, the twilio-ruby
library will throw a Twilio::REST::RestError. 400-level errors are normal
during API operation (“Invalid number”, “Cannot deliver SMS to that number”,
for example) and should be handled appropriately.
require 'twilio-ruby'
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token
begin
messages = @client.messages.list(limit: 20)
rescue Twilio::REST::RestError => e
puts e.message
end
Debug API requests
To assist with debugging, the library allows you to access the underlying request and response objects. This capability is built into the default HTTP client that ships with the library.
For example, you can retrieve the status code of the last response like so:
require 'rubygems' # Not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'
# Your Account SID and Auth Token from console.twilio.com
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)
@message = @client.messages.create(
to: '+14158675309',
from: '+14258675310',
body: 'Ahoy!'
)
# Retrieve the status code of the last response from the HTTP client
puts @client.http_client.last_response.status_code
Customize your HTTP Client
twilio-ruby uses Faraday to make HTTP requests. You can tell Twilio::REST::Client to use any of the Faraday adapters like so:
@client.http_client.adapter = :typhoeus
To use a custom HTTP client with this helper library, please see the advanced example of how to do so.
To apply customizations such as middleware, you can use the configure_connection method like so:
@client.http_client.configure_connection do |faraday|
faraday.use SomeMiddleware
end
Get started With Client Capability Tokens
If you just need to generate a Capability Token for use with Twilio Client, you can do this:
require 'twilio-ruby'
# put your own account credentials here:
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
# set up
capability = Twilio::JWT::ClientCapability.new account_sid, auth_token
# allow outgoing calls to an application
outgoing_scope = Twilio::JWT::ClientCapability::OutgoingClientScope.new 'AP11111111111111111111111111111111'
capability.add_scope(outgoing_scope)
# allow incoming calls to 'andrew'
incoming_scope = Twilio::JWT::ClientCapability::IncomingClientScope.new 'andrew'
capability.add_scope(incoming_scope)
# generate the token string
@token = capability.to_s
There is a slightly more detailed document in the Capability section of the wiki.
OAuth Feature for Twilio APIs
We are introducing Client Credentials Flow-based OAuth 2.0 authentication. This feature is currently in beta and its implementation is subject to change.
API examples here
Generate TwiML
To control phone calls, your application needs to output TwiML.
You can construct a TwiML response like this:
require 'twilio-ruby'
response = Twilio::TwiML::VoiceResponse.new do |r|
r.say(message: 'hello there', voice: 'alice')
r.dial(caller_id: '+14159992222') do |d|
d.client 'jenny'
end
end
# print the result
puts response.to_s
This will print the following (except for the whitespace):
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice">hello there</Say>
<Dial callerId="+14159992222">
<Client>jenny</Client>
</Dial>
</Response>
Docker Image
The Dockerfile present in this repository and its respective twilio/twilio-ruby Docker image are currently used by Twilio for testing purposes only.
Getting help
If you need help installing or using the library, please check the Twilio Support Help Center first, and file a support ticket if you don't find an answer to your question.
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
Owner metadata
- Name: Twilio
- Login: twilio
- Email:
- Kind: organization
- Description:
- Website: http://www.twilio.com
- Location: San Francisco
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/109142?v=4
- Repositories: 226
- Last ynced at: 2023-04-09T10:46:16.472Z
- Profile URL: https://github.com/twilio
GitHub Events
Total
- Create event: 43
- Release event: 23
- Issues event: 11
- Watch event: 26
- Delete event: 19
- Issue comment event: 47
- Push event: 113
- Pull request review comment event: 12
- Pull request review event: 29
- Pull request event: 36
- Fork event: 3
Last Year
- Create event: 37
- Issues event: 9
- Release event: 21
- Watch event: 22
- Delete event: 17
- Issue comment event: 38
- Push event: 86
- Pull request review comment event: 12
- Pull request review event: 27
- Pull request event: 31
- Fork event: 3
Committers metadata
Last synced: 4 days ago
Total Commits: 1,393
Total Committers: 131
Avg Commits per committer: 10.634
Development Distribution Score (DDS): 0.821
Commits in past year: 73
Committers in past year: 8
Avg Commits per committer in past year: 9.125
Development Distribution Score (DDS) in past year: 0.26
| Name | Commits | |
|---|---|---|
| Twilio | t****b@t****m | 249 |
| Twilio | t****i@t****m | 165 |
| Andrew Benton | a****n@g****m | 146 |
| Doug Black | d****k@t****m | 102 |
| Carlos Diaz-Padron | c****n@t****m | 86 |
| childish-sambino | s****n@t****m | 60 |
| Phil Nash | p****h@g****m | 58 |
| Evan Fossier | e****r@g****m | 58 |
| matt | m****t@t****m | 46 |
| Sam Kimbrel | s****l@t****m | 37 |
| Tom Connors | t****s@t****m | 33 |
| Jingming Niu | j****u@t****m | 28 |
| Karl Freeman | k****n@g****m | 17 |
| Elise Shanholtz | e****z@t****m | 17 |
| tmconnors | c****m@g****m | 15 |
| Carlos Diaz-Padron | c****s@c****o | 14 |
| Ilan Biala | i****a@g****m | 13 |
| Kyle Conroy | k****y@k****l | 13 |
| Manisha Singh | s****5@g****m | 12 |
| Shubham | t****5@g****m | 12 |
| Alexandre Payment | a****t@t****m | 11 |
| Kevin Burke | k****n@t****m | 11 |
| Jeremy McEntire | j****e@t****m | 10 |
| Evan Fossier | e****r@t****m | 9 |
| Elmer Thomas | e****s@t****m | 8 |
| Shwetha Radhakrishna | s****e | 7 |
| sbansla | 1****a | 6 |
| Jennifer Mah | 4****h | 5 |
| ekarson | 3****n | 5 |
| cjcodes | c****s@c****m | 5 |
| and 101 more... | ||
Committer domains:
- twilio.com: 23
- pivotallabs.com: 3
- c.mroach.com: 1
- freelancing-gods.com: 1
- ryanbigg.com: 1
- cavi.cc: 1
- keeptruckin.com: 1
- lizmrush.com: 1
- bitpop.in: 1
- gatech.edu: 1
- colgate.edu: 1
- cratercreative.com: 1
- mozilla.com: 1
- connormontgomery.com: 1
- blackacid.org: 1
- cjcodes.com: 1
- hey.com: 1
- oxon.org: 1
- jasonnoble.org: 1
- gautampai.com: 1
- inburke.com: 1
- benjaminste.in: 1
- beanserver.net: 1
- us.ibm.com: 1
- addfour.co: 1
- dougblack.io: 1
- gironda.org: 1
- calingilan.com: 1
- free.fr: 1
- adamek.me: 1
- jpcutler.net: 1
- wawra.co.uk: 1
- carlosdp.io: 1
Issue and Pull Request metadata
Last synced: 5 days ago
Total issues: 69
Total pull requests: 182
Average time to close issues: 3 months
Average time to close pull requests: 11 days
Total issue authors: 65
Total pull request authors: 58
Average comments per issue: 3.3
Average comments per pull request: 0.69
Merged pull request: 130
Bot issues: 0
Bot pull requests: 0
Past year issues: 7
Past year pull requests: 38
Past year average time to close issues: 2 months
Past year average time to close pull requests: 18 days
Past year issue authors: 7
Past year pull request authors: 8
Past year average comments per issue: 1.57
Past year average comments per pull request: 0.66
Past year merged pull request: 23
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- navid-farjad (2)
- ngouy (2)
- AxelTheGerman (2)
- arinchoi03 (2)
- visionsIT (1)
- codeundercoverdev (1)
- maceto (1)
- lusa (1)
- exop-it (1)
- oehlschl (1)
- ramaboo-deliv (1)
- f3ndot (1)
- mahkhaledm (1)
- jp-melanson (1)
- mohamedhafez (1)
Top Pull Request Authors
- tiwarishubham635 (44)
- manisha1997 (28)
- sbansla (9)
- shrutiburman (8)
- kridai (7)
- childish-sambino (6)
- eshanholtz (5)
- Copilot (4)
- claudiachua (4)
- casperisfine (2)
- ab320012 (2)
- JYorston (2)
- rohith-prakash (2)
- KobeBrooks (2)
- Hunga1 (2)
Top Issue Labels
- type: bug (18)
- status: waiting for feedback (13)
- type: question (12)
- status: help wanted (5)
- type: support (4)
- type: non-library issue (4)
- status: work in progress (4)
- type: community enhancement (3)
- type: twilio enhancement (3)
- priority: medium (3)
- priority: high (2)
- type: getting started (1)
- status: waiting for feature (1)
- status: invalid (1)
- type: docs update (1)
- status: code review request (1)
- status: ready for merge (1)
- code-generation (1)
- difficulty: medium (1)
- dependencies (1)
Top Pull Request Labels
- type: twilio enhancement (3)
- status: ready for deploy (2)
- status: waiting for feature (2)
- type: bug (2)
- status: ready for merge (2)
- status: code review request (1)
- dependencies (1)
- status: duplicate (1)
- status: work in progress (1)
Package metadata
- Total packages: 3
-
Total downloads:
- rubygems: 228,204,205 total
- Total docker downloads: 204,120,744
- Total dependent packages: 101 (may contain duplicates)
- Total dependent repositories: 6,396 (may contain duplicates)
- Total versions: 698
- Total maintainers: 1
gem.coop: twilio-ruby
The official library for communicating with the Twilio REST API, building TwiML, and generating Twilio JWT Capability Tokens
- Homepage: https://github.com/twilio/twilio-ruby
- Documentation: http://www.rubydoc.info/gems/twilio-ruby/
- Licenses: MIT
- Latest release: 7.8.8 (published 7 days ago)
- Last Synced: 2025-12-08T09:01:39.215Z (2 days ago)
- Versions: 347
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 114,249,147 Total
- Docker Downloads: 102,060,372
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.189%
- Downloads: 0.223%
- Docker downloads count: 0.531%
- Maintainers (1)
rubygems.org: twilio-ruby
The official library for communicating with the Twilio REST API, building TwiML, and generating Twilio JWT Capability Tokens
- Homepage: https://github.com/twilio/twilio-ruby
- Documentation: http://www.rubydoc.info/gems/twilio-ruby/
- Licenses: MIT
- Latest release: 7.8.8 (published 7 days ago)
- Last Synced: 2025-12-03T11:32:55.555Z (7 days ago)
- Versions: 348
- Dependent Packages: 101
- Dependent Repositories: 6,396
- Downloads: 113,955,058 Total
- Docker Downloads: 102,060,372
-
Rankings:
- Downloads: 0.237%
- Dependent packages count: 0.312%
- Dependent repos count: 0.403%
- Docker downloads count: 0.629%
- Average: 0.712%
- Forks count: 1.25%
- Stargazers count: 1.441%
- Maintainers (1)
proxy.golang.org: github.com/twilio/twilio-ruby
- Homepage:
- Documentation: https://pkg.go.dev/github.com/twilio/twilio-ruby#section-documentation
- Licenses: mit
- Latest release: v4.2.1+incompatible (published over 10 years ago)
- Last Synced: 2025-12-06T23:02:12.615Z (3 days ago)
- Versions: 3
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 8.542%
- Average: 9.088%
- Dependent repos count: 9.634%
Dependencies
- simplecov >= 0 development
- bundler >= 1.5, < 3.0 development
- equivalent-xml ~> 0.6 development
- fakeweb ~> 1.3 development
- logger ~> 1.4.2 development
- rack ~> 2.0 development
- rake ~> 13.0 development
- rspec ~> 3.0 development
- yard ~> 0.9.9 development
- faraday >= 0.9, < 3.0
- jwt >= 1.5, <= 2.5
- nokogiri >= 1.6, < 2.0
- amannn/action-semantic-pull-request v5 composite
- SonarSource/sonarcloud-github-action master composite
- actions/checkout v3 composite
- docker/login-action v2 composite
- rtCamp/action-slack-notify v2 composite
- ruby/setup-ruby v1 composite
- sendgrid/dx-automator/actions/datadog-release-metric main composite
- sendgrid/dx-automator/actions/release main composite
- ruby 2.4 build
Score: 32.01619791703575