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

2024-05-04

我正在处理 lex 并希望在响应中给出槽值,只有当用户在前一个槽值中输入特定输入时才会询问该值。我正在尝试一些事情,但我不这样做,我做得对还是错。

我在 lex 中有以下插槽。

  1. 出发城市
  2. 到达城市
  3. 出发(单程或往返)
  4. 归期
  5. 日期(出发日期)
  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,
    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 },
  };
}

error:

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由于某种原因参数没有返回到 Lex。要确认 Lambda 返回给 Lex 的内容,请尝试使用 Lex 机器人传递的相同输入来运行该函数的测试调用。

此外,当返回 Lambda 响应中槽的值时,如果您没有返回其他槽的值,Lex 会将它们视为 null。从而确保返回的所有槽值都不是null并包含用户输入的值。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为响应中的特定槽位提供槽位值并恢复对话 的相关文章

随机推荐