

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

# 使用 Amazon Kinesis Data Streams 获取针对语音和聊天的 Contact Lens 分析
<a name="contact-analysis-segment-streams"></a>

联系分析分段流使您能够获取针对语音和聊天联系的 Contact Lens 分析。直播克服了现有[通话和聊天分析 APIs](contact-lens-api.md)的扩展限制。对于语音联系，它还提供对名为 `Utterance` 的数据段的访问权限，该数据段允许您访问部分文字记录。这样您就能够满足超低延迟要求，以协助座席进行实时通话。

本节介绍如何与 Amazon Kinesis Data Streams 集成以实现流式传输。

通过流式传输，您可以接收以下事件类型：
+ 在联系人分析会话开始时发布的 STARTED 事件。
+ 在联系人分析会话期间发布的 SEGMENTS 事件。这些事件包含带有已分析信息的分段列表。
+ 在联系人分析会话结束时发布的 COMPLETED 或 FAILED 事件。

**Topics**
+ [启用联系人分析分段流](enable-contact-analysis-segment-streams.md)
+ [语音：对话分析分段流数据模型](real-time-contact-analysis-segment-streams-data-model.md)
+ [聊天：对话分析分段流数据模型](chat-real-time-contact-analysis-segment-streams-data-model.md)
+ [语音：对话分析段流样本](sample-real-time-contact-analysis-segment-stream.md)
+ [聊天：对话分析段流样本](chat-sample-real-time-contact-analysis-segment-stream.md)

# 启用联系分析分段流分析 Contact Lens 对话
<a name="enable-contact-analysis-segment-streams"></a>

默认情况下，未启用联系人分析分段流。本主题介绍如何启用它们。

## 步骤 1：创建 Kinesis 流
<a name="enable-segment-streams-step1"></a>

在您的 Amazon Connect 实例所驻留的同一账户和区域创建数据流。有关说明，请参阅《Amazon Kinesis Data Streams 开发人员指南**》中的[步骤 1：创建数据流](https://docs.aws.amazon.com/streams/latest/dev/tutorial-stock-data-kplkcl-create-stream.html)。

**提示**  
建议为每种类型的数据创建一个单独的流。虽然可以将同一个流用于联系人分析分段流、座席事件和联系记录，但是当您为每个流使用单独的流时，管理数据和从流中获取数据要容易得多。有关更多信息，请参阅 [Amazon Kinesis Data Streams 开发人员指南](https://docs.aws.amazon.com/streams/latest/dev/introduction.html)。

## 步骤 2：为 Kinesis 流设置服务器端加密（可选，但建议使用）
<a name="enable-segment-streams-step2"></a>

可通过多种方式执行此操作。
+ 选项 1：使用 Kinesis AWS 托管式密钥 (`aws/kinesis`)。这无需您进行额外的设置即可使用。
+ 选项 2：在您的 Amazon Connect 实例中使用相同的客户自主管理型密钥进行通话录音、聊天转录或导出报告。

  启用加密，并在您的 Amazon Connect 实例中使用客户自主管理型密钥进行通话录音、聊天转录或导出报告。然后为您的 Kinesis 数据流选择相同的 KMS 密钥。此密钥已具有使用所需的权限（授权）。
+ 选项 3：使用其他客户自主管理型密钥。

  使用现有客户自主管理型密钥或创建一个新密钥并添加 Amazon Connect 角色使用相应密钥所需的权限。要使用 AWS KMS 授权添加权限，请参阅以下示例：

  ```
  aws kms create-grant \
      --key-id your key ID \
      --grantee-principal arn:aws:iam::your AWS account ID:role/aws-service-role/connect.amazonaws.com/AWSServiceRoleForAmazonConnect_11111111111111111111 \
      --operations GenerateDataKey \
      --retiring-principal arn:aws:iam::your AWS account ID:role/adminRole
  ```

  其中 `grantee-principal` 是与您的 Amazon Connect 实例关联的服务相关角色的 ARN。要查找服务相关角色的 ARN，请在 Amazon Connect 控制台中，转至**概述**、**分配设置**、**服务相关角色**。

## 步骤 3：关联 Kinesis 流
<a name="enable-segment-streams-step3"></a>

使用 Amazon Connect [AssociateInstanceStorageConfig](https://docs.aws.amazon.com/connect/latest/APIReference/API_AssociateInstanceStorageConfig.html)API 关联以下资源类型：
+ 对于语音联系，请使用 `REAL_TIME_CONTACT_ANALYSIS_VOICE_SEGMENTS`
+ 对于聊天联系，请使用 `REAL_TIME_CONTACT_ANALYSIS_CHAT_SEGMENTS`

**注意**  
`REAL_TIME_CONTACT_ANALYSIS_SEGMENTS` 已被弃用，但仍受支持，且仅适用于语音联系。使用 `REAL_TIME_CONTACT_ANALYSIS_VOICE_SEGMENTS` 来继续语音联系。  
如果您之前已将流与 `REAL_TIME_CONTACT_ANALYSIS_SEGMENTS` 关联，则无需任何操作即可将流更新为 `REAL_TIME_CONTACT_ANALYSIS_VOICE_SEGMENTS`。

指定发布实时联系分析片段的 Kinesis 流。您需要相应的实例 ID 和 Kinesis 流 ARN。下方代码显示了一个示例：

```
// Build request
  const request: Connect.Types.AssociateInstanceStorageConfigRequest = {
    InstanceId: 'your Amazon Connect instance ID',
    ResourceType: 'REAL_TIME_CONTACT_ANALYSIS_VOICE_SEGMENTS or REAL_TIME_CONTACT_ANALYSIS_CHAT_SEGMENTS',
    StorageConfig: {
      StorageType: 'KINESIS_STREAM',
      KinesisStreamConfig: {
        StreamArn: 'the ARN of your Kinesis stream',
      },
    }
  };
```

### AWS CLI
<a name="step3-cli"></a>

下面是聊天联系的示例。

**提示**  
如果您不包括 AWS 区域 (`--region`)，则它将使用基于 CLI 配置文件的默认区域。  
`--storage-config` 参数值不得包含在单引号（'）中，否则会引发错误。

```
aws connect associate-instance-storage-config \
--region "us-west-2" \
--instance-id your Amazon Connect instance ID \
--resource-type REAL_TIME_CONTACT_ANALYSIS_CHAT_SEGMENTS \
--storage-config StorageType=KINESIS_STREAM,KinesisStreamConfig={StreamArn=the ARN of your Kinesis stream}
```

### AWS SDK
<a name="step3-sdk"></a>

下面是语音联系的示例。

```
import { Connect } from 'aws-sdk';

async function associate (): Promise <void> {
  const clientConfig: Connect.ClientConfiguration = {
    region: 'the Region of your Amazon Connect instance',
  };

  const connect = new Connect(clientConfig);

  // Build request
  const request: Connect.Types.AssociateInstanceStorageConfigRequest = {
    InstanceId: 'your Amazon Connect instance ID',
    ResourceType: 'REAL_TIME_CONTACT_ANALYSIS_VOICE_SEGMENTS',
    StorageConfig: {
      StorageType: 'KINESIS_STREAM',
      KinesisStreamConfig: {
        StreamArn: 'the ARN of your Kinesis stream',
      },
    }
  };

  try {
    // Execute request
    const response: Connect.Types.AssociateInstanceStorageConfigResponse = await connect.associateInstanceStorageConfig(request).promise();

    // Process response
    console.log('raw response: ${JSON.stringify(response, null, 2)}');
  } catch (err) {
    console.error('Error calling associateInstanceStorageConfig. err.code: ${err.code},' +
      'err.message: ${err.message}, err.statusCode: ${err.statusCode}, err.retryable: ${err.retryable}');
  }
}

associate().then(r => console.log('Done'));
```

## 步骤 4：为您的 Amazon Connect 实例启用 Contact Lens
<a name="enable-segment-streams-step4"></a>

有关说明，请参阅[在 Amazon Connect Contact Lens 中启用对话分析](enable-analytics.md)。

## 步骤 5（可选）：查看示例分段流
<a name="enable-segment-streams-step5"></a>

建议您查看[语音](sample-real-time-contact-analysis-segment-stream.md)或[聊天](chat-sample-real-time-contact-analysis-segment-stream.md)示例分段流，以熟悉其外观。

# Contact Lens 中用于分析语音联系的对话分析分段流数据模型
<a name="real-time-contact-analysis-segment-streams-data-model"></a>

实时联系人分析分段流以 JSON 格式生成。事件 JSON Blob 将发布到启用了实时对话分析的每个联系人的关联流中。语音联系的对话分析会话可以发布以下类型的事件：
+ STARTED 事件 – 每个对话分析会话都会在会话开始时发布一个 STARTED 事件。
+ SEGMENTS 事件 – 每个对话分析会话在会话期间都可以发布零个或多个 SEGMENTS 事件。这些事件包含带有已分析信息的分段列表。对于语音联系，分段列表可能包括“`Utterance`”、“`Transcript`”、“`Categories`”或“`PostContactSummary`”分段。
+ COMPLETED 或 FAILED 事件 – 每个对话分析会话在会话结束时都会发布一个 COMPLETED 或 FAILED 事件。

## 语音联系的所有活动中包含的常用属性
<a name="segment-streams-data-model-common-properties"></a>

每个时间均包括以下属性：

**版本**  
事件架构的版本。  
类型：字符串

**频道**  
此联系的通道类型。  
类型：字符串  
有效值：`VOICE`、`CHAT`、`TASK`  
有关通道的更多信息，请参阅[在 Amazon Connect 中路由联系人的渠道和并发性](channels-and-concurrency.md)。

**AccountId**  
此次联系发生的账户的标识符。  
类型：字符串

**ContactId**  
正在分析的联系人的标识符。  
类型：字符串

**InstanceId**  
此次联系发生的实例的标识符。  
类型：字符串 

**LanguageCode**  
与此联系人相关的语言代码。  
类型：字符串   
有效值：[Contact Lens 实时通话分析支持的语言](supported-languages.md#supported-languages-contact-lens)之一的语言代码。

**EventType**  
已发布的事件类型。  
类型：字符串  
有效值：`STARTED`、`SEGMENTS`、`COMPLETED`、`FAILED`

## STARTED 事件
<a name="segment-streams-data-model-started-event"></a>

`STARTED` 事件仅包含常用属性：
+ 版本
+ 频道
+ AccountId
+ ContactId
+ LanguageCode
+ EventType: 已启动

## SEGMENTS 事件
<a name="segment-streams-data-model-segments-event"></a>

`SEGMENTS` 事件包括以下属性：
+ 版本
+ 频道
+ AccountId
+ ContactId
+ LanguageCode
+ EventType: 细分
+ 分段：除了常用属性外，`SEGMENTS` 事件还包括具有已分析信息的分段列表。

  类型：[分段](#segment)对象数组
+ PostContactSummary：有关语音联系区段的联系后摘要的信息。

  类型：[PostContactSummary](https://docs.aws.amazon.com/connect/latest/APIReference/API_connect-contact-lens_PostContactSummary.html)物体 

  必需：否

**分段**  
用于实时分析会话的已分析分段。  
每个分段都是一个具有以下可选属性的对象。这些属性中只有一个存在，具体取决于分段类型：  
+ 表达
+ 转录
+ 类别
+ PostContactSummary

**表达**  
已分析的表达。  
必需：否  
+ **Id**

  表达的标识符。

  类型：字符串
+ ** TranscriptId**

  与此表达关联的转录的标识符。

  类型：字符串
+ **ParticipantId**

  参与者的标识符。

  类型：字符串
+ ** ParticipantRole**

  参与者的角色。例如，它是客户、座席还是系统。

  类型：字符串
+ ** PartialContent**

  表达的内容。

  类型：字符串
+ ** BeginOffsetMillis**

  此转录的联系人中的起始偏移量。

  类型：整数
+ ** EndOffsetMillis**

  此转录的联系人中的结束偏移量。

  类型：整数

**转录**  
已分析的转录。  
类型：[转录](https://docs.aws.amazon.com/contact-lens/latest/APIReference/API_Transcript.html)对象   
必需：否

**类别**  
匹配的类别规则。  
类型：[类别](https://docs.aws.amazon.com/contact-lens/latest/APIReference/API_Categories.html)对象  
必需：否

**PostContactSummary**  
有关语音联络分段的联系后摘要信息的信息。  
类型：[PostContactSummary](https://docs.aws.amazon.com/connect/latest/APIReference/API_connect-contact-lens_PostContactSummary.html) 对象  
必需：否

## COMPLETED 事件
<a name="segment-streams-data-model-completed-event"></a>

`COMPLETED` 事件仅包括以下常用属性：
+ 版本
+ 频道
+ AccountId
+ ContactId
+ LanguageCode
+ EventType: 已完成

## FAILED 事件
<a name="segment-streams-data-model-failed-event"></a>

`FAILED` 事件仅包括以下常用属性：
+ 版本
+ 频道
+ AccountId
+ ContactId
+ LanguageCode
+ EventType: 失败

# Contact Lens 中用于分析聊天的对话分析分段流数据模型
<a name="chat-real-time-contact-analysis-segment-streams-data-model"></a>

聊天联系的对话分析分段流以 JSON 格式生成。事件 JSON Blob 将发布到启用了实时对话分析的每个联系人的关联流中。聊天联系的对话分析会话可以发布以下类型的事件：
+ STARTED 事件 – 每个对话分析会话都会在会话开始时发布一个 STARTED 事件。
+ SEGMENTS 事件 – 每个对话分析会话在会话期间都可以发布零个或多个 SEGMENTS 事件。这些事件包含带有已分析信息的分段列表。对于聊天联系，分段列表可能包括 “`Attachments`”、“`Transcript`”、“`Categories`”、“`Events`”、“`Issues`”或“`PostContactSummary`”分段。
+ COMPLETED 或 FAILED 事件 – 每个对话分析会话在会话结束时都会发布一个 COMPLETED 或 FAILED 事件。

## 聊天联系的所有活动中包含的常用属性
<a name="chat-segment-streams-data-model-common-properties"></a>

每个时间均包括以下属性：

**版本**  
事件架构的版本。对于聊天联系，这是 2.0.0。  
类型：字符串

**频道**  
此联系的通道类型。  
类型：字符串  
有效值：`VOICE`、`CHAT`、`TASK`  
有关通道的更多信息，请参阅[在 Amazon Connect 中路由联系人的渠道和并发性](channels-and-concurrency.md)。

**AccountId**  
此次联系发生的账户的标识符。  
类型：字符串

**InstanceId**  
此次联系发生的实例的标识符。  
类型：字符串 

**ContactId**  
正在分析的联系人的标识符。  
类型：字符串

**StreamingEventType**  
已发布的事件类型。  
类型：字符串   
有效值：`STARTED`、`SEGMENTS`、`COMPLETED`、`FAILED`

**StreamingSettings**  
此联系的 Contact Lens 设置  
类型：[StreamingSettings](#streamingsettingsobject) 对象 

## StreamingSettings 对象
<a name="streamingsettingsobject"></a>

**LanguageCode**  
与此联系人相关的语言代码。  
类型：字符串   
有效值：[Contact Lens 实时通话分析支持的语言](supported-languages.md#supported-languages-contact-lens)之一的语言代码。

**Output**  
为此联系启用的 Contact Lens 输出类型。  
类型：字符串  
有效值：`Raw`、`Redacted`、`RedactedAndRaw`

**RedactionTypes**  
为此联系启用的编辑类型。  
类型：字符串数组  
有效值：`PII`

**RedactionTypesMetadata**  
每种编辑类型的编辑元数据。  
类型： RedactionType 字符串到[RedactionMetadata](#redactionmetadata)对象   
有效值：`PII`

## RedactionMetadata 对象
<a name="redactionmetadata"></a>

提供有关编辑设置的信息。

**RedactionMaskMode**  
数据编辑替换设置  
类型：字符串   
有效值：`PII`、`EntityType`

## STARTED 事件
<a name="chat-segment-streams-data-model-started-event"></a>

`STARTED` 事件仅包含常用属性：
+ 版本
+ 频道
+ AccountId
+ ContactId
+ StreamingEventType: 已启动
+ StreamingSettings

## SEGMENTS 事件
<a name="chat-segment-streams-data-model-segments-event"></a>

`SEGMENTS` 事件包括以下属性：
+ 版本
+ 频道
+ AccountId
+ OutputType
  + 当前分段的 Contact Lens 输出类型
  + 类型：字符串
  + 有效值：`Raw`、`Redacted`
+ ContactId
+ StreamingEventType: 细分
+ StreamingSettings
+ Segments
  + 包含已分析信息的分段列表。
  + 类型：[分段](#chat-segment)对象数组

**分段**  
用于实时分析会话的已分析分段。  
每个分段都是一个具有以下可选属性的对象。这些属性中只有一个存在，具体取决于分段类型：  
+  [附件](#chat-attachments)
+  [类别](#chat-category)
+  [Event (事件)](#chat-event)
+  [问题](#chat-issues)
+  [文字记录](#chat-transcript)
+ [PostContactSummary](#chat-postcontactsummary)

**附件**  
已分析的附件。  
必需：否  
类型：[RealTimeContactAnalysisSegmentAttachments](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealTimeContactAnalysisSegmentAttachments.html) 对象

**类别**  
匹配的类别规则。  
类型：[RealTimeContactAnalysisSegmentCategories](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealTimeContactAnalysisSegmentCategories.html) 对象  
必需：否

**事件**  
描述联系活动的片段类型。  
类型：[RealTimeContactAnalysisSegmentEvent](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealTimeContactAnalysisSegmentEvent.html) 对象  
必需：否

**问题**  
包含检测到的问题列表的片段类型。  
类型：[RealTimeContactAnalysisSegmentIssues](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealTimeContactAnalysisSegmentIssues.html) 对象  
必需：否

**文字记录**  
已分析的文字记录片段。  
类型：[RealTimeContactAnalysisSegmentTranscript](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealTimeContactAnalysisSegmentTranscript.html) 对象  
必需：否

**PostContactSummary**  
有关聊天的实时联系段的联系后摘要信息。  
类型：[RealTimeContactAnalysisSegmentPostContactSummary](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealTimeContactAnalysisSegmentPostContactSummary.html) 对象   
必需：否

## COMPLETED 事件
<a name="chat-segment-streams-data-model-completed-event"></a>

`COMPLETED` 事件仅包括以下常用属性：
+ 版本
+ 频道
+ AccountId
+ InstanceId
+ ContactId
+ StreamingEventType: 已完成
+ StreamingSettings

## FAILED 事件
<a name="chat-segment-streams-data-model-failed-event"></a>

`FAILED` 事件仅包括以下常用属性：
+ 版本
+ 频道
+ AccountId
+ InstanceId
+ ContactId
+ StreamingEventType: 失败
+ StreamingSettings

# 使用 Contact Lens 分析通话的对话分析分段流示例
<a name="sample-real-time-contact-analysis-segment-stream"></a>

本主题为语音联系过程中可能发生的 STARTED、COMPLETED 和 FAILED 活动提供样本段流。

## 示例 STARTED 事件
<a name="sample-started-event"></a>
+ EventType: 已启动
+ 在对话分析会话开始时发布。

```
{
    "Version": "1.0.0",
    "Channel": "VOICE",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "LanguageCode": "en-US", // the language code of the contact
    "EventType": "STARTED"
}
```

## 示例 SEGMENTS 事件
<a name="sample-segments-event"></a>
+ EventType: 细分
+ 在对话分析会话期间发布。此事件包含带有已分析信息的分段列表。该分段列表可能包括“`Utterance`”、“`Transcript`”、“`Categories`”或“`PostContactSummary`”分段。

```
{
    "Version": "1.0.0",
    "Channel": "VOICE",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "LanguageCode": "en-US", // the language code of the contact
    "EventType": "SEGMENTS",
    "Segments": [
        {
            "Utterance": {
                "Id": "7b48ca3d-73d3-443a-bf34-a9e8fcc01747",
                "TranscriptId": "121d1581-905f-4169-9804-b841bb4df04a",
                "ParticipantId": "AGENT",
                "ParticipantRole": "AGENT",
                "PartialContent": "Hello, thank you for calling Example Corp. My name is Adam.",
                "BeginOffsetMillis": 19010,
                "EndOffsetMillis": 22980
            }
        },
        {
            "Utterance": {
                "Id": "75acb743-2154-486b-aaeb-c960ae290e88",
                "TranscriptId": "121d1581-905f-4169-9804-b841bb4df04a",
                "ParticipantId": "AGENT",
                "ParticipantRole": "AGENT",
                "PartialContent": "How can I help you?",
                "BeginOffsetMillis": 23000,
                "EndOffsetMillis": 24598
            }
        },
        {
            "Transcript": {
                "Id": "121d1581-905f-4169-9804-b841bb4df04a",
                "ParticipantId": "AGENT",
                "ParticipantRole": "AGENT",
                "Content": "Hello, thank you for calling Example Corp. My name is Adam. How can I help you?",
                "BeginOffsetMillis": 19010,
                "EndOffsetMillis": 24598,
                "Sentiment": "NEUTRAL"
            }
        },
        {
            "Transcript": {
                "Id": "4295e927-43aa-4447-bbfc-8fccc2027530",
                "ParticipantId": "CUSTOMER",
                "ParticipantRole": "CUSTOMER",
                "Content": "I'm having trouble submitting the application, number AX876293 on the portal. I tried but couldn't connect to my POC on the portal. So, I'm calling on this toll free number",
                "BeginOffsetMillis": 19010,
                "EndOffsetMillis": 22690,
                "Sentiment": "NEGATIVE",
                "IssuesDetected": [
                    {
                        "CharacterOffsets": {
                            "BeginOffsetChar": 0,
                            "EndOffsetChar": 81
                        }
                    }
                ]
            }
        },
        {
            "Categories": {
                "MatchedCategories": [
                    "CreditCardRelated",
                    "CardBrokenIssue"
                ],
                "MatchedDetails": {
                    "CreditCardRelated": {
                        "PointsOfInterest": [
                            {
                                "BeginOffsetMillis": 19010,
                                "EndOffsetMillis": 22690
                            }
                        ]
                    },
                    "CardBrokenIssue": {
                        "PointsOfInterest": [
                            {
                                "BeginOffsetMillis": 25000,
                                "EndOffsetMillis": 29690
                            }
                        ]
                    }
                }
            }
        },
        {
            "PostContactSummary": {
                "Content": "Customer contacted Example Corp because of an issue with their application",
                "Status": "COMPLETED"
            }
        }
    ]
}
```

## 示例 COMPLETED 事件
<a name="sample-completed-event"></a>
+ EventType: 已完成
+ 如果分析成功完成，则在对话分析会话结束时发布。

```
{
    "Version": "1.0.0",
    "Channel": "VOICE",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "LanguageCode": "en-US", // the language code of the contact
    "EventType": "COMPLETED"
}
```

## 示例 FAILED 事件
<a name="sample-failed-event"></a>
+ EventType: 失败
+ 如果分析失败，则在对话分析会话结束时发布。

```
{
    "Version": "1.0.0",
    "Channel": "VOICE",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "LanguageCode": "en-US", // the language code of the contact
    "EventType": "FAILED"
}
```

# 在 Contact Lens 中分析聊天的对话分析流示例
<a name="chat-sample-real-time-contact-analysis-segment-stream"></a>

本主题为聊天联系过程中可能发生的 STARTED、COMPLETED 和 FAILED 活动提供样本段流。

## 示例 STARTED 事件
<a name="chat-sample-started-event"></a>
+ EventType: 已启动
+ 在对话分析会话开始时发布。

```
{
    "Version": "2.0.0",
    "Channel": "CHAT",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "StreamingEventType": "STARTED",
    "StreamingSettings": {
      "LanguageCode": "en-US", // the language code of the contact
      "Output": "RedactedAndRaw",
      "RedactionTypes": [
          "PII"
      ],
      "RedactionTypesMetadata": {
        "PII": {
            "RedactionMaskMode": "PII"
         }
       }
    }
}
```

## 示例 SEGMENTS 事件
<a name="chat-sample-segments-event"></a>
+ EventType: [细分](chat-real-time-contact-analysis-segment-streams-data-model.md#chat-segment-streams-data-model-segments-event) 
+ 在对话分析会话期间发布。此事件包含包含已分析信息的[RealtimeContactAnalysisSegment](https://docs.aws.amazon.com/connect/latest/APIReference/API_RealtimeContactAnalysisSegment.html)对象列表。区段列表可能包括`"Transcript"`、`"Categories"`、`"Issue"`、`"Event"``"Attachment"`、或 “PostContactSummary” 区段。

```
{
    "Version": "2.0.0",
    "Channel": "CHAT",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "OutputType": "Redacted",
    "StreamingEventType": "SEGMENTS",
    "StreamingSettings": {
        "LanguageCode": "en-US", // the language code of the contact
        "Output": "RedactedAndRaw",
        "RedactionTypes": [
            "PII"
        ],
        "RedactionTypesMetadata": {
            "PII": {
                "RedactionMaskMode": "PII"
            }
        }
    },
    "Segments": [{
        "Transcript": {
            "Id": "07a2d668-5c9e-4f69-b2fe-986261b0743a",
            "ParticipantId": "a309ac1e-ca87-44ca-bb5d-197eca8ed77a",
            "ParticipantRole": "AGENT",
            "DisplayName": "[PII]",
            "Content": "Hello, thank you for contacting Example Corp. My name is Ray.",
            "ContentType": "text/markdown",
            "Time": {
                "AbsoluteTime": "2024-03-14T19:39:26.715Z"
            },
            "Sentiment": "NEUTRAL"
        }
    }, {
        "Categories": {
            "MatchedDetails": {
                "Hi": {
                    "PointsOfInterest": [{
                        "TranscriptItems": [{
                            "Id": "5205b050-8aa9-4645-a381-a308801649ab",
                            "CharacterOffsets": {
                                "BeginOffsetChar": 0,
                                "EndOffsetChar": 40
                            }
                        }]
                    }]
                }
            }
        }
    }, {
        "Issues": {
            "IssuesDetected": [{
                "TranscriptItems": [{
                    "Content": "I have an issue with my bank account",
                    "Id": "0e5574a7-2aeb-4eab-8bb5-3a7f66a2284a",
                    "CharacterOffsets": {
                        "BeginOffsetChar": 7,
                        "EndOffsetChar": 43
                    }
                }]
            }]
        }
    }, {
        "Attachments": {
            "Id": "06ddc1eb-2302-4a8e-a73f-37687fe41aa9",
            "ParticipantId": "7810b1de-cca8-4153-b522-2498416255af",
            "ParticipantRole": "CUSTOMER",
            "DisplayName": "Customer",
            "Attachments": [{
                "AttachmentName": "Lily.jpg",
                "ContentType": "image/jpeg",
                "AttachmentId": "343e34da-391a-4541-8b7e-3909d931fcfa",
                "Status": "APPROVED"
            }],
            "Time": {
                "AbsoluteTime": "2024-03-14T19:39:26.715Z"
            }
        }
    }, {
        "Event": {
            "Id": "fbe61c5f-d0d8-4345-912a-4e81f5734d3b",
            "ParticipantId": "7810b1de-cca8-4153-b522-2498416255af",
            "ParticipantRole": "CUSTOMER",
            "DisplayName": "Customer",
            "EventType": "application/vnd.amazonaws.connect.event.participant.left",
            "Time": {
                "AbsoluteTime": "2024-03-14T19:40:00.614Z"
            }
        }
    },
    {
        "PostContactSummary": {
            "Content": "Customer contacted Example Corp because of an issue with their bank account",
            "Status": "COMPLETED"
        }
    }]
}
```

## 示例 COMPLETED 事件
<a name="chat-sample-completed-event"></a>
+ EventType: 已完成
+ 如果分析成功完成，则在对话分析会话结束时发布。

```
{
    "Version": "2.0.0",
    "Channel": "CHAT",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "StreamingEventType": "COMPLETED",
    "StreamingEventSettings": {
        "LanguageCode": "en-US", // the language code of the contact
        "Output": "RedactedAndRaw",
        "RedactionTypes": ["PII"],
        "RedactionTypesMetadata": {
            "PII": {
                "RedactionMaskMode": "PII"
            }
        }
    }
}
```

## 示例 FAILED 事件
<a name="chat-sample-failed-event"></a>
+ EventType: 失败
+ 如果分析失败，则在对话分析会话结束时发布。

```
{
    "Version": "2.0.0",
    "Channel": "CHAT",
    "AccountId": "123456789012", // your AWS account ID
    "InstanceId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",  // your Amazon Connect instance ID
    "ContactId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", // the ID of the contact
    "StreamingEventType": "FAILED",
    "StreamingEventSettings": {
        "LanguageCode": "en-US",
        "Output": "RedactedAndRaw",
        "RedactionTypes": ["PII"],
        "RedactionTypesMetadata": {
            "PII": {
                "RedactionMaskMode": "PII"
            }
        }
    }
}
```