Amazon lex 根据前一个插槽的解析值跳过一个插槽
Amazon lex skip a slot based on resolved value of previous slot
我的 amazon lex bot intent 中有 7 个插槽。
{
slot1: null,
slot2: null,
slot3: null,
slot4: null,
slot5: null,
slot6: null,
slot7: null
}
slot2 has 2 values for resolution. Yes or No.
slot3 has 3 values for resolution.
我想要实现的是,如果选择 Yes,然后在 slot3 中显示值并完成意图。
如果选择 否,则跳过 slot3 并继续进行其他插槽。
下面是用于初始化和验证代码钩子的lambda代码,请阅读评论:
exports.handler = async(event) => {
if (event.currentIntent.slots.slot2 != null) {
if (event.currentIntent.slots.slot4 == null) {
// handle slot2 "yes" or "no"
switch (event.currentIntent.slots.slot2) {
case 'No':
return {
dialogAction: {
type: "ElicitSlot",
intentName: event.currentIntent.name,
slots: event.currentIntent.slots,
slotToElicit: "slot4"
}
};
}
}
// If slot2 value is yes and any one of the value from slot3 is selected then fulfill the intent. Alo if you can tell me that we can add some call to action on slot3 value clicks like mailto: or tel: it will be really helpful.
if (event.currentIntent.slots.slot2 === "Yes" && event.currentIntent.slots.slot3 != null) {
return {
dialogAction: {
type: "Close",
fulfillmentState: "Fulfilled",
message: {
contentType: "PlainText",
content: "Fullfillment text"
}
}
}
}
// here I am trying to remove slot3 from the intent when slot2 value is "no"
if (event.currentIntent.slots.slot2 === "No" && event.currentIntent.slots.slot4 != null) {
delete event.currentIntent.slots.slot3;
}
}
// default return dialog action
return {
dialogAction: {
type: "Delegate",
slots: event.currentIntent.slots
}
};
};
看起来不错。
首先,不要删除slot3
。基本上,任何时候您不需要使用插槽,只需将其保留或将其设置为 null
并确保它没有按照您的 Lex 控制台的要求进行勾选,仅此而已。如果删除它,那么您的响应将不再匹配 Lex 期望的所有槽。
您正在使用 DialogAction
: "Delegate",这让 Lex 决定接下来要引出哪个插槽。所以在 Lex 引出 slot2
之后,我相信 Lex 会简单地选择下一个插槽。但是,Lex 可能会选择下一个 required 插槽优先于非必需插槽,因此请再次确保未按要求勾选 slot3
。
为了更好地控制您的对话,您可能根本不想使用 Delegate,而是完全按照您的喜好构建对话逻辑,仅使用 ElicitSlot 来确保在正确的时间点引出正确的插槽对话。
如果我简化你的代码,它看起来像这样:
if slot2 != null
if slot4 == null
if slot2 == No
elicit slot4
if slot2 == Yes and slot3 != null
fulfill intent
else
delegate
有些事情你可以清理一下,这样看可能会为你阐明这个问题,但也许你有计划扩展它并且有一个原因,例如你为什么使用 switch case只有一个案例(目前?)。
考虑一种没有委托的更直接和可控的方法:
if slot1 == null
elicit slot1
else // slot1 filled
if slot2 == null
elicit slot2
else // slot2 filled
(validate slot2 value)
if slot2 == Yes
if slot3 == null
elicit slot3
else // slot3 filled
(validate slot3 value)
fulfill intent
if slot2 == No
elicit slot4
...
从 slot1 跳到 slot3,你能跳到 slot5 并且 slot5 把我送到 slot6 吗?我无法解决它,我只能跳到一个插槽但是当我尝试跳到另一个插槽时它会循环,如果它更新它的值但不改变插槽?谢谢!
我的 amazon lex bot intent 中有 7 个插槽。
{
slot1: null,
slot2: null,
slot3: null,
slot4: null,
slot5: null,
slot6: null,
slot7: null
}
slot2 has 2 values for resolution. Yes or No.
slot3 has 3 values for resolution.
我想要实现的是,如果选择 Yes,然后在 slot3 中显示值并完成意图。
如果选择 否,则跳过 slot3 并继续进行其他插槽。
下面是用于初始化和验证代码钩子的lambda代码,请阅读评论:
exports.handler = async(event) => {
if (event.currentIntent.slots.slot2 != null) {
if (event.currentIntent.slots.slot4 == null) {
// handle slot2 "yes" or "no"
switch (event.currentIntent.slots.slot2) {
case 'No':
return {
dialogAction: {
type: "ElicitSlot",
intentName: event.currentIntent.name,
slots: event.currentIntent.slots,
slotToElicit: "slot4"
}
};
}
}
// If slot2 value is yes and any one of the value from slot3 is selected then fulfill the intent. Alo if you can tell me that we can add some call to action on slot3 value clicks like mailto: or tel: it will be really helpful.
if (event.currentIntent.slots.slot2 === "Yes" && event.currentIntent.slots.slot3 != null) {
return {
dialogAction: {
type: "Close",
fulfillmentState: "Fulfilled",
message: {
contentType: "PlainText",
content: "Fullfillment text"
}
}
}
}
// here I am trying to remove slot3 from the intent when slot2 value is "no"
if (event.currentIntent.slots.slot2 === "No" && event.currentIntent.slots.slot4 != null) {
delete event.currentIntent.slots.slot3;
}
}
// default return dialog action
return {
dialogAction: {
type: "Delegate",
slots: event.currentIntent.slots
}
};
};
看起来不错。
首先,不要删除slot3
。基本上,任何时候您不需要使用插槽,只需将其保留或将其设置为 null
并确保它没有按照您的 Lex 控制台的要求进行勾选,仅此而已。如果删除它,那么您的响应将不再匹配 Lex 期望的所有槽。
您正在使用 DialogAction
: "Delegate",这让 Lex 决定接下来要引出哪个插槽。所以在 Lex 引出 slot2
之后,我相信 Lex 会简单地选择下一个插槽。但是,Lex 可能会选择下一个 required 插槽优先于非必需插槽,因此请再次确保未按要求勾选 slot3
。
为了更好地控制您的对话,您可能根本不想使用 Delegate,而是完全按照您的喜好构建对话逻辑,仅使用 ElicitSlot 来确保在正确的时间点引出正确的插槽对话。
如果我简化你的代码,它看起来像这样:
if slot2 != null
if slot4 == null
if slot2 == No
elicit slot4
if slot2 == Yes and slot3 != null
fulfill intent
else
delegate
有些事情你可以清理一下,这样看可能会为你阐明这个问题,但也许你有计划扩展它并且有一个原因,例如你为什么使用 switch case只有一个案例(目前?)。
考虑一种没有委托的更直接和可控的方法:
if slot1 == null
elicit slot1
else // slot1 filled
if slot2 == null
elicit slot2
else // slot2 filled
(validate slot2 value)
if slot2 == Yes
if slot3 == null
elicit slot3
else // slot3 filled
(validate slot3 value)
fulfill intent
if slot2 == No
elicit slot4
...
从 slot1 跳到 slot3,你能跳到 slot5 并且 slot5 把我送到 slot6 吗?我无法解决它,我只能跳到一个插槽但是当我尝试跳到另一个插槽时它会循环,如果它更新它的值但不改变插槽?谢谢!