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

问题描述 投票:0回答:1

我已经创建了一个微软团队应用程序,它由标签和一个机器人组成。我把这个作为 参考 用于创建团队插件。这里我使用的是机器人框架建议的瀑布流模型。当使用这个模型时,我必须给出固定数量的动作,但我想有动态的动作。

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到decidedStep,而不出现任何问题。我试着从actStep中调用decisionStep,然后我就出现了异常,机器人失败了。当有一些重复性的工作要做时,由于动作数量固定,我无法做。

先谢谢你。

botframework microsoft-graph microsoft-teams
1个回答
1
投票

我也遇到了同样的问题,我用下面的代码(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
投票

你能不能看看下面的示例代码 对话机器人 .

你可以找到更多的解决方案样本 此处

© www.soinside.com 2019 - 2024. All rights reserved.