javascript - 为特定插槽提供插槽值作为响应并恢复对话
问题描述
我正在研究 lex 并希望在响应中给出槽值,只会询问用户是否在前一个槽值中输入特定输入。我正在尝试一些事情,但我不知道我做得对与否。
我在 lex 中有以下插槽。
- 出发城市
- 到达城市
- 出发(单程或往返)
- 归期
- 日期(出发日期)
- 航班时刻表
例如,如果用户选择往返然后询问返回日期,否则跳过该插槽并通过询问剩余插槽的值来继续流程
这是我为实现这种情况而正在做的一段代码。
"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
某种原因未将参数返回给 Lex 造成的。要确认 Lambda 返回给 Lex 的内容,请尝试使用 Lex 机器人传递的相同输入运行函数的测试调用。
此外,在 Lambda 响应中返回槽的值时,如果您不返回其他槽的值,Lex 会将它们视为 null。因此确保返回的所有槽值都不是null
并且包含用户输入的值。
推荐阅读
- r - 当 menuItem 中的更多功能使用闪亮和闪亮的仪表板时,tabItem 无法显示内容
- angularjs-scope - Angurlarjs 中的范围
- amazon-web-services - 如何在同一个 AWS EMR 集群中同时运行 Spark 作业?
- javascript - Javascript中的时间复杂度分析
- c++ - sizeof(* struct pointer) 是否为您提供结构的值
- javascript - Firebase 数据对象访问
- mysql - firebird程序到mysql
- c++ - PeekMessage 和 PostMessage 用法
- javascript - 使用 JavaScript reduce 函数对数组进行排序
- php - 我将如何构建基于 Curl 示例的 php JSON POST 请求?