public virtual ConversationResponse ProcessUserInput(IConversationContext context)
        {
            if (string.IsNullOrWhiteSpace(context.Result.Query) || context.Result == null)
            {
                return(IntentProvider.GetDefaultResponse(context.AppId));
            }

            // gather data
            var intent         = IntentProvider.GetTopScoringIntent(context);
            var conversation   = context.GetCurrentConversation();
            var isConfident    = context.Result.TopScoringIntent.Score > ApiKeys.LuisIntentConfidenceThreshold;
            var hasValidIntent = intent != null && isConfident;
            var inConversation = conversation != null && !conversation.IsEnded;
            var requestedQuit  = hasValidIntent && intent.KeyName.Equals(context.QuitIntentName);

            // if the user is trying to end or finish a conversation
            if (inConversation && requestedQuit)
            {
                return(EndCurrentConversation(context));
            }

            // continue conversation
            if (inConversation)
            {
                return(HandleCurrentConversation(context));
            }

            // is a user frustrated or is their intention unclear
            var sentimentScore = context.Result.SentimentAnalysis?.score ?? 1;

            return((sentimentScore <= 0.4)
                ? IntentProvider.GetIntent(context.AppId, context.FrustratedIntentName)?.Respond(null, null, null) ?? IntentProvider.GetDefaultResponse(context.AppId)
                : IntentProvider.GetDefaultResponse(context.AppId));
        }
        public virtual IConversation GetCurrentConversation()
        {
            var intent = IntentProvider.GetTopScoringIntent(this);

            IConversation conversation = null;

            var isConfident    = Result.TopScoringIntent.Score > ApiKeys.LuisIntentConfidenceThreshold;
            var hasValidIntent = intent != null && isConfident && intent.KeyName != "none";

            if (ConversationHistory.Conversations.Any())
            {
                conversation = ConversationHistory.Conversations.Last();
            }

            var inConversation = conversation != null && !conversation.IsEnded;

            if (!inConversation && hasValidIntent)
            {
                conversation = ConversationFactory.Create(Result, intent);
                ConversationHistory.Conversations.Add(conversation);
            }

            return(conversation);
        }