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