wechaty-puppet-matrix 0.0.10 → 0.0.13
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/messages/message-location.d.ts +2 -0
- package/dist/cjs/src/matrix/messages/message-location.d.ts.map +1 -0
- package/dist/cjs/src/matrix/messages/message-location.js +18 -0
- package/dist/cjs/src/matrix/service/request.d.ts +55 -0
- package/dist/cjs/src/matrix/service/request.d.ts.map +1 -1
- package/dist/cjs/src/matrix/service/request.js +365 -1
- 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 +7 -0
- package/dist/cjs/src/puppet-matrix.d.ts.map +1 -1
- package/dist/cjs/src/puppet-matrix.js +94 -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/messages/message-location.d.ts +2 -0
- package/dist/esm/src/matrix/messages/message-location.d.ts.map +1 -0
- package/dist/esm/src/matrix/messages/message-location.js +15 -0
- package/dist/esm/src/matrix/service/request.d.ts +55 -0
- package/dist/esm/src/matrix/service/request.d.ts.map +1 -1
- package/dist/esm/src/matrix/service/request.js +365 -1
- 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 +7 -0
- package/dist/esm/src/puppet-matrix.d.ts.map +1 -1
- package/dist/esm/src/puppet-matrix.js +95 -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/messages/message-location.ts +46 -0
- package/src/matrix/service/request.ts +483 -2
- package/src/matrix/utils/index.ts +62 -0
- package/src/puppet-matrix.ts +130 -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,6 +91,215 @@ 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);
|
|
103
|
+
const baseDirExist = await fs.pathExists(tempFilePath);
|
|
104
|
+
if (!baseDirExist) {
|
|
105
|
+
await fs.mkdirp(tempFilePath);
|
|
106
|
+
}
|
|
107
|
+
const finalFilePath = path.join(tempFilePath, 'temp_image_' + Date.now() + path.extname(imageUrl));
|
|
108
|
+
await fs.writeFile(finalFilePath, response.data);
|
|
109
|
+
const dimensions = imageSize(finalFilePath);
|
|
110
|
+
await fs.unlink(finalFilePath);
|
|
111
|
+
return {
|
|
112
|
+
file_size: fileSize,
|
|
113
|
+
image_width: dimensions.width,
|
|
114
|
+
image_height: dimensions.height,
|
|
115
|
+
file_type: dimensions.type,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.error('获取图片信息错误:', error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function splitAddress(address = '') {
|
|
124
|
+
if (!address) {
|
|
125
|
+
return { province: '', city: '', area: '' };
|
|
126
|
+
}
|
|
127
|
+
let province = '';
|
|
128
|
+
let city = '';
|
|
129
|
+
let area = '';
|
|
130
|
+
const provinceRegex = /^(.*?(省|自治区|市))|^(.*?)(北京|天津|上海|重庆)市?$/;
|
|
131
|
+
const provinceMatch = address.match(provinceRegex);
|
|
132
|
+
if (provinceMatch) {
|
|
133
|
+
province = provinceMatch[1] || provinceMatch[3];
|
|
134
|
+
address = address.replace(province, '');
|
|
135
|
+
}
|
|
136
|
+
const cityRegex = /^(.*?(市|自治州|地区|盟))|^([^\u4e00-\u9fa5]*)(北京|天津|上海|重庆)$/;
|
|
137
|
+
const cityMatch = address.match(cityRegex);
|
|
138
|
+
if (cityMatch) {
|
|
139
|
+
city = cityMatch[1] || cityMatch[3];
|
|
140
|
+
address = address.replace(city, '');
|
|
141
|
+
}
|
|
142
|
+
const areaRegex = /^(.*?(区|县|市|旗|自治县|林区|特区))|^(.*?(街道|镇|乡))|^([^\u4e00-\u9fa5]*)/;
|
|
143
|
+
const areaMatch = address.match(areaRegex);
|
|
144
|
+
if (areaMatch) {
|
|
145
|
+
area = areaMatch[1] || areaMatch[3] || areaMatch[4];
|
|
146
|
+
address = address.replace(area, '');
|
|
147
|
+
}
|
|
148
|
+
return { province, city, area };
|
|
149
|
+
}
|
|
150
|
+
const genTextPosSnsXml = (wxid, content, location) => {
|
|
151
|
+
const addressInfo = location ? splitAddress(location.address) : {};
|
|
152
|
+
const xmlTemplate = `
|
|
153
|
+
<TimelineObject>
|
|
154
|
+
<id>0</id>
|
|
155
|
+
<username><![CDATA[${wxid}]]></username>
|
|
156
|
+
<createTime><![CDATA[${Math.floor(Date.now() / 1000)}]]></createTime>
|
|
157
|
+
<contentDesc><![CDATA[${content}]]></contentDesc>
|
|
158
|
+
<contentDescShowType>0</contentDescShowType>
|
|
159
|
+
<contentDescScene>3</contentDescScene>
|
|
160
|
+
<private>0</private>
|
|
161
|
+
<sightFolded>0</sightFolded>
|
|
162
|
+
<showFlag>0</showFlag>${location ? `<location city="${addressInfo.city}" longitude="${location.longitude}" latitude="${location.latitude}" poiName="${location.name}" poiAddress="${location.address}" poiScale="11.000000" poiInfoUrl="" poiClassifyId="${location.poiId}" poiClassifyType="1" poiClickableStatus="0" buildingId="0" floorName=""/>` : ''}
|
|
163
|
+
<appInfo>
|
|
164
|
+
<id/>
|
|
165
|
+
<version/>
|
|
166
|
+
<appName/>
|
|
167
|
+
<installUrl/>
|
|
168
|
+
<fromUrl/>
|
|
169
|
+
<isForceUpdate>0</isForceUpdate>
|
|
170
|
+
<isHidden>0</isHidden>
|
|
171
|
+
</appInfo>
|
|
172
|
+
<sourceUserName/>
|
|
173
|
+
<sourceNickName/>
|
|
174
|
+
<statisticsData/>
|
|
175
|
+
<statExtStr/>
|
|
176
|
+
<ContentObject>
|
|
177
|
+
<contentStyle>2</contentStyle>
|
|
178
|
+
<title/>
|
|
179
|
+
<description/>
|
|
180
|
+
<mediaList/>
|
|
181
|
+
</ContentObject>
|
|
182
|
+
</TimelineObject>`;
|
|
183
|
+
return xmlTemplate;
|
|
184
|
+
};
|
|
185
|
+
const genVideoSnsXml = (wxid, content, media, location) => {
|
|
186
|
+
const addressInfo = location ? splitAddress(location.address) : {};
|
|
187
|
+
const xmlTemplate = `
|
|
188
|
+
<TimelineObject>
|
|
189
|
+
<id>0</id>
|
|
190
|
+
<username>${wxid}</username>
|
|
191
|
+
<createTime>${Math.floor(Date.now() / 1000)}</createTime>
|
|
192
|
+
<contentDesc>${content}</contentDesc>
|
|
193
|
+
<contentDescShowType>0</contentDescShowType>
|
|
194
|
+
<contentDescScene>0</contentDescScene>
|
|
195
|
+
<private>0</private>
|
|
196
|
+
<sightFolded>0</sightFolded>
|
|
197
|
+
<showFlag>0</showFlag>${location ? `<location city="${addressInfo.city}" longitude="${location.longitude}" latitude="${location.latitude}" poiName="${location.name}" poiAddress="${location.address}" poiScale="11.000000" poiInfoUrl="" poiClassifyId="${location.poiId}" poiClassifyType="1" poiClickableStatus="0" buildingId="0" floorName=""/>` : ''}
|
|
198
|
+
<appInfo>
|
|
199
|
+
<id></id>
|
|
200
|
+
<version></version>
|
|
201
|
+
<appName></appName>
|
|
202
|
+
<installUrl></installUrl>
|
|
203
|
+
<fromUrl></fromUrl>
|
|
204
|
+
<isForceUpdate>0</isForceUpdate>
|
|
205
|
+
<isHidden>0</isHidden>
|
|
206
|
+
</appInfo>
|
|
207
|
+
<sourceUserName></sourceUserName>
|
|
208
|
+
<sourceNickName></sourceNickName>
|
|
209
|
+
<statisticsData></statisticsData>
|
|
210
|
+
<statExtStr></statExtStr>
|
|
211
|
+
<ContentObject>
|
|
212
|
+
<contentStyle>15</contentStyle>
|
|
213
|
+
<title>微信小视频</title>
|
|
214
|
+
<description>Sight</description>
|
|
215
|
+
<mediaList>
|
|
216
|
+
<media>
|
|
217
|
+
<id>0</id>
|
|
218
|
+
<type>6</type>
|
|
219
|
+
<title></title>
|
|
220
|
+
<description>${content}</description>
|
|
221
|
+
<private>0</private>
|
|
222
|
+
<userData></userData>
|
|
223
|
+
<subType>0</subType>
|
|
224
|
+
<videoSize width="${media.video_width}" height="${media.video_height}"/>
|
|
225
|
+
<url type="1" md5="951a7d7864d685a92fd2624155794bf9" videomd5="577f55635faf44f595a69ded26d87bcc">${media.file_url}</url>
|
|
226
|
+
<thumb type="1">${media.thumb_url}</thumb>
|
|
227
|
+
<size width="${media.thumb_width}.000000" height="${media.thumb_height}.000000" totalSize="${media.file_size}"/>
|
|
228
|
+
<videoDuration>${media.video_duration}.000000</videoDuration>
|
|
229
|
+
</media>
|
|
230
|
+
</mediaList>
|
|
231
|
+
<contentUrl>https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&v=1</contentUrl>
|
|
232
|
+
</ContentObject>
|
|
233
|
+
</TimelineObject>`;
|
|
234
|
+
return xmlTemplate;
|
|
235
|
+
};
|
|
236
|
+
const genImageSnsXml = (wxid, contentDesc, mediaList, location) => {
|
|
237
|
+
const mediaTemplate = (media) => `
|
|
238
|
+
<media>
|
|
239
|
+
<id><![CDATA[0]]></id>
|
|
240
|
+
<type><![CDATA[2]]></type>
|
|
241
|
+
<title></title>
|
|
242
|
+
<description></description>
|
|
243
|
+
<private><![CDATA[0]]></private>
|
|
244
|
+
<url type="1" md5="951a7d7864d685a92fd2624155794bf9"><![CDATA[${media.file_url}]]></url>
|
|
245
|
+
<thumb type="1"><![CDATA[${media.thumb_url}]]></thumb>
|
|
246
|
+
<videoDuration><![CDATA[0.0]]></videoDuration>
|
|
247
|
+
<size totalSize="${media.file_size}" width="${media.image_width}" height="${media.image_height}"></size>
|
|
248
|
+
</media>`;
|
|
249
|
+
const mediaString = mediaList.map(media => mediaTemplate(media)).join('');
|
|
250
|
+
const addressInfo = location ? splitAddress(location.address) : {};
|
|
251
|
+
const xmlTemplate = `
|
|
252
|
+
<TimelineObject>
|
|
253
|
+
<id><![CDATA[0]]></id>
|
|
254
|
+
<username><![CDATA[${wxid}]]></username>
|
|
255
|
+
<createTime><![CDATA[${Math.floor(Date.now() / 1000)}]]></createTime>
|
|
256
|
+
<contentDescShowType>0</contentDescShowType>
|
|
257
|
+
<contentDescScene>0</contentDescScene>
|
|
258
|
+
<private><![CDATA[0]]></private>
|
|
259
|
+
<contentDesc><![CDATA[${contentDesc}]]></contentDesc>
|
|
260
|
+
<contentattr><![CDATA[0]]></contentattr>
|
|
261
|
+
<sourceUserName></sourceUserName>
|
|
262
|
+
<sourceNickName></sourceNickName>
|
|
263
|
+
<statisticsData></statisticsData>
|
|
264
|
+
<weappInfo>
|
|
265
|
+
<appUserName></appUserName>
|
|
266
|
+
<pagePath></pagePath>
|
|
267
|
+
<version><![CDATA[0]]></version>
|
|
268
|
+
<isHidden>0</isHidden>
|
|
269
|
+
<debugMode><![CDATA[0]]></debugMode>
|
|
270
|
+
<shareActionId></shareActionId>
|
|
271
|
+
<isGame><![CDATA[0]]></isGame>
|
|
272
|
+
<messageExtraData></messageExtraData>
|
|
273
|
+
<subType><![CDATA[0]]></subType>
|
|
274
|
+
<preloadResources></preloadResources>
|
|
275
|
+
</weappInfo>
|
|
276
|
+
<canvasInfoXml></canvasInfoXml>
|
|
277
|
+
${location ? `<location city="${addressInfo.city}" longitude="${location.longitude}" latitude="${location.latitude}" poiName="${location.name}" poiAddress="${location.address}" poiScale="11.000000" poiInfoUrl="" poiClassifyId="${location.poiId}" poiClassifyType="1" poiClickableStatus="0" buildingId="0" floorName=""/>` : ''}
|
|
278
|
+
<ContentObject>
|
|
279
|
+
<contentStyle><![CDATA[1]]></contentStyle>
|
|
280
|
+
<contentSubStyle><![CDATA[0]]></contentSubStyle>
|
|
281
|
+
<title></title>
|
|
282
|
+
<description></description>
|
|
283
|
+
<contentUrl></contentUrl>
|
|
284
|
+
<mediaList>${mediaString}</mediaList>
|
|
285
|
+
</ContentObject>
|
|
286
|
+
<actionInfo>
|
|
287
|
+
<appMsg>
|
|
288
|
+
<mediaTagName></mediaTagName>
|
|
289
|
+
<messageExt></messageExt>
|
|
290
|
+
<messageAction></messageAction>
|
|
291
|
+
</appMsg>
|
|
292
|
+
</actionInfo>
|
|
293
|
+
<appInfo><id></id></appInfo>
|
|
294
|
+
<publicUserName></publicUserName>
|
|
295
|
+
<streamvideo>
|
|
296
|
+
<streamvideourl></streamvideourl>
|
|
297
|
+
<streamvideothumburl></streamvideothumburl>
|
|
298
|
+
<streamvideoweburl></streamvideoweburl>
|
|
299
|
+
</streamvideo>
|
|
300
|
+
</TimelineObject>`;
|
|
301
|
+
return xmlTemplate;
|
|
302
|
+
};
|
|
90
303
|
class Client extends EventEmitter {
|
|
91
304
|
options;
|
|
92
305
|
connectionStatus = { status: 'disconnected' };
|
|
@@ -1398,7 +1611,7 @@ class Client extends EventEmitter {
|
|
|
1398
1611
|
announcement: content,
|
|
1399
1612
|
},
|
|
1400
1613
|
});
|
|
1401
|
-
if (res
|
|
1614
|
+
if (res?.baseResponse?.ret) {
|
|
1402
1615
|
log.error('sendAnnouncement error: %s', JSON.stringify(res.baseResponse));
|
|
1403
1616
|
}
|
|
1404
1617
|
}
|
|
@@ -1406,5 +1619,156 @@ class Client extends EventEmitter {
|
|
|
1406
1619
|
log.error(PRE, 'sendAnnouncement(%s, %s): %s', roomId, content, error);
|
|
1407
1620
|
}
|
|
1408
1621
|
}
|
|
1622
|
+
async uploadSnsImage(url) {
|
|
1623
|
+
try {
|
|
1624
|
+
const res = await this.postData({
|
|
1625
|
+
path: '/cloud/cdn_upload_sns_image',
|
|
1626
|
+
data: {
|
|
1627
|
+
url,
|
|
1628
|
+
},
|
|
1629
|
+
});
|
|
1630
|
+
if (res?.errcode !== 0) {
|
|
1631
|
+
log.error('uploadSnsImage error: %s', JSON.stringify(res));
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
return res;
|
|
1635
|
+
}
|
|
1636
|
+
catch (error) {
|
|
1637
|
+
log.error(PRE, 'uploadSnsImage(%s): %s', url, error);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
async uploadSnsVideo(url) {
|
|
1641
|
+
try {
|
|
1642
|
+
const res = await this.postData({
|
|
1643
|
+
path: '/cloud/cdn_upload_sns_video',
|
|
1644
|
+
data: {
|
|
1645
|
+
url,
|
|
1646
|
+
},
|
|
1647
|
+
});
|
|
1648
|
+
log.info('uploadSnsVideo result: %s', res);
|
|
1649
|
+
if (res?.errcode !== 0) {
|
|
1650
|
+
log.error('uploadSnsVideo error: %s', JSON.stringify(res));
|
|
1651
|
+
}
|
|
1652
|
+
return res;
|
|
1653
|
+
}
|
|
1654
|
+
catch (error) {
|
|
1655
|
+
log.error(PRE, 'updateSnsImage(%s): %s', url, error);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
async sendSnsMoment(wxid, momentInfo) {
|
|
1659
|
+
try {
|
|
1660
|
+
log.info('momentInfo: %s', JSON.stringify(momentInfo));
|
|
1661
|
+
let xmlContent = '';
|
|
1662
|
+
if (momentInfo.parentId && momentInfo.rootId) {
|
|
1663
|
+
return await this.sendMomentReply(momentInfo.rootId, momentInfo.content, momentInfo.parentId === momentInfo.rootId ? '' : momentInfo.parentId);
|
|
1664
|
+
}
|
|
1665
|
+
if (momentInfo.imageUrls.length) {
|
|
1666
|
+
const imageInfo = [];
|
|
1667
|
+
for (const image of momentInfo.imageUrls) {
|
|
1668
|
+
const res = await this.uploadSnsImage(image);
|
|
1669
|
+
if (res) {
|
|
1670
|
+
const imageBaseInfo = await getImageInfo(image);
|
|
1671
|
+
imageInfo.push({ ...res, ...imageBaseInfo });
|
|
1672
|
+
}
|
|
1673
|
+
xmlContent = genImageSnsXml(wxid, momentInfo.content, imageInfo, momentInfo.location);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
else if (momentInfo.videoUrl) {
|
|
1677
|
+
const mediaInfo = await this.uploadSnsVideo(momentInfo.videoUrl);
|
|
1678
|
+
if (mediaInfo) {
|
|
1679
|
+
const thumbInfo = await getImageInfo(mediaInfo.thumb_url);
|
|
1680
|
+
xmlContent = genVideoSnsXml(wxid, momentInfo.content, { ...mediaInfo, ...thumbInfo }, momentInfo.location);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
else {
|
|
1684
|
+
xmlContent = genTextPosSnsXml(wxid, momentInfo.content, momentInfo.location);
|
|
1685
|
+
}
|
|
1686
|
+
return await this.sendMoment(xmlContent);
|
|
1687
|
+
}
|
|
1688
|
+
catch (error) {
|
|
1689
|
+
log.error(PRE, 'sendSnsMoment(%s): %s', JSON.stringify(momentInfo), error);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
async sendMoment(content) {
|
|
1693
|
+
try {
|
|
1694
|
+
const res = await this.postData({
|
|
1695
|
+
path: '/sns/sns_post',
|
|
1696
|
+
data: {
|
|
1697
|
+
object_desc: content,
|
|
1698
|
+
with_user_list: [],
|
|
1699
|
+
block_user_list: [],
|
|
1700
|
+
group_user_list: [],
|
|
1701
|
+
group_contact_tag_id_list: [],
|
|
1702
|
+
black_contact_tag_id_list: [],
|
|
1703
|
+
},
|
|
1704
|
+
});
|
|
1705
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1706
|
+
log.error('sendMoment error: %s', JSON.stringify(res));
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
log.info(PRE, 'sendMomen success: %s', res?.snsObject?.id);
|
|
1710
|
+
return res?.snsObject?.id;
|
|
1711
|
+
}
|
|
1712
|
+
catch (error) {
|
|
1713
|
+
log.error(PRE, 'sendMoment(%s): %s', content, error);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
async unSendMoment(objectId) {
|
|
1717
|
+
try {
|
|
1718
|
+
const res = await this.postData({
|
|
1719
|
+
path: '/sns/sns_delete',
|
|
1720
|
+
data: {
|
|
1721
|
+
object_id: objectId,
|
|
1722
|
+
},
|
|
1723
|
+
});
|
|
1724
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1725
|
+
log.error('unSendMoment error: %s', JSON.stringify(res));
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
return objectId;
|
|
1729
|
+
}
|
|
1730
|
+
catch (error) {
|
|
1731
|
+
log.error(PRE, 'unSendMoment(%s): %s', objectId, error);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
async sendMomentLike(objectId, status) {
|
|
1735
|
+
try {
|
|
1736
|
+
const res = await this.postData({
|
|
1737
|
+
path: '/sns/sns_like',
|
|
1738
|
+
data: {
|
|
1739
|
+
object_id: objectId,
|
|
1740
|
+
status,
|
|
1741
|
+
},
|
|
1742
|
+
});
|
|
1743
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1744
|
+
log.error('sendMomentLike error: %s', JSON.stringify(res));
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
return res?.snsObject?.id;
|
|
1748
|
+
}
|
|
1749
|
+
catch (error) {
|
|
1750
|
+
log.error(PRE, 'sendMomentLike(%s): %s', objectId, error);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
async sendMomentReply(objectId, content, commentId) {
|
|
1754
|
+
try {
|
|
1755
|
+
const res = await this.postData({
|
|
1756
|
+
path: '/sns/sns_comment',
|
|
1757
|
+
data: {
|
|
1758
|
+
object_id: objectId,
|
|
1759
|
+
content,
|
|
1760
|
+
reply_comment_id: commentId || '0',
|
|
1761
|
+
},
|
|
1762
|
+
});
|
|
1763
|
+
if (res?.baseResponse?.ret !== 0) {
|
|
1764
|
+
log.error('sendMomentLike error: %s', JSON.stringify(res));
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
return res?.snsObject?.id;
|
|
1768
|
+
}
|
|
1769
|
+
catch (error) {
|
|
1770
|
+
log.error(PRE, 'sendMomentLike(%s): %s', objectId, error);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1409
1773
|
}
|
|
1410
1774
|
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
|
+
}
|
|
@@ -62,6 +62,7 @@ declare class PuppetMatrix extends PUPPET.Puppet {
|
|
|
62
62
|
messageImage(messageId: string): Promise<FileBoxInterface>;
|
|
63
63
|
messageMiniProgram(messageId: string): Promise<PUPPET.payloads.MiniProgram>;
|
|
64
64
|
messageUrl(messageId: string): Promise<PUPPET.payloads.UrlLink>;
|
|
65
|
+
messageLocation(messageId: string): Promise<PUPPET.payloads.Location>;
|
|
65
66
|
messageSendContact(toUserId: string, contactId: string): Promise<void | string>;
|
|
66
67
|
messageSendFile(conversationId: string, fileBox: FileBoxInterface): Promise<string | void>;
|
|
67
68
|
messageSendMiniProgram(toUserName: string, mpPayload: PUPPET.payloads.MiniProgram): Promise<void | string>;
|
|
@@ -95,6 +96,12 @@ declare class PuppetMatrix extends PUPPET.Puppet {
|
|
|
95
96
|
roomInvitationRawPayloadParser(rawPayload: any): Promise<PUPPET.payloads.RoomInvitation>;
|
|
96
97
|
friendshipRawPayloadParser(rawPayload: PUPPET.payloads.Friendship): Promise<PUPPET.payloads.Friendship>;
|
|
97
98
|
friendshipRawPayload(id: string): Promise<PUPPET.payloads.Friendship>;
|
|
99
|
+
postPublish(payload: PUPPET.payloads.Post): Promise<void | string>;
|
|
100
|
+
postUnpublish(id: string): Promise<void>;
|
|
101
|
+
postRawPayload(id: string): Promise<PUPPET.payloads.Post | string>;
|
|
102
|
+
postPayloadSayable(postId: string, sayableId: string): Promise<PUPPET.payloads.Sayable>;
|
|
103
|
+
postRawPayloadParser(payload: PUPPET.payloads.Post): Promise<PUPPET.payloads.Post>;
|
|
104
|
+
tap(postId: string, type: PUPPET.types.Tap, tap?: boolean): Promise<boolean | void>;
|
|
98
105
|
syncRoom(): Promise<void>;
|
|
99
106
|
private _getRoomMemberList;
|
|
100
107
|
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;AA4BhD,QAAA,MAAM,OAAO,QAAiC,C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|
+
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';
|
|
@@ -13,6 +13,7 @@ import { parseEmotionMessagePayload } from './matrix/messages/message-emotion.js
|
|
|
13
13
|
import { parseImageMessagePayload } from './matrix/messages/message-image.js';
|
|
14
14
|
import { parseAudioMessagePayload } from './matrix/messages/message-audio.js';
|
|
15
15
|
import { parseVideoMessagePayload } from './matrix/messages/message-video.js';
|
|
16
|
+
import { parseLocationMessagePayload } from './matrix/messages/message-location.js';
|
|
16
17
|
import { CachedPromiseFunc } from './matrix/utils/cached-promise.js';
|
|
17
18
|
import { engineMessageToWechaty } from './matrix/schema-mapper/message.js';
|
|
18
19
|
import { engineContactToWechaty } from './matrix/schema-mapper/contact.js';
|
|
@@ -568,6 +569,15 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
568
569
|
url: appPayload.url,
|
|
569
570
|
};
|
|
570
571
|
}
|
|
572
|
+
async messageLocation(messageId) {
|
|
573
|
+
const rawPayload = await this.messageRawPayload(messageId);
|
|
574
|
+
const payload = await this.messageRawPayloadParser(rawPayload);
|
|
575
|
+
if (payload.type !== PUPPET.types.Message.Location) {
|
|
576
|
+
throw new Error('Can not get location from non location payload');
|
|
577
|
+
}
|
|
578
|
+
const locationPayload = await parseLocationMessagePayload(rawPayload.msg);
|
|
579
|
+
return locationPayload;
|
|
580
|
+
}
|
|
571
581
|
async messageSendContact(toUserId, contactId) {
|
|
572
582
|
log.verbose('PuppetWeChat', 'messageSend("%s", %s)', toUserId, contactId);
|
|
573
583
|
const contactPayload = await this.contactRawPayload(contactId);
|
|
@@ -837,6 +847,90 @@ class PuppetMatrix extends PUPPET.Puppet {
|
|
|
837
847
|
}
|
|
838
848
|
return ret;
|
|
839
849
|
}
|
|
850
|
+
async postPublish(payload) {
|
|
851
|
+
log.verbose(PRE, 'postPublish(%s)', payload);
|
|
852
|
+
if (!PUPPET.payloads.isPostClient(payload)) {
|
|
853
|
+
throw new Error('can only publish client post now');
|
|
854
|
+
}
|
|
855
|
+
const momentInfo = {
|
|
856
|
+
content: '',
|
|
857
|
+
mentionIdList: [],
|
|
858
|
+
visibledList: [],
|
|
859
|
+
imageUrls: [],
|
|
860
|
+
videoUrl: '',
|
|
861
|
+
urlLink: null,
|
|
862
|
+
channel: null,
|
|
863
|
+
miniInfo: null,
|
|
864
|
+
location: null,
|
|
865
|
+
rootId: '',
|
|
866
|
+
parentId: '',
|
|
867
|
+
};
|
|
868
|
+
for (const item of payload.sayableList) {
|
|
869
|
+
switch (item.type) {
|
|
870
|
+
case PUPPET.types.Sayable.Text:
|
|
871
|
+
momentInfo.content = `${momentInfo.content ? momentInfo.content + '\n' : ''}${item.payload.text}`;
|
|
872
|
+
momentInfo.mentionIdList = item.payload.mentions;
|
|
873
|
+
break;
|
|
874
|
+
case PUPPET.types.Sayable.Attachment: {
|
|
875
|
+
const fileBox = item.payload.filebox;
|
|
876
|
+
if (typeof item.payload.filebox !== 'string' && fileBox.type === FileBoxType.Url) {
|
|
877
|
+
const fileType = fileBox.mediaType && fileBox.mediaType !== 'application/octet-stream' ? fileBox.mediaType : path.extname(fileBox.name);
|
|
878
|
+
const fileUrl = fileBox.remoteUrl || '';
|
|
879
|
+
if (fileBox.mediaType.startsWith('image/')) {
|
|
880
|
+
momentInfo.imageUrls.push(fileUrl);
|
|
881
|
+
}
|
|
882
|
+
else if (fileType.includes('video/mp4') || fileType.includes('.mp4')) {
|
|
883
|
+
momentInfo.videoUrl = fileUrl;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
break;
|
|
887
|
+
}
|
|
888
|
+
case PUPPET.types.Sayable.Url: {
|
|
889
|
+
momentInfo.urlLink = item.payload;
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
case PUPPET.types.Sayable.Channel: {
|
|
893
|
+
momentInfo.channel = item.payload;
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
case PUPPET.types.Sayable.MiniProgram: {
|
|
897
|
+
momentInfo.miniInfo = item.payload;
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
default:
|
|
901
|
+
throw new Error(`postPublish unsupported type ${item.type}`);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
if (payload.rootId)
|
|
905
|
+
momentInfo.rootId = payload.rootId;
|
|
906
|
+
if (payload.parentId)
|
|
907
|
+
momentInfo.parentId = payload.parentId;
|
|
908
|
+
if (payload.location)
|
|
909
|
+
momentInfo.location = payload.location;
|
|
910
|
+
momentInfo.visibleList = payload.visibleList;
|
|
911
|
+
const res = await this._client?.sendSnsMoment(this._self?.wxid || '', momentInfo);
|
|
912
|
+
return res;
|
|
913
|
+
}
|
|
914
|
+
async postUnpublish(id) {
|
|
915
|
+
log.verbose(PRE, 'postUnpublish(%s)', id);
|
|
916
|
+
await this._client?.unSendMoment(id);
|
|
917
|
+
}
|
|
918
|
+
async postRawPayload(id) {
|
|
919
|
+
log.verbose(PRE, 'postRawPayload(%s)', id);
|
|
920
|
+
return id;
|
|
921
|
+
}
|
|
922
|
+
async postPayloadSayable(postId, sayableId) {
|
|
923
|
+
log.verbose(PRE, 'postPayloadSayable(%s, %s)', postId, sayableId);
|
|
924
|
+
return postId;
|
|
925
|
+
}
|
|
926
|
+
async postRawPayloadParser(payload) {
|
|
927
|
+
return payload;
|
|
928
|
+
}
|
|
929
|
+
async tap(postId, type, tap = true) {
|
|
930
|
+
log.verbose(PRE, 'tap(%s, %s, %s)', postId, type, tap);
|
|
931
|
+
const res = await this._client?.sendMomentLike(postId, type);
|
|
932
|
+
return !!res;
|
|
933
|
+
}
|
|
840
934
|
async syncRoom() {
|
|
841
935
|
if (this.state.active() !== true) {
|
|
842
936
|
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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FileBoxType, } from 'file-box';
|
|
2
|
+
const PASS_THROUGH_THRESHOLD_BYTES = 20 * 1024;
|
|
3
|
+
const greenFileBoxTypes = [
|
|
4
|
+
FileBoxType.Url,
|
|
5
|
+
FileBoxType.Uuid,
|
|
6
|
+
FileBoxType.QRCode,
|
|
7
|
+
];
|
|
8
|
+
const yellowFileBoxTypes = [];
|
|
9
|
+
const canPassthrough = (fileBox) => {
|
|
10
|
+
if (greenFileBoxTypes.includes(fileBox.type)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (!yellowFileBoxTypes.includes(fileBox.type)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const size = fileBox.size;
|
|
17
|
+
if (size < 0) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
else if (size > PASS_THROUGH_THRESHOLD_BYTES) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const normalizeFileBoxUuid = (FileBoxUuid) => async (fileBox) => {
|
|
28
|
+
if (canPassthrough(fileBox)) {
|
|
29
|
+
return fileBox;
|
|
30
|
+
}
|
|
31
|
+
const stream = await fileBox.toStream();
|
|
32
|
+
const uuid = await FileBoxUuid
|
|
33
|
+
.fromStream(stream, fileBox.name)
|
|
34
|
+
.toUuid();
|
|
35
|
+
const uuidFileBox = FileBoxUuid.fromUuid(uuid, {
|
|
36
|
+
md5: fileBox.md5,
|
|
37
|
+
name: fileBox.name,
|
|
38
|
+
size: fileBox.size,
|
|
39
|
+
});
|
|
40
|
+
return uuidFileBox;
|
|
41
|
+
};
|
|
42
|
+
export { canPassthrough, normalizeFileBoxUuid, };
|