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";
            };
        }
示例#2
0
        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";
            };
        }
 static void Main(string[] args)
 {
     Response resp = new Response();
     resp.AddSpeak("Hi, Plivo calling", new Dictionary<string, string>() {
         { "language", "en-US" },
         { "voice", "WOMAN" }
     });
     resp.AddPlay("http://examples.com/play/Trumpet.mp3", new Dictionary<string, string>() {
         { "loop", "2" }
     });
     resp.AddWait(new Dictionary<string, string>() {
         { "length", "3" }
     });
     Console.WriteLine(resp.ToString());
 }
示例#5
0
        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()
        {
            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";
            };
        }
        public Program()
        {
            Get["/basic_wait"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add Speak XML Tag
                resp.AddSpeak("I will wait for 10 seconds", new Dictionary<string, string>() { });

                // Add Wait XML Tag
                resp.AddWait(new Dictionary<string, string>()
                {
                    {"length", "10"}
                });

                // Add Speak XML Tag
                resp.AddSpeak("I just waited 10 seconds", new Dictionary<string, string>() { });

                Debug.WriteLine(resp.ToString());

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

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

                // Add Wait XML Tag
                resp.AddWait(new Dictionary<string, string>()
                {
                    {"length", "10"}
                });

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

                Debug.WriteLine(resp.ToString());

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

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

                // Add Wait XML Tag
                resp.AddWait(new Dictionary<string, string>()
                {
                    {"length", "100"},
                    {"beep", "true"}
                });

                // Add Speak XML Tag
                resp.AddSpeak("Hello", 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["/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");
            };
        }
        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";
            };
        }
示例#10
0
        public Program()
        {
            Get["/basic_wait"] = x =>
            {
                Plivo.XML.Response resp = new Plivo.XML.Response();

                // Add Speak XML Tag
                resp.AddSpeak("I will wait for 10 seconds", new Dictionary <string, string>()
                {
                });

                // Add Wait XML Tag
                resp.AddWait(new Dictionary <string, string>()
                {
                    { "length", "10" }
                });

                // Add Speak XML Tag
                resp.AddSpeak("I just waited 10 seconds", new Dictionary <string, string>()
                {
                });

                Debug.WriteLine(resp.ToString());

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

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

                // Add Wait XML Tag
                resp.AddWait(new Dictionary <string, string>()
                {
                    { "length", "10" }
                });

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

                Debug.WriteLine(resp.ToString());

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

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

                // Add Wait XML Tag
                resp.AddWait(new Dictionary <string, string>()
                {
                    { "length", "100" },
                    { "beep", "true" }
                });

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

                Debug.WriteLine(resp.ToString());

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