nrx-bails 0.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.
- package/LICENSE +21 -0
- package/README.md +1541 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +169661 -0
- package/lib/Defaults/index.d.ts +113 -0
- package/lib/Defaults/index.js +156 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/ye-bail-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +41 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +90 -0
- package/lib/Signal/Group/group_cipher.d.ts +12 -0
- package/lib/Signal/Group/group_cipher.js +122 -0
- package/lib/Signal/Group/index.d.ts +22 -0
- package/lib/Signal/Group/index.js +83 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +81 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.js +83 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +60 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +95 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +77 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +79 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +125 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +55 -0
- package/lib/Signal/libsignal.d.ts +37 -0
- package/lib/Signal/libsignal.js +200 -0
- package/lib/Socket/Client/index.d.ts +1 -0
- package/lib/Socket/Client/index.js +44 -0
- package/lib/Socket/Client/types.d.ts +7 -0
- package/lib/Socket/Client/types.js +39 -0
- package/lib/Socket/Client/websocket.d.ts +19 -0
- package/lib/Socket/Client/websocket.js +137 -0
- package/lib/Socket/business.d.ts +329 -0
- package/lib/Socket/business.js +286 -0
- package/lib/Socket/chats.d.ts +84 -0
- package/lib/Socket/chats.js +1022 -0
- package/lib/Socket/groups.d.ts +216 -0
- package/lib/Socket/groups.js +358 -0
- package/lib/Socket/index.d.ts +330 -0
- package/lib/Socket/index.js +36 -0
- package/lib/Socket/messages-recv.d.ts +271 -0
- package/lib/Socket/messages-recv.js +1079 -0
- package/lib/Socket/messages-send.d.ts +258 -0
- package/lib/Socket/messages-send.js +1190 -0
- package/lib/Socket/newsletter.d.ts +253 -0
- package/lib/Socket/newsletter.js +362 -0
- package/lib/Socket/registration.d.ts +361 -0
- package/lib/Socket/registration.js +179 -0
- package/lib/Socket/socket.d.ts +33 -0
- package/lib/Socket/socket.js +699 -0
- package/lib/Socket/usync.d.ts +27 -0
- package/lib/Socket/usync.js +96 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
- package/lib/Store/make-cache-manager-auth-state.js +118 -0
- package/lib/Store/make-in-memory-store.d.ts +64 -0
- package/lib/Store/make-in-memory-store.js +465 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/make-ordered-dictionary.js +107 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +53 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +28 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +28 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +30 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +28 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +28 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +28 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +53 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +35 -0
- package/lib/Types/Message.d.ts +2 -0
- package/lib/Types/Message.js +33 -0
- package/lib/Types/Newsletter.d.ts +4 -0
- package/lib/Types/Newsletter.js +62 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +28 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +28 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +28 -0
- package/lib/Types/State.d.ts +1 -0
- package/lib/Types/State.js +28 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +28 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +68 -0
- package/lib/Utils/auth-utils.d.ts +63 -0
- package/lib/Utils/auth-utils.js +248 -0
- package/lib/Utils/browser-utils.d.ts +3 -0
- package/lib/Utils/browser-utils.js +61 -0
- package/lib/Utils/business.d.ts +53 -0
- package/lib/Utils/business.js +260 -0
- package/lib/Utils/chat-utils.d.ts +253 -0
- package/lib/Utils/chat-utils.js +756 -0
- package/lib/Utils/crypto.d.ts +43 -0
- package/lib/Utils/crypto.js +219 -0
- package/lib/Utils/decode-wa-message.d.ts +61 -0
- package/lib/Utils/decode-wa-message.js +233 -0
- package/lib/Utils/event-buffer.d.ts +17 -0
- package/lib/Utils/event-buffer.js +544 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +471 -0
- package/lib/Utils/history.d.ts +59 -0
- package/lib/Utils/history.js +120 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/link-preview.d.ts +19 -0
- package/lib/Utils/link-preview.js +152 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +33 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +77 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +69 -0
- package/lib/Utils/message-retry-manager.d.ts +34 -0
- package/lib/Utils/message-retry-manager.js +154 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +1024 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +1407 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +176 -0
- package/lib/Utils/pre-key-manager.d.ts +13 -0
- package/lib/Utils/pre-key-manager.js +93 -0
- package/lib/Utils/process-message.d.ts +40 -0
- package/lib/Utils/process-message.js +430 -0
- package/lib/Utils/signal.d.ts +72 -0
- package/lib/Utils/signal.js +179 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +151 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +255 -0
- package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
- package/lib/Utils/ye-bail-event-stream.js +89 -0
- package/lib/WABinary/constants.d.ts +23 -0
- package/lib/WABinary/constants.js +1328 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +291 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +276 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +155 -0
- package/lib/WABinary/index.d.ts +1 -0
- package/lib/WABinary/index.js +47 -0
- package/lib/WABinary/jid-utils.d.ts +34 -0
- package/lib/WABinary/jid-utils.js +111 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +28 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +39 -0
- package/lib/WAM/constants.d.ts +35374 -0
- package/lib/WAM/constants.js +15376 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +181 -0
- package/lib/WAM/index.d.ts +1 -0
- package/lib/WAM/index.js +45 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.js +46 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +115 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +52 -0
- package/lib/WAUSync/index.d.ts +1 -0
- package/lib/WAUSync/index.js +45 -0
- package/lib/index.js +81 -0
- package/package.json +113 -0
- package/requirements.js +32 -0
|
@@ -0,0 +1,1190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.makeMessagesSocket = void 0;
|
|
33
|
+
const boom_1 = require("@hapi/boom");
|
|
34
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
35
|
+
const crypto_1 = require("crypto");
|
|
36
|
+
const WAProto_1 = require("../../WAProto");
|
|
37
|
+
const Defaults_1 = require("../Defaults");
|
|
38
|
+
const Utils_1 = require("../Utils");
|
|
39
|
+
const message_retry_manager_1 = require("../Utils/message-retry-manager");
|
|
40
|
+
const link_preview_1 = require("../Utils/link-preview");
|
|
41
|
+
const WABinary_1 = require("../WABinary");
|
|
42
|
+
const WAUSync_1 = require("../WAUSync");
|
|
43
|
+
const newsletter_1 = require("./newsletter");
|
|
44
|
+
const makeMessagesSocket = (config) => {
|
|
45
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount, } = config;
|
|
46
|
+
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
47
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
|
|
48
|
+
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
49
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
50
|
+
useClones: false
|
|
51
|
+
});
|
|
52
|
+
const messageRetryManager = enableRecentMessageCache ? new message_retry_manager_1.MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
53
|
+
let mediaConn;
|
|
54
|
+
const refreshMediaConn = async (forceGet = false) => {
|
|
55
|
+
const media = await mediaConn;
|
|
56
|
+
if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
|
57
|
+
mediaConn = (async () => {
|
|
58
|
+
const result = await query({
|
|
59
|
+
tag: 'iq',
|
|
60
|
+
attrs: {
|
|
61
|
+
type: 'set',
|
|
62
|
+
xmlns: 'w:m',
|
|
63
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
64
|
+
},
|
|
65
|
+
content: [{ tag: 'media_conn', attrs: {} }]
|
|
66
|
+
});
|
|
67
|
+
const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
|
|
68
|
+
const node = {
|
|
69
|
+
hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
70
|
+
hostname: attrs.hostname,
|
|
71
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
72
|
+
})),
|
|
73
|
+
auth: mediaConnNode.attrs.auth,
|
|
74
|
+
ttl: +mediaConnNode.attrs.ttl,
|
|
75
|
+
fetchDate: new Date()
|
|
76
|
+
};
|
|
77
|
+
logger.debug('fetched media conn');
|
|
78
|
+
return node;
|
|
79
|
+
})();
|
|
80
|
+
}
|
|
81
|
+
return mediaConn;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* generic send receipt function
|
|
85
|
+
* used for receipts of phone call, read, delivery etc.
|
|
86
|
+
* */
|
|
87
|
+
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
88
|
+
const node = {
|
|
89
|
+
tag: 'receipt',
|
|
90
|
+
attrs: {
|
|
91
|
+
id: messageIds[0],
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
95
|
+
if (isReadReceipt) {
|
|
96
|
+
node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
97
|
+
}
|
|
98
|
+
if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
|
|
99
|
+
node.attrs.recipient = jid;
|
|
100
|
+
node.attrs.to = participant;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
node.attrs.to = jid;
|
|
104
|
+
if (participant) {
|
|
105
|
+
node.attrs.participant = participant;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (type) {
|
|
109
|
+
node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
|
|
110
|
+
}
|
|
111
|
+
const remainingMessageIds = messageIds.slice(1);
|
|
112
|
+
if (remainingMessageIds.length) {
|
|
113
|
+
node.content = [
|
|
114
|
+
{
|
|
115
|
+
tag: 'list',
|
|
116
|
+
attrs: {},
|
|
117
|
+
content: remainingMessageIds.map(id => ({
|
|
118
|
+
tag: 'item',
|
|
119
|
+
attrs: { id }
|
|
120
|
+
}))
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
125
|
+
await sendNode(node);
|
|
126
|
+
};
|
|
127
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
|
128
|
+
const sendReceipts = async (keys, type) => {
|
|
129
|
+
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
130
|
+
for (const { jid, participant, messageIds } of recps) {
|
|
131
|
+
await sendReceipt(jid, participant, messageIds, type);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/** Bulk read messages. Keys can be from different chats & participants */
|
|
135
|
+
const readMessages = async (keys) => {
|
|
136
|
+
const privacySettings = await fetchPrivacySettings();
|
|
137
|
+
|
|
138
|
+
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
139
|
+
await sendReceipts(keys, readType);
|
|
140
|
+
};
|
|
141
|
+
/** Fetch all the devices we've to send a message to */
|
|
142
|
+
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
143
|
+
var _a;
|
|
144
|
+
const deviceResults = [];
|
|
145
|
+
if (!useCache) {
|
|
146
|
+
logger.debug('not using cache for devices');
|
|
147
|
+
}
|
|
148
|
+
const toFetch = [];
|
|
149
|
+
jids = Array.from(new Set(jids));
|
|
150
|
+
for (let jid of jids) {
|
|
151
|
+
const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
|
|
152
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
153
|
+
if (useCache) {
|
|
154
|
+
const devices = userDevicesCache.get(user);
|
|
155
|
+
if (devices) {
|
|
156
|
+
deviceResults.push(...devices);
|
|
157
|
+
logger.trace({ user }, 'using cache for devices');
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
toFetch.push(jid);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
toFetch.push(jid);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!toFetch.length) {
|
|
168
|
+
return deviceResults;
|
|
169
|
+
}
|
|
170
|
+
const query = new WAUSync_1.USyncQuery()
|
|
171
|
+
.withContext('message')
|
|
172
|
+
.withDeviceProtocol();
|
|
173
|
+
for (const jid of toFetch) {
|
|
174
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
175
|
+
}
|
|
176
|
+
const result = await sock.executeUSyncQuery(query);
|
|
177
|
+
if (result) {
|
|
178
|
+
const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
|
|
179
|
+
const deviceMap = {};
|
|
180
|
+
for (const item of extracted) {
|
|
181
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
182
|
+
deviceMap[item.user].push(item);
|
|
183
|
+
deviceResults.push(item);
|
|
184
|
+
}
|
|
185
|
+
for (const key in deviceMap) {
|
|
186
|
+
userDevicesCache.set(key, deviceMap[key]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return deviceResults;
|
|
190
|
+
};
|
|
191
|
+
const assertSessions = async (jids, force) => {
|
|
192
|
+
let didFetchNewSession = false;
|
|
193
|
+
let jidsRequiringFetch = [];
|
|
194
|
+
if (force) {
|
|
195
|
+
jidsRequiringFetch = jids;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const addrs = jids.map(jid => (signalRepository
|
|
199
|
+
.jidToSignalProtocolAddress(jid)));
|
|
200
|
+
const sessions = await authState.keys.get('session', addrs);
|
|
201
|
+
for (const jid of jids) {
|
|
202
|
+
const signalId = signalRepository
|
|
203
|
+
.jidToSignalProtocolAddress(jid);
|
|
204
|
+
if (!sessions[signalId]) {
|
|
205
|
+
jidsRequiringFetch.push(jid);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (jidsRequiringFetch.length) {
|
|
210
|
+
logger.debug({ jidsRequiringFetch }, 'fetching sessions');
|
|
211
|
+
const result = await query({
|
|
212
|
+
tag: 'iq',
|
|
213
|
+
attrs: {
|
|
214
|
+
xmlns: 'encrypt',
|
|
215
|
+
type: 'get',
|
|
216
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
217
|
+
},
|
|
218
|
+
content: [
|
|
219
|
+
{
|
|
220
|
+
tag: 'key',
|
|
221
|
+
attrs: {},
|
|
222
|
+
content: jidsRequiringFetch.map(jid => ({
|
|
223
|
+
tag: 'user',
|
|
224
|
+
attrs: { jid },
|
|
225
|
+
}))
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
});
|
|
229
|
+
await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
|
|
230
|
+
didFetchNewSession = true;
|
|
231
|
+
}
|
|
232
|
+
return didFetchNewSession;
|
|
233
|
+
};
|
|
234
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
235
|
+
var _a;
|
|
236
|
+
|
|
237
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
238
|
+
throw new boom_1.Boom('Not authenticated');
|
|
239
|
+
}
|
|
240
|
+
const protocolMessage = {
|
|
241
|
+
protocolMessage: {
|
|
242
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
243
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
247
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
248
|
+
additionalAttributes: {
|
|
249
|
+
category: 'peer',
|
|
250
|
+
|
|
251
|
+
push_priority: 'high_force',
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
return msgId;
|
|
255
|
+
};
|
|
256
|
+
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
257
|
+
let patched = await patchMessageBeforeSending(message, jids);
|
|
258
|
+
if (!Array.isArray(patched)) {
|
|
259
|
+
patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
|
|
260
|
+
}
|
|
261
|
+
let shouldIncludeDeviceIdentity = false;
|
|
262
|
+
const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
|
|
263
|
+
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
|
|
264
|
+
if (!jid) {
|
|
265
|
+
return {};
|
|
266
|
+
}
|
|
267
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
|
|
268
|
+
const { type, ciphertext } = await signalRepository
|
|
269
|
+
.encryptMessage({ jid, data: bytes });
|
|
270
|
+
if (type === 'pkmsg') {
|
|
271
|
+
shouldIncludeDeviceIdentity = true;
|
|
272
|
+
}
|
|
273
|
+
const node = {
|
|
274
|
+
tag: 'to',
|
|
275
|
+
attrs: { jid },
|
|
276
|
+
content: [{
|
|
277
|
+
tag: 'enc',
|
|
278
|
+
attrs: {
|
|
279
|
+
v: '2',
|
|
280
|
+
type,
|
|
281
|
+
...extraAttrs || {}
|
|
282
|
+
},
|
|
283
|
+
content: ciphertext
|
|
284
|
+
}]
|
|
285
|
+
};
|
|
286
|
+
return node;
|
|
287
|
+
}));
|
|
288
|
+
return { nodes, shouldIncludeDeviceIdentity };
|
|
289
|
+
};
|
|
290
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
291
|
+
var _a;
|
|
292
|
+
const meId = authState.creds.me.id;
|
|
293
|
+
let shouldIncludeDeviceIdentity = false;
|
|
294
|
+
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
295
|
+
const statusJid = 'status@broadcast';
|
|
296
|
+
const isGroup = server === 'g.us';
|
|
297
|
+
const isNewsletter = server === 'newsletter';
|
|
298
|
+
const isStatus = jid === statusJid;
|
|
299
|
+
const isLid = server === 'lid';
|
|
300
|
+
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
|
301
|
+
useUserDevicesCache = useUserDevicesCache !== false;
|
|
302
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
303
|
+
const participants = [];
|
|
304
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
305
|
+
const binaryNodeContent = [];
|
|
306
|
+
const devices = [];
|
|
307
|
+
const meMsg = {
|
|
308
|
+
deviceSentMessage: {
|
|
309
|
+
destinationJid,
|
|
310
|
+
message
|
|
311
|
+
},
|
|
312
|
+
messageContextInfo: message.messageContextInfo
|
|
313
|
+
};
|
|
314
|
+
const extraAttrs = {};
|
|
315
|
+
if (participant) {
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
if (!isGroup && !isStatus) {
|
|
320
|
+
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
321
|
+
}
|
|
322
|
+
const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
|
|
323
|
+
devices.push({ user, device });
|
|
324
|
+
}
|
|
325
|
+
await authState.keys.transaction(async () => {
|
|
326
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
327
|
+
const mediaType = getMediaType(message);
|
|
328
|
+
if (mediaType) {
|
|
329
|
+
extraAttrs['mediatype'] = mediaType;
|
|
330
|
+
}
|
|
331
|
+
if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
|
|
332
|
+
extraAttrs['decrypt-fail'] = 'hide';
|
|
333
|
+
}
|
|
334
|
+
if (isGroup || isStatus) {
|
|
335
|
+
const [groupData, senderKeyMap] = await Promise.all([
|
|
336
|
+
(async () => {
|
|
337
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
338
|
+
if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
|
|
339
|
+
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
340
|
+
}
|
|
341
|
+
else if (!isStatus) {
|
|
342
|
+
groupData = await groupMetadata(jid);
|
|
343
|
+
}
|
|
344
|
+
return groupData;
|
|
345
|
+
})(),
|
|
346
|
+
(async () => {
|
|
347
|
+
if (!participant && !isStatus) {
|
|
348
|
+
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
349
|
+
return result[jid] || {};
|
|
350
|
+
}
|
|
351
|
+
return {};
|
|
352
|
+
})()
|
|
353
|
+
]);
|
|
354
|
+
if (!participant) {
|
|
355
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
|
|
356
|
+
if (isStatus && statusJidList) {
|
|
357
|
+
participantsList.push(...statusJidList);
|
|
358
|
+
}
|
|
359
|
+
if (!isStatus) {
|
|
360
|
+
additionalAttributes = {
|
|
361
|
+
...additionalAttributes,
|
|
362
|
+
|
|
363
|
+
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
367
|
+
devices.push(...additionalDevices);
|
|
368
|
+
}
|
|
369
|
+
const patched = await patchMessageBeforeSending(message);
|
|
370
|
+
if (Array.isArray(patched)) {
|
|
371
|
+
throw new boom_1.Boom('Per-jid patching is not supported in groups');
|
|
372
|
+
}
|
|
373
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
374
|
+
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
375
|
+
group: destinationJid,
|
|
376
|
+
data: bytes,
|
|
377
|
+
meId,
|
|
378
|
+
});
|
|
379
|
+
const senderKeyJids = [];
|
|
380
|
+
|
|
381
|
+
for (const { user, device } of devices) {
|
|
382
|
+
const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
383
|
+
if (!senderKeyMap[jid] || !!participant) {
|
|
384
|
+
senderKeyJids.push(jid);
|
|
385
|
+
|
|
386
|
+
senderKeyMap[jid] = true;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
if (senderKeyJids.length) {
|
|
392
|
+
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
393
|
+
const senderKeyMsg = {
|
|
394
|
+
senderKeyDistributionMessage: {
|
|
395
|
+
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
396
|
+
groupId: destinationJid
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
await assertSessions(senderKeyJids, false);
|
|
400
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
|
|
401
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
402
|
+
participants.push(...result.nodes);
|
|
403
|
+
}
|
|
404
|
+
binaryNodeContent.push({
|
|
405
|
+
tag: 'enc',
|
|
406
|
+
attrs: { v: '2', type: 'skmsg' },
|
|
407
|
+
content: ciphertext
|
|
408
|
+
});
|
|
409
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
410
|
+
}
|
|
411
|
+
else if (isNewsletter) {
|
|
412
|
+
|
|
413
|
+
if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
|
|
414
|
+
msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
|
|
415
|
+
message = message.protocolMessage.editedMessage;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
419
|
+
msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
|
|
420
|
+
message = {};
|
|
421
|
+
}
|
|
422
|
+
const patched = await patchMessageBeforeSending(message, []);
|
|
423
|
+
if (Array.isArray(patched)) {
|
|
424
|
+
throw new boom_1.Boom('Per-jid patching is not supported in channel');
|
|
425
|
+
}
|
|
426
|
+
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
427
|
+
binaryNodeContent.push({
|
|
428
|
+
tag: 'plaintext',
|
|
429
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
430
|
+
content: bytes
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
435
|
+
if (!participant) {
|
|
436
|
+
devices.push({ user });
|
|
437
|
+
if (user !== meUser) {
|
|
438
|
+
devices.push({ user: meUser });
|
|
439
|
+
}
|
|
440
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
441
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
442
|
+
devices.push(...additionalDevices);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const allJids = [];
|
|
446
|
+
const meJids = [];
|
|
447
|
+
const otherJids = [];
|
|
448
|
+
for (const { user, device } of devices) {
|
|
449
|
+
const isMe = user === meUser;
|
|
450
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
451
|
+
if (isMe) {
|
|
452
|
+
meJids.push(jid);
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
otherJids.push(jid);
|
|
456
|
+
}
|
|
457
|
+
allJids.push(jid);
|
|
458
|
+
}
|
|
459
|
+
await assertSessions(allJids, false);
|
|
460
|
+
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
461
|
+
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
462
|
+
createParticipantNodes(otherJids, message, extraAttrs)
|
|
463
|
+
]);
|
|
464
|
+
participants.push(...meNodes);
|
|
465
|
+
participants.push(...otherNodes);
|
|
466
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
467
|
+
}
|
|
468
|
+
if (participants.length) {
|
|
469
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
|
|
470
|
+
const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
|
|
471
|
+
if (peerNode) {
|
|
472
|
+
binaryNodeContent.push(peerNode);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
binaryNodeContent.push({
|
|
477
|
+
tag: 'participants',
|
|
478
|
+
attrs: {},
|
|
479
|
+
content: participants
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const stanza = {
|
|
484
|
+
tag: 'message',
|
|
485
|
+
attrs: {
|
|
486
|
+
id: msgId,
|
|
487
|
+
type: isNewsletter ? getTypeMessage(message) : 'text',
|
|
488
|
+
...(additionalAttributes || {})
|
|
489
|
+
},
|
|
490
|
+
content: binaryNodeContent
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
if (participant) {
|
|
496
|
+
if ((0, WABinary_1.isJidGroup)(destinationJid)) {
|
|
497
|
+
stanza.attrs.to = destinationJid;
|
|
498
|
+
stanza.attrs.participant = participant.jid;
|
|
499
|
+
}
|
|
500
|
+
else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
|
|
501
|
+
stanza.attrs.to = participant.jid;
|
|
502
|
+
stanza.attrs.recipient = destinationJid;
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
stanza.attrs.to = participant.jid;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
stanza.attrs.to = destinationJid;
|
|
510
|
+
}
|
|
511
|
+
if (shouldIncludeDeviceIdentity) {
|
|
512
|
+
stanza.content.push({
|
|
513
|
+
tag: 'device-identity',
|
|
514
|
+
attrs: {},
|
|
515
|
+
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
516
|
+
});
|
|
517
|
+
logger.debug({ jid }, 'adding device identity');
|
|
518
|
+
}
|
|
519
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
520
|
+
if (!stanza.content || !Array.isArray(stanza.content)) {
|
|
521
|
+
stanza.content = [];
|
|
522
|
+
}
|
|
523
|
+
stanza.content.push(...additionalNodes);
|
|
524
|
+
}
|
|
525
|
+
const messages = (0, Utils_1.normalizeMessageContent)(message);
|
|
526
|
+
const buttonType = getButtonType(messages);
|
|
527
|
+
if (!isNewsletter && buttonType) {
|
|
528
|
+
const buttonsNode = getButtonArgs(messages);
|
|
529
|
+
const content = (stanza.content && Array.isArray(stanza.content)) ? stanza.content : (stanza.content = []);
|
|
530
|
+
const hasBizNode = content.some((node) => {
|
|
531
|
+
var _a, _b;
|
|
532
|
+
if (!node || typeof node !== 'object' || node.tag !== 'biz') {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
if ((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.native_flow_name) {
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
const children = Array.isArray(node.content) ? node.content : [];
|
|
539
|
+
if (buttonType === 'list') {
|
|
540
|
+
return children.some((t) => { var _a, _b; return (t === null || t === void 0 ? void 0 : t.tag) === 'list' && ((_a = t.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'product_list' && ((_b = t.attrs) === null || _b === void 0 ? void 0 : _b.v) === '2'; });
|
|
541
|
+
}
|
|
542
|
+
if (buttonType === 'template') {
|
|
543
|
+
return children.some((t) => (t === null || t === void 0 ? void 0 : t.tag) === 'hsm');
|
|
544
|
+
}
|
|
545
|
+
return children.some((t) => { var _a, _b; return (t === null || t === void 0 ? void 0 : t.tag) === 'interactive' && ((_a = t.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'native_flow' && ((_b = t.attrs) === null || _b === void 0 ? void 0 : _b.v) === '1'; }) || ((_b = node.attrs) === null || _b === void 0 ? void 0 : _b.native_flow_name);
|
|
546
|
+
});
|
|
547
|
+
if (!hasBizNode) {
|
|
548
|
+
content.push(buttonsNode);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
552
|
+
await sendNode(stanza);
|
|
553
|
+
if (messageRetryManager && !participant) {
|
|
554
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
return msgId;
|
|
558
|
+
};
|
|
559
|
+
const getTypeMessage = (msg) => {
|
|
560
|
+
if (msg.viewOnceMessage) {
|
|
561
|
+
return getTypeMessage(msg.viewOnceMessage.message);
|
|
562
|
+
}
|
|
563
|
+
else if (msg.viewOnceMessageV2) {
|
|
564
|
+
return getTypeMessage(msg.viewOnceMessageV2.message);
|
|
565
|
+
}
|
|
566
|
+
else if (msg.viewOnceMessageV2Extension) {
|
|
567
|
+
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
568
|
+
}
|
|
569
|
+
else if (msg.ephemeralMessage) {
|
|
570
|
+
return getTypeMessage(msg.ephemeralMessage.message);
|
|
571
|
+
}
|
|
572
|
+
else if (msg.documentWithCaptionMessage) {
|
|
573
|
+
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
574
|
+
}
|
|
575
|
+
else if (msg.reactionMessage) {
|
|
576
|
+
return 'reaction';
|
|
577
|
+
}
|
|
578
|
+
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
579
|
+
return 'poll';
|
|
580
|
+
}
|
|
581
|
+
else if (getMediaType(msg)) {
|
|
582
|
+
return 'media';
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
return 'text';
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
const getMediaType = (message) => {
|
|
589
|
+
if (message.imageMessage) {
|
|
590
|
+
return 'image';
|
|
591
|
+
}
|
|
592
|
+
else if (message.videoMessage) {
|
|
593
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
594
|
+
}
|
|
595
|
+
else if (message.audioMessage) {
|
|
596
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
597
|
+
}
|
|
598
|
+
else if (message.contactMessage) {
|
|
599
|
+
return 'vcard';
|
|
600
|
+
}
|
|
601
|
+
else if (message.documentMessage) {
|
|
602
|
+
return 'document';
|
|
603
|
+
}
|
|
604
|
+
else if (message.contactsArrayMessage) {
|
|
605
|
+
return 'contact_array';
|
|
606
|
+
}
|
|
607
|
+
else if (message.liveLocationMessage) {
|
|
608
|
+
return 'livelocation';
|
|
609
|
+
}
|
|
610
|
+
else if (message.stickerMessage) {
|
|
611
|
+
return 'sticker';
|
|
612
|
+
}
|
|
613
|
+
else if (message.listMessage) {
|
|
614
|
+
return 'list';
|
|
615
|
+
}
|
|
616
|
+
else if (message.listResponseMessage) {
|
|
617
|
+
return 'list_response';
|
|
618
|
+
}
|
|
619
|
+
else if (message.buttonsResponseMessage) {
|
|
620
|
+
return 'buttons_response';
|
|
621
|
+
}
|
|
622
|
+
else if (message.orderMessage) {
|
|
623
|
+
return 'order';
|
|
624
|
+
}
|
|
625
|
+
else if (message.productMessage) {
|
|
626
|
+
return 'product';
|
|
627
|
+
}
|
|
628
|
+
else if (message.interactiveResponseMessage) {
|
|
629
|
+
return 'native_flow_response';
|
|
630
|
+
}
|
|
631
|
+
else if (message.groupInviteMessage) {
|
|
632
|
+
return 'url';
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
const getButtonType = (message) => {
|
|
636
|
+
if (message.listMessage) {
|
|
637
|
+
return 'list';
|
|
638
|
+
} else if (message.buttonsMessage) {
|
|
639
|
+
return 'buttons';
|
|
640
|
+
} else if (message.templateMessage) {
|
|
641
|
+
return 'template';
|
|
642
|
+
} else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
643
|
+
return 'native_flow';
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
const getButtonArgs = (message) => {
|
|
647
|
+
var _a, _b, _c;
|
|
648
|
+
const nativeFlowMsg = (_a = message.interactiveMessage) === null || _a === void 0 ? void 0 : _a.nativeFlowMessage;
|
|
649
|
+
const nativeFlowButtonName = (_c = (_b = nativeFlowMsg === null || nativeFlowMsg === void 0 ? void 0 : nativeFlowMsg.buttons) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.name;
|
|
650
|
+
if (nativeFlowButtonName === 'review_and_pay') {
|
|
651
|
+
return {
|
|
652
|
+
tag: 'biz',
|
|
653
|
+
attrs: {
|
|
654
|
+
native_flow_name: 'order_details'
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
} else if (nativeFlowMsg || message.buttonsMessage) {
|
|
658
|
+
const flowName = nativeFlowButtonName || 'quick_reply';
|
|
659
|
+
return {
|
|
660
|
+
tag: 'biz',
|
|
661
|
+
attrs: {},
|
|
662
|
+
content: [{
|
|
663
|
+
tag: 'interactive',
|
|
664
|
+
attrs: {
|
|
665
|
+
type: 'native_flow',
|
|
666
|
+
v: '1'
|
|
667
|
+
},
|
|
668
|
+
content: [{
|
|
669
|
+
tag: 'native_flow',
|
|
670
|
+
attrs: {
|
|
671
|
+
name: flowName
|
|
672
|
+
}
|
|
673
|
+
}]
|
|
674
|
+
}]
|
|
675
|
+
};
|
|
676
|
+
} else if (message.listMessage) {
|
|
677
|
+
return {
|
|
678
|
+
tag: 'biz',
|
|
679
|
+
attrs: {},
|
|
680
|
+
content: [{
|
|
681
|
+
tag: 'list',
|
|
682
|
+
attrs: {
|
|
683
|
+
type: 'product_list',
|
|
684
|
+
v: '2'
|
|
685
|
+
}
|
|
686
|
+
}]
|
|
687
|
+
};
|
|
688
|
+
} else if (message.templateMessage) {
|
|
689
|
+
return {
|
|
690
|
+
tag: 'biz',
|
|
691
|
+
attrs: {},
|
|
692
|
+
content: [{
|
|
693
|
+
tag: 'hsm',
|
|
694
|
+
attrs: {
|
|
695
|
+
tag: 'AUTHENTICATION',
|
|
696
|
+
category: ''
|
|
697
|
+
}
|
|
698
|
+
}]
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
const getPrivacyTokens = async (jids) => {
|
|
703
|
+
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
704
|
+
const result = await query({
|
|
705
|
+
tag: 'iq',
|
|
706
|
+
attrs: {
|
|
707
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
708
|
+
type: 'set',
|
|
709
|
+
xmlns: 'privacy'
|
|
710
|
+
},
|
|
711
|
+
content: [
|
|
712
|
+
{
|
|
713
|
+
tag: 'tokens',
|
|
714
|
+
attrs: {},
|
|
715
|
+
content: jids.map(jid => ({
|
|
716
|
+
tag: 'token',
|
|
717
|
+
attrs: {
|
|
718
|
+
jid: (0, WABinary_1.jidNormalizedUser)(jid),
|
|
719
|
+
t,
|
|
720
|
+
type: 'trusted_contact'
|
|
721
|
+
}
|
|
722
|
+
}))
|
|
723
|
+
}
|
|
724
|
+
]
|
|
725
|
+
});
|
|
726
|
+
return result;
|
|
727
|
+
};
|
|
728
|
+
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
729
|
+
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
730
|
+
return {
|
|
731
|
+
...sock,
|
|
732
|
+
getPrivacyTokens,
|
|
733
|
+
assertSessions,
|
|
734
|
+
relayMessage,
|
|
735
|
+
sendReceipt,
|
|
736
|
+
sendReceipts,
|
|
737
|
+
readMessages,
|
|
738
|
+
refreshMediaConn,
|
|
739
|
+
waUploadToServer,
|
|
740
|
+
fetchPrivacySettings,
|
|
741
|
+
getUSyncDevices,
|
|
742
|
+
createParticipantNodes,
|
|
743
|
+
messageRetryManager,
|
|
744
|
+
sendPeerDataOperationMessage,
|
|
745
|
+
updateMediaMessage: async (message) => {
|
|
746
|
+
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
747
|
+
const mediaKey = content.mediaKey;
|
|
748
|
+
const meId = authState.creds.me.id;
|
|
749
|
+
const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
750
|
+
let error = undefined;
|
|
751
|
+
await Promise.all([
|
|
752
|
+
sendNode(node),
|
|
753
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
754
|
+
const result = update.find(c => c.key.id === message.key.id);
|
|
755
|
+
if (result) {
|
|
756
|
+
if (result.error) {
|
|
757
|
+
error = result.error;
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
try {
|
|
761
|
+
const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
762
|
+
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
763
|
+
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
764
|
+
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
765
|
+
}
|
|
766
|
+
content.directPath = media.directPath;
|
|
767
|
+
content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
|
|
768
|
+
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
769
|
+
}
|
|
770
|
+
catch (err) {
|
|
771
|
+
error = err;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
})
|
|
777
|
+
]);
|
|
778
|
+
if (error) {
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
ev.emit('messages.update', [
|
|
782
|
+
{ key: message.key, update: { message: message.message } }
|
|
783
|
+
]);
|
|
784
|
+
return message;
|
|
785
|
+
},
|
|
786
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
787
|
+
const userJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
788
|
+
const distribution = new Set([userJid]);
|
|
789
|
+
const mentionedUsers = new Set();
|
|
790
|
+
for (const id of jids || []) {
|
|
791
|
+
const normalized = (0, WABinary_1.jidNormalizedUser)(id);
|
|
792
|
+
if ((0, WABinary_1.isJidGroup)(normalized)) {
|
|
793
|
+
try {
|
|
794
|
+
const metadata = (cachedGroupMetadata ? await cachedGroupMetadata(normalized) : undefined) || await groupMetadata(normalized);
|
|
795
|
+
for (const p of metadata.participants || []) {
|
|
796
|
+
const pj = (0, WABinary_1.jidNormalizedUser)(p.id);
|
|
797
|
+
distribution.add(pj);
|
|
798
|
+
if ((0, WABinary_1.isJidUser)(pj)) {
|
|
799
|
+
mentionedUsers.add(pj);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
catch (err) {
|
|
804
|
+
logger.error({ err, jid: normalized }, 'failed to resolve group participants for status mentions');
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
else if ((0, WABinary_1.isJidUser)(normalized)) {
|
|
808
|
+
distribution.add(normalized);
|
|
809
|
+
mentionedUsers.add(normalized);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
const uniqueDistribution = Array.from(distribution);
|
|
813
|
+
const uniqueMentions = Array.from(mentionedUsers);
|
|
814
|
+
const randomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, '0')}`;
|
|
815
|
+
const isAudio = typeof content === 'object' && !!content && 'audio' in content && !!content.audio;
|
|
816
|
+
const isMedia = typeof content === 'object' && !!content && (('image' in content && !!content.image) || ('video' in content && !!content.video) || ('audio' in content && !!content.audio));
|
|
817
|
+
const messageContent = { ...content };
|
|
818
|
+
if (isMedia && !isAudio && typeof messageContent.text === 'string') {
|
|
819
|
+
messageContent.caption = messageContent.text;
|
|
820
|
+
delete messageContent.text;
|
|
821
|
+
}
|
|
822
|
+
if (isAudio) {
|
|
823
|
+
delete messageContent.text;
|
|
824
|
+
delete messageContent.caption;
|
|
825
|
+
}
|
|
826
|
+
const font = !isMedia ? (typeof messageContent.font === 'number' ? messageContent.font : Math.floor(Math.random() * 9)) : undefined;
|
|
827
|
+
const textColor = !isMedia ? (typeof messageContent.textColor === 'string' ? messageContent.textColor : randomHexColor()) : undefined;
|
|
828
|
+
const backgroundColor = (!isMedia || isAudio) ? (typeof messageContent.backgroundColor === 'string' ? messageContent.backgroundColor : randomHexColor()) : undefined;
|
|
829
|
+
const ptt = isAudio ? (typeof messageContent.ptt === 'boolean' ? messageContent.ptt : true) : undefined;
|
|
830
|
+
const msg = await (0, Utils_1.generateWAMessage)(WABinary_1.STORIES_JID, messageContent, {
|
|
831
|
+
logger,
|
|
832
|
+
userJid,
|
|
833
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
834
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
835
|
+
fetchOpts: { timeout: 3000, ...axiosOptions || {} },
|
|
836
|
+
logger,
|
|
837
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
838
|
+
}),
|
|
839
|
+
upload: async (readStream, opts) => waUploadToServer(readStream, { ...opts }),
|
|
840
|
+
mediaCache: config.mediaCache,
|
|
841
|
+
options: config.options,
|
|
842
|
+
font,
|
|
843
|
+
textColor,
|
|
844
|
+
backgroundColor,
|
|
845
|
+
ptt
|
|
846
|
+
});
|
|
847
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
848
|
+
messageId: msg.key.id,
|
|
849
|
+
statusJidList: uniqueDistribution,
|
|
850
|
+
additionalNodes: [
|
|
851
|
+
{
|
|
852
|
+
tag: 'meta',
|
|
853
|
+
attrs: {},
|
|
854
|
+
content: [
|
|
855
|
+
{
|
|
856
|
+
tag: 'mentioned_users',
|
|
857
|
+
attrs: {},
|
|
858
|
+
content: uniqueMentions.map(jid => ({ tag: 'to', attrs: { jid } }))
|
|
859
|
+
}
|
|
860
|
+
]
|
|
861
|
+
}
|
|
862
|
+
]
|
|
863
|
+
});
|
|
864
|
+
for (const jid of uniqueMentions) {
|
|
865
|
+
const wrapperKey = (0, WABinary_1.isJidUser)(jid) ? 'statusMentionMessage' : 'groupStatusMentionMessage';
|
|
866
|
+
const protocolMessage = {
|
|
867
|
+
[wrapperKey]: {
|
|
868
|
+
message: {
|
|
869
|
+
protocolMessage: {
|
|
870
|
+
key: msg.key,
|
|
871
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.STATUS_MENTION_MESSAGE
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
messageContextInfo: {
|
|
876
|
+
messageSecret: (0, crypto_1.randomBytes)(32)
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
const statusMsg = (0, Utils_1.generateWAMessageFromContent)(jid, protocolMessage, {});
|
|
880
|
+
await relayMessage(jid, statusMsg.message, {
|
|
881
|
+
additionalNodes: [
|
|
882
|
+
{
|
|
883
|
+
tag: 'meta',
|
|
884
|
+
attrs: { is_status_mention: 'true' }
|
|
885
|
+
}
|
|
886
|
+
]
|
|
887
|
+
});
|
|
888
|
+
await (0, Utils_1.delay)(1500);
|
|
889
|
+
}
|
|
890
|
+
return msg;
|
|
891
|
+
},
|
|
892
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
893
|
+
var _a, _b, _c;
|
|
894
|
+
const userJid = authState.creds.me.id;
|
|
895
|
+
if (!options.ephemeralExpiration) {
|
|
896
|
+
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
897
|
+
const groups = await sock.groupQuery(jid, 'get', [{
|
|
898
|
+
tag: 'query',
|
|
899
|
+
attrs: {
|
|
900
|
+
request: 'interactive'
|
|
901
|
+
}
|
|
902
|
+
}]);
|
|
903
|
+
const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
|
|
904
|
+
const expiration = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(metadata, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.expiration) || 0;
|
|
905
|
+
options.ephemeralExpiration = expiration;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (typeof content === 'object' &&
|
|
909
|
+
'disappearingMessagesInChat' in content &&
|
|
910
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
911
|
+
(0, WABinary_1.isJidGroup)(jid)) {
|
|
912
|
+
const { disappearingMessagesInChat } = content;
|
|
913
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
914
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
915
|
+
disappearingMessagesInChat;
|
|
916
|
+
await groupToggleEphemeral(jid, value);
|
|
917
|
+
}
|
|
918
|
+
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
919
|
+
const { album, caption } = content;
|
|
920
|
+
if (caption && !album[0].caption) {
|
|
921
|
+
album[0].caption = caption;
|
|
922
|
+
}
|
|
923
|
+
let mediaHandle;
|
|
924
|
+
let mediaMsg;
|
|
925
|
+
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
926
|
+
albumMessage: {
|
|
927
|
+
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
928
|
+
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
929
|
+
}
|
|
930
|
+
}, { userJid, ...options });
|
|
931
|
+
await relayMessage(jid, albumMsg.message, {
|
|
932
|
+
messageId: albumMsg.key.id
|
|
933
|
+
});
|
|
934
|
+
for (const i in album) {
|
|
935
|
+
const media = album[i];
|
|
936
|
+
if ('image' in media) {
|
|
937
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
938
|
+
image: media.image,
|
|
939
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
940
|
+
...options
|
|
941
|
+
}, {
|
|
942
|
+
userJid,
|
|
943
|
+
upload: async (readStream, opts) => {
|
|
944
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
945
|
+
mediaHandle = up.handle;
|
|
946
|
+
return up;
|
|
947
|
+
},
|
|
948
|
+
...options,
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
else if ('video' in media) {
|
|
952
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
953
|
+
video: media.video,
|
|
954
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
955
|
+
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
956
|
+
...options
|
|
957
|
+
}, {
|
|
958
|
+
userJid,
|
|
959
|
+
upload: async (readStream, opts) => {
|
|
960
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
961
|
+
mediaHandle = up.handle;
|
|
962
|
+
return up;
|
|
963
|
+
},
|
|
964
|
+
...options,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
if (mediaMsg) {
|
|
968
|
+
mediaMsg.message.messageContextInfo = {
|
|
969
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
970
|
+
messageAssociation: {
|
|
971
|
+
associationType: 1,
|
|
972
|
+
parentMessageKey: albumMsg.key
|
|
973
|
+
},
|
|
974
|
+
participant: "0@s.whatsapp.net",
|
|
975
|
+
remoteJid: "status@broadcast",
|
|
976
|
+
forwardingScore: 99999,
|
|
977
|
+
isForwarded: true,
|
|
978
|
+
mentionedJid: [jid],
|
|
979
|
+
starred: true,
|
|
980
|
+
labels: ["Y", "Important"],
|
|
981
|
+
isHighlighted: true,
|
|
982
|
+
businessMessageForwardInfo: {
|
|
983
|
+
businessOwnerJid: jid
|
|
984
|
+
},
|
|
985
|
+
dataSharingContext: {
|
|
986
|
+
showMmDisclosure: true
|
|
987
|
+
},
|
|
988
|
+
forwardedNewsletterMessageInfo: {
|
|
989
|
+
newsletterJid: Buffer.from("MTIwMzYzNDIzMTc1Mjg5ODI2QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
990
|
+
serverMessageId: 1,
|
|
991
|
+
newsletterName: "NEROXRTX | Development Full Stack",
|
|
992
|
+
contentType: 1,
|
|
993
|
+
timestamp: new Date().toISOString(),
|
|
994
|
+
senderName: "NEROXRTX",
|
|
995
|
+
content: "Text Message",
|
|
996
|
+
priority: "high",
|
|
997
|
+
status: "sent"
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
mediaMsg.message.forwardedNewsletterMessageInfo = {
|
|
1001
|
+
newsletterJid: Buffer.from("MTIwMzYzNDIzMTc1Mjg5ODI2QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
1002
|
+
serverMessageId: 1,
|
|
1003
|
+
newsletterName: "NEROXRTX | Development Full Stack",
|
|
1004
|
+
contentType: 1,
|
|
1005
|
+
timestamp: new Date().toISOString(),
|
|
1006
|
+
senderName: "NEROXRTX",
|
|
1007
|
+
content: "Text Message",
|
|
1008
|
+
priority: "high",
|
|
1009
|
+
status: "sent"
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
await relayMessage(jid, mediaMsg.message, {
|
|
1013
|
+
messageId: mediaMsg.key.id
|
|
1014
|
+
});
|
|
1015
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
1016
|
+
}
|
|
1017
|
+
return albumMsg;
|
|
1018
|
+
}
|
|
1019
|
+
else if (typeof content === 'object' && 'groupStatusMessage' in content) {
|
|
1020
|
+
const storyData = content.groupStatusMessage;
|
|
1021
|
+
let waMsgContent;
|
|
1022
|
+
|
|
1023
|
+
if (storyData.message) {
|
|
1024
|
+
waMsgContent = storyData;
|
|
1025
|
+
} else {
|
|
1026
|
+
waMsgContent = await (0, Utils_1.generateWAMessageContent)(storyData, {
|
|
1027
|
+
logger,
|
|
1028
|
+
userJid,
|
|
1029
|
+
upload: async (readStream, opts) => {
|
|
1030
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
1031
|
+
return up;
|
|
1032
|
+
},
|
|
1033
|
+
mediaCache: config.mediaCache,
|
|
1034
|
+
options: config.options,
|
|
1035
|
+
...options
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
const msg = {
|
|
1040
|
+
message: {
|
|
1041
|
+
groupStatusMessageV2: {
|
|
1042
|
+
message: waMsgContent.message || waMsgContent
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
return await relayMessage(jid, msg.message, {
|
|
1048
|
+
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id)
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
else if (typeof content === 'object' && 'eventMessage' in content) {
|
|
1052
|
+
const eventData = content.eventMessage;
|
|
1053
|
+
const msg = await (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
1054
|
+
viewOnceMessage: {
|
|
1055
|
+
message: {
|
|
1056
|
+
messageContextInfo: {
|
|
1057
|
+
deviceListMetadata: {},
|
|
1058
|
+
deviceListMetadataVersion: 2,
|
|
1059
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
1060
|
+
supportPayload: JSON.stringify({
|
|
1061
|
+
version: 2,
|
|
1062
|
+
is_ai_message: true,
|
|
1063
|
+
should_show_system_message: true,
|
|
1064
|
+
ticket_id: (0, crypto_1.randomBytes)(16).toString('hex')
|
|
1065
|
+
})
|
|
1066
|
+
},
|
|
1067
|
+
eventMessage: {
|
|
1068
|
+
contextInfo: {
|
|
1069
|
+
mentionedJid: [jid],
|
|
1070
|
+
participant: jid,
|
|
1071
|
+
remoteJid: "status@broadcast",
|
|
1072
|
+
forwardedNewsletterMessageInfo: {
|
|
1073
|
+
newsletterName: "NEROXRTX | Development Full Stack",
|
|
1074
|
+
newsletterJid: Buffer.from("MTIwMzYzNDIzMTc1Mjg5ODI2QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
1075
|
+
serverMessageId: 1
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
isCanceled: eventData.isCanceled || false,
|
|
1079
|
+
name: eventData.name,
|
|
1080
|
+
description: eventData.description,
|
|
1081
|
+
location: eventData.location || {
|
|
1082
|
+
degreesLatitude: 0,
|
|
1083
|
+
degreesLongitude: 0,
|
|
1084
|
+
name: "Location"
|
|
1085
|
+
},
|
|
1086
|
+
joinLink: eventData.joinLink || '',
|
|
1087
|
+
startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
|
|
1088
|
+
endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
|
|
1089
|
+
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}, options);
|
|
1094
|
+
return await relayMessage(jid, msg.message, {
|
|
1095
|
+
messageId: msg.key.id
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
let mediaHandle;
|
|
1100
|
+
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
1101
|
+
logger,
|
|
1102
|
+
userJid,
|
|
1103
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
1104
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1105
|
+
fetchOpts: {
|
|
1106
|
+
timeout: 3000,
|
|
1107
|
+
...axiosOptions || {}
|
|
1108
|
+
},
|
|
1109
|
+
logger,
|
|
1110
|
+
uploadImage: generateHighQualityLinkPreview
|
|
1111
|
+
? waUploadToServer
|
|
1112
|
+
: undefined
|
|
1113
|
+
}),
|
|
1114
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1115
|
+
upload: async (readStream, opts) => {
|
|
1116
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
1117
|
+
mediaHandle = up.handle;
|
|
1118
|
+
return up;
|
|
1119
|
+
},
|
|
1120
|
+
mediaCache: config.mediaCache,
|
|
1121
|
+
options: config.options,
|
|
1122
|
+
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
|
|
1123
|
+
...options,
|
|
1124
|
+
});
|
|
1125
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1126
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1127
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1128
|
+
const isKeepMsg = 'keep' in content && content.keep;
|
|
1129
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1130
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
1131
|
+
const additionalAttributes = {};
|
|
1132
|
+
const additionalNodes = [];
|
|
1133
|
+
|
|
1134
|
+
if (isDeleteMsg) {
|
|
1135
|
+
|
|
1136
|
+
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
1137
|
+
additionalAttributes.edit = '8';
|
|
1138
|
+
}
|
|
1139
|
+
else {
|
|
1140
|
+
additionalAttributes.edit = '7';
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
}
|
|
1144
|
+
else if (isEditMsg) {
|
|
1145
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
1146
|
+
|
|
1147
|
+
}
|
|
1148
|
+
else if (isPinMsg) {
|
|
1149
|
+
additionalAttributes.edit = '2';
|
|
1150
|
+
|
|
1151
|
+
}
|
|
1152
|
+
else if (isKeepMsg) {
|
|
1153
|
+
additionalAttributes.edit = '6';
|
|
1154
|
+
|
|
1155
|
+
}
|
|
1156
|
+
else if (isPollMessage) {
|
|
1157
|
+
additionalNodes.push({
|
|
1158
|
+
tag: 'meta',
|
|
1159
|
+
attrs: {
|
|
1160
|
+
polltype: 'creation'
|
|
1161
|
+
},
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
}
|
|
1165
|
+
else if (isAiMsg) {
|
|
1166
|
+
additionalNodes.push({
|
|
1167
|
+
attrs: {
|
|
1168
|
+
biz_bot: '1'
|
|
1169
|
+
},
|
|
1170
|
+
tag: "bot"
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
if (mediaHandle) {
|
|
1174
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
1175
|
+
}
|
|
1176
|
+
if ('cachedGroupMetadata' in options) {
|
|
1177
|
+
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
1178
|
+
}
|
|
1179
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
|
|
1180
|
+
if (config.emitOwnEvents) {
|
|
1181
|
+
process.nextTick(() => {
|
|
1182
|
+
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
return fullMsg;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
};
|
|
1190
|
+
exports.makeMessagesSocket = makeMessagesSocket;
|