Exemplo n.º 1
0
        private async Task <DialogTurnResult> EditStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string messageText;
            var    newStatement     = stepContext.Result.ToString();
            var    conversationData = await conversationStateAccessors.GetAsync(stepContext.Context, () => new ConversationData());

            var complexResult = await complexRecognizer.RecognizeAsync <ComplexModel>(stepContext.Context, cancellationToken);

            var       topIntent = complexResult.TopIntent().intent;
            Statement old       = null;

            // TODO: itt lehet szerkeszteni

            switch (topIntent)
            {
            case ComplexModel.Intent.Statement:
                messageText = await queryHandler.AddStatementAsync(complexResult, stepContext.Context);

                foreach (var statement in conversationData.Statements)
                {
                    if (statement.Text == conversationData.StatementToEdit)
                    {
                        old = statement;
                    }
                }
                conversationData.Statements.Remove(old);
                conversationData.Edited = true;
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            case ComplexModel.Intent.Delete:
                foreach (var statement in conversationData.Statements)
                {
                    if (statement.Text == conversationData.StatementToEdit)
                    {
                        old = statement;
                    }
                }
                conversationData.Statements.Remove(old);
                conversationData.Edited = true;
                messageText             = "Deleted constraint: " + conversationData.StatementToEdit;
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            case ComplexModel.Intent.Help:
                messageText = "Help intent recognized";
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            default:
                messageText = "Sorry, I could not understand that.";
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));
            }
        }
Exemplo n.º 2
0
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string messageText;
            var    conversationData = await conversationStateAccessors.GetAsync(stepContext.Context, () => new ConversationData());

            var complexResult = await complexRecognizer.RecognizeAsync <ComplexModel>(stepContext.Context, cancellationToken);

            var topIntent = complexResult.TopIntent().intent;

            conversationData.CurrentIntent = topIntent.ToString();

            switch (topIntent)
            {
            case ComplexModel.Intent.Statement:
                string s = await queryHandler.AddStatementAsync(complexResult, stepContext.Context);

                messageText = s;
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            case ComplexModel.Intent.ObjectType:
                string ss = await queryHandler.AddObjectTypeAsync(complexResult, stepContext.Context);

                conversationData.SpecifiedObjectType = ss;
                if (conversationData.SpecifiedObjectType == null)
                {
                    messageText = "Coulnd't understand the type you specified.";
                }
                else
                {
                    messageText = "Got it, you are looking for a " + conversationData.SpecifiedObjectType + ".";
                }
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            case ComplexModel.Intent.Done:
                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 ComplexModel.Intent.List:
                await DisplayQuery(conversationData, stepContext.Context, cancellationToken);

                return(await stepContext.ReplaceDialogAsync(InitialDialogId, "You can continue to add constraints, edit them or execute the query.", cancellationToken));

            case ComplexModel.Intent.Delete:
                messageText = "Delete intent recognized";
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            case ComplexModel.Intent.Edit:
                return(await stepContext.BeginDialogAsync(nameof(EditDialog), null, cancellationToken));

            case ComplexModel.Intent.Exit:
                return(await stepContext.EndDialogAsync(null, cancellationToken));

            case ComplexModel.Intent.Help:
                messageText = "Help intent recognized";
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));

            default:
                messageText = "Sorry, I could not understand that.";
                return(await stepContext.ReplaceDialogAsync(InitialDialogId, messageText, cancellationToken));
            }
        }