riftcore 1.4.5 → 1.4.7
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/README.md +422 -0
- package/WAProto/index.js +79296 -118676
- package/example.js +13 -0
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +7 -16
- package/lib/Defaults/index.js +103 -90
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +27 -29
- package/lib/Socket/chats.js +90 -97
- package/lib/Socket/erlanggaofficial.d.ts +219 -0
- package/lib/Socket/erlanggaofficial.js +439 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +5 -20
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +377 -541
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +41 -73
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -270
- package/lib/Socket/socket.js +38 -62
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +15 -27
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +17 -3
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +23 -73
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +157 -406
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +48 -345
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +25 -108
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +35 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +66 -90
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +17 -39
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.js +10 -2
- package/lib/WABinary/jid-utils.d.ts +5 -11
- package/lib/WABinary/jid-utils.js +5 -28
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +2 -6
- package/lib/index.js +15 -31
- package/package.json +51 -39
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/lib/Socket/setup.js +0 -481
- package/lib/Socket/setup.ts +0 -623
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
/* baileys by alip
|
|
2
|
-
mau ngapain lu memekkkkkkk*/
|
|
3
|
-
|
|
4
1
|
"use strict";
|
|
5
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
4
|
+
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.makeMessagesSocket = void 0;
|
|
10
7
|
const boom_1 = require("@hapi/boom");
|
|
11
|
-
const node_cache_1 = __importDefault(require("
|
|
12
|
-
const crypto_1 = require("crypto");
|
|
8
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
13
9
|
const WAProto_1 = require("../../WAProto");
|
|
14
10
|
const Defaults_1 = require("../Defaults");
|
|
11
|
+
const axios_1 = require("axios")
|
|
15
12
|
const Utils_1 = require("../Utils");
|
|
16
13
|
const link_preview_1 = require("../Utils/link-preview");
|
|
17
14
|
const WABinary_1 = require("../WABinary");
|
|
18
|
-
const WAUSync_1 = require("../WAUSync");
|
|
19
15
|
const newsletter_1 = require("./newsletter");
|
|
20
|
-
const
|
|
16
|
+
const erlangga = require('./erlanggaofficial');
|
|
17
|
+
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
21
18
|
const makeMessagesSocket = (config) => {
|
|
22
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
logger,
|
|
21
|
+
linkPreviewImageThumbnailWidth,
|
|
22
|
+
generateHighQualityLinkPreview,
|
|
23
|
+
options: axiosOptions,
|
|
24
|
+
patchMessageBeforeSending
|
|
25
|
+
} = config;
|
|
23
26
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
24
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
ev,
|
|
29
|
+
authState,
|
|
30
|
+
processingMutex,
|
|
31
|
+
signalRepository,
|
|
32
|
+
upsertMessage,
|
|
33
|
+
query,
|
|
34
|
+
fetchPrivacySettings,
|
|
35
|
+
generateMessageTag,
|
|
36
|
+
sendNode,
|
|
37
|
+
groupMetadata,
|
|
38
|
+
groupToggleEphemeral
|
|
39
|
+
} = sock;
|
|
25
40
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
26
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
41
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
27
42
|
useClones: false
|
|
28
43
|
});
|
|
29
44
|
let mediaConn;
|
|
@@ -82,7 +97,7 @@ const makeMessagesSocket = (config) => {
|
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
if (type) {
|
|
85
|
-
node.attrs.type = (0, WABinary_1.
|
|
100
|
+
node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
|
|
86
101
|
}
|
|
87
102
|
const remainingMessageIds = messageIds.slice(1);
|
|
88
103
|
if (remainingMessageIds.length) {
|
|
@@ -121,46 +136,66 @@ const makeMessagesSocket = (config) => {
|
|
|
121
136
|
if (!useCache) {
|
|
122
137
|
logger.debug('not using cache for devices');
|
|
123
138
|
}
|
|
124
|
-
const
|
|
139
|
+
const users = [];
|
|
125
140
|
jids = Array.from(new Set(jids));
|
|
126
141
|
for (let jid of jids) {
|
|
127
142
|
const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
|
|
128
143
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
logger.trace({ user }, 'using cache for devices');
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
toFetch.push(jid);
|
|
137
|
-
}
|
|
144
|
+
const devices = userDevicesCache.get(user);
|
|
145
|
+
if (devices && useCache) {
|
|
146
|
+
deviceResults.push(...devices);
|
|
147
|
+
logger.trace({ user }, 'using cache for devices');
|
|
138
148
|
}
|
|
139
149
|
else {
|
|
140
|
-
|
|
150
|
+
users.push({ tag: 'user', attrs: { jid } });
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
|
-
if (!
|
|
153
|
+
if (!users.length) {
|
|
144
154
|
return deviceResults;
|
|
145
155
|
}
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
const iq = {
|
|
157
|
+
tag: 'iq',
|
|
158
|
+
attrs: {
|
|
159
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
160
|
+
type: 'get',
|
|
161
|
+
xmlns: 'usync',
|
|
162
|
+
},
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
tag: 'usync',
|
|
166
|
+
attrs: {
|
|
167
|
+
sid: generateMessageTag(),
|
|
168
|
+
mode: 'query',
|
|
169
|
+
last: 'true',
|
|
170
|
+
index: '0',
|
|
171
|
+
context: 'message',
|
|
172
|
+
},
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
tag: 'query',
|
|
176
|
+
attrs: {},
|
|
177
|
+
content: [
|
|
178
|
+
{
|
|
179
|
+
tag: 'devices',
|
|
180
|
+
attrs: { version: '2' }
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
},
|
|
184
|
+
{ tag: 'list', attrs: {}, content: users }
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
const result = await query(iq);
|
|
190
|
+
const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
|
|
191
|
+
const deviceMap = {};
|
|
192
|
+
for (const item of extracted) {
|
|
193
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
194
|
+
deviceMap[item.user].push(item);
|
|
195
|
+
deviceResults.push(item);
|
|
151
196
|
}
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
|
|
155
|
-
const deviceMap = {};
|
|
156
|
-
for (const item of extracted) {
|
|
157
|
-
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
158
|
-
deviceMap[item.user].push(item);
|
|
159
|
-
deviceResults.push(item);
|
|
160
|
-
}
|
|
161
|
-
for (const key in deviceMap) {
|
|
162
|
-
userDevicesCache.set(key, deviceMap[key]);
|
|
163
|
-
}
|
|
197
|
+
for (const key in deviceMap) {
|
|
198
|
+
userDevicesCache.set(key, deviceMap[key]);
|
|
164
199
|
}
|
|
165
200
|
return deviceResults;
|
|
166
201
|
};
|
|
@@ -207,40 +242,11 @@ const makeMessagesSocket = (config) => {
|
|
|
207
242
|
}
|
|
208
243
|
return didFetchNewSession;
|
|
209
244
|
};
|
|
210
|
-
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
211
|
-
var _a;
|
|
212
|
-
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
213
|
-
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
214
|
-
throw new boom_1.Boom('Not authenticated');
|
|
215
|
-
}
|
|
216
|
-
const protocolMessage = {
|
|
217
|
-
protocolMessage: {
|
|
218
|
-
peerDataOperationRequestMessage: pdoMessage,
|
|
219
|
-
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
223
|
-
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
224
|
-
additionalAttributes: {
|
|
225
|
-
category: 'peer',
|
|
226
|
-
// eslint-disable-next-line camelcase
|
|
227
|
-
push_priority: 'high_force',
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
return msgId;
|
|
231
|
-
};
|
|
232
245
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
|
|
236
|
-
}
|
|
246
|
+
const patched = await patchMessageBeforeSending(message, jids);
|
|
247
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
237
248
|
let shouldIncludeDeviceIdentity = false;
|
|
238
|
-
const nodes = await Promise.all(
|
|
239
|
-
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
|
|
240
|
-
if (!jid) {
|
|
241
|
-
return {};
|
|
242
|
-
}
|
|
243
|
-
const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
|
|
249
|
+
const nodes = await Promise.all(jids.map(async (jid) => {
|
|
244
250
|
const { type, ciphertext } = await signalRepository
|
|
245
251
|
.encryptMessage({ jid, data: bytes });
|
|
246
252
|
if (type === 'pkmsg') {
|
|
@@ -262,23 +268,20 @@ const makeMessagesSocket = (config) => {
|
|
|
262
268
|
return node;
|
|
263
269
|
}));
|
|
264
270
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
265
|
-
};
|
|
266
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache,
|
|
267
|
-
var _a;
|
|
271
|
+
}; //apela
|
|
272
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList, AI = true }) => {
|
|
268
273
|
const meId = authState.creds.me.id;
|
|
269
274
|
let shouldIncludeDeviceIdentity = false;
|
|
275
|
+
let didPushAdditional = false
|
|
270
276
|
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
271
277
|
const statusJid = 'status@broadcast';
|
|
272
278
|
const isGroup = server === 'g.us';
|
|
273
|
-
const isPrivatee = server === 's.whatsapp.net'
|
|
274
|
-
const isNewsletter = server === 'newsletter';
|
|
275
279
|
const isStatus = jid === statusJid;
|
|
276
280
|
const isLid = server === 'lid';
|
|
277
|
-
const
|
|
278
|
-
const
|
|
279
|
-
msgId = msgId || (0, Utils_1.
|
|
281
|
+
const isPrivate = server === 's.whatsapp.net'
|
|
282
|
+
const isNewsletter = server === 'newsletter';
|
|
283
|
+
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
280
284
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
281
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
282
285
|
const participants = [];
|
|
283
286
|
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
284
287
|
const binaryNodeContent = [];
|
|
@@ -287,10 +290,8 @@ const makeMessagesSocket = (config) => {
|
|
|
287
290
|
deviceSentMessage: {
|
|
288
291
|
destinationJid,
|
|
289
292
|
message
|
|
290
|
-
}
|
|
291
|
-
messageContextInfo: message.messageContextInfo
|
|
293
|
+
}
|
|
292
294
|
};
|
|
293
|
-
const extraAttrs = {};
|
|
294
295
|
if (participant) {
|
|
295
296
|
// when the retry request is not for a group
|
|
296
297
|
// only send to the specific device that asked for a retry
|
|
@@ -302,22 +303,16 @@ const makeMessagesSocket = (config) => {
|
|
|
302
303
|
devices.push({ user, device });
|
|
303
304
|
}
|
|
304
305
|
await authState.keys.transaction(async () => {
|
|
305
|
-
var _a, _b, _c, _d, _e, _f
|
|
306
|
+
var _a, _b, _c, _d, _e, _f;
|
|
306
307
|
const mediaType = getMediaType(message);
|
|
307
|
-
if (mediaType) {
|
|
308
|
-
extraAttrs['mediatype'] = mediaType;
|
|
309
|
-
}
|
|
310
|
-
if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
|
|
311
|
-
extraAttrs['decrypt-fail'] = 'hide';
|
|
312
|
-
}
|
|
313
308
|
if (isGroup || isStatus) {
|
|
314
309
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
315
310
|
(async () => {
|
|
316
|
-
let groupData =
|
|
317
|
-
if (groupData
|
|
311
|
+
let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
312
|
+
if (groupData) {
|
|
318
313
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
319
314
|
}
|
|
320
|
-
|
|
315
|
+
if (!groupData && !isStatus) {
|
|
321
316
|
groupData = await groupMetadata(jid);
|
|
322
317
|
}
|
|
323
318
|
return groupData;
|
|
@@ -335,20 +330,10 @@ const makeMessagesSocket = (config) => {
|
|
|
335
330
|
if (isStatus && statusJidList) {
|
|
336
331
|
participantsList.push(...statusJidList);
|
|
337
332
|
}
|
|
338
|
-
if (!isStatus) {
|
|
339
|
-
additionalAttributes = {
|
|
340
|
-
...additionalAttributes,
|
|
341
|
-
// eslint-disable-next-line camelcase
|
|
342
|
-
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
333
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
346
334
|
devices.push(...additionalDevices);
|
|
347
335
|
}
|
|
348
|
-
const patched = await patchMessageBeforeSending(message);
|
|
349
|
-
if (Array.isArray(patched)) {
|
|
350
|
-
throw new boom_1.Boom('Per-jid patching is not supported in groups');
|
|
351
|
-
}
|
|
336
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
352
337
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
353
338
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
354
339
|
group: destinationJid,
|
|
@@ -376,7 +361,7 @@ const makeMessagesSocket = (config) => {
|
|
|
376
361
|
}
|
|
377
362
|
};
|
|
378
363
|
await assertSessions(senderKeyJids, false);
|
|
379
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg,
|
|
364
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
|
|
380
365
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
381
366
|
participants.push(...result.nodes);
|
|
382
367
|
}
|
|
@@ -389,20 +374,17 @@ const makeMessagesSocket = (config) => {
|
|
|
389
374
|
}
|
|
390
375
|
else if (isNewsletter) {
|
|
391
376
|
// Message edit
|
|
392
|
-
if ((
|
|
393
|
-
msgId = (
|
|
377
|
+
if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
|
|
378
|
+
msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
|
|
394
379
|
message = message.protocolMessage.editedMessage;
|
|
395
380
|
}
|
|
396
381
|
// Message delete
|
|
397
|
-
if (((
|
|
398
|
-
msgId = (
|
|
382
|
+
if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
383
|
+
msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
|
|
399
384
|
message = {};
|
|
400
385
|
}
|
|
401
386
|
const patched = await patchMessageBeforeSending(message, []);
|
|
402
|
-
|
|
403
|
-
throw new boom_1.Boom('Per-jid patching is not supported in channel');
|
|
404
|
-
}
|
|
405
|
-
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
387
|
+
const bytes = WAProto_1.proto.Message.encode(patched).finish();
|
|
406
388
|
binaryNodeContent.push({
|
|
407
389
|
tag: 'plaintext',
|
|
408
390
|
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
@@ -410,23 +392,22 @@ const makeMessagesSocket = (config) => {
|
|
|
410
392
|
});
|
|
411
393
|
}
|
|
412
394
|
else {
|
|
413
|
-
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
395
|
+
const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
|
|
414
396
|
if (!participant) {
|
|
415
397
|
devices.push({ user });
|
|
416
|
-
if
|
|
398
|
+
// do not send message to self if the device is 0 (mobile)
|
|
399
|
+
if (meDevice !== undefined && meDevice !== 0) {
|
|
417
400
|
devices.push({ user: meUser });
|
|
418
401
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
devices.push(...additionalDevices);
|
|
422
|
-
}
|
|
402
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
403
|
+
devices.push(...additionalDevices);
|
|
423
404
|
}
|
|
424
405
|
const allJids = [];
|
|
425
406
|
const meJids = [];
|
|
426
407
|
const otherJids = [];
|
|
427
408
|
for (const { user, device } of devices) {
|
|
428
409
|
const isMe = user === meUser;
|
|
429
|
-
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((
|
|
410
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
430
411
|
if (isMe) {
|
|
431
412
|
meJids.push(jid);
|
|
432
413
|
}
|
|
@@ -437,27 +418,19 @@ const makeMessagesSocket = (config) => {
|
|
|
437
418
|
}
|
|
438
419
|
await assertSessions(allJids, false);
|
|
439
420
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
440
|
-
createParticipantNodes(meJids, meMsg,
|
|
441
|
-
createParticipantNodes(otherJids, message,
|
|
421
|
+
createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
|
|
422
|
+
createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
|
|
442
423
|
]);
|
|
443
424
|
participants.push(...meNodes);
|
|
444
425
|
participants.push(...otherNodes);
|
|
445
426
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
446
427
|
}
|
|
447
428
|
if (participants.length) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
binaryNodeContent.push({
|
|
456
|
-
tag: 'participants',
|
|
457
|
-
attrs: {},
|
|
458
|
-
content: participants
|
|
459
|
-
});
|
|
460
|
-
}
|
|
429
|
+
binaryNodeContent.push({
|
|
430
|
+
tag: 'participants',
|
|
431
|
+
attrs: {},
|
|
432
|
+
content: participants
|
|
433
|
+
});
|
|
461
434
|
}
|
|
462
435
|
const stanza = {
|
|
463
436
|
tag: 'message',
|
|
@@ -495,54 +468,61 @@ const makeMessagesSocket = (config) => {
|
|
|
495
468
|
});
|
|
496
469
|
logger.debug({ jid }, 'adding device identity');
|
|
497
470
|
}
|
|
498
|
-
if (pollMessage || messages.eventMessage) {
|
|
499
|
-
let attrs = {};
|
|
500
|
-
if (messages.eventMessage) {
|
|
501
|
-
attrs.event_type = 'creation';
|
|
502
|
-
} else {
|
|
503
|
-
attrs.polltype = 'creation';
|
|
504
|
-
if (isNewsletter) {
|
|
505
|
-
attrs.contenttype = (pollMessage && pollMessage.pollContentType === 2) ? 'image' : 'text';
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
stanza.content.push({
|
|
509
|
-
tag: 'meta',
|
|
510
|
-
attrs: attrs
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
471
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
514
472
|
stanza.content.push(...additionalNodes);
|
|
515
473
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}];
|
|
474
|
+
else {
|
|
475
|
+
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && ((message === null || message === void 0 ? void 0 : message.viewOnceMessage) ? message === null || message === void 0 ? void 0 : message.viewOnceMessage : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2 : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension : (message === null || message === void 0 ? void 0 : message.ephemeralMessage) ? message === null || message === void 0 ? void 0 : message.ephemeralMessage : (message === null || message === void 0 ? void 0 : message.templateMessage) ? message === null || message === void 0 ? void 0 : message.templateMessage : (message === null || message === void 0 ? void 0 : message.interactiveMessage) ? message === null || message === void 0 ? void 0 : message.interactiveMessage : message === null || message === void 0 ? void 0 : message.buttonsMessage)) {
|
|
476
|
+
stanza.content.push({
|
|
477
|
+
tag: 'biz',
|
|
478
|
+
attrs: {},
|
|
479
|
+
content: [{
|
|
480
|
+
tag: 'interactive',
|
|
481
|
+
attrs: {
|
|
482
|
+
type: 'native_flow',
|
|
483
|
+
v: '1'
|
|
484
|
+
},
|
|
485
|
+
content: [{
|
|
486
|
+
tag: 'native_flow',
|
|
487
|
+
attrs: { v: '9', name: 'mixed' }
|
|
488
|
+
}]
|
|
489
|
+
}]
|
|
490
|
+
});
|
|
534
491
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}];
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (AI && isPrivate) {
|
|
495
|
+
const botNode = {
|
|
496
|
+
tag: 'bot',
|
|
497
|
+
attrs: {
|
|
498
|
+
biz_bot: '1'
|
|
499
|
+
}
|
|
544
500
|
}
|
|
545
|
-
|
|
501
|
+
|
|
502
|
+
const filteredBizBot = WABinary_1.getBinaryFilteredBizBot(additionalNodes ? additionalNodes : [])
|
|
503
|
+
|
|
504
|
+
if (filteredBizBot) {
|
|
505
|
+
stanza.content.push(...additionalNodes)
|
|
506
|
+
didPushAdditional = true
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
else {
|
|
510
|
+
stanza.content.push(botNode)
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const buttonType = getButtonType(message);
|
|
514
|
+
if (buttonType) {
|
|
515
|
+
stanza.content.push({
|
|
516
|
+
tag: 'biz',
|
|
517
|
+
attrs: {},
|
|
518
|
+
content: [
|
|
519
|
+
{
|
|
520
|
+
tag: buttonType,
|
|
521
|
+
attrs: getButtonArgs(message),
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
});
|
|
525
|
+
logger.debug({ jid }, 'adding business node');
|
|
546
526
|
}
|
|
547
527
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
548
528
|
await sendNode(stanza);
|
|
@@ -550,81 +530,153 @@ const makeMessagesSocket = (config) => {
|
|
|
550
530
|
return msgId;
|
|
551
531
|
};
|
|
552
532
|
const getTypeMessage = (msg) => {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
561
|
-
}
|
|
562
|
-
else if (msg.ephemeralMessage) {
|
|
563
|
-
return getTypeMessage(msg.ephemeralMessage.message);
|
|
564
|
-
}
|
|
565
|
-
else if (msg.documentWithCaptionMessage) {
|
|
566
|
-
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
567
|
-
}
|
|
568
|
-
else if (msg.reactionMessage) {
|
|
569
|
-
return 'reaction';
|
|
570
|
-
}
|
|
571
|
-
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
572
|
-
return 'poll';
|
|
573
|
-
}
|
|
574
|
-
else if (getMediaType(msg)) {
|
|
575
|
-
return 'media';
|
|
576
|
-
}
|
|
533
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
534
|
+
if (message.reactionMessage) {
|
|
535
|
+
return 'reaction'
|
|
536
|
+
}
|
|
537
|
+
else if (getMediaType(message)) {
|
|
538
|
+
return 'media'
|
|
539
|
+
}
|
|
577
540
|
else {
|
|
578
|
-
return 'text'
|
|
541
|
+
return 'text'
|
|
579
542
|
}
|
|
580
|
-
}
|
|
543
|
+
}
|
|
544
|
+
|
|
581
545
|
const getMediaType = (message) => {
|
|
582
546
|
if (message.imageMessage) {
|
|
583
|
-
return 'image'
|
|
547
|
+
return 'image'
|
|
584
548
|
}
|
|
585
549
|
else if (message.videoMessage) {
|
|
586
|
-
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
550
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
587
551
|
}
|
|
588
552
|
else if (message.audioMessage) {
|
|
589
|
-
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
553
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
590
554
|
}
|
|
591
555
|
else if (message.contactMessage) {
|
|
592
|
-
return 'vcard'
|
|
556
|
+
return 'vcard'
|
|
593
557
|
}
|
|
594
558
|
else if (message.documentMessage) {
|
|
595
|
-
return 'document'
|
|
559
|
+
return 'document'
|
|
596
560
|
}
|
|
597
561
|
else if (message.contactsArrayMessage) {
|
|
598
|
-
return 'contact_array'
|
|
562
|
+
return 'contact_array'
|
|
599
563
|
}
|
|
600
564
|
else if (message.liveLocationMessage) {
|
|
601
|
-
return 'livelocation'
|
|
565
|
+
return 'livelocation'
|
|
602
566
|
}
|
|
603
567
|
else if (message.stickerMessage) {
|
|
604
|
-
return 'sticker'
|
|
568
|
+
return 'sticker'
|
|
605
569
|
}
|
|
606
570
|
else if (message.listMessage) {
|
|
607
|
-
return 'list'
|
|
571
|
+
return 'list'
|
|
608
572
|
}
|
|
609
573
|
else if (message.listResponseMessage) {
|
|
610
|
-
return 'list_response'
|
|
574
|
+
return 'list_response'
|
|
611
575
|
}
|
|
612
576
|
else if (message.buttonsResponseMessage) {
|
|
613
|
-
return 'buttons_response'
|
|
577
|
+
return 'buttons_response'
|
|
614
578
|
}
|
|
615
579
|
else if (message.orderMessage) {
|
|
616
|
-
return 'order'
|
|
580
|
+
return 'order'
|
|
617
581
|
}
|
|
618
582
|
else if (message.productMessage) {
|
|
619
|
-
return 'product'
|
|
583
|
+
return 'product'
|
|
620
584
|
}
|
|
621
585
|
else if (message.interactiveResponseMessage) {
|
|
622
|
-
return 'native_flow_response'
|
|
586
|
+
return 'native_flow_response'
|
|
623
587
|
}
|
|
624
588
|
else if (message.groupInviteMessage) {
|
|
625
|
-
return 'url'
|
|
589
|
+
return 'url'
|
|
590
|
+
}
|
|
591
|
+
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
592
|
+
return 'productlink'
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const getButtonType = (message) => {
|
|
596
|
+
if (message.listMessage) {
|
|
597
|
+
return 'list'
|
|
598
|
+
}
|
|
599
|
+
else if (message.buttonsMessage) {
|
|
600
|
+
return 'buttons'
|
|
601
|
+
}
|
|
602
|
+
else if(message.interactiveMessage?.nativeFlowMessage) {
|
|
603
|
+
return 'native_flow'
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const getButtonArgs = (message) => {
|
|
607
|
+
if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'review_and_pay') {
|
|
608
|
+
return {
|
|
609
|
+
tag: 'biz',
|
|
610
|
+
attrs: {
|
|
611
|
+
native_flow_name: 'order_details'
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
} else if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'payment_info') {
|
|
615
|
+
return {
|
|
616
|
+
tag: 'biz',
|
|
617
|
+
attrs: {
|
|
618
|
+
native_flow_name: 'payment_info'
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
} else if (message.interactiveMessage?.nativeFlowMessage &&message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 &&
|
|
622
|
+
['mpm', 'cta_catalog', 'send_location', 'call_permission_request', 'wa_payment_transaction_details', 'automated_greeting_message_view_catalog']
|
|
623
|
+
.includes(message.interactiveMessage.nativeFlowMessage.buttons[0].name)) {
|
|
624
|
+
return {
|
|
625
|
+
tag: 'biz',
|
|
626
|
+
attrs: {},
|
|
627
|
+
content: [{
|
|
628
|
+
tag: 'interactive',
|
|
629
|
+
attrs: {
|
|
630
|
+
type: 'native_flow',
|
|
631
|
+
v: '1'
|
|
632
|
+
},
|
|
633
|
+
content: [{
|
|
634
|
+
tag: 'native_flow',
|
|
635
|
+
attrs: {
|
|
636
|
+
v: '2',
|
|
637
|
+
name: message.interactiveMessage.nativeFlowMessage.buttons[0].name
|
|
638
|
+
}
|
|
639
|
+
}]
|
|
640
|
+
}]
|
|
641
|
+
}
|
|
642
|
+
} else if (message.interactiveMessage?.nativeFlowMessage || message.buttonsMessage) {
|
|
643
|
+
return {
|
|
644
|
+
tag: 'biz',
|
|
645
|
+
attrs: {},
|
|
646
|
+
content: [{
|
|
647
|
+
tag: 'interactive',
|
|
648
|
+
attrs: {
|
|
649
|
+
type: 'native_flow',
|
|
650
|
+
v: '1'
|
|
651
|
+
},
|
|
652
|
+
content: [{
|
|
653
|
+
tag: 'native_flow',
|
|
654
|
+
attrs: {
|
|
655
|
+
v: '9',
|
|
656
|
+
name: 'mixed'
|
|
657
|
+
}
|
|
658
|
+
}]
|
|
659
|
+
}]
|
|
660
|
+
}
|
|
661
|
+
} else if (message.listMessage) {
|
|
662
|
+
return {
|
|
663
|
+
tag: 'biz',
|
|
664
|
+
attrs: {},
|
|
665
|
+
content: [{
|
|
666
|
+
tag: 'list',
|
|
667
|
+
attrs: {
|
|
668
|
+
v: '2',
|
|
669
|
+
type: 'product_list'
|
|
670
|
+
}
|
|
671
|
+
}]
|
|
672
|
+
}
|
|
673
|
+
} else {
|
|
674
|
+
return {
|
|
675
|
+
tag: 'biz',
|
|
676
|
+
attrs: {}
|
|
677
|
+
}
|
|
626
678
|
}
|
|
627
|
-
}
|
|
679
|
+
}
|
|
628
680
|
const getPrivacyTokens = async (jids) => {
|
|
629
681
|
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
630
682
|
const result = await query({
|
|
@@ -650,9 +702,32 @@ const makeMessagesSocket = (config) => {
|
|
|
650
702
|
]
|
|
651
703
|
});
|
|
652
704
|
return result;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
708
|
+
var _a;
|
|
709
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
710
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
711
|
+
throw new boom_1.Boom('Not authenticated');
|
|
712
|
+
}
|
|
713
|
+
const protocolMessage = {
|
|
714
|
+
protocolMessage: {
|
|
715
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
716
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
720
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
721
|
+
additionalAttributes: {
|
|
722
|
+
category: 'peer',
|
|
723
|
+
// eslint-disable-next-line camelcase
|
|
724
|
+
push_priority: 'high_force',
|
|
725
|
+
},
|
|
726
|
+
});
|
|
727
|
+
return msgId;
|
|
653
728
|
};
|
|
654
729
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
655
|
-
const
|
|
730
|
+
const rahmi = new erlangga(Utils_1, waUploadToServer, relayMessage);
|
|
656
731
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
657
732
|
return {
|
|
658
733
|
...sock,
|
|
@@ -661,23 +736,24 @@ const makeMessagesSocket = (config) => {
|
|
|
661
736
|
relayMessage,
|
|
662
737
|
sendReceipt,
|
|
663
738
|
sendReceipts,
|
|
664
|
-
|
|
739
|
+
rahmi,
|
|
740
|
+
getButtonArgs,
|
|
665
741
|
readMessages,
|
|
666
742
|
refreshMediaConn,
|
|
667
|
-
waUploadToServer,
|
|
668
|
-
fetchPrivacySettings,
|
|
669
743
|
getUSyncDevices,
|
|
670
744
|
createParticipantNodes,
|
|
745
|
+
waUploadToServer,
|
|
671
746
|
sendPeerDataOperationMessage,
|
|
747
|
+
fetchPrivacySettings,
|
|
672
748
|
updateMediaMessage: async (message) => {
|
|
673
749
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
674
750
|
const mediaKey = content.mediaKey;
|
|
675
751
|
const meId = authState.creds.me.id;
|
|
676
|
-
const node =
|
|
752
|
+
const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
677
753
|
let error = undefined;
|
|
678
754
|
await Promise.all([
|
|
679
755
|
sendNode(node),
|
|
680
|
-
waitForMsgMediaUpdate(
|
|
756
|
+
waitForMsgMediaUpdate(update => {
|
|
681
757
|
const result = update.find(c => c.key.id === message.key.id);
|
|
682
758
|
if (result) {
|
|
683
759
|
if (result.error) {
|
|
@@ -685,7 +761,7 @@ const makeMessagesSocket = (config) => {
|
|
|
685
761
|
}
|
|
686
762
|
else {
|
|
687
763
|
try {
|
|
688
|
-
const media =
|
|
764
|
+
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
689
765
|
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
690
766
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
691
767
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
@@ -710,348 +786,108 @@ const makeMessagesSocket = (config) => {
|
|
|
710
786
|
]);
|
|
711
787
|
return message;
|
|
712
788
|
},
|
|
713
|
-
sendStatusMentions: async (content, jids = []) => {
|
|
714
|
-
const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
|
|
715
|
-
let allUsers = new Set()
|
|
716
|
-
allUsers.add(userJid)
|
|
717
|
-
|
|
718
|
-
for (const id of jids) {
|
|
719
|
-
const isGroup = WABinary_1.isJidGroup(id)
|
|
720
|
-
const isPrivate = WABinary_1.isJidUser(id)
|
|
721
|
-
|
|
722
|
-
if (isGroup) {
|
|
723
|
-
try {
|
|
724
|
-
const metadata = await cachedGroupMetadata(id) || await global.groupMetadataCache(id)
|
|
725
|
-
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
|
|
726
|
-
participants.forEach(jid => allUsers.add(jid))
|
|
727
|
-
} catch (error) {
|
|
728
|
-
logger.error(`Error getting metadata for group ${id}: ${error}`)
|
|
729
|
-
}
|
|
730
|
-
} else if (isPrivate) {
|
|
731
|
-
allUsers.add(WABinary_1.jidNormalizedUser(id))
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
const uniqueUsers = Array.from(allUsers)
|
|
736
|
-
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
|
|
737
|
-
|
|
738
|
-
const isMedia = content.image || content.video || content.audio
|
|
739
|
-
const isAudio = !!content.audio
|
|
740
|
-
|
|
741
|
-
const messageContent = {
|
|
742
|
-
...content
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (isMedia && !isAudio) {
|
|
746
|
-
if (messageContent.text) {
|
|
747
|
-
messageContent.caption = messageContent.text
|
|
748
|
-
|
|
749
|
-
delete messageContent.text
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
delete messageContent.ptt
|
|
753
|
-
delete messageContent.font
|
|
754
|
-
delete messageContent.backgroundColor
|
|
755
|
-
delete messageContent.textColor
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
if (isAudio) {
|
|
759
|
-
delete messageContent.text
|
|
760
|
-
delete messageContent.caption
|
|
761
|
-
delete messageContent.font
|
|
762
|
-
delete messageContent.textColor
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined
|
|
766
|
-
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined
|
|
767
|
-
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined
|
|
768
|
-
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
|
|
769
|
-
|
|
770
|
-
let msg
|
|
771
|
-
let mediaHandle
|
|
772
|
-
try {
|
|
773
|
-
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
774
|
-
logger,
|
|
775
|
-
userJid,
|
|
776
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
777
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
778
|
-
fetchOpts: {
|
|
779
|
-
timeout: 3000,
|
|
780
|
-
...axiosOptions || {}
|
|
781
|
-
},
|
|
782
|
-
logger,
|
|
783
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
784
|
-
}),
|
|
785
|
-
upload: async (encFilePath, opts) => {
|
|
786
|
-
const up = await waUploadToServer(encFilePath, {
|
|
787
|
-
...opts
|
|
788
|
-
})
|
|
789
|
-
mediaHandle = up.handle
|
|
790
|
-
return up
|
|
791
|
-
},
|
|
792
|
-
mediaCache: config.mediaCache,
|
|
793
|
-
options: config.options,
|
|
794
|
-
font,
|
|
795
|
-
textColor,
|
|
796
|
-
backgroundColor,
|
|
797
|
-
ptt
|
|
798
|
-
})
|
|
799
|
-
} catch (error) {
|
|
800
|
-
logger.error(`Error generating message: ${error}`)
|
|
801
|
-
throw error
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
805
|
-
messageId: msg.key.id,
|
|
806
|
-
statusJidList: uniqueUsers,
|
|
807
|
-
additionalNodes: [{
|
|
808
|
-
tag: 'meta',
|
|
809
|
-
attrs: {},
|
|
810
|
-
content: [{
|
|
811
|
-
tag: 'mentioned_users',
|
|
812
|
-
attrs: {},
|
|
813
|
-
content: jids.map(jid => ({
|
|
814
|
-
tag: 'to',
|
|
815
|
-
attrs: {
|
|
816
|
-
jid: WABinary_1.jidNormalizedUser(jid)
|
|
817
|
-
}
|
|
818
|
-
}))
|
|
819
|
-
}]
|
|
820
|
-
}]
|
|
821
|
-
})
|
|
822
|
-
|
|
823
|
-
for (const id of jids) {
|
|
824
|
-
try {
|
|
825
|
-
const normalizedId = WABinary_1.jidNormalizedUser(id)
|
|
826
|
-
const isPrivate = WABinary_1.isJidUser(normalizedId)
|
|
827
|
-
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
|
|
828
|
-
|
|
829
|
-
const protocolMessage = {
|
|
830
|
-
[type]: {
|
|
831
|
-
message: {
|
|
832
|
-
protocolMessage: {
|
|
833
|
-
key: msg.key,
|
|
834
|
-
type: 25
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
},
|
|
838
|
-
messageContextInfo: {
|
|
839
|
-
messageSecret: crypto_1.randomBytes(32)
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
|
|
844
|
-
protocolMessage, {}
|
|
845
|
-
)
|
|
846
|
-
|
|
847
|
-
await relayMessage(
|
|
848
|
-
normalizedId,
|
|
849
|
-
statusMsg.message, {
|
|
850
|
-
additionalNodes: [{
|
|
851
|
-
tag: 'meta',
|
|
852
|
-
attrs: isPrivate ? {
|
|
853
|
-
is_status_mention: 'true'
|
|
854
|
-
} : {
|
|
855
|
-
is_group_status_mention: 'true'
|
|
856
|
-
}
|
|
857
|
-
}]
|
|
858
|
-
}
|
|
859
|
-
)
|
|
860
|
-
|
|
861
|
-
await Utils_1.delay(2000)
|
|
862
|
-
} catch (error) {
|
|
863
|
-
logger.error(`Error sending to ${id}: ${error}`)
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
return msg
|
|
868
|
-
},
|
|
869
789
|
sendMessage: async (jid, content, options = {}) => {
|
|
870
|
-
var _a, _b, _c;
|
|
871
790
|
const userJid = authState.creds.me.id;
|
|
872
|
-
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
873
791
|
const { filter = false, quoted } = options;
|
|
874
|
-
const
|
|
875
|
-
|
|
792
|
+
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
793
|
+
const messageType = rahmi.detectType(content);
|
|
794
|
+
|
|
876
795
|
if (messageType) {
|
|
877
|
-
switch
|
|
796
|
+
switch(messageType) {
|
|
878
797
|
case 'PAYMENT':
|
|
879
|
-
const paymentContent = await
|
|
798
|
+
const paymentContent = await rahmi.handlePayment(content, quoted);
|
|
880
799
|
return await relayMessage(jid, paymentContent, {
|
|
881
800
|
messageId: Utils_1.generateMessageID(),
|
|
882
801
|
...getParticipantAttr()
|
|
883
802
|
});
|
|
884
|
-
|
|
803
|
+
|
|
885
804
|
case 'PRODUCT':
|
|
886
|
-
const productContent = await
|
|
805
|
+
const productContent = await rahmi.handleProduct(content, jid, quoted);
|
|
887
806
|
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
888
807
|
return await relayMessage(jid, productMsg.message, {
|
|
889
808
|
messageId: productMsg.key.id,
|
|
890
809
|
...getParticipantAttr()
|
|
891
810
|
});
|
|
892
|
-
|
|
811
|
+
|
|
893
812
|
case 'INTERACTIVE':
|
|
894
|
-
const interactiveContent = await
|
|
813
|
+
const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
|
|
895
814
|
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
896
815
|
return await relayMessage(jid, interactiveMsg.message, {
|
|
897
816
|
messageId: interactiveMsg.key.id,
|
|
898
817
|
...getParticipantAttr()
|
|
899
818
|
});
|
|
900
|
-
|
|
901
819
|
case 'ALBUM':
|
|
902
|
-
|
|
903
|
-
return
|
|
904
|
-
|
|
820
|
+
const albumContent = await rahmi.handleAlbum(content, jid, quoted)
|
|
821
|
+
return albumContent;
|
|
822
|
+
|
|
905
823
|
case 'EVENT':
|
|
906
|
-
|
|
907
|
-
return await NotForralll.handleEvent(content, jid, quoted);
|
|
908
|
-
|
|
909
|
-
case 'POLL_RESULT':
|
|
910
|
-
// Handler custom ini melakukan relay message sendiri
|
|
911
|
-
return await NotForralll.handlePollResult(content, jid, quoted);
|
|
824
|
+
return await rahmi.handleEvent(content, jid, quoted)
|
|
912
825
|
|
|
913
|
-
case '
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
audio: content.audio,
|
|
927
|
-
mimetype: content.mimetype,
|
|
928
|
-
ptt: true
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
if (!options.ephemeralExpiration) {
|
|
933
|
-
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
934
|
-
const groups = await sock.groupQuery(jid, 'get', [{
|
|
935
|
-
tag: 'query',
|
|
936
|
-
attrs: {
|
|
937
|
-
request: 'interactive'
|
|
938
|
-
}
|
|
939
|
-
}]);
|
|
940
|
-
const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
|
|
941
|
-
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;
|
|
942
|
-
options.ephemeralExpiration = expiration;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
if (typeof content === 'object' &&
|
|
946
|
-
'disappearingMessagesInChat' in content &&
|
|
947
|
-
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
948
|
-
(0, WABinary_1.isJidGroup)(jid)) {
|
|
949
|
-
const { disappearingMessagesInChat } = content;
|
|
950
|
-
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
951
|
-
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
952
|
-
disappearingMessagesInChat;
|
|
953
|
-
await groupToggleEphemeral(jid, value);
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
// **FIX: Menghapus logika album built-in yang redundant di sini**
|
|
957
|
-
/*
|
|
958
|
-
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
959
|
-
const { album, caption } = content;
|
|
960
|
-
// ... (LOGIKA ALBUM ASLI BAILEYS) ...
|
|
961
|
-
return albumMsg;
|
|
962
|
-
}
|
|
963
|
-
else {
|
|
964
|
-
*/
|
|
965
|
-
let mediaHandle;
|
|
966
|
-
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
967
|
-
logger,
|
|
968
|
-
userJid,
|
|
969
|
-
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
970
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
971
|
-
fetchOpts: {
|
|
972
|
-
timeout: 3000,
|
|
973
|
-
...axiosOptions || {}
|
|
974
|
-
},
|
|
975
|
-
logger,
|
|
976
|
-
uploadImage: generateHighQualityLinkPreview
|
|
977
|
-
? waUploadToServer
|
|
978
|
-
: undefined
|
|
979
|
-
}),
|
|
980
|
-
getProfilePicUrl: sock.profilePictureUrl,
|
|
981
|
-
upload: async (readStream, opts) => {
|
|
982
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
983
|
-
mediaHandle = up.handle;
|
|
984
|
-
return up;
|
|
826
|
+
case 'POLL_RESULT':
|
|
827
|
+
return await rahmi.handlePollResult(content, jid, quoted)
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
831
|
+
logger,
|
|
832
|
+
userJid,
|
|
833
|
+
quoted,
|
|
834
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
835
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
836
|
+
fetchOpts: {
|
|
837
|
+
timeout: 3000,
|
|
838
|
+
...axiosOptions || {}
|
|
985
839
|
},
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
const isPinMsg = 'pin' in content && !!content.pin;
|
|
994
|
-
const isKeepMsg = 'keep' in content && content.keep;
|
|
995
|
-
const isPollMessage = 'poll' in content && !!content.poll;
|
|
996
|
-
const isAiMsg = 'ai' in content && !!content.ai;
|
|
997
|
-
const additionalAttributes = {};
|
|
998
|
-
const additionalNodes = [];
|
|
999
|
-
// required for delete
|
|
1000
|
-
if (isDeleteMsg) {
|
|
1001
|
-
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1002
|
-
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
1003
|
-
additionalAttributes.edit = '8';
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
additionalAttributes.edit = '7';
|
|
1007
|
-
}
|
|
1008
|
-
// required for edit message
|
|
1009
|
-
}
|
|
1010
|
-
else if (isEditMsg) {
|
|
1011
|
-
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
1012
|
-
// required for pin message
|
|
1013
|
-
}
|
|
1014
|
-
else if (isPinMsg) {
|
|
1015
|
-
additionalAttributes.edit = '2';
|
|
1016
|
-
// required for keep message
|
|
1017
|
-
}
|
|
1018
|
-
else if (isKeepMsg) {
|
|
1019
|
-
additionalAttributes.edit = '6';
|
|
1020
|
-
// required for polling message
|
|
1021
|
-
}
|
|
1022
|
-
else if (isPollMessage) {
|
|
1023
|
-
additionalNodes.push({
|
|
1024
|
-
tag: 'meta',
|
|
1025
|
-
attrs: {
|
|
1026
|
-
polltype: 'creation'
|
|
1027
|
-
},
|
|
840
|
+
logger,
|
|
841
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
842
|
+
}),
|
|
843
|
+
upload: async (readStream, opts) => {
|
|
844
|
+
const up = await waUploadToServer(readStream, {
|
|
845
|
+
...opts,
|
|
846
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
1028
847
|
});
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
|
|
848
|
+
return up;
|
|
849
|
+
},
|
|
850
|
+
mediaCache: config.mediaCache,
|
|
851
|
+
options: config.options,
|
|
852
|
+
...options
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
856
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
857
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
858
|
+
|
|
859
|
+
const additionalAttributes = {};
|
|
860
|
+
const additionalNodes = [];
|
|
861
|
+
|
|
862
|
+
if (isDeleteMsg) {
|
|
863
|
+
const fromMe = content.delete?.fromMe;
|
|
864
|
+
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
865
|
+
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
866
|
+
} else if (isEditMsg) {
|
|
867
|
+
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
868
|
+
} else if (isAiMsg) {
|
|
869
|
+
additionalNodes.push({
|
|
1033
870
|
attrs: {
|
|
1034
871
|
biz_bot: '1'
|
|
1035
872
|
}, tag: "bot"
|
|
1036
873
|
});
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
*/
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
await relayMessage(jid, fullMsg.message, {
|
|
877
|
+
messageId: fullMsg.key.id,
|
|
878
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
879
|
+
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
880
|
+
additionalAttributes,
|
|
881
|
+
statusJidList: options.statusJidList
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
if (config.emitOwnEvents) {
|
|
885
|
+
process.nextTick(() => {
|
|
886
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
return fullMsg;
|
|
1054
890
|
}
|
|
1055
|
-
}
|
|
891
|
+
}
|
|
1056
892
|
};
|
|
1057
893
|
exports.makeMessagesSocket = makeMessagesSocket;
|