【问题标题】:How to reconstruct a response to Amazon lex from AWS lambda?如何从 AWS lambda 重建对 Amazon lex 的响应?
【发布时间】:2019-09-16 14:08:06
【问题描述】:

我在 lex 控制台中设置了一个机器人,它从用户那里收集数据,例如他们感兴趣的产品/服务以及电子邮件 ID、电话号码等。现在,每次访问者与机器人交互时,我都想接收包含聊天对话的电子邮件。

我还创建了一个由 lex 实现触发的 lambda 函数,但我在 bot ui 上收到此错误 发生错误:无效的 Lambda 响应:收到来自 Lambda 的无效响应:无法构造 IntentResponse 的实例:没有字符串-参数构造函数/工厂方法从字符串值反序列化

根据文档,我已重建响应并返回它。

import json

def lambda_handler(event, context):
    print(event)

    var1 = '''dialogAction": {
    "type": "close",
    "fulfillmentState": "fulfilled",
    "message": {
      "contentType": "PlainText or SSML or CustomPayload",
      "content": "Message to convey to the user. For example, What size pizza would you like?"
    },
    }
    }'''
    return(var1)

这是错误的样子:-

An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse: no String-argument constructor/factory method to deserialize from String value ('"dialogAction": { "type": "close", "fulfillmentState": "fulfilled", "message": { "contentType": "PlainText or SSML or CustomPayload", "content": "Message to convey to the user. For example, What size pizza would you like?" }, } }') at [Source: "\"dialogAction\": {\n \"type\": \"close\",\n \"fulfillmentState\": \"fulfilled\",\n \"message\": {\n \"contentType\": \"PlainText or SSML or CustomPayload\",\n \"content\": \"Message to convey to the user. For example, What size pizza would you like?\"\n },\n }\n }"; line: 1, column: 1]

【问题讨论】:

    标签: python-3.x aws-lambda chatbot amazon-lex


    【解决方案1】:

    您错误地将响应作为字符串传递。通过使用三重引号''',它添加了您可以在错误源中看到的换行符\n,而您不需要这些。

    所以试试这个,只需将响应作为对象返回。我相信回调函数会在传递给 Lex 之前自动转换为 JSON。

     var1 = {
        dialogAction": {
             "type": "close",
             "fulfillmentState": "fulfilled",
             "message": {
                   "contentType": "PlainText or SSML or CustomPayload",
                   "content": "Message to convey to the user. For example, What size pizza would you like?"
             },
        }
    }
    return var1
    

    【讨论】:

      猜你喜欢
      • 2018-06-13
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 2021-07-23
      相关资源
      最近更新 更多