我正在开发一个几乎所有对话框都是瀑布对话框的机器人。
他们从包含CancelAndHelpDialog
方法的示例中扩展InterruptAsync
,从OnBeginDialogAsync
调用此方法:
private async Task<DialogTurnResult> InterruptAsync(DialogContext innerDc, CancellationToken cancellationToken)
{
if (innerDc.Context.Activity.Type == ActivityTypes.Message)
{
var text = innerDc.Context.Activity.Text.ToLowerInvariant();
switch (text)
{
case "help":
case "?":
await ShowHelpAsync(/*-- pass WaterfallStepContext here --*/)
return new DialogTurnResult(DialogTurnStatus.Waiting);
case "cancel":
case "quit":
await innerDc.Context.SendActivityAsync($"Cancelling", cancellationToken: cancellationToken);
return await innerDc.CancelAllDialogsAsync();
}
}
return null;
}
我想声明一个根据WaterfallStepContext.Index
属性显示帮助消息的方法,并且子对话框可以覆盖它,就像这样:
protected async Task ShowHelpAsync(WaterfallStepContext stepContext)
{
switch(stepContext.Index)
{
case 0:
//Send help message for step 0.
...
}
};
该方法将在InterruptAsync
方法内部调用。
如何从CancelAndHelpDialog
的子对话框中获取WaterfallStepContext?
我试图检查innerDc
是否为运行时类型WaterfallStepContext
,但没有成功。
我知道我可以将stepContext保存在存储中,并使用ConversationState访问器进行检索,但是我必须在每个WaterfallStep中都进行此操作。
有没有更好的方法来实现这一目标?