

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

# 設定 Amazon Connect Customer Profiles 中的計算屬性
<a name="customerprofiles-calculated-attributes"></a>

*計算屬性*是使用公式，衍生自其他屬性的值。您可以使用計算屬性來識別使用者的彙總行為。

您可以建立計算屬性，以定義自己的商業邏輯，使客戶設定檔資料為可轉換為實際行動的資料點。如此一來，您可以個人化自動化體驗，例如互動式語音回應。

透過計算屬性，您可以識別客戶過去行為的相關關鍵屬性。例如：
+ 上次造訪的網站或上次交談的客服人員
+ 行為模式，例如偏好的管道和聯絡頻率
+ 客戶價值，例如新客戶和平均交易規模

您可以使用計算屬性 API，使用常見的彙總作業 (例如平均值、計數、最小值、最大值與總和) 來建立新屬性。

計算屬性會自動將原始資料即時轉換為可轉換為實際行動的資料點和指標。聯絡中心管理員能夠根據客戶設定檔中可用的原始資料來定義和設定計算。這些計算屬性可讓您更輕鬆地構建自動化體驗，例如交互式語音回應 (IVR) 或聊天機器人。您可以構建個人化體驗，並幫助客服人員更快地了解客戶情境。

如需可使用計算屬性 APIs AWS 的區域清單，請參閱 [客戶設定檔計算屬性 API 可用性 (按區域)](regions.md#customerprofiles_calculatedattributesregion)。

**Topics**
+ [計算屬性入門](customerprofiles-calculated-attributes-admin-website.md)
+ [計算屬性 API](customerprofiles-calculated-attributes-apis.md)
+ [建立自訂計算屬性定義](customerprofiles-calculated-attributes-creating-definition.md)
+ [驗證計算屬性值](customerprofiles-calculated-attributes-validating-values.md)
+ [預設計算屬性](customerprofiles-default-calculated-attributes.md)
+ [錯誤訊息和解決方案](customerprofiles-calculated-attributes-troubleshooting.md)

# Amazon Connect 客戶設定檔中的計算屬性入門
<a name="customerprofiles-calculated-attributes-admin-website"></a>

使用計算屬性來定義自己的商業邏輯，將您的客戶設定檔資料轉換為可轉換為實際行動的資料點，以個人化自動化體驗 (例如互動式語音回應)。

透過計算屬性，您可以識別客戶過去行為、行為模式和客戶價值的相關關鍵屬性。

本章節的主題說明如何建立、檢視、編輯和刪除計算屬性。

**Topics**
+ [建立計算屬性](calculated-attributes-admin-website-create.md)
+ [設定事件篩選條件](calculated-attributes-admin-website-event-filters.md)
+ [檢視計算屬性](calculated-attributes-admin-website-view.md)
+ [編輯計算屬性](calculated-attributes-admin-website-edit.md)
+ [刪除計算屬性](calculated-attributes-admin-website-delete.md)

# 在 Amazon Connect 中建立計算屬性
<a name="calculated-attributes-admin-website-create"></a>

1. 先決條件：請確認您具有必要的安全性設定檔權限。如需詳細資訊，請參閱[更新 Amazon Connect Customer Profiles 中的計算屬性權限](security-profile-customer-profile-calc-attribs.md)。

1. 在 Amazon Connect 管理員網站中，導覽至**客戶設定檔**、**計算屬性**，然後在**計算屬性**資料表檢視中選擇**建立**屬性。  
![\[客服人員工作區中的客戶設定檔索引標籤，關聯按鈕。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-create-1.png)

1. 若要建立計算屬性，請指定描述性名稱、新增有關屬性詳細資訊的說明 (選用)，然後設定必要欄位：
   + **計算：**定義屬性的計算方式 (平均值/計數/總和/最小值/第一次出現/上次出現/最大值)。
   + **屬性：**客戶設定檔資料的資料點。
**注意**  
如果您要從標準物件類型 (`_asset`、`_case`、`_order`) 中選取屬性，則屬性必須位於 PascalCase。這表示屬性名稱中每個單字的第一個字母都會大寫，例如 `_case.CreatedBy` 或 `_order.TotalPrice`。  
![\[客服人員工作區中的客戶設定檔索引標籤，關聯按鈕。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-create-2.png)

1. 此外，您可以選擇*加號*圖示以新增其他屬性。您最多可以選擇兩個屬性來進行計算，並由運算子合併。指定運算子 (例如*加號*或*減號*) 以合併屬性值。  
![\[客服人員工作區中的客戶設定檔索引標籤，關聯按鈕。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-create-3.png)

1. 選取計算之後，您可以選擇設定事件數量、期間和來源時間戳記。根據預設，計算屬性設為使用無限事件、無限期間，以及根據擷取日期的時間戳記。

   當在指定的時段內至少有一個事件時，系統會傳回一個輸出。
   + **事件數量：**設定限制或使用無限 (預設)
   + **期間：**設定特定時間範圍或使用無限 (預設)
   + **來源時間戳記：**選擇特定時間戳記欄位或擷取日期 (預設)
**注意**  
雖然沒有事件限制，但有資料大小限制；最舊的資料將被較新的資料取代。建立後無法變更來源時間戳記。  
![\[客服人員工作區中的客戶設定檔索引標籤，關聯按鈕。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-create-4.png)

1. 或者，您可以定義條件，在計算中僅包含相關事件。如需詳細資訊，請參閱 [設定事件篩選條件](calculated-attributes-admin-website-event-filters.md)。

1. 選取**建立**以建立計算屬性。

1. 成功建立計算屬性後，表格視圖會顯示橫幅，以在客群或流程中使用計算屬性。您也可以根據準備程度檢視計算屬性的狀態。  
![\[已建立計算屬性的橫幅。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-create-5.png)

# 設定事件篩選條件
<a name="calculated-attributes-admin-website-event-filters"></a>

您可以透過事件篩選條件，篩選要在計算屬性中使用的設定檔物件。例如，事件篩選條件可能會篩選客戶的標準資產物件，只在計算中包含**狀態為已安裝或已註冊**的資產。

**注意**  
建立計算屬性定義後，就無法編輯事件篩選條件。

建立計算屬性時，您可以建立一個或多個事件篩選條件。事件篩選條件包含以下元件：

![\[事件篩選條件元件。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-event-filters-1.png)

+  **篩選條件群組**：套用至設定檔物件的篩選條件群組。您可以新增多個依 OR 關係連接的篩選條件群組。
+  **篩選條件**：指定屬性、運算子和值，篩選計算屬性的計算所包含的設定檔物件。您可以根據需要，為您的使用案例新增任意數量的篩選條件。
+  **屬性**：要篩選物件的屬性。您可以從 Customer Profiles 網域中的物件選取屬性，或使用物件類型定義所定義的欄位名稱。如需詳細了解物件類型映射，請參閱 [Amazon Connect Customer Profiles 中的物件類型映射定義詳細資訊](object-type-mapping-definition-details.md)。
**注意**  
 在 Amazon Connect 管理網站中，屬性下拉式清單會顯示上次使用 屬性儲存或更新任何設定檔物件時的時間戳記。
 如果同時有設定檔物件的屬性和具相同名稱的物件類型欄位，事件篩選條件會優先使用物件類型欄位名稱進行篩選。例如，如果設定檔物件具有名為 **Status** 的屬性，並且還有名為 **Status** 的物件類型欄位，則篩選條件將使用物件類型欄位 **Status** 進行篩選。
+  **運算子** — 運算子決定屬性與您輸入值的關係。如需更多詳細資訊，請參閱 [篩選條件運算子](#calculated-attributes-admin-website-event-filter-operators)
+  **值** — 用來篩選物件的值。您可以指定依 OR 關係連接的多個值。例如，*資產的狀態為已安裝或已註冊*。請留意，該值區分大小寫。例如，*Asset's Status is Installed* 會傳回與 *Asset's Status is installed* 不同的結果。若要檢視設定檔物件，請使用 Amazon Connect Customer Profiles [ListProfileObjects](https://docs.aws.amazon.com/connect/latest/APIReference/API_connect-customer-profiles_ListProfileObjects.html) API。

 您可以選擇建立最多兩個事件篩選條件，並在它們之間建立關係 (AND/OR/EXCLUDE)。如需有關關係的詳細資訊，請參閱 [事件篩選條件之間的關係](#calculated-attributes-admin-website-relationship-between-event-filters)。

 

## 篩選條件運算子
<a name="calculated-attributes-admin-website-event-filter-operators"></a>

運算子決定屬性與您輸入值的關係。下表說明可用的運算子。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/calculated-attributes-admin-website-event-filters.html)

**注意**  
 Amazon Connect 管理網站中計算的屬性使用 UTC 時區和預設時間 00：00：00 UTC 進行所有以時間為基礎的篩選條件。 您可以篩選日期，但時間會記錄為相同的值。如果您輸入的日期為 2024-01-01，主控台傳遞的時間會是 2024-01-01T00:00:00Z。

**注意**  
根據預設，儲存或更新設定檔物件時，會評估事件篩選條件。例如，如果您篩選 `PurchaseDate` 在上週的標準資產物件，則相對時間的計算方式為*儲存或更新該資產物件後的最後一週內*。這表示篩選結果可能因物件的儲存或更新時間而有所不同。

## 事件篩選條件之間的關係
<a name="calculated-attributes-admin-website-relationship-between-event-filters"></a>

 或者，您可以新增第二個事件篩選條件，並定義其與第一個事件篩選條件的關係。在 Amazon Connect 管理員網站建立計算屬性時，每個計算屬性最多可以有兩個事件篩選條件。如果您將第二個事件篩選條件新增至計算屬性，您可以選擇一種方式，來指定兩個事件篩選條件的連接方式：
+  **AND 關係** — 如果您使用 AND 關係來連接兩個事件篩選條件，則符合第一個和第二個事件篩選條件的物件將包含在計算中。
+  **OR 關係** — 如果您使用 OR 關係來連接兩個事件篩選條件，則符合第一個或第二個事件篩選條件的物件將包含在計算中。
+  **EXCLUDE 關係** — 如果您使用 EXCLUDE 關係來連接兩個事件篩選條件，則符合第一個但不符合第二個事件篩選條件的物件將包含在計算中。

## 後續步驟
<a name="calculated-attributes-admin-website-event-filter-next-steps"></a>
+  [透過流程編輯器，在聯絡中心使用您的計算屬性](https://docs.aws.amazon.com/connect/latest/adminguide/customer-profiles-block.html#customer-profiles-block-properties-get-calculated-attributes) 
+  [使用計算屬性來定義客戶客群](https://docs.aws.amazon.com/connect/latest/adminguide/segmentation-admin-website)
+  [在 Amazon Connect 中檢視計算屬性](https://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-view.html) 
+  [在 Amazon Connect 中編輯計算屬性](https://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-edit.html) 
+  [在 Amazon Connect 中刪除計算屬性](https://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-delete.html) 

# 在 Amazon Connect 中檢視計算屬性
<a name="calculated-attributes-admin-website-view"></a>

1. 登入 Amazon Connect 管理網站，網址為 https：//*instance name*.my.connect.aws/。使用管理員帳戶，或已指派至安全性設定檔，並具有 **Customer Profiles - 計算屬性**權限的帳戶。

1. 在 Amazon Connect 的左側導覽窗格中，選擇 **Customer Profiles**、**計算屬性**。

1. 在**計算屬性**頁面上，從表格的**名稱**欄選擇計算屬性。

   下圖顯示**名稱**欄所列計算屬性的範例。  
![\[列出計算屬性的表格。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-view-1.png)

1. 您現在可以檢視您所選屬性的詳細資訊。下圖顯示計算屬性的詳細資訊頁面。  
![\[計算屬性的詳細視圖。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-view-2.png)

# 在 Amazon Connect 中編輯計算屬性
<a name="calculated-attributes-admin-website-edit"></a>

1. 若要編輯計算屬性，請選擇可啟用**編輯**按鈕的選項按鈕，在表格視圖中選擇屬性。選擇**編輯**。  
![\[編輯計算屬性\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-edit-1.png)

1. 您能夠編輯**說明**、**事件數量**和**期間**。完成時，請選擇**儲存**。  
![\[編輯計算屬性。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-edit-2.png)

# 在 Amazon Connect 中刪除計算屬性
<a name="calculated-attributes-admin-website-delete"></a>

1. 若要刪除計算屬性，請選擇要刪除之屬性旁的選項按鈕，以選擇表格中的屬性。

1. 選擇後，選擇**刪除**。

1. 在**刪除屬性**彈出式視窗中，確認詳細資訊並輸入*確認*以啟用**刪除**按鈕。  
![\[刪除新的計算屬性。\]](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/calculated-attributes-admin-website-delete-1.png)

1. 選擇**刪除**。

# Amazon Connect Customer Profiles 計算屬性 API
<a name="customerprofiles-calculated-attributes-apis"></a>

您可以使用下列客戶設定檔計算屬性 API

------
#### [ CreateCalculatedAttributeDefinition ]

**CreateCalculatedAttributeDefinition**

建立新的計算屬性。這需要網域中的現有物件類型。您可以定義要從單一來源物件中提取的屬性，以及要套用至彙總的數學運算，以及時間範圍和物件計數。

建立之後，擷取至客戶設定檔的新物件資料將包含在計算屬性中，您可以使用 `GetCalculatedAttributeForProfile` API 針對設定檔擷取該屬性。若要使用歷史資料，請指定 `UseHistoricalData` 為 true。API 回應上的 `Readiness` 和 `Status` 欄位將提供計算屬性所含歷史資料的狀態資訊。

定義計算屬性可讓網域內的所有設定檔使用該屬性。每個計算屬性只能參照一個 ObjectType，以及該 ObjectType 中的最多兩個欄位。

**請求**

```
POST /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

```
{
    "CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
       "Attributes": [
           {
               "Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE",
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
     },
     "Tags": {}
}
```

**回應**

```
{
    "CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
       "Attributes": [
           {
               "Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE"
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
    },
    "CreatedAt": number,
    "LastUpdatedAt": number,
    "Tags": {}
}
```

**請求內文**
+ **CalculatedAttributeName**

  計算屬性的唯一 (每個網域) 名稱。
  + 類型：字串
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是
+ **DisplayName**

  計算屬性的顯示名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z_][a-zA-Z_0-9-\s]*$`
  + 必要：否
+ **Description**

  計算屬性的描述。
  + 類型：字串
  + 長度限制：長度下限為 1。長度上限為 1000。
  + 必要：否
+ **UseHistoricalData**

  建立計算屬性前擷取的歷史資料是否應包含在計算中。
  + 類型：布林值
  + 必要：否
+ **AttributeDetails**

  定義中使用的屬性詳細資訊，以及屬性之間涉及的數學運算。參閱以下元件：
  + **Attributes**

    在數學運算式中指定的屬性項目清單。
    + **AttributeItem**

      在數學運算式中指定的單一屬性項目的詳細資訊。
      + 名稱
        + 設定檔物件類型中定義的屬性名稱。
        + 類型：字串
  + **運算式**

    針對屬性清單中所提供屬性項目執行的數學運算式。運算式中的每個元素應遵循 \$1"\$1ObjectTypeName.AttributeName\$1\$1" 的結構。
    + 範例：`{ObjA.AttributeA} - {ObjA.AttributeB}`
    + 類型：字串
    + 我們只支援以下數學運算：`+ - * /`
    + 計算屬性定義建立後，您就無法修改「運算式」
+ **條件**

  定義計算屬性彙總條件和閾值。
  + 類型：條件物件
    + 範圍
    + ObjectCount
    + Threshold
+ **範圍**

  資料包含在彙總中的相對期間。
  + 類型：範圍物件
    + 值：指定單位的時間長度。`ValueRange` 會覆寫 Value。
      + 類型：整數
      + 必要：否
    + ValueRange：可讓客戶指定相對時間範圍的結構，其中的資料會包含在計算屬性中。使用正數表示結束時間在過去時間，負數表示在未來時間。ValueRange 會覆寫 Value。
      + 類型：ValueRange
      + 必要：否
        + Start
          + 應開始包含物件的時間。使用正數表示開始時間在過去時間，負數表示在未來時間。
          + 類型：整數
          + 必要：是 
        + 結束
          + 應不再包含物件的時間。使用正數表示開始時間在過去時間，負數表示在未來時間。
          + 類型：整數
          + 必要：是 
    + TimestampSource：指定 JSON 物件中應剖析日期欄位的運算式。運算式應遵循以下結構：\$1"\$1ObjectTypeName.<Location of timestamp field in JSON pointer format>\$1\$1"。例如，如果您的物件類型是 MyType，而來源 JSON 為 `{"generatedAt": {"timestamp": "1737587945945"}}`，則 TimestampSource 應為 `"{MyType.generatedAt.timestamp}"`。
      + 長度限制：長度下限為 1。長度上限為 255。
      + 必要：否
    + TimestampFormat：指定 JSON 物件中時間戳記欄位的格式。此值應為 EPOCHMILLI (適用於具秒/毫秒精確度的 Unix epoch 時間戳記) 或 ISO\$18601 (遵循 ISO\$18601 格式，具秒/毫秒精確度，可選偏移 Z 或格式 HH:MM 或 HHMM)。例如，如果您的物件類型是 MyType，而來源 JSON 為 `{"generatedAt": {"timestamp": "2001-07-04T12:08:56.235-0700"}},`，則 TimestampFormat 應為 `"ISO_8601"`。
    + 單位：時間單位
      + 有效值：天
      + 必要：是
  + 必要：是
  + 初始範圍：最多 366 天
+ **ObjectCount**

  用於計算屬性的設定檔物件數目。
  + 類型：數字
  + 範圍：1 至 100
  + 必要：否
+ **Threshold**

  用來產生真/假計算屬性的比較邏輯。
  + 類型：臨界值物件
    + Value
      + 閾值的值
      + 類型：字串
      + 必要：否
    + 運算子
      + 閾值的運算子
      + 類型：ENUM
      + 有效值：
        + GREATER\$1THAN
        + LESS\$1THAN
        + EQUAL\$1TO
        + NOT\$1EQUAL\$1TO
  + 必要：否
+ **統計數字**

  要針對計算屬性執行的彙總作業。
  + 類型：ENUM
  + 有效值：
    + FIRST\$1OCCURRENCE
    + LAST\$1OCCURRENCE
    + COUNT
    + SUM
    + MINIMUM
    + MAXIMUM
    + AVERAGE
    + MAX\$1OCCURRENCE

------
#### [ UpdateCalculatedAttributeDefinition ]

**UpdateCalculatedAttributeDefinition**

更新計算屬性定義。更新僅限於顯示名稱、描述、時間範圍、物件計數和閾值。此 API 支援部分更新，因此只需要包含需要更新的參數。

**注意**  
更新條件時：  
增加計算屬性的日期範圍並不會觸發將大於目前日期範圍的歷史資料納入。
建立計算屬性定義後，就無法更新 TimestampSource 和 TimestampFormat。

**請求**

```
PUT /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

```
{
    "DisplayName": "string",
    "Description": "string",
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
   }
}
```

**回應**

```
{
    "CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
       "Attributes": [
           {
               "Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE"
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
    },
    "CreatedAt": number,
    "LastUpdatedAt": number,
    "Tags": {}
}
```

**請求內文**
+ **DisplayName**

  計算屬性的顯示名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z_][a-zA-Z_0-9-\s]*$`
  + 必要：否
+ **Description**

  計算屬性的描述。
  + 類型：字串
  + 長度限制：長度下限為 1。長度上限為 1000。
  + 必要：否
+ **條件**

  定義計算屬性彙總條件和閾值。
  + 類型：條件物件
    + 範圍
    + ObjectCount
    + Threshold
+ **範圍**

  資料包含在彙總中的相對期間。
  + 類型：範圍物件
    + 值：指定單位的時間長度
      + 類型：整數
      + 必要：否
    + ValueRange：可讓客戶指定相對時間範圍的結構，其中的資料會包含在計算屬性中。使用正數表示結束時間在過去時間，負數表示在未來時間。ValueRange 會覆寫 Value。
      + 類型：ValueRange
      + 必要：否
        + Start
          + 應開始包含物件的時間。使用正數表示開始時間在過去時間，負數表示在未來時間。
          + 類型：整數
          + 必要：是 
        + 結束
          + 應不再包含物件的時間。使用正數表示開始時間在過去時間，負數表示在未來時間。
          + 類型：整數
          + 必要：是 
    + 單位：時間單位
      + 有效值：天
      + 必要：是
  + 必要：是
  + 初始範圍：最多 366 天
+ **ObjectCount**

  用於計算屬性的設定檔物件數目。
  + 類型：數字
  + 範圍：1 至 100
  + 必要：否
+ **Threshold**

  用來產生真/假計算屬性的比較邏輯。
  + 類型：臨界值物件
    + Value
      + 閾值的值
      + 類型：字串
      + 必要：否
    + 運算子
      + 閾值的運算子
      + 類型：ENUM
      + 有效值：
        + GREATER\$1THAN
        + LESS\$1THAN
        + EQUAL\$1TO
        + NOT\$1EQUAL\$1TO
  + 必要：否

------
#### [ GetCalculatedAttributeDefinition ]

**GetCalculatedAttributeDefinition**

擷取計算屬性定義。

**請求**

```
GET /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

**請求內文**

```
The request does not have a request body.
```

**回應**

```
{
"CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
"Attributes": [
           {
"Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE"
"Conditions": {
"Range": {
      "Unit": "string",
      "Value": number
      "ValueRange"
        {
            "Start": number 
            "End": number 
        },
      "TimestampFormat": "string", 
      "TimestampSource": "string"
    },
        "ObjectCount": "number",
        "Threshold": {
"Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
    },
    "UseHistoricalData" boolean,
  "Status": "PREPARING" | "IN_PROGRESS" | "COMPLETED" | "FAILED",
  "Readiness": {
        "ProgressPercentage": number, 
        "Message": "string", 
        },
    "CreatedAt": number,
    "LastUpdatedAt": number,
    "Tags": {}
}
```

**URI 請求參數**
+ **DomainName**

  網域的唯一名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是
+ **CalculatedAttributeName**

  計算屬性的唯一 (每個網域) 名稱。
  + 類型：字串
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是

------
#### [ DeleteCalculatedAttributeDefinition ]

**DeleteCalculatedAttributeDefinition**

刪除現有的計算屬性定義。請注意，您可以刪除預設的計算屬性，但是一旦刪除，您將無法復原該動作，如果您想要還原，則需要使用 `CreateCalculatedAttributeDefinition` API 自行重新建立該屬性。

**請求**

```
DELETE /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

**請求內文**

```
The request does not have a request body.
```

**回應**

```
The response does not have a response body.
```

**URI 請求參數**
+ **DomainName**

  網域的唯一名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是
+ **CalculatedAttributeName**

  計算屬性的唯一 (每個網域) 名稱。
  + 類型：字串
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是

------
#### [ ListCalculatedAttributeDefinitions ]

**ListCalculatedAttributeDefinitions**

擷取網域的所有計算屬性定義。

**請求**

```
GET /domains/DomainName/calculated-attributes?max-results=MaxResults&next-token=NextToken
```

**請求內文**

```
The request does not have a request body.
```

**回應**

```
{ 
    "Items": [
        {
            "UseHistoricalData": boolean,
            "ReadinessStatus": PREPARING | IN_PROGRESS | COMPLETED | FAILED,
            "CalculatedAttributeName": "string", 
            "CreatedAt": number, 
            "Description": "string", 
            "DisplayName": "string", 
            "LastUpdatedAt": number, 
            "Tags": { 
                "string" : "string" 
            }
        } 
    ], 
    "NextToken": "string"
}
```

**URI 請求參數**
+ **DomainName**

  網域的唯一名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是
+ **MaxResults**

  每頁傳回的物件數量上限。
  + 有效範圍：最小值為 1。最大值為 100。
+ **NextToken**

  先前 ListCalculatedAttributeDefinition API 呼叫的分頁字符。
  + 長度限制：長度下限為 1。長度上限為 1024。

------
#### [ GetCalculatedAttributeForProfile ]

**GetCalculatedAttributeForProfile**

啟動計算並擷取單一設定檔中單一計算屬性的結果。

**請求**

```
GET /domains/DomainName/profile/ProfileId/calculated-attributes/CalculatedAttributeName
```

**請求內文**

```
The request does not have a request body.
```

**回應**

```
{
"Name": "string",
    "DisplayName": "string",
    "Value": "string",
    "IsDataPartial": "string",
    "LastObjectTimestamp" : number
}
```

**URI 請求參數**
+ **DomainName**

  網域的唯一名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是
+ **CalculatedAttributeName**

  計算屬性的唯一 (每個網域) 名稱。
  + 類型：字串
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是

------
#### [ ListCalculatedAttributesForProfile ]

**ListCalculatedAttributesForProfile**

啟動計算並擷取單一設定檔所有計算屬性的結果。

**請求**

```
GET /domains/DomainName/profile/ProfileId/calculated-attributes?max-results=MaxResults&next-token=NextToken
```

**請求內文**

```
The request does not have a request body.
```

**回應**

```
{
"Items": [
        {
"CalculatedAttributeName": "string",
            "DisplayName": "string",
            "Value": "string",
            "IsDataPartial" : "string",
            "LastObjectTimestamp" : number
        },
        ...
    ],
    "NextToken": "string"
}
```

**URI 請求參數**
+ **DomainName**

  網域的唯一名稱。
  + 長度限制：長度下限為 1。長度上限為 64。
  + 模式：`^[a-zA-Z0-9_-]+$`
  + 必要：是
+ **ProfileId**
  + 模式：`[a-f0-9]{32}`
  + 必要：是
+ **MaxResults**

  每頁傳回的物件數量上限。
  + 有效範圍：最小值為 1。最大值為 100。
+ **NextToken**

  先前 ListCalculatedAttributeDefinition API 呼叫的分頁字符。
  + 長度限制：長度下限為 1。長度上限為 1024。

------

# 建立自訂 Amazon Connect Customer Profiles 計算屬性定義
<a name="customerprofiles-calculated-attributes-creating-definition"></a>

使用客戶設定檔 [CreateCalculatedAttributeDefinition](https://docs.aws.amazon.com/customerprofiles/latest/APIReference/API_CreateCalculatedAttributeDefinition.html) API，您可以根據自訂物件類型以程式設計方式建立自己的計算屬性。

在本主題中，我們將展示如何使用自訂 JSON 檔案來建立計算屬性。

## 步驟 1：建立 JSON 檔案
<a name="step1-calculate-attribute-api"></a>

使用下列內容建立檔案：

```
{
"DomainName": "your-domain-name", 
   "CalculatedAttributeName": "your-calculated-attribute-name",
   "UseHistoricalData": true,
   "DisplayName": "your-display-name",
   "Description": "your-description",
   "AttributeDetails": {
"Attributes": [
         {
            "Name": "your-attribute-name"
         }
       ],
       "Expression": "{your-object-type.your-attribute-name}"
   },
    "Statistic": "your-statistic",
    "Conditions": {
       "Range": {
        "ValueRange"
        {
            "Start": your-range-start
            "End": your-range-end
        },
        "TimestampSource": "{your-object-type.your-timestamp-source}",          
        "Unit": "days"
        },
        "ObjectCount":  your-object-count,
        "Threshold": {
           "Value": "your-threshold-value",
           "Operator": "your-threshold-operator"
        }
   }  
}
```

若要使用您自己的值來自訂 JSON，請遵循下列指示：
+ **屬性**：這應包含您要用於計算屬性之物件類型中的欄位名稱。支援此清單中參照的兩個屬性。
+ **運算式**：支援在屬性之間執行的基本數學運算式。如果您只有一個屬性，則此欄位應該是 `{ObjectTypeName.AttributeName}`，否則如果您有數學運算式，則此欄位應包含這兩個屬性。
+ **Statistic**：這是當您呼叫其中一個實際執行彙總作業的計算 API 時所執行的作業。大多數都是不言自明的，但我們已經為那些不清楚的添加了解釋。

  **支援的統計**
  + `FIRST_OCCURRENCE` 傳回在最早擷取物件的運算式中指定的屬性。
  + `LAST_OCCURRENCE` 傳回在最新擷取物件的運算式中指定的屬性。
  + `COUNT` 從選擇的資料傳回計數。
  + `SUM` 從選擇的資料傳回總和。
  + `MINIMUM` 從選擇的資料傳回最小值。
  + `MAXIMUM` 從選擇的資料傳回最大值。
  + `AVERAGE` 從選擇的資料傳回平均值。
  + `MAX_OCCURRENCE` 返回表達式中所指定，出現最頻繁的值。
+ **範圍**：
  + 單位：目前僅支援 DAYS 單位。
  + ValueRange：在 ValueRange 的開始或結束欄位中指定正數，以指定應從幾天前開始，或使用負數指定應從未來幾天開始。
  + TimestampSource：指定 JSON 物件中應剖析日期欄位的運算式。運算式應遵循以下結構：\$1"\$1ObjectTypeName.<Location of timestamp field in JSON pointer format>\$1\$1"。例如，如果您的物件類型是 MyType，而來源 JSON 為 `{"generatedAt": {"timestamp": "1737587945945"}}`，則 TimestampSource 應為 `"{MyType.generatedAt.timestamp}"`。
+ **ObjectCount**：指出應根據計算屬性計算的物件數目。
+ **Threshold**：如果您想知道它是否大於特定值，而不是確切的計算屬性值，則可以使用閾值。

  閾值可以是任何字串，且支援下列閾值運算子。
  + `GREATER_THAN`
  + `LESS_THAN`
  + `EQUAL_TO`
  + `NOT_EQUAL_TO`
+ UseHistoricalData：建立計算屬性前擷取的歷史資料是否應包含在計算中。

## 步驟 2：呼叫 CreateCalculatedAttributeDefinition API
<a name="step2-calculated-attribute-api"></a>

使用您的值建立並自訂 JSON 檔案之後，呼叫 [CreateCalculatedAttributeDefinition](https://docs.aws.amazon.com/customerprofiles/latest/APIReference/API_CreateCalculatedAttributeDefinition.html) API，如下列範例所示：

```
aws customer-profiles create-calculated-attribute-definition --cli-input-json file:///custom_calculated_attribute_cli.json --region region_name
```

也可以使用以下端點：

```
https://profile.your-region.amazonaws.com/domains/your-domain-name/calculated-attributes
```

# 使用 API，在 Amazon Connect Customer Profiles 驗證計算屬性值
<a name="customerprofiles-calculated-attributes-validating-values"></a>

有兩個 API，`GetCalculatedAttributeForProfile` 和 `ListCalculatedAttributesForProfile`，位於設定檔層級。
+ **GetCalculatedAttributeForProfile** - 為單一設定檔檢索單一計算屬性。
+ **ListCalculatedAttributesForProfile** - 擷取單一設定檔的計算屬性清單

使用有效的設定檔 ID，您應該會看到計算屬性的值：

**回應範例**

```
{   
    "CalculatedAttributeName": "_average_hold_time",
    "DisplayName": "Average hold time",
    "IsDataPartial": "true",
    "Value": "24144"
}
```

**IsDataPartial** - 此旗標表示尚未達到時間範圍 (30 天) 或物件計數，因此計算屬性仍在計算中。例如，如果您想要超過 30 天的平均值，則只有在 30 天後，`IsDataPartial` 欄位才會設定為 false。

## 擷取計算屬性的清單
<a name="calculated-attributes-validating-a-list-of-values"></a>

**使用 AWS CLI**

```
aws customer-profiles list-calculated-attributes-for-profile --region your-region --domain-name your-domain-name --profile-id your-profile-id
```

**將 AWS CLI 與自訂 JSON 檔案搭配使用**

使用下列內容建立檔案：

```
{
    "DomainName": "your-domain-name", 
    "ProfileId" "some-profile-id"
}
```

```
aws customer-profiles list-calculated-attributes-for-profile --region your-region --cli-input-json file://list_calculated_attributes_for_profile_cli.json
```

**端點：**

```
https://profile.your-region.amazonaws.com/domains/your-domain-name/profile/your-profile-id/calculated-attributes/
```

## 擷取單一已計算屬性
<a name="calculated-attributes-validating-a-single-value"></a>

**使用 AWS CLI**：

```
aws customer-profiles get-calculated-attributes-for-profile --region your-region --domain-name your-domain-name --calculated-attribute-name your-calculated-attribute-name --profile-id your-profile-id
```

**使用 AWS CLI 搭配自訂 JSON 檔案**：

使用下列內容建立檔案：

```
{   
    "DomainName": "your-domain-name", 
    "CalculatedAttributeName": "your-calculated-attribute-name",
    "ProfileId" "your-profile-id"
}
```

```
aws customer-profiles get-calculated-attributes-for-profile --region your-region --cli-input-json file://list_calculated_attributes_for_profile_cli.json
```

**端點：**

```
https://profile.your-region.amazonaws.com/domains/your-domain-name/profile/your-profile-id/calculated-attributes/your-calculated-attribute-name
```

# Amazon Connect Customer Profiles 中的預設計算屬性
<a name="customerprofiles-default-calculated-attributes"></a>

## 預設 CTR 計算屬性
<a name="customerprofiles-default-calculated-attributes-ctr"></a>

Amazon Connect Customer Profiles 會根據聯絡記錄提供 out-of-the 立即可用的預設屬性。屬性如下：

**最常見的管道**

```
{
   "CalculatedAttributeName": "_most_frequent_channel",
   "DisplayName": "Most frequent channel",
   "Description": "Returns customer's frequently used communication channel. Channels include voice, chat, task.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "MAX_OCCURRENCE",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
       },
       "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "channel"
         }
      ],
      "Expression": "{CTR.channel}"
   },
   "Tags": {
   }
}
```

**最後一個管道**

```
{
   "CalculatedAttributeName": "_last_channel",
   "DisplayName": "Last channel",
   "Description": "Returns customer's last communication channel. Channels include voice, chat, task.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "LAST_OCCURRENCE",
   "Conditions": {
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "channel"
         }
       ],
       "Expression": "{CTR.channel}"
   },
   "Tags": {
   }
}
```

**最後一個客服人員識別符**

```
{
   "CalculatedAttributeName": "_last_agent_id",
   "DisplayName": "Last agent identifier",
   "Description": "Returns identifier of the last agent customer connected with.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "LAST_OCCURRENCE",
   "Conditions": {
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "agent.id"
         }
      ],
      "Expression": "{CTR.agent.id}"
   },
   "Tags": {
   }
}
```

**經常通話者**

```
{
   "CalculatedAttributeName": "_frequent_caller",
   "DisplayName": "Frequent caller",
   "Description": "Returns true or false based on the number of times a customer has called.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "COUNT",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
      },
      "ObjectCount": null,
      "Threshold": {
         "Value": "5",
         "Operator": "GREATER_THAN"
      }
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "contactId"
         }
      ],
      "Expression": "{CTR.contactId}"
   },
   "Tags": {
   }
}
```

**平均保留時間**

```
{
   "CalculatedAttributeName": "_average_hold_time",
   "DisplayName": "Average hold time",
   "Description": "Returns customer's average hold time for voice calls.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "AVERAGE",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
      },
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "agent.customerHoldDurationMillis"
         },
         {
            "Name": "queue.durationMillis"
         }
      ],
      "Expression": "{CTR.agent.customerHoldDurationMillis} + {CTR.queue.durationMillis}"
   },
   "Tags": {
   }
}
```

**平均通話時間**

```
{
   "CalculatedAttributeName": "_average_call_duration",
   "DisplayName": "Average call duration",
   "Description": "Returns customer's average call duration for voice calls.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "AVERAGE",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
       },
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "disconnectTimestamp"
         },
         {
            "Name": "initiationTimestamp"
         }
      ],
      "Expression": "{CTR.disconnectTimestamp} - {CTR.initiationTimestamp}"
   },
   "Tags": {
   }
}
```

**客戶的最長保留時間**

```
{
    "CalculatedAttributeName": "_maximum_hold_time",
    "DisplayName": "Customer's maximum hold time",
    "Description": "Returns customer's maximum hold time for voice calls in the past month.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "agent.customerHoldDurationMillis"
        },
        {
          "Name": "queue.durationMillis"
        }
      ],
      "Expression": "{CTR.agent.customerHoldDurationMillis} + {CTR.queue.durationMillis}"
    },
    "Statistic": "MAXIMUM",
    "Conditions": {
      "Range": {
        "Value": 30,
        "Unit": "DAYS"
      },
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

## 預設設定檔計算屬性
<a name="customerprofiles-default-calculated-attributes-profile"></a>

Amazon Connect Customer Profiles 會根據設定檔提供out-of-the可用的預設屬性。屬性如下：

**新客戶**

```
{
   "CalculatedAttributeName": "_new_customer",
   "DisplayName": "New customer",
   "Description": "Returns true or false for new customer profiles created.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "TIME_DIFFERENCE_FROM_NOW",
   "Conditions": {
      "ObjectCount": null,
      "Threshold": {
         "Value": "30",
         "Operator": "LESS_THAN"
      }
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "createdAt"
         }
      ],
      "Expression": "{_profile.createdAt}"
   },
   "Tags": {
   }
}
```

## 預設資產計算屬性
<a name="customerprofiles-default-calculated-attributes-asset"></a>

Amazon Connect Customer Profiles 會根據資產提供 out-of-the 立即可用的預設屬性。屬性如下：

**資產數量**

```
{
    "CalculatedAttributeName": "_assets_count",
    "DisplayName": "Count of assets",
    "Description": "Returns the count of assets for a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "AssetId"
        }
      ],
      "Expression": "{_asset.AssetId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**第一個資產的購買日期**

```
{
    "CalculatedAttributeName": "_asset_first_occurrence",
    "DisplayName": "First asset purchased date",
    "Description": "Returns purchase date of the customer's first asset.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "PurchaseDate"
        }
      ],
      "Expression": "{_asset.PurchaseDate}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**最後一個資產的購買日期**

```
{
    "CalculatedAttributeName": "_asset_last_occurrence",
    "DisplayName": "Last asset purchased date",
    "Description": "Returns purchase date of the customer's last asset.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "PurchaseDate"
        }
      ],
      "Expression": "{_asset.PurchaseDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**總資產價格**

```
{
    "CalculatedAttributeName": "_assets_price_sum",
    "DisplayName": "Total asset price",
    "Description": "Returns customer's total asset price.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Price"
        }
      ],
      "Expression": "{_asset.Price}"
    },
    "Statistic": "SUM",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**平均資產價格**

```
{
    "CalculatedAttributeName": "_assets_price_average",
    "DisplayName": "Average asset price",
    "Description": "Returns customer's average asset price.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Price"
        }
      ],
      "Expression": "{_asset.Price}"
    },
    "Statistic": "AVERAGE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**第一個資產的名稱**

```
{
    "CalculatedAttributeName": "_assets_name_first_occurrence",
    "DisplayName": "First asset name",
    "Description": "Returns name of the customer's first asset",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "AssetName"
        }
      ],
      "Expression": "{_asset.AssetName}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**最後一個資產的名稱**

```
{
    "CalculatedAttributeName": "_assets_name_last_occurrence",
    "DisplayName": "Last asset name",
    "Description": "Returns name of the customer's last asset.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "AssetName"
        }
      ],
      "Expression": "{_asset.AssetName}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

## 預設案例計算屬性
<a name="customerprofiles-default-calculated-attributes-case"></a>

Amazon Connect Customer Profiles 會根據案例提供 out-of-the 立即可用的預設屬性。屬性如下：

**案例數量**

```
{
    "CalculatedAttributeName": "_cases_count",
    "DisplayName": "Count of cases",
    "Description": "Returns the count of customer's cases for a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CaseId"
        }
      ],
      "Expression": "{_case.CaseId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**第一個案例的建立日期**

```
{
    "CalculatedAttributeName": "_case_first_occurrence",
    "DisplayName": "First case created date",
    "Description": "Returns created date of the customer's first case.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_case.CreatedDate}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**最後一個案例的建立日期**

```
{
    "CalculatedAttributeName": "_case_last_occurrence",
    "DisplayName": "Last case created date",
    "Description": "Returns created date of the customer's last case.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_case.CreatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**開啟的案例數量**

```
{
    "CalculatedAttributeName": "_cases_open_status_count",
    "DisplayName": "Count of open cases",
    "Description": "Returns the count of customer's open cases.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CaseId"
        }
      ],
      "Expression": "{_case.CaseId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Status": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Open"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**關閉的案例數量**

```
{
    "CalculatedAttributeName": "_cases_closed_status_count",
    "DisplayName": "Count of closed cases",
    "Description": "Returns the count of customer's closed cases.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CaseId"
        }
      ],
      "Expression": "{_case.CaseId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Status": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Closed"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

## 預設通訊記錄計算屬性
<a name="customerprofiles-default-calculated-attributes-communication-record"></a>

Amazon Connect Customer Profiles 會根據通訊記錄提供 out-of-the 立即可用的預設屬性。屬性如下：

**最後一次開啟電子郵件的日期**

```
{
    "CalculatedAttributeName": "_campaign_email_last_open",
    "DisplayName": "Last email open date",
    "Description": "Returns the last email open date of the customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Events.Open.UpdatedDate"
        }
      ],
      "Expression": "{_communicationRecord.Events.Open.UpdatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:Email"]
                },
                "Events.Open.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Open"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**開啟的電子郵件數量**

```
{
    "CalculatedAttributeName": "_campaign_email_open_count",
    "DisplayName": "Email open count",
    "Description": "Returns the number of times emails were opened by a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CommunicationRecordId"
        }
      ],
      "Expression": "{_communicationRecord.CommunicationRecordId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:Email"]
                },
                "Events.Open.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Open"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**傳送的電子郵件數量**

```
{
    "CalculatedAttributeName": "_campaign_email_delivery_count",
    "DisplayName": "Email delivery count",
    "Description": "Returns the number of times emails were delivered to a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CommunicationRecordId"
        }
      ],
      "Expression": "{_communicationRecord.CommunicationRecordId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:Email"]
                },
                "Events.Delivery.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Delivery"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**已傳送的 SMS 數量**

```
{
    "CalculatedAttributeName": "_campaign_sms_delivery_count",
    "DisplayName": "SMS delivered count",
    "Description": "Returns the number of times SMS were delivered to a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CommunicationRecordId"
        }
      ],
      "Expression": "{_communicationRecord.CommunicationRecordId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:SMS"]
                },
                "Events.TEXT_DELIVERED.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["TEXT_DELIVERED"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**最後一次封鎖 SMS 的日期**

```
  {
    "CalculatedAttributeName": "_campaign_sms_last_stop",
    "DisplayName": "Last SMS blocked date",
    "Description": "Returns the last SMS blocked date of the customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Events.TEXT_BLOCKED.UpdatedDate"
        }
      ],
      "Expression": "{_communicationRecord.Events.TEXT_BLOCKED.UpdatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ANY",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:SMS"]
                },
                "Events.TEXT_BLOCKED.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["TEXT_BLOCKED"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**通訊業者最後一次封鎖 SMS 的日期**

```
{
    "CalculatedAttributeName": "_campaign_sms_last_stop_carrier",
    "DisplayName": "Last SMS carrier blocked date",
    "Description": "Returns the last SMS carrier blocked date of the customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Events.TEXT_CARRIER_BLOCKED.UpdatedDate"
        }
      ],
      "Expression": "{_communicationRecord.Events.TEXT_CARRIER_BLOCKED.UpdatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ANY",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:SMS"]
                },
                "Events.TEXT_CARRIER_BLOCKED.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["TEXT_CARRIER_BLOCKED"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

## 預設訂單計算屬性
<a name="customerprofiles-default-calculated-attributes-order"></a>

Amazon Connect Customer Profiles 會根據訂單提供 out-of-the 立即可用的預設屬性。屬性如下：

**訂單數量**

```
{
    "CalculatedAttributeName": "_orders_count",
    "DisplayName": "Count of orders",
    "Description": "Returns the count of orders for a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "OrderId"
        }
      ],
      "Expression": "{_order.OrderId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**第一個訂單的建立日期**

```
{
    "CalculatedAttributeName": "_order_first_occurrence",
    "DisplayName": "First order created date",
    "Description": "Returns created date of the customer's first order.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_order.CreatedDate}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**最後一個訂單的建立日期**

```
{
    "CalculatedAttributeName": "_order_last_occurrence",
    "DisplayName": "Last order created date",
    "Description": "Returns created date of the customer's last order.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_order.CreatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**所有訂單的總價格**

```
{
    "CalculatedAttributeName": "_orders_total_price_sum",
    "DisplayName": "Total price of all orders",
    "Description": "Returns sum of total price for all customer's orders.",
    "Statistic": "SUM",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "TotalPrice"
        }
      ],
      "Expression": "{_order.TotalPrice}"
    },
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**訂單的平均總價**

```
{
    "CalculatedAttributeName": "_orders_total_price_average",
    "DisplayName": "Orders average of total price",
    "Description": "Returns average of total price for all customer's orders.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "TotalPrice"
        }
      ],
      "Expression": "{_order.TotalPrice}"
    },
    "Statistic": "AVERAGE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

# Amazon Connect Customer Profiles 計算屬性的錯誤訊息和解決方案
<a name="customerprofiles-calculated-attributes-troubleshooting"></a>

下表顯示每個錯誤的計算屬性錯誤訊息、原因和解決方案。


| 錯誤訊息 | 原因 | Resolution | 
| --- | --- | --- | 
| 擷取設定檔的計算屬性會顯示空值 | 這可能是因為計算屬性沒有資料而導致。建立計算屬性之後，必須擷取新資料。 | 透過整合或 CreateProfile 和 PutProfileObject API 擷取新資料或重新擷取舊資料。 | 