【问题标题】:Error importing json file in Lex Chatbot AWS在 Lex Chatbot AWS 中导入 json 文件时出错
【发布时间】:2021-03-24 23:20:03
【问题描述】:

我正在尝试使用 Lex 构建一个聊天机器人来获取实例详细信息。我正在尝试使用 json 构建 Bot。当我导入 json 文件时,它说“请求中的 JSON 结构无效。检查 JSON 结构并再次尝试您的请求。” .. 尝试了几个代码和相同的问题. 我不认为问题出在代码上,但我错过了什么.. 或者请指导我使用 Json 文件创建一个 Bot。

谢谢

{
"name": "AWSBot",
"intents": [
    {
        "intentName": "RunningInstances",
        "intentVersion": "7"
    },
    {
        "intentName": "InstanceStatus",
        "intentVersion": "2"
    },
    {
        "intentName": "GetAddress",
        "intentVersion": "2"
    },
    {
        "intentName": "ShutdownReason",
        "intentVersion": "9"
    },
    {
        "intentName": "Discovery",
        "intentVersion": "1"
    },
    {
        "intentName": "StartInstance",
        "intentVersion": "3"
    },
    {
        "intentName": "GetLaunchTime",
        "intentVersion": "1"
    },
    {
        "intentName": "StopInstance",
        "intentVersion": "3"
    }
],
"clarificationPrompt": {
    "messages": [
        {
            "contentType": "PlainText",
            "content": "Sorry, can you please repeat that?"
        }
    ],
    "maxAttempts": 5
},
"abortStatement": {
    "messages": [
        {
            "contentType": "PlainText",
            "content": "Sorry, I could not understand. Goodbye."
        }
    ]
},
"status": "READY",
"lastUpdatedDate": 1508081752.212,
"createdDate": 1495671152.723,
"idleSessionTTLInSeconds": 300,
"voiceId": "0",
"checksum": "4a7de68b-468c-43d0-8c6d-1e37e3f99ed3",
"version": "$LATEST",
"locale": "en-US",
"childDirected": false
}

{
    "name": "RunningInstances",
    "slots": [],
    "sampleUtterances": [
        "What's the number of running instances",
        "Tell me how many instances are running.",
        "How many servers are up"
    ],
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1498612715.974,
    "createdDate": 1495671367.924,
    "version": "$LATEST",
    "checksum": "bd5811f5-9ae1-4381-8f4a-c9dda7f690c8"
}


{
    "name": "InstanceStatus",
    "slots": [],
    "sampleUtterances": [
        "Tell me the status of my instances.",
        "Status report.",
        "how are my instances"
    ],
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1498612653.385,
    "createdDate": 1496013449.711,
    "version": "$LATEST",
    "checksum": "1525e15a-aa06-49c1-8031-68c14c861376"
}


{
    "name": "GetAddress",
    "slots": [
        {
            "name": "instance_id",
            "slotConstraint": "Optional",
            "slotType": "instance_id",
            "slotTypeVersion": "2",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 1,
            "sampleUtterances": []
        },
        {
            "name": "short_code",
            "slotConstraint": "Optional",
            "slotType": "AMAZON.NUMBER",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 2,
            "sampleUtterances": []
        }
    ],
    "sampleUtterances": [
        "What is the IP address of instance {instance_id}",
        "What is the IP address of instance {short_code}",
        "what's the name of {instance_id}",
        "what's the name of {short_code}",
        "hostname {instance_id}",
        "hostname {short_code}"
    ],
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1508081701.779,
    "createdDate": 1499550333.168,
    "version": "$LATEST",
    "checksum": "5ae31dcd-fde0-4cb4-b57e-7cb0ed7de635"
}


{
    "name": "ShutdownReason",
    "slots": [
        {
            "name": "instance_id",
            "slotConstraint": "Optional",
            "slotType": "instance_id",
            "slotTypeVersion": "2",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 1,
            "sampleUtterances": []
        },
        {
            "name": "short_code",
            "slotConstraint": "Optional",
            "slotType": "AMAZON.NUMBER",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "e.g. What city?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 2,
            "sampleUtterances": []
        }
    ],
    "sampleUtterances": [
        "Why is {instance_id} shut down",
        "Why is {short_code} shut down",
        "what's the reason for {instance_id} shutdown",
        "what's the reason for {short_code} shutdown",
        "why is {instance_id} off",
        "why is {short_code} off"
    ],
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1498612810.201,
    "createdDate": 1496798177.871,
    "version": "$LATEST",
    "checksum": "edbadfd6-e1e5-47c5-9cf7-22c06acde602"
}


{
    "name": "Discovery",
    "slots": [],
    "sampleUtterances": [
        "What can I ask you",
        "What can you do",
        "What functions do you have",
        "Tell me your available functions"
    ],
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1499530232.691,
    "createdDate": 1499530127.365,
    "version": "$LATEST",
    "checksum": "a4564397-238e-4c90-a4e4-c72e991c84c2"
}


{
    "name": "StartInstance",
    "slots": [
        {
            "name": "instance_id",
            "slotConstraint": "Optional",
            "slotType": "instance_id",
            "slotTypeVersion": "2",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 1,
            "sampleUtterances": []
        },
        {
            "name": "short_code",
            "slotConstraint": "Optional",
            "slotType": "AMAZON.NUMBER",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which number?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 2,
            "sampleUtterances": []
        }
    ],
    "sampleUtterances": [
        "Start instance {instance_id}",
        "Start instance {short_code}",
        "start {instance_id}",
        "start {short_code}",
        "turn on {instance_id}",
        "turn on {short_code}",
        "Spin up {instance_id}",
        "Spin up {short_code}"
    ],
    "confirmationPrompt": {
        "messages": [
            {
                "contentType": "PlainText",
                "content": "Are you sure you want to start this instance?"
            }
        ],
        "maxAttempts": 3
    },
    "rejectionStatement": {
        "messages": [
            {
                "contentType": "PlainText",
                "content": "OK, I won't start this instance."
            }
        ]
    },
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1498612493.964,
    "createdDate": 1497201911.538,
    "version": "$LATEST",
    "checksum": "3d24d22f-cf77-4d59-b773-14a2f3eda596"
}


{
    "name": "GetLaunchTime",
    "slots": [
        {
            "name": "instance_id",
            "slotConstraint": "Optional",
            "slotType": "instance_id",
            "slotTypeVersion": "2",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 1,
            "sampleUtterances": []
        },
        {
            "name": "short_code",
            "slotConstraint": "Optional",
            "slotType": "AMAZON.NUMBER",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 2,
            "sampleUtterances": []
        }
    ],
    "sampleUtterances": [
        "When was {instance_id} started",
        "When was {short_code} started",
        "Uptime {instance_id}",
        "Uptime {short_code}",
        "Tell me when {instance_id} was launched",
        "Tell me when {short_code} was launched"
    ],
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1503272964.782,
    "createdDate": 1503272771.838,
    "version": "$LATEST",
    "checksum": "06328fa0-15b9-4875-a2e0-1b5f9ac1b940"
}


{
    "name": "StopInstance",
    "slots": [
        {
            "name": "instance_id",
            "slotConstraint": "Optional",
            "slotType": "instance_id",
            "slotTypeVersion": "2",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which instance?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 1,
            "sampleUtterances": []
        },
        {
            "name": "short_code",
            "slotConstraint": "Optional",
            "slotType": "AMAZON.NUMBER",
            "valueElicitationPrompt": {
                "messages": [
                    {
                        "contentType": "PlainText",
                        "content": "Which number?"
                    }
                ],
                "maxAttempts": 2
            },
            "priority": 2,
            "sampleUtterances": []
        }
    ],
    "sampleUtterances": [
        "Stop instance {instance_id}",
        "Stop instance {short_code}",
        "Stop {instance_id}",
        "stop {short_code}",
        "shut down {instance_id}",
        "shut down {short_code}"
    ],
    "confirmationPrompt": {
        "messages": [
            {
                "contentType": "PlainText",
                "content": "Are you sure you want to stop this instance?"
            }
        ],
        "maxAttempts": 3
    },
    "rejectionStatement": {
        "messages": [
            {
                "contentType": "PlainText",
                "content": "OK, I won't stop this instance."
            }
        ]
    },
    "fulfillmentActivity": {
        "type": "CodeHook",
        "codeHook": {
            "uri": "arn:aws:lambda:us-east-1:account-id:function:get-ec2-status",
            "messageVersion": "1.0"
        }
    },
    "lastUpdatedDate": 1498612645.996,
    "createdDate": 1497202428.572,
    "version": "$LATEST",
    "checksum": "faa549de-c578-4448-8010-0b46f2757722"
}

预计 Bot 应该使用上面提到的插槽、话语等代码创建......

但它说错误..

【问题讨论】:

    标签: json amazon-web-services aws-lambda chatbot amazon-lex


    【解决方案1】:

    这里的问题是您的意图代码在 Intent 数组之外。理想情况下,如果您从 Lex 控制台导出完整的机器人,它应该如下所示:

    // Just the portion that includes the intents array
    "intents": [
      {
        "name": "IntentName",
        "version": "1",
        "fulfillmentActivity": {
          "type": "ReturnIntent"
        },
        "sampleUtterances": [
          "Utterance 1",
          "Utterance 2",
          "Utterance 3"
        ],
        "slots": [
          {
            "sampleUtterances": [],
            "slotType": "Slot Name",
            "slotTypeVersion": "1",
            "slotConstraint": "Optional",
            "valueElicitationPrompt": {
              "messages": [
                {
                  "contentType": "PlainText",
                  "content": "Slot Prompt"
                }
              ],
              "maxAttempts": 2
            },
            "priority": 1,
            "name": "Slot Name (provided by developer)"
          }
        ],
        "conclusionStatement": {
          "messages": [ ]
        }
      },
      {
        "name": "Intent 2",
        "version": "3",
        "fulfillmentActivity": {
          "type": "ReturnIntent"
        },
        "sampleUtterances": [
          "Utterance 1",
          "Utterance 2",
          "Utterance 3"
        ],
        "slots": [],
        "conclusionStatement": {
          "messages": [ ]
        }
      },
    
    // repeat for all other intents
    

    与您的情况不同,只有意图名称似乎在意图数组中。如果您将输入的 JSON 放入 JSON 格式化程序网站(我个人使用https://jsonformatter.org/),它将显示检测到 JSON 错误的哪一行。

    【讨论】:

    • 我尝试了几个脚本和相同的错误..任何建议请。
    • @itechworkerz 你能分享一下你正在尝试的脚本是什么样的吗?这样我就可以帮助调试你的 JSON。
    • 我已经在我的原始帖子中分享了代码..(在问题中)。请指教。
    【解决方案2】:

    intent json 结构(要导入)应如下所述,如here 所述(注意元数据和资源元素):

    {
      "metadata": {
        "schemaVersion": "1.0",
        "importType": "LEX",
        "importFormat": "JSON"
      },
      "resource": {
        "description": "intent description",
        "rejectionStatement": {
          "messages": [
            {
              "contentType": "PlainText or SSML or CustomPayload",
              "content": "string"
            }
          ]
        },
        "name": "intent name",
        "version": "version number",
        "fulfillmentActivity": {
          "type": "ReturnIntent or CodeHook"
        },
        "sampleUtterances": [
          "string",
          "string"
        ],
        "slots": [
          {
            "name": "slot name",
            "description": "slot description",
            "slotConstraint": "Required or Optional",
            "slotType": "slot type",
            "valueElicitationPrompt": {
              "messages": [
                {
                  "contentType": "PlainText or SSML or CustomPayload",
                  "content": "string"
                }
              ],
              "maxAttempts": value
            },
            "priority": value,
            "sampleUtterances": []
          }
        ],
        "confirmationPrompt": {
          "messages": [
            {
              "contentType": "PlainText or SSML or CustomPayload",
              "content": "string"
            },
            {
              "contentType": "PlainText or SSML or CustomPayload",
              "content": "string"
            }
          ],
          "maxAttempts": value
        },
        "slotTypes": [
            List of slot type JSON structures.
            For more information, see Slot Type structure.
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多