

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon Lex V2 AWS Lambda函數中的常見結構
<a name="lambda-common-structures"></a>

在 Lambda 回應中，有許多結構會重複發生。本節提供這些常見結構的詳細資訊。

## 意圖
<a name="lambda-intent"></a>

```
"intent": {
    "confirmationState": "Confirmed | Denied | None",
    "name": string,
    "slots": {
        // see 槽 for details about the structure
    },
    "state": "Failed | Fulfilled | FulfillmentInProgress | InProgress | ReadyForFulfillment | Waiting",
    "kendraResponse": {
        // Only present when intent is KendraSearchIntent. For details, see
// https://docs.aws.amazon.com/kendra/latest/dg/API_Query.html#API_Query_ResponseSyntax       }
}
```

`intent` 欄位會映射至具有下列欄位的物件：

### confirmationState
<a name="lambda-intent-confirmationstate"></a>

指出使用者是否已確認意圖的槽，且意圖已準備好履行。可能的值如下：

`Confirmed` – 使用者確認槽值正確。

`Denied` – 使用者表示槽值不正確。

`None` – 使用者尚未到達確認階段。

### name
<a name="lambda-intent-name"></a>

意圖的名稱。

### slots
<a name="lambda-intent-slots"></a>

完成意圖所需的槽資訊。[槽](#lambda-slot) 如需結構的詳細資訊，請參閱 。

### state
<a name="lambda-intent-state"></a>

指出意圖的履行狀態。可能的值如下：

`Failed` – 機器人無法滿足意圖。

`Fulfilled` – 機器人已完成意圖的履行。

`FulfillmentInProgress` – 機器人正在履行意圖。

`InProgress` – 機器人正在引發滿足意圖所需的槽值。

`ReadyForFulfillment` – 機器人已引出意圖的所有槽值，並準備好滿足意圖。

`Waiting` – 機器人正在等待使用者的回應 （僅限於串流對話）。

### kendraResponse
<a name="lambda-intent-kendraresponse"></a>

包含 Kendra 搜尋查詢結果的相關資訊。只有在意圖為 時，才會顯示此欄位`KendraSearchIntent`。如需詳細資訊[，請參閱 Kendra 的查詢 API 呼叫中的回應語法](https://docs.aws.amazon.com/kendra/latest/dg/API_Query.html#API_Query_ResponseSyntax)。

## 槽
<a name="lambda-slot"></a>

`slots` 欄位存在於 `intent` 結構中，並映射到其索引鍵為該意圖槽名稱的結構。如果插槽不是多值插槽 （如需詳細資訊[在槽中使用多個值](multi-valued-slots.md)，請參閱 )，則會對應至具有下列格式的結構。請注意， `shape`是 `Scalar`。

```
{
    slot name: {
        "shape": "Scalar",
        "value": {
            "originalValue": string,
            "interpretedValue": string,
            "resolvedValues": [
                string,
                ...
            ]
        }
    }
}
```

如果插槽是多值插槽，則其對應的物件包含另一個名為 的欄位`values`，其會對應至結構清單，每個欄位都包含構成多值插槽的插槽相關資訊。清單中每個物件的格式符合一般槽所對應的物件格式。請注意， `shape`是 `List`，但 下的元件插槽`shape`的 `values`是 `Scalar`。

```
{
    slot name: {
    "shape": "List",
    "value": {
        "originalValue": string,
        "interpretedValue": string,
        "resolvedValues": [
            string,
            ...
        ]
    },
    "values": [
        {
            "shape": "Scalar",
            "value": {
                "originalValue": string,
                "interpretedValue": string,
                "resolvedValues": [
                    string,
                    ...
                ]
            }
        },
        {
            "shape": "Scalar",
            "value": {
                "originalValue": string,
                "interpretedValue": string,
                "resolvedValues": [
                    string,
                    ...
                ]
            }
        },
        ...
    ]
}
```

槽物件中的欄位如下所述：

### shape
<a name="lambda-slots-shape"></a>

槽的形狀。`List` 如果槽中有多個值 （如需詳細資訊[在槽中使用多個值](multi-valued-slots.md)，請參閱 )，則此值為 ，`Scalar`否則為 。

### value
<a name="lambda-slots-value"></a>

包含使用者為插槽提供的值和 Amazon Lex V2 解釋相關資訊的物件，格式如下：

```
{
    "originalValue": string,
    "interpretedValue": string,
    "resolvedValues": [
        string,
        ...
    ]
}
```

這些欄位如下所述：
+ **originalValue** – 使用者對 Amazon Lex V2 確定與槽值相關的槽引出的回應部分。
+ **interpretedValue** – Amazon Lex V2 根據使用者輸入決定的槽值。
+ **resolvedValues** – Amazon Lex V2 判斷為使用者輸入可能解析度的值清單。

### values
<a name="lambda-slots-values"></a>

物件清單，其中包含構成多值槽的槽相關資訊。每個物件的格式都符合正常槽的格式，以及上述的 `shape`和 `value` 欄位。`values`只有在該槽包含多個值時才會顯示 （如需詳細資訊[在槽中使用多個值](multi-valued-slots.md)，請參閱 )。下列 JSON 物件顯示兩個元件插槽：

```
"values": [
    {
        "shape": "Scalar",
        "value": {
            "originalValue": string,
            "interpretedValue": string,
            "resolvedValues": [
                string,
                ...
            ]
        }
    },
    {
        "shape": "Scalar",
        "value": {
            "originalValue": string,
            "interpretedValue": string,
            "resolvedValues": [
                string,
                ...
            ]
        }
    },
    ...
]
```

## 工作階段狀態
<a name="lambda-session-state"></a>

`sessionState` 欄位會映射至 物件，其中包含與使用者對話狀態的相關資訊。物件中出現的實際欄位取決於對話方塊動作的類型。如需 Lambda 回應中的必要欄位，[回應中的必要欄位](lambda-response-format.md#lambda-response-required)請參閱 。`sessionState` 物件的格式如下：

```
"sessionState": {
    "activeContexts": [
        {
            "name": string,
            "contextAttributes": {
                string: string
            },
            "timeToLive": {
                "timeToLiveInSeconds": number,
                "turnsToLive": number
            }
        },
        ...
    ],
    "sessionAttributes": {
        string: string,
        ...
    },
    "runtimeHints": {
        "slotHints": {
            intent name: {
                slot name: {
                    "runtimeHintValues": [
                        {
                            "phrase": string
                        },
                        ...
                    ]
                },
                ...
            },
            ...
        }
    },
    "dialogAction": {
        "slotElicitationStyle": "Default | SpellByLetter | SpellByWord",
        "slotToElicit": string,
        "type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot"
    },
    "intent": {
        // see 意圖 for details about the structure
    },
    "originatingRequestId": string
}
```

這些欄位如下所述：

### activeContexts
<a name="lambda-active-contexts"></a>

物件清單，其中包含使用者在工作階段中使用的內容相關資訊。使用內容來促進和控制意圖辨識。如需內容的詳細資訊，請參閱 [設定 Lex V2 機器人的意圖內容](context-mgmt-active-context.md)。每個物件的格式如下：

```
{
    "name": string,
    "contextAttributes": {
        string: string
    },
    "timeToLive": {
        "timeToLiveInSeconds": number,
        "turnsToLive": number
    }
}
```

這些欄位如下所述：
+ **name** – 內容的名稱。
+ **contextAttributes** – 物件，其中包含內容的屬性名稱及其對應的值。
+ **timeToLive** – 指定內容保持作用中狀態的物件。此物件可以包含下列其中一個或兩個欄位：
  + **timeToLiveInSeconds** – 內容保持作用中的秒數。
  + **turnsToLive** – 內容保持作用中的轉彎次數。

### sessionAttributes
<a name="lambda-session-attributes"></a>

代表工作階段特定內容資訊的鍵/值對映射。如需詳細資訊，請參閱[設定 Lex V2 機器人的工作階段屬性](context-mgmt-session-attribs.md)。物件的格式如下所示：

```
{
    string: string,
    ...
}
```

### runtimeHints
<a name="lambda-runtime-hints"></a>

提供提示給客戶可能用於槽的片語，以改善音訊辨識。您在提示中提供的值會提升這些值的音訊辨識能力，而不是類似聲音的單字。`runtimeHints` 物件的格式如下：

```
{
    "slotHints": {
        intent name: {
            slot name: {
                "runtimeHintValues": [
                    {
                        "phrase": string
                    },
                    ...
                ]
            },
            ...
        },
        ...
    }
}
```

`slotHints` 欄位映射到物件，其欄位是機器人中意圖的名稱。每個意圖名稱都會映射到一個物件，其欄位是該意圖的槽名稱。每個槽名稱都會映射到具有單一欄位 的結構`runtimeHintValues`，這是物件清單。每個物件都包含一個映射到提示`phrase`的欄位。

### dialogAction
<a name="lambda-dialog-action"></a>

決定 Amazon Lex V2 要採取的下一個動作。物件的格式如下所示：

```
{
    "slotElicitationStyle": "Default | SpellByLetter | SpellByWord",
    "slotToElicit": string,
    "type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot"
}
```

這些欄位如下所述：
+  **slotElicitationStyle** – 如果 `type``dialogAction`為 ，則決定 Amazon Lex V2 如何解譯使用者的音訊輸入`ElicitSlot`。如需詳細資訊，請參閱[在對話期間使用拼寫樣式擷取槽值](spelling-styles.md)。可能的值如下：

  `Default` – Amazon Lex V2 會以預設方式解譯音訊輸入，以滿足插槽。

  `SpellByLetter` – Amazon Lex V2 會接聽使用者拼寫的槽值。

  `SpellByWord` – Amazon Lex V2 會使用與每個字母相關聯的單字 （例如 Apple 中的「a」) 接聽使用者拼法的槽值。
+  **slotToElicit** – 如果 `dialogAction`為 ，則定義要從使用者引出`type`的插槽`ElicitSlot`。
+ **type** – 定義機器人應執行的動作。可能的值如下：

  `Delegate` – 讓 Amazon Lex V2 決定下一個步驟。

  `ElicitIntent` – 提示客戶表達意圖。

  `ConfirmIntent` – 確認客戶的槽值，以及意圖是否已準備好履行。

  `ElicitSlot` – 提示客戶提供意圖的槽值。

  `Close` – 結束意圖履行程序。

### intent
<a name="lambda-sessionstate-intent"></a>

如需 `intent` 欄位的結構[意圖](#lambda-intent)，請參閱 。

### originatingRequestId
<a name="lambda-originating-request-id"></a>

請求的唯一識別符。此欄位對於 Lambda 回應是選用的。