Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit aa46310

Browse files
patillacodedprothero
authored andcommitted
Fix python example snippets (#722)
* Task: Fix python example to match expected output * Task: Remove '/' in example output file (wrong XML syntax) * Task: PHP version 4.x snippet fixed. * Task: Ruby version 5.x snippet fixed. * Typo. * Task: C# version 5.x snippet fixed. * Task: PHP version 4.x lib load with require_once. * Task: C# version 5.x TwiML generation fixed. * Task: Java version 7.x fixed Task import and Builder call. * Task: C# version 5.x corrected response output
1 parent 3358a57 commit aa46310

File tree

6 files changed

+33
-24
lines changed

6 files changed

+33
-24
lines changed

rest/taskrouter/twiml/example2/example/example.4.x.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22
// Download the library and copy into the folder containing this file.
3-
require('twilio-php/Services/Twilio.php');
3+
require_once '/path/to/vendor/twilio/sdk/Services/Twilio.php';
44

55
$response = new Services_Twilio_Twiml;
6-
$response->enqueue(array(workflowSid => 'WW0123456789abcdef0123456789abcdef'))
7-
->task("{'account_number':'12345abcdef'}");
6+
$response->enqueue(array('workflowSid' => 'WW0123456789abcdef0123456789abcdef'))
7+
->task("{'account_number':'12345abcdef'}");
88
print $response;
99
?>
10-
1110
<!-- alternatively -->
1211

1312
<?php
@@ -21,4 +20,4 @@
2120
<Enqueue workflowSid="<?php echo $workflowSid ?>">
2221
<Task>{"account_number": "12345abcdef"}</Task>
2322
</Enqueue>
24-
</Response>
23+
</Response>

rest/taskrouter/twiml/example2/example/example.5.x.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
using System;
44
using System.Net;
55
using Twilio.TwiML;
6+
using Twilio.TwiML.Voice;
67

78
class Example
89
{
9-
public static HttpListenerResponse SendResponse(HttpListenerContext ctx)
10+
public static void SendResponse(HttpListenerContext ctx)
1011
{
1112
HttpListenerRequest request = ctx.Request;
1213
HttpListenerResponse response = ctx.Response;
1314

1415
response.StatusCode = (int)HttpStatusCode.OK;
1516
response.ContentType = "text/xml";
1617

18+
// Generate TwiML
1719
var twiml = new VoiceResponse();
18-
twiml.Enqueue("{\"account_number\":\"12345abcdef\"}",
19-
workflowSid: "WW0123456789abcdef0123456789abcdef");
20+
var enqueue = new Enqueue(workflowSid: "WW0123456789abcdef0123456789abcdef");
21+
enqueue.Task("{\"account_number\": \"12345abcdef\"}");
22+
twiml.Append(enqueue);
2023

21-
response.StatusDescription = twiml.ToString();
22-
return response;
24+
// Write the output and close the stream
25+
byte[] buffer = Encoding.UTF8.GetBytes(twiml.ToString());
26+
response.ContentLength64 = buffer.Length;
27+
response.OutputStream.Write(buffer,0, buffer.Length);
28+
response.OutputStream.Close();
2329
}
2430
}

rest/taskrouter/twiml/example2/example/example.5.x.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
set :port, 8080
66

77
post '/enqueue_call' do
8-
attributes = '{"account_number":"12345abcdef"}'
98

10-
Twilio::TwiML::Response.new do |r|
11-
r.Enqueue workflowSid: 'WW0123456789abcdef0123456789abcdef' do |e|
12-
e.Task attributes
9+
attributes = '{"account_number": "12345abcdef"}'
10+
11+
Twilio::TwiML::VoiceResponse.new do |response|
12+
response.enqueue(workflowSid: 'WW0123456789abcdef0123456789abcdef') do |e|
13+
e.task(attributes)
1314
end
14-
end.text
15+
end.to_s
1516
end
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# Download the Python helper library from twilio.com/docs/python/install
22
from flask import Flask
3-
from twilio.twiml.voice_response import VoiceResponse
3+
from twilio.twiml.voice_response import VoiceResponse, Enqueue
44

55
app = Flask(__name__)
66

77

88
@app.route("/enqueue_call", methods=['GET', 'POST'])
99
def enqueue_call():
10-
# workflow_sid = 'WW0123456789abcdef0123456789abcdef'
10+
11+
workflow_sid = 'WW0123456789abcdef0123456789abcdef'
1112

1213
resp = VoiceResponse()
13-
# TODO waiting for https://github.com/twilio/twilio-python/issues/283
1414

15-
# with resp.enqueue(None, workflowSid=workflow_sid) as e:
16-
# e.task('{"account_number":"12345abcdef"}')
15+
e = Enqueue(None, workflowSid=workflow_sid)
16+
e.task('{"account_number":"12345abcdef"}')
17+
18+
resp.append(e)
1719

1820
return str(resp)

rest/taskrouter/twiml/example2/example/example.7.x.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import javax.servlet.http.HttpServletResponse;
77

88
import com.twilio.twiml.voice.Enqueue;
9-
import com.twilio.twiml.Task;
9+
import com.twilio.twiml.voice.Task;
1010
import com.twilio.twiml.TwiMLException;
1111
import com.twilio.twiml.VoiceResponse;
1212

@@ -15,7 +15,8 @@ public class Example extends HttpServlet {
1515

1616
@Override
1717
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
18-
Task task = new Task.Builder().data("{\"account_number\":\"12345abcdef\"}").build();
18+
19+
Task task = new Task.Builder("{\"account_number\":\"12345abcdef\"}").build();
1920

2021
Enqueue enqueue =
2122
new Enqueue.Builder()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Response>
3-
<Enqueue workflowSid="WW0123456789abcdef0123456789abcdef"/>
3+
<Enqueue workflowSid="WW0123456789abcdef0123456789abcdef">
44
<Task>{"account_number": "12345abcdef"}</Task>
55
</Enqueue>
6-
</Response>
6+
</Response>

0 commit comments

Comments
 (0)