From ba349806b7b73681498a47111153c63e15bb73f7 Mon Sep 17 00:00:00 2001 From: Brianna DelValle Date: Thu, 29 Jul 2021 16:33:13 -0600 Subject: [PATCH 1/3] Update examples to include action Uri, TwiMLResult, VoiceRequest, and correct Gather syntax --- .../gather-example-step-0/example.5.x.cs | 10 ++++---- .../gather-example-step-1/example.5.x.cs | 15 ++++++------ .../gather-example-step-2.1/example.5.x.cs | 13 +++++++---- .../gather-example-step-2/example.5.x.cs | 23 ++++++++++--------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs index 260a557a0c..5adb23d81f 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs @@ -3,20 +3,22 @@ using System.Web.Mvc; using Twilio.AspNet.Mvc; +using Twilio.AspNet.Common; using Twilio.TwiML; +using System; public class VoiceController : TwilioController { [HttpPost] - public ActionResult Index() + public TwiMLResult Index() { var response = new VoiceResponse(); // Use the verb to collect user input - response.Gather(new Gather(numDigits: 1) - .Say("For sales, press 1. For support, press 2.")); + response.Gather(numDigits: 1) + .Say("For sales, press 1. For support, press 2."); // If the user doesn't enter input, loop - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); return TwiML(response); } diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs index e7164cd724..8a2ba86aa4 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs @@ -3,18 +3,20 @@ using System.Web.Mvc; using Twilio.AspNet.Mvc; +using Twilio.AspNet.Common; using Twilio.TwiML; +using System; public class VoiceController : TwilioController { [HttpPost] - public ActionResult Index(string digits) + public TiwMLResult Index(VoiceRequest request) { var response = new VoiceResponse(); - if (!string.IsNullOrEmpty(digits)) + if (!string.IsNullOrEmpty(request.Digits)) { - switch (digits) + switch (request.Digits) { case "1": response.Say("You selected sales. Good for you!"); @@ -39,11 +41,10 @@ public ActionResult Index(string digits) private static void RenderMainMenu(VoiceResponse response) { - response.Gather( - new Gather(numDigits: 1) - .Say("For sales, press 1. For support, press 2.")); + response.Gather(numDigits: 1) + .Say("For sales, press 1. For support, press 2."); // If the user doesn't enter input, loop - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); } } diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs index 47af9bc35a..853c83b354 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs @@ -1,21 +1,24 @@ // In Package Manager, run: // Install-Package Twilio.AspNet.Mvc -DependencyVersion HighestMinor + using System.Web.Mvc; using Twilio.AspNet.Mvc; +using Twilio.AspNet.Common; using Twilio.TwiML; +using System; public class VoiceController : TwilioController { [HttpPost] - public ActionResult Gather(string digits) + public TwiMLResult Gather(VoiceRequest request) { var response = new VoiceResponse(); // If the user entered digits, process their request - if (!string.IsNullOrEmpty(digits)) + if (!string.IsNullOrEmpty(request.Digits)) { - switch (digits) + switch (request.Digits) { case "1": response.Say("You selected sales. Good for you!"); @@ -25,14 +28,14 @@ public ActionResult Gather(string digits) break; default: response.Say("Sorry, I don't understand that choice.").Pause(); - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); break; } } else { // If no input was sent, redirect to the /voice route - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); } return TwiML(response); diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs index 7efebea8b9..96624403fb 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs @@ -3,34 +3,35 @@ using System.Web.Mvc; using Twilio.AspNet.Mvc; +using Twilio.AspNet.Common; using Twilio.TwiML; +using System; public class VoiceController : TwilioController { [HttpPost] - public ActionResult Index() + public TwiMLResult Index() { var response = new VoiceResponse(); - response.Gather( - new Gather(numDigits: 1, action: "/voice/gather") - .Say("For sales, press 1. For support, press 2.")); + response.Gather(numDigits: 1, action: new Uri("/voice/gather")) + .Say("For sales, press 1. For support, press 2."); // If the user doesn't enter input, loop - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); - return Content(response.ToString(), "text/xml"); + return TwiML(response); } [HttpPost] - public ActionResult Gather(string digits) + public TwiMLResult Gather(VoiceRequest request) { var response = new VoiceResponse(); // If the user entered digits, process their request - if (!string.IsNullOrEmpty(digits)) + if (!string.IsNullOrEmpty(request.Digits)) { - switch (digits) + switch (request.Digits) { case "1": response.Say("You selected sales. Good for you!"); @@ -40,14 +41,14 @@ public ActionResult Gather(string digits) break; default: response.Say("Sorry, I don't understand that choice.").Pause(); - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); break; } } else { // If no input was sent, redirect to the /voice route - response.Redirect("/voice"); + response.Redirect(new Uri("/voice")); } return TwiML(response); From ae7d8da40d9cced3c7de564f449f6b37c709eb57 Mon Sep 17 00:00:00 2001 From: Brianna DelValle Date: Fri, 30 Jul 2021 09:36:32 -0600 Subject: [PATCH 2/3] Fix typo --- .../gather-example-step-1/example.5.x.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs index 8a2ba86aa4..954be9fbc6 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs @@ -10,7 +10,7 @@ public class VoiceController : TwilioController { [HttpPost] - public TiwMLResult Index(VoiceRequest request) + public TwiMLResult Index(VoiceRequest request) { var response = new VoiceResponse(); From 727071edbd0cfc66bb16e5f19f153c6c3ee93ad9 Mon Sep 17 00:00:00 2001 From: Brianna DelValle Date: Fri, 30 Jul 2021 12:55:32 -0600 Subject: [PATCH 3/3] Add UriKind.Relative --- .../gather-example-step-0/example.5.x.cs | 2 +- .../gather-example-step-1/example.5.x.cs | 2 +- .../gather-example-step-2.1/example.5.x.cs | 4 ++-- .../gather-example-step-2/example.5.x.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs index 5adb23d81f..6f81ff4633 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-0/example.5.x.cs @@ -18,7 +18,7 @@ public TwiMLResult Index() response.Gather(numDigits: 1) .Say("For sales, press 1. For support, press 2."); // If the user doesn't enter input, loop - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); return TwiML(response); } diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs index 954be9fbc6..18637e1833 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-1/example.5.x.cs @@ -45,6 +45,6 @@ private static void RenderMainMenu(VoiceResponse response) .Say("For sales, press 1. For support, press 2."); // If the user doesn't enter input, loop - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); } } diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs index 853c83b354..13b8109cca 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2.1/example.5.x.cs @@ -28,14 +28,14 @@ public TwiMLResult Gather(VoiceRequest request) break; default: response.Say("Sorry, I don't understand that choice.").Pause(); - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); break; } } else { // If no input was sent, redirect to the /voice route - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); } return TwiML(response); diff --git a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs index 96624403fb..5ba12594ac 100644 --- a/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs +++ b/guides/voice/gather-dtmf-tones-guide/gather-example-step-2/example.5.x.cs @@ -13,11 +13,11 @@ public class VoiceController : TwilioController public TwiMLResult Index() { var response = new VoiceResponse(); - response.Gather(numDigits: 1, action: new Uri("/voice/gather")) + response.Gather(numDigits: 1, action: new Uri("/voice/gather", UriKind.Relative)) .Say("For sales, press 1. For support, press 2."); // If the user doesn't enter input, loop - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); return TwiML(response); } @@ -41,14 +41,14 @@ public TwiMLResult Gather(VoiceRequest request) break; default: response.Say("Sorry, I don't understand that choice.").Pause(); - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); break; } } else { // If no input was sent, redirect to the /voice route - response.Redirect(new Uri("/voice")); + response.Redirect(new Uri("/voice", UriKind.Relative)); } return TwiML(response);