# Connect AstrBot to WeChat Official Account Platform

AstrBot supports WeChat Official Account integration (version >= v3.5.8). After setup, you can chat with AstrBot directly in the WeChat Official Account chat interface.

## Before You Start

1. Open AstrBot Dashboard.
2. Click `Bots` in the left sidebar.
3. Click `+ Create Bot`.
4. Select `weixin_official_account`.

A configuration dialog will appear. Keep it open and continue.

## Create / Sign In to WeChat Official Account Platform

Open [WeChat Official Account Platform](https://mp.weixin.qq.com/).

- If you already have an account, sign in.
- If not, register a new account and choose `Official Account`.

> [!NOTE]
> A newly registered account may require 1-2 days for review before it can be used.

## Configure Callback Service

Open `Settings & Development` -> `Development Interface Management`.

![Development Interface Management](https://files.astrbot.app/docs/source/images/weixin-official-account/image.png)

Copy AppID and AppSecret from WeChat platform to AstrBot fields `appid` and `secret`.

Open IP whitelist and add your public IP(s), one per line if multiple.

In server configuration, click modify.

- `Token`: create any string with length 3-32, and fill the same value in AstrBot `token`.
- `EncodingAESKey`: click random generate and fill AstrBot `encoding_aes_key`.

Keep `Unified Webhook Mode (unified_webhook_mode)` enabled (recommended), then save AstrBot config and wait for restart.

For `URL`:

- If unified mode is enabled, use the unique callback URL generated by AstrBot (from logs or bot card).
- If unified mode is disabled, use `http://<your-domain>/callback/command`.

![unified_webhook](https://files.astrbot.app/docs/source/images/use/unified-webhook.png)

> [!NOTE]
> WeChat Official Account callback supports only ports 80 or 443. You usually need a domain and reverse proxy:
> - Unified mode enabled: forward to AstrBot port `6185`
> - Unified mode disabled: forward to adapter port `6194`

Set message encryption mode to `Security Mode`.

Wait a moment and click `Submit`. If configuration is correct, you will see success.

## Test

In WeChat Official Account platform, open account profile and find your QR code.

Scan it with WeChat, send `help`, and check whether AstrBot replies.

If it replies, integration is successful.

> [!NOTE]
> If console shows `ip xxxxx not in whitelist`, your public IP is not in WeChat whitelist yet. Add it and wait a few minutes for WeChat to refresh.

## Reverse Proxy (Custom API Base)

AstrBot supports custom endpoint via `api_base_url` for environments without stable public IP.

## Voice Input

Install `ffmpeg` for voice input support.

- Linux: `apt install ffmpeg`
- Windows: download from [FFmpeg website](https://ffmpeg.org/download.html)
- macOS: `brew install ffmpeg`
