【问题标题】:How to send multiple messages to user as answer from AWS lambda?如何从 AWS lambda 向用户发送多条消息作为答案?
【发布时间】:2019-12-26 19:18:02
【问题描述】:

我已按照教程设置 Lex&Lambda。我的 lambda 函数返回

return {
            "dialogAction": {
                "type": "ConfirmIntent",
                "intentName": "GetPersonInfo",
                "message": {
                    "contentType": "PlainText",
                    "content": ""
                }
            }
        }

并且 Lex 将其显示为单个消息。当我在 aws 网站上构建我的机器人时,我可以设置多条消息作为答案(不使用 lambda),我想使用 lambda 函数来做到这一点,就像在 img 上一样:https://docs.aws.amazon.com/lex/latest/dg/images/default-response-25a.png

在 aws 网站上,我为多条消息准备了输出,它看起来像这样:

{
  "dialogState": "Fulfilled",
  "intentName": "GetPersonInfo",
  "message": "{\"messages\":[{\"type\":\"PlainText\",\"group\":1,\"value\":\"siema siemanko\"},{\"type\":\"CustomPayload\",\"group\":2,\"value\":\"{\\\"moj\\\":\\\"json\\\"}\"}]}",
  "messageFormat": "Composite",
...
}

我注意到 Lex 期望“dialogAction”作为 lambda 输出,并且在“PostText”和“PostContent”中使用了多消息功能。我知道,dialogAction 用于构建 PostText/PostContent 对象。

我还想向语音发送不同的消息,不同的显示为文本,另一个显示为 JSON(用于我的前端)。现在我的解决方案是在 dialogAction 对象中将所有内容作为纯文本消息发送,然后通过我的前端执行 Polly 来阅读为演讲准备的消息。是否可以仅使用 Lex 和 lambda 来做这些事情?

【问题讨论】:

    标签: python amazon-web-services aws-lambda amazon-lex


    【解决方案1】:

    我知道显示多条消息的唯一方法是通过 AWS Lex 端的 Lex 配置来实现。举个例子: 1. 您创建一个带有话语I want to get information about user {UserEmailAddress}. 的意图 2. 您创建一个必需的插槽UserEmailAddress 和非必需的UserFirstNameUserLastName。 3.一旦第一个插槽被话语填充,您就可以在 Lambda 导出函数中向后端 API 发送请求,以通过他的电子邮件地址获取有关该用户的信息并填充其他插槽(代码适用于节点 8.10,您可以创建自己的Python版本): `

    exports.handler = async (event, context) => {
        ...
        return context.succeed({
            event.sessionAttributes,
            dialogAction: {
                type: "Delegate",
                {
                    ...event.currentIntent.slots,
                    UserFirstName: httpResponse.firstName,
                    UserLastName: httpResponse.lastName
                }
            }
        })
    }
    

    ` 4. 在您​​的意图的“响应”部分中添加多条消息: 这是用户 {UserEmailAddress} 的信息 他的名字是 {UserFirstName},姓氏是 {UserLastName}。 5. 将包含话语的问题添加为一个/多个响应的响应卡。例如,“你接下来想做什么?”这个问题。和一个按钮: 按钮标题:“获取他的地址”, 按钮值:“”

    理想情况下,对话框应如下所示:

    User: I want to get information about user simon@tech.com
    Bot: Here is the information about user simon@tech.com
    Bot: His first name is Simon his last name is Anderson
    Bot: What do you want to do next?
         [Get his address]
    

    当您单击按钮时,它看起来与插槽的普通响应相同。

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 2019-03-15
      • 2023-03-18
      • 2016-12-25
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 2023-02-13
      • 2023-01-30
      相关资源
      最近更新 更多