예제 #1
0
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string messageText;
            var    conversationData = await conversationStateAccessors.GetAsync(stepContext.Context, () => new ConversationData());

            var simpleResult = await simpleRecognizer.RecognizeAsync <SimpleModel>(stepContext.Context, cancellationToken);

            var topIntent = simpleResult.TopIntent().intent;

            conversationData.CurrentIntent = topIntent.ToString();

            switch (topIntent)
            {
            case SimpleModel.Intent.simplestatement:
                var recognizedStatement = await queryHandler.AddStatementAsync(simpleResult, stepContext.Context);

                messageText = $"New statement: {recognizedStatement}";
                await SendTextMessage(messageText, stepContext.Context, cancellationToken);

                return(await stepContext.ReplaceDialogAsync(InitialDialogId, null, cancellationToken));

            case SimpleModel.Intent.finishedstatement:
                var choices = new List <Choice>
                {
                    new Choice("Show result"),
                    new Choice("Return to editing query")
                };

                var card         = DialogHelper.CreateChoiceCard(choices);
                var cardActivity = (Activity)card.CreateActivity();

                return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
                {
                    Prompt = cardActivity,
                    RetryPrompt = cardActivity,
                    Choices = choices,
                    Style = ListStyle.None
                }, cancellationToken));

            case SimpleModel.Intent.list:
                await DisplayQuery(conversationData, stepContext.Context, cancellationToken);

                messageText = "What would you like to do?";
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            default:
                messageText = "Sorry, I could not understand that.";
                var message = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(message, cancellationToken);

                return(await stepContext.ReplaceDialogAsync(InitialDialogId, null, cancellationToken));
            }
        }
예제 #2
0
        private async Task <IEnumerable <dynamic> > ExecuteQueryAsync(ConversationData conversationData, ITurnContext context)
        {
            var query = new Query();

            foreach (var statement in conversationData.Statements)
            {
                if (conversationData.ModelBeingUsed == CognitiveModel.Complex)
                {
                    await complexQueryHandler.AddStatementAsync(statement, query, context);
                }
                else
                {
                    await simpleQueryHandler.AddStatementAsync(statement, query, context);
                }
            }

            var xQuery = queryFactory.FromQuery(conversationData.Query);

            return(xQuery.Get());
        }