【问题标题】:How do I trigger LUIS in all dialogs retaining the previous context?如何在保留先前上下文的所有对话框中触发 LUIS?
【发布时间】:2022-01-11 19:15:04
【问题描述】:

我正在使用 Microsoft Bot Framework、LUIS 和 node.js 开发一个机器人。这个机器人基于 Microsoft Teams,我正在使用 TeamsBotSsoPrompt 和 Microsoft-Graph 对用户进行身份验证。

AUTH_DIALOG中的认证步骤如下:

async showUserInfo(stepContext) {

    const tokenResponse = stepContext.result;
    if (tokenResponse) {
      try {

        // Call Microsoft Graph on behalf of user
        const oboCredential = new OnBehalfOfUserCredential(tokenResponse.ssoToken);
        //console.log("oboCredential> " + JSON.stringify(oboCredential));
        const graphClient = createMicrosoftGraphClient(oboCredential, this.requiredScopes);
        const me = await graphClient.api("/me").get();
        const lanID = await graphClient.api("/me/onPremisesSamAccountName").get();
        if (me) {

          var authHeaders = {
            "user": me.userPrincipalName,
            "token": tokenResponse.token,
            header1: null,
            header2: null,
            header3: null,
          }

          userName = me.givenName;

          authHeaders['name'] = userName;

          await stepContext.context.sendActivity({ type: ActivityTypes.Typing });
          await stepContext.context.sendActivity(`Hello! <b>` + userName + `</b>`);
          await stepContext.context.sendActivity({ type: ActivityTypes.Typing });
          await stepContext.context.sendActivity("Let's get started.How can I help you?");
          return await stepContext.beginDialog(FLOW_DIALOG, authHeaders);

        } else {
          await stepContext.context.sendActivity({ type: ActivityTypes.Typing });
          await stepContext.context.sendActivity("Getting profile from Microsoft Graph failed! ");
          return await stepContext.endDialog();
        }
      }
      catch (error) {
           // error logged here
      }
    }
    else {
      await stepContext.context.sendActivity({ type: ActivityTypes.Typing });
      await stepContext.context.sendActivity("Login was not successful please try again.");
      return await stepContext.endDialog();
    }
  }

FLOW_DIALOG 是我启用 LUIS 的位置。从FLOW_DIALOG,我将机器人重定向到基于Intent 的其他对话框。但是当我在另一个对话框中并且如果我在机器人中输入某些内容时,当前对话结束并将流程返回到FLOW_DIALOG。我希望所有对话框触发 LUIS 并将流移动到正确的 Intent 对话框。

FLOW_DIALOG如下:

async introStep(stepContext) {
    const ActionCard = utility.createSuggestedActions(suggestionList, suggestionTitle);
    await stepContext.context.sendActivity({ type: ActivityTypes.Typing });
    await stepContext.context.sendActivity({ attachments: [ActionCard] });
    return { status: DialogTurnStatus.waiting };
}

async actStep(stepContext) {
    const luisRecognizer = new LuisRecogniser(luisConfig, stepContext.dialogs.telemetryClient);
    let authHeaders = stepContext.options;
    if (!luisRecognizer.isConfigured) {
        return await stepContext.context.sendActivity("Something went wrong. Please Contact Your Administrator");
    }
    
    const luisResult = await luisRecognizer.executeLuisQuery(stepContext.result ? stepContext.result : stepContext.context);
    topIntent = LuisRecognizer.topIntent(luisResult);
    switch (topIntent) {
        case "Intent1": {
            authHeaders['header1'] = luisResult.entities;
            return await stepContext.beginDialog(DIALOG_A, authHeaders);
        }
        case "Intent2": {
            authHeaders['header2'] = luisResult.entities;
            return await stepContext.beginDialog(DIALOG_B, authHeaders);
        }
        // ... and other intents in similar way
    }
}

现在,我确实尝试将 LUIS 添加到 onMessage 调用,但我无法访问 context.options 来设置或重置我拥有的 authHeaders。我知道DialogContext 的上下文是TurnContext。

因此,是否可以更改标头值并将其传递给对话框调用,并为用户从当前有权访问的任何对话框输入的每条消息触发 LUIS。

【问题讨论】:

  • 您可以查看此示例以了解有关对话框的更多信息 - Custom Dialogs Sample 并了解有关 Teams 身份验证的更多信息,您可以参考此内容 - Teams auth sample
  • 请同时参考此文档 - Using Dialogs
  • 你能帮我举个例子吗?我仍然无法弄清楚如何让 LUIS 提示每条带有样本的消息。我已经参考了这些样本,但仍然无法接近我想要的。
  • 您能否通过设置此示例进行检查 - Core bot。在此示例中,我们基于用户消息实现了 LUIS,选择了对话框并开始了流程。
  • 实际上我只遵循了这个例子。如果你看一下FLOW_DIALOG,它就像是一样的。我担心的是当我被引导到一个对话框时,如果我在那个对话框中输入我应该输入的内容能够允许 LUIS 处理它。然后如果没有找到 Intent 则继续对话框,否则重定向到另一个对话框。

标签: node.js botframework bots microsoft-teams azure-language-understanding


【解决方案1】:

似乎不支持将 LUIS 集成到 Waterfall 对话框中。在 TextPrompt 的情况下它工作得很好,但是当我们有 'ChoicePrompt' 或 'ConfirmPrompt' 时我找不到这样做的方法。

我们可以集成 LUIS 来决定启动哪个对话框,并且对于相同的示例也可用 - Core bot。

您也可以参考此链接以了解如何在机器人中使用对话框 - https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-waterfall-dialogs?view=azure-bot-service-4.0#using-dialogs

【讨论】:

    猜你喜欢
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多