註冊使用 Business Messages 合作夥伴時,您可以建立代理程式來啟用使用者和品牌之間的對話,也就是代表業務功能 (例如網站支援和品牌位置) 的對話實體。
當使用者在 Google 搜尋或 Google 地圖上找到您管理的品牌時,搜尋結果會顯示「Chat」選項。使用者按一下「Chat」後,就能傳送訊息至品牌的服務專員。代理程式可讓您接收及回應使用者的訊息。
註冊成為合作夥伴
註冊使用 Business Messages 合作夥伴、為品牌建立代理程式,以及運用支援代理程式的 API,即可為客戶服務、銷售和其他商業應用程式啟用訊息體驗。
- 開啟 Business Communications Developer Console。
- 在「企業訊息」下方,按一下 [建立合作夥伴帳戶]。
輸入夥伴資訊的值:
欄位 值 你的名稱 你的全名 合作夥伴名稱 貴機構的名稱 合作夥伴網站 貴機構的網站 區域 您要代管 Business Messages 服務的區域
詳閱並接受《Business Messages 服務條款》。
點選「建立」。
您現在已經註冊為 Business Messages 合作夥伴,並可使用 Business Messages 和 Business Communications API。Business Messages API 可以傳送訊息給使用者,而 Business Communications API 則會管理代理程式。
建立服務帳戶
如要安全地驗證向 Business Messages 和 Business Communications API 發出的 API 呼叫,您必須具備服務帳戶金鑰和 oauth2l 指令列工具。
- 在 Business Communications Developer Console 首頁中,按一下 [合作夥伴帳戶設定]。
- 在左側導覽面板中,按一下 [Service account] (服務帳戶)。
點選 [建立金鑰],然後按一下 [建立]。
您的瀏覽器會下載服務帳戶金鑰。將服務帳戶金鑰儲存在安全無虞的私人地點。請勿公開分享金鑰。您稍後必須使用這組金鑰才能存取 Business Message 和 Business Communication API。
設定您的手冊
現在 Business Messages 和 Business Communications API 已啟用,您必須指定 Webhook 網址才能開始接收訊息。
- 在 Business Communications 開發人員控制台中開啟帳戶設定。
- 確認已選取正確的合作夥伴帳戶。
- 針對「Business Messages Webhook URL」,按一下 [Configure]。
- 在「Webhook 端點網址」中,輸入「https://」的 Webhook 網址。
- 請記下您的
clientToken
值。您需要這些資訊才能驗證您收到的訊息來自 Google。 將 Webhook 設為接受含有指定
clientToken
參數的POST
要求,並傳送200 OK
回應和secret
參數的純文字值做為回應主體。舉例來說,如果您的 Webhook 收到含有下列主體內容的
POST
要求,{ "clientToken":"SJENCPGJESMGUFPY", "secret":"0123456789" }
您的 Webhook 應確認
clientToken
值,如果clientToken
正確,則傳回含有0123456789
的200 OK
回應。在主控台中,按一下 [驗證]。
Business Messages 驗證 Webhook 後,對話方塊就會關閉。
請參閱範例:更新 Webhook 網址一文,瞭解如何使用 Business Communication API 設定 Webhook。
取得合作夥伴資訊
如要取得目前的合作夥伴資訊,您可以使用合作夥伴 ID 查詢 Business Communications API。
執行下列指令。將 PARTNER_ID 替換成您的合作夥伴 ID。
# This code gets the partner. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get # Replace the __PARTNER_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/partners/__PARTNER_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
更新合作夥伴資訊
如要更新合作夥伴資訊,您可以使用 Business Communications Developer Console 中的「帳戶設定」頁面或執行下列指令。
將 PARTNER_ID 替換成您的合作夥伴 ID(可在 Business Communications 開發人員控制台中找到合作夥伴 ID),並以您更新的欄位名稱取代 UPDATED_FIELDS。
# This code updates the partner entity. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/patch # Replace the __PARTNER_ID__, __UPDATED_FIELDS__, __FIELD_NAME__, __FIELD_VALUE__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/partners/__PARTNER_ID__?updateMask=__UPDATED_FIELDS__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "__FIELD_NAME__": "__FIELD_VALUE__" }'
如需格式設定和值選項,請參閱 partners.patch
。
範例:更新顯示名稱
curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/12345/partners/67890?updateMask=displayName" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json /path/to/service/account/key businesscommunications)" \ -d "{ 'displayName': 'XYZ Messaging', }"
範例:更新 Webhook 網址
curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/partners/12345?updateMask=productCapabilities" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json /path/to/service/account/key businesscommunications)" \ -d "{ 'productCapabilities': [ { 'product': 'BUSINESS_MESSAGES', 'businessMessagesCapability': { 'webhookUrl': 'https://xyz.messaging.com/webhook', }, }, ], }"
後續步驟
您是已註冊的合作夥伴,且已啟用 API,現在可以開始透過 Business Messages 進行開發。如要快速開始使用,請參閱建立您的第一個代理程式一文。