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