【问题标题】:provide slot value for specific slot in response and resume the conversation为特定插槽提供插槽值作为响应并恢复对话
【发布时间】:2021-02-19 10:22:56
【问题描述】:

我正在研究 lex 并希望在响应中给出槽值,只有在用户在前一个槽值中输入特定输入时才会询问该值。我正在尝试一些事情,但我不知道我做得对与否。

我在 lex 中有以下插槽。

  1. Departure_city
  2. Arrival_city
  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 },
  };
}

错误:

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]

请告诉我做错了什么,或者如果您在理解我的要求方面有任何问题。

【问题讨论】:

  • 您应该返回所有已输入的槽值,而不仅仅是“ReturnDate”。如果您不返回它,则插槽将被视为空。如果这没有帮助,请发布完整的错误消息。
  • @Paradigm 我已更新错误消息和更新代码。请检查。
  • 您能否通过使用 lex 传递的相同输入从 Lambda 控制台进行测试运行来确认 Lambda 函数返回什么?
  • @Paradigm 我可以与您共享日志。在日志中它没有显示任何错误
  • 或跳过一个插槽也可以,例如如果用户输入 oneway 所以,跳过 returnDate 槽,否则不要跳过。这可能吗?

标签: javascript amazon-web-services amazon-lex


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 2019-07-12
  • 2020-04-29
  • 1970-01-01
  • 2019-07-08
  • 2020-03-12
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
  • 1970-01-01
相关资源
最近更新 更多