wechaty-web-panel 1.6.123 → 1.6.125
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/dist/common/index.js +1 -1
- package/dist/package-json.js +1 -1
- package/dist/service/msg-filters.js +7 -4
- package/dist/task/customTask.js +49 -0
- package/dist/task/index.js +8 -1
- package/package.json +1 -1
- package/src/common/index.js +1 -1
- package/src/package-json.js +1 -1
- package/src/service/msg-filters.js +7 -4
- package/src/task/customTask.js +50 -0
- package/src/task/index.js +8 -2
package/dist/common/index.js
CHANGED
|
@@ -98,7 +98,7 @@ async function updateContactInfo(that, noCache = false) {
|
|
|
98
98
|
return payload.friend && !notids.includes(payload.id) && !payload.id.includes('gh_');
|
|
99
99
|
});
|
|
100
100
|
for (let i of realContact) {
|
|
101
|
-
await i.sync()
|
|
101
|
+
// await i.sync()
|
|
102
102
|
let contact = i.payload || i._payload;
|
|
103
103
|
let obj = {
|
|
104
104
|
robotId: contactSelf.robotId,
|
package/dist/package-json.js
CHANGED
|
@@ -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}】发送的内容:${
|
|
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(token, baseurl);
|
|
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
|
package/dist/task/index.js
CHANGED
|
@@ -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 =
|
|
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
package/src/common/index.js
CHANGED
|
@@ -103,7 +103,7 @@ async function updateContactInfo(that, noCache = false) {
|
|
|
103
103
|
return payload.friend && !notids.includes(payload.id) && !payload.id.includes('gh_')
|
|
104
104
|
})
|
|
105
105
|
for (let i of realContact) {
|
|
106
|
-
await i.sync()
|
|
106
|
+
// await i.sync()
|
|
107
107
|
let contact = i.payload || i._payload
|
|
108
108
|
let obj = {
|
|
109
109
|
robotId: contactSelf.robotId,
|
package/src/package-json.js
CHANGED
|
@@ -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}】发送的内容:${
|
|
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(token, baseurl);
|
|
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 =
|
|
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) {
|