Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ on:

jobs:
build:
permissions:
contents: read
strategy:
matrix:
os:
Expand Down
18 changes: 18 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"default": true,
"no-trailing-punctuation": {
"punctuation": ".,;:!"
},
"MD013": false,
"MD033": {
"allowed_elements": ["dl", "dt", "dd", "code", "var", "cite", "div", "a", "img"]
},
"MD055": false,
"MD059": false,
"MD060": false,
"first-line-h1": false,
"no-hard-tabs": true,
"no-trailing-spaces": {
"br_spaces": 2
}
}
15 changes: 15 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Instructions for coding agents

- This repository is ESM-only (`"type": "module"`) and targets Node.js 26+ and npm 10+ via `engines`. Do not add `package-lock.json` (see `DEVELOPMENT.md`).
- Node.js runs `.ts` sources directly with built-in type stripping; compilation to `dist/` happens only via `npm run build`.
- Relative imports must end in `.ts`, type-only imports must use `import type` or inline `type` modifiers (`verbatimModuleSyntax`), and only erasable TypeScript syntax is allowed (`erasableSyntaxOnly`: no enums, value namespaces, or constructor parameter properties).
- Prefer WinterTC web-standard APIs (`fetch`, `URL`, `URLSearchParams`, `AbortController`, `EventTarget`) over Node-only legacy packages when writing or updating examples and tests.
- Write portable smoke tests using `node:test` and `node:assert/strict` in `tests/*.test.ts`. Register `t.after()` cleanup before starting bots.
- Keep `npm run lint` (`lint:biome`, `lint:ts`, `lint:md`), `npm run build`, and `npm test` passing.
- Reference GitHub Actions by version tags (for example, `@v7`), not commit hashes.

### Source Code Documentation (AI-First)

- Begin each source and test file with a concise header comment explaining why it exists and what it owns.
- Document exported functions and nontrivial helpers with TSDoc-compatible `/** ... */` comments.
- Keep documentation accurate and concise; update comments whenever code changes.
19 changes: 9 additions & 10 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# DEVELOPMENT

This repository is the Wechaty getting-started tutorial. Its toolchain follows
[wechaty/wechaty](https://github.com/wechaty/wechaty) 2.0. The bot examples stay
on the Wechaty 1.x API (`wechaty` `^1.20.2`).
This repository is the Wechaty getting-started tutorial. Its toolchain and
starter bots follow [wechaty/wechaty](https://github.com/wechaty/wechaty) 2.0
(`wechaty` `>=2.0.0-0 <3`). `examples/cqrs` is kept for a future Wechaty 2
upgrade and is excluded from the root `tsconfig.json`.

## Node, TypeScript, and modules

Expand All @@ -28,9 +29,7 @@ TypeScript's semantic check remains required. Type stripping does not check
types, so a file that Node.js can execute is not a substitute for
`npm run lint:ts`. Deno runs with `--no-check` for the same reason.

`examples/third-parties/maodou` and `examples/third-parties/xiaoli` keep their
own `package.json` and their own dependencies. Root `npm install` does not
install those modules, and root `tsc` does not include them.
`examples/cqrs` is excluded from `tsconfig.json` until its Wechaty 2 upgrade.

## Why `package-lock.json` is not committed

Expand All @@ -47,10 +46,10 @@ off, because there is no lockfile to cache from.

## Tests

Smoke tests use `node:test` and `node:assert/strict`. `npm test` lints, then
runs `tests/*.test.ts` with Node.js directly. The runner uses
`--test-force-exit` because a puppet can leave sockets open after `bot.stop()`,
and `--test-timeout=180000` because a scan can take up to two minutes.
Smoke tests use `node:test` and `node:assert/strict`, registering `t.after()`
cleanup before starting bots. `npm test` lints (`lint:biome`, `lint:ts`,
`lint:md`), then runs `tests/*.test.ts` with Node.js directly. The runner uses
`--test-timeout=180000` because a scan can take up to two minutes.

The same suite has an experimental Deno 2.9.8 job,
`npm run test:unit:deno`. Deno is not a supported runtime yet. That CI job
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This repository tracks Wechaty 2. It needs Node.js 26 or newer and TypeScript 7.
### Wechaty Getting Started video tutorial

<div align="center">
<a target="_blank" href="https://youtu.be/GdmikkU4ZfM?si=cpsuh7RyQjtgLE5F"><img src="docs/images/video-tutorial-img.webp" border=0 width="60%"></a>
<a target="_blank" href="https://youtu.be/GdmikkU4ZfM?si=cpsuh7RyQjtgLE5F"><img src="docs/images/video-tutorial-img.webp" alt="Wechaty Getting Started video tutorial" border=0 width="60%"></a>
</div>

Above is a short run-through of the ding-dong bot.
Expand Down Expand Up @@ -106,7 +106,7 @@ You are all set!

#### Step 4: Troubleshooting

If you run into problems while following the above steps, check the items below. You are also welcome to ask questions in our [gitter chatroom](https://gitter.im/wechaty/wechaty).
If you run into problems while following the above steps, check the items below. You are also welcome to ask questions in our [Discord community](https://discord.gg/7q8NBZbQzt).

1. `node -v` is v26 or newer, and `npm -v` is 10 or newer.
1. On Linux, `ldd --version` reports glibc 2.38 or newer.
Expand Down Expand Up @@ -137,7 +137,7 @@ Learn more about installing Wechaty on windows from this [blog post](https://wec
### 1. Wechaty Tutorial

<div align="center">
<a target="_blank" href="https://wechaty.js.org/2017/01/01/getting-started-wechaty/"><img src="https://cloud.githubusercontent.com/assets/1361891/21722581/3ec957d0-d468-11e6-8888-a91c236e0ba2.jpg" border=0 width="60%"></a>
<a target="_blank" href="https://wechaty.js.org/2017/01/01/getting-started-wechaty/"><img src="https://cloud.githubusercontent.com/assets/1361891/21722581/3ec957d0-d468-11e6-8888-a91c236e0ba2.jpg" alt="Wechaty 10 minute video tutorial" border=0 width="60%"></a>
</div>

Above is a 10 minute video tutorial. It is using version 0.14 or older versions of Wechaty therefore it is also outdated. It is a good way to start if you are new to Wechaty.
Expand All @@ -146,9 +146,19 @@ Above is a 10 minute video tutorial. It is using version 0.14 or older versions

> Note: Before you attempt more examples, make sure you have tried out the wechaty getting started project in this repository.

- [Official Wechaty Examples Directory](https://github.com/wechaty/getting-started/tree/master/examples)
- [Official Wechaty Examples Directory](https://github.com/wechaty/getting-started/tree/main/examples)

The files under `examples/` other than the two starter bots are v1-era samples. The root package does not install them.
`examples/cqrs/` is kept for a future Wechaty 2 upgrade and is excluded from the root TypeScript check.

#### Verification

Run linting, TypeScript checks, and smoke tests locally:

```sh
npm run lint
npm test
npm run test:unit:deno
```

## API REFERENCE

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.6.8/schema.json",
"$schema": "https://biomejs.dev/schemas/2.6.9/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
Expand Down
69 changes: 16 additions & 53 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,23 @@
# WECHATY OFFICIAL EXAMPLES LIST DIRECTORY
# Wechaty Official Examples Directory

The `wechaty-getting-started/examples` directory is provided for people who want to learn coding wechaty, for them to get an easier start. If you start coding wechaty for the first time, we highly recommend to start with the [ding-dong-bot.ts](basic/ding-dong-bot.ts), the best starter template for you.
The `examples/` directory provides starter bots for learning Wechaty 2 with Node.js 26 and TypeScript 7. If you are new to Wechaty, start with [ding-dong-bot.ts](ding-dong-bot.ts).

The starter bots, [ding-dong-bot.ts](ding-dong-bot.ts) and [ding-dong-bot.js](basic/ding-dong-bot.js), run on Wechaty 2 with Puppet Neo. The other files in this directory are v1-era samples. The root `package.json` does not install them.
## Starter & Basic Examples

| Filename | Description | 描述 |
| --- | --- | --- |
| ding-dong-bot.ts | The Best Starter Template for You | |
| Filename | Description |
| --- | --- |
| [ding-dong-bot.ts](ding-dong-bot.ts) | Recommended starter template using `PuppetNeo` |
| [basic/ding-dong-bot.ts](basic/ding-dong-bot.ts) | Basic ding-dong bot with `PuppetNeo` |
| [basic/the-worlds-shortest-chatbot-code-in-6-lines.ts](basic/the-worlds-shortest-chatbot-code-in-6-lines.ts) | Minimal 6-line Wechaty chatbot example |

Moreover,
## CQRS (Pending Upgrade)

- All the other examples have been carefully arranged into different categories so as to better guide you for what to choose/see, as you move along.
- In order to keep things simple, we just put the examples in the subdirectory of the examples/ directory, so that they each can just run out-of-the-box.
- We also recommend that you at least read through them all, before starting coding, for a even better, smoother ride.
- More demos are welcome. If you have anything interesting to add, please don't hesitate to reach out to us.
| Filename | Description |
| --- | --- |
| [cqrs/ding-dong-bot.ts](cqrs/ding-dong-bot.ts) | CQRS ding-dong bot example (excluded from root `tsconfig.json` pending Wechaty 2 upgrade) |

## 1. BASIC
## Tutorials

Wechaty Basic Functions (demos under the `basic/` directory)

| FileName | Description | 描述 |
| --- | --- | --- |
| the-worlds-shortest-chatbot-code-in-6-lines.ts | The very first wechaty example showcasing how easy it is to get started | |
| ding-dong-bot.ts | Practical example illustrates on how to do message handling | |
| contact-bot.ts | List all contacts by Wechat ID & Name | 在终端下输出微信号下所有联系的人微信ID和昵称。|

## 2. ADVANCED

Wechaty Advanced Functions (demos under the `advanced/` directory)

| FileName | Description | 描述 |
| --- | --- | --- |
| demo-in-tutorial.ts | the demo bot from the tutorial | |
| busy-bot.ts | auto response "busy" message for you when you are | |
| media-file-bot.ts | Save Media Attachment in Message to local files | 将消息中的文件、图片、视频等非文本信息存到本地。 |
| room-bot.ts,room-say-cli.ts | Practical example illustrates on how to do room handling | |
| friend-bot.ts | Practical example illustrates on how to do friend handling | |
| gist-bot/ | Best template for bigger modules, with each handler in separated files | |

## 3. PROFESSIONAL

Wechaty Integrated with Other Modules/Services (demos under the `professional/` directory)

| FileName | Description | 描述 |
| --- | --- | --- |
| ctrl-c-signal-bot.ts | Ctrl-C signal handling demo | |
| api-ai-bot.ts | Wechaty bot that uses ApiAi.com brain | |
| speech-to-text-bot.ts | bot that uses baidu speech (vop.baidu.com) | |
| tuling123-bot.ts | Connect to [tuling123](http://www.tuling123.com/) chatbot | 接入[tuling123机器人](http://www.tuling123.com/) |
| telegram-roger-bot.ts | single bot that runs under/for both Telegram and WeChaty | |
| blessed-twins-bot/ | Wechaty multi-instance support (v0.16+) demo | |

## Multi-lang Wechaty Examples Directories

1. Python: <https://github.com/wechaty/python-wechaty-getting-started/tree/master/examples>
1. Java: <https://github.com/wechaty/java-wechaty-getting-started/examples/>
1. Go: <https://github.com/wechaty/go-wechaty-getting-started/examples/>

I hope you will enjoy them, cheers!
| Filename | Description |
| --- | --- |
| [tutorials/google-cloud-shell-tutorial.md](tutorials/google-cloud-shell-tutorial.md) | Interactive Google Cloud Shell walkthrough |
176 changes: 0 additions & 176 deletions examples/advanced/busy-bot.ts

This file was deleted.

Loading
Loading