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

问题描述

我正在研究lex,想在响应中提供slot值,仅在用户是否在前一个slot值中输入了特定的输入时才会询问。我正在尝试某些东西,但我做对与否。

我在lex中有以下插槽。

  1. 出发城市
  2. 到达城市
  3. 出发(单程或往返)
  4. ReturnDate
  5. 日期(DepartureDate)
  6. 航班时刻表

例如如果用户选择“往返”,则要求返回日期,否则,请跳过该时段并通过询问剩余时段的值来继续进行操作

这是我为实现此方案而要做代码

"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,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,};
}

错误

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]

enter image description here

请告诉我我在做错什么,或者您在理解我的要求时是否有任何问题。

解决方法

您看到的问题似乎是由于slotToElicit参数由于某种原因未返回给Lex引起的。要确认Lambda返回Lex的内容,请尝试使用Lex bot传递的相同输入来运行该函数的测试调用。

此外,在Lambda响应中返回插槽的值时,如果不返回其他插槽的值,则Lex会将它们视为null。因此,请确保返回的所有插槽值都不为null,并包含用户输入的值。