@hbmodsofc/baileys 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.MD +220 -1198
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +5619 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +97 -122
- package/lib/Defaults/phonenumber_mcc.json +223 -0
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/business.js +8 -2
- package/lib/Socket/chats.js +455 -288
- package/lib/Socket/communities.js +441 -0
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/hbmods.js +374 -406
- package/lib/Socket/index.js +43 -11
- package/lib/Socket/messages-recv.js +24 -69
- package/lib/Socket/messages-send.js +391 -419
- package/lib/Socket/newsletter.js +104 -190
- package/lib/Socket/socket.js +40 -54
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +27 -15
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/index.js +2 -2
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.js +13 -9
- package/lib/Utils/generics.js +88 -84
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +340 -246
- package/lib/Utils/messages.js +329 -192
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/resolveJid.js +52 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -0
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.js +2 -1
- package/package.json +112 -104
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- 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/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/hbmods.d.ts +0 -254
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.js.bak +0 -237
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -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");
|
|
10
|
+
const hbmodsofc = require('./hbmods');
|
|
9
11
|
const WAProto_1 = require("../../WAProto");
|
|
10
12
|
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");
|
|
16
17
|
const newsletter_1 = require("./newsletter");
|
|
17
|
-
const WAUSync_1 = require("../WAUSync")
|
|
18
|
-
const hbmodofc = require('./hbmods');
|
|
19
|
-
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
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,32 @@ 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 }) => {
|
|
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 isNewsletter = server === 'newsletter';
|
|
301
271
|
const isStatus = jid === statusJid;
|
|
302
272
|
const isLid = server === 'lid';
|
|
303
|
-
|
|
304
|
-
const isNewsletter = server === 'newsletter';
|
|
305
|
-
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
273
|
+
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
|
306
274
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
307
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
275
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
308
276
|
const participants = [];
|
|
309
|
-
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
277
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
310
278
|
const binaryNodeContent = [];
|
|
311
279
|
const devices = [];
|
|
312
280
|
const meMsg = {
|
|
313
281
|
deviceSentMessage: {
|
|
314
282
|
destinationJid,
|
|
315
283
|
message
|
|
316
|
-
}
|
|
284
|
+
},
|
|
285
|
+
messageContextInfo: message.messageContextInfo
|
|
317
286
|
};
|
|
318
|
-
const extraAttrs = {}
|
|
319
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
320
|
-
const buttonType = getButtonType(messages);
|
|
287
|
+
const extraAttrs = {};
|
|
321
288
|
if (participant) {
|
|
322
289
|
// when the retry request is not for a group
|
|
323
290
|
// only send to the specific device that asked for a retry
|
|
@@ -325,80 +292,67 @@ const makeMessagesSocket = (config) => {
|
|
|
325
292
|
if (!isGroup && !isStatus) {
|
|
326
293
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
327
294
|
}
|
|
328
|
-
const { user, device } = WABinary_1.jidDecode(participant.jid);
|
|
295
|
+
const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
|
|
329
296
|
devices.push({ user, device });
|
|
330
297
|
}
|
|
331
298
|
await authState.keys.transaction(async () => {
|
|
332
|
-
|
|
333
|
-
|
|
299
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
300
|
+
const mediaType = getMediaType(message);
|
|
334
301
|
if (mediaType) {
|
|
335
|
-
extraAttrs['mediatype'] = mediaType
|
|
302
|
+
extraAttrs['mediatype'] = mediaType;
|
|
336
303
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
extraAttrs['decrypt-fail'] = 'hide'
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
343
|
-
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
304
|
+
if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
|
|
305
|
+
extraAttrs['decrypt-fail'] = 'hide';
|
|
344
306
|
}
|
|
345
|
-
|
|
346
307
|
if (isGroup || isStatus) {
|
|
347
308
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
348
309
|
(async () => {
|
|
349
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
350
|
-
if (groupData) {
|
|
310
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
311
|
+
if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
|
|
351
312
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
352
313
|
}
|
|
353
|
-
|
|
354
314
|
else if (!isStatus) {
|
|
355
|
-
groupData = await groupMetadata(jid)
|
|
315
|
+
groupData = await groupMetadata(jid);
|
|
356
316
|
}
|
|
357
|
-
|
|
358
317
|
return groupData;
|
|
359
318
|
})(),
|
|
360
319
|
(async () => {
|
|
361
320
|
if (!participant && !isStatus) {
|
|
362
|
-
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
|
-
return result[jid] || {}
|
|
321
|
+
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
322
|
+
return result[jid] || {};
|
|
364
323
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
})()
|
|
324
|
+
return {};
|
|
325
|
+
})()
|
|
369
326
|
]);
|
|
370
327
|
if (!participant) {
|
|
371
|
-
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
-
|
|
328
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
|
|
373
329
|
if (isStatus && statusJidList) {
|
|
374
|
-
participantsList.push(...statusJidList)
|
|
330
|
+
participantsList.push(...statusJidList);
|
|
375
331
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
const bytes = Utils_1.encodeWAMessage(patched);
|
|
392
|
-
|
|
332
|
+
if (!isStatus) {
|
|
333
|
+
additionalAttributes = {
|
|
334
|
+
...additionalAttributes,
|
|
335
|
+
// eslint-disable-next-line camelcase
|
|
336
|
+
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
340
|
+
devices.push(...additionalDevices);
|
|
341
|
+
}
|
|
342
|
+
const patched = await patchMessageBeforeSending(message);
|
|
343
|
+
if (Array.isArray(patched)) {
|
|
344
|
+
throw new boom_1.Boom('Per-jid patching is not supported in groups');
|
|
345
|
+
}
|
|
346
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
393
347
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
394
348
|
group: destinationJid,
|
|
395
349
|
data: bytes,
|
|
396
350
|
meId,
|
|
397
351
|
});
|
|
398
352
|
const senderKeyJids = [];
|
|
399
|
-
|
|
353
|
+
// ensure a connection is established with every device
|
|
400
354
|
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);
|
|
355
|
+
const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
402
356
|
if (!senderKeyMap[jid] || !!participant) {
|
|
403
357
|
senderKeyJids.push(jid);
|
|
404
358
|
// store that this person has had the sender keys sent to them
|
|
@@ -416,115 +370,107 @@ const makeMessagesSocket = (config) => {
|
|
|
416
370
|
}
|
|
417
371
|
};
|
|
418
372
|
await assertSessions(senderKeyJids, false);
|
|
419
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
373
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
|
|
420
374
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
421
375
|
participants.push(...result.nodes);
|
|
422
376
|
}
|
|
423
377
|
binaryNodeContent.push({
|
|
424
378
|
tag: 'enc',
|
|
425
|
-
attrs: { v: '2', type: 'skmsg'
|
|
379
|
+
attrs: { v: '2', type: 'skmsg' },
|
|
426
380
|
content: ciphertext
|
|
427
381
|
});
|
|
428
382
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
429
383
|
}
|
|
430
384
|
else if (isNewsletter) {
|
|
431
385
|
// Message edit
|
|
432
|
-
if (message.protocolMessage
|
|
433
|
-
msgId = message.protocolMessage.key
|
|
434
|
-
message = message.protocolMessage.editedMessage
|
|
386
|
+
if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
|
|
387
|
+
msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
|
|
388
|
+
message = message.protocolMessage.editedMessage;
|
|
435
389
|
}
|
|
436
|
-
|
|
437
390
|
// Message delete
|
|
438
|
-
if (message.protocolMessage
|
|
439
|
-
msgId = message.protocolMessage.key
|
|
440
|
-
message = {}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
391
|
+
if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
392
|
+
msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
|
|
393
|
+
message = {};
|
|
394
|
+
}
|
|
395
|
+
const patched = await patchMessageBeforeSending(message, []);
|
|
396
|
+
if (Array.isArray(patched)) {
|
|
397
|
+
throw new boom_1.Boom('Per-jid patching is not supported in channel');
|
|
398
|
+
}
|
|
399
|
+
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
446
400
|
binaryNodeContent.push({
|
|
447
401
|
tag: 'plaintext',
|
|
448
|
-
attrs:
|
|
402
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
449
403
|
content: bytes
|
|
450
|
-
})
|
|
404
|
+
});
|
|
451
405
|
}
|
|
452
406
|
else {
|
|
453
|
-
const { user: meUser } = WABinary_1.jidDecode(meId);
|
|
407
|
+
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
454
408
|
if (!participant) {
|
|
455
|
-
devices.push({ user })
|
|
409
|
+
devices.push({ user });
|
|
456
410
|
if (user !== meUser) {
|
|
457
|
-
devices.push({ user: meUser })
|
|
411
|
+
devices.push({ user: meUser });
|
|
458
412
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
devices.push(...additionalDevices)
|
|
413
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
414
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
415
|
+
devices.push(...additionalDevices);
|
|
464
416
|
}
|
|
465
417
|
}
|
|
466
418
|
const allJids = [];
|
|
467
419
|
const meJids = [];
|
|
468
420
|
const otherJids = [];
|
|
469
421
|
for (const { user, device } of devices) {
|
|
470
|
-
const isMe = user === meUser
|
|
471
|
-
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds
|
|
472
|
-
|
|
422
|
+
const isMe = user === meUser;
|
|
423
|
+
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
424
|
if (isMe) {
|
|
474
|
-
meJids.push(jid)
|
|
425
|
+
meJids.push(jid);
|
|
475
426
|
}
|
|
476
|
-
|
|
477
427
|
else {
|
|
478
|
-
otherJids.push(jid)
|
|
428
|
+
otherJids.push(jid);
|
|
479
429
|
}
|
|
480
|
-
|
|
481
|
-
allJids.push(jid)
|
|
430
|
+
allJids.push(jid);
|
|
482
431
|
}
|
|
483
432
|
await assertSessions(allJids, false);
|
|
484
433
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
485
434
|
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
486
435
|
createParticipantNodes(otherJids, message, extraAttrs)
|
|
487
|
-
])
|
|
436
|
+
]);
|
|
488
437
|
participants.push(...meNodes);
|
|
489
438
|
participants.push(...otherNodes);
|
|
490
439
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
491
440
|
}
|
|
492
441
|
if (participants.length) {
|
|
493
|
-
if (additionalAttributes
|
|
494
|
-
const peerNode = participants[0]
|
|
495
|
-
|
|
442
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
|
|
443
|
+
const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
|
|
496
444
|
if (peerNode) {
|
|
497
|
-
binaryNodeContent.push(peerNode) // push only enc
|
|
445
|
+
binaryNodeContent.push(peerNode); // push only enc
|
|
498
446
|
}
|
|
499
447
|
}
|
|
500
|
-
|
|
501
448
|
else {
|
|
502
449
|
binaryNodeContent.push({
|
|
503
450
|
tag: 'participants',
|
|
504
451
|
attrs: {},
|
|
505
452
|
content: participants
|
|
506
|
-
})
|
|
453
|
+
});
|
|
507
454
|
}
|
|
508
455
|
}
|
|
509
|
-
|
|
510
456
|
const stanza = {
|
|
511
457
|
tag: 'message',
|
|
512
458
|
attrs: {
|
|
513
459
|
id: msgId,
|
|
514
|
-
type: getTypeMessage(
|
|
460
|
+
type: isNewsletter ? getTypeMessage(message) : 'text',
|
|
515
461
|
...(additionalAttributes || {})
|
|
516
462
|
},
|
|
517
463
|
content: binaryNodeContent
|
|
518
|
-
}
|
|
464
|
+
};
|
|
519
465
|
// if the participant to send to is explicitly specified (generally retry recp)
|
|
520
466
|
// ensure the message is only sent to that person
|
|
521
467
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
522
468
|
if (participant) {
|
|
523
|
-
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
469
|
+
if ((0, WABinary_1.isJidGroup)(destinationJid)) {
|
|
524
470
|
stanza.attrs.to = destinationJid;
|
|
525
471
|
stanza.attrs.participant = participant.jid;
|
|
526
472
|
}
|
|
527
|
-
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
473
|
+
else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
|
|
528
474
|
stanza.attrs.to = participant.jid;
|
|
529
475
|
stanza.attrs.recipient = destinationJid;
|
|
530
476
|
}
|
|
@@ -543,162 +489,123 @@ const makeMessagesSocket = (config) => {
|
|
|
543
489
|
});
|
|
544
490
|
logger.debug({ jid }, 'adding device identity');
|
|
545
491
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const botNode = {
|
|
549
|
-
tag: 'bot',
|
|
550
|
-
attrs: {
|
|
551
|
-
biz_bot: '1'
|
|
552
|
-
}
|
|
553
|
-
}
|
|
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)
|
|
564
|
-
}
|
|
492
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
493
|
+
stanza.content.push(...additionalNodes);
|
|
565
494
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
495
|
+
const content = (0, Utils_1.normalizeMessageContent)(message);
|
|
496
|
+
const contentType = (0, Utils_1.getContentType)(content);
|
|
497
|
+
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
|
|
498
|
+
contentType === 'buttonsMessage' ||
|
|
499
|
+
contentType === 'listMessage')) {
|
|
500
|
+
const bizNode = { tag: 'biz', attrs: {} };
|
|
501
|
+
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))) {
|
|
502
|
+
bizNode.content = [{
|
|
503
|
+
tag: 'interactive',
|
|
504
|
+
attrs: {
|
|
505
|
+
type: 'native_flow',
|
|
506
|
+
v: '1'
|
|
507
|
+
},
|
|
508
|
+
content: [{
|
|
509
|
+
tag: 'native_flow',
|
|
510
|
+
attrs: { v: '9', name: 'mixed' }
|
|
511
|
+
}]
|
|
512
|
+
}];
|
|
577
513
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
514
|
+
else if (message === null || message === void 0 ? void 0 : message.listMessage) {
|
|
515
|
+
// list message only support in private chat
|
|
516
|
+
bizNode.content = [{
|
|
517
|
+
tag: 'list',
|
|
518
|
+
attrs: {
|
|
519
|
+
type: 'product_list',
|
|
520
|
+
v: '2'
|
|
521
|
+
}
|
|
522
|
+
}];
|
|
523
|
+
}
|
|
524
|
+
stanza.content.push(bizNode);
|
|
583
525
|
}
|
|
584
|
-
|
|
585
526
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
586
527
|
await sendNode(stanza);
|
|
587
528
|
});
|
|
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;
|
|
529
|
+
return msgId;
|
|
606
530
|
};
|
|
607
531
|
const getTypeMessage = (msg) => {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
532
|
+
if (msg.viewOnceMessage) {
|
|
533
|
+
return getTypeMessage(msg.viewOnceMessage.message);
|
|
534
|
+
}
|
|
535
|
+
else if (msg.viewOnceMessageV2) {
|
|
536
|
+
return getTypeMessage(msg.viewOnceMessageV2.message);
|
|
537
|
+
}
|
|
538
|
+
else if (msg.viewOnceMessageV2Extension) {
|
|
539
|
+
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
540
|
+
}
|
|
541
|
+
else if (msg.ephemeralMessage) {
|
|
542
|
+
return getTypeMessage(msg.ephemeralMessage.message);
|
|
543
|
+
}
|
|
544
|
+
else if (msg.documentWithCaptionMessage) {
|
|
545
|
+
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
546
|
+
}
|
|
547
|
+
else if (msg.reactionMessage) {
|
|
548
|
+
return 'reaction';
|
|
549
|
+
}
|
|
550
|
+
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
551
|
+
return 'poll';
|
|
552
|
+
}
|
|
553
|
+
else if (getMediaType(msg)) {
|
|
554
|
+
return 'media';
|
|
555
|
+
}
|
|
615
556
|
else {
|
|
616
|
-
return 'text'
|
|
557
|
+
return 'text';
|
|
617
558
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
559
|
+
};
|
|
620
560
|
const getMediaType = (message) => {
|
|
621
561
|
if (message.imageMessage) {
|
|
622
|
-
return 'image'
|
|
562
|
+
return 'image';
|
|
623
563
|
}
|
|
624
564
|
else if (message.videoMessage) {
|
|
625
|
-
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
565
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
626
566
|
}
|
|
627
567
|
else if (message.audioMessage) {
|
|
628
|
-
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
568
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
629
569
|
}
|
|
630
570
|
else if (message.contactMessage) {
|
|
631
|
-
return 'vcard'
|
|
571
|
+
return 'vcard';
|
|
632
572
|
}
|
|
633
573
|
else if (message.documentMessage) {
|
|
634
|
-
return 'document'
|
|
574
|
+
return 'document';
|
|
635
575
|
}
|
|
636
576
|
else if (message.contactsArrayMessage) {
|
|
637
|
-
return 'contact_array'
|
|
577
|
+
return 'contact_array';
|
|
638
578
|
}
|
|
639
579
|
else if (message.liveLocationMessage) {
|
|
640
|
-
return 'livelocation'
|
|
580
|
+
return 'livelocation';
|
|
641
581
|
}
|
|
642
582
|
else if (message.stickerMessage) {
|
|
643
|
-
return 'sticker'
|
|
583
|
+
return 'sticker';
|
|
644
584
|
}
|
|
645
585
|
else if (message.listMessage) {
|
|
646
|
-
return 'list'
|
|
586
|
+
return 'list';
|
|
647
587
|
}
|
|
648
588
|
else if (message.listResponseMessage) {
|
|
649
|
-
return 'list_response'
|
|
589
|
+
return 'list_response';
|
|
650
590
|
}
|
|
651
591
|
else if (message.buttonsResponseMessage) {
|
|
652
|
-
return 'buttons_response'
|
|
592
|
+
return 'buttons_response';
|
|
653
593
|
}
|
|
654
594
|
else if (message.orderMessage) {
|
|
655
|
-
return 'order'
|
|
595
|
+
return 'order';
|
|
656
596
|
}
|
|
657
597
|
else if (message.productMessage) {
|
|
658
|
-
return 'product'
|
|
598
|
+
return 'product';
|
|
659
599
|
}
|
|
660
600
|
else if (message.interactiveResponseMessage) {
|
|
661
|
-
return 'native_flow_response'
|
|
601
|
+
return 'native_flow_response';
|
|
662
602
|
}
|
|
663
603
|
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'
|
|
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'
|
|
604
|
+
return 'url';
|
|
695
605
|
}
|
|
696
|
-
|
|
697
|
-
return 'native_flow'
|
|
698
|
-
}
|
|
699
|
-
}
|
|
606
|
+
};
|
|
700
607
|
const getPrivacyTokens = async (jids) => {
|
|
701
|
-
const t = Utils_1.unixTimestampSeconds().toString();
|
|
608
|
+
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
702
609
|
const result = await query({
|
|
703
610
|
tag: 'iq',
|
|
704
611
|
attrs: {
|
|
@@ -713,7 +620,7 @@ const makeMessagesSocket = (config) => {
|
|
|
713
620
|
content: jids.map(jid => ({
|
|
714
621
|
tag: 'token',
|
|
715
622
|
attrs: {
|
|
716
|
-
jid: WABinary_1.jidNormalizedUser(jid),
|
|
623
|
+
jid: (0, WABinary_1.jidNormalizedUser)(jid),
|
|
717
624
|
t,
|
|
718
625
|
type: 'trusted_contact'
|
|
719
626
|
}
|
|
@@ -722,34 +629,34 @@ const makeMessagesSocket = (config) => {
|
|
|
722
629
|
]
|
|
723
630
|
});
|
|
724
631
|
return result;
|
|
725
|
-
}
|
|
632
|
+
};
|
|
726
633
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
|
-
const
|
|
634
|
+
const miz = new hbmodsofc(Utils_1, waUploadToServer, relayMessage);
|
|
728
635
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
729
636
|
return {
|
|
730
637
|
...sock,
|
|
638
|
+
miz,
|
|
731
639
|
getPrivacyTokens,
|
|
732
640
|
assertSessions,
|
|
733
641
|
relayMessage,
|
|
734
642
|
sendReceipt,
|
|
735
643
|
sendReceipts,
|
|
736
|
-
rahmi,
|
|
737
644
|
readMessages,
|
|
738
645
|
refreshMediaConn,
|
|
646
|
+
waUploadToServer,
|
|
647
|
+
fetchPrivacySettings,
|
|
739
648
|
getUSyncDevices,
|
|
740
649
|
createParticipantNodes,
|
|
741
|
-
waUploadToServer,
|
|
742
650
|
sendPeerDataOperationMessage,
|
|
743
|
-
fetchPrivacySettings,
|
|
744
651
|
updateMediaMessage: async (message) => {
|
|
745
652
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
746
653
|
const mediaKey = content.mediaKey;
|
|
747
654
|
const meId = authState.creds.me.id;
|
|
748
|
-
const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
655
|
+
const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
749
656
|
let error = undefined;
|
|
750
657
|
await Promise.all([
|
|
751
658
|
sendNode(node),
|
|
752
|
-
waitForMsgMediaUpdate(update => {
|
|
659
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
753
660
|
const result = update.find(c => c.key.id === message.key.id);
|
|
754
661
|
if (result) {
|
|
755
662
|
if (result.error) {
|
|
@@ -757,7 +664,7 @@ const makeMessagesSocket = (config) => {
|
|
|
757
664
|
}
|
|
758
665
|
else {
|
|
759
666
|
try {
|
|
760
|
-
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
667
|
+
const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
761
668
|
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
762
669
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
763
670
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
@@ -778,132 +685,197 @@ const makeMessagesSocket = (config) => {
|
|
|
778
685
|
throw error;
|
|
779
686
|
}
|
|
780
687
|
ev.emit('messages.update', [
|
|
781
|
-
{
|
|
782
|
-
key: message.key,
|
|
783
|
-
update: {
|
|
784
|
-
message: message.message
|
|
785
|
-
}
|
|
786
|
-
}
|
|
688
|
+
{ key: message.key, update: { message: message.message } }
|
|
787
689
|
]);
|
|
788
690
|
return message;
|
|
789
691
|
},
|
|
790
692
|
sendMessage: async (jid, content, options = {}) => {
|
|
693
|
+
var _a, _b, _c;
|
|
791
694
|
const userJid = authState.creds.me.id;
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
695
|
+
if (!options.ephemeralExpiration) {
|
|
696
|
+
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
697
|
+
const groups = await sock.groupQuery(jid, 'get', [{
|
|
698
|
+
tag: 'query',
|
|
699
|
+
attrs: {
|
|
700
|
+
request: 'interactive'
|
|
701
|
+
}
|
|
702
|
+
}]);
|
|
703
|
+
const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
|
|
704
|
+
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;
|
|
705
|
+
options.ephemeralExpiration = expiration;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (typeof content === 'object' &&
|
|
709
|
+
'disappearingMessagesInChat' in content &&
|
|
710
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
711
|
+
(0, WABinary_1.isJidGroup)(jid)) {
|
|
712
|
+
const { disappearingMessagesInChat } = content;
|
|
800
713
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
801
714
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
802
|
-
disappearingMessagesInChat
|
|
803
|
-
|
|
804
|
-
await groupToggleEphemeral(jid, value)
|
|
715
|
+
disappearingMessagesInChat;
|
|
716
|
+
await groupToggleEphemeral(jid, value);
|
|
805
717
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
718
|
+
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
719
|
+
const { album, caption } = content;
|
|
720
|
+
if (caption && !album[0].caption) {
|
|
721
|
+
album[0].caption = caption;
|
|
722
|
+
}
|
|
723
|
+
let mediaHandle;
|
|
724
|
+
let mediaMsg;
|
|
725
|
+
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
726
|
+
albumMessage: {
|
|
727
|
+
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
728
|
+
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
729
|
+
}
|
|
730
|
+
}, { userJid, ...options });
|
|
731
|
+
await relayMessage(jid, albumMsg.message, {
|
|
732
|
+
messageId: albumMsg.key.id
|
|
733
|
+
});
|
|
734
|
+
for (const i in album) {
|
|
735
|
+
const media = album[i];
|
|
736
|
+
if ('image' in media) {
|
|
737
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
738
|
+
image: media.image,
|
|
739
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
740
|
+
...options
|
|
741
|
+
}, {
|
|
742
|
+
userJid,
|
|
743
|
+
upload: async (readStream, opts) => {
|
|
744
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
745
|
+
mediaHandle = up.handle;
|
|
746
|
+
return up;
|
|
747
|
+
},
|
|
748
|
+
...options,
|
|
826
749
|
});
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
...
|
|
750
|
+
}
|
|
751
|
+
else if ('video' in media) {
|
|
752
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
753
|
+
video: media.video,
|
|
754
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
755
|
+
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
756
|
+
...options
|
|
757
|
+
}, {
|
|
758
|
+
userJid,
|
|
759
|
+
upload: async (readStream, opts) => {
|
|
760
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
761
|
+
mediaHandle = up.handle;
|
|
762
|
+
return up;
|
|
763
|
+
},
|
|
764
|
+
...options,
|
|
834
765
|
});
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
766
|
+
}
|
|
767
|
+
if (mediaMsg) {
|
|
768
|
+
mediaMsg.message.messageContextInfo = {
|
|
769
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
770
|
+
messageAssociation: {
|
|
771
|
+
associationType: 1,
|
|
772
|
+
parentMessageKey: albumMsg.key
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
await relayMessage(jid, mediaMsg.message, {
|
|
777
|
+
messageId: mediaMsg.key.id
|
|
778
|
+
});
|
|
779
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
843
780
|
}
|
|
781
|
+
return albumMsg;
|
|
844
782
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
timeout: 3000,
|
|
853
|
-
...axiosOptions || {}
|
|
854
|
-
},
|
|
783
|
+
else if (content.groupStatusMessage) {
|
|
784
|
+
const { quoted } = options;
|
|
785
|
+
return await miz.handleGroupStory(content, jid, quoted);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
let mediaHandle;
|
|
789
|
+
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
855
790
|
logger,
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
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"
|
|
888
|
-
});
|
|
889
|
-
}
|
|
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'));
|
|
791
|
+
userJid,
|
|
792
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
793
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
794
|
+
fetchOpts: {
|
|
795
|
+
timeout: 3000,
|
|
796
|
+
...axiosOptions || {}
|
|
797
|
+
},
|
|
798
|
+
logger,
|
|
799
|
+
uploadImage: generateHighQualityLinkPreview
|
|
800
|
+
? waUploadToServer
|
|
801
|
+
: undefined
|
|
802
|
+
}),
|
|
803
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
804
|
+
upload: async (readStream, opts) => {
|
|
805
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
806
|
+
mediaHandle = up.handle;
|
|
807
|
+
return up;
|
|
808
|
+
},
|
|
809
|
+
mediaCache: config.mediaCache,
|
|
810
|
+
options: config.options,
|
|
811
|
+
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
|
|
812
|
+
...options,
|
|
902
813
|
});
|
|
903
|
-
|
|
904
|
-
|
|
814
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
815
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
816
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
817
|
+
const isKeepMsg = 'keep' in content && content.keep;
|
|
818
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
819
|
+
const isAiMsg = content && content.ai === true;
|
|
820
|
+
const additionalAttributes = {};
|
|
821
|
+
const additionalNodes = [];
|
|
822
|
+
// required for delete
|
|
823
|
+
if (isDeleteMsg) {
|
|
824
|
+
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
825
|
+
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
826
|
+
additionalAttributes.edit = '8';
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
additionalAttributes.edit = '7';
|
|
830
|
+
}
|
|
831
|
+
// required for edit message
|
|
832
|
+
}
|
|
833
|
+
else if (isEditMsg) {
|
|
834
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
835
|
+
// required for pin message
|
|
836
|
+
}
|
|
837
|
+
else if (isPinMsg) {
|
|
838
|
+
additionalAttributes.edit = '2';
|
|
839
|
+
// required for keep message
|
|
840
|
+
}
|
|
841
|
+
else if (isKeepMsg) {
|
|
842
|
+
additionalAttributes.edit = '6';
|
|
843
|
+
// required for polling message
|
|
844
|
+
}
|
|
845
|
+
else if (isPollMessage) {
|
|
846
|
+
additionalNodes.push({
|
|
847
|
+
tag: 'meta',
|
|
848
|
+
attrs: {
|
|
849
|
+
polltype: 'creation'
|
|
850
|
+
},
|
|
851
|
+
});
|
|
852
|
+
// required to display AI icon on message
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
else if (isAiMsg) {
|
|
856
|
+
fullMsg.message.messageContextInfo = {
|
|
857
|
+
...(fullMsg.message.messageContextInfo || {}),
|
|
858
|
+
businessMessageType: 3,
|
|
859
|
+
aiMessageMetadata: {
|
|
860
|
+
isAiMessage: true
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
if (mediaHandle) {
|
|
865
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
866
|
+
}
|
|
867
|
+
if ('cachedGroupMetadata' in options) {
|
|
868
|
+
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
869
|
+
}
|
|
870
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
|
|
871
|
+
if (config.emitOwnEvents) {
|
|
872
|
+
process.nextTick(() => {
|
|
873
|
+
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
return fullMsg;
|
|
905
877
|
}
|
|
906
878
|
}
|
|
907
|
-
}
|
|
879
|
+
};
|
|
908
880
|
};
|
|
909
881
|
exports.makeMessagesSocket = makeMessagesSocket;
|