Inheritance: PlivoElement
Example #1
0
        public Program()
        {
            Get["/connect"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add Speak XML Tag
                resp.AddSpeak("Connecting your call..", new Dictionary <string, string>()
                {
                });

                // Add Dial XML Tag
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                });
                dial.AddNumber("2222222222", new Dictionary <string, string>()
                {
                });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
        public Program()
        {
            Get["/dial"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() 
                {
                    {"action","http://dotnettest.apphb.com/dial_status"}, // Redirect to this URL after leaving Dial.
                    {"method","GET"} // Submit to action URL using GET or POST.
                });
                dial.AddNumber("1111111111", new Dictionary<string, string>() { });
                
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };

            Get["/dial_status"] = x =>
            {
                // After completion of the call, Plivo will report back the status to the action URL in the Dial XML.
                String status = Request.Query["DialStatus"];
                String aleg = Request.Form["DialALegUUID"];
                String bleg = Request.Form["DialBLegUUID"];

                Debug.WriteLine("Status : {0}, ALeg UUID : {1}, BLeg UUID : {2}", status, aleg, bleg);
                return "OK";
            };
        }
        public Program()
        {
            Get["/forward"] = x =>
            {
                // The phone number of the person calling your Plivo number,
                // we'll use this as the Caller ID when we forward the call.
                String from_number = Request.Query["From"];

                // The number you would like to forward the call to.
                String forwarding_number = "2222222222";

                Plivo.XML.Response resp = new Plivo.XML.Response();
                Plivo.XML.Dial     dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                    { "callerId", from_numbers } // The phone number to be used as the caller id. It can be set to the from_number or any custom number.
                });
                dial.AddNumber(forwarding_number, new Dictionary <string, string>()
                {
                });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
Example #4
0
        public Program()
        {
            Get["/seq_dial"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                    { "timeout", "20" }, // The duration (in seconds) for which the called party has to be given a ring.
                    { "action", "http://dotnettest.apphb.com/dial_status" } // Redirect to this URL after leaving Dial.
                });
                dial.AddNumber("1111111111", new Dictionary <string, string>()
                {
                });
                dial.AddNumber("2222222222", new Dictionary <string, string>()
                {
                });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
        public Program()
        {
            Get["/forward"] = x =>
            {
                // The phone number of the person calling your Plivo number,
                // we'll use this as the Caller ID when we forward the call.
                String from_number = Request.Query["From"];

                // The number you would like to forward the call to.
                String forwarding_number = "2222222222";

                Plivo.XML.Response resp = new Plivo.XML.Response();
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() 
                {
                    {"callerId", from_numbers} // The phone number to be used as the caller id. It can be set to the from_number or any custom number.
                });
                dial.AddNumber(forwarding_number, new Dictionary<string, string>() { });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Get["/call_hunting"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                });
                dial.AddUser("sip:[email protected]", new Dictionary <string, string>()
                {
                });
                dial.AddNumber("2222222222", new Dictionary <string, string>()
                {
                });
                dial.AddNumber("3333333333", new Dictionary <string, string>()
                {
                });
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
        static void Main(string[] args)
        {
            Response resp = new Response();
            resp.AddRecord(new Dictionary<string,string>() {
                { "action", "http://some.domain/recordfile" },
                { "startOnDialAnswer", "true" }
            });

            Dial dial = new Dial(new Dictionary<string, string>() {
                { "callerId", "12222222222" },
            });
            dial.AddNumber("12121212121", new Dictionary<string,string>());
            resp.Add(dial);
            Console.WriteLine(resp.ToString());
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     Plivo.XML.Response resp = new Plivo.XML.Response();
     Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() { });
     if (Request.HttpMethod == "GET")
     {
         int i = 0;
         for(;i<Request.QueryString.Count;i++)
         {
             if (Request.QueryString.GetKey(i) == "Numbers")
                 dial.AddNumber(Request.QueryString.Get(i), new Dict
     ionary<string, string>());
             else if (Request.QueryString.GetKey(i) == "Users")
                 dial.AddUser(Request.QueryString.Get(i), new Dictionary<string, string>());
         }
        public Program()
        {
            Get["/call_transfer"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add speak XML tag
                resp.AddSpeak("Please wait while your call is being transferred", new Dictionary <string, string>()
                {
                });

                // Add Redirect XML tag
                resp.AddRedirect("http://dotnettest.apphb.com/connect", new Dictionary <string, string>()
                {
                });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };

            Get["/connect"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                    { "action", "http://dotnettest.apphb.com/dial_status" }, // Redirect to this URL after leaving Dial.
                    { "method", "GET" },                                     // Submit to action URL using GET or POST.
                    { "redirect", "true" } // If set to false, do not redirect to action URL. We expect an XML from the action URL if this parameter is set to true.
                });
                dial.AddNumber("1111111111", new Dictionary <string, string>()
                {
                });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
Example #10
0
        public Program()
        {
            Get["/call_whisper"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate DIal XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                    { "confirmSound", "http://dotnettest.apphb.com/confirm_sound" }, // A remote URL fetched with POST HTTP request which must return an
                                                                                     // XML response with Play, Wait and/or Speak elements only.
                    { "confirmKey", "5" } // The digit to be pressed by the called party to accept the call.
                });
                dial.AddNumber("1111111111", new Dictionary <string, string>()
                {
                });
                dial.AddNumber("2222222222", new Dictionary <string, string>()
                {
                });
                dial.AddNumber("3333333333", new Dictionary <string, string>()
                {
                });
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };

            Get["/confirm_sound"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                //Generate Speak XML
                resp.AddSpeak("Press 5 to answer the call", new Dictionary <string, string>()
                {
                });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
        public Program()
        {
            Get["dynamic_caller_id"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() { });
                dial.AddNumber("1111111111", new Dictionary<string, string>() { });
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
Example #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Plivo.XML.Response resp = new Plivo.XML.Response();
        Plivo.XML.Dial     dial = new Plivo.XML.Dial(new Dictionary <string, string>()
        {
        });
        if (Request.HttpMethod == "GET")
        {
            int i = 0;
            for (; i < Request.QueryString.Count; i++)
            {
                if (Request.QueryString.GetKey(i) == "Numbers")
                {
                    dial.AddNumber(Request.QueryString.Get(i), new Dict
                                   ionary <string, string>());
                }
                else if (Request.QueryString.GetKey(i) == "Users")
                {
                    dial.AddUser(Request.QueryString.Get(i), new Dictionary <string, string>());
                }
            }
            resp.Add(dial);
        }
        else if (Request.HttpMethod == "POST")
        {
            int i = 0;
            for (; i < Request.Form.Count; i++)
            {
                if (Request.Form.GetKey(i) == "Numbers")
                {
                    dial.AddNumber(Request.Form.Get(i), new Dictionary <string, string>());
                }
                else if (Request.Form.GetKey(i) == "Users")
                {
                    dial.AddUser(Request.Form.Get(i), new Dictionary <string, string>());
                }
            }
            resp.Add(dial);
        }

        Response.Write(resp.ToString());
        Response.ContentType = "text/xml";
        Response.End();
    }
        public Program()
        {
            Get["/call_transfer"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add speak XML tag
                resp.AddSpeak("Please wait while your call is being transferred", new Dictionary<string, string>() { });

                // Add Redirect XML tag
                resp.AddRedirect("http://dotnettest.apphb.com/connect", new Dictionary<string, string>() { });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };

            Get["/connect"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() 
                {
                    {"action","http://dotnettest.apphb.com/dial_status"}, // Redirect to this URL after leaving Dial. 
                    {"method","GET"}, // Submit to action URL using GET or POST.
                    {"redirect", "true"} // If set to false, do not redirect to action URL. We expect an XML from the action URL if this parameter is set to true. 
                });
                dial.AddNumber("1111111111", new Dictionary<string, string>() { });
                
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Get["/dial"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                    { "dialMusic", "http://dotnettest.apphb.com/custom_tone" } // Music to be played to the caller while the call is being connected.
                });
                dial.AddNumber("1111111111", new Dictionary <string, string>()
                {
                });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };

            Get["/custom_tone"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add Play XML Tags
                resp.AddPlay("https://s3.amazonaws.com/plivocloud/music.mp3", new Dictionary <string, string>()
                {
                });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
        public Program()
        {
            Get["/call_whisper"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate DIal XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() 
                {
                    {"confirmSound","http://dotnettest.apphb.com/confirm_sound"}, // A remote URL fetched with POST HTTP request which must return an 
                                                                                  // XML response with Play, Wait and/or Speak elements only.
                    {"confirmKey","5"} // The digit to be pressed by the called party to accept the call.
                });
                dial.AddNumber("1111111111", new Dictionary<string, string>() { });
                dial.AddNumber("2222222222", new Dictionary<string, string>() { });
                dial.AddNumber("3333333333", new Dictionary<string, string>() { });
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };

            Get["/confirm_sound"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                //Generate Speak XML
                resp.AddSpeak("Press 5 to answer the call", new Dictionary<string, string>() { });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Get["dynamic_caller_id"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                });
                dial.AddNumber("1111111111", new Dictionary <string, string>()
                {
                });
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
        public Program()
        {
            Get["/connect"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add Speak XML Tag
                resp.AddSpeak("Connecting your call..", new Dictionary<string, string>() { });

                // Add Dial XML Tag
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() { });
                dial.AddNumber("2222222222", new Dictionary<string, string>() { });
                
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Get["/dial"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() 
                {
                    {"dialMusic","http://dotnettest.apphb.com/custom_tone"} // Music to be played to the caller while the call is being connected.
                });
                dial.AddNumber("1111111111", new Dictionary<string, string>() { });
                
                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };

            Get["/custom_tone"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();
             
                // Add Play XML Tags
                resp.AddPlay("https://s3.amazonaws.com/plivocloud/music.mp3", new Dictionary<string, string>() { });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Get["/seq_dial"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary<string, string>() 
                {
                    {"timeout", "20"}, // The duration (in seconds) for which the called party has to be given a ring.
                    {"action", "http://dotnettest.apphb.com/dial_status"} // Redirect to this URL after leaving Dial. 
                });
                dial.AddNumber("1111111111", new Dictionary<string, string>() { });
                dial.AddNumber("2222222222", new Dictionary<string, string>() { });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
Example #20
0
        public Program()
        {
            Get["/dial"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Dial XML
                Plivo.XML.Dial dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                {
                    { "action", "http://dotnettest.apphb.com/dial_status" }, // Redirect to this URL after leaving Dial.
                    { "method", "GET" } // Submit to action URL using GET or POST.
                });
                dial.AddNumber("1111111111", new Dictionary <string, string>()
                {
                });

                resp.Add(dial);
                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };

            Get["/dial_status"] = x =>
            {
                // After completion of the call, Plivo will report back the status to the action URL in the Dial XML.
                String status = Request.Query["DialStatus"];
                String aleg   = Request.Form["DialALegUUID"];
                String bleg   = Request.Form["DialBLegUUID"];

                Debug.WriteLine("Status : {0}, ALeg UUID : {1}, BLeg UUID : {2}", status, aleg, bleg);
                return("OK");
            };
        }
Example #21
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);
        }
        public Program()
        {
            Get["/answer_incoming"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                resp.AddRecord(new Dictionary<string, string>()
                {
                    {"action","http://dotnettest.apphb.com/record_action"}, // Submit the result of the record to this URL.
                    {"method","GET"}, // Submit to action url using GET or POST
                    {"redirect","false"}, // If false, don't redirect to action url, only request the url and continue to next element.
                    {"recordSession","true"} // Record current call session in background 
                });

                resp.AddWait(new Dictionary<string, string>()
                {
                    {"length", "10"} // Time to wait in seconds
                });

                Dial dial = new Dial(new Dictionary<string, string>()
                {
                    {"callbackUrl",""}, // URL that is notified by Plivo when one of the following events occur : 
                                        // called party is bridged with caller, called party hangs up, caller has pressed any digit
                    {"callbackMethod","GET"} // Method used to notify callbackUrl.
                });

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

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
            
            // The Callback URL of Dial will make a request to the Record API which will record only the B Leg
            // Play API is invoked which will play a music only on the B Leg.
            Get["dial_outbound"] = x =>
            {
                string events = Request.Query["Event"];
                string call_uuid = Request.Query["CallUUID"];
                Debug.WriteLine("Event : " + events);
                Debug.WriteLine("Call UUID : " + call_uuid);

                if (events == "DialAnswer")
                {
                    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",call_uuid}, // ID of the call
                        {"callback_url","http://dotnettest.apphb.com/record_callback"}, // The URL invoked by the API when the recording ends.
                        {"callback_method","GET"} // The method which is used to invoke the callback_url URL. Defaults to POST.
                    });

                    Debug.WriteLine(resp.Content);

                    RestAPI plivo1 = new RestAPI(auth_id, auth_token);
                    IRestResponse<GenericResponse> resp1 = plivo1.play(new Dictionary<string, string>()
                    {
                        {"call_uuid",call_uuid}, // ID of the call
                        {"url","https://s3.amazonaws.com/plivocloud/Trumpet.mp3"} // A single URL or a list of comma separated URLs pointing to an mp3 or wav file.
                    });

                    Debug.WriteLine(resp1.Content);
                }    
                else
                {
                    Debug.WriteLine("Invalid");                        
                }

                return "OK";
            };

            // The Callback URL of record api will return the B Leg record details.
            Get["/record_callback"] = x =>
            {
                String record_url = Request.Query["RecordUrl"];
                String record_duration = Request.Query["RecordingDuration"];
                String record_id = Request.Query["RecordingID"];

                Debug.WriteLine("Record URL : {0}, Recording Duration : {1}, Record ID : {2}", record_url, record_duration, record_id);
                return "Done";
            };
        }
Example #23
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"));
        }