简体   繁体   English

botFramework v4如何在LUIS调用后处理对话框响应

[英]botFramework v4 how to handle dialog response after LUIS call

I have a bot written in C# that is using LUIS to determine intents. 我有一个用C#编写的机器人,它使用LUIS来确定意图。 I have a method that makes a call to the LUIS service and then looks for an 'Open_Case' intent. 我有一个方法来调用LUIS服务,然后寻找一个“ Open_Case”意图。 The model has a CaseNumber entity defined which may or may not be included in the response from the LUIS service. 该模型定义了一个CaseNumber实体,该实体可以或可以不包括在LUIS服务的响应中。 If the response doesn't have a case number entity I start a dialog to ask the user for the case number. 如果响应中没有案例编号实体,那么我将启动一个对话框,要求用户输入案例编号。 Once I have a case number I then want to return a card with case information. 有了案件号后,我想退还一张包含案件信息的卡。

Here's the code I have:- 这是我的代码:

/// <summary>
/// Dispatches the turn to the requested LUIS model.
/// </summary>
private async Task DispatchToLuisModelAsync(ITurnContext context, string appName, DialogContext dc, CancellationToken cancellationToken =
default (CancellationToken)) {
var result = await botServices.LuisServices[appName].RecognizeAsync(context, cancellationToken);
var intent = result.Intents ? .FirstOrDefault();

    string caseNumber = null;

    if (intent ? .Key == "Open_Case") {
    if (!result.Entities.ContainsKey("Case_CaseNumber")) {
    var dialogResult = await dc.BeginDialogAsync(CaseNumberDialogId, null, cancellationToken);
     } else {
      caseNumber = (string)((Newtonsoft.Json.Linq.JValue) result.Entities["Case_CaseNumber"].First).Value;
      var cardAttachment = botServices.CaseInfoServices.LookupCase(caseNumber);
      var reply = context.Activity.CreateReply();
      reply.Attachments = new List < Attachment > () {
       cardAttachment
      };
      await context.SendActivityAsync(reply, cancellationToken);
     }
    }
   }

What I'm struggling with is where the code send the card response should sit. 我正在努力的是代码发送卡响应的位置。 In the code I currently have I send the card if the number was returned in the LUIS response, but if there was no number and I start the dialog then I only get access to the number either in the final step of the dialog or in the dialog result in the root turn handler. 在当前代码中,如果LUIS响应中返回了数字,则我将卡片发送给我,但是如果没有数字,并且启动了对话框,则只能在对话框的最后一步或在对话框中访问该数字。对话结果在根转弯处理程序中。 I've currently duplicated the reply inside the final step in the dialog, but it feels wrong and inelegant. 我目前已在对话框的最后一步中复制了答复,但感觉不对且不雅。 I'm sure there must be a way that I can collect the number from LUIS or the dialog and THEN send the response from a single place instead of duplicating code. 我确信必须有一种方法可以从LUIS或对话框中收集号码,然后从一个地方发送响应,而不是重复代码。

Any suggestions gratefully received... 感谢收到任何建议...

我得出的结论是,我需要将显示卡的代码放入bot类的方法中,然后在dialogTurnStatus等于Complete时从代码片段中的else以及转弯处理程序中调用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM