public Program()
        {
            Post["/receive_sms"] = x =>
            {
                String from_number = Request.Form["From"]; // Sender's phone number
                String to_number = Request.Form["To"]; // Receiver's phone number
                String text = Request.Form["Text"]; // The text which was received

                // Print the message
                Console.WriteLine("From : {0}, To : {1}, Text : {2}", from_number, to_number, text);

                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate Message XML
                resp.AddMessage("Thank you for your message", new Dictionary<string, string>() {
                { "src", to_number }, // Sender's phone number
                { "dst", from_number } // receiver's phone number
                });

                // Print the XML
                Console.WriteLine(resp.ToString());

                // Return the XML
                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Post["/receive_sms"] = x =>
            {
                String from_number = Request.Form["From"]; // Sender's phone number
                String to_number = Request.Form["To"]; // Receiver's phone number
                String text = Request.Form["Text"]; // The text which was received


                Console.WriteLine("From : {0}, To : {1}, Text : {2}", from_number, to_number, text);

                String to_forward = "1111111111"; // The phone number to which the sms has to be forwarded

                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate the Message XML
                resp.AddMessage(text, new Dictionary<string, string>() {
                { "src", to_number },
                { "dst", to_forward }
                });

                // Print the XML
                Console.WriteLine(resp.ToString());

                // Return the XML
                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
        public Program()
        {
            Post["/receive_sms"] = x =>
            {
                String from_number = Request.Form["From"]; // Sender's phone number
                String to_number   = Request.Form["To"];   // Receiver's phone number
                String text        = Request.Form["Text"]; // The text which was received


                Console.WriteLine("From : {0}, To : {1}, Text : {2}", from_number, to_number, text);

                String to_forward = "1111111111"; // The phone number to which the sms has to be forwarded

                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Generate the Message XML
                resp.AddMessage(text, new Dictionary <string, string>()
                {
                    { "src", to_number },
                    { "dst", to_forward }
                });

                // Print the XML
                Console.WriteLine(resp.ToString());

                // Return the XML
                var output = resp.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
Beispiel #4
0
        public PlivoDirectDial()
        {
            Get["/response/sip/route/"] = _ => {
                string dst = Request.Query["ForwardTo"];
                string src = Request.Query["CLID"];
                string cname = Request.Query["CallerName"];
                string hangup = Request.Query["HangupCause"];
                string dialMusic = Request.Query["DialMusic"];
                string disableCall = Request.Query["DisableCall"];
                if ( String.IsNullOrEmpty(dst) )
                    dst = Request.Query["To"];
                if ( String.IsNullOrEmpty(src) )
                    src = Request.Query["From"];

                if (String.IsNullOrEmpty(cname))
                    cname = "";
                if ( !String.IsNullOrEmpty(hangup) )
                    return "SIP Route hangup callback";

                Plivo.XML.Response response = new Plivo.XML.Response();

                if ( String.IsNullOrEmpty(dst) ) {
                    Console.WriteLine("SIP Route cannot identify destination number");
                    response.AddHangup(new dict {
                        {"reason", "busy"},
                    });
                } else {
                    bool isSipUser = false;

                    if (dst.Length > 4 && dst.Substring(0, 4) == "sip:")
                        isSipUser = true;

                    if (isSipUser && disableCall == "all" || disableCall == "sip") {
                        Console.WriteLine(String.Format("SIP Route calling sip user is disabled : %s", disableCall));
                        response.AddHangup(new dict {
                            { "reason", "busy" },
                        });
                    } else if (!isSipUser && disableCall == "all" || disableCall == "number") {
                        response.AddHangup(new dict {
                            { "reason", "busy" },
                        });
                    } else {
                        Console.WriteLine(String.Format("SIP Route dialing %s", dst));
                        
                        if (!String.IsNullOrEmpty(dialMusic) && isSipUser) {
                            var dial = response.AddDial(new dict {
                                {"callerId", src},
                                {"callerName", cname},
        public Program()
        {
            //Machine Detection URL example
            Get["/machine_detection"] = x =>
            {
                String from_number = Request.Query["From"];
                String machine = Request.Query["Machine"];
                String to_number = Request.Query["To"];
                String call_uuid = Request.Query["CallUUID"];
                String event_ = Request.Query["Event"];
                String status = Request.Query["CallStatus"];

                Debug.WriteLine("From : {0}, Machine : {1}, To : {2}, Call UUID : {3}, Event : {4}, Call Status : {5}", from_number, machine, to_number, call_uuid, event_, status);
                return "Done";
            };

            // As soon as the voicemail finishes speaking, and there is a silence for minSilence milliseconds, 
            // the next element in the XML is processed, without waiting for the whole period of length seconds to pass

            Get["/detect"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();
                resp.AddWait(new Dictionary<string, string>()
                {
                    {"length","1000"},
                    {"silence","true"},
                    {"minSilence","3000"}
                });

                resp.AddSpeak("Hello Voicemail!", new Dictionary<string, string>() { });

                Debug.WriteLine(resp.ToString());

                var output = resp.ToString();
                var res = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return res;
            };
        }
Beispiel #6
0
        public PlivoDirectDial()
        {
            Get["/response/sip/route/"] = _ => {
                string dst = Request.Query["ForwardTo"];
                string src = Request.Query["CLID"];
                string cname = Request.Query["CallerName"];
                string hangup = Request.Query["HangupCause"];
                string dialMusic = Request.Query["DialMusic"];
                string disableCall = Request.Query["DisableCall"];
                if ( String.IsNullOrEmpty(dst) )
                    dst = Request.Query["To"];
                if ( String.IsNullOrEmpty(src) )
                    src = Request.Query["From"];

                if (String.IsNullOrEmpty(cname))
                    cname = "";
                if ( !String.IsNullOrEmpty(hangup) )
                    return "SIP Route hangup callback";

                Plivo.XML.Response response = new Plivo.XML.Response();

                if ( String.IsNullOrEmpty(dst) ) {
                    Console.WriteLine("SIP Route cannot identify destination number");
                    response.AddHangup(new dict {
                        {"reason", "busy"},
                    });
                } else {
                    bool isSipUser = false;

                    if (dst.Length > 4 && dst.Substring(0, 4) == "sip:")
                        isSipUser = true;

                    if (isSipUser && disableCall == "all" || disableCall == "sip") {
                        Console.WriteLine(String.Format("SIP Route calling sip user is disabled : %s", disableCall));
                        response.AddHangup(new dict {
                            { "reason", "busy" },
                        });
                    } else if (!isSipUser && disableCall == "all" || disableCall == "number") {
                        response.AddHangup(new dict {
                            { "reason", "busy" },
                        });
                    } else {
                        Console.WriteLine(String.Format("SIP Route dialing %s", dst));

                        if (!String.IsNullOrEmpty(dialMusic) && isSipUser) {
                            var dial = response.AddDial(new dict {
                                {"callerId", src},
                                {"callerName", cname},
                                {"dialMusic", dialMusic)},
                            });
                            dial.AddUser(dst, new dict { });
                            response.Add(dial);
                        } else if (String.IsNullOrEmpty(dialMusic) && isSipUser) {
                            var dial = new Plivo.XML.Dial(new dict {
                                {"callerId", src},
                                {"callerName", cname},
                            });
                            dial.AddUser(dst, new dict { });
                            response.Add(dial);
                        } else if (!String.IsNullOrEmpty(dialMusic) && !isSipUser) {
                            var dial = new Plivo.XML.Dial(new dict {
                                {"callerId", src},
                                {"callerName", cname},
                                {"dialMusic", dialMusic},
                            });
                            dial.AddNumber(dst, new dict { });
                            response.Add(dial);
                        } else if (String.IsNullOrEmpty(dialMusic) && !isSipUser) {
                            var dial = new Plivo.XML.Dial(new dict {
                                {"callerId", src},
                                {"callerName", cname},
                            });
                            dial.AddUser(dst, new dict { });
                            response.Add(dial);
                        }

                        var xmlBytes = Encoding.UTF8.GetBytes(response.ToString());
                        return new Response
                        {
                          ContentType = 'text/xml';
                          Contents = s => s.Write(xmlBytes, 0, xmlBytes.Length);
                        };
                    }
                }
            };

            //Similarly, we can setup for HTTP POST as well.
            // Use Request.Form to get the values.
            //Post["/response/sip/route/"] = _ =>
            //{
            //    return Response("Hello" + Request.Form["cname"]);
            //};
        }
Beispiel #7
0
        public PlivoDirectDial()
        {
            Get["/direct-dial/"] = x => {
                string dst         = Request.Query["ForwardTo"];
                string src         = Request.Query["CLID"];
                string cname       = Request.Query["CallerName"];
                string hangup      = Request.Query["HangupCause"];
                string dialMusic   = Request.Query["DialMusic"];
                string disableCall = Request.Query["DisableCall"];
                if (String.IsNullOrEmpty(dst))
                {
                    dst = Request.Query["To"];
                }
                if (String.IsNullOrEmpty(src))
                {
                    src = Request.Query["From"];
                }

                if (String.IsNullOrEmpty(cname))
                {
                    cname = "";
                }
                if (!String.IsNullOrEmpty(hangup))
                {
                    return("SIP Route hangup callback");
                }

                Plivo.XML.Response response = new Plivo.XML.Response();

                if (String.IsNullOrEmpty(dst))
                {
                    Console.WriteLine("SIP Route cannot identify destination number");
                    response.AddHangup(new Dictionary <string, string> {
                        { "reason", "busy" },
                    });
                }
                else
                {
                    bool isSipUser = false;

                    if (dst.Length > 4 && dst.Substring(0, 4) == "sip:")
                    {
                        isSipUser = true;
                    }

                    if (isSipUser && disableCall == "all" || disableCall == "sip")
                    {
                        Console.WriteLine(String.Format("SIP Route calling sip user is disabled : %s", disableCall));
                        response.AddHangup(new Dictionary <string, string>()
                        {
                            { "reason", "busy" },
                        });
                    }
                    else if (!isSipUser && disableCall == "all" || disableCall == "number")
                    {
                        response.AddHangup(new Dictionary <string, string>()
                        {
                            { "reason", "busy" },
                        });
                    }
                    else
                    {
                        Console.WriteLine(String.Format("SIP Route dialing %s", dst));

                        if (!String.IsNullOrEmpty(dialMusic) && isSipUser)
                        {
                            var dial = response.AddDial(new Dictionary <string, string>()
                            {
                                { "callerId", src },
                                { "callerName", cname },
                                { "dialMusic", dialMusic }
                            });
                            dial.AddUser(dst, new Dictionary <string, string>()
                            {
                            });
                            response.Add(dial);
                        }
                        else if (String.IsNullOrEmpty(dialMusic) && isSipUser)
                        {
                            var dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                            {
                                { "callerId", src },
                                { "callerName", cname },
                            });
                            dial.AddUser(dst, new Dictionary <string, string>()
                            {
                            });
                            response.Add(dial);
                        }
                        else if (!String.IsNullOrEmpty(dialMusic) && !isSipUser)
                        {
                            var dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                            {
                                { "callerId", src },
                                { "callerName", cname },
                                { "dialMusic", dialMusic },
                            });
                            dial.AddNumber(dst, new Dictionary <string, string>()
                            {
                            });
                            response.Add(dial);
                        }
                        else if (String.IsNullOrEmpty(dialMusic) && !isSipUser)
                        {
                            var dial = new Plivo.XML.Dial(new Dictionary <string, string>()
                            {
                                { "callerId", src },
                                { "callerName", cname },
                            });
                            dial.AddUser(dst, new Dictionary <string, string>()
                            {
                            });
                            response.Add(dial);
                        }
                    }
                }
                Debug.WriteLine(response.ToString());

                var output = response.ToString();
                var res    = (Nancy.Response)output;
                res.ContentType = "text/xml";
                return(res);
            };
        }
Beispiel #8
0
        public PlivoDirectDial()
        {
            Get["/direct-dial/"] = x => {
                string dst = Request.Query["ForwardTo"];
                string src = Request.Query["CLID"];
                string cname = Request.Query["CallerName"];
                string hangup = Request.Query["HangupCause"];
                string dialMusic = Request.Query["DialMusic"];
                string disableCall = Request.Query["DisableCall"];
                if ( String.IsNullOrEmpty(dst) )
                    dst = Request.Query["To"];
                if ( String.IsNullOrEmpty(src) )
                    src = Request.Query["From"];

                if (String.IsNullOrEmpty(cname))
                    cname = "";
                if ( !String.IsNullOrEmpty(hangup) )
                    return "SIP Route hangup callback";

                Plivo.XML.Response response = new Plivo.XML.Response();

                if ( String.IsNullOrEmpty(dst) ) {
                    Console.WriteLine("SIP Route cannot identify destination number");
                    response.AddHangup(new Dictionary<string, string> {
                        {"reason", "busy"},
                    });
                } else {
                    bool isSipUser = false;

                    if (dst.Length > 4 && dst.Substring(0, 4) == "sip:")
                        isSipUser = true;

                    if (isSipUser && disableCall == "all" || disableCall == "sip") {
                        Console.WriteLine(String.Format("SIP Route calling sip user is disabled : %s", disableCall));
                        response.AddHangup(new Dictionary<string, string>() {
                            { "reason", "busy" },
                        });
                    } else if (!isSipUser && disableCall == "all" || disableCall == "number") {
                        response.AddHangup(new Dictionary<string, string>() {
                            { "reason", "busy" },
                        });
                    } else {
                        Console.WriteLine(String.Format("SIP Route dialing %s", dst));

                        if (!String.IsNullOrEmpty(dialMusic) && isSipUser) {
                            var dial = response.AddDial(new Dictionary<string, string>() {
                                {"callerId", src},
                                {"callerName", cname},
                                {"dialMusic", dialMusic}
                            });
                            dial.AddUser(dst, new Dictionary<string, string>() { });
                            response.Add(dial);
                        } else if (String.IsNullOrEmpty(dialMusic) && isSipUser) {
                            var dial = new Plivo.XML.Dial(new Dictionary<string, string>() {
                                {"callerId", src},
                                {"callerName", cname},
                            });
                            dial.AddUser(dst, new Dictionary<string, string>() { });
                            response.Add(dial);
                        } else if (!String.IsNullOrEmpty(dialMusic) && !isSipUser) {
                            var dial = new Plivo.XML.Dial(new Dictionary<string, string>() {
                                {"callerId", src},
                                {"callerName", cname},
                                {"dialMusic", dialMusic},
                            });
                            dial.AddNumber(dst, new Dictionary<string, string>() { });
                            response.Add(dial);
                        } else if (String.IsNullOrEmpty(dialMusic) && !isSipUser) {
                            var dial = new Plivo.XML.Dial(new Dictionary<string, string>() {
                                {"callerId", src},
                                {"callerName", cname},
                            });
                            dial.AddUser(dst, new Dictionary<string, string>() { });
                            response.Add(dial);
                        }
                    }
                }
                Debug.WriteLine(response.ToString());

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