Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 27e45cf

Browse files
authored
Feat issue166 (#169)
2 parents 6447c45 + 5ffac0b commit 27e45cf

File tree

8 files changed

+102
-82
lines changed

8 files changed

+102
-82
lines changed

README.md

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,73 @@
66
<a href="https://discord.gg/qBF9VsBdc8"><img src="https://img.shields.io/discord/1165844612473172088?logo=Discord&link=https%3A%2F%2Fdiscord.gg%qBF9VsBdc8" /></a>
77

88

9-
[🚢 Docker 镜像](https://hub.docker.com/repository/docker/dannicool/docker-wechatbot-webhook/general)| [📦 NPM包](https://www.npmjs.com/package/wechatbot-webhook)[🔍 FAQ](https://github.com/danni-cool/wechatbot-webhook/issues/72)
9+
[🚢 Docker 镜像](https://hub.docker.com/repository/docker/dannicool/docker-wechatbot-webhook/general) | [📦 NPM包](https://www.npmjs.com/package/wechatbot-webhook)[🔍 FAQ](https://github.com/danni-cool/wechatbot-webhook/issues/72)
1010
</div>
1111

12-
开箱即用的 Wechaty 应用层项目,实现了一个支持消息收发的微信 webhook 机器人,当 http 调用和二次开发亦可,二次开发请fork
13-
14-
> [!Caution]
15-
> 当前版本基于web协议,除了bug修补和稳定性功能外,不再接收新的 feature request,后续精力会放到 windows 分支上,感兴趣的可以点个 watch 👀
12+
开箱即用的微信webhook机器人,通过 http 接口调用即可实现微信消息的发送和接收,二次开发请 fork
1613

1714
## ✨ Features
1815

19-
- **推送消息** (发送文字 / 图片 / 文件)
20-
- 💬 支持消息单条 / 多条 / 群发
21-
- 🌃 消息 url 解析成文件发送
22-
- 📁 支持读文件发送
23-
24-
- **接收消息**(文字 / 图片 / 语音 / 视频 / 文件 / 好友申请 / 公众号推文链接)
25-
- 🚗 单 API 收发消息(依赖收消息API,被动回复无需公网IP)
26-
- 🪧 登入掉线异常事件通知
27-
28-
- **其他功能**
29-
- 🤖 支持 非掉线自动登录
30-
- ✈️ 支持 带鉴权 api 接口获取登陆二维码
31-
- 支持 [n8n](https://n8n.io/) 低码平台丝滑接入(webhook 节点)
32-
- 🚢 支持 docker 部署,兼容 `arm64``amd64`
33-
- ✍️ 支持 日志文件导出
34-
35-
- **❌ 不支持**
16+
> [!Caution]
17+
> 当前版本基于web协议,其支持的功能有限,也不完美,除了bug修补和稳定性功能外,不再接收新的 feature request,后续精力会放到 windows 分支上,感兴趣的可以点个 watch 👀
18+
19+
| **功能** | web协议 | windows协议 |
20+
| --- | --- | --- |
21+
| 目前可用性 |||
22+
| 代码分支 | main | windows |
23+
| Docker Tag | latest | windows |
24+
| **<发送消息>** | ✅ 单条 / 多条 / 群发 | ✅ 单条 / 多条 / 群发 |
25+
| 发文字 |||
26+
| 发图片 | ✅ 本地图片 / url图片解析 | ✅ 本地图片 / url图片解析 |
27+
| 发视频(mp4) | ✅ 本地视频 / url视频解析 | |
28+
| 发文件 | ✅ 本地文件 / url文件解析 | ✅ 本地文件 / url文件解析 |
29+
| **<接收消息>** | | |
30+
| 接收文字 |||
31+
| 接收图片 || |
32+
| 接收视频 || |
33+
| 接收文件 || |
34+
| 接收好友申请 || |
35+
| 接收公众号推文链接 || |
36+
| 接收系统通知 | ✅ 上线通知 / 掉线通知 / 异常通知 | |
37+
| [快捷回复](https://github.com/danni-cool/wechatbot-webhook?tab=readme-ov-file#2-%E6%94%B6%E6%B6%88%E6%81%AF-api) |||
38+
| **<群管理>** | | |
39+
| **<好友管理>** | | |
40+
| **<其他功能>** | | |
41+
| 非掉线自动登录 || |
42+
| API 鉴权 |||
43+
| [n8n](https://n8n.io/) 无缝接入 || |
44+
| 支持docker部署 | ✅ arm64 / amd64 | ✅ amd64 |
45+
| 日志文件导出 |||
46+
47+
### ⚠️ 特别说明:
48+
49+
以上提到的功能 ✅ 为已实现,受限于微信协议限制,不同协议支持功能也是不同的,并不是所有功能都可以对接,例如:
50+
3651
- 企业微信消息的收发 [#142](https://github.com/danni-cool/wechatbot-webhook/issues/142)
37-
- 发送语音消息/分享音乐/公众号等未提到的功能
52+
- 发送语音消息 / 分享音乐 / 公众号等在 features 中未提到的功能
3853

3954
## 🚀 一分钟 Demo
4055

41-
### 1. 运行
56+
### 1. 运行 & 扫码
4257

4358
```bash
4459
npx wechatbot-webhook
4560
```
4661

4762
> 除非掉线,默认记住上次登录,换帐号请运行以下命令 `npx wechatbot-webhook -r`
4863
49-
### 2. 扫码登录
64+
### 2. 复制推消息 api
65+
66+
从命令行中复制推消息api,例如 http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]
5067

51-
![](https://cdn.jsdelivr.net/gh/danni-cool/danni-cool@cdn/image/Jietu20231224-170732.gif)
68+
![](https://cdn.jsdelivr.net/gh/danni-cool/danni-cool@cdn/image/wechatbot-demo.gif)
5269

53-
### 3. 使用 http 请求给指定用户发消息
70+
### 3. 使用以下结构发消息
5471

55-
新开个终端试试以下 curl,to字段值换成你要发送的昵称
72+
从命令行中复制推消息新开个终端试试以下 curl,to, token字段值换成你要值
5673

5774
```bash
58-
curl --location 'http://localhost:3001/webhook/msg/v2' \
75+
curl --location 'http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]' \
5976
--header 'Content-Type: application/json' \
6077
--data '{ "to": "测试昵称", data: { "content": "Hello World!" }}'
6178
```
@@ -99,7 +116,7 @@ docker logs -f wxBotWebhook
99116

100117
找到二维码登录地址,图下 url 部分,浏览器访问,扫码登录wx
101118

102-
<https://localhost:3001/login?token=YOUR_PERSONAL_TOKEN>
119+
<https://localhost:3001/login?token=[YOUR_PERSONAL_TOKEN]>
103120

104121
#### 可选 env 参数
105122

@@ -117,7 +134,7 @@ docker logs -f wxBotWebhook
117134

118135
> v2版本接口增加了群发功能,v1 版本接口请移步 [legacy-api](./docs/legacy-api.md)
119136
120-
- Url:<http://localhost:3001/webhook/msg/v2>
137+
- Url:<http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]>
121138
- Methods: `POST`
122139
- ContentType: `application/json`
123140
- Body: 格式见下面表格
@@ -144,7 +161,7 @@ docker logs -f wxBotWebhook
144161
##### 发单条消息
145162

146163
```bash
147-
curl --location 'http://localhost:3001/webhook/msg/v2' \
164+
curl --location 'http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]' \
148165
--header 'Content-Type: application/json' \
149166
--data '{
150167
"to": "testUser",
@@ -155,7 +172,7 @@ curl --location 'http://localhost:3001/webhook/msg/v2' \
155172
##### 发给群消息
156173

157174
```bash
158-
curl --location 'http://localhost:3001/webhook/msg/v2' \
175+
curl --location 'http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]' \
159176
--header 'Content-Type: application/json' \
160177
--data '{
161178
"to": "testGroup",
@@ -167,7 +184,7 @@ curl --location 'http://localhost:3001/webhook/msg/v2' \
167184
##### 同一对象多条消息(群消息同理)
168185

169186
```bash
170-
curl --location 'http://localhost:3001/webhook/msg/v2' \
187+
curl --location 'http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]' \
171188
--header 'Content-Type: application/json' \
172189
--data '{
173190
"to": "testUser",
@@ -187,7 +204,7 @@ curl --location 'http://localhost:3001/webhook/msg/v2' \
187204
##### 群发消息
188205

189206
``` bash
190-
curl --location 'http://localhost:3001/webhook/msg/v2' \
207+
curl --location 'http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]' \
191208
--header 'Content-Type: application/json' \
192209
--data '[
193210
{
@@ -247,7 +264,7 @@ curl --location 'http://localhost:3001/webhook/msg/v2' \
247264

248265
> 读文件暂时只支持单条发送
249266
250-
- Url:<http://localhost:3001/webhook/msg>
267+
- Url:<http://localhost:3001/webhook/msg?token=[YOUR_PERSONAL_TOKEN]>
251268
- Methods: `POST`
252269
- ContentType: `multipart/form-data`
253270
- FormData: 格式见下面表格
@@ -263,7 +280,7 @@ curl --location 'http://localhost:3001/webhook/msg/v2' \
263280
##### Curl
264281

265282
```bash
266-
curl --location --request POST 'http://localhost:3001/webhook/msg' \
283+
curl --location --request POST 'http://localhost:3001/webhook/msg?token=[YOUR_PERSONAL_TOKEN]' \
267284
--form 'to=testGroup' \
268285
--form content=@"$HOME/demo.jpg" \
269286
--form 'isRoom=1'
@@ -372,7 +389,7 @@ curl --location 'https://your.recvdapi.com' \
372389
#### token 配置说明
373390
> 除了在 docker 启动时配置token,在默认缺省 token 的情况,会默认生成一个写入 `.env` 文件中
374391
375-
#### `/login?token=YOUR_PERSONAL_TOKEN`
392+
#### `/login?token=[YOUR_PERSONAL_TOKEN]`
376393

377394
- **描述**:获取登录二维码接口。
378395
- **methods**: `GET`
@@ -388,7 +405,7 @@ curl --location 'https://your.recvdapi.com' \
388405
**status**: `302`
389406
登录态掉了,跳转最新的登录二维码
390407

391-
#### `/healthz?token=YOUR_PERSONAL_TOKEN`
408+
#### `/healthz?token=[YOUR_PERSONAL_TOKEN]`
392409

393410
- **描述**:健康检测接口。
394411
- **methods**: `GET`

docs/legacy-api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## V1 版本
44

5-
- Url:<http://localhost:3001/webhook/msg>
5+
- Url:<http://localhost:3001/webhook/msg?token=[YOUR_PERSONAL_TOKEN]>
66
- Methods: `POST`
77

88
#### Case1. 发文字或文件(外链)
@@ -24,7 +24,7 @@
2424
##### Curl (发文字)
2525

2626
```bash
27-
curl --location --request POST 'http://localhost:3001/webhook/msg' \
27+
curl --location --request POST 'http://localhost:3001/webhook/msg?token=[YOUR_PERSONAL_TOKEN]' \
2828
--header 'Content-Type: application/json' \
2929
--data-raw '{
3030
"to": "testUser",
@@ -36,7 +36,7 @@ curl --location --request POST 'http://localhost:3001/webhook/msg' \
3636
##### Curl(发文件,解析url)
3737

3838
```bash
39-
curl --location --request POST 'http://localhost:3001/webhook/msg' \
39+
curl --location --request POST 'http://localhost:3001/webhook/msg?token=[YOUR_PERSONAL_TOKEN]' \
4040
--header 'Content-Type: application/json' \
4141
--data-raw '{
4242
"to": "testGroup",
@@ -60,7 +60,7 @@ curl --location --request POST 'http://localhost:3001/webhook/msg' \
6060
##### Curl
6161

6262
```bash
63-
curl --location --request POST 'http://localhost:3001/webhook/msg' \
63+
curl --location --request POST 'http://localhost:3001/webhook/msg?token=[YOUR_PERSONAL_TOKEN]' \
6464
--form 'to=testGroup' \
6565
--form content=@"$HOME/demo.jpg" \
6666
--form 'isRoom=1'

main.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ const registerRoute = require('./src/route')
1313
const bot = wechatBotInit()
1414
const app = new Hono()
1515

16-
/**
17-
* @param {import('hono').Context} ctx
18-
* @param {import('hono').Next} next
19-
*/
20-
const attachData = (ctx, next) => {
21-
ctx.bot = bot
22-
return next()
23-
}
24-
25-
app.use('*', attachData)
26-
27-
// 注册webhook
2816
registerRoute({ app, bot })
2917

3018
serve({

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"main": "main.js",
1313
"scripts": {
1414
"prestart": "node ./scripts/preStart",
15-
"start": "node main"
15+
"start": "node main",
16+
"build:cli": "pnpm --filter wechatbot-webhook run build"
1617
},
1718
"engines": {
1819
"node": ">=18.14.1"

packages/cli/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[🚢 Docker 镜像](https://hub.docker.com/repository/docker/dannicool/docker-wechatbot-webhook/general) | [🧑‍💻 Github](https://github.com/danni-cool/wechatbot-webhook)[🔍 FAQ](https://github.com/danni-cool/wechatbot-webhook/issues/72)
1010
</div>
1111

12-
开箱即用的 Wechaty 应用层项目,实现了一个支持消息收发的微信 webhook 机器人
12+
开箱即用的微信webhook机器人,通过 http 接口调用即可实现微信消息的发送和接收
1313

1414
## ✨ Features
1515

@@ -31,11 +31,15 @@
3131

3232
### 1. 安装
3333

34+
> 目前使用 pnpm 管理包,以支持临时包修补(patches)和加速依赖安装,如果你还不了解 pnpm,可以先了解 [pnpm](https://pnpm.io/zh/motivation)
35+
3436
```bash
35-
npm i wechatbot-webhook -g
37+
pnpm i wechatbot-webhook -g
3638
```
3739

38-
### 2. 运行
40+
### 2. 运行 & 扫码
41+
42+
![](https://cdn.jsdelivr.net/gh/danni-cool/danni-cool@cdn/image/wechatbot-demo.gif)
3943

4044
```bash
4145
wxbot
@@ -51,16 +55,17 @@ Options:
5155
-h, --help display help for command
5256
```
5357

54-
### 2. 扫码登录
5558

56-
![](https://cdn.jsdelivr.net/gh/danni-cool/danni-cool@cdn/image/Jietu20231224-170732.gif)
59+
### 3. 复制推消息 api
60+
61+
从命令行中复制推消息api,例如 http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]
5762

58-
### 3. 使用 http 请求给指定用户发消息
63+
### 4. 使用以下结构发消息
5964

60-
新开个终端试试以下 curl,to字段值换成你要发送的昵称
65+
从命令行中复制推消息新开个终端试试以下 curl,to, token字段值换成你要值
6166

6267
```bash
63-
curl --location 'http://localhost:3001/webhook/msg/v2' \
68+
curl --location 'http://localhost:3001/webhook/msg/v2?token=[YOUR_PERSONAL_TOKEN]' \
6469
--header 'Content-Type: application/json' \
6570
--data '{ "to": "测试昵称", data: { "content": "Hello World!" }}'
6671
```

src/route/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
const Middleware = require('../middleware/index')
12
/**
23
* 注册路由
34
* @param {Object} param
45
* @param {import('hono').Hono} param.app
56
* @param {import('wechaty').Wechaty} param.bot
67
*/
78
module.exports = function registerRoute({ app, bot }) {
9+
/**
10+
* @param {import('hono').Context} ctx
11+
* @param {import('hono').Next} next
12+
*/
13+
const attachData = (ctx, next) => {
14+
ctx.bot = bot
15+
return next()
16+
}
17+
// 挂载wecahty实例到全局路由
18+
app.use('*', attachData)
19+
// 全局鉴权
20+
app.use(Middleware.verifyToken)
21+
822
require('./msg')({ app, bot })
923
require('./login')({ app, bot })
1024
}

src/route/login.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const Service = require('../service')
22
const Utils = require('../utils')
3-
const Middleware = require('../middleware')
43
const { TextMsg } = require('../utils/msg.js')
54

65
/**
@@ -87,8 +86,6 @@ module.exports = function registerLoginCheck({ app, bot }) {
8786

8887
app.get(
8988
'/login',
90-
Middleware.verifyToken,
91-
9289
/** @param {import('hono').Context} c */
9390
async (c) => {
9491
// 登录成功的话,返回登录信息
@@ -105,7 +102,6 @@ module.exports = function registerLoginCheck({ app, bot }) {
105102

106103
app.get(
107104
'/healthz',
108-
Middleware.verifyToken,
109105
/** @param {import('hono').Context} c */
110106
async (c) => {
111107
// 登录成功的话,返回登录信息

src/wechaty/init.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ module.exports = function init() {
3030

3131
// 登陆成功事件
3232
.on('login', async (user) => {
33-
if (process.env.homeEnvCfg !== undefined) {
34-
Utils.logger.info(
35-
[
36-
'🌱 ' + chalk.green(`User ${user.toString()} logged in`),
37-
'📖 发送消息 HTTP API 请参考: ' +
38-
`${chalk.cyan(
39-
'https://github.com/danni-cool/wechatbot-webhook?tab=readme-ov-file#%EF%B8%8F-api'
40-
)}`
41-
].join('\n')
42-
)
43-
return
44-
}
45-
46-
Utils.logger.info(`🌱 User ${user.toString()} logged in`)
33+
Utils.logger.info('🌱 ' + chalk.green(`User ${user} logged in`))
34+
Utils.logger.info(
35+
'💬 ' +
36+
`你的推消息 api 为:${chalk.cyan(
37+
`http://localhost:${PORT}/webhook/msg/v2?token=${token}`
38+
)}`
39+
)
40+
Utils.logger.info(
41+
'📖 发送消息结构 API 请参考: ' +
42+
`${chalk.cyan(
43+
'https://github.com/danni-cool/wechatbot-webhook?tab=readme-ov-file#%EF%B8%8F-api'
44+
)}\n`
45+
)
4746
})
4847

4948
// 登出事件

0 commit comments

Comments
 (0)