Reputation: 11
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
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:
StartAsync
-> MessageReceivedAsync
-> PromptDialog.Text(context, OnEmailSet)
. Now dialog is waiting for Email postedOnEmailSet
-> PromptDialog.Text(context, OnPhoneSet
. Now dialog is waiting for Phone postedOnPhoneSet
. On OnPhoneSet
you'll do further actions, for example you can close dialog using Context.Done
or something.Upvotes: 2