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