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

Commit 3d9d737

Browse files
authored
2.7.0版本更新计划 (#144)
- [x] #165 暂时只用文本展示 - [x] 代码提交 @Daydaylw3 - [x] 文档增加说明 - [x] #159 - [x] 增加有条件开启是否转发自己消息 - [x] 消息增加标识自己 - [x] 设备上自己发送消息上报recvd-api - [x] 通过推消息api自己发送的消息上报recvd-api - [x] #140 - [x] 系统消息单独定义类型 - [x] 根据特定的错误标识,提前触发logout 事件,并且屏蔽上报请求 - [x] 完善readme - [x] #160 - [x] 尝试根据wechaty的通用错误手动触发 logout 事件,并且登出当前账号 - [x] 版本部署测试环境,观测掉线事件中 - [x] 优化代码,确保登出事件只触发一次
2 parents 67615d3 + 6a895c7 commit 3d9d737

29 files changed

+590
-205
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ LOG_LEVEL=info
77
# 如果不希望登录一次后就记住当前账号,想每次都扫码登陆,填 true
88
DISABLE_AUTO_LOGIN=
99

10+
# RECVD_MSG_API 是否接收来自自己发的消息
11+
ACCEPT_RECVD_MSG_MYSELF=false
12+
1013
# 如果想自己处理收到消息的逻辑,在下面填上你的API地址, 默认为空
1114
LOCAL_RECVD_MSG_API=
1215

.github/workflows/nightly-build.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ jobs:
1919
with:
2020
username: dannicool
2121
password: ${{ secrets.DOCKERHUB_TOKEN }}
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v1
2225

2326
- name: Build and Push Docker Image
24-
run: |
25-
docker build . -t dannicool/docker-wechatbot-webhook:nightly
26-
docker push dannicool/docker-wechatbot-webhook:nightly
27+
uses: docker/build-push-action@v2
28+
with:
29+
context: .
30+
file: ./Dockerfile
31+
push: true
32+
tags: dannicool/docker-wechatbot-webhook:nightly
33+
platforms: linux/amd64,linux/arm64

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx -y commitlint --edit "$1"
4+
npx commitlint --edit "$1"

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx -y lint-staged
4+
npx lint-staged

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ docker logs -f wxBotWebhook
125125

126126
> Tips:需要增加参数使用 -e,多行用 \ 隔开,例如 -e RECVD_MSG_API="<https://example.com/your/url>" \
127127
128-
| 功能 | 环境变量 | 案例 | 备注 |
129-
|--|--|--|--|
130-
| 收消息 | RECVD_MSG_API | RECVD_MSG_API=<https://example.com/your/url> | 如果想自己处理收到消息的逻辑,比如根据消息联动,填上你的处理逻辑 url,该行可以省略 |
131-
| 禁用自动登录 | DISABLE_AUTO_LOGIN | DISABLE_AUTO_LOGIN=true | 非微信踢下线账号,可以依靠session免登, 如果想每次都扫码登陆,则增加该条配置 |
132-
| 自定义登录 API token | LOGIN_API_TOKEN | LOGIN_API_TOKEN=abcdefg123 | 你也可以自定义一个自己的登录令牌,不配置的话,默认会生成一个 |
128+
| 功能 | 变量 | 备注 |
129+
|--|--|--|
130+
| 日志级别 | LOG_LEVEL=info | 日志级别,默认 info,只影响当前日志输出,详细输出考虑使用 debug。无论该值如何变化,日志文件总是记录debug级别的日志 |
131+
| 收消息 API | RECVD_MSG_API=<https://example.com/your/url> | 如果想自己处理收到消息的逻辑,比如根据消息联动,填上你的处理逻辑 url |
132+
| 收消息 API 接受自己发的消息 | ACCEPT_RECVD_MSG_MYSELF=false | RECVD_MSG_API 是否接收来自自己发的消息(设置为true,即接收, 默认false) |
133+
| 自定义登录 API token | LOGIN_API_TOKEN=abcdefg123 | 你也可以自定义一个自己的登录令牌,不配置的话,默认会生成一个 |
134+
| 禁用自动登录 | DISABLE_AUTO_LOGIN=true | **非微信踢下线账号,可以依靠当前登录的session免登**, 如果想每次都扫码登陆,则增加该条配置 |
133135

134136
## 🛠️ API
135137

@@ -309,11 +311,11 @@ curl --location --request POST 'http://localhost:3001/webhook/msg?token=[YOUR_PE
309311

310312
| formData | 说明 | 数据类型 | 可选值 | 示例 |
311313
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ----------------------- | ------------------------------------------------ |
312-
| type | <div>支持的类型</div><ul><li>✅ 文字(text)</li><li>✅ 链接卡片(urlLink)</li><li>✅ 图片(file)</li><li>✅ 视频(file)</li><li>✅ 附件(file)</li> <li>✅ 语音(file)</li><li>✅ 添加好友邀请(friendship)</li></ul> refer: [wechaty类型支持列表](https://wechaty.js.org/docs/api/message#messagetype--messagetype) | `String` | `text` `file` `urlLink` `friendship` | - |
314+
| type | <div>功能类型</div><ul><li>✅ 文字(text)</li><li>✅ 链接卡片(urlLink)</li><li>✅ 图片(file)</li><li>✅ 视频(file)</li><li>✅ 附件(file)</li> <li>✅ 语音(file)</li><li>✅ 添加好友邀请(friendship)</li></ul><div>其他类型</div><ul><li>未实现的消息类型(unknown)</li></ul><div>系统类型</div><ul><li>✅ 登录(system_event_login)</li><li>✅ 登出(system_event_logout)</li><li>✅ 异常报错(system_event_error)</li><li>✅ 快捷回复后消息推送状态通知(system_event_push_notify)</li></ul> | `String` | `text` `file` `urlLink` `friendship` `unknown` `system_event_login` `system_event_logout` `system_event_error` `system_event_push_notify`| - |
313315
| content | 传输的内容, 文本或传输的文件共用这个字段,结构映射请看示例 | `String` `Binary` | | [示例](docs/recvdApi.example.md#formdatacontent) |
314316
| source | 消息的相关发送方数据, JSON String | `String` | | [示例](docs/recvdApi.example.md#formdatasource) |
315-
| isMentioned | 该消息是@我的消息[#38](https://github.com/danni-cool/wechatbot-webhook/issues/38) | `String` | `1` `0` | - |
316-
| isSystemEvent | 是否是来自系统消息事件(上线,掉线、异常事件、快捷回复后的通知) | `String` | `1` `0` | - |
317+
| isMentioned | 该消息是@我的消息 [#38](https://github.com/danni-cool/wechatbot-webhook/issues/38) | `String` | `1` `0` | - |
318+
| isMsgFromSelf | 是否是来自自己的消息 [#159](https://github.com/danni-cool/wechatbot-webhook/issues/159) | `String` | `1` `0` | - |
317319

318320
**服务端处理 formData 一般需要对应的处理程序,假设你已经完成这一步,你将得到以下 request**
319321

@@ -323,7 +325,8 @@ curl --location --request POST 'http://localhost:3001/webhook/msg?token=[YOUR_PE
323325
"content": "你好",
324326
"source": "{\"room\":\"\",\"to\":{\"_events\":{},\"_eventsCount\":0,\"id\":\"@f387910fa45\",\"payload\":{\"alias\":\"\",\"avatar\":\"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=1302335654&username=@f38bfd1e0567910fa45&skey=@crypaafc30\",\"friend\":false,\"gender\":1,\"id\":\"@f38bfd1e10fa45\",\"name\":\"ch.\",\"phone\":[],\"star\":false,\"type\":1}},\"from\":{\"_events\":{},\"_eventsCount\":0,\"id\":\"@6b5111dcc269b6901fbb58\",\"payload\":{\"address\":\"\",\"alias\":\"\",\"avatar\":\"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=123234564&username=@6b5dbb58&skey=@crypt_ec356afc30\",\"city\":\"Mars\",\"friend\":false,\"gender\":1,\"id\":\"@6b5dbd3facb58\",\"name\":\"Daniel\",\"phone\":[],\"province\":\"Earth\",\"signature\":\"\",\"star\":false,\"weixin\":\"\",\"type\":1}}}",
325327
"isMentioned": "0",
326-
"isSystemEvent": "0"
328+
"isMsgFromSelf": "0",
329+
"isSystemEvent": "0" // 考虑废弃,请使用type类型判断系统消息
327330
}
328331
```
329332

@@ -334,8 +337,7 @@ curl --location 'https://your.recvdapi.com' \
334337
--form 'type="file"' \
335338
--form 'content=@"/Users/Downloads/13482835.jpeg"' \
336339
--form 'source="{\\\"room\\\":\\\"\\\",\\\"to\\\":{\\\"_events\\\":{},\\\"_eventsCount\\\":0,\\\"id\\\":\\\"@f387910fa45\\\",\\\"payload\\\":{\\\"alias\\\":\\\"\\\",\\\"avatar\\\":\\\"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=1302335654&username=@f38bfd1e0567910fa45&skey=@crypaafc30\\\",\\\"friend\\\":false,\\\"gender\\\":1,\\\"id\\\":\\\"@f38bfd1e10fa45\\\",\\\"name\\\":\\\"ch.\\\",\\\"phone\\\":[],\\\"star\\\":false,\\\"type\\\":1}},\\\"from\\\":{\\\"_events\\\":{},\\\"_eventsCount\\\":0,\\\"id\\\":\\\"@6b5111dcc269b6901fbb58\\\",\\\"payload\\\":{\\\"address\\\":\\\"\\\",\\\"alias\\\":\\\"\\\",\\\"avatar\\\":\\\"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=123234564&username=@6b5dbb58&skey=@crypt_ec356afc30\\\",\\\"city\\\":\\\"Mars\\\",\\\"friend\\\":false,\\\"gender\\\":1,\\\"id\\\":\\\"@6b5dbd3facb58\\\",\\\"name\\\":\\\"Daniel\\\",\\\"phone\\\":[],\\\"province\\\":\\\"Earth\\\",\\\"signature\\\":\\\"\\\",\\\"star\\\":false,\\\"weixin\\\":\\\"\\\",\\\"type\\\":1}}}"' \
337-
--form 'isMentioned="0"' \
338-
--form 'isSystemEvent="0"'
340+
--form 'isMentioned="0"'
339341
```
340342

341343

@@ -399,14 +401,18 @@ curl --location 'https://your.recvdapi.com' \
399401
- **query**: token
400402

401403
**status**: `200`
402-
登录成功,返回 json 包含当前用户
404+
405+
##### 登录成功
406+
407+
返回 json 包含当前用户
403408

404409
```json
405410
{"success":true,"message":"Contact<TestUser>is already login"}
406411
```
407412

408-
**status**: `302`
409-
登录态掉了,跳转最新的登录二维码
413+
##### 登录失败
414+
415+
展示微信登录扫码页面
410416

411417
#### `/healthz?token=[YOUR_PERSONAL_TOKEN]`
412418

docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ services:
88
ports:
99
- "3001:3001"
1010
environment:
11-
- LOG_LEVEL=info # 调整容器输出级别(不影响日志文件输出等级)运行时提示的消息等级(默认info,想有更详细的日志,等级同log4js)
11+
- LOG_LEVEL=info # 调整容器输出级别(不影响日志文件输出等级)运行时提示的消息等级(默认info,debug级别会输出详细的日志)
1212
# - DISABLE_AUTO_LOGIN=true # 如果不希望登录一次后就记住当前账号,想每次都扫码登陆,填 true
13-
# - LOCAL_RECVD_MSG_API= # 如果想自己处理收到消息的逻辑,在下面填上你的API地址, 默认为空
14-
# - LOCAL_LOGIN_API_TOKEN= # 登录地址Token访问地址: http://localhost:3001/login?token=[LOCAL_LOGIN_API_TOKEN]
13+
# - ACCEPT_RECVD_MSG_MYSELF=true # 如果希望机器人可以自己接收消息,填 true
14+
# - RECVD_MSG_API= # 如果想自己处理收到消息的逻辑,在下面填上你的API地址, 默认为空
15+
# - LOGIN_API_TOKEN= # 登录地址Token访问地址: http://localhost:3001/login?token=[LOCAL_LOGIN_API_TOKEN]
1516
restart: unless-stopped

dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ ENV RECVD_MSG_API=
2222
ENV LOGIN_API_TOKEN=
2323
# 是否禁用默认登录
2424
ENV DISABLE_AUTO_LOGIN=
25+
# 运行时提示的消息等级(默认info,想有更详细的日志,可以指定为debug)
26+
ENV LOG_LEVEL=info
27+
# RECVD_MSG_API 是否接收来自自己发的消息(设置为true,即接收)
28+
ENV ACCEPT_RECVD_MSG_MYSELF=false
2529

2630
# 暴露端口(你的 Express 应用程序监听的端口)
2731
EXPOSE 3001

docs/recvdApi.example.md

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# RECVD_MSG_API JSON 示例
22

3-
## formData 请求体不同情况说明
3+
## 1. `formData.type` 不同情况说明
44

5-
### 文字消息 `formData.type === text`
5+
### 1.1 功能消息类型
6+
7+
#### 文字消息 `text`
68

79
- 是否支持快捷回复:✅
810
- `formData.content`: `String`
911

10-
### 文件消息 `formData.type === file`
12+
#### 文件消息 `file`
1113

1214
- 是否支持快捷回复:✅
1315
- `formData.content`: `binary`
1416

15-
### 公众号推文 `formData.type === urlLink`
17+
#### 公众号推文 `urlLink`
1618

1719
- 是否支持快捷回复:❌
1820
- `formData.content``json`
@@ -27,7 +29,7 @@
2729
}
2830
```
2931

30-
### 加好友请求 `formData.type === friendship`
32+
#### 加好友请求 `friendship`
3133

3234
- 是否支持快捷回复:✅
3335
- `formData.content``json`
@@ -41,16 +43,31 @@
4143

4244
> 通过好友请求,需要通过接口返回 `{ "success": true }` 字段
4345
44-
### 4. 系统消息 `formData.isSystemEvent === '1'`
46+
### 1.2 其他消息类型
47+
48+
#### 不支持的消息类型 `unknown`
49+
50+
- 是否支持快捷回复:✅
51+
52+
没法在当前版本微信中展示的消息,如果能展示值,会以**文本形式**展示,否则为空
53+
54+
例如:
55+
- [unknown 类型里拍一拍消息提示](https://github.com/danni-cool/wechatbot-webhook/pull/121)
56+
57+
58+
### 1.3 系统通知消息类型
4559

4660
- 是否支持快捷回复:❌
61+
62+
#### 微信已登录/登出 `system_event_login` | `system_event_logout`
63+
4764
- `formData.content`: `json`
48-
示例
65+
4966
```js
5067
{
51-
"event": "login", // login | logout | error | notifyOfRecvdApiPushMsg
68+
"event": "login", // login | logout
5269

53-
"user": { // 当前的用户信息,没有则为null
70+
"user": { // 当前的用户信息
5471
"_events": {},
5572
"_eventsCount": 0,
5673
"id": "@xxxasdfsf",
@@ -65,11 +82,61 @@
6582
"star": false,
6683
"type": 1
6784
}
68-
69-
"error": ''// js 报错的错误栈信息
7085
}
86+
}
87+
```
88+
89+
#### 系统运行出错 `system_event_error`
90+
- `formData.content`: `json`
91+
```js
92+
{
93+
"event": "error", //notifyOfRecvdApiPushMsg
94+
95+
"user": { // 当前的用户信息
96+
"_events": {},
97+
"_eventsCount": 0,
98+
"id": "@xxxasdfsf",
99+
"payload": {
100+
"alias": "",
101+
"avatar": "",
102+
"friend": false,
103+
"gender": 1,
104+
"id": "@xxx",
105+
"name": "somebody",
106+
"phone": [],
107+
"star": false,
108+
"type": 1
109+
}
110+
},
111+
112+
"error": {} // 具体出错信息 js error stack
113+
}
114+
```
115+
116+
#### 快捷回复后通知 `system_event_push_notify`
117+
- `formData.content`: `json`
118+
```js
119+
{
120+
"event": "error", //notifyOfRecvdApiPushMsg
121+
122+
"user": { // 当前的用户信息
123+
"_events": {},
124+
"_eventsCount": 0,
125+
"id": "@xxxasdfsf",
126+
"payload": {
127+
"alias": "",
128+
"avatar": "",
129+
"friend": false,
130+
"gender": 1,
131+
"id": "@xxx",
132+
"name": "somebody",
133+
"phone": [],
134+
"star": false,
135+
"type": 1
136+
}
137+
},
71138

72-
//仅当 event: "notifyOfRecvdApiPushMsg" 快捷回复后触发才返回次结构, 如果有部分消息推送失败也在此结构能拿到所有信息, 结构同推消息的api结构
139+
// 快捷回复后触发才返回此结构,如果有部分消息推送失败也在此结构能拿到所有信息, 结构同推消息的api结构
73140
"recvdApiReplyNotify": {
74141
"success": true,
75142
"message": "Message sent successfully",
@@ -86,7 +153,7 @@
86153
```
87154

88155

89-
## formData.source `String`
156+
## 2. formData.source `String`
90157

91158
```js
92159
{
@@ -99,7 +166,7 @@
99166
"adminIdList": [],
100167
"avatar": "xxxx", // 相对路径,应该要配合解密
101168
"memberList": [
102-
{id: '@xxxx', name:'昵称', alias: '备注名' }
169+
{id: '@xxxx', name:'昵称', alias: '备注名'/** 个人备注名,非群备注名 */ }
103170
]
104171
},
105172
//以下暂不清楚什么用途,如有兴趣,请查阅 wechaty 官网文档

main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
require('dotenv').config({
22
path: process.env.homeEnvCfg /** 兼容cli调用 */ ?? './.env'
33
})
4-
/** log 在 prestart 阶段初始化了,后续需要手动改level才能同步env配置 */
5-
require('./src/utils/index').proxyConsole({
6-
logLevel: process.env.LOG_LEVEL
7-
})
4+
require('./src/utils/index').proxyConsole()
85
const { PORT } = process.env
96
const { Hono } = require('hono')
107
const { serve } = require('@hono/node-server')

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"dotenv": "^16.3.1",
4646
"file-box": "1.4.15",
4747
"form-data": "^4.0.0",
48+
"gerror": "^1.0.16",
4849
"hono": "^3.11.11",
4950
"log4js": "^6.9.1",
5051
"mime": "^3.0.0",
@@ -70,7 +71,9 @@
7071
},
7172
"pnpm": {
7273
"patchedDependencies": {
73-
74+
75+
76+
7477
}
7578
}
7679
}

0 commit comments

Comments
 (0)