简体   繁体   English

Bot框架卡在对话循环中

[英]Bot Framework stuck in a Dialog Loop

I am using Bot Framework for one of my project. 我正在为我的一个项目使用Bot Framework。 It seems to be stuck in a loop while processing reply from a PromptDialog.Confirm function. 在处理来自PromptDialog.Confirm函数的回复时似乎陷入了循环。

namespace Genome
{
public class InitiateDialog : IDialog<object>
{
    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(ConversationStarted);
    }

    public async Task ConversationStarted(IDialogContext context, IAwaitable<IMessageActivity> message)
    {
        await context.PostAsync("Hi!");
        PromptDialog.Confirm(
            context: context,
            resume: ResumeAndPromptPlatformAsync,
            prompt: "Would you like to upload the document?",
            retry: "I didn't understand. Please try again."
            );
    }

    public async Task ResumeAndPromptPlatformAsync(IDialogContext context, IAwaitable<bool> result)
    {
        await context.PostAsync("Input Received");
    }
}
}

The execution of this code never reaches the ResumeAndPromptPlatformAsync function. 此代码的执行永远不会到达ResumeAndPromptPlatformAsync函数。 Every-time I choose Yes/No at the PromptDialog.Confirm() the Bot Emulator loops back to start with ConversationStarted() and asks the same question again. 每次我在PromptDialog.Confirm()中选择Yes / No,Bot Emulator循环回来以ConversationStarted()开始并再次询问相同的问题。

I think your current code is correct, but there may have been an error in your previous code that caused the loop. 我认为您当前的代码是正确的,但您之前的代码中可能存在导致循环的错误。 Since bot framework saves the state automatically, you are still kind of stuck using the old code. 由于bot框架会自动保存状态,因此您仍然无法使用旧代码。

If you're using the facebook channel, type " /deleteprofile " to reset the state and start using your new code. 如果您正在使用Facebook频道,请键入“ /deleteprofile ”以重置状态并开始使用新代码。 If you're on the emulator, click either Delete Data or start a new conversation with a new user. 如果您在模拟器上,请单击“删除数据”或与新用户开始新对话。

Also, your ResumeAndPromptPlatformAsync method must end with either context.Wait or context.Done , or else you're causing an exception which may also be a reason for the problem. 此外,您的ResumeAndPromptPlatformAsync方法必须以context.Waitcontext.Done结束,否则您将导致异常,这也可能是问题的原因。

Update: I've run your code and it works as expected for me after I've added context.Done(this); 更新:我已经运行了你的代码,在我添加了context.Done(this);后,它按预期的那样工作context.Done(this); . I'm using the emulator. 我正在使用模拟器。

public async Task ResumeAndPromptPlatformAsync(IDialogContext context, IAwaitable<bool> result)
{
    await context.PostAsync("Input Received");
    context.Done(this);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM