【发布时间】:2020-05-26 07:10:36
【问题描述】:
我的亚马逊 lex 机器人意图中有 7 个插槽。
{
slot1: null,
slot2: null,
slot3: null,
slot4: null,
slot5: null,
slot6: null,
slot7: null
}
slot2 有 2 个分辨率值。 Yes 或 No。
slot3 有 3 个分辨率值。
我想要实现的是,如果选择 Yes,然后在 slot3 中显示值并满足意图。
如果选择 No,则跳过 slot3 并继续处理更多的插槽。
以下是用于初始化和验证代码钩子的 lambda 代码,请阅读 cmets:
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
}
};
};
【问题讨论】:
-
你试过什么?分享相关的 Lambda 代码,我们就知道你是用 Python 还是 Node JS 并给你答案。
-
@JayA.Little 我已经更新了这个问题。请立即查看。
标签: amazon-web-services aws-lambda amazon-lex