wechaty-web-panel 1.6.67 → 1.6.68

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/cjs/src/botInstance/sdk/cozev3.d.ts +4 -3
  3. package/dist/cjs/src/botInstance/sdk/difyClient.d.ts +10 -9
  4. package/dist/cjs/src/botInstance/sdk/qanything.d.ts +2 -1
  5. package/dist/cjs/src/common/index.js +13 -2
  6. package/dist/cjs/src/handlers/on-callback-message.d.ts +3 -0
  7. package/dist/cjs/src/handlers/on-callback-message.js +178 -0
  8. package/dist/cjs/src/handlers/on-message.js +5 -1
  9. package/dist/cjs/src/index.d.ts +1 -0
  10. package/dist/cjs/src/index.js +8 -1
  11. package/dist/cjs/src/lib/oss.d.ts +2 -0
  12. package/dist/cjs/src/lib/oss.js +31 -0
  13. package/dist/cjs/src/package-json.d.ts +1 -0
  14. package/dist/cjs/src/package-json.js +2 -1
  15. package/dist/cjs/src/proxy/aibotk.js +3 -0
  16. package/dist/cjs/src/proxy/mqtt.js +36 -8
  17. package/dist/cjs/src/proxy/multimodal.js +3 -3
  18. package/dist/cjs/src/proxy/superagent.d.ts +3 -2
  19. package/dist/esm/src/botInstance/sdk/cozev3.d.ts +4 -3
  20. package/dist/esm/src/botInstance/sdk/difyClient.d.ts +10 -9
  21. package/dist/esm/src/botInstance/sdk/qanything.d.ts +2 -1
  22. package/dist/esm/src/common/index.js +13 -2
  23. package/dist/esm/src/handlers/on-callback-message.d.ts +3 -0
  24. package/dist/esm/src/handlers/on-callback-message.js +173 -0
  25. package/dist/esm/src/handlers/on-message.js +5 -1
  26. package/dist/esm/src/index.d.ts +1 -0
  27. package/dist/esm/src/index.js +7 -1
  28. package/dist/esm/src/lib/oss.d.ts +2 -0
  29. package/dist/esm/src/lib/oss.js +24 -0
  30. package/dist/esm/src/package-json.d.ts +1 -0
  31. package/dist/esm/src/package-json.js +2 -1
  32. package/dist/esm/src/proxy/aibotk.js +3 -0
  33. package/dist/esm/src/proxy/mqtt.js +38 -10
  34. package/dist/esm/src/proxy/multimodal.js +3 -3
  35. package/dist/esm/src/proxy/superagent.d.ts +3 -2
  36. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.6.68(2024-11-29)
4
+ 1、支持群消息带@
5
+
3
6
  ### V1.6.66(2024-10-25)
4
7
  1、修复发送消息问题
5
8
 
@@ -30,7 +30,7 @@ declare class CozeClient {
30
30
  botId: any;
31
31
  systemMessage: any;
32
32
  updateApiKey(apiKey: any): void;
33
- sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<import("axios").AxiosResponse<any, any>>;
33
+ sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<axios.AxiosResponse<any, any>>;
34
34
  sendRequest({ method, endpoint, data, params, stream, headerParams, timeoutMs }: {
35
35
  method: any;
36
36
  endpoint: any;
@@ -39,7 +39,7 @@ declare class CozeClient {
39
39
  stream?: boolean | undefined;
40
40
  headerParams?: {} | undefined;
41
41
  timeoutMs?: number | undefined;
42
- }): Promise<import("axios").AxiosResponse<any, any> | undefined>;
42
+ }): Promise<axios.AxiosResponse<any, any> | undefined>;
43
43
  getConversationId({ messages, timeoutMs }: {
44
44
  messages: any;
45
45
  timeoutMs: any;
@@ -49,7 +49,8 @@ declare class CozeClient {
49
49
  chatId: any;
50
50
  timeoutMs: any;
51
51
  }): Promise<any>;
52
- fileUpload(data: any): Promise<import("axios").AxiosResponse<any, any>>;
52
+ fileUpload(data: any): Promise<axios.AxiosResponse<any, any>>;
53
53
  }
54
+ import axios from "axios";
54
55
  export {};
55
56
  //# sourceMappingURL=cozev3.d.ts.map
@@ -67,7 +67,7 @@ export class DifyClient {
67
67
  stream: boolean;
68
68
  systemMessage: any;
69
69
  updateApiKey(apiKey: any): void;
70
- sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<import("axios").AxiosResponse<any, any>>;
70
+ sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<axios.AxiosResponse<any, any>>;
71
71
  sendRequest({ method, endpoint, data, params, stream, headerParams, timeoutMs }: {
72
72
  method: any;
73
73
  endpoint: any;
@@ -76,13 +76,13 @@ export class DifyClient {
76
76
  stream?: boolean | undefined;
77
77
  headerParams?: {} | undefined;
78
78
  timeoutMs?: number | undefined;
79
- }): Promise<import("axios").AxiosResponse<any, any>>;
80
- messageFeedback(messageId: any, rating: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
81
- getApplicationParameters(user: any): Promise<import("axios").AxiosResponse<any, any>>;
82
- fileUpload(data: any): Promise<import("axios").AxiosResponse<any, any>>;
79
+ }): Promise<axios.AxiosResponse<any, any>>;
80
+ messageFeedback(messageId: any, rating: any, user: any): Promise<axios.AxiosResponse<any, any>>;
81
+ getApplicationParameters(user: any): Promise<axios.AxiosResponse<any, any>>;
82
+ fileUpload(data: any): Promise<axios.AxiosResponse<any, any>>;
83
83
  }
84
84
  export class CompletionClient extends DifyClient {
85
- createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<import("axios").AxiosResponse<any, any>>;
85
+ createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<axios.AxiosResponse<any, any>>;
86
86
  }
87
87
  export class ChatClient extends DifyClient {
88
88
  sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files, inputs }: {
@@ -93,8 +93,9 @@ export class ChatClient extends DifyClient {
93
93
  files?: null | undefined;
94
94
  inputs: any;
95
95
  }): Promise<any>;
96
- getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<import("axios").AxiosResponse<any, any>>;
97
- getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<import("axios").AxiosResponse<any, any>>;
98
- renameConversation(conversationId: any, name: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
96
+ getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<axios.AxiosResponse<any, any>>;
97
+ getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<axios.AxiosResponse<any, any>>;
98
+ renameConversation(conversationId: any, name: any, user: any): Promise<axios.AxiosResponse<any, any>>;
99
99
  }
100
+ import axios from "axios";
100
101
  //# sourceMappingURL=difyClient.d.ts.map
@@ -29,7 +29,8 @@ declare class QAnyClient {
29
29
  stream?: boolean | undefined;
30
30
  headerParams?: {} | undefined;
31
31
  timeoutMs?: number | undefined;
32
- }): Promise<import("axios").AxiosResponse<any, any>>;
32
+ }): Promise<axios.AxiosResponse<any, any>>;
33
33
  }
34
+ import axios from "axios";
34
35
  export {};
35
36
  //# sourceMappingURL=qanything.d.ts.map
@@ -253,7 +253,12 @@ async function roomSay(room, contact, msg) {
253
253
  if (msg.type === 1 && msg.content) {
254
254
  const content = await formatContent(msg.content);
255
255
  // 文字
256
- contact ? await room.say(content, contact) : await room.say(content);
256
+ if (Array.isArray(contact)) {
257
+ await room.say(content, ...contact);
258
+ }
259
+ else {
260
+ contact ? await room.say(content, contact) : await room.say(content);
261
+ }
257
262
  void addReplyHistory(this, { content, contact: null, room: room });
258
263
  }
259
264
  else if (msg.type === 2 && msg.url) {
@@ -270,11 +275,17 @@ async function roomSay(room, contact, msg) {
270
275
  else if (msg.type === 3 && msg.url) {
271
276
  // bse64文件
272
277
  let obj = file_box_1.FileBox.fromDataURL(msg.url, 'room-avatar.jpg');
273
- contact ? await room.say('', contact) : '';
278
+ if (Array.isArray(contact)) {
279
+ await room.say('', ...contact);
280
+ }
281
+ else {
282
+ contact ? await room.say('', contact) : '';
283
+ }
274
284
  await (0, index_js_1.delay)(500);
275
285
  await room.say(obj);
276
286
  }
277
287
  else if (msg.type === 4 && msg.url && msg.title && msg.description) {
288
+ // @ts-ignore
278
289
  const description = await formatContent(msg.description);
279
290
  const title = await formatContent(msg.title);
280
291
  let url = new this.UrlLink({
@@ -0,0 +1,3 @@
1
+ export default onRecordMessage;
2
+ declare function onRecordMessage(msg: any): Promise<void>;
3
+ //# sourceMappingURL=on-callback-message.d.ts.map
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const configDb_js_1 = require("../db/configDb.js");
7
+ const oss_js_1 = require("../lib/oss.js");
8
+ const dayjs_1 = __importDefault(require("dayjs"));
9
+ const puppetDb_js_1 = require("../db/puppetDb.js");
10
+ const path_1 = __importDefault(require("path"));
11
+ const axios_1 = __importDefault(require("axios"));
12
+ async function onRecordMessage(msg) {
13
+ try {
14
+ const puppetInfo = await (0, puppetDb_js_1.getPuppetInfo)();
15
+ const config = await (0, configDb_js_1.allConfig)();
16
+ const conversationRecord = config.conversationRecord || {};
17
+ const { role } = config && config.userInfo || { role: 'default' };
18
+ if (role !== 'vip' || !conversationRecord?.open)
19
+ return;
20
+ const contact = msg.talker(); // 发消息人
21
+ const contactName = contact.name(); // 发消息人昵称
22
+ const contactAlias = await contact.alias();
23
+ const room = msg.room(); // 是否为群消息
24
+ const roomName = room ? await room.topic() : '';
25
+ const msgSelf = msg.self(); // 是否自己发给自己的消息
26
+ const type = msg.type();
27
+ const timestamp = msg.timestamp || (0, dayjs_1.default)().unix();
28
+ const robotInfo = this.currentUser;
29
+ const isOfficial = contact.type() === this.Contact.Type.Official;
30
+ if (msgSelf || isOfficial)
31
+ return;
32
+ console.log('msg', msg);
33
+ const baseMsg = {
34
+ conversionId: room ? room.id : contact.id,
35
+ conversionName: room ? roomName : contactName,
36
+ isRoom: !!room,
37
+ chatName: contactName,
38
+ chatId: contact.id,
39
+ chatAlias: contactAlias,
40
+ time: timestamp.length > 10 ? parseInt(timestamp / 1000) : timestamp
41
+ };
42
+ switch (type) {
43
+ case this.Message.Type.Channel:
44
+ baseMsg.type = '视频号';
45
+ const channelInfo = await msg.toChannel();
46
+ baseMsg.mediaInfo = {
47
+ nickname: channelInfo.nickname(),
48
+ coverUrl: channelInfo.coverUrl(),
49
+ avatar: channelInfo.avatar(),
50
+ desc: channelInfo.desc(),
51
+ url: channelInfo.url(),
52
+ objectId: channelInfo.objectId(),
53
+ objectNonceId: channelInfo.objectNonceId()
54
+ };
55
+ break;
56
+ case this.Message.Type.Contact:
57
+ baseMsg.type = '名片';
58
+ const contactInfo = await msg.toContact();
59
+ baseMsg.mediaInfo = {
60
+ name: contactInfo.name(),
61
+ avatar: contactInfo.payload.avatar || '',
62
+ wxid: contactInfo.id,
63
+ };
64
+ break;
65
+ case this.Message.Type.RedEnvelope:
66
+ baseMsg.type = '红包';
67
+ baseMsg.content = "收到红包";
68
+ break;
69
+ case this.Message.Type.Emoticon:
70
+ baseMsg.type = '自定义表情';
71
+ const emoticonFileBox = await msg.toFileBox();
72
+ const emoticonBuffer = await emoticonFileBox.toBuffer();
73
+ const emoticonUrl = await (0, oss_js_1.uploadOssFile)(`${conversationRecord?.ossConfig?.custom_path || ''}${emoticonFileBox.name}`, emoticonBuffer);
74
+ baseMsg.url = emoticonUrl;
75
+ break;
76
+ case this.Message.Type.Text:
77
+ baseMsg.type = '文字';
78
+ baseMsg.content = msg.text().trim();
79
+ break;
80
+ case this.Message.Type.Url:
81
+ const urlLink = await msg.toUrlLink();
82
+ baseMsg.type = 'h5链接';
83
+ baseMsg.mediaInfo = {
84
+ url: urlLink.url(),
85
+ description: urlLink.description(),
86
+ imageUrl: urlLink.thumbnailUrl(),
87
+ title: urlLink.title(),
88
+ };
89
+ break;
90
+ case this.Message.Type.MiniProgram:
91
+ const miniProgram = await msg.toMiniProgram();
92
+ const appid = puppetInfo.puppetType === 'PuppetService' ? miniProgram.username() : miniProgram.appid().replaceAll('@app', '');
93
+ const username = puppetInfo.puppetType === 'PuppetService' ? miniProgram.appid().replaceAll('@app', '') : miniProgram.username();
94
+ baseMsg.type = '小程序';
95
+ baseMsg.mediaInfo = {
96
+ url: decodeURIComponent(miniProgram.pagePath()),
97
+ appid,
98
+ username,
99
+ description: miniProgram.description(),
100
+ imageUrl: miniProgram.thumbnailUrl(),
101
+ title: miniProgram.title(),
102
+ };
103
+ break;
104
+ case this.Message.Type.Attachment:
105
+ case this.Message.Type.Image:
106
+ case this.Message.Type.Video:
107
+ const attachFileBox = await msg.toFileBox();
108
+ const fileExtname = path_1.default.extname(attachFileBox.name);
109
+ const isImage = fileExtname.includes('.png') || fileExtname.includes('.jpg') || fileExtname.includes('.jpeg') || fileExtname.includes('.gif');
110
+ baseMsg.type = isImage ? '图片' : '文件';
111
+ const buffer = await attachFileBox.toBuffer();
112
+ const url = await (0, oss_js_1.uploadOssFile)(`${conversationRecord?.ossConfig?.custom_path || ''}${attachFileBox.name}`, buffer);
113
+ baseMsg.url = url;
114
+ break;
115
+ case this.Message.Type.Audio:
116
+ baseMsg.type = '语音';
117
+ const audioFileBox = await msg.toFileBox();
118
+ const audioBuffer = await audioFileBox.toBuffer();
119
+ const audioUrl = await (0, oss_js_1.uploadOssFile)(`${conversationRecord?.ossConfig?.custom_path || ''}${audioFileBox.name}`, audioBuffer);
120
+ baseMsg.url = audioUrl;
121
+ break;
122
+ default:
123
+ break;
124
+ }
125
+ console.log('baseMsg', baseMsg);
126
+ sendMessage(baseMsg, conversationRecord, robotInfo);
127
+ }
128
+ catch (e) {
129
+ console.log('记录消息失败', e);
130
+ }
131
+ }
132
+ function sendMessage(msgInfo, recordConfig, robotInfo) {
133
+ const blackKey = ['conversationId', 'conversionName', 'isRoom', 'isRobot', 'chatName', 'chatId', 'chatAlias', 'time', 'type', 'url', 'mediaInfo', 'content'];
134
+ const baseData = {
135
+ ...msgInfo
136
+ };
137
+ recordConfig.moreData &&
138
+ recordConfig.moreData.length &&
139
+ recordConfig.moreData.forEach((mItem) => {
140
+ if (!blackKey.includes(mItem.key) && mItem.key && mItem.value) {
141
+ baseData[mItem.key] = mItem.value;
142
+ }
143
+ });
144
+ const timeout = recordConfig.timeout || 180;
145
+ const header = {
146
+ 'Content-Type': 'application/json'
147
+ };
148
+ recordConfig.header &&
149
+ recordConfig.header.length &&
150
+ recordConfig.header.forEach((mItem) => {
151
+ if (mItem.key && mItem.value) {
152
+ header[mItem.key] = mItem.value;
153
+ }
154
+ });
155
+ const config = {
156
+ url: recordConfig.customUrl,
157
+ method: 'POST',
158
+ timeout: timeout * 1000,
159
+ headers: header,
160
+ data: {
161
+ robotInfo: {
162
+ wxid: robotInfo.id,
163
+ name: robotInfo.name(),
164
+ },
165
+ message: baseData
166
+ }
167
+ };
168
+ if (recordConfig?.debug) {
169
+ console.log('消息回调请求参数', config);
170
+ }
171
+ axios_1.default.request(config).then((res) => {
172
+ console.log('消息发送成功', res);
173
+ }).catch((err) => {
174
+ console.log('消息发送失败', err);
175
+ });
176
+ }
177
+ exports.default = onRecordMessage;
178
+ //# sourceMappingURL=on-callback-message.js.map
@@ -248,7 +248,11 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
248
248
  else {
249
249
  content = msg.text();
250
250
  }
251
- const mentionSelf = await msg.mentionSelf() || content.includes(`@${userSelfName}`);
251
+ let mentionSelf = await msg.mentionSelf() || content.includes(`@${userSelfName}`);
252
+ const isMentionAll = await msg.isMentionAll();
253
+ if (config?.ignoreRoomMentionAll && isMentionAll && mentionSelf) {
254
+ mentionSelf = false;
255
+ }
252
256
  const receiverName = receiver?.name();
253
257
  content = content.replace('@' + receiverName, '').replace('@' + userSelfName, '').replace(/@[^,,::\s@]+/g, '').trim();
254
258
  console.log(`群名: ${roomName} 发消息人: ${contactName} 内容: ${content} | 机器人被@:${mentionSelf ? '是' : '否'}`);
@@ -4,4 +4,5 @@ export function WechatyWebPanelPlugin(config?: {
4
4
  scanTimes: any;
5
5
  }): (bot: any) => void;
6
6
  export function WechatyMessageRecordPlugin(): (bot: any) => void;
7
+ export function WechatyMessageCallBackPlugin(): (bot: any) => void;
7
8
  //# sourceMappingURL=index.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.WechatyMessageRecordPlugin = exports.WechatyWebPanelPlugin = void 0;
6
+ exports.WechatyMessageCallBackPlugin = exports.WechatyMessageRecordPlugin = exports.WechatyWebPanelPlugin = void 0;
7
7
  const global_js_1 = __importDefault(require("./db/global.js"));
8
8
  const aiDb_js_1 = require("./db/aiDb.js");
9
9
  const on_scan_js_1 = __importDefault(require("./handlers/on-scan.js"));
@@ -19,6 +19,7 @@ const on_roomtopic_js_1 = __importDefault(require("./handlers/on-roomtopic.js"))
19
19
  const on_roomleave_js_1 = __importDefault(require("./handlers/on-roomleave.js"));
20
20
  const on_verifycode_js_1 = __importDefault(require("./handlers/on-verifycode.js"));
21
21
  const on_record_message_js_1 = __importDefault(require("./handlers/on-record-message.js"));
22
+ const on_callback_message_js_1 = __importDefault(require("./handlers/on-callback-message.js"));
22
23
  const dayjs_1 = __importDefault(require("dayjs"));
23
24
  const originalConsoleLog = console.log;
24
25
  // 重写 console.log 方法
@@ -85,4 +86,10 @@ function WechatyMessageRecordPlugin() {
85
86
  };
86
87
  }
87
88
  exports.WechatyMessageRecordPlugin = WechatyMessageRecordPlugin;
89
+ function WechatyMessageCallBackPlugin() {
90
+ return function (bot) {
91
+ bot.on('message', on_callback_message_js_1.default);
92
+ };
93
+ }
94
+ exports.WechatyMessageCallBackPlugin = WechatyMessageCallBackPlugin;
88
95
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export function uploadOssFile(fileName: any, file: any): Promise<any>;
2
+ //# sourceMappingURL=oss.d.ts.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.uploadOssFile = void 0;
7
+ const ali_oss_1 = __importDefault(require("ali-oss"));
8
+ const configDb_js_1 = require("../db/configDb.js");
9
+ async function initStore() {
10
+ const config = await (0, configDb_js_1.allConfig)();
11
+ const ossConfig = config.conversationRecord && config.conversationRecord.ossConfig;
12
+ const options = {
13
+ region: ossConfig.region,
14
+ accessKeyId: ossConfig.aliAkId,
15
+ accessKeySecret: ossConfig.aliAkSecret,
16
+ bucket: ossConfig.bucket
17
+ };
18
+ if (ossConfig.custom_domain) {
19
+ options.endpoint = ossConfig.custom_domain;
20
+ }
21
+ const store = new ali_oss_1.default(options);
22
+ return store;
23
+ }
24
+ async function uploadOssFile(fileName, file) {
25
+ console.log('file', file);
26
+ const store = await initStore();
27
+ const result = await store.put(fileName, file);
28
+ return result?.url || '';
29
+ }
30
+ exports.uploadOssFile = uploadOssFile;
31
+ //# sourceMappingURL=oss.js.map
@@ -56,6 +56,7 @@ export namespace packageJson {
56
56
  }
57
57
  const dependencies: {
58
58
  "@dqbd/tiktoken": string;
59
+ "ali-oss": string;
59
60
  axios: string;
60
61
  "baidu-aip-sdk": string;
61
62
  dayjs: string;
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.6.67",
9
+ "version": "1.6.68",
10
10
  "description": "智能微秘书插件",
11
11
  "exports": {
12
12
  ".": {
@@ -77,6 +77,7 @@ exports.packageJson = {
77
77
  },
78
78
  "dependencies": {
79
79
  "@dqbd/tiktoken": "^1.0.2",
80
+ "ali-oss": "^6.21.0",
80
81
  "axios": "^1.6.6",
81
82
  "baidu-aip-sdk": "^4.16.10",
82
83
  "dayjs": "^1.11.7",
@@ -260,6 +260,9 @@ async function getConfig() {
260
260
  defaultReply: '',
261
261
  forwards: [],
262
262
  openRecord: false,
263
+ openWhisper: false,
264
+ whisperConfig: {},
265
+ ignoreRoomMentionAll: true,
263
266
  ...config,
264
267
  cloudRoom
265
268
  });
@@ -44,23 +44,32 @@ const global_js_1 = __importDefault(require("../db/global.js"));
44
44
  const on_scan_js_1 = require("../handlers/on-scan.js");
45
45
  const chatHistory_js_1 = require("../db/chatHistory.js");
46
46
  let mqttclient = null;
47
- async function sendRoomSay(that, room, messages) {
47
+ async function getContact(that, contact) {
48
+ const contactInfo = (contact.wxid && await that.Contact.find({ id: contact.wxid || '' })) || (contact.id && await that.Contact.find({ id: contact.id || '' })) || (contact.name && await that.Contact.find({ name: contact.name || '' })) || (contact.alias && await that.Contact.find({ alias: contact.alias || '' })) || (contact.weixin && await that.Contact.find({ weixin: contact.weixin || '' }));
49
+ return contactInfo;
50
+ }
51
+ async function getRoom(that, room) {
52
+ const roomInfo = (room.wxid && await that.Room.find({ id: room.wxid || '' })) || (room.id && await that.Room.find({ id: room.id || '' })) || (room.name && await that.Room.find({ topic: room.name || '' })) || (room.roomName && await that.Room.find({ topic: room.roomName || '' }));
53
+ return roomInfo;
54
+ }
55
+ async function sendRoomSay(that, room, messages, atList) {
48
56
  console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
49
- const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
57
+ const finalRoom = await getRoom(room);
50
58
  if (!finalRoom) {
51
59
  console.log(`查找不到群:${room.name},请检查群名是否正确`);
52
60
  return;
53
61
  }
54
62
  else {
55
63
  for (let message of messages) {
56
- await index_js_1.roomSay.call(that, finalRoom, '', message);
64
+ const atContacts = await getAtContacts(that, atList);
65
+ await index_js_1.roomSay.call(that, finalRoom, atContacts, message);
57
66
  await (0, index_js_3.delay)(500);
58
67
  }
59
68
  }
60
69
  }
61
70
  async function sendContactSay(that, contact, messages) {
62
71
  console.log(`收到好友:${contact.name}批量发送消息请求, 消息数量【${messages.length}】`);
63
- const finalContact = await that.Contact.find({ id: contact.id || '', name: contact.name, alias: contact.alias || '', weixin: contact.weixin || '' });
72
+ const finalContact = await getContact(that, contact);
64
73
  if (!finalContact) {
65
74
  console.log(`查找不到好友:${contact.name},请检查好友名称是否正确`);
66
75
  return;
@@ -72,9 +81,27 @@ async function sendContactSay(that, contact, messages) {
72
81
  }
73
82
  }
74
83
  }
84
+ async function getAtContacts(that, atList) {
85
+ if (!atList || atList.length === 0)
86
+ return '';
87
+ console.log('atList', atList);
88
+ let contacts = [];
89
+ for (let contact of atList) {
90
+ if (contact.id === '@all' || contact.name === '@all') {
91
+ contacts.push('@all');
92
+ return contacts;
93
+ }
94
+ let atContact = await getContact(that, contact);
95
+ if (atContact) {
96
+ contacts.push(atContact);
97
+ }
98
+ }
99
+ console.log('search contact', contacts);
100
+ return contacts;
101
+ }
75
102
  async function sendRoomsNotice(that, room, messages) {
76
103
  console.log(`收到群:${room.name}批量发送群公告请求, 公告数量【${messages.length}】`);
77
- const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
104
+ const finalRoom = await getRoom(that, room);
78
105
  if (!finalRoom) {
79
106
  console.log(`查找不到群:${room.name},请检查群名是否正确`);
80
107
  return;
@@ -132,12 +159,13 @@ async function initMqtt(that) {
132
159
  return;
133
160
  }
134
161
  else {
135
- await index_js_1.roomSay.call(that, room, '', content.message);
162
+ const atContacts = content?.atList && content?.atList.length ? await getAtContacts(that, content?.atList) : '';
163
+ await index_js_1.roomSay.call(that, room, atContacts, content.message);
136
164
  }
137
165
  }
138
166
  else if (content.target === 'Contact' || content.target === 'contact') {
139
167
  console.log(`收到联系人:${content.alias || content.name}发送消息请求: ${content.message.content || content.message.url}`);
140
- let contact = (content.wxid && await that.Contact.load(content.wxid)) || (await that.Contact.find({ name: content.name })) || (await that.Contact.find({ alias: content.alias })) || (await that.Contact.find({ weixin: content.weixin })); // 获取你要发送的联系人
168
+ let contact = await getContact(that, content); // 获取你要发送的联系人
141
169
  if (!contact) {
142
170
  console.log(`查找不到联系人:${content.name || content.alias},请检查联系人名称是否正确`);
143
171
  return;
@@ -151,7 +179,7 @@ async function initMqtt(that) {
151
179
  console.log('触发批量发送消息请求', content.target);
152
180
  if (content.target === 'Room' || content.target === 'room') {
153
181
  for (let room of content.groups) {
154
- await sendRoomSay(that, room, content.messages);
182
+ await sendRoomSay(that, room, content.messages, content?.atList);
155
183
  await (0, index_js_3.delay)(600);
156
184
  }
157
185
  }
@@ -26,7 +26,7 @@ async function getVoiceText(file, aiConfig) {
26
26
  let config = {
27
27
  method: 'post',
28
28
  maxBodyLength: Infinity,
29
- timeout: 60000,
29
+ timeout: 180000,
30
30
  url: config_js_1.AIBOTK_OUTAPI + '/voice/text',
31
31
  headers: {
32
32
  ...formData.getHeaders(),
@@ -62,7 +62,7 @@ async function getText2Speech(text, aiConfig) {
62
62
  let config = {
63
63
  method: 'post',
64
64
  maxBodyLength: Infinity,
65
- timeout: 60000,
65
+ timeout: 180000,
66
66
  url: config_js_1.AIBOTK_OUTAPI + '/text/speech',
67
67
  headers: {
68
68
  'Content-Type': 'application/json',
@@ -102,7 +102,7 @@ async function getImageVision(images, question, config) {
102
102
  const reqConfig = {
103
103
  method: 'post',
104
104
  maxBodyLength: Infinity,
105
- timeout: 60000,
105
+ timeout: 180000,
106
106
  url: config_js_1.AIBOTK_OUTAPI + '/image/vision',
107
107
  headers: {
108
108
  Authorization: `Bearer ${apiKey}`,
@@ -9,6 +9,7 @@ export default _default;
9
9
  export function req(option: any): Promise<any> | undefined;
10
10
  export function txReq(option: any): Promise<any>;
11
11
  export function aiBotReq(option: any): Promise<any>;
12
- export const service: import("axios").AxiosInstance;
13
- export function callbackAibotApi(url: any, data: any, timeout?: number): Promise<never[] | import("axios").AxiosResponse<any, any>>;
12
+ export const service: axios.AxiosInstance;
13
+ export function callbackAibotApi(url: any, data: any, timeout?: number): Promise<never[] | axios.AxiosResponse<any, any>>;
14
+ import axios from "axios";
14
15
  //# sourceMappingURL=superagent.d.ts.map
@@ -30,7 +30,7 @@ declare class CozeClient {
30
30
  botId: any;
31
31
  systemMessage: any;
32
32
  updateApiKey(apiKey: any): void;
33
- sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<import("axios").AxiosResponse<any, any>>;
33
+ sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<axios.AxiosResponse<any, any>>;
34
34
  sendRequest({ method, endpoint, data, params, stream, headerParams, timeoutMs }: {
35
35
  method: any;
36
36
  endpoint: any;
@@ -39,7 +39,7 @@ declare class CozeClient {
39
39
  stream?: boolean | undefined;
40
40
  headerParams?: {} | undefined;
41
41
  timeoutMs?: number | undefined;
42
- }): Promise<import("axios").AxiosResponse<any, any> | undefined>;
42
+ }): Promise<axios.AxiosResponse<any, any> | undefined>;
43
43
  getConversationId({ messages, timeoutMs }: {
44
44
  messages: any;
45
45
  timeoutMs: any;
@@ -49,7 +49,8 @@ declare class CozeClient {
49
49
  chatId: any;
50
50
  timeoutMs: any;
51
51
  }): Promise<any>;
52
- fileUpload(data: any): Promise<import("axios").AxiosResponse<any, any>>;
52
+ fileUpload(data: any): Promise<axios.AxiosResponse<any, any>>;
53
53
  }
54
+ import axios from "axios";
54
55
  export {};
55
56
  //# sourceMappingURL=cozev3.d.ts.map
@@ -67,7 +67,7 @@ export class DifyClient {
67
67
  stream: boolean;
68
68
  systemMessage: any;
69
69
  updateApiKey(apiKey: any): void;
70
- sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<import("axios").AxiosResponse<any, any>>;
70
+ sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<axios.AxiosResponse<any, any>>;
71
71
  sendRequest({ method, endpoint, data, params, stream, headerParams, timeoutMs }: {
72
72
  method: any;
73
73
  endpoint: any;
@@ -76,13 +76,13 @@ export class DifyClient {
76
76
  stream?: boolean | undefined;
77
77
  headerParams?: {} | undefined;
78
78
  timeoutMs?: number | undefined;
79
- }): Promise<import("axios").AxiosResponse<any, any>>;
80
- messageFeedback(messageId: any, rating: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
81
- getApplicationParameters(user: any): Promise<import("axios").AxiosResponse<any, any>>;
82
- fileUpload(data: any): Promise<import("axios").AxiosResponse<any, any>>;
79
+ }): Promise<axios.AxiosResponse<any, any>>;
80
+ messageFeedback(messageId: any, rating: any, user: any): Promise<axios.AxiosResponse<any, any>>;
81
+ getApplicationParameters(user: any): Promise<axios.AxiosResponse<any, any>>;
82
+ fileUpload(data: any): Promise<axios.AxiosResponse<any, any>>;
83
83
  }
84
84
  export class CompletionClient extends DifyClient {
85
- createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<import("axios").AxiosResponse<any, any>>;
85
+ createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<axios.AxiosResponse<any, any>>;
86
86
  }
87
87
  export class ChatClient extends DifyClient {
88
88
  sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files, inputs }: {
@@ -93,8 +93,9 @@ export class ChatClient extends DifyClient {
93
93
  files?: null | undefined;
94
94
  inputs: any;
95
95
  }): Promise<any>;
96
- getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<import("axios").AxiosResponse<any, any>>;
97
- getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<import("axios").AxiosResponse<any, any>>;
98
- renameConversation(conversationId: any, name: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
96
+ getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<axios.AxiosResponse<any, any>>;
97
+ getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<axios.AxiosResponse<any, any>>;
98
+ renameConversation(conversationId: any, name: any, user: any): Promise<axios.AxiosResponse<any, any>>;
99
99
  }
100
+ import axios from "axios";
100
101
  //# sourceMappingURL=difyClient.d.ts.map
@@ -29,7 +29,8 @@ declare class QAnyClient {
29
29
  stream?: boolean | undefined;
30
30
  headerParams?: {} | undefined;
31
31
  timeoutMs?: number | undefined;
32
- }): Promise<import("axios").AxiosResponse<any, any>>;
32
+ }): Promise<axios.AxiosResponse<any, any>>;
33
33
  }
34
+ import axios from "axios";
34
35
  export {};
35
36
  //# sourceMappingURL=qanything.d.ts.map
@@ -239,7 +239,12 @@ async function roomSay(room, contact, msg) {
239
239
  if (msg.type === 1 && msg.content) {
240
240
  const content = await formatContent(msg.content);
241
241
  // 文字
242
- contact ? await room.say(content, contact) : await room.say(content);
242
+ if (Array.isArray(contact)) {
243
+ await room.say(content, ...contact);
244
+ }
245
+ else {
246
+ contact ? await room.say(content, contact) : await room.say(content);
247
+ }
243
248
  void addReplyHistory(this, { content, contact: null, room: room });
244
249
  }
245
250
  else if (msg.type === 2 && msg.url) {
@@ -256,11 +261,17 @@ async function roomSay(room, contact, msg) {
256
261
  else if (msg.type === 3 && msg.url) {
257
262
  // bse64文件
258
263
  let obj = FileBox.fromDataURL(msg.url, 'room-avatar.jpg');
259
- contact ? await room.say('', contact) : '';
264
+ if (Array.isArray(contact)) {
265
+ await room.say('', ...contact);
266
+ }
267
+ else {
268
+ contact ? await room.say('', contact) : '';
269
+ }
260
270
  await delay(500);
261
271
  await room.say(obj);
262
272
  }
263
273
  else if (msg.type === 4 && msg.url && msg.title && msg.description) {
274
+ // @ts-ignore
264
275
  const description = await formatContent(msg.description);
265
276
  const title = await formatContent(msg.title);
266
277
  let url = new this.UrlLink({
@@ -0,0 +1,3 @@
1
+ export default onRecordMessage;
2
+ declare function onRecordMessage(msg: any): Promise<void>;
3
+ //# sourceMappingURL=on-callback-message.d.ts.map
@@ -0,0 +1,173 @@
1
+ import { allConfig } from '../db/configDb.js';
2
+ import { uploadOssFile } from "../lib/oss.js";
3
+ import dayjs from "dayjs";
4
+ import { getPuppetInfo } from "../db/puppetDb.js";
5
+ import path from "path";
6
+ import axios from "axios";
7
+ async function onRecordMessage(msg) {
8
+ try {
9
+ const puppetInfo = await getPuppetInfo();
10
+ const config = await allConfig();
11
+ const conversationRecord = config.conversationRecord || {};
12
+ const { role } = config && config.userInfo || { role: 'default' };
13
+ if (role !== 'vip' || !conversationRecord?.open)
14
+ return;
15
+ const contact = msg.talker(); // 发消息人
16
+ const contactName = contact.name(); // 发消息人昵称
17
+ const contactAlias = await contact.alias();
18
+ const room = msg.room(); // 是否为群消息
19
+ const roomName = room ? await room.topic() : '';
20
+ const msgSelf = msg.self(); // 是否自己发给自己的消息
21
+ const type = msg.type();
22
+ const timestamp = msg.timestamp || dayjs().unix();
23
+ const robotInfo = this.currentUser;
24
+ const isOfficial = contact.type() === this.Contact.Type.Official;
25
+ if (msgSelf || isOfficial)
26
+ return;
27
+ console.log('msg', msg);
28
+ const baseMsg = {
29
+ conversionId: room ? room.id : contact.id,
30
+ conversionName: room ? roomName : contactName,
31
+ isRoom: !!room,
32
+ chatName: contactName,
33
+ chatId: contact.id,
34
+ chatAlias: contactAlias,
35
+ time: timestamp.length > 10 ? parseInt(timestamp / 1000) : timestamp
36
+ };
37
+ switch (type) {
38
+ case this.Message.Type.Channel:
39
+ baseMsg.type = '视频号';
40
+ const channelInfo = await msg.toChannel();
41
+ baseMsg.mediaInfo = {
42
+ nickname: channelInfo.nickname(),
43
+ coverUrl: channelInfo.coverUrl(),
44
+ avatar: channelInfo.avatar(),
45
+ desc: channelInfo.desc(),
46
+ url: channelInfo.url(),
47
+ objectId: channelInfo.objectId(),
48
+ objectNonceId: channelInfo.objectNonceId()
49
+ };
50
+ break;
51
+ case this.Message.Type.Contact:
52
+ baseMsg.type = '名片';
53
+ const contactInfo = await msg.toContact();
54
+ baseMsg.mediaInfo = {
55
+ name: contactInfo.name(),
56
+ avatar: contactInfo.payload.avatar || '',
57
+ wxid: contactInfo.id,
58
+ };
59
+ break;
60
+ case this.Message.Type.RedEnvelope:
61
+ baseMsg.type = '红包';
62
+ baseMsg.content = "收到红包";
63
+ break;
64
+ case this.Message.Type.Emoticon:
65
+ baseMsg.type = '自定义表情';
66
+ const emoticonFileBox = await msg.toFileBox();
67
+ const emoticonBuffer = await emoticonFileBox.toBuffer();
68
+ const emoticonUrl = await uploadOssFile(`${conversationRecord?.ossConfig?.custom_path || ''}${emoticonFileBox.name}`, emoticonBuffer);
69
+ baseMsg.url = emoticonUrl;
70
+ break;
71
+ case this.Message.Type.Text:
72
+ baseMsg.type = '文字';
73
+ baseMsg.content = msg.text().trim();
74
+ break;
75
+ case this.Message.Type.Url:
76
+ const urlLink = await msg.toUrlLink();
77
+ baseMsg.type = 'h5链接';
78
+ baseMsg.mediaInfo = {
79
+ url: urlLink.url(),
80
+ description: urlLink.description(),
81
+ imageUrl: urlLink.thumbnailUrl(),
82
+ title: urlLink.title(),
83
+ };
84
+ break;
85
+ case this.Message.Type.MiniProgram:
86
+ const miniProgram = await msg.toMiniProgram();
87
+ const appid = puppetInfo.puppetType === 'PuppetService' ? miniProgram.username() : miniProgram.appid().replaceAll('@app', '');
88
+ const username = puppetInfo.puppetType === 'PuppetService' ? miniProgram.appid().replaceAll('@app', '') : miniProgram.username();
89
+ baseMsg.type = '小程序';
90
+ baseMsg.mediaInfo = {
91
+ url: decodeURIComponent(miniProgram.pagePath()),
92
+ appid,
93
+ username,
94
+ description: miniProgram.description(),
95
+ imageUrl: miniProgram.thumbnailUrl(),
96
+ title: miniProgram.title(),
97
+ };
98
+ break;
99
+ case this.Message.Type.Attachment:
100
+ case this.Message.Type.Image:
101
+ case this.Message.Type.Video:
102
+ const attachFileBox = await msg.toFileBox();
103
+ const fileExtname = path.extname(attachFileBox.name);
104
+ const isImage = fileExtname.includes('.png') || fileExtname.includes('.jpg') || fileExtname.includes('.jpeg') || fileExtname.includes('.gif');
105
+ baseMsg.type = isImage ? '图片' : '文件';
106
+ const buffer = await attachFileBox.toBuffer();
107
+ const url = await uploadOssFile(`${conversationRecord?.ossConfig?.custom_path || ''}${attachFileBox.name}`, buffer);
108
+ baseMsg.url = url;
109
+ break;
110
+ case this.Message.Type.Audio:
111
+ baseMsg.type = '语音';
112
+ const audioFileBox = await msg.toFileBox();
113
+ const audioBuffer = await audioFileBox.toBuffer();
114
+ const audioUrl = await uploadOssFile(`${conversationRecord?.ossConfig?.custom_path || ''}${audioFileBox.name}`, audioBuffer);
115
+ baseMsg.url = audioUrl;
116
+ break;
117
+ default:
118
+ break;
119
+ }
120
+ console.log('baseMsg', baseMsg);
121
+ sendMessage(baseMsg, conversationRecord, robotInfo);
122
+ }
123
+ catch (e) {
124
+ console.log('记录消息失败', e);
125
+ }
126
+ }
127
+ function sendMessage(msgInfo, recordConfig, robotInfo) {
128
+ const blackKey = ['conversationId', 'conversionName', 'isRoom', 'isRobot', 'chatName', 'chatId', 'chatAlias', 'time', 'type', 'url', 'mediaInfo', 'content'];
129
+ const baseData = {
130
+ ...msgInfo
131
+ };
132
+ recordConfig.moreData &&
133
+ recordConfig.moreData.length &&
134
+ recordConfig.moreData.forEach((mItem) => {
135
+ if (!blackKey.includes(mItem.key) && mItem.key && mItem.value) {
136
+ baseData[mItem.key] = mItem.value;
137
+ }
138
+ });
139
+ const timeout = recordConfig.timeout || 180;
140
+ const header = {
141
+ 'Content-Type': 'application/json'
142
+ };
143
+ recordConfig.header &&
144
+ recordConfig.header.length &&
145
+ recordConfig.header.forEach((mItem) => {
146
+ if (mItem.key && mItem.value) {
147
+ header[mItem.key] = mItem.value;
148
+ }
149
+ });
150
+ const config = {
151
+ url: recordConfig.customUrl,
152
+ method: 'POST',
153
+ timeout: timeout * 1000,
154
+ headers: header,
155
+ data: {
156
+ robotInfo: {
157
+ wxid: robotInfo.id,
158
+ name: robotInfo.name(),
159
+ },
160
+ message: baseData
161
+ }
162
+ };
163
+ if (recordConfig?.debug) {
164
+ console.log('消息回调请求参数', config);
165
+ }
166
+ axios.request(config).then((res) => {
167
+ console.log('消息发送成功', res);
168
+ }).catch((err) => {
169
+ console.log('消息发送失败', err);
170
+ });
171
+ }
172
+ export default onRecordMessage;
173
+ //# sourceMappingURL=on-callback-message.js.map
@@ -246,7 +246,11 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
246
246
  else {
247
247
  content = msg.text();
248
248
  }
249
- const mentionSelf = await msg.mentionSelf() || content.includes(`@${userSelfName}`);
249
+ let mentionSelf = await msg.mentionSelf() || content.includes(`@${userSelfName}`);
250
+ const isMentionAll = await msg.isMentionAll();
251
+ if (config?.ignoreRoomMentionAll && isMentionAll && mentionSelf) {
252
+ mentionSelf = false;
253
+ }
250
254
  const receiverName = receiver?.name();
251
255
  content = content.replace('@' + receiverName, '').replace('@' + userSelfName, '').replace(/@[^,,::\s@]+/g, '').trim();
252
256
  console.log(`群名: ${roomName} 发消息人: ${contactName} 内容: ${content} | 机器人被@:${mentionSelf ? '是' : '否'}`);
@@ -4,4 +4,5 @@ export function WechatyWebPanelPlugin(config?: {
4
4
  scanTimes: any;
5
5
  }): (bot: any) => void;
6
6
  export function WechatyMessageRecordPlugin(): (bot: any) => void;
7
+ export function WechatyMessageCallBackPlugin(): (bot: any) => void;
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -13,6 +13,7 @@ import onRoomtopic from './handlers/on-roomtopic.js';
13
13
  import onRoomleave from './handlers/on-roomleave.js';
14
14
  import onVerifyCode from './handlers/on-verifycode.js';
15
15
  import onRecordMessage from './handlers/on-record-message.js';
16
+ import onCallbackMessage from "./handlers/on-callback-message.js";
16
17
  import dayjs from "dayjs";
17
18
  const originalConsoleLog = console.log;
18
19
  // 重写 console.log 方法
@@ -77,5 +78,10 @@ function WechatyMessageRecordPlugin() {
77
78
  bot.on('message', onRecordMessage);
78
79
  };
79
80
  }
80
- export { WechatyWebPanelPlugin, WechatyMessageRecordPlugin };
81
+ function WechatyMessageCallBackPlugin() {
82
+ return function (bot) {
83
+ bot.on('message', onCallbackMessage);
84
+ };
85
+ }
86
+ export { WechatyWebPanelPlugin, WechatyMessageRecordPlugin, WechatyMessageCallBackPlugin };
81
87
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export function uploadOssFile(fileName: any, file: any): Promise<any>;
2
+ //# sourceMappingURL=oss.d.ts.map
@@ -0,0 +1,24 @@
1
+ import OSS from 'ali-oss';
2
+ import { allConfig } from '../db/configDb.js';
3
+ async function initStore() {
4
+ const config = await allConfig();
5
+ const ossConfig = config.conversationRecord && config.conversationRecord.ossConfig;
6
+ const options = {
7
+ region: ossConfig.region,
8
+ accessKeyId: ossConfig.aliAkId,
9
+ accessKeySecret: ossConfig.aliAkSecret,
10
+ bucket: ossConfig.bucket
11
+ };
12
+ if (ossConfig.custom_domain) {
13
+ options.endpoint = ossConfig.custom_domain;
14
+ }
15
+ const store = new OSS(options);
16
+ return store;
17
+ }
18
+ export async function uploadOssFile(fileName, file) {
19
+ console.log('file', file);
20
+ const store = await initStore();
21
+ const result = await store.put(fileName, file);
22
+ return result?.url || '';
23
+ }
24
+ //# sourceMappingURL=oss.js.map
@@ -56,6 +56,7 @@ export namespace packageJson {
56
56
  }
57
57
  const dependencies: {
58
58
  "@dqbd/tiktoken": string;
59
+ "ali-oss": string;
59
60
  axios: string;
60
61
  "baidu-aip-sdk": string;
61
62
  dayjs: string;
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.67",
6
+ "version": "1.6.68",
7
7
  "description": "智能微秘书插件",
8
8
  "exports": {
9
9
  ".": {
@@ -74,6 +74,7 @@ export const packageJson = {
74
74
  },
75
75
  "dependencies": {
76
76
  "@dqbd/tiktoken": "^1.0.2",
77
+ "ali-oss": "^6.21.0",
77
78
  "axios": "^1.6.6",
78
79
  "baidu-aip-sdk": "^4.16.10",
79
80
  "dayjs": "^1.11.7",
@@ -246,6 +246,9 @@ async function getConfig() {
246
246
  defaultReply: '',
247
247
  forwards: [],
248
248
  openRecord: false,
249
+ openWhisper: false,
250
+ whisperConfig: {},
251
+ ignoreRoomMentionAll: true,
249
252
  ...config,
250
253
  cloudRoom
251
254
  });
@@ -1,9 +1,9 @@
1
1
  import * as mqtt from 'mqtt';
2
2
  import { allConfig } from '../db/configDb.js';
3
3
  import { contactSay, roomSay, sendRoomNotice } from '../common/index.js';
4
- import { getConfig, getMqttConfig, getGptConfig, getRssConfig, getVerifyCode, getTasks } from "./aibotk.js";
4
+ import { getConfig, getGptConfig, getMqttConfig, getRssConfig, getTasks, getVerifyCode } from "./aibotk.js";
5
5
  import { dispatchEventContent } from '../service/event-dispatch-service.js';
6
- import { sendTaskMessage, initMultiTask, sendMultiTaskMessage } from "../task/index.js";
6
+ import { initMultiTask, sendMultiTaskMessage, sendTaskMessage } from "../task/index.js";
7
7
  import { delay, randomRange } from "../lib/index.js";
8
8
  import { reset } from './bot/chatgpt.js';
9
9
  import { reset as difyReset } from './bot/dify.js';
@@ -15,23 +15,32 @@ import globalConfig from "../db/global.js";
15
15
  import { resetScanTime } from '../handlers/on-scan.js';
16
16
  import { clearHistory } from "../db/chatHistory.js";
17
17
  let mqttclient = null;
18
- async function sendRoomSay(that, room, messages) {
18
+ async function getContact(that, contact) {
19
+ const contactInfo = (contact.wxid && await that.Contact.find({ id: contact.wxid || '' })) || (contact.id && await that.Contact.find({ id: contact.id || '' })) || (contact.name && await that.Contact.find({ name: contact.name || '' })) || (contact.alias && await that.Contact.find({ alias: contact.alias || '' })) || (contact.weixin && await that.Contact.find({ weixin: contact.weixin || '' }));
20
+ return contactInfo;
21
+ }
22
+ async function getRoom(that, room) {
23
+ const roomInfo = (room.wxid && await that.Room.find({ id: room.wxid || '' })) || (room.id && await that.Room.find({ id: room.id || '' })) || (room.name && await that.Room.find({ topic: room.name || '' })) || (room.roomName && await that.Room.find({ topic: room.roomName || '' }));
24
+ return roomInfo;
25
+ }
26
+ async function sendRoomSay(that, room, messages, atList) {
19
27
  console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
20
- const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
28
+ const finalRoom = await getRoom(room);
21
29
  if (!finalRoom) {
22
30
  console.log(`查找不到群:${room.name},请检查群名是否正确`);
23
31
  return;
24
32
  }
25
33
  else {
26
34
  for (let message of messages) {
27
- await roomSay.call(that, finalRoom, '', message);
35
+ const atContacts = await getAtContacts(that, atList);
36
+ await roomSay.call(that, finalRoom, atContacts, message);
28
37
  await delay(500);
29
38
  }
30
39
  }
31
40
  }
32
41
  async function sendContactSay(that, contact, messages) {
33
42
  console.log(`收到好友:${contact.name}批量发送消息请求, 消息数量【${messages.length}】`);
34
- const finalContact = await that.Contact.find({ id: contact.id || '', name: contact.name, alias: contact.alias || '', weixin: contact.weixin || '' });
43
+ const finalContact = await getContact(that, contact);
35
44
  if (!finalContact) {
36
45
  console.log(`查找不到好友:${contact.name},请检查好友名称是否正确`);
37
46
  return;
@@ -43,9 +52,27 @@ async function sendContactSay(that, contact, messages) {
43
52
  }
44
53
  }
45
54
  }
55
+ async function getAtContacts(that, atList) {
56
+ if (!atList || atList.length === 0)
57
+ return '';
58
+ console.log('atList', atList);
59
+ let contacts = [];
60
+ for (let contact of atList) {
61
+ if (contact.id === '@all' || contact.name === '@all') {
62
+ contacts.push('@all');
63
+ return contacts;
64
+ }
65
+ let atContact = await getContact(that, contact);
66
+ if (atContact) {
67
+ contacts.push(atContact);
68
+ }
69
+ }
70
+ console.log('search contact', contacts);
71
+ return contacts;
72
+ }
46
73
  async function sendRoomsNotice(that, room, messages) {
47
74
  console.log(`收到群:${room.name}批量发送群公告请求, 公告数量【${messages.length}】`);
48
- const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
75
+ const finalRoom = await getRoom(that, room);
49
76
  if (!finalRoom) {
50
77
  console.log(`查找不到群:${room.name},请检查群名是否正确`);
51
78
  return;
@@ -103,12 +130,13 @@ async function initMqtt(that) {
103
130
  return;
104
131
  }
105
132
  else {
106
- await roomSay.call(that, room, '', content.message);
133
+ const atContacts = content?.atList && content?.atList.length ? await getAtContacts(that, content?.atList) : '';
134
+ await roomSay.call(that, room, atContacts, content.message);
107
135
  }
108
136
  }
109
137
  else if (content.target === 'Contact' || content.target === 'contact') {
110
138
  console.log(`收到联系人:${content.alias || content.name}发送消息请求: ${content.message.content || content.message.url}`);
111
- let contact = (content.wxid && await that.Contact.load(content.wxid)) || (await that.Contact.find({ name: content.name })) || (await that.Contact.find({ alias: content.alias })) || (await that.Contact.find({ weixin: content.weixin })); // 获取你要发送的联系人
139
+ let contact = await getContact(that, content); // 获取你要发送的联系人
112
140
  if (!contact) {
113
141
  console.log(`查找不到联系人:${content.name || content.alias},请检查联系人名称是否正确`);
114
142
  return;
@@ -122,7 +150,7 @@ async function initMqtt(that) {
122
150
  console.log('触发批量发送消息请求', content.target);
123
151
  if (content.target === 'Room' || content.target === 'room') {
124
152
  for (let room of content.groups) {
125
- await sendRoomSay(that, room, content.messages);
153
+ await sendRoomSay(that, room, content.messages, content?.atList);
126
154
  await delay(600);
127
155
  }
128
156
  }
@@ -20,7 +20,7 @@ export async function getVoiceText(file, aiConfig) {
20
20
  let config = {
21
21
  method: 'post',
22
22
  maxBodyLength: Infinity,
23
- timeout: 60000,
23
+ timeout: 180000,
24
24
  url: AIBOTK_OUTAPI + '/voice/text',
25
25
  headers: {
26
26
  ...formData.getHeaders(),
@@ -55,7 +55,7 @@ export async function getText2Speech(text, aiConfig) {
55
55
  let config = {
56
56
  method: 'post',
57
57
  maxBodyLength: Infinity,
58
- timeout: 60000,
58
+ timeout: 180000,
59
59
  url: AIBOTK_OUTAPI + '/text/speech',
60
60
  headers: {
61
61
  'Content-Type': 'application/json',
@@ -94,7 +94,7 @@ export async function getImageVision(images, question, config) {
94
94
  const reqConfig = {
95
95
  method: 'post',
96
96
  maxBodyLength: Infinity,
97
- timeout: 60000,
97
+ timeout: 180000,
98
98
  url: AIBOTK_OUTAPI + '/image/vision',
99
99
  headers: {
100
100
  Authorization: `Bearer ${apiKey}`,
@@ -9,6 +9,7 @@ export default _default;
9
9
  export function req(option: any): Promise<any> | undefined;
10
10
  export function txReq(option: any): Promise<any>;
11
11
  export function aiBotReq(option: any): Promise<any>;
12
- export const service: import("axios").AxiosInstance;
13
- export function callbackAibotApi(url: any, data: any, timeout?: number): Promise<never[] | import("axios").AxiosResponse<any, any>>;
12
+ export const service: axios.AxiosInstance;
13
+ export function callbackAibotApi(url: any, data: any, timeout?: number): Promise<never[] | axios.AxiosResponse<any, any>>;
14
+ import axios from "axios";
14
15
  //# sourceMappingURL=superagent.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.67",
3
+ "version": "1.6.68",
4
4
  "description": "智能微秘书插件",
5
5
  "exports": {
6
6
  ".": {
@@ -71,6 +71,7 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "@dqbd/tiktoken": "^1.0.2",
74
+ "ali-oss": "^6.21.0",
74
75
  "axios": "^1.6.6",
75
76
  "baidu-aip-sdk": "^4.16.10",
76
77
  "dayjs": "^1.11.7",