【发布时间】:2021-02-19 10:22:56
【问题描述】:
我正在研究 lex 并希望在响应中给出槽值,只有在用户在前一个槽值中输入特定输入时才会询问该值。我正在尝试一些事情,但我不知道我做得对与否。
我在 lex 中有以下插槽。
- Departure_city
- Arrival_city
- 出发(单程或往返)
- 返回日期
- 日期(出发日期)
- 航班时刻表
例如如果用户选择往返然后询问返回日期,否则跳过该插槽并通过询问剩余插槽的值继续流程
这是我为实现这个场景而做的一段代码。
"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