我正在尝试编写一个允许用户创建请求的机器人(例如,我想买一件 T 恤或者我想修理我的电脑)。根据他们选择的请求,他们将被问到与该请求相关的一系列问题;这些问题与他们选择的请求直接相关。目前我正在尝试遍历这个问题列表并使用 PromptDialog.Text 方法来获得答案。但是,这只会询问列表中的最后一个问题,当给出答案时,我会收到一个无效需要的错误:预期等待,已完成作为消息。
private async Task ListOfferings(IDialogContext context, IAwaitable<string> result)
{
string name = await result;
var offerings = Offerings.Where((x) =>
CultureInfo.CurrentCulture.CompareInfo.IndexOf(x.Name, name,
CompareOptions.IgnoreCase) >= 0
);
if (offerings.Count() != 0)
{
PromptDialog.Choice(context, CreateOffering, offerings, "Which of these would you like?");
}
else
{
await context.PostAsync(string.Format("Could not find an offering with name {0}", name));
context.Wait(MessageReceived);
}
}
private async Task CreateOffering(IDialogContext context, IAwaitable<Offering> result)
{
var offering = result.GetAwaiter().GetResult();
await context.PostAsync(string.Format("***CREATING {0}***", offering.Name.ToUpper()));
foreach (var question in offering.Questions)
{
PromptDialog.Text(context, null, question.Question);
}
}
是否有可能做这样的事情,我想动态地决定用户在运行时会被问到的问题,还是我需要采取更静态的脚本化方法?