Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Weixin Agent Sdk

ASecurity

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

81 stars
0 votes
0 copies
0 views
Added 9/19/2026
ai-agentstypescriptgobashnodegitapibackend

Works with

claude codeterminalcliapi

Security Analysis

A92/100
mediumInstalls packages at runtime which could introduce malicious dependencies
mediumInstalls packages at runtime which could introduce malicious dependencies

Scanned 9/19/2026

Install to Claude Code

$npx -y skills add reason-machines/trending-skills --skill weixin-agent-sdk --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Weixin Agent Sdk?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Weixin Agent Sdk
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/reason-machines-weixin-agent-sdk/badge)](https://www.skillsdirectory.com/skills/reason-machines-weixin-agent-sdk)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
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](https://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

```bash
# 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)

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

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

### 2. Implement the Agent interface

```typescript
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

```typescript
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

```typescript
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)

```typescript
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

```typescript
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

```typescript
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.

```bash
# 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)

| Variable | Required | Description |
|---|---|---|
| `OPENAI_API_KEY` | Yes | OpenAI API key |
| `OPENAI_BASE_URL` | No | Custom API base URL (OpenAI-compatible services) |
| `OPENAI_MODEL` | No | Model name, default `gpt-5.4` |
| `SYSTEM_PROMPT` | No | System prompt for the assistant |

---

## Built-in Slash Commands

Send these in WeChat chat to control the bot:

| Command | Description |
|---|---|
| `/echo <message>` | Echoes back directly (bypasses Agent), shows channel latency |
| `/toggle-debug` | Toggles debug mode — appends full latency stats to each reply |

---

## Supported Message Types

### Incoming (WeChat → Agent)

| Type | `media.type` | Notes |
|---|---|---|
| Text | — | Plain text in `request.text` |
| Image | `image` | Downloaded & decrypted, `filePath` = local file |
| Voice | `audio` | SILK auto-converted to WAV (requires `silk-wasm`) |
| Video | `video` | Downloaded & decrypted |
| File | `file` | Downloaded & 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)

| Type | Usage |
|---|---|
| Text | Return `{ text: "..." }` |
| Image | Return `{ media: { type: "image", url: "..." } }` |
| Video | Return `{ media: { type: "video", url: "..." } }` |
| File | Return `{ media: { type: "file", url: "...", fileName: "..." } }` |
| Text + Media | Return both `text` and `media` together |
| Remote image | Set `url` to an HTTPS link — SDK auto-downloads and uploads to WeChat CDN |

---

## Monorepo / pnpm Setup

```bash
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.

Attribution

reason-machinesreason-machines
View sourceMore from reason-machines →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.

1023331 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

686011 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3331 votes

catchup

Recovers prior coding-agent session context by running `catchup <agent> --since-compact`, which extracts a clean summary of a previous Codex, Claude Code, Antigravity, OpenCode, or Pi Agent session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", or asks to recover/summarize a previous session before continuing. Do NOT use for the current conversation, git history, or any non-agent log.

611 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →