如何在AWS Lex中添加多个响应 [英] How to ADD Multiple Responses in AWS Lex

查看:89
本文介绍了如何在AWS Lex中添加多个响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用AWS Lambda函数为AWS Lex添加多个响应,但是我遇到了这个错误.

I was trying to add Multiple Responses for AWS Lex using AWS Lambda Functions but I am facing this error.

我正在尝试

I was trying for

但是我被消息困住了

发生错误:无效的Lambda响应:从Lambda接收到无效的响应:无法构造Message实例,问题:contentType在[Source:{"dialogAction":{"type":"ConfirmIntent", "message":{"messages":[{"contentType":"PlainText","group":1,"content":"Hello"},{"contentType":"PlainText","group":2,"content:" My},{" contentType:" PlainText," group:3," content:" Friend}]}," intentName:" CardsI," slots:{" CardsB": 空值}}};行:1,列:252]

An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of Message, problem: contentType must not be null at [Source: {"dialogAction": {"type": "ConfirmIntent", "message": {"messages": [{"contentType": "PlainText", "group": 1, "content": "Hello"}, {"contentType": "PlainText", "group": 2, "content": "My"}, {"contentType": "PlainText", "group": 3, "content": "Friend"}]}, "intentName": "CardsI", "slots": {"CardsB": null}}}; line: 1, column: 252]

在Lambda函数中,我们使用以下代码来打印多个响应

In Lambda Function we are using the following code for printing multiple responses

return {
    "dialogAction": {
        "type": "ConfirmIntent",
        "message": {
            "messages": [{
                    "contentType": "PlainText",
                    "group": 1,
                    "content": "Hello"
                },
                {
                    "contentType": "PlainText",
                    "group": 2,
                    "content": "My"
                },
                {
                    "contentType": "PlainText",
                    "group": 3,
                    "content": "Friend"
                }
            ]
        },
        "intentName": "CardsI",
        "slots": {
            "CardsB": ""
        }
    }
}

我们甚至浏览了

  1. https://docs.aws.amazon.com/lex/latest/dg/howitworks-manage-prompts.html#message-groups

    https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html#special-response

    但是我们仍然面临着问题.有帮助吗?

    but we still are facing issue. Any help ?

    推荐答案

    我遇到了同样的问题,文档没有任何建议.但是,检查来自lex的网络响应时,我们可以看到,在有多个消息的情况下,消息数组是作为字符串而不是作为对象传递的.

    I had the same problem, The docs don't suggest anything. But when inspecting the network response from the lex we can see that in case of multiple messages the array of messages passed in as a string, not as an object.

    lambda的响应应采用以下格式.

    The response from the lambda should be in the below format.

    return {
    "dialogAction": {
        "type": "ConfirmIntent",
        "message": {
            "contentType": "CustomPayload",
            "content": "{\"messages\":[{\"type\":\"PlainText\",\"group\":1,\"value\":\"Hello\"},{\"type\":\"PlainText\",\"group\":2,\"value\":\"Hey\"}]}"
        },
        "intentName": "CardsI",
        "slots": {
            "CardsB": null
        }
    }
    

    这篇关于如何在AWS Lex中添加多个响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆