wechaty-web-panel 1.6.57 → 1.6.58

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 (48) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/cjs/src/botInstance/dify.d.ts +4 -1
  3. package/dist/cjs/src/botInstance/dify.js +6 -6
  4. package/dist/cjs/src/botInstance/officialOpenAi.d.ts +1 -1
  5. package/dist/cjs/src/botInstance/officialOpenAi.js +4 -1
  6. package/dist/cjs/src/botInstance/sdk/chatGPT.js +4 -1
  7. package/dist/cjs/src/botInstance/sdk/difyClient.d.ts +2 -1
  8. package/dist/cjs/src/botInstance/sdk/difyClient.js +4 -2
  9. package/dist/cjs/src/handlers/on-message.js +17 -6
  10. package/dist/cjs/src/package-json.js +1 -1
  11. package/dist/cjs/src/proxy/bot/chatgpt.d.ts +4 -1
  12. package/dist/cjs/src/proxy/bot/chatgpt.js +2 -2
  13. package/dist/cjs/src/proxy/bot/dify.d.ts +4 -1
  14. package/dist/cjs/src/proxy/bot/dify.js +2 -2
  15. package/dist/cjs/src/proxy/bot/dispatch.d.ts +1 -1
  16. package/dist/cjs/src/proxy/bot/dispatch.js +6 -6
  17. package/dist/cjs/src/proxy/difyAi.d.ts +8 -3
  18. package/dist/cjs/src/proxy/difyAi.js +4 -4
  19. package/dist/cjs/src/proxy/openAi.d.ts +3 -2
  20. package/dist/cjs/src/proxy/openAi.js +4 -4
  21. package/dist/cjs/src/service/event-dispatch-service.d.ts +6 -2
  22. package/dist/cjs/src/service/event-dispatch-service.js +8 -8
  23. package/dist/cjs/src/service/msg-filters.d.ts +2 -1
  24. package/dist/cjs/src/service/msg-filters.js +9 -5
  25. package/dist/esm/src/botInstance/dify.d.ts +4 -1
  26. package/dist/esm/src/botInstance/dify.js +6 -6
  27. package/dist/esm/src/botInstance/officialOpenAi.d.ts +1 -1
  28. package/dist/esm/src/botInstance/officialOpenAi.js +4 -1
  29. package/dist/esm/src/botInstance/sdk/chatGPT.js +4 -1
  30. package/dist/esm/src/botInstance/sdk/difyClient.d.ts +2 -1
  31. package/dist/esm/src/botInstance/sdk/difyClient.js +4 -2
  32. package/dist/esm/src/handlers/on-message.js +17 -6
  33. package/dist/esm/src/package-json.js +1 -1
  34. package/dist/esm/src/proxy/bot/chatgpt.d.ts +4 -1
  35. package/dist/esm/src/proxy/bot/chatgpt.js +2 -2
  36. package/dist/esm/src/proxy/bot/dify.d.ts +4 -1
  37. package/dist/esm/src/proxy/bot/dify.js +2 -2
  38. package/dist/esm/src/proxy/bot/dispatch.d.ts +1 -1
  39. package/dist/esm/src/proxy/bot/dispatch.js +6 -6
  40. package/dist/esm/src/proxy/difyAi.d.ts +8 -3
  41. package/dist/esm/src/proxy/difyAi.js +4 -4
  42. package/dist/esm/src/proxy/openAi.d.ts +3 -2
  43. package/dist/esm/src/proxy/openAi.js +4 -4
  44. package/dist/esm/src/service/event-dispatch-service.d.ts +6 -2
  45. package/dist/esm/src/service/event-dispatch-service.js +8 -8
  46. package/dist/esm/src/service/msg-filters.d.ts +2 -1
  47. package/dist/esm/src/service/msg-filters.js +9 -5
  48. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.6.58(2024-07-10)
4
+ 1、Dify 和 FastGPT 每次调用都会携带用户信息和群聊信息,可以使用环境变量获取,实现真正的个性化机器人服务,更像真人
5
+
3
6
  ### V1.6.57(2024-06-05)
4
7
  1、添加聊天内容记录到本地
5
8
 
@@ -31,7 +31,10 @@ declare class DifyAi {
31
31
  * @return {Promise<void>}
32
32
  */
33
33
  reset(): Promise<void>;
34
- getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
34
+ getReply({ content, inputs }: {
35
+ content: any;
36
+ inputs: any;
37
+ }, id: any, adminId?: string, systemMessage?: string): Promise<{
35
38
  type: number;
36
39
  content: any;
37
40
  }[]>;
@@ -59,7 +59,7 @@ class DifyAi {
59
59
  reset() {
60
60
  this.difyChat = null;
61
61
  }
62
- async getReply(content, uid, adminId = '', systemMessage = '') {
62
+ async getReply({ content, inputs }, id, adminId = '', systemMessage = '') {
63
63
  try {
64
64
  if (!this.difyChat) {
65
65
  console.log('启用Dify对话平台');
@@ -74,12 +74,12 @@ class DifyAi {
74
74
  }
75
75
  if (systemMessage || content === 'reset' || content === '重置') {
76
76
  console.log('重新更新上下文对话');
77
- this.chatOption[uid] = {};
77
+ this.chatOption[id] = {};
78
78
  if (content === 'reset' || content === '重置') {
79
79
  return [{ type: 1, content: '上下文已重置' }];
80
80
  }
81
81
  }
82
- const { conversationId, text, files } = systemMessage ? await this.difyChat.sendMessage(content, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: uid }) : await this.difyChat.sendMessage(content, { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: uid });
82
+ const { conversationId, text, files } = systemMessage ? await this.difyChat.sendMessage(content, { ...this.chatOption[id], inputs, systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: id }) : await this.difyChat.sendMessage(content, { ...this.chatOption[id], inputs, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: id });
83
83
  if (this.config.filter) {
84
84
  const censor = await this.contentCensor.checkText(text);
85
85
  if (!censor) {
@@ -88,11 +88,11 @@ class DifyAi {
88
88
  }
89
89
  }
90
90
  if (this.config.record) {
91
- void (0, aichatDb_js_1.addAichatRecord)({ contactId: uid, adminId, input: content, output: text, time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss') });
91
+ void (0, aichatDb_js_1.addAichatRecord)({ contactId: id, adminId, input: content, output: text, time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss') });
92
92
  }
93
93
  // 保存对话id 对于同一个用户的对话不更新conversationId
94
- if (!this.chatOption[uid]?.conversationId) {
95
- this.chatOption[uid] = {
94
+ if (!this.chatOption[id]?.conversationId) {
95
+ this.chatOption[id] = {
96
96
  conversationId
97
97
  };
98
98
  }
@@ -66,7 +66,7 @@ declare class OfficialOpenAi {
66
66
  * @return {Promise<void>}
67
67
  */
68
68
  reset(): Promise<void>;
69
- getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any): Promise<{
69
+ getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any, variables: any): Promise<{
70
70
  type: number;
71
71
  content: any;
72
72
  }[]>;
@@ -135,7 +135,7 @@ class OfficialOpenAi {
135
135
  reset() {
136
136
  this.chatGPT = null;
137
137
  }
138
- async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
138
+ async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT, variables) {
139
139
  try {
140
140
  if (!this.chatGPT) {
141
141
  console.log(isFastGPT ? '看到此消息说明启用了FastGPT' : '看到此消息说明已启用ChatGPT');
@@ -165,6 +165,9 @@ class OfficialOpenAi {
165
165
  if (systemMessage) {
166
166
  sendParams.systemMessage = systemMessage;
167
167
  }
168
+ if (isFastGPT && variables) {
169
+ sendParams.variables = variables;
170
+ }
168
171
  const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
169
172
  if (this.config.filter) {
170
173
  const censor = await this.contentCensor.checkText(text);
@@ -148,7 +148,7 @@ let ChatGPTAPI = class {
148
148
  }
149
149
  }
150
150
  async sendMessage(text, opts = {}) {
151
- const { parentMessageId, messageId = (0, uuid_1.v4)(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId } = opts;
151
+ const { parentMessageId, messageId = (0, uuid_1.v4)(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId, variables } = opts;
152
152
  let { abortSignal } = opts;
153
153
  let abortController = null;
154
154
  if (timeoutMs && !abortSignal) {
@@ -187,6 +187,9 @@ let ChatGPTAPI = class {
187
187
  if (chatId) {
188
188
  body.chatId = chatId;
189
189
  }
190
+ if (variables) {
191
+ body.variables = variables;
192
+ }
190
193
  if (this._apiOrg) {
191
194
  headers["OpenAI-Organization"] = this._apiOrg;
192
195
  }
@@ -85,12 +85,13 @@ export class CompletionClient extends DifyClient {
85
85
  createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<import("axios").AxiosResponse<any, any>>;
86
86
  }
87
87
  export class ChatClient extends DifyClient {
88
- sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files }: {
88
+ sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files, inputs }: {
89
89
  systemMessage: any;
90
90
  user: any;
91
91
  conversationId?: null | undefined;
92
92
  timeoutMs?: number | undefined;
93
93
  files?: null | undefined;
94
+ inputs: any;
94
95
  }): Promise<any>;
95
96
  getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<import("axios").AxiosResponse<any, any>>;
96
97
  getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<import("axios").AxiosResponse<any, any>>;
@@ -132,9 +132,11 @@ class CompletionClient extends DifyClient {
132
132
  }
133
133
  exports.CompletionClient = CompletionClient;
134
134
  class ChatClient extends DifyClient {
135
- async sendMessage(query, { systemMessage, user, conversationId = null, timeoutMs = 100 * 1000, files = null }) {
135
+ async sendMessage(query, { systemMessage, user, conversationId = null, timeoutMs = 100 * 1000, files = null, inputs }) {
136
136
  const data = {
137
- inputs: {},
137
+ inputs: {
138
+ ...inputs
139
+ },
138
140
  query,
139
141
  user,
140
142
  response_mode: this.stream ? 'streaming' : 'blocking',
@@ -104,9 +104,16 @@ async function dispatchFriendFilterByMsgType(that, msg) {
104
104
  break;
105
105
  case that.Message.Type.Audio:
106
106
  let finalConfig = await (0, msg_filters_js_1.getCustomConfig)({ name, id: contact.id, roomName: '', roomId: '', room: false, type: 'openWhisper' });
107
+ if (!finalConfig && config?.customBot?.openWhisper) {
108
+ finalConfig = {
109
+ botConfig: {
110
+ whisperConfig: config?.customBot?.whisperConfig
111
+ }
112
+ };
113
+ }
107
114
  if (finalConfig) {
108
115
  const audioFileBox = await msg.toFileBox();
109
- const text = await (0, multimodal_js_1.getVoiceText)(audioFileBox, finalConfig.botConfig.whisperConfig);
116
+ const text = msg.text().trim() ? msg.text().trim() : await (0, multimodal_js_1.getVoiceText)(audioFileBox, finalConfig.botConfig.whisperConfig);
110
117
  console.log('语音解析结果', text);
111
118
  const keyword = finalConfig.botConfig.whisperConfig?.keywords?.length ? finalConfig.botConfig?.whisperConfig.keywords?.find((item) => text.includes(item)) : true;
112
119
  const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
@@ -165,9 +172,6 @@ async function dispatchFriendFilterByMsgType(that, msg) {
165
172
  case that.Message.Type.Video:
166
173
  console.log(`发消息人${await contact.name()}:发了一个视频`);
167
174
  break;
168
- case that.Message.Type.Audio:
169
- console.log(`发消息人${await contact.name()}:发了一个视频`);
170
- break;
171
175
  case that.Message.Type.MiniProgram:
172
176
  console.log(`发消息人${await contact.name()}:发了一个小程序`);
173
177
  const miniProgram = await msg.toMiniProgram();
@@ -314,9 +318,16 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
314
318
  case that.Message.Type.Audio:
315
319
  console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个语音`);
316
320
  let finalConfig = await (0, msg_filters_js_1.getCustomConfig)({ name: contactName, id: contactId, roomName, roomId: room.id, room, type: 'openWhisper' });
321
+ if (!finalConfig && config?.customBot?.openWhisper) {
322
+ finalConfig = {
323
+ botConfig: {
324
+ whisperConfig: config?.customBot?.whisperConfig
325
+ }
326
+ };
327
+ }
317
328
  if (finalConfig) {
318
329
  const audioFileBox = await msg.toFileBox();
319
- const text = await (0, multimodal_js_1.getVoiceText)(audioFileBox, finalConfig.botConfig.whisperConfig);
330
+ const text = msg.text().trim() ? msg.text().trim() : await (0, multimodal_js_1.getVoiceText)(audioFileBox, finalConfig.botConfig.whisperConfig);
320
331
  console.log('语音解析结果', text);
321
332
  const keyword = finalConfig.botConfig.whisperConfig?.keywords?.length ? finalConfig.botConfig?.whisperConfig?.keywords?.find((item) => text.includes(item)) : true;
322
333
  const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
@@ -338,7 +349,7 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
338
349
  }
339
350
  return;
340
351
  }
341
- replys = await await (0, reply_js_1.getRoomTextReply)({
352
+ replys = await (0, reply_js_1.getRoomTextReply)({
342
353
  that,
343
354
  content: text,
344
355
  isFriend,
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.6.57",
9
+ "version": "1.6.58",
10
10
  "description": "智能微秘书插件",
11
11
  "exports": {
12
12
  ".": {
@@ -1,6 +1,9 @@
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, variables }: {
4
+ content: any;
5
+ variables: any;
6
+ }, uid: any, adminId: any, config: {
4
7
  token: string;
5
8
  debug: boolean;
6
9
  proxyPass: string;
@@ -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: [] }, isFastGPT) {
26
+ async function getChatGPTReply({ content, variables }, 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, isFastGPT);
44
+ return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage, isFastGPT, variables);
45
45
  }
46
46
  exports.getChatGPTReply = getChatGPTReply;
47
47
  //# sourceMappingURL=chatgpt.js.map
@@ -1,6 +1,9 @@
1
1
  export function reset(adminId: any): void;
2
2
  export function resetAll(): void;
3
- export function getDifyAiReply(content: any, uid: any, adminId: any, config?: {
3
+ export function getDifyAiReply({ content, inputs }: {
4
+ content: any;
5
+ inputs: any;
6
+ }, uid: any, adminId: any, config?: {
4
7
  token: string;
5
8
  debug: boolean;
6
9
  proxyPass: string;
@@ -23,7 +23,7 @@ function resetAll() {
23
23
  difyAi = {};
24
24
  }
25
25
  exports.resetAll = resetAll;
26
- async function getDifyAiReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [], isAiAgent: false }) {
26
+ async function getDifyAiReply({ content, inputs }, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [], isAiAgent: false }) {
27
27
  if (!config.token) {
28
28
  console.log('请到智能微秘书平台配置Dify的 api秘钥方可使用');
29
29
  return [{ type: 1, content: '请到智能微秘书平台配置Dify的 api秘钥方可使用' }];
@@ -41,7 +41,7 @@ async function getDifyAiReply(content, uid, adminId, config = { token: "", debug
41
41
  content = content.replace(finalSystemMsg.keyword, '');
42
42
  }
43
43
  }
44
- return await difyAi[adminId].getReply(content, uid, adminId, systemMessage);
44
+ return await difyAi[adminId].getReply({ content, inputs }, uid, adminId, systemMessage);
45
45
  }
46
46
  exports.getDifyAiReply = getDifyAiReply;
47
47
  //# sourceMappingURL=dify.js.map
@@ -3,5 +3,5 @@
3
3
  * @param {botType: 机器人类别, content: 消息内容, uid: 说话的用户id, updateId: 更新的用户id, adminId: 对话实例id,用于分割不同配置, config: 机器人配置}
4
4
  * @returns
5
5
  */
6
- export function dispatchBot({ botType, content, uid, adminId, config }: any): Promise<any>;
6
+ export function dispatchBot({ botType, content, id, uid, uname, roomId, roomName, adminId, config }: any): Promise<any>;
7
7
  //# sourceMappingURL=dispatch.d.ts.map
@@ -15,7 +15,7 @@ const global_js_1 = __importDefault(require("../../db/global.js"));
15
15
  * @param {botType: 机器人类别, content: 消息内容, uid: 说话的用户id, updateId: 更新的用户id, adminId: 对话实例id,用于分割不同配置, config: 机器人配置}
16
16
  * @returns
17
17
  */
18
- async function dispatchBot({ botType, content, uid, adminId, config }) {
18
+ async function dispatchBot({ botType, content, id, uid, uname, roomId, roomName, adminId, config }) {
19
19
  console.log('进入定制机器人回复');
20
20
  try {
21
21
  const gptConfig = global_js_1.default.getGptConfigById(adminId);
@@ -23,29 +23,29 @@ async function dispatchBot({ botType, content, uid, adminId, config }) {
23
23
  switch (botType) {
24
24
  case 6:
25
25
  // ChatGPT api
26
- res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config, false);
26
+ res = await (0, chatgpt_js_1.getChatGPTReply)({ content }, id, adminId, config, false);
27
27
  replys = res;
28
28
  break;
29
29
  case 7:
30
30
  // ChatGPT web
31
31
  console.log('进入聊天');
32
- res = await (0, chatgpt_web_js_1.getChatGPTWebReply)(content, uid, adminId, config);
32
+ res = await (0, chatgpt_web_js_1.getChatGPTWebReply)(content, id, adminId, config);
33
33
  replys = res;
34
34
  break;
35
35
  case 8:
36
36
  // dify ai
37
37
  console.log('进入Dify聊天');
38
- res = await (0, dify_js_1.getDifyAiReply)(content, uid, adminId, config);
38
+ res = await (0, dify_js_1.getDifyAiReply)({ content, inputs: { uid, uname, roomId, roomName } }, id, adminId, config);
39
39
  replys = res;
40
40
  break;
41
41
  case 9:
42
42
  // fastGPT api
43
- res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config, true);
43
+ res = await (0, chatgpt_js_1.getChatGPTReply)({ content, variables: { uid, uname, roomId, roomName } }, id, adminId, config, true);
44
44
  replys = res;
45
45
  break;
46
46
  case 11:
47
47
  // coze api
48
- res = await (0, coze_js_1.getCozeReply)(content, uid, adminId, config);
48
+ res = await (0, coze_js_1.getCozeReply)(content, id, adminId, config);
49
49
  replys = res;
50
50
  break;
51
51
  default:
@@ -2,10 +2,15 @@
2
2
  * 重置实例
3
3
  */
4
4
  export function reset(): void;
5
- export function getDifyReply(content: any, uid: any): Promise<any>;
6
- export function getDifySimpleReply({ content, uid, config }: {
5
+ export function getDifyReply({ content, id, inputs }: {
7
6
  content: any;
8
- uid: any;
7
+ id: any;
8
+ inputs: any;
9
+ }): Promise<any>;
10
+ export function getDifySimpleReply({ content, id, inputs, config }: {
11
+ content: any;
12
+ id: any;
13
+ inputs: any;
9
14
  config: any;
10
15
  }): Promise<{
11
16
  type: number;
@@ -17,7 +17,7 @@ function reset() {
17
17
  }
18
18
  }
19
19
  exports.reset = reset;
20
- async function getDifyReply(content, uid) {
20
+ async function getDifyReply({ content, id, inputs }) {
21
21
  const config = await (0, configDb_js_1.allConfig)();
22
22
  if (!config.dify_token) {
23
23
  console.log('请到智能微秘书平台配置difyAi apikey参数方可使用');
@@ -42,10 +42,10 @@ async function getDifyReply(content, uid) {
42
42
  if (!difyAi) {
43
43
  difyAi = new dify_js_1.default(chatConfig);
44
44
  }
45
- return await difyAi.getReply(content, uid);
45
+ return await difyAi.getReply({ content, inputs }, id);
46
46
  }
47
47
  exports.getDifyReply = getDifyReply;
48
- async function getDifySimpleReply({ content, uid, config }) {
48
+ async function getDifySimpleReply({ content, id, inputs, config }) {
49
49
  if (!config.token) {
50
50
  console.log('请到智能微秘书平台配置聊天总结API Token参数方可使用');
51
51
  return [{ type: 1, content: '请到平台配置API Token参数方可使用' }];
@@ -59,7 +59,7 @@ async function getDifySimpleReply({ content, uid, config }) {
59
59
  systemMessage: '',
60
60
  isAiAgent: true,
61
61
  };
62
- return await new dify_js_1.default(chatConfig).getReply(content, uid);
62
+ return await new dify_js_1.default(chatConfig).getReply({ content, inputs }, id);
63
63
  }
64
64
  exports.getDifySimpleReply = getDifySimpleReply;
65
65
  //# sourceMappingURL=difyAi.js.map
@@ -2,12 +2,13 @@
2
2
  * 重置实例
3
3
  */
4
4
  export function reset(): void;
5
- export function getGptOfficialReply(content: any, uid: any, isFastGPT: any): Promise<any>;
6
- export function getSimpleGptReply({ content, uid, config, isFastGPT }: {
5
+ export function getGptOfficialReply(content: any, uid: any, isFastGPT: any, variables: any): Promise<any>;
6
+ export function getSimpleGptReply({ content, uid, config, isFastGPT, variables }: {
7
7
  content: any;
8
8
  uid: any;
9
9
  config: any;
10
10
  isFastGPT: any;
11
+ variables: any;
11
12
  }): Promise<{
12
13
  type: number;
13
14
  content: any;
@@ -17,7 +17,7 @@ function reset() {
17
17
  }
18
18
  }
19
19
  exports.reset = reset;
20
- async function getGptOfficialReply(content, uid, isFastGPT) {
20
+ async function getGptOfficialReply(content, uid, isFastGPT, variables) {
21
21
  const config = await (0, configDb_js_1.allConfig)();
22
22
  if (!config.gpttoken) {
23
23
  console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
@@ -46,10 +46,10 @@ async function getGptOfficialReply(content, uid, isFastGPT) {
46
46
  if (!chatGPT) {
47
47
  chatGPT = new officialOpenAi_js_1.default(chatConfig);
48
48
  }
49
- return await chatGPT.getReply(content, uid, '', '', isFastGPT);
49
+ return await chatGPT.getReply(content, uid, '', '', isFastGPT, variables);
50
50
  }
51
51
  exports.getGptOfficialReply = getGptOfficialReply;
52
- async function getSimpleGptReply({ content, uid, config, isFastGPT }) {
52
+ async function getSimpleGptReply({ content, uid, config, isFastGPT, variables }) {
53
53
  if (!config.token) {
54
54
  console.log('请到智能微秘书平台配置聊天总结的API Token参数方可使用');
55
55
  return [{ type: 1, content: '请到平台配置聊天总结的API Token参数方可使用' }];
@@ -64,7 +64,7 @@ async function getSimpleGptReply({ content, uid, config, isFastGPT }) {
64
64
  model: config.model,
65
65
  systemMessage: config.prompt, // 预设promotion
66
66
  };
67
- return await new officialOpenAi_js_1.default(chatConfig).getReply(content, uid, '', '', isFastGPT);
67
+ return await new officialOpenAi_js_1.default(chatConfig).getReply(content, uid, '', '', isFastGPT, variables);
68
68
  }
69
69
  exports.getSimpleGptReply = getSimpleGptReply;
70
70
  //# sourceMappingURL=openAi.js.map
@@ -21,10 +21,14 @@ export function dispatchEventContent(that: any, eName: string, msg: string, name
21
21
  * @param {*} name 发消息人
22
22
  * @param {*} id 发消息人id
23
23
  */
24
- export function dispatchAiBot(bot: any, msg: any, name: any, id: any): Promise<any>;
25
- export function dispatchSummerBot({ content, uid, config }: {
24
+ export function dispatchAiBot({ bot, msg, name, id, uid, uname, roomId, roomName }: any): Promise<any>;
25
+ export function dispatchSummerBot({ content, id, uid, uname, roomId, roomName, config }: {
26
26
  content: any;
27
+ id: any;
27
28
  uid: any;
29
+ uname: any;
30
+ roomId: any;
31
+ roomName: any;
28
32
  config: any;
29
33
  }): Promise<"" | {
30
34
  type: number;
@@ -147,7 +147,7 @@ exports.dispatchEventContent = dispatchEventContent;
147
147
  * @param {*} name 发消息人
148
148
  * @param {*} id 发消息人id
149
149
  */
150
- async function dispatchAiBot(bot, msg, name, id) {
150
+ async function dispatchAiBot({ bot, msg, name, id, uid, uname, roomId, roomName }) {
151
151
  try {
152
152
  let res, replys;
153
153
  switch (bot) {
@@ -173,12 +173,12 @@ async function dispatchAiBot(bot, msg, name, id) {
173
173
  break;
174
174
  case 8:
175
175
  // dify ai
176
- res = await (0, difyAi_js_1.getDifyReply)(msg, id);
176
+ res = await (0, difyAi_js_1.getDifyReply)({ content: msg, id, inputs: { uid, uname, roomId, roomName } });
177
177
  replys = res;
178
178
  break;
179
179
  case 9:
180
180
  // fast gpt
181
- res = await (0, openAi_js_1.getGptOfficialReply)(msg, id, true);
181
+ res = await (0, openAi_js_1.getGptOfficialReply)(msg, id, true, { uid, uname, roomId, roomName });
182
182
  replys = res;
183
183
  break;
184
184
  case 11:
@@ -198,28 +198,28 @@ async function dispatchAiBot(bot, msg, name, id) {
198
198
  }
199
199
  }
200
200
  exports.dispatchAiBot = dispatchAiBot;
201
- async function dispatchSummerBot({ content, uid, config }) {
201
+ async function dispatchSummerBot({ content, id, uid, uname, roomId, roomName, config }) {
202
202
  try {
203
203
  let res, replys;
204
204
  switch (config.botType) {
205
205
  case 6:
206
206
  // ChatGPT-api
207
- res = await (0, openAi_js_1.getSimpleGptReply)({ content, uid, config, isFastGPT: false });
207
+ res = await (0, openAi_js_1.getSimpleGptReply)({ content, uid: id, config, isFastGPT: false });
208
208
  replys = res;
209
209
  break;
210
210
  case 8:
211
211
  // dify ai
212
- res = await (0, difyAi_js_1.getDifySimpleReply)({ content, uid, config });
212
+ res = await (0, difyAi_js_1.getDifySimpleReply)({ content, id, inputs: { uid, uname, roomId, roomName }, config });
213
213
  replys = res;
214
214
  break;
215
215
  case 9:
216
216
  // fast gpt
217
- res = await (0, openAi_js_1.getSimpleGptReply)({ content, uid, config, isFastGPT: true });
217
+ res = await (0, openAi_js_1.getSimpleGptReply)({ content, uid: id, config, isFastGPT: true, variables: { uid, uname, roomId, roomName } });
218
218
  replys = res;
219
219
  break;
220
220
  case 11:
221
221
  // coze
222
- res = await (0, cozeAi_js_1.getCozeSimpleReply)({ content, uid, config, isFastGPT: true });
222
+ res = await (0, cozeAi_js_1.getCozeSimpleReply)({ content, uid: id, config, isFastGPT: true });
223
223
  replys = res;
224
224
  break;
225
225
  default:
@@ -126,12 +126,13 @@ export function keywordsMsg({ msg, config, room, isMention }: {
126
126
  room: any;
127
127
  isMention: any;
128
128
  }): Promise<any>;
129
- export function robotMsg({ msg, name, id, config, isMention, room, roomId, isFriend }: {
129
+ export function robotMsg({ msg, name, id, config, isMention, roomName, room, roomId, isFriend }: {
130
130
  msg: any;
131
131
  name: any;
132
132
  id: any;
133
133
  config: any;
134
134
  isMention: any;
135
+ roomName: any;
135
136
  room: any;
136
137
  roomId: any;
137
138
  isFriend: any;
@@ -269,7 +269,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
269
269
  }
270
270
  }
271
271
  exports.keywordsMsg = keywordsMsg;
272
- async function robotMsg({ msg, name, id, config, isMention, room, roomId, isFriend }) {
272
+ async function robotMsg({ msg, name, id, config, isMention, roomName, room, roomId, isFriend }) {
273
273
  // 如果群里没有提及不开启机器人聊天
274
274
  if (room && !isMention && config.roomAt || room && !isMention && !config.roomAt && isFriend && config.friendNoReplyInRoom) {
275
275
  return [];
@@ -279,7 +279,7 @@ async function robotMsg({ msg, name, id, config, isMention, room, roomId, isFrie
279
279
  let msgArr = []; // 返回的消息列表
280
280
  if (config.autoReply) {
281
281
  console.log('开启了机器人自动回复功能');
282
- msgArr = await event_dispatch_service_js_1.default.dispatchAiBot(config.defaultBot, msg, name, `${roomId ? roomId + '_' : ''}${id}`);
282
+ msgArr = await event_dispatch_service_js_1.default.dispatchAiBot({ bot: config.defaultBot, msg, name, uname: name, uid: id, roomName: roomName || '', roomId: roomId || '', id: `${roomId ? roomId + '_' : ''}${id}` });
283
283
  }
284
284
  else {
285
285
  console.log('没有开启机器人自动回复功能');
@@ -372,9 +372,13 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
372
372
  const msgArr = await (0, dispatch_js_1.dispatchBot)({
373
373
  botType: finalConfig.robotType,
374
374
  content: msg,
375
- uid: `${roomId ? roomId + '_' : ''}${id}`,
375
+ id: `${roomId ? roomId + '_' : ''}${id}`,
376
376
  adminId: finalConfig.id,
377
- config: finalConfig.botConfig
377
+ config: finalConfig.botConfig,
378
+ uid: id,
379
+ uname: name,
380
+ roomId,
381
+ roomName
378
382
  });
379
383
  if (msgArr.length)
380
384
  return msgArr;
@@ -579,7 +583,7 @@ async function summerChat({ that, msg, name, id, config, room, isMention, roomId
579
583
  console.log('获取到的聊天内容', content);
580
584
  }
581
585
  console.log('开始总结聊天内容');
582
- const res = await event_dispatch_service_js_1.default.dispatchSummerBot({ content, config: item, uid: room ? `${roomId}_${id}` : id });
586
+ const res = await event_dispatch_service_js_1.default.dispatchSummerBot({ content, config: item, uid: id, uname: name, roomId: roomId, roomName, id: room ? `${roomId ? roomId + '_' : ''}${id}` : id });
583
587
  return res;
584
588
  }
585
589
  else {
@@ -31,7 +31,10 @@ declare class DifyAi {
31
31
  * @return {Promise<void>}
32
32
  */
33
33
  reset(): Promise<void>;
34
- getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
34
+ getReply({ content, inputs }: {
35
+ content: any;
36
+ inputs: any;
37
+ }, id: any, adminId?: string, systemMessage?: string): Promise<{
35
38
  type: number;
36
39
  content: any;
37
40
  }[]>;
@@ -54,7 +54,7 @@ class DifyAi {
54
54
  reset() {
55
55
  this.difyChat = null;
56
56
  }
57
- async getReply(content, uid, adminId = '', systemMessage = '') {
57
+ async getReply({ content, inputs }, id, adminId = '', systemMessage = '') {
58
58
  try {
59
59
  if (!this.difyChat) {
60
60
  console.log('启用Dify对话平台');
@@ -69,12 +69,12 @@ class DifyAi {
69
69
  }
70
70
  if (systemMessage || content === 'reset' || content === '重置') {
71
71
  console.log('重新更新上下文对话');
72
- this.chatOption[uid] = {};
72
+ this.chatOption[id] = {};
73
73
  if (content === 'reset' || content === '重置') {
74
74
  return [{ type: 1, content: '上下文已重置' }];
75
75
  }
76
76
  }
77
- const { conversationId, text, files } = systemMessage ? await this.difyChat.sendMessage(content, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: uid }) : await this.difyChat.sendMessage(content, { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: uid });
77
+ const { conversationId, text, files } = systemMessage ? await this.difyChat.sendMessage(content, { ...this.chatOption[id], inputs, systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: id }) : await this.difyChat.sendMessage(content, { ...this.chatOption[id], inputs, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: id });
78
78
  if (this.config.filter) {
79
79
  const censor = await this.contentCensor.checkText(text);
80
80
  if (!censor) {
@@ -83,11 +83,11 @@ class DifyAi {
83
83
  }
84
84
  }
85
85
  if (this.config.record) {
86
- void addAichatRecord({ contactId: uid, adminId, input: content, output: text, time: dayjs().format('YYYY-MM-DD HH:mm:ss') });
86
+ void addAichatRecord({ contactId: id, adminId, input: content, output: text, time: dayjs().format('YYYY-MM-DD HH:mm:ss') });
87
87
  }
88
88
  // 保存对话id 对于同一个用户的对话不更新conversationId
89
- if (!this.chatOption[uid]?.conversationId) {
90
- this.chatOption[uid] = {
89
+ if (!this.chatOption[id]?.conversationId) {
90
+ this.chatOption[id] = {
91
91
  conversationId
92
92
  };
93
93
  }
@@ -66,7 +66,7 @@ declare class OfficialOpenAi {
66
66
  * @return {Promise<void>}
67
67
  */
68
68
  reset(): Promise<void>;
69
- getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any): Promise<{
69
+ getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any, variables: any): Promise<{
70
70
  type: number;
71
71
  content: any;
72
72
  }[]>;
@@ -130,7 +130,7 @@ class OfficialOpenAi {
130
130
  reset() {
131
131
  this.chatGPT = null;
132
132
  }
133
- async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
133
+ async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT, variables) {
134
134
  try {
135
135
  if (!this.chatGPT) {
136
136
  console.log(isFastGPT ? '看到此消息说明启用了FastGPT' : '看到此消息说明已启用ChatGPT');
@@ -160,6 +160,9 @@ class OfficialOpenAi {
160
160
  if (systemMessage) {
161
161
  sendParams.systemMessage = systemMessage;
162
162
  }
163
+ if (isFastGPT && variables) {
164
+ sendParams.variables = variables;
165
+ }
163
166
  const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
164
167
  if (this.config.filter) {
165
168
  const censor = await this.contentCensor.checkText(text);
@@ -140,7 +140,7 @@ let ChatGPTAPI = class {
140
140
  }
141
141
  }
142
142
  async sendMessage(text, opts = {}) {
143
- const { parentMessageId, messageId = uuidv4(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId } = opts;
143
+ const { parentMessageId, messageId = uuidv4(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId, variables } = opts;
144
144
  let { abortSignal } = opts;
145
145
  let abortController = null;
146
146
  if (timeoutMs && !abortSignal) {
@@ -179,6 +179,9 @@ let ChatGPTAPI = class {
179
179
  if (chatId) {
180
180
  body.chatId = chatId;
181
181
  }
182
+ if (variables) {
183
+ body.variables = variables;
184
+ }
182
185
  if (this._apiOrg) {
183
186
  headers["OpenAI-Organization"] = this._apiOrg;
184
187
  }
@@ -85,12 +85,13 @@ export class CompletionClient extends DifyClient {
85
85
  createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<import("axios").AxiosResponse<any, any>>;
86
86
  }
87
87
  export class ChatClient extends DifyClient {
88
- sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files }: {
88
+ sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files, inputs }: {
89
89
  systemMessage: any;
90
90
  user: any;
91
91
  conversationId?: null | undefined;
92
92
  timeoutMs?: number | undefined;
93
93
  files?: null | undefined;
94
+ inputs: any;
94
95
  }): Promise<any>;
95
96
  getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<import("axios").AxiosResponse<any, any>>;
96
97
  getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<import("axios").AxiosResponse<any, any>>;
@@ -124,9 +124,11 @@ export class CompletionClient extends DifyClient {
124
124
  }
125
125
  }
126
126
  export class ChatClient extends DifyClient {
127
- async sendMessage(query, { systemMessage, user, conversationId = null, timeoutMs = 100 * 1000, files = null }) {
127
+ async sendMessage(query, { systemMessage, user, conversationId = null, timeoutMs = 100 * 1000, files = null, inputs }) {
128
128
  const data = {
129
- inputs: {},
129
+ inputs: {
130
+ ...inputs
131
+ },
130
132
  query,
131
133
  user,
132
134
  response_mode: this.stream ? 'streaming' : 'blocking',
@@ -102,9 +102,16 @@ async function dispatchFriendFilterByMsgType(that, msg) {
102
102
  break;
103
103
  case that.Message.Type.Audio:
104
104
  let finalConfig = await getCustomConfig({ name, id: contact.id, roomName: '', roomId: '', room: false, type: 'openWhisper' });
105
+ if (!finalConfig && config?.customBot?.openWhisper) {
106
+ finalConfig = {
107
+ botConfig: {
108
+ whisperConfig: config?.customBot?.whisperConfig
109
+ }
110
+ };
111
+ }
105
112
  if (finalConfig) {
106
113
  const audioFileBox = await msg.toFileBox();
107
- const text = await getVoiceText(audioFileBox, finalConfig.botConfig.whisperConfig);
114
+ const text = msg.text().trim() ? msg.text().trim() : await getVoiceText(audioFileBox, finalConfig.botConfig.whisperConfig);
108
115
  console.log('语音解析结果', text);
109
116
  const keyword = finalConfig.botConfig.whisperConfig?.keywords?.length ? finalConfig.botConfig?.whisperConfig.keywords?.find((item) => text.includes(item)) : true;
110
117
  const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
@@ -163,9 +170,6 @@ async function dispatchFriendFilterByMsgType(that, msg) {
163
170
  case that.Message.Type.Video:
164
171
  console.log(`发消息人${await contact.name()}:发了一个视频`);
165
172
  break;
166
- case that.Message.Type.Audio:
167
- console.log(`发消息人${await contact.name()}:发了一个视频`);
168
- break;
169
173
  case that.Message.Type.MiniProgram:
170
174
  console.log(`发消息人${await contact.name()}:发了一个小程序`);
171
175
  const miniProgram = await msg.toMiniProgram();
@@ -312,9 +316,16 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
312
316
  case that.Message.Type.Audio:
313
317
  console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个语音`);
314
318
  let finalConfig = await getCustomConfig({ name: contactName, id: contactId, roomName, roomId: room.id, room, type: 'openWhisper' });
319
+ if (!finalConfig && config?.customBot?.openWhisper) {
320
+ finalConfig = {
321
+ botConfig: {
322
+ whisperConfig: config?.customBot?.whisperConfig
323
+ }
324
+ };
325
+ }
315
326
  if (finalConfig) {
316
327
  const audioFileBox = await msg.toFileBox();
317
- const text = await getVoiceText(audioFileBox, finalConfig.botConfig.whisperConfig);
328
+ const text = msg.text().trim() ? msg.text().trim() : await getVoiceText(audioFileBox, finalConfig.botConfig.whisperConfig);
318
329
  console.log('语音解析结果', text);
319
330
  const keyword = finalConfig.botConfig.whisperConfig?.keywords?.length ? finalConfig.botConfig?.whisperConfig?.keywords?.find((item) => text.includes(item)) : true;
320
331
  const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
@@ -336,7 +347,7 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
336
347
  }
337
348
  return;
338
349
  }
339
- replys = await await getRoomTextReply({
350
+ replys = await getRoomTextReply({
340
351
  that,
341
352
  content: text,
342
353
  isFriend,
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.57",
6
+ "version": "1.6.58",
7
7
  "description": "智能微秘书插件",
8
8
  "exports": {
9
9
  ".": {
@@ -1,6 +1,9 @@
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, variables }: {
4
+ content: any;
5
+ variables: any;
6
+ }, uid: any, adminId: any, config: {
4
7
  token: string;
5
8
  debug: boolean;
6
9
  proxyPass: string;
@@ -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: [] }, isFastGPT) {
18
+ export async function getChatGPTReply({ content, variables }, 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, isFastGPT);
36
+ return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage, isFastGPT, variables);
37
37
  }
38
38
  //# sourceMappingURL=chatgpt.js.map
@@ -1,6 +1,9 @@
1
1
  export function reset(adminId: any): void;
2
2
  export function resetAll(): void;
3
- export function getDifyAiReply(content: any, uid: any, adminId: any, config?: {
3
+ export function getDifyAiReply({ content, inputs }: {
4
+ content: any;
5
+ inputs: any;
6
+ }, uid: any, adminId: any, config?: {
4
7
  token: string;
5
8
  debug: boolean;
6
9
  proxyPass: string;
@@ -15,7 +15,7 @@ export function resetAll() {
15
15
  });
16
16
  difyAi = {};
17
17
  }
18
- export async function getDifyAiReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [], isAiAgent: false }) {
18
+ export async function getDifyAiReply({ content, inputs }, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [], isAiAgent: false }) {
19
19
  if (!config.token) {
20
20
  console.log('请到智能微秘书平台配置Dify的 api秘钥方可使用');
21
21
  return [{ type: 1, content: '请到智能微秘书平台配置Dify的 api秘钥方可使用' }];
@@ -33,6 +33,6 @@ export async function getDifyAiReply(content, uid, adminId, config = { token: ""
33
33
  content = content.replace(finalSystemMsg.keyword, '');
34
34
  }
35
35
  }
36
- return await difyAi[adminId].getReply(content, uid, adminId, systemMessage);
36
+ return await difyAi[adminId].getReply({ content, inputs }, uid, adminId, systemMessage);
37
37
  }
38
38
  //# sourceMappingURL=dify.js.map
@@ -3,5 +3,5 @@
3
3
  * @param {botType: 机器人类别, content: 消息内容, uid: 说话的用户id, updateId: 更新的用户id, adminId: 对话实例id,用于分割不同配置, config: 机器人配置}
4
4
  * @returns
5
5
  */
6
- export function dispatchBot({ botType, content, uid, adminId, config }: any): Promise<any>;
6
+ export function dispatchBot({ botType, content, id, uid, uname, roomId, roomName, adminId, config }: any): Promise<any>;
7
7
  //# sourceMappingURL=dispatch.d.ts.map
@@ -9,7 +9,7 @@ import globalConfig from '../../db/global.js';
9
9
  * @param {botType: 机器人类别, content: 消息内容, uid: 说话的用户id, updateId: 更新的用户id, adminId: 对话实例id,用于分割不同配置, config: 机器人配置}
10
10
  * @returns
11
11
  */
12
- export async function dispatchBot({ botType, content, uid, adminId, config }) {
12
+ export async function dispatchBot({ botType, content, id, uid, uname, roomId, roomName, adminId, config }) {
13
13
  console.log('进入定制机器人回复');
14
14
  try {
15
15
  const gptConfig = globalConfig.getGptConfigById(adminId);
@@ -17,29 +17,29 @@ export async function dispatchBot({ botType, content, uid, adminId, config }) {
17
17
  switch (botType) {
18
18
  case 6:
19
19
  // ChatGPT api
20
- res = await getChatGPTReply(content, uid, adminId, config, false);
20
+ res = await getChatGPTReply({ content }, id, adminId, config, false);
21
21
  replys = res;
22
22
  break;
23
23
  case 7:
24
24
  // ChatGPT web
25
25
  console.log('进入聊天');
26
- res = await getChatGPTWebReply(content, uid, adminId, config);
26
+ res = await getChatGPTWebReply(content, id, adminId, config);
27
27
  replys = res;
28
28
  break;
29
29
  case 8:
30
30
  // dify ai
31
31
  console.log('进入Dify聊天');
32
- res = await getDifyAiReply(content, uid, adminId, config);
32
+ res = await getDifyAiReply({ content, inputs: { uid, uname, roomId, roomName } }, id, adminId, config);
33
33
  replys = res;
34
34
  break;
35
35
  case 9:
36
36
  // fastGPT api
37
- res = await getChatGPTReply(content, uid, adminId, config, true);
37
+ res = await getChatGPTReply({ content, variables: { uid, uname, roomId, roomName } }, id, adminId, config, true);
38
38
  replys = res;
39
39
  break;
40
40
  case 11:
41
41
  // coze api
42
- res = await getCozeReply(content, uid, adminId, config);
42
+ res = await getCozeReply(content, id, adminId, config);
43
43
  replys = res;
44
44
  break;
45
45
  default:
@@ -2,10 +2,15 @@
2
2
  * 重置实例
3
3
  */
4
4
  export function reset(): void;
5
- export function getDifyReply(content: any, uid: any): Promise<any>;
6
- export function getDifySimpleReply({ content, uid, config }: {
5
+ export function getDifyReply({ content, id, inputs }: {
7
6
  content: any;
8
- uid: any;
7
+ id: any;
8
+ inputs: any;
9
+ }): Promise<any>;
10
+ export function getDifySimpleReply({ content, id, inputs, config }: {
11
+ content: any;
12
+ id: any;
13
+ inputs: any;
9
14
  config: any;
10
15
  }): Promise<{
11
16
  type: number;
@@ -10,7 +10,7 @@ export function reset() {
10
10
  difyAi = null;
11
11
  }
12
12
  }
13
- export async function getDifyReply(content, uid) {
13
+ export async function getDifyReply({ content, id, inputs }) {
14
14
  const config = await allConfig();
15
15
  if (!config.dify_token) {
16
16
  console.log('请到智能微秘书平台配置difyAi apikey参数方可使用');
@@ -35,9 +35,9 @@ export async function getDifyReply(content, uid) {
35
35
  if (!difyAi) {
36
36
  difyAi = new DifyAi(chatConfig);
37
37
  }
38
- return await difyAi.getReply(content, uid);
38
+ return await difyAi.getReply({ content, inputs }, id);
39
39
  }
40
- export async function getDifySimpleReply({ content, uid, config }) {
40
+ export async function getDifySimpleReply({ content, id, inputs, config }) {
41
41
  if (!config.token) {
42
42
  console.log('请到智能微秘书平台配置聊天总结API Token参数方可使用');
43
43
  return [{ type: 1, content: '请到平台配置API Token参数方可使用' }];
@@ -51,6 +51,6 @@ export async function getDifySimpleReply({ content, uid, config }) {
51
51
  systemMessage: '',
52
52
  isAiAgent: true,
53
53
  };
54
- return await new DifyAi(chatConfig).getReply(content, uid);
54
+ return await new DifyAi(chatConfig).getReply({ content, inputs }, id);
55
55
  }
56
56
  //# sourceMappingURL=difyAi.js.map
@@ -2,12 +2,13 @@
2
2
  * 重置实例
3
3
  */
4
4
  export function reset(): void;
5
- export function getGptOfficialReply(content: any, uid: any, isFastGPT: any): Promise<any>;
6
- export function getSimpleGptReply({ content, uid, config, isFastGPT }: {
5
+ export function getGptOfficialReply(content: any, uid: any, isFastGPT: any, variables: any): Promise<any>;
6
+ export function getSimpleGptReply({ content, uid, config, isFastGPT, variables }: {
7
7
  content: any;
8
8
  uid: any;
9
9
  config: any;
10
10
  isFastGPT: any;
11
+ variables: any;
11
12
  }): Promise<{
12
13
  type: number;
13
14
  content: any;
@@ -10,7 +10,7 @@ export function reset() {
10
10
  chatGPT = null;
11
11
  }
12
12
  }
13
- export async function getGptOfficialReply(content, uid, isFastGPT) {
13
+ export async function getGptOfficialReply(content, uid, isFastGPT, variables) {
14
14
  const config = await allConfig();
15
15
  if (!config.gpttoken) {
16
16
  console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
@@ -39,9 +39,9 @@ export async function getGptOfficialReply(content, uid, isFastGPT) {
39
39
  if (!chatGPT) {
40
40
  chatGPT = new OfficialOpenAi(chatConfig);
41
41
  }
42
- return await chatGPT.getReply(content, uid, '', '', isFastGPT);
42
+ return await chatGPT.getReply(content, uid, '', '', isFastGPT, variables);
43
43
  }
44
- export async function getSimpleGptReply({ content, uid, config, isFastGPT }) {
44
+ export async function getSimpleGptReply({ content, uid, config, isFastGPT, variables }) {
45
45
  if (!config.token) {
46
46
  console.log('请到智能微秘书平台配置聊天总结的API Token参数方可使用');
47
47
  return [{ type: 1, content: '请到平台配置聊天总结的API Token参数方可使用' }];
@@ -56,6 +56,6 @@ export async function getSimpleGptReply({ content, uid, config, isFastGPT }) {
56
56
  model: config.model,
57
57
  systemMessage: config.prompt, // 预设promotion
58
58
  };
59
- return await new OfficialOpenAi(chatConfig).getReply(content, uid, '', '', isFastGPT);
59
+ return await new OfficialOpenAi(chatConfig).getReply(content, uid, '', '', isFastGPT, variables);
60
60
  }
61
61
  //# sourceMappingURL=openAi.js.map
@@ -21,10 +21,14 @@ export function dispatchEventContent(that: any, eName: string, msg: string, name
21
21
  * @param {*} name 发消息人
22
22
  * @param {*} id 发消息人id
23
23
  */
24
- export function dispatchAiBot(bot: any, msg: any, name: any, id: any): Promise<any>;
25
- export function dispatchSummerBot({ content, uid, config }: {
24
+ export function dispatchAiBot({ bot, msg, name, id, uid, uname, roomId, roomName }: any): Promise<any>;
25
+ export function dispatchSummerBot({ content, id, uid, uname, roomId, roomName, config }: {
26
26
  content: any;
27
+ id: any;
27
28
  uid: any;
29
+ uname: any;
30
+ roomId: any;
31
+ roomName: any;
28
32
  config: any;
29
33
  }): Promise<"" | {
30
34
  type: number;
@@ -143,7 +143,7 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room, ro
143
143
  * @param {*} name 发消息人
144
144
  * @param {*} id 发消息人id
145
145
  */
146
- async function dispatchAiBot(bot, msg, name, id) {
146
+ async function dispatchAiBot({ bot, msg, name, id, uid, uname, roomId, roomName }) {
147
147
  try {
148
148
  let res, replys;
149
149
  switch (bot) {
@@ -169,12 +169,12 @@ async function dispatchAiBot(bot, msg, name, id) {
169
169
  break;
170
170
  case 8:
171
171
  // dify ai
172
- res = await getDifyReply(msg, id);
172
+ res = await getDifyReply({ content: msg, id, inputs: { uid, uname, roomId, roomName } });
173
173
  replys = res;
174
174
  break;
175
175
  case 9:
176
176
  // fast gpt
177
- res = await getGptOfficialReply(msg, id, true);
177
+ res = await getGptOfficialReply(msg, id, true, { uid, uname, roomId, roomName });
178
178
  replys = res;
179
179
  break;
180
180
  case 11:
@@ -193,28 +193,28 @@ async function dispatchAiBot(bot, msg, name, id) {
193
193
  return '';
194
194
  }
195
195
  }
196
- async function dispatchSummerBot({ content, uid, config }) {
196
+ async function dispatchSummerBot({ content, id, uid, uname, roomId, roomName, config }) {
197
197
  try {
198
198
  let res, replys;
199
199
  switch (config.botType) {
200
200
  case 6:
201
201
  // ChatGPT-api
202
- res = await getSimpleGptReply({ content, uid, config, isFastGPT: false });
202
+ res = await getSimpleGptReply({ content, uid: id, config, isFastGPT: false });
203
203
  replys = res;
204
204
  break;
205
205
  case 8:
206
206
  // dify ai
207
- res = await getDifySimpleReply({ content, uid, config });
207
+ res = await getDifySimpleReply({ content, id, inputs: { uid, uname, roomId, roomName }, config });
208
208
  replys = res;
209
209
  break;
210
210
  case 9:
211
211
  // fast gpt
212
- res = await getSimpleGptReply({ content, uid, config, isFastGPT: true });
212
+ res = await getSimpleGptReply({ content, uid: id, config, isFastGPT: true, variables: { uid, uname, roomId, roomName } });
213
213
  replys = res;
214
214
  break;
215
215
  case 11:
216
216
  // coze
217
- res = await getCozeSimpleReply({ content, uid, config, isFastGPT: true });
217
+ res = await getCozeSimpleReply({ content, uid: id, config, isFastGPT: true });
218
218
  replys = res;
219
219
  break;
220
220
  default:
@@ -126,12 +126,13 @@ export function keywordsMsg({ msg, config, room, isMention }: {
126
126
  room: any;
127
127
  isMention: any;
128
128
  }): Promise<any>;
129
- export function robotMsg({ msg, name, id, config, isMention, room, roomId, isFriend }: {
129
+ export function robotMsg({ msg, name, id, config, isMention, roomName, room, roomId, isFriend }: {
130
130
  msg: any;
131
131
  name: any;
132
132
  id: any;
133
133
  config: any;
134
134
  isMention: any;
135
+ roomName: any;
135
136
  room: any;
136
137
  roomId: any;
137
138
  isFriend: any;
@@ -254,7 +254,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
254
254
  return [];
255
255
  }
256
256
  }
257
- async function robotMsg({ msg, name, id, config, isMention, room, roomId, isFriend }) {
257
+ async function robotMsg({ msg, name, id, config, isMention, roomName, room, roomId, isFriend }) {
258
258
  // 如果群里没有提及不开启机器人聊天
259
259
  if (room && !isMention && config.roomAt || room && !isMention && !config.roomAt && isFriend && config.friendNoReplyInRoom) {
260
260
  return [];
@@ -264,7 +264,7 @@ async function robotMsg({ msg, name, id, config, isMention, room, roomId, isFrie
264
264
  let msgArr = []; // 返回的消息列表
265
265
  if (config.autoReply) {
266
266
  console.log('开启了机器人自动回复功能');
267
- msgArr = await dispatch.dispatchAiBot(config.defaultBot, msg, name, `${roomId ? roomId + '_' : ''}${id}`);
267
+ msgArr = await dispatch.dispatchAiBot({ bot: config.defaultBot, msg, name, uname: name, uid: id, roomName: roomName || '', roomId: roomId || '', id: `${roomId ? roomId + '_' : ''}${id}` });
268
268
  }
269
269
  else {
270
270
  console.log('没有开启机器人自动回复功能');
@@ -355,9 +355,13 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
355
355
  const msgArr = await dispatchBot({
356
356
  botType: finalConfig.robotType,
357
357
  content: msg,
358
- uid: `${roomId ? roomId + '_' : ''}${id}`,
358
+ id: `${roomId ? roomId + '_' : ''}${id}`,
359
359
  adminId: finalConfig.id,
360
- config: finalConfig.botConfig
360
+ config: finalConfig.botConfig,
361
+ uid: id,
362
+ uname: name,
363
+ roomId,
364
+ roomName
361
365
  });
362
366
  if (msgArr.length)
363
367
  return msgArr;
@@ -558,7 +562,7 @@ export async function summerChat({ that, msg, name, id, config, room, isMention,
558
562
  console.log('获取到的聊天内容', content);
559
563
  }
560
564
  console.log('开始总结聊天内容');
561
- const res = await dispatch.dispatchSummerBot({ content, config: item, uid: room ? `${roomId}_${id}` : id });
565
+ const res = await dispatch.dispatchSummerBot({ content, config: item, uid: id, uname: name, roomId: roomId, roomName, id: room ? `${roomId ? roomId + '_' : ''}${id}` : id });
562
566
  return res;
563
567
  }
564
568
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.57",
3
+ "version": "1.6.58",
4
4
  "description": "智能微秘书插件",
5
5
  "exports": {
6
6
  ".": {