本文档将向您介绍如何使用开发者机器设置 WhatsApp Business API 客户端的单一实例以进行测试。如要设置生产环境,请遵照生产环境设置中列出的相关说明。
如要从头开始设置单一实例,请查阅我们的要求列表,并按照以下步骤操作:
在创建之前,您需要完成以下步骤:
To install Docker Desktop on your developer machine:
The remaining steps are based on macOS and should be very similar for Linux or Windows 10.
To install Docker using macOS:
Docker Compose is a plugin that is bundled with Docker Desktop and should have installed automatically. For more information about using or Docker Compose, see Overview of Docker Compose. If for some reason Docker Compose was not installed, you can install it by following the instructions located at Install Docker Compose.
务必在开发环境中设置本地测试帐户。其目的是快速开发和测试新版本。
Perform the following steps to install a single instance of the WhatsApp Business API client on a developer system.
Create a ~/biz
directory for the WhatsApp Business API client.
Clone the WhatsApp Business API Client docker-compose.yml
and db.env
configuration files from the WhatsApp GitHub repository for either a
MySQL database setup or a Postgres database setup to your ~/biz
directory.
The WA_API_VERSION
environmental variable should be set to the current version.
~/biz $ export WA_API_VERSION=CURRENT-WA-API-VERSION
To find the current version of the API that you installed, open docker-compose.yml
and search for "WA_API_VERSION=
". The version number should be noted by a developer in the wacore
label:
wacore: image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.31.4 docker-compose <command> <options>)}
To start the WhatsApp Business API client, run:
~/biz $ docker-compose up -d
The resulting output should look like the following:
Creating volume "biz_whatsappMedia" with local driver Creating volume "biz_mysqlData" with local driver Creating biz_db_1 ... done Creating biz_wacore_1 ... done Creating biz_waweb_1 ... done
You can check that all containers have an UP state by running:
~/biz $ docker-compose ps
By default, the Webapp container will be running on port 9090
(https://localhost:9090
) and the database container will be running on port 33060
(https://localhost:33060
).
The resulting output should look like the following:
~/biz $ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------- biz_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:33060->3306/tcp, 33060/tcp biz_wacore_1 /opt/whatsapp/bin/wait_on_ ... Up 6250/tcp, 6251/tcp, 6252/tcp, 6253/tcp biz_waweb_1 /opt/whatsapp/bin/wait_on_ ... Up 0.0.0.0:9090->443/tcp
Send a GET
request to /v1/health
endpoint to check the status of your client.
On success, you will see the following:
{ "health": { "gateway_status": "unregistered" } }
To register your WhatsApp Business API client, send a POST
request to the /v1/account
endpoint.
Upon registration gateway_status
will be set connected
. Your Coreapp container is able to connect to the WhatsApp server for checking contacts and sending messages.
WA_API_VERSION
环境变量更改为新版本请使用以下代码,将 WA_API_VERSION
环境变量更新为新版本编号:
export WA_API_VERSION=new-whatsapp-version
如果是升级至版本 2.33.4,则命令示例为:
~/biz $ export WA_API_VERSION=2.33.4
运行以下代码,重启 Docker 容器:
docker-compose up -d
所得输出结果应如下所示:
biz_db_1 is up-to-date Recreating biz_wacore_1 ... done Recreating biz_waweb_1 ... done
v2.23.x
和更高版本您现在可使用数据库升级服务,在应用程序运行时升级数据库,从而避免停机。
dbupgrade-compose.yml 文件包含用于指明容器版本的字段。
示例:
services: dbupgrade: image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:-2.21.3}
如要升级安装程序,请启动 dbupgrade-service 容器,并将 WA_API_VERSION
环境变量设为最新版本:
WA_API_VERSION=new-whatsapp-version docker-compose -f dbupgrade-compose.yml up -d
注意:无论退出代码为何,如果您使用的编排程序会在退出时重启容器,则请将 EXIT_ON_SUCCESS
环境变量设为 FALSE
并启动服务,以避免在退出代码为 0
时退出容器。
如果数据库升级成功,则容器会退出,且退出代码为 0
。您可使用以下 Docker 命令来追踪状态:
docker wait your-database-upgrade-container-name
此命令会输出 dbupgrade-service 容器的退出代码。
将 WA_API_VERSION
环境变量设为最新版本,然后重启核心应用和网页应用 Docker 容器:
WA_API_VERSION=new-whatsapp-version docker-compose up -d
强烈建议您在卸载前备份应用程序的当前设置。请遵循备份和还原文档进行操作。
如果您需要通过移除所有容器来重置开发环境,请从包含 docker-compose.yml
文件的目录中运行以下命令:
WA_API_VERSION={VERSION_NUMBER} docker-compose down
所得输出结果应如下所示:
Stopping biz_waweb_1 ... done Stopping biz_wacore_1 ... done Stopping biz_db_1 ... done Removing biz_waweb_1 ... done Removing biz_wacore_1 ... done Removing biz_db_1 ... done
除容器之外,如还要移除 docker-compose.yml
文件中定义的所有卷,请使用 -v
参数运行 down
命令:
WA_API_VERSION={VERSION_NUMBER} docker-compose down -v
建议使用 WADebug,以便更有效地解决问题。WADebug 是一个命令行工具,可助您找到 WhatsApp Business API 设置中的任何潜在问题,并让您更有效地向 WhatsApp 支持团队请求帮助。
在无法使用 WADebug 或运行工具返回错误的情况下,如要从所有容器中收集记录,请运行以下命令:
docker-compose logs > debug_output.txt
如要收集特定服务的记录,请将服务名称(waweb
或 wacore
)附加至 docker-compose logs
命令中:
docker-compose logs waweb > debug_output.txt
您可以在当前目录的 debug_output.txt
文件中找到相应记录。