@zetagoaurum-socket/wasocket 2.2.2 → 3.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/README.md +84 -67
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +3344 -0
- package/WAProto/index.d.ts +37016 -0
- package/WAProto/index.js +79296 -118676
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -6
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +9 -50
- package/lib/Signal/libsignal.js +29 -51
- package/lib/Socket/business.d.ts +2 -3
- package/lib/Socket/chats.d.ts +28 -215
- package/lib/Socket/chats.js +70 -185
- package/lib/Socket/dugong.js +141 -432
- package/lib/Socket/groups.js +23 -20
- package/lib/Socket/index.js +15 -2
- package/lib/Socket/messages-recv.d.ts +55 -56
- package/lib/Socket/messages-recv.js +112 -370
- package/lib/Socket/messages-send.d.ts +2 -3
- package/lib/Socket/messages-send.js +368 -465
- package/lib/Socket/newsletter.js +28 -175
- package/lib/Socket/socket.js +174 -203
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +0 -1
- package/lib/Types/Newsletter.d.ts +86 -97
- package/lib/Types/Newsletter.js +32 -38
- package/lib/Utils/chat-utils.js +3 -17
- package/lib/Utils/generics.js +31 -68
- package/lib/Utils/history.js +1 -6
- package/lib/Utils/link-preview.js +2 -4
- package/lib/Utils/messages-media.js +57 -145
- package/lib/Utils/messages.js +305 -89
- package/lib/Utils/signal.js +46 -48
- package/lib/Utils/use-multi-file-auth-state.js +6 -45
- package/lib/Utils/validate-connection.js +65 -91
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/encode.js +123 -160
- package/lib/WABinary/generic-utils.d.ts +0 -2
- package/lib/WABinary/generic-utils.js +36 -124
- package/lib/WABinary/jid-utils.js +26 -5
- package/lib/WAUSync/Fall +1 -0
- package/lib/WAUSync/Protocols/Fal +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -9
- package/package.json +100 -105
- package/engine-requirements.js +0 -10
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group-session-builder.js +0 -64
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.js +0 -96
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/index.js +0 -57
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/keyhelper.js +0 -55
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-chain-key.js +0 -34
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-name.js +0 -51
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-record.js +0 -53
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-key-state.js +0 -99
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Socket/chats.js.bak +0 -981
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/Utils/anti-crash.js +0 -20
- package/lib/Utils/auto-contact.js +0 -74
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/validate-connection.js.bak +0 -237
|
@@ -1,46 +1,22 @@
|
|
|
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
|
|
9
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
10
9
|
const WAProto_1 = require("../../WAProto");
|
|
11
10
|
const Defaults_1 = require("../Defaults");
|
|
12
|
-
const axios_1 = require("axios")
|
|
13
|
-
const Types_1 = require("../Types")
|
|
14
11
|
const Utils_1 = require("../Utils");
|
|
15
12
|
const link_preview_1 = require("../Utils/link-preview");
|
|
16
13
|
const WABinary_1 = require("../WABinary");
|
|
17
14
|
const newsletter_1 = require("./newsletter");
|
|
18
|
-
const WAUSync_1 = require("../WAUSync")
|
|
19
|
-
const kikyy = require('./dugong');
|
|
20
15
|
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
21
16
|
const makeMessagesSocket = (config) => {
|
|
22
|
-
const {
|
|
23
|
-
logger,
|
|
24
|
-
linkPreviewImageThumbnailWidth,
|
|
25
|
-
generateHighQualityLinkPreview,
|
|
26
|
-
options: axiosOptions,
|
|
27
|
-
patchMessageBeforeSending
|
|
28
|
-
} = config;
|
|
17
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
|
|
29
18
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
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;
|
|
19
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
44
20
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
45
21
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
46
22
|
useClones: false
|
|
@@ -59,9 +35,9 @@ const makeMessagesSocket = (config) => {
|
|
|
59
35
|
},
|
|
60
36
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
61
37
|
});
|
|
62
|
-
const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
|
|
38
|
+
const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
|
|
63
39
|
const node = {
|
|
64
|
-
hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
40
|
+
hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
65
41
|
hostname: attrs.hostname,
|
|
66
42
|
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
67
43
|
})),
|
|
@@ -90,7 +66,7 @@ const makeMessagesSocket = (config) => {
|
|
|
90
66
|
if (isReadReceipt) {
|
|
91
67
|
node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
92
68
|
}
|
|
93
|
-
if (type === 'sender' && WABinary_1.isJidUser(jid)) {
|
|
69
|
+
if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
|
|
94
70
|
node.attrs.recipient = jid;
|
|
95
71
|
node.attrs.to = participant;
|
|
96
72
|
}
|
|
@@ -101,7 +77,7 @@ const makeMessagesSocket = (config) => {
|
|
|
101
77
|
}
|
|
102
78
|
}
|
|
103
79
|
if (type) {
|
|
104
|
-
node.attrs.type = WABinary_1.isJidNewsLetter(jid) ? 'read-self' : type;
|
|
80
|
+
node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
|
|
105
81
|
}
|
|
106
82
|
const remainingMessageIds = messageIds.slice(1);
|
|
107
83
|
if (remainingMessageIds.length) {
|
|
@@ -135,70 +111,74 @@ const makeMessagesSocket = (config) => {
|
|
|
135
111
|
};
|
|
136
112
|
/** Fetch all the devices we've to send a message to */
|
|
137
113
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
138
|
-
|
|
139
|
-
|
|
114
|
+
var _a;
|
|
115
|
+
const deviceResults = [];
|
|
140
116
|
if (!useCache) {
|
|
141
|
-
logger.debug('not using cache for devices')
|
|
117
|
+
logger.debug('not using cache for devices');
|
|
142
118
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
jids = Array.from(new Set(jids))
|
|
147
|
-
|
|
119
|
+
const users = [];
|
|
120
|
+
jids = Array.from(new Set(jids));
|
|
148
121
|
for (let jid of jids) {
|
|
149
|
-
const user = WABinary_1.jidDecode(jid)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
}
|
|
122
|
+
const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
|
|
123
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
124
|
+
const devices = userDevicesCache.get(user);
|
|
125
|
+
if (devices && useCache) {
|
|
126
|
+
deviceResults.push(...devices);
|
|
127
|
+
logger.trace({ user }, 'using cache for devices');
|
|
164
128
|
}
|
|
165
|
-
|
|
166
129
|
else {
|
|
167
|
-
|
|
130
|
+
users.push({ tag: 'user', attrs: { jid } });
|
|
168
131
|
}
|
|
169
132
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return deviceResults
|
|
173
|
-
}
|
|
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
|
-
}
|
|
133
|
+
if (!users.length) {
|
|
134
|
+
return deviceResults;
|
|
198
135
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
136
|
+
const iq = {
|
|
137
|
+
tag: 'iq',
|
|
138
|
+
attrs: {
|
|
139
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
140
|
+
type: 'get',
|
|
141
|
+
xmlns: 'usync',
|
|
142
|
+
},
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
tag: 'usync',
|
|
146
|
+
attrs: {
|
|
147
|
+
sid: generateMessageTag(),
|
|
148
|
+
mode: 'query',
|
|
149
|
+
last: 'true',
|
|
150
|
+
index: '0',
|
|
151
|
+
context: 'message',
|
|
152
|
+
},
|
|
153
|
+
content: [
|
|
154
|
+
{
|
|
155
|
+
tag: 'query',
|
|
156
|
+
attrs: {},
|
|
157
|
+
content: [
|
|
158
|
+
{
|
|
159
|
+
tag: 'devices',
|
|
160
|
+
attrs: { version: '2' }
|
|
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
|
+
};
|
|
202
182
|
const assertSessions = async (jids, force) => {
|
|
203
183
|
let didFetchNewSession = false;
|
|
204
184
|
let jidsRequiringFetch = [];
|
|
@@ -242,29 +222,6 @@ const makeMessagesSocket = (config) => {
|
|
|
242
222
|
}
|
|
243
223
|
return didFetchNewSession;
|
|
244
224
|
};
|
|
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
|
-
};
|
|
268
225
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
269
226
|
const patched = await patchMessageBeforeSending(message, jids);
|
|
270
227
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
@@ -292,51 +249,27 @@ const makeMessagesSocket = (config) => {
|
|
|
292
249
|
}));
|
|
293
250
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
294
251
|
}; //apela
|
|
295
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata,
|
|
252
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }) => {
|
|
296
253
|
const meId = authState.creds.me.id;
|
|
297
254
|
let shouldIncludeDeviceIdentity = false;
|
|
298
|
-
|
|
299
|
-
const { user, server } = WABinary_1.jidDecode(jid);
|
|
255
|
+
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
300
256
|
const statusJid = 'status@broadcast';
|
|
301
257
|
const isGroup = server === 'g.us';
|
|
302
258
|
const isStatus = jid === statusJid;
|
|
303
259
|
const isLid = server === 'lid';
|
|
304
|
-
const isPrivate = server === 's.whatsapp.net'
|
|
305
260
|
const isNewsletter = server === 'newsletter';
|
|
306
261
|
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
307
262
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
308
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
309
263
|
const participants = [];
|
|
310
|
-
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
264
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
311
265
|
const binaryNodeContent = [];
|
|
312
266
|
const devices = [];
|
|
313
267
|
const meMsg = {
|
|
314
268
|
deviceSentMessage: {
|
|
315
269
|
destinationJid,
|
|
316
|
-
|
|
317
|
-
message,
|
|
270
|
+
message
|
|
318
271
|
}
|
|
319
272
|
};
|
|
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);
|
|
340
273
|
if (participant) {
|
|
341
274
|
// when the retry request is not for a group
|
|
342
275
|
// only send to the specific device that asked for a retry
|
|
@@ -344,80 +277,51 @@ const makeMessagesSocket = (config) => {
|
|
|
344
277
|
if (!isGroup && !isStatus) {
|
|
345
278
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
346
279
|
}
|
|
347
|
-
const { user, device } = WABinary_1.jidDecode(participant.jid);
|
|
280
|
+
const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
|
|
348
281
|
devices.push({ user, device });
|
|
349
282
|
}
|
|
350
283
|
await authState.keys.transaction(async () => {
|
|
351
|
-
|
|
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
|
-
|
|
284
|
+
var _a, _b, _c, _d, _e, _f;
|
|
285
|
+
const mediaType = getMediaType(message);
|
|
365
286
|
if (isGroup || isStatus) {
|
|
366
287
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
367
288
|
(async () => {
|
|
368
|
-
let groupData =
|
|
289
|
+
let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
369
290
|
if (groupData) {
|
|
370
291
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
371
292
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
groupData = await groupMetadata(jid)
|
|
293
|
+
if (!groupData && !isStatus) {
|
|
294
|
+
groupData = await groupMetadata(jid);
|
|
375
295
|
}
|
|
376
|
-
|
|
377
296
|
return groupData;
|
|
378
297
|
})(),
|
|
379
298
|
(async () => {
|
|
380
299
|
if (!participant && !isStatus) {
|
|
381
|
-
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
382
|
-
return result[jid] || {}
|
|
300
|
+
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
301
|
+
return result[jid] || {};
|
|
383
302
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
})()
|
|
303
|
+
return {};
|
|
304
|
+
})()
|
|
388
305
|
]);
|
|
389
306
|
if (!participant) {
|
|
390
|
-
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
391
|
-
|
|
307
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
|
|
392
308
|
if (isStatus && statusJidList) {
|
|
393
|
-
participantsList.push(...statusJidList)
|
|
309
|
+
participantsList.push(...statusJidList);
|
|
394
310
|
}
|
|
395
|
-
|
|
396
|
-
|
|
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)
|
|
311
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
312
|
+
devices.push(...additionalDevices);
|
|
407
313
|
}
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
const bytes = Utils_1.encodeWAMessage(patched);
|
|
411
|
-
|
|
314
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
315
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
412
316
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
413
317
|
group: destinationJid,
|
|
414
318
|
data: bytes,
|
|
415
319
|
meId,
|
|
416
320
|
});
|
|
417
321
|
const senderKeyJids = [];
|
|
418
|
-
|
|
322
|
+
// ensure a connection is established with every device
|
|
419
323
|
for (const { user, device } of devices) {
|
|
420
|
-
const jid = WABinary_1.jidEncode(user,
|
|
324
|
+
const jid = (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
421
325
|
if (!senderKeyMap[jid] || !!participant) {
|
|
422
326
|
senderKeyJids.push(jid);
|
|
423
327
|
// store that this person has had the sender keys sent to them
|
|
@@ -435,115 +339,95 @@ const makeMessagesSocket = (config) => {
|
|
|
435
339
|
}
|
|
436
340
|
};
|
|
437
341
|
await assertSessions(senderKeyJids, false);
|
|
438
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg,
|
|
342
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
|
|
439
343
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
440
344
|
participants.push(...result.nodes);
|
|
441
345
|
}
|
|
442
346
|
binaryNodeContent.push({
|
|
443
347
|
tag: 'enc',
|
|
444
|
-
attrs: { v: '2', type: 'skmsg'
|
|
348
|
+
attrs: { v: '2', type: 'skmsg' },
|
|
445
349
|
content: ciphertext
|
|
446
350
|
});
|
|
447
351
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
448
352
|
}
|
|
449
353
|
else if (isNewsletter) {
|
|
450
354
|
// Message edit
|
|
451
|
-
if (message.protocolMessage
|
|
452
|
-
msgId = message.protocolMessage.key
|
|
453
|
-
message = message.protocolMessage.editedMessage
|
|
355
|
+
if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
|
|
356
|
+
msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
|
|
357
|
+
message = message.protocolMessage.editedMessage;
|
|
454
358
|
}
|
|
455
|
-
|
|
456
359
|
// Message delete
|
|
457
|
-
if (message.protocolMessage
|
|
458
|
-
msgId = message.protocolMessage.key
|
|
459
|
-
message = {}
|
|
360
|
+
if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
361
|
+
msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
|
|
362
|
+
message = {};
|
|
460
363
|
}
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
464
|
-
|
|
364
|
+
const patched = await patchMessageBeforeSending(message, []);
|
|
365
|
+
const bytes = WAProto_1.proto.Message.encode(patched).finish();
|
|
465
366
|
binaryNodeContent.push({
|
|
466
367
|
tag: 'plaintext',
|
|
467
|
-
attrs:
|
|
368
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
468
369
|
content: bytes
|
|
469
|
-
})
|
|
370
|
+
});
|
|
470
371
|
}
|
|
471
372
|
else {
|
|
472
|
-
const { user: meUser } = WABinary_1.jidDecode(meId);
|
|
373
|
+
const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
|
|
473
374
|
if (!participant) {
|
|
474
|
-
devices.push({ user })
|
|
475
|
-
if
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (additionalAttributes?.['category'] !== 'peer') {
|
|
480
|
-
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
481
|
-
|
|
482
|
-
devices.push(...additionalDevices)
|
|
375
|
+
devices.push({ user });
|
|
376
|
+
// do not send message to self if the device is 0 (mobile)
|
|
377
|
+
if (meDevice !== undefined && meDevice !== 0) {
|
|
378
|
+
devices.push({ user: meUser });
|
|
483
379
|
}
|
|
380
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
381
|
+
devices.push(...additionalDevices);
|
|
484
382
|
}
|
|
485
383
|
const allJids = [];
|
|
486
384
|
const meJids = [];
|
|
487
385
|
const otherJids = [];
|
|
488
386
|
for (const { user, device } of devices) {
|
|
489
|
-
const isMe = user === meUser
|
|
490
|
-
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds
|
|
491
|
-
|
|
387
|
+
const isMe = user === meUser;
|
|
388
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
492
389
|
if (isMe) {
|
|
493
|
-
meJids.push(jid)
|
|
390
|
+
meJids.push(jid);
|
|
494
391
|
}
|
|
495
|
-
|
|
496
392
|
else {
|
|
497
|
-
otherJids.push(jid)
|
|
393
|
+
otherJids.push(jid);
|
|
498
394
|
}
|
|
499
|
-
|
|
500
|
-
allJids.push(jid)
|
|
395
|
+
allJids.push(jid);
|
|
501
396
|
}
|
|
502
397
|
await assertSessions(allJids, false);
|
|
503
398
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
504
|
-
createParticipantNodes(meJids, meMsg,
|
|
505
|
-
createParticipantNodes(otherJids, message,
|
|
506
|
-
])
|
|
399
|
+
createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
|
|
400
|
+
createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
|
|
401
|
+
]);
|
|
507
402
|
participants.push(...meNodes);
|
|
508
403
|
participants.push(...otherNodes);
|
|
509
404
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
510
405
|
}
|
|
511
406
|
if (participants.length) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
else {
|
|
521
|
-
binaryNodeContent.push({
|
|
522
|
-
tag: 'participants',
|
|
523
|
-
attrs: {},
|
|
524
|
-
content: participants
|
|
525
|
-
})
|
|
526
|
-
}
|
|
407
|
+
binaryNodeContent.push({
|
|
408
|
+
tag: 'participants',
|
|
409
|
+
attrs: {},
|
|
410
|
+
content: participants
|
|
411
|
+
});
|
|
527
412
|
}
|
|
528
|
-
|
|
529
413
|
const stanza = {
|
|
530
414
|
tag: 'message',
|
|
531
415
|
attrs: {
|
|
532
416
|
id: msgId,
|
|
533
|
-
type: getTypeMessage(
|
|
417
|
+
type: isNewsletter ? getTypeMessage(message) : 'text',
|
|
534
418
|
...(additionalAttributes || {})
|
|
535
419
|
},
|
|
536
420
|
content: binaryNodeContent
|
|
537
|
-
}
|
|
421
|
+
};
|
|
538
422
|
// if the participant to send to is explicitly specified (generally retry recp)
|
|
539
423
|
// ensure the message is only sent to that person
|
|
540
424
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
541
425
|
if (participant) {
|
|
542
|
-
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
426
|
+
if ((0, WABinary_1.isJidGroup)(destinationJid)) {
|
|
543
427
|
stanza.attrs.to = destinationJid;
|
|
544
428
|
stanza.attrs.participant = participant.jid;
|
|
545
429
|
}
|
|
546
|
-
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
430
|
+
else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
|
|
547
431
|
stanza.attrs.to = participant.jid;
|
|
548
432
|
stanza.attrs.recipient = destinationJid;
|
|
549
433
|
}
|
|
@@ -562,70 +446,46 @@ const makeMessagesSocket = (config) => {
|
|
|
562
446
|
});
|
|
563
447
|
logger.debug({ jid }, 'adding device identity');
|
|
564
448
|
}
|
|
565
|
-
|
|
566
|
-
|
|
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)
|
|
585
|
-
}
|
|
449
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
450
|
+
stanza.content.push(...additionalNodes);
|
|
586
451
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
452
|
+
else {
|
|
453
|
+
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && ((message === null || message === void 0 ? void 0 : message.viewOnceMessage) ? message === null || message === void 0 ? void 0 : message.viewOnceMessage : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2 : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension : (message === null || message === void 0 ? void 0 : message.ephemeralMessage) ? message === null || message === void 0 ? void 0 : message.ephemeralMessage : (message === null || message === void 0 ? void 0 : message.templateMessage) ? message === null || message === void 0 ? void 0 : message.templateMessage : (message === null || message === void 0 ? void 0 : message.interactiveMessage) ? message === null || message === void 0 ? void 0 : message.interactiveMessage : message === null || message === void 0 ? void 0 : message.buttonsMessage)) {
|
|
454
|
+
stanza.content.push({
|
|
455
|
+
tag: 'biz',
|
|
456
|
+
attrs: {},
|
|
457
|
+
content: [{
|
|
458
|
+
tag: 'interactive',
|
|
459
|
+
attrs: {
|
|
460
|
+
type: 'native_flow',
|
|
461
|
+
v: '1'
|
|
462
|
+
},
|
|
463
|
+
content: [{
|
|
464
|
+
tag: 'native_flow',
|
|
465
|
+
attrs: { v: '9', name: 'mixed' }
|
|
466
|
+
}]
|
|
467
|
+
}]
|
|
468
|
+
});
|
|
598
469
|
}
|
|
599
|
-
logger.debug({ jid }, 'adding business node')
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
603
|
-
stanza.content.push(...additionalNodes);
|
|
604
470
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
471
|
+
const buttonType = getButtonType(message);
|
|
472
|
+
if (buttonType) {
|
|
473
|
+
stanza.content.push({
|
|
474
|
+
tag: 'biz',
|
|
475
|
+
attrs: {},
|
|
476
|
+
content: [
|
|
477
|
+
{
|
|
478
|
+
tag: buttonType,
|
|
479
|
+
attrs: getButtonArgs(message),
|
|
480
|
+
}
|
|
481
|
+
]
|
|
482
|
+
});
|
|
483
|
+
logger.debug({ jid }, 'adding business node');
|
|
484
|
+
}
|
|
608
485
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
609
486
|
await sendNode(stanza);
|
|
610
487
|
});
|
|
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;
|
|
488
|
+
return msgId;
|
|
629
489
|
};
|
|
630
490
|
const getTypeMessage = (msg) => {
|
|
631
491
|
const message = Utils_1.normalizeMessageContent(msg)
|
|
@@ -690,38 +550,93 @@ const makeMessagesSocket = (config) => {
|
|
|
690
550
|
return 'productlink'
|
|
691
551
|
}
|
|
692
552
|
}
|
|
693
|
-
|
|
694
553
|
const getButtonType = (message) => {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
554
|
+
if (message.listMessage) {
|
|
555
|
+
return 'list'
|
|
556
|
+
}
|
|
698
557
|
else if (message.buttonsMessage) {
|
|
699
558
|
return 'buttons'
|
|
700
559
|
}
|
|
701
|
-
else if
|
|
702
|
-
return 'review_and_pay'
|
|
703
|
-
}
|
|
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) {
|
|
560
|
+
else if(message.interactiveMessage?.nativeFlowMessage) {
|
|
720
561
|
return 'native_flow'
|
|
721
562
|
}
|
|
722
563
|
}
|
|
564
|
+
const getButtonArgs = (message) => {
|
|
565
|
+
if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'review_and_pay') {
|
|
566
|
+
return {
|
|
567
|
+
tag: 'biz',
|
|
568
|
+
attrs: {
|
|
569
|
+
native_flow_name: 'order_details'
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
} else if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'payment_info') {
|
|
573
|
+
return {
|
|
574
|
+
tag: 'biz',
|
|
575
|
+
attrs: {
|
|
576
|
+
native_flow_name: 'payment_info'
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
} else if (message.interactiveMessage?.nativeFlowMessage &&message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 &&
|
|
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
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
723
638
|
const getPrivacyTokens = async (jids) => {
|
|
724
|
-
const t = Utils_1.unixTimestampSeconds().toString();
|
|
639
|
+
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
725
640
|
const result = await query({
|
|
726
641
|
tag: 'iq',
|
|
727
642
|
attrs: {
|
|
@@ -736,7 +651,7 @@ const makeMessagesSocket = (config) => {
|
|
|
736
651
|
content: jids.map(jid => ({
|
|
737
652
|
tag: 'token',
|
|
738
653
|
attrs: {
|
|
739
|
-
jid: WABinary_1.jidNormalizedUser(jid),
|
|
654
|
+
jid: (0, WABinary_1.jidNormalizedUser)(jid),
|
|
740
655
|
t,
|
|
741
656
|
type: 'trusted_contact'
|
|
742
657
|
}
|
|
@@ -745,9 +660,8 @@ const makeMessagesSocket = (config) => {
|
|
|
745
660
|
]
|
|
746
661
|
});
|
|
747
662
|
return result;
|
|
748
|
-
}
|
|
663
|
+
};
|
|
749
664
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
750
|
-
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
751
665
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
752
666
|
return {
|
|
753
667
|
...sock,
|
|
@@ -756,13 +670,12 @@ const makeMessagesSocket = (config) => {
|
|
|
756
670
|
relayMessage,
|
|
757
671
|
sendReceipt,
|
|
758
672
|
sendReceipts,
|
|
759
|
-
|
|
673
|
+
getButtonArgs,
|
|
760
674
|
readMessages,
|
|
761
675
|
refreshMediaConn,
|
|
762
676
|
getUSyncDevices,
|
|
763
677
|
createParticipantNodes,
|
|
764
678
|
waUploadToServer,
|
|
765
|
-
sendPeerDataOperationMessage,
|
|
766
679
|
fetchPrivacySettings,
|
|
767
680
|
updateMediaMessage: async (message) => {
|
|
768
681
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
@@ -801,155 +714,145 @@ const makeMessagesSocket = (config) => {
|
|
|
801
714
|
throw error;
|
|
802
715
|
}
|
|
803
716
|
ev.emit('messages.update', [
|
|
804
|
-
{
|
|
805
|
-
key: message.key,
|
|
806
|
-
update: {
|
|
807
|
-
message: message.message
|
|
808
|
-
}
|
|
809
|
-
}
|
|
717
|
+
{ key: message.key, update: { message: message.message } }
|
|
810
718
|
]);
|
|
811
719
|
return message;
|
|
812
720
|
},
|
|
813
721
|
sendMessage: async (jid, content, options = {}) => {
|
|
814
722
|
const userJid = authState.creds.me.id;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
723
|
+
const additionalAttributes = {};
|
|
724
|
+
const additionalNodes = [];
|
|
725
|
+
const { kikyy } = require("./dugong");
|
|
726
|
+
const rahmi = new kikyy(sock);
|
|
727
|
+
|
|
728
|
+
const messageType = Object.keys(content)[0];
|
|
729
|
+
if (messageType) {
|
|
730
|
+
switch (messageType) {
|
|
731
|
+
case 'PAYMENT':
|
|
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
|
+
}
|
|
834
772
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
...
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
773
|
+
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
774
|
+
logger,
|
|
775
|
+
userJid,
|
|
776
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
777
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
778
|
+
fetchOpts: {
|
|
779
|
+
timeout: 3000,
|
|
780
|
+
...axiosOptions || {}
|
|
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;
|
|
854
799
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
case 'POLL_RESULT':
|
|
868
|
-
return await rahmi.handlePollResult(content, jid, quoted)
|
|
869
|
-
case 'GROUP_STORY':
|
|
870
|
-
return await rahmi.handleGroupStory(content, jid, quoted)
|
|
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';
|
|
871
812
|
}
|
|
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
|
-
|
|
898
|
-
|
|
899
813
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
814
|
+
// AI Logic (Hybrid)
|
|
815
|
+
if (isAiMsg || options.AI) {
|
|
816
|
+
// For Private Chats: Use biz_bot (standard)
|
|
817
|
+
if ((0, WABinary_1.isJidUser)(jid)) {
|
|
818
|
+
additionalNodes.push({
|
|
819
|
+
attrs: {
|
|
820
|
+
biz_bot: '1'
|
|
821
|
+
},
|
|
822
|
+
tag: "bot"
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
// For Group Chats: Use supportPayload (safer, no drop)
|
|
826
|
+
else if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
827
|
+
const msgType = Object.keys(fullMsg.message)[0];
|
|
828
|
+
if (msgType) {
|
|
829
|
+
fullMsg.message[msgType].messageContextInfo = fullMsg.message[msgType].messageContextInfo || {};
|
|
830
|
+
fullMsg.message[msgType].messageContextInfo.messageSecret = fullMsg.message[msgType].messageContextInfo.messageSecret || crypto.randomBytes(32);
|
|
831
|
+
fullMsg.message[msgType].messageContextInfo.supportPayload = JSON.stringify({
|
|
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
|
+
}
|
|
839
|
+
}
|
|
907
840
|
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
if (
|
|
916
|
-
|
|
917
|
-
|
|
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"
|
|
841
|
+
if (mediaHandle) {
|
|
842
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
843
|
+
}
|
|
844
|
+
if ('cachedGroupMetadata' in options) {
|
|
845
|
+
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
846
|
+
}
|
|
847
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalNodes, additionalAttributes, statusJidList: options.statusJidList });
|
|
848
|
+
if (config.emitOwnEvents) {
|
|
849
|
+
process.nextTick(() => {
|
|
850
|
+
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
932
851
|
});
|
|
933
852
|
}
|
|
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;
|
|
853
|
+
return fullMsg;
|
|
951
854
|
}
|
|
952
855
|
}
|
|
953
|
-
}
|
|
856
|
+
};
|
|
954
857
|
};
|
|
955
858
|
exports.makeMessagesSocket = makeMessagesSocket;
|