Liam Griffin
Liam Griffin

Reputation: 11

Microsoft bot error - Exception: invalid need: expected Call, have Poll

I keep getting this error and I don't know how to fix it: Exception: invalid need: expected Call, have Poll

            PromptDialog.Text(context, setEmail, "What is the contact's email? "); 
            PromptDialog.Text(context, setPhone, "What is the contact's phone number? ");


    private async Task setPhone(IDialogContext context, IAwaitable<string> result)
    {
        this.contact1.Phone = await result;
        ReturnContact(context, contact1);

    }

    private async Task setEmail(IDialogContext context, IAwaitable<string> result)
    {
        this.contact1.Email = await result;
        ReturnContact(context, contact1);
    }

the prompt dialogs are part of a different method. How do I prompt the user twice in a row without getting this error?

Upvotes: 0

Views: 1675

Answers (1)

Artem
Artem

Reputation: 2314

PromptDialog.Text was not designed to be called twice, because you need two different answers from a user, so in terms of botframework it is like two separate "transactions".

Rather than making a double call you need to create a cascade of calls, where you initiate the Phone question from the Email question handler:

[Serializable]
public class SomeDialog : IDialog<object>
{
    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync); 
    }

    private async Task OnPhoneSet(IDialogContext context, IAwaitable<string> result)
    {
        var res = await result;
    }

    private async Task OnEmailSet(IDialogContext context, IAwaitable<string> result)
    {
        var res = await result;
        PromptDialog.Text(context, OnPhoneSet, "What is the contact's phone number? ");
    }

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

        PromptDialog.Text(context, OnEmailSet, "What is the contact's email? ");
    }
}

The workflow is like the following:

  1. User initiates a dialog for the first time. Callstack: StartAsync -> MessageReceivedAsync -> PromptDialog.Text(context, OnEmailSet). Now dialog is waiting for Email posted
  2. User posts Email. Callstack: OnEmailSet -> PromptDialog.Text(context, OnPhoneSet. Now dialog is waiting for Phone posted
  3. User posts Phone. Callstack: OnPhoneSet. On OnPhoneSet you'll do further actions, for example you can close dialog using Context.Done or something.

Upvotes: 2

Related Questions