@pontalabs/baileys 1.1.1 → 1.1.2
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/lib/Socket/messages-send.js +24 -64
- package/lib/Socket/newsletter.js +97 -2
- package/lib/Types/Newsletter.js +2 -0
- package/lib/Utils/messages.js +10 -523
- package/lib/Utils/rich-message-utils.js +1 -1
- package/lib/index.js +10 -52
- package/package.json +1 -1
|
@@ -222,40 +222,14 @@ const makeMessagesSocket = (config) => {
|
|
|
222
222
|
if (!toFetch.length) {
|
|
223
223
|
return deviceResults;
|
|
224
224
|
}
|
|
225
|
-
const requestedLidUsers = new Set();
|
|
226
|
-
for (const jid of toFetch) {
|
|
227
|
-
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
|
228
|
-
const user = jidDecode(jid)?.user;
|
|
229
|
-
if (user) requestedLidUsers.add(user);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
225
|
const query = new USyncQuery()
|
|
233
226
|
.withContext("message")
|
|
234
|
-
.withDeviceProtocol()
|
|
235
|
-
.withLIDProtocol();
|
|
227
|
+
.withDeviceProtocol();
|
|
236
228
|
for (const jid of toFetch) {
|
|
237
229
|
query.withUser(new USyncUser().withId(jid));
|
|
238
230
|
}
|
|
239
231
|
const result = await executeUSyncQuery(query);
|
|
240
232
|
if (result) {
|
|
241
|
-
const lidResults = result.list.filter((a) => !!a.lid);
|
|
242
|
-
if (lidResults.length > 0) {
|
|
243
|
-
logger.trace("Storing LID maps from device call");
|
|
244
|
-
await signalRepository.lidMapping.storeLIDPNMappings(
|
|
245
|
-
lidResults.map((a) => ({ lid: a.lid, pn: a.id }))
|
|
246
|
-
);
|
|
247
|
-
try {
|
|
248
|
-
const lids = lidResults.map((a) => a.lid);
|
|
249
|
-
if (lids.length) {
|
|
250
|
-
await assertSessions(lids, true);
|
|
251
|
-
}
|
|
252
|
-
} catch (e) {
|
|
253
|
-
logger.warn(
|
|
254
|
-
{ e: e, count: lidResults.length },
|
|
255
|
-
"failed to assert sessions for newly mapped LIDs"
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
233
|
const extracted = extractDeviceJids(
|
|
260
234
|
result?.list,
|
|
261
235
|
authState.creds.me.id,
|
|
@@ -268,20 +242,16 @@ const makeMessagesSocket = (config) => {
|
|
|
268
242
|
deviceMap[item.user]?.push(item);
|
|
269
243
|
}
|
|
270
244
|
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
271
|
-
const isLidUser = requestedLidUsers.has(user);
|
|
272
245
|
for (const item of userDevices) {
|
|
273
|
-
const finalJid =
|
|
274
|
-
? jidEncode(user, item.server, item.device)
|
|
275
|
-
: jidEncode(item.user, item.server, item.device);
|
|
246
|
+
const finalJid = jidEncode(item.user, item.server, item.device);
|
|
276
247
|
deviceResults.push({ ...item, jid: finalJid });
|
|
277
248
|
logger.debug(
|
|
278
249
|
{
|
|
279
250
|
user: item.user,
|
|
280
251
|
device: item.device,
|
|
281
252
|
finalJid: finalJid,
|
|
282
|
-
usedLid: isLidUser,
|
|
283
253
|
},
|
|
284
|
-
"Processed device
|
|
254
|
+
"Processed device"
|
|
285
255
|
);
|
|
286
256
|
}
|
|
287
257
|
}
|
|
@@ -362,18 +332,7 @@ const makeMessagesSocket = (config) => {
|
|
|
362
332
|
jidsRequiringFetch.push(jid);
|
|
363
333
|
}
|
|
364
334
|
if (jidsRequiringFetch.length) {
|
|
365
|
-
|
|
366
|
-
...jidsRequiringFetch.filter((jid) => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
367
|
-
...(
|
|
368
|
-
(await signalRepository.lidMapping.getLIDsForPNs(
|
|
369
|
-
jidsRequiringFetch.filter((jid) => !!isPnUser(jid) || !!isHostedPnUser(jid))
|
|
370
|
-
)) || []
|
|
371
|
-
).map((a) => a.lid),
|
|
372
|
-
];
|
|
373
|
-
logger.debug(
|
|
374
|
-
{ jidsRequiringFetch: jidsRequiringFetch, wireJids: wireJids },
|
|
375
|
-
"fetching sessions"
|
|
376
|
-
);
|
|
335
|
+
logger.debug({ jidsRequiringFetch: jidsRequiringFetch }, "fetching sessions");
|
|
377
336
|
const result = await query({
|
|
378
337
|
tag: "iq",
|
|
379
338
|
attrs: { xmlns: "encrypt", type: "get", to: S_WHATSAPP_NET },
|
|
@@ -381,7 +340,7 @@ const makeMessagesSocket = (config) => {
|
|
|
381
340
|
{
|
|
382
341
|
tag: "key",
|
|
383
342
|
attrs: {},
|
|
384
|
-
content:
|
|
343
|
+
content: jidsRequiringFetch.map((jid) => {
|
|
385
344
|
const attrs = { jid: jid };
|
|
386
345
|
if (force) attrs.reason = "identity";
|
|
387
346
|
return { tag: "user", attrs: attrs };
|
|
@@ -391,8 +350,8 @@ const makeMessagesSocket = (config) => {
|
|
|
391
350
|
});
|
|
392
351
|
await parseAndInjectE2ESessions(result, signalRepository);
|
|
393
352
|
didFetchNewSession = true;
|
|
394
|
-
for (const
|
|
395
|
-
const signalId = signalRepository.jidToSignalProtocolAddress(
|
|
353
|
+
for (const jid of jidsRequiringFetch) {
|
|
354
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(jid);
|
|
396
355
|
peerSessionsCache.set(signalId, true);
|
|
397
356
|
}
|
|
398
357
|
}
|
|
@@ -1363,7 +1322,6 @@ for (const { user, jid } of devices) {
|
|
|
1363
1322
|
}
|
|
1364
1323
|
return msg;
|
|
1365
1324
|
},
|
|
1366
|
-
// --- tambahan dari 1.0.11: kirim album (banyak media digabung 1 pesan) ---
|
|
1367
1325
|
sendAlbumMessage: async (jid, medias, options = {}) => {
|
|
1368
1326
|
const userJid = authState.creds.me.id;
|
|
1369
1327
|
for (const media of medias) {
|
|
@@ -1374,17 +1332,18 @@ for (const { user, jid } of devices) {
|
|
|
1374
1332
|
delete options.delay;
|
|
1375
1333
|
const album = await generateWAMessageFromContent(jid, {
|
|
1376
1334
|
albumMessage: {
|
|
1377
|
-
expectedImageCount: medias.filter(media => media.image).length,
|
|
1378
|
-
expectedVideoCount: medias.filter(media => media.video).length,
|
|
1379
|
-
...options
|
|
1380
|
-
}
|
|
1335
|
+
expectedImageCount: medias.filter((media) => media.image).length,
|
|
1336
|
+
expectedVideoCount: medias.filter((media) => media.video).length,
|
|
1337
|
+
...options,
|
|
1338
|
+
},
|
|
1381
1339
|
}, {
|
|
1382
1340
|
userJid,
|
|
1383
|
-
...options
|
|
1341
|
+
...options,
|
|
1384
1342
|
});
|
|
1385
1343
|
await relayMessage(jid, album.message, {
|
|
1386
|
-
messageId: album.key.id
|
|
1344
|
+
messageId: album.key.id,
|
|
1387
1345
|
});
|
|
1346
|
+
let mediaHandle;
|
|
1388
1347
|
let msg;
|
|
1389
1348
|
for (const i in medias) {
|
|
1390
1349
|
const media = medias[i];
|
|
@@ -1392,30 +1351,32 @@ for (const { user, jid } of devices) {
|
|
|
1392
1351
|
msg = await generateWAMessage(jid, {
|
|
1393
1352
|
image: media.image,
|
|
1394
1353
|
...media,
|
|
1395
|
-
...options
|
|
1354
|
+
...options,
|
|
1396
1355
|
}, {
|
|
1397
1356
|
userJid,
|
|
1398
1357
|
upload: async (readStream, opts) => {
|
|
1399
1358
|
const up = await waUploadToServer(readStream, {
|
|
1400
1359
|
...opts,
|
|
1401
|
-
newsletter: isJidNewsletter(jid)
|
|
1360
|
+
newsletter: isJidNewsletter(jid),
|
|
1402
1361
|
});
|
|
1362
|
+
mediaHandle = up.handle;
|
|
1403
1363
|
return up;
|
|
1404
1364
|
},
|
|
1405
|
-
...options
|
|
1365
|
+
...options,
|
|
1406
1366
|
});
|
|
1407
1367
|
} else if (media.video) {
|
|
1408
1368
|
msg = await generateWAMessage(jid, {
|
|
1409
1369
|
video: media.video,
|
|
1410
1370
|
...media,
|
|
1411
|
-
...options
|
|
1371
|
+
...options,
|
|
1412
1372
|
}, {
|
|
1413
1373
|
userJid,
|
|
1414
1374
|
upload: async (readStream, opts) => {
|
|
1415
1375
|
const up = await waUploadToServer(readStream, {
|
|
1416
1376
|
...opts,
|
|
1417
|
-
newsletter: isJidNewsletter(jid)
|
|
1377
|
+
newsletter: isJidNewsletter(jid),
|
|
1418
1378
|
});
|
|
1379
|
+
mediaHandle = up.handle;
|
|
1419
1380
|
return up;
|
|
1420
1381
|
},
|
|
1421
1382
|
...options,
|
|
@@ -1426,18 +1387,17 @@ for (const { user, jid } of devices) {
|
|
|
1426
1387
|
messageSecret: randomBytes(32),
|
|
1427
1388
|
messageAssociation: {
|
|
1428
1389
|
associationType: 1,
|
|
1429
|
-
parentMessageKey: album.key
|
|
1430
|
-
}
|
|
1390
|
+
parentMessageKey: album.key,
|
|
1391
|
+
},
|
|
1431
1392
|
};
|
|
1432
1393
|
}
|
|
1433
1394
|
await relayMessage(jid, msg.message, {
|
|
1434
|
-
messageId: msg.key.id
|
|
1395
|
+
messageId: msg.key.id,
|
|
1435
1396
|
});
|
|
1436
1397
|
await delay(time);
|
|
1437
1398
|
}
|
|
1438
1399
|
return album;
|
|
1439
1400
|
},
|
|
1440
|
-
// --- akhir tambahan ---
|
|
1441
1401
|
sendMessage: async (jid, content, options = {}) => {
|
|
1442
1402
|
const userJid = authState.creds.me.id;
|
|
1443
1403
|
const additionalAttributes = {};
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
|
|
4
4
|
const { QueryIds, XWAPaths } = require("../Types");
|
|
5
5
|
const { generateProfilePicture } = require("../Utils");
|
|
6
|
-
const { getBinaryNodeChild } = require("../WABinary");
|
|
6
|
+
const { getBinaryNodeChild, getBinaryNodeChildren, getAllBinaryNodeChildren, isJidNewsletter } = require("../WABinary");
|
|
7
|
+
const { decryptMessageNode } = require("../Utils/decode-wa-message");
|
|
7
8
|
const { makeGroupsSocket } = require("./groups");
|
|
8
9
|
const { executeWMexQuery: genericExecuteWMexQuery } = require("./mex");
|
|
9
10
|
|
|
@@ -44,11 +45,55 @@ const parseNewsletterMetadata = (result) => {
|
|
|
44
45
|
|
|
45
46
|
const makeNewsletterSocket = (config) => {
|
|
46
47
|
const conn = makeGroupsSocket(config);
|
|
47
|
-
const { query, generateMessageTag } = conn;
|
|
48
|
+
const { query, generateMessageTag, authState, signalRepository } = conn;
|
|
48
49
|
|
|
49
50
|
const executeWMexQuery = (variables, queryId, dataPath) =>
|
|
50
51
|
genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
51
52
|
|
|
53
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
54
|
+
let child;
|
|
55
|
+
if (type === "messages") {
|
|
56
|
+
child = getBinaryNodeChild(node, "messages");
|
|
57
|
+
} else {
|
|
58
|
+
const parent = getBinaryNodeChild(node, "message_updates");
|
|
59
|
+
child = getBinaryNodeChild(parent, "messages");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return Promise.all(
|
|
63
|
+
getAllBinaryNodeChildren(child).map(async (messageNode) => {
|
|
64
|
+
messageNode.attrs.from = child?.attrs.jid;
|
|
65
|
+
|
|
66
|
+
const views = parseInt(
|
|
67
|
+
getBinaryNodeChild(messageNode, "views_count")?.attrs?.count || "0"
|
|
68
|
+
);
|
|
69
|
+
const reactionNode = getBinaryNodeChild(messageNode, "reactions");
|
|
70
|
+
const reactions = getBinaryNodeChildren(reactionNode, "reaction").map(
|
|
71
|
+
({ attrs }) => ({ count: +attrs.count, code: attrs.code })
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const data = {
|
|
75
|
+
server_id: messageNode.attrs.server_id,
|
|
76
|
+
views,
|
|
77
|
+
reactions,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (type === "messages") {
|
|
81
|
+
const { fullMessage: message, decrypt } = decryptMessageNode(
|
|
82
|
+
messageNode,
|
|
83
|
+
authState.creds.me.id,
|
|
84
|
+
authState.creds.me.lid || "",
|
|
85
|
+
signalRepository,
|
|
86
|
+
config.logger
|
|
87
|
+
);
|
|
88
|
+
await decrypt();
|
|
89
|
+
data.message = message;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return data;
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
52
97
|
const newsletterUpdate = async (jid, updates) => {
|
|
53
98
|
return executeWMexQuery(
|
|
54
99
|
{
|
|
@@ -208,6 +253,56 @@ const makeNewsletterSocket = (config) => {
|
|
|
208
253
|
newsletterDelete: async (jid) => {
|
|
209
254
|
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.DELETE_V2);
|
|
210
255
|
},
|
|
256
|
+
|
|
257
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
258
|
+
await executeWMexQuery(
|
|
259
|
+
{
|
|
260
|
+
newsletter_id: jid,
|
|
261
|
+
updates: { settings: { reaction_codes: { value: mode } } },
|
|
262
|
+
},
|
|
263
|
+
QueryIds.UPDATE_METADATA,
|
|
264
|
+
XWAPaths.UPDATE
|
|
265
|
+
);
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
newsletterFetchAllParticipating: async () => {
|
|
269
|
+
const data = {};
|
|
270
|
+
|
|
271
|
+
const newsletters = await executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.SUBSCRIBED);
|
|
272
|
+
|
|
273
|
+
for (const i of newsletters) {
|
|
274
|
+
if (!isJidNewsletter(i.id)) continue;
|
|
275
|
+
|
|
276
|
+
const metadata = await self.newsletterMetadata("JID", i.id);
|
|
277
|
+
data[metadata.id] = metadata;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return data;
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
284
|
+
const result = await query({
|
|
285
|
+
tag: "iq",
|
|
286
|
+
attrs: {
|
|
287
|
+
id: generateMessageTag(),
|
|
288
|
+
type: "get",
|
|
289
|
+
xmlns: "newsletter",
|
|
290
|
+
to: jid,
|
|
291
|
+
},
|
|
292
|
+
content: [
|
|
293
|
+
{
|
|
294
|
+
tag: "message_updates",
|
|
295
|
+
attrs: {
|
|
296
|
+
count: count.toString(),
|
|
297
|
+
after: after?.toString() || "100",
|
|
298
|
+
since: since?.toString() || "0",
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
return parseFetchedUpdates(result, "updates");
|
|
305
|
+
},
|
|
211
306
|
};
|
|
212
307
|
|
|
213
308
|
return self;
|
package/lib/Types/Newsletter.js
CHANGED
|
@@ -14,6 +14,7 @@ const XWAPaths = {
|
|
|
14
14
|
CHANGE_OWNER: "xwa2_newsletter_change_owner",
|
|
15
15
|
DEMOTE: "xwa2_newsletter_demote",
|
|
16
16
|
DELETE_V2: "xwa2_newsletter_delete_v2",
|
|
17
|
+
SUBSCRIBED: "xwa2_newsletter_subscribed",
|
|
17
18
|
};
|
|
18
19
|
const QueryIds = {
|
|
19
20
|
CREATE: "8823471724422422",
|
|
@@ -28,5 +29,6 @@ const QueryIds = {
|
|
|
28
29
|
CHANGE_OWNER: "7341777602580933",
|
|
29
30
|
DEMOTE: "6551828931592903",
|
|
30
31
|
DELETE: "30062808666639665",
|
|
32
|
+
SUBSCRIBED: "6388546374527196",
|
|
31
33
|
};
|
|
32
34
|
module.exports = { XWAPaths: XWAPaths, QueryIds: QueryIds };
|
package/lib/Utils/messages.js
CHANGED
|
@@ -16,48 +16,6 @@ const generics_1 = require("./generics")
|
|
|
16
16
|
const messages_media_1 = require("./messages-media")
|
|
17
17
|
const rich_message_utils_1 = require("./rich-message-utils")
|
|
18
18
|
|
|
19
|
-
// --- shim kompatibilitas tambahan dari @pontalabs 1.1.9 (untuk richMessage/buttonsMessage) ---
|
|
20
|
-
const Jimp = require("jimp")
|
|
21
|
-
const { proto } = WAProto_1
|
|
22
|
-
const { getStream, toBuffer } = messages_media_1
|
|
23
|
-
const { promises } = fs_1
|
|
24
|
-
const hasNonNullishProperty = (message, key) =>
|
|
25
|
-
typeof message === "object" &&
|
|
26
|
-
message !== null &&
|
|
27
|
-
key in message &&
|
|
28
|
-
message[key] !== null &&
|
|
29
|
-
message[key] !== undefined
|
|
30
|
-
async function processLocationThumbnail(input, options = {}) {
|
|
31
|
-
const {
|
|
32
|
-
maxWidth = 300,
|
|
33
|
-
maxHeight = 300,
|
|
34
|
-
quality = 80
|
|
35
|
-
} = options
|
|
36
|
-
|
|
37
|
-
let buffer
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
typeof input === "string" &&
|
|
41
|
-
(input.startsWith("http://") || input.startsWith("https://"))
|
|
42
|
-
) {
|
|
43
|
-
const { stream } = await getStream({ url: input })
|
|
44
|
-
buffer = await toBuffer(stream)
|
|
45
|
-
} else if (typeof input === "string") {
|
|
46
|
-
buffer = await promises.readFile(input)
|
|
47
|
-
} else if (Buffer.isBuffer(input)) {
|
|
48
|
-
buffer = input
|
|
49
|
-
} else {
|
|
50
|
-
throw new Error("thumbnail must be URL, path or Buffer")
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const image = await Jimp.read(buffer)
|
|
54
|
-
|
|
55
|
-
image.scaleToFit(maxWidth, maxHeight)
|
|
56
|
-
|
|
57
|
-
return await image.quality(quality).getBufferAsync(Jimp.MIME_JPEG)
|
|
58
|
-
}
|
|
59
|
-
// --- akhir shim ---
|
|
60
|
-
|
|
61
19
|
const MIMETYPE_MAP = {
|
|
62
20
|
image: 'image/jpeg',
|
|
63
21
|
video: 'video/mp4',
|
|
@@ -332,7 +290,7 @@ const prepareAlbumMessageContent = async (jid, albums, options) => {
|
|
|
332
290
|
}
|
|
333
291
|
}, options)
|
|
334
292
|
|
|
335
|
-
await options.
|
|
293
|
+
await options.conn.relayMessage(jid, albumMsg.message, {
|
|
336
294
|
messageId: albumMsg.key.id
|
|
337
295
|
})
|
|
338
296
|
|
|
@@ -347,7 +305,7 @@ const prepareAlbumMessageContent = async (jid, albums, options) => {
|
|
|
347
305
|
}, {
|
|
348
306
|
userJid: options.userJid,
|
|
349
307
|
upload: async (encFilePath, opts) => {
|
|
350
|
-
const up = await options.
|
|
308
|
+
const up = await options.conn.waUploadToServer(encFilePath, {
|
|
351
309
|
...opts,
|
|
352
310
|
newsletter: WABinary_1.isJidNewsletter(jid)
|
|
353
311
|
})
|
|
@@ -364,7 +322,7 @@ const prepareAlbumMessageContent = async (jid, albums, options) => {
|
|
|
364
322
|
}, {
|
|
365
323
|
userJid: options.userJid,
|
|
366
324
|
upload: async (encFilePath, opts) => {
|
|
367
|
-
const up = await options.
|
|
325
|
+
const up = await options.conn.waUploadToServer(encFilePath, {
|
|
368
326
|
...opts,
|
|
369
327
|
newsletter: WABinary_1.isJidNewsletter(jid)
|
|
370
328
|
})
|
|
@@ -763,8 +721,12 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
763
721
|
const os = message.orderStatus
|
|
764
722
|
if (!os.image) throw new Error('orderStatus requires image')
|
|
765
723
|
let imageInput = os.image
|
|
766
|
-
if (typeof imageInput === 'string'
|
|
767
|
-
imageInput
|
|
724
|
+
if (typeof imageInput === 'string') {
|
|
725
|
+
if (imageInput.startsWith('http://') || imageInput.startsWith('https://')) {
|
|
726
|
+
imageInput = { url: imageInput }
|
|
727
|
+
} else {
|
|
728
|
+
imageInput = await fs_1.promises.readFile(imageInput)
|
|
729
|
+
}
|
|
768
730
|
}
|
|
769
731
|
const media = await prepareWAMessageMedia({ image: imageInput }, { upload: options.upload, ...options })
|
|
770
732
|
m = {
|
|
@@ -1476,450 +1438,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
1476
1438
|
m = {
|
|
1477
1439
|
interactiveMessage
|
|
1478
1440
|
}
|
|
1479
|
-
} else if (hasNonNullishProperty(message, "buttonsMessage")) {
|
|
1480
|
-
const btnMsg = { ...message.buttonsMessage };
|
|
1481
|
-
if (btnMsg.locationMessage?.jpegThumbnail && !Buffer.isBuffer(btnMsg.locationMessage.jpegThumbnail)) {
|
|
1482
|
-
btnMsg.locationMessage.jpegThumbnail = await processLocationThumbnail(btnMsg.locationMessage.jpegThumbnail);
|
|
1483
|
-
}
|
|
1484
|
-
m = { buttonsMessage: btnMsg };
|
|
1485
|
-
} else if (hasNonNullishProperty(message, "richMessage")) {
|
|
1486
|
-
const { randomUUID } = require('crypto');
|
|
1487
|
-
const rich = message.richMessage;
|
|
1488
|
-
const submessages = [];
|
|
1489
|
-
const sections = [];
|
|
1490
|
-
const richResponseSources = [];
|
|
1491
|
-
|
|
1492
|
-
const extractIE = (text) => {
|
|
1493
|
-
let ie = [], result = '', last = 0, citation_index = 1, hyperlink_index = 0, latex_index = 0, stack = [];
|
|
1494
|
-
for (let i = 0; i < text.length; i++) {
|
|
1495
|
-
if (text[i] == '[' && text[i - 1] != '\\') {
|
|
1496
|
-
stack.push(i);
|
|
1497
|
-
} else if (text[i] == ']' && (text[i + 1] == '(' || text[i + 1] == '<')) {
|
|
1498
|
-
let start = stack.pop();
|
|
1499
|
-
if (start == null) continue;
|
|
1500
|
-
let open = text[i + 1], close = open == '(' ? ')' : '>', type = open == '(' ? 'link' : 'latex', end = i + 2, depth = 1;
|
|
1501
|
-
while (end < text.length && depth) {
|
|
1502
|
-
if (text[end] == open && text[end - 1] != '\\') depth++;
|
|
1503
|
-
else if (text[end] == close && text[end - 1] != '\\') depth--;
|
|
1504
|
-
end++;
|
|
1505
|
-
}
|
|
1506
|
-
if (depth) continue;
|
|
1507
|
-
let raw = text.slice(start + 1, i).trim(), url = text.slice(i + 2, end - 1).trim(), key, tag, data;
|
|
1508
|
-
if (type == 'latex') {
|
|
1509
|
-
let [txt = '', width = null, height = null, font_height = null, padding = null] = raw.split('|');
|
|
1510
|
-
key = `LATEX_${latex_index++}`;
|
|
1511
|
-
tag = `{{${key}}}${txt || 'image'}{{/${key}}}`;
|
|
1512
|
-
data = { type: 'latex', ie: { key, text: txt, url, width, height, font_height, padding } };
|
|
1513
|
-
} else if (raw) {
|
|
1514
|
-
key = `HLINK_${hyperlink_index++}`;
|
|
1515
|
-
tag = `{{${key}}}${url}{{/${key}}}`;
|
|
1516
|
-
data = { type: 'hyperlink', ie: { key, text: raw, url } };
|
|
1517
|
-
} else {
|
|
1518
|
-
key = `CITE_${citation_index - 1}`;
|
|
1519
|
-
tag = `{{${key}}}${url}{{/${key}}}`;
|
|
1520
|
-
data = { type: 'citation', ie: { reference_id: citation_index++, key, text: '', url } };
|
|
1521
|
-
}
|
|
1522
|
-
result += text.slice(last, start) + tag;
|
|
1523
|
-
last = end;
|
|
1524
|
-
ie.push(data);
|
|
1525
|
-
i = end - 1;
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
result += text.slice(last);
|
|
1529
|
-
return { text: result, ie };
|
|
1530
|
-
};
|
|
1531
|
-
|
|
1532
|
-
const tokenizer = (code, lang = 'javascript') => {
|
|
1533
|
-
const keywordsMap = {
|
|
1534
|
-
javascript: new Set(['break','case','catch','continue','debugger','delete','do','else','finally','for','function','if','in','instanceof','new','return','switch','this','throw','try','typeof','var','void','while','with','true','false','null','undefined','class','const','let','super','extends','export','import','yield','static','constructor','async','await','get','set'])
|
|
1535
|
-
};
|
|
1536
|
-
const TYPE_MAP = { 0:'DEFAULT', 1:'KEYWORD', 2:'METHOD', 3:'STR', 4:'NUMBER', 5:'COMMENT' };
|
|
1537
|
-
const keywords = keywordsMap[lang] || new Set();
|
|
1538
|
-
const tokens = [];
|
|
1539
|
-
let i = 0;
|
|
1540
|
-
const push = (content, type) => {
|
|
1541
|
-
if (!content) return;
|
|
1542
|
-
const last = tokens[tokens.length - 1];
|
|
1543
|
-
if (last && last.highlightType === type) last.codeContent += content;
|
|
1544
|
-
else tokens.push({ codeContent: content, highlightType: type });
|
|
1545
|
-
};
|
|
1546
|
-
while (i < code.length) {
|
|
1547
|
-
const c = code[i];
|
|
1548
|
-
if (/\s/.test(c)) { let s = i; while (i < code.length && /\s/.test(code[i])) i++; push(code.slice(s, i), 0); continue; }
|
|
1549
|
-
if (c === '/' && code[i + 1] === '/') { let s = i; i += 2; while (i < code.length && code[i] !== '\n') i++; push(code.slice(s, i), 5); continue; }
|
|
1550
|
-
if (c === '"' || c === "'" || c === '`') { let s = i; const q = c; i++; while (i < code.length) { if (code[i] === '\\' && i + 1 < code.length) i += 2; else if (code[i] === q) { i++; break; } else i++; } push(code.slice(s, i), 3); continue; }
|
|
1551
|
-
if (/[0-9]/.test(c)) { let s = i; while (i < code.length && /[0-9.]/.test(code[i])) i++; push(code.slice(s, i), 4); continue; }
|
|
1552
|
-
if (/[a-zA-Z_$]/.test(c)) { let s = i; while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) i++; const word = code.slice(s, i); let type = 0; if (keywords.has(word)) type = 1; else { let j = i; while (j < code.length && /\s/.test(code[j])) j++; if (code[j] === '(') type = 2; } push(word, type); continue; }
|
|
1553
|
-
push(c, 0); i++;
|
|
1554
|
-
}
|
|
1555
|
-
return { codeBlock: tokens, unified_codeBlock: tokens.map(t => ({ content: t.codeContent, type: TYPE_MAP[t.highlightType] })) };
|
|
1556
|
-
};
|
|
1557
|
-
|
|
1558
|
-
const toTableMetadata = (arr) => {
|
|
1559
|
-
const [header, ...rows] = arr;
|
|
1560
|
-
const maxLen = Math.max(header.length, ...rows.map(r => r.length));
|
|
1561
|
-
const normalize = (r) => [...r, ...Array(maxLen - r.length).fill('')];
|
|
1562
|
-
const unified_rows = [{ is_header: true, cells: normalize(header) }, ...rows.map(r => ({ is_header: false, cells: normalize(r) }))];
|
|
1563
|
-
const rowsMeta = unified_rows.map(r => ({ items: r.cells, ...(r.is_header ? { isHeading: true } : {}) }));
|
|
1564
|
-
return { title: '', rows: rowsMeta, unified_rows };
|
|
1565
|
-
};
|
|
1566
|
-
|
|
1567
|
-
if (rich.text) {
|
|
1568
|
-
const parsed = typeof rich.text === 'string' ? extractIE(rich.text) : rich.text;
|
|
1569
|
-
const text = parsed.text || parsed;
|
|
1570
|
-
const inline_entities = parsed.ie ? parsed.ie.map(({ type, ie }) => {
|
|
1571
|
-
if (type === 'hyperlink') return { key: ie.key, metadata: { display_name: ie.text, is_trusted: true, url: ie.url, __typename: 'GenAIInlineLinkItem' } };
|
|
1572
|
-
if (type === 'citation') return { key: ie.key, metadata: { reference_id: ie.reference_id, reference_url: ie.url, reference_title: ie.url, reference_display_name: ie.url, sources: [], __typename: 'GenAISearchCitationItem' } };
|
|
1573
|
-
if (type === 'latex') return { key: ie.key, metadata: { latex_expression: ie.text || '', latex_image: { url: ie.url, width: Number(ie.width) || 100, height: Number(ie.height) || 100 }, font_height: Number(ie.font_height) || 83.33, padding: Number(ie.padding) || 15, __typename: 'GenAILatexItem' } };
|
|
1574
|
-
return null;
|
|
1575
|
-
}).filter(Boolean) : [];
|
|
1576
|
-
submessages.push({ messageType: 2, messageText: text });
|
|
1577
|
-
sections.push({
|
|
1578
|
-
view_model: {
|
|
1579
|
-
primitive: { text, inline_entities, __typename: 'GenAIMarkdownTextUXPrimitive' },
|
|
1580
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
if (rich.code) {
|
|
1586
|
-
const { language, code } = rich.code;
|
|
1587
|
-
const tok = tokenizer(code, language);
|
|
1588
|
-
submessages.push({ messageType: 5, codeMetadata: { codeLanguage: language, codeBlocks: tok.codeBlock } });
|
|
1589
|
-
sections.push({
|
|
1590
|
-
view_model: {
|
|
1591
|
-
primitive: { language, code_blocks: tok.unified_codeBlock, __typename: 'GenAICodeUXPrimitive' },
|
|
1592
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1593
|
-
}
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
if (rich.table) {
|
|
1598
|
-
const meta = toTableMetadata(rich.table);
|
|
1599
|
-
submessages.push({ messageType: 4, tableMetadata: { title: meta.title, rows: meta.rows } });
|
|
1600
|
-
sections.push({
|
|
1601
|
-
view_model: {
|
|
1602
|
-
primitive: { rows: meta.unified_rows, __typename: 'GenATableUXPrimitive' },
|
|
1603
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1604
|
-
}
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
if (rich.images) {
|
|
1609
|
-
const urls = Array.isArray(rich.images) ? rich.images : [rich.images];
|
|
1610
|
-
submessages.push({
|
|
1611
|
-
messageType: 1,
|
|
1612
|
-
gridImageMetadata: {
|
|
1613
|
-
gridImageUrl: { imagePreviewUrl: urls[0] },
|
|
1614
|
-
imageUrls: urls.map(url => ({ imagePreviewUrl: url, imageHighResUrl: url, sourceUrl: 'https://www.levvicode.cloud/' }))
|
|
1615
|
-
}
|
|
1616
|
-
});
|
|
1617
|
-
urls.forEach(url => {
|
|
1618
|
-
sections.push({
|
|
1619
|
-
view_model: {
|
|
1620
|
-
primitive: { media: { url, mime_type: 'image/jpeg' }, imagine_type: 3, status: { status: 'READY' }, __typename: 'GenAIImaginePrimitive' },
|
|
1621
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1622
|
-
}
|
|
1623
|
-
});
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
if (rich.video) {
|
|
1628
|
-
submessages.push({ messageType: 2, messageText: '[ CANNOT_LOAD_VIDEO - Ponta ]' });
|
|
1629
|
-
sections.push({
|
|
1630
|
-
view_model: {
|
|
1631
|
-
primitive: {
|
|
1632
|
-
media: { url: rich.video, mime_type: 'video/mp4', duration: 10 },
|
|
1633
|
-
imagine_type: 'ANIMATE',
|
|
1634
|
-
status: { status: 'READY' },
|
|
1635
|
-
__typename: 'GenAIImaginePrimitive'
|
|
1636
|
-
},
|
|
1637
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1638
|
-
}
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
if (rich.productSingle) {
|
|
1643
|
-
submessages.push({ messageType: 2, messageText: '[ CANNOT_LOAD_PRODUCT - Ponta ]' });
|
|
1644
|
-
sections.push({
|
|
1645
|
-
view_model: {
|
|
1646
|
-
primitive: { ...rich.productSingle, __typename: 'GenAIProductItemCardPrimitive' },
|
|
1647
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
|
-
if (rich.productMultiple) {
|
|
1653
|
-
submessages.push({ messageType: 2, messageText: '[ CANNOT_LOAD_PRODUCT - Ponta ]' });
|
|
1654
|
-
sections.push({
|
|
1655
|
-
view_model: {
|
|
1656
|
-
primitives: rich.productMultiple.map(p => ({ ...p, __typename: 'GenAIProductItemCardPrimitive' })),
|
|
1657
|
-
__typename: 'GenAIHScrollLayoutViewModel'
|
|
1658
|
-
}
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
if (rich.product && !rich.productSingle && !rich.productMultiple) {
|
|
1663
|
-
submessages.push({ messageType: 2, messageText: '[ CANNOT_LOAD_PRODUCT - Ponta ]' });
|
|
1664
|
-
if (Array.isArray(rich.product)) {
|
|
1665
|
-
sections.push({
|
|
1666
|
-
view_model: {
|
|
1667
|
-
primitives: rich.product.map(p => ({ ...p, __typename: 'GenAIProductItemCardPrimitive' })),
|
|
1668
|
-
__typename: 'GenAIHScrollLayoutViewModel'
|
|
1669
|
-
}
|
|
1670
|
-
});
|
|
1671
|
-
} else {
|
|
1672
|
-
sections.push({
|
|
1673
|
-
view_model: {
|
|
1674
|
-
primitive: { ...rich.product, __typename: 'GenAIProductItemCardPrimitive' },
|
|
1675
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1676
|
-
}
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
if (rich.post) {
|
|
1682
|
-
submessages.push({ messageType: 2, messageText: '[ CANNOT_LOAD_POST - Ponta ]' });
|
|
1683
|
-
if (Array.isArray(rich.post)) {
|
|
1684
|
-
sections.push({
|
|
1685
|
-
view_model: {
|
|
1686
|
-
primitives: rich.post.map(p => ({ ...p, __typename: 'GenAIPostPrimitive' })),
|
|
1687
|
-
__typename: 'GenAIHScrollLayoutViewModel'
|
|
1688
|
-
}
|
|
1689
|
-
});
|
|
1690
|
-
} else {
|
|
1691
|
-
sections.push({
|
|
1692
|
-
view_model: {
|
|
1693
|
-
primitive: { ...rich.post, __typename: 'GenAIPostPrimitive' },
|
|
1694
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1695
|
-
}
|
|
1696
|
-
});
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
if (rich.reels) {
|
|
1701
|
-
const items = Array.isArray(rich.reels) ? rich.reels : [rich.reels];
|
|
1702
|
-
submessages.push({
|
|
1703
|
-
messageType: 9,
|
|
1704
|
-
contentItemsMetadata: {
|
|
1705
|
-
contentType: 1,
|
|
1706
|
-
itemsMetadata: items.map(i => ({
|
|
1707
|
-
reelItem: { title: i.title, profileIconUrl: i.profileIconUrl, thumbnailUrl: i.thumbnailUrl, videoUrl: i.videoUrl }
|
|
1708
|
-
}))
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
sections.push({
|
|
1712
|
-
view_model: {
|
|
1713
|
-
primitives: items.map(i => ({
|
|
1714
|
-
reels_url: i.videoUrl,
|
|
1715
|
-
thumbnail_url: i.thumbnailUrl,
|
|
1716
|
-
creator: i.title,
|
|
1717
|
-
avatar_url: i.profileIconUrl,
|
|
1718
|
-
reels_title: i.reels_title || '',
|
|
1719
|
-
likes_count: i.likes_count || 0,
|
|
1720
|
-
shares_count: i.shares_count || 0,
|
|
1721
|
-
view_count: i.view_count || 0,
|
|
1722
|
-
reel_source: i.reel_source || 'IG',
|
|
1723
|
-
is_verified: i.is_verified || false,
|
|
1724
|
-
__typename: 'GenAIReelPrimitive'
|
|
1725
|
-
})),
|
|
1726
|
-
__typename: 'GenAIHScrollLayoutViewModel'
|
|
1727
|
-
}
|
|
1728
|
-
});
|
|
1729
|
-
items.forEach((i, idx) => richResponseSources.push({
|
|
1730
|
-
provider: 'Ponta',
|
|
1731
|
-
thumbnailCDNURL: i.thumbnailUrl,
|
|
1732
|
-
sourceProviderURL: i.videoUrl,
|
|
1733
|
-
sourceQuery: '',
|
|
1734
|
-
faviconCDNURL: i.profileIconUrl,
|
|
1735
|
-
citationNumber: idx + 1,
|
|
1736
|
-
sourceTitle: i.title
|
|
1737
|
-
}));
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
if (rich.sources) {
|
|
1741
|
-
const sourceArr = Array.isArray(rich.sources) ? rich.sources : [rich.sources];
|
|
1742
|
-
sections.push({
|
|
1743
|
-
view_model: {
|
|
1744
|
-
primitive: {
|
|
1745
|
-
sources: sourceArr.map(s => typeof s === 'object' ? s : {
|
|
1746
|
-
source_type: 'THIRD_PARTY',
|
|
1747
|
-
source_display_name: s[2] || '',
|
|
1748
|
-
source_subtitle: 'AI',
|
|
1749
|
-
source_url: s[1] || '',
|
|
1750
|
-
favicon: { url: s[0] || '', mime_type: 'image/jpeg', width: 16, height: 16 }
|
|
1751
|
-
}),
|
|
1752
|
-
__typename: 'GenAISearchResultPrimitive'
|
|
1753
|
-
},
|
|
1754
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1755
|
-
}
|
|
1756
|
-
});
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
if (rich.tip) {
|
|
1760
|
-
submessages.push({ messageType: 2, messageText: rich.tip });
|
|
1761
|
-
sections.push({
|
|
1762
|
-
view_model: {
|
|
1763
|
-
primitive: { text: rich.tip, __typename: 'GenAIMetadataTextPrimitive' },
|
|
1764
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1765
|
-
}
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
if (rich.suggestions) {
|
|
1770
|
-
sections.push({
|
|
1771
|
-
view_model: {
|
|
1772
|
-
primitives: rich.suggestions.map(s => ({
|
|
1773
|
-
prompt_text: s,
|
|
1774
|
-
prompt_type: 'SUGGESTED_PROMPT',
|
|
1775
|
-
__typename: 'GenAIFollowUpSuggestionPillPrimitive'
|
|
1776
|
-
})),
|
|
1777
|
-
__typename: 'GenAIActionRowLayoutViewModel'
|
|
1778
|
-
}
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
if (rich.footer) {
|
|
1783
|
-
sections.push({
|
|
1784
|
-
view_model: {
|
|
1785
|
-
primitive: { text: rich.footer, __typename: 'GenAIMetadataTextPrimitive' },
|
|
1786
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
1787
|
-
}
|
|
1788
|
-
});
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
const unifiedData = { response_id: randomUUID(), sections };
|
|
1792
|
-
|
|
1793
|
-
m = {
|
|
1794
|
-
messageContextInfo: {
|
|
1795
|
-
deviceListMetadata: {},
|
|
1796
|
-
deviceListMetadataVersion: 2,
|
|
1797
|
-
botMetadata: {
|
|
1798
|
-
messageDisclaimerText: rich.title || '',
|
|
1799
|
-
richResponseSourcesMetadata: { sources: richResponseSources }
|
|
1800
|
-
}
|
|
1801
|
-
},
|
|
1802
|
-
botForwardedMessage: {
|
|
1803
|
-
message: {
|
|
1804
|
-
richResponseMessage: {
|
|
1805
|
-
messageType: 1,
|
|
1806
|
-
submessages,
|
|
1807
|
-
unifiedResponse: {
|
|
1808
|
-
data: Buffer.from(JSON.stringify(unifiedData)).toString('base64')
|
|
1809
|
-
},
|
|
1810
|
-
contextInfo: {
|
|
1811
|
-
forwardingScore: 1,
|
|
1812
|
-
isForwarded: true,
|
|
1813
|
-
forwardedAiBotMessageInfo: { botJid: '0@bot' },
|
|
1814
|
-
forwardOrigin: 4
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
};
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
else {
|
|
1825
|
-
m = await prepareWAMessageMedia(message, options);
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
if (hasNonNullishProperty(message, "buttonReply")) {
|
|
1829
|
-
switch (message.type) {
|
|
1830
|
-
case "list":
|
|
1831
|
-
m.listResponseMessage = {
|
|
1832
|
-
title: message.buttonReply.title,
|
|
1833
|
-
description: message.buttonReply.description,
|
|
1834
|
-
singleSelectReply: { selectedRowId: message.buttonReply.rowId },
|
|
1835
|
-
lisType: proto.Message.ListResponseMessage.ListType.SINGLE_SELECT,
|
|
1836
|
-
};
|
|
1837
|
-
break;
|
|
1838
|
-
case "template":
|
|
1839
|
-
m.templateButtonReplyMessage = {
|
|
1840
|
-
selectedDisplayText: message.buttonReply.displayText,
|
|
1841
|
-
selectedId: message.buttonReply.id,
|
|
1842
|
-
selectedIndex: message.buttonReply.index,
|
|
1843
|
-
};
|
|
1844
|
-
break;
|
|
1845
|
-
case "plain":
|
|
1846
|
-
m.buttonsResponseMessage = {
|
|
1847
|
-
selectedButtonId: message.buttonReply.id,
|
|
1848
|
-
selectedDisplayText: message.buttonReply.displayText,
|
|
1849
|
-
type: proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT,
|
|
1850
|
-
};
|
|
1851
|
-
break;
|
|
1852
|
-
case "interactive":
|
|
1853
|
-
m.interactiveResponseMessage = {
|
|
1854
|
-
body: {
|
|
1855
|
-
text: message.buttonReply.displayText,
|
|
1856
|
-
format: proto.Message.InteractiveResponseMessage.Body.Format.EXTENSIONS_1,
|
|
1857
|
-
},
|
|
1858
|
-
nativeFlowResponseMessage: {
|
|
1859
|
-
name: message.buttonReply.nativeFlows.name,
|
|
1860
|
-
paramsJson: message.buttonReply.nativeFlows.paramsJson,
|
|
1861
|
-
version: message.buttonReply.nativeFlows.version,
|
|
1862
|
-
},
|
|
1863
|
-
};
|
|
1864
|
-
break;
|
|
1865
|
-
}
|
|
1866
|
-
} else if (hasNonNullishProperty(message, "templateButtons")) {
|
|
1867
|
-
const hydratedTemplate = { hydratedButtons: message.templateButtons };
|
|
1868
|
-
if (hasNonNullishProperty(message, "text")) {
|
|
1869
|
-
hydratedTemplate.hydratedContentText = message.text;
|
|
1870
|
-
} else {
|
|
1871
|
-
if (hasNonNullishProperty(message, "caption")) {
|
|
1872
|
-
hydratedTemplate.hydratedContentText = message.caption;
|
|
1873
|
-
}
|
|
1874
|
-
Object.assign(msg, m);
|
|
1875
|
-
}
|
|
1876
|
-
if (hasNonNullishProperty(message, "footer")) {
|
|
1877
|
-
hydratedTemplate.hydratedFooterText = message.footer;
|
|
1878
|
-
}
|
|
1879
|
-
m = { templateMessage: { hydratedTemplate: hydratedTemplate } };
|
|
1880
|
-
} else if (hasNonNullishProperty(message, "interactiveButtons")) {
|
|
1881
|
-
const interactiveMessage = {
|
|
1882
|
-
nativeFlowMessage: { buttons: message.interactiveButtons },
|
|
1883
|
-
};
|
|
1884
|
-
if (hasNonNullishProperty(message, "text")) {
|
|
1885
|
-
interactiveMessage.body = { text: message.text };
|
|
1886
|
-
}
|
|
1887
|
-
if (hasNonNullishProperty(message, "title")) {
|
|
1888
|
-
interactiveMessage.header = {
|
|
1889
|
-
title: message.title,
|
|
1890
|
-
subtitle: null,
|
|
1891
|
-
hasMediaAttachment: false,
|
|
1892
|
-
};
|
|
1893
|
-
if (hasNonNullishProperty(message, "subtitle")) {
|
|
1894
|
-
interactiveMessage.header.subtitle = message.subtitle;
|
|
1895
|
-
}
|
|
1896
|
-
} else {
|
|
1897
|
-
if (hasNonNullishProperty(message, "caption")) {
|
|
1898
|
-
interactiveMessage.body = { text: message.caption };
|
|
1899
|
-
interactiveMessage.header = {
|
|
1900
|
-
title: null,
|
|
1901
|
-
subtitle: null,
|
|
1902
|
-
hasMediaAttachment: false,
|
|
1903
|
-
...Object.assign(interactiveMessage, m),
|
|
1904
|
-
};
|
|
1905
|
-
if (hasNonNullishProperty(message, "title")) {
|
|
1906
|
-
interactiveMessage.header.title = message.title;
|
|
1907
|
-
}
|
|
1908
|
-
if (hasNonNullishProperty(message, "subtitle")) {
|
|
1909
|
-
interactiveMessage.header.subtitle = message.subtitle;
|
|
1910
|
-
}
|
|
1911
|
-
if (hasNonNullishProperty(message, "hasMediaAttachment")) {
|
|
1912
|
-
interactiveMessage.header.hasMediaAttachment = Boolean(
|
|
1913
|
-
message.hasMediaAttachment
|
|
1914
|
-
);
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
if (hasNonNullishProperty(message, "footer")) {
|
|
1919
|
-
interactiveMessage.footer = { text: message.footer };
|
|
1920
|
-
}
|
|
1921
|
-
m = { interactiveMessage: interactiveMessage };
|
|
1922
|
-
} else if (hasNonNullishProperty(message, "shop")) {
|
|
1923
1441
|
}
|
|
1924
1442
|
|
|
1925
1443
|
if ('ephemeral' in message && !!message.ephemeral) {
|
|
@@ -2221,34 +1739,6 @@ function getAggregateVotesInPollMessage({
|
|
|
2221
1739
|
return Object.values(voteHashMap)
|
|
2222
1740
|
}
|
|
2223
1741
|
|
|
2224
|
-
// --- tambahan dari @pontalabs 1.1.9: dukungan Event RSVP response ---
|
|
2225
|
-
const updateMessageWithEventResponse = (msg, update) => {
|
|
2226
|
-
const authorID = generics_1.getKeyAuthor(update.eventResponseMessageKey)
|
|
2227
|
-
const responses = (msg.eventResponses || []).filter(
|
|
2228
|
-
(r) => generics_1.getKeyAuthor(r.eventResponseMessageKey) !== authorID
|
|
2229
|
-
)
|
|
2230
|
-
responses.push(update)
|
|
2231
|
-
msg.eventResponses = responses
|
|
2232
|
-
}
|
|
2233
|
-
function getAggregateResponsesInEventMessage({ eventResponses }, meLid) {
|
|
2234
|
-
const responseTypes = ["GOING", "NOT_GOING", "MAYBE"]
|
|
2235
|
-
const responseMap = {}
|
|
2236
|
-
for (const type of responseTypes) {
|
|
2237
|
-
responseMap[type] = { response: type, responders: [] }
|
|
2238
|
-
}
|
|
2239
|
-
for (const update of eventResponses) {
|
|
2240
|
-
const { response } = update.response || 0
|
|
2241
|
-
const responseType = proto.Message.EventResponseMessage.EventResponseType[response]
|
|
2242
|
-
if (responseType !== "UNKNOWN" && responseMap[responseType]) {
|
|
2243
|
-
responseMap[responseType].responders.push(
|
|
2244
|
-
generics_1.getKeyAuthor(update.eventResponseMessageKey, meLid)
|
|
2245
|
-
)
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
return Object.values(responseMap)
|
|
2249
|
-
}
|
|
2250
|
-
// --- akhir tambahan ---
|
|
2251
|
-
|
|
2252
1742
|
const aggregateMessageKeysNotFromMe = (keys) => {
|
|
2253
1743
|
const keyMap = {}
|
|
2254
1744
|
|
|
@@ -2381,12 +1871,9 @@ module.exports = {
|
|
|
2381
1871
|
updateMessageWithReceipt,
|
|
2382
1872
|
updateMessageWithReaction,
|
|
2383
1873
|
updateMessageWithPollUpdate,
|
|
2384
|
-
updateMessageWithEventResponse,
|
|
2385
1874
|
getAggregateVotesInPollMessage,
|
|
2386
|
-
getAggregateResponsesInEventMessage,
|
|
2387
1875
|
aggregateMessageKeysNotFromMe,
|
|
2388
1876
|
downloadMediaMessage,
|
|
2389
1877
|
assertMediaContent,
|
|
2390
|
-
patchMessageForMdIfRequired
|
|
2391
|
-
hasNonNullishProperty
|
|
1878
|
+
patchMessageForMdIfRequired
|
|
2392
1879
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* rich-message-utils.js
|
|
5
5
|
* @pontalabs-baileys
|
|
6
|
-
* Tambahkan file ini ke: node_modules/@
|
|
6
|
+
* Tambahkan file ini ke: node_modules/@pontalabs/baileys/lib/Utils/rich-message-utils.js
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true })
|
package/lib/index.js
CHANGED
|
@@ -1,60 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
{ c1: [255, 80, 120], c2: [255, 180, 210] },
|
|
5
|
-
{ c1: [140, 90, 255], c2: [90, 200, 255] },
|
|
6
|
-
{ c1: [0, 200, 255], c2: [120, 255, 220] },
|
|
7
|
-
{ c1: [255, 170, 0], c2: [255, 255, 120] }
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
const pkg = {
|
|
11
|
-
name: "Pontalabs",
|
|
12
|
-
version: "1.1.9",
|
|
13
|
-
developer: "Ponta",
|
|
14
|
-
author: "Ramacodex"
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const mottos = [
|
|
18
|
-
"Pontalabs — Fast & Reliable.",
|
|
19
|
-
"Built for WhatsApp bots.",
|
|
20
|
-
"Modern Baileys modification.",
|
|
21
|
-
"Optimized for performance.",
|
|
22
|
-
"Simple and efficient.",
|
|
23
|
-
"Reliable automation starts here.",
|
|
24
|
-
"Designed for developers.",
|
|
25
|
-
"Lightweight and powerful.",
|
|
26
|
-
"Made for better messaging.",
|
|
27
|
-
"Your trusted Baileys fork."
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const g = gradients[Math.floor(Math.random() * gradients.length)];
|
|
31
|
-
const motto = mottos[Math.floor(Math.random() * mottos.length)];
|
|
32
|
-
|
|
33
|
-
const gradient = (text) =>
|
|
34
|
-
text
|
|
35
|
-
.split("")
|
|
36
|
-
.map((ch, i, arr) => {
|
|
37
|
-
const t = i / (arr.length - 1 || 1);
|
|
38
|
-
const r = Math.round(g.c1[0] + (g.c2[0] - g.c1[0]) * t);
|
|
39
|
-
const gg = Math.round(g.c1[1] + (g.c2[1] - g.c1[1]) * t);
|
|
40
|
-
const b = Math.round(g.c1[2] + (g.c2[2] - g.c1[2]) * t);
|
|
41
|
-
return `\x1b[38;2;${r};${gg};${b}m${ch}`;
|
|
42
|
-
})
|
|
43
|
-
.join("") + "\x1b[0m";
|
|
3
|
+
const rgb = (r, g, b, text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
|
|
44
4
|
|
|
45
5
|
console.log(`
|
|
46
|
-
${
|
|
47
|
-
${
|
|
48
|
-
${gradient(` Version : ${pkg.version}`)}
|
|
49
|
-
${gradient(` Thanks To : ${pkg.author}`)}
|
|
50
|
-
${gradient(` Developer : ${pkg.developer}`)}
|
|
51
|
-
|
|
52
|
-
${gradient(` ${motto}`)}
|
|
53
|
-
${gradient("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")}
|
|
6
|
+
${rgb(0, 255, 170, "Welcome Baileys PontaLabs")}
|
|
7
|
+
${rgb(180, 180, 180, "Terimakasih telah menggunakan baileys ini.")}
|
|
54
8
|
`);
|
|
55
9
|
|
|
56
|
-
|
|
57
|
-
|
|
58
10
|
const __createBinding =
|
|
59
11
|
(this && this.__createBinding) ||
|
|
60
12
|
(Object.create
|
|
@@ -75,6 +27,7 @@ const __createBinding =
|
|
|
75
27
|
if (k2 === undefined) k2 = k;
|
|
76
28
|
o[k2] = m[k];
|
|
77
29
|
});
|
|
30
|
+
|
|
78
31
|
const __exportStar =
|
|
79
32
|
(this && this.__exportStar) ||
|
|
80
33
|
function (m, exports) {
|
|
@@ -84,8 +37,10 @@ const __exportStar =
|
|
|
84
37
|
}
|
|
85
38
|
}
|
|
86
39
|
};
|
|
40
|
+
|
|
87
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
88
42
|
exports.proto = exports.makeWASocket = null;
|
|
43
|
+
|
|
89
44
|
const { proto: proto } = require("../WAProto");
|
|
90
45
|
Object.defineProperty(exports, "proto", {
|
|
91
46
|
enumerable: true,
|
|
@@ -93,7 +48,9 @@ Object.defineProperty(exports, "proto", {
|
|
|
93
48
|
return proto;
|
|
94
49
|
},
|
|
95
50
|
});
|
|
51
|
+
|
|
96
52
|
const { default: socket } = require("./Socket");
|
|
53
|
+
|
|
97
54
|
exports.makeWASocket = socket;
|
|
98
55
|
__exportStar(require("../WAProto"), exports);
|
|
99
56
|
__exportStar(require("./Utils"), exports);
|
|
@@ -103,4 +60,5 @@ __exportStar(require("./Defaults"), exports);
|
|
|
103
60
|
__exportStar(require("./WABinary"), exports);
|
|
104
61
|
__exportStar(require("./WAM"), exports);
|
|
105
62
|
__exportStar(require("./WAUSync"), exports);
|
|
106
|
-
|
|
63
|
+
|
|
64
|
+
exports.default = socket;
|