wechaty-web-panel 1.6.124 → 1.6.126

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.
@@ -159,11 +159,20 @@ export class DifyClient {
159
159
  user,
160
160
  streaming
161
161
  };
162
- return this.sendRequest(routes.textToAudio.method, routes.textToAudio.url(), data, null, streaming);
162
+ return this.sendRequest({
163
+ method: routes.textToAudio.method,
164
+ endpoint: routes.textToAudio.url(),
165
+ data,
166
+ stream: streaming
167
+ });
163
168
  }
164
169
  getMeta(user) {
165
170
  const params = { user };
166
- return this.sendRequest(routes.meta.method, routes.meta.url(), null, params);
171
+ return this.sendRequest({
172
+ method: routes.getMeta.method,
173
+ endpoint: routes.getMeta.url(),
174
+ params
175
+ });
167
176
  }
168
177
  }
169
178
  export class CompletionClient extends DifyClient {
@@ -187,7 +196,12 @@ export class CompletionClient extends DifyClient {
187
196
  user,
188
197
  response_mode: stream ? "streaming" : "blocking",
189
198
  };
190
- return this.sendRequest(routes.runWorkflow.method, routes.runWorkflow.url(), data, null, stream);
199
+ return this.sendRequest({
200
+ method: routes.runWorkflow.method,
201
+ endpoint: routes.runWorkflow.url(),
202
+ data,
203
+ stream
204
+ });
191
205
  }
192
206
  }
193
207
  export class ChatClient extends DifyClient {
@@ -219,7 +233,7 @@ export class ChatClient extends DifyClient {
219
233
  function unicodeToChar(text) {
220
234
  if (!text)
221
235
  return '';
222
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
236
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
223
237
  return String.fromCharCode(parseInt(p1, 16));
224
238
  });
225
239
  }
@@ -303,7 +317,7 @@ export class ChatClient extends DifyClient {
303
317
  if (this.debug) {
304
318
  console.log('dify request error', res.data.code, res.data.message);
305
319
  }
306
- return Promise.reject(res.message);
320
+ return Promise.reject(res.data.message);
307
321
  }
308
322
  const response = res.data;
309
323
  return {
@@ -345,15 +359,26 @@ export class ChatClient extends DifyClient {
345
359
  }
346
360
  getSuggested(message_id, user) {
347
361
  const data = { user };
348
- return this.sendRequest(routes.getSuggested.method, routes.getSuggested.url(message_id), data);
362
+ return this.sendRequest({
363
+ method: routes.getSuggested.method,
364
+ endpoint: routes.getSuggested.url(message_id),
365
+ params: data
366
+ });
349
367
  }
350
368
  stopMessage(task_id, user) {
351
369
  const data = { user };
352
- return this.sendRequest(routes.stopChatMessage.method, routes.stopChatMessage.url(task_id), data);
370
+ return this.sendRequest({
371
+ method: routes.stopChatMessage.method,
372
+ endpoint: routes.stopChatMessage.url(task_id),
373
+ data
374
+ });
353
375
  }
354
376
  audioToText(data) {
355
- return this.sendRequest(routes.audioToText.method, routes.audioToText.url(), data, null, false, {
356
- "Content-Type": 'multipart/form-data'
377
+ return this.sendRequest({
378
+ method: routes.audioToText.method,
379
+ endpoint: routes.audioToText.url(),
380
+ data,
381
+ headerParams: { 'Content-Type': 'multipart/form-data' }
357
382
  });
358
383
  }
359
384
  }
@@ -364,25 +389,42 @@ export class WorkflowClient extends DifyClient {
364
389
  response_mode: stream ? "streaming" : "blocking",
365
390
  user
366
391
  };
367
- return this.sendRequest(routes.runWorkflow.method, routes.runWorkflow.url(), data, null, stream);
392
+ return this.sendRequest({
393
+ method: routes.runWorkflow.method,
394
+ endpoint: routes.runWorkflow.url(),
395
+ data,
396
+ stream
397
+ });
368
398
  }
369
399
  stop(task_id, user) {
370
400
  const data = { user };
371
- return this.sendRequest(routes.stopWorkflow.method, routes.stopWorkflow.url(task_id), data);
401
+ return this.sendRequest({
402
+ method: routes.stopWorkflow.method,
403
+ endpoint: routes.stopWorkflow.url(task_id),
404
+ data
405
+ });
372
406
  }
373
407
  info(user) {
374
408
  const params = { user };
375
- return this.sendRequest(routes.getWorkflowInfo.method, routes.getWorkflowInfo.url(), null, params);
409
+ console.log('获取工作流信息', routes.getWorkflowInfo.method, routes.getWorkflowInfo.url());
410
+ return this.sendRequest({
411
+ method: routes.getWorkflowInfo.method,
412
+ endpoint: routes.getWorkflowInfo.url(),
413
+ params
414
+ });
376
415
  }
377
416
  result(task_id) {
378
- return this.sendRequest(routes.getWorkflowResult.method, routes.getWorkflowResult.url(task_id), null);
417
+ return this.sendRequest({
418
+ method: routes.getWorkflowResult.method,
419
+ endpoint: routes.getWorkflowResult.url(task_id)
420
+ });
379
421
  }
380
422
  async getWorkflowResult(input, user, isStream) {
381
423
  const res = await this.run(input, user, isStream);
382
424
  function unicodeToChar(text) {
383
425
  if (!text)
384
426
  return '';
385
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
427
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
386
428
  return String.fromCharCode(parseInt(p1, 16));
387
429
  });
388
430
  }
@@ -413,6 +455,7 @@ export class WorkflowClient extends DifyClient {
413
455
  task_id = res?.workflow_run_id;
414
456
  console.log('工作流node节点执行任务中');
415
457
  }
458
+ console.log('工作流输出结果', res.event, res.data);
416
459
  if (res.event === 'workflow_finished' || res.event === 'tts_message_end') {
417
460
  console.log('工作流执行完毕,正在组装数据进行发送');
418
461
  task_id = res?.workflow_run_id;
@@ -421,12 +464,13 @@ export class WorkflowClient extends DifyClient {
421
464
  });
422
465
  });
423
466
  stream.on('end', async () => {
467
+ console.log('执行工作流结束');
424
468
  const { data } = task_id ? await this.result(task_id) : { data: { outputs: '' } };
425
469
  console.log('获取工作流执行结果', task_id, JSON.stringify(data.outputs));
426
470
  let outputs = {};
427
471
  if (data.outputs) {
428
472
  try {
429
- outputs = JSON.parse(data.outputs);
473
+ outputs = typeof data.outputs === 'object' ? data.outputs : JSON.parse(data.outputs);
430
474
  }
431
475
  catch (error) {
432
476
  console.log(`获取工作流执行结果,失败:${error}`);
@@ -443,7 +487,7 @@ export class WorkflowClient extends DifyClient {
443
487
  if (!isStream) {
444
488
  if (res.data.code) {
445
489
  console.log('Dify 工作流执行失败', res.data.code, res.data.message);
446
- return Promise.reject(res.message);
490
+ return Promise.reject(res.data.message);
447
491
  }
448
492
  const response = res.data;
449
493
  return {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.124",
6
+ "version": "1.6.126",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js"
@@ -494,8 +494,11 @@ function checkKeyword(forward, msg) {
494
494
  }
495
495
  return false;
496
496
  }
497
- function getForwardConfig({ name, id, room, roomId, roomName, msg, config }) {
497
+ function getForwardConfig({ name, id, room, roomId, roomName, msg, config, sourceMsg }) {
498
498
  const configs = config.forwards;
499
+ if (room) {
500
+ msg = sourceMsg.text();
501
+ }
499
502
  if (configs && configs.length) {
500
503
  let finalConfig = '';
501
504
  if (room) {
@@ -551,17 +554,17 @@ async function getTargets(that, targets, type) {
551
554
  }
552
555
  return finalTargets;
553
556
  }
554
- export async function keywordForward({ that, msg, name, id, config, room, isMention, roomId, roomName }) {
557
+ export async function keywordForward({ that, msg, name, id, config, room, isMention, roomId, roomName, sourceMsg }) {
555
558
  try {
556
559
  const forwards = config.forwards || [];
557
560
  if (forwards.length) {
558
- const finalConfig = getForwardConfig({ name, id, room, msg, config, roomId, roomName });
561
+ const finalConfig = getForwardConfig({ name, id, room, msg, config, roomId, roomName, sourceMsg });
559
562
  if (finalConfig) {
560
563
  const finalTargets = await getTargets(that, finalConfig.forwardTargets, finalConfig.forwardType);
561
564
  if (finalTargets.length) {
562
565
  const eol = await getPuppetEol();
563
566
  for (let contact of finalTargets) {
564
- const content = room ? `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到群聊【${roomName}】中【${name}】发送的内容:${msg}` : `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到好友【${name}】发送的内容:${msg}`;
567
+ const content = room ? `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到群聊【${roomName}】中【${name}】发送的内容:${sourceMsg.text()}` : `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到好友【${name}】发送的内容:${msg}`;
565
568
  await contact.say(content);
566
569
  await delay(3000);
567
570
  }
@@ -0,0 +1,49 @@
1
+ import { WorkflowClient } from '../bot/dify/sdk/index.js';
2
+ const getDifyWorkflowContent = async (baseurl, token, inputs) => {
3
+ try {
4
+ const user = 'dify-schedule';
5
+ console.log('getDifyWorkflowContent request info:', baseurl, token, inputs);
6
+ const workflow = new WorkflowClient({ apiKey: token, baseUrl: baseurl, stream: true });
7
+ console.log(`正在获取Dify工作流基础信息...`);
8
+ const info = await workflow.info(user);
9
+ console.log(`Dify工作流【${info.data.name}】开始执行...`);
10
+ const response = await workflow.getWorkflowResult(inputs, user, true);
11
+ return response;
12
+ }
13
+ catch (error) {
14
+ console.log('getDifyWorkflowContent', error);
15
+ return error && error.toString();
16
+ }
17
+ };
18
+ async function getDifyContent(taskInfo) {
19
+ const baseUrl = taskInfo.baseUrl || '';
20
+ const token = taskInfo.apikey || '';
21
+ if (!baseUrl || !token) {
22
+ return [{ type: 1, content: 'Dify工作流未配置服务地址或密钥,请配置后重新设置定时任务!' }];
23
+ }
24
+ const inputs = {};
25
+ const variables = taskInfo.variables || [];
26
+ variables.forEach((item) => {
27
+ if (item.key && item.value) {
28
+ inputs[item.key] = item.value;
29
+ }
30
+ });
31
+ const res = await getDifyWorkflowContent(baseUrl, token, inputs);
32
+ const reply = [];
33
+ if (res.text) {
34
+ reply.push({ type: 1, content: res.text });
35
+ }
36
+ if (res.img) {
37
+ reply.push({ type: 2, url: encodeURI(res.img) });
38
+ }
39
+ return reply;
40
+ }
41
+ export async function dispatchLocalCustomContent(taskId, taskInfo) {
42
+ if (parseInt(taskId) === 30001) {
43
+ return await getDifyContent(taskInfo);
44
+ }
45
+ else {
46
+ return [];
47
+ }
48
+ }
49
+ //# sourceMappingURL=customTask.js.map
@@ -3,6 +3,7 @@ import { allConfig } from "../db/configDb.js";
3
3
  import { getScheduleList, updateSchedule } from "../proxy/aibotk.js";
4
4
  import { getNewsContent, getEveryDayContent, roomSay, getRoomEveryDayContent, contactSay, getCountDownContent, getCustomContent } from "../common/index.js";
5
5
  import globalConfig from "../db/global.js";
6
+ import { dispatchLocalCustomContent } from './customTask.js';
6
7
  const typeMap = {
7
8
  contact: "用户名", room: "群名"
8
9
  };
@@ -155,7 +156,13 @@ async function sendNews({ that, target, item, isMulti, targets }) {
155
156
  */
156
157
  async function sendCustomContent({ that, target, type, item, isMulti, targets, taskId }) {
157
158
  console.log("发送定制内容开始,目标:", item.sortId, taskId);
158
- let contents = await getCustomContent(item.sortId, taskId);
159
+ let contents = [];
160
+ if (item.isLocal) {
161
+ contents = await dispatchLocalCustomContent(item.sortId, item);
162
+ }
163
+ else {
164
+ contents = await getCustomContent(item.sortId, taskId);
165
+ }
159
166
  console.log("定制内容发送", contents);
160
167
  if (!isMulti) {
161
168
  for (const reply of contents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.124",
3
+ "version": "1.6.126",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js"
@@ -179,22 +179,20 @@ export class DifyClient {
179
179
  user,
180
180
  streaming
181
181
  };
182
- return this.sendRequest(
183
- routes.textToAudio.method,
184
- routes.textToAudio.url(),
182
+ return this.sendRequest({
183
+ method: routes.textToAudio.method,
184
+ endpoint: routes.textToAudio.url(),
185
185
  data,
186
- null,
187
- streaming
188
- );
186
+ stream: streaming
187
+ });
189
188
  }
190
189
  getMeta(user) {
191
190
  const params = { user };
192
- return this.sendRequest(
193
- routes.meta.method,
194
- routes.meta.url(),
195
- null,
191
+ return this.sendRequest({
192
+ method: routes.getMeta.method,
193
+ endpoint: routes.getMeta.url(),
196
194
  params
197
- );
195
+ });
198
196
  }
199
197
  }
200
198
 
@@ -219,13 +217,12 @@ export class CompletionClient extends DifyClient {
219
217
  user,
220
218
  response_mode: stream ? "streaming" : "blocking",
221
219
  };
222
- return this.sendRequest(
223
- routes.runWorkflow.method,
224
- routes.runWorkflow.url(),
220
+ return this.sendRequest({
221
+ method: routes.runWorkflow.method,
222
+ endpoint: routes.runWorkflow.url(),
225
223
  data,
226
- null,
227
224
  stream
228
- );
225
+ });
229
226
  }
230
227
  }
231
228
 
@@ -261,7 +258,7 @@ export class ChatClient extends DifyClient {
261
258
  if (!text)
262
259
  return ''
263
260
 
264
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
261
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
265
262
  return String.fromCharCode(parseInt(p1, 16))
266
263
  })
267
264
  }
@@ -344,7 +341,7 @@ export class ChatClient extends DifyClient {
344
341
  if (this.debug) {
345
342
  console.log('dify request error', res.data.code, res.data.message)
346
343
  }
347
- return Promise.reject(res.message)
344
+ return Promise.reject(res.data.message)
348
345
  }
349
346
 
350
347
  const response = res.data
@@ -390,31 +387,27 @@ export class ChatClient extends DifyClient {
390
387
  }
391
388
  getSuggested(message_id, user) {
392
389
  const data = { user };
393
- return this.sendRequest(
394
- routes.getSuggested.method,
395
- routes.getSuggested.url(message_id),
396
- data
397
- );
390
+ return this.sendRequest({
391
+ method: routes.getSuggested.method,
392
+ endpoint: routes.getSuggested.url(message_id),
393
+ params: data
394
+ });
398
395
  }
399
396
  stopMessage(task_id, user) {
400
397
  const data = { user };
401
- return this.sendRequest(
402
- routes.stopChatMessage.method,
403
- routes.stopChatMessage.url(task_id),
398
+ return this.sendRequest({
399
+ method: routes.stopChatMessage.method,
400
+ endpoint: routes.stopChatMessage.url(task_id),
404
401
  data
405
- );
402
+ });
406
403
  }
407
404
  audioToText(data) {
408
- return this.sendRequest(
409
- routes.audioToText.method,
410
- routes.audioToText.url(),
405
+ return this.sendRequest({
406
+ method: routes.audioToText.method,
407
+ endpoint: routes.audioToText.url(),
411
408
  data,
412
- null,
413
- false,
414
- {
415
- "Content-Type": 'multipart/form-data'
416
- }
417
- );
409
+ headerParams: { 'Content-Type': 'multipart/form-data' }
410
+ });
418
411
  }
419
412
  }
420
413
 
@@ -427,38 +420,37 @@ export class WorkflowClient extends DifyClient {
427
420
  user
428
421
  };
429
422
 
430
- return this.sendRequest(
431
- routes.runWorkflow.method,
432
- routes.runWorkflow.url(),
423
+ return this.sendRequest({
424
+ method: routes.runWorkflow.method,
425
+ endpoint: routes.runWorkflow.url(),
433
426
  data,
434
- null,
435
427
  stream
436
- );
428
+ });
437
429
  }
438
430
 
439
431
  stop(task_id, user) {
440
432
  const data = { user };
441
- return this.sendRequest(
442
- routes.stopWorkflow.method,
443
- routes.stopWorkflow.url(task_id),
433
+ return this.sendRequest({
434
+ method: routes.stopWorkflow.method,
435
+ endpoint: routes.stopWorkflow.url(task_id),
444
436
  data
445
- );
437
+ });
446
438
  }
447
439
  info(user) {
448
440
  const params = { user };
449
- return this.sendRequest(
450
- routes.getWorkflowInfo.method,
451
- routes.getWorkflowInfo.url(),
452
- null,
441
+ console.log('获取工作流信息', routes.getWorkflowInfo.method,
442
+ routes.getWorkflowInfo.url())
443
+ return this.sendRequest({
444
+ method: routes.getWorkflowInfo.method,
445
+ endpoint: routes.getWorkflowInfo.url(),
453
446
  params
454
- );
447
+ });
455
448
  }
456
449
  result(task_id) {
457
- return this.sendRequest(
458
- routes.getWorkflowResult.method,
459
- routes.getWorkflowResult.url(task_id),
460
- null
461
- );
450
+ return this.sendRequest({
451
+ method: routes.getWorkflowResult.method,
452
+ endpoint: routes.getWorkflowResult.url(task_id)
453
+ });
462
454
  }
463
455
  async getWorkflowResult(input, user, isStream) {
464
456
  const res = await this.run(input, user, isStream)
@@ -466,7 +458,7 @@ export class WorkflowClient extends DifyClient {
466
458
  if (!text)
467
459
  return ''
468
460
 
469
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
461
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
470
462
  return String.fromCharCode(parseInt(p1, 16))
471
463
  })
472
464
  }
@@ -497,6 +489,7 @@ export class WorkflowClient extends DifyClient {
497
489
  task_id = res?.workflow_run_id
498
490
  console.log('工作流node节点执行任务中')
499
491
  }
492
+ console.log('工作流输出结果', res.event, res.data)
500
493
  if (res.event === 'workflow_finished' || res.event === 'tts_message_end') {
501
494
  console.log('工作流执行完毕,正在组装数据进行发送')
502
495
  task_id = res?.workflow_run_id
@@ -505,13 +498,13 @@ export class WorkflowClient extends DifyClient {
505
498
  })
506
499
  })
507
500
  stream.on('end', async () => {
508
-
501
+ console.log('执行工作流结束')
509
502
  const { data } = task_id ? await this.result(task_id) : { data: { outputs: '' } }
510
503
  console.log('获取工作流执行结果', task_id, JSON.stringify(data.outputs))
511
504
  let outputs = {}
512
505
  if(data.outputs) {
513
506
  try {
514
- outputs = JSON.parse(data.outputs)
507
+ outputs = typeof data.outputs === 'object' ? data.outputs : JSON.parse(data.outputs)
515
508
  } catch (error) {
516
509
  console.log(`获取工作流执行结果,失败:${error}`)
517
510
  }
@@ -527,7 +520,7 @@ export class WorkflowClient extends DifyClient {
527
520
  if (!isStream) {
528
521
  if (res.data.code) {
529
522
  console.log('Dify 工作流执行失败', res.data.code, res.data.message)
530
- return Promise.reject(res.message)
523
+ return Promise.reject(res.data.message)
531
524
  }
532
525
  const response = res.data
533
526
  return {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.124",
6
+ "version": "1.6.126",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js"
@@ -485,8 +485,11 @@ function checkKeyword(forward, msg) {
485
485
  return false;
486
486
  }
487
487
 
488
- function getForwardConfig({ name, id, room, roomId, roomName, msg, config }) {
488
+ function getForwardConfig({ name, id, room, roomId, roomName, msg, config, sourceMsg }) {
489
489
  const configs = config.forwards
490
+ if(room) {
491
+ msg = sourceMsg.text()
492
+ }
490
493
  if (configs && configs.length) {
491
494
  let finalConfig = ''
492
495
  if (room) {
@@ -541,17 +544,17 @@ async function getTargets(that, targets, type) {
541
544
  return finalTargets;
542
545
  }
543
546
 
544
- export async function keywordForward({ that, msg, name, id, config, room, isMention, roomId, roomName }) {
547
+ export async function keywordForward({ that, msg, name, id, config, room, isMention, roomId, roomName, sourceMsg }) {
545
548
  try {
546
549
  const forwards = config.forwards || [];
547
550
  if(forwards.length) {
548
- const finalConfig = getForwardConfig({ name, id, room, msg, config, roomId, roomName })
551
+ const finalConfig = getForwardConfig({ name, id, room, msg, config, roomId, roomName, sourceMsg })
549
552
  if(finalConfig) {
550
553
  const finalTargets = await getTargets(that, finalConfig.forwardTargets, finalConfig.forwardType)
551
554
  if(finalTargets.length) {
552
555
  const eol = await getPuppetEol()
553
556
  for(let contact of finalTargets) {
554
- const content = room ? `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到群聊【${roomName}】中【${name}】发送的内容:${msg}` : `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到好友【${name}】发送的内容:${msg}`
557
+ const content = room ? `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到群聊【${roomName}】中【${name}】发送的内容:${sourceMsg.text()}` : `【关键词转发】${eol} 时间:${dayjs().format('MM-DD HH:mm:ss')} ${eol}收到好友【${name}】发送的内容:${msg}`
555
558
  await contact.say(content)
556
559
  await delay(3000)
557
560
  }
@@ -0,0 +1,50 @@
1
+
2
+
3
+ import { WorkflowClient } from '../bot/dify/sdk/index.js';
4
+
5
+ const getDifyWorkflowContent = async (baseurl, token, inputs) => {
6
+ try {
7
+ const user = 'dify-schedule'
8
+ console.log('getDifyWorkflowContent request info:', baseurl, token, inputs)
9
+ const workflow = new WorkflowClient({apiKey: token, baseUrl: baseurl, stream: true});
10
+ console.log(`正在获取Dify工作流基础信息...`)
11
+ const info = await workflow.info(user);
12
+ console.log(`Dify工作流【${info.data.name}】开始执行...`)
13
+ const response = await workflow.getWorkflowResult(inputs, user, true)
14
+ return response
15
+ } catch (error) {
16
+ console.log('getDifyWorkflowContent', error)
17
+ return error && error.toString()
18
+ }
19
+ }
20
+ async function getDifyContent(taskInfo) {
21
+ const baseUrl = taskInfo.baseUrl || '';
22
+ const token = taskInfo.apikey || '';
23
+ if (!baseUrl || !token) {
24
+ return [{ type: 1, content: 'Dify工作流未配置服务地址或密钥,请配置后重新设置定时任务!' }];
25
+ }
26
+ const inputs = {}
27
+ const variables = taskInfo.variables || [];
28
+ variables.forEach((item) => {
29
+ if (item.key && item.value) {
30
+ inputs[item.key] = item.value;
31
+ }
32
+ });
33
+ const res = await getDifyWorkflowContent(baseUrl, token, inputs);
34
+ const reply = []
35
+ if (res.text) {
36
+ reply.push({ type: 1, content: res.text })
37
+ }
38
+ if (res.img) {
39
+ reply.push({ type: 2, url: encodeURI(res.img) })
40
+ }
41
+ return reply;
42
+ }
43
+
44
+ export async function dispatchLocalCustomContent(taskId, taskInfo) {
45
+ if (parseInt(taskId) === 30001) {
46
+ return await getDifyContent(taskInfo);
47
+ } else {
48
+ return []
49
+ }
50
+ }
package/src/task/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  getNewsContent, getEveryDayContent, roomSay, getRoomEveryDayContent, contactSay, getCountDownContent, getCustomContent
6
6
  } from "../common/index.js";
7
7
  import globalConfig from "../db/global.js";
8
-
8
+ import { dispatchLocalCustomContent } from './customTask.js'
9
9
  const typeMap = {
10
10
  contact: "用户名", room: "群名"
11
11
  };
@@ -149,7 +149,13 @@ async function sendNews ({ that, target, item, isMulti, targets }) {
149
149
  */
150
150
  async function sendCustomContent ({ that, target, type, item, isMulti, targets, taskId }) {
151
151
  console.log("发送定制内容开始,目标:", item.sortId, taskId);
152
- let contents = await getCustomContent(item.sortId, taskId);
152
+ let contents = []
153
+ if(item.isLocal) {
154
+ contents = await dispatchLocalCustomContent(item.sortId, item)
155
+ } else {
156
+ contents = await getCustomContent(item.sortId, taskId);
157
+ }
158
+
153
159
  console.log("定制内容发送", contents);
154
160
 
155
161
  if (!isMulti) {