对话是不是从那里等待用户继续输入

问题描述 投票:1回答:1

这个代码是使用botframework 4

我有rootdialog它调用一个叫choicedialog。从choicedialog我从BeginDialogAsync method.After返回DialogturnResult(等待),另一个对话框,该机器人等待来自用户的输入。当用户输入的东西就应该调用在ChoiceDialog.But机器人被调用Rootdailog ContinueAsync的ContinueAsync方法。究竟是什么原因呢?我怎样才能解决这个问题?

在控制器onTurnAync方法

async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
    {
        if (turnContext.Activity.Type == ActivityTypes.Message)
        {

                var dc = await Dialogs.CreateContextAsync(turnContext, cancellationToken);
                var dialogResult = await dc.ContinueDialogAsync();

                if (!dc.Context.Responded)
                {
                    // examine results from active dialog
                    switch (dialogResult.Status)
                    {
                        case DialogTurnStatus.Empty:
                            await dc.BeginDialogAsync(nameof(RootDialog));
                            break;

                        case DialogTurnStatus.Waiting:
                            // The active dialog is waiting for a response from the user, so do nothing.
                            break;

                        case DialogTurnStatus.Complete:
                            await dc.EndDialogAsync();
                            break;

                        default:
                            await dc.CancelAllDialogsAsync();
                            break;
                    }
                }
        }
    }

rootDialog

public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext context, object options = null, CancellationToken cancellationToken = default(CancellationToken))
    {
        var activity = context.Context.Activity;
        context.SendTyping(activity);
            var response = DataFromService();
            if (response == null || response.StatusCode != 1)
            {
                await context.PostAsync(Messages.StandardErrorMessage);

            }

            if (response.Data != null)
            {

                return await dialog.BeginDialogAsync(context);

            }
            else
            {
                return new DialogTurnResult(DialogTurnStatus.Waiting);
            }

    }

ChoiceDialog

public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext context, object options = null, CancellationToken cancellationToken = default(CancellationToken))
    {
        choiceStep.SaveEntityDataInContext(context: context);

        IList<IMessageActivity> messages = GenerateMessageActivity(context);

        if (messages.IsCollectionValid())
        {
            foreach (var message in messages)
            {
                await context.PostActivityToUser(message);
            }
        }
        var dialogResult = new DialogTurnResult(DialogTurnStatus.Waiting);
        return dialogResult;
    }
c# .net dialog botframework state
1个回答
0
投票

我没有看到你将更改保存到任何地方DialogState。通常,这是在OnTurnAsync年底完成。您也可能会被使用AutoSaveStateMiddleware,但你没有提到(,坦率地说,我不会推荐它)。

具体来说,你需要调用SaveChangesAsync上,你叫BotStateCreateProperty<DialogState>实例。通常这是ConversationState

如果你不这样做,动不动就会有一个空的对话框栈开始,因此行为你描述其中的根本对话框总是被运行。

© www.soinside.com 2019 - 2024. All rights reserved.