forked from twilio/twilio-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request twilio#35 from TwilioDevEd/reservations_call_snippets
Includes reservation call snippets
- Loading branch information
Showing
8 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Install the Java helper library from twilio.com/docs/java/install | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.twilio.sdk.TwilioRestException; | ||
import com.twilio.sdk.TwilioTaskRouterClient; | ||
import com.twilio.sdk.resource.instance.taskrouter.Reservation; | ||
import com.twilio.sdk.resource.instance.taskrouter.Task; | ||
import com.twilio.sdk.resource.instance.taskrouter.Workspace; | ||
|
||
public class Example { | ||
|
||
// Find your Account Sid and Token at twilio.com/user/account | ||
private static final String ACCOUNT_SID = "{{ account_sid }}"; | ||
private static final String AUTH_TOKEN = "{{ auth_token }}"; | ||
private static final String WORKSPACE_SID = "{{ workspace_sid }}"; | ||
private static final String TASK_SID = "{{ task_sid }}"; | ||
private static final String RESERVATION_SID = "{{ reservation_sid }}"; | ||
|
||
public static void main(String[] args) throws TwilioRestException { | ||
TwilioTaskRouterClient client = new TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN); | ||
|
||
Reservation reservation = client.getReservation(WORKSPACE_SID, TASK_SID, RESERVATION_SID); | ||
|
||
// call using a reservation | ||
Map<String, String> params = new HashMap<String, String>(); | ||
params.put("Instruction", "Call"); | ||
params.put("CallFrom", "+15558675309"); | ||
params.put("CallUrl", "http://example.com/agent_answer"); | ||
params.put("CallStatusCallbackUrl", "http://example.com/agent_answer_status_callback"); | ||
params.put("CallAccept", "true"); | ||
reservation.update(params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Download the Node helper library from twilio.com/docs/node/install | ||
// These vars are your accountSid and authToken from twilio.com/user/account | ||
var twilio = require('twilio'); | ||
|
||
var accountSid = "{{ account_sid }}"; | ||
var authToken = "{{ auth_token }}"; | ||
var workspaceSid = "{{ workspace_sid }}"; | ||
var taskSid = "{{ task_sid }}"; | ||
var reservationSid = "{{ reservation_sid }}"; | ||
|
||
var client = new twilio.TaskRouterClient(accountSid, authToken, workspaceSid); | ||
|
||
// call using a reservation | ||
client.workspace.tasks(taskSid).reservations(reservationSid).update({ | ||
instruction: 'call', | ||
callFrom: '+15558675309', | ||
callUrl: 'http://example.com/agent_answer', | ||
callStatusCallbackUrl: 'http://example.com/agent_answer_status_callback', | ||
callAccept: 'true' | ||
}, function(err, reservation) { | ||
console.log(reservation.reservation_status); | ||
console.log(reservation.worker_name); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$ curl -XPOST https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{ReservationSid} \ | ||
-d "Instruction=call" \ | ||
-d "CallFrom=+15558675309" \ | ||
-d "CallUrl=http://example.com/agent_answer" \ | ||
-d "CallStatusCallbackUrl=http://example.com/agent_answer_status_callback" \ | ||
-d "CallAccept=true" \ | ||
-u '{account_sid}:{auth_token}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
// Get the PHP helper library from twilio.com/docs/php/install | ||
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library | ||
|
||
// Your Account Sid and Auth Token from twilio.com/user/account | ||
$accountSid = "{{ account_sid }}"; | ||
$authToken = "{{ auth_token }}"; | ||
$workspaceSid = "{{ workspace_sid }}"; | ||
$taskSid = "{{ task_sid }}"; | ||
$reservationSid = "{{ reservation_sid }}"; | ||
|
||
$client = new TaskRouter_Services_Twilio($accountSid, $authToken, $workspaceSid); | ||
|
||
// call using a reservation | ||
$reservation = $client->workspace->tasks->get($taskSid)->reservations($reservationSid); | ||
$reservation->update( | ||
array( | ||
'Instruction' => 'call', | ||
'CallFrom' => '+15558675309', | ||
'CallUrl' => 'http://example.com/agent_answer', | ||
'CallStatusCallbackUrl' => 'http://example.com/agent_answer_status_callback', | ||
'CallAccept' => 'true' | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Download the Python helper library from twilio.com/docs/python/install | ||
from twilio.rest import TwilioTaskRouterClient | ||
|
||
# Your Account Sid and Auth Token from twilio.com/user/account | ||
account_sid = "{{ account_sid }}" | ||
auth_token = "{{ auth_token }}" | ||
workspace_sid = "{{ workspace_sid }}" | ||
task_sid = "{{ task_sid }}" | ||
reservation_sid = "{{ reservation_sid }}" | ||
|
||
client = TwilioTaskRouterClient(account_sid, auth_token) | ||
|
||
# call using a reservation | ||
reservation = client.reservations(workspace_sid, task_sid).update(reservation_sid, | ||
instruction='call', | ||
call_from='+15558675309', | ||
call_url='http://example.com/agent_answer', | ||
call_status_callback_url='http://example.com/agent_answer_status_callback', | ||
call_accept='true') | ||
print reservation.reservation_status | ||
print reservation.worker_name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Get twilio-ruby from twilio.com/docs/ruby/install | ||
require 'rubygems' # This line not needed for ruby > 1.8 | ||
require 'twilio-ruby' | ||
|
||
# Get your Account Sid and Auth Token from twilio.com/user/account | ||
account_sid = '{{ account_sid }}' | ||
auth_token = '{{ auth_token }}' | ||
workspace_sid = '{{ workspace_sid }}' | ||
task_sid = '{{ task_sid }}' | ||
|
||
client = Twilio::REST::TaskRouterClient.new account_sid, auth_token, workspace_sid | ||
|
||
reservation = client.workspace.tasks.get(task_sid).reservations.get(reservation_sid) | ||
reservation.update(instruction: 'call', | ||
callFrom: '+15558675309', | ||
callUrl: 'http://example.com/agent_answer', | ||
callStatusCallbackUrl: 'http://example.com/agent_answer_status_callback', | ||
callAccept: 'true') | ||
|
||
puts reservation.reservation_status | ||
puts reservation.worker_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "Call Instruction", | ||
"type": "server" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"sid": "WR692a16edbfe00cbb2c2295f9462407d6", | ||
"account_sid": "AC9242e2195ab0681fd413fc3c03b7d7f8", | ||
"workspace_sid": "WS7d4813fc78909747b773945352c5b960", | ||
"task_sid": "WTd480a09f869b59812e7690af3e7cf23c", | ||
"worker_sid": "WKa0f24176fee1938e495760b1122995b6", | ||
"worker_name": "Cases Worker", | ||
"reservation_status": "pending", | ||
"date_created": "2015-07-31T20:18:09Z", | ||
"date_updated": "2015-07-31T20:18:09Z", | ||
"url": "https://taskrouter.twilio.com/v1/Workspaces/WS7d4813fc78909747b773945352c5b960/Tasks/WTd480a09f869b59812e7690af3e7cf23c/Reservations/WR692a16edbfe00cbb2c2295f9462407d6", | ||
"links": { | ||
"task": "https://taskrouter.twilio.com/v1/Workspaces/WS7d4813fc78909747b773945352c5b960/Tasks/WTd480a09f869b59812e7690af3e7cf23c", | ||
"worker": "https://taskrouter.twilio.com/v1/Workspaces/WS7d4813fc78909747b773945352c5b960/Workers/WKa0f24176fee1938e495760b1122995b6", | ||
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WS7d4813fc78909747b773945352c5b960" | ||
} | ||
} |