在Dialog类

时间:2017-02-03 11:52:36

标签: c# botframework

我在C#中使用Microsoft Bot Framework做了一个机器人,我遇到了一个问题。

问题在于,当我调用“PromptDialog”从用户获取String时,在这种情况下是密码,它不会要求它,它会打开“Password”方法并在尝试获取该字符串时崩溃

感谢您的帮助!

该课程扩展了LUISDialog

PromptDialog.Text(context, resume: Password, prompt: "Enter password:");

LUIS Intent null:

[LuisIntent("")]
    public async Task None(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
    {
        Boolean PassLogin;
        Start(context, activity); //Does this need to be awaited?
        if (!context.UserData.TryGetValue<Boolean>("PassLogin", out PassLogin)) PassLogin = false;
        if (PassLogin)
        {
            var act = await activity;
            if (act.Conversation.IsGroup != null && act.Conversation.IsGroup.Value)
            {
                context.Wait(MessageReceived);
            }
            else
            {
                await Nothing(context, activity, result);
            }
        }
        else context.Wait(MessageReceived);
    }

启动方法。每个来自LUIS的意图都会调用Start方法。

public async Task Start(IDialogContext context, IAwaitable<IMessageActivity> activity)
    {
        Boolean PassLogin, start;
        if (!context.UserData.TryGetValue<Boolean>("PassLogin", out PassLogin))
        {
            PassLogin = false;
            context.UserData.SetValue<Boolean>("PassLogin", PassLogin);
        }
        if (!context.UserData.TryGetValue<Boolean>("start", out start))
        {
            start = true;
        }
        if (start)
        {
            PromptDialog.Text(context, resume: Password, prompt: "Enter password:");
            await context.PostAsync("Something"); //This prints out before going to password.
        }
        await GetKey(context, activity);
    }

private async Task Password(IDialogContext context, IAwaitable<String> argument)
    {
        var response = await argument;
        if (response=="test")
        {
            context.UserData.SetValue<Boolean>("PassLogin", true);
            await context.PostAsync("Correct Password.");
            if (context.UserData.Get<Boolean>("PassLogin"))
            {
                await context.PostAsync("Welcome");
                context.UserData.SetValue<Boolean>("start", false);
            }
        }
        else
        {
            context.UserData.SetValue<Boolean>("PassLogin", false);
            await context.PostAsync("Incorrect password.");
        }
        context.Wait(MessageReceived); //Does this need to be here? (Tried with and without.)
    }

这就是错误所说的:

Exception: Microsoft.Bot.Builder.Internals.Fibers.InvalidNextException: invalid next: Wait: Poll Object for ThunkStart.Rest have Object at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.&lt;Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop&lt;C&gt;-PollAsync&gt;d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult() at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.&lt;ResumeAsync&gt;d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.<Rest>d4.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d19.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.&lt;Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop&lt;C&gt;-PollAsync&gt;d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d13.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IDialogStack-PollAsync>d19.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d21`1.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.&lt;Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync&gt;d__21.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.ScoringDialogTask1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.&lt;Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync&gt;d__31.MoveNext() — End of stack trace from previous location where exception was thrown — at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d3`1.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.SerializingDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.&lt;Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync&gt;d__51.MoveNext()

1 个答案:

答案 0 :(得分:1)

正如我在评论中写的那样,有一些问题需要解决:

  1. 必须等待Start方法的调用
  2. 调用PromptDialog.Text后不应该是代码。该代码正在启动一个新对话框,该对话框将在ResumeAfter方法完成后继续
  3. Start调用后的所有代码似乎都取决于提示的ResumeAfter,因此应将其移至那里。