@dappaoffc/baileys-mod 5.0.6 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @dappaoffc/baileys-mod might be problematic. Click here for more details.
- package/WAProto/index.js +133384 -57814
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +141 -117
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -12
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +42 -10
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +87 -75
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -13
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +52 -17
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +33 -27
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -62
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +66 -65
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +44 -45
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +49 -39
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +93 -80
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +28 -27
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +163 -313
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -4
- 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/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +242 -359
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +935 -846
- 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 +309 -304
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +10 -15
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1054 -1107
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +448 -639
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +314 -199
- 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 +650 -779
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -6
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +81 -73
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +423 -286
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +79 -77
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +26 -24
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Chat.js +4 -9
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +26 -24
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +8 -6
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Message.js +9 -12
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -33
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/Socket.js +2 -4
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -11
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.d.ts +57 -0
- package/lib/Types/index.js +41 -27
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +198 -211
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +61 -42
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +214 -213
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +687 -710
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +133 -112
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +183 -252
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +496 -510
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +392 -319
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +92 -83
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -21
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +83 -71
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +7 -5
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +46 -40
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +41 -34
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +768 -550
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +261 -352
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +149 -138
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +303 -323
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +141 -149
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +103 -95
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +214 -183
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +35 -1298
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -237
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +260 -213
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +65 -56
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -7
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +58 -89
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/BinaryInfo.js +12 -10
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15348 -22851
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +136 -135
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -49
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +28 -27
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -36
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +20 -26
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +85 -86
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +25 -23
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +36 -24
- package/package.json +106 -98
- package/LICENSE +0 -21
- package/WAProto/WAProto.proto +0 -5311
- package/lib/KeyDB/BinarySearch.js +0 -20
- package/lib/KeyDB/KeyedDB.js +0 -167
- package/lib/KeyDB/index.js +0 -4
- package/lib/Signal/lid-mapping.js +0 -155
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -52
- package/lib/Socket/communities.js +0 -413
- package/lib/Socket/mex.js +0 -45
- package/lib/Types/Bussines.js +0 -3
- package/lib/Types/Newsletter.js.bak +0 -33
- package/lib/Utils/browser-utils.js +0 -25
- package/lib/Utils/message-retry-manager.js +0 -113
- package/lib/Utils/pre-key-manager.js +0 -85
|
@@ -1,89 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} from '../WABinary/index.js';
|
|
46
|
-
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
47
|
-
import { makeKeyedMutex } from '../Utils/make-mutex.js';
|
|
48
|
-
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
49
|
-
import { makeNewsletterSocket } from './newsletter.js';
|
|
50
|
-
export const makeMessagesSocket = (config) => {
|
|
51
|
-
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
52
|
-
const sock = makeNewsletterSocket(config);
|
|
53
|
-
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
54
|
-
const userDevicesCache = config.userDevicesCache ||
|
|
55
|
-
new NodeCache({
|
|
56
|
-
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
57
|
-
useClones: false
|
|
58
|
-
});
|
|
59
|
-
const peerSessionsCache = new NodeCache({
|
|
60
|
-
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeMessagesSocket = void 0;
|
|
7
|
+
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
+
const WAProto_1 = require("../../WAProto");
|
|
10
|
+
const Defaults_1 = require("../Defaults");
|
|
11
|
+
const axios_1 = require("axios")
|
|
12
|
+
const Types_1 = require("../Types")
|
|
13
|
+
const Utils_1 = require("../Utils");
|
|
14
|
+
const link_preview_1 = require("../Utils/link-preview");
|
|
15
|
+
const WABinary_1 = require("../WABinary");
|
|
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;
|
|
20
|
+
const makeMessagesSocket = (config) => {
|
|
21
|
+
const {
|
|
22
|
+
logger,
|
|
23
|
+
linkPreviewImageThumbnailWidth,
|
|
24
|
+
generateHighQualityLinkPreview,
|
|
25
|
+
options: axiosOptions,
|
|
26
|
+
patchMessageBeforeSending
|
|
27
|
+
} = config;
|
|
28
|
+
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;
|
|
43
|
+
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
44
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
61
45
|
useClones: false
|
|
62
46
|
});
|
|
63
|
-
// Initialize message retry manager if enabled
|
|
64
|
-
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
65
|
-
// Prevent race conditions in Signal session encryption by user
|
|
66
|
-
const encryptionMutex = makeKeyedMutex();
|
|
67
47
|
let mediaConn;
|
|
68
48
|
const refreshMediaConn = async (forceGet = false) => {
|
|
69
49
|
const media = await mediaConn;
|
|
70
|
-
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
50
|
+
if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
|
71
51
|
mediaConn = (async () => {
|
|
72
52
|
const result = await query({
|
|
73
53
|
tag: 'iq',
|
|
74
54
|
attrs: {
|
|
75
55
|
type: 'set',
|
|
76
56
|
xmlns: 'w:m',
|
|
77
|
-
to: S_WHATSAPP_NET
|
|
57
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
78
58
|
},
|
|
79
59
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
80
60
|
});
|
|
81
|
-
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
82
|
-
// TODO: explore full length of data that whatsapp provides
|
|
61
|
+
const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
|
|
83
62
|
const node = {
|
|
84
|
-
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
63
|
+
hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
85
64
|
hostname: attrs.hostname,
|
|
86
|
-
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
65
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
87
66
|
})),
|
|
88
67
|
auth: mediaConnNode.attrs.auth,
|
|
89
68
|
ttl: +mediaConnNode.attrs.ttl,
|
|
@@ -100,20 +79,17 @@ export const makeMessagesSocket = (config) => {
|
|
|
100
79
|
* used for receipts of phone call, read, delivery etc.
|
|
101
80
|
* */
|
|
102
81
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
103
|
-
if (!messageIds || messageIds.length === 0) {
|
|
104
|
-
throw new Boom('missing ids in receipt');
|
|
105
|
-
}
|
|
106
82
|
const node = {
|
|
107
83
|
tag: 'receipt',
|
|
108
84
|
attrs: {
|
|
109
|
-
id: messageIds[0]
|
|
110
|
-
}
|
|
85
|
+
id: messageIds[0],
|
|
86
|
+
},
|
|
111
87
|
};
|
|
112
88
|
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
113
89
|
if (isReadReceipt) {
|
|
114
|
-
node.attrs.t = unixTimestampSeconds().toString();
|
|
90
|
+
node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
115
91
|
}
|
|
116
|
-
if (type === 'sender' && (
|
|
92
|
+
if (type === 'sender' && WABinary_1.isJidUser(jid)) {
|
|
117
93
|
node.attrs.recipient = jid;
|
|
118
94
|
node.attrs.to = participant;
|
|
119
95
|
}
|
|
@@ -124,7 +100,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
124
100
|
}
|
|
125
101
|
}
|
|
126
102
|
if (type) {
|
|
127
|
-
node.attrs.type = type;
|
|
103
|
+
node.attrs.type = WABinary_1.isJidNewsLetter(jid) ? 'read-self' : type;
|
|
128
104
|
}
|
|
129
105
|
const remainingMessageIds = messageIds.slice(1);
|
|
130
106
|
if (remainingMessageIds.length) {
|
|
@@ -144,7 +120,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
144
120
|
};
|
|
145
121
|
/** Correctly bulk send receipts to multiple chats, participants */
|
|
146
122
|
const sendReceipts = async (keys, type) => {
|
|
147
|
-
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
123
|
+
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
148
124
|
for (const { jid, participant, messageIds } of recps) {
|
|
149
125
|
await sendReceipt(jid, participant, messageIds, type);
|
|
150
126
|
}
|
|
@@ -158,349 +134,207 @@ export const makeMessagesSocket = (config) => {
|
|
|
158
134
|
};
|
|
159
135
|
/** Fetch all the devices we've to send a message to */
|
|
160
136
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
161
|
-
const deviceResults = []
|
|
137
|
+
const deviceResults = []
|
|
138
|
+
|
|
162
139
|
if (!useCache) {
|
|
163
|
-
logger.debug('not using cache for devices')
|
|
140
|
+
logger.debug('not using cache for devices')
|
|
164
141
|
}
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
device,
|
|
176
|
-
jid
|
|
177
|
-
});
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
jid = jidNormalizedUser(jid);
|
|
181
|
-
return { jid, user };
|
|
182
|
-
})
|
|
183
|
-
.filter(jid => jid !== null);
|
|
184
|
-
let mgetDevices;
|
|
185
|
-
if (useCache && userDevicesCache.mget) {
|
|
186
|
-
const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
|
|
187
|
-
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
188
|
-
}
|
|
189
|
-
for (const { jid, user } of jidsWithUser) {
|
|
142
|
+
|
|
143
|
+
const toFetch = []
|
|
144
|
+
|
|
145
|
+
jids = Array.from(new Set(jids))
|
|
146
|
+
|
|
147
|
+
for (let jid of jids) {
|
|
148
|
+
const user = WABinary_1.jidDecode(jid)?.user
|
|
149
|
+
|
|
150
|
+
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
+
|
|
190
152
|
if (useCache) {
|
|
191
|
-
const devices =
|
|
192
|
-
|
|
153
|
+
const devices = userDevicesCache.get(user)
|
|
154
|
+
|
|
193
155
|
if (devices) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
jid: jidEncode(d.user, d.server, d.device)
|
|
197
|
-
}));
|
|
198
|
-
deviceResults.push(...devicesWithJid);
|
|
199
|
-
logger.trace({ user }, 'using cache for devices');
|
|
156
|
+
deviceResults.push(...devices)
|
|
157
|
+
logger.trace({ user }, 'using cache for devices')
|
|
200
158
|
}
|
|
159
|
+
|
|
201
160
|
else {
|
|
202
|
-
toFetch.push(jid)
|
|
161
|
+
toFetch.push(jid)
|
|
203
162
|
}
|
|
204
163
|
}
|
|
164
|
+
|
|
205
165
|
else {
|
|
206
|
-
toFetch.push(jid)
|
|
166
|
+
toFetch.push(jid)
|
|
207
167
|
}
|
|
208
168
|
}
|
|
169
|
+
|
|
209
170
|
if (!toFetch.length) {
|
|
210
|
-
return deviceResults
|
|
171
|
+
return deviceResults
|
|
211
172
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
requestedLidUsers.add(user);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
|
|
173
|
+
|
|
174
|
+
const query = new WAUSync_1.USyncQuery()
|
|
175
|
+
.withContext('message')
|
|
176
|
+
.withDeviceProtocol()
|
|
177
|
+
|
|
221
178
|
for (const jid of toFetch) {
|
|
222
|
-
query.withUser(new USyncUser().withId(jid))
|
|
179
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
223
180
|
}
|
|
224
|
-
|
|
181
|
+
|
|
182
|
+
const result = await executeUSyncQuery(query)
|
|
183
|
+
|
|
225
184
|
if (result) {
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
logger.trace('Storing LID maps from device call');
|
|
230
|
-
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
231
|
-
}
|
|
232
|
-
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
233
|
-
const deviceMap = {};
|
|
185
|
+
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
186
|
+
const deviceMap = {}
|
|
187
|
+
|
|
234
188
|
for (const item of extracted) {
|
|
235
|
-
deviceMap[item.user] = deviceMap[item.user] || []
|
|
236
|
-
deviceMap[item.user]
|
|
237
|
-
|
|
238
|
-
// Process each user's devices as a group for bulk LID migration
|
|
239
|
-
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
240
|
-
const isLidUser = requestedLidUsers.has(user);
|
|
241
|
-
// Process all devices for this user
|
|
242
|
-
for (const item of userDevices) {
|
|
243
|
-
const finalJid = isLidUser
|
|
244
|
-
? jidEncode(user, item.server, item.device)
|
|
245
|
-
: jidEncode(item.user, item.server, item.device);
|
|
246
|
-
deviceResults.push({
|
|
247
|
-
...item,
|
|
248
|
-
jid: finalJid
|
|
249
|
-
});
|
|
250
|
-
logger.debug({
|
|
251
|
-
user: item.user,
|
|
252
|
-
device: item.device,
|
|
253
|
-
finalJid,
|
|
254
|
-
usedLid: isLidUser
|
|
255
|
-
}, 'Processed device with LID priority');
|
|
256
|
-
}
|
|
189
|
+
deviceMap[item.user] = deviceMap[item.user] || []
|
|
190
|
+
deviceMap[item.user].push(item)
|
|
191
|
+
deviceResults.push(item)
|
|
257
192
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
for (const key in deviceMap) {
|
|
264
|
-
if (deviceMap[key])
|
|
265
|
-
await userDevicesCache.set(key, deviceMap[key]);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const userDeviceUpdates = {};
|
|
269
|
-
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
270
|
-
if (devices && devices.length > 0) {
|
|
271
|
-
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
275
|
-
try {
|
|
276
|
-
await authState.keys.set({ 'device-list': userDeviceUpdates });
|
|
277
|
-
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
|
|
278
|
-
}
|
|
279
|
-
catch (error) {
|
|
280
|
-
logger.warn({ error }, 'failed to store user device lists');
|
|
281
|
-
}
|
|
193
|
+
|
|
194
|
+
for (const key in deviceMap) {
|
|
195
|
+
userDevicesCache.set(key, deviceMap[key])
|
|
282
196
|
}
|
|
283
197
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
198
|
+
|
|
199
|
+
return deviceResults
|
|
200
|
+
}
|
|
201
|
+
const assertSessions = async (jids, force) => {
|
|
287
202
|
let didFetchNewSession = false;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const sessionValidation = await signalRepository.validateSession(jid);
|
|
302
|
-
const hasSession = sessionValidation.exists;
|
|
303
|
-
peerSessionsCache.set(signalId, hasSession);
|
|
304
|
-
if (hasSession) {
|
|
305
|
-
continue;
|
|
203
|
+
let jidsRequiringFetch = [];
|
|
204
|
+
if (force) {
|
|
205
|
+
jidsRequiringFetch = jids;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const addrs = jids.map(jid => (signalRepository
|
|
209
|
+
.jidToSignalProtocolAddress(jid)));
|
|
210
|
+
const sessions = await authState.keys.get('session', addrs);
|
|
211
|
+
for (const jid of jids) {
|
|
212
|
+
const signalId = signalRepository
|
|
213
|
+
.jidToSignalProtocolAddress(jid);
|
|
214
|
+
if (!sessions[signalId]) {
|
|
215
|
+
jidsRequiringFetch.push(jid);
|
|
306
216
|
}
|
|
307
217
|
}
|
|
308
|
-
jidsRequiringFetch.push(jid);
|
|
309
218
|
}
|
|
310
219
|
if (jidsRequiringFetch.length) {
|
|
311
|
-
|
|
312
|
-
const wireJids = [
|
|
313
|
-
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
314
|
-
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
315
|
-
];
|
|
316
|
-
logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
|
|
220
|
+
logger.debug({ jidsRequiringFetch }, 'fetching sessions');
|
|
317
221
|
const result = await query({
|
|
318
222
|
tag: 'iq',
|
|
319
223
|
attrs: {
|
|
320
224
|
xmlns: 'encrypt',
|
|
321
225
|
type: 'get',
|
|
322
|
-
to: S_WHATSAPP_NET
|
|
226
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
323
227
|
},
|
|
324
228
|
content: [
|
|
325
229
|
{
|
|
326
230
|
tag: 'key',
|
|
327
231
|
attrs: {},
|
|
328
|
-
content:
|
|
232
|
+
content: jidsRequiringFetch.map(jid => ({
|
|
329
233
|
tag: 'user',
|
|
330
|
-
attrs: { jid }
|
|
234
|
+
attrs: { jid },
|
|
331
235
|
}))
|
|
332
236
|
}
|
|
333
237
|
]
|
|
334
238
|
});
|
|
335
|
-
await parseAndInjectE2ESessions(result, signalRepository);
|
|
239
|
+
await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
|
|
336
240
|
didFetchNewSession = true;
|
|
337
|
-
// Cache fetched sessions using wire JIDs
|
|
338
|
-
for (const wireJid of wireJids) {
|
|
339
|
-
const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
|
|
340
|
-
peerSessionsCache.set(signalId, true);
|
|
341
|
-
}
|
|
342
241
|
}
|
|
343
242
|
return didFetchNewSession;
|
|
344
243
|
};
|
|
244
|
+
|
|
245
|
+
|
|
345
246
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
346
|
-
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
347
247
|
if (!authState.creds.me?.id) {
|
|
348
|
-
throw new Boom('Not authenticated')
|
|
248
|
+
throw new boom_1.Boom('Not authenticated')
|
|
349
249
|
}
|
|
250
|
+
|
|
350
251
|
const protocolMessage = {
|
|
351
252
|
protocolMessage: {
|
|
352
253
|
peerDataOperationRequestMessage: pdoMessage,
|
|
353
|
-
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
254
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
354
255
|
}
|
|
355
256
|
};
|
|
356
|
-
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
257
|
+
const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
|
|
357
258
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
358
259
|
additionalAttributes: {
|
|
359
260
|
category: 'peer',
|
|
360
|
-
|
|
261
|
+
// eslint-disable-next-line camelcase
|
|
262
|
+
push_priority: 'high_force',
|
|
361
263
|
},
|
|
362
|
-
additionalNodes: [
|
|
363
|
-
{
|
|
364
|
-
tag: 'meta',
|
|
365
|
-
attrs: { appdata: 'default' }
|
|
366
|
-
}
|
|
367
|
-
]
|
|
368
264
|
});
|
|
369
265
|
return msgId;
|
|
370
266
|
};
|
|
371
|
-
const createParticipantNodes = async (
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
376
|
-
const patchedMessages = Array.isArray(patched)
|
|
377
|
-
? patched
|
|
378
|
-
: recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
|
|
267
|
+
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
268
|
+
const patched = await patchMessageBeforeSending(message, jids);
|
|
269
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
379
270
|
let shouldIncludeDeviceIdentity = false;
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const mutexKey = jid;
|
|
400
|
-
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
401
|
-
const { type, ciphertext } = await signalRepository.encryptMessage({
|
|
402
|
-
jid,
|
|
403
|
-
data: bytes
|
|
404
|
-
});
|
|
405
|
-
if (type === 'pkmsg') {
|
|
406
|
-
shouldIncludeDeviceIdentity = true;
|
|
407
|
-
}
|
|
408
|
-
return {
|
|
409
|
-
tag: 'to',
|
|
410
|
-
attrs: { jid },
|
|
411
|
-
content: [
|
|
412
|
-
{
|
|
413
|
-
tag: 'enc',
|
|
414
|
-
attrs: {
|
|
415
|
-
v: '2',
|
|
416
|
-
type,
|
|
417
|
-
...(extraAttrs || {})
|
|
418
|
-
},
|
|
419
|
-
content: ciphertext
|
|
420
|
-
}
|
|
421
|
-
]
|
|
422
|
-
};
|
|
423
|
-
});
|
|
271
|
+
const nodes = await Promise.all(jids.map(async (jid) => {
|
|
272
|
+
const { type, ciphertext } = await signalRepository
|
|
273
|
+
.encryptMessage({ jid, data: bytes });
|
|
274
|
+
if (type === 'pkmsg') {
|
|
275
|
+
shouldIncludeDeviceIdentity = true;
|
|
276
|
+
}
|
|
277
|
+
const node = {
|
|
278
|
+
tag: 'to',
|
|
279
|
+
attrs: { jid },
|
|
280
|
+
content: [{
|
|
281
|
+
tag: 'enc',
|
|
282
|
+
attrs: {
|
|
283
|
+
v: '2',
|
|
284
|
+
type,
|
|
285
|
+
...extraAttrs || {}
|
|
286
|
+
},
|
|
287
|
+
content: ciphertext
|
|
288
|
+
}]
|
|
289
|
+
};
|
|
424
290
|
return node;
|
|
425
|
-
});
|
|
426
|
-
const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
|
|
291
|
+
}));
|
|
427
292
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
428
|
-
};
|
|
429
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
430
|
-
// let shouldIncludeDeviceIdentity = false;
|
|
431
|
-
let didPushAdditional = false
|
|
293
|
+
}; //apela
|
|
294
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
432
295
|
const meId = authState.creds.me.id;
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
296
|
+
let shouldIncludeDeviceIdentity = false;
|
|
297
|
+
let didPushAdditional = false
|
|
298
|
+
const { user, server } = WABinary_1.jidDecode(jid);
|
|
436
299
|
const statusJid = 'status@broadcast';
|
|
437
|
-
const { user, server } = jidDecode(jid);
|
|
438
300
|
const isGroup = server === 'g.us';
|
|
439
301
|
const isStatus = jid === statusJid;
|
|
440
302
|
const isLid = server === 'lid';
|
|
441
|
-
const isNewsletter = server === 'newsletter';
|
|
442
303
|
const isPrivate = server === 's.whatsapp.net'
|
|
443
|
-
const
|
|
444
|
-
msgId = msgId ||
|
|
304
|
+
const isNewsletter = server === 'newsletter';
|
|
305
|
+
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
445
306
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
446
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
307
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
447
308
|
const participants = [];
|
|
448
|
-
const destinationJid = !isStatus ?
|
|
309
|
+
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
449
310
|
const binaryNodeContent = [];
|
|
450
311
|
const devices = [];
|
|
451
312
|
const meMsg = {
|
|
452
313
|
deviceSentMessage: {
|
|
453
314
|
destinationJid,
|
|
454
315
|
message
|
|
455
|
-
}
|
|
456
|
-
messageContextInfo: message.messageContextInfo
|
|
316
|
+
}
|
|
457
317
|
};
|
|
458
|
-
const extraAttrs = {}
|
|
459
|
-
const messages = normalizeMessageContent(message)
|
|
318
|
+
const extraAttrs = {}
|
|
319
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
460
320
|
const buttonType = getButtonType(messages);
|
|
461
321
|
if (participant) {
|
|
322
|
+
// when the retry request is not for a group
|
|
323
|
+
// only send to the specific device that asked for a retry
|
|
324
|
+
// otherwise the message is sent out to every device that should be a recipient
|
|
462
325
|
if (!isGroup && !isStatus) {
|
|
463
|
-
additionalAttributes = {
|
|
464
|
-
...additionalAttributes,
|
|
465
|
-
device_fanout: 'false'
|
|
466
|
-
};
|
|
326
|
+
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
467
327
|
}
|
|
468
|
-
const { user, device } = jidDecode(participant.jid);
|
|
469
|
-
devices.push({
|
|
470
|
-
user,
|
|
471
|
-
device,
|
|
472
|
-
jid: participant.jid
|
|
473
|
-
});
|
|
328
|
+
const { user, device } = WABinary_1.jidDecode(participant.jid);
|
|
329
|
+
devices.push({ user, device });
|
|
474
330
|
}
|
|
475
331
|
await authState.keys.transaction(async () => {
|
|
476
|
-
const mediaType = getMediaType(
|
|
332
|
+
const mediaType = getMediaType(messages);
|
|
333
|
+
|
|
477
334
|
if (mediaType) {
|
|
478
|
-
extraAttrs['mediatype'] = mediaType
|
|
335
|
+
extraAttrs['mediatype'] = mediaType
|
|
479
336
|
}
|
|
480
337
|
|
|
481
|
-
if (isNewsletter) {
|
|
482
|
-
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
483
|
-
const bytes = encodeNewsletterMessage(patched);
|
|
484
|
-
binaryNodeContent.push({
|
|
485
|
-
tag: "plaintext",
|
|
486
|
-
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
487
|
-
content: bytes
|
|
488
|
-
});
|
|
489
|
-
const stanza = {
|
|
490
|
-
tag: "message",
|
|
491
|
-
attrs: {
|
|
492
|
-
to: jid,
|
|
493
|
-
id: msgId,
|
|
494
|
-
type: getTypeMessage(message),
|
|
495
|
-
...(additionalAttributes || {})
|
|
496
|
-
},
|
|
497
|
-
content: binaryNodeContent
|
|
498
|
-
};
|
|
499
|
-
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
500
|
-
await sendNode(stanza);
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
338
|
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
505
339
|
extraAttrs['decrypt-fail'] = 'hide'
|
|
506
340
|
}
|
|
@@ -512,228 +346,185 @@ export const makeMessagesSocket = (config) => {
|
|
|
512
346
|
if (isGroup || isStatus) {
|
|
513
347
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
514
348
|
(async () => {
|
|
515
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
516
|
-
if (groupData
|
|
517
|
-
logger.trace({
|
|
518
|
-
jid,
|
|
519
|
-
participants: groupData.participants.length
|
|
520
|
-
}, 'using cached group metadata');
|
|
349
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
350
|
+
if (groupData) {
|
|
351
|
+
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
521
352
|
}
|
|
353
|
+
|
|
522
354
|
else if (!isStatus) {
|
|
523
|
-
groupData = await groupMetadata(jid)
|
|
355
|
+
groupData = await groupMetadata(jid)
|
|
524
356
|
}
|
|
357
|
+
|
|
525
358
|
return groupData;
|
|
526
359
|
})(),
|
|
527
360
|
(async () => {
|
|
528
361
|
if (!participant && !isStatus) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
|
|
532
|
-
return result[jid] || {};
|
|
362
|
+
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
|
+
return result[jid] || {}
|
|
533
364
|
}
|
|
534
|
-
|
|
535
|
-
|
|
365
|
+
|
|
366
|
+
return {}
|
|
367
|
+
|
|
368
|
+
})()
|
|
536
369
|
]);
|
|
537
370
|
if (!participant) {
|
|
538
|
-
const participantsList = groupData && !isStatus ? groupData.participants.map(p => p.id) : []
|
|
371
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
+
|
|
539
373
|
if (isStatus && statusJidList) {
|
|
540
|
-
participantsList.push(...statusJidList)
|
|
374
|
+
participantsList.push(...statusJidList)
|
|
541
375
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
expiration: groupData.ephemeralDuration.toString()
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
const patched = await patchMessageBeforeSending(message);
|
|
558
|
-
if (Array.isArray(patched)) {
|
|
559
|
-
throw new Boom('Per-jid patching is not supported in groups');
|
|
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)
|
|
560
388
|
}
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
const
|
|
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
|
+
|
|
564
393
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
565
394
|
group: destinationJid,
|
|
566
395
|
data: bytes,
|
|
567
|
-
meId
|
|
396
|
+
meId,
|
|
568
397
|
});
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
//todo: revamp all this logic
|
|
578
|
-
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
|
579
|
-
senderKeyRecipients.push(deviceJid);
|
|
580
|
-
senderKeyMap[deviceJid] = true;
|
|
398
|
+
const senderKeyJids = [];
|
|
399
|
+
|
|
400
|
+
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);
|
|
402
|
+
if (!senderKeyMap[jid] || !!participant) {
|
|
403
|
+
senderKeyJids.push(jid);
|
|
404
|
+
// store that this person has had the sender keys sent to them
|
|
405
|
+
senderKeyMap[jid] = true;
|
|
581
406
|
}
|
|
582
407
|
}
|
|
583
|
-
if
|
|
584
|
-
|
|
408
|
+
// if there are some participants with whom the session has not been established
|
|
409
|
+
// if there are, we re-send the senderkey
|
|
410
|
+
if (senderKeyJids.length) {
|
|
411
|
+
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
585
412
|
const senderKeyMsg = {
|
|
586
413
|
senderKeyDistributionMessage: {
|
|
587
414
|
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
588
415
|
groupId: destinationJid
|
|
589
416
|
}
|
|
590
417
|
};
|
|
591
|
-
|
|
592
|
-
await
|
|
593
|
-
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
418
|
+
await assertSessions(senderKeyJids, false);
|
|
419
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
594
420
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
595
421
|
participants.push(...result.nodes);
|
|
596
422
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
content: encryptedContent
|
|
610
|
-
});
|
|
423
|
+
binaryNodeContent.push({
|
|
424
|
+
tag: 'enc',
|
|
425
|
+
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
426
|
+
content: ciphertext
|
|
427
|
+
});
|
|
428
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
429
|
+
}
|
|
430
|
+
else if (isNewsletter) {
|
|
431
|
+
// Message edit
|
|
432
|
+
if (message.protocolMessage?.editedMessage) {
|
|
433
|
+
msgId = message.protocolMessage.key?.id
|
|
434
|
+
message = message.protocolMessage.editedMessage
|
|
611
435
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
type: 'skmsg',
|
|
618
|
-
...extraAttrs
|
|
619
|
-
},
|
|
620
|
-
content: ciphertext
|
|
621
|
-
});
|
|
622
|
-
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
436
|
+
|
|
437
|
+
// Message delete
|
|
438
|
+
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
439
|
+
msgId = message.protocolMessage.key?.id
|
|
440
|
+
message = {}
|
|
623
441
|
}
|
|
442
|
+
|
|
443
|
+
const patched = await patchMessageBeforeSending(message, [])
|
|
444
|
+
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
445
|
+
|
|
446
|
+
binaryNodeContent.push({
|
|
447
|
+
tag: 'plaintext',
|
|
448
|
+
attrs: extraAttrs ? extraAttrs : {},
|
|
449
|
+
content: bytes
|
|
450
|
+
})
|
|
624
451
|
}
|
|
625
452
|
else {
|
|
626
|
-
|
|
627
|
-
// TODO: investigate if this is true
|
|
628
|
-
let ownId = meId;
|
|
629
|
-
if (isLid && meLid) {
|
|
630
|
-
ownId = meLid;
|
|
631
|
-
logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
|
|
635
|
-
}
|
|
636
|
-
const { user: ownUser } = jidDecode(ownId);
|
|
453
|
+
const { user: meUser } = WABinary_1.jidDecode(meId);
|
|
637
454
|
if (!participant) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
user
|
|
641
|
-
device: 0,
|
|
642
|
-
jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
|
|
643
|
-
});
|
|
644
|
-
if (user !== ownUser) {
|
|
645
|
-
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
646
|
-
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
647
|
-
devices.push({
|
|
648
|
-
user: ownUserForAddressing,
|
|
649
|
-
device: 0,
|
|
650
|
-
jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
651
|
-
});
|
|
455
|
+
devices.push({ user })
|
|
456
|
+
if (user !== meUser) {
|
|
457
|
+
devices.push({ user: meUser })
|
|
652
458
|
}
|
|
459
|
+
|
|
653
460
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const senderIdentity = isLid && meLid
|
|
658
|
-
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
659
|
-
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
660
|
-
// Enumerate devices for sender and target with consistent addressing
|
|
661
|
-
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
662
|
-
devices.push(...sessionDevices);
|
|
663
|
-
logger.debug({
|
|
664
|
-
deviceCount: devices.length,
|
|
665
|
-
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
666
|
-
}, 'Device enumeration complete with unified addressing');
|
|
461
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
462
|
+
|
|
463
|
+
devices.push(...additionalDevices)
|
|
667
464
|
}
|
|
668
465
|
}
|
|
669
|
-
const
|
|
670
|
-
const
|
|
671
|
-
const
|
|
672
|
-
const { user
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (isExactSenderDevice) {
|
|
677
|
-
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)');
|
|
678
|
-
continue;
|
|
679
|
-
}
|
|
680
|
-
// Check if this is our device (could match either PN or LID user)
|
|
681
|
-
const isMe = user === mePnUser || user === meLidUser;
|
|
466
|
+
const allJids = [];
|
|
467
|
+
const meJids = [];
|
|
468
|
+
const otherJids = [];
|
|
469
|
+
for (const { user, device } of devices) {
|
|
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
|
+
|
|
682
473
|
if (isMe) {
|
|
683
|
-
|
|
474
|
+
meJids.push(jid)
|
|
684
475
|
}
|
|
476
|
+
|
|
685
477
|
else {
|
|
686
|
-
|
|
478
|
+
otherJids.push(jid)
|
|
687
479
|
}
|
|
688
|
-
|
|
480
|
+
|
|
481
|
+
allJids.push(jid)
|
|
689
482
|
}
|
|
690
|
-
await assertSessions(
|
|
483
|
+
await assertSessions(allJids, false);
|
|
691
484
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
692
|
-
|
|
693
|
-
createParticipantNodes(
|
|
694
|
-
|
|
695
|
-
]);
|
|
485
|
+
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
486
|
+
createParticipantNodes(otherJids, message, extraAttrs)
|
|
487
|
+
])
|
|
696
488
|
participants.push(...meNodes);
|
|
697
489
|
participants.push(...otherNodes);
|
|
698
|
-
/* if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
699
|
-
extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients]);
|
|
700
|
-
}*/
|
|
701
490
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
702
491
|
}
|
|
703
492
|
if (participants.length) {
|
|
704
493
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
705
|
-
const peerNode = participants[0]?.content?.[0]
|
|
494
|
+
const peerNode = participants[0]?.content?.[0]
|
|
495
|
+
|
|
706
496
|
if (peerNode) {
|
|
707
|
-
binaryNodeContent.push(peerNode)
|
|
497
|
+
binaryNodeContent.push(peerNode) // push only enc
|
|
708
498
|
}
|
|
709
499
|
}
|
|
500
|
+
|
|
710
501
|
else {
|
|
711
502
|
binaryNodeContent.push({
|
|
712
503
|
tag: 'participants',
|
|
713
504
|
attrs: {},
|
|
714
505
|
content: participants
|
|
715
|
-
})
|
|
506
|
+
})
|
|
716
507
|
}
|
|
717
508
|
}
|
|
509
|
+
|
|
718
510
|
const stanza = {
|
|
719
511
|
tag: 'message',
|
|
720
512
|
attrs: {
|
|
721
513
|
id: msgId,
|
|
722
|
-
|
|
723
|
-
type: getTypeMessage(messages),
|
|
514
|
+
type: getTypeMessage(messages),
|
|
724
515
|
...(additionalAttributes || {})
|
|
725
516
|
},
|
|
726
517
|
content: binaryNodeContent
|
|
727
|
-
}
|
|
518
|
+
}
|
|
728
519
|
// if the participant to send to is explicitly specified (generally retry recp)
|
|
729
520
|
// ensure the message is only sent to that person
|
|
730
521
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
731
522
|
if (participant) {
|
|
732
|
-
if (isJidGroup(destinationJid)) {
|
|
523
|
+
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
733
524
|
stanza.attrs.to = destinationJid;
|
|
734
525
|
stanza.attrs.participant = participant.jid;
|
|
735
526
|
}
|
|
736
|
-
else if (areJidsSameUser(participant.jid, meId)) {
|
|
527
|
+
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
737
528
|
stanza.attrs.to = participant.jid;
|
|
738
529
|
stanza.attrs.recipient = destinationJid;
|
|
739
530
|
}
|
|
@@ -745,14 +536,14 @@ export const makeMessagesSocket = (config) => {
|
|
|
745
536
|
stanza.attrs.to = destinationJid;
|
|
746
537
|
}
|
|
747
538
|
if (shouldIncludeDeviceIdentity) {
|
|
748
|
-
;
|
|
749
539
|
stanza.content.push({
|
|
750
540
|
tag: 'device-identity',
|
|
751
541
|
attrs: {},
|
|
752
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
542
|
+
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
753
543
|
});
|
|
754
544
|
logger.debug({ jid }, 'adding device identity');
|
|
755
545
|
}
|
|
546
|
+
|
|
756
547
|
if (AI && isPrivate) {
|
|
757
548
|
const botNode = {
|
|
758
549
|
tag: 'bot',
|
|
@@ -761,7 +552,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
761
552
|
}
|
|
762
553
|
}
|
|
763
554
|
|
|
764
|
-
const filteredBizBot = getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
555
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
765
556
|
|
|
766
557
|
if (filteredBizBot) {
|
|
767
558
|
stanza.content.push(...additionalNodes)
|
|
@@ -773,9 +564,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
773
564
|
}
|
|
774
565
|
}
|
|
775
566
|
|
|
776
|
-
if(buttonType && !isStatus) {
|
|
777
|
-
const content = getAdditionalNode(buttonType)
|
|
778
|
-
const filteredNode = getBinaryNodeFilter(additionalNodes)
|
|
567
|
+
if(!isNewsletter && buttonType && !isStatus) {
|
|
568
|
+
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
569
|
+
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
779
570
|
|
|
780
571
|
if (filteredNode) {
|
|
781
572
|
didPushAdditional = true
|
|
@@ -790,44 +581,42 @@ export const makeMessagesSocket = (config) => {
|
|
|
790
581
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
791
582
|
stanza.content.push(...additionalNodes);
|
|
792
583
|
}
|
|
584
|
+
|
|
793
585
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
794
586
|
await sendNode(stanza);
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
587
|
+
});
|
|
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;
|
|
801
606
|
};
|
|
802
607
|
const getTypeMessage = (msg) => {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
811
|
-
}
|
|
812
|
-
else if (msg.ephemeralMessage) {
|
|
813
|
-
return getTypeMessage(msg.ephemeralMessage.message);
|
|
814
|
-
}
|
|
815
|
-
else if (msg.documentWithCaptionMessage) {
|
|
816
|
-
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
817
|
-
}
|
|
818
|
-
else if (msg.reactionMessage) {
|
|
819
|
-
return 'reaction';
|
|
820
|
-
}
|
|
821
|
-
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
822
|
-
return 'poll';
|
|
823
|
-
}
|
|
824
|
-
else if (getMediaType(msg)) {
|
|
825
|
-
return 'media';
|
|
826
|
-
}
|
|
608
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
609
|
+
if (message.reactionMessage) {
|
|
610
|
+
return 'reaction'
|
|
611
|
+
}
|
|
612
|
+
else if (getMediaType(message)) {
|
|
613
|
+
return 'media'
|
|
614
|
+
}
|
|
827
615
|
else {
|
|
828
|
-
return 'text'
|
|
616
|
+
return 'text'
|
|
829
617
|
}
|
|
830
|
-
}
|
|
618
|
+
}
|
|
619
|
+
|
|
831
620
|
const getMediaType = (message) => {
|
|
832
621
|
if (message.imageMessage) {
|
|
833
622
|
return 'image'
|
|
@@ -877,7 +666,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
877
666
|
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
878
667
|
return 'productlink'
|
|
879
668
|
}
|
|
880
|
-
}
|
|
669
|
+
}
|
|
670
|
+
|
|
881
671
|
const getButtonType = (message) => {
|
|
882
672
|
if (message.listMessage) {
|
|
883
673
|
return 'list'
|
|
@@ -908,11 +698,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
908
698
|
}
|
|
909
699
|
}
|
|
910
700
|
const getPrivacyTokens = async (jids) => {
|
|
911
|
-
const t = unixTimestampSeconds().toString();
|
|
701
|
+
const t = Utils_1.unixTimestampSeconds().toString();
|
|
912
702
|
const result = await query({
|
|
913
703
|
tag: 'iq',
|
|
914
704
|
attrs: {
|
|
915
|
-
to: S_WHATSAPP_NET,
|
|
705
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
916
706
|
type: 'set',
|
|
917
707
|
xmlns: 'privacy'
|
|
918
708
|
},
|
|
@@ -923,7 +713,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
923
713
|
content: jids.map(jid => ({
|
|
924
714
|
tag: 'token',
|
|
925
715
|
attrs: {
|
|
926
|
-
jid: jidNormalizedUser(jid),
|
|
716
|
+
jid: WABinary_1.jidNormalizedUser(jid),
|
|
927
717
|
t,
|
|
928
718
|
type: 'trusted_contact'
|
|
929
719
|
}
|
|
@@ -932,9 +722,10 @@ export const makeMessagesSocket = (config) => {
|
|
|
932
722
|
]
|
|
933
723
|
});
|
|
934
724
|
return result;
|
|
935
|
-
}
|
|
936
|
-
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
937
|
-
const
|
|
725
|
+
}
|
|
726
|
+
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
728
|
+
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
938
729
|
return {
|
|
939
730
|
...sock,
|
|
940
731
|
getPrivacyTokens,
|
|
@@ -942,23 +733,23 @@ export const makeMessagesSocket = (config) => {
|
|
|
942
733
|
relayMessage,
|
|
943
734
|
sendReceipt,
|
|
944
735
|
sendReceipts,
|
|
736
|
+
rahmi,
|
|
945
737
|
readMessages,
|
|
946
738
|
refreshMediaConn,
|
|
739
|
+
getUSyncDevices,
|
|
740
|
+
createParticipantNodes,
|
|
947
741
|
waUploadToServer,
|
|
948
|
-
fetchPrivacySettings,
|
|
949
742
|
sendPeerDataOperationMessage,
|
|
950
|
-
|
|
951
|
-
getUSyncDevices,
|
|
952
|
-
messageRetryManager,
|
|
743
|
+
fetchPrivacySettings,
|
|
953
744
|
updateMediaMessage: async (message) => {
|
|
954
|
-
const content = assertMediaContent(message.message);
|
|
745
|
+
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
955
746
|
const mediaKey = content.mediaKey;
|
|
956
747
|
const meId = authState.creds.me.id;
|
|
957
|
-
const node =
|
|
748
|
+
const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
958
749
|
let error = undefined;
|
|
959
750
|
await Promise.all([
|
|
960
751
|
sendNode(node),
|
|
961
|
-
waitForMsgMediaUpdate(
|
|
752
|
+
waitForMsgMediaUpdate(update => {
|
|
962
753
|
const result = update.find(c => c.key.id === message.key.id);
|
|
963
754
|
if (result) {
|
|
964
755
|
if (result.error) {
|
|
@@ -966,16 +757,13 @@ export const makeMessagesSocket = (config) => {
|
|
|
966
757
|
}
|
|
967
758
|
else {
|
|
968
759
|
try {
|
|
969
|
-
const media =
|
|
970
|
-
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
971
|
-
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
972
|
-
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
973
|
-
data: media,
|
|
974
|
-
statusCode: getStatusCodeForMediaRetry(media.result) || 404
|
|
975
|
-
});
|
|
760
|
+
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
761
|
+
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
762
|
+
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
763
|
+
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
976
764
|
}
|
|
977
765
|
content.directPath = media.directPath;
|
|
978
|
-
content.url = getUrlFromDirectPath(content.directPath);
|
|
766
|
+
content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
|
|
979
767
|
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
980
768
|
}
|
|
981
769
|
catch (err) {
|
|
@@ -989,112 +777,133 @@ export const makeMessagesSocket = (config) => {
|
|
|
989
777
|
if (error) {
|
|
990
778
|
throw error;
|
|
991
779
|
}
|
|
992
|
-
ev.emit('messages.update', [
|
|
780
|
+
ev.emit('messages.update', [
|
|
781
|
+
{
|
|
782
|
+
key: message.key,
|
|
783
|
+
update: {
|
|
784
|
+
message: message.message
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
]);
|
|
993
788
|
return message;
|
|
994
789
|
},
|
|
995
790
|
sendMessage: async (jid, content, options = {}) => {
|
|
996
791
|
const userJid = authState.creds.me.id;
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
:
|
|
1007
|
-
|
|
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
|
+
|
|
800
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
801
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
802
|
+
disappearingMessagesInChat
|
|
803
|
+
|
|
804
|
+
await groupToggleEphemeral(jid, value)
|
|
1008
805
|
}
|
|
806
|
+
|
|
1009
807
|
else {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1021
|
-
}),
|
|
1022
|
-
//TODO: CACHE
|
|
1023
|
-
getProfilePicUrl: sock.profilePictureUrl,
|
|
1024
|
-
getCallLink: sock.createCallLink,
|
|
1025
|
-
upload: async (readStream, opts) => {
|
|
1026
|
-
const up = await waUploadToServer(readStream, {
|
|
1027
|
-
...opts,
|
|
1028
|
-
newsletter: isJidNewsletter(jid)
|
|
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()
|
|
1029
818
|
});
|
|
1030
|
-
|
|
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()
|
|
826
|
+
});
|
|
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)
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
846
|
+
logger,
|
|
847
|
+
userJid,
|
|
848
|
+
quoted,
|
|
849
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
850
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
851
|
+
fetchOpts: {
|
|
852
|
+
timeout: 3000,
|
|
853
|
+
...axiosOptions || {}
|
|
1031
854
|
},
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
855
|
+
logger,
|
|
856
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
857
|
+
}),
|
|
858
|
+
upload: async (readStream, opts) => {
|
|
859
|
+
const up = await waUploadToServer(readStream, {
|
|
860
|
+
...opts,
|
|
861
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
862
|
+
});
|
|
863
|
+
return up;
|
|
864
|
+
},
|
|
865
|
+
mediaCache: config.mediaCache,
|
|
866
|
+
options: config.options,
|
|
867
|
+
...options
|
|
868
|
+
});
|
|
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({
|
|
1060
885
|
attrs: {
|
|
1061
886
|
biz_bot: '1'
|
|
1062
887
|
}, tag: "bot"
|
|
1063
888
|
});
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
additionalNodes.push({
|
|
1078
|
-
tag: 'meta',
|
|
1079
|
-
attrs: {
|
|
1080
|
-
event_type: 'creation'
|
|
1081
|
-
}
|
|
1082
|
-
});
|
|
1083
|
-
}
|
|
1084
|
-
await relayMessage(jid, fullMsg.message, {
|
|
1085
|
-
messageId: fullMsg.key.id,
|
|
1086
|
-
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1087
|
-
additionalAttributes,
|
|
1088
|
-
statusJidList: options.statusJidList,
|
|
1089
|
-
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes
|
|
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'));
|
|
1090
902
|
});
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
return fullMsg;
|
|
903
|
+
}
|
|
904
|
+
return fullMsg;
|
|
1097
905
|
}
|
|
1098
906
|
}
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
exports.makeMessagesSocket = makeMessagesSocket;
|