Gav Kr
Gav Kr

Reputation: 65

Bot Framework stuck in a Dialog Loop

I am using Bot Framework for one of my project. It seems to be stuck in a loop while processing reply from a PromptDialog.Confirm function.

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. 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.

Upvotes: 4

Views: 1230

Answers (1)

user6269864
user6269864

Reputation:

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.

If you're using the facebook channel, type "/deleteprofile" to reset the state and start using your new code. 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.

Update: I've run your code and it works as expected for me after I've added 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);
}

Upvotes: 1

Related Questions