wechaty-web-panel 1.6.21 → 1.6.23

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.6.23(2023-10-19)
4
+ 1、添加批量群发功能和批量群发公告功能
5
+
6
+ ### V1.6.22(2023-10-14)
7
+ 1、添加fastGPT单独支持,可以记录日志到fastGPT平台
8
+ 2、添加群公告发布功能,除web协议以外支持
9
+
3
10
  ### V1.6.20(2023-09-19)
4
11
  1、修复h5链接发送图片无效
5
12
 
@@ -59,7 +59,7 @@ declare class OfficialOpenAi {
59
59
  * @return {Promise<void>}
60
60
  */
61
61
  reset(): Promise<void>;
62
- getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
62
+ getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any): Promise<{
63
63
  type: number;
64
64
  content: any;
65
65
  }[]>;
@@ -112,10 +112,10 @@ class OfficialOpenAi {
112
112
  reset() {
113
113
  this.chatGPT = null;
114
114
  }
115
- async getReply(content, uid, adminId = '', systemMessage = '') {
115
+ async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
116
116
  try {
117
117
  if (!this.chatGPT) {
118
- console.log('看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
118
+ console.log(isFastGPT ? '看到此消息说明启用了fastgpt' : '看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
119
119
  await this.init();
120
120
  }
121
121
  if (this.config.filter) {
@@ -132,7 +132,14 @@ class OfficialOpenAi {
132
132
  return [{ type: 1, content: '上下文已重置' }];
133
133
  }
134
134
  }
135
- const { conversationId, text, id } = systemMessage ? await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 }) : await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 });
135
+ const sendParams = { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
136
+ if (systemMessage) {
137
+ sendParams.systemMessage = systemMessage;
138
+ }
139
+ if (isFastGPT) {
140
+ sendParams.chatId = uid;
141
+ }
142
+ const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
136
143
  if (this.config.filter) {
137
144
  const censor = await this.contentCensor.checkText(text);
138
145
  if (!censor) {
@@ -149,7 +149,7 @@ Current date: ${currentDate}`;
149
149
  }
150
150
  }
151
151
  async sendMessage(text, opts = {}) {
152
- const { parentMessageId, messageId = (0, uuid_1.v4)(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId } = opts;
152
+ const { parentMessageId, messageId = (0, uuid_1.v4)(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId } = opts;
153
153
  let { abortSignal } = opts;
154
154
  let abortController = null;
155
155
  if (timeoutMs && !abortSignal) {
@@ -185,6 +185,9 @@ Current date: ${currentDate}`;
185
185
  messages,
186
186
  stream
187
187
  };
188
+ if (chatId) {
189
+ body.chatId = chatId;
190
+ }
188
191
  if (this._apiOrg) {
189
192
  headers["OpenAI-Organization"] = this._apiOrg;
190
193
  }
@@ -8,32 +8,19 @@ const axios_1 = __importDefault(require("axios"));
8
8
  exports.BASE_URL = "https://api.dify.ai/v1";
9
9
  exports.routes = {
10
10
  application: {
11
- method: "GET",
12
- url: () => `/parameters`
13
- },
14
- feedback: {
15
- method: "POST",
16
- url: (messageId) => `/messages/${messageId}/feedbacks`
17
- },
18
- createCompletionMessage: {
19
- method: "POST",
20
- url: () => `/completion-messages`
21
- },
22
- createChatMessage: {
23
- method: "POST",
24
- url: () => `/chat-messages`
25
- },
26
- getConversationMessages: {
27
- method: "GET",
28
- url: () => "/messages"
29
- },
30
- getConversations: {
31
- method: "GET",
32
- url: () => "/conversations"
33
- },
34
- renameConversation: {
35
- method: "PATCH",
36
- url: (conversationId) => `/conversations/${conversationId}`
11
+ method: "GET", url: () => `/parameters`
12
+ }, feedback: {
13
+ method: "POST", url: (messageId) => `/messages/${messageId}/feedbacks`
14
+ }, createCompletionMessage: {
15
+ method: "POST", url: () => `/completion-messages`
16
+ }, createChatMessage: {
17
+ method: "POST", url: () => `/chat-messages`
18
+ }, getConversationMessages: {
19
+ method: "GET", url: () => "/messages"
20
+ }, getConversations: {
21
+ method: "GET", url: () => "/conversations"
22
+ }, renameConversation: {
23
+ method: "PATCH", url: (conversationId) => `/conversations/${conversationId}`
37
24
  }
38
25
  };
39
26
  class DifyClient {
@@ -48,8 +35,7 @@ class DifyClient {
48
35
  }
49
36
  async sendRequest({ method, endpoint, data, params, stream = false, timeoutMs = 60 * 1000 }) {
50
37
  const headers = {
51
- "Authorization": `Bearer ${this.apiKey}`,
52
- "Content-Type": "application/json"
38
+ "Authorization": `Bearer ${this.apiKey}`, "Content-Type": "application/json"
53
39
  };
54
40
  const url = `${this.baseUrl}${endpoint}`;
55
41
  let response;
@@ -69,17 +55,14 @@ class DifyClient {
69
55
  }
70
56
  else {
71
57
  response = await fetch(url, {
72
- headers,
73
- method,
74
- body: JSON.stringify(data)
58
+ headers, method, body: JSON.stringify(data)
75
59
  });
76
60
  }
77
61
  return response;
78
62
  }
79
63
  messageFeedback(messageId, rating, user) {
80
64
  const data = {
81
- rating,
82
- user
65
+ rating, user
83
66
  };
84
67
  return this.sendRequest({ method: exports.routes.feedback.method, endpoint: exports.routes.feedback.url(messageId), data });
85
68
  }
@@ -92,10 +75,7 @@ exports.DifyClient = DifyClient;
92
75
  class CompletionClient extends DifyClient {
93
76
  createCompletionMessage(inputs, query, user, responseMode) {
94
77
  const data = {
95
- inputs,
96
- query,
97
- responseMode,
98
- user
78
+ inputs, query, responseMode, user
99
79
  };
100
80
  return this.sendRequest({
101
81
  method: exports.routes.createCompletionMessage.method,
@@ -109,17 +89,14 @@ exports.CompletionClient = CompletionClient;
109
89
  class ChatClient extends DifyClient {
110
90
  async sendMessage(query, { systemMessage, user, responseMode = "json", conversationId = null, timeoutMs = 60 * 1000 }) {
111
91
  const data = {
112
- inputs: {},
113
- query,
114
- user,
115
- responseMode
92
+ inputs: {}, query, user, responseMode
116
93
  };
117
94
  if (systemMessage || this.systemMessage) {
118
- data.inputs['systemMessage'] = systemMessage || this.systemMessage;
95
+ data.inputs["systemMessage"] = systemMessage || this.systemMessage;
119
96
  }
120
97
  if (conversationId)
121
98
  data.conversation_id = conversationId;
122
- console.log('request data', data);
99
+ console.log("request data", data);
123
100
  const res = await this.sendRequest({
124
101
  method: exports.routes.createChatMessage.method,
125
102
  endpoint: exports.routes.createChatMessage.url(),
@@ -135,9 +112,7 @@ class ChatClient extends DifyClient {
135
112
  }
136
113
  const response = res.data;
137
114
  return {
138
- text: response.answer,
139
- conversationId: response.conversation_id,
140
- id: response.id
115
+ text: response.answer, conversationId: response.conversation_id, id: response.id
141
116
  };
142
117
  }
143
118
  getConversationMessages(user, conversationId = "", firstId = null, limit = null) {
@@ -149,21 +124,19 @@ class ChatClient extends DifyClient {
149
124
  if (limit)
150
125
  params.limit = limit;
151
126
  return this.sendRequest({
152
- method: exports.routes.getConversationMessages.method,
153
- endpoint: exports.routes.getConversationMessages.url(),
154
- params
127
+ method: exports.routes.getConversationMessages.method, endpoint: exports.routes.getConversationMessages.url(), params
155
128
  });
156
129
  }
157
130
  getConversations(user, firstId = null, limit = null, pinned = null) {
158
131
  const params = { user, first_id: firstId, limit, pinned };
159
- return this.sendRequest({ method: exports.routes.getConversations.method, endpoint: exports.routes.getConversations.url(), params });
132
+ return this.sendRequest({
133
+ method: exports.routes.getConversations.method, endpoint: exports.routes.getConversations.url(), params
134
+ });
160
135
  }
161
136
  renameConversation(conversationId, name, user) {
162
137
  const data = { name, user };
163
138
  return this.sendRequest({
164
- method: exports.routes.renameConversation.method,
165
- endpoint: exports.routes.renameConversation.url(conversationId),
166
- data
139
+ method: exports.routes.renameConversation.method, endpoint: exports.routes.renameConversation.url(conversationId), data
167
140
  });
168
141
  }
169
142
  }
@@ -91,4 +91,11 @@ export function getRoomEveryDayContent(date: any, city: any, endWord: any): Prom
91
91
  * @return {string}
92
92
  */
93
93
  export function getCountDownContent(date: any, prefix: any, suffix: any, endWord: any): string;
94
+ /**
95
+ * 发送群公告
96
+ * @param roomIds
97
+ * @param content
98
+ * @return {Promise<void>}
99
+ */
100
+ export function sendRoomNotice(room: any, content: any): Promise<void>;
94
101
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCountDownContent = exports.getRoomEveryDayContent = exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getNewsContent = exports.getEveryDayContent = exports.updateContactOnly = exports.updateRoomOnly = void 0;
3
+ exports.sendRoomNotice = exports.getCountDownContent = exports.getRoomEveryDayContent = exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getNewsContent = 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");
@@ -343,6 +343,20 @@ async function addRoom(that, contact, roomName, replys) {
343
343
  }
344
344
  }
345
345
  exports.addRoom = addRoom;
346
+ /**
347
+ * 发送群公告
348
+ * @param roomIds
349
+ * @param content
350
+ * @return {Promise<void>}
351
+ */
352
+ async function sendRoomNotice(room, content) {
353
+ const config = await (0, configDb_js_1.allConfig)();
354
+ const { role } = config.userInfo;
355
+ if (role === 'vip' && room && content) {
356
+ await room.announce(content);
357
+ }
358
+ }
359
+ exports.sendRoomNotice = sendRoomNotice;
346
360
  /**
347
361
  * 重新同步好友和群组
348
362
  * @param that
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.6.21",
9
+ "version": "1.6.23",
10
10
  "description": "智能微秘书插件",
11
11
  "exports": {
12
12
  ".": {
@@ -1,6 +1,6 @@
1
1
  export function reset(adminId: any): void;
2
2
  export function resetAll(): void;
3
- export function getChatGPTReply(content: any, uid: any, adminId: any, config?: {
3
+ export function getChatGPTReply(content: any, uid: any, adminId: any, config: {
4
4
  token: string;
5
5
  debug: boolean;
6
6
  proxyPass: string;
@@ -10,5 +10,5 @@ export function getChatGPTReply(content: any, uid: any, adminId: any, config?: {
10
10
  model: string;
11
11
  systemMessage: string;
12
12
  keywordSystemMessages: never[];
13
- }): Promise<any>;
13
+ } | undefined, isFastGPT: any): Promise<any>;
14
14
  //# sourceMappingURL=chatgpt.d.ts.map
@@ -23,7 +23,7 @@ function resetAll() {
23
23
  chatGPT = {};
24
24
  }
25
25
  exports.resetAll = resetAll;
26
- async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }) {
26
+ async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }, isFastGPT) {
27
27
  if (!config.token) {
28
28
  console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
29
29
  return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
@@ -41,7 +41,7 @@ async function getChatGPTReply(content, uid, adminId, config = { token: "", debu
41
41
  content = content.replace(finalSystemMsg.keyword, '');
42
42
  }
43
43
  }
44
- return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
44
+ return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage, isFastGPT);
45
45
  }
46
46
  exports.getChatGPTReply = getChatGPTReply;
47
47
  //# sourceMappingURL=chatgpt.js.map
@@ -22,7 +22,7 @@ async function dispatchBot({ botType, content, uid, adminId, config }) {
22
22
  switch (botType) {
23
23
  case 6:
24
24
  // ChatGPT api
25
- res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config);
25
+ res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config, false);
26
26
  replys = res;
27
27
  break;
28
28
  case 7:
@@ -37,6 +37,11 @@ async function dispatchBot({ botType, content, uid, adminId, config }) {
37
37
  res = await (0, dify_js_1.getDifyAiReply)(content, uid, adminId, config);
38
38
  replys = res;
39
39
  break;
40
+ case 9:
41
+ // fastGPT api
42
+ res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config, true);
43
+ replys = res;
44
+ break;
40
45
  default:
41
46
  replys = [];
42
47
  break;
@@ -36,6 +36,48 @@ const chatgpt_web_js_1 = require("./bot/chatgpt-web.js");
36
36
  const dify_js_1 = require("./bot/dify.js");
37
37
  const rss_js_1 = require("../task/rss.js");
38
38
  let mqttclient = null;
39
+ async function sendRoomSay(that, room, messages) {
40
+ console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
41
+ const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
42
+ if (!finalRoom) {
43
+ console.log(`查找不到群:${room.name},请检查群名是否正确`);
44
+ return;
45
+ }
46
+ else {
47
+ for (let message of messages) {
48
+ await index_js_1.roomSay.call(that, finalRoom, '', message);
49
+ await (0, index_js_3.delay)(500);
50
+ }
51
+ }
52
+ }
53
+ async function sendContactSay(that, contact, messages) {
54
+ console.log(`收到好友:${contact.name}批量发送消息请求, 消息数量【${messages.length}】`);
55
+ const finalContact = await that.Contact.find({ id: contact.id || '', name: contact.name, alias: contact.alias || '', weixin: contact.weixin || '' });
56
+ if (!finalContact) {
57
+ console.log(`查找不到好友:${contact.name},请检查好友名称是否正确`);
58
+ return;
59
+ }
60
+ else {
61
+ for (let message of messages) {
62
+ await index_js_1.contactSay.call(that, finalContact, message);
63
+ await (0, index_js_3.delay)(500);
64
+ }
65
+ }
66
+ }
67
+ async function sendRoomsNotice(that, room, messages) {
68
+ console.log(`收到群:${room.name}批量发送群公告请求, 公告数量【${messages.length}】`);
69
+ const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
70
+ if (!finalRoom) {
71
+ console.log(`查找不到群:${room.name},请检查群名是否正确`);
72
+ return;
73
+ }
74
+ else {
75
+ for (let message of messages) {
76
+ await index_js_1.sendRoomNotice.call(that, finalRoom, message.content);
77
+ await (0, index_js_3.delay)(500);
78
+ }
79
+ }
80
+ }
39
81
  async function initMqtt(that) {
40
82
  try {
41
83
  await (0, aibotk_js_1.getConfig)(); // 获取配置文件
@@ -97,6 +139,27 @@ async function initMqtt(that) {
97
139
  }
98
140
  }
99
141
  }
142
+ if (topic === `aibotk/${userId}/multisay`) {
143
+ console.log('触发批量发送消息请求', content.target);
144
+ if (content.target === 'Room') {
145
+ for (let room of content.groups) {
146
+ await sendRoomSay(that, room, content.messages);
147
+ await (0, index_js_3.delay)(600);
148
+ }
149
+ }
150
+ else if (content.target === 'Contact') {
151
+ for (let contact of content.groups) {
152
+ await sendContactSay(that, contact, content.messages);
153
+ await (0, index_js_3.delay)(600);
154
+ }
155
+ }
156
+ else if (content.target === 'RoomNotice') {
157
+ for (let room of content.groups) {
158
+ await sendRoomsNotice(that, room, content.messages);
159
+ await (0, index_js_3.delay)(600);
160
+ }
161
+ }
162
+ }
100
163
  else if (topic === `aibotk/${userId}/event`) {
101
164
  if (content.target === 'system') {
102
165
  console.log('触发了内置事件');
@@ -2,5 +2,5 @@
2
2
  * 重置实例
3
3
  */
4
4
  export function reset(): void;
5
- export function getGptOfficialReply(content: any, uid: any): Promise<any>;
5
+ export function getGptOfficialReply(content: any, uid: any, isFastGPT: any): Promise<any>;
6
6
  //# sourceMappingURL=openAi.d.ts.map
@@ -17,7 +17,7 @@ function reset() {
17
17
  }
18
18
  }
19
19
  exports.reset = reset;
20
- async function getGptOfficialReply(content, uid) {
20
+ async function getGptOfficialReply(content, uid, isFastGPT) {
21
21
  const config = await (0, configDb_js_1.allConfig)();
22
22
  if (!config.gpttoken) {
23
23
  console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
@@ -43,7 +43,7 @@ async function getGptOfficialReply(content, uid) {
43
43
  if (!chatGPT) {
44
44
  chatGPT = new officialOpenAi_js_1.default(chatConfig);
45
45
  }
46
- return await chatGPT.getReply(content, uid);
46
+ return await chatGPT.getReply(content, uid, '', '', isFastGPT);
47
47
  }
48
48
  exports.getGptOfficialReply = getGptOfficialReply;
49
49
  //# sourceMappingURL=openAi.js.map
@@ -164,8 +164,8 @@ async function dispatchAiBot(bot, msg, name, id) {
164
164
  replys = res;
165
165
  break;
166
166
  case 6:
167
- // ChatGPT3
168
- res = await (0, openAi_js_1.getGptOfficialReply)(msg, id);
167
+ // ChatGPT-api
168
+ res = await (0, openAi_js_1.getGptOfficialReply)(msg, id, false);
169
169
  replys = res;
170
170
  break;
171
171
  case 7:
@@ -178,6 +178,11 @@ async function dispatchAiBot(bot, msg, name, id) {
178
178
  res = await (0, difyAi_js_1.getDifyReply)(msg, id);
179
179
  replys = res;
180
180
  break;
181
+ case 9:
182
+ // fast gpt
183
+ res = await (0, openAi_js_1.getGptOfficialReply)(msg, id, true);
184
+ replys = res;
185
+ break;
181
186
  default:
182
187
  replys = [{ type: 1, content: '' }];
183
188
  break;
@@ -59,7 +59,7 @@ declare class OfficialOpenAi {
59
59
  * @return {Promise<void>}
60
60
  */
61
61
  reset(): Promise<void>;
62
- getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
62
+ getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any): Promise<{
63
63
  type: number;
64
64
  content: any;
65
65
  }[]>;
@@ -107,10 +107,10 @@ class OfficialOpenAi {
107
107
  reset() {
108
108
  this.chatGPT = null;
109
109
  }
110
- async getReply(content, uid, adminId = '', systemMessage = '') {
110
+ async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
111
111
  try {
112
112
  if (!this.chatGPT) {
113
- console.log('看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
113
+ console.log(isFastGPT ? '看到此消息说明启用了fastgpt' : '看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
114
114
  await this.init();
115
115
  }
116
116
  if (this.config.filter) {
@@ -127,7 +127,14 @@ class OfficialOpenAi {
127
127
  return [{ type: 1, content: '上下文已重置' }];
128
128
  }
129
129
  }
130
- const { conversationId, text, id } = systemMessage ? await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 }) : await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 });
130
+ const sendParams = { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
131
+ if (systemMessage) {
132
+ sendParams.systemMessage = systemMessage;
133
+ }
134
+ if (isFastGPT) {
135
+ sendParams.chatId = uid;
136
+ }
137
+ const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
131
138
  if (this.config.filter) {
132
139
  const censor = await this.contentCensor.checkText(text);
133
140
  if (!censor) {
@@ -141,7 +141,7 @@ Current date: ${currentDate}`;
141
141
  }
142
142
  }
143
143
  async sendMessage(text, opts = {}) {
144
- const { parentMessageId, messageId = uuidv4(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId } = opts;
144
+ const { parentMessageId, messageId = uuidv4(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId } = opts;
145
145
  let { abortSignal } = opts;
146
146
  let abortController = null;
147
147
  if (timeoutMs && !abortSignal) {
@@ -177,6 +177,9 @@ Current date: ${currentDate}`;
177
177
  messages,
178
178
  stream
179
179
  };
180
+ if (chatId) {
181
+ body.chatId = chatId;
182
+ }
180
183
  if (this._apiOrg) {
181
184
  headers["OpenAI-Organization"] = this._apiOrg;
182
185
  }
@@ -2,32 +2,19 @@ import axios from "axios";
2
2
  export const BASE_URL = "https://api.dify.ai/v1";
3
3
  export const routes = {
4
4
  application: {
5
- method: "GET",
6
- url: () => `/parameters`
7
- },
8
- feedback: {
9
- method: "POST",
10
- url: (messageId) => `/messages/${messageId}/feedbacks`
11
- },
12
- createCompletionMessage: {
13
- method: "POST",
14
- url: () => `/completion-messages`
15
- },
16
- createChatMessage: {
17
- method: "POST",
18
- url: () => `/chat-messages`
19
- },
20
- getConversationMessages: {
21
- method: "GET",
22
- url: () => "/messages"
23
- },
24
- getConversations: {
25
- method: "GET",
26
- url: () => "/conversations"
27
- },
28
- renameConversation: {
29
- method: "PATCH",
30
- url: (conversationId) => `/conversations/${conversationId}`
5
+ method: "GET", url: () => `/parameters`
6
+ }, feedback: {
7
+ method: "POST", url: (messageId) => `/messages/${messageId}/feedbacks`
8
+ }, createCompletionMessage: {
9
+ method: "POST", url: () => `/completion-messages`
10
+ }, createChatMessage: {
11
+ method: "POST", url: () => `/chat-messages`
12
+ }, getConversationMessages: {
13
+ method: "GET", url: () => "/messages"
14
+ }, getConversations: {
15
+ method: "GET", url: () => "/conversations"
16
+ }, renameConversation: {
17
+ method: "PATCH", url: (conversationId) => `/conversations/${conversationId}`
31
18
  }
32
19
  };
33
20
  export class DifyClient {
@@ -42,8 +29,7 @@ export class DifyClient {
42
29
  }
43
30
  async sendRequest({ method, endpoint, data, params, stream = false, timeoutMs = 60 * 1000 }) {
44
31
  const headers = {
45
- "Authorization": `Bearer ${this.apiKey}`,
46
- "Content-Type": "application/json"
32
+ "Authorization": `Bearer ${this.apiKey}`, "Content-Type": "application/json"
47
33
  };
48
34
  const url = `${this.baseUrl}${endpoint}`;
49
35
  let response;
@@ -63,17 +49,14 @@ export class DifyClient {
63
49
  }
64
50
  else {
65
51
  response = await fetch(url, {
66
- headers,
67
- method,
68
- body: JSON.stringify(data)
52
+ headers, method, body: JSON.stringify(data)
69
53
  });
70
54
  }
71
55
  return response;
72
56
  }
73
57
  messageFeedback(messageId, rating, user) {
74
58
  const data = {
75
- rating,
76
- user
59
+ rating, user
77
60
  };
78
61
  return this.sendRequest({ method: routes.feedback.method, endpoint: routes.feedback.url(messageId), data });
79
62
  }
@@ -85,10 +68,7 @@ export class DifyClient {
85
68
  export class CompletionClient extends DifyClient {
86
69
  createCompletionMessage(inputs, query, user, responseMode) {
87
70
  const data = {
88
- inputs,
89
- query,
90
- responseMode,
91
- user
71
+ inputs, query, responseMode, user
92
72
  };
93
73
  return this.sendRequest({
94
74
  method: routes.createCompletionMessage.method,
@@ -101,17 +81,14 @@ export class CompletionClient extends DifyClient {
101
81
  export class ChatClient extends DifyClient {
102
82
  async sendMessage(query, { systemMessage, user, responseMode = "json", conversationId = null, timeoutMs = 60 * 1000 }) {
103
83
  const data = {
104
- inputs: {},
105
- query,
106
- user,
107
- responseMode
84
+ inputs: {}, query, user, responseMode
108
85
  };
109
86
  if (systemMessage || this.systemMessage) {
110
- data.inputs['systemMessage'] = systemMessage || this.systemMessage;
87
+ data.inputs["systemMessage"] = systemMessage || this.systemMessage;
111
88
  }
112
89
  if (conversationId)
113
90
  data.conversation_id = conversationId;
114
- console.log('request data', data);
91
+ console.log("request data", data);
115
92
  const res = await this.sendRequest({
116
93
  method: routes.createChatMessage.method,
117
94
  endpoint: routes.createChatMessage.url(),
@@ -127,9 +104,7 @@ export class ChatClient extends DifyClient {
127
104
  }
128
105
  const response = res.data;
129
106
  return {
130
- text: response.answer,
131
- conversationId: response.conversation_id,
132
- id: response.id
107
+ text: response.answer, conversationId: response.conversation_id, id: response.id
133
108
  };
134
109
  }
135
110
  getConversationMessages(user, conversationId = "", firstId = null, limit = null) {
@@ -141,21 +116,19 @@ export class ChatClient extends DifyClient {
141
116
  if (limit)
142
117
  params.limit = limit;
143
118
  return this.sendRequest({
144
- method: routes.getConversationMessages.method,
145
- endpoint: routes.getConversationMessages.url(),
146
- params
119
+ method: routes.getConversationMessages.method, endpoint: routes.getConversationMessages.url(), params
147
120
  });
148
121
  }
149
122
  getConversations(user, firstId = null, limit = null, pinned = null) {
150
123
  const params = { user, first_id: firstId, limit, pinned };
151
- return this.sendRequest({ method: routes.getConversations.method, endpoint: routes.getConversations.url(), params });
124
+ return this.sendRequest({
125
+ method: routes.getConversations.method, endpoint: routes.getConversations.url(), params
126
+ });
152
127
  }
153
128
  renameConversation(conversationId, name, user) {
154
129
  const data = { name, user };
155
130
  return this.sendRequest({
156
- method: routes.renameConversation.method,
157
- endpoint: routes.renameConversation.url(conversationId),
158
- data
131
+ method: routes.renameConversation.method, endpoint: routes.renameConversation.url(conversationId), data
159
132
  });
160
133
  }
161
134
  }
@@ -91,4 +91,11 @@ export function getRoomEveryDayContent(date: any, city: any, endWord: any): Prom
91
91
  * @return {string}
92
92
  */
93
93
  export function getCountDownContent(date: any, prefix: any, suffix: any, endWord: any): string;
94
+ /**
95
+ * 发送群公告
96
+ * @param roomIds
97
+ * @param content
98
+ * @return {Promise<void>}
99
+ */
100
+ export function sendRoomNotice(room: any, content: any): Promise<void>;
94
101
  //# sourceMappingURL=index.d.ts.map
@@ -330,6 +330,19 @@ async function addRoom(that, contact, roomName, replys) {
330
330
  console.log(`不存在此群:${roomName}`);
331
331
  }
332
332
  }
333
+ /**
334
+ * 发送群公告
335
+ * @param roomIds
336
+ * @param content
337
+ * @return {Promise<void>}
338
+ */
339
+ async function sendRoomNotice(room, content) {
340
+ const config = await allConfig();
341
+ const { role } = config.userInfo;
342
+ if (role === 'vip' && room && content) {
343
+ await room.announce(content);
344
+ }
345
+ }
333
346
  /**
334
347
  * 重新同步好友和群组
335
348
  * @param that
@@ -380,6 +393,7 @@ export { addRoomWelcomeSay };
380
393
  export { updateContactAndRoom };
381
394
  export { getRoomEveryDayContent };
382
395
  export { getCountDownContent };
396
+ export { sendRoomNotice };
383
397
  export default {
384
398
  updateRoomOnly,
385
399
  updateContactOnly,
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.21",
6
+ "version": "1.6.23",
7
7
  "description": "智能微秘书插件",
8
8
  "exports": {
9
9
  ".": {
@@ -1,6 +1,6 @@
1
1
  export function reset(adminId: any): void;
2
2
  export function resetAll(): void;
3
- export function getChatGPTReply(content: any, uid: any, adminId: any, config?: {
3
+ export function getChatGPTReply(content: any, uid: any, adminId: any, config: {
4
4
  token: string;
5
5
  debug: boolean;
6
6
  proxyPass: string;
@@ -10,5 +10,5 @@ export function getChatGPTReply(content: any, uid: any, adminId: any, config?: {
10
10
  model: string;
11
11
  systemMessage: string;
12
12
  keywordSystemMessages: never[];
13
- }): Promise<any>;
13
+ } | undefined, isFastGPT: any): Promise<any>;
14
14
  //# sourceMappingURL=chatgpt.d.ts.map
@@ -15,7 +15,7 @@ export function resetAll() {
15
15
  });
16
16
  chatGPT = {};
17
17
  }
18
- export async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }) {
18
+ export async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }, isFastGPT) {
19
19
  if (!config.token) {
20
20
  console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
21
21
  return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
@@ -33,6 +33,6 @@ export async function getChatGPTReply(content, uid, adminId, config = { token: "
33
33
  content = content.replace(finalSystemMsg.keyword, '');
34
34
  }
35
35
  }
36
- return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
36
+ return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage, isFastGPT);
37
37
  }
38
38
  //# sourceMappingURL=chatgpt.js.map
@@ -16,7 +16,7 @@ export async function dispatchBot({ botType, content, uid, adminId, config }) {
16
16
  switch (botType) {
17
17
  case 6:
18
18
  // ChatGPT api
19
- res = await getChatGPTReply(content, uid, adminId, config);
19
+ res = await getChatGPTReply(content, uid, adminId, config, false);
20
20
  replys = res;
21
21
  break;
22
22
  case 7:
@@ -31,6 +31,11 @@ export async function dispatchBot({ botType, content, uid, adminId, config }) {
31
31
  res = await getDifyAiReply(content, uid, adminId, config);
32
32
  replys = res;
33
33
  break;
34
+ case 9:
35
+ // fastGPT api
36
+ res = await getChatGPTReply(content, uid, adminId, config, true);
37
+ replys = res;
38
+ break;
34
39
  default:
35
40
  replys = [];
36
41
  break;
@@ -1,15 +1,57 @@
1
1
  import * as mqtt from 'mqtt';
2
2
  import { allConfig } from '../db/configDb.js';
3
- import { contactSay, roomSay } from '../common/index.js';
3
+ import { contactSay, roomSay, sendRoomNotice } from '../common/index.js';
4
4
  import { getConfig, getMqttConfig, getGptConfig, getRssConfig } from "./aibotk.js";
5
5
  import { dispatchEventContent } from '../service/event-dispatch-service.js';
6
6
  import { sendTaskMessage } from "../task/index.js";
7
- import { randomRange } from '../lib/index.js';
7
+ import { delay, randomRange } from "../lib/index.js";
8
8
  import { reset } from './bot/chatgpt.js';
9
9
  import { reset as webReset } from './bot/chatgpt-web.js';
10
10
  import { reset as difyReset } from './bot/dify.js';
11
11
  import { initRssTask, sendRssTaskMessage } from "../task/rss.js";
12
12
  let mqttclient = null;
13
+ async function sendRoomSay(that, room, messages) {
14
+ console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
15
+ const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
16
+ if (!finalRoom) {
17
+ console.log(`查找不到群:${room.name},请检查群名是否正确`);
18
+ return;
19
+ }
20
+ else {
21
+ for (let message of messages) {
22
+ await roomSay.call(that, finalRoom, '', message);
23
+ await delay(500);
24
+ }
25
+ }
26
+ }
27
+ async function sendContactSay(that, contact, messages) {
28
+ console.log(`收到好友:${contact.name}批量发送消息请求, 消息数量【${messages.length}】`);
29
+ const finalContact = await that.Contact.find({ id: contact.id || '', name: contact.name, alias: contact.alias || '', weixin: contact.weixin || '' });
30
+ if (!finalContact) {
31
+ console.log(`查找不到好友:${contact.name},请检查好友名称是否正确`);
32
+ return;
33
+ }
34
+ else {
35
+ for (let message of messages) {
36
+ await contactSay.call(that, finalContact, message);
37
+ await delay(500);
38
+ }
39
+ }
40
+ }
41
+ async function sendRoomsNotice(that, room, messages) {
42
+ console.log(`收到群:${room.name}批量发送群公告请求, 公告数量【${messages.length}】`);
43
+ const finalRoom = await that.Room.find({ id: room.id, topic: room.name });
44
+ if (!finalRoom) {
45
+ console.log(`查找不到群:${room.name},请检查群名是否正确`);
46
+ return;
47
+ }
48
+ else {
49
+ for (let message of messages) {
50
+ await sendRoomNotice.call(that, finalRoom, message.content);
51
+ await delay(500);
52
+ }
53
+ }
54
+ }
13
55
  async function initMqtt(that) {
14
56
  try {
15
57
  await getConfig(); // 获取配置文件
@@ -71,6 +113,27 @@ async function initMqtt(that) {
71
113
  }
72
114
  }
73
115
  }
116
+ if (topic === `aibotk/${userId}/multisay`) {
117
+ console.log('触发批量发送消息请求', content.target);
118
+ if (content.target === 'Room') {
119
+ for (let room of content.groups) {
120
+ await sendRoomSay(that, room, content.messages);
121
+ await delay(600);
122
+ }
123
+ }
124
+ else if (content.target === 'Contact') {
125
+ for (let contact of content.groups) {
126
+ await sendContactSay(that, contact, content.messages);
127
+ await delay(600);
128
+ }
129
+ }
130
+ else if (content.target === 'RoomNotice') {
131
+ for (let room of content.groups) {
132
+ await sendRoomsNotice(that, room, content.messages);
133
+ await delay(600);
134
+ }
135
+ }
136
+ }
74
137
  else if (topic === `aibotk/${userId}/event`) {
75
138
  if (content.target === 'system') {
76
139
  console.log('触发了内置事件');
@@ -2,5 +2,5 @@
2
2
  * 重置实例
3
3
  */
4
4
  export function reset(): void;
5
- export function getGptOfficialReply(content: any, uid: any): Promise<any>;
5
+ export function getGptOfficialReply(content: any, uid: any, isFastGPT: any): Promise<any>;
6
6
  //# sourceMappingURL=openAi.d.ts.map
@@ -10,7 +10,7 @@ export function reset() {
10
10
  chatGPT = null;
11
11
  }
12
12
  }
13
- export async function getGptOfficialReply(content, uid) {
13
+ export async function getGptOfficialReply(content, uid, isFastGPT) {
14
14
  const config = await allConfig();
15
15
  if (!config.gpttoken) {
16
16
  console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
@@ -36,6 +36,6 @@ export async function getGptOfficialReply(content, uid) {
36
36
  if (!chatGPT) {
37
37
  chatGPT = new OfficialOpenAi(chatConfig);
38
38
  }
39
- return await chatGPT.getReply(content, uid);
39
+ return await chatGPT.getReply(content, uid, '', '', isFastGPT);
40
40
  }
41
41
  //# sourceMappingURL=openAi.js.map
@@ -157,8 +157,8 @@ async function dispatchAiBot(bot, msg, name, id) {
157
157
  replys = res;
158
158
  break;
159
159
  case 6:
160
- // ChatGPT3
161
- res = await getGptOfficialReply(msg, id);
160
+ // ChatGPT-api
161
+ res = await getGptOfficialReply(msg, id, false);
162
162
  replys = res;
163
163
  break;
164
164
  case 7:
@@ -171,6 +171,11 @@ async function dispatchAiBot(bot, msg, name, id) {
171
171
  res = await getDifyReply(msg, id);
172
172
  replys = res;
173
173
  break;
174
+ case 9:
175
+ // fast gpt
176
+ res = await getGptOfficialReply(msg, id, true);
177
+ replys = res;
178
+ break;
174
179
  default:
175
180
  replys = [{ type: 1, content: '' }];
176
181
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.21",
3
+ "version": "1.6.23",
4
4
  "description": "智能微秘书插件",
5
5
  "exports": {
6
6
  ".": {