开发者设置:单一实例

本文档将向您介绍如何使用开发者机器设置 WhatsApp Business API 客户端的单一实例以进行测试。如要设置生产环境,请遵照生产环境设置中列出的相关说明。

如要从头开始设置单一实例,请查阅我们的要求列表,并按照以下步骤操作:

  1. 为设置脚本创建 biz 目录
  2. 获取 WhatsApp Business API 客户端配置文件
  3. 设置 WA_API_VERSION 环境变量
  4. 启动 WhatsApp Business API 客户端
  5. 验证容器是否正在运行
  6. 执行运行状况检查
  7. 注册 WhatsApp Business API 客户端

完成设置实例后,您可以选择对其进行升级。如要卸载客户端,请遵照这些步骤

准备工作

在创建之前,您需要完成以下步骤:

Install Docker Desktop

To install Docker Desktop on your developer machine:

  1. Navigate to the Docker website.
  2. If you do not have an existing Docker account, create one by clicking on Sign Up.
  3. After you have created your account, you will be directed to the Docker download page.
  4. Download Docker Desktop based on your OS (This should be automatically detected and presented as the default option).

The remaining steps are based on macOS and should be very similar for Linux or Windows 10.

To install Docker using macOS:

  1. Install the package (docker.dmg for macOS).
  2. After extraction, Finder will pop-up and you will be presented with a dialog that instructs you to drag the Docker icon to Applications. Drag Docker icon to the Application folder in Finder.
  3. In Applications launch Docker and then click the Open button.
  4. You may be prompted to enter your password Docker needs priviledged/administrator access.
  5. Docker will present you with a tutorial, you can click Start to launch a tutorial or you can click Skip Tutorial to start using Docker.

Verify Docker Compose is installed

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.

其他前提条件

务必在开发环境中设置本地测试帐户。其目的是快速开发和测试新版本。

WhatsApp Business API 客户端的初始设置

Perform the following steps to install a single instance of the WhatsApp Business API client on a developer system.

Step 1: Create ~/biz

Create a ~/biz directory for the WhatsApp Business API client.

Step 2: Get Config Files

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.

Step 3: Set the Version

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>)}

Step 4: Start the Client

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

Verify Containers Are Running

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

Status Check

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"
    }
}

Register Your Client

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.

Next Steps

升级 WhatsApp Business API 客户端

升级期间将会出现停机状况。

我们强烈建议您在升级前备份应用程序的当前设置,以确保可以快速恢复并运行。请遵循备份和还原文档进行操作。

我们建议您在时间充裕的情况下进行升级。

第 1 步:将 WA_API_VERSION 环境变量更改为新版本

请使用以下代码,将 WA_API_VERSION 环境变量更新为新版本编号:

export WA_API_VERSION=new-whatsapp-version

如果是升级至版本 2.33.4,则命令示例为:

~/biz $ export WA_API_VERSION=2.33.4

第 2 步:重启 Docker 容器

运行以下代码,重启 Docker 容器:

docker-compose up -d

所得输出结果应如下所示:

biz_db_1 is up-to-date
Recreating biz_wacore_1 ... done
Recreating biz_waweb_1  ... done

如果 MySQL 数据库用户已升级到 v2.23.x 和更高版本

您现在可使用数据库升级服务,在应用程序运行时升级数据库,从而避免停机。

第 1 步:下载配置文件

dbupgrade-compose.yml 文件包含用于指明容器版本的字段。

示例:

services:
  dbupgrade:
    image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:-2.21.3}

第 2 步:启动容器

如要升级安装程序,请启动 dbupgrade-service 容器,并将 WA_API_VERSION 环境变量设为最新版本:

WA_API_VERSION=new-whatsapp-version docker-compose -f dbupgrade-compose.yml up -d

注意:无论退出代码为何,如果您使用的编排程序会在退出时重启容器,则请将 EXIT_ON_SUCCESS 环境变量设为 FALSE 并启动服务,以避免在退出代码为 0 时退出容器。

第 3 步:静候升级完成

如果数据库升级成功,则容器会退出,且退出代码为 0。您可使用以下 Docker 命令来追踪状态:

docker wait your-database-upgrade-container-name

此命令会输出 dbupgrade-service 容器的退出代码。

第 4 步:重启核心应用和网页应用容器

WA_API_VERSION 环境变量设为最新版本,然后重启核心应用和网页应用 Docker 容器:

WA_API_VERSION=new-whatsapp-version docker-compose up -d

卸载 WhatsApp Business API 客户端

强烈建议您在卸载前备份应用程序的当前设置。请遵循备份和还原文档进行操作。

如果您需要通过移除所有容器来重置开发环境,请从包含 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

如要收集特定服务的记录,请将服务名称(wawebwacore)附加至 docker-compose logs 命令中:

docker-compose logs waweb > debug_output.txt

您可以在当前目录的 debug_output.txt 文件中找到相应记录。


此软件使用受 LGPLv2.1 许可证保护的 FFmpeg 代码,点击此处即可下载源代码。