

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

# 从 Lex V2 中查看亚马逊 CloudWatch 日志中的文本日志
<a name="conversation-logs-cw"></a>

Amazon Lex V2 将您的对话文本日志存储在亚马逊 CloudWatch 日志中。要查看日志，请使用 CloudWatch 日志控制台或 API。有关更多信息，请参阅 *Amazon Logs 用户指南中的[使用筛选模式搜索CloudWatch 日志数据](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SearchDataFilterPattern.html)和 CloudWatch 日志*[见解查询语法](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html)。

**要使用 Amazon Lex V2 控制台查看日志，请执行以下操作：**

1. 打开 Amazon Lex V2 主机[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)操作来找到日志的日志流前缀。

用户言语的日志条目位于多个日志流中。对话中的一个话语在一个日志流中具有一个带指定前缀的条目。日志流中的条目包含以下信息：

message-version  
消息架构版本。

自动程序  
有关客户正在与之交互的机器人的详细信息。

消息  
机器人发回给用户的响应。

utteranceContext  
有关处理该言语的信息。  
+ `runtimeHints`：用于转录和解释用户输入的运行时上下文。有关更多信息，请参阅 [在对话中使用运行时提示改善对槽位值的识别](using-hints.md)。
+ `slotElicitationStyle`：用于解释用户输入的槽位引发样式。有关更多信息，请参阅 [在对话期间使用拼写样式捕获槽位值](spelling-styles.md)。

sessionState  
用户与机器人之间对话的当前状态。有关更多信息，请参阅 [了解 Amazon Lex V2 机器人对话](managing-conversations.md)。

interpretations  
Amazon Lex V2 确定可以满足用户言语的意图列表。[使用置信度分数提高对话的准确性](confidence-scores.md)。

interpretationSource  
表示插槽是由 Amazon Lex V2 还是由 Amazon Bedrock 解析的。值：Lex \| Bedrock

sessionId  
正在进行对话的用户会话的标识符。

inputTranscript  
用户输入的转录。  
+ 对于文本输入，表示用户键入的文本。对于 DTMF 输入，表示用户输入的密钥。
+ 对于语音输入，这是 Amazon Lex V2 将用户言语转换成的文本，以便调用意图或填补槽位。

未加工的 InputTranscript  
应用任何文本处理之前的用户输入原始转录。注意：文本处理仅适用于 en-US 和 en-GB 区域设置。

transcriptions  
用户输入的潜在转录列表。有关更多信息，请参阅 [使用语音转录置信度分数来改善与 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`、`RecognizeText`、`RecognizeUtterance` 或 `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` 做出相应更改。您的代码不应在有新字段时引发错误。