예제 #1
0
        public async Task <string> GatherCallback()
        {
            string json;

            using (var reader = new StreamReader(Request.Body))
            {
                json = await reader.ReadToEndAsync();
            }

            dynamic      gatherEvent  = JsonConvert.DeserializeObject <dynamic>(json);
            string       digits       = gatherEvent.digits;
            const string SUCCESS_FILE = "https://bw-demo.s3.amazonaws.com/tada.wav";
            const string FAIL_FILE    = "https://bw-demo.s3.amazonaws.com/fail.wav";

            string    media     = digits.Equals("11") ? SUCCESS_FILE : FAIL_FILE;
            PlayAudio playAudio = new PlayAudio();

            playAudio.Url = media;
            Hangup hangup = new Hangup();

            Response response = new Response();

            response.Add(playAudio);
            response.Add(hangup);

            string bxml = response.ToBXML();

            return(bxml);
        }
예제 #2
0
        public ActionResult MakeRecordMessageDone(RecordingUtteranceActionCallback recordingUtteranceStatusCallback)
        {
            // Create an empty PerCL script container
            PerCLScript script = new PerCLScript();

            if (Request != null)
            {
                // Check if recording was successful by checking if a recording identifier was provided
                if (recordingUtteranceStatusCallback.getRecordingId != null)
                {
                    // Recording was successful as recording identifier present in response

                    // Create PerCL say script with US English as the language
                    Say say = new Say();
                    say.setLanguage(ELanguage.EnglishUS);
                    // Set prompt to indicate message has been recorded
                    say.setText("Thanks. The message has been recorded.");

                    // Add PerCL say script to PerCL container
                    script.Add(say);
                }
                else
                {
                    // Recording was failed as there is no recording identifier present in response

                    // Create PerCL say script with US English as the language
                    Say say = new Say();
                    say.setLanguage(ELanguage.EnglishUS);
                    // Set prompt to indicate message recording failed
                    say.setText("Sorry we weren't able to record the message.");

                    // Add PerCL say script to PerCL container
                    script.Add(say);
                }

                // Create PerCL pause script with a duration of 100 milliseconds
                Pause pause = new Pause(100);

                // Add PerCL pause script to PerCL container
                script.Add(pause);

                // Create PerCL say script with US English as the language
                Say sayGoodbye = new Say();
                sayGoodbye.setLanguage(ELanguage.EnglishUS);
                // Set prompt sayGoodbye.setText("Goodbye");

                // Add PerCL say script to PerCL container
                script.Add(sayGoodbye);

                // Create PerCL hangup script
                Hangup hangup = new Hangup();

                // Add PerCL hangup script to PerCL container
                script.Add(new Hangup());
            }

            // Convert PerCL container to JSON and append to response
            return(Content(script.toJson(), "application/json"));
        }
예제 #3
0
        public void DefaultHangupCommandToJsonTest()
        {
            Hangup hangup = new Hangup();

            string json = hangup.toJson();

            Assert.IsNotNull(json);
            Assert.AreEqual(json, "{\"Hangup\":{}}");
        }
예제 #4
0
        public void TestEmptyElement()
        {
            var elem = new Hangup();

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Hangup></Hangup>",
                elem.ToString()
                );
        }
예제 #5
0
        /**
         * Initialize a "hangup" command.
         *
         * @return this
         */
        public Voice Hangup()
        {
            // initialize hangup
            Hangup hangup = new Hangup();

            // push to our commands
            this.rootArray.Add(hangup.GetAction());

            return(this);
        }
예제 #6
0
        public ActionResult SelectColorDone(GetSpeechActionCallback getSpeechStatusCallback)
        {
            // Create an empty PerCL script container
            PerCLScript script = new PerCLScript();

            // Check if recognition was successful
            if (getSpeechStatusCallback.getReason == ESpeechTermReason.Recognition)
            {
                // Create PerCL say script with US English as the language
                Say say = new Say();
                say.setLanguage(ELanguage.EnglishUS);
                // Set prompt to speak the selected color
                say.setText(string.Format("Selected color was {0}", (getSpeechStatusCallback.getRecognitionResult).ToLower()));

                // Add PerCL say script to PerCL container
                script.Add(say);
            }
            else
            {
                // Create PerCL say script with US English as the language
                Say say = new Say();
                say.setLanguage(ELanguage.EnglishUS);
                // Set prompt to indicated selection error
                say.setText("There was an error in selecting a color.");

                // Add PerCL say script to PerCL container
                script.Add(say);
            }

            // Create PerCL pause script with a duration of 100 milliseconds
            Pause pause = new Pause(100);

            // Add PerCL pause script to PerCL container
            script.Add(pause);

            // Create PerCL say script with US English as the language
            Say sayGoodbye = new Say();

            sayGoodbye.setLanguage(ELanguage.EnglishUS);
            // Set prompt
            sayGoodbye.setText("Goodbye");
            // Add PerCL say script to PerCL container
            script.Add(sayGoodbye);

            // Create PerCL hangup script
            Hangup hangup = new Hangup();

            // Add PerCL hangup script to PerCL container
            script.Add(new Hangup());

            // Convert PerCL container to JSON and append to response
            return(Content(script.toJson(), "application/json"));
        }
예제 #7
0
        public void TestElementWithTextNode()
        {
            var elem = new Hangup();

            elem.AddText("Here is the content");

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Hangup>Here is the content</Hangup>",
                elem.ToString()
                );
        }
예제 #8
0
        public void HangupCommandToJsonTest()
        {
            Hangup hangup = new Hangup();

            hangup.setCallId("12345");
            hangup.setReason("the reason");

            string json = hangup.toJson();

            Assert.IsNotNull(json);
            Assert.AreEqual(json, "{\"Hangup\":{\"callId\":\"12345\",\"reason\":\"the reason\"}}");
        }
        public override string ToString()
        {
            d = (Hangup)base.Tag;

            Binding descbinding = new Binding("Description");
            descbinding.Mode = BindingMode.TwoWay;
            descbinding.Source = d;
            txtdesc.SetBinding(TextBox.TextProperty, descbinding);


            return base.ToString();
        }
예제 #10
0
        public void TestElementWithExtraAttributes()
        {
            var elem = new Hangup();

            elem.SetOption("newParam1", "value");
            elem.SetOption("newParam2", 1);

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Hangup newParam1=\"value\" newParam2=\"1\"></Hangup>",
                elem.ToString()
                );
        }
        public override string ToString()
        {
            d = (Hangup)base.Tag;

            Binding descbinding = new Binding("Description");

            descbinding.Mode   = BindingMode.TwoWay;
            descbinding.Source = d;
            txtdesc.SetBinding(TextBox.TextProperty, descbinding);


            return(base.ToString());
        }
예제 #12
0
        public void TestMixedContent()
        {
            var elem = new Hangup();

            elem.AddText("before")
            .AddChild("Child").AddText("content");
            elem.AddText("after");

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Hangup>before<Child>content</Child>after</Hangup>",
                elem.ToString()
                );
        }
예제 #13
0
        public void TestAllowGenericChildNodes()
        {
            var elem = new Hangup();

            elem.AddChild("generic-tag").AddText("Content").SetOption("tag", true);

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Hangup>" + Environment.NewLine +
                "  <generic-tag tag=\"True\">Content</generic-tag>" + Environment.NewLine +
                "</Hangup>",
                elem.ToString()
                );
        }
        public ActionResult InboundCall(CallStatusCallback freeClimbRequest)
        {
            // Create an empty PerCL script container
            PerCLScript script = new PerCLScript();

            // Verify inbound call is in proper state
            if (freeClimbRequest.getCallStatus == ECallStatus.Ringing)
            {
                // Create PerCL say script with US English as the language
                Say say = new Say();
                say.setLanguage(ELanguage.EnglishUS);
                // Set prompt to record message
                say.setText("Hello. Thank you for invoking the accept incoming call tutorial.");

                // Add PerCL say script to PerCL container
                script.Add(say);

                // Create PerCL pause script with a duration of 100 milliseconds
                Pause pause = new Pause(100);

                // Add PerCL pause script to PerCL container
                script.Add(pause);

                // Create PerCL say script with US English as the language
                Say sayGoodbye = new Say();
                sayGoodbye.setLanguage(ELanguage.EnglishUS);
                // Set prompt
                sayGoodbye.setText("Goodbye.");

                // Add PerCL say script to PerCL container
                script.Add(sayGoodbye);

                // Create PerCL hangup script
                Hangup hangup = new Hangup();

                // Add PerCL hangup script to PerCL container
                script.Add(new Hangup());
            }
            // Convert PerCL container to JSON and append to response
            return(Content(script.toJson(), "application/json"));
        }
예제 #15
0
        static void TestVoice()
        {
            Header headers = new Header(
                new string[] { "x-sbc-from", "\"username\"<sip:[email protected]>;tag=2a648c6e" },
                new string[] { "x-sbc-allow", "BYE" },
                new string[] { "x-sbc-user-agent", "sipgw-1.0" },
                new string[] { "x-sbc-contact", "<sip:[email protected]:16000>" },
                new string[] { "Content-Length", "247" },
                new string[] { "To", "<sip:[email protected]:5060>" },
                new string[] { "Contact", "<sip:[email protected]:5060>" },
                new string[] { "x-sbc-request-uri", "sip:[email protected]:5060" },
                new string[] { "x-sbc-call-id", "OWE0OGFkMTE1ZGY4NTI1MmUzMjc1M2Y3Y2ExMzc2YhG." },
                new string[] { "x-sid", "39f4688b8896f024f3a3aebd0cfb40b2" },
                new string[] { "x-sbc-cseq", "1 INVITE" },
                new string[] { "x-sbc-max-forwards", "70" },
                new string[] { "CSeq", "2 INVITE" },
                new string[] { "Via", "SIP/2.0/UDP 66.190.50.10:5060;received=10.6.60.100" },
                new string[] { "x-sbc-record-route", "<sip:190.40.250.230:5061;r2=on;lr;ftag=2a648c6e>" },
                new string[] { "Call-ID", "0-13c4-4b7d8ff7-1c3c1b82-7935-1d10b081" },
                new string[] { "Content-Type", "application/sdp" },
                new string[] { "x-sbc-to", "<sip:[email protected]:5060>" },
                new string[] { "From", "<sip:[email protected]:5060>;tag=0-13c4-4b7d8ff7-1c3c1b82-5c7b" }
                );

            Ask ask = new Ask(
                INSTANCE(
                    new Choices(
                        VALUE("1"),
                        MODE(Mode.DTMF),
                        TERMINATOR("*")
                        )
                    ),
                ATTEMPTS(10),
                BARGEIN(true),
                MIN_CONFIDENCE(10),
                NAME("foo"),
                RECOGNIZER(Recognizer.US_ENGLISH),
                REQUIRED(false),
                INSTANCE(
                    new Say("Hello World")
                    ),
                TIMEOUT(10),
                VOICE(VoiceEnum.VICTOR),
                INTER_DIGIT_TIMEOUT(10),
                SENSITIVITY(10),
                SPEECH_COMPLETE_TIMEOUT(10),
                SPEECH_INCOMPLETE_TIMEOUT(10)
                );

            Print(ask.GetAction());

            Call call = new Call(
                TO("+123456"),
                ANSWER_ON_MEDIA(false),
                CHANNEL(Channel.VOICE),
                FROM("+123456"),
                INSTANCE(headers),
                NAME("call"),
                NETWORK(Network.SIP),
                INSTANCE(
                    new Record(
                        INSTANCE(new Say(VALUE("Hello World"), ARRAY(new Say("Hello World"))))
                        )
                    ),
                REQUIRED(true),
                TIMEOUT(10),
                ALLOW_SIGNALS(true),
                INSTANCE(
                    new MachineDetection(
                        INTRODUCTION("Hello World"),
                        VOICE(VoiceEnum.VICTOR)
                        )
                    )
                );

            Print(call.GetAction());

            Choices choices = new Choices(
                VALUE("[5 DIGITS]"),
                MODE(Mode.DTMF),
                TERMINATOR("#")
                );

            Print(choices.GetAction());

            Conference conference = new Conference(
                ID("12345"),
                MUTE(false),
                NAME("conference"),
                PLAY_TONES(false),
                REQUIRED(false),
                TERMINATOR("#"),
                ALLOW_SIGNALS(false),
                INTER_DIGIT_TIMEOUT(10),
                INSTANCE(new JoinPrompt(VALUE("Please welcome the monster to the party!"))),
                INSTANCE(new LeavePrompt(VALUE("The monster has decide to depart!")))
                );

            Print(conference.GetAction());

            Hangup hangup = new Hangup();

            Print(hangup.GetAction());

            MachineDetection md = new MachineDetection(
                INTRODUCTION("Hello World"),
                VOICE(VoiceEnum.VICTOR)
                );

            Print(md.GetAction());

            Message message = new Message(
                INSTANCE(new Say("Hello World")),
                TO("+63525544787"),
                ANSWER_ON_MEDIA(false),
                CHANNEL(Channel.TEXT),
                FROM("2542562"),
                NAME("message"),
                NETWORK(Network.JABBER),
                REQUIRED(false),
                TIMEOUT(60),
                VOICE(VoiceEnum.CARMEN)
                );

            Print(message.GetAction());

            On on = new On(
                EVENT("continue"),
                NAME("event"),
                NEXT("http://openovate.com/hello.php"),
                REQUIRED(false),
                INSTANCE(new Say("Hello World")),
                INSTANCE(ask),
                INSTANCE(message),
                INSTANCE(new Wait(MILLISECONDS(3000), ALLOW_SIGNALS(true)))
                );

            Print(on.GetAction());

            Record record = new Record(
                ATTEMPTS(10),
                BARGEIN(false),
                BEEP(false),
                INSTANCE(choices),
                FORMAT(Format.MP3),
                MAX_SILENCE(10),
                MAX_TIME(60),
                METHOD("POST"),
                MIN_CONFIDENCE(10),
                NAME("recording"),
                REQUIRED(false),
                INSTANCE(new Say("Hello World")),
                TIMEOUT(10),
                INSTANCE(
                    new Transcription(
                        ID("12345"),
                        URL("https//gmail.com"),
                        EMAIL_FORMAT("format")
                        )
                    ),
                URL("http://openovate.com/recording.js"),
                USERNAME("admin"),
                PASSWORD("admin"),
                VOICE(VoiceEnum.CARLOS),
                ALLOW_SIGNALS(false),
                INTER_DIGIT_TIMEOUT(10)
                );

            Print(record.GetAction());

            Redirect redirect = new Redirect(TO("+12345"), NAME("charles"), REQUIRED(false));

            Print(redirect.GetAction());

            Reject reject = new Reject();

            Print(reject.GetAction());

            Say say = new Say(
                VALUE("Hello World"),
                AS(As.DIGITS),
                NAME("say"),
                REQUIRED(false),
                VOICE(VoiceEnum.BERNARD),
                ALLOW_SIGNALS(false)
                );

            Print(say.GetAction());

            StartRecording sr = new StartRecording(
                FORMAT(Format.MP3),
                METHOD("POST"),
                URL("http://openovate.com/recording.js"),
                USERNAME("admin"),
                PASSWORD("admin"),
                TRANSCRIPTION_ID("12345"),
                TRANSCRIPTION_EMAIL_FORMAT("format"),
                TRANSCRIPTION_OUT_URI("http://openovate.com/recording.js")
                );

            Print(sr.GetAction());

            Transfer transfer = new Transfer(
                TO("+123456"),
                ANSWER_ON_MEDIA(false),
                INSTANCE(choices),
                FROM("12345"),
                INSTANCE(headers),
                NAME("transfer"),
                INSTANCE(
                    new On(ARRAY(
                               new On(
                                   EVENT("ring"),
                                   INSTANCE(new Say("http://www.phono.com/audio/holdmusic.mp3"))
                                   ),
                               new On(
                                   EVENT("connect"),
                                   INSTANCE(say)
                                   ))
                           )
                    ),
                REQUIRED(false),
                TERMINATOR("*"),
                TIMEOUT(10),
                ALLOW_SIGNALS(false),
                INTER_DIGIT_TIMEOUT(10),
                INSTANCE(md)
                );

            Print(transfer.GetAction());

            Wait wait = new Wait(
                MILLISECONDS(500),
                ALLOW_SIGNALS(true)
                );

            Print(wait.GetAction());

            string  resultJson   = @"{""result"":{""callId"":""8a2bd2f204f4488e22c099a21e900068"",""sequence"":1,""calledid"":""6391721584130"",""sessionId"":""a1e275877b5346c576ae309cb2e6d829"",""state"":""ANSWERED"",""sessionDuration"":10,""complete"":true,""error"":null,""actions"":{""disposition"":""SUCCESS"",""interpretation"":""52521"",""xml"":""<?xml version=\""1.0\""?>\r\n<result grammar=\""[email protected]\"">\r\n    <interpretation grammar=\""[email protected]\"" confidence=\""100\"">\r\n        \r\n      <input mode=\""dtmf\"">dtmf-5 dtmf-2 dtmf-5 dtmf-2 dtmf-1<\/input>\r\n    <\/interpretation>\r\n<\/result>\r\n"",""confidence"":100,""name"":""foo"",""value"":""52521"",""utterance"":""52521"",""attempts"":1}}}";
            JObject resultParsed = JObject.Parse(resultJson);

            Result result = new Result(resultParsed);

            Print(result.GetResult());

            string  sessionJson   = @"{""session"":{""callId"":""e9d6ea5c3e1f9cdf7bd6755df792128f"",""accountId"":""357"",""headers"":{""P-Asserted-Identity"":""<sip:[email protected]>"",""Call-ID"":""[email protected]"",""Session-Expires"":""1800"",""Max-Forwards"":""67"",""CSeq"":""22885 INVITE"",""Record-Route"":""<sip:54.251.186.109:5060;transport=udp;lr>"",""User-Agent"":""ZTE Softswitch/1.0.0"",""x-sid"":""d7cb81bdeef47e5d9520e3867e99dd2e"",""From"":""09065272450 <sip:[email protected]>;tag=aa38c01-u0HM7d7ee5c02"",""Supported"":""100rel"",""Contact"":""<sip:[email protected]:5060>"",""Allow"":""INVITE"",""Via"":""SIP/2.0/UDP 54.251.186.109:5060;branch=z9hG4bK6vnl2t62s715;rport=5060;received=172.31.28.102"",""Min-SE"":""90"",""To"":""21584130 <sip:[email protected]>"",""Content-Length"":""790"",""P-Charging-Vector"":""icid-value=Netun-20161125172901-00580505"",""Content-Type"":""application/sdp""},""initialText"":null,""from"":{""name"":""09065272450"",""channel"":""VOICE"",""id"":""6309065272450"",""network"":""SIP""},""id"":""27741ecb65b5c916eeded4039ae22396"",""userType"":""HUMAN"",""to"":{""name"":""21584130"",""channel"":""VOICE"",""id"":""6391721584130"",""network"":""SIP""},""timestamp"":""2016-11-25T09:29:01.129Z""}}";
            JObject sessionParsed = JObject.Parse(sessionJson);

            Session session = new Session(sessionParsed);

            Print(session.GetSession());

            VoiceBase voice = new VoiceBase();

            voice.Say("Hello World");
            voice.Wait();

            Print(voice.Render().ToString());
        }