LangBot Docs

WeChat Official Account

Build a WeChat Official Account AI bot with LangBot. Connect LLMs to your WeChat public account.

Deploy WeChat Official Account bot to connect with LangBot.

LangBot WeChat Official Account Integration Modes

The current Official Account adapter supports three modes. Save the bot configuration after changing the mode. Existing bots keep their selected mode; the default remains drop. The legacy adapter does not offer auto.

ModeHow replies are delivered
autoReturns a loading message, processes the request in the background, then tries the customer service API. If restricted, queues the answer for retrieval with the next message.
passiveReturns a loading message and queues the answer. The user sends another message to retrieve it. Does not call the customer service API.
drop (default)Replies within the current callback. Suitable for replies completed within 5 seconds. Does not use the customer service API or fall back to retrieval.

How auto works

auto does not query the account's verification status in advance. When the processor sends its reply, LangBot calls the customer service API and uses the actual result:

  • Success: the user receives the answer without sending another message.
  • Permission denied (48001), expired reply window (45015), exhausted quota (45047), or recipient not following the account (43004): the answer is queued for retrieval with the next message.
  • Other failures, including credentials, IP whitelist and network errors: an error is recorded instead of treating the failure as a permission restriction.

This decision is made for each reply. An initial loading message does not mean the answer has been generated; check processor execution logs if no answer arrives.

Verification and reply windows

Callbacks require a response within 5 seconds, regardless of verification. drop uses this callback; WeChat retries do not provide a reliable 15-second generation window. See the official passive reply documentation.

Customer service messages can be sent after the callback ends. WeChat currently requires enterprise verification for Official Accounts and Service Accounts to use this API. Identity verification alone does not grant this permission; actual account permissions and API responses determine availability.

User actionCustomer service message quotaValidity
Sends a message5 messages48 hours
Clicks an eligible custom menu, follows the account, or scans a QR code3 messages1 minute

These are platform limits, not AI generation timeouts. Consult the official customer service API documentation for current rules.

Retrieving replies

In passive, or after auto falls back, the next message retrieves the previous answer and is not also processed as a new question. If the answer is still being generated, the loading message is returned again. Retrieve the answer before sending a new question.

LoadingMessage applies to both auto and passive, not drop. For auto, use wording such as “Processing your request. If no answer arrives, send any message later to retrieve it.” If empty, LangBot acknowledges the callback without a visible loading message.

Queued replies are stored in memory and cleared when LangBot restarts or the bot configuration is reloaded. All modes remain subject to WeChat content and message-length limits.

Route incoming messages to a processor. Reply modes do not automatically send every Agent text output: approve the reply-to-current-conversation tool and instruct the Agent to use it. Plugin processors must call the reply API.

Create Bot

Enter the WeChat Official Account Platform, if you already have an official account, scan the QR code to log in and enter the console. If you haven't registered an official account before, click Register Now, select Official Account, fill in the information in sequence, and enter the console. The console looks like this: Console Page

Set Callback Address

WeChat Official Account requires a public domain and HTTPS. If you don't have a server, LangBot Cloud includes built-in domain resolution — sign up and get started immediately.

Get Configuration Items

Click Settings and Development, Development Interface Management, and you'll see a page like this: Set Development Items

Record the Developer ID (AppID), Developer Password (AppSecret), and add the server where LangBot is deployed to the IP Whitelist.

Set Up Reverse Proxy for LangBot

Since WeChat Official Accounts only support http (port 80) and https (port 443), please follow the documentation Configure HTTP Reverse Proxy and SSL for configuration.

Save Callback Address

Click Set Server Configuration, enter Token, EncodingAESKey, and change the message encryption/decryption method to Safe Mode.

At this point, open the LangBot Webui page, create a new bot, and fill in the four configuration items obtained (AppID, AppSecret, token, EncodingAESKey)

Set Development Items

Select auto, passive, or drop in Mode using the comparison above. The default is drop.

The LoadingMessage option controls the loading message for auto and passive. Set enable to true.

After filling in successfully, on the LangBot homepage, enable and select the corresponding bot, click to enter the configuration page, copy the Webhook callback address, return to the WeChat Official Account bot configuration page, and fill it into URL. For example, if the URL is filled as https://your_domain_name/bots/xxxxx, where your_domain_name is the domain name filled in Caddy. Click Save. If it can be saved successfully, it means the deployment is successful. If you see System error, please try again later, please recheck whether the above configuration content is filled in correctly.

Custom menu shows "Custom menu not enabled" after enabling the callback

Once the server configuration (message push) is enabled, the Official Account runs in developer mode. WeChat then disables the custom menu edited in the web console and shows "Because the developer modified the menu configuration through the API, the current menu configuration has expired and been disabled" on the Custom Menu page. This is a WeChat platform rule; LangBot does not modify or delete your menu on its own.

To keep using LangBot, publish the menu again from LangBot (see Custom menu below). Disabling message push restores the web-edited menu, but LangBot will no longer receive messages from the account.

Custom menu

Bots using the new Official Account adapter have a Custom Menu tab on the bot detail page for editing and publishing the menu at the bottom of the Official Account chat:

  1. Make sure the bot is enabled and the LangBot server's outbound IP is in the account's API IP whitelist (shown in the bot's IP Whitelist field).
  2. Open the Custom Menu tab on the bot detail page. If you had a menu in the WeChat web console, click Import from WeChat to read the disabled menu back as it was; the imported menu is saved to LangBot right away.
  3. Click a button in Menu structure and change its name and tap action under Button settings. Top-level menus and sub-buttons are added, reordered with the arrows, and deleted in Menu structure. Click buttons in the phone preview to see what users get.
  4. Click Save and sync to WeChat. The menu is saved to LangBot and then replaces the whole menu on the account; users usually see it after a few minutes or after re-entering the account. While the bot is disabled or a button is incomplete, the menu is only saved to LangBot.

Custom menu editor: phone preview, menu structure and button settings

Up to 3 top-level buttons, each with up to 5 sub-buttons. Top-level names are limited to 16 bytes and sub-button names to 60 bytes (a Chinese character is about 3 bytes). Tap actions:

ActionEffect
Open web pageGoes to a URL.
Open mini programOpens a page of a linked mini program; older clients without mini program support open the fallback web page.
Reply with fixed textReplies with preset text right away, without calling the AI.
Let the AI replySends a preset message for the user; the current chat pipeline or Agent answers it.
Trigger event (advanced)Emits a platform.specific event (officialaccount.CLICK) whose data.EventKey is the button's event key. Add a binding in Event Routing filtered on data.EventKey to hand it to an Agent or plugin.

When you choose Trigger event (advanced), the button settings show an Event Routing filter you can copy:

Event key and routing filter of a trigger-event button

News, image, voice and video material buttons from the WeChat web console cannot be imported through the API. They are marked as an unsupported type after import and must be changed to another action before the menu can be synced to WeChat.

If syncing fails, the page shows the WeChat error code and an explanation. Common causes: the server outbound IP is not in the API IP whitelist (40164), the account has no custom menu API permission (48001, typical for unverified subscription accounts), or the mini program is not linked to the account (85005).

Plugins and Agents can also manage the menu through call_platform_api with menu.get, menu.import_console, menu.publish and menu.delete. The legacy adapter has no menu editor; switch to the new adapter to use it.

On this page