開發人員設定:單一實例

本文件將為您講解如何使用開發人員機器設定 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 檔案中定義的所有磁碟區,請運行 down 指令及 -v 參數:

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 程式碼,您可在此處下載其原始碼。