wechaty-puppet-matrix 0.0.9 → 0.0.12
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/cjs/src/matrix/cache-manager.js +1 -1
- package/dist/cjs/src/matrix/service/request.d.ts +63 -0
- package/dist/cjs/src/matrix/service/request.d.ts.map +1 -1
- package/dist/cjs/src/matrix/service/request.js +407 -4
- package/dist/cjs/src/matrix/utils/index.d.ts +3 -0
- package/dist/cjs/src/matrix/utils/index.d.ts.map +1 -1
- package/dist/cjs/src/matrix/utils/index.js +31 -0
- package/dist/cjs/src/puppet-matrix.d.ts +6 -0
- package/dist/cjs/src/puppet-matrix.d.ts.map +1 -1
- package/dist/cjs/src/puppet-matrix.js +84 -0
- package/dist/cjs/src/utils/normalize-filebox.d.ts +6 -0
- package/dist/cjs/src/utils/normalize-filebox.d.ts.map +1 -0
- package/dist/cjs/src/utils/normalize-filebox.js +46 -0
- package/dist/cjs/src/utils/sns-xml-generator.d.ts +19 -0
- package/dist/cjs/src/utils/sns-xml-generator.d.ts.map +1 -0
- package/dist/cjs/src/utils/sns-xml-generator.js +171 -0
- package/dist/esm/src/matrix/cache-manager.js +1 -1
- package/dist/esm/src/matrix/service/request.d.ts +63 -0
- package/dist/esm/src/matrix/service/request.d.ts.map +1 -1
- package/dist/esm/src/matrix/service/request.js +407 -4
- package/dist/esm/src/matrix/utils/index.d.ts +3 -0
- package/dist/esm/src/matrix/utils/index.d.ts.map +1 -1
- package/dist/esm/src/matrix/utils/index.js +28 -0
- package/dist/esm/src/puppet-matrix.d.ts +6 -0
- package/dist/esm/src/puppet-matrix.d.ts.map +1 -1
- package/dist/esm/src/puppet-matrix.js +85 -1
- package/dist/esm/src/utils/normalize-filebox.d.ts +6 -0
- package/dist/esm/src/utils/normalize-filebox.d.ts.map +1 -0
- package/dist/esm/src/utils/normalize-filebox.js +42 -0
- package/dist/esm/src/utils/sns-xml-generator.d.ts +19 -0
- package/dist/esm/src/utils/sns-xml-generator.d.ts.map +1 -0
- package/dist/esm/src/utils/sns-xml-generator.js +165 -0
- package/package.json +6 -5
- package/src/matrix/cache-manager.ts +1 -1
- package/src/matrix/service/request.ts +523 -8
- package/src/matrix/utils/index.ts +62 -0
- package/src/puppet-matrix.ts +112 -1
- package/src/utils/normalize-filebox.ts +90 -0
- package/src/utils/sns-xml-generator.ts +184 -0
|
@@ -6,6 +6,10 @@ import * as PUPPET from '@juzi/wechaty-puppet';
|
|
|
6
6
|
import { format, getUnixTime } from 'date-fns';
|
|
7
7
|
import { xmlToJson } from '../utils/xml-to-json.js';
|
|
8
8
|
import { isRoomId } from '../utils/is-type.js';
|
|
9
|
+
import imageSize from 'image-size';
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import os from 'os';
|
|
12
|
+
import path from 'path';
|
|
9
13
|
const PRE = '[PuppetMatrix]';
|
|
10
14
|
export var NotifyTypeEnum;
|
|
11
15
|
(function (NotifyTypeEnum) {
|
|
@@ -87,13 +91,210 @@ async function getAtWxidList(source) {
|
|
|
87
91
|
}
|
|
88
92
|
return [];
|
|
89
93
|
}
|
|
94
|
+
async function getImageInfo(imageUrl) {
|
|
95
|
+
try {
|
|
96
|
+
const response = await axios({
|
|
97
|
+
method: 'get',
|
|
98
|
+
url: imageUrl,
|
|
99
|
+
responseType: 'arraybuffer',
|
|
100
|
+
});
|
|
101
|
+
const fileSize = response.data.length;
|
|
102
|
+
const tempFilePath = path.join(os.homedir(), path.sep, '.wechaty', 'puppet-matrix-cache', path.sep, 'temp_image_' + Date.now() + path.extname(imageUrl), path.sep);
|
|
103
|
+
const baseDirExist = await fs.pathExists(tempFilePath);
|
|
104
|
+
if (!baseDirExist) {
|
|
105
|
+
await fs.mkdirp(tempFilePath);
|
|
106
|
+
}
|
|
107
|
+
await fs.writeFile(tempFilePath, response.data);
|
|
108
|
+
const dimensions = imageSize(tempFilePath);
|
|
109
|
+
await fs.unlink(tempFilePath);
|
|
110
|
+
return {
|
|
111
|
+
file_size: fileSize,
|
|
112
|
+
image_width: dimensions.width,
|
|
113
|
+
image_height: dimensions.height,
|
|
114
|
+
file_type: dimensions.type,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error('获取图片信息错误:', error);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const genTextSnsXml = (wxid, content) => {
|
|
123
|
+
const xmlTemplate = `
|
|
124
|
+
<TimelineObject>
|
|
125
|
+
<id><![CDATA[0]]></id>
|
|
126
|
+
<username><![CDATA[${wxid}]]></username>
|
|
127
|
+
<createTime><![CDATA[${Math.floor(Date.now() / 1000)}]]></createTime>
|
|
128
|
+
<contentDescShowType>0</contentDescShowType>
|
|
129
|
+
<contentDescScene>0</contentDescScene>
|
|
130
|
+
<private><![CDATA[0]]></private>
|
|
131
|
+
<contentDesc><![CDATA[${content}]]></contentDesc>
|
|
132
|
+
<contentattr><![CDATA[0]]></contentattr>
|
|
133
|
+
<sourceUserName></sourceUserName>
|
|
134
|
+
<sourceNickName></sourceNickName>
|
|
135
|
+
<statisticsData></statisticsData>
|
|
136
|
+
<weappInfo>
|
|
137
|
+
<appUserName></appUserName>
|
|
138
|
+
<pagePath></pagePath>
|
|
139
|
+
<version><![CDATA[0]]></version>
|
|
140
|
+
<isHidden>0</isHidden>
|
|
141
|
+
<debugMode><![CDATA[0]]></debugMode>
|
|
142
|
+
<shareActionId></shareActionId>
|
|
143
|
+
<isGame><![CDATA[0]]></isGame>
|
|
144
|
+
<messageExtraData></messageExtraData>
|
|
145
|
+
<subType><![CDATA[0]]></subType>
|
|
146
|
+
<preloadResources></preloadResources>
|
|
147
|
+
</weappInfo>
|
|
148
|
+
<canvasInfoXml></canvasInfoXml>
|
|
149
|
+
<ContentObject>
|
|
150
|
+
<contentStyle><![CDATA[2]]></contentStyle>
|
|
151
|
+
<contentSubStyle><![CDATA[0]]></contentSubStyle>
|
|
152
|
+
<title></title>
|
|
153
|
+
<description></description>
|
|
154
|
+
<contentUrl></contentUrl>
|
|
155
|
+
</ContentObject>
|
|
156
|
+
<actionInfo>
|
|
157
|
+
<appMsg>
|
|
158
|
+
<mediaTagName></mediaTagName>
|
|
159
|
+
<messageExt></messageExt>
|
|
160
|
+
<messageAction></messageAction>
|
|
161
|
+
</appMsg>
|
|
162
|
+
</actionInfo>
|
|
163
|
+
<appInfo><id></id></appInfo>
|
|
164
|
+
<publicUserName></publicUserName>
|
|
165
|
+
<streamvideo>
|
|
166
|
+
<streamvideourl></streamvideourl>
|
|
167
|
+
<streamvideothumburl></streamvideothumburl>
|
|
168
|
+
<streamvideoweburl></streamvideoweburl>
|
|
169
|
+
</streamvideo>
|
|
170
|
+
</TimelineObject>`.replace(/\s+/g, '');
|
|
171
|
+
return xmlTemplate;
|
|
172
|
+
};
|
|
173
|
+
const genVideoSnsXml = (wxid, content, media) => {
|
|
174
|
+
const xmlTemplate = `
|
|
175
|
+
<TimelineObject>
|
|
176
|
+
<id>0</id>
|
|
177
|
+
<username>${wxid}</username>
|
|
178
|
+
<createTime>${Math.floor(Date.now() / 1000)}</createTime>
|
|
179
|
+
<contentDesc>${content}</contentDesc>
|
|
180
|
+
<contentDescShowType>0</contentDescShowType>
|
|
181
|
+
<contentDescScene>0</contentDescScene>
|
|
182
|
+
<private>0</private>
|
|
183
|
+
<sightFolded>0</sightFolded>
|
|
184
|
+
<showFlag>0</showFlag>
|
|
185
|
+
<appInfo>
|
|
186
|
+
<id></id>
|
|
187
|
+
<version></version>
|
|
188
|
+
<appName></appName>
|
|
189
|
+
<installUrl></installUrl>
|
|
190
|
+
<fromUrl></fromUrl>
|
|
191
|
+
<isForceUpdate>0</isForceUpdate>
|
|
192
|
+
<isHidden>0</isHidden>
|
|
193
|
+
</appInfo>
|
|
194
|
+
<sourceUserName></sourceUserName>
|
|
195
|
+
<sourceNickName></sourceNickName>
|
|
196
|
+
<statisticsData></statisticsData>
|
|
197
|
+
<statExtStr></statExtStr>
|
|
198
|
+
<ContentObject>
|
|
199
|
+
<contentStyle>15</contentStyle>
|
|
200
|
+
<title></title>
|
|
201
|
+
<description>Sight</description>
|
|
202
|
+
<mediaList>
|
|
203
|
+
<media>
|
|
204
|
+
<id>0</id>
|
|
205
|
+
<type>6</type>
|
|
206
|
+
<title></title>
|
|
207
|
+
<description>测试</description>
|
|
208
|
+
<private>0</private>
|
|
209
|
+
<userData></userData>
|
|
210
|
+
<subType>0</subType>
|
|
211
|
+
<videoSize width="${media.video_width}" height="${media.video_height}"/>
|
|
212
|
+
<url type="1" md5="951a7d7864d685a92fd2624155794bf9" videomd5="577f55635faf44f595a69ded26d87bcc">${media.file_url}</url>
|
|
213
|
+
<thumb type="1">${media.thumb_url}</thumb>
|
|
214
|
+
<size width="${media.thumb_width}.000000" height="${media.thumb_height}.000000" totalSize="${media.file_size}"/>
|
|
215
|
+
<videoDuration>${media.video_duration}.000000</videoDuration>
|
|
216
|
+
</media>
|
|
217
|
+
</mediaList>
|
|
218
|
+
</ContentObject>
|
|
219
|
+
</TimelineObject>`;
|
|
220
|
+
return xmlTemplate;
|
|
221
|
+
};
|
|
222
|
+
const genImageSnsXml = (wxid, contentDesc, mediaList) => {
|
|
223
|
+
const mediaTemplate = (media) => `
|
|
224
|
+
<media>
|
|
225
|
+
<id><![CDATA[0]]></id>
|
|
226
|
+
<type><![CDATA[2]]></type>
|
|
227
|
+
<title></title>
|
|
228
|
+
<description></description>
|
|
229
|
+
<private><![CDATA[0]]></private>
|
|
230
|
+
<url type="1" md5="951a7d7864d685a92fd2624155794bf9"><![CDATA[${media.file_url}]]></url>
|
|
231
|
+
<thumb type="1"><![CDATA[${media.thumb_url}]]></thumb>
|
|
232
|
+
<videoDuration><![CDATA[0.0]]></videoDuration>
|
|
233
|
+
<size totalSize="${media.file_size}" width="${media.image_width}" height="${media.image_height}"></size>
|
|
234
|
+
</media>`;
|
|
235
|
+
const mediaString = mediaList.map(media => mediaTemplate(media)).join('');
|
|
236
|
+
const xmlTemplate = `
|
|
237
|
+
<TimelineObject>
|
|
238
|
+
<id><![CDATA[0]]></id>
|
|
239
|
+
<username><![CDATA[${wxid}]]></username>
|
|
240
|
+
<createTime><![CDATA[${Math.floor(Date.now() / 1000)}]]></createTime>
|
|
241
|
+
<contentDescShowType>0</contentDescShowType>
|
|
242
|
+
<contentDescScene>0</contentDescScene>
|
|
243
|
+
<private><![CDATA[0]]></private>
|
|
244
|
+
<contentDesc><![CDATA[${contentDesc}]]></contentDesc>
|
|
245
|
+
<contentattr><![CDATA[0]]></contentattr>
|
|
246
|
+
<sourceUserName></sourceUserName>
|
|
247
|
+
<sourceNickName></sourceNickName>
|
|
248
|
+
<statisticsData></statisticsData>
|
|
249
|
+
<weappInfo>
|
|
250
|
+
<appUserName></appUserName>
|
|
251
|
+
<pagePath></pagePath>
|
|
252
|
+
<version><![CDATA[0]]></version>
|
|
253
|
+
<isHidden>0</isHidden>
|
|
254
|
+
<debugMode><![CDATA[0]]></debugMode>
|
|
255
|
+
<shareActionId></shareActionId>
|
|
256
|
+
<isGame><![CDATA[0]]></isGame>
|
|
257
|
+
<messageExtraData></messageExtraData>
|
|
258
|
+
<subType><![CDATA[0]]></subType>
|
|
259
|
+
<preloadResources></preloadResources>
|
|
260
|
+
</weappInfo>
|
|
261
|
+
<canvasInfoXml></canvasInfoXml>
|
|
262
|
+
<ContentObject>
|
|
263
|
+
<contentStyle><![CDATA[1]]></contentStyle>
|
|
264
|
+
<contentSubStyle><![CDATA[0]]></contentSubStyle>
|
|
265
|
+
<title></title>
|
|
266
|
+
<description></description>
|
|
267
|
+
<contentUrl></contentUrl>
|
|
268
|
+
<mediaList>${mediaString}</mediaList>
|
|
269
|
+
</ContentObject>
|
|
270
|
+
<actionInfo>
|
|
271
|
+
<appMsg>
|
|
272
|
+
<mediaTagName></mediaTagName>
|
|
273
|
+
<messageExt></messageExt>
|
|
274
|
+
<messageAction></messageAction>
|
|
275
|
+
</appMsg>
|
|
276
|
+
</actionInfo>
|
|
277
|
+
<appInfo><id></id></appInfo>
|
|
278
|
+
<publicUserName></publicUserName>
|
|
279
|
+
<streamvideo>
|
|
280
|
+
<streamvideourl></streamvideourl>
|
|
281
|
+
<streamvideothumburl></streamvideothumburl>
|
|
282
|
+
<streamvideoweburl></streamvideoweburl>
|
|
283
|
+
</streamvideo>
|
|
284
|
+
</TimelineObject>`;
|
|
285
|
+
return xmlTemplate;
|
|
286
|
+
};
|
|
90
287
|
class Client extends EventEmitter {
|
|
91
288
|
options;
|
|
92
289
|
connectionStatus = { status: 'disconnected' };
|
|
93
290
|
MAX_RECONNECT_ATTEMPTS = 10;
|
|
94
291
|
INITIAL_RECONNECT_DELAY = 1000;
|
|
95
292
|
MAX_RECONNECT_DELAY = 30000;
|
|
293
|
+
HEARTBEAT_INTERVAL = 40 * 1000;
|
|
294
|
+
HEARTBEAT_TIMEOUT = 5000;
|
|
96
295
|
reconnectAttempts = 0;
|
|
296
|
+
heartbeatTimer;
|
|
297
|
+
heartbeatTimeoutTimer;
|
|
97
298
|
socket;
|
|
98
299
|
server;
|
|
99
300
|
tokenInfo;
|
|
@@ -151,7 +352,7 @@ class Client extends EventEmitter {
|
|
|
151
352
|
ws.once('open', () => {
|
|
152
353
|
this.connectionStatus.status = 'connected';
|
|
153
354
|
this.reconnectAttempts = 0;
|
|
154
|
-
log.
|
|
355
|
+
log.info('WebSocket connection opened');
|
|
155
356
|
resolve();
|
|
156
357
|
});
|
|
157
358
|
ws.once('error', (error) => {
|
|
@@ -163,12 +364,17 @@ class Client extends EventEmitter {
|
|
|
163
364
|
reject(new Error(`WebSocket closed: ${code} - ${reason}`));
|
|
164
365
|
});
|
|
165
366
|
});
|
|
166
|
-
this.setupWebSocketListeners(ws);
|
|
167
367
|
this.socket = ws;
|
|
368
|
+
this.setupWebSocketListeners(ws);
|
|
168
369
|
}
|
|
169
370
|
setupWebSocketListeners(ws) {
|
|
170
371
|
ws.on('message', (data) => {
|
|
372
|
+
this.resetHeartbeatTimeout();
|
|
171
373
|
log.silly(PRE, 'initWebSocket() ws.on(message): %s', data);
|
|
374
|
+
if (data.toString() === 'pong') {
|
|
375
|
+
log.info('Received heartbeat');
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
172
378
|
try {
|
|
173
379
|
const payload = JSON.parse(data);
|
|
174
380
|
log.info('Received payload', JSON.stringify(payload));
|
|
@@ -188,13 +394,59 @@ class Client extends EventEmitter {
|
|
|
188
394
|
this.emit('error', error);
|
|
189
395
|
});
|
|
190
396
|
ws.on('close', (code, reason) => {
|
|
397
|
+
this.stopHeartbeat();
|
|
191
398
|
void this.handleWebSocketClose(code, reason);
|
|
192
399
|
});
|
|
400
|
+
this.startHeartbeat();
|
|
401
|
+
}
|
|
402
|
+
startHeartbeat() {
|
|
403
|
+
this.stopHeartbeat();
|
|
404
|
+
this.socket?.send('ping');
|
|
405
|
+
this.heartbeatTimer = setInterval(() => {
|
|
406
|
+
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
407
|
+
try {
|
|
408
|
+
this.socket.send('ping');
|
|
409
|
+
this.setHeartbeatTimeout();
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
log.error('Failed to send heartbeat:', error);
|
|
413
|
+
void this.handleWebSocketClose(1006, 'Heartbeat failed');
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}, this.HEARTBEAT_INTERVAL);
|
|
417
|
+
}
|
|
418
|
+
stopHeartbeat() {
|
|
419
|
+
if (this.heartbeatTimer) {
|
|
420
|
+
clearInterval(this.heartbeatTimer);
|
|
421
|
+
this.heartbeatTimer = undefined;
|
|
422
|
+
}
|
|
423
|
+
if (this.heartbeatTimeoutTimer) {
|
|
424
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
425
|
+
this.heartbeatTimeoutTimer = undefined;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
setHeartbeatTimeout() {
|
|
429
|
+
if (this.heartbeatTimeoutTimer) {
|
|
430
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
431
|
+
}
|
|
432
|
+
this.heartbeatTimeoutTimer = setTimeout(() => {
|
|
433
|
+
log.warn('Heartbeat timeout, reconnecting...');
|
|
434
|
+
void this.handleWebSocketClose(1006, 'Heartbeat timeout');
|
|
435
|
+
}, this.HEARTBEAT_TIMEOUT);
|
|
436
|
+
}
|
|
437
|
+
resetHeartbeatTimeout() {
|
|
438
|
+
if (this.heartbeatTimeoutTimer) {
|
|
439
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
440
|
+
this.heartbeatTimeoutTimer = undefined;
|
|
441
|
+
}
|
|
193
442
|
}
|
|
194
443
|
async handleWebSocketClose(code, reason) {
|
|
195
444
|
this.connectionStatus.status = 'disconnected';
|
|
196
445
|
log.warn(`WebSocket closed: Code ${code}, Reason ${reason}`);
|
|
197
|
-
this.socket
|
|
446
|
+
if (this.socket) {
|
|
447
|
+
this.socket.close();
|
|
448
|
+
this.socket = null;
|
|
449
|
+
}
|
|
198
450
|
await this.reconnect();
|
|
199
451
|
}
|
|
200
452
|
async reconnect() {
|
|
@@ -1343,7 +1595,7 @@ class Client extends EventEmitter {
|
|
|
1343
1595
|
announcement: content,
|
|
1344
1596
|
},
|
|
1345
1597
|
});
|
|
1346
|
-
if (res
|
|
1598
|
+
if (res?.baseResponse?.ret) {
|
|
1347
1599
|
log.error('sendAnnouncement error: %s', JSON.stringify(res.baseResponse));
|
|
1348
1600
|
}
|
|
1349
1601
|
}
|
|
@@ -1351,5 +1603,156 @@ class Client extends EventEmitter {
|
|
|
1351
1603
|
log.error(PRE, 'sendAnnouncement(%s, %s): %s', roomId, content, error);
|
|
1352
1604
|
}
|
|
1353
1605
|
}
|
|
1606
|
+
async uploadSnsImage(url) {
|
|
1607
|
+
try {
|
|
1608
|
+
const res = await this.postData({
|
|
1609
|
+
path: '/cloud/cdn_upload_sns_image',
|
|
1610
|
+
data: {
|
|
1611
|
+
url,
|
|
1612
|
+
},
|
|
1613
|
+
});
|
|
1614
|
+
if (res?.errcode !== 0) {
|
|
1615
|
+
log.error('uploadSnsImage error: %s', JSON.stringify(res));
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
return res;
|
|
1619
|
+
}
|
|
1620
|
+
catch (error) {
|
|
1621
|
+
log.error(PRE, 'uploadSnsImage(%s): %s', url, error);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
async uploadSnsVideo(url) {
|
|
1625
|
+
try {
|
|
1626
|
+
const res = await this.postData({
|
|
1627
|
+
path: '/cloud/cdn_upload_sns_video',
|
|
1628
|
+
data: {
|
|
1629
|
+
url,
|
|
1630
|
+
},
|
|
1631
|
+
});
|
|
1632
|
+
log.info('uploadSnsVideo result:%s', res.data);
|
|
1633
|
+
if (res?.errcode !== 0) {
|
|
1634
|
+
log.error('uploadSnsVideo error: %s', JSON.stringify(res));
|
|
1635
|
+
}
|
|
1636
|
+
return res;
|
|
1637
|
+
}
|
|
1638
|
+
catch (error) {
|
|
1639
|
+
log.error(PRE, 'updateSnsImage(%s): %s', url, error);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
async sendSnsMoment(wxid, momentInfo) {
|
|
1643
|
+
try {
|
|
1644
|
+
log.info('momentInfo: %s', JSON.stringify(momentInfo));
|
|
1645
|
+
let xmlContent = '';
|
|
1646
|
+
if (momentInfo.parentId && momentInfo.rootId) {
|
|
1647
|
+
return await this.sendMomentReply(momentInfo.rootId, momentInfo.content, momentInfo.parentId === momentInfo.rootId ? '' : momentInfo.parentId);
|
|
1648
|
+
}
|
|
1649
|
+
if (momentInfo.imageUrls.length) {
|
|
1650
|
+
const imageInfo = [];
|
|
1651
|
+
for (const image of momentInfo.imageUrls) {
|
|
1652
|
+
const res = await this.uploadSnsImage(image);
|
|
1653
|
+
if (res) {
|
|
1654
|
+
const imageBaseInfo = await getImageInfo(image);
|
|
1655
|
+
imageInfo.push({ ...res, ...imageBaseInfo });
|
|
1656
|
+
}
|
|
1657
|
+
xmlContent = genImageSnsXml(wxid, momentInfo.content, imageInfo);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
else if (momentInfo.videoUrl) {
|
|
1661
|
+
const mediaInfo = await this.uploadSnsVideo(momentInfo.videoUrl);
|
|
1662
|
+
if (mediaInfo) {
|
|
1663
|
+
const thumbInfo = await getImageInfo(mediaInfo.thumb_url);
|
|
1664
|
+
xmlContent = genVideoSnsXml(wxid, momentInfo.content, { ...mediaInfo, ...thumbInfo });
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
else {
|
|
1668
|
+
xmlContent = genTextSnsXml(wxid, momentInfo.content);
|
|
1669
|
+
}
|
|
1670
|
+
return await this.sendMoment(xmlContent);
|
|
1671
|
+
}
|
|
1672
|
+
catch (error) {
|
|
1673
|
+
log.error(PRE, 'sendSnsMoment(%s): %s', JSON.stringify(momentInfo), error);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
async sendMoment(content) {
|
|
1677
|
+
try {
|
|
1678
|
+
const res = await this.postData({
|
|
1679
|
+
path: '/sns/sns_post',
|
|
1680
|
+
data: {
|
|
1681
|
+
object_desc: content,
|
|
1682
|
+
with_user_list: [],
|
|
1683
|
+
block_user_list: [],
|
|
1684
|
+
group_user_list: [],
|
|
1685
|
+
group_contact_tag_id_list: [],
|
|
1686
|
+
black_contact_tag_id_list: [],
|
|
1687
|
+
},
|
|
1688
|
+
});
|
|
1689
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1690
|
+
log.error('sendMoment error: %s', JSON.stringify(res));
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
log.info(PRE, 'sendMomen success: %s', res?.snsObject?.id);
|
|
1694
|
+
return res?.snsObject?.id;
|
|
1695
|
+
}
|
|
1696
|
+
catch (error) {
|
|
1697
|
+
log.error(PRE, 'sendMoment(%s): %s', content, error);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
async unSendMoment(objectId) {
|
|
1701
|
+
try {
|
|
1702
|
+
const res = await this.postData({
|
|
1703
|
+
path: '/sns/sns_delete',
|
|
1704
|
+
data: {
|
|
1705
|
+
object_id: objectId,
|
|
1706
|
+
},
|
|
1707
|
+
});
|
|
1708
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1709
|
+
log.error('unSendMoment error: %s', JSON.stringify(res));
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
return objectId;
|
|
1713
|
+
}
|
|
1714
|
+
catch (error) {
|
|
1715
|
+
log.error(PRE, 'unSendMoment(%s): %s', objectId, error);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
async sendMomentLike(objectId, status) {
|
|
1719
|
+
try {
|
|
1720
|
+
const res = await this.postData({
|
|
1721
|
+
path: '/sns/sns_like',
|
|
1722
|
+
data: {
|
|
1723
|
+
object_id: objectId,
|
|
1724
|
+
status,
|
|
1725
|
+
},
|
|
1726
|
+
});
|
|
1727
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1728
|
+
log.error('sendMomentLike error: %s', JSON.stringify(res));
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
return res?.snsObject?.id;
|
|
1732
|
+
}
|
|
1733
|
+
catch (error) {
|
|
1734
|
+
log.error(PRE, 'sendMomentLike(%s): %s', objectId, error);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
async sendMomentReply(objectId, content, commentId) {
|
|
1738
|
+
try {
|
|
1739
|
+
const res = await this.postData({
|
|
1740
|
+
path: '/sns/sns_comment',
|
|
1741
|
+
data: {
|
|
1742
|
+
object_id: objectId,
|
|
1743
|
+
content,
|
|
1744
|
+
reply_comment_id: commentId || '0',
|
|
1745
|
+
},
|
|
1746
|
+
});
|
|
1747
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1748
|
+
log.error('sendMomentLike error: %s', JSON.stringify(res));
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
return res?.snsObject?.id;
|
|
1752
|
+
}
|
|
1753
|
+
catch (error) {
|
|
1754
|
+
log.error(PRE, 'sendMomentLike(%s): %s', objectId, error);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1354
1757
|
}
|
|
1355
1758
|
export default Client;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare function delay(ms: number): Promise<void>;
|
|
2
2
|
export declare function putFileTransfer(fileName: string, fileData: Buffer): Promise<string>;
|
|
3
3
|
export declare function getFileName(path: string): string;
|
|
4
|
+
export declare function generateUniqueNumeric(digits?: number): number;
|
|
5
|
+
export declare function generateRandomString(length: number): string;
|
|
6
|
+
export declare function generateCustomRandomString(prefix: string, length: number): string;
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/utils/index.ts"],"names":[],"mappings":"AAOA,wBAAsB,KAAK,CAAE,EAAE,EAAC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,CAEpD;AAKD,wBAAsB,eAAe,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1F;AAOD,wBAAgB,WAAW,CAAE,IAAI,EAAC,MAAM,GAAG,MAAM,CAKhD"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/utils/index.ts"],"names":[],"mappings":"AAOA,wBAAsB,KAAK,CAAE,EAAE,EAAC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,CAEpD;AAKD,wBAAsB,eAAe,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1F;AAOD,wBAAgB,WAAW,CAAE,IAAI,EAAC,MAAM,GAAG,MAAM,CAKhD;AAOD,wBAAgB,qBAAqB,CAAE,MAAM,SAAK,UAoBjD;AAOD,wBAAgB,oBAAoB,CAAE,MAAM,EAAE,MAAM,UAUnD;AAQD,wBAAgB,0BAA0B,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAUzE"}
|
|
@@ -22,3 +22,31 @@ export function getFileName(path) {
|
|
|
22
22
|
return path.substring(pos + 1);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export function generateUniqueNumeric(digits = 20) {
|
|
26
|
+
digits = digits - 13;
|
|
27
|
+
if (digits <= 0) {
|
|
28
|
+
throw new Error('位数长度必须大于0');
|
|
29
|
+
}
|
|
30
|
+
const currentTimestamp = Date.now();
|
|
31
|
+
const maxRandom = Math.pow(10, digits) - 1;
|
|
32
|
+
const randomPart = Math.floor(Math.random() * maxRandom);
|
|
33
|
+
const paddedRandomPart = randomPart.toString().padStart(digits, '0');
|
|
34
|
+
const uniqueNumeric = parseInt(`${currentTimestamp}${paddedRandomPart}`);
|
|
35
|
+
return uniqueNumeric;
|
|
36
|
+
}
|
|
37
|
+
export function generateRandomString(length) {
|
|
38
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
39
|
+
let result = '';
|
|
40
|
+
for (let i = 0; i < length; i++) {
|
|
41
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
42
|
+
result += characters.charAt(randomIndex);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
export function generateCustomRandomString(prefix, length) {
|
|
47
|
+
if (prefix.length >= length) {
|
|
48
|
+
throw new Error('前缀长度不能大于或等于总长度');
|
|
49
|
+
}
|
|
50
|
+
const remainingPart = generateRandomString(length - prefix.length);
|
|
51
|
+
return prefix + remainingPart;
|
|
52
|
+
}
|
|
@@ -95,6 +95,12 @@ declare class PuppetMatrix extends PUPPET.Puppet {
|
|
|
95
95
|
roomInvitationRawPayloadParser(rawPayload: any): Promise<PUPPET.payloads.RoomInvitation>;
|
|
96
96
|
friendshipRawPayloadParser(rawPayload: PUPPET.payloads.Friendship): Promise<PUPPET.payloads.Friendship>;
|
|
97
97
|
friendshipRawPayload(id: string): Promise<PUPPET.payloads.Friendship>;
|
|
98
|
+
postPublish(payload: PUPPET.payloads.Post): Promise<void | string>;
|
|
99
|
+
postUnpublish(id: string): Promise<void>;
|
|
100
|
+
postRawPayload(id: string): Promise<PUPPET.payloads.Post | string>;
|
|
101
|
+
postPayloadSayable(postId: string, sayableId: string): Promise<PUPPET.payloads.Sayable>;
|
|
102
|
+
postRawPayloadParser(payload: PUPPET.payloads.Post): Promise<PUPPET.payloads.Post>;
|
|
103
|
+
tap(postId: string, type: PUPPET.types.Tap, tap?: boolean): Promise<boolean | void>;
|
|
98
104
|
syncRoom(): Promise<void>;
|
|
99
105
|
private _getRoomMemberList;
|
|
100
106
|
private _updateContactCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"puppet-matrix.d.ts","sourceRoot":"","sources":["../../../src/puppet-matrix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAe,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"puppet-matrix.d.ts","sourceRoot":"","sources":["../../../src/puppet-matrix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAe,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAKhD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExE,OAAO,MAAM,MAAM,6BAA6B,CAAA;AA2BhD,QAAA,MAAM,OAAO,QAAiC,CAAA;AAK9C,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,aAAa,GAAG;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,GAAG,CAAA;CACb,CAAA;AAED,cAAM,YAAa,SA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AM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC;IAKnE,kBAAkB,CAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;IAKxF,oBAAoB,CAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAMnF,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,UAAO,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAY1F,QAAQ;YAWA,kBAAkB;YAkClB,mBAAmB;YAgCnB,iBAAiB;IAYlB,WAAW,CAAE,MAAM,EAAC,MAAM;YAgBzB,cAAc;YAcd,cAAc;YA4Dd,eAAe;YAcf,iBAAiB;IAa/B,OAAO,CAAC,gBAAgB;YAeV,uBAAuB;YASvB,uBAAuB;YASvB,uBAAuB;YAgBvB,sBAAsB;IAuBvB,WAAW;CAQzB;AAED,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAA;AAEhC,eAAe,YAAY,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { log } from '@juzi/wechaty-puppet';
|
|
2
2
|
import * as PUPPET from '@juzi/wechaty-puppet';
|
|
3
|
-
import { FileBox } from 'file-box';
|
|
3
|
+
import { FileBox, FileBoxType, } from 'file-box';
|
|
4
4
|
import Client from './matrix/service/request.js';
|
|
5
5
|
import { getUnixTime } from 'date-fns';
|
|
6
6
|
import { delay } from './matrix/utils/index.js';
|
|
@@ -837,6 +837,90 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
837
837
|
}
|
|
838
838
|
return ret;
|
|
839
839
|
}
|
|
840
|
+
async postPublish(payload) {
|
|
841
|
+
log.verbose(PRE, 'postPublish(%s)', payload);
|
|
842
|
+
if (!PUPPET.payloads.isPostClient(payload)) {
|
|
843
|
+
throw new Error('can only publish client post now');
|
|
844
|
+
}
|
|
845
|
+
const momentInfo = {
|
|
846
|
+
content: '',
|
|
847
|
+
mentionIdList: [],
|
|
848
|
+
visibledList: [],
|
|
849
|
+
imageUrls: [],
|
|
850
|
+
videoUrl: '',
|
|
851
|
+
urlLink: null,
|
|
852
|
+
channel: null,
|
|
853
|
+
miniInfo: null,
|
|
854
|
+
location: null,
|
|
855
|
+
rootId: '',
|
|
856
|
+
parentId: '',
|
|
857
|
+
};
|
|
858
|
+
for (const item of payload.sayableList) {
|
|
859
|
+
switch (item.type) {
|
|
860
|
+
case PUPPET.types.Sayable.Text:
|
|
861
|
+
momentInfo.content = `${momentInfo.content ? momentInfo.content + '\n' : ''}${item.payload.text}`;
|
|
862
|
+
momentInfo.mentionIdList = item.payload.mentions;
|
|
863
|
+
break;
|
|
864
|
+
case PUPPET.types.Sayable.Attachment: {
|
|
865
|
+
const fileBox = item.payload.filebox;
|
|
866
|
+
if (typeof item.payload.filebox !== 'string' && fileBox.type === FileBoxType.Url) {
|
|
867
|
+
const fileType = fileBox.mediaType && fileBox.mediaType !== 'application/octet-stream' ? fileBox.mediaType : path.extname(fileBox.name);
|
|
868
|
+
const fileUrl = fileBox.remoteUrl || '';
|
|
869
|
+
if (fileBox.mediaType.startsWith('image/')) {
|
|
870
|
+
momentInfo.imageUrls.push(fileUrl);
|
|
871
|
+
}
|
|
872
|
+
else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
873
|
+
momentInfo.videoInfo = fileUrl;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
case PUPPET.types.Sayable.Url: {
|
|
879
|
+
momentInfo.urlLink = item.payload;
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
case PUPPET.types.Sayable.Channel: {
|
|
883
|
+
momentInfo.channel = item.payload;
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
case PUPPET.types.Sayable.MiniProgram: {
|
|
887
|
+
momentInfo.miniInfo = item.payload;
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
default:
|
|
891
|
+
throw new Error(`postPublish unsupported type ${item.type}`);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (payload.rootId)
|
|
895
|
+
momentInfo.rootId = payload.rootId;
|
|
896
|
+
if (payload.parentId)
|
|
897
|
+
momentInfo.parentId = payload.parentId;
|
|
898
|
+
if (payload.location)
|
|
899
|
+
momentInfo.location = payload.location;
|
|
900
|
+
momentInfo.visibleList = payload.visibleList;
|
|
901
|
+
const res = await this._client?.sendSnsMoment(this._self?.wxid || '', momentInfo);
|
|
902
|
+
return res;
|
|
903
|
+
}
|
|
904
|
+
async postUnpublish(id) {
|
|
905
|
+
log.verbose(PRE, 'postUnpublish(%s)', id);
|
|
906
|
+
await this._client?.unSendMoment(id);
|
|
907
|
+
}
|
|
908
|
+
async postRawPayload(id) {
|
|
909
|
+
log.verbose(PRE, 'postRawPayload(%s)', id);
|
|
910
|
+
return id;
|
|
911
|
+
}
|
|
912
|
+
async postPayloadSayable(postId, sayableId) {
|
|
913
|
+
log.verbose(PRE, 'postPayloadSayable(%s, %s)', postId, sayableId);
|
|
914
|
+
return postId;
|
|
915
|
+
}
|
|
916
|
+
async postRawPayloadParser(payload) {
|
|
917
|
+
return payload;
|
|
918
|
+
}
|
|
919
|
+
async tap(postId, type, tap = true) {
|
|
920
|
+
log.verbose(PRE, 'tap(%s, %s, %s)', postId, type, tap);
|
|
921
|
+
const res = await this._client?.sendMomentLike(postId, type);
|
|
922
|
+
return !!res;
|
|
923
|
+
}
|
|
840
924
|
async syncRoom() {
|
|
841
925
|
if (this.state.active() !== true) {
|
|
842
926
|
throw new Error('Can not sync contact before login');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FileBox } from 'file-box';
|
|
2
|
+
import { FileBoxInterface } from 'file-box';
|
|
3
|
+
declare const canPassthrough: (fileBox: FileBoxInterface) => boolean;
|
|
4
|
+
declare const normalizeFileBoxUuid: (FileBoxUuid: typeof FileBox) => (fileBox: FileBoxInterface) => Promise<FileBoxInterface | FileBox>;
|
|
5
|
+
export { canPassthrough, normalizeFileBoxUuid, };
|
|
6
|
+
//# sourceMappingURL=normalize-filebox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-filebox.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalize-filebox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACR,MAA0B,UAAU,CAAA;AACrC,OAAO,EAEL,gBAAgB,EACjB,MAA0B,UAAU,CAAA;AA4BrC,QAAA,MAAM,cAAc,YAAa,gBAAgB,YA8BhD,CAAA;AAED,QAAA,MAAM,oBAAoB,gBAAiB,OAAO,OAAO,eAAqB,gBAAgB,wCAkB7F,CAAA;AAED,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,CAAA"}
|