Botframework-sdk: [Question] PromptConfirm firing twice

Created on 8 Aug 2017  路  7Comments  路  Source: microsoft/botframework-sdk

Hello. I got a dialog which has the following method:

public Task StartAsync(IDialogContext context)
{
            string prompt = $"驴Please choose an option?";
            PromptDialog.Confirm(context, Resume, prompt, "Please repeat");
            return Task.CompletedTask;
}

The issue here is that I see the prompt on my chat, but right after (before me typing anything), I see the "Please Repeat" prompt.

Am I doing something wrong?

Thanks!

All 7 comments

Can you share your resume code too please?

@JasonSowers here it is:

 private async Task Resume(IDialogContext context, IAwaitable<bool> result)
 {
            var confirm = await result;
            if (confirm)
            {
                context.Activity.AsMessageActivity().Text = Correction;

                context.Done(context.Activity.AsMessageActivity());
            }
            else
            {
                context.PrivateConversationData.SetValue("OmitSpellCheck", true);
                context.Activity.AsMessageActivity().Text = Original;

                context.Done(context.Activity.AsMessageActivity());
            }
}

Generally, you do not need to or want to edit the public Task StartAsync(IDialogContext context) method. It doesn't make sense here because you are starting a dialog with a confirm prompt, so what are you confirming? I assume you did this because you were just testing this out, which makes sense. Below is a code example that has been tested and functions as intended

[Serializable]
    public class TestDialog : IDialog<object>
    {
        public string Option { get; set; }

        private async Task MessageReceived(IDialogContext context, IAwaitable<object> result)
        {
            if (string.IsNullOrEmpty(Option))
            {
                string prompt = $"驴Please choose an option?";
                PromptDialog.Confirm(context, Resume, prompt, "Please repeat");
            }
            else
            {
                var activity = await result as Activity;
                await context.PostAsync($"hello...in test dialog ... option chosen");
            }
        }
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceived);
            return Task.CompletedTask;
        }

        private async Task Resume(IDialogContext context, IAwaitable<bool> result)
        {
            var x = await result;
            this.Option = x.ToString();
            await context.PostAsync($"Your choice has been recorded.");
            context.Wait(MessageReceived);           
        }
    }

Ok. After a while, found out that this happened because my dialog was called with context.Forward, however I changed it to context.Call and works fine.

Not sure if this should be taken as a bug in the Framework?

I'm surprised you got it working that way, glad you figured it out though.

Note i was calling it from the messagesController like

 if (activity.Type == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
            }

and was seeing the same behavior. I'm not sure what the rest of your code looks like so I cannot tell you if .Call or .Forward is the right thing to use or if it would be a bug or not.

Closing this, but please reopen if you need to

@JasonSowers actually it was unneeded to do it by Forward. I did it because I copied and pasted some code I had for redirecting to another dialog. However I didnt need to pass any activity to the other dialog so context.call was the correct way.

Thanks for checking out, tho!

Was this page helpful?
0 / 5 - 0 ratings