每个WaterfallStep的自定义帮助消息

时间:2020-01-16 10:09:40

标签: asp.net-core botframework

我正在开发一个几乎所有对话框都是瀑布对话框的机器人。

他们从包含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中都进行此操作。

有没有更好的方法来实现这一目标?

0 个答案:

没有答案