public IActionResult Answer()
        {
            var TO_NUMBER     = Environment.GetEnvironmentVariable("TO_NUMBER") ?? "TO_NUMBER";
            var VONAGE_NUMBER = Environment.GetEnvironmentVariable("VONAGE_NUMBER") ?? "VONAGE_NUMBER";
            var host          = Request.Host.ToString();
            //Uncomment the next line if using ngrok with --host-header option
            //host = Request.Headers["X-Original-Host"];
            var sitebase = $"{Request.Scheme}://{host}";

            var recordAction = new RecordAction()
            {
                EventUrl    = new string[] { $"{sitebase}/recordcall/webhooks/recording" },
                EventMethod = "POST"
            };

            var connectAction = new ConnectAction()
            {
                From = VONAGE_NUMBER, Endpoint = new[] { new PhoneEndpoint {
                                                             Number = TO_NUMBER
                                                         } }
            };

            var ncco = new Ncco(recordAction, connectAction);

            return(Ok(ncco.ToString()));
        }
Esempio n. 2
0
        public IActionResult Answer()
        {
            var TO_NUMBER     = Environment.GetEnvironmentVariable("TO_NUMBER") ?? "TO_NUMBER";
            var VONAGE_NUMBER = Environment.GetEnvironmentVariable("VONAGE_NUMBER") ?? "VONAGE_NUMBER";
            var host          = Request.Host.ToString();
            //Uncomment the next line if using ngrok with --host-header option
            //host = Request.Headers["X-Original-Host"];

            var eventUrl   = $"{Request.Scheme}://{host}/SplitAudio/webhooks/recording";
            var talkAction = new TalkAction {
                Text = "recording call", BargeIn = "false"
            };
            var recordAction = new RecordAction()
            {
                EventUrl    = new string[] { eventUrl },
                EventMethod = "POST",
                Channels    = 2,
                Split       = "conversation"
            };

            var connectAction = new ConnectAction()
            {
                From     = VONAGE_NUMBER,
                Endpoint = new[] { new PhoneEndpoint {
                                       Number = TO_NUMBER
                                   } },
            };

            var ncco = new Ncco(talkAction, recordAction, connectAction);

            return(Ok(ncco.ToString()));
        }
Esempio n. 3
0
        public void TestSerializeNccoKitchenSink()
        {
            // arrage
            var expected = @"[{""dtmf"":{""timeOut"":3,""maxDigits"":1,""submitOnHash"":true},""speech"":{""uuid"":[""aaaaaaaa-bbbb-cccc-dddd-0123456789ab""],""endOnSilence"":1,""language"":""en-US"",""context"":[""dog"",""cat""],""startTimeout"":5,""maxDuration"":30},""action"":""input""}]";
            var settings = new SpeechSettings
            {
                Uuid         = new[] { "aaaaaaaa-bbbb-cccc-dddd-0123456789ab" },
                EndOnSilence = 1,
                Language     = "en-US",
                Context      = new string[] { "dog", "cat" },
                StartTimeout = 5,
                MaxDuration  = 30
            };
            var dtmfSettings = new DtmfSettings {
                MaxDigits = 1, TimeOut = 3, SubmitOnHash = true
            };
            var inputAction = new MultiInputAction {
                Speech = settings, Dtmf = dtmfSettings
            };

            //act
            var ncco   = new Ncco(inputAction);
            var actual = ncco.ToString();

            //assert
            Assert.Equal(expected, actual);
        }
Esempio n. 4
0
        private Response OnAnswerRecordingSplitAudio()
        {
            string TO_NUMBER    = "TO_NUMBER";
            string NEXMO_NUMBER = "NEXMO_NUMBER";

            var recordAction = new RecordAction()
            {
                Split    = "conversation",
                Channels = 2,
                EventUrl = new [] { $"{SiteBase}/webhook/record" }
            };
            var phoneEndpoint = new PhoneEndpoint()
            {
                Number = TO_NUMBER
            };
            var connectAction = new ConnectAction()
            {
                From     = NEXMO_NUMBER,
                Endpoint = new [] { phoneEndpoint }
            };

            var ncco = new Ncco(recordAction, connectAction);

            return(ncco.ToString());
        }
Esempio n. 5
0
        public IActionResult Answer()
        {
            var host = Request.Host.ToString();
            //Uncomment the next line if using ngrok with --host-header option
            //host = Request.Headers["X-Original-Host"];
            var sitebase       = $"{Request.Scheme}://{host}";
            var outGoingAction = new TalkAction()
            {
                Text = "Please leave a message after the tone, then press #. We will get back to you as soon as we can"
            };
            var recordAction = new RecordAction()
            {
                EventUrl     = new string[] { $"{sitebase}/recordmessage/webhooks/recording" },
                EventMethod  = "POST",
                EndOnSilence = "3",
                EndOnKey     = "#",
                BeepStart    = "true"
            };
            var thankYouAction = new TalkAction {
                Text = "Thank you for your message. Goodbye"
            };
            var ncco = new Ncco(outGoingAction, recordAction, thankYouAction);

            return(Ok(ncco.ToString()));
        }
        public void TestConnect()
        {
            var expectedJson  = @"[{""endpoint"":[{""number"":""447700900001"",""dtmfAnswer"":""2p02p"",""onAnswer"":{""url"":""https://example.com/answer"",""ringbackTone"":""http://example.com/ringbackTone.wav""},""type"":""phone""}],""from"":""447700900000"",""eventType"":""synchronous"",""timeout"":""60"",""limit"":""7200"",""machineDetection"":""continue"",""eventUrl"":[""https://exampe.com/webhooks/events""],""eventMethod"":""POST"",""ringbackTone"":""http://example.com/ringbackTone.wav"",""action"":""connect""}]";
            var connectAction = new ConnectAction
            {
                Endpoint = new[]
                {
                    new PhoneEndpoint
                    {
                        Number     = "447700900001",
                        DtmfAnswer = "2p02p",
                        OnAnswer   = new PhoneEndpoint.Answer
                        {
                            Url          = "https://example.com/answer",
                            RingbackTone = "http://example.com/ringbackTone.wav"
                        }
                    }
                },
                From             = "447700900000",
                EventType        = "synchronous",
                Timeout          = "60",
                Limit            = "7200",
                MachineDetection = "continue",
                EventUrl         = new[] { "https://exampe.com/webhooks/events" },
                RingbackTone     = "http://example.com/ringbackTone.wav",
                EventMethod      = "POST"
            };
            var ncco = new Ncco(connectAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
Esempio n. 7
0
        public IActionResult Answer()
        {
            var host = Request.Host.ToString();
            //Uncomment the next line if using ngrok with --host-header option
            //host = Request.Headers["X-Original-Host"];

            var eventUrl = $"{Request.Scheme}://{host}/webhooks/notification";

            var talkAction = new TalkAction()
            {
                Text = "Thanks for calling the notification line"
            };
            var notifyAction = new NotifyAction()
            {
                EventUrl = new[] { eventUrl },
                Payload  = new FooBar()
                {
                    Foo = "bar"
                }
            };
            var talkAction2 = new TalkAction()
            {
                Text = "You will never hear me as the notification URL will return an NCCO"
            };
            var ncco = new Ncco(talkAction, notifyAction, talkAction2);

            return(Ok(ncco.ToString()));
        }
Esempio n. 8
0
        public string AnswerForTrackInProgressNCCO()
        {
            var talkAction = new TalkAction()
            {
                Text = "This is a text to speech call from Nexmo"
            };

            var payload = new Foo()
            {
                Bar = "Bar"
            };

            var nofityAction = new NotifyAction()
            {
                EventUrl = new[] { $"{SITE_BASE}/voice/Notify" },
                Payload  = payload
            };

            var talkAction2 = new TalkAction()
            {
                Text = "You'll never hear this talk action because the notification handler will return an NCCO"
            };

            var ncco = new Ncco(talkAction, nofityAction, talkAction2);

            return(ncco.ToString());
        }
        public string TrackCall()
        {
            var talkAction = new TalkAction
            {
                Text = "This call will be tracked and stored using event sourcing."
            };
            var ncco = new Ncco(talkAction);

            return(ncco.ToString());
        }
Esempio n. 10
0
        public string Notify()
        {
            var talkAction = new TalkAction()
            {
                Text = "Hello, This is the talk action from the notify NCCO."
            };
            var ncco = new Ncco(talkAction);

            return(ncco.ToString());
        }
Esempio n. 11
0
        public async Task <IActionResult> OnInput()
        {
            var input = await WebhookParser.ParseWebhookAsync <MultiInput>(Request.Body, Request.ContentType);

            var talkAction = new TalkAction();

            talkAction.Text = input.Speech.SpeechResults[0].Text;
            var ncco = new Ncco(talkAction);

            return(Ok(ncco.ToString()));
        }
        public async Task <IActionResult> Dtmf()
        {
            var input      = WebhookParser.ParseWebhook <MultiInput>(Request.Body, Request.ContentType);
            var talkAction = new TalkAction()
            {
                Text = $"You Pressed {input?.Dtmf.Digits}, goodbye"
            };
            var ncco = new Ncco(talkAction);

            return(Ok(ncco.ToString()));
        }
        public void TestTalkBareBones()
        {
            var expectedJson = @"[{""text"":""Hello World"",""action"":""talk""}]";
            var talkAction   = new TalkAction
            {
                Text = "Hello World"
            };
            var ncco = new Ncco(talkAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
        public string Answer()
        {
            var talkAction = new TalkAction()
            {
                Text = $"Thank you for calling from " +
                       $"{string.Join(" ", Request.Query["from"].ToString().ToCharArray())}"
            };
            var ncco = new Ncco(talkAction);

            return(ncco.ToString());
        }
Esempio n. 15
0
        private Response OnAnswerInboundCall()
        {
            string number     = Request.Query["from"].Value;
            var    talkAction = new TalkAction()
            {
                Text      = ("Thank you for calling from " + string.Join(" ", number.ToCharArray())),
                VoiceName = "Kimberly"
            };
            var ncco = new Ncco(talkAction);

            return(ncco.ToString());
        }
        public string Answer()
        {
            var streamAction = new StreamAction {
                StreamUrl = new string[]
                {
                    STREAM_URL
                }
            };
            var ncco = new Ncco(streamAction);

            return(ncco.ToString());
        }
Esempio n. 17
0
        public async Task <IActionResult> Notify()
        {
            var notification = await WebhookParser.ParseWebhookAsync <Notification <FooBar> >(Request.Body, Request.ContentType);

            Console.WriteLine($"Notification received payload's foo = {notification.Payload.Foo}");
            var talkAction = new TalkAction()
            {
                Text = "Your notification has been received, loud and clear"
            };
            var ncco = new Ncco(talkAction);

            return(Ok(ncco.ToString()));
        }
        public async Task <ActionResult> Dtmf()
        {
            var input = await WebhookParser.ParseWebhookAsync <MultiInput>
                            (Request.Body, Request.ContentType);

            var talkAction = new TalkAction
            {
                Text = $"Thank you for inputing: {input.Dtmf.Digits}"
            };
            var ncco = new Ncco(talkAction);

            return(Ok(ncco.ToString()));
        }
        public void TestStream()
        {
            var expectedJson = @"[{""streamUrl"":[""https://acme.com/streams/music.mp3""],""level"":""0"",""bargeIn"":""true"",""loop"":""2"",""action"":""stream""}]";
            var talkAction   = new StreamAction
            {
                StreamUrl = new[] { "https://acme.com/streams/music.mp3" },
                BargeIn   = "true",
                Loop      = "2",
                Level     = "0",
            };
            var ncco = new Ncco(talkAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
        public void TestTalk()
        {
            var expectedJson = @"[{""text"":""Hello World"",""bargeIn"":""true"",""loop"":""2"",""level"":""0"",""voiceName"":""kimberly"",""action"":""talk""}]";
            var talkAction   = new TalkAction
            {
                Text      = "Hello World",
                BargeIn   = "true",
                Loop      = "2",
                Level     = "0",
                VoiceName = "kimberly"
            };
            var ncco = new Ncco(talkAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
        public void TestInput()
        {
            var expectedJson = @"[{""timeOut"":""3"",""maxDigits"":4,""submitOnHash"":""true"",""eventUrl"":[""https://example.com/ivr""],""eventMethod"":""POST"",""action"":""input""}]";
            var inputAction  = new InputAction
            {
                TimeOut      = "3",
                MaxDigits    = 4,
                SubmitOnHash = "true",
                EventUrl     = new[] { "https://example.com/ivr" },
                EventMethod  = "POST"
            };
            var ncco = new Ncco(inputAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
Esempio n. 22
0
        public string Answer()
        {
            var CONF_NAME  = Environment.GetEnvironmentVariable("CONF_NAME") ?? "CONF_NAME";
            var talkAction = new TalkAction()
            {
                Text = "Please wait while we connect you to the conference"
            };
            var conversationAction = new ConversationAction()
            {
                Name = CONF_NAME
            };
            var ncco = new Ncco(talkAction, conversationAction);

            return(ncco.ToString());
        }
        public string OnInput()
        {
            MultiInput input;

            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                var result = reader.ReadToEndAsync().Result;
                input = JsonConvert.DeserializeObject <MultiInput>(result);
            }
            var talkAction = new TalkAction();

            talkAction.Text = input.Speech.SpeechResults[0].Text;
            var ncco = new Ncco(talkAction);

            return(ncco.ToString());
        }
        public void TestNotify()
        {
            var expectedJson = @"[{""payload"":{""Bar"":""foo""},""eventUrl"":[""https://example.com/webhooks/events""],""eventMethod"":""POST"",""action"":""notify""}]";
            var notifyAction = new NotifyAction
            {
                EventMethod = "POST",
                Payload     = new Foo
                {
                    Bar = "foo"
                },
                EventUrl = new[] { "https://example.com/webhooks/events" }
            };
            var ncco = new Ncco(notifyAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
Esempio n. 25
0
        private Response OnAnswerConference()
        {
            var talkNcco = new TalkAction()
            {
                Text      = "Hello. You will now be added to the conference call.",
                VoiceName = "Emma"
            };

            var conferenceNcco = new ConversationAction()
            {
                Name = "conference-call"
            };

            var ncco = new Ncco(talkNcco, conferenceNcco);

            return(ncco.ToString());
        }
        public void TestConversation()
        {
            var expectedJson       = @"[{""name"":""vonage-conference-standard"",""musicOnHoldUrl"":[""https://example.com/music.mp3""],""startOnEnter"":""true"",""endOnExit"":""false"",""record"":""true"",""canSpeak"":[""6a4d6af0-55a6-4667-be90-8614e4c8e83c""],""canHear"":[""6a4d6af0-55a6-4667-be90-8614e4c8e83c""],""action"":""conversation""}]";
            var conversationAction = new ConversationAction
            {
                Name           = "vonage-conference-standard",
                MusicOnHoldUrl = new[] { "https://example.com/music.mp3" },
                StartOnEnter   = "true",
                EndOnExit      = "false",
                Record         = "true",
                CanSpeak       = new[] { "6a4d6af0-55a6-4667-be90-8614e4c8e83c" },
                CanHear        = new[] { "6a4d6af0-55a6-4667-be90-8614e4c8e83c" }
            };
            var ncco = new Ncco(conversationAction);

            Assert.Equal(expectedJson, ncco.ToString());
        }
Esempio n. 27
0
        private Response OnAnswerDtmf()
        {
            var talkAction = new TalkAction()
            {
                Text = "Hello. Please Press Any Key To continue"
            };

            var inputAction = new InputAction()
            {
                MaxDigits = "1",
                TimeOut   = "6",
                EventUrl  = new [] { $"{SiteBase}/webhook/dtmf" }
            };

            var ncco = new Ncco(talkAction, inputAction);

            return(ncco.ToString());
        }
Esempio n. 28
0
        public void TestSerializeNccoKitchenEmpty()
        {
            // arrage
            var expected = @"[{""dtmf"":{},""speech"":{""uuid"":[""aaaaaaaa-bbbb-cccc-dddd-0123456789ab""]},""action"":""input""}]";
            var settings = new SpeechSettings
            {
                Uuid = new[] { "aaaaaaaa-bbbb-cccc-dddd-0123456789ab" }
            };
            var inputAction = new MultiInputAction {
                Speech = settings
            };

            //act
            var ncco   = new Ncco(inputAction);
            var actual = ncco.ToString();

            //assert
            Assert.Equal(expected, actual);
        }
Esempio n. 29
0
        private string OnRecordComplete()
        {
            var recordEvent = EventBase.ParseEvent(Request.Body.AsString()) as Record;

            if (recordEvent != null)
            {
                Debug.WriteLine($"Recording URL: {recordEvent.RecordingUrl}");
            }

            var talkAction = new TalkAction()
            {
                Text      = "Thank you for calling in the recording is now finished, have a nice day",
                VoiceName = "Kimberly"
            };

            var ncco = new Ncco(talkAction);

            return(ncco.ToString());
        }
Esempio n. 30
0
        public IActionResult Answer()
        {
            var CONF_NAME = Environment.GetEnvironmentVariable("CONF_NAME") ?? "CONF_NAME";
            var host      = Request.Host.ToString();
            //Uncomment the next line if using ngrok with --host-header option
            //host = Request.Headers["X-Original-Host"];
            var sitebase = $"{Request.Scheme}://{host}";

            var conversationAction = new ConversationAction()
            {
                Name        = CONF_NAME, Record = "true",
                EventMethod = "POST",
                EventUrl    = new string[] { $"{sitebase}/recordconversation/webhooks/recording" }
            };
            var ncco = new Ncco(conversationAction);
            var json = ncco.ToString();

            return(Ok(json));
        }