Microsoft Teams Bot-框架技能对话框:endDialog()不起作用

时间:2020-06-19 09:15:25

标签: node.js botframework microsoft-teams

我正在实现一个dialogRootBot,它将调用skillDialogBot。

我的dialogRootBot能够调用skillDialogBot。对话可以继续进行,直到应该使用skillDialogBot将结果返回到dialogRootBot为止。

skillDialogBot具有以下设置

this.addDialog(new TextPrompt(TEXT_PROMPT))
.addDialog(new ConfirmPrompt(CONFIRM_PROMPT))
.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
    this.processStep.bind(this)
]));

processStep的布局如下

async processStep(stepContext) {
const details = stepContext.options;
details.result = {
    status: 'success'
};
return await stepContext.endDialog(stepContext.options);

}

我希望在processStep调用endDialog之后,dialogRootBot可以从skillDialogBot中获取结果,但是那永远不会发生。取而代之的是,用户一直停留在skillDialogBot上,直到用户手动键入“ abort”为止,这是dialogRootBot正在监视取消其onContinueDialog()实现中的所有对话框的命令。

这是onContinueDialog()的样子

async onContinueDialog(innerDc) {
    const activeSkill = await this.activeSkillProperty.get(innerDc.context, () => null);
    const activity = innerDc.context.activity;
    if (activeSkill != null && activity.type === ActivityTypes.Message && activity.text) {
        if (activity.text.toLocaleLowerCase() === 'abort') {
            // Cancel all dialogs when the user says abort.
            // The SkillDialog automatically sends an EndOfConversation message to the skill to let the
            // skill know that it needs to end its current dialogs, too.
            await innerDc.cancelAllDialogs();
            return await innerDc.replaceDialog(this.initialDialogId, { text: 'Request canceled!' });
        }
    }

    return await super.onContinueDialog(innerDc);
}

我以botbuilder-samples \ samples \ javascript_nodejs \ 81.skills-skilldialog示例为模型。如果我要更改skillDialogBot并让它在finalStep()的endDialog()之前执行ConfirmPrompt(),则对话将以SkillDialogBot()将对话框的结果发布到rootDialogBot正确结束。

为清楚起见,这是技能-技能对话框示例中的bookingDialog的外观

/**
 * Confirm the information the user has provided.
 */
async confirmStep(stepContext) {
    const bookingDetails = stepContext.options;

    // Capture the results of the previous step.
    bookingDetails.travelDate = stepContext.result;
    const messageText = `Please confirm, I have you traveling to: ${ bookingDetails.destination } from: ${ bookingDetails.origin } on: ${ bookingDetails.travelDate }. Is this correct?`;
    const msg = MessageFactory.text(messageText, messageText, InputHints.ExpectingInput);

    // Offer a YES/NO prompt.
    return await stepContext.prompt(CONFIRM_PROMPT, { prompt: msg });
}

/**
 * Complete the interaction and end the dialog.
 */
async finalStep(stepContext) {
    if (stepContext.result === true) {
        const bookingDetails = stepContext.options;
        return await stepContext.endDialog(bookingDetails);
    }
    return await stepContext.endDialog();
}

在没有提示的情况下,endDialog()是否不可能?为什么我的skillDialogBot无法endDialog并将结果传递给rootDialogBot?

谢谢

1 个答案:

答案 0 :(得分:0)

为参考起见,当使用stepContext.beginDialog()时,如果瀑布对话框未添加提示步骤,则我们似乎无法可靠地endDialog()。如果存在用例,我们要使用skillDialogBot并通过stepContext.beginDialog()在skillDialogBot中调用特定对话框,并且被调用的对话框仅在进行处理(例如,调用REST API),而无需提示用户进一步的信息,在处理结束时,我们可以选择结束对话。

因此,假设我们将finalStep()绑定到瀑布对话框作为最后一步,只需在finalStep()中使用以下内容

return await stepContext.context.sendActivity({
    type: ActivityTypes.EndOfConversation,
    code: EndOfConversationCodes.CompletedSuccessfully,
    value: stepContext.options
});

至少对于我的用例,我能够在不需要用户提示的情况下终止对话框,并将结果返回到rootDialog。