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