Esempio n. 1
0
        private Task <Workflow> HandleRecordOutcome(ConversationResult conversationResult, RecordOutcome recordOutcome, Task <Stream> recordedContent)
        {
            var outcomeEvent = new RecordOutcomeEvent(conversationResult, CreateInitialWorkflow(), recordOutcome, recordedContent);
            var eventHandler = OnRecordCompleted;

            return(InvokeHandlerIfSet(eventHandler, outcomeEvent));
        }
Esempio n. 2
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(EndingMessage),
                new Hangup {
                    OperationId = Guid.NewGuid().ToString()
                }
            };

            // Convert the audio to text
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var    record = await recordOutcomeEvent.RecordedContent;
                string text   = await this.GetTextFromAudioAsync(record);

                StockBot2.StockLUIS Data = new StockBot2.StockLUIS();
                Data = await GetEntityFromLUIS(text);

                var callState = this.callStateMap[recordOutcomeEvent.ConversationResult.Id];

                await this.SendSTTResultToUser("We detected the following audio: " + Data.entities[0].entity, callState.Participants);
            }

            recordOutcomeEvent.ResultingWorkflow.Links = null;
            this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
        }
Esempio n. 3
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            // Convert the audio to text
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var    record = await recordOutcomeEvent.RecordedContent;
                string text   = await this.GetTextFromAudioAsync(record);

                var callState = this.callStateMap[recordOutcomeEvent.ConversationResult.Id];
                AddToTranscript(botUser, text);

                if (counter == 1)
                {
                    text = $"ok. I think you said *'{text}'*. Please say something else and I can repeat after you?";
                    recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                    {
                        GetRecordForText(text)
                    };
                }
                if (counter == 2)
                {
                    text = $"ok. This time you said *'{text}'*. Lets try something different! Say 'Yes' if you want to know the current weather condition, otherwise say 'No'";
                    recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                    {
                        CreateIvrOptions(text, 2, false)
                    };
                }

                counter++;
                AddToTranscript(botName, text);
            }
            else
            {
            }
        }
Esempio n. 4
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            Trace.TraceInformation(DateTime.Now + " RecordCompleted " + recordOutcomeEvent.ConversationResult.Id);

            // Convert the audio to text
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var text = await GetResultFromRecording(recordOutcomeEvent);

                var client = new DirectLineClient(directLineSecret);

                var callState = this.callStateMap[recordOutcomeEvent.ConversationResult.Id];

                Activity userMessage = GenerateActivity(text, callState);
                Trace.TraceInformation(DateTime.Now + " Posting message to message controller");
                // The result below contains the conversationId, as well as an incrementing number for each back and forth
                var resulttt = await client.Conversations.PostActivityAsync(callState.Conversation.ConversationId, userMessage);

                var actionList = await GetActionListOnRecordCompleted(client, callState);

                recordOutcomeEvent.ResultingWorkflow.Actions = actionList;
            }

            //recordOutcomeEvent.ResultingWorkflow.Links = null;
            //this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
        }
        private Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            var id = Guid.NewGuid().ToString();

            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(IvrOptions.Ending),
                new Hangup {
                    OperationId = id
                }
            };

            var        conversationId  = recordOutcomeEvent.ConversationResult.Id;
            var        recordedContent = recordOutcomeEvent.RecordedContent.Result;
            BingSpeech bs = new BingSpeech(
                async t =>
            {
                this._callStateMap[conversationId].SpeechToTextPhrase = t;
                // The below is not always guaranteed
                var url = "https://skype.botframework.com";

                // create a channel account for user
                var userAccount = new ChannelAccount(caller.Identity, caller.DisplayName);

                // create a channel account for bot
                var botAccount = new ChannelAccount(callee.Identity, callee.DisplayName);

                // authentication
                var account = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"].ToString(),
                                                          ConfigurationManager.AppSettings["MicrosoftAppPassword"].ToString());
                var connector = new ConnectorClient(new Uri(url), account);

                // This is required for Microsoft App Credentials to trust the outgoing message
                // This is automatically done for incoming messages, since we are initiating a proactive message
                // the service url should be trustable
                MicrosoftAppCredentials.TrustServiceUrl(url, DateTime.Now.AddDays(7));

                // Create a direct line connection with the user for proactive communication
                var conversation         = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);
                IMessageActivity message = Activity.CreateMessageActivity();
                message.From             = botAccount;
                message.Recipient        = userAccount;
                message.Conversation     = new ConversationAccount(id: conversation.Id);
                // send the message, remember the call is dropped by now. You can design your in a way
                // that you can seek confirmation from the user on the converted text
                message.Text   = string.Format("Your comment has been recorded. Thanks for calling: {0}, Complaint Id: {1}", t, conversationId);
                message.Locale = "en-us";
                await connector.Conversations.SendToConversationAsync((Activity)message);
                this._callStateMap.Remove(conversationId);
            },
                t => Console.WriteLine("Bing Speech to Text failed with error: " + t)
                );

            bs.CreateDataRecoClient();
            bs.SendAudioHelper(recordedContent);
            recordOutcomeEvent.ResultingWorkflow.Links = null;
            //_callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
            return(Task.FromResult(true));
        }
Esempio n. 6
0
 private void HangUpCall(RecordOutcomeEvent recordOutcomeEvent, string hangupMessage)
 {
     recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
     {
         GetPromptForText(hangupMessage),
         new Hangup {
             OperationId = Guid.NewGuid().ToString()
         }
     };
     callerId = null;
     recordOutcomeEvent.ResultingWorkflow.Links = null;
     this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
 }
Esempio n. 7
0
        private Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            var id = Guid.NewGuid().ToString();

            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(IvrOptions.Ending),
                new Hangup {
                    OperationId = id
                }
            };
            recordOutcomeEvent.ResultingWorkflow.Links = null;
            _callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
            return(Task.FromResult(true));
        }
Esempio n. 8
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var    record = await recordOutcomeEvent.RecordedContent;
                string path   = HttpContext.Current.Server.MapPath($"~/{recordOutcomeEvent.RecordOutcome.Id}.wma");

                System.Diagnostics.Debug.WriteLine($"\r\n\r\nType of the recording: >>> {record.GetType()} \r\n\r\n");

                using (var writer = new FileStream(path, FileMode.Create))
                {
                    await record.CopyToAsync(writer);
                }
            }

            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                CreateIvrOptions("Recorded! Press 1 to record your voice again, Press 2 to hangup.", 2, false)
            };
        }
Esempio n. 9
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            List <ActionBase> actions = new List <ActionBase>();

            var spokenText = string.Empty;

            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var record = await recordOutcomeEvent.RecordedContent;
                spokenText = await this.speechService.GetTextFromAudioAsync(record);

                actions.Add(new PlayPrompt {
                    OperationId = Guid.NewGuid().ToString(), Prompts = new List <Prompt> {
                        new Prompt {
                            Value = "Thanks for leaving the message."
                        }, new Prompt {
                            Value = "You said... " + spokenText
                        }
                    }
                });
            }
            else
            {
                actions.Add(new PlayPrompt {
                    OperationId = Guid.NewGuid().ToString(), Prompts = new List <Prompt> {
                        new Prompt {
                            Value = "Sorry, there was an issue. "
                        }
                    }
                });
            }

            actions.Add(new Hangup {
                OperationId = Guid.NewGuid().ToString()
            });                                                                  // hang up the call

            recordOutcomeEvent.ResultingWorkflow.Actions = actions;
            recordOutcomeEvent.ResultingWorkflow.Links   = null;
        }
Esempio n. 10
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            List <ActionBase> actions = new List <ActionBase>();

            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(EndingMessage),
                new Hangup {
                    OperationId = Guid.NewGuid().ToString()
                }
            };

            // Convert the audio to text
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var    record     = await recordOutcomeEvent.RecordedContent;
                string spokenText = await this.GetTextFromAudioAsync(record);

                actions.Add(new PlayPrompt {
                    OperationId = Guid.NewGuid().ToString(), Prompts = new List <Prompt> {
                        new Prompt {
                            Value = "Thanks for leaving the message."
                        }, new Prompt {
                            Value = "You said... " + spokenText
                        }
                    }
                });

                var callState = this.callStateMap[recordOutcomeEvent.ConversationResult.Id];
                var from      = callState.Participants.First(x => !x.Originator);

                await this.SendSTTResultToUser("We detected the following audio: " + spokenText + " : " + from, callState.Participants);
            }

            recordOutcomeEvent.ResultingWorkflow.Actions = actions;

            recordOutcomeEvent.ResultingWorkflow.Links = null;
            this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
        }
Esempio n. 11
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var record = await recordOutcomeEvent.RecordedContent;
                var bs     = new BotBingSpeech(recordOutcomeEvent.ConversationResult, t => _response.Add(t),
                                               s => _sttFailed = s, () => _rootDialog);
                bs.CreateDataRecoClient();
                bs.SendAudioHelper(record);

                recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                {
                    GetSilencePrompt()
                };
            }
            else
            {
                if (_silenceTimes > 1)
                {
                    recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                    {
                        GetPromptForText("Obrigado por sua ligação."),
                        new Hangup {
                            OperationId = Guid.NewGuid().ToString()
                        }
                    };
                    recordOutcomeEvent.ResultingWorkflow.Links = null;
                    _silenceTimes = 0;
                }
                else
                {
                    _silenceTimes++;
                    recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                    {
                        GetRecordForText("Não entendi, poderia repetir?")
                    };
                }
            }
        }
Esempio n. 12
0
 private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
 {
     if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
     {
         var        record = await recordOutcomeEvent.RecordedContent;
         BingSpeech bs     = new BingSpeech(recordOutcomeEvent.ConversationResult, t => response.Add(t), s => sttFailed = s);
         bs.CreateDataRecoClient();
         bs.SendAudioHelper(record);
         recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
         {
             GetSilencePrompt()
         };
     }
     else
     {
         if (silenceTimes > 1)
         {
             recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
             {
                 GetPromptForText("Thank you for calling"),
                 new Hangup()
                 {
                     OperationId = Guid.NewGuid().ToString()
                 }
             };
             recordOutcomeEvent.ResultingWorkflow.Links = null;
             silenceTimes = 0;
         }
         else
         {
             silenceTimes++;
             recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
             {
                 GetRecordForText("I didn't catch that, would you kinly repeat?")
             };
         }
     }
 }
Esempio n. 13
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            var id = Guid.NewGuid().ToString();

            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(Message_Ending),
                new Hangup {
                    OperationId = id
                }
            };

            // Convert the audio to text
            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var    record = await recordOutcomeEvent.RecordedContent;
                string sst    = await BingSpeech.GetTextFromAudioAsync(record);
                await SendSTTResultToUser($"We detected the following audio: {sst}");
            }

            recordOutcomeEvent.ResultingWorkflow.Links = null;
            _callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
        }
Esempio n. 14
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            var id = Guid.NewGuid().ToString();

            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var record    = await recordOutcomeEvent.RecordedContent;
                var container = this.CloudService.CreateContainer("advanced", BlobContainerPublicAccessType.Container);
                await container.CreateIfNotExistsAsync();

                this.CloudService.CreateCloudBlob(container, record, $"{recordOutcomeEvent.RecordOutcome.Id}.wma");
            }

            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(IvrOptions.Ending),
                new Hangup {
                    OperationId = id
                }
            };
            recordOutcomeEvent.ResultingWorkflow.Links = null;
            _callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
        }
        /// <summary>
        /// Called when [record completed].
        /// </summary>
        /// <param name="recordOutcomeEvent">The record outcome event.</param>
        /// <returns></returns>
        private async Task <bool> OnRecordCompletedAsync(RecordOutcomeEvent recordOutcomeEvent)
        {
            telemetryClient.TrackTrace($"RecordCompleted - {recordOutcomeEvent.ConversationResult.Id}");
            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
            {
                GetPromptForText(IVROptions.Ending),
                new Hangup {
                    OperationId = Guid.NewGuid().ToString()
                }
            };

            // Message from User as stream of bytes format
            var recordedContent = recordOutcomeEvent.RecordedContent.Result;

            this.callStateMap[recordOutcomeEvent.ConversationResult.Id].RecordedContent = recordedContent;

            // save call state
            var azureStorgeContext = new AzureStorageContext();
            await azureStorgeContext.SaveCallStateAsync(this.callStateMap[recordOutcomeEvent.ConversationResult.Id]);

            recordOutcomeEvent.ResultingWorkflow.Links = null;
            this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
            return(await Task.FromResult(true));
        }
Esempio n. 16
0
        private async Task <string> GetResultFromRecording(RecordOutcomeEvent recordOutcomeEvent)
        {
            var record = await recordOutcomeEvent.RecordedContent;

            return(await this.GetTextFromAudioAsync(record));
        }
Esempio n. 17
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            var actions = new List <ActionBase>();

            var spokenText = string.Empty;


            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var record = await recordOutcomeEvent.RecordedContent;
                spokenText = await this.speechService.GetTextFromAudioAsync(record);

                if (recordOutcomeEvent.RecordOutcome.Id == Intent.WelcomeMessage.ToString() || recordOutcomeEvent.RecordOutcome.Id == Intent.YesOrNoQuery.ToString())
                {
                    if (spokenText.ToUpperInvariant().Contains("YES"))
                    {
                        var recording = CreateRecordingAction("OK, say 1 or 2.", Intent.OneOrTwoQuery);

                        actions = new List <ActionBase>
                        {
                            recording,
                        };
                    }
                    else if (spokenText.ToUpperInvariant().Contains("NO") && !spokenText.ToUpperInvariant().Contains("YES"))
                    {
                        actions.Add(CreatePlayPromptAction("Screw you!"));
                        actions.Add(new Hangup {
                            OperationId = Guid.NewGuid().ToString()
                        });
                    }
                    else
                    {
                        var recording = CreateRecordingAction("We couldn't recognize your message. Please repeat. Say yes or no.", Intent.YesOrNoQuery);
                        i--;
                        actions.Add(recording);
                    }
                }
                else
                {
                    if (spokenText.Contains("1") || spokenText.Contains("2"))
                    {
                        var random       = new Random();
                        var randomNumber = random.Next(0, 100);
                        var list         = new List <string> {
                            "Congrats", "won"
                        };
                        if (randomNumber % 2 == 0)
                        {
                            list[0] = "Sorry";
                            list[1] = "lost";
                        }
                        actions.Add(CreatePlayPromptAction($"{list[0]}, you {list[1]}, because you said {spokenText}!"));
                        actions.Add(new Hangup {
                            OperationId = Guid.NewGuid().ToString()
                        });
                    }
                    else
                    {
                        var recording = CreateRecordingAction("We couldn't recognize your message. Please repeat. Say one or two.", Intent.OneOrTwoQuery);

                        actions.Add(recording);
                    }
                }
            }
            else
            {
                actions.Add(CreatePlayPromptAction("Sorry, there was an issue."));
            }

            //actions.Add(new Hangup { OperationId = Guid.NewGuid().ToString() }); // hang up the call


            recordOutcomeEvent.ResultingWorkflow.Actions     = actions;
            this.incomingCallEvent.ResultingWorkflow.Actions = actions;
        }
Esempio n. 18
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            var actions = new List <ActionBase>();

            var spokenText = string.Empty;

            try
            {
                if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
                {
                    var record = await recordOutcomeEvent.RecordedContent;
                    spokenText = await this.speechService.GetTextFromAudioAsync(record);

                    switch (int.Parse(recordOutcomeEvent.RecordOutcome.Id))
                    {
                    case (int)Intent.WelcomeMessage:
                        if (spokenText.ToUpperInvariant().Contains("CAR"))
                        {
                            actions.Add(CreateRecordingAction("what kind of car do you want? ", Intent.CarQuery));
                        }
                        else if (spokenText.ToUpperInvariant().Contains("DOCUMENT") &&
                                 !spokenText.ToUpperInvariant().Contains("CAR"))

                        {
                            actions.Add(CreateRecordingAction("what kind of docs do you want to send?", Intent.DocQuery));
                        }
                        else
                        {
                            if (spokenText.Contains("REPEAT"))
                            {
                                actions.Add(CreateRecordingAction(
                                                $"We couldn't recognize your message. You should choose either Documents or Car. Please repeat.", Intent.WelcomeMessage));
                            }
                            else
                            {
                                actions.Add(CreateRecordingAction(
                                                $"We couldn't recognize your message. Did you say {spokenText}? You should choose either Documents or Car. Please repeat.", Intent.WelcomeMessage));
                            }
                        }
                        break;

                    case (int)Intent.CarQuery:
                        if (spokenText.ToUpperInvariant().Contains("MUSTANG"))
                        {
                            actions.Add(CreatePlayPromptAction("Your mustang will arrive soon. Thank you for using our service."));
                            actions.Add(new Hangup {
                                OperationId = Guid.NewGuid().ToString()
                            });
                        }
                        else if (spokenText.ToUpperInvariant().Contains("FERRARI"))
                        {
                            actions.Add(CreatePlayPromptAction("Your Ferrari will arrive soon. Thank you for using our service."));
                            actions.Add(new Hangup {
                                OperationId = Guid.NewGuid().ToString()
                            });
                        }
                        else
                        {
                            actions.Add(CreatePlayPromptAction(
                                            "We weren't able to understand your request (you didn't choose Mustang or Ferrari), so you will get a fiat multipla. see ya!"));
                            actions.Add(new Hangup {
                                OperationId = Guid.NewGuid().ToString()
                            });
                        }
                        break;

                    case (int)Intent.DocQuery:
                        if (spokenText.ToUpperInvariant().Contains("CREDIT CARD"))
                        {
                            actions.Add(CreatePlayPromptAction("Your credit card info will be sent soon. Thank you for using our service."));
                            actions.Add(new Hangup {
                                OperationId = Guid.NewGuid().ToString()
                            });
                        }
                        else if (spokenText.ToUpperInvariant().Contains("DRIVING LICENCE"))
                        {
                            actions.Add(CreatePlayPromptAction("Your driving licence info will be sent soon. Thank you for using our service."));
                            actions.Add(new Hangup {
                                OperationId = Guid.NewGuid().ToString()
                            });
                        }
                        else
                        {
                            actions.Add(CreatePlayPromptAction("We weren't able to understand your request (you didn't choose Credit card or Driving licence, so you will get some spam. See ya!"));
                            actions.Add(new Hangup {
                                OperationId = Guid.NewGuid().ToString()
                            });
                        }
                        break;

                    case (int)Intent.CarSpecification:
                        break;

                    case (int)Intent.DocSpecification:
                        break;
                    }
                }
                else
                {
                    actions.Add(CreatePlayPromptAction("Sorry, there was an issue."));
                }

                //actions.Add(new Hangup { OperationId = Guid.NewGuid().ToString() }); // hang up the call
                recordOutcomeEvent.ResultingWorkflow.Actions     = actions;
                this.incomingCallEvent.ResultingWorkflow.Actions = actions;
            }
            catch (Exception e)
            {
                var action = CreatePlayPromptAction(e.ToString());
                actions.Add(action);
                actions.Add(new Hangup {
                    OperationId = Guid.NewGuid().ToString()
                });
                recordOutcomeEvent.ResultingWorkflow.Actions     = actions;
                this.incomingCallEvent.ResultingWorkflow.Actions = actions;
            }
        }
Esempio n. 19
0
        private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
        {
            List <ActionBase> actions = new List <ActionBase>();



            // Convert the audio to text
            string spokenText = string.Empty;

            if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
            {
                var record = await recordOutcomeEvent.RecordedContent;

                spokenText = await this.GetTextFromAudioAsync(record);

                var intentRecieved = await MicrosoftCognitiveSpeechService.SendToLUISViaAPI(spokenText);

                Intent luisIntent = JsonConvert.DeserializeObject <Intent>(intentRecieved);

                var rootIntent = rootIntentActiveState.Values.All(a => a == false) ? RootIntentFinder(luisIntent) : rootIntentActiveState.Where(a => a.Value == true).FirstOrDefault().Key;

                var callState = this.callStateMap[recordOutcomeEvent.ConversationResult.Id];


                if (!luisIntent.topScoringIntent.intent.Equals("Exit", StringComparison.InvariantCultureIgnoreCase) || rootIntentActiveState.Values.Contains(true))
                {
                    if (callerId == null)
                    {
                        int idTemp         = ExtractNumbers(spokenText);
                        var userRecognised = BotStubs.AuthenticateUser(idTemp);
                        if (string.IsNullOrEmpty(userRecognised))
                        {
                            SetupRecording(recordOutcomeEvent.ResultingWorkflow, "User id not recognised please retry.");
                        }
                        else
                        {
                            callerId = idTemp;
                            //Check whether any registration is there against the user
                            var userRegistrationDate = BotStubs.GetUserRegistrationDate(callerId);
                            //if there is any registration available then give option to reschedule , cancel
                            if (userRegistrationDate == null)
                            {
                                SetupRecording(recordOutcomeEvent.ResultingWorkflow, String.Format("Welcome {0}, You have no appointments booked as of now.", userRecognised));
                            }
                            else
                            {
                                SetupRecording(recordOutcomeEvent.ResultingWorkflow, String.Format("Welcome {0}, You have appointments booked on {1} " +
                                                                                                   " Do you want to reschedule or cancel it.", userRecognised, userRegistrationDate.Value.ToString()));
                            }
                        }
                    }
                    else
                    {
                        if (rootIntentActiveState.Values.All(a => a == false) && !rootIntentActiveState[rootIntent])
                        {
                            HandleRootIntent(rootIntent, recordOutcomeEvent.ResultingWorkflow);
                        }
                        else
                        {
                            switch (rootIntent)
                            {
                            case RootIntent.REGISTER:
                                if (rootIntentActiveState[RootIntent.REGISTER])
                                {
                                    var dates = BotStubs.GetDates();

                                    String DateAcceptance = String.Format("Following dates are available for registration" +
                                                                          "First. {0} Second. {0} Third. {0}, Please choose the number", dates[0].ToString(), dates[1].ToString()
                                                                          , dates[3].ToString());

                                    SetupRecording(recordOutcomeEvent.ResultingWorkflow, DateAcceptance);

                                    int dateChoiceIndex = spokenText.ToLower().Contains("first") ? 0 : spokenText.ToLower().Contains("second") ? 1 : spokenText.ToLower().Contains("third") ? 2 : -1;
                                    if (dateChoiceIndex >= 0)
                                    {
                                        var selectedDate   = dates[dateChoiceIndex];
                                        var registrationId = BotStubs.Register(callerId.Value, selectedDate);

                                        await this.SendSTTResultToUser(String.Format("Registration Booked successfully on {0}," +
                                                                                     " Registration Id is {1}", selectedDate, registrationId), callState.Participants);

                                        rootIntentActiveState[RootIntent.REGISTER] = false;


                                        recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                                        {
                                            GetPromptForText(String.Format("Registration Booked successfully on {0}," +
                                                                           " Registration Id is {1}. Thank you for using the service.", selectedDate, registrationId)),
                                            new Hangup {
                                                OperationId = Guid.NewGuid().ToString()
                                            }
                                        };
                                        callerId = null;
                                        recordOutcomeEvent.ResultingWorkflow.Links = null;
                                        this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
                                    }
                                }
                                break;

                            case RootIntent.RESCHEDULE:
                                if (rootIntentActiveState[RootIntent.RESCHEDULE])
                                {
                                    var dates = BotStubs.GetDates();

                                    String DateAcceptance = String.Format("Following dates are available for reschedule" +
                                                                          "First. {0} Second. {0} Third. {0}, Please choose the number", dates[0].ToString(), dates[1].ToString()
                                                                          , dates[3].ToString());
                                    SetupRecording(recordOutcomeEvent.ResultingWorkflow, DateAcceptance);

                                    int dateChoiceIndex = spokenText.ToLower().Contains("first") ? 0 : spokenText.ToLower().Contains("second") ? 1 : spokenText.ToLower().Contains("third") ? 2 : -1;
                                    if (dateChoiceIndex >= 0)
                                    {
                                        var selectedDate   = dates[dateChoiceIndex];
                                        var registrationId = BotStubs.Register(callerId.Value, selectedDate);

                                        await this.SendSTTResultToUser(String.Format("Registration Rescheduled successfully on {0}," +
                                                                                     " Registration Id is {1}", selectedDate, registrationId), callState.Participants);

                                        rootIntentActiveState[RootIntent.RESCHEDULE] = false;

                                        recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                                        {
                                            GetPromptForText(String.Format("Registration rescheduled successfully on {0}," +
                                                                           " Registration Id is {1}. Thank you for using the service.", selectedDate, registrationId)),
                                            new Hangup {
                                                OperationId = Guid.NewGuid().ToString()
                                            }
                                        };
                                        callerId = null;
                                        recordOutcomeEvent.ResultingWorkflow.Links = null;
                                        this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
                                    }
                                }
                                break;

                            case RootIntent.CANCEL:
                                if (rootIntentActiveState[RootIntent.CANCEL])
                                {
                                    rootIntentActiveState[RootIntent.CANCEL] = false;
                                    if (BotStubs.CancelRegistration(callerId.Value))
                                    {
                                        var cancelStatus = BotStubs.CancelRegistration(callerId.Value);
                                        if (cancelStatus)
                                        {
                                            recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase>
                                            {
                                                GetPromptForText("Registration cancelled successfully. Thank you for using the service."),
                                                new Hangup {
                                                    OperationId = Guid.NewGuid().ToString()
                                                }
                                            };
                                            callerId = null;
                                            recordOutcomeEvent.ResultingWorkflow.Links = null;
                                            this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
                                        }
                                    }
                                    else
                                    {
                                        SetupRecording(recordOutcomeEvent.ResultingWorkflow, "Please retry, cancelation failed");
                                    }
                                }
                                break;

                            case RootIntent.LOOK_UP:
                                return;
                            }
                        }
                    }
                }
                else if (luisIntent.topScoringIntent.intent.Equals("Exit", StringComparison.InvariantCultureIgnoreCase) && luisIntent.topScoringIntent.score > 0.50)
                {
                    //recordOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                    //{
                    //    GetPromptForText("Thanks for using emergency bot"),
                    //    new Hangup { OperationId = Guid.NewGuid().ToString() }

                    //};
                    //callerId = null;
                    //recordOutcomeEvent.ResultingWorkflow.Links = null;
                    //this.callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id);
                    HangUpCall(recordOutcomeEvent, "Thanks for using emergency bot");
                }
            }
            else
            {
                recordOutcomeEvent.ResultingWorkflow.Actions = actions;
                SetupRecording(recordOutcomeEvent.ResultingWorkflow, "Recording failed please retry.");
            }
        }