alipclutch-baileys 8.3.0 → 8.4.1
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 +3 -1
- package/README.md +10 -9
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +55057 -0
- package/WAProto/index.js +56887 -17535
- package/WAProto/index.ts.ts +53473 -0
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +16 -7
- package/lib/Defaults/index.js +90 -119
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/types.d.ts +0 -1
- package/lib/Socket/Client/types.js +0 -1
- package/lib/Socket/Client/websocket.d.ts +0 -1
- package/lib/Socket/Client/websocket.js +0 -1
- package/lib/Socket/business.d.ts +59 -58
- package/lib/Socket/chats.d.ts +45 -230
- package/lib/Socket/chats.js +139 -238
- package/lib/Socket/groups.d.ts +41 -32
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/index.d.ts +63 -64
- package/lib/Socket/index.js +2 -3
- package/lib/Socket/messages-recv.js +9 -65
- package/lib/Socket/messages-send.d.ts +49 -47
- package/lib/Socket/messages-send.js +584 -395
- package/lib/Socket/newsletter.d.ts +39 -37
- package/lib/Socket/newsletter.js +88 -123
- package/lib/Socket/setup.js +433 -0
- package/lib/Socket/{dugong.d.ts → setup.ts} +17 -52
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +62 -38
- package/lib/Socket/usync.d.ts +3 -4
- package/lib/Socket/usync.js +0 -1
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +26 -14
- 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 +0 -7
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +14 -7
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +44 -2
- package/lib/Types/GroupMetadata.d.ts +11 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +148 -21
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +73 -97
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/Socket.d.ts +17 -9
- package/lib/Types/index.d.ts +8 -1
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +15 -16
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.d.ts +22 -6
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +11 -7
- package/lib/Utils/generics.d.ts +17 -20
- package/lib/Utils/generics.js +95 -75
- package/lib/Utils/history.d.ts +4 -0
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/logger.d.ts +10 -3
- 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 +28 -24
- package/lib/Utils/messages-media.js +272 -111
- package/lib/Utils/messages.d.ts +13 -10
- package/lib/Utils/messages.js +323 -50
- package/lib/Utils/noise-handler.d.ts +10 -12
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +51 -6
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +90 -66
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.d.ts +1 -4
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.d.ts +11 -5
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +27 -15
- package/package.json +18 -31
- package/engine-requirements.js +0 -10
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/dugong.js +0 -483
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
|
@@ -1,47 +1,26 @@
|
|
|
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 node_cache_1 = __importDefault(require("node-cache"));
|
|
8
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
9
10
|
const WAProto_1 = require("../../WAProto");
|
|
10
11
|
const Defaults_1 = require("../Defaults");
|
|
11
|
-
const axios_1 = require("axios")
|
|
12
|
-
const Types_1 = require("../Types")
|
|
13
12
|
const Utils_1 = require("../Utils");
|
|
14
13
|
const link_preview_1 = require("../Utils/link-preview");
|
|
15
14
|
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const WAUSync_1 = require("../WAUSync");
|
|
16
16
|
const newsletter_1 = require("./newsletter");
|
|
17
|
-
const
|
|
18
|
-
const kikyy = require('./dugong');
|
|
19
|
-
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
17
|
+
const NotForrAll = require("./setup");
|
|
20
18
|
const makeMessagesSocket = (config) => {
|
|
21
|
-
const {
|
|
22
|
-
logger,
|
|
23
|
-
linkPreviewImageThumbnailWidth,
|
|
24
|
-
generateHighQualityLinkPreview,
|
|
25
|
-
options: axiosOptions,
|
|
26
|
-
patchMessageBeforeSending
|
|
27
|
-
} = config;
|
|
19
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
|
|
28
20
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
29
|
-
const {
|
|
30
|
-
ev,
|
|
31
|
-
authState,
|
|
32
|
-
processingMutex,
|
|
33
|
-
signalRepository,
|
|
34
|
-
upsertMessage,
|
|
35
|
-
query,
|
|
36
|
-
fetchPrivacySettings,
|
|
37
|
-
generateMessageTag,
|
|
38
|
-
sendNode,
|
|
39
|
-
groupMetadata,
|
|
40
|
-
groupToggleEphemeral,
|
|
41
|
-
executeUSyncQuery
|
|
42
|
-
} = sock;
|
|
21
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
|
|
43
22
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
44
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
23
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
45
24
|
useClones: false
|
|
46
25
|
});
|
|
47
26
|
let mediaConn;
|
|
@@ -58,9 +37,9 @@ const makeMessagesSocket = (config) => {
|
|
|
58
37
|
},
|
|
59
38
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
60
39
|
});
|
|
61
|
-
const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
|
|
40
|
+
const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
|
|
62
41
|
const node = {
|
|
63
|
-
hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
42
|
+
hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
64
43
|
hostname: attrs.hostname,
|
|
65
44
|
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
66
45
|
})),
|
|
@@ -89,7 +68,7 @@ const makeMessagesSocket = (config) => {
|
|
|
89
68
|
if (isReadReceipt) {
|
|
90
69
|
node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
91
70
|
}
|
|
92
|
-
if (type === 'sender' && WABinary_1.isJidUser(jid)) {
|
|
71
|
+
if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
|
|
93
72
|
node.attrs.recipient = jid;
|
|
94
73
|
node.attrs.to = participant;
|
|
95
74
|
}
|
|
@@ -100,7 +79,7 @@ const makeMessagesSocket = (config) => {
|
|
|
100
79
|
}
|
|
101
80
|
}
|
|
102
81
|
if (type) {
|
|
103
|
-
node.attrs.type = WABinary_1.
|
|
82
|
+
node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
|
|
104
83
|
}
|
|
105
84
|
const remainingMessageIds = messageIds.slice(1);
|
|
106
85
|
if (remainingMessageIds.length) {
|
|
@@ -134,70 +113,54 @@ const makeMessagesSocket = (config) => {
|
|
|
134
113
|
};
|
|
135
114
|
/** Fetch all the devices we've to send a message to */
|
|
136
115
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
137
|
-
|
|
138
|
-
|
|
116
|
+
var _a;
|
|
117
|
+
const deviceResults = [];
|
|
139
118
|
if (!useCache) {
|
|
140
|
-
logger.debug('not using cache for devices')
|
|
119
|
+
logger.debug('not using cache for devices');
|
|
141
120
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
jids = Array.from(new Set(jids))
|
|
146
|
-
|
|
121
|
+
const toFetch = [];
|
|
122
|
+
jids = Array.from(new Set(jids));
|
|
147
123
|
for (let jid of jids) {
|
|
148
|
-
const user = WABinary_1.jidDecode(jid)
|
|
149
|
-
|
|
150
|
-
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
-
|
|
124
|
+
const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
|
|
125
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
152
126
|
if (useCache) {
|
|
153
|
-
const devices = userDevicesCache.get(user)
|
|
154
|
-
|
|
127
|
+
const devices = userDevicesCache.get(user);
|
|
155
128
|
if (devices) {
|
|
156
|
-
deviceResults.push(...devices)
|
|
157
|
-
logger.trace({ user }, 'using cache for devices')
|
|
129
|
+
deviceResults.push(...devices);
|
|
130
|
+
logger.trace({ user }, 'using cache for devices');
|
|
158
131
|
}
|
|
159
|
-
|
|
160
132
|
else {
|
|
161
|
-
toFetch.push(jid)
|
|
133
|
+
toFetch.push(jid);
|
|
162
134
|
}
|
|
163
135
|
}
|
|
164
|
-
|
|
165
136
|
else {
|
|
166
|
-
toFetch.push(jid)
|
|
137
|
+
toFetch.push(jid);
|
|
167
138
|
}
|
|
168
139
|
}
|
|
169
|
-
|
|
170
140
|
if (!toFetch.length) {
|
|
171
|
-
return deviceResults
|
|
141
|
+
return deviceResults;
|
|
172
142
|
}
|
|
173
|
-
|
|
174
143
|
const query = new WAUSync_1.USyncQuery()
|
|
175
144
|
.withContext('message')
|
|
176
|
-
.withDeviceProtocol()
|
|
177
|
-
|
|
145
|
+
.withDeviceProtocol();
|
|
178
146
|
for (const jid of toFetch) {
|
|
179
|
-
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
147
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
180
148
|
}
|
|
181
|
-
|
|
182
|
-
const result = await executeUSyncQuery(query)
|
|
183
|
-
|
|
149
|
+
const result = await sock.executeUSyncQuery(query);
|
|
184
150
|
if (result) {
|
|
185
|
-
const extracted = Utils_1.extractDeviceJids(result
|
|
186
|
-
const deviceMap = {}
|
|
187
|
-
|
|
151
|
+
const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
|
|
152
|
+
const deviceMap = {};
|
|
188
153
|
for (const item of extracted) {
|
|
189
|
-
deviceMap[item.user] = deviceMap[item.user] || []
|
|
190
|
-
deviceMap[item.user].push(item)
|
|
191
|
-
deviceResults.push(item)
|
|
154
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
155
|
+
deviceMap[item.user].push(item);
|
|
156
|
+
deviceResults.push(item);
|
|
192
157
|
}
|
|
193
|
-
|
|
194
158
|
for (const key in deviceMap) {
|
|
195
|
-
userDevicesCache.set(key, deviceMap[key])
|
|
159
|
+
userDevicesCache.set(key, deviceMap[key]);
|
|
196
160
|
}
|
|
197
161
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
162
|
+
return deviceResults;
|
|
163
|
+
};
|
|
201
164
|
const assertSessions = async (jids, force) => {
|
|
202
165
|
let didFetchNewSession = false;
|
|
203
166
|
let jidsRequiringFetch = [];
|
|
@@ -241,20 +204,19 @@ const makeMessagesSocket = (config) => {
|
|
|
241
204
|
}
|
|
242
205
|
return didFetchNewSession;
|
|
243
206
|
};
|
|
244
|
-
|
|
245
|
-
|
|
246
207
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
247
|
-
|
|
248
|
-
|
|
208
|
+
var _a;
|
|
209
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
210
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
211
|
+
throw new boom_1.Boom('Not authenticated');
|
|
249
212
|
}
|
|
250
|
-
|
|
251
213
|
const protocolMessage = {
|
|
252
214
|
protocolMessage: {
|
|
253
215
|
peerDataOperationRequestMessage: pdoMessage,
|
|
254
216
|
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
255
217
|
}
|
|
256
218
|
};
|
|
257
|
-
const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
|
|
219
|
+
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
258
220
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
259
221
|
additionalAttributes: {
|
|
260
222
|
category: 'peer',
|
|
@@ -265,10 +227,17 @@ const makeMessagesSocket = (config) => {
|
|
|
265
227
|
return msgId;
|
|
266
228
|
};
|
|
267
229
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
268
|
-
|
|
269
|
-
|
|
230
|
+
let patched = await patchMessageBeforeSending(message, jids);
|
|
231
|
+
if (!Array.isArray(patched)) {
|
|
232
|
+
patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
|
|
233
|
+
}
|
|
270
234
|
let shouldIncludeDeviceIdentity = false;
|
|
271
|
-
const nodes = await Promise.all(
|
|
235
|
+
const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
|
|
236
|
+
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
|
|
237
|
+
if (!jid) {
|
|
238
|
+
return {};
|
|
239
|
+
}
|
|
240
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
|
|
272
241
|
const { type, ciphertext } = await signalRepository
|
|
273
242
|
.encryptMessage({ jid, data: bytes });
|
|
274
243
|
if (type === 'pkmsg') {
|
|
@@ -290,34 +259,35 @@ const makeMessagesSocket = (config) => {
|
|
|
290
259
|
return node;
|
|
291
260
|
}));
|
|
292
261
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
293
|
-
};
|
|
294
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache,
|
|
262
|
+
};
|
|
263
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
264
|
+
var _a;
|
|
295
265
|
const meId = authState.creds.me.id;
|
|
296
266
|
let shouldIncludeDeviceIdentity = false;
|
|
297
|
-
|
|
298
|
-
const { user, server } = WABinary_1.jidDecode(jid);
|
|
267
|
+
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
299
268
|
const statusJid = 'status@broadcast';
|
|
300
269
|
const isGroup = server === 'g.us';
|
|
270
|
+
const isPrivatee = server === 's.whatsapp.net'
|
|
271
|
+
const isNewsletter = server === 'newsletter';
|
|
301
272
|
const isStatus = jid === statusJid;
|
|
302
273
|
const isLid = server === 'lid';
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
msgId = msgId || (0, Utils_1.
|
|
274
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
275
|
+
const pollMessage = messages.pollCreationMessage || messages.pollCreationMessageV2 || messages.pollCreationMessageV3
|
|
276
|
+
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
|
306
277
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
307
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
278
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
308
279
|
const participants = [];
|
|
309
|
-
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
280
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
310
281
|
const binaryNodeContent = [];
|
|
311
282
|
const devices = [];
|
|
312
283
|
const meMsg = {
|
|
313
284
|
deviceSentMessage: {
|
|
314
285
|
destinationJid,
|
|
315
286
|
message
|
|
316
|
-
}
|
|
287
|
+
},
|
|
288
|
+
messageContextInfo: message.messageContextInfo
|
|
317
289
|
};
|
|
318
|
-
const extraAttrs = {}
|
|
319
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
320
|
-
const buttonType = getButtonType(messages);
|
|
290
|
+
const extraAttrs = {};
|
|
321
291
|
if (participant) {
|
|
322
292
|
// when the retry request is not for a group
|
|
323
293
|
// only send to the specific device that asked for a retry
|
|
@@ -325,80 +295,67 @@ const makeMessagesSocket = (config) => {
|
|
|
325
295
|
if (!isGroup && !isStatus) {
|
|
326
296
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
327
297
|
}
|
|
328
|
-
const { user, device } = WABinary_1.jidDecode(participant.jid);
|
|
298
|
+
const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
|
|
329
299
|
devices.push({ user, device });
|
|
330
300
|
}
|
|
331
301
|
await authState.keys.transaction(async () => {
|
|
332
|
-
|
|
333
|
-
|
|
302
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
303
|
+
const mediaType = getMediaType(message);
|
|
334
304
|
if (mediaType) {
|
|
335
|
-
extraAttrs['mediatype'] = mediaType
|
|
305
|
+
extraAttrs['mediatype'] = mediaType;
|
|
336
306
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
extraAttrs['decrypt-fail'] = 'hide'
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
343
|
-
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
307
|
+
if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
|
|
308
|
+
extraAttrs['decrypt-fail'] = 'hide';
|
|
344
309
|
}
|
|
345
|
-
|
|
346
310
|
if (isGroup || isStatus) {
|
|
347
311
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
348
312
|
(async () => {
|
|
349
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
350
|
-
if (groupData) {
|
|
313
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
314
|
+
if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
|
|
351
315
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
352
316
|
}
|
|
353
|
-
|
|
354
317
|
else if (!isStatus) {
|
|
355
|
-
groupData = await groupMetadata(jid)
|
|
318
|
+
groupData = await groupMetadata(jid);
|
|
356
319
|
}
|
|
357
|
-
|
|
358
320
|
return groupData;
|
|
359
321
|
})(),
|
|
360
322
|
(async () => {
|
|
361
323
|
if (!participant && !isStatus) {
|
|
362
|
-
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
|
-
return result[jid] || {}
|
|
324
|
+
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
325
|
+
return result[jid] || {};
|
|
364
326
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
})()
|
|
327
|
+
return {};
|
|
328
|
+
})()
|
|
369
329
|
]);
|
|
370
330
|
if (!participant) {
|
|
371
|
-
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
-
|
|
331
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
|
|
373
332
|
if (isStatus && statusJidList) {
|
|
374
|
-
participantsList.push(...statusJidList)
|
|
333
|
+
participantsList.push(...statusJidList);
|
|
375
334
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
335
|
+
if (!isStatus) {
|
|
336
|
+
additionalAttributes = {
|
|
337
|
+
...additionalAttributes,
|
|
338
|
+
// eslint-disable-next-line camelcase
|
|
339
|
+
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
343
|
+
devices.push(...additionalDevices);
|
|
344
|
+
}
|
|
345
|
+
const patched = await patchMessageBeforeSending(message);
|
|
346
|
+
if (Array.isArray(patched)) {
|
|
347
|
+
throw new boom_1.Boom('Per-jid patching is not supported in groups');
|
|
388
348
|
}
|
|
389
|
-
|
|
390
|
-
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
391
|
-
const bytes = Utils_1.encodeWAMessage(patched);
|
|
392
|
-
|
|
349
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
393
350
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
394
351
|
group: destinationJid,
|
|
395
352
|
data: bytes,
|
|
396
353
|
meId,
|
|
397
354
|
});
|
|
398
355
|
const senderKeyJids = [];
|
|
399
|
-
|
|
356
|
+
// ensure a connection is established with every device
|
|
400
357
|
for (const { user, device } of devices) {
|
|
401
|
-
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
358
|
+
const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
402
359
|
if (!senderKeyMap[jid] || !!participant) {
|
|
403
360
|
senderKeyJids.push(jid);
|
|
404
361
|
// store that this person has had the sender keys sent to them
|
|
@@ -416,115 +373,107 @@ const makeMessagesSocket = (config) => {
|
|
|
416
373
|
}
|
|
417
374
|
};
|
|
418
375
|
await assertSessions(senderKeyJids, false);
|
|
419
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
376
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
|
|
420
377
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
421
378
|
participants.push(...result.nodes);
|
|
422
379
|
}
|
|
423
380
|
binaryNodeContent.push({
|
|
424
381
|
tag: 'enc',
|
|
425
|
-
attrs: { v: '2', type: 'skmsg'
|
|
382
|
+
attrs: { v: '2', type: 'skmsg' },
|
|
426
383
|
content: ciphertext
|
|
427
384
|
});
|
|
428
385
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
429
386
|
}
|
|
430
387
|
else if (isNewsletter) {
|
|
431
388
|
// Message edit
|
|
432
|
-
if (message.protocolMessage
|
|
433
|
-
msgId = message.protocolMessage.key
|
|
434
|
-
message = message.protocolMessage.editedMessage
|
|
389
|
+
if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
|
|
390
|
+
msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
|
|
391
|
+
message = message.protocolMessage.editedMessage;
|
|
435
392
|
}
|
|
436
|
-
|
|
437
393
|
// Message delete
|
|
438
|
-
if (message.protocolMessage
|
|
439
|
-
msgId = message.protocolMessage.key
|
|
440
|
-
message = {}
|
|
394
|
+
if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
395
|
+
msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
|
|
396
|
+
message = {};
|
|
441
397
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
398
|
+
const patched = await patchMessageBeforeSending(message, []);
|
|
399
|
+
if (Array.isArray(patched)) {
|
|
400
|
+
throw new boom_1.Boom('Per-jid patching is not supported in channel');
|
|
401
|
+
}
|
|
402
|
+
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
446
403
|
binaryNodeContent.push({
|
|
447
404
|
tag: 'plaintext',
|
|
448
|
-
attrs:
|
|
405
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
449
406
|
content: bytes
|
|
450
|
-
})
|
|
407
|
+
});
|
|
451
408
|
}
|
|
452
409
|
else {
|
|
453
|
-
const { user: meUser } = WABinary_1.jidDecode(meId);
|
|
410
|
+
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
454
411
|
if (!participant) {
|
|
455
|
-
devices.push({ user })
|
|
412
|
+
devices.push({ user });
|
|
456
413
|
if (user !== meUser) {
|
|
457
|
-
devices.push({ user: meUser })
|
|
414
|
+
devices.push({ user: meUser });
|
|
458
415
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
devices.push(...additionalDevices)
|
|
416
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
417
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
418
|
+
devices.push(...additionalDevices);
|
|
464
419
|
}
|
|
465
420
|
}
|
|
466
421
|
const allJids = [];
|
|
467
422
|
const meJids = [];
|
|
468
423
|
const otherJids = [];
|
|
469
424
|
for (const { user, device } of devices) {
|
|
470
|
-
const isMe = user === meUser
|
|
471
|
-
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds
|
|
472
|
-
|
|
425
|
+
const isMe = user === meUser;
|
|
426
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
473
427
|
if (isMe) {
|
|
474
|
-
meJids.push(jid)
|
|
428
|
+
meJids.push(jid);
|
|
475
429
|
}
|
|
476
|
-
|
|
477
430
|
else {
|
|
478
|
-
otherJids.push(jid)
|
|
431
|
+
otherJids.push(jid);
|
|
479
432
|
}
|
|
480
|
-
|
|
481
|
-
allJids.push(jid)
|
|
433
|
+
allJids.push(jid);
|
|
482
434
|
}
|
|
483
435
|
await assertSessions(allJids, false);
|
|
484
436
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
485
437
|
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
486
438
|
createParticipantNodes(otherJids, message, extraAttrs)
|
|
487
|
-
])
|
|
439
|
+
]);
|
|
488
440
|
participants.push(...meNodes);
|
|
489
441
|
participants.push(...otherNodes);
|
|
490
442
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
491
443
|
}
|
|
492
444
|
if (participants.length) {
|
|
493
|
-
if (additionalAttributes
|
|
494
|
-
const peerNode = participants[0]
|
|
495
|
-
|
|
445
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
|
|
446
|
+
const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
|
|
496
447
|
if (peerNode) {
|
|
497
|
-
binaryNodeContent.push(peerNode) // push only enc
|
|
448
|
+
binaryNodeContent.push(peerNode); // push only enc
|
|
498
449
|
}
|
|
499
450
|
}
|
|
500
|
-
|
|
501
451
|
else {
|
|
502
452
|
binaryNodeContent.push({
|
|
503
453
|
tag: 'participants',
|
|
504
454
|
attrs: {},
|
|
505
455
|
content: participants
|
|
506
|
-
})
|
|
456
|
+
});
|
|
507
457
|
}
|
|
508
458
|
}
|
|
509
|
-
|
|
510
459
|
const stanza = {
|
|
511
460
|
tag: 'message',
|
|
512
461
|
attrs: {
|
|
513
462
|
id: msgId,
|
|
514
|
-
type: getTypeMessage(
|
|
463
|
+
type: isNewsletter ? getTypeMessage(message) : 'text',
|
|
515
464
|
...(additionalAttributes || {})
|
|
516
465
|
},
|
|
517
466
|
content: binaryNodeContent
|
|
518
|
-
}
|
|
467
|
+
};
|
|
519
468
|
// if the participant to send to is explicitly specified (generally retry recp)
|
|
520
469
|
// ensure the message is only sent to that person
|
|
521
470
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
522
471
|
if (participant) {
|
|
523
|
-
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
472
|
+
if ((0, WABinary_1.isJidGroup)(destinationJid)) {
|
|
524
473
|
stanza.attrs.to = destinationJid;
|
|
525
474
|
stanza.attrs.participant = participant.jid;
|
|
526
475
|
}
|
|
527
|
-
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
476
|
+
else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
|
|
528
477
|
stanza.attrs.to = participant.jid;
|
|
529
478
|
stanza.attrs.recipient = destinationJid;
|
|
530
479
|
}
|
|
@@ -543,162 +492,138 @@ const makeMessagesSocket = (config) => {
|
|
|
543
492
|
});
|
|
544
493
|
logger.debug({ jid }, 'adding device identity');
|
|
545
494
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
495
|
+
if (pollMessage || messages.eventMessage) {
|
|
496
|
+
let attrs = {};
|
|
497
|
+
if (messages.eventMessage) {
|
|
498
|
+
attrs.event_type = 'creation';
|
|
499
|
+
} else {
|
|
500
|
+
attrs.polltype = 'creation';
|
|
501
|
+
if (isNewsletter) {
|
|
502
|
+
attrs.contenttype = (pollMessage && pollMessage.pollContentType === 2) ? 'image' : 'text';
|
|
552
503
|
}
|
|
553
504
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
stanza.content.push(...additionalNodes)
|
|
559
|
-
didPushAdditional = true
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
else {
|
|
563
|
-
stanza.content.push(botNode)
|
|
564
|
-
}
|
|
505
|
+
stanza.content.push({
|
|
506
|
+
tag: 'meta',
|
|
507
|
+
attrs: attrs
|
|
508
|
+
});
|
|
565
509
|
}
|
|
566
|
-
|
|
567
|
-
if(!isNewsletter && buttonType && !isStatus) {
|
|
568
|
-
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
569
|
-
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
570
|
-
|
|
571
|
-
if (filteredNode) {
|
|
572
|
-
didPushAdditional = true
|
|
573
|
-
stanza.content.push(...additionalNodes)
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
stanza.content.push(...content)
|
|
577
|
-
}
|
|
578
|
-
logger.debug({ jid }, 'adding business node')
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
510
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
582
511
|
stanza.content.push(...additionalNodes);
|
|
583
512
|
}
|
|
584
|
-
|
|
513
|
+
const content = (0, Utils_1.normalizeMessageContent)(message);
|
|
514
|
+
const contentType = (0, Utils_1.getContentType)(content);
|
|
515
|
+
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
|
|
516
|
+
contentType === 'buttonsMessage' ||
|
|
517
|
+
contentType === 'listMessage')) {
|
|
518
|
+
const bizNode = { tag: 'biz', attrs: {} };
|
|
519
|
+
if ((((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
|
|
520
|
+
bizNode.content = [{
|
|
521
|
+
tag: 'interactive',
|
|
522
|
+
attrs: {
|
|
523
|
+
type: 'native_flow',
|
|
524
|
+
v: '1'
|
|
525
|
+
},
|
|
526
|
+
content: [{
|
|
527
|
+
tag: 'native_flow',
|
|
528
|
+
attrs: { v: '9', name: 'mixed' }
|
|
529
|
+
}]
|
|
530
|
+
}];
|
|
531
|
+
}
|
|
532
|
+
else if (message === null || message === void 0 ? void 0 : message.listMessage) {
|
|
533
|
+
// list message only support in private chat
|
|
534
|
+
bizNode.content = [{
|
|
535
|
+
tag: 'list',
|
|
536
|
+
attrs: {
|
|
537
|
+
type: 'product_list',
|
|
538
|
+
v: '2'
|
|
539
|
+
}
|
|
540
|
+
}];
|
|
541
|
+
}
|
|
542
|
+
stanza.content.push(bizNode);
|
|
543
|
+
}
|
|
585
544
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
586
545
|
await sendNode(stanza);
|
|
587
546
|
});
|
|
588
|
-
|
|
589
|
-
message = Types_1.WAProto.Message.fromObject(message)
|
|
590
|
-
|
|
591
|
-
const messageJSON = {
|
|
592
|
-
key: {
|
|
593
|
-
remoteJid: jid,
|
|
594
|
-
fromMe: true,
|
|
595
|
-
id: msgId
|
|
596
|
-
},
|
|
597
|
-
message: message,
|
|
598
|
-
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
599
|
-
messageStubParameters: [],
|
|
600
|
-
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
601
|
-
status: Types_1.WAMessageStatus.PENDING
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
605
|
-
// return msgId;
|
|
547
|
+
return msgId;
|
|
606
548
|
};
|
|
607
549
|
const getTypeMessage = (msg) => {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
550
|
+
if (msg.viewOnceMessage) {
|
|
551
|
+
return getTypeMessage(msg.viewOnceMessage.message);
|
|
552
|
+
}
|
|
553
|
+
else if (msg.viewOnceMessageV2) {
|
|
554
|
+
return getTypeMessage(msg.viewOnceMessageV2.message);
|
|
555
|
+
}
|
|
556
|
+
else if (msg.viewOnceMessageV2Extension) {
|
|
557
|
+
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
558
|
+
}
|
|
559
|
+
else if (msg.ephemeralMessage) {
|
|
560
|
+
return getTypeMessage(msg.ephemeralMessage.message);
|
|
561
|
+
}
|
|
562
|
+
else if (msg.documentWithCaptionMessage) {
|
|
563
|
+
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
564
|
+
}
|
|
565
|
+
else if (msg.reactionMessage) {
|
|
566
|
+
return 'reaction';
|
|
567
|
+
}
|
|
568
|
+
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
569
|
+
return 'poll';
|
|
570
|
+
}
|
|
571
|
+
else if (getMediaType(msg)) {
|
|
572
|
+
return 'media';
|
|
573
|
+
}
|
|
615
574
|
else {
|
|
616
|
-
return 'text'
|
|
575
|
+
return 'text';
|
|
617
576
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
577
|
+
};
|
|
620
578
|
const getMediaType = (message) => {
|
|
621
579
|
if (message.imageMessage) {
|
|
622
|
-
return 'image'
|
|
580
|
+
return 'image';
|
|
623
581
|
}
|
|
624
582
|
else if (message.videoMessage) {
|
|
625
|
-
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
583
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
626
584
|
}
|
|
627
585
|
else if (message.audioMessage) {
|
|
628
|
-
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
586
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
629
587
|
}
|
|
630
588
|
else if (message.contactMessage) {
|
|
631
|
-
return 'vcard'
|
|
589
|
+
return 'vcard';
|
|
632
590
|
}
|
|
633
591
|
else if (message.documentMessage) {
|
|
634
|
-
return 'document'
|
|
592
|
+
return 'document';
|
|
635
593
|
}
|
|
636
594
|
else if (message.contactsArrayMessage) {
|
|
637
|
-
return 'contact_array'
|
|
595
|
+
return 'contact_array';
|
|
638
596
|
}
|
|
639
597
|
else if (message.liveLocationMessage) {
|
|
640
|
-
return 'livelocation'
|
|
598
|
+
return 'livelocation';
|
|
641
599
|
}
|
|
642
600
|
else if (message.stickerMessage) {
|
|
643
|
-
return 'sticker'
|
|
601
|
+
return 'sticker';
|
|
644
602
|
}
|
|
645
603
|
else if (message.listMessage) {
|
|
646
|
-
return 'list'
|
|
604
|
+
return 'list';
|
|
647
605
|
}
|
|
648
606
|
else if (message.listResponseMessage) {
|
|
649
|
-
return 'list_response'
|
|
607
|
+
return 'list_response';
|
|
650
608
|
}
|
|
651
609
|
else if (message.buttonsResponseMessage) {
|
|
652
|
-
return 'buttons_response'
|
|
610
|
+
return 'buttons_response';
|
|
653
611
|
}
|
|
654
612
|
else if (message.orderMessage) {
|
|
655
|
-
return 'order'
|
|
613
|
+
return 'order';
|
|
656
614
|
}
|
|
657
615
|
else if (message.productMessage) {
|
|
658
|
-
return 'product'
|
|
616
|
+
return 'product';
|
|
659
617
|
}
|
|
660
618
|
else if (message.interactiveResponseMessage) {
|
|
661
|
-
return 'native_flow_response'
|
|
619
|
+
return 'native_flow_response';
|
|
662
620
|
}
|
|
663
621
|
else if (message.groupInviteMessage) {
|
|
664
|
-
return 'url'
|
|
665
|
-
}
|
|
666
|
-
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
667
|
-
return 'productlink'
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
const getButtonType = (message) => {
|
|
672
|
-
if (message.listMessage) {
|
|
673
|
-
return 'list'
|
|
674
|
-
}
|
|
675
|
-
else if (message.buttonsMessage) {
|
|
676
|
-
return 'buttons'
|
|
677
|
-
}
|
|
678
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
|
|
679
|
-
return 'review_and_pay'
|
|
680
|
-
}
|
|
681
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
|
|
682
|
-
return 'review_order'
|
|
683
|
-
}
|
|
684
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
685
|
-
return 'payment_info'
|
|
686
|
-
}
|
|
687
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
688
|
-
return 'payment_status'
|
|
622
|
+
return 'url';
|
|
689
623
|
}
|
|
690
|
-
|
|
691
|
-
return 'payment_method'
|
|
692
|
-
}
|
|
693
|
-
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
694
|
-
return 'interactive'
|
|
695
|
-
}
|
|
696
|
-
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
697
|
-
return 'native_flow'
|
|
698
|
-
}
|
|
699
|
-
}
|
|
624
|
+
};
|
|
700
625
|
const getPrivacyTokens = async (jids) => {
|
|
701
|
-
const t = Utils_1.unixTimestampSeconds().toString();
|
|
626
|
+
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
702
627
|
const result = await query({
|
|
703
628
|
tag: 'iq',
|
|
704
629
|
attrs: {
|
|
@@ -713,7 +638,7 @@ const makeMessagesSocket = (config) => {
|
|
|
713
638
|
content: jids.map(jid => ({
|
|
714
639
|
tag: 'token',
|
|
715
640
|
attrs: {
|
|
716
|
-
jid: WABinary_1.jidNormalizedUser(jid),
|
|
641
|
+
jid: (0, WABinary_1.jidNormalizedUser)(jid),
|
|
717
642
|
t,
|
|
718
643
|
type: 'trusted_contact'
|
|
719
644
|
}
|
|
@@ -722,9 +647,9 @@ const makeMessagesSocket = (config) => {
|
|
|
722
647
|
]
|
|
723
648
|
});
|
|
724
649
|
return result;
|
|
725
|
-
}
|
|
650
|
+
};
|
|
726
651
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
|
-
const
|
|
652
|
+
const NotForralll = new NotForrAll(Utils_1, waUploadToServer, relayMessage);
|
|
728
653
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
729
654
|
return {
|
|
730
655
|
...sock,
|
|
@@ -733,23 +658,23 @@ const makeMessagesSocket = (config) => {
|
|
|
733
658
|
relayMessage,
|
|
734
659
|
sendReceipt,
|
|
735
660
|
sendReceipts,
|
|
736
|
-
|
|
661
|
+
NotForralll,
|
|
737
662
|
readMessages,
|
|
738
663
|
refreshMediaConn,
|
|
664
|
+
waUploadToServer,
|
|
665
|
+
fetchPrivacySettings,
|
|
739
666
|
getUSyncDevices,
|
|
740
667
|
createParticipantNodes,
|
|
741
|
-
waUploadToServer,
|
|
742
668
|
sendPeerDataOperationMessage,
|
|
743
|
-
fetchPrivacySettings,
|
|
744
669
|
updateMediaMessage: async (message) => {
|
|
745
670
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
746
671
|
const mediaKey = content.mediaKey;
|
|
747
672
|
const meId = authState.creds.me.id;
|
|
748
|
-
const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
673
|
+
const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
749
674
|
let error = undefined;
|
|
750
675
|
await Promise.all([
|
|
751
676
|
sendNode(node),
|
|
752
|
-
waitForMsgMediaUpdate(update => {
|
|
677
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
753
678
|
const result = update.find(c => c.key.id === message.key.id);
|
|
754
679
|
if (result) {
|
|
755
680
|
if (result.error) {
|
|
@@ -757,7 +682,7 @@ const makeMessagesSocket = (config) => {
|
|
|
757
682
|
}
|
|
758
683
|
else {
|
|
759
684
|
try {
|
|
760
|
-
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
685
|
+
const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
761
686
|
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
762
687
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
763
688
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
@@ -778,132 +703,396 @@ const makeMessagesSocket = (config) => {
|
|
|
778
703
|
throw error;
|
|
779
704
|
}
|
|
780
705
|
ev.emit('messages.update', [
|
|
781
|
-
{
|
|
782
|
-
key: message.key,
|
|
783
|
-
update: {
|
|
784
|
-
message: message.message
|
|
785
|
-
}
|
|
786
|
-
}
|
|
706
|
+
{ key: message.key, update: { message: message.message } }
|
|
787
707
|
]);
|
|
788
708
|
return message;
|
|
789
709
|
},
|
|
790
|
-
|
|
791
|
-
const userJid = authState.creds.me.id
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
795
|
-
const messageType = rahmi.detectType(content);
|
|
796
|
-
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
797
|
-
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
798
|
-
const { disappearingMessagesInChat } = content
|
|
710
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
711
|
+
const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
|
|
712
|
+
let allUsers = new Set()
|
|
713
|
+
allUsers.add(userJid)
|
|
799
714
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
715
|
+
for (const id of jids) {
|
|
716
|
+
const isGroup = WABinary_1.isJidGroup(id)
|
|
717
|
+
const isPrivate = WABinary_1.isJidUser(id)
|
|
803
718
|
|
|
804
|
-
|
|
719
|
+
if (isGroup) {
|
|
720
|
+
try {
|
|
721
|
+
const metadata = await cachedGroupMetadata(id) || await global.groupMetadataCache(id)
|
|
722
|
+
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
|
|
723
|
+
participants.forEach(jid => allUsers.add(jid))
|
|
724
|
+
} catch (error) {
|
|
725
|
+
logger.error(`Error getting metadata for group ${id}: ${error}`)
|
|
726
|
+
}
|
|
727
|
+
} else if (isPrivate) {
|
|
728
|
+
allUsers.add(WABinary_1.jidNormalizedUser(id))
|
|
729
|
+
}
|
|
805
730
|
}
|
|
806
|
-
|
|
807
|
-
else {
|
|
808
|
-
let mediaHandle
|
|
809
731
|
|
|
810
|
-
|
|
732
|
+
const uniqueUsers = Array.from(allUsers)
|
|
733
|
+
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
|
|
734
|
+
|
|
735
|
+
const isMedia = content.image || content.video || content.audio
|
|
736
|
+
const isAudio = !!content.audio
|
|
737
|
+
|
|
738
|
+
const messageContent = {
|
|
739
|
+
...content
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if (isMedia && !isAudio) {
|
|
743
|
+
if (messageContent.text) {
|
|
744
|
+
messageContent.caption = messageContent.text
|
|
745
|
+
|
|
746
|
+
delete messageContent.text
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
delete messageContent.ptt
|
|
750
|
+
delete messageContent.font
|
|
751
|
+
delete messageContent.backgroundColor
|
|
752
|
+
delete messageContent.textColor
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (isAudio) {
|
|
756
|
+
delete messageContent.text
|
|
757
|
+
delete messageContent.caption
|
|
758
|
+
delete messageContent.font
|
|
759
|
+
delete messageContent.textColor
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined
|
|
763
|
+
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined
|
|
764
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined
|
|
765
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
|
|
766
|
+
|
|
767
|
+
let msg
|
|
768
|
+
let mediaHandle
|
|
769
|
+
try {
|
|
770
|
+
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
771
|
+
logger,
|
|
772
|
+
userJid,
|
|
773
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
774
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
775
|
+
fetchOpts: {
|
|
776
|
+
timeout: 3000,
|
|
777
|
+
...axiosOptions || {}
|
|
778
|
+
},
|
|
779
|
+
logger,
|
|
780
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
781
|
+
}),
|
|
782
|
+
upload: async (encFilePath, opts) => {
|
|
783
|
+
const up = await waUploadToServer(encFilePath, {
|
|
784
|
+
...opts
|
|
785
|
+
})
|
|
786
|
+
mediaHandle = up.handle
|
|
787
|
+
return up
|
|
788
|
+
},
|
|
789
|
+
mediaCache: config.mediaCache,
|
|
790
|
+
options: config.options,
|
|
791
|
+
font,
|
|
792
|
+
textColor,
|
|
793
|
+
backgroundColor,
|
|
794
|
+
ptt
|
|
795
|
+
})
|
|
796
|
+
} catch (error) {
|
|
797
|
+
logger.error(`Error generating message: ${error}`)
|
|
798
|
+
throw error
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
802
|
+
messageId: msg.key.id,
|
|
803
|
+
statusJidList: uniqueUsers,
|
|
804
|
+
additionalNodes: [{
|
|
805
|
+
tag: 'meta',
|
|
806
|
+
attrs: {},
|
|
807
|
+
content: [{
|
|
808
|
+
tag: 'mentioned_users',
|
|
809
|
+
attrs: {},
|
|
810
|
+
content: jids.map(jid => ({
|
|
811
|
+
tag: 'to',
|
|
812
|
+
attrs: {
|
|
813
|
+
jid: WABinary_1.jidNormalizedUser(jid)
|
|
814
|
+
}
|
|
815
|
+
}))
|
|
816
|
+
}]
|
|
817
|
+
}]
|
|
818
|
+
})
|
|
819
|
+
|
|
820
|
+
for (const id of jids) {
|
|
821
|
+
try {
|
|
822
|
+
const normalizedId = WABinary_1.jidNormalizedUser(id)
|
|
823
|
+
const isPrivate = WABinary_1.isJidUser(normalizedId)
|
|
824
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
|
|
825
|
+
|
|
826
|
+
const protocolMessage = {
|
|
827
|
+
[type]: {
|
|
828
|
+
message: {
|
|
829
|
+
protocolMessage: {
|
|
830
|
+
key: msg.key,
|
|
831
|
+
type: 25
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
messageContextInfo: {
|
|
836
|
+
messageSecret: crypto_1.randomBytes(32)
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
|
|
841
|
+
protocolMessage, {}
|
|
842
|
+
)
|
|
843
|
+
|
|
844
|
+
await relayMessage(
|
|
845
|
+
normalizedId,
|
|
846
|
+
statusMsg.message, {
|
|
847
|
+
additionalNodes: [{
|
|
848
|
+
tag: 'meta',
|
|
849
|
+
attrs: isPrivate ? {
|
|
850
|
+
is_status_mention: 'true'
|
|
851
|
+
} : {
|
|
852
|
+
is_group_status_mention: 'true'
|
|
853
|
+
}
|
|
854
|
+
}]
|
|
855
|
+
}
|
|
856
|
+
)
|
|
857
|
+
|
|
858
|
+
await Utils_1.delay(2000)
|
|
859
|
+
} catch (error) {
|
|
860
|
+
logger.error(`Error sending to ${id}: ${error}`)
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
return msg
|
|
865
|
+
},
|
|
866
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
867
|
+
var _a, _b, _c;
|
|
868
|
+
const userJid = authState.creds.me.id;
|
|
869
|
+
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
870
|
+
const { filter = false, quoted } = options;
|
|
871
|
+
const messageType = NotForralll.detectType(content);
|
|
872
|
+
|
|
811
873
|
if (messageType) {
|
|
812
|
-
switch(messageType) {
|
|
874
|
+
switch (messageType) {
|
|
813
875
|
case 'PAYMENT':
|
|
814
|
-
const paymentContent = await
|
|
876
|
+
const paymentContent = await NotForralll.handlePayment(content, quoted);
|
|
815
877
|
return await relayMessage(jid, paymentContent, {
|
|
816
878
|
messageId: Utils_1.generateMessageID(),
|
|
817
879
|
...getParticipantAttr()
|
|
818
880
|
});
|
|
819
|
-
|
|
881
|
+
|
|
820
882
|
case 'PRODUCT':
|
|
821
|
-
const productContent = await
|
|
883
|
+
const productContent = await NotForralll.handleProduct(content, jid, quoted);
|
|
822
884
|
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
823
885
|
return await relayMessage(jid, productMsg.message, {
|
|
824
886
|
messageId: productMsg.key.id,
|
|
825
887
|
...getParticipantAttr()
|
|
826
888
|
});
|
|
827
|
-
|
|
889
|
+
|
|
828
890
|
case 'INTERACTIVE':
|
|
829
|
-
const interactiveContent = await
|
|
891
|
+
const interactiveContent = await NotForralll.handleInteractive(content, jid, quoted);
|
|
830
892
|
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
831
893
|
return await relayMessage(jid, interactiveMsg.message, {
|
|
832
894
|
messageId: interactiveMsg.key.id,
|
|
833
895
|
...getParticipantAttr()
|
|
834
896
|
});
|
|
897
|
+
|
|
835
898
|
case 'ALBUM':
|
|
836
|
-
|
|
899
|
+
const albumContent = await NotForralll.handleAlbum(content, jid, quoted);
|
|
900
|
+
return albumContent;
|
|
901
|
+
|
|
837
902
|
case 'EVENT':
|
|
838
|
-
return await
|
|
903
|
+
return await NotForralll.handleEvent(content, jid, quoted);
|
|
904
|
+
|
|
839
905
|
case 'POLL_RESULT':
|
|
840
|
-
return await
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
846
|
-
logger,
|
|
847
|
-
userJid,
|
|
848
|
-
quoted,
|
|
849
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
850
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
851
|
-
fetchOpts: {
|
|
852
|
-
timeout: 3000,
|
|
853
|
-
...axiosOptions || {}
|
|
854
|
-
},
|
|
855
|
-
logger,
|
|
856
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
857
|
-
}),
|
|
858
|
-
upload: async (readStream, opts) => {
|
|
859
|
-
const up = await waUploadToServer(readStream, {
|
|
860
|
-
...opts,
|
|
861
|
-
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
862
|
-
});
|
|
863
|
-
return up;
|
|
864
|
-
},
|
|
865
|
-
mediaCache: config.mediaCache,
|
|
866
|
-
options: config.options,
|
|
867
|
-
...options
|
|
868
|
-
});
|
|
906
|
+
return await NotForralll.handlePollResult(content, jid, quoted);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
869
909
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
910
|
+
if (content.audio && content.ptt) {
|
|
911
|
+
if (!content.mimetype) content.mimetype = 'audio/ogg; codecs=opus';
|
|
912
|
+
content = {
|
|
913
|
+
audio: content.audio,
|
|
914
|
+
mimetype: content.mimetype,
|
|
915
|
+
ptt: true
|
|
916
|
+
};
|
|
917
|
+
}
|
|
873
918
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
919
|
+
if (!options.ephemeralExpiration) {
|
|
920
|
+
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
921
|
+
const groups = await sock.groupQuery(jid, 'get', [{
|
|
922
|
+
tag: 'query',
|
|
923
|
+
attrs: {
|
|
924
|
+
request: 'interactive'
|
|
925
|
+
}
|
|
926
|
+
}]);
|
|
927
|
+
const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
|
|
928
|
+
const expiration = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(metadata, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.expiration) || 0;
|
|
929
|
+
options.ephemeralExpiration = expiration;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (typeof content === 'object' &&
|
|
933
|
+
'disappearingMessagesInChat' in content &&
|
|
934
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
935
|
+
(0, WABinary_1.isJidGroup)(jid)) {
|
|
936
|
+
const { disappearingMessagesInChat } = content;
|
|
937
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
938
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
939
|
+
disappearingMessagesInChat;
|
|
940
|
+
await groupToggleEphemeral(jid, value);
|
|
941
|
+
}
|
|
942
|
+
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
943
|
+
const { album, caption } = content;
|
|
944
|
+
if (caption && !album[0].caption) {
|
|
945
|
+
album[0].caption = caption;
|
|
946
|
+
}
|
|
947
|
+
let mediaHandle;
|
|
948
|
+
let mediaMsg;
|
|
949
|
+
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
950
|
+
albumMessage: {
|
|
951
|
+
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
952
|
+
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
953
|
+
}
|
|
954
|
+
}, { userJid, ...options });
|
|
955
|
+
await relayMessage(jid, albumMsg.message, {
|
|
956
|
+
messageId: albumMsg.key.id
|
|
957
|
+
});
|
|
958
|
+
for (const i in album) {
|
|
959
|
+
const media = album[i];
|
|
960
|
+
if ('image' in media) {
|
|
961
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
962
|
+
image: media.image,
|
|
963
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
964
|
+
...options
|
|
965
|
+
}, {
|
|
966
|
+
userJid,
|
|
967
|
+
upload: async (readStream, opts) => {
|
|
968
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
969
|
+
mediaHandle = up.handle;
|
|
970
|
+
return up;
|
|
971
|
+
},
|
|
972
|
+
...options,
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
else if ('video' in media) {
|
|
976
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
977
|
+
video: media.video,
|
|
978
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
979
|
+
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
980
|
+
...options
|
|
981
|
+
}, {
|
|
982
|
+
userJid,
|
|
983
|
+
upload: async (readStream, opts) => {
|
|
984
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
985
|
+
mediaHandle = up.handle;
|
|
986
|
+
return up;
|
|
987
|
+
},
|
|
988
|
+
...options,
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
if (mediaMsg) {
|
|
992
|
+
mediaMsg.message.messageContextInfo = {
|
|
993
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
994
|
+
messageAssociation: {
|
|
995
|
+
associationType: 1,
|
|
996
|
+
parentMessageKey: albumMsg.key
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
await relayMessage(jid, mediaMsg.message, {
|
|
1001
|
+
messageId: mediaMsg.key.id
|
|
1002
|
+
});
|
|
1003
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
1004
|
+
}
|
|
1005
|
+
return albumMsg;
|
|
1006
|
+
}
|
|
1007
|
+
else {
|
|
1008
|
+
let mediaHandle;
|
|
1009
|
+
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
1010
|
+
logger,
|
|
1011
|
+
userJid,
|
|
1012
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
1013
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1014
|
+
fetchOpts: {
|
|
1015
|
+
timeout: 3000,
|
|
1016
|
+
...axiosOptions || {}
|
|
1017
|
+
},
|
|
1018
|
+
logger,
|
|
1019
|
+
uploadImage: generateHighQualityLinkPreview
|
|
1020
|
+
? waUploadToServer
|
|
1021
|
+
: undefined
|
|
1022
|
+
}),
|
|
1023
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1024
|
+
upload: async (readStream, opts) => {
|
|
1025
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
1026
|
+
mediaHandle = up.handle;
|
|
1027
|
+
return up;
|
|
1028
|
+
},
|
|
1029
|
+
mediaCache: config.mediaCache,
|
|
1030
|
+
options: config.options,
|
|
1031
|
+
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
|
|
1032
|
+
...options,
|
|
1033
|
+
});
|
|
1034
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1035
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1036
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1037
|
+
const isKeepMsg = 'keep' in content && content.keep;
|
|
1038
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1039
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
1040
|
+
const additionalAttributes = {};
|
|
1041
|
+
const additionalNodes = [];
|
|
1042
|
+
// required for delete
|
|
1043
|
+
if (isDeleteMsg) {
|
|
1044
|
+
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1045
|
+
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
1046
|
+
additionalAttributes.edit = '8';
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
additionalAttributes.edit = '7';
|
|
1050
|
+
}
|
|
1051
|
+
// required for edit message
|
|
1052
|
+
}
|
|
1053
|
+
else if (isEditMsg) {
|
|
1054
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
1055
|
+
// required for pin message
|
|
1056
|
+
}
|
|
1057
|
+
else if (isPinMsg) {
|
|
1058
|
+
additionalAttributes.edit = '2';
|
|
1059
|
+
// required for keep message
|
|
1060
|
+
}
|
|
1061
|
+
else if (isKeepMsg) {
|
|
1062
|
+
additionalAttributes.edit = '6';
|
|
1063
|
+
// required for polling message
|
|
1064
|
+
}
|
|
1065
|
+
else if (isPollMessage) {
|
|
1066
|
+
additionalNodes.push({
|
|
1067
|
+
tag: 'meta',
|
|
1068
|
+
attrs: {
|
|
1069
|
+
polltype: 'creation'
|
|
1070
|
+
},
|
|
1071
|
+
});
|
|
1072
|
+
// required to display AI icon on message
|
|
1073
|
+
}
|
|
1074
|
+
else if (isAiMsg) {
|
|
1075
|
+
additionalNodes.push({
|
|
885
1076
|
attrs: {
|
|
886
1077
|
biz_bot: '1'
|
|
887
1078
|
}, tag: "bot"
|
|
888
1079
|
});
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
cachedGroupMetadata
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
statusJidList: options.statusJidList
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
return fullMsg;
|
|
1080
|
+
}
|
|
1081
|
+
if (mediaHandle) {
|
|
1082
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
1083
|
+
}
|
|
1084
|
+
if ('cachedGroupMetadata' in options) {
|
|
1085
|
+
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
1086
|
+
}
|
|
1087
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
|
|
1088
|
+
if (config.emitOwnEvents) {
|
|
1089
|
+
process.nextTick(() => {
|
|
1090
|
+
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
return fullMsg;
|
|
905
1094
|
}
|
|
906
1095
|
}
|
|
907
|
-
}
|
|
1096
|
+
};
|
|
908
1097
|
};
|
|
909
1098
|
exports.makeMessagesSocket = makeMessagesSocket;
|