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

Commit 2cf4bb7

Browse files
authored
Merge pull request #926 from TwilioDevEd/dotnet-dtmf-tones-fix
Update C# DTMF guide examples
2 parents f7fbb2f + 727071e commit 2cf4bb7

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33

44
using System.Web.Mvc;
55
using Twilio.AspNet.Mvc;
6+
using Twilio.AspNet.Common;
67
using Twilio.TwiML;
8+
using System;
79

810
public class VoiceController : TwilioController
911
{
1012
[HttpPost]
11-
public ActionResult Index()
13+
public TwiMLResult Index()
1214
{
1315
var response = new VoiceResponse();
1416

1517
// Use the <Gather> verb to collect user input
16-
response.Gather(new Gather(numDigits: 1)
17-
.Say("For sales, press 1. For support, press 2."));
18+
response.Gather(numDigits: 1)
19+
.Say("For sales, press 1. For support, press 2.");
1820
// If the user doesn't enter input, loop
19-
response.Redirect("/voice");
21+
response.Redirect(new Uri("/voice", UriKind.Relative));
2022

2123
return TwiML(response);
2224
}

guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
using System.Web.Mvc;
55
using Twilio.AspNet.Mvc;
6+
using Twilio.AspNet.Common;
67
using Twilio.TwiML;
8+
using System;
79

810
public class VoiceController : TwilioController
911
{
1012
[HttpPost]
11-
public ActionResult Index(string digits)
13+
public TwiMLResult Index(VoiceRequest request)
1214
{
1315
var response = new VoiceResponse();
1416

15-
if (!string.IsNullOrEmpty(digits))
17+
if (!string.IsNullOrEmpty(request.Digits))
1618
{
17-
switch (digits)
19+
switch (request.Digits)
1820
{
1921
case "1":
2022
response.Say("You selected sales. Good for you!");
@@ -39,11 +41,10 @@ public ActionResult Index(string digits)
3941

4042
private static void RenderMainMenu(VoiceResponse response)
4143
{
42-
response.Gather(
43-
new Gather(numDigits: 1)
44-
.Say("For sales, press 1. For support, press 2."));
44+
response.Gather(numDigits: 1)
45+
.Say("For sales, press 1. For support, press 2.");
4546

4647
// If the user doesn't enter input, loop
47-
response.Redirect("/voice");
48+
response.Redirect(new Uri("/voice", UriKind.Relative));
4849
}
4950
}

guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
// In Package Manager, run:
22
// Install-Package Twilio.AspNet.Mvc -DependencyVersion HighestMinor
33

4+
45
using System.Web.Mvc;
56
using Twilio.AspNet.Mvc;
7+
using Twilio.AspNet.Common;
68
using Twilio.TwiML;
9+
using System;
710

811
public class VoiceController : TwilioController
912
{
1013
[HttpPost]
11-
public ActionResult Gather(string digits)
14+
public TwiMLResult Gather(VoiceRequest request)
1215
{
1316
var response = new VoiceResponse();
1417

1518
// If the user entered digits, process their request
16-
if (!string.IsNullOrEmpty(digits))
19+
if (!string.IsNullOrEmpty(request.Digits))
1720
{
18-
switch (digits)
21+
switch (request.Digits)
1922
{
2023
case "1":
2124
response.Say("You selected sales. Good for you!");
@@ -25,14 +28,14 @@ public ActionResult Gather(string digits)
2528
break;
2629
default:
2730
response.Say("Sorry, I don't understand that choice.").Pause();
28-
response.Redirect("/voice");
31+
response.Redirect(new Uri("/voice", UriKind.Relative));
2932
break;
3033
}
3134
}
3235
else
3336
{
3437
// If no input was sent, redirect to the /voice route
35-
response.Redirect("/voice");
38+
response.Redirect(new Uri("/voice", UriKind.Relative));
3639
}
3740

3841
return TwiML(response);

guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,35 @@
33

44
using System.Web.Mvc;
55
using Twilio.AspNet.Mvc;
6+
using Twilio.AspNet.Common;
67
using Twilio.TwiML;
8+
using System;
79

810
public class VoiceController : TwilioController
911
{
1012
[HttpPost]
11-
public ActionResult Index()
13+
public TwiMLResult Index()
1214
{
1315
var response = new VoiceResponse();
14-
response.Gather(
15-
new Gather(numDigits: 1, action: "/voice/gather")
16-
.Say("For sales, press 1. For support, press 2."));
16+
response.Gather(numDigits: 1, action: new Uri("/voice/gather", UriKind.Relative))
17+
.Say("For sales, press 1. For support, press 2.");
1718

1819
// If the user doesn't enter input, loop
19-
response.Redirect("/voice");
20+
response.Redirect(new Uri("/voice", UriKind.Relative));
2021

21-
return Content(response.ToString(), "text/xml");
22+
return TwiML(response);
2223
}
2324

2425

2526
[HttpPost]
26-
public ActionResult Gather(string digits)
27+
public TwiMLResult Gather(VoiceRequest request)
2728
{
2829
var response = new VoiceResponse();
2930

3031
// If the user entered digits, process their request
31-
if (!string.IsNullOrEmpty(digits))
32+
if (!string.IsNullOrEmpty(request.Digits))
3233
{
33-
switch (digits)
34+
switch (request.Digits)
3435
{
3536
case "1":
3637
response.Say("You selected sales. Good for you!");
@@ -40,14 +41,14 @@ public ActionResult Gather(string digits)
4041
break;
4142
default:
4243
response.Say("Sorry, I don't understand that choice.").Pause();
43-
response.Redirect("/voice");
44+
response.Redirect(new Uri("/voice", UriKind.Relative));
4445
break;
4546
}
4647
}
4748
else
4849
{
4950
// If no input was sent, redirect to the /voice route
50-
response.Redirect("/voice");
51+
response.Redirect(new Uri("/voice", UriKind.Relative));
5152
}
5253

5354
return TwiML(response);

0 commit comments

Comments
 (0)