

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

# 啟用行動聊天的推播通知
<a name="enable-push-notifications-for-mobile-chat"></a>

行動聊天的推播通知是透過 [AWS 終端使用者訊息](https://docs.aws.amazon.com/sms-voice/latest/userguide/what-is-service.html)設定的。您可以在 iOS 或 Android 裝置上啟用行動聊天的推播通知，如此，即使客戶當下並未使用行動應用程式，您也能提醒他們有新訊息。您可以在與 [Connect Customer 行動 SDK](https://docs.aws.amazon.com/connect/latest/adminguide/integrate-chat-with-mobile.html)、[Webview 解決方案](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples)或自訂原生解決方案整合的現有應用程式中啟用此功能。

 下列步驟和資源將協助您開始將 Connect Customer 推送通知整合到原生行動應用程式：

## 步驟 1：從 Apple 的 APN 和 Google 的 FCM 主控台取得登入資料
<a name="step-1-enable-push-notifications-for-mobile-chat"></a>

為了設定 Connect Customer 以便將推播通知傳送到您的應用程式，您必須先從 Apple 的 APNs 和 Google 的 FCM 主控台取得登入資料，讓[AWS 最終使用者傳訊](https://docs.aws.amazon.com/sms-voice/latest/userguide/what-is-service.html)能夠將通知傳送到您的行動應用程式。您提供的登入資料取決於您使用的推播通知系統：
+  有關 Apple 推播通知服務 (APN) 登入資料，請參閱 Apple 開發人員文件中的[取得 Apple 的加密金鑰和金鑰 ID](https://developer.apple.com/documentation/usernotifications/establishing-a-token-based-connection-to-apns#Obtain-an-encryption-key-and-key-ID-from-Apple) 和[取得 Apple 的提供者憑證](https://developer.apple.com/documentation/usernotifications/establishing-a-certificate-based-connection-to-apns#Obtain-a-provider-certificate-from-Apple)。
+  Google Firebase Cloud Messaging (FCM) 登入資料可透過 Firebase 主控台取得，相關資訊請參閱 [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging)。

## 步驟 2：使用 AWS 主控台建立 AWS 最終使用者傳訊服務應用程式，並為 FCM 或 APNs 啟用推送通知管道
<a name="step-2-enable-push-notifications-for-mobile-chat"></a>

 您必須先[建立AWS 終端使用者訊息應用程式，並啟用推播通知](https://docs.aws.amazon.com/push-notifications/latest/userguide/procedure-enable-push.html)管道 (在 [AWS 主控台](https://console.aws.amazon.com/push-notifications/)中)，才能讓 Amazon Connect 傳送推播通知。

 請依照這些指示建立應用程式並啟用任何推播管道。若要完成此程序，只需輸入應用程式名稱即可。您可以稍後啟用或停用任何推播管道：

1.  在 https：//[https://console.aws.amazon.com/push-notifications/](https://console.aws.amazon.com/push-notifications/) 開啟 AWS 最終使用者傳訊推送主控台 

1.  選擇**建立應用程式**。

1.  針對**應用程式名稱**，輸入您的應用程式名稱。

1.  (選用) 依照這個選用步驟，啟用 **Apple 推播通知服務 (APN)**。

   1.  針對 **Apple 推播通知服務 (APN)**，選取**啟用**。

   1.  針對**預設身分驗證類型**，選擇下列其中一項：

      1.  如果您選擇**金鑰登入**資料，請從 Apple 開發人員帳戶提供以下資訊。 AWS 最終使用者傳訊推送需要此資訊來建構身分驗證字符。

         1.  **金鑰 ID** – 指派給簽署金鑰的 ID。

         1.  **封包識別符** – 指派給 iOS 應用程式的 ID。

         1.  **團隊識別符** – 指派給 Apple 開發人員帳戶團隊的 ID。

         1.  **驗證金鑰** – 您在建立驗證金鑰時，從 Apple 開發人員帳戶下載的 .p8 檔案。

      1.  如果您選擇**憑證登入資料**，請提供下列資訊：

         1.  **SSL 憑證** – 您的 TLS 憑證的 .p12 檔案。

         1.  **憑證密碼** – 如果您已為憑證指派密碼，請在此處輸入。

         1.  **憑證類型** – 選取要使用的憑證類型。

1.  (選用) 依照這個選用步驟，啟用 **Firebase Cloud Messaging (FCM)**。

   1.  針對 **Firebase Cloud Messaging (FCM)**，選取**啟用**。

   1.  針對**預設身分驗證類型**選擇**權杖登入資料**，然後選擇您的服務 JSON 檔案。

1.  選擇**建立應用程式**。

## 步驟 3：將 AWS 最終使用者傳訊 應用程式與 Connect Customer 執行個體建立關聯
<a name="step-3-enable-push-notifications-for-mobile-chat"></a>

 若要在[Connect Customer 執行個體](https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html)上啟用推播通知，您需要呼叫 [CreateIntegrationAssociation](https://docs.aws.amazon.com/connect/latest/APIReference/API_CreateIntegrationAssociation.html) API 與 `PINPOINT_APP` [IntegrationType](https://docs.aws.amazon.com/connect/latest/APIReference/API_CreateIntegrationAssociation.html#API_CreateIntegrationAssociation_RequestSyntax)，將 AWS 最終使用者傳訊應用程式與[Connect Customer 執行個體](https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html)建立關聯。您可以使用 [AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/connect/create-integration-association.html) 或任何支援語言的 [Amazon Connect SDK](https://aws.amazon.com/developer/tools/) 來呼叫此 API。這是 AWS 最終使用者傳訊應用程式和 Connect Customer 執行個體之間每次整合所需的一次性加入步驟。

## 步驟 4：使用 FCM 或 APNs開發套件取得裝置字符，並將其註冊至 Connect Customer
<a name="step-4-enable-push-notifications-for-mobile-chat"></a>

您需要擷取裝置字符，並使用它向 Connect Customer 聊天聯絡人註冊最終使用者行動裝置，以傳送聊天中新訊息的推播通知。 請閱讀下列 FCM/APNs開發人員文件，以了解裝置字符如何產生並從行動應用程式取得。
+  對於 Apple 的推播通知服務 (APN)，請參閱 Apple 開發人員文件中的[對 APN 註冊您的應用程式](https://developer.apple.com/documentation/usernotifications/registering-your-app-with-apns)。
+  對於 Firebase Cloud Messaging (FCM)，請參閱 [FCM 註冊權杖管理的最佳實務](https://firebase.google.com/docs/cloud-messaging/manage-tokens)。

 若要對聊天聯絡註冊裝置，建議您執行下列動作：

1.  在行動應用程式呼叫 [StartChatContact](https://docs.aws.amazon.com/connect/latest/APIReference/API_StartChatContact.html) API 時，傳入 `deviceToken` 和 `deviceType` 作為[聯絡屬性](https://docs.aws.amazon.com/connect/latest/APIReference/API_StartChatContact.html#connect-StartChatContact-request-Attributes)。對於 Webview 和託管通訊小工具使用者，請參閱[如何將聯絡屬性傳入通訊小工具](https://docs.aws.amazon.com/connect/latest/adminguide/pass-contact-attributes-chat.html#how-to-contact-attributes-chatwidget)，以取得詳細資訊。

1.  在聯絡流程的 Lambda 函數中，嵌入對 [CreatePushNotificationRegistration](https://docs.aws.amazon.com/connect/latest/APIReference/API_CreatePushNotificationRegistration.html) 動作的呼叫。流程區塊應從使用者定義的聯絡屬性讀取 `deviceToken` 和 `deviceType`，並從系統屬性讀取 `initialContactId`，然後將這些值傳遞至 Lambda 函數。

   1.  根據您的使用案例，如果您想要讓終端使用者立即接收到推播通知，請在開始聊天後 (流程開始時) 緊接著放置 Lambda 函數，或是在聯絡轉接至佇列之前放置，如此，使用者只會在客服人員即將加入時接收到聯絡。進行 API 呼叫後，裝置就會開始在客服人員或系統傳入新訊息時接收推播通知。依預設會為所有的系統和客服人員訊息傳送推播通知。  
![在 Connect Customer 管理員網站流程設計工具中調用 lambda 函數流程區塊。](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/images/step-4-set-up-push-notifications-for-mobile-chat-1.png)

1.  (選用) 在流程的 Lambda 函數中，嵌入對 [DeletePushNotificationRegistration](https://docs.aws.amazon.com/connect/latest/APIReference/API_DeletePushNotificationRegistration.html) 動作的呼叫。進行 API 呼叫後，裝置就會停止在客服人員或系統傳入新訊息時接收推播通知。

## 步驟 5：在您的行動應用程式上接收推播通知
<a name="step-5-enable-push-notifications-for-mobile-chat"></a>

 查看我們的[Connect Customer 聊天 UI 範例](https://github.com/amazon-connect/amazon-connect-chat-ui-examples) 專案，並參考我們的 [iOS](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples/iOS-WKWebView-sample) 和 [Android](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples/android-webview-sample) 聊天 Webview 範例，示範如何整合 Connect Customer APIs以加入和接收推播通知。

## 監控推播通知的用量
<a name="monitor-your-usage-for-push-notification"></a>

 為了確保推播通知的可靠性、可用性和效能，請務必監控其用量。您可以透過數個管道來追蹤這項資訊：

1.  AWS 提供推送通知的完整監控工具。 如需詳細資訊，請參閱[監控 AWS 最終使用者傳訊推送](https://docs.aws.amazon.com/push-notifications/latest/userguide/monitoring-overview.html)。

1.  視您使用的推播通知服務而定，您可以透過其對應的主控台存取其他用量資料。

   1.  Firebase Cloud Messaging (FCM)：參閱有關於[了解訊息傳遞](https://firebase.google.com/docs/cloud-messaging/understand-delivery?platform=android)的 FCM 文件，深入了解您的 FCM 用量。

   1.  Apple 推播通知服務 (APN)：檢閱有關於[使用指標和 APN 檢視推播通知狀態](https://developer.apple.com/documentation/usernotifications/viewing-the-status-of-push-notifications-using-metrics-and-apns)的 APN 文件章節，以監控您的通知狀態。