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