public void GetDigitsPromptsTest() { GetDigits getDigits = new GetDigits("http://foo.com"); Say say = new Say(); say.setLanguage(ELanguage.EnglishUS); say.setText("hello"); getDigits.setPrompts(say); Pause pause = new Pause(1000); getDigits.setPrompts(pause); say = new Say(); say.setLanguage(ELanguage.EnglishUS); say.setText("goodbye"); getDigits.setPrompts(say); string json = getDigits.toJson(); Assert.IsNotNull(json); Assert.AreEqual(json, "{\"GetDigits\":{\"actionUrl\":\"http://foo.com\",\"prompts\":[{\"Say\":{\"text\":\"hello\",\"language\":\"en-US\"}},{\"Pause\":{\"length\":1000}},{\"Say\":{\"text\":\"goodbye\",\"language\":\"en-US\"}}]}}"); }
public ActionResult CallDequeueSelect(GetDigitsActionCallback getDigitsStatusCallback) { // Create an empty PerCL script container PerCLScript script = new PerCLScript(); if ((getDigitsStatusCallback.getDigits != null) && (getDigitsStatusCallback.getDigits.Length > 0)) { // Create PerCL dequeue script and add to PerCL container script.Add(new Dequeue()); } else { // Create PerCL getdigits script GetDigits digits = new GetDigits(getAppUrl() + "/voice/CallDequeueSelect"); // Create PerCL say script with US English as the language Say say = new Say(); say.setLanguage(ELanguage.EnglishUS); // Add prompt to for queue exit say.setText("Press any key to exit queue."); // Add say script as a prompt to getdigits digits.setPrompts(say); // Add PerCL getdigits script to PerCL container script.Add(digits); } // Convert PerCL container to JSON and append to response return(Content(script.toJson(), "application/json")); }
public Program() { Get["/record_api"] = x => { Plivo.XML.Response resp = new Plivo.XML.Response(); String getdigits_action_url = "http://dotnettest.apphb.com/recording_action"; GetDigits gd = new GetDigits("", new Dictionary <string, string>() { { "action", getdigits_action_url }, // The URL to which the digits are sent { "method", "GET" }, // Submit to action URL using GET or POST. { "timeout", "7" }, // Time in seconds to wait to receive the first digit. { "numDigitd", "1" }, // Maximum number of digits to be processed in the current operation. { "retries", "1" }, // Indicates the number of retries the user is allowed to input the digits { "redirect", "false" } // Redirect to action URL if true. If false,only request the URL and continue to next element. }); gd.AddSpeak("Press 1 to record this call", new Dictionary <string, string>()); resp.Add(gd); resp.AddWait(new Dictionary <string, string>() { { "length", "10" } // Time to wait in seconds }); Debug.WriteLine(resp.ToString()); var output = resp.ToString(); var res = (Nancy.Response)output; res.ContentType = "text/xml"; return(res); }; Get["/recording_action"] = x => { String digits = Request.Query["Digits"]; String uuid = Request.Query["CallUUID"]; Debug.WriteLine("Digit pressed : {0}, Call UUID : {1}", digits, uuid); if (digits == "1") { string auth_id = "Your AUTH_ID"; string auth_token = "Your AUTH_TOKEN"; RestAPI plivo = new RestAPI(auth_id, auth_token); IRestResponse <Plivo.API.Record> resp = plivo.record(new Dictionary <string, string>() { { "call_uuid", uuid } // ID of the call }); Debug.WriteLine(resp.Content); } else { Debug.WriteLine("Invalid"); } return("OK"); }; }
public void GetDigitsNoPromptsTest() { GetDigits getDigits = new GetDigits("http://foo.com"); string json = getDigits.toJson(); Assert.IsNotNull(json); Assert.AreEqual(json, "{\"GetDigits\":{\"actionUrl\":\"http://foo.com\",\"prompts\":[]}}"); }
public Program() { Get["/speak_api"] = x => { Plivo.XML.Response resp = new Plivo.XML.Response(); String getdigits_action_url = "http://dotnettest.apphb.com/speak_action"; // Add GetDigits XML Tag GetDigits gd = new GetDigits("",new Dictionary<string, string>() { {"action",getdigits_action_url}, // The URL to which the digits are sent. {"method","GET"}, // Submit to action URL using GET or POST. {"timeout","7"}, // Time in seconds to wait to receive the first digit. {"retries","1"}, // Indicates the number of retries the user is allowed to input the digits, {"redirect","false"} // Redirect to action URL if true. If false,only request the URL and continue to next element. }); // Add GetDigits Speak XML Tag gd.AddSpeak("Press 1 to listen to a message",new Dictionary<string,string>()); resp.Add(gd); // Add Wait XML Tag resp.AddWait(new Dictionary<string, string>() { {"length","10"} }); Debug.WriteLine(resp.ToString()); var output = resp.ToString(); var res = (Nancy.Response)output; res.ContentType = "text/xml"; return res; }; Get["/speak_action"] = x => { String digits = Request.Query["Digits"]; String uuid = Request.Query["CallUUID"]; Debug.WriteLine("Digit pressed : {0}, Call UUID : {1}",digits, uuid ); RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN"; // Call to Speak API IRestResponse<GenericResponse> resp = plivo.speak(new Dictionary<string, string>() { { "call_uuid", uuid }, // ID of the call { "text", "Hello, from Speak API" }, // Text to be played. { "voice", "WOMAN" }, // The voice to be used, can be MAN,WOMAN. Defaults to WOMAN. {"language","en-GB"} // The language to be used }); Debug.WriteLine(resp.Content); return "Speak API"; }; }
[HttpPost("InboundCall")] //POST /voice/InboundCall public ActionResult InboundCall(CallStatusCallback callStatus) { PerCLScript script = new PerCLScript(); var getDigitsActionUrl = getAppUrl() + "/voice/GetDigitsDone"; GetDigits getDigits = new GetDigits(getDigitsActionUrl); getDigits.setMaxDigits(1); Say say = new Say(); say.setText("Hello. Welcome to the conferences tutorial, please enter your access code."); getDigits.setPrompts(say); script.Add(getDigits); return(Content(script.toJson(), "application/json")); }
[HttpPost("InboundCall")] // POST voice/InboundCall public ActionResult InboundCall(CallStatusCallback freeClimbRequest) { // Create an empty PerCL script container PerCLScript script = new PerCLScript(); // Verify inbund call is in proper state if (freeClimbRequest.getCallStatus == ECallStatus.Ringing) { // Create PerCL say script with US English as the language Say say = new Say(); say.setLanguage(ELanguage.EnglishUS); // Set greeting prompt say.setText("Hello"); // Add PerCL say script to PerCL container script.Add(say); // Create PerCL pause script with a 100 millisecond pause Pause pause = new Pause(100); // Add PerCL pause script to PerCL container script.Add(pause); // Create PerCL getdigits script string getDigitsUrl = AppUrl + "/voice/ColorSelectionDone"; GetDigits getDigits = new GetDigits(getDigitsUrl); // Set the max and min number of expected digits to 1 getDigits.setMaxDigits(1); getDigits.setMinDigits(1); // Set the DTMF buffer flush to false getDigits.setFlushBuffer(EBool.False); // Create PerCL say script with US English as the language say = new Say(); say.setLanguage(ELanguage.EnglishUS); // Set color selection menu prompt say.setText("Please select a color. Enter one for green, two for red or three for yellow."); // Add main selection menu prompt to the getdigits script getDigits.setPrompts(say); // Add PerCL getdigits script to PerCL container script.Add(getDigits); } // Convert PerCL container to JSON and append to response return(Content(script.toJson(), "application/json")); }
public ActionResult InboundCallWait(QueueWaitCallback queueWaitStatusCallback) { // Create an empty PerCL script container PerCLScript script = new PerCLScript(); // Create PerCL getdigits script string getDigitsUrl = Url.Action(getAppUrl() + "/voice/CallDequeueSelect"); GetDigits digits = new GetDigits(getDigitsUrl); // actionUrl // Create PerCL say script with US English as the language Say say = new Say(); say.setLanguage(ELanguage.EnglishUS); // Add prompt to for queue exit say.setText("Press any key to exit queue."); // Add say script as a prompt to getdigits digits.setPrompts(say); // Add PerCL getdigits script to PerCL container script.Add(digits); // Convert PerCL container to JSON and append to response return(Content(script.toJson(), "application/json")); }
public Program() { // When the call is answered, a text is played which prompts the user to press 1 to transfer the call. // Once the digit is pressed, the transfer API request is made and the call is transfered to another number. Get["call_transfer"] = x => { Plivo.XML.Response resp = new Plivo.XML.Response(); String getdigits_action_url = "http://dotnettest.apphb.com/transfer_action"; // Add GetDigits XML Tag GetDigits gd = new GetDigits("", new Dictionary <string, string>() { { "action", getdigits_action_url }, // The URL to which the digits are sent. { "method", "GET" }, // Submit to action URL using GET or POST. { "timeout", "7" }, // Time in seconds to wait to receive the first digit. { "retries", "1" }, // Indicates the number of retries the user is allowed to input the digits { "redirect", "false" }, // Redirect to action URL if true. If false,only request the URL and continue to next element. { "numDigits", "1" } }); // Add Speak XML Tag gd.AddSpeak("Press 1 to transfer this call", new Dictionary <string, string>()); resp.Add(gd); // Add Wait XML Tag resp.AddWait(new Dictionary <string, string>() { { "length", "10" } }); Debug.WriteLine(resp.ToString()); var output = resp.ToString(); var res = (Nancy.Response)output; res.ContentType = "text/xml"; return(res); }; // The Transfer API is invoked by the Get Digits action URL Get["/transfer_action"] = x => { String digits = Request.Query["Digits"]; String uuid = Request.Query["CallUUID"]; Debug.WriteLine("Digit pressed : {0}, Call UUID : {1}", digits, uuid); RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN"); // Transfer API IRestResponse <GenericResponse> resp = plivo.transfer_call(new Dictionary <string, string>() { { "call_uuid", uuid }, // ID of the call { "aleg_url", "http://dotnettest.apphb.com/connect" }, // URL to transfer for aleg { "aleg_method", "GET" } // Method to invoke the aleg_url }); Debug.WriteLine(resp.Content); return("Transfer API"); }; }
public Program() { // This file will be played when a caller presses 2. String PLIVO_SONG = "https://s3.amazonaws.com/plivocloud/music.mp3"; // This is the message that Plivo reads when the caller dials in String IVR_MESSAGE1 = "Welcome to the Plivo IVR Demo App. Press 1 to listen to a pre recorded text in different languages. Press 2 to listen to a song."; String IVR_MESSAGE2 = "Press 1 for English. Press 2 for French. Press 3 for Russian"; // This is the message that Plivo reads when the caller does nothing at all String NO_INPUT_MESSAGE = "Sorry, I didn't catch that. Please hangup and try again later."; // This is the message that Plivo reads when the caller inputs a wrong number. String WRONG_INPUT_MESSAGE = "Sorry, it's a wrong input."; Get["/response/ivr"] = x => { Plivo.XML.Response resp = new Plivo.XML.Response(); String getdigits_action_url = "http://dotnettest.apphb.com/response/ivr"; // Add GetDigits XML Tag GetDigits gd = new GetDigits("", new Dictionary <string, string>() { { "action", getdigits_action_url }, { "method", "POST" }, { "timeout", "7" }, { "numDigits", "1" }, { "retries", "1" } }); // Add Speak XML Tag gd.AddSpeak(IVR_MESSAGE1, new Dictionary <string, string>() { }); resp.Add(gd); // Add Speak XML Tag resp.AddSpeak(NO_INPUT_MESSAGE, new Dictionary <string, string>() { }); Debug.WriteLine(resp.ToString()); var output = resp.ToString(); var res = (Nancy.Response)output; res.ContentType = "text/xml"; return(res); }; Post["/response/ivr"] = x => { String digit = Request.Form["Digits"]; Debug.WriteLine("Digit pressed : {0}", digit); Plivo.XML.Response resp = new Plivo.XML.Response(); if (digit == "1") { String getdigits_action_url = "http://dotnettest.apphb.com/response/tree"; // Add GetDigits XML Tag GetDigits gd = new GetDigits("", new Dictionary <string, string>() { { "action", getdigits_action_url }, // The URL to which the digits are sent. { "method", "GET" }, // Submit to action URL using GET or POST. { "timeout", "7" }, // Time in seconds to wait to receive the first digit. { "numDigits", "1" }, // Maximum number of digits to be processed in the current operation. { "retries", "1" } // Indicates the number of retries the user is allowed to input the digits }); // Add Speak XML Tag gd.AddSpeak(IVR_MESSAGE2, new Dictionary <string, string>() { }); resp.Add(gd); // Add Speak XML Tag resp.AddSpeak(NO_INPUT_MESSAGE, new Dictionary <string, string>() { }); } else if (digit == "2") { // Add Play XML Tag resp.AddPlay(PLIVO_SONG, new Dictionary <string, string>() { }); } else { // Add Speak XML Tag resp.AddSpeak(WRONG_INPUT_MESSAGE, new Dictionary <string, string>() { }); } Debug.WriteLine(resp.ToString()); var output = resp.ToString(); var res = (Nancy.Response)output; res.ContentType = "text/xml"; return(res); }; Get["/response/tree"] = x => { Plivo.XML.Response resp = new Plivo.XML.Response(); String digit = Request.Query["Digits"]; // Add Speak XMLTag if (digit == "1") { resp.AddSpeak("This message is being read out in English", new Dictionary <string, string>() { { "language", "en-GB" } }); } else if (digit == "2") { resp.AddSpeak("Ce message est lu en français", new Dictionary <string, string>() { { "language", "fr-FR" } }); } else if (digit == "3") { resp.AddSpeak("Это сообщение было прочитано в России", new Dictionary <string, string>() { { "language", "ru-RU" } }); } else { resp.AddSpeak(WRONG_INPUT_MESSAGE, new Dictionary <string, string>() { }); } Debug.WriteLine(resp.ToString()); var output = resp.ToString(); var res = (Nancy.Response)output; res.ContentType = "text/xml"; return(res); }; }