@yaonyan/chat-adapter-weixin
v0.1.1
Published
WeChat (企业微信/iLink) adapter for the chat SDK
Readme
@yaonyan/chat-adapter-weixin
WeChat (微信/iLink) adapter for the chat SDK.
Installation
pnpm add @yaonyan/chat-adapter-weixin chatUsage
import { Chat } from "chat";
import { createWeixinAdapter } from "@yaonyan/chat-adapter-weixin";
import { createMemoryState } from "@chat-adapter/state-memory";
const adapter = createWeixinAdapter({
baseUrl: "https://ilink.weixin.qq.com/",
token: process.env.WEIXIN_BOT_TOKEN,
botUserId: process.env.WEIXIN_BOT_USER_ID,
});
const bot = new Chat({
userName: "my-bot",
adapters: { weixin: adapter },
state: createMemoryState(),
});
bot.onNewMention(async (thread, message) => {
await thread.post(`You said: ${message.text}`);
});Environment Variables
| Variable | Description |
|---|---|
| WEIXIN_BASE_URL | iLink API base URL (default: https://ilink.weixin.qq.com/) |
| WEIXIN_BOT_TOKEN | Bot bearer token |
| WEIXIN_BOT_USER_ID | Bot's own WeChat user ID (for isMe detection) |
How It Works
- Uses long-poll (
POST /ilink/bot/getupdates) to receive messages — no webhook server required. - All WeChat conversations are DMs; every inbound message triggers
onNewMention. - Replies include the
context_tokenfrom the triggering message (required by the WeChat API). - Thread ID format:
weixin:{userId}(e.g.weixin:[email protected]).
Limitations
- Text messages only in v0.1. Media (image/video/voice/file) attachment sending is not yet supported.
- No server-side message history API; message history is persisted locally via the
chatSDK'sThreadHistoryCache.
