

终止支持通知：2025年9月15日， AWS 我们将停止对Amazon Lex V1的支持。2025 年 9 月 15 日之后，您将无法再访问 Amazon Lex V1 控制台或 Amazon Lex V1 资源。如果您使用的是 Amazon Lex V2，请改为参阅 [Amazon Lex V2 指南](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# PutIntent
<a name="API_PutIntent"></a>

创建目的或替换现有目的。

要定义用户和您的机器人之间的互动，您可以使用一个或多个意图。例如，对于订购披萨机器人，您可以创建一个 `OrderPizza` 意图。

要创建意图或替换现有意图，您必须提供以下信息：
+ 意图名称。例如 `OrderPizza`。
+ 示例言语。例如，“请问我可以点披萨吗。” 和“我想订一个披萨。”
+ 有待收集的信息。您可以为机器人向用户请求的信息指定插槽类型。您可以指定标准插槽类型（例如日期或时间），也可以指定自定义插槽类型（例如披萨的大小和外皮）。
+ 履行意图的方式。您可以提供 Lambda 函数或配置意图以将意图信息返回给客户端应用程序。如果您使用 Lambda 函数，则当所有意图信息都可用时，Amazon Lex 会调用您的 Lambda 函数。如果您将意图配置为仅将意图信息返回给客户端应用程序。

您可以在请求中指定其他可选信息，例如：
+ 要求用户确认意图的确认提示。例如，“我可以为您的披萨下订单了吗？”
+ 意图实现后要发送给用户的结论语句。例如，“我已经为您的披萨下订单了。”
+ 一个后续提示，询问用户是否要进行其他活动。例如，询问“您想和披萨一起订一杯饮品吗？”

如果您指定现有意图名称来更新意图，Amazon Lex 会将意图的 `$LATEST` 版本中的值替换为请求中的值。Amazon Lex 会删除您在请求中未提供的字段。如果您没有指定必填字段，Amazon Lex 会引发异常。更新意图的 `$LATEST` 版本时，任何使用意图的 `$LATEST` 版本的机器人的 `status` 字段都将设置为 `NOT_BUILT`。

有关更多信息，请参阅 [Amazon Lex：工作原理](how-it-works.md)。

此操作需要 `lex:PutIntent` 操作的权限。

## 请求语法
<a name="API_PutIntent_RequestSyntax"></a>

```
PUT /intents/name/versions/$LATEST HTTP/1.1
Content-type: application/json

{
   "checksum": "string",
   "conclusionStatement": { 
      "messages": [ 
         { 
            "content": "string",
            "contentType": "string",
            "groupNumber": number
         }
      ],
      "responseCard": "string"
   },
   "confirmationPrompt": { 
      "maxAttempts": number,
      "messages": [ 
         { 
            "content": "string",
            "contentType": "string",
            "groupNumber": number
         }
      ],
      "responseCard": "string"
   },
   "createVersion": boolean,
   "description": "string",
   "dialogCodeHook": { 
      "messageVersion": "string",
      "uri": "string"
   },
   "followUpPrompt": { 
      "prompt": { 
         "maxAttempts": number,
         "messages": [ 
            { 
               "content": "string",
               "contentType": "string",
               "groupNumber": number
            }
         ],
         "responseCard": "string"
      },
      "rejectionStatement": { 
         "messages": [ 
            { 
               "content": "string",
               "contentType": "string",
               "groupNumber": number
            }
         ],
         "responseCard": "string"
      }
   },
   "fulfillmentActivity": { 
      "codeHook": { 
         "messageVersion": "string",
         "uri": "string"
      },
      "type": "string"
   },
   "inputContexts": [ 
      { 
         "name": "string"
      }
   ],
   "kendraConfiguration": { 
      "kendraIndex": "string",
      "queryFilterString": "string",
      "role": "string"
   },
   "outputContexts": [ 
      { 
         "name": "string",
         "timeToLiveInSeconds": number,
         "turnsToLive": number
      }
   ],
   "parentIntentSignature": "string",
   "rejectionStatement": { 
      "messages": [ 
         { 
            "content": "string",
            "contentType": "string",
            "groupNumber": number
         }
      ],
      "responseCard": "string"
   },
   "sampleUtterances": [ "string" ],
   "slots": [ 
      { 
         "defaultValueSpec": { 
            "defaultValueList": [ 
               { 
                  "defaultValue": "string"
               }
            ]
         },
         "description": "string",
         "name": "string",
         "obfuscationSetting": "string",
         "priority": number,
         "responseCard": "string",
         "sampleUtterances": [ "string" ],
         "slotConstraint": "string",
         "slotType": "string",
         "slotTypeVersion": "string",
         "valueElicitationPrompt": { 
            "maxAttempts": number,
            "messages": [ 
               { 
                  "content": "string",
                  "contentType": "string",
                  "groupNumber": number
               }
            ],
            "responseCard": "string"
         }
      }
   ]
}
```

## URI 请求参数
<a name="API_PutIntent_RequestParameters"></a>

请求使用以下 URI 参数。

 ** [name](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-uri-name"></a>
意图的名称。名称*不*区分大小写。  
该名称不能与内置意图名称匹配，否则含有“AMAZON.”的内置意图名称 会被删除。例如，由于存在名为 `AMAZON.HelpIntent` 的内置意图，因此您无法创建名为的 `HelpIntent` 的自定义意图。  
有关内置目的的列表，请参阅 [Alexa Skills Kit](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/built-in-intent-ref/standard-intents) 中的*标准内置目的*。  
长度限制：最小长度为 1。最大长度为 100。  
模式：`^([A-Za-z]_?)+$`  
必需：是

## 请求体
<a name="API_PutIntent_RequestBody"></a>

请求接受采用 JSON 格式的以下数据。

 ** [checksum](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-checksum"></a>
标识 `$LATEST` 版本的特定修订版。  
创建新意图时，请将 `checksum` 字段留空。如果指定校验和，则会出现 `BadRequestException` 异常。  
当您想更新意图时，请将 `checksum` 字段设置为 `$LATEST` 版本最新修订版的校验和。如果您未指定 ` checksum` 字段，或者校验和与 `$LATEST` 版本不匹配，则会出现 `PreconditionFailedException` 异常。  
类型：字符串  
必需：否

 ** [conclusionStatement](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-conclusionStatement"></a>
 您希望 Amazon Lex 在 Lambda 函数成功履行意图后向用户传达的语句。  
仅当您在 `fulfillmentActivity` 中提供 Lambda 函数时，此元素才有意义。如果您将意图返回给客户端应用程序，则无法指定此元素。  
`followUpPrompt` 和 `conclusionStatement` 是互斥的。您只能指定其中一个。
类型：[Statement](API_Statement.md) 对象  
必需：否

 ** [confirmationPrompt](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-confirmationPrompt"></a>
提示用户确认目的。此问题的回答应为 yes 或 no。  
Amazon Lex 使用此提示来确保用户确认意图可履行。例如，对于 `OrderPizza` 意图，您可能需要在下单之前确认订单是正确的。对于其他意图，例如仅回答用户问题的意图，在提供信息之前，您可能无需要求用户进行确认。  
您必须同时提供 `rejectionStatement` 和 `confirmationPrompt`，或者两者都不提供。
类型：[Prompt](API_Prompt.md) 对象  
必需：否

 ** [createVersion](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-createVersion"></a>
当设置为 `true` 时，将创建意图的新编号版本。这与调用 `CreateIntentVersion` 操作相同。如果不指定 `createVersion`，则默认值为 `false`。  
类型：布尔值  
必需：否

 ** [description](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-description"></a>
目的的描述。  
类型：字符串  
长度限制：最小长度为 0。最大长度为 200。  
必需：否

 ** [dialogCodeHook](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-dialogCodeHook"></a>
 指定为每个用户输入调用的 Lambda 函数。您可以调用此 Lambda 函数对用户交互进行个性化。  
例如，假设您的机器人确定用户是 John。您的 Lambda 函数可能会从后端数据库中检索 John 的信息并预先填充一些值。例如，如果您发现 John 对谷蛋白过敏，则可以将相应的意图插槽 `GlutenIntolerant` 设置为 true。您可能会找到 John 的电话号码并设置相应的会话属性。  
类型：[CodeHook](API_CodeHook.md) 对象  
必需：否

 ** [followUpPrompt](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-followUpPrompt"></a>
Amazon Lex 将在履行意图后使用此提示来征求其他活动。例如，在履行 `OrderPizza` 意图后，您可以提示用户订购饮品。  
Amazon Lex 采取的操作取决于用户的响应，如下所示：  
+ 如果用户说“是”，则会使用为机器人配置的澄清提示进行响应。
+ 如果用户说“是”，然后继续说一句触发意图的言语，则会启动针对该意图的对话。
+ 如果用户说“否”，则会使用为后续提示配置的拒绝语句进行响应。
+ 如果它无法识别出这句话，它会再次重复后续提示。
`followUpPrompt` 字段和 `conclusionStatement` 字段是互斥的。您只能指定其中一个。  
类型：[FollowUpPrompt](API_FollowUpPrompt.md) 对象  
必需：否

 ** [fulfillmentActivity](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-fulfillmentActivity"></a>
必需。描述履行意图的方式。例如，在用户提供披萨订单的所有信息后，`fulfillmentActivity` 定义机器人如何向当地披萨店下订单。  
 您可以将 Amazon Lex 配置为将所有意图信息返回给客户端应用程序，或者指示其调用可以处理意图的 Lambda 函数（例如，向披萨店下订单）。  
类型：[FulfillmentActivity](API_FulfillmentActivity.md) 对象  
必需：否

 ** [inputContexts](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-inputContexts"></a>
`InputContext` 对象数组，列出了 Amazon Lex 在与用户的对话中选择意图时必须处于活动状态的上下文。  
类型：[InputContext](API_InputContext.md) 对象数组  
数组成员：最少 0 个物品。最多 5 项。  
必需：否

 ** [kendraConfiguration](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-kendraConfiguration"></a>
使用 `AMAZON.KendraSearchIntent` 意图以连接至 Amazon Kendra 索引所需的配置信息。有关更多信息，请参阅[亚马逊。 KendraSearchIntent](https://docs.aws.amazon.com/lex/latest/dg/built-in-intent-kendra-search.html)。  
类型：[KendraConfiguration](API_KendraConfiguration.md) 对象  
必需：否

 ** [outputContexts](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-outputContexts"></a>
`OutputContext` 对象数组，列出了履行意图时意图激活的上下文。  
类型：[OutputContext](API_OutputContext.md) 对象数组  
数组成员：最少 0 个物品。最多 10 个物品。  
必需：否

 ** [parentIntentSignature](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-parentIntentSignature"></a>
内置目的的唯一标识符，此目的建立在它的基础之上。要查找意图的签名，请参阅 *Alexa Skills Kit* 中的[标准内置意图](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/built-in-intent-ref/standard-intents)。  
类型：字符串  
必需：否

 ** [rejectionStatement](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-rejectionStatement"></a>
当用户对 `confirmationPrompt` 中定义的问题回答“否”时，Amazon Lex 将使用此响应进行响应，以确认意图已被取消。  
您必须同时提供 `rejectionStatement` 和 `confirmationPrompt`，或者两者都不提供。
类型：[Statement](API_Statement.md) 对象  
必需：否

 ** [sampleUtterances](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-sampleUtterances"></a>
用户可能用以传递意图的一组言语（字符串）。例如，“我想要 \$1PizzaSize\$1 披萨”、“订购 \$1Quantity\$1 \$1PizzaSize\$1 个披萨”。  
在每句言语中，插槽名称都用大括号括起来。  
类型：字符串数组  
数组成员：最少 0 项。最多 1500 项。  
长度限制：最小长度为 1。最大长度为 200。  
必需：否

 ** [slots](#API_PutIntent_RequestSyntax) **   <a name="lex-PutIntent-request-slots"></a>
意图插槽数组。在运行时，Amazon Lex 使用插槽中定义的提示从用户那里引发所需的插槽值。有关更多信息，请参阅 [Amazon Lex：工作原理](how-it-works.md)。  
类型：[Slot](API_Slot.md) 对象数组  
数组成员：最少 0 个物品。最多 100 个项目。  
必需：否

## 响应语法
<a name="API_PutIntent_ResponseSyntax"></a>

```
HTTP/1.1 200
Content-type: application/json

{
   "checksum": "string",
   "conclusionStatement": { 
      "messages": [ 
         { 
            "content": "string",
            "contentType": "string",
            "groupNumber": number
         }
      ],
      "responseCard": "string"
   },
   "confirmationPrompt": { 
      "maxAttempts": number,
      "messages": [ 
         { 
            "content": "string",
            "contentType": "string",
            "groupNumber": number
         }
      ],
      "responseCard": "string"
   },
   "createdDate": number,
   "createVersion": boolean,
   "description": "string",
   "dialogCodeHook": { 
      "messageVersion": "string",
      "uri": "string"
   },
   "followUpPrompt": { 
      "prompt": { 
         "maxAttempts": number,
         "messages": [ 
            { 
               "content": "string",
               "contentType": "string",
               "groupNumber": number
            }
         ],
         "responseCard": "string"
      },
      "rejectionStatement": { 
         "messages": [ 
            { 
               "content": "string",
               "contentType": "string",
               "groupNumber": number
            }
         ],
         "responseCard": "string"
      }
   },
   "fulfillmentActivity": { 
      "codeHook": { 
         "messageVersion": "string",
         "uri": "string"
      },
      "type": "string"
   },
   "inputContexts": [ 
      { 
         "name": "string"
      }
   ],
   "kendraConfiguration": { 
      "kendraIndex": "string",
      "queryFilterString": "string",
      "role": "string"
   },
   "lastUpdatedDate": number,
   "name": "string",
   "outputContexts": [ 
      { 
         "name": "string",
         "timeToLiveInSeconds": number,
         "turnsToLive": number
      }
   ],
   "parentIntentSignature": "string",
   "rejectionStatement": { 
      "messages": [ 
         { 
            "content": "string",
            "contentType": "string",
            "groupNumber": number
         }
      ],
      "responseCard": "string"
   },
   "sampleUtterances": [ "string" ],
   "slots": [ 
      { 
         "defaultValueSpec": { 
            "defaultValueList": [ 
               { 
                  "defaultValue": "string"
               }
            ]
         },
         "description": "string",
         "name": "string",
         "obfuscationSetting": "string",
         "priority": number,
         "responseCard": "string",
         "sampleUtterances": [ "string" ],
         "slotConstraint": "string",
         "slotType": "string",
         "slotTypeVersion": "string",
         "valueElicitationPrompt": { 
            "maxAttempts": number,
            "messages": [ 
               { 
                  "content": "string",
                  "contentType": "string",
                  "groupNumber": number
               }
            ],
            "responseCard": "string"
         }
      }
   ],
   "version": "string"
}
```

## 响应元素
<a name="API_PutIntent_ResponseElements"></a>

如果此操作成功，则该服务将会发送回 HTTP 200 响应。

服务以 JSON 格式返回以下数据。

 ** [checksum](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-checksum"></a>
创建或更新意图的 `$LATEST` 版本的校验和。  
类型：字符串

 ** [conclusionStatement](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-conclusionStatement"></a>
在 `fulfillmentActivity` 意图中指定的 Lambda 函数履行意图后，Amazon Lex 会将此语句传达给用户。  
类型：[Statement](API_Statement.md) 对象

 ** [confirmationPrompt](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-confirmationPrompt"></a>
如果在意图中已定义，则 Amazon Lex 会在履行意图之前提示用户确认意图。  
类型：[Prompt](API_Prompt.md) 对象

 ** [createdDate](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-createdDate"></a>
意图的创建日期。  
类型：时间戳

 ** [createVersion](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-createVersion"></a>
 `True`（如果创建了新版本的意图）。如果请求中未指定 `createVersion` 字段，则在响应中将 `createVersion` 字段设置为 false。  
类型：布尔值

 ** [description](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-description"></a>
目的的描述。  
类型：字符串  
长度限制：最小长度为 0。最大长度为 200。

 ** [dialogCodeHook](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-dialogCodeHook"></a>
如果在意图中已定义，Amazon Lex 会为每个用户输入调用 Lambda 函数。  
类型：[CodeHook](API_CodeHook.md) 对象

 ** [followUpPrompt](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-followUpPrompt"></a>
如果已在意图中定义，则 Amazon Lex 会在履行意图后使用此提示来征求其他用户活动。  
类型：[FollowUpPrompt](API_FollowUpPrompt.md) 对象

 ** [fulfillmentActivity](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-fulfillmentActivity"></a>
如果已在意图中定义，则在用户提供意图所需的所有信息后，Amazon Lex 会调用 Lambda 函数来履行意图。  
类型：[FulfillmentActivity](API_FulfillmentActivity.md) 对象

 ** [inputContexts](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-inputContexts"></a>
`InputContext` 对象数组，列出了 Amazon Lex 在与用户的对话中选择意图时必须处于活动状态的上下文。  
类型：[InputContext](API_InputContext.md) 对象数组  
数组成员：最少 0 个物品。最多 5 项。

 ** [kendraConfiguration](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-kendraConfiguration"></a>
连接至 Amazon Kendra 索引并使用 `AMAZON.KendraSearchIntent` 意图所需的配置信息（如果有）。  
类型：[KendraConfiguration](API_KendraConfiguration.md) 对象

 ** [lastUpdatedDate](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-lastUpdatedDate"></a>
意图的更新日期。创建资源时，创建日期和上次更新日期相同。  
类型：时间戳

 ** [name](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-name"></a>
意图的名称。  
类型：字符串  
长度约束：最小长度为 1。最大长度为 100。  
模式：`^([A-Za-z]_?)+$`

 ** [outputContexts](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-outputContexts"></a>
`OutputContext` 对象数组，列出了履行意图时意图激活的上下文。  
类型：[OutputContext](API_OutputContext.md) 对象数组  
数组成员：最少 0 个物品。最多 10 个物品。

 ** [parentIntentSignature](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-parentIntentSignature"></a>
内置意图唯一标识符，此意图建立在该意图的基础之上。  
类型：字符串

 ** [rejectionStatement](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-rejectionStatement"></a>
当用户对 `confirmationPrompt` 中定义的问题回答“否”时，Amazon Lex 将使用此语句进行响应，以确认意图已被取消。  
类型：[Statement](API_Statement.md) 对象

 ** [sampleUtterances](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-sampleUtterances"></a>
 为意图配置的一组示例言语。  
类型：字符串数组  
数组成员：最少 0 项。最多 1500 项。  
长度限制：最小长度为 1。最大长度为 200。

 ** [slots](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-slots"></a>
为意图配置的一系列意图插槽。  
类型：[Slot](API_Slot.md) 对象数组  
数组成员：最少 0 个物品。最多 100 个项目。

 ** [version](#API_PutIntent_ResponseSyntax) **   <a name="lex-PutIntent-response-version"></a>
意图的版本。对于新意图，版本始终是 `$LATEST`。  
类型：字符串  
长度限制：最小长度为 1。长度上限为 64。  
模式：`\$LATEST|[0-9]+`

## 错误
<a name="API_PutIntent_Errors"></a>

 ** BadRequestException **   
请求格式不正确。例如，值无效或必填字段未填充。检查字段值，然后重试。  
HTTP 状态代码：400

 ** ConflictException **   
 处理请求时出现冲突。请再次尝试您的请求。  
HTTP 状态代码：409

 ** InternalFailureException **   
出现内部 Amazon Lex 错误。请再次尝试您的请求。  
HTTP 状态代码：500

 ** LimitExceededException **   
请求超出了限制。请再次尝试您的请求。  
HTTP 状态代码：429

 ** PreconditionFailedException **   
 您尝试更改的资源的校验和与请求中的校验和不匹配。检查资源的校验和并重试。  
HTTP 状态代码：412

## 另请参阅
<a name="API_PutIntent_SeeAlso"></a>

有关以特定语言之一使用此 API 的更多信息 AWS SDKs，请参阅以下内容：
+  [AWS 命令行界面 V2](https://docs.aws.amazon.com/goto/cli2/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于.NET 的 SDK V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于 C\$1\$1 的 SDK](https://docs.aws.amazon.com/goto/SdkForCpp/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于 Go v2 的 SDK](https://docs.aws.amazon.com/goto/SdkForGoV2/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于 Java 的 SDK V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/lex-models-2017-04-19/PutIntent) 
+  [AWS JavaScript V3 版软件开发工具包](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于 Kotlin 的 SDK](https://docs.aws.amazon.com/goto/SdkForKotlin/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于 PHP 的 SDK V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lex-models-2017-04-19/PutIntent) 
+  [AWS Python 软件开发工具包](https://docs.aws.amazon.com/goto/boto3/lex-models-2017-04-19/PutIntent) 
+  [AWS 适用于 Ruby V3 的 SDK](https://docs.aws.amazon.com/goto/SdkForRubyV3/lex-models-2017-04-19/PutIntent) 