开始之前,建议您通读开发者文档和 Postman 收藏夹。这有助您了解云端 API 的运行原理,包括如何入门和迁移号码。
您必须使用嵌入式注册让新客户开始使用云端 API。如果您尚未执行此步骤,请集成并启动嵌入式注册。嵌入式注册是最快捷简单的客户注册方式,客户只需不到五分钟即可完成注册,开始发送消息。
接下来,请考虑您希望先将哪些客户迁移至云端 API。我们一般建议将所有客户从本地迁移至云端 API,但每位客户的需求可能各不相同。在考虑要迁移哪些客户时,请考虑以下因素:
考量因素 | 更多背景信息 |
---|---|
云端 API 能否支持客户的吞吐量和消息量? | 云端 API 为大多数商家提供 250 条消息/秒的累积峰值吞吐量,文本/媒体和入站/出站消息一并算入其中。 |
云端 API 能否满足客户的合规性需求? | 云端 API 符合《通用数据保护条例》要求并已通过 SOC 2 认证。服务器托管在北美地区和欧洲。 |
客户使用的功能能否得到云端 API 支持? | 大部分重要功能都受支持。请参阅此处,查看受支持功能的完整清单。 |
确定迁移对象后,即可制定迁移计划和时间表。
在制定计划时,记得设计适用于以下两种场景的系统:新客户注册,以及将现有客户从本地迁移到云端 API。对于迁移,请加入相关计划,备份您当前的本地实例并将相关号码迁移到云端 API。
首先,您需要确定是否要通知现有客户有关迁移的事宜。然后,您应确定是否需要创建或更新任何支持文档,以帮助完成云端 API 设置。
由于云端 API 的托管费用由 Meta 承担,您需决定是否对您的定价作出相应的更新。
如要使用云端 API,解决方案合作伙伴需要准备下列资产:
资产 | 具体说明 |
---|---|
商务管理平台 | 您可以使用现有的商务管理平台,也可以设置新的商务管理平台。保存商务管理平台编号。 |
WhatsApp Business 商业帐号 (WABA) | 如需相关帮助,请参阅为 WhatsApp Business API 创建 WhatsApp Business 商业帐号。 |
如果您还没有应用,则需创建一个“业务”类型的应用。请记得为应用添加显示名和联系邮箱。 如果您是解决方案合作伙伴,您的应用必须通过应用审核并请求获取以下权限的高级访问级别:
作为解决方案合作伙伴,您还可以在不同客户端及不同 WABA 下自由使用同一个 Meta 应用。但请注意,每个应用都要经受应用审核,且只能有一个 Webhooks 端点。 | |
系统用户 | 如需相关帮助,请参阅向商务管理平台添加系统用户。 目前,拥有
建议您使用管理员级系统用户进行生产部署。如需了解更多信息,请参阅商务管理平台用户身份和权限简介。 |
商家电话号码 | 这是商家发送消息时要使用的电话号码,需通过短信/语音通话进行验证。 对于解决方案合作伙伴和直营商家:如果您想使用自己的号码,则应在 WhatsApp 管理工具中添加电话号码,并通过图谱 API 的认证端点进行认证。 对于使用解决方案合作伙伴的商家:如果您想使用自己的号码,则应根据解决方案合作伙伴的嵌入式注册流程添加和认证号码。 电话号码的认证状态不会影响本地 API 与云端 API 之间的迁移。如果您无法访问嵌入式注册流程来认证电话号码,建议您先使用本地解决方案认证电话号码,然后再将这些号码迁移到云端 API。 向云端 API 添加商家电话号码时没有数量限制。 |
消费者电话号码 | 此为当前使用消费者 WhatsApp 应用的电话号码。此号码将接收由您的商家电话号码发送的消息。 |
如要访问 WhatsApp Business 消息云端 API,您首先需要代表您的商家接受《WhatsApp Business 开放平台服务条款》。
为此,请前往 WhatsApp 管理工具并接受信息横幅中的服务条款。
如果您目前是云端 API 的 Beta 测试版合作伙伴,则会有 90 天的宽限期。这表示您需要在 2022 年 7 月 5 日前接受服务条款,否则会失去访问权限。
如果您是新加入云端 API 的商家(包括从本地 API 迁移的商家),则需接受服务条款后才能开始使用云端 API。如不接受服务条款,注册调用会一直失败。
作为开发者,您需要接受服务条款。如果您是解决方案合作伙伴,则无需让客户接受服务条款。
图谱 API 调用使用访问口令进行身份验证。详情请参阅访问口令。建议您使用系统用户来生成口令。
如要生成系统用户访问口令,请根据下列步骤操作:
whatsapp_business_management
和 whatsapp_business_messaging
。点击生成口令。通过 Webhooks 设置,您将可接收 WhatsApp Business 开放平台的实时 HTTP 通知。这表示您会在出现相关动态时收到通知,例如收到客户发来的消息或您的 WhatsApp Business 商业帐号 (WABA) 发生更改。
如要设置 Webhooks,您需要使用符合 Meta 和 WhatsApp 要求的网址,创建面向互联网的网络服务器。如需具体操作说明,请参阅创建端点。如果需要用于测试的端点,您可以生成一个测试 Webhooks 端点。
准备好端点后,请配置此端点以供 Meta 应用使用:
在应用面板中,找到 WhatsApp 产品并点击配置。然后,找到 Webhooks 部分,点击配置 Webhooks。点击之后,屏幕上会出现一个对话框,要求您提供以下两项内容:
添加信息后,点击验证并保存。
返回应用面板,依次点击左侧面板中的 WhatsApp > 配置。在 Webhooks 下,点击管理。页面随即会显示一个对话框,其中包含您可获取相关通知的所有对象。如要接收用户消息,请点击订阅消息。
您只需为每个应用程序设置一次 Webhooks。您可以使用相同的 Webhooks 接收多个 WhatsApp Business 商业帐号的多个事件类型。详情请参阅我们的 Webhooks 部分。
在任何情况下,您只能为每个 Meta 应用配置一个端点。如果您需要将 Webhooks 更新发送到多个端点,则需要多个 Meta 应用。
为确保收到正确帐号的通知,请订阅您的应用:
curl -X POST \
'https://graph.facebook.com/v19.0
/WHATSAPP_BUSINESS_ACCOUNT_ID/subscribed_apps' \
-H 'Authorization: Bearer ACCESS_TOKEN'
如果收到下方响应,此帐号所含电话号码的所有 Webhooks 事件都将发送到您配置的 Webhooks 端点。
{ "success": true }
如要发送消息,您需要注册想要使用的电话号码,即上文准备工作中提到的商家电话号码。
在进行注册前,您需要找到该电话号码的编号。如要获取电话号码编号,请作出以下 API 调用:
curl -X GET \
'https://graph.facebook.com/v19.0
/WHATSAPP_BUSINESS_ACCOUNT_ID/phone_numbers' \
-H 'Authorization: Bearer ACCESS_TOKEN'
如果请求成功,响应中将包含与您的 WABA 关联的所有电话号码:
{ "data": [ { "verified_name": "Jasper's Market", "display_phone_number": "+1 631-555-5555", "id": "1906385232743451", "quality_rating": "GREEN" }, { "verified_name": "Jasper's Ice Cream", "display_phone_number": "+1 631-555-5556", "id": "1913623884432103", "quality_rating": "NA" } ] }
保存您想注册的电话号码的编号。如需了解此端点的详细信息,请参阅读取电话号码。
如果您要将电话号码从本地 API 迁移到云端 API,则在通过云端 API 注册电话号码之前,需要采取额外步骤。如需获取完整流程,请参阅本地 API 和云端 API 之间的迁移。
获取电话号码编号后,您即可注册该号码。在注册 API 调用中,您需同时执行以下两项操作:
使用云端 API 必须设置双重验证。如未设置,您将收到一条注册失败消息:
请求示例:
curl -X POST \
'https://graph.facebook.com/v19.0
/FROM_PHONE_NUMBER_ID/register' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"messaging_product": "whatsapp","pin": "6_DIGIT_PIN"}'
响应示例:
{ "success": true }
必须在完成嵌入式注册流程后的 14 天内注册电话号码。如果未在该窗口期内注册号码,则必须再次完成嵌入式注册流程后,才能重新注册。
在参与的客户向您的商家发送消息后,您即可获得 24 小时免费消息窗口期,此窗口期称为“客户服务窗口期”。出于测试目的,我们需要启用此窗口期,这样您就可以发送任意数量的消息。
使用个人 WhatsApp iOS/Android 应用向您刚注册的电话号码发送一条消息。发送消息后,您应会收到一条传入 Webhooks 的通知消息,其格式如下。
{ "object": "whatsapp_business_account", "entry": [ { "id": "WHATSAPP_BUSINESS_ACCOUNT_ID", "changes": [ { "value": { "messaging_product": "whatsapp", "metadata": { "display_phone_number": "16315551234", "phone_number_id": "PHONE_NUMBER_ID" }, "contacts": [ { "profile": { "name": "Kerry Fisher" }, "wa_id": "16315555555" } ], "messages": [ { "from": "16315555555", "id": "wamid.ABGGFlA5FpafAgo6tHcNmNjXmuSf", "timestamp": "1602139392", "text": { "body": "Hello!" }, "type": "text" } ] }, "field": "messages" } ] } ] }
启用客户服务窗口期后,您可以向上一步中使用的消费者号码发送一条测试消息。为此,请作出以下 API 调用:
curl -X POST \
'https://graph.facebook.com/v19.0
/FROM_PHONE_NUMBER_ID/messages' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"messaging_product": "whatsapp", "to": "16315555555","text": {"body" : "hello world!"}}'
如果调用成功,响应中将包含消息编号。请使用该编号通过 Webhooks 来追踪消息进度。该编号最长为 128 个字符。
响应示例:
{ "id":"wamid.gBGGFlaCGg0xcvAdgmZ9plHrf2Mh-o" }
我们将在每个月的第一个星期二发布云端 API 更新。更新包括新功能和改进。云端 API 会自动更新,因此您无需任何操作,即可使用发布的任何新功能。
WhatsApp develops and operates the WhatsApp Business API, which enables businesses to communicate with WhatsApp consumer users on the WhatsApp network. When using the Cloud API, Meta will host the WhatsApp Business API for you and provide an endpoint for the WhatsApp service for your incoming and outgoing WhatsApp communications.
No, there is no difference in messaging prices between the Cloud API and the On-Premises API. Access to Cloud API is free, and we expect it to generate additional cost savings for developers. The two types of cost savings for the Cloud API are 1) set up cost (including server or external cloud provider cost), 2) ongoing cost of maintenance (including engineering time for API upgrades).
A Solution Partner can select which setup a given client should use. We recommend that the majority of clients use the Cloud API for ease of implementation and maintenance. Solution Partners can also continue to maintain integration with the On-Premises API.
We want to make it clear what it means to message with a business on WhatsApp. Some businesses may choose to use Meta or another company to help them manage and store their messages. When a business chooses to manage their messages with another company, we will let consumers know by showing a different system message. Learn more.
We expect Cloud API to provide the same key features as the On-Premises API soon, including user change notifications and sticker pack management. Our goal is for the Cloud API to become the preferred platform for new features.
We will release updates monthly with new features and improvements. There is no work required to access these features - the Cloud API updates automatically.
Please view information about the sunset of the On-Premises API.
The Cloud API architecture significantly simplifies the Solution Partner's operational and infrastructure requirements to integrate with WhatsApp Business Platform. First, it removes the infrastructure requirements to run Business API docker containers (CAPEX savings). Second, it obviates the need of operational responsibilities to manage the deployment (OPEX savings). For details, refer to the architecture diagram comparing the On-Premises and Cloud API deployments.
Solution Partners and direct clients do not need the WebApp and CoreApp containers that are used in the On-Premises API. Meta will manage all database data and media data on behalf of the Solution Partner or direct client.
We will have disaster recovery and data replication across multiple regions. The expected downtime would be within our SLA and usually in the order of less than a minute to less than five minutes.
As your on-premises performance depends heavily on your hardware, software, and connectivity to WhatsApp servers, if you wish to understand these differences, you can perform your own load tests on Cloud API as you might have done for your own on-premises installation. You can also refer to our performance comparison to understand more details around how the on-premise and Cloud APIs compare.
云端 API 在 Meta 数据中心运行,除非公司自己选择使用云端 API 本次存储选项。Meta 在北美和欧盟设有数据中心。
消息静止数据会加密。这些数据会在 30 天后被自动删除。
和其他所有 WhatsApp Business API 解决方案合作伙伴一样,Meta 会代表公司管理加密和解密密钥。为了让公司能够通过云端 API 发送和接收消息,云端 API 会代表公司管理加密/解密密钥。Meta 负责运行云端 API,根据 Meta 条款的规定,云端 API 只能用于传递消息。WhatsApp 没有密钥和消息的访问权限。