wechaty-web-panel 1.6.112 → 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.
Files changed (109) hide show
  1. package/dist/bot/chatgpt/index.js +235 -0
  2. package/dist/bot/coze/sdk/index.js +110 -0
  3. package/dist/bot/dify/sdk/index.js +461 -0
  4. package/dist/bot/dify/sdk/office.js +319 -0
  5. package/dist/bot/fastgpt/index.js +98 -0
  6. package/dist/bot/qanything/index.js +136 -0
  7. package/dist/botInstance/coze.js +167 -0
  8. package/dist/botInstance/cozev3.js +157 -0
  9. package/dist/botInstance/dify.js +160 -0
  10. package/dist/botInstance/fastgpt.js +130 -0
  11. package/dist/botInstance/gpt4v.js +95 -0
  12. package/dist/botInstance/officialOpenAi.js +186 -0
  13. package/dist/botInstance/qany.js +144 -0
  14. package/dist/botInstance/sdk/chatGPT4V.js +89 -0
  15. package/dist/botInstance/sdk/coze.js +200 -0
  16. package/dist/botInstance/sdk/difyClient.js +354 -0
  17. package/dist/botInstance/sdk/pTimeout.js +97 -0
  18. package/dist/botInstance/sdk/qanything.js +137 -0
  19. package/dist/botInstance/sdk/quick-lru.js +237 -0
  20. package/dist/common/hook.js +66 -0
  21. package/dist/common/index.js +513 -0
  22. package/dist/common/multiReply.js +158 -0
  23. package/dist/common/reply.js +23 -0
  24. package/dist/const/puppet-type.js +71 -0
  25. package/dist/db/aiDb.js +27 -0
  26. package/dist/db/aichatDb.js +84 -0
  27. package/dist/db/chatHistory.js +137 -0
  28. package/dist/db/configDb.js +97 -0
  29. package/dist/db/global.js +62 -0
  30. package/dist/db/gptConfig.js +85 -0
  31. package/dist/db/nedb.js +88 -0
  32. package/dist/db/puppetDb.js +58 -0
  33. package/dist/db/roomDb.js +83 -0
  34. package/dist/db/rssConfig.js +82 -0
  35. package/dist/db/rssHistory.js +88 -0
  36. package/dist/db/userDb.js +27 -0
  37. package/dist/handlers/on-callback-message.js +183 -0
  38. package/dist/handlers/on-error.js +5 -0
  39. package/dist/handlers/on-friend.js +62 -0
  40. package/dist/handlers/on-heartbeat.js +20 -0
  41. package/dist/handlers/on-login.js +58 -0
  42. package/dist/handlers/on-logout.js +17 -0
  43. package/dist/handlers/on-message.js +644 -0
  44. package/dist/handlers/on-ready.js +36 -0
  45. package/dist/handlers/on-record-message.js +56 -0
  46. package/dist/handlers/on-roomjoin.js +42 -0
  47. package/dist/handlers/on-roomleave.js +12 -0
  48. package/dist/handlers/on-roomtopic.js +16 -0
  49. package/dist/handlers/on-scan.js +64 -0
  50. package/dist/handlers/on-verifycode.js +42 -0
  51. package/dist/index.js +81 -69306
  52. package/dist/lib/contentCensor.js +23 -0
  53. package/dist/lib/index.js +562 -0
  54. package/dist/lib/oss.js +43 -0
  55. package/dist/lib/s3oss.js +33 -0
  56. package/dist/mcp/mcp-server.js +26 -0
  57. package/dist/mcp/src/config/database.js +51 -0
  58. package/dist/mcp/src/index.js +238 -0
  59. package/dist/mcp/src/mcp/schemas.js +178 -0
  60. package/dist/mcp/src/mcp/server.js +421 -0
  61. package/dist/mcp/src/mcp/streamable-server.js +690 -0
  62. package/dist/mcp/src/models/ChatMessage.js +151 -0
  63. package/dist/mcp/src/models/Friend.js +64 -0
  64. package/dist/mcp/src/models/Group.js +55 -0
  65. package/dist/mcp/src/models/GroupMember.js +67 -0
  66. package/dist/mcp/src/models/index.js +27 -0
  67. package/dist/mcp/src/scripts/migrate.js +21 -0
  68. package/dist/mcp/src/services/ChatDataService.js +284 -0
  69. package/dist/mcp/src/services/McpService.js +521 -0
  70. package/dist/mcp/src/services/McpTools.js +504 -0
  71. package/dist/mcp/streamable-examples.js +283 -0
  72. package/dist/mcp/streamable-server.js +79 -0
  73. package/dist/mcp/test-mcp.js +64 -0
  74. package/dist/mcp/test-streamable-server.js +86 -0
  75. package/dist/package-json.js +89 -0
  76. package/dist/proxy/aibotk.js +829 -0
  77. package/dist/proxy/api.js +431 -0
  78. package/dist/proxy/apib.js +587 -0
  79. package/dist/proxy/bot/chatgpt.js +38 -0
  80. package/dist/proxy/bot/coze.js +38 -0
  81. package/dist/proxy/bot/cozev3.js +38 -0
  82. package/dist/proxy/bot/dify.js +38 -0
  83. package/dist/proxy/bot/dispatch.js +81 -0
  84. package/dist/proxy/bot/fastgpt.js +27 -0
  85. package/dist/proxy/bot/qany.js +27 -0
  86. package/dist/proxy/config.js +14 -0
  87. package/dist/proxy/cozeAi.js +60 -0
  88. package/dist/proxy/cozeV3Ai.js +60 -0
  89. package/dist/proxy/difyAi.js +58 -0
  90. package/dist/proxy/fastgpt.js +55 -0
  91. package/dist/proxy/mqtt.js +275 -0
  92. package/dist/proxy/multimodal.js +122 -0
  93. package/dist/proxy/openAi.js +63 -0
  94. package/dist/proxy/outapi.js +62 -0
  95. package/dist/proxy/qAnyAi.js +57 -0
  96. package/dist/proxy/superagent.js +200 -0
  97. package/dist/proxy/tencent-open.js +255 -0
  98. package/dist/service/event-dispatch-service.js +309 -0
  99. package/dist/service/gpt4vService.js +45 -0
  100. package/dist/service/msg-filter-service.js +121 -0
  101. package/dist/service/msg-filters.js +645 -0
  102. package/dist/service/room-async-service.js +455 -0
  103. package/dist/task/index.js +535 -0
  104. package/dist/task/rss.js +174 -0
  105. package/package.json +2 -2
  106. package/src/package-json.js +2 -2
  107. package/tsconfig.json +3 -12
  108. package/dist/index.d.ts +0 -9
  109. package/tsconfig.cjs.json +0 -12
@@ -0,0 +1,431 @@
1
+ import { EMOHOST, TXSJHOST } from './config.js';
2
+ import { randomRange, MD5 } from '../lib/index.js';
3
+ import { allConfig } from '../db/configDb.js';
4
+ import { getFireNews } from './aibotk.js';
5
+ import { getPuppetEol } from '../const/puppet-type.js';
6
+ import axios from 'axios';
7
+ const service = axios.create({
8
+ // 定义统一的请求头部
9
+ headers: {
10
+ 'Content-Type': 'application/json; charset=utf-8'
11
+ }, // 配置请求超时时间
12
+ timeout: 60 * 1000, // 如果用的JSONP,可以配置此参数带上cookie凭证,如果是代理和CORS不用设置
13
+ withCredentials: false
14
+ });
15
+ // 请求拦截
16
+ service.interceptors.request.use((config) => {
17
+ return config;
18
+ });
19
+ // 返回拦截
20
+ service.interceptors.response.use((response) => {
21
+ if (response.status === 200) {
22
+ // 获取接口返回结果
23
+ const res = response.data;
24
+ // code为0,直接把结果返回回去,这样前端代码就不用在获取一次data.
25
+ if (res.code === 200) {
26
+ return Promise.resolve(res.result);
27
+ }
28
+ else {
29
+ console.log(`天行API接口请求错误:${res.msg}`);
30
+ }
31
+ }
32
+ console.log(`天行API网络请求错误:${response.status}`);
33
+ return Promise.reject();
34
+ }, (err) => {
35
+ console.log('天行API网络请求错误:', err);
36
+ return Promise.reject(err);
37
+ });
38
+ async function txReq(option) {
39
+ const config = await allConfig();
40
+ if (!option)
41
+ return;
42
+ const params = {
43
+ key: config.txApiKey, ...option.params
44
+ };
45
+ if (option.method === 'POST') {
46
+ return service.post(TXSJHOST + '/' + option.url + '/index', params, { headers: { contentType: option.contentType } });
47
+ }
48
+ else {
49
+ return service.get(TXSJHOST + '/' + option.url + '/index', { params, headers: { contentType: option.contentType } });
50
+ }
51
+ }
52
+ /**
53
+ * 天行聊天机器人
54
+ * @param {*} word 内容
55
+ * @param {*} id id
56
+ */
57
+ export async function getResByTX(word, id) {
58
+ try {
59
+ const eol = await getPuppetEol();
60
+ let uniqueId = MD5(id);
61
+ let option = {
62
+ method: 'GET', url: 'robot', params: { question: word, uniqueid: uniqueId }
63
+ };
64
+ let result = await txReq(option);
65
+ let response = '';
66
+ if (result.datatype === 'text') {
67
+ response = result.reply.replaceAll('\n', eol).replace(/<br>/g, eol);
68
+ }
69
+ else if (result.datatype === 'view') {
70
+ let reply = '';
71
+ result.reply.forEach((item) => {
72
+ reply = reply + `《${item.title}》:${item.url}${eol}`;
73
+ });
74
+ response = `虽然我不太懂你说的是什么,但是感觉很高级的样子,因此我也查找了类似的文章去学习,你觉得有用吗:\n${reply}`;
75
+ }
76
+ else {
77
+ response = '你太厉害了,说的话把我难倒了,我要去学习了,不然没法回答你的问题';
78
+ }
79
+ return response;
80
+ }
81
+ catch (error) {
82
+ console.log('获取天行机器人对话失败,请申请https://www.tianapi.com/apiview/47 这个接口');
83
+ }
84
+ }
85
+ /**
86
+ * 获取垃圾分类结果
87
+ * @param {String} word 垃圾名称
88
+ */
89
+ export async function getRubbishType(word) {
90
+ const eol = await getPuppetEol();
91
+ try {
92
+ let option = {
93
+ method: 'GET', url: 'lajifenlei', params: { word: word }
94
+ };
95
+ let content = await txReq(option);
96
+ let type;
97
+ if (content.list[0].type == 0) {
98
+ type = '是可回收垃圾';
99
+ }
100
+ else if (content.list[0].type == 1) {
101
+ type = '是有害垃圾';
102
+ }
103
+ else if (content.list[0].type == 2) {
104
+ type = '是厨余(湿)垃圾';
105
+ }
106
+ else if (content.list[0].type == 3) {
107
+ type = '是其他(干)垃圾';
108
+ }
109
+ let response = `${content.list[0].name}${type}${eol}解释:${content.list[0].explain}${eol}主要包括:${content.list[0].contain}${eol}投放提示:${content.list[0].tip}`;
110
+ return response;
111
+ }
112
+ catch (error) {
113
+ console.log('垃圾分类请求失,请申请https://www.tianapi.com/apiview/97 这个接口');
114
+ }
115
+ }
116
+ /**
117
+ * 土味情话获取
118
+ */
119
+ export async function getSweetWord() {
120
+ const eol = await getPuppetEol();
121
+ try {
122
+ let option = {
123
+ method: 'GET', url: 'saylove', params: {}
124
+ };
125
+ let content = await txReq(option);
126
+ let sweet = content.content;
127
+ let str = sweet.replaceAll('\r\n', eol).replace(/<br>/g, eol).replaceAll('\n', eol);
128
+ return str;
129
+ }
130
+ catch (err) {
131
+ console.log('获取土情话接口失败,请申请https://www.tianapi.com/apiview/80 这个接口');
132
+ }
133
+ }
134
+ /**
135
+ * 获取天行天气
136
+ */
137
+ export async function getTXweather(city) {
138
+ const eol = await getPuppetEol();
139
+ try {
140
+ let option = {
141
+ method: 'GET', url: 'tianqi', params: { city: city }
142
+ };
143
+ const res = await txReq(option);
144
+ let todayInfo = res.list[0];
145
+ console.log('todayInfo', todayInfo);
146
+ let obj = {
147
+ weatherTips: todayInfo.tips,
148
+ todayWeather: `今天:${todayInfo.weather}${eol}温度:${todayInfo.lowest}/${todayInfo.highest}${eol}${todayInfo.wind} ${todayInfo.windspeed}${eol}${eol}`
149
+ };
150
+ return obj;
151
+ }
152
+ catch (err) {
153
+ console.log('获取天气接口失败,请申请https://www.tianapi.com/apiview/72 这个接口');
154
+ }
155
+ }
156
+ /**
157
+ * 获取每日新闻内容
158
+ * @param {*} id 新闻频道对应的ID
159
+ */
160
+ export async function getNews(id, num = 10) {
161
+ if (id > 1000) {
162
+ return getFireNews(id, num);
163
+ }
164
+ const eol = await getPuppetEol();
165
+ try {
166
+ let option = {
167
+ method: 'GET', url: 'allnews', params: { num: num, col: id }
168
+ };
169
+ let content = await txReq(option);
170
+ let newList = content.newslist;
171
+ let news = '';
172
+ // let shortUrl = 'https://www.tianapi.com/weixin/news/?col=' + id
173
+ for (let i in newList) {
174
+ let num = parseInt(i) + 1;
175
+ news = `${news}${eol}${num}.${newList[i].title}`;
176
+ }
177
+ return `${news}${eol}`;
178
+ }
179
+ catch (error) {
180
+ console.log('获取天行新闻失败,请申请https://www.tianapi.com/apiview/51 这个接口');
181
+ return '';
182
+ }
183
+ }
184
+ /**
185
+ * 获取名人名言
186
+ */
187
+ export async function getMingYan() {
188
+ const eol = await getPuppetEol();
189
+ try {
190
+ let option = {
191
+ method: 'GET', url: 'mingyan', params: { num: 1 }
192
+ };
193
+ let content = await txReq(option);
194
+ let newList = content.list;
195
+ let news = `${newList[0].content}${eol}——————————${newList[0].author}`;
196
+ return news;
197
+ }
198
+ catch (error) {
199
+ console.log('获取名人名言失败,请申请https://www.tianapi.com/apiview/92 这个接口');
200
+ }
201
+ }
202
+ /**
203
+ * 获取星座运势
204
+ * @param {string} satro 星座
205
+ */
206
+ export async function getStar(astro) {
207
+ const eol = await getPuppetEol();
208
+ try {
209
+ let option = {
210
+ method: 'GET', url: 'star', params: { astro: astro }
211
+ };
212
+ let content = await txReq(option);
213
+ let newList = content.list;
214
+ let news = '';
215
+ for (let item of newList) {
216
+ news = `${news}${item.type}:${item.content}${eol}`;
217
+ }
218
+ return news;
219
+ }
220
+ catch (error) {
221
+ console.log('获取天行星座运势失败,请申请https://www.tianapi.com/apiview/78 这个接口');
222
+ }
223
+ }
224
+ /**
225
+ * 获取姓氏起源
226
+ * @param {string} 姓
227
+ */
228
+ export async function getXing(name) {
229
+ try {
230
+ let option = {
231
+ method: 'GET', url: 'surname', params: { xing: name }
232
+ };
233
+ let content = await txReq(option);
234
+ return `${content.content}`;
235
+ }
236
+ catch (error) {
237
+ console.log('获取天行姓氏起源失败, 请申请https://www.tianapi.com/apiview/94 这个接口');
238
+ }
239
+ }
240
+ /**
241
+ * 获取顺口溜
242
+ */
243
+ export async function getSkl() {
244
+ try {
245
+ let option = {
246
+ method: 'GET', url: 'skl', params: {}
247
+ };
248
+ let content = await txReq(option);
249
+ return `${content.content}`;
250
+ }
251
+ catch (error) {
252
+ console.log('获取天行顺口溜失败,请申请https://www.tianapi.com/apiview/54 这个接口', error);
253
+ }
254
+ }
255
+ /**
256
+ * 获取老黄历
257
+ */
258
+ export async function getLunar(date) {
259
+ const eol = await getPuppetEol();
260
+ try {
261
+ let option = {
262
+ method: 'GET', url: 'lunar', params: { date: date }
263
+ };
264
+ let content = await txReq(option);
265
+ let item = content;
266
+ let news = `阳历:${item.gregoriandate}${eol}阴历:${item.lunardate}${eol}节日:${item.lunar_festival}${eol}适宜:${item.fitness}${eol}不宜:${item.taboo}${eol}神位:${item.shenwei}${eol}胎神:${item.taishen}${eol}冲煞:${item.chongsha}${eol}岁煞:${item.suisha}`;
267
+ return news;
268
+ }
269
+ catch (error) {
270
+ console.log('获取天行老黄历失败, 请申请https://www.tianapi.com/apiview/45 这个接口');
271
+ }
272
+ }
273
+ /**
274
+ * 天行神回复
275
+ */
276
+ export async function getGoldReply() {
277
+ const eol = await getPuppetEol();
278
+ try {
279
+ let option = {
280
+ method: 'GET', url: 'godreply', params: { num: 1 }
281
+ };
282
+ let content = await txReq(option);
283
+ let item = content.list[0];
284
+ let news = `问题:"${item.title}"${eol}回复:${item.content}`;
285
+ return news;
286
+ }
287
+ catch (error) {
288
+ console.log('获取天行神回复失败,请申请https://www.tianapi.com/apiview/39 这个接口');
289
+ }
290
+ }
291
+ /**
292
+ * 天行歇后语
293
+ */
294
+ export async function getXhy() {
295
+ try {
296
+ let option = {
297
+ method: 'GET', url: 'xiehou', params: { num: 1 }
298
+ };
299
+ let content = await txReq(option);
300
+ let item = content.list[0];
301
+ let news = `${item.quest}————${item.result}`;
302
+ return news;
303
+ }
304
+ catch (error) {
305
+ console.log('获取天行歇后语失败, 请申请https://www.tianapi.com/apiview/38 这个接口');
306
+ }
307
+ }
308
+ /**
309
+ * 天行绕口令
310
+ */
311
+ export async function getRkl() {
312
+ try {
313
+ let option = {
314
+ method: 'GET', url: 'rkl', params: { num: 1 }
315
+ };
316
+ let content = await txReq(option);
317
+ let item = content.list[0];
318
+ let news = `${item.content}`;
319
+ return news;
320
+ }
321
+ catch (error) {
322
+ console.log('获取天行绕口令失败,请申请https://www.tianapi.com/apiview/37 这个接口');
323
+ }
324
+ }
325
+ /**
326
+ * 获取自定义头像
327
+ * @param {*} base
328
+ * @param type
329
+ */
330
+ export async function getAvatar(base, type) {
331
+ try {
332
+ let option = {
333
+ method: 'POST', url: 'imgtx', params: {
334
+ createid: type || 2, img: 'data:image/jpeg;base64,' + base
335
+ }
336
+ };
337
+ let content = await txReq(option);
338
+ return content.picurl;
339
+ }
340
+ catch (e) {
341
+ console.log('获取自定义头像失败,请申请https://www.tianapi.com/apiview/123 这个接口');
342
+ }
343
+ }
344
+ /**
345
+ * 获取表情包
346
+ * @param {*} msg
347
+ */
348
+ export async function getEmo(msg) {
349
+ try {
350
+ let res = await axios.get(`${EMOHOST}keyword=${encodeURIComponent(msg)}`, { headers: { 'Content-Type': 'application/json;charset=UTF-8' } });
351
+ const content = res.data;
352
+ if (content.totalSize > 0) {
353
+ if (content.items && content.items.length > 0) {
354
+ let arr = [];
355
+ for (let i of content.items) {
356
+ if (i.url.includes('.jpg') || i.url.includes('.gif')) {
357
+ arr.push(i);
358
+ }
359
+ }
360
+ let item = arr[randomRange(0, arr.length)];
361
+ if (item.url) {
362
+ return item.url;
363
+ }
364
+ else {
365
+ return 'http://img.doutula.com/production/uploads/image/2017/11/30/20171130047004_PiJlhx.gif';
366
+ }
367
+ }
368
+ else {
369
+ return 'http://img.doutula.com/production/uploads/image/2017/11/30/20171130047004_PiJlhx.gif';
370
+ }
371
+ }
372
+ }
373
+ catch (e) {
374
+ console.log('获取表情包失败', e);
375
+ }
376
+ }
377
+ /**
378
+ * 天行网络取名
379
+ */
380
+ export async function getCname() {
381
+ try {
382
+ let option = {
383
+ method: 'GET', url: 'cname'
384
+ };
385
+ let content = await txReq(option);
386
+ let item = content.list[0];
387
+ let cname = item.naming;
388
+ return cname;
389
+ }
390
+ catch (error) {
391
+ console.log('获取天行网络取名失败,请申请https://www.tianapi.com/apiview/36 这个接口');
392
+ }
393
+ }
394
+ /**
395
+ * 天行违章码查询
396
+ */
397
+ export async function getJtwfcode(code) {
398
+ try {
399
+ const eol = await getPuppetEol();
400
+ let option = {
401
+ method: 'GET', url: 'jtwfcode', params: { code }
402
+ };
403
+ let content = await txReq(option);
404
+ return `违章码:${code}${eol}违章行为:${content.behavior}${eol}扣分:${content.deduct}${eol}罚款:${content.fine}元${eol}其他处罚:${content.others}`;
405
+ }
406
+ catch (error) {
407
+ console.log('获取天行违章码查询失败,请申请https://www.tianapi.com/apiview/36 这个接口');
408
+ }
409
+ }
410
+ /**
411
+ * 天行健康小妙招
412
+ */
413
+ export async function getHealthskill(word) {
414
+ try {
415
+ const eol = await getPuppetEol();
416
+ let option = {
417
+ method: 'GET', url: 'healthskill', params: { word }
418
+ };
419
+ let content = await txReq(option);
420
+ let list = content.list;
421
+ let tips = '';
422
+ for (let item of list) {
423
+ tips = `🌟🌟${item.content}🌟🌟${eol}`;
424
+ }
425
+ return tips;
426
+ }
427
+ catch (error) {
428
+ console.log('获取天行健康小妙招名失败,请申请https://www.tianapi.com/apiview/252 这个接口');
429
+ }
430
+ }
431
+ //# sourceMappingURL=api.js.map