【发布时间】:2021-08-04 17:42:21
【问题描述】:
在主提示中,我想调用提示用户输入 (ChoicePrompt) 的子对话框,将结果保存到变量并使用该结果。
在示例代码中,实际上最终发生的是子对话框被触发,但主对话框中的代码在子对话框完成之前(在用户输入之前)继续。
我想要实现的示例代码:
private async Task<DialogTurnResult> IntentCheckStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
LuisResult = await InDocRecognizer.RecognizeAsync<InDocChatbotService>(stepContext.Context, cancellationToken);
var topIntent = LuisResult.TopIntent().intent;
if (LuisResult.TopIntent().score < 0.30)
{
topIntent = InDocChatbotService.Intent.None;
}
// if first and second option is close in score prompt user choice between them
else if (LuisResult.Intents.ElementAt(0).Value.Score - LuisResult.Intents.ElementAt(1).Value.Score < 0.20)
{
var topIntent = await stepContext.BeginDialogAsync(nameof(ChooseIntentDialog), LuisResult, cancellationToken);
// Code in this dialog continues before user gives input to child dialog "ChooseIntentDialog"
}
// DO MORE STUFF WITH VARIABLE topIntent
}
我确实有一个解决方法,但它很丑陋并且会影响代码风格。我这样做的方法是返回子对话框,然后在主对话框中的另一个瀑布步骤中处理来自ChooseIntentDialog 的事情。
这很糟糕,因为我需要将多个变量带到该瀑布步骤,而这似乎完全没有必要。如果我可以让瀑布步骤等待子对话框并返回结果,而不必使用另一个瀑布步骤。
这可能吗?如果不是,还有什么替代方案,因为我的解决方案在代码方面似乎不是很有效。
【问题讨论】:
标签: c# botframework chatbot