注册 Business Messages 的合作伙伴后,您可以创建代理,即代表业务功能(例如网站支持和品牌营业地点)的对话实体,从而实现用户与品牌之间的对话。
当用户找到您在 Google 搜索或 Google 地图中管理的品牌时,搜索结果会显示聊天选项。当用户点击聊天时,他们可以向品牌的代理发送消息。借助该代理,您可以接收和回复用户的消息。
注册为合作伙伴
通过注册成为 Business Messages 的合作伙伴,为品牌创建代理,并利用为代理提供支持的 API,您可以为客户服务、销售和其他业务应用启用消息体验。
- 打开 Business Communications 开发者控制台。
- 在 Business Messages 下,点击创建合作伙伴帐号。
输入合作伙伴信息的值:
字段 值 您的姓名 您的全名 合作伙伴名称 您的组织名称 合作伙伴网站 您的组织网站 区域 您要托管 Business Messages 服务的区域
查看并接受 Business Messages 服务条款。
点击创建。
您现在已注册为 Business Messages 合作伙伴,并有权访问 Business Messages 和 Business Communications API。Business Messages API 向用户发送消息,而 Business Communications API 用于管理代理。
创建服务帐号
要安全地对 Business Messages API 和 Business Communications API 的 API 调用进行身份验证,您需要服务帐号密钥和 oauth2l 命令行工具。
- 在 Business Communications 开发者控制台首页上,点击合作伙伴帐号设置。
- 在左侧导航栏中,点击服务帐号。
点击创建密钥,然后点击创建。
您的浏览器会下载服务帐号密钥。将您的服务帐号密钥存储在安全的私密位置。请勿公开共享您的密钥。您稍后需要使用此密钥来访问 Business Message API 和 Business Communications API。
设置 Webook
现在,Business Messages 和 Business Communications API 已启用,您必须指定您的网络钩子网址才能开始接收消息。
- 在 Business Communications 开发者控制台中打开帐号设置。
- 确保选择了正确的合作伙伴帐号。
- 对于 Business Messages 网络钩子网址,点击配置。
- 在网络钩子端点网址部分,输入 webhook 的网址,以“https://”开头。
- 记下您的
clientToken
值。您需要使用它来验证您收到的消息是否来自 Google。 将 webhook 配置为接受具有指定
clientToken
参数的POST
请求,并发送200 OK
响应,并将secret
参数的纯文本值作为响应正文。例如,如果您的 webhook 收到具有以下正文内容的
POST
请求{ "clientToken":"SJENCPGJESMGUFPY", "secret":"0123456789" }
webhook 应确认
clientToken
值,如果clientToken
正确无误,则返回200 OK
响应,并将0123456789
作为响应正文。在控制台中,点击验证。
Business Messages 验证您的 webhook 后,对话框将关闭。
请参阅示例:更新网络钩子网址,了解如何使用 Business Communications API 配置您的网络钩子。
获取合作伙伴信息
如需获取最新的合作伙伴信息,您可以使用合作伙伴 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 开发者控制台中的帐号设置页面,也可以运行以下命令。
将 PARTNER_ID 替换为您的合作伙伴 ID(合作伙伴 ID 可在 Business Communications 开发者控制台中找到),并将 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', }"
示例:更新网络钩子网址
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 进行开发了。如需快速上手,请参阅创建您的第一个代理。