Inheritance: PlivoElement
        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 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";
            };
        }
Example #3
0
        public void TestAllXml()
        {
            var resp = new Response();
            resp.AddConference("My room",
                new Dictionary<string, string>()
                {
                    {"callbackUrl", "http://foo.com/confevents/"},
                    {"callbackMethod", "POST"},
                    {"digitsMatch", "#0,99,000"}
                });

            Plivo.XML.Dial dial = new Plivo.XML.Dial(new
                Dictionary<string, string>()
                {
                    {"confirmSound", "http://foo.com/sound/"},
                    {"confirmKey", "3"}
                });
            dial.AddNumber("18217654321",
                new Dictionary<string, string>()
                {
                    {"sendDigits", "wwww2410"}
                });
            dial.AddUser("sip:[email protected]",
                new Dictionary<string, string>()
                {
                    {"sendDigits", "wwww2410"}
                });
            resp.Add(dial);

            Plivo.XML.Dial dial1 = new Plivo.XML.Dial(new
                Dictionary<string, string>()
                {
                    {"timeout", "20"},
                    {"action", "http://foo.com/dial_action/"}
                });

            dial1.AddNumber("18217654321",
                new Dictionary<string, string>() { });

            Plivo.XML.Dial dial2 = new Plivo.XML.Dial(new
                Dictionary<string, string>()
            { });
            dial2.AddNumber("15671234567",
                new Dictionary<string, string>() { });
            resp.Add(dial1);
            resp.Add(dial2);

            resp.AddDTMF("12345",
                new Dictionary<string, string>() { });

            Plivo.XML.GetDigits get_digits = new
                Plivo.XML.GetDigits("",
                    new Dictionary<string, string>()
                    {
                        {"action", "http://www.foo.com/gather_pin/"},
                        {"method", "POST"}
                    });
            resp.Add(get_digits);

            get_digits.AddSpeak("Enter PIN number.",
                new Dictionary<string, string>() { });
            resp.AddSpeak("Input not recieved.",
                new Dictionary<string, string>() { });

            resp.AddHangup(new Dictionary<string, string>()
            {
                {"schedule", "60"},
                {"reason", "rejected"}
            });
            resp.AddSpeak("Call will hangup after a min.",
                new Dictionary<string, string>()
                {
                    {"loop", "0"}
                });

            resp.AddMessage("Hi, message from Plivo.",
                new Dictionary<string, string>()
                {
                    {"src", "12023222222"},
                    {"dst", "15671234567"},
                    {"type", "sms"},
                    {"callbackUrl", "http://foo.com/sms_status/"},
                    {"callbackMethod", "POST"}
                });

            resp.AddPlay("https://amazonaws.com/Trumpet.mp3",
                new Dictionary<string, string>() { });

            Plivo.XML.PreAnswer answer = new
                Plivo.XML.PreAnswer();
            answer.AddSpeak("This call will cost $2 a min.",
                new Dictionary<string, string>() { });
            resp.Add(answer);
            resp.AddSpeak("Thanks for dropping by.",
                new Dictionary<string, string>() { });

            resp.AddRecord(new Dictionary<string, string>()
            {
                {"action", "http://foo.com/get_recording/"},
                {"startOnDialAnswer", "true"},
                {"redirect", "false"}
            });

            Plivo.XML.Dial dial3 = new Plivo.XML.Dial(new
                Dictionary<string, string>()
            { });

            dial3.AddNumber("15551234567",
                new Dictionary<string, string>() { });
            resp.Add(dial3);

            resp.AddSpeak("Leave message after the beep.",
                new Dictionary<string, string>() { });
            resp.AddRecord(new Dictionary<string, string>()
            {
                {"action", "http://foo.com/get_recording/"},
                {"maxLength", "30"},
                {"finishOnKey", "*"}
            });
            resp.AddSpeak("Recording not received.",
                new Dictionary<string, string>() { });

            resp.AddSpeak("Your call is being transferred.",
                new Dictionary<string, string>() { });
            resp.AddRedirect("http://foo.com/redirect/",
                new Dictionary<string, string>() { });

            resp.AddSpeak("Go green, go plivo.",
                new Dictionary<string, string>()
                {
                    {"loop", "3"}
                });

            resp.AddSpeak("I will wait 7 seconds starting now!",
                new Dictionary<string, string>() { });
            resp.AddWait(new Dictionary<string, string>()
            {
                {"length", "7"}
            });
            resp.AddSpeak("I just waited 7 seconds.",
                new Dictionary<string, string>() { });

            resp.AddWait(new Dictionary<string, string>()
            {
                {"length", "120"},
                {"beep", "true"}
            });
            resp.AddPlay("https://s3.amazonaws.com/abc.mp3",
                new Dictionary<string, string>() { });

            resp.AddWait(new Dictionary<string, string>()
            {
                {"length", "10"}
            });
            resp.AddSpeak("Hello",
                new Dictionary<string, string>() { });

            resp.AddWait(new Dictionary<string, string>()
            {
                {"length", "10"},
                {"silence", "true"},
                {"minSilence", "3000"}
            });
            resp.AddSpeak("Hello, welcome to the Jungle.",
                new Dictionary<string, string>() { });

            var output = resp.ToString();
            Console.WriteLine(output);
        }
Example #4
0
        public void TestAllXml()
        {
            var resp = new Response();

            resp.AddConference("My room",
                               new Dictionary <string, string>()
            {
                { "callbackUrl", "http://foo.com/confevents/" },
                { "callbackMethod", "POST" },
                { "digitsMatch", "#0,99,000" }
            });

            Plivo.XML.Dial dial = new Plivo.XML.Dial(new
                                                     Dictionary <string, string>()
            {
                { "confirmSound", "http://foo.com/sound/" },
                { "confirmKey", "3" }
            });
            dial.AddNumber("18217654321",
                           new Dictionary <string, string>()
            {
                { "sendDigits", "wwww2410" }
            });
            dial.AddUser("sip:[email protected]",
                         new Dictionary <string, string>()
            {
                { "sendDigits", "wwww2410" }
            });
            resp.Add(dial);

            Plivo.XML.Dial dial1 = new Plivo.XML.Dial(new
                                                      Dictionary <string, string>()
            {
                { "timeout", "20" },
                { "action", "http://foo.com/dial_action/" }
            });

            dial1.AddNumber("18217654321",
                            new Dictionary <string, string>()
            {
            });

            Plivo.XML.Dial dial2 = new Plivo.XML.Dial(new
                                                      Dictionary <string, string>()
            {
            });
            dial2.AddNumber("15671234567",
                            new Dictionary <string, string>()
            {
            });
            resp.Add(dial1);
            resp.Add(dial2);

            resp.AddDTMF("12345",
                         new Dictionary <string, string>()
            {
            });

            Plivo.XML.GetDigits get_digits = new
                                             Plivo.XML.GetDigits("",
                                                                 new Dictionary <string, string>()
            {
                { "action", "http://www.foo.com/gather_pin/" },
                { "method", "POST" }
            });
            resp.Add(get_digits);

            get_digits.AddSpeak("Enter PIN number.",
                                new Dictionary <string, string>()
            {
            });
            resp.AddSpeak("Input not recieved.",
                          new Dictionary <string, string>()
            {
            });

            resp.AddHangup(new Dictionary <string, string>()
            {
                { "schedule", "60" },
                { "reason", "rejected" }
            });
            resp.AddSpeak("Call will hangup after a min.",
                          new Dictionary <string, string>()
            {
                { "loop", "0" }
            });

            resp.AddMessage("Hi, message from Plivo.",
                            new Dictionary <string, string>()
            {
                { "src", "12023222222" },
                { "dst", "15671234567" },
                { "type", "sms" },
                { "callbackUrl", "http://foo.com/sms_status/" },
                { "callbackMethod", "POST" }
            });

            resp.AddPlay("https://amazonaws.com/Trumpet.mp3",
                         new Dictionary <string, string>()
            {
            });

            Plivo.XML.PreAnswer answer = new
                                         Plivo.XML.PreAnswer();
            answer.AddSpeak("This call will cost $2 a min.",
                            new Dictionary <string, string>()
            {
            });
            resp.Add(answer);
            resp.AddSpeak("Thanks for dropping by.",
                          new Dictionary <string, string>()
            {
            });

            resp.AddRecord(new Dictionary <string, string>()
            {
                { "action", "http://foo.com/get_recording/" },
                { "startOnDialAnswer", "true" },
                { "redirect", "false" }
            });

            Plivo.XML.Dial dial3 = new Plivo.XML.Dial(new
                                                      Dictionary <string, string>()
            {
            });

            dial3.AddNumber("15551234567",
                            new Dictionary <string, string>()
            {
            });
            resp.Add(dial3);

            resp.AddSpeak("Leave message after the beep.",
                          new Dictionary <string, string>()
            {
            });
            resp.AddRecord(new Dictionary <string, string>()
            {
                { "action", "http://foo.com/get_recording/" },
                { "maxLength", "30" },
                { "finishOnKey", "*" }
            });
            resp.AddSpeak("Recording not received.",
                          new Dictionary <string, string>()
            {
            });

            resp.AddSpeak("Your call is being transferred.",
                          new Dictionary <string, string>()
            {
            });
            resp.AddRedirect("http://foo.com/redirect/",
                             new Dictionary <string, string>()
            {
            });

            resp.AddSpeak("Go green, go plivo.",
                          new Dictionary <string, string>()
            {
                { "loop", "3" }
            });

            resp.AddSpeak("I will wait 7 seconds starting now!",
                          new Dictionary <string, string>()
            {
            });
            resp.AddWait(new Dictionary <string, string>()
            {
                { "length", "7" }
            });
            resp.AddSpeak("I just waited 7 seconds.",
                          new Dictionary <string, string>()
            {
            });

            resp.AddWait(new Dictionary <string, string>()
            {
                { "length", "120" },
                { "beep", "true" }
            });
            resp.AddPlay("https://s3.amazonaws.com/abc.mp3",
                         new Dictionary <string, string>()
            {
            });

            resp.AddWait(new Dictionary <string, string>()
            {
                { "length", "10" }
            });
            resp.AddSpeak("Hello",
                          new Dictionary <string, string>()
            {
            });

            resp.AddWait(new Dictionary <string, string>()
            {
                { "length", "10" },
                { "silence", "true" },
                { "minSilence", "3000" }
            });
            resp.AddSpeak("Hello, welcome to the Jungle.",
                          new Dictionary <string, string>()
            {
            });

            var output = resp.ToString();

            // Console.WriteLine(output);
            Assert.Equal(
                "<Response>\n  <Conference callbackUrl=\"http://foo.com/confevents/\" callbackMethod=\"POST\" digitsMatch=\"#0,99,000\">My room</Conference>\n  <Dial confirmSound=\"http://foo.com/sound/\" confirmKey=\"3\">\n    <Number sendDigits=\"wwww2410\">18217654321</Number>\n    <User sendDigits=\"wwww2410\">sip:[email protected]</User>\n  </Dial>\n  <Dial timeout=\"20\" action=\"http://foo.com/dial_action/\">\n    <Number>18217654321</Number>\n  </Dial>\n  <Dial>\n    <Number>15671234567</Number>\n  </Dial>\n  <DTMF>12345</DTMF>\n  <GetDigits action=\"http://www.foo.com/gather_pin/\" method=\"POST\">\n    <Speak>Enter PIN number.</Speak>\n  </GetDigits>\n  <Speak>Input not recieved.</Speak>\n  <Hangup schedule=\"60\" reason=\"rejected\" />\n  <Speak loop=\"0\">Call will hangup after a min.</Speak>\n  <Message src=\"12023222222\" dst=\"15671234567\" type=\"sms\" callbackUrl=\"http://foo.com/sms_status/\" callbackMethod=\"POST\">Hi, message from Plivo.</Message>\n  <Play>https://amazonaws.com/Trumpet.mp3</Play>\n  <PreAnswer>\n    <Speak>This call will cost $2 a min.</Speak>\n  </PreAnswer>\n  <Speak>Thanks for dropping by.</Speak>\n  <Record action=\"http://foo.com/get_recording/\" startOnDialAnswer=\"true\" redirect=\"false\" />\n  <Dial>\n    <Number>15551234567</Number>\n  </Dial>\n  <Speak>Leave message after the beep.</Speak>\n  <Record action=\"http://foo.com/get_recording/\" maxLength=\"30\" finishOnKey=\"*\" />\n  <Speak>Recording not received.</Speak>\n  <Speak>Your call is being transferred.</Speak>\n  <Redirect>http://foo.com/redirect/</Redirect>\n  <Speak loop=\"3\">Go green, go plivo.</Speak>\n  <Speak>I will wait 7 seconds starting now!</Speak>\n  <Wait length=\"7\" />\n  <Speak>I just waited 7 seconds.</Speak>\n  <Wait length=\"120\" beep=\"true\" />\n  <Play>https://s3.amazonaws.com/abc.mp3</Play>\n  <Wait length=\"10\" />\n  <Speak>Hello</Speak>\n  <Wait length=\"10\" silence=\"true\" minSilence=\"3000\" />\n  <Speak>Hello, welcome to the Jungle.</Speak>\n</Response>",
                output.Replace(Environment.NewLine, "\n"));
        }
        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;
            };
        }