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