【问题标题】:Amazon lex skip a slot based on resolved value of previous slotAmazon lex 根据前一个插槽的解析值跳过一个插槽
【发布时间】: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


【解决方案1】:

看起来不错。

首先,不要删除slot3。基本上,只要您不需要使用插槽,只需将其保留或将其设置为 null 并确保在您的 Lex 控制台中没有按要求勾选它,仅此而已。如果您删除它,那么您的响应将不再匹配 Lex 期望的所有位置。

您正在使用DialogAction: "Delegate",它让 Lex 确定接下来要引出的槽。所以在 Lex 引出slot2 之后,我相信 Lex 会简单地选择下一个插槽。但是,Lex 可能会选择下一个 必需 槽作为非必需槽的优先级,因此请再次确保 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
        ...

【讨论】:

  • 非常感谢。只需取消选中控制台中所需的复选框并进行一些逻辑调整即可使其工作。
【解决方案2】:

从 slot1 跳到 slot3,你能跳到 slot5 并且那个 slot5 把我送到 slot6 吗?我无法解决它,我只能跳到一个插槽,但是当我尝试跳到另一个插槽时,它会循环,如果它更新了它的值但不更改插槽?谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多