botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

PromptDialog.Choice has duplicate replies

Open NOTPOWERUSER opened this issue 9 years ago • 1 comments

I'm working with the Bot framework in C# and I encountered a problem.

The problem is: I have a Dialog and use PromptDialog.Choice let users select a question they interested. But in my test, I got duplicate replies see the following picture

image

` public async Task StartAsync(IDialogContext context) {

        this.ShowOptions(context);


    }`

` private void ShowOptions(IDialogContext context) { PromptDialog.Choice(context, this.OnOptionSelected, new List() { ImageOption, ToolOption }, "Please select one of the following category.", "Not a valid option", 3);

    }`

` private async Task OnOptionSelected(IDialogContext context, IAwaitable result) {

            string optionSelected = await result;

            switch (optionSelected)
            {
                case ImageOption:
                    context.Call(new ImgRelated(), this.ResumeAfterOptionDialog);
                    
                    break;

                case ToolOption:
                    context.Call(new ToolPBmDailog(), this.ResumeAfterOptionDialog);
                    

                    break;
            }
        
       
    }`

Anyone has idea?

NOTPOWERUSER avatar Mar 16 '17 07:03 NOTPOWERUSER

Implementation questions like this are better suited to the Bot framework tag at Stack Overflow, and we're trying to redirect people there. I have asked and answered your question there. You can see it at this link.

Basically, you're not waiting for a response from the user in the ShowOptions method. You need to make it an async method, have it take IAwaitable<IMessageActivity> result as an argument, and change this.ShowOptions(context); in StartAsync to context.Wait(this.ShowOptions).

    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(this.MessageReceivedAsync);
    }

    public async virtual Task ShowOptions(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        var message = await result;

        PromptDialog.Choice<string>(
            context,
            this.OnOptionSelected,
            new List() { ImageOption, ToolOption },
            "Please select one of the following category.",
            "Not a valid option",
            3);
    }

    ...

mgbennet avatar Mar 16 '17 19:03 mgbennet