为响应中的特定槽提供槽值并恢复对话

provide slot value for specific slot in response and resume the conversation

我正在处理 lex 并想在响应中提供槽值,如果用户在前一个槽值中输入特定输入,系统只会询问它。我正在尝试一些事情,但我不知道我做得对不对。

我在 lex 中有以下插槽。

  1. Departure_city
  2. Arrival_city
  3. 出发(单程或往返)
  4. 返回日期
  5. 日期(出发日期)
  6. 航班时刻表

例如如果用户 select 往返则询问 return 日期否则跳过该槽并通过询问剩余槽的值继续流程

这是我为实现此场景所做的一段代码。

"use strict";

const lexResponses = require("./lexResponse");

const depart = ["one-way", "oneway"];

const buildValidationResult = (isValid, violatedSlot, messageContent) => {
  if (messageContent == null) {
    return {
      isValid: isValid,
      violatedSlot: violatedSlot,
    };
  }
  return {
    isValid: isValid,
    violatedSlot: violatedSlot,
    message: { contentType: "PlainText", content: messageContent },
  };
};

function validateBookaflight(
  Departing,
  ReturnDate
) {
  if (Departing && depart.indexOf(Departing.toLowerCase()) === -1) {
   
     return {
          dialogAction: {
            type: "ElicitSlot",
            intentName: "Bookaflight",
            slots: {
              Departure_city: Departure_city,
              Arrival_city: Arrival_city,
              Departing: Departing,
              ReturnDate: ReturnDate,
            },
            slotToElicit: "ReturnDate",
            message: {
              contentType: "PlainText",
              content: "Please enter return date,(yyyy-mm-dd)",
            },
          },
        }
    };
     return buildValidationResult(true, null, null);
}

function buildFulfilmentResult(fullfilmentState, messageContent) {
  return {
    fullfilmentState,
    message: { contentType: "PlainText", content: messageContent },
  };
}

错误:

An error has occurred: Invalid Lambda 
Response: Received invalid response from 
Lambda: Can not construct instance of 
ElicitSlotDialogAction, problem: 
slotToElicit must not be blank in ElicitSlot 
dialog action at 
[Source: {"sessionAttributes":{},"dialogAction":{"type":"ElicitSlot","intentName":"Bookaflight",
"slots":{"ReturnDate":null,"Departure_city":"london","Flight_schedule":null,"Arrival_city":"lahore","Date":null,
"Departing":"roundtrip",
"undefined":null}}}; line: 1, column: 241]

请告诉我哪里做错了,或者如果您在理解我的要求时遇到任何问题。

您看到的问题似乎是由于 slotToElicit 参数出于某种原因未 returned 到 Lex 引起的。要确认 Lambda return 对 Lex 的作用,请尝试 运行 使用 Lex 机器人传递的相同输入对该函数进行测试调用。

此外,当 return 在 Lambda 响应中输入槽的值时,如果您不 return 其他槽的值,Lex 会将它们视为空值。因此,确保 returned 的所有插槽值不是 null 并且包含用户输入的值。