> ## Documentation Index
> Fetch the complete documentation index at: https://kiro.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# WeChat (Weixin)

> Connect Crew to personal WeChat (微信) through iLink. QR-scan sign-in from the dashboard, no public URL needed.

Connect Crew to **personal WeChat** (微信) through Tencent's iLink bot API. Sign-in is a QR scan from the dashboard; messages arrive over HTTP long-poll, so no public endpoint, webhook, or tunnel is required.

**⚠️ Warning:** **This is not WeCom.** For enterprise WeChat (企业微信), use the [WeCom channel](https://kiro.dev/docs/crew/interfaces/wecom.md) instead — it uses an official WebSocket bot gateway. This page covers *personal* WeChat via iLink.

## Risks — read before enabling

- **Unofficial surface.** The iLink bot API is not a published Tencent developer product. Behavior can change without notice, and using a personal account as a bot may violate WeChat's terms of service. Accounts can be limited or banned.
- **DM only.** The iLink bot identity generally does not receive group events. Group chat is unsupported.
- **One poller per credential.** Only a single gateway may long-poll a given bot credential at a time.

Prefer WeCom for anything business-critical.

## Setup

### From the dashboard (recommended)

1. Open **Settings → Messaging Channels → WeChat** in the dashboard
2. Click **Connect via QR**
3. Scan the code with the WeChat mobile app and confirm on your phone
4. Restart the gateway — the status pill turns **Connected**

The bot credential is written server-side (into the credential store, never returned to the browser). Only the non-secret account ID and connection status are exposed to the dashboard.

### From the CLI

The QR flow requires the dashboard UI — there's no CLI-only path for the initial sign-in. After connecting via the dashboard, manage settings in `config.json`:

```json
{
  "weixin": {
    "enabled": true,
    "dm_policy": "allowlist",
    "allowed_user_ids": ["user-id-from-log"]
  }
}
```

Then: `kirocrew restart`

## Access policy

`Who can message the bot` maps to `weixin.dm_policy`:

| Value | Behavior |
|---|---|
| `allowlist` (default) | Only user IDs in `weixin.allowed_user_ids` |
| `open` | Anyone who messages the bot |
| `disabled` | All messages ignored |

The default is **`allowlist` with an empty list, which authorizes nobody** — a freshly connected bot ignores every DM until you add an ID. To collect a user ID, have the person DM the bot once and read the ID from the gateway log.

## Commands

| Command | Effect |
|---|---|
| `/new` (or `新对话`, `清空`) | Start a fresh session |
| `/compact` | Compact session context in place |

Context is managed automatically: at `soft_threshold_pct` (80%) the bot suggests `/compact` or `/new`; at `hard_threshold_pct` (95%) it compacts on its own.

## Behavior notes

- **One reply per turn** — iLink cannot edit a sent message, so the answer is buffered and delivered when the turn completes (not streamed). The native "typing…" indicator runs for the duration.
- **Markdown is preserved** — iLink clients render it. Replies longer than 4000 characters split at paragraph/code-fence boundaries.
- **Tool calls and reasoning are not echoed** to the chat (they would each become a separate bubble).
- **No approval buttons** — iLink has no interactive controls. In `interactive` mode, tools needing approval are denied by default. Use `auto` or `trust` mode, or approve from the dashboard.
- **Text only** — media (images, voice, files) is not supported yet.

## Configuration

Set under `weixin` in `config.json` (or via the Settings panel):

| Key | Default | Purpose |
|---|---|---|
| `weixin.enabled` | `false` | Enable the channel |
| `weixin.account_id` | — | iLink bot account ID (from QR login) |
| `weixin.base_url` | `https://ilinkai.weixin.qq.com` | iLink API base URL |
| `weixin.dm_policy` | `allowlist` | `allowlist` / `open` / `disabled` |
| `weixin.allowed_user_ids` | `[]` | Permitted user IDs when `allowlist` |
| `weixin.soft_threshold_pct` | `80` | Suggest compaction past this usage |
| `weixin.hard_threshold_pct` | `95` | Force compaction past this |

The credential is read from the `WEIXIN_TOKEN` credential (env / `.env` / credential store).

## Troubleshooting

| Problem | Fix |
|---|---|
| Status stuck on "Signed in — restart to connect" | Restart the gateway; credentials are read once at boot |
| `errcode -14` in the log | Session expired — re-run the QR sign-in |
| `errcode -2` | iLink rate limit; the poller backs off automatically |
| Bot ignores DMs | Check `dm_policy` — under `allowlist` the sender must be listed |
| Group messages ignored | Expected: iLink bot identities do not receive group events |
| Images / voice / files ignored | Expected: text only for now |
| Startup error about `aiohttp` | Install the messaging extra |
