【问题标题】:AWS Lex lambda function Elicit slotsAWS Lex lambda 函数 引出槽
【发布时间】:2018-04-13 12:27:40
【问题描述】:

我现在正在构建 AWS Lex 聊天机器人,但在 lambda 函数设置方面遇到了一些问题。根据示例代码,它在对话结束时使用了这个 lambda 函数。这就是为什么代码是这样的:function close(.....)

'use strict';

    // Close dialog with the customer, reporting fulfillmentState of Failed 
       or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
    function close(sessionAttributes, fulfillmentState, message) {
        return {
            sessionAttributes,
            dialogAction: {
                type: 'Close',
                fulfillmentState,
                message,
            },
        };
    }

但是我想做的是使用 DialogCodeHook 而不是这个 FulfillmentCodeHook。

Lex 中最简单的逻辑是问问题 1-->得到答案 1-->问问题 2-->得到答案 2-->问问题 2-->得到答案 3; 我想做的是 1- 允许的响应值为 1.1、1.2 如果响应值 = 值 1.1 2 如果响应值 = 值 1.2 3 4- 价值 4.1,价值 4.2 ..等等

在 AWS 论坛上,答案如下: 是的,您可以使用 Lambda 来实现决策树。 Lambda 允许您设置特定消息并使用“dialogAction”引出一个槽。

对于这个特定的对话流程

if (response_value = 1.1) {
// set dialogAction.message = "Question 2"
...
// set type = ElicitSlot
...
// slotToElicit = answer2"

}

类似地,您可以定义提出问题 3、4 等的条件。

但我不确定我应该把这个 If..... 放在哪里以及如何使用这个 ElicitSlot 函数。

close函数的完整版示例代码为:

'use strict';

// Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
    return {
        sessionAttributes,
        dialogAction: {
            type: 'Close',
            fulfillmentState,
            message,
        },
    };
}

// --------------- Events -----------------------

function dispatch(intentRequest, callback) {
    console.log('request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.intentName}');
    const sessionAttributes = intentRequest.sessionAttributes;
    const slots = intentRequest.currentIntent.slots;
    const crust = slots.crust;
    const size = slots.size;
    const pizzaKind = slots.pizzaKind;

    callback(close(sessionAttributes, 'Fulfilled',
    {'contentType': 'PlainText', 'content': `Okay, I have ordered your ${size} ${pizzaKind} pizza on ${crust} crust`}));

}

// --------------- Main handler -----------------------

// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
    try {
        dispatch(event,
            (response) => {
                callback(null, response);
            });
    } catch (err) {
        callback(err);
    }
};

希望有人可以提供帮助!非常感谢!!!!!!!!!!!!!!!!!!!!!!!!

【问题讨论】:

  • 恐怕您的问题中的 lex 标签是错误的。 (这个 lex 标签是用于编译器编译工具 lex 或 flex 的,它经常与 yacc 或 bison 一起使用。)我相信这不是你想要的 lex。 (如果有疑问,请查看 lex 的气泡帮助或单击标签。)
  • 哦,是的,我的意思是 AWS Lex 函数。对此感到抱歉。谢谢!

标签: node.js amazon-web-services aws-lambda amazon-lex


【解决方案1】:

请查看此代码:https://github.com/nicholasjackson/slack-bot-lex-lambda/blob/master/src/dispatcher.js

它列出了所有可能场景的函数,包括您拥有的 close(...) 以及您所追求的 ElicitSlot(...) 。 请注意,还有一个 ElicitIntent 对话框操作类型,它没有在代码中使用,但在某些情况下可能很有用。

希望对您有所帮助。 提伯尔

【讨论】:

  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 2018-08-08
  • 2018-08-09
  • 1970-01-01
  • 2018-11-11
  • 2018-09-15
  • 2022-01-21
  • 1970-01-01
  • 2017-11-25
相关资源
最近更新 更多