File tree Expand file tree Collapse file tree 6 files changed +123
-0
lines changed
stun-turn/list-post-example
token-generation-server-rooms Expand file tree Collapse file tree 6 files changed +123
-0
lines changed Original file line number Diff line number Diff line change 1+ # Get twilio-ruby from twilio.com/docs/ruby/install
2+ require 'rubygems' # This line not needed for ruby > 1.8
3+ require 'twilio-ruby'
4+
5+ # Get your Account Sid and Auth Token from twilio.com/user/account
6+ account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
7+ auth_token = 'your_auth_token'
8+ @client = Twilio ::REST ::Client . new account_sid , auth_token
9+
10+ token = @client . account . tokens . create
11+ puts token . username
Original file line number Diff line number Diff line change 1+ require 'twilio-ruby'
2+ require 'sinatra'
3+ require 'sinatra/json'
4+ require 'dotenv'
5+ require 'faker'
6+
7+ # Load environment configuration
8+ Dotenv . load
9+
10+ # Render home page
11+ get '/' do
12+ File . read ( File . join ( 'public' , 'index.html' ) )
13+ end
14+
15+ # Generate a token for use in our Video application
16+ get '/token' do
17+ # Create a random username for the client
18+ identity = Faker ::Internet . user_name
19+
20+ # Create an Access Token for Video usage
21+ token = Twilio ::Util ::AccessToken . new (
22+ ENV [ 'TWILIO_ACCOUNT_SID' ] ,
23+ ENV [ 'TWILIO_API_KEY' ] ,
24+ ENV [ 'TWILIO_API_SECRET' ] ,
25+ 3600 ,
26+ identity
27+ )
28+
29+ # Grant access to Twilio Video
30+ grant = Twilio ::Util ::AccessToken ::ConversationsGrant . new
31+ grant . configuration_profile_sid = ENV [ 'TWILIO_CONFIGURATION_SID' ]
32+ token . add_grant grant
33+
34+ # Generate the token and send to client
35+ json identity : identity , token : token . to_jwt
36+ end
Original file line number Diff line number Diff line change 1+ require 'twilio-ruby'
2+ require 'sinatra'
3+ require 'sinatra/json'
4+ require 'dotenv'
5+ require 'faker'
6+
7+ # Load environment configuration
8+ Dotenv . load
9+
10+ # Render home page
11+ get '/' do
12+ File . read ( File . join ( 'public' , 'index.html' ) )
13+ end
14+
15+ # Generate a token for use in our Video application
16+ get '/token' do
17+ # Create a random username for the client
18+ identity = Faker ::Internet . user_name
19+
20+ # Create an Access Token for Video usage
21+ token = Twilio ::Util ::AccessToken . new (
22+ ENV [ 'TWILIO_ACCOUNT_SID' ] ,
23+ ENV [ 'TWILIO_API_KEY' ] ,
24+ ENV [ 'TWILIO_API_SECRET' ] ,
25+ 3600 ,
26+ identity
27+ )
28+
29+ # Grant access to Video
30+ grant = Twilio ::Util ::AccessToken ::VideoGrant . new
31+ grant . configuration_profile_sid = ENV [ 'TWILIO_CONFIGURATION_SID' ]
32+ token . add_grant grant
33+
34+ # Generate the token and send to client
35+ json identity : identity , token : token . to_jwt
36+ end
Original file line number Diff line number Diff line change 1+ require 'sinatra'
2+ require 'twilio-ruby'
3+
4+ # Handles the POST request from Twilio and generates the
5+ # TwiML that connects agent with the first caller in the Queue
6+ post '/agent/?' do
7+ response = Twilio ::TwiML ::Response . new do |r |
8+ r . Dial do |d |
9+ d . Queue 'Queue Demo'
10+ end
11+ end
12+ response . text
13+ end
Original file line number Diff line number Diff line change 1+ require 'sinatra'
2+ require 'twilio-ruby'
3+
4+ # Handles the POST request from Twilio and generates the
5+ # TwiML that puts caller in a queue.
6+ post '/caller/?' do
7+ response = Twilio ::TwiML ::Response . new do |r |
8+ # Use <Enqueue> verb to place caller in a <Queue>
9+ r . Enqueue 'Queue Demo'
10+ end
11+ response . text
12+ end
Original file line number Diff line number Diff line change 1+ require 'sinatra'
2+ require 'twilio-ruby'
3+
4+ # Handles the POST request from Twilio and generates the TwiML
5+ # that connects agent with the first caller in the Queue
6+ post '/agent/?' do
7+ response = Twilio ::TwiML ::Response . new do |r |
8+ r . Say 'You will now be connected to the first caller in the queue.'
9+ r . Dial do |d |
10+ d . Queue 'Queue Demo'
11+ end
12+ r . Redirect
13+ end
14+ response . text
15+ end
You can’t perform that action at this time.
0 commit comments