@modzneverdie/baileys 17.1.12 → 17.1.17
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 +364 -0
- package/engine-requirements.js +4 -4
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +119 -78
- 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 +230 -45
- package/lib/Socket/chats.js +238 -139
- package/lib/Socket/{setup.ts → dugong.d.ts} +52 -17
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +23 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +399 -415
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +136 -71
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +617 -754
- 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 +14 -26
- 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 +97 -73
- package/lib/Types/Newsletter.js +38 -18
- 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 +84 -102
- 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 +236 -298
- package/lib/Utils/messages.d.ts +10 -8
- package/lib/Utils/messages.js +60 -304
- 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 -89
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -6
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +76 -20
- package/lib/WABinary/constants.d.ts +27 -24
- 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 +152 -137
- package/lib/WABinary/generic-utils.d.ts +4 -1
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +5 -10
- package/lib/WABinary/jid-utils.js +5 -26
- 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 +6 -20
- package/package.json +105 -107
- 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 -433
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -1,26 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
4
|
+
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
|
-
const node_cache_1 = __importDefault(require("
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
8
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
10
9
|
const WAProto_1 = require("../../WAProto");
|
|
11
10
|
const Defaults_1 = require("../Defaults");
|
|
11
|
+
const axios_1 = require("axios")
|
|
12
|
+
const Types_1 = require("../Types")
|
|
12
13
|
const Utils_1 = require("../Utils");
|
|
13
14
|
const link_preview_1 = require("../Utils/link-preview");
|
|
14
15
|
const WABinary_1 = require("../WABinary");
|
|
15
|
-
const WAUSync_1 = require("../WAUSync");
|
|
16
16
|
const newsletter_1 = require("./newsletter");
|
|
17
|
-
const
|
|
17
|
+
const WAUSync_1 = require("../WAUSync")
|
|
18
|
+
const kikyy = require('./dugong');
|
|
19
|
+
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
18
20
|
const makeMessagesSocket = (config) => {
|
|
19
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
logger,
|
|
23
|
+
linkPreviewImageThumbnailWidth,
|
|
24
|
+
generateHighQualityLinkPreview,
|
|
25
|
+
options: axiosOptions,
|
|
26
|
+
patchMessageBeforeSending
|
|
27
|
+
} = config;
|
|
20
28
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
21
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
ev,
|
|
31
|
+
authState,
|
|
32
|
+
processingMutex,
|
|
33
|
+
signalRepository,
|
|
34
|
+
upsertMessage,
|
|
35
|
+
query,
|
|
36
|
+
fetchPrivacySettings,
|
|
37
|
+
generateMessageTag,
|
|
38
|
+
sendNode,
|
|
39
|
+
groupMetadata,
|
|
40
|
+
groupToggleEphemeral,
|
|
41
|
+
executeUSyncQuery
|
|
42
|
+
} = sock;
|
|
22
43
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
23
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
44
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
24
45
|
useClones: false
|
|
25
46
|
});
|
|
26
47
|
let mediaConn;
|
|
@@ -37,9 +58,9 @@ const makeMessagesSocket = (config) => {
|
|
|
37
58
|
},
|
|
38
59
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
39
60
|
});
|
|
40
|
-
const mediaConnNode =
|
|
61
|
+
const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
|
|
41
62
|
const node = {
|
|
42
|
-
hosts:
|
|
63
|
+
hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
43
64
|
hostname: attrs.hostname,
|
|
44
65
|
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
45
66
|
})),
|
|
@@ -68,7 +89,7 @@ const makeMessagesSocket = (config) => {
|
|
|
68
89
|
if (isReadReceipt) {
|
|
69
90
|
node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
70
91
|
}
|
|
71
|
-
if (type === 'sender' &&
|
|
92
|
+
if (type === 'sender' && WABinary_1.isJidUser(jid)) {
|
|
72
93
|
node.attrs.recipient = jid;
|
|
73
94
|
node.attrs.to = participant;
|
|
74
95
|
}
|
|
@@ -79,7 +100,7 @@ const makeMessagesSocket = (config) => {
|
|
|
79
100
|
}
|
|
80
101
|
}
|
|
81
102
|
if (type) {
|
|
82
|
-
node.attrs.type =
|
|
103
|
+
node.attrs.type = WABinary_1.isJidNewsLetter(jid) ? 'read-self' : type;
|
|
83
104
|
}
|
|
84
105
|
const remainingMessageIds = messageIds.slice(1);
|
|
85
106
|
if (remainingMessageIds.length) {
|
|
@@ -113,54 +134,70 @@ const makeMessagesSocket = (config) => {
|
|
|
113
134
|
};
|
|
114
135
|
/** Fetch all the devices we've to send a message to */
|
|
115
136
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
116
|
-
|
|
117
|
-
|
|
137
|
+
const deviceResults = []
|
|
138
|
+
|
|
118
139
|
if (!useCache) {
|
|
119
|
-
logger.debug('not using cache for devices')
|
|
140
|
+
logger.debug('not using cache for devices')
|
|
120
141
|
}
|
|
121
|
-
|
|
122
|
-
|
|
142
|
+
|
|
143
|
+
const toFetch = []
|
|
144
|
+
|
|
145
|
+
jids = Array.from(new Set(jids))
|
|
146
|
+
|
|
123
147
|
for (let jid of jids) {
|
|
124
|
-
const user =
|
|
125
|
-
|
|
148
|
+
const user = WABinary_1.jidDecode(jid)?.user
|
|
149
|
+
|
|
150
|
+
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
+
|
|
126
152
|
if (useCache) {
|
|
127
|
-
const devices = userDevicesCache.get(user)
|
|
153
|
+
const devices = userDevicesCache.get(user)
|
|
154
|
+
|
|
128
155
|
if (devices) {
|
|
129
|
-
deviceResults.push(...devices)
|
|
130
|
-
logger.trace({ user }, 'using cache for devices')
|
|
156
|
+
deviceResults.push(...devices)
|
|
157
|
+
logger.trace({ user }, 'using cache for devices')
|
|
131
158
|
}
|
|
159
|
+
|
|
132
160
|
else {
|
|
133
|
-
toFetch.push(jid)
|
|
161
|
+
toFetch.push(jid)
|
|
134
162
|
}
|
|
135
163
|
}
|
|
164
|
+
|
|
136
165
|
else {
|
|
137
|
-
toFetch.push(jid)
|
|
166
|
+
toFetch.push(jid)
|
|
138
167
|
}
|
|
139
168
|
}
|
|
169
|
+
|
|
140
170
|
if (!toFetch.length) {
|
|
141
|
-
return deviceResults
|
|
171
|
+
return deviceResults
|
|
142
172
|
}
|
|
173
|
+
|
|
143
174
|
const query = new WAUSync_1.USyncQuery()
|
|
144
175
|
.withContext('message')
|
|
145
|
-
.withDeviceProtocol()
|
|
176
|
+
.withDeviceProtocol()
|
|
177
|
+
|
|
146
178
|
for (const jid of toFetch) {
|
|
147
|
-
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
179
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
148
180
|
}
|
|
149
|
-
|
|
181
|
+
|
|
182
|
+
const result = await executeUSyncQuery(query)
|
|
183
|
+
|
|
150
184
|
if (result) {
|
|
151
|
-
const extracted =
|
|
152
|
-
const deviceMap = {}
|
|
185
|
+
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
186
|
+
const deviceMap = {}
|
|
187
|
+
|
|
153
188
|
for (const item of extracted) {
|
|
154
|
-
deviceMap[item.user] = deviceMap[item.user] || []
|
|
155
|
-
deviceMap[item.user].push(item)
|
|
156
|
-
deviceResults.push(item)
|
|
189
|
+
deviceMap[item.user] = deviceMap[item.user] || []
|
|
190
|
+
deviceMap[item.user].push(item)
|
|
191
|
+
deviceResults.push(item)
|
|
157
192
|
}
|
|
193
|
+
|
|
158
194
|
for (const key in deviceMap) {
|
|
159
|
-
userDevicesCache.set(key, deviceMap[key])
|
|
195
|
+
userDevicesCache.set(key, deviceMap[key])
|
|
160
196
|
}
|
|
161
197
|
}
|
|
162
|
-
|
|
163
|
-
|
|
198
|
+
|
|
199
|
+
return deviceResults
|
|
200
|
+
}
|
|
164
201
|
const assertSessions = async (jids, force) => {
|
|
165
202
|
let didFetchNewSession = false;
|
|
166
203
|
let jidsRequiringFetch = [];
|
|
@@ -204,19 +241,20 @@ const makeMessagesSocket = (config) => {
|
|
|
204
241
|
}
|
|
205
242
|
return didFetchNewSession;
|
|
206
243
|
};
|
|
244
|
+
|
|
245
|
+
|
|
207
246
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
211
|
-
throw new boom_1.Boom('Not authenticated');
|
|
247
|
+
if (!authState.creds.me?.id) {
|
|
248
|
+
throw new boom_1.Boom('Not authenticated')
|
|
212
249
|
}
|
|
250
|
+
|
|
213
251
|
const protocolMessage = {
|
|
214
252
|
protocolMessage: {
|
|
215
253
|
peerDataOperationRequestMessage: pdoMessage,
|
|
216
254
|
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
217
255
|
}
|
|
218
256
|
};
|
|
219
|
-
const meJid =
|
|
257
|
+
const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
|
|
220
258
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
221
259
|
additionalAttributes: {
|
|
222
260
|
category: 'peer',
|
|
@@ -227,17 +265,10 @@ const makeMessagesSocket = (config) => {
|
|
|
227
265
|
return msgId;
|
|
228
266
|
};
|
|
229
267
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
|
|
233
|
-
}
|
|
268
|
+
const patched = await patchMessageBeforeSending(message, jids);
|
|
269
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
234
270
|
let shouldIncludeDeviceIdentity = false;
|
|
235
|
-
const nodes = await Promise.all(
|
|
236
|
-
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
|
|
237
|
-
if (!jid) {
|
|
238
|
-
return {};
|
|
239
|
-
}
|
|
240
|
-
const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
|
|
271
|
+
const nodes = await Promise.all(jids.map(async (jid) => {
|
|
241
272
|
const { type, ciphertext } = await signalRepository
|
|
242
273
|
.encryptMessage({ jid, data: bytes });
|
|
243
274
|
if (type === 'pkmsg') {
|
|
@@ -259,32 +290,34 @@ const makeMessagesSocket = (config) => {
|
|
|
259
290
|
return node;
|
|
260
291
|
}));
|
|
261
292
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
262
|
-
};
|
|
263
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
264
|
-
var _a;
|
|
293
|
+
}; //apela
|
|
294
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
265
295
|
const meId = authState.creds.me.id;
|
|
266
296
|
let shouldIncludeDeviceIdentity = false;
|
|
267
|
-
|
|
297
|
+
let didPushAdditional = false
|
|
298
|
+
const { user, server } = WABinary_1.jidDecode(jid);
|
|
268
299
|
const statusJid = 'status@broadcast';
|
|
269
300
|
const isGroup = server === 'g.us';
|
|
270
|
-
const isNewsletter = server === 'newsletter';
|
|
271
301
|
const isStatus = jid === statusJid;
|
|
272
302
|
const isLid = server === 'lid';
|
|
273
|
-
|
|
303
|
+
const isPrivate = server === 's.whatsapp.net'
|
|
304
|
+
const isNewsletter = server === 'newsletter';
|
|
305
|
+
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
274
306
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
275
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
307
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
276
308
|
const participants = [];
|
|
277
|
-
const destinationJid = (!isStatus) ?
|
|
309
|
+
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
278
310
|
const binaryNodeContent = [];
|
|
279
311
|
const devices = [];
|
|
280
312
|
const meMsg = {
|
|
281
313
|
deviceSentMessage: {
|
|
282
314
|
destinationJid,
|
|
283
315
|
message
|
|
284
|
-
}
|
|
285
|
-
messageContextInfo: message.messageContextInfo
|
|
316
|
+
}
|
|
286
317
|
};
|
|
287
|
-
const extraAttrs = {}
|
|
318
|
+
const extraAttrs = {}
|
|
319
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
320
|
+
const buttonType = getButtonType(messages);
|
|
288
321
|
if (participant) {
|
|
289
322
|
// when the retry request is not for a group
|
|
290
323
|
// only send to the specific device that asked for a retry
|
|
@@ -292,67 +325,80 @@ const makeMessagesSocket = (config) => {
|
|
|
292
325
|
if (!isGroup && !isStatus) {
|
|
293
326
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
294
327
|
}
|
|
295
|
-
const { user, device } =
|
|
328
|
+
const { user, device } = WABinary_1.jidDecode(participant.jid);
|
|
296
329
|
devices.push({ user, device });
|
|
297
330
|
}
|
|
298
331
|
await authState.keys.transaction(async () => {
|
|
299
|
-
|
|
300
|
-
|
|
332
|
+
const mediaType = getMediaType(messages);
|
|
333
|
+
|
|
301
334
|
if (mediaType) {
|
|
302
|
-
extraAttrs['mediatype'] = mediaType
|
|
335
|
+
extraAttrs['mediatype'] = mediaType
|
|
303
336
|
}
|
|
304
|
-
|
|
305
|
-
|
|
337
|
+
|
|
338
|
+
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
339
|
+
extraAttrs['decrypt-fail'] = 'hide'
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
343
|
+
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
306
344
|
}
|
|
345
|
+
|
|
307
346
|
if (isGroup || isStatus) {
|
|
308
347
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
309
348
|
(async () => {
|
|
310
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
311
|
-
if (groupData
|
|
349
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
350
|
+
if (groupData) {
|
|
312
351
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
313
352
|
}
|
|
353
|
+
|
|
314
354
|
else if (!isStatus) {
|
|
315
|
-
groupData = await groupMetadata(jid)
|
|
355
|
+
groupData = await groupMetadata(jid)
|
|
316
356
|
}
|
|
357
|
+
|
|
317
358
|
return groupData;
|
|
318
359
|
})(),
|
|
319
360
|
(async () => {
|
|
320
361
|
if (!participant && !isStatus) {
|
|
321
|
-
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
322
|
-
return result[jid] || {}
|
|
362
|
+
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
|
+
return result[jid] || {}
|
|
323
364
|
}
|
|
324
|
-
|
|
325
|
-
|
|
365
|
+
|
|
366
|
+
return {}
|
|
367
|
+
|
|
368
|
+
})()
|
|
326
369
|
]);
|
|
327
370
|
if (!participant) {
|
|
328
|
-
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
371
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
+
|
|
329
373
|
if (isStatus && statusJidList) {
|
|
330
|
-
participantsList.push(...statusJidList)
|
|
374
|
+
participantsList.push(...statusJidList)
|
|
331
375
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
376
|
+
|
|
377
|
+
// if (!isStatus) {
|
|
378
|
+
// const expiration = await getEphemeralGroup(jid)
|
|
379
|
+
// additionalAttributes = {
|
|
380
|
+
// ...additionalAttributes,
|
|
381
|
+
// addressing_mode: 'pn',
|
|
382
|
+
// ...expiration ? { expiration: expiration.toString() } : null
|
|
383
|
+
// }
|
|
384
|
+
// }
|
|
385
|
+
|
|
386
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
387
|
+
devices.push(...additionalDevices)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
391
|
+
const bytes = Utils_1.encodeWAMessage(patched);
|
|
392
|
+
|
|
347
393
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
348
394
|
group: destinationJid,
|
|
349
395
|
data: bytes,
|
|
350
396
|
meId,
|
|
351
397
|
});
|
|
352
398
|
const senderKeyJids = [];
|
|
353
|
-
|
|
399
|
+
|
|
354
400
|
for (const { user, device } of devices) {
|
|
355
|
-
const jid =
|
|
401
|
+
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
356
402
|
if (!senderKeyMap[jid] || !!participant) {
|
|
357
403
|
senderKeyJids.push(jid);
|
|
358
404
|
// store that this person has had the sender keys sent to them
|
|
@@ -370,107 +416,115 @@ const makeMessagesSocket = (config) => {
|
|
|
370
416
|
}
|
|
371
417
|
};
|
|
372
418
|
await assertSessions(senderKeyJids, false);
|
|
373
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
419
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
374
420
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
375
421
|
participants.push(...result.nodes);
|
|
376
422
|
}
|
|
377
423
|
binaryNodeContent.push({
|
|
378
424
|
tag: 'enc',
|
|
379
|
-
attrs: { v: '2', type: 'skmsg' },
|
|
425
|
+
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
380
426
|
content: ciphertext
|
|
381
427
|
});
|
|
382
428
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
383
429
|
}
|
|
384
430
|
else if (isNewsletter) {
|
|
385
431
|
// Message edit
|
|
386
|
-
if (
|
|
387
|
-
msgId =
|
|
388
|
-
message = message.protocolMessage.editedMessage
|
|
432
|
+
if (message.protocolMessage?.editedMessage) {
|
|
433
|
+
msgId = message.protocolMessage.key?.id
|
|
434
|
+
message = message.protocolMessage.editedMessage
|
|
389
435
|
}
|
|
436
|
+
|
|
390
437
|
// Message delete
|
|
391
|
-
if (
|
|
392
|
-
msgId =
|
|
393
|
-
message = {}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
438
|
+
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
439
|
+
msgId = message.protocolMessage.key?.id
|
|
440
|
+
message = {}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const patched = await patchMessageBeforeSending(message, [])
|
|
444
|
+
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
445
|
+
|
|
400
446
|
binaryNodeContent.push({
|
|
401
447
|
tag: 'plaintext',
|
|
402
|
-
attrs:
|
|
448
|
+
attrs: extraAttrs ? extraAttrs : {},
|
|
403
449
|
content: bytes
|
|
404
|
-
})
|
|
450
|
+
})
|
|
405
451
|
}
|
|
406
452
|
else {
|
|
407
|
-
const { user: meUser } =
|
|
453
|
+
const { user: meUser } = WABinary_1.jidDecode(meId);
|
|
408
454
|
if (!participant) {
|
|
409
|
-
devices.push({ user })
|
|
455
|
+
devices.push({ user })
|
|
410
456
|
if (user !== meUser) {
|
|
411
|
-
devices.push({ user: meUser })
|
|
457
|
+
devices.push({ user: meUser })
|
|
412
458
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
459
|
+
|
|
460
|
+
if (additionalAttributes?.['category'] !== 'peer') {
|
|
461
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
462
|
+
|
|
463
|
+
devices.push(...additionalDevices)
|
|
416
464
|
}
|
|
417
465
|
}
|
|
418
466
|
const allJids = [];
|
|
419
467
|
const meJids = [];
|
|
420
468
|
const otherJids = [];
|
|
421
469
|
for (const { user, device } of devices) {
|
|
422
|
-
const isMe = user === meUser
|
|
423
|
-
const jid =
|
|
470
|
+
const isMe = user === meUser
|
|
471
|
+
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
472
|
+
|
|
424
473
|
if (isMe) {
|
|
425
|
-
meJids.push(jid)
|
|
474
|
+
meJids.push(jid)
|
|
426
475
|
}
|
|
476
|
+
|
|
427
477
|
else {
|
|
428
|
-
otherJids.push(jid)
|
|
478
|
+
otherJids.push(jid)
|
|
429
479
|
}
|
|
430
|
-
|
|
480
|
+
|
|
481
|
+
allJids.push(jid)
|
|
431
482
|
}
|
|
432
483
|
await assertSessions(allJids, false);
|
|
433
484
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
434
485
|
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
435
486
|
createParticipantNodes(otherJids, message, extraAttrs)
|
|
436
|
-
])
|
|
487
|
+
])
|
|
437
488
|
participants.push(...meNodes);
|
|
438
489
|
participants.push(...otherNodes);
|
|
439
490
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
440
491
|
}
|
|
441
492
|
if (participants.length) {
|
|
442
|
-
if (
|
|
443
|
-
const peerNode =
|
|
493
|
+
if (additionalAttributes?.['category'] === 'peer') {
|
|
494
|
+
const peerNode = participants[0]?.content?.[0]
|
|
495
|
+
|
|
444
496
|
if (peerNode) {
|
|
445
|
-
binaryNodeContent.push(peerNode)
|
|
497
|
+
binaryNodeContent.push(peerNode) // push only enc
|
|
446
498
|
}
|
|
447
499
|
}
|
|
500
|
+
|
|
448
501
|
else {
|
|
449
502
|
binaryNodeContent.push({
|
|
450
503
|
tag: 'participants',
|
|
451
504
|
attrs: {},
|
|
452
505
|
content: participants
|
|
453
|
-
})
|
|
506
|
+
})
|
|
454
507
|
}
|
|
455
508
|
}
|
|
509
|
+
|
|
456
510
|
const stanza = {
|
|
457
511
|
tag: 'message',
|
|
458
512
|
attrs: {
|
|
459
513
|
id: msgId,
|
|
460
|
-
type:
|
|
514
|
+
type: getTypeMessage(messages),
|
|
461
515
|
...(additionalAttributes || {})
|
|
462
516
|
},
|
|
463
517
|
content: binaryNodeContent
|
|
464
|
-
}
|
|
518
|
+
}
|
|
465
519
|
// if the participant to send to is explicitly specified (generally retry recp)
|
|
466
520
|
// ensure the message is only sent to that person
|
|
467
521
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
468
522
|
if (participant) {
|
|
469
|
-
if (
|
|
523
|
+
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
470
524
|
stanza.attrs.to = destinationJid;
|
|
471
525
|
stanza.attrs.participant = participant.jid;
|
|
472
526
|
}
|
|
473
|
-
else if (
|
|
527
|
+
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
474
528
|
stanza.attrs.to = participant.jid;
|
|
475
529
|
stanza.attrs.recipient = destinationJid;
|
|
476
530
|
}
|
|
@@ -489,123 +543,162 @@ const makeMessagesSocket = (config) => {
|
|
|
489
543
|
});
|
|
490
544
|
logger.debug({ jid }, 'adding device identity');
|
|
491
545
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
contentType === 'listMessage')) {
|
|
500
|
-
const bizNode = { tag: 'biz', attrs: {} };
|
|
501
|
-
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))) {
|
|
502
|
-
bizNode.content = [{
|
|
503
|
-
tag: 'interactive',
|
|
504
|
-
attrs: {
|
|
505
|
-
type: 'native_flow',
|
|
506
|
-
v: '1'
|
|
507
|
-
},
|
|
508
|
-
content: [{
|
|
509
|
-
tag: 'native_flow',
|
|
510
|
-
attrs: { v: '9', name: 'mixed' }
|
|
511
|
-
}]
|
|
512
|
-
}];
|
|
546
|
+
|
|
547
|
+
if (AI && isPrivate) {
|
|
548
|
+
const botNode = {
|
|
549
|
+
tag: 'bot',
|
|
550
|
+
attrs: {
|
|
551
|
+
biz_bot: '1'
|
|
552
|
+
}
|
|
513
553
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
554
|
+
|
|
555
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
556
|
+
|
|
557
|
+
if (filteredBizBot) {
|
|
558
|
+
stanza.content.push(...additionalNodes)
|
|
559
|
+
didPushAdditional = true
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
else {
|
|
563
|
+
stanza.content.push(botNode)
|
|
523
564
|
}
|
|
524
|
-
stanza.content.push(bizNode);
|
|
525
565
|
}
|
|
566
|
+
|
|
567
|
+
if(!isNewsletter && buttonType && !isStatus) {
|
|
568
|
+
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
569
|
+
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
570
|
+
|
|
571
|
+
if (filteredNode) {
|
|
572
|
+
didPushAdditional = true
|
|
573
|
+
stanza.content.push(...additionalNodes)
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
stanza.content.push(...content)
|
|
577
|
+
}
|
|
578
|
+
logger.debug({ jid }, 'adding business node')
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
582
|
+
stanza.content.push(...additionalNodes);
|
|
583
|
+
}
|
|
584
|
+
|
|
526
585
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
527
586
|
await sendNode(stanza);
|
|
528
587
|
});
|
|
529
|
-
|
|
588
|
+
|
|
589
|
+
message = Types_1.WAProto.Message.fromObject(message)
|
|
590
|
+
|
|
591
|
+
const messageJSON = {
|
|
592
|
+
key: {
|
|
593
|
+
remoteJid: jid,
|
|
594
|
+
fromMe: true,
|
|
595
|
+
id: msgId
|
|
596
|
+
},
|
|
597
|
+
message: message,
|
|
598
|
+
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
599
|
+
messageStubParameters: [],
|
|
600
|
+
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
601
|
+
status: Types_1.WAMessageStatus.PENDING
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
605
|
+
// return msgId;
|
|
530
606
|
};
|
|
531
607
|
const getTypeMessage = (msg) => {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
540
|
-
}
|
|
541
|
-
else if (msg.ephemeralMessage) {
|
|
542
|
-
return getTypeMessage(msg.ephemeralMessage.message);
|
|
543
|
-
}
|
|
544
|
-
else if (msg.documentWithCaptionMessage) {
|
|
545
|
-
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
546
|
-
}
|
|
547
|
-
else if (msg.reactionMessage) {
|
|
548
|
-
return 'reaction';
|
|
549
|
-
}
|
|
550
|
-
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
551
|
-
return 'poll';
|
|
552
|
-
}
|
|
553
|
-
else if (getMediaType(msg)) {
|
|
554
|
-
return 'media';
|
|
555
|
-
}
|
|
608
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
609
|
+
if (message.reactionMessage) {
|
|
610
|
+
return 'reaction'
|
|
611
|
+
}
|
|
612
|
+
else if (getMediaType(message)) {
|
|
613
|
+
return 'media'
|
|
614
|
+
}
|
|
556
615
|
else {
|
|
557
|
-
return 'text'
|
|
616
|
+
return 'text'
|
|
558
617
|
}
|
|
559
|
-
}
|
|
618
|
+
}
|
|
619
|
+
|
|
560
620
|
const getMediaType = (message) => {
|
|
561
621
|
if (message.imageMessage) {
|
|
562
|
-
return 'image'
|
|
622
|
+
return 'image'
|
|
563
623
|
}
|
|
564
624
|
else if (message.videoMessage) {
|
|
565
|
-
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
625
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
566
626
|
}
|
|
567
627
|
else if (message.audioMessage) {
|
|
568
|
-
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
628
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
569
629
|
}
|
|
570
630
|
else if (message.contactMessage) {
|
|
571
|
-
return 'vcard'
|
|
631
|
+
return 'vcard'
|
|
572
632
|
}
|
|
573
633
|
else if (message.documentMessage) {
|
|
574
|
-
return 'document'
|
|
634
|
+
return 'document'
|
|
575
635
|
}
|
|
576
636
|
else if (message.contactsArrayMessage) {
|
|
577
|
-
return 'contact_array'
|
|
637
|
+
return 'contact_array'
|
|
578
638
|
}
|
|
579
639
|
else if (message.liveLocationMessage) {
|
|
580
|
-
return 'livelocation'
|
|
640
|
+
return 'livelocation'
|
|
581
641
|
}
|
|
582
642
|
else if (message.stickerMessage) {
|
|
583
|
-
return 'sticker'
|
|
643
|
+
return 'sticker'
|
|
584
644
|
}
|
|
585
645
|
else if (message.listMessage) {
|
|
586
|
-
return 'list'
|
|
646
|
+
return 'list'
|
|
587
647
|
}
|
|
588
648
|
else if (message.listResponseMessage) {
|
|
589
|
-
return 'list_response'
|
|
649
|
+
return 'list_response'
|
|
590
650
|
}
|
|
591
651
|
else if (message.buttonsResponseMessage) {
|
|
592
|
-
return 'buttons_response'
|
|
652
|
+
return 'buttons_response'
|
|
593
653
|
}
|
|
594
654
|
else if (message.orderMessage) {
|
|
595
|
-
return 'order'
|
|
655
|
+
return 'order'
|
|
596
656
|
}
|
|
597
657
|
else if (message.productMessage) {
|
|
598
|
-
return 'product'
|
|
658
|
+
return 'product'
|
|
599
659
|
}
|
|
600
660
|
else if (message.interactiveResponseMessage) {
|
|
601
|
-
return 'native_flow_response'
|
|
661
|
+
return 'native_flow_response'
|
|
602
662
|
}
|
|
603
663
|
else if (message.groupInviteMessage) {
|
|
604
|
-
return 'url'
|
|
664
|
+
return 'url'
|
|
605
665
|
}
|
|
606
|
-
|
|
666
|
+
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
667
|
+
return 'productlink'
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const getButtonType = (message) => {
|
|
672
|
+
if (message.listMessage) {
|
|
673
|
+
return 'list'
|
|
674
|
+
}
|
|
675
|
+
else if (message.buttonsMessage) {
|
|
676
|
+
return 'buttons'
|
|
677
|
+
}
|
|
678
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
|
|
679
|
+
return 'review_and_pay'
|
|
680
|
+
}
|
|
681
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
|
|
682
|
+
return 'review_order'
|
|
683
|
+
}
|
|
684
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
685
|
+
return 'payment_info'
|
|
686
|
+
}
|
|
687
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
688
|
+
return 'payment_status'
|
|
689
|
+
}
|
|
690
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
691
|
+
return 'payment_method'
|
|
692
|
+
}
|
|
693
|
+
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
694
|
+
return 'interactive'
|
|
695
|
+
}
|
|
696
|
+
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
697
|
+
return 'native_flow'
|
|
698
|
+
}
|
|
699
|
+
}
|
|
607
700
|
const getPrivacyTokens = async (jids) => {
|
|
608
|
-
const t =
|
|
701
|
+
const t = Utils_1.unixTimestampSeconds().toString();
|
|
609
702
|
const result = await query({
|
|
610
703
|
tag: 'iq',
|
|
611
704
|
attrs: {
|
|
@@ -620,7 +713,7 @@ const makeMessagesSocket = (config) => {
|
|
|
620
713
|
content: jids.map(jid => ({
|
|
621
714
|
tag: 'token',
|
|
622
715
|
attrs: {
|
|
623
|
-
jid:
|
|
716
|
+
jid: WABinary_1.jidNormalizedUser(jid),
|
|
624
717
|
t,
|
|
625
718
|
type: 'trusted_contact'
|
|
626
719
|
}
|
|
@@ -629,9 +722,9 @@ const makeMessagesSocket = (config) => {
|
|
|
629
722
|
]
|
|
630
723
|
});
|
|
631
724
|
return result;
|
|
632
|
-
}
|
|
725
|
+
}
|
|
633
726
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
634
|
-
const
|
|
727
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
635
728
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
636
729
|
return {
|
|
637
730
|
...sock,
|
|
@@ -640,23 +733,23 @@ const makeMessagesSocket = (config) => {
|
|
|
640
733
|
relayMessage,
|
|
641
734
|
sendReceipt,
|
|
642
735
|
sendReceipts,
|
|
643
|
-
|
|
736
|
+
rahmi,
|
|
644
737
|
readMessages,
|
|
645
738
|
refreshMediaConn,
|
|
646
|
-
waUploadToServer,
|
|
647
|
-
fetchPrivacySettings,
|
|
648
739
|
getUSyncDevices,
|
|
649
740
|
createParticipantNodes,
|
|
741
|
+
waUploadToServer,
|
|
650
742
|
sendPeerDataOperationMessage,
|
|
743
|
+
fetchPrivacySettings,
|
|
651
744
|
updateMediaMessage: async (message) => {
|
|
652
745
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
653
746
|
const mediaKey = content.mediaKey;
|
|
654
747
|
const meId = authState.creds.me.id;
|
|
655
|
-
const node =
|
|
748
|
+
const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
656
749
|
let error = undefined;
|
|
657
750
|
await Promise.all([
|
|
658
751
|
sendNode(node),
|
|
659
|
-
waitForMsgMediaUpdate(
|
|
752
|
+
waitForMsgMediaUpdate(update => {
|
|
660
753
|
const result = update.find(c => c.key.id === message.key.id);
|
|
661
754
|
if (result) {
|
|
662
755
|
if (result.error) {
|
|
@@ -664,7 +757,7 @@ const makeMessagesSocket = (config) => {
|
|
|
664
757
|
}
|
|
665
758
|
else {
|
|
666
759
|
try {
|
|
667
|
-
const media =
|
|
760
|
+
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
668
761
|
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
669
762
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
670
763
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
@@ -685,241 +778,132 @@ const makeMessagesSocket = (config) => {
|
|
|
685
778
|
throw error;
|
|
686
779
|
}
|
|
687
780
|
ev.emit('messages.update', [
|
|
688
|
-
{
|
|
781
|
+
{
|
|
782
|
+
key: message.key,
|
|
783
|
+
update: {
|
|
784
|
+
message: message.message
|
|
785
|
+
}
|
|
786
|
+
}
|
|
689
787
|
]);
|
|
690
788
|
return message;
|
|
691
789
|
},
|
|
692
790
|
sendMessage: async (jid, content, options = {}) => {
|
|
693
|
-
var _a, _b, _c;
|
|
694
791
|
const userJid = authState.creds.me.id;
|
|
695
|
-
|
|
792
|
+
delete options.ephemeralExpiration
|
|
696
793
|
const { filter = false, quoted } = options;
|
|
697
|
-
const
|
|
698
|
-
|
|
794
|
+
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
795
|
+
const messageType = rahmi.detectType(content);
|
|
796
|
+
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
797
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
798
|
+
const { disappearingMessagesInChat } = content
|
|
799
|
+
|
|
800
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
801
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
802
|
+
disappearingMessagesInChat
|
|
803
|
+
|
|
804
|
+
await groupToggleEphemeral(jid, value)
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
else {
|
|
808
|
+
let mediaHandle
|
|
809
|
+
|
|
810
|
+
|
|
699
811
|
if (messageType) {
|
|
700
|
-
switch
|
|
812
|
+
switch(messageType) {
|
|
701
813
|
case 'PAYMENT':
|
|
702
|
-
const paymentContent = await
|
|
814
|
+
const paymentContent = await rahmi.handlePayment(content, quoted);
|
|
703
815
|
return await relayMessage(jid, paymentContent, {
|
|
704
816
|
messageId: Utils_1.generateMessageID(),
|
|
705
817
|
...getParticipantAttr()
|
|
706
818
|
});
|
|
707
|
-
|
|
819
|
+
|
|
708
820
|
case 'PRODUCT':
|
|
709
|
-
const productContent = await
|
|
821
|
+
const productContent = await rahmi.handleProduct(content, jid, quoted);
|
|
710
822
|
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
711
823
|
return await relayMessage(jid, productMsg.message, {
|
|
712
824
|
messageId: productMsg.key.id,
|
|
713
825
|
...getParticipantAttr()
|
|
714
826
|
});
|
|
715
|
-
|
|
827
|
+
|
|
716
828
|
case 'INTERACTIVE':
|
|
717
|
-
const interactiveContent = await
|
|
829
|
+
const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
|
|
718
830
|
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
719
831
|
return await relayMessage(jid, interactiveMsg.message, {
|
|
720
832
|
messageId: interactiveMsg.key.id,
|
|
721
833
|
...getParticipantAttr()
|
|
722
834
|
});
|
|
723
|
-
|
|
724
835
|
case 'ALBUM':
|
|
725
|
-
|
|
726
|
-
return albumContent;
|
|
727
|
-
|
|
836
|
+
return await rahmi.handleAlbum(content, jid, quoted)
|
|
728
837
|
case 'EVENT':
|
|
729
|
-
return await
|
|
730
|
-
|
|
838
|
+
return await rahmi.handleEvent(content, jid, quoted)
|
|
731
839
|
case 'POLL_RESULT':
|
|
732
|
-
return await
|
|
840
|
+
return await rahmi.handlePollResult(content, jid, quoted)
|
|
841
|
+
case 'GROUP_STORY':
|
|
842
|
+
return await rahmi.handleGroupStory(content, jid, quoted)
|
|
733
843
|
}
|
|
734
844
|
}
|
|
845
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
846
|
+
logger,
|
|
847
|
+
userJid,
|
|
848
|
+
quoted,
|
|
849
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
850
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
851
|
+
fetchOpts: {
|
|
852
|
+
timeout: 3000,
|
|
853
|
+
...axiosOptions || {}
|
|
854
|
+
},
|
|
855
|
+
logger,
|
|
856
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
857
|
+
}),
|
|
858
|
+
upload: async (readStream, opts) => {
|
|
859
|
+
const up = await waUploadToServer(readStream, {
|
|
860
|
+
...opts,
|
|
861
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
862
|
+
});
|
|
863
|
+
return up;
|
|
864
|
+
},
|
|
865
|
+
mediaCache: config.mediaCache,
|
|
866
|
+
options: config.options,
|
|
867
|
+
...options
|
|
868
|
+
});
|
|
735
869
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
audio: content.audio,
|
|
740
|
-
mimetype: content.mimetype,
|
|
741
|
-
ptt: true
|
|
742
|
-
};
|
|
743
|
-
}
|
|
870
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
871
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
872
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
744
873
|
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
'disappearingMessagesInChat' in content &&
|
|
760
|
-
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
761
|
-
(0, WABinary_1.isJidGroup)(jid)) {
|
|
762
|
-
const { disappearingMessagesInChat } = content;
|
|
763
|
-
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
764
|
-
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
765
|
-
disappearingMessagesInChat;
|
|
766
|
-
await groupToggleEphemeral(jid, value);
|
|
767
|
-
}
|
|
768
|
-
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
769
|
-
const { album, caption } = content;
|
|
770
|
-
if (caption && !album[0].caption) {
|
|
771
|
-
album[0].caption = caption;
|
|
772
|
-
}
|
|
773
|
-
let mediaHandle;
|
|
774
|
-
let mediaMsg;
|
|
775
|
-
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
776
|
-
albumMessage: {
|
|
777
|
-
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
778
|
-
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
779
|
-
}
|
|
780
|
-
}, { userJid, ...options });
|
|
781
|
-
await relayMessage(jid, albumMsg.message, {
|
|
782
|
-
messageId: albumMsg.key.id
|
|
874
|
+
const additionalAttributes = {};
|
|
875
|
+
const additionalNodes = [];
|
|
876
|
+
|
|
877
|
+
if (isDeleteMsg) {
|
|
878
|
+
const fromMe = content.delete?.fromMe;
|
|
879
|
+
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
880
|
+
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
881
|
+
} else if (isEditMsg) {
|
|
882
|
+
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
883
|
+
} else if (isAiMsg) {
|
|
884
|
+
additionalNodes.push({
|
|
885
|
+
attrs: {
|
|
886
|
+
biz_bot: '1'
|
|
887
|
+
}, tag: "bot"
|
|
783
888
|
});
|
|
784
|
-
for (const i in album) {
|
|
785
|
-
const media = album[i];
|
|
786
|
-
if ('image' in media) {
|
|
787
|
-
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
788
|
-
image: media.image,
|
|
789
|
-
...(media.caption ? { caption: media.caption } : {}),
|
|
790
|
-
...options
|
|
791
|
-
}, {
|
|
792
|
-
userJid,
|
|
793
|
-
upload: async (readStream, opts) => {
|
|
794
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
795
|
-
mediaHandle = up.handle;
|
|
796
|
-
return up;
|
|
797
|
-
},
|
|
798
|
-
...options,
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
else if ('video' in media) {
|
|
802
|
-
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
803
|
-
video: media.video,
|
|
804
|
-
...(media.caption ? { caption: media.caption } : {}),
|
|
805
|
-
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
806
|
-
...options
|
|
807
|
-
}, {
|
|
808
|
-
userJid,
|
|
809
|
-
upload: async (readStream, opts) => {
|
|
810
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
811
|
-
mediaHandle = up.handle;
|
|
812
|
-
return up;
|
|
813
|
-
},
|
|
814
|
-
...options,
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
if (mediaMsg) {
|
|
818
|
-
mediaMsg.message.messageContextInfo = {
|
|
819
|
-
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
820
|
-
messageAssociation: {
|
|
821
|
-
associationType: 1,
|
|
822
|
-
parentMessageKey: albumMsg.key
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
await relayMessage(jid, mediaMsg.message, {
|
|
827
|
-
messageId: mediaMsg.key.id
|
|
828
|
-
});
|
|
829
|
-
await new Promise(resolve => setTimeout(resolve, 800));
|
|
830
|
-
}
|
|
831
|
-
return albumMsg;
|
|
832
889
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
uploadImage: generateHighQualityLinkPreview
|
|
846
|
-
? waUploadToServer
|
|
847
|
-
: undefined
|
|
848
|
-
}),
|
|
849
|
-
getProfilePicUrl: sock.profilePictureUrl,
|
|
850
|
-
upload: async (readStream, opts) => {
|
|
851
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
852
|
-
mediaHandle = up.handle;
|
|
853
|
-
return up;
|
|
854
|
-
},
|
|
855
|
-
mediaCache: config.mediaCache,
|
|
856
|
-
options: config.options,
|
|
857
|
-
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
|
|
858
|
-
...options,
|
|
890
|
+
|
|
891
|
+
await relayMessage(jid, fullMsg.message, {
|
|
892
|
+
messageId: fullMsg.key.id,
|
|
893
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
894
|
+
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
895
|
+
additionalAttributes,
|
|
896
|
+
statusJidList: options.statusJidList
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
if (config.emitOwnEvents) {
|
|
900
|
+
process.nextTick(() => {
|
|
901
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
859
902
|
});
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
const isPinMsg = 'pin' in content && !!content.pin;
|
|
863
|
-
const isKeepMsg = 'keep' in content && content.keep;
|
|
864
|
-
const isPollMessage = 'poll' in content && !!content.poll;
|
|
865
|
-
const isAiMsg = 'ai' in content && !!content.ai;
|
|
866
|
-
const additionalAttributes = {};
|
|
867
|
-
const additionalNodes = [];
|
|
868
|
-
// required for delete
|
|
869
|
-
if (isDeleteMsg) {
|
|
870
|
-
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
871
|
-
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
872
|
-
additionalAttributes.edit = '8';
|
|
873
|
-
}
|
|
874
|
-
else {
|
|
875
|
-
additionalAttributes.edit = '7';
|
|
876
|
-
}
|
|
877
|
-
// required for edit message
|
|
878
|
-
}
|
|
879
|
-
else if (isEditMsg) {
|
|
880
|
-
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
881
|
-
// required for pin message
|
|
882
|
-
}
|
|
883
|
-
else if (isPinMsg) {
|
|
884
|
-
additionalAttributes.edit = '2';
|
|
885
|
-
// required for keep message
|
|
886
|
-
}
|
|
887
|
-
else if (isKeepMsg) {
|
|
888
|
-
additionalAttributes.edit = '6';
|
|
889
|
-
// required for polling message
|
|
890
|
-
}
|
|
891
|
-
else if (isPollMessage) {
|
|
892
|
-
additionalNodes.push({
|
|
893
|
-
tag: 'meta',
|
|
894
|
-
attrs: {
|
|
895
|
-
polltype: 'creation'
|
|
896
|
-
},
|
|
897
|
-
});
|
|
898
|
-
// required to display AI icon on message
|
|
899
|
-
}
|
|
900
|
-
else if (isAiMsg) {
|
|
901
|
-
additionalNodes.push({
|
|
902
|
-
attrs: {
|
|
903
|
-
biz_bot: '1'
|
|
904
|
-
},
|
|
905
|
-
tag: "bot"
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
if (mediaHandle) {
|
|
909
|
-
additionalAttributes['media_id'] = mediaHandle;
|
|
910
|
-
}
|
|
911
|
-
if ('cachedGroupMetadata' in options) {
|
|
912
|
-
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
913
|
-
}
|
|
914
|
-
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
|
|
915
|
-
if (config.emitOwnEvents) {
|
|
916
|
-
process.nextTick(() => {
|
|
917
|
-
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
return fullMsg;
|
|
903
|
+
}
|
|
904
|
+
return fullMsg;
|
|
921
905
|
}
|
|
922
906
|
}
|
|
923
|
-
}
|
|
907
|
+
}
|
|
924
908
|
};
|
|
925
909
|
exports.makeMessagesSocket = makeMessagesSocket;
|