

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Amazon Connect Cases 이벤트 스트림
<a name="case-event-streams"></a>

Amazon Connect Cases 이벤트 스트림은 Amazon Connect Cases 도메인 내에서 사례가 생성되거나 수정될 때 거의 실시간으로 업데이트를 제공합니다. 스트림에 게시된 이벤트에는 다음과 같은 리소스 이벤트가 포함되어 있습니다.
+ 사례 생성됨
+ 사례 수정됨
+ 관련 항목(댓글, 통화, 채팅, 태스크)이 사례에 추가됨

사례 이벤트 스트림을 사용하여 스트림을 데이터 레이크 솔루션에 통합하고, 사례 성과 지표를 표시하는 대시보드를 만들고, 사례 이벤트를 기반으로 비즈니스 규칙 또는 자동화된 작업을 구현하고, 특정 사례 활동에 대한 사용자 지정 알림을 트리거하도록 알림 도구를 구성할 수 있습니다.

**Topics**
+ [사례 이벤트 스트림 설정](case-event-streams-enable.md)
+ [Cases가 Contact Lens 규칙에 대한 업데이트를 보내도록 허용](cases-rules-integration-onboarding.md)
+ [사례 이벤트 페이로드 및 스키마](case-event-streams-sample.md)

# Amazon Connect Cases 이벤트 스트림 설정
<a name="case-event-streams-enable"></a>

이 주제에서는 사례 이벤트 스트림을 설정하고 사용하는 방법에 대해 설명합니다. 일부 온보딩 단계에서는 [Amazon Connect Cases API](https://docs.aws.amazon.com/cases/latest/APIReference/Welcome.html)를 호출해야 합니다.

## 1단계: Amazon Connect 인스턴스를 생성하고 Customer Profiles 활성화
<a name="step1-case-event-streams-enable"></a>

1. Cases를 사용할 수 있는 AWS 리전 중 하나에서 작동하는 Amazon Connect 인스턴스가 있는지 확인합니다. [리전별 Cases 가용성](regions.md#cases_region)을 참조하세요.

1. Amazon Connect Customer Profiles 활성화 지침은 [Amazon Connect 인스턴스에 Customer Profiles 활성화](enable-customer-profiles.md) 섹션을 참조하세요.

   각 사례는 Customer Profiles 서비스의 고객 프로필과 연결되어야 하므로 Amazon Connect Cases에 Customer Profiles가 필요합니다.

## 2단계: Amazon Connect 인스턴스에 Cases 도메인 추가
<a name="step2-case-event-streams-enable"></a>

지침은 [Amazon Connect 콘솔을 사용하여 Cases 활성화](enable-cases.md) 섹션을 참조하세요.

API를 사용하여 사례 템플릿을 추가하려면 **Amazon Connect Cases API 참조에서 [CreateDomain](https://docs.aws.amazon.com/cases/latest/APIReference/API_CreateDomain.html) API를 참조하세요.

## 3단계: 사례 템플릿 생성
<a name="step3-case-event-streams-enable"></a>

[사례 템플릿을 생성](case-templates.md)합니다. **6단계: 사례 이벤트 스트림 테스트에서는 템플릿을 사용합니다.

API를 사용하여 사례 템플릿을 생성하려면 **Amazon Connect Cases API 참조에서 [CreateTemplate](https://docs.aws.amazon.com/cases/latest/APIReference/API_CreateTemplate.html) API를 참조하세요.

## 4단계: 사례 이벤트 스트림을 활성화하고 이벤트를 SQS 대기열로 수신하도록 설정
<a name="step4-case-event-streams-enable"></a>

다음 명령을 실행하여 Cases 도메인에 대한 사례 이벤트 스트림을 활성화합니다. 이 명령이 실행된 후 사례가 생성되거나 업데이트되면 이벤트가 계정에 있는 EventBridge 서비스의 기본 버스에 게시됩니다(이는 Cases 도메인 AWS 리전 과 동일한에 있어야 함).

```
aws connectcases put-case-event-configuration --domain-id dad5efb6-8485-4a55-8241-98a88EXAMPLE --event-bridge enabled=true
```

기본적으로 Amazon Connect Cases에서 게시한 이벤트에는 `templateId`, `caseId`, `caseArn`, `approximateChangeTime` 등과 같은 사례에 대한 메타데이터만 포함됩니다. 다음 명령을 실행하여 이벤트에 포함할 사례에 대한 자세한 정보(이벤트가 생성된 시점의 정보)를 얻을 수 있습니다.

**참고**  
이벤트에 사용자 지정 필드를 포함하려면 사용자 지정 필드 ID를 사용합니다. 사용자 지정 필드 ID를 찾는 방법에 대한 지침은 [사용자 지정 필드 ID 찾기](cases-block.md#get-case-properties-find-uuid)를 참조하세요.

```
# You can include any other field defined in your cases domain in the fields section.
# To list the fields that are defined in your cases domain, call the Cases ListFields API.
# To include case fields that you create (custom fields) in the event, enter the custom field ID.
aws connectcases put-case-event-configuration --domain-id YOUR_CASES_DOMAIN_ID --event-bridge "{
    \"enabled\": true, 
    \"includedData\": {
       \"caseData\": {
          \"fields\": [
          {
          \"id\": \"status\"
          },
          {
          \"id\": \"title\"
          },
          {
          \"id\": \"customer_id\"
          },
         {
          \"id\": \"your custom field ID\"
          }
        ]
      },
      \"relatedItemData\": {
      \"includeContent\": true
      }
    }
  }"
```

그런 다음, 모든 사례 이벤트가 나중에 처리될 수 있도록 Amazon SQS 대기열을 생성하고 이를 EventBridge 버스에서 Amazon Connect Cases 이벤트의 대상으로 설정합니다.

```
# Create an SQS queue
aws sqs create-queue --queue-name case-events-queue --attributes "{\"Policy\": \"{ \\\"Version\\\": \\\"2012-10-17\\\", \\\"Statement\\\": [{ \\\"Sid\\\": \\\"case-event-subscription\\\", \\\"Effect\\\": \\\"Allow\\\", \\\"Principal\\\": { \\\"Service\\\": \\\"events.amazonaws.com\\\"}, \\\"Action\\\": \\\"SQS:SendMessage\\\", \\\"Resource\\\": \\\"*\\\"}]}\"}"

# Create an rule on the EventBridge default bus that represents the case events
aws events put-rule --name case-events-to-sqs-queue --event-pattern "{\"source\": [\"aws.cases\"]}" --state ENABLED

# Ask event bridge to publish case events to the SQS queue.
aws events put-targets --rule case-events-to-sqs-queue --target "[{
\"Id\": \"target-1\",
\"Arn\": \"arn:aws:sqs:The AWS Region of your Amazon Connect instance:your AWS account ID:case-events-queue\"
}]"
```

## 5단계: 사례 이벤트 스트림 테스트
<a name="step5-case-event-streams-enable"></a>

Amazon Connect 에이전트 애플리케이션을 사용하여 다음을 수행합니다.

1. 채팅 문의를 수락합니다.

1. 고객 프로필을 만들어 채팅 고객 응대에 연결합니다.

1. 사례를 생성합니다.
**참고**  
문의를 수락하고 해당 문의를 고객 프로필에 연결할 때까지는 **사례** 탭의 **사례 생성** 버튼이 비활성화됩니다.

Amazon SQS 콘솔로 이동하여 새로 만든 사례에 대한 사례 이벤트(유형: `CASE.CREATED`)가 SQS 대기열에서 사용 가능한지 확인합니다. 마찬가지로 위에서 만든 사례를 수정하여 SQS 대기열에서 해당 사례 이벤트(유형: `CASE.UPDATED`)를 가져올 수 있습니다. 문의를 사례에 연결하고 사례에 댓글을 남기면 해당 작업에 대한 사례 이벤트도 받을 수 있습니다.

## 6단계: 사례 이벤트 스트림의 사례 사용
<a name="step6-case-event-streams-enable"></a>

사례 이벤트 스트림은 사례가 만들어지고, 사례가 업데이트되고, 문의가 사례에 연결되고, 사례에 댓글이 추가될 때마다 이벤트를 게시합니다. 이러한 이벤트는 다음과 같은 용도로 사용할 수 있습니다.
+ 지표, 분석 및 대시보드
+ 사용자에게 알림을 보내는 앱 구축(예: 이메일 전송)
+ 특정 유형의 사례 업데이트에 따라 트리거되는 자동화된 작업

예를 들어 4단계에 표시된 대로 EventBridge의 SQS 대상을 사용하여 사례 이벤트를 SQS 대기열에 임시로 저장하고, Lambda 함수를 사용하여 사례 업데이트 시 고객에게 이메일을 보내고, 사례에 연결된 모든 태스크를 자동으로 해결하는 등의 사용자 지정 애플리케이션을 구축하기 위해 SQS에서 이벤트를 처리할 수 있습니다. 마찬가지로 EventBridge의 Firehose 대상을 사용하여 사례 이벤트를 S3 버킷에 저장한 다음 ETL AWS Glue 의 경우 , 임시 분석의 경우 Athena, 대시보드의 경우 Quick을 사용할 수 있습니다.

# Amazon Connect Cases가 Contact Lens 규칙에 대한 업데이트를 보내도록 허용
<a name="cases-rules-integration-onboarding"></a>

**참고**  
이 절차의 지침을 수행하려면 개발자 기술이 있거나 Amazon Connect CLI에 경험이 있어야 합니다.

사용자가 사례가 생성되거나 업데이트될 때 실행되는 규칙을 설정할 수 있도록 이 일회성 절차를 완료합니다.

1. Amazon Connect 인스턴스에 Amazon Connect Cases가 [활성화](enable-cases.md)되어 있는지 확인합니다.

1. Amazon Connect Cases 이벤트 스트림을 활성화하는 단계를 완료합니다. 자세한 내용은 [Amazon Connect Cases 이벤트 스트림 설정](case-event-streams-enable.md)을 참조하세요. 절차에 대한 다음과 같은 변경 사항을 참고하세요.

   1. SQS 대기열 생성을 요청하는 부분은 필수가 아니므로 건너뛰어도 됩니다.

   1. `put-case-event-configuration` CLI 명령을 실행하여 모든 사례 필드 정보를 이벤트에 포함합니다. 규칙 엔진이 작동하는 데 필요한 모든 필드를 포함해야 합니다.
**참고**  
사례 SLA 위반 규칙이 제대로 작동하는지 확인하려면 다음 예제와 같이 `relatedItemData.includeContent`를 `true`로 설정해야 합니다.

      ```
      aws connectcases put-case-event-configuration --domain-id 01310a0e-24ba-4a3c-89e9-9e1daeaxxxx --event-bridge "{
          \"enabled\": true, 
          \"includedData\": {
             \"caseData\": {
                 \"fields\": [
                   {
                     \"id\": \"status\"
                   },
                   {
                     \"id\": \"title\"
                   },
                   {
                     \"id\": \"assigned_queue\"
                   },
                   {
                     \"id\": \"assigned_user\"
                   },
                   {
                     \"id\": \"case_reason\"
                   },
                   {
                     \"id\": \"last_closed_datetime\"
                   },
                   {
                     \"id\": \"created_datetime\"
                   },
                   {
                     \"id\": \"last_updated_datetime\"
                   },
                   {
                     \"id\": \"reference_number\"
                   },
                   {
                     \"id\": \"summary\"
                   }
                 ]
            },
            \"relatedItemData\": {
            \"includeContent\": true
            }
          }
        }"
      ```

   1. 사용자 지정 사례 필드가 있는 경우 이전 페이로드의 필드 배열에 사용자 지정 필드 ID도 포함해야 합니다. 다음 `list-fields` CLI 명령을 실행하여 필드 ID를 찾을 수 있습니다.

      ```
      aws connectcases list-fields --domain-id 01310a0e-24ba-4a3c-89e9-9e1daeaxxxx
      ```

   1. 새 사용자 지정 필드를 추가해야 하는 경우 2단계를 반복합니다.

1. 다음 예시 명령과 같이 [CreateEventIntegration](https://docs.aws.amazon.com/appintegrations/latest/APIReference/API_CreateEventIntegration.html) API 직접 호출을 수행하거나 `create-event-integration` CLI 명령을 실행합니다.
   + 페이로드:

     ```
     aws appintegrations create-event-integration --name amazon-connect-cases --description amazon-connect-cases --event-filter '{"Source":"aws.cases"}' --event-bridge-bus default
     ```
   + 다음 샘플과 비슷한 출력이 표시될 것입니다.

     ```
     {
         "EventIntegrationArn": "arn:aws:app-integrations:us-west-2:111222333444:event-integration/amazon-connect-cases"
     }
     ```

1. 다음 예제 명령과 같이 [CreateIntegrationAssociation](https://docs.aws.amazon.com/connect/latest/APIReference/API_CreateIntegrationAssociation.html) API 직접 호출을 수행하거나 `create-integration-association` CLI 명령을 실행합니다.
   + 페이로드:

     `IntegrationArn`은 3단계에서 받는 응답입니다.

     ```
     aws connect create-integration-association --instance-id bba5df5c-6a5f-421f-a81d-9c16402xxxx --integration-type EVENT --integration-arn arn:aws:app-integrations:us-west-2:111222333444:event-integration/amazon-connect-cases --source-type CASES
     ```
   + 출력은 다음 샘플과 유사합니다.

     ```
     {
         "IntegrationAssociationId": "d49048cd-497d-4257-ab5c-8de797a123445",
         "IntegrationAssociationArn": "arn:aws:connect:us-west-2:111222333444:instance/bba5df5c-6a5f-421f-a81d-9c16402bxxxx/integration-association/d49048cd-497d-4257-ab5c-8de797a123445"
     }
     ```

이제 사용자는 사례가 생성되거나 업데이트될 때 실행되는 규칙을 생성할 수 있습니다.

# Amazon Connect Cases의 사례 이벤트 페이로드 및 스키마
<a name="case-event-streams-sample"></a>

이벤트 페이로드에 사례 데이터를 포함하도록 요청하면 해당 데이터는 특정 편집 후 사례의 버전을 반영합니다.

Amazon Connect Cases의 기본 제한은 페이로드가 256KB(EventBus 이벤트의 최대 크기) 미만이 되도록 보장합니다. 사례 객체 모델을 사용자 지정할 수 있으므로(예: 사례 객체에 사용자 지정 필드를 정의하여 비즈니스 관련 정보를 캡처할 수 있음), 사례 이벤트 스키마는 다음 예와 같이 사례 객체에 대한 사용자 지정 사항을 반영합니다(예: 고객별 UUID가 JSON 속성으로 사용되는 방법 참조).

## 사례 리소스에 대한 사례 이벤트 페이로드 예제
<a name="example-case-event-payload"></a>

```
// Given the limits on the "includedData" configuration
// this payload is guaranteed to less than 256KB at launch.
{
    "version": "0",
    "id": "event ID",
    "detail-type": "Amazon Connect Cases Change",
    "source": "aws.cases",
    "account": "your AWS account ID",
    "time": "2022-03-16T23:43:26Z",
    "region": "The AWS Region of your Amazon Connect instance",
    "resources": [
        "arn:aws:cases:your Amazon Connect AWS Region:your AWS account ID:domain/case domain ID",
        "arn:aws:cases:your Amazon Connect AWS Region:your AWS account ID:domain/case domain ID/case/case ID"
    ],
    "detail": {
        "version": "0",
        "eventType": "CASE.UPDATED",
        "approximateChangeTime": "2022-03-16T23:16:57.893Z",  // Can be used for ordering
        "changedFieldIds": ["status", "last_updated_datetime"],
        "performedBy": {
            "user": {
                "userArn": "arn:aws:connect:your Amazon Connect AWS Region:your AWS account ID:instance/connect instance ID/user/connect user ID"        
            },
            "iamPrincipalArn": "arn:aws:iam::your Amazon Connect AWS Region:role/role name"
        },       
        "case": {
            "caseId": "case ID",
            "templateId": "template ID",
            "createdDateTime": "2022-03-16T23:16:57.893Z",
            
            // This section contains only non-null field values for the 
            // fields that customers have configured in the "includedData".
           
            // Field values included in this section reflects the case
            // after this particular change is applied.
            "fields": {
                "status": {
                    "value": {
                        "stringValue": "open"
                   }
                },
                "case_reason": {
                    "value": {
                        "stringValue": "Shipment lost"
                    }
                },
                "custom-field-uuid-1": {
                    "value": {
                        "stringValue": "Customer didn't receive the product"
                    }
                }
            }
        }
    }
}
```

## 관련 항목 리소스에 대한 사례 이벤트 페이로드 예제
<a name="example-case-event-payload"></a>

```
// Given the limits on the "includedData" configuration
// this payload is guaranteed to less than 256KB
{
    "version": "0",
    "id": "event ID",
    "detail-type": "Amazon Connect Cases Change",
    "source": "aws.cases",
    "account": "your AWS account ID",
    "time": "2022-03-16T23:43:26Z",
    "region": "The AWS Region of your Amazon Connect instance",
    "resources": [
        "arn:aws:cases:your Amazon Connect AWS Region:your AWS account ID:domain/case domain ID",
        "arn:aws:cases:your Amazon Connect AWS Region:your AWS account ID:domain/case domain ID/case/case ID/related-item/related-item ID"
    ],
    
    "detail": {   
        "version": "0",
        "eventType": "RELATED_ITEM.CREATED",
        "approximateChangeTime": "2022-03-16T23:16:57.893Z", // Can be used for ordering
        "changedAttributes": ["comment.commentText"],
        "performedBy": {
            "user": {
                "userArn": "arn:aws:connect:your Amazon Connect AWS Region:your AWS account ID:instance/connect instance ID/user/connect user ID"        
            },
            "iamPrincipalArn": "arn:aws:iam::your Amazon Connect AWS Region:role/role name"
        },        
        "relatedItem": {
            "relatedItemType": "Comment",
            "relatedItemId": "related-item ID",
            "caseId": "case id that this related item is a sub-resource of",
            "createdDateTime": "2022-03-16T23:16:57.893Z",
            
            // This section includes any attributes that customers have configured
            // in the "includedData" configuration.
            "comment": {               
                "body": "Gave a $5 refund to customer to make them happy",
            },
            
            // if the related item was of type contact.
            // "contact": {
            //      "contactArn": ".......",
            // }
        }
    }
}
```

## 사용자 정의 엔터티가 수행한 사례 리소스에 대한 사례 이벤트 페이로드 예제
<a name="example-case-event-payload-case-resource-custom-entity"></a>

```
// Given the limits on the "includedData" configuration
// this payload is guaranteed to less than 256KB at launch.
{
    "version": "0",
    "id": "event ID",
    "detail-type": "Amazon Connect Cases Change",
    "source": "aws.cases",
    "account": "your AWS account ID",
    "time": "2022-03-16T23:43:26Z",
    "region": "The AWS Region of your Amazon Connect instance",
    "resources": [
        "arn:aws:cases:your Amazon Connect AWS Region:your AWS account ID:domain/case domain ID",
        "arn:aws:cases:your Amazon Connect AWS Region:your AWS account ID:domain/case domain ID/case/case ID"
    ],
    "detail": {
        "version": "0",
        "eventType": "CASE.UPDATED",
        "approximateChangeTime": "2022-03-16T23:16:57.893Z",  // Can be used for ordering
        "changedFieldIds": ["status", "last_updated_datetime"],
        "performedBy": {
            "user": {
                "customEntity": "your custom entity"        
            },
            "iamPrincipalArn": "arn:aws:iam::your Amazon Connect AWS Region:role/role name"
        },       
        "case": {
            "caseId": "case ID",
            "templateId": "template ID",
            "createdDateTime": "2022-03-16T23:16:57.893Z",
            
            // This section contains only non-null field values for the 
            // fields that customers have configured in the "includedData".
           
            // Field values included in this section reflects the case
            // after this particular change is applied.
            "fields": {
                "status": {
                    "value": {
                        "stringValue": "open"
                   }
                },
                "case_reason": {
                    "value": {
                        "stringValue": "Shipment lost"
                    }
                },
                "custom-field-uuid-1": {
                    "value": {
                        "stringValue": "Customer didn't receive the product"
                    }
                }
            }
        }
    }
}
```