public void TestAnswered()
        {
            var json            = @"
                {
                    ""from"":""442079460000"", 
                    ""to"":""447700900000"", 
                    ""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""status"":""answered"",
                    ""direction"":""outbound"",
                    ""timestamp"":""2020-01-01T12:00:00.000Z"",
                    ""start_time"":""2020-01-01T12:00:00.000Z"",
                    ""rate"":""0.02"",
                    ""network"":""1234""
                }";
            var answeredWebhook = (Answered)EventBase.ParseEvent(json);

            Assert.Equal("442079460000", answeredWebhook.From);
            Assert.Equal("447700900000", answeredWebhook.To);
            Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", answeredWebhook.Uuid);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", answeredWebhook.ConversationUuid);
            Assert.Equal("answered", answeredWebhook.Status);
            Assert.Equal(Direction.outbound, answeredWebhook.Direction);
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (answeredWebhook.TimeStamp));
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (answeredWebhook.StartTime));
            Assert.Equal("1234", answeredWebhook.Network);
            Assert.Equal("0.02", answeredWebhook.Rate);
        }
        public void TestRecord()
        {
            var json          = @"
                {
                    ""timestamp"":""2020-01-01T12:00:00.000Z"",
                    ""start_time"":""2020-01-01T12:00:00.000Z"",
                    ""end_time"":""2020-01-01T12:00:01.000Z"",
                    ""recording_url"":""https://api.nexmo.com/v1/files/bbbbbbbb-aaaa-cccc-dddd-0123456789ab"",
                    ""size"":12222,
                    ""recording_uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab""                    
                }";
            var recordWebhook = (Voice.EventWebhooks.Record)EventBase.ParseEvent(json);

            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (recordWebhook.TimeStamp));
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (recordWebhook.StartTime));
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:01.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (recordWebhook.EndTime));
            Assert.Equal("https://api.nexmo.com/v1/files/bbbbbbbb-aaaa-cccc-dddd-0123456789ab", recordWebhook.RecordingUrl);
            Assert.True(12222 == recordWebhook.Size);
            Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", recordWebhook.Uuid);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", recordWebhook.ConversationUuid);
        }
        public void TestSpeechMultiInputStruct()
        {
            var json = @"
                {
                    ""from"":""442079460000"",
                    ""to"":""447700900000"",
                    ""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""speech"":{""results"":[{""text"":""hello world"",""confidence"":"".91""}], ""error"":""foo"", ""timeout_reason"":""bar""},
                    ""timed_out"":""true"",
                    ""timestamp"":""2020-01-01T12:00:00.000Z""
                }";

            var inputWebhook = (MultiInput)EventBase.ParseEvent(json);

            Assert.Equal("442079460000", inputWebhook.From);
            Assert.Equal("447700900000", inputWebhook.To);
            Assert.Equal("hello world", inputWebhook.Speech.SpeechResults[0].Text);
            Assert.Equal(".91", inputWebhook.Speech.SpeechResults[0].Confidence);
            Assert.Equal("foo", inputWebhook.Speech.Error);
            Assert.Equal("bar", inputWebhook.Speech.TimeoutReason);
            Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", inputWebhook.Uuid);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", inputWebhook.ConversationUuid);
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (inputWebhook.TimeStamp));
        }
Exemplo n.º 4
0
        private Response OnEvent()
        {
            var body = Request.Body.AsString();
            var e    = EventBase.ParseEvent(body);

            Debug.WriteLine(e.ToString());
            return(Request.Query["status"]);
        }
        public async Task <IActionResult> Event()
        {
            // Read the incoming json and load it as the
            // proper C# type it represents ("Started", "Answered", etc.)
            var json   = await new StreamReader(this.Request.Body).ReadToEndAsync();
            var @event = (CallStatusEvent)EventBase.ParseEvent(json);

            using var session = this._store.OpenSession();
            await new CallAuditHandlers(session).Handle(@event);
            return(this.Ok());
        }
        public void TestError()
        {
            var json         = @"
                {
                    ""reason"":""Syntax error in NCCO. Invalid value type or action."",                    
                    ""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""timestamp"":""2020-01-01T12:00:00.000Z""
                }";
            var errorWebhook = (Error)EventBase.ParseEvent(json);

            Assert.Equal("Syntax error in NCCO. Invalid value type or action.", errorWebhook.Reason);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", errorWebhook.ConversationUuid);
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (errorWebhook.TimeStamp));
        }
        public void TestTransfer()
        {
            var json            = @"
                {
                    ""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid_from"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid_to"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""timestamp"":""2020-01-01T12:00:00.000Z""
                }";
            var transferWebhook = (Transfer)EventBase.ParseEvent(json);

            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", transferWebhook.ConversationUuidFrom);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", transferWebhook.ConversationUuidTo);
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (transferWebhook.TimeStamp));
            Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", transferWebhook.Uuid);
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
0
        private Response GetDTMFInput()
        {
            var input = EventBase.ParseEvent(Request.Body.AsString()) as Input;

            var talkNcco = new TalkAction();

            if (input != null)
            {
                talkNcco.Text = $"You pressed {input.Dtmf}";
            }
            else
            {
                talkNcco.Text = "No input received";
            }

            var ncco = new Ncco(talkNcco);

            return(ncco.ToString());
        }
        public void TestHumanMachine(string type)
        {
            var json = @"
                {
                    ""from"":""442079460000"", 
                    ""to"":""447700900000"", 
                    ""call_uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""status"":""" + type + @""",
                    ""direction"":""outbound"",
                    ""timestamp"":""2020-01-01T12:00:00.000Z""
                }";
            var humanMachineWebhook = (HumanMachine)EventBase.ParseEvent(json);

            Assert.Equal("442079460000", humanMachineWebhook.From);
            Assert.Equal("447700900000", humanMachineWebhook.To);
            Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", humanMachineWebhook.Uuid);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", humanMachineWebhook.ConversationUuid);
            Assert.Equal(type, humanMachineWebhook.Status);
            Assert.Equal(Direction.outbound, humanMachineWebhook.Direction);
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (humanMachineWebhook.TimeStamp));
        }
        public void TestInputOld()
        {
            var json = @"
                {
                    ""from"":""442079460000"", 
                    ""to"":""447700900000"", 
                    ""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
                    ""dtmf"":""42"",
                    ""timed_out"":""true"",
                    ""timestamp"":""2020-01-01T12:00:00.000Z""
                }";

            var inputWebhook = (Input)EventBase.ParseEvent(json);

            Assert.Equal("442079460000", inputWebhook.From);
            Assert.Equal("447700900000", inputWebhook.To);
            Assert.Equal("42", inputWebhook.Dtmf);
            Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", inputWebhook.Uuid);
            Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", inputWebhook.ConversationUuid);
            Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
                                             DateTimeStyles.AdjustToUniversal), (inputWebhook.TimeStamp));
        }
 public void TestEmpty()
 {
     Assert.Null(EventBase.ParseEvent("{}"));
 }