Weixin

Community Weixin (WeChat) iLink bot adapter for Chat SDK. Calls the iLink bot HTTP JSON APIs directly, with long polling, QR login, media uploads, and typing indicators.

Community adapter. Not maintained by Vercel or Chat SDK contributors. For feature requests, bug reports, and support, file an issue on the adapter's repo.

Install

pnpm add chat-adapter-weixin chat @chat-adapter/state-memory

Quick start

The Weixin adapter requires a state adapter. It stores the long-polling cursor, per-user context tokens, dedupe markers, and thread history through Chat SDK's StateAdapter. Any state adapter works. The example uses @chat-adapter/state-memory; use Redis or Postgres in production.

lib/bot.ts
import { Chat } from "chat";
import { createMemoryState } from "@chat-adapter/state-memory";
import { createWeixinAdapter } from "chat-adapter-weixin";

const bot = new Chat({
  userName: "mybot",
  state: createMemoryState(),
  adapters: {
    weixin: createWeixinAdapter({
      accountId: process.env.WEIXIN_ACCOUNT_ID,
      token: process.env.WEIXIN_BOT_TOKEN,
    }),
  },
});

bot.onDirectMessage(async (thread, message) => {
  await thread.post(`You said: ${message.text}`);
});

await bot.initialize();

Weixin iLink bots are 1:1 only, so messages arrive through onDirectMessage. When called with no arguments, createWeixinAdapter() reads its credentials from environment variables.

QR login

The bundled CLI acquires accountId and token by scanning a QR code with the Weixin app. It does not replace your Chat SDK state storage.

weixin-chat-adapter login --env   # print as WEIXIN_ env vars
weixin-chat-adapter login --json  # print as JSON
weixin-chat-adapter login --save --state-dir ./.weixin-dev

Use --save only as a local-development convenience. In production, pass the resulting token through environment variables or your secret manager.

Configuration

All options are auto-detected from environment variables when not provided.

Prop

Type

Environment variables

VariableRequiredDescription
WEIXIN_ACCOUNT_IDYesiLink bot account ID. Obtain it via weixin-chat-adapter login.
WEIXIN_BOT_TOKENYesiLink bot token. Obtain it via weixin-chat-adapter login.
WEIXIN_BASE_URLNoiLink API base URL (default: https://ilinkai.weixin.qq.com).
WEIXIN_CDN_BASE_URLNoCDN base URL for media (default: https://novac2c.cdn.weixin.qq.com/c2c).
WEIXIN_BOT_USERNAMENoOverride the bot display name (default: weixin-bot).
WEIXIN_BOT_TYPENoiLink bot type (default: 3).
WEIXIN_ROUTE_TAGNoOptional routing tag forwarded to the iLink API.

Transport

Weixin has no inbound webhook, unlike most platform adapters. When you call bot.initialize(), the adapter opens a long-polling loop against the iLink getUpdates endpoint, and it tears the loop down on disconnect(). There is no /api/webhooks/weixin route to register.

Messages and media

The adapter strips all markdown formatting, including bold, italic, and code blocks, to plain text, because Weixin renders no formatting. It sends and receives images, files, voice, and video, and supports typing indicators. Per-user context tokens and dedupe markers persist through your StateAdapter.

Thread IDs

weixin:{base64url(accountId)}:{base64url(userId)}

Both segments are base64url-encoded so IDs stay delimiter-safe. Every thread is a 1:1 conversation between the bot account and a single user, so isDM() always returns true.

Limitations

  • iLink bots are 1:1 only, so there are no group chats. postChannelMessage and mentions don't apply.
  • The iLink bot API doesn't support editing or deleting messages. editMessage and deleteMessage throw NotImplementedError.
  • Reactions aren't supported. addReaction and removeReaction throw NotImplementedError.
  • The API doesn't expose message history, so fetchMessages returns an empty array.

Feature support

Messaging

FeatureSupported
Post message
Message replies
Edit message
Delete message
File uploads
Streaming
Scheduled messages

Rich content

FeatureSupported
Card format
Buttons
Link buttons
Select menus
Tables
Charts
Fields
Images in cards
Modals

Conversations

FeatureSupported
Slash commands
Mentions
Add reactions
Remove reactions
Typing indicator
Mark as read
Message edit events
Message delete events
DMs
Ephemeral messages
User lookup
Parent subject
Native client
Custom API endpointbaseUrl

Message history

FeatureSupported
Fetch messages
Fetch single message
Fetch thread info
Fetch channel messages
List threads
Fetch channel info
Post channel message

On this page