

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

# 從 Lex V2 檢視 Amazon CloudWatch Logs 中的文字日誌
<a name="conversation-logs-cw"></a>

Amazon Lex V2 會將對話的文字日誌儲存在 Amazon CloudWatch Logs 中。若要檢視日誌，請使用 CloudWatch Logs 主控台或 API。如需詳細資訊，請參閱《Amazon [CloudWatch Logs 使用者指南》中的](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html)[使用篩選條件模式和 CloudWatch Logs Insights 查詢語法搜尋日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SearchDataFilterPattern.html)。 *Amazon CloudWatch *

**使用 Amazon Lex V2 主控台檢視日誌**

1. 開啟 Amazon Lex V2 主控台 https：//[https://console.aws.amazon.com/lexv2](https://console.aws.amazon.com/lexv2)。

1. 從清單中選擇一個機器人。

1. 從左側功能表中，選擇**分析**，然後選擇 **CloudWatch 指標**。

1. 在 **CloudWatch 指標頁面上檢視機器人的指標**。

您也可以使用 CloudWatch 主控台或 API 來檢視您的日誌項目。若要尋找日誌項目，請導覽至您針對別名設定的日誌群組。您可以在 Amazon Lex V2 主控台或使用 [DescribeBotAlias](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_DescribeBotAlias.html) 操作找到日誌的日誌串流字首。

使用者表達用語的日誌項目可在多個日誌串流中找到。對話中的表達用語在其中一個日誌串流中具有指定前綴的項目。日誌串流中的項目包含下列資訊：

訊息版本  
訊息結構描述版本。

機器人  
與客戶互動之機器人的詳細資訊。

messages  
機器人傳回給使用者的回應。

utteranceContext  
有關處理此表達用語的資訊。  
+ `runtimeHints`- 用來轉錄和解譯使用者輸入的執行期內容。如需詳細資訊，請參閱[改善對話中具有執行時間提示的槽值辨識](using-hints.md)。
+ `slotElicitationStyle`- 用於解譯使用者輸入的槽引出樣式。如需詳細資訊，請參閱[在對話期間使用拼寫樣式擷取槽值](spelling-styles.md)。

sessionState  
使用者與機器人之間對話的目前狀態。如需詳細資訊，請參閱[了解 Amazon Lex V2 機器人對話](managing-conversations.md)。

解釋  
Amazon Lex V2 確定的意圖清單可以滿足使用者的表達用語。 [使用可信度分數來改善對話準確性](confidence-scores.md)

interpretationSource  
指出槽是由 Amazon Lex V2 或 Amazon Bedrock 解析。值：Lex \$1 Bedrock

sessionId  
正在對話之使用者工作階段的識別符。

inputTranscript  
來自使用者的輸入轉錄。  
+ 對於文字輸入，這是使用者輸入的文字。對於 DTMF 輸入，這是使用者輸入的金鑰。
+ 對於語音輸入，這是 Amazon Lex V2 將使用者表達用語轉換為文字，以叫用意圖或填入槽。

rawInputTranscript  
套用任何文字處理之前，使用者輸入的原始文字記錄。注意：文字處理僅適用於 en-US 和 en-GB 地區設定。

轉錄  
使用者輸入的潛在轉錄清單。如需詳細資訊，請參閱[使用語音轉錄可信度分數來改善與 Lex V2 機器人的對話](using-transcript-confidence-scores.md)。

rawTranscription  
使用語音轉錄可信度分數。如需詳細資訊，請參閱[使用語音轉錄可信度分數來改善與 Lex V2 機器人的對話](using-transcript-confidence-scores.md)。

missedUtterance  
指出 Amazon Lex V2 是否能夠辨識使用者的表達用語。

requestId  
Amazon Lex V2 為使用者輸入產生的請求 ID。

timestamp  
使用者輸入的時間戳記。

developerOverride  
指出對話流程是否已使用對話方塊程式碼掛勾更新。如需使用對話方塊程式碼掛鉤的詳細資訊，請參閱 [將 AWS Lambda函數整合到您的 Amazon Lex V2 機器人](lambda.md)。

inputMode  
指出輸入類型。可以是音訊、DTMF 或文字。

requestAttributes  
處理使用者輸入時使用的請求屬性。

audioProperties  
如果啟用音訊對話日誌，且使用者輸入為音訊格式， 會包含音訊輸入的總持續時間、語音持續時間和音訊中的靜音持續時間。它還包含音訊檔案的連結。

bargeIn  
指出使用者輸入是否中斷先前的機器人回應。

responseReason  
產生回應的原因。可為下列其中一個：  
+ `UtteranceResponse` – 對使用者輸入的回應
+ `StartTimeout` – 當使用者未提供輸入時，伺服器產生的回應
+ `StillWaitingResponse` – 當使用者請求機器人等待時，伺服器產生的回應
+ `FulfillmentInitiated` – 伺服器產生的回應，即將啟動履行
+ `FulfillmentStartedResponse` – 伺服器產生的回應，表示已開始履行
+ `FulfillmentUpdateResponse` – 在履行進行時定期伺服器產生的回應
+ `FulfillmentCompletedResponse` – 伺服器在履行完成時產生的回應。

operationName  
用來與機器人互動的 API。可以是 `PutSession`、`RecognizeUtterance`、 `RecognizeText`或 之一`StartConversation`。

```
{
    "message-version": "2.0",
    "bot": {
        "id": "string",
        "name": "string",
        "aliasId": "string",
        "aliasName": "string",
        "localeId": "string",
        "version": "string"
    },
    "messages": [
        {
            "contentType": "PlainText | SSML | CustomPayload | ImageResponseCard",
            "content": "string",
            "imageResponseCard": {
                "title": "string",
                "subtitle": "string",
                "imageUrl": "string",
                "buttonsList": [
                    {
                        "text": "string",
                        "value": "string"
                    }
                ]
            }
        }
    ],
    "utteranceContext": {
        "activeRuntimeHints": {
            "slotHints": {
                "string": {
                    "string": {
                        "runtimeHintValues": [
                            {
                                "phrase": "string"
                            },
                            {
                                "phrase": "string"
                            }
                        ]
                    }
                }
            }
        },
        "slotElicitationStyle": "string"
    },
    "sessionState": {
        "dialogAction": {
            "type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot",
            "slotToElicit": "string"
        },
        "intent": {
            "name": "string",
            "slots": {
                "string": { 
                    "value": { 
                       "interpretedValue": "string",
                       "originalValue": "string",
                       "resolvedValues": [ "string" ]
                    }
                 },  
                "string": {
                    "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" ]
                            }
                        }
                    ]
                }
            },
            "kendraResponse": {
                // Only present when intent is KendraSearchIntent. For details, see 
                // https://docs.aws.amazon.com/kendra/latest/dg/API_Query.html#API_Query_ResponseSyntax
                },
            "state": "InProgress | ReadyForFulfillment | Fulfilled | Failed",
            "confirmationState": "Confirmed | Denied | None"
        },
        "originatingRequestId": "string",
        "sessionAttributes": {
            "string": "string"
        },
        "runtimeHints": {
            "slotHints": {
                "string": {
                    "string": {
                        "runtimeHintValues": [
                            {
                                "phrase": "string"
                            },
                            {
                                "phrase": "string"
                            }
                        ]
                    }
                }
            }
        }
    },
   "dialogEventLogs": [
        {
	  // only for conditional
     "conditionalEvaluationResult":[
      // all the branches until true

     {
     "conditionalBranchName": "string",
     "expressionString": "string",
     "evaluatedExpression": "string",
     "evaluationResult": "true | false"
     }
    ],
  "dialogCodeHookInvocationLabel": "string",
  "response": "string",
  "nextStep": {
        "dialogAction": {
            "type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot",
            "slotToElicit": "string"
        },
	      "intent": {
                          "name": "string",
           "slots": {
               }
        }
       }
    ]
    "interpretations": [
        {
            "interpretationSource": "Bedrock | Lex",
            "nluConfidence": "string",
            "intent": {
                "name": "string",
                "slots": {
                    "string": {
                        "value": {
                            "originalValue": "string",
                            "interpretedValue": "string",
                            "resolvedValues": [ "string" ]
                        }
                    },
                    "string": {
                        "shape": "List",
                        "value": {
                            "interpretedValue": "string",
                            "originalValue": "string",
                            "resolvedValues": [ "string" ]
                        },
                        "values": [
                            {
                                "shape": "Scalar",
                                "value": {
                                    "interpretedValue": "string",
                                    "originalValue": "string",
                                    "resolvedValues": [ "string" ]
                                }
                            },
                            {
                                "shape": "Scalar",
                                "value": {
                                    "interpretedValue": "string",
                                    "originalValue": "string",
                                    "resolvedValues": [ "string" ]
                                }

                            }
                        ]
                    }
                },
                "kendraResponse": {
                    // Only present when intent is KendraSearchIntent. For details, see 
                    // https://docs.aws.amazon.com/kendra/latest/dg/API_Query.html#API_Query_ResponseSyntax
                    },
                "state": "InProgress | ReadyForFulfillment | Fulfilled | Failed",
                "confirmationState": "Confirmed | Denied | None"
                },
            "sentimentResponse": {
                "sentiment": "string",
                "sentimentScore": {
                    "positive": "string",
                    "negative": "string",
                    "neutral": "string",
                    "mixed": "string"
                }
            }
        }
    ],
    "sessionId": "string",
    "inputTranscript": "string",
    "rawInputTranscript": "string",
    "transcriptions": [
        {
            "transcription": "string",
            "rawTranscription": "string",
            "transcriptionConfidence": "number",
            },
            "resolvedContext": {
                "intent": "string"
            },
            "resolvedSlots": {
                "string": {
                    "name": "slotName",
                    "shape": "List",
                    "value": { 
                        "originalValue": "string",
                        "resolvedValues": [
                            "string"
                        ]
                    }
                }
            }
        }
    ],
    "missedUtterance": "bool",
    "requestId": "string",
    "timestamp": "string",
    "developerOverride": "bool",
    "inputMode": "DTMF | Speech | Text",
    "requestAttributes": {
        "string": "string"
    },
    "audioProperties": {
        "contentType": "string",
        "s3Path": "string",
        "duration": {
            "total": "integer",
            "voice": "integer",
            "silence": "integer"
        }
    },
    "bargeIn": "string",
    "responseReason": "string",
    "operationName": "string"
}
```

日誌項目的內容取決於交易的結果，以及機器人和請求的組態。
+ 若 `missedUtterance` 欄位是 `true`，則 `intent`、`slots` 和 `slotToElicit` 不會顯示在輸入中。
+ 如果音訊日誌已停用或 `inputDialogMode` 欄位是 `Text`，則 `s3PathForAudio` 欄位不會出現。
+ 只有在您為機器人定義回應卡片時，才會顯示 `responseCard` 欄位。
+ 只有在請求中指定了請求屬性時，才會顯示 `requestAttributes` 對映。
+ 只有在 `AMAZON.KendraSearchIntent` 提出搜尋 Amazon Kendra 索引的請求時，才會出現 `kendraResponse` 欄位。
+ 在機器人的 Lambda 函數中指定替代意圖時， `developerOverride` 欄位為 true。
+ 只有在請求中指定了工作階段屬性時，才會顯示 `sessionAttributes` 映射。
+ 只有在您設定機器人傳回情緒值時，才會顯示 `sentimentResponse` 映射。

**注意**  
即使 `messageVersion` 中沒有對應的變更，輸入格式也可能變更。如果出現新欄位，您的程式碼不應擲出錯誤。