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