wechaty-web-panel 1.6.111 → 1.6.113
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/bot/chatgpt/index.js +235 -0
- package/dist/bot/coze/sdk/index.js +110 -0
- package/dist/bot/dify/sdk/index.js +461 -0
- package/dist/bot/dify/sdk/office.js +319 -0
- package/dist/bot/fastgpt/index.js +98 -0
- package/dist/bot/qanything/index.js +136 -0
- package/dist/botInstance/coze.js +167 -0
- package/dist/botInstance/cozev3.js +157 -0
- package/dist/botInstance/dify.js +160 -0
- package/dist/botInstance/fastgpt.js +130 -0
- package/dist/botInstance/gpt4v.js +95 -0
- package/dist/botInstance/officialOpenAi.js +186 -0
- package/dist/botInstance/qany.js +144 -0
- package/dist/botInstance/sdk/chatGPT4V.js +89 -0
- package/dist/botInstance/sdk/coze.js +200 -0
- package/dist/botInstance/sdk/difyClient.js +354 -0
- package/dist/botInstance/sdk/pTimeout.js +97 -0
- package/dist/botInstance/sdk/qanything.js +137 -0
- package/dist/botInstance/sdk/quick-lru.js +237 -0
- package/dist/common/hook.js +66 -0
- package/dist/common/index.js +513 -0
- package/dist/common/multiReply.js +158 -0
- package/dist/common/reply.js +23 -0
- package/dist/const/puppet-type.js +71 -0
- package/dist/db/aiDb.js +27 -0
- package/dist/db/aichatDb.js +84 -0
- package/dist/db/chatHistory.js +137 -0
- package/dist/db/configDb.js +97 -0
- package/dist/db/global.js +62 -0
- package/dist/db/gptConfig.js +85 -0
- package/dist/db/nedb.js +88 -0
- package/dist/db/puppetDb.js +58 -0
- package/dist/db/roomDb.js +83 -0
- package/dist/db/rssConfig.js +82 -0
- package/dist/db/rssHistory.js +88 -0
- package/dist/db/userDb.js +27 -0
- package/dist/handlers/on-callback-message.js +183 -0
- package/dist/handlers/on-error.js +5 -0
- package/dist/handlers/on-friend.js +62 -0
- package/dist/handlers/on-heartbeat.js +20 -0
- package/dist/handlers/on-login.js +58 -0
- package/dist/handlers/on-logout.js +17 -0
- package/dist/handlers/on-message.js +644 -0
- package/dist/handlers/on-ready.js +36 -0
- package/dist/handlers/on-record-message.js +56 -0
- package/dist/handlers/on-roomjoin.js +42 -0
- package/dist/handlers/on-roomleave.js +12 -0
- package/dist/handlers/on-roomtopic.js +16 -0
- package/dist/handlers/on-scan.js +64 -0
- package/dist/handlers/on-verifycode.js +42 -0
- package/dist/index.js +81 -69306
- package/dist/lib/contentCensor.js +23 -0
- package/dist/lib/index.js +562 -0
- package/dist/lib/oss.js +43 -0
- package/dist/lib/s3oss.js +33 -0
- package/dist/mcp/mcp-server.js +26 -0
- package/dist/mcp/src/config/database.js +51 -0
- package/dist/mcp/src/index.js +238 -0
- package/dist/mcp/src/mcp/schemas.js +178 -0
- package/dist/mcp/src/mcp/server.js +421 -0
- package/dist/mcp/src/mcp/streamable-server.js +690 -0
- package/dist/mcp/src/models/ChatMessage.js +151 -0
- package/dist/mcp/src/models/Friend.js +64 -0
- package/dist/mcp/src/models/Group.js +55 -0
- package/dist/mcp/src/models/GroupMember.js +67 -0
- package/dist/mcp/src/models/index.js +27 -0
- package/dist/mcp/src/scripts/migrate.js +21 -0
- package/dist/mcp/src/services/ChatDataService.js +284 -0
- package/dist/mcp/src/services/McpService.js +521 -0
- package/dist/mcp/src/services/McpTools.js +504 -0
- package/dist/mcp/streamable-examples.js +283 -0
- package/dist/mcp/streamable-server.js +79 -0
- package/dist/mcp/test-mcp.js +64 -0
- package/dist/mcp/test-streamable-server.js +86 -0
- package/dist/package-json.js +89 -0
- package/dist/proxy/aibotk.js +829 -0
- package/dist/proxy/api.js +431 -0
- package/dist/proxy/apib.js +587 -0
- package/dist/proxy/bot/chatgpt.js +38 -0
- package/dist/proxy/bot/coze.js +38 -0
- package/dist/proxy/bot/cozev3.js +38 -0
- package/dist/proxy/bot/dify.js +38 -0
- package/dist/proxy/bot/dispatch.js +81 -0
- package/dist/proxy/bot/fastgpt.js +27 -0
- package/dist/proxy/bot/qany.js +27 -0
- package/dist/proxy/config.js +14 -0
- package/dist/proxy/cozeAi.js +60 -0
- package/dist/proxy/cozeV3Ai.js +60 -0
- package/dist/proxy/difyAi.js +58 -0
- package/dist/proxy/fastgpt.js +55 -0
- package/dist/proxy/mqtt.js +275 -0
- package/dist/proxy/multimodal.js +122 -0
- package/dist/proxy/openAi.js +63 -0
- package/dist/proxy/outapi.js +62 -0
- package/dist/proxy/qAnyAi.js +57 -0
- package/dist/proxy/superagent.js +200 -0
- package/dist/proxy/tencent-open.js +255 -0
- package/dist/service/event-dispatch-service.js +309 -0
- package/dist/service/gpt4vService.js +45 -0
- package/dist/service/msg-filter-service.js +121 -0
- package/dist/service/msg-filters.js +645 -0
- package/dist/service/room-async-service.js +455 -0
- package/dist/task/index.js +535 -0
- package/dist/task/rss.js +174 -0
- package/package.json +3 -3
- package/src/package-json.js +3 -3
- package/tsconfig.json +3 -12
- package/dist/index.d.ts +0 -9
- package/tsconfig.cjs.json +0 -12
|
@@ -0,0 +1,829 @@
|
|
|
1
|
+
import { aiBotReq, req } from './superagent.js';
|
|
2
|
+
import { updateConfig } from '../db/configDb.js';
|
|
3
|
+
import { packageJson } from '../package-json.js';
|
|
4
|
+
import { updateAllRssConfig, resetRssData } from "../db/rssConfig.js";
|
|
5
|
+
import { getPuppetEol } from "../const/puppet-type.js";
|
|
6
|
+
import globalConfig from "../db/global.js";
|
|
7
|
+
/**
|
|
8
|
+
* 获取美女图片
|
|
9
|
+
*/
|
|
10
|
+
async function getMeiNv() {
|
|
11
|
+
try {
|
|
12
|
+
let option = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
url: '/meinv',
|
|
15
|
+
params: {},
|
|
16
|
+
};
|
|
17
|
+
let content = await aiBotReq(option);
|
|
18
|
+
let pics = content.data.pics || [];
|
|
19
|
+
if (pics.length) {
|
|
20
|
+
let url = pics[0];
|
|
21
|
+
return url.includes('.jpg') ? url : 'https://tva2.sinaimg.cn/large/0072Vf1pgy1foxkcsx9rmj31hc0u0h9k.jpg';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
console.log('获取美女图片失败', e);
|
|
26
|
+
return 'https://tva2.sinaimg.cn/large/0072Vf1pgy1foxkcsx9rmj31hc0u0h9k.jpg';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 获取配置词云的所有群名
|
|
31
|
+
*/
|
|
32
|
+
export async function getWordCloudRoom() {
|
|
33
|
+
try {
|
|
34
|
+
let option = {
|
|
35
|
+
method: 'get',
|
|
36
|
+
url: '/wordcloudroom',
|
|
37
|
+
params: {},
|
|
38
|
+
};
|
|
39
|
+
let content = await aiBotReq(option);
|
|
40
|
+
const roomNames = content.data.map(item => item.roomName);
|
|
41
|
+
return roomNames || [];
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.log('群词云配置拉取失败', e);
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 获取群合影配置
|
|
50
|
+
*/
|
|
51
|
+
export async function getWordCloudConfig(roomName) {
|
|
52
|
+
try {
|
|
53
|
+
let option = {
|
|
54
|
+
method: 'get',
|
|
55
|
+
url: '/roomCloud',
|
|
56
|
+
params: { name: roomName },
|
|
57
|
+
};
|
|
58
|
+
let content = await aiBotReq(option);
|
|
59
|
+
return content.data || '';
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.log('群词云配置拉取失败', e);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 获取每日一句
|
|
67
|
+
*/
|
|
68
|
+
async function getOne() {
|
|
69
|
+
try {
|
|
70
|
+
let option = {
|
|
71
|
+
method: 'GET',
|
|
72
|
+
url: '/one',
|
|
73
|
+
params: {},
|
|
74
|
+
timeout: 5 * 60 * 1000
|
|
75
|
+
};
|
|
76
|
+
let content = await aiBotReq(option);
|
|
77
|
+
let word = content.data.word || '今日一句似乎已经消失';
|
|
78
|
+
return word;
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
console.log('获取每日一句失败', e);
|
|
82
|
+
return '今日一句似乎已经消失';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 获取火灾新闻
|
|
87
|
+
*/
|
|
88
|
+
async function getFireNews(id, num) {
|
|
89
|
+
try {
|
|
90
|
+
let option = {
|
|
91
|
+
method: 'GET',
|
|
92
|
+
url: '/firenews',
|
|
93
|
+
params: {
|
|
94
|
+
id,
|
|
95
|
+
num
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
let content = await aiBotReq(option);
|
|
99
|
+
let newList = content.data || [];
|
|
100
|
+
let news = '';
|
|
101
|
+
const eol = await getPuppetEol();
|
|
102
|
+
for (let i in newList) {
|
|
103
|
+
let num = parseInt(i) + 1;
|
|
104
|
+
const url = newList[i].shortUrl ? newList[i].shortUrl : newList[i].url;
|
|
105
|
+
news = `${news}${eol}${num}.${newList[i].title}${url ? `${eol}${url}${eol}` : `${eol}`}`;
|
|
106
|
+
}
|
|
107
|
+
const endMap = {
|
|
108
|
+
1001: '您可以 @消防小助手+新闻标题,通过ChatGPT为您分析时事新闻!',
|
|
109
|
+
1002: '您可以 @消防小助手+新闻标题,通过ChatGPT为您分析今日消防行业招标信息!',
|
|
110
|
+
};
|
|
111
|
+
return `${news}…………………………${eol}${eol}${endMap[id] || ''}`;
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
console.log('获取每日一句失败', e);
|
|
115
|
+
return '今日一句似乎已经消失';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 获取自定义内容
|
|
120
|
+
* @param id
|
|
121
|
+
* @param taskId
|
|
122
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
123
|
+
*/
|
|
124
|
+
export async function getCustomNews(id, taskId) {
|
|
125
|
+
try {
|
|
126
|
+
let option = {
|
|
127
|
+
method: 'GET',
|
|
128
|
+
url: '/customnews',
|
|
129
|
+
params: {
|
|
130
|
+
id,
|
|
131
|
+
taskId
|
|
132
|
+
},
|
|
133
|
+
timeout: 5 * 60 * 1000
|
|
134
|
+
};
|
|
135
|
+
let content = await aiBotReq(option);
|
|
136
|
+
let newContent = content.data || [];
|
|
137
|
+
return newContent;
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
console.log('定制内容获取失败', e);
|
|
141
|
+
return [{ type: 1, content: '定制内容获取失败' }];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 获取自定义技能
|
|
146
|
+
* @param params
|
|
147
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
148
|
+
*/
|
|
149
|
+
export async function getCustomEvents(params) {
|
|
150
|
+
try {
|
|
151
|
+
let option = {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
url: '/customevent',
|
|
154
|
+
params,
|
|
155
|
+
timeout: 5 * 60 * 1000
|
|
156
|
+
};
|
|
157
|
+
let content = await aiBotReq(option);
|
|
158
|
+
let newContent = content.data || [];
|
|
159
|
+
return newContent;
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
console.log('自定义技能获取失败', e);
|
|
163
|
+
return [{ type: 1, content: '自定义技能获取失败' }];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 获取配置文件
|
|
168
|
+
* @returns {Promise<*>}
|
|
169
|
+
*/
|
|
170
|
+
async function getConfig() {
|
|
171
|
+
try {
|
|
172
|
+
let option = {
|
|
173
|
+
method: 'GET',
|
|
174
|
+
url: '/wechat/config',
|
|
175
|
+
params: {},
|
|
176
|
+
};
|
|
177
|
+
let content = await aiBotReq(option);
|
|
178
|
+
const config = JSON.parse(content.data.config);
|
|
179
|
+
let cloudRoom = [];
|
|
180
|
+
if (config.userInfo.role === 'vip') {
|
|
181
|
+
await getGptConfig();
|
|
182
|
+
await getRssConfig();
|
|
183
|
+
await getTasks();
|
|
184
|
+
cloudRoom = await getWordCloudRoom();
|
|
185
|
+
}
|
|
186
|
+
let cres = await updateConfig({
|
|
187
|
+
puppetType: 'wechaty-puppet-wechat',
|
|
188
|
+
no_remind: false, // 不需要开启提醒
|
|
189
|
+
botScope: 'all',
|
|
190
|
+
parseMini: false,
|
|
191
|
+
openaiSystemMessage: '',
|
|
192
|
+
showQuestion: true,
|
|
193
|
+
openaiTimeout: 60,
|
|
194
|
+
chatDelay: 2,
|
|
195
|
+
openaiAccessToken: '',
|
|
196
|
+
openaiDebug: false,
|
|
197
|
+
openaiModel: 'gpt-3.5-turbo',
|
|
198
|
+
temperature: 0.8,
|
|
199
|
+
top_p: 1,
|
|
200
|
+
presence_penalty: 1,
|
|
201
|
+
maxToken: null,
|
|
202
|
+
modelMaxToken: null,
|
|
203
|
+
cozev3_token: '',
|
|
204
|
+
cozev3_botId: '',
|
|
205
|
+
cozev3_baseUrl: '',
|
|
206
|
+
qany_botId: '',
|
|
207
|
+
qany_token: '',
|
|
208
|
+
qany_baseUrl: '',
|
|
209
|
+
dify_token: '',
|
|
210
|
+
dify_baseUrl: '',
|
|
211
|
+
difyAgent: false,
|
|
212
|
+
coze_token: '',
|
|
213
|
+
coze_botId: '',
|
|
214
|
+
coze_baseUrl: '',
|
|
215
|
+
coze_showSuggestions: false,
|
|
216
|
+
proxyUrl: '',
|
|
217
|
+
proxyPassUrl: '',
|
|
218
|
+
chatFilter: 0,
|
|
219
|
+
filterType: 1, // 过滤引擎类型 1 百度文本审核
|
|
220
|
+
filterAppid: '',
|
|
221
|
+
filterApiKey: '',
|
|
222
|
+
filterSecretKey: '',
|
|
223
|
+
countDownTaskSchedule: [],
|
|
224
|
+
parseMiniRooms: [],
|
|
225
|
+
preventLength: 1000,
|
|
226
|
+
preventWords: '',
|
|
227
|
+
customBot: null,
|
|
228
|
+
roomAt: 1,
|
|
229
|
+
friendNoReplyInRoom: 0,
|
|
230
|
+
defaultReply: '',
|
|
231
|
+
forwards: [],
|
|
232
|
+
openRecord: false,
|
|
233
|
+
openWhisper: false,
|
|
234
|
+
whisperConfig: {},
|
|
235
|
+
ignoreRoomMentionAll: true,
|
|
236
|
+
noNeedAt: false,
|
|
237
|
+
uploadFileConfig: null,
|
|
238
|
+
ignoreFiles: false,
|
|
239
|
+
filterLinkContent: false,
|
|
240
|
+
...config,
|
|
241
|
+
cloudRoom
|
|
242
|
+
});
|
|
243
|
+
return cres;
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
246
|
+
console.log('获取配置文件失败:' + e);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 获取gpt配置
|
|
251
|
+
* @return {Promise<*>}
|
|
252
|
+
*/
|
|
253
|
+
export async function getGptConfig() {
|
|
254
|
+
try {
|
|
255
|
+
let option = {
|
|
256
|
+
method: 'GET',
|
|
257
|
+
url: '/gpt/config',
|
|
258
|
+
params: {},
|
|
259
|
+
};
|
|
260
|
+
let content = await aiBotReq(option);
|
|
261
|
+
if (content.data) {
|
|
262
|
+
const list = content.data.map(item => ({ ...item, _id: item.id }));
|
|
263
|
+
globalConfig.updateAllGptConfig(list);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
console.log('获取gpt配置文件失败:' + error);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 获取批量任务
|
|
272
|
+
* @return {Promise<*>}
|
|
273
|
+
*/
|
|
274
|
+
export async function getTasks() {
|
|
275
|
+
try {
|
|
276
|
+
let option = {
|
|
277
|
+
method: 'GET',
|
|
278
|
+
url: '/user/task',
|
|
279
|
+
params: {},
|
|
280
|
+
};
|
|
281
|
+
let content = await aiBotReq(option);
|
|
282
|
+
if (content.data) {
|
|
283
|
+
const list = content.data.map(item => ({ ...item, _id: item.id }));
|
|
284
|
+
globalConfig.updateAllTasks(list);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.log('获取批量任务失败:' + error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* 获取rss配置
|
|
293
|
+
* @return {Promise<*>}
|
|
294
|
+
*/
|
|
295
|
+
export async function getRssConfig() {
|
|
296
|
+
try {
|
|
297
|
+
let option = {
|
|
298
|
+
method: 'GET',
|
|
299
|
+
url: '/rss/config',
|
|
300
|
+
params: {},
|
|
301
|
+
};
|
|
302
|
+
let content = await aiBotReq(option);
|
|
303
|
+
if (content.data) {
|
|
304
|
+
const list = content.data.map(item => ({ ...item, _id: item.id }));
|
|
305
|
+
resetRssData();
|
|
306
|
+
await updateAllRssConfig(list);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
console.log('获取rss配置文件失败:' + error);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 更新rss最后一条内容的配置
|
|
315
|
+
* @return {Promise<*>}
|
|
316
|
+
*/
|
|
317
|
+
async function updateRssLast(id, lastcontent) {
|
|
318
|
+
try {
|
|
319
|
+
console.log('id----', id, lastcontent);
|
|
320
|
+
let option = {
|
|
321
|
+
method: 'POST',
|
|
322
|
+
url: `/rss/lastcontent/${id}`,
|
|
323
|
+
params: {
|
|
324
|
+
content: lastcontent
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
let content = await aiBotReq(option);
|
|
328
|
+
return content;
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
console.log('获取rss配置文件失败:' + error);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* 更新rss最后一条内容的配置
|
|
336
|
+
* @return {Promise<*>}
|
|
337
|
+
*/
|
|
338
|
+
async function getRssLast(id) {
|
|
339
|
+
try {
|
|
340
|
+
let option = {
|
|
341
|
+
method: 'GET',
|
|
342
|
+
url: `/rss/lastcontent/${id}`,
|
|
343
|
+
params: {},
|
|
344
|
+
};
|
|
345
|
+
let content = await aiBotReq(option);
|
|
346
|
+
return content.data;
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
console.log('获取rss配置文件失败:' + error);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* 更新对话次数
|
|
354
|
+
* @param id
|
|
355
|
+
* @param num
|
|
356
|
+
* @return {Promise<*>}
|
|
357
|
+
*/
|
|
358
|
+
async function updateChatRecord(id, num) {
|
|
359
|
+
try {
|
|
360
|
+
let option = {
|
|
361
|
+
method: 'POST',
|
|
362
|
+
url: '/gpt/config',
|
|
363
|
+
params: {
|
|
364
|
+
id,
|
|
365
|
+
usedNum: num
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
let content = await aiBotReq(option);
|
|
369
|
+
return content.data;
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
console.log('更新对话次数' + error);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* 获取promotion信息
|
|
377
|
+
* @param id
|
|
378
|
+
* @return {Promise<*>}
|
|
379
|
+
*/
|
|
380
|
+
async function getPromotInfo(id) {
|
|
381
|
+
try {
|
|
382
|
+
let option = {
|
|
383
|
+
method: 'get',
|
|
384
|
+
url: '/promot/info',
|
|
385
|
+
params: {
|
|
386
|
+
id
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
let content = await aiBotReq(option);
|
|
390
|
+
return content.data;
|
|
391
|
+
}
|
|
392
|
+
catch (e) {
|
|
393
|
+
console.log("catch error:" + e);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* 获取输入的验证码
|
|
398
|
+
* @param id
|
|
399
|
+
* @return {Promise<*>}
|
|
400
|
+
*/
|
|
401
|
+
async function getVerifyCode() {
|
|
402
|
+
try {
|
|
403
|
+
let option = {
|
|
404
|
+
method: 'get',
|
|
405
|
+
url: '/worker/verifycode',
|
|
406
|
+
};
|
|
407
|
+
let content = await aiBotReq(option);
|
|
408
|
+
if (content.data.code) {
|
|
409
|
+
globalConfig.setVerifyCode(content.data.code);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (e) {
|
|
413
|
+
console.log("catch error:" + e);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* 清除使用过的验证码
|
|
418
|
+
* @returns {Promise<*>}
|
|
419
|
+
*/
|
|
420
|
+
async function clearVerifyCode() {
|
|
421
|
+
try {
|
|
422
|
+
let option = {
|
|
423
|
+
method: 'get',
|
|
424
|
+
url: '/worker/clearverifycode',
|
|
425
|
+
};
|
|
426
|
+
await aiBotReq(option);
|
|
427
|
+
globalConfig.setVerifyCode('');
|
|
428
|
+
}
|
|
429
|
+
catch (e) {
|
|
430
|
+
console.log("catch error:" + e);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 获取定时提醒任务列表
|
|
435
|
+
*/
|
|
436
|
+
async function getScheduleList() {
|
|
437
|
+
try {
|
|
438
|
+
let option = {
|
|
439
|
+
method: 'GET',
|
|
440
|
+
url: '/task',
|
|
441
|
+
params: {},
|
|
442
|
+
};
|
|
443
|
+
let content = await aiBotReq(option);
|
|
444
|
+
let scheduleList = content.data;
|
|
445
|
+
console.log('获取定时任务成功:' + scheduleList);
|
|
446
|
+
return scheduleList;
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
console.log('获取定时任务失败:' + error);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* 设置定时提醒任务
|
|
454
|
+
* @param {*} obj 任务详情
|
|
455
|
+
* @returns {*} 任务详情
|
|
456
|
+
*/
|
|
457
|
+
async function setSchedule(obj) {
|
|
458
|
+
try {
|
|
459
|
+
let option = {
|
|
460
|
+
method: 'POST',
|
|
461
|
+
url: '/task',
|
|
462
|
+
params: obj,
|
|
463
|
+
};
|
|
464
|
+
let content = await aiBotReq(option);
|
|
465
|
+
return content.data;
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
console.log('添加定时任务失败', error);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* 更新定时提醒任务
|
|
473
|
+
*/
|
|
474
|
+
async function updateSchedule(id) {
|
|
475
|
+
try {
|
|
476
|
+
let option = {
|
|
477
|
+
method: 'GET',
|
|
478
|
+
url: '/task/update',
|
|
479
|
+
params: { id: id },
|
|
480
|
+
};
|
|
481
|
+
let content = await aiBotReq(option);
|
|
482
|
+
console.log('更新定时任务成功');
|
|
483
|
+
}
|
|
484
|
+
catch (error) {
|
|
485
|
+
console.log('更新定时任务失败', error);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* 登录二维码推送
|
|
490
|
+
* @param url
|
|
491
|
+
* @param status
|
|
492
|
+
* @returns {Promise<void>}
|
|
493
|
+
*/
|
|
494
|
+
async function setQrCode(url, status) {
|
|
495
|
+
try {
|
|
496
|
+
let option = {
|
|
497
|
+
method: 'GET',
|
|
498
|
+
url: '/wechat/qrcode',
|
|
499
|
+
params: { qrUrl: url, qrStatus: status },
|
|
500
|
+
};
|
|
501
|
+
let content = await aiBotReq(option);
|
|
502
|
+
if (content) {
|
|
503
|
+
console.log('推送二维码成功');
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
console.log('推送登录二维码失败');
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
console.log('推送登录二维码失败', error);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* 更新验证信息
|
|
515
|
+
* @param messages
|
|
516
|
+
* @returns {Promise<void>}
|
|
517
|
+
*/
|
|
518
|
+
async function setVerifyInfo(messages) {
|
|
519
|
+
try {
|
|
520
|
+
let option = {
|
|
521
|
+
method: 'POST',
|
|
522
|
+
url: '/wechat/setSecurityInfo',
|
|
523
|
+
params: { verifyMessage: messages },
|
|
524
|
+
};
|
|
525
|
+
let content = await aiBotReq(option);
|
|
526
|
+
if (content) {
|
|
527
|
+
console.log('推送验证信息成功');
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
console.log('推送验证信息失败');
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
console.log('推送验证信息失败', error);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* 清除验证信息
|
|
539
|
+
* @param messages
|
|
540
|
+
* @returns {Promise<void>}
|
|
541
|
+
*/
|
|
542
|
+
async function clearVerifyInfo(messages) {
|
|
543
|
+
try {
|
|
544
|
+
let option = {
|
|
545
|
+
method: 'POST',
|
|
546
|
+
url: '/wechat/clearSecurityInfo',
|
|
547
|
+
params: { verifyMessage: '' },
|
|
548
|
+
};
|
|
549
|
+
let content = await aiBotReq(option);
|
|
550
|
+
if (content) {
|
|
551
|
+
console.log('清除验证信息成功');
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
console.log('清除验证信息失败');
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
console.log('清除验证信息失败', error);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* 推送登录状态的心跳
|
|
563
|
+
* @param heart
|
|
564
|
+
* @returns {Promise<void>}
|
|
565
|
+
*/
|
|
566
|
+
async function sendHeartBeat(heart) {
|
|
567
|
+
try {
|
|
568
|
+
let option = {
|
|
569
|
+
method: 'GET',
|
|
570
|
+
url: '/wechat/heart',
|
|
571
|
+
params: { heartBeat: heart },
|
|
572
|
+
};
|
|
573
|
+
let content = await aiBotReq(option);
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
console.log('推送心跳失败', error);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* 更新头像
|
|
581
|
+
* @returns {Promise<void>}
|
|
582
|
+
* @param url
|
|
583
|
+
* @param info 用户基本信息
|
|
584
|
+
*/
|
|
585
|
+
async function sendRobotInfo(url, name, id) {
|
|
586
|
+
try {
|
|
587
|
+
let option = {
|
|
588
|
+
method: 'POST',
|
|
589
|
+
url: '/wechat/info',
|
|
590
|
+
params: { avatar: url, robotName: name, robotId: id },
|
|
591
|
+
};
|
|
592
|
+
let content = await aiBotReq(option);
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
console.log('推送头像失败', error);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* 更新好友
|
|
600
|
+
* @returns {Promise<void>}
|
|
601
|
+
* @param url
|
|
602
|
+
*/
|
|
603
|
+
async function sendFriend(friend) {
|
|
604
|
+
try {
|
|
605
|
+
let option = {
|
|
606
|
+
method: 'POST',
|
|
607
|
+
url: '/wechat/friend',
|
|
608
|
+
params: { friend: friend },
|
|
609
|
+
};
|
|
610
|
+
let content = await aiBotReq(option);
|
|
611
|
+
if (!content.code === 200) {
|
|
612
|
+
console.log('推送失败', content.msg);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
console.log('推送好友列表失败');
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* 更新群
|
|
621
|
+
* @returns {Promise<void>}
|
|
622
|
+
* @param url
|
|
623
|
+
*/
|
|
624
|
+
async function sendRoom(room) {
|
|
625
|
+
try {
|
|
626
|
+
let option = {
|
|
627
|
+
method: 'POST',
|
|
628
|
+
url: '/wechat/room',
|
|
629
|
+
params: { room: room },
|
|
630
|
+
};
|
|
631
|
+
let content = await aiBotReq(option);
|
|
632
|
+
if (!content.code === 200) {
|
|
633
|
+
console.log('推送失败', content.msg);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
console.log('推送群列表失败', error);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* 同步群和好友列表
|
|
642
|
+
* type: 1 好友 2 群组
|
|
643
|
+
*/
|
|
644
|
+
async function asyncData(robotId, type) {
|
|
645
|
+
try {
|
|
646
|
+
let option = {
|
|
647
|
+
method: 'get',
|
|
648
|
+
url: '/wechat/asyncData',
|
|
649
|
+
params: { type, robotId },
|
|
650
|
+
};
|
|
651
|
+
let content = await aiBotReq(option);
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
console.log('同步好友列表失败', error);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* 获取上传token
|
|
659
|
+
* @returns {Promise<*>}
|
|
660
|
+
*/
|
|
661
|
+
async function getQiToken() {
|
|
662
|
+
try {
|
|
663
|
+
let option = {
|
|
664
|
+
method: 'GET',
|
|
665
|
+
url: '/wechat/qitoken',
|
|
666
|
+
params: {},
|
|
667
|
+
platform: 'qi',
|
|
668
|
+
};
|
|
669
|
+
let content = await aiBotReq(option);
|
|
670
|
+
return content.data.token;
|
|
671
|
+
}
|
|
672
|
+
catch (e) {
|
|
673
|
+
console.log('token error', e);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* 上传base64图片到七牛云
|
|
678
|
+
* @param base
|
|
679
|
+
* @param name
|
|
680
|
+
* @returns {Promise<void>}
|
|
681
|
+
*/
|
|
682
|
+
async function putqn(base, name) {
|
|
683
|
+
try {
|
|
684
|
+
const token = await getQiToken();
|
|
685
|
+
const namebase = Buffer.from(name).toString('base64').replace(/=/g, '');
|
|
686
|
+
let filename = 'wechat/avatar/' + namebase + '.jpeg';
|
|
687
|
+
let base_file_name = Buffer.from(filename).toString('base64').replace('+', '-').replace('/', '_');
|
|
688
|
+
let options = {
|
|
689
|
+
method: 'POST',
|
|
690
|
+
url: 'http://upload.qiniup.com/putb64/-1/key/' + base_file_name,
|
|
691
|
+
contentType: 'application/octet-stream',
|
|
692
|
+
authorization: 'UpToken ' + token,
|
|
693
|
+
params: base,
|
|
694
|
+
platform: 'chuan',
|
|
695
|
+
};
|
|
696
|
+
let content = await req(options);
|
|
697
|
+
console.log('上传结果', content.key);
|
|
698
|
+
return 'https://img.aibotk.com/' + content.key;
|
|
699
|
+
}
|
|
700
|
+
catch (e) {
|
|
701
|
+
console.log('上传失败', e.Error);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* 更新插件版本信息
|
|
706
|
+
* @param {*} version
|
|
707
|
+
*/
|
|
708
|
+
async function updatePanelVersion() {
|
|
709
|
+
try {
|
|
710
|
+
let option = {
|
|
711
|
+
method: 'POST',
|
|
712
|
+
url: '/webPanel/version',
|
|
713
|
+
params: { version: packageJson.version || '' },
|
|
714
|
+
};
|
|
715
|
+
console.log('更新插件版本号', packageJson.version);
|
|
716
|
+
let content = await aiBotReq(option);
|
|
717
|
+
return content.data;
|
|
718
|
+
}
|
|
719
|
+
catch (error) {
|
|
720
|
+
console.log('error', error);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* 更新插件版本信息
|
|
725
|
+
* @param {*} version
|
|
726
|
+
*/
|
|
727
|
+
export async function getPanelVersion() {
|
|
728
|
+
try {
|
|
729
|
+
let option = {
|
|
730
|
+
method: 'GET',
|
|
731
|
+
url: '/webPanel/version',
|
|
732
|
+
};
|
|
733
|
+
let content = await aiBotReq(option);
|
|
734
|
+
return content.data.version;
|
|
735
|
+
}
|
|
736
|
+
catch (error) {
|
|
737
|
+
console.log('error', error);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* 获取mqtt信息
|
|
742
|
+
* @param {*} version
|
|
743
|
+
*/
|
|
744
|
+
async function getMqttConfig() {
|
|
745
|
+
try {
|
|
746
|
+
let option = {
|
|
747
|
+
method: 'GET',
|
|
748
|
+
url: '/ws/mqtt/config',
|
|
749
|
+
params: {},
|
|
750
|
+
};
|
|
751
|
+
let content = await aiBotReq(option);
|
|
752
|
+
return content.data;
|
|
753
|
+
}
|
|
754
|
+
catch (error) {
|
|
755
|
+
console.log('获取mqtt配置错误', error);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* 获取实时素材
|
|
760
|
+
* @param {*} version
|
|
761
|
+
*/
|
|
762
|
+
async function getMaterial(id) {
|
|
763
|
+
try {
|
|
764
|
+
let option = {
|
|
765
|
+
method: 'GET',
|
|
766
|
+
url: '/wechat/material',
|
|
767
|
+
params: {
|
|
768
|
+
id,
|
|
769
|
+
},
|
|
770
|
+
};
|
|
771
|
+
let content = await aiBotReq(option);
|
|
772
|
+
console.log('素材', content.data);
|
|
773
|
+
return content.data;
|
|
774
|
+
}
|
|
775
|
+
catch (error) {
|
|
776
|
+
console.log('获取mqtt配置错误', error);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
export { getVerifyCode };
|
|
780
|
+
export { clearVerifyCode };
|
|
781
|
+
export { getConfig };
|
|
782
|
+
export { getScheduleList };
|
|
783
|
+
export { setSchedule };
|
|
784
|
+
export { updateSchedule };
|
|
785
|
+
export { setQrCode };
|
|
786
|
+
export { sendHeartBeat };
|
|
787
|
+
export { sendRobotInfo };
|
|
788
|
+
export { putqn };
|
|
789
|
+
export { sendFriend };
|
|
790
|
+
export { sendRoom };
|
|
791
|
+
export { asyncData };
|
|
792
|
+
export { updatePanelVersion };
|
|
793
|
+
export { getMqttConfig };
|
|
794
|
+
export { getMeiNv };
|
|
795
|
+
export { getOne };
|
|
796
|
+
export { getMaterial };
|
|
797
|
+
export { getFireNews };
|
|
798
|
+
export { updateChatRecord };
|
|
799
|
+
export { getPromotInfo };
|
|
800
|
+
export { getRssLast };
|
|
801
|
+
export { updateRssLast };
|
|
802
|
+
export { clearVerifyInfo };
|
|
803
|
+
export { setVerifyInfo };
|
|
804
|
+
export default {
|
|
805
|
+
getConfig,
|
|
806
|
+
getScheduleList,
|
|
807
|
+
setSchedule,
|
|
808
|
+
updateSchedule,
|
|
809
|
+
setQrCode,
|
|
810
|
+
sendHeartBeat,
|
|
811
|
+
sendRobotInfo,
|
|
812
|
+
putqn,
|
|
813
|
+
sendFriend,
|
|
814
|
+
sendRoom,
|
|
815
|
+
asyncData,
|
|
816
|
+
updatePanelVersion,
|
|
817
|
+
getMqttConfig,
|
|
818
|
+
getMeiNv,
|
|
819
|
+
getOne,
|
|
820
|
+
getMaterial,
|
|
821
|
+
getFireNews,
|
|
822
|
+
clearVerifyCode,
|
|
823
|
+
getRssLast,
|
|
824
|
+
updateRssLast,
|
|
825
|
+
getVerifyCode,
|
|
826
|
+
clearVerifyInfo,
|
|
827
|
+
setVerifyInfo
|
|
828
|
+
};
|
|
829
|
+
//# sourceMappingURL=aibotk.js.map
|