Examples
The repository includes small examples that you can run and modify.
Available examples
| Example | What it shows | Command |
|---|---|---|
basic | QR login, session persistence, echo replies | pnpm example |
commands | Simple command handling | pnpm example:commands |
media | sendFile() and sendImage() | pnpm example:media |
ai-chat | DeepSeek chat bot with per-user context | pnpm example:ai-chat |
Run from the repository root
bash
git clone https://github.com/YunYouJun/weixin-ts.git
cd weixin-ts
pnpm install
pnpm exampleUse another script to run a different example:
bash
pnpm example:commands
pnpm example:media
pnpm example:ai-chatRun from an example directory
bash
pnpm -C examples/basic startFor watch mode:
bash
pnpm -C examples/basic devLogin
By default, examples show a QR code in the terminal. Scan it with WeChat and confirm login.
If you already have a bot token, set WEIXIN_BOT_TOKEN to skip QR login:
bash
WEIXIN_BOT_TOKEN=your-token pnpm exampleExamples may save .weixin-bot.session.json to reuse the session. Delete it if the session expires or you want to scan again.
AI chat setup
The AI example needs a DeepSeek API key:
bash
cd examples/ai-chat
cp .env.example .env
# edit .env and set DEEPSEEK_API_KEY
pnpm startDo not commit .env or session files.