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