angularsockets 1.0.3 → 1.4.0
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/LICENSE +21 -0
- package/README.MD +170 -0
- package/README.md +1 -1900
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +4798 -124
- package/WAProto/index.js +14270 -302
- package/WAProto/index.ts.ts +53473 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -6
- package/lib/Defaults/index.js +4 -6
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -2
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +2 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/RHandler.d.ts +416 -0
- package/lib/Socket/RHandler.js +530 -0
- package/lib/Socket/business.d.ts +39 -37
- package/lib/Socket/chats.d.ts +36 -23
- package/lib/Socket/chats.js +74 -116
- package/lib/Socket/groups.d.ts +42 -33
- package/lib/Socket/groups.js +26 -9
- package/lib/Socket/index.d.ts +39 -39
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +111 -29
- package/lib/Socket/messages-send.d.ts +50 -53
- package/lib/Socket/messages-send.js +213 -397
- package/lib/Socket/newsletter.d.ts +25 -21
- package/lib/Socket/newsletter.js +92 -25
- package/lib/Socket/socket.d.ts +10 -11
- package/lib/Socket/socket.js +34 -23
- package/lib/Socket/usync.d.ts +11 -12
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +22 -22
- package/lib/Store/make-in-memory-store.js +21 -13
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -6
- package/lib/Types/Chat.d.ts +6 -4
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +8 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +59 -90
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +10 -7
- package/lib/Types/index.d.ts +1 -3
- package/lib/Types/index.js +1 -1
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -41
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/chat-utils.d.ts +12 -12
- package/lib/Utils/chat-utils.js +4 -19
- package/lib/Utils/crypto.d.ts +15 -15
- package/lib/Utils/crypto.js +6 -12
- package/lib/Utils/decode-wa-message.d.ts +5 -6
- package/lib/Utils/decode-wa-message.js +28 -55
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +2 -1
- package/lib/Utils/generics.d.ts +12 -11
- package/lib/Utils/generics.js +64 -38
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/logger.d.ts +10 -1
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/messages-media.d.ts +40 -29
- package/lib/Utils/messages-media.js +276 -110
- package/lib/Utils/messages.d.ts +8 -10
- package/lib/Utils/messages.js +126 -317
- package/lib/Utils/noise-handler.d.ts +10 -11
- package/lib/Utils/noise-handler.js +3 -13
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +17 -5
- package/lib/Utils/signal.js +2 -8
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +72 -242
- package/lib/Utils/validate-connection.d.ts +2 -3
- package/lib/Utils/validate-connection.js +19 -51
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +2 -2
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +5 -7
- package/lib/WABinary/generic-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.d.ts +9 -4
- package/lib/WABinary/jid-utils.js +26 -5
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +48 -4
- package/lib/index.js.bak +56 -0
- package/package.json +43 -35
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -5,34 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
|
-
const
|
|
8
|
+
const { audioToBuffer, getAudioWaveform } = require("../Utils")
|
|
9
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
11
|
+
const RexxHayanasi = require('./RHandler');
|
|
9
12
|
const WAProto_1 = require("../../WAProto");
|
|
10
13
|
const Defaults_1 = require("../Defaults");
|
|
11
|
-
const Types_1 = require("../Types");
|
|
12
14
|
const Utils_1 = require("../Utils");
|
|
15
|
+
|
|
13
16
|
const link_preview_1 = require("../Utils/link-preview");
|
|
14
17
|
const WABinary_1 = require("../WABinary");
|
|
15
18
|
const WAUSync_1 = require("../WAUSync");
|
|
16
19
|
const newsletter_1 = require("./newsletter");
|
|
17
|
-
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
18
20
|
const makeMessagesSocket = (config) => {
|
|
19
|
-
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
|
|
21
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
|
|
20
22
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
21
|
-
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings,
|
|
22
|
-
const patchMessageRequiresBeforeSending = (msg, recipientJids) => {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
if ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.listMessage) {
|
|
25
|
-
msg = JSON.parse(JSON.stringify(msg));
|
|
26
|
-
msg.deviceSentMessage.message.listMessage.listType = WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT;
|
|
27
|
-
}
|
|
28
|
-
if (msg === null || msg === void 0 ? void 0 : msg.listMessage) {
|
|
29
|
-
msg = JSON.parse(JSON.stringify(msg));
|
|
30
|
-
msg.listMessage.listType = WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT;
|
|
31
|
-
}
|
|
32
|
-
return msg;
|
|
33
|
-
};
|
|
23
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
|
|
34
24
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
35
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
25
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
36
26
|
useClones: false
|
|
37
27
|
});
|
|
38
28
|
let mediaConn;
|
|
@@ -91,7 +81,7 @@ const makeMessagesSocket = (config) => {
|
|
|
91
81
|
}
|
|
92
82
|
}
|
|
93
83
|
if (type) {
|
|
94
|
-
node.attrs.type = (0, WABinary_1.
|
|
84
|
+
node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
|
|
95
85
|
}
|
|
96
86
|
const remainingMessageIds = messageIds.slice(1);
|
|
97
87
|
if (remainingMessageIds.length) {
|
|
@@ -123,43 +113,6 @@ const makeMessagesSocket = (config) => {
|
|
|
123
113
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
124
114
|
await sendReceipts(keys, readType);
|
|
125
115
|
};
|
|
126
|
-
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
127
|
-
var _a, _b, _c, _d;
|
|
128
|
-
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
129
|
-
if ((0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
130
|
-
const node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
131
|
-
input: {
|
|
132
|
-
key: jid,
|
|
133
|
-
type: "JID",
|
|
134
|
-
'view_role': 'GUEST'
|
|
135
|
-
},
|
|
136
|
-
'fetch_viewer_metadata': true,
|
|
137
|
-
'fetch_full_image': true,
|
|
138
|
-
'fetch_creation_time': true
|
|
139
|
-
});
|
|
140
|
-
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
141
|
-
const metadataPath = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER];
|
|
142
|
-
const pictype = type === 'image' ? 'picture' : 'preview';
|
|
143
|
-
const directPath = (_c = metadataPath === null || metadataPath === void 0 ? void 0 : metadataPath.thread_metadata[pictype]) === null || _c === void 0 ? void 0 : _c.direct_path;
|
|
144
|
-
return directPath ? (0, Utils_1.getUrlFromDirectPath)(directPath) : null;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
const result = await query({
|
|
148
|
-
tag: 'iq',
|
|
149
|
-
attrs: {
|
|
150
|
-
target: jid,
|
|
151
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
152
|
-
type: 'get',
|
|
153
|
-
xmlns: 'w:profile:picture'
|
|
154
|
-
},
|
|
155
|
-
content: [
|
|
156
|
-
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
157
|
-
]
|
|
158
|
-
}, timeoutMs);
|
|
159
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
160
|
-
return (_d = child === null || child === void 0 ? void 0 : child.attrs) === null || _d === void 0 ? void 0 : _d.url;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
116
|
/** Fetch all the devices we've to send a message to */
|
|
164
117
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
165
118
|
var _a;
|
|
@@ -277,10 +230,16 @@ const makeMessagesSocket = (config) => {
|
|
|
277
230
|
};
|
|
278
231
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
279
232
|
let patched = await patchMessageBeforeSending(message, jids);
|
|
280
|
-
|
|
281
|
-
|
|
233
|
+
if (!Array.isArray(patched)) {
|
|
234
|
+
patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
|
|
235
|
+
}
|
|
282
236
|
let shouldIncludeDeviceIdentity = false;
|
|
283
|
-
const nodes = await Promise.all(
|
|
237
|
+
const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
|
|
238
|
+
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
|
|
239
|
+
if (!jid) {
|
|
240
|
+
return {};
|
|
241
|
+
}
|
|
242
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
|
|
284
243
|
const { type, ciphertext } = await signalRepository
|
|
285
244
|
.encryptMessage({ jid, data: bytes });
|
|
286
245
|
if (type === 'pkmsg') {
|
|
@@ -302,18 +261,18 @@ const makeMessagesSocket = (config) => {
|
|
|
302
261
|
return node;
|
|
303
262
|
}));
|
|
304
263
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
305
|
-
};
|
|
306
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache,
|
|
264
|
+
};
|
|
265
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
266
|
+
var _a;
|
|
307
267
|
const meId = authState.creds.me.id;
|
|
308
268
|
let shouldIncludeDeviceIdentity = false;
|
|
309
269
|
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
310
270
|
const statusJid = 'status@broadcast';
|
|
311
271
|
const isGroup = server === 'g.us';
|
|
272
|
+
const isNewsletter = server === 'newsletter';
|
|
312
273
|
const isStatus = jid === statusJid;
|
|
313
274
|
const isLid = server === 'lid';
|
|
314
|
-
|
|
315
|
-
const isNewsletter = server === 'newsletter';
|
|
316
|
-
msgId = msgId || (await config.generateMessageID() ?? (0, Utils_1.generateMessageID)());
|
|
275
|
+
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
|
317
276
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
318
277
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
319
278
|
const participants = [];
|
|
@@ -324,7 +283,8 @@ const makeMessagesSocket = (config) => {
|
|
|
324
283
|
deviceSentMessage: {
|
|
325
284
|
destinationJid,
|
|
326
285
|
message
|
|
327
|
-
}
|
|
286
|
+
},
|
|
287
|
+
messageContextInfo: message.messageContextInfo
|
|
328
288
|
};
|
|
329
289
|
const extraAttrs = {};
|
|
330
290
|
if (participant) {
|
|
@@ -338,7 +298,7 @@ const makeMessagesSocket = (config) => {
|
|
|
338
298
|
devices.push({ user, device });
|
|
339
299
|
}
|
|
340
300
|
await authState.keys.transaction(async () => {
|
|
341
|
-
var _a, _b, _c, _d, _e, _f;
|
|
301
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
342
302
|
const mediaType = getMediaType(message);
|
|
343
303
|
if (mediaType) {
|
|
344
304
|
extraAttrs['mediatype'] = mediaType;
|
|
@@ -353,7 +313,7 @@ const makeMessagesSocket = (config) => {
|
|
|
353
313
|
if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
|
|
354
314
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
355
315
|
}
|
|
356
|
-
if (!
|
|
316
|
+
else if (!isStatus) {
|
|
357
317
|
groupData = await groupMetadata(jid);
|
|
358
318
|
}
|
|
359
319
|
return groupData;
|
|
@@ -371,12 +331,21 @@ const makeMessagesSocket = (config) => {
|
|
|
371
331
|
if (isStatus && statusJidList) {
|
|
372
332
|
participantsList.push(...statusJidList);
|
|
373
333
|
}
|
|
334
|
+
if (!isStatus) {
|
|
335
|
+
additionalAttributes = {
|
|
336
|
+
...additionalAttributes,
|
|
337
|
+
// eslint-disable-next-line camelcase
|
|
338
|
+
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
|
339
|
+
};
|
|
340
|
+
}
|
|
374
341
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
375
342
|
devices.push(...additionalDevices);
|
|
376
343
|
}
|
|
377
|
-
const patched = await patchMessageBeforeSending(message
|
|
378
|
-
|
|
379
|
-
|
|
344
|
+
const patched = await patchMessageBeforeSending(message);
|
|
345
|
+
if (Array.isArray(patched)) {
|
|
346
|
+
throw new boom_1.Boom('Per-jid patching is not supported in groups');
|
|
347
|
+
}
|
|
348
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
380
349
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
381
350
|
group: destinationJid,
|
|
382
351
|
data: bytes,
|
|
@@ -385,7 +354,7 @@ const makeMessagesSocket = (config) => {
|
|
|
385
354
|
const senderKeyJids = [];
|
|
386
355
|
// ensure a connection is established with every device
|
|
387
356
|
for (const { user, device } of devices) {
|
|
388
|
-
const jid = (0, WABinary_1.jidEncode)(user,
|
|
357
|
+
const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
389
358
|
if (!senderKeyMap[jid] || !!participant) {
|
|
390
359
|
senderKeyJids.push(jid);
|
|
391
360
|
// store that this person has had the sender keys sent to them
|
|
@@ -403,7 +372,7 @@ const makeMessagesSocket = (config) => {
|
|
|
403
372
|
}
|
|
404
373
|
};
|
|
405
374
|
await assertSessions(senderKeyJids, false);
|
|
406
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg,
|
|
375
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
|
|
407
376
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
408
377
|
participants.push(...result.nodes);
|
|
409
378
|
}
|
|
@@ -416,17 +385,20 @@ const makeMessagesSocket = (config) => {
|
|
|
416
385
|
}
|
|
417
386
|
else if (isNewsletter) {
|
|
418
387
|
// Message edit
|
|
419
|
-
if ((
|
|
420
|
-
msgId = (
|
|
388
|
+
if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
|
|
389
|
+
msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
|
|
421
390
|
message = message.protocolMessage.editedMessage;
|
|
422
391
|
}
|
|
423
392
|
// Message delete
|
|
424
|
-
if (((
|
|
425
|
-
msgId = (
|
|
393
|
+
if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
394
|
+
msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
|
|
426
395
|
message = {};
|
|
427
396
|
}
|
|
428
397
|
const patched = await patchMessageBeforeSending(message, []);
|
|
429
|
-
|
|
398
|
+
if (Array.isArray(patched)) {
|
|
399
|
+
throw new boom_1.Boom('Per-jid patching is not supported in channel');
|
|
400
|
+
}
|
|
401
|
+
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
430
402
|
binaryNodeContent.push({
|
|
431
403
|
tag: 'plaintext',
|
|
432
404
|
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
@@ -434,26 +406,23 @@ const makeMessagesSocket = (config) => {
|
|
|
434
406
|
});
|
|
435
407
|
}
|
|
436
408
|
else {
|
|
437
|
-
const { user: meUser
|
|
409
|
+
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
438
410
|
if (!participant) {
|
|
439
411
|
devices.push({ user });
|
|
440
|
-
|
|
441
|
-
if (meDevice !== undefined && meDevice !== 0) {
|
|
412
|
+
if (user !== meUser) {
|
|
442
413
|
devices.push({ user: meUser });
|
|
443
414
|
}
|
|
444
|
-
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
445
415
|
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
446
416
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
447
417
|
devices.push(...additionalDevices);
|
|
448
418
|
}
|
|
449
|
-
devices.push(...additionalDevices);
|
|
450
419
|
}
|
|
451
420
|
const allJids = [];
|
|
452
421
|
const meJids = [];
|
|
453
422
|
const otherJids = [];
|
|
454
423
|
for (const { user, device } of devices) {
|
|
455
424
|
const isMe = user === meUser;
|
|
456
|
-
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((
|
|
425
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
457
426
|
if (isMe) {
|
|
458
427
|
meJids.push(jid);
|
|
459
428
|
}
|
|
@@ -464,8 +433,8 @@ const makeMessagesSocket = (config) => {
|
|
|
464
433
|
}
|
|
465
434
|
await assertSessions(allJids, false);
|
|
466
435
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
467
|
-
createParticipantNodes(meJids, meMsg,
|
|
468
|
-
createParticipantNodes(otherJids, message,
|
|
436
|
+
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
437
|
+
createParticipantNodes(otherJids, message, extraAttrs)
|
|
469
438
|
]);
|
|
470
439
|
participants.push(...meNodes);
|
|
471
440
|
participants.push(...otherNodes);
|
|
@@ -473,7 +442,7 @@ const makeMessagesSocket = (config) => {
|
|
|
473
442
|
}
|
|
474
443
|
if (participants.length) {
|
|
475
444
|
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
|
|
476
|
-
const peerNode = (
|
|
445
|
+
const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
|
|
477
446
|
if (peerNode) {
|
|
478
447
|
binaryNodeContent.push(peerNode); // push only enc
|
|
479
448
|
}
|
|
@@ -525,13 +494,14 @@ const makeMessagesSocket = (config) => {
|
|
|
525
494
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
526
495
|
stanza.content.push(...additionalNodes);
|
|
527
496
|
}
|
|
528
|
-
const
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
497
|
+
const content = (0, Utils_1.normalizeMessageContent)(message);
|
|
498
|
+
const contentType = (0, Utils_1.getContentType)(content);
|
|
499
|
+
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
|
|
500
|
+
contentType === 'buttonsMessage' ||
|
|
501
|
+
contentType === 'listMessage')) {
|
|
502
|
+
const bizNode = { tag: 'biz', attrs: {} };
|
|
503
|
+
if ((((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
|
|
504
|
+
bizNode.content = [{
|
|
535
505
|
tag: 'interactive',
|
|
536
506
|
attrs: {
|
|
537
507
|
type: 'native_flow',
|
|
@@ -539,92 +509,27 @@ const makeMessagesSocket = (config) => {
|
|
|
539
509
|
},
|
|
540
510
|
content: [{
|
|
541
511
|
tag: 'native_flow',
|
|
542
|
-
attrs: {
|
|
543
|
-
name: 'quick_reply'
|
|
544
|
-
}
|
|
512
|
+
attrs: { v: '9', name: 'mixed' }
|
|
545
513
|
}]
|
|
546
|
-
}]
|
|
547
|
-
};
|
|
548
|
-
const resultNativeNode = filterNativeNode(additionalNodes);
|
|
549
|
-
if (resultNativeNode && additionalNodes && additionalNodes.length > 0) {
|
|
550
|
-
stanza.content.push(...resultNativeNode);
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
stanza.content.push(nativeNode);
|
|
554
|
-
}
|
|
555
|
-
}/*
|
|
556
|
-
if (isPrivate) {
|
|
557
|
-
const botNode = {
|
|
558
|
-
tag: 'bot',
|
|
559
|
-
attrs: { biz_bot: '1' }
|
|
560
|
-
};
|
|
561
|
-
const resultBotNode = filterBotNode(additionalNodes);
|
|
562
|
-
if (resultBotNode && additionalNodes && additionalNodes.length > 0) {
|
|
563
|
-
stanza.content.push(...resultBotNode);
|
|
514
|
+
}];
|
|
564
515
|
}
|
|
565
|
-
else {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}*
|
|
569
|
-
if (message && message.listMessage) {
|
|
570
|
-
stanza.content.push({
|
|
571
|
-
tag: 'biz',
|
|
572
|
-
attrs: {},
|
|
573
|
-
content: [
|
|
574
|
-
{
|
|
516
|
+
else if (message === null || message === void 0 ? void 0 : message.listMessage) {
|
|
517
|
+
// list message only support in private chat
|
|
518
|
+
bizNode.content = [{
|
|
575
519
|
tag: 'list',
|
|
576
|
-
attrs:
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (buttonType) {
|
|
584
|
-
stanza.content.push({
|
|
585
|
-
tag: 'biz',
|
|
586
|
-
attrs: {},
|
|
587
|
-
content: [
|
|
588
|
-
{
|
|
589
|
-
tag: buttonType,
|
|
590
|
-
attrs: getButtonArgs(message),
|
|
591
|
-
}
|
|
592
|
-
]
|
|
593
|
-
});
|
|
594
|
-
logger.debug({ jid }, 'adding business node');
|
|
520
|
+
attrs: {
|
|
521
|
+
type: 'product_list',
|
|
522
|
+
v: '2'
|
|
523
|
+
}
|
|
524
|
+
}];
|
|
525
|
+
}
|
|
526
|
+
stanza.content.push(bizNode);
|
|
595
527
|
}
|
|
596
528
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
597
529
|
await sendNode(stanza);
|
|
598
530
|
});
|
|
599
531
|
return msgId;
|
|
600
532
|
};
|
|
601
|
-
const filterNativeNode = (nodeContent) => {
|
|
602
|
-
if (Array.isArray(nodeContent)) {
|
|
603
|
-
return nodeContent.filter((item) => {
|
|
604
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
605
|
-
if (item.tag === 'biz' && ((_a = item === null || item === void 0 ? void 0 : item.content[0]) === null || _a === void 0 ? void 0 : _a.tag) === 'interactive' && ((_c = (_b = item === null || item === void 0 ? void 0 : item.content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.type) === 'native_flow' && ((_e = (_d = item === null || item === void 0 ? void 0 : item.content[0]) === null || _d === void 0 ? void 0 : _d.content[0]) === null || _e === void 0 ? void 0 : _e.tag) === 'native_flow' && ((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.content[0]) === null || _f === void 0 ? void 0 : _f.content[0]) === null || _g === void 0 ? void 0 : _g.attrs) === null || _h === void 0 ? void 0 : _h.name) === 'quick_reply') {
|
|
606
|
-
return false;
|
|
607
|
-
}
|
|
608
|
-
return true;
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
return nodeContent;
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
const filterBotNode = (nodeContent) => {
|
|
616
|
-
if (Array.isArray(nodeContent)) {
|
|
617
|
-
return nodeContent.filter((item) => {
|
|
618
|
-
if (item.tag === 'bot' && item.attrs.biz_bot === '1') {
|
|
619
|
-
return false;
|
|
620
|
-
}
|
|
621
|
-
return true;
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
else {
|
|
625
|
-
return nodeContent;
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
533
|
const getTypeMessage = (msg) => {
|
|
629
534
|
if (msg.viewOnceMessage) {
|
|
630
535
|
return getTypeMessage(msg.viewOnceMessage.message);
|
|
@@ -701,39 +606,26 @@ const makeMessagesSocket = (config) => {
|
|
|
701
606
|
return 'url';
|
|
702
607
|
}
|
|
703
608
|
};
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
return {};
|
|
725
|
-
}
|
|
726
|
-
else if (message.listMessage) {
|
|
727
|
-
const type = message.listMessage.listType;
|
|
728
|
-
if (!type) {
|
|
729
|
-
throw new boom_1.Boom('Expected list type inside message');
|
|
730
|
-
}
|
|
731
|
-
return { v: '2', type: ListType[type].toLowerCase() };
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
return {};
|
|
735
|
-
}
|
|
736
|
-
};
|
|
609
|
+
|
|
610
|
+
const waveform = async (content, logger) => {
|
|
611
|
+
if (typeof content === 'object' && 'audio' in content) {
|
|
612
|
+
try {
|
|
613
|
+
const audioBuffer = await audioToBuffer(content.audio)
|
|
614
|
+
const wave = await getAudioWaveform(audioBuffer, logger)
|
|
615
|
+
|
|
616
|
+
if (wave) {
|
|
617
|
+
content.waveform = wave
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
console.log(`Audio buffer length: ${audioBuffer.length} bytes`)
|
|
621
|
+
} catch (err) {
|
|
622
|
+
logger?.warn
|
|
623
|
+
? logger.warn(`Gagal membuat waveform: ${err}`)
|
|
624
|
+
: console.warn(`Gagal membuat waveform: ${err}`)
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
737
629
|
const getPrivacyTokens = async (jids) => {
|
|
738
630
|
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
739
631
|
const result = await query({
|
|
@@ -760,24 +652,25 @@ const makeMessagesSocket = (config) => {
|
|
|
760
652
|
});
|
|
761
653
|
return result;
|
|
762
654
|
};
|
|
655
|
+
|
|
763
656
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
657
|
+
const rexx = new RexxHayanasi(Utils_1, waUploadToServer, relayMessage);
|
|
764
658
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
765
659
|
return {
|
|
766
660
|
...sock,
|
|
661
|
+
rexx,
|
|
767
662
|
getPrivacyTokens,
|
|
768
663
|
assertSessions,
|
|
769
664
|
relayMessage,
|
|
770
665
|
sendReceipt,
|
|
771
666
|
sendReceipts,
|
|
772
|
-
getButtonArgs,
|
|
773
667
|
readMessages,
|
|
774
668
|
refreshMediaConn,
|
|
775
|
-
getUSyncDevices,
|
|
776
|
-
sendPeerDataOperationMessage,
|
|
777
|
-
createParticipantNodes,
|
|
778
|
-
profilePictureUrl,
|
|
779
669
|
waUploadToServer,
|
|
780
670
|
fetchPrivacySettings,
|
|
671
|
+
getUSyncDevices,
|
|
672
|
+
createParticipantNodes,
|
|
673
|
+
sendPeerDataOperationMessage,
|
|
781
674
|
updateMediaMessage: async (message) => {
|
|
782
675
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
783
676
|
const mediaKey = content.mediaKey;
|
|
@@ -786,7 +679,7 @@ const makeMessagesSocket = (config) => {
|
|
|
786
679
|
let error = undefined;
|
|
787
680
|
await Promise.all([
|
|
788
681
|
sendNode(node),
|
|
789
|
-
waitForMsgMediaUpdate(async update => {
|
|
682
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
790
683
|
const result = update.find(c => c.key.id === message.key.id);
|
|
791
684
|
if (result) {
|
|
792
685
|
if (result.error) {
|
|
@@ -795,7 +688,7 @@ const makeMessagesSocket = (config) => {
|
|
|
795
688
|
else {
|
|
796
689
|
try {
|
|
797
690
|
const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
798
|
-
if (media
|
|
691
|
+
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
799
692
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
800
693
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
801
694
|
}
|
|
@@ -819,168 +712,23 @@ const makeMessagesSocket = (config) => {
|
|
|
819
712
|
]);
|
|
820
713
|
return message;
|
|
821
714
|
},
|
|
822
|
-
sendStatusMentions: async (content, jids = []) => {
|
|
823
|
-
const userJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
824
|
-
let allUsers = [];
|
|
825
|
-
for (const id of jids) {
|
|
826
|
-
const { user, server } = (0, WABinary_1.jidDecode)(id);
|
|
827
|
-
const isGroup = server === 'g.us';
|
|
828
|
-
const isPrivate = server === 's.whatsapp.net';
|
|
829
|
-
if (isGroup) {
|
|
830
|
-
let userId = await groupMetadata(id);
|
|
831
|
-
let participant = await userId.participants;
|
|
832
|
-
let users = await Promise.all(participant.map(u => (0, WABinary_1.jidNormalizedUser)(u.id)));
|
|
833
|
-
allUsers = [...allUsers, ...users];
|
|
834
|
-
}
|
|
835
|
-
else if (isPrivate) {
|
|
836
|
-
let users = await Promise.all(jids.map(id => id.replace(/\b\d{18}@.{4}\b/g, '')));
|
|
837
|
-
allUsers = [...allUsers, ...users];
|
|
838
|
-
}
|
|
839
|
-
if (!allUsers.find(user => user.includes(userJid))) {
|
|
840
|
-
allUsers.push(userJid);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
;
|
|
844
|
-
const getRandomHexColor = () => {
|
|
845
|
-
return "#" + Math.floor(Math.random() * 16777215)
|
|
846
|
-
.toString(16)
|
|
847
|
-
.padStart(6, "0");
|
|
848
|
-
};
|
|
849
|
-
let mediaHandle;
|
|
850
|
-
let msg = await (0, Utils_1.generateWAMessage)(WABinary_1.STORIES_JID, content, {
|
|
851
|
-
logger,
|
|
852
|
-
userJid,
|
|
853
|
-
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
854
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
855
|
-
fetchOpts: {
|
|
856
|
-
timeout: 3000,
|
|
857
|
-
...axiosOptions || {}
|
|
858
|
-
},
|
|
859
|
-
logger,
|
|
860
|
-
uploadImage: generateHighQualityLinkPreview
|
|
861
|
-
? waUploadToServer
|
|
862
|
-
: undefined
|
|
863
|
-
}),
|
|
864
|
-
upload: async (readStream, opts) => {
|
|
865
|
-
const up = await waUploadToServer(readStream, { ...opts });
|
|
866
|
-
mediaHandle = up.handle;
|
|
867
|
-
return up;
|
|
868
|
-
},
|
|
869
|
-
mediaCache: config.mediaCache,
|
|
870
|
-
options: config.options,
|
|
871
|
-
backgroundColor: getRandomHexColor(),
|
|
872
|
-
font: Math.floor(Math.random() * 9),
|
|
873
|
-
});
|
|
874
|
-
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
875
|
-
messageId: msg.key.id,
|
|
876
|
-
statusJidList: allUsers,
|
|
877
|
-
additionalNodes: [
|
|
878
|
-
{
|
|
879
|
-
tag: 'meta',
|
|
880
|
-
attrs: {},
|
|
881
|
-
content: [
|
|
882
|
-
{
|
|
883
|
-
tag: 'mentioned_users',
|
|
884
|
-
attrs: {},
|
|
885
|
-
content: jids.map(jid => ({
|
|
886
|
-
tag: 'to',
|
|
887
|
-
attrs: { jid },
|
|
888
|
-
content: undefined,
|
|
889
|
-
})),
|
|
890
|
-
},
|
|
891
|
-
],
|
|
892
|
-
},
|
|
893
|
-
],
|
|
894
|
-
});
|
|
895
|
-
jids.forEach(async (id) => {
|
|
896
|
-
id = (0, WABinary_1.jidNormalizedUser)(id);
|
|
897
|
-
const { user, server } = (0, WABinary_1.jidDecode)(id);
|
|
898
|
-
const isPrivate = server === 's.whatsapp.net';
|
|
899
|
-
let type = isPrivate
|
|
900
|
-
? 'statusMentionMessage'
|
|
901
|
-
: 'groupStatusMentionMessage';
|
|
902
|
-
await relayMessage(id, {
|
|
903
|
-
[type]: {
|
|
904
|
-
message: {
|
|
905
|
-
protocolMessage: {
|
|
906
|
-
key: msg.key,
|
|
907
|
-
type: 25,
|
|
908
|
-
},
|
|
909
|
-
},
|
|
910
|
-
},
|
|
911
|
-
}, {});
|
|
912
|
-
await (0, Utils_1.delay)(2500);
|
|
913
|
-
});
|
|
914
|
-
return msg;
|
|
915
|
-
},
|
|
916
|
-
sendAlbumMessage: async (jid, medias, options = {}) => {
|
|
917
|
-
const userJid = authState.creds.me.id;
|
|
918
|
-
for (const media of medias) {
|
|
919
|
-
if (!media.image && !media.video)
|
|
920
|
-
throw new TypeError(`medias[i] must have image or video property`);
|
|
921
|
-
}
|
|
922
|
-
if (medias.length < 2)
|
|
923
|
-
throw new RangeError("Minimum 2 media");
|
|
924
|
-
const time = options.delay || 500;
|
|
925
|
-
delete options.delay;
|
|
926
|
-
const album = await (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
927
|
-
albumMessage: {
|
|
928
|
-
expectedImageCount: medias.filter(media => media.image).length,
|
|
929
|
-
expectedVideoCount: medias.filter(media => media.video).length,
|
|
930
|
-
...options
|
|
931
|
-
}
|
|
932
|
-
}, { userJid, ...options });
|
|
933
|
-
await relayMessage(jid, album.message, { messageId: album.key.id });
|
|
934
|
-
let mediaHandle;
|
|
935
|
-
let msg;
|
|
936
|
-
for (const i in medias) {
|
|
937
|
-
const media = medias[i];
|
|
938
|
-
if (media.image) {
|
|
939
|
-
msg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
940
|
-
image: media.image,
|
|
941
|
-
...media,
|
|
942
|
-
...options
|
|
943
|
-
}, {
|
|
944
|
-
userJid,
|
|
945
|
-
upload: async (readStream, opts) => {
|
|
946
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
|
947
|
-
mediaHandle = up.handle;
|
|
948
|
-
return up;
|
|
949
|
-
},
|
|
950
|
-
...options,
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
else if (media.video) {
|
|
954
|
-
msg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
955
|
-
video: media.video,
|
|
956
|
-
...media,
|
|
957
|
-
...options
|
|
958
|
-
}, {
|
|
959
|
-
userJid,
|
|
960
|
-
upload: async (readStream, opts) => {
|
|
961
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
|
962
|
-
mediaHandle = up.handle;
|
|
963
|
-
return up;
|
|
964
|
-
},
|
|
965
|
-
...options,
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
if (msg) {
|
|
969
|
-
msg.message.messageContextInfo = {
|
|
970
|
-
messageAssociation: {
|
|
971
|
-
associationType: 1,
|
|
972
|
-
parentMessageKey: album.key
|
|
973
|
-
}
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
await relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
977
|
-
await (0, Utils_1.delay)(time);
|
|
978
|
-
}
|
|
979
|
-
return album;
|
|
980
|
-
},
|
|
981
715
|
sendMessage: async (jid, content, options = {}) => {
|
|
716
|
+
await waveform(content, logger);
|
|
982
717
|
var _a, _b, _c;
|
|
983
718
|
const userJid = authState.creds.me.id;
|
|
719
|
+
if (!options.ephemeralExpiration) {
|
|
720
|
+
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
721
|
+
const groups = await sock.groupQuery(jid, 'get', [{
|
|
722
|
+
tag: 'query',
|
|
723
|
+
attrs: {
|
|
724
|
+
request: 'interactive'
|
|
725
|
+
}
|
|
726
|
+
}]);
|
|
727
|
+
const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
|
|
728
|
+
const expiration = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(metadata, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.expiration) || 0;
|
|
729
|
+
options.ephemeralExpiration = expiration;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
984
732
|
if (typeof content === 'object' &&
|
|
985
733
|
'disappearingMessagesInChat' in content &&
|
|
986
734
|
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
@@ -991,26 +739,80 @@ const makeMessagesSocket = (config) => {
|
|
|
991
739
|
disappearingMessagesInChat;
|
|
992
740
|
await groupToggleEphemeral(jid, value);
|
|
993
741
|
}
|
|
994
|
-
else {
|
|
742
|
+
else if (typeof content === 'object' && 'album' in content && content.album) {
|
|
743
|
+
const { album, caption } = content;
|
|
744
|
+
if (caption && !album[0].caption) {
|
|
745
|
+
album[0].caption = caption;
|
|
746
|
+
}
|
|
995
747
|
let mediaHandle;
|
|
996
|
-
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
const
|
|
1008
|
-
|
|
748
|
+
let mediaMsg;
|
|
749
|
+
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
750
|
+
albumMessage: {
|
|
751
|
+
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
752
|
+
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
753
|
+
}
|
|
754
|
+
}, { userJid, ...options });
|
|
755
|
+
await relayMessage(jid, albumMsg.message, {
|
|
756
|
+
messageId: albumMsg.key.id
|
|
757
|
+
});
|
|
758
|
+
for (const i in album) {
|
|
759
|
+
const media = album[i];
|
|
760
|
+
if ('image' in media) {
|
|
761
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
762
|
+
image: media.image,
|
|
763
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
764
|
+
...options
|
|
765
|
+
}, {
|
|
766
|
+
userJid,
|
|
767
|
+
upload: async (readStream, opts) => {
|
|
768
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
769
|
+
mediaHandle = up.handle;
|
|
770
|
+
return up;
|
|
771
|
+
},
|
|
772
|
+
...options,
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
else if ('video' in media) {
|
|
776
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
777
|
+
video: media.video,
|
|
778
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
779
|
+
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
780
|
+
...options
|
|
781
|
+
}, {
|
|
782
|
+
userJid,
|
|
783
|
+
upload: async (readStream, opts) => {
|
|
784
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
785
|
+
mediaHandle = up.handle;
|
|
786
|
+
return up;
|
|
787
|
+
},
|
|
788
|
+
...options,
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
if (mediaMsg) {
|
|
792
|
+
mediaMsg.message.messageContextInfo = {
|
|
793
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
794
|
+
messageAssociation: {
|
|
795
|
+
associationType: 1,
|
|
796
|
+
parentMessageKey: albumMsg.key
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
await relayMessage(jid, mediaMsg.message, {
|
|
801
|
+
messageId: mediaMsg.key.id
|
|
802
|
+
});
|
|
803
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
1009
804
|
}
|
|
805
|
+
return albumMsg;
|
|
806
|
+
}
|
|
807
|
+
else if (content.groupStatusMessage) {
|
|
808
|
+
const { quoted } = options;
|
|
809
|
+
return await rexx.handleGroupStory(content, jid, quoted);
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
let mediaHandle;
|
|
1010
813
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
1011
814
|
logger,
|
|
1012
815
|
userJid,
|
|
1013
|
-
ephemeralExpiration: (options.ephemeralExpiration && options.ephemeralExpiration > 0) ? options.ephemeralExpiration : eph,
|
|
1014
816
|
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
1015
817
|
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1016
818
|
fetchOpts: {
|
|
@@ -1022,50 +824,64 @@ const makeMessagesSocket = (config) => {
|
|
|
1022
824
|
? waUploadToServer
|
|
1023
825
|
: undefined
|
|
1024
826
|
}),
|
|
827
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1025
828
|
upload: async (readStream, opts) => {
|
|
1026
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.
|
|
829
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
1027
830
|
mediaHandle = up.handle;
|
|
1028
831
|
return up;
|
|
1029
832
|
},
|
|
1030
833
|
mediaCache: config.mediaCache,
|
|
1031
834
|
options: config.options,
|
|
1032
|
-
messageId:
|
|
835
|
+
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
|
|
1033
836
|
...options,
|
|
1034
837
|
});
|
|
1035
|
-
const
|
|
838
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
839
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1036
840
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1037
841
|
const isKeepMsg = 'keep' in content && content.keep;
|
|
1038
|
-
const
|
|
1039
|
-
const
|
|
1040
|
-
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
842
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
843
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
1041
844
|
const additionalAttributes = {};
|
|
1042
845
|
const additionalNodes = [];
|
|
1043
846
|
// required for delete
|
|
1044
847
|
if (isDeleteMsg) {
|
|
1045
848
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1046
|
-
if (((0, WABinary_1.isJidGroup)(
|
|
849
|
+
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
1047
850
|
additionalAttributes.edit = '8';
|
|
1048
851
|
}
|
|
1049
852
|
else {
|
|
1050
853
|
additionalAttributes.edit = '7';
|
|
1051
854
|
}
|
|
855
|
+
// required for edit message
|
|
1052
856
|
}
|
|
1053
857
|
else if (isEditMsg) {
|
|
1054
|
-
additionalAttributes.edit = (0, WABinary_1.
|
|
858
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
859
|
+
// required for pin message
|
|
1055
860
|
}
|
|
1056
861
|
else if (isPinMsg) {
|
|
1057
862
|
additionalAttributes.edit = '2';
|
|
863
|
+
// required for keep message
|
|
864
|
+
}
|
|
865
|
+
else if (isKeepMsg) {
|
|
866
|
+
additionalAttributes.edit = '6';
|
|
867
|
+
// required for polling message
|
|
868
|
+
}
|
|
869
|
+
else if (isPollMessage) {
|
|
870
|
+
additionalNodes.push({
|
|
871
|
+
tag: 'meta',
|
|
872
|
+
attrs: {
|
|
873
|
+
polltype: 'creation'
|
|
874
|
+
},
|
|
875
|
+
});
|
|
876
|
+
// required to display AI icon on message
|
|
1058
877
|
}
|
|
1059
878
|
else if (isAiMsg) {
|
|
1060
879
|
additionalNodes.push({
|
|
1061
880
|
attrs: {
|
|
1062
881
|
biz_bot: '1'
|
|
1063
882
|
},
|
|
1064
|
-
tag:
|
|
883
|
+
tag: "bot"
|
|
1065
884
|
});
|
|
1066
|
-
if (options.additionalNodes) {
|
|
1067
|
-
additionalNodes.push(...options.additionalNodes);
|
|
1068
|
-
}
|
|
1069
885
|
}
|
|
1070
886
|
if (mediaHandle) {
|
|
1071
887
|
additionalAttributes['media_id'] = mediaHandle;
|
|
@@ -1073,7 +889,7 @@ const makeMessagesSocket = (config) => {
|
|
|
1073
889
|
if ('cachedGroupMetadata' in options) {
|
|
1074
890
|
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
1075
891
|
}
|
|
1076
|
-
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id,
|
|
892
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
|
|
1077
893
|
if (config.emitOwnEvents) {
|
|
1078
894
|
process.nextTick(() => {
|
|
1079
895
|
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|