wechaty-web-panel 1.2.11 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +14 -10
- package/dist/cjs/src/common/index.d.ts +2 -0
- package/dist/cjs/src/common/index.js +23 -8
- package/dist/cjs/src/handlers/on-login.js +10 -8
- package/dist/cjs/src/handlers/on-message.js +45 -7
- package/dist/cjs/src/package-json.d.ts +4 -2
- package/dist/cjs/src/package-json.js +11 -5
- package/dist/cjs/src/proxy/aibotk.js +1 -1
- package/dist/cjs/src/proxy/chatgpt.d.ts +1 -1
- package/dist/cjs/src/proxy/chatgpt.js +49 -26
- package/dist/cjs/src/proxy/tencent-open.js +2 -2
- package/dist/cjs/src/service/msg-filter-service.js +4 -3
- package/dist/cjs/src/service/msg-filters.d.ts +6 -0
- package/dist/cjs/src/service/msg-filters.js +16 -10
- package/dist/cjs/src/task/index.d.ts +1 -1
- package/dist/cjs/src/task/index.js +82 -21
- package/dist/esm/src/common/index.d.ts +2 -0
- package/dist/esm/src/common/index.js +22 -7
- package/dist/esm/src/handlers/on-login.js +10 -8
- package/dist/esm/src/handlers/on-message.js +45 -7
- package/dist/esm/src/package-json.d.ts +4 -2
- package/dist/esm/src/package-json.js +11 -5
- package/dist/esm/src/proxy/aibotk.js +1 -1
- package/dist/esm/src/proxy/chatgpt.d.ts +1 -1
- package/dist/esm/src/proxy/chatgpt.js +49 -26
- package/dist/esm/src/proxy/tencent-open.js +2 -2
- package/dist/esm/src/service/msg-filter-service.js +4 -3
- package/dist/esm/src/service/msg-filters.d.ts +6 -0
- package/dist/esm/src/service/msg-filters.js +15 -9
- package/dist/esm/src/task/index.d.ts +1 -1
- package/dist/esm/src/task/index.js +83 -22
- package/doc/img/event.png +0 -0
- package/doc/img/everyday.png +0 -0
- package/doc/img/index.png +0 -0
- package/doc/img/material.png +0 -0
- package/doc/img/roomasync.png +0 -0
- package/package.json +11 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
## 更新日志
|
|
2
2
|
|
|
3
|
+
### V1.4.0(2023-01-13)
|
|
4
|
+
|
|
5
|
+
1、增加更多消息类型的解析,小程序和链接支持返回解析参数
|
|
6
|
+
2、定时任务同时支持群和好友,每日说,新闻资讯,自定义定时任务,回调事件均已适配
|
|
7
|
+
3、所有关键词回复,机器人回复,回调事件,技能中心支持配置触发范围,可以指定只在群,或者私聊中触发
|
|
8
|
+
4、增加H5和小程序素材,为后续推出puppet-engine做准备
|
|
9
|
+
5、素材添加分类标签,支持筛选和归类,方便查询
|
|
10
|
+
6、在线素材发送支持小程序和h5链接
|
|
11
|
+
7、智能微秘书平台菜单重新规划,关键词回复改为简单问答,关键词事件改为技能中心
|
|
12
|
+
|
|
13
|
+
### V1.2.12(2022-12-21)
|
|
14
|
+
|
|
15
|
+
1、修改ChatGPT 为官方api版本
|
|
16
|
+
|
|
3
17
|
### V1.2.8(2022-12-07)
|
|
4
18
|
|
|
5
19
|
1、添加ChatGPT让你的机器人更智能
|
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/gengchen528/wechaty-web-panel)
|
|
4
4
|
[](https://github.com/Wechaty/wechaty)
|
|
5
|
+
[](https://www.npmjs.com/package/wechaty-web-panel)
|
|
5
6
|
|
|
6
7
|
Wechaty Web Panel 插件,让你的 wechaty 机器人快速接入 web 控制面板
|
|
7
8
|
|
|
@@ -9,8 +10,6 @@ Wechaty Web Panel 插件,让你的 wechaty 机器人快速接入 web 控制面
|
|
|
9
10
|
|
|
10
11
|
## 面板主要功能
|
|
11
12
|
|
|
12
|
-
- [x] 微信每日说,定时给女朋友发送每日天气提醒,以及每日一句
|
|
13
|
-
|
|
14
13
|
* 定时提醒
|
|
15
14
|
|
|
16
15
|
- [x] 当天定时提醒 例:"提醒 我 18:00 下班了,记得带好随身物品"
|
|
@@ -22,15 +21,18 @@ Wechaty Web Panel 插件,让你的 wechaty 机器人快速接入 web 控制面
|
|
|
22
21
|
- [x] 天行机器人
|
|
23
22
|
- [x] 图灵机器人
|
|
24
23
|
- [x] 腾讯闲聊机器人
|
|
24
|
+
- [x] ChatGPT api
|
|
25
|
+
- [x] 微信对话开放平台
|
|
25
26
|
- [ ] 更多
|
|
26
27
|
|
|
27
|
-
*
|
|
28
|
+
* 定时任务
|
|
28
29
|
|
|
29
|
-
- [x]
|
|
30
|
-
- [x]
|
|
30
|
+
- [x] 新闻定时发送
|
|
31
|
+
- [x] 自定义内容定时发送
|
|
32
|
+
- [x] 微信每日说,定时给女朋友和群友发送每日天气提醒,以及每日一句
|
|
31
33
|
- [ ] 更多功能等你来 pr
|
|
32
34
|
|
|
33
|
-
*
|
|
35
|
+
* 技能中心
|
|
34
36
|
|
|
35
37
|
- [x] 关键词加好友
|
|
36
38
|
- [x] 关键词加群
|
|
@@ -65,6 +67,8 @@ Wechaty Web Panel 插件,让你的 wechaty 机器人快速接入 web 控制面
|
|
|
65
67
|
- [x] 主动更新配置
|
|
66
68
|
- [x] 主动同步好友和群列表
|
|
67
69
|
- [x] 多群消息同步
|
|
70
|
+
- [x] 回调事件
|
|
71
|
+
- [x] 群发助手
|
|
68
72
|
- [x] openapi请求
|
|
69
73
|
|
|
70
74
|
更多详情介绍:[传送门](https://www.xkboke.com/web-inn/secretary/client.html#%E5%B0%8F%E5%8A%A9%E6%89%8B%E5%8A%9F%E8%83%BD%E4%B8%80%E8%A7%88)
|
|
@@ -131,7 +135,7 @@ npm install wechaty-web-panel@latest wechaty@latest --save
|
|
|
131
135
|
$ vim mybot.js
|
|
132
136
|
|
|
133
137
|
const {WechatyBuilder} = require('wechaty')
|
|
134
|
-
const WechatyWebPanelPlugin = require('
|
|
138
|
+
const WechatyWebPanelPlugin = require('wechaty-web-panel')
|
|
135
139
|
|
|
136
140
|
const name = 'wechat-assistant'
|
|
137
141
|
|
|
@@ -167,7 +171,6 @@ $ node mybot.js
|
|
|
167
171
|

|
|
168
172
|

|
|
169
173
|

|
|
170
|
-

|
|
171
174
|

|
|
172
175
|

|
|
173
176
|
|
|
@@ -181,8 +184,9 @@ $ node mybot.js
|
|
|
181
184
|
|
|
182
185
|
群消息同步
|
|
183
186
|
|
|
184
|
-
|
|
187
|
+
<img src="./doc/img/async.png" width="300">
|
|
185
188
|
|
|
186
189
|
群合影
|
|
187
190
|
|
|
188
|
-
|
|
191
|
+
<img src="./doc/img/group.jpeg" width="300">
|
|
192
|
+
|
|
@@ -10,6 +10,7 @@ declare namespace _default {
|
|
|
10
10
|
export { roomSay };
|
|
11
11
|
export { addRoomWelcomeSay };
|
|
12
12
|
export { updateContactAndRoom };
|
|
13
|
+
export { getRoomEveryDayContent };
|
|
13
14
|
}
|
|
14
15
|
export default _default;
|
|
15
16
|
/**
|
|
@@ -80,4 +81,5 @@ export function addRoomWelcomeSay(room: any, roomName: any, contactName: any, ms
|
|
|
80
81
|
* @returns {Promise<void>}
|
|
81
82
|
*/
|
|
82
83
|
export function updateContactAndRoom(that: any): Promise<void>;
|
|
84
|
+
export function getRoomEveryDayContent(date: any, city: any, endWord: any): Promise<string>;
|
|
83
85
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getEveryDayRoomContent = exports.getEveryDayContent = exports.updateContactOnly = exports.updateRoomOnly = void 0;
|
|
3
|
+
exports.getRoomEveryDayContent = exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getEveryDayRoomContent = exports.getEveryDayContent = exports.updateContactOnly = exports.updateRoomOnly = void 0;
|
|
4
4
|
const api_js_1 = require("../proxy/api.js");
|
|
5
5
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
6
6
|
const userDb_js_1 = require("../db/userDb.js");
|
|
@@ -35,6 +35,15 @@ async function getEveryDayContent(date, city, endWord) {
|
|
|
35
35
|
return str;
|
|
36
36
|
}
|
|
37
37
|
exports.getEveryDayContent = getEveryDayContent;
|
|
38
|
+
async function getRoomEveryDayContent(date, city, endWord) {
|
|
39
|
+
let one = await (0, aibotk_js_1.getOne)(); //获取每日一句
|
|
40
|
+
let weather = await (0, api_js_1.getTXweather)(city); //获取天气信息
|
|
41
|
+
let today = (0, index_js_1.formatDate)(new Date()); //获取今天的日期
|
|
42
|
+
let memorialDay = (0, index_js_1.getDay)(date); //获取纪念日天数
|
|
43
|
+
let str = `${today}\n家人们相聚在一起的第${memorialDay}天\n\n元气满满的一天开始啦,家人们要努力保持活跃啊^_^\n\n今日天气\n${weather.weatherTips}\n${weather.todayWeather}\n每日一句:\n${one}\n\n————————${endWord}`;
|
|
44
|
+
return str;
|
|
45
|
+
}
|
|
46
|
+
exports.getRoomEveryDayContent = getRoomEveryDayContent;
|
|
38
47
|
/**
|
|
39
48
|
* 更新用户信息
|
|
40
49
|
*/
|
|
@@ -160,11 +169,13 @@ exports.addRoomWelcomeSay = addRoomWelcomeSay;
|
|
|
160
169
|
* @param {*} isRoom
|
|
161
170
|
*/
|
|
162
171
|
async function roomSay(room, contact, msg) {
|
|
163
|
-
console.log('msg', msg);
|
|
164
172
|
const config = await (0, configDb_js_1.allConfig)();
|
|
165
173
|
const { role } = config.userInfo;
|
|
166
174
|
if (msg.id && role === 'vip') {
|
|
167
|
-
|
|
175
|
+
const res = await (0, aibotk_js_1.getMaterial)(msg.id);
|
|
176
|
+
if (res.id) {
|
|
177
|
+
msg = res;
|
|
178
|
+
}
|
|
168
179
|
}
|
|
169
180
|
try {
|
|
170
181
|
if (msg.type === 1 && msg.content) {
|
|
@@ -194,10 +205,9 @@ async function roomSay(room, contact, msg) {
|
|
|
194
205
|
title: msg.title,
|
|
195
206
|
url: msg.url,
|
|
196
207
|
});
|
|
197
|
-
console.log(url);
|
|
198
208
|
await room.say(url);
|
|
199
209
|
}
|
|
200
|
-
else if (msg.type === 5 && msg.appid && msg.title && msg.pagePath && msg.description && msg.thumbUrl
|
|
210
|
+
else if (msg.type === 5 && msg.appid && msg.title && msg.pagePath && msg.description && msg.thumbUrl) {
|
|
201
211
|
let miniProgram = new this.MiniProgram({
|
|
202
212
|
appid: msg.appid,
|
|
203
213
|
title: msg.title,
|
|
@@ -205,6 +215,7 @@ async function roomSay(room, contact, msg) {
|
|
|
205
215
|
description: msg.description,
|
|
206
216
|
thumbUrl: msg.thumbUrl,
|
|
207
217
|
thumbKey: msg.thumbKey,
|
|
218
|
+
username: msg.username || ''
|
|
208
219
|
});
|
|
209
220
|
await room.say(miniProgram);
|
|
210
221
|
}
|
|
@@ -222,11 +233,13 @@ exports.roomSay = roomSay;
|
|
|
222
233
|
* type 1 文字 2 图片url 3 图片base64 4 url链接 5 小程序 6 名片
|
|
223
234
|
*/
|
|
224
235
|
async function contactSay(contact, msg, isRoom = false) {
|
|
225
|
-
console.log('msg', msg);
|
|
226
236
|
const config = await (0, configDb_js_1.allConfig)();
|
|
227
237
|
const { role } = config.userInfo;
|
|
228
238
|
if (msg.id && role === 'vip') {
|
|
229
|
-
|
|
239
|
+
const res = await (0, aibotk_js_1.getMaterial)(msg.id);
|
|
240
|
+
if (res.id) {
|
|
241
|
+
msg = res;
|
|
242
|
+
}
|
|
230
243
|
}
|
|
231
244
|
try {
|
|
232
245
|
if (msg.type === 1 && msg.content) {
|
|
@@ -259,7 +272,7 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
259
272
|
});
|
|
260
273
|
await contact.say(url);
|
|
261
274
|
}
|
|
262
|
-
else if (msg.type === 5 && msg.appid && msg.title && msg.pagePath && msg.description && msg.thumbUrl
|
|
275
|
+
else if (msg.type === 5 && msg.appid && msg.title && msg.pagePath && msg.description && msg.thumbUrl) {
|
|
263
276
|
let miniProgram = new this.MiniProgram({
|
|
264
277
|
appid: msg.appid,
|
|
265
278
|
title: msg.title,
|
|
@@ -267,6 +280,7 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
267
280
|
description: msg.description,
|
|
268
281
|
thumbUrl: msg.thumbUrl,
|
|
269
282
|
thumbKey: msg.thumbKey,
|
|
283
|
+
username: msg.username || ''
|
|
270
284
|
});
|
|
271
285
|
await contact.say(miniProgram);
|
|
272
286
|
}
|
|
@@ -352,5 +366,6 @@ exports.default = {
|
|
|
352
366
|
roomSay,
|
|
353
367
|
addRoomWelcomeSay,
|
|
354
368
|
updateContactAndRoom,
|
|
369
|
+
getRoomEveryDayContent
|
|
355
370
|
};
|
|
356
371
|
//# sourceMappingURL=index.js.map
|
|
@@ -24,14 +24,16 @@ async function onLogin(user) {
|
|
|
24
24
|
robotId: payload.weixin || (0, index_js_1.MD5)(user.name()),
|
|
25
25
|
};
|
|
26
26
|
await (0, userDb_js_1.addUser)(userInfo); // 全局存储登录用户信息
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
if (payload.avatar) {
|
|
28
|
+
const file = await user.avatar();
|
|
29
|
+
if (file) {
|
|
30
|
+
const base = await file.toBase64();
|
|
31
|
+
const avatarUrl = await (0, aibotk_js_1.putqn)(base, userId);
|
|
32
|
+
(0, aibotk_js_1.sendRobotInfo)(avatarUrl, user.name(), userInfo.robotId); // 更新用户头像
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log('头像未获取到,不影响项目正常使用');
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
await (0, mqtt_js_1.initMqtt)(this); // 初始化mqtt任务
|
|
37
39
|
}
|
|
@@ -73,15 +73,34 @@ async function dispatchFriendFilterByMsgType(that, msg) {
|
|
|
73
73
|
case that.Message.Type.Image:
|
|
74
74
|
console.log(`发消息人${await contact.name()}:发了一张图片`);
|
|
75
75
|
break;
|
|
76
|
-
case that.Message.Type.Url:
|
|
77
|
-
console.log(`发消息人${await contact.name()}:发了一个链接`);
|
|
78
|
-
break;
|
|
79
76
|
case that.Message.Type.Video:
|
|
80
77
|
console.log(`发消息人${await contact.name()}:发了一个视频`);
|
|
81
78
|
break;
|
|
82
79
|
case that.Message.Type.Audio:
|
|
83
80
|
console.log(`发消息人${await contact.name()}:发了一个视频`);
|
|
84
81
|
break;
|
|
82
|
+
case that.Message.Type.MiniProgram:
|
|
83
|
+
console.log(`发消息人${await contact.name()}:发了一个小程序`);
|
|
84
|
+
const miniProgram = await msg.toMiniProgram();
|
|
85
|
+
if (config.parseMini && miniProgram.payload) {
|
|
86
|
+
const miniParse = `【小程序解析】\n\nappid:${miniProgram.appid()}\nusername:${miniProgram.username()}\n标题:${miniProgram.title()}\n描述:${miniProgram.description()}\n路径:${miniProgram.pagePath()}`;
|
|
87
|
+
contact.say(miniParse);
|
|
88
|
+
}
|
|
89
|
+
console.log('mini', miniProgram);
|
|
90
|
+
break;
|
|
91
|
+
case that.Message.Type.Url:
|
|
92
|
+
console.log(`发消息人${await contact.name()}:发了一个h5链接`);
|
|
93
|
+
const urlLink = await msg.toUrlLink();
|
|
94
|
+
if (config.parseMini && urlLink.payload) {
|
|
95
|
+
const urlParse = `【链接解析】\n\n标题:${urlLink.title()}\n描述:${urlLink.description()}\n链接:${urlLink.url()}\n缩略图:${urlLink.thumbnailUrl()}`;
|
|
96
|
+
contact.say(urlParse);
|
|
97
|
+
}
|
|
98
|
+
console.log('urlLink', urlLink);
|
|
99
|
+
break;
|
|
100
|
+
case that.Message.Type.Transfer:
|
|
101
|
+
console.log(`发消息人${await contact.name()}: 发起一个转账,请在手机接收`);
|
|
102
|
+
console.log('内容', msg.payload);
|
|
103
|
+
break;
|
|
85
104
|
default:
|
|
86
105
|
break;
|
|
87
106
|
}
|
|
@@ -108,7 +127,7 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
108
127
|
const receiver = msg.to();
|
|
109
128
|
let content = "";
|
|
110
129
|
let replys = "";
|
|
111
|
-
let contactId = contact.id
|
|
130
|
+
let contactId = contact.id;
|
|
112
131
|
let contactAvatar = await contact.avatar();
|
|
113
132
|
switch (type) {
|
|
114
133
|
case that.Message.Type.Text:
|
|
@@ -155,15 +174,34 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
155
174
|
case that.Message.Type.Image:
|
|
156
175
|
console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一张图片`);
|
|
157
176
|
break;
|
|
158
|
-
case that.Message.Type.Url:
|
|
159
|
-
console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个链接`);
|
|
160
|
-
break;
|
|
161
177
|
case that.Message.Type.Video:
|
|
162
178
|
console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个视频`);
|
|
163
179
|
break;
|
|
164
180
|
case that.Message.Type.Audio:
|
|
165
181
|
console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个语音`);
|
|
166
182
|
break;
|
|
183
|
+
case that.Message.Type.MiniProgram:
|
|
184
|
+
console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个小程序`);
|
|
185
|
+
const miniProgram = await msg.toMiniProgram();
|
|
186
|
+
if (config.parseMiniRooms.includes(roomName) && miniProgram.payload) {
|
|
187
|
+
const miniParse = `【小程序解析】\n\nappid:${miniProgram.appid()}\nusername:${miniProgram.username()}\n标题:${miniProgram.title()}\n描述:${miniProgram.description()}\n路径:${miniProgram.pagePath()}\n`;
|
|
188
|
+
room.say(miniParse);
|
|
189
|
+
}
|
|
190
|
+
console.log('mini', miniProgram);
|
|
191
|
+
break;
|
|
192
|
+
case that.Message.Type.Url:
|
|
193
|
+
console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个h5链接`);
|
|
194
|
+
const urlLink = await msg.toUrlLink();
|
|
195
|
+
if (config.parseMiniRooms.includes(roomName) && urlLink.payload) {
|
|
196
|
+
const urlParse = `【链接解析】\n\n标题:${urlLink.title()}\n描述:${urlLink.description()}\n链接:${urlLink.url()}\n缩略图:${urlLink.thumbnailUrl()}`;
|
|
197
|
+
room.say(urlParse);
|
|
198
|
+
}
|
|
199
|
+
console.log('urlLink', urlLink);
|
|
200
|
+
break;
|
|
201
|
+
case that.Message.Type.Transfer:
|
|
202
|
+
console.log(`群名: ${roomName} 发消息人: ${contactName} 发起了转账,请在手机查看`);
|
|
203
|
+
console.log('内容', msg.payload);
|
|
204
|
+
break;
|
|
167
205
|
default:
|
|
168
206
|
break;
|
|
169
207
|
}
|
|
@@ -43,6 +43,7 @@ export namespace packageJson {
|
|
|
43
43
|
prettier: string;
|
|
44
44
|
wechaty: string;
|
|
45
45
|
"wechaty-puppet-wechat": string;
|
|
46
|
+
"wechaty-puppet-wechat4u": string;
|
|
46
47
|
};
|
|
47
48
|
const readme: string;
|
|
48
49
|
namespace engines {
|
|
@@ -51,16 +52,17 @@ export namespace packageJson {
|
|
|
51
52
|
}
|
|
52
53
|
const dependencies: {
|
|
53
54
|
axios: string;
|
|
54
|
-
chatgpt: string;
|
|
55
55
|
ix: string;
|
|
56
56
|
jsonwebtoken: string;
|
|
57
57
|
mqtt: string;
|
|
58
58
|
mustache: string;
|
|
59
59
|
nedb: string;
|
|
60
60
|
"node-schedule": string;
|
|
61
|
-
|
|
61
|
+
openai: string;
|
|
62
62
|
puppeteer: string;
|
|
63
63
|
"qrcode-terminal": string;
|
|
64
|
+
remark: string;
|
|
65
|
+
"strip-markdown": string;
|
|
64
66
|
superagent: string;
|
|
65
67
|
};
|
|
66
68
|
namespace publishConfig {
|
|
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
exports.packageJson = {
|
|
8
8
|
"name": "wechaty-web-panel",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.4.0",
|
|
10
10
|
"description": "",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -34,7 +34,11 @@ exports.packageJson = {
|
|
|
34
34
|
"Wechaty",
|
|
35
35
|
"wechatEveryDay",
|
|
36
36
|
"wechaty",
|
|
37
|
-
"wechaty-plugin"
|
|
37
|
+
"wechaty-plugin",
|
|
38
|
+
"chatGPT",
|
|
39
|
+
"openai",
|
|
40
|
+
"chatBot",
|
|
41
|
+
"openGPT"
|
|
38
42
|
],
|
|
39
43
|
"author": {
|
|
40
44
|
"name": "Leo_chen",
|
|
@@ -56,7 +60,8 @@ exports.packageJson = {
|
|
|
56
60
|
"npm-run-all": "^4.1.5",
|
|
57
61
|
"prettier": "^2.0.5",
|
|
58
62
|
"wechaty": "^1.20.2",
|
|
59
|
-
"wechaty-puppet-wechat": "^1.18.4"
|
|
63
|
+
"wechaty-puppet-wechat": "^1.18.4",
|
|
64
|
+
"wechaty-puppet-wechat4u": "^1.13.12"
|
|
60
65
|
},
|
|
61
66
|
"readme": "README.md",
|
|
62
67
|
"engines": {
|
|
@@ -65,16 +70,17 @@ exports.packageJson = {
|
|
|
65
70
|
},
|
|
66
71
|
"dependencies": {
|
|
67
72
|
"axios": "^0.27.2",
|
|
68
|
-
"chatgpt": "^1.4.0",
|
|
69
73
|
"ix": "^4.5.2",
|
|
70
74
|
"jsonwebtoken": "^8.5.1",
|
|
71
75
|
"mqtt": "^4.2.6",
|
|
72
76
|
"mustache": "^4.2.0",
|
|
73
77
|
"nedb": "^1.8.0",
|
|
74
78
|
"node-schedule": "^1.3.2",
|
|
75
|
-
"
|
|
79
|
+
"openai": "^3.1.0",
|
|
76
80
|
"puppeteer": "^13.3.2",
|
|
77
81
|
"qrcode-terminal": "^0.12.0",
|
|
82
|
+
"remark": "^14.0.2",
|
|
83
|
+
"strip-markdown": "^5.0.0",
|
|
78
84
|
"superagent": "^5.2.2"
|
|
79
85
|
},
|
|
80
86
|
"publishConfig": {
|
|
@@ -122,7 +122,7 @@ async function getConfig() {
|
|
|
122
122
|
let content = await (0, superagent_js_1.aiBotReq)(option);
|
|
123
123
|
const config = JSON.parse(content.data.config);
|
|
124
124
|
const cloudRoom = await getWordCloudRoom();
|
|
125
|
-
let cres = await (0, configDb_js_1.updateConfig)({ puppetType: 'wechaty-puppet-wechat', ...config, cloudRoom });
|
|
125
|
+
let cres = await (0, configDb_js_1.updateConfig)({ puppetType: 'wechaty-puppet-wechat', botScope: 'all', parseMini: false, parseMiniRooms: [], preventLength: 1000, ...config, cloudRoom });
|
|
126
126
|
return cres;
|
|
127
127
|
}
|
|
128
128
|
catch (e) {
|
|
@@ -4,36 +4,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.geGPTReply = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const remark_1 = require("remark");
|
|
8
|
+
const strip_markdown_1 = __importDefault(require("strip-markdown"));
|
|
9
|
+
const openai_1 = require("openai");
|
|
9
10
|
const configDb_js_1 = require("../db/configDb.js");
|
|
11
|
+
let openai = null;
|
|
12
|
+
function markdownToText(markdown) {
|
|
13
|
+
return (0, remark_1.remark)()
|
|
14
|
+
.use(strip_markdown_1.default)
|
|
15
|
+
.processSync(markdown || '')
|
|
16
|
+
.toString();
|
|
17
|
+
}
|
|
10
18
|
async function geGPTReply(content) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
try {
|
|
20
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
21
|
+
if (!config.gpttoken) {
|
|
22
|
+
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
23
|
+
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
24
|
+
}
|
|
25
|
+
if (!openai) {
|
|
26
|
+
let configuration = new openai_1.Configuration({
|
|
27
|
+
apiKey: config.gpttoken,
|
|
28
|
+
});
|
|
29
|
+
openai = new openai_1.OpenAIApi(configuration);
|
|
30
|
+
}
|
|
31
|
+
let response = await openai.createCompletion({
|
|
32
|
+
model: 'text-davinci-003',
|
|
33
|
+
prompt: content,
|
|
34
|
+
temperature: 0.9,
|
|
35
|
+
max_tokens: 2000,
|
|
36
|
+
top_p: 1,
|
|
37
|
+
frequency_penalty: 0.0,
|
|
38
|
+
presence_penalty: 0.6,
|
|
39
|
+
stop: [' Human:', ' AI:'],
|
|
40
|
+
});
|
|
41
|
+
response = markdownToText(response.data.choices[0].text);
|
|
42
|
+
let replys = [];
|
|
43
|
+
let message = response;
|
|
44
|
+
while (message.length > 500) {
|
|
45
|
+
replys.push(message.slice(0, 500));
|
|
46
|
+
message = message.slice(500);
|
|
47
|
+
}
|
|
48
|
+
replys.push(message);
|
|
49
|
+
replys = replys.map(item => {
|
|
50
|
+
return {
|
|
51
|
+
type: 1,
|
|
52
|
+
content: item
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
return replys;
|
|
15
56
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const threeMinutesMs = 3 * 60 * 1000;
|
|
19
|
-
const response = await (0, p_timeout_1.default)(api.sendMessage(content), {
|
|
20
|
-
milliseconds: threeMinutesMs,
|
|
21
|
-
message: 'ChatGPT返回超时了,用的人太多,太火爆了,等会再试吧'
|
|
22
|
-
});
|
|
23
|
-
let replys = [];
|
|
24
|
-
let message = response;
|
|
25
|
-
while (message.length > 500) {
|
|
26
|
-
replys.push(message.slice(0, 500));
|
|
27
|
-
message = message.slice(500);
|
|
57
|
+
catch (e) {
|
|
58
|
+
return [{ type: 1, content: '现在询问我的人太多了,请稍后询问' }];
|
|
28
59
|
}
|
|
29
|
-
replys.push(message);
|
|
30
|
-
replys = replys.map(item => {
|
|
31
|
-
return {
|
|
32
|
-
type: 1,
|
|
33
|
-
content: item
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
return replys;
|
|
37
60
|
}
|
|
38
61
|
exports.geGPTReply = geGPTReply;
|
|
39
62
|
exports.default = {
|
|
@@ -145,7 +145,7 @@ function getFormatReply(answer, options = [], userInfo, puppetType) {
|
|
|
145
145
|
replys = [{ type: 1, content: '收到了一个小程序,但是小秘书还没学会展示😭,等等我回去再修炼五百年💪' }];
|
|
146
146
|
}
|
|
147
147
|
else {
|
|
148
|
-
replys = [{ type: 5, appid: answer.miniprogrampage.appid, title: answer.miniprogrampage.title, pagePath: answer.miniprogrampage.pagepath, description: answer.miniprogrampage.title, thumbUrl: answer.miniprogrampage.thumb_url, thumbKey: undefined, username:
|
|
148
|
+
replys = [{ type: 5, appid: answer.miniprogrampage.appid, title: answer.miniprogrampage.title, pagePath: answer.miniprogrampage.pagepath, description: answer.miniprogrampage.title, thumbUrl: answer.miniprogrampage.thumb_url, thumbKey: undefined, username: answer.miniprogrampage.appid }];
|
|
149
149
|
}
|
|
150
150
|
break;
|
|
151
151
|
default:
|
|
@@ -191,7 +191,7 @@ async function getTencentOpenReply({ msg, id, userInfo }) {
|
|
|
191
191
|
// 其他协议可以发链接的用H5卡片发送
|
|
192
192
|
const music = resData.msg[0];
|
|
193
193
|
return [
|
|
194
|
-
{ type: 4, url: music.url, title: music.title,
|
|
194
|
+
{ type: 4, url: music.url, title: music.title, thumbUrl: music.picurl, description: music.description },
|
|
195
195
|
];
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -45,7 +45,8 @@ async function filterFriendMsg(that, contact, msg) {
|
|
|
45
45
|
const avatar = await contact.avatar();
|
|
46
46
|
const resArray = [
|
|
47
47
|
{ bool: msg === '', method: 'emptyMsg' },
|
|
48
|
-
{ bool: msg.includes(DELETEFRIEND) || WEIXINOFFICIAL.includes(name)
|
|
48
|
+
{ bool: msg.includes(DELETEFRIEND) || WEIXINOFFICIAL.includes(name), method: 'officialMsg' },
|
|
49
|
+
{ bool: config.preventLength && msg.length > config.preventLength, method: 'maxLengthMsg' },
|
|
49
50
|
{ bool: msg.includes(NEWADDFRIEND), method: 'newFriendMsg' },
|
|
50
51
|
{ bool: config.roomJoinKeywords && config.roomJoinKeywords.length > 0, method: 'roomInviteMsg' },
|
|
51
52
|
{ bool: msg.startsWith(REMINDKEY), method: 'scheduleJobMsg' },
|
|
@@ -53,7 +54,7 @@ async function filterFriendMsg(that, contact, msg) {
|
|
|
53
54
|
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
54
55
|
{ bool: config.avatarList && config.avatarList.length > 0, method: 'avatarCrop' },
|
|
55
56
|
{ bool: true, method: 'keywordsMsg' },
|
|
56
|
-
{ bool: config.autoReply, method: 'robotMsg' },
|
|
57
|
+
{ bool: config.autoReply && config.botScope !== 'room', method: 'robotMsg' },
|
|
57
58
|
];
|
|
58
59
|
const msgArr = await getMsgReply(resArray, { that, msg, contact, name, config, avatar, id });
|
|
59
60
|
return msgArr.length > 0 ? msgArr : [{ type: 1, content: '', url: '' }];
|
|
@@ -84,7 +85,7 @@ async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention }) {
|
|
|
84
85
|
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
85
86
|
{ bool: config.avatarList && config.avatarList.length > 0, method: 'avatarCrop' },
|
|
86
87
|
{ bool: true, method: 'keywordsMsg' },
|
|
87
|
-
{ bool: config.autoReply, method: 'robotMsg' },
|
|
88
|
+
{ bool: config.autoReply && config.botScope !== 'friend', method: 'robotMsg' },
|
|
88
89
|
];
|
|
89
90
|
const msgArr = await getMsgReply(resArray, { that, msg, name, config, avatar, id, room, isMention });
|
|
90
91
|
return msgArr.length > 0 ? msgArr : [{ type: 1, content: '', url: '' }];
|
|
@@ -9,6 +9,7 @@ declare namespace _default {
|
|
|
9
9
|
export { eventMsg };
|
|
10
10
|
export { keywordsMsg };
|
|
11
11
|
export { robotMsg };
|
|
12
|
+
export { maxLengthMsg };
|
|
12
13
|
}
|
|
13
14
|
export default _default;
|
|
14
15
|
/**
|
|
@@ -104,4 +105,9 @@ export function robotMsg({ msg, name, id, config, isMention, room }: {
|
|
|
104
105
|
isMention: any;
|
|
105
106
|
room: any;
|
|
106
107
|
}): Promise<any[]>;
|
|
108
|
+
export function maxLengthMsg(): {
|
|
109
|
+
type: number;
|
|
110
|
+
content: string;
|
|
111
|
+
url: string;
|
|
112
|
+
}[];
|
|
107
113
|
//# sourceMappingURL=msg-filters.d.ts.map
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.robotMsg = exports.keywordsMsg = exports.eventMsg = exports.scheduleJobMsg = exports.roomInviteMsg = exports.newFriendMsg = exports.officialMsg = exports.emptyMsg = exports.avatarCrop = exports.callbackEvent = void 0;
|
|
6
|
+
exports.maxLengthMsg = exports.robotMsg = exports.keywordsMsg = exports.eventMsg = exports.scheduleJobMsg = exports.roomInviteMsg = exports.newFriendMsg = exports.officialMsg = exports.emptyMsg = exports.avatarCrop = exports.callbackEvent = void 0;
|
|
7
7
|
const event_dispatch_service_js_1 = __importDefault(require("./event-dispatch-service.js"));
|
|
8
8
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
9
9
|
const index_js_1 = require("../lib/index.js");
|
|
@@ -20,10 +20,15 @@ function emptyMsg({ room, isMention }) {
|
|
|
20
20
|
}
|
|
21
21
|
exports.emptyMsg = emptyMsg;
|
|
22
22
|
function officialMsg() {
|
|
23
|
-
console.log('
|
|
23
|
+
console.log('官方消息,不做回复');
|
|
24
24
|
return [{ type: 1, content: '', url: '' }];
|
|
25
25
|
}
|
|
26
26
|
exports.officialMsg = officialMsg;
|
|
27
|
+
function maxLengthMsg() {
|
|
28
|
+
console.log('字符超过设定值,不做回复');
|
|
29
|
+
return [{ type: 1, content: '', url: '' }];
|
|
30
|
+
}
|
|
31
|
+
exports.maxLengthMsg = maxLengthMsg;
|
|
27
32
|
function newFriendMsg({ config, name }) {
|
|
28
33
|
console.log(`新添加好友:${name},默认回复`);
|
|
29
34
|
return config.newFriendReplys || [{ type: 1, content: '', url: '' }];
|
|
@@ -154,8 +159,8 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
154
159
|
for (let item of config.callBackEvents) {
|
|
155
160
|
for (let key of item.keywords) {
|
|
156
161
|
if ((item.reg === 1 && msg.includes(key)) || (item.reg === 2 && msg === key)) {
|
|
157
|
-
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复
|
|
158
|
-
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention) {
|
|
162
|
+
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
163
|
+
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention || room && item.scope === 'friend' || !room && item.scope === 'room') {
|
|
159
164
|
return [];
|
|
160
165
|
}
|
|
161
166
|
msg = msg.trim();
|
|
@@ -194,8 +199,8 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
194
199
|
for (let item of config.eventKeywords) {
|
|
195
200
|
for (let key of item.keywords) {
|
|
196
201
|
if ((item.reg === 1 && msg.includes(key)) || (item.reg === 2 && msg === key)) {
|
|
197
|
-
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复
|
|
198
|
-
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention) {
|
|
202
|
+
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
203
|
+
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention || room && item.scope === 'friend' || !room && item.scope === 'room') {
|
|
199
204
|
return [];
|
|
200
205
|
}
|
|
201
206
|
msg = msg.replace(key, '');
|
|
@@ -221,8 +226,8 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
221
226
|
if (config.replyKeywords && config.replyKeywords.length > 0) {
|
|
222
227
|
for (let item of config.replyKeywords) {
|
|
223
228
|
if (item.reg === 2 && item.keywords.includes(msg)) {
|
|
224
|
-
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复
|
|
225
|
-
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention) {
|
|
229
|
+
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
230
|
+
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention || room && item.scope === 'friend' || !room && item.scope === 'room') {
|
|
226
231
|
return [];
|
|
227
232
|
}
|
|
228
233
|
console.log(`精确匹配到关键词${msg},正在回复用户`);
|
|
@@ -231,8 +236,8 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
231
236
|
else if (item.reg === 1) {
|
|
232
237
|
for (let key of item.keywords) {
|
|
233
238
|
if (msg.includes(key)) {
|
|
234
|
-
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复
|
|
235
|
-
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention) {
|
|
239
|
+
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
240
|
+
if (room && item.needAt === 1 && !isMention || room && item.needAt === undefined && !isMention || room && item.scope === 'friend' || !room && item.scope === 'room') {
|
|
236
241
|
return [];
|
|
237
242
|
}
|
|
238
243
|
console.log(`模糊匹配到关键词${msg},正在回复用户`);
|
|
@@ -349,5 +354,6 @@ exports.default = {
|
|
|
349
354
|
eventMsg,
|
|
350
355
|
keywordsMsg,
|
|
351
356
|
robotMsg,
|
|
357
|
+
maxLengthMsg
|
|
352
358
|
};
|
|
353
359
|
//# sourceMappingURL=msg-filters.js.map
|