amazon-web-services - 如何处理对 Amazon Lex 的 lambda 响应?

标签 amazon-web-services aws-lambda amazon-dynamodb amazon-lex

我想通过 Lambda 集成将 Amazon Lex Chatbot 中给出的输入存储在 Amazon DynamoDB 中。如何处理来自 Amazon Lambda 的响应。我收到的错误为 - (发生错误:无效的 Lambda 响应:从 Lambda 收到无效响应:意外的 token (END_OBJECT),预期的 FIELD_NAME:缺少包含类型 id 的属性“类型”(对于类 DialogAction )在 [来源:{"dialogAction":{"Type":"Close","fulfillmentState":"failed","message":{"ContentType":"PlainText","Content":"嘿 null,您的请求nullTickets on null at null"}}};行:1,列:164] )

请帮忙解决这个问题。我的 Amazon Lambda 代码如下,

exports.handler = (事件、上下文、回调) => {

var Name = event.currentIntent.slots.Name;
var TicketType = event.currentIntent.slots.TicketType;
var BookingDate = event.currentIntent.slots.BookingDate;
var BookingTime = event.currentIntent.slots.BookingTime;
callback(null, {
    "dialogAction": {
        "Type":"Close",
        "fulfillmentState": "failed",
        "message": {
            "ContentType": "PlainText",
            "Content":  "Hey " +Name+ ",  Your Requested "+ TicketType + "Tickets on " +BookingDate+" at " +BookingTime+"" ,
        }
    }

})

}

最佳答案

以下是 Lambda 对 Lex 的典型响应。

“type”有拼写错误,请使用小写(“type”而不是“Type”)

{
    "sessionAttributes": {
    "key1": "value1",
    "key2": "value2"
    ...
  },
  "recentIntentSummaryView": [
    {
       "intentName": "Name",
       "checkpointLabel": "Label",
       "slots": {
         "slot name": "value",
         "slot name": "value"
        },
       "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)",
        "dialogActionType": "ElicitIntent, ElicitSlot, ConfirmIntent, Delegate, or Close",
        "fulfillmentState": "Fulfilled or Failed",
        "slotToElicit": "Next slot to elicit
    }
  ],
  "dialogAction": {
    "type": "ElicitIntent, ElicitSlot, ConfirmIntent, Delegate, or Close",
    Full structure based on the type field.
  }
}

引用:https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html#using-lambda-response-format

关于amazon-web-services - 如何处理对 Amazon Lex 的 lambda 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60097648/

相关文章:

javascript - Dynamodb 中的项目的值为 undefined

visual-studio-2010 - 适用于 .NET 的 AWS Toolkit 无法在 Visual Studio 中打开

amazon-dynamodb - DynamoDB 读写

amazon-web-services - 仅来自某些文件的日志显示 aws cloudwatch

amazon-web-services - 如何在 terraform 中导入 aws_lambda_permission

node.js - context.done 在处理程序 'graphql' 中调用了两次

amazon-web-services - 尝试配置 lambda 蓝图 iot-button-email 时输入无效

grails - 使用Dynamodb的Grails Spring 安全性

amazon-web-services - 如何检索用于向注册表验证 Docker 客户端的登录命令

amazon-web-services - 无法通过 ssh 隧道 + 代理连接到远程实例