如何为使用Microsoft机器人框架构建的团队机器人提供动态流程?

时间:2020-06-02 08:41:17

标签: botframework microsoft-graph-api microsoft-teams

我创建了一个由标签和漫游器组成的Microsoft团队应用。我将其作为reference来创建团队插件。在这里,我使用的是bot框架建议的Waterfall流模型。在使用此功能时,我必须给出固定数量的动作,但是我想进行动态动作。这是示例

class MainDialog extends ComponentDialog {
constructor(luisRecognizer, bookingDialog) {
    super('MainDialog');

    if (!luisRecognizer) throw new Error('[MainDialog]: Missing parameter \'luisRecognizer\' is required');
    this.luisRecognizer = luisRecognizer;

    if (!bookingDialog) throw new Error('[MainDialog]: Missing parameter \'bookingDialog\' is required');

    // Define the main dialog and its related components.
    // This is a sample "book a flight" dialog.
    this.addDialog(new TextPrompt(TEXT_PROMPT))
        .addDialog(bookingDialog)
        .addDialog(nominationDialogue)
        .addDialog(new ChoicePrompt(CHOICE_PROMPT))
        .addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
            this.introStep.bind(this),
            this.decidestep.bind(this),
            this.originStep.bind(this),
            this.actStep.bind(this),
            this.Actualstep.bind(this)
        ]));

    this.initialDialogId = MAIN_WATERFALL_DIALOG;
}

/**
 * The run method handles the incoming activity (in the form of a TurnContext) and passes it through the dialog system.
 * If no dialog is active, it will start the default dialog.
 * @param {*} turnContext
 * @param {*} accessor
 */
async run(turnContext, accessor) {
    const dialogSet = new DialogSet(accessor);
    dialogSet.add(this);

    const dialogContext = await dialogSet.createContext(turnContext);
    const results = await dialogContext.continueDialog();
    if (results && results.status === DialogTurnStatus.empty) {
        await dialogContext.beginDialog(this.id);
    }
}

我该如何转到上一个功能,即actStep再次决定DecisionsStep,而不会出现任何问题。我尝试从actStep调用defineStep,然后出现异常并且bot失败了。当有一些重复的工作要完成时,由于操作数量固定,我无法执行。

谢谢。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,并且使用类似以下代码(C#)的方法解决了该问题。这不干净(有点黑),但是可以用

private static async Task<DialogTurnResult> actStep (WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    .
    .
    .
    stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 2;
    return await stepContext.NextAsync(null, cancellationToken);
}

答案 1 :(得分:1)

请问一下Conversation Bot的示例代码。

您可以找到更多示例解决方案here