PluginBench
Skill
Review
Audit score 70

weixin-agent-sdk

aradotso/trending-skills

Bridge any AI agent backend to WeChat via long-polling with a minimal Agent interface.

What is weixin-agent-sdk?

weixin-agent-sdk is a TypeScript framework that connects AI backends (OpenAI, Claude, or custom logic) to WeChat without requiring a public server. It uses long-polling to receive messages and exposes a simple Agent interface for handling text, images, audio, video, and files.

  • Receive and respond to WeChat messages (text, images, audio, video, files) via long-polling
  • Maintain multi-turn conversation history per user/conversation ID
  • Support OpenAI, Claude, or any custom AI backend logic
  • Handle media uploads and downloads with automatic encryption/decryption
  • Send responses with text and/or media (images, videos, files)
  • Built-in slash commands for debugging and echo testing

How to install weixin-agent-sdk

npx skills add https://github.com/aradotso/trending-skills --skill weixin-agent-sdk
Prerequisites
  • Node.js >= 22
  • WeChat account for QR code login (credentials persisted to ~/.openclaw/)
  • OpenAI API key (if using OpenAI backend)
  • Optional: silk-wasm for audio SILK-to-WAV conversion
Claude Code
Cursor
Windsurf
Cline

How to use weixin-agent-sdk

  1. 1.Install via npm: npm install weixin-agent-sdk
  2. 2.Run login() once to scan QR code and persist credentials
  3. 3.Implement the Agent interface with a chat() method
  4. 4.Call start(agent) to begin the message loop
  5. 5.Send messages in WeChat to test; use /echo or /toggle-debug for debugging

Use cases

Good for
  • Build a WeChat chatbot powered by OpenAI or Claude without a public server
  • Create a multi-turn conversational AI assistant that remembers chat history
  • Send images, videos, or files from your AI agent directly to WeChat users
  • Integrate an ACP-compatible agent (Claude Code, Codex, kimi-cli) with WeChat
  • Process voice messages and transcriptions from WeChat
Who it's for
  • AI/ML engineers building WeChat bots
  • Developers integrating OpenAI or Claude with WeChat
  • Teams needing a serverless WeChat chatbot solution
  • Anyone bridging existing AI agents to WeChat

weixin-agent-sdk FAQ

Do I need a public server to run this?

No. weixin-agent-sdk uses long-polling, so it works behind firewalls and NAT without exposing a public endpoint.

Can I use this with Claude or other AI backends?

Yes. The Agent interface is backend-agnostic. You can plug in OpenAI, Claude, or any custom logic. For ACP-compatible agents, use the weixin-acp package.

What happens if my session expires?

The SDK automatically enters a 1-hour cooldown and then reconnects. No manual intervention is needed.

Does it support media like images and videos?

Yes. It handles incoming images, audio, video, and files (auto-decrypted), and can send images, videos, and files in responses.

How do I debug message latency?

Send /toggle-debug in WeChat to append full latency stats to each reply, or use /echo to test channel latency directly.

Full instructions (SKILL.md)

Source of truth, from aradotso/trending-skills.


name: weixin-agent-sdk description: Bridge any AI agent backend to WeChat using the weixin-agent-sdk framework with simple Agent interface, login, and message loop. triggers:

  • connect my AI agent to WeChat
  • integrate OpenAI with WeChat bot
  • weixin agent sdk setup
  • how to build a WeChat AI chatbot
  • bridge Claude or GPT to WeChat
  • weixin-agent-sdk usage
  • ACP agent WeChat integration
  • set up WeChat message loop with custom agent

weixin-agent-sdk

Skill by ara.so — Daily 2026 Skills collection.

weixin-agent-sdk is a TypeScript framework that bridges any AI backend to WeChat (微信) via the Clawbot channel. It uses long-polling to receive messages — no public server required — and exposes a minimal Agent interface so you can plug in OpenAI, Claude, or any custom logic in minutes.


Installation

# npm
npm install weixin-agent-sdk

# pnpm (monorepo)
pnpm add weixin-agent-sdk

Node.js >= 22 required.


Quick Start

1. Login (scan QR code once)

import { login } from "weixin-agent-sdk";

await login();
// Credentials are persisted to ~/.openclaw/ — run once, then use start()

2. Implement the Agent interface

import { login, start, type Agent } from "weixin-agent-sdk";

const echo: Agent = {
  async chat(req) {
    return { text: `You said: ${req.text}` };
  },
};

await login();
await start(echo);

Core API

Agent Interface

interface Agent {
  chat(request: ChatRequest): Promise<ChatResponse>;
}

interface ChatRequest {
  conversationId: string;   // Unique user/conversation identifier
  text: string;             // Message text content
  media?: {
    type: "image" | "audio" | "video" | "file";
    filePath: string;       // Local path (already downloaded & decrypted)
    mimeType: string;
    fileName?: string;
  };
}

interface ChatResponse {
  text?: string;            // Markdown supported; auto-converted to plain text
  media?: {
    type: "image" | "video" | "file";
    url: string;            // Local path OR HTTPS URL (auto-downloaded)
    fileName?: string;
  };
}

login()

Triggers QR code scan and persists session to ~/.openclaw/. Only needs to run once.

start(agent)

Starts the message loop. Blocks until process exits. Automatically reconnects on session expiry.


Common Patterns

Multi-turn Conversation with History

import { login, start, type Agent } from "weixin-agent-sdk";

const conversations = new Map<string, string[]>();

const myAgent: Agent = {
  async chat(req) {
    const history = conversations.get(req.conversationId) ?? [];
    history.push(`user: ${req.text}`);

    const reply = await callMyAIService(history);

    history.push(`assistant: ${reply}`);
    conversations.set(req.conversationId, history);

    return { text: reply };
  },
};

await login();
await start(myAgent);

OpenAI Agent (Full Example)

import OpenAI from "openai";
import { login, start, type Agent, type ChatRequest } from "weixin-agent-sdk";
import * as fs from "fs";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: process.env.OPENAI_BASE_URL, // optional override
});

const model = process.env.OPENAI_MODEL ?? "gpt-4o";
const systemPrompt = process.env.SYSTEM_PROMPT ?? "You are a helpful assistant.";

type Message = OpenAI.Chat.ChatCompletionMessageParam;
const histories = new Map<string, Message[]>();

const openaiAgent: Agent = {
  async chat(req: ChatRequest) {
    const history = histories.get(req.conversationId) ?? [];

    // Build user message — support image input
    const content: OpenAI.Chat.ChatCompletionContentPart[] = [];

    if (req.text) {
      content.push({ type: "text", text: req.text });
    }

    if (req.media?.type === "image") {
      const imageData = fs.readFileSync(req.media.filePath).toString("base64");
      content.push({
        type: "image_url",
        image_url: {
          url: `data:${req.media.mimeType};base64,${imageData}`,
        },
      });
    }

    history.push({ role: "user", content });

    const response = await client.chat.completions.create({
      model,
      messages: [
        { role: "system", content: systemPrompt },
        ...history,
      ],
    });

    const reply = response.choices[0].message.content ?? "";
    history.push({ role: "assistant", content: reply });
    histories.set(req.conversationId, history);

    return { text: reply };
  },
};

await login();
await start(openaiAgent);

Send Image Response

const imageAgent: Agent = {
  async chat(req) {
    return {
      text: "Here is your image:",
      media: {
        type: "image",
        url: "/tmp/output.png",       // local path
        // or: url: "https://example.com/image.png"  — auto-downloaded
      },
    };
  },
};

Send File Response

const fileAgent: Agent = {
  async chat(req) {
    return {
      media: {
        type: "file",
        url: "/tmp/report.pdf",
        fileName: "monthly-report.pdf",
      },
    };
  },
};

ACP (Agent Client Protocol) Integration

If you have an ACP-compatible agent (Claude Code, Codex, kimi-cli, etc.), use the weixin-acp package — no code needed.

# Claude Code
npx weixin-acp claude-code

# Codex
npx weixin-acp codex

# Any ACP-compatible agent (e.g. kimi-cli)
npx weixin-acp start -- kimi acp

weixin-acp launches your agent as a subprocess and communicates via JSON-RPC over stdio.


Environment Variables (OpenAI Example)

VariableRequiredDescription
OPENAI_API_KEYYesOpenAI API key
OPENAI_BASE_URLNoCustom API base URL (OpenAI-compatible services)
OPENAI_MODELNoModel name, default gpt-5.4
SYSTEM_PROMPTNoSystem prompt for the assistant

Built-in Slash Commands

Send these in WeChat chat to control the bot:

CommandDescription
/echo <message>Echoes back directly (bypasses Agent), shows channel latency
/toggle-debugToggles debug mode — appends full latency stats to each reply

Supported Message Types

Incoming (WeChat → Agent)

Typemedia.typeNotes
Text—Plain text in request.text
ImageimageDownloaded & decrypted, filePath = local file
VoiceaudioSILK auto-converted to WAV (requires silk-wasm)
VideovideoDownloaded & decrypted
FilefileDownloaded & decrypted, original filename preserved
Quoted message—Quoted text appended to request.text, quoted media as media
Voice-to-text—WeChat transcription delivered as request.text

Outgoing (Agent → WeChat)

TypeUsage
TextReturn { text: "..." }
ImageReturn { media: { type: "image", url: "..." } }
VideoReturn { media: { type: "video", url: "..." } }
FileReturn { media: { type: "file", url: "...", fileName: "..." } }
Text + MediaReturn both text and media together
Remote imageSet url to an HTTPS link — SDK auto-downloads and uploads to WeChat CDN

Monorepo / pnpm Setup

git clone https://github.com/wong2/weixin-agent-sdk
cd weixin-agent-sdk
pnpm install

# Login (scan QR code)
pnpm run login -w packages/example-openai

# Start the OpenAI bot
OPENAI_API_KEY=$OPENAI_API_KEY pnpm run start -w packages/example-openai

Troubleshooting

Session expired (errcode -14) The SDK automatically enters a 1-hour cooldown and then reconnects. No manual intervention needed.

Audio not converting from SILK to WAV Install the optional dependency: npm install silk-wasm

Bot not receiving messages after restart State is persisted in ~/.openclaw/get_updates_buf. The bot resumes from the last position automatically.

Remote image URL not sending Ensure the URL is HTTPS and publicly accessible. The SDK downloads it before uploading to WeChat CDN.

login() QR code not appearing Ensure your terminal supports rendering QR codes, or check ~/.openclaw/ for the raw QR data.