kage-baileys 3.0.6 → 3.2.4
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/Example/connection.cjs +4 -0
- package/README.MD +4726 -48
- package/README.md +5941 -0
- package/WAProto/WAProto.proto +3395 -415
- package/WAProto/compat.cjs +12 -0
- package/WAProto/index.d.ts +47104 -19888
- package/WAProto/index.js +131979 -57361
- package/lib/Addon/http-error.js +43 -0
- package/lib/Addon/index.js +32 -0
- package/lib/Addon/keyed-db.js +250 -0
- package/lib/Addon/link-preview.js +82 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +110 -0
- package/lib/Defaults/constants.js +156 -0
- package/lib/Defaults/history.js +46 -0
- package/lib/Defaults/index.js +230 -0
- package/lib/Defaults/media.js +104 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +44 -0
- package/lib/Extensions/business-advanced.js +382 -0
- package/lib/Extensions/business.js +159 -0
- package/lib/Extensions/chats-advanced.js +1106 -0
- package/lib/Extensions/chats.js +349 -0
- package/lib/Extensions/communities-advanced.js +430 -0
- package/lib/Extensions/community.js +94 -0
- package/lib/Extensions/groups-advanced.js +343 -0
- package/lib/Extensions/index.js +30 -0
- package/lib/Extensions/messages-recv-advanced.js +1690 -0
- package/lib/Extensions/messages-send-advanced.js +622 -0
- package/lib/Extensions/messages-send.js +1380 -0
- package/lib/Extensions/newsletter-advanced.js +228 -0
- package/lib/Extensions/newsletter.js +72 -0
- package/lib/Extensions/socket.js +389 -0
- package/lib/Modded/message_builder.js +2084 -4
- package/lib/Signal/Group/ciphertext-message.js +54 -0
- package/lib/Signal/Group/group-session-builder.js +124 -0
- package/lib/Signal/Group/group_cipher.js +216 -0
- package/lib/Signal/Group/index.js +124 -0
- package/lib/Signal/Group/keyhelper.js +108 -0
- package/lib/Signal/Group/sender-chain-key.js +83 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
- package/lib/Signal/Group/sender-key-message.js +166 -0
- package/lib/Signal/Group/sender-key-name.js +130 -0
- package/lib/Signal/Group/sender-key-record.js +113 -0
- package/lib/Signal/Group/sender-key-state.js +208 -0
- package/lib/Signal/Group/sender-message-key.js +82 -0
- package/lib/Signal/libsignal.js +935 -0
- package/lib/Signal/lid-mapping.js +545 -1
- package/lib/Socket/Client/index.js +60 -0
- package/lib/Socket/Client/types.js +51 -0
- package/lib/Socket/Client/websocket.js +152 -0
- package/lib/Socket/business.js +831 -0
- package/lib/Socket/chats.js +2535 -49
- package/lib/Socket/communities.js +450 -1
- package/lib/Socket/community.js +1022 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/groups.js +747 -0
- package/lib/Socket/index.js +60 -2
- package/lib/Socket/messages-recv.js +3450 -5
- package/lib/Socket/messages-send.js +3123 -0
- package/lib/Socket/mex.js +126 -1
- package/lib/Socket/newsletter.js +465 -0
- package/lib/Socket/socket.js +2217 -1
- package/lib/Store/index.js +79 -0
- package/lib/Store/make-cache-manager-store.js +186 -0
- package/lib/Store/make-in-memory-store.js +878 -0
- package/lib/Store/make-ordered-dictionary.js +187 -0
- package/lib/Store/object-repository.js +78 -0
- package/lib/Types/Auth.js +25 -0
- package/lib/Types/Bussines.js +25 -1
- package/lib/Types/Call.js +25 -0
- package/lib/Types/Chat.js +39 -0
- package/lib/Types/Contact.js +25 -0
- package/lib/Types/Events.js +25 -0
- package/lib/Types/GroupMetadata.js +25 -0
- package/lib/Types/Label.js +76 -0
- package/lib/Types/LabelAssociation.js +40 -0
- package/lib/Types/Message.js +57 -0
- package/lib/Types/Mex.js +56 -1
- package/lib/Types/MexUpdates.js +46 -0
- package/lib/Types/Newsletter.js +56 -0
- package/lib/Types/Product.js +25 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.js +25 -0
- package/lib/Types/Socket.js +25 -0
- package/lib/Types/State.js +92 -0
- package/lib/Types/USync.js +25 -0
- package/lib/Types/index.js +133 -0
- package/lib/Utils/auth-utils.js +703 -0
- package/lib/Utils/automation-tools.js +51 -16
- package/lib/Utils/baileys-event-stream.js +146 -0
- package/lib/Utils/browser-utils.js +95 -0
- package/lib/Utils/business.js +525 -0
- package/lib/Utils/chat-utils.js +1861 -0
- package/lib/Utils/companion-reg-client-utils.js +55 -1
- package/lib/Utils/crypto.js +355 -0
- package/lib/Utils/decode-wa-message.js +709 -0
- package/lib/Utils/event-buffer.js +1323 -8
- package/lib/Utils/generics.js +945 -1
- package/lib/Utils/history.js +266 -0
- package/lib/Utils/identity-change-handler.js +62 -1
- package/lib/Utils/index.js +114 -0
- package/lib/Utils/link-preview.js +179 -0
- package/lib/Utils/logger.js +42 -0
- package/lib/Utils/lt-hash.js +73 -0
- package/lib/Utils/make-mutex.js +104 -0
- package/lib/Utils/message-inspector.js +110 -0
- package/lib/Utils/message-retry-manager.js +507 -2
- package/lib/Utils/messages-media.js +1931 -1
- package/lib/Utils/messages.js +3748 -0
- package/lib/Utils/noise-handler.js +423 -0
- package/lib/Utils/offline-node-processor.js +53 -1
- package/lib/Utils/pre-key-manager.js +255 -1
- package/lib/Utils/process-message.js +1592 -0
- package/lib/Utils/reporting-utils.js +272 -1
- package/lib/Utils/rich-message-utils.js +377 -0
- package/lib/Utils/rich-messages.js +1 -1
- package/lib/Utils/signal.js +437 -0
- package/lib/Utils/stanza-ack.js +51 -1
- package/lib/Utils/status-refresh.js +37 -0
- package/lib/Utils/status-tools.js +4 -2
- package/lib/Utils/sync-action-utils.js +63 -1
- package/lib/Utils/tc-token-utils.js +185 -1
- package/lib/Utils/terminal-banner.js +31 -0
- package/lib/Utils/use-multi-file-auth-state.js +271 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +142 -0
- package/lib/Utils/validate-connection.js +497 -1
- package/lib/Utils/view-once-compat.js +13 -5
- package/lib/VoIP/audio-feeder.js +150 -0
- package/lib/VoIP/index.js +289 -0
- package/lib/VoIP/relay-transport.js +608 -0
- package/lib/VoIP/signaling.js +583 -0
- package/lib/VoIP/types.js +30 -0
- package/lib/VoIP/wasm-engine.js +1261 -2
- package/lib/VoIP/worker-bootstrap.js +1090 -2
- package/lib/WABinary/constants.js +2805 -0
- package/lib/WABinary/decode.js +649 -2
- package/lib/WABinary/encode.js +564 -2
- package/lib/WABinary/generic-utils.js +401 -0
- package/lib/WABinary/index.js +82 -0
- package/lib/WABinary/jid-utils.js +290 -0
- package/lib/WABinary/types.js +25 -0
- package/lib/WAM/BinaryInfo.js +50 -0
- package/lib/WAM/constants.js +45747 -0
- package/lib/WAM/encode.js +393 -0
- package/lib/WAM/index.js +78 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
- package/lib/WAUSync/Protocols/index.js +83 -0
- package/lib/WAUSync/USyncQuery.js +241 -2
- package/lib/WAUSync/USyncUser.js +86 -0
- package/lib/WAUSync/index.js +78 -0
- package/lib/assets/wasm/loader.js +1875 -1
- package/lib/assets/wasm/worker-modules.js +11047 -1
- package/lib/index.d.ts +126 -0
- package/lib/index.js +53 -21
- package/lib/index.mjs +437 -0
- package/licenses/upstream-MIT.txt +22 -0
- package/maintenance/api-coverage.json +1642 -0
- package/maintenance/archivos-sha256.json +207 -0
- package/maintenance/consumer-validation.log +3 -0
- package/maintenance/dependency-audit.json +4 -4
- package/maintenance/extension-inventory.json +57 -0
- package/maintenance/protocol-update.json +1101 -0
- package/maintenance/protocol-wire-audit.json +4 -0
- package/maintenance/reference-socket-surface.json +209 -0
- package/maintenance/resumen-validacion.json +50 -0
- package/maintenance/validation.log +2725 -0
- package/maintenance/verification.json +566 -0
- package/package.json +107 -9
- package/scripts/check-imports.cjs +10 -0
- package/scripts/check-package.cjs +40 -0
- package/scripts/check-syntax.cjs +1 -1
- package/scripts/generate-protobuf.cjs +6 -1
- package/scripts/generate-public-types.cjs +9 -0
- package/scripts/kage-base64-fix.cjs +45 -0
- package/scripts/maintenance.cjs +10 -0
- package/test/advanced.test.cjs +24 -0
- package/test/base64-fix.test.cjs +49 -0
- package/test/maintenance.test.cjs +1 -1
- package/test/npm-publication.test.cjs +141 -0
- package/test/recepcion-reparada.test.cjs +98 -0
- package/test/resilience-binary.test.cjs +69 -0
- package/test/resilience-transport.test.cjs +34 -0
- package/test/types.test.ts +5 -0
- package/test/upgrade.test.cjs +104 -0
- package/tsconfig.json +20 -0
- package/WAProto/p.html +0 -1
- package/lib/KageExtra/Modded/message_builder.js +0 -2330
- package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
- package/lib/KageExtra/VoIP/index.js +0 -282
- package/lib/KageExtra/VoIP/relay-transport.js +0 -559
- package/lib/KageExtra/VoIP/signaling.js +0 -603
- package/lib/KageExtra/VoIP/types.js +0 -17
- package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
- package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
- package/lib/KageExtra/assets/wasm/loader.js +0 -5
- package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
- package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
- package/lib/KageExtra/index.js +0 -3
- package/lib/KageExtra/package.json +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/maintenance/revision-full-check.txt +0 -1097
- package/maintenance/revision-library-tests.tap +0 -1088
- package/maintenance/revision-protobuf.txt +0 -5
- package/maintenance/revision-syntax.txt +0 -5
- package/maintenance/schema-coverage.json +0 -23
- package/maintenance/schema-merge.json +0 -30
- package/maintenance/validation-node20.txt +0 -191
- package/maintenance/validation-node22.txt +0 -237
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attachAdvanced = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
6
|
+
const index_js_2 = require("../Addon/index.js");
|
|
7
|
+
const index_js_3 = require("../Defaults/index.js");
|
|
8
|
+
const index_js_4 = require("../Utils/index.js");
|
|
9
|
+
const index_js_5 = require("../Types/index.js");
|
|
10
|
+
const link_preview_js_1 = require("../Utils/link-preview.js");
|
|
11
|
+
const make_mutex_js_1 = require("../Utils/make-mutex.js");
|
|
12
|
+
const reporting_utils_js_1 = require("../Utils/reporting-utils.js");
|
|
13
|
+
const tc_token_utils_js_1 = require("../Utils/tc-token-utils.js");
|
|
14
|
+
const index_js_6 = require("../WABinary/index.js");
|
|
15
|
+
const index_js_7 = require("../WAUSync/index.js");
|
|
16
|
+
const attachAdvanced = (base, config) => {
|
|
17
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
18
|
+
const sock = base;
|
|
19
|
+
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
|
|
20
|
+
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
21
|
+
/**
|
|
22
|
+
* Set of tctoken storage JIDs with a fire-and-forget `issuePrivacyTokens` IQ in flight.
|
|
23
|
+
* Prevents duplicate IQs from rapid back-to-back sends before `senderTimestamp` persists.
|
|
24
|
+
* Entries are always removed in `.finally()`, so the set is bounded by concurrency.
|
|
25
|
+
*/
|
|
26
|
+
const inFlightTcTokenIssuance = new Set();
|
|
27
|
+
const userDevicesCache = config.userDevicesCache ||
|
|
28
|
+
(0, index_js_2.createCache)({
|
|
29
|
+
ttl: index_js_3.DEFAULT_CACHE_TTLS.USER_DEVICES // 5 minutes
|
|
30
|
+
});
|
|
31
|
+
/** Serializes writes to userDevicesCache across USync refresh and device-notification handling. */
|
|
32
|
+
const devicesMutex = (0, make_mutex_js_1.makeMutex)();
|
|
33
|
+
// Initialize message retry manager if enabled
|
|
34
|
+
const messageRetryManager = enableRecentMessageCache ? new index_js_4.MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
35
|
+
// Prevent race conditions in Signal session encryption by user
|
|
36
|
+
const encryptionMutex = (0, make_mutex_js_1.makeKeyedMutex)();
|
|
37
|
+
// Prevent race conditions in media connection refresh
|
|
38
|
+
const mediaConnMutex = (0, make_mutex_js_1.makeKeyedMutex)();
|
|
39
|
+
let mediaConn;
|
|
40
|
+
/** Per-socket media host; updated whenever media_conn is fetched. Defaults to the public WhatsApp host. */
|
|
41
|
+
let mediaHost = index_js_4.DEF_MEDIA_HOST;
|
|
42
|
+
const refreshMediaConn = async (forceGet = false) => {
|
|
43
|
+
return mediaConnMutex.mutex('media-conn', async () => {
|
|
44
|
+
const media = await mediaConn;
|
|
45
|
+
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
46
|
+
mediaConn = (async () => {
|
|
47
|
+
const result = await query({
|
|
48
|
+
tag: 'iq',
|
|
49
|
+
attrs: {
|
|
50
|
+
type: 'set',
|
|
51
|
+
xmlns: 'w:m',
|
|
52
|
+
to: index_js_6.S_WHATSAPP_NET
|
|
53
|
+
},
|
|
54
|
+
content: [{ tag: 'media_conn', attrs: {} }]
|
|
55
|
+
});
|
|
56
|
+
const mediaConnNode = (0, index_js_6.getBinaryNodeChild)(result, 'media_conn');
|
|
57
|
+
// TODO: explore full length of data that whatsapp provides
|
|
58
|
+
const node = {
|
|
59
|
+
hosts: (0, index_js_6.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
60
|
+
hostname: attrs.hostname,
|
|
61
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
62
|
+
})),
|
|
63
|
+
auth: mediaConnNode.attrs.auth,
|
|
64
|
+
ttl: +mediaConnNode.attrs.ttl,
|
|
65
|
+
fetchDate: new Date()
|
|
66
|
+
};
|
|
67
|
+
logger.debug('fetched media conn');
|
|
68
|
+
if (node.hosts[0]) {
|
|
69
|
+
mediaHost = node.hosts[0].hostname;
|
|
70
|
+
}
|
|
71
|
+
return node;
|
|
72
|
+
})();
|
|
73
|
+
}
|
|
74
|
+
return mediaConn;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* generic send receipt function
|
|
79
|
+
* used for receipts of phone call, read, delivery etc.
|
|
80
|
+
* */
|
|
81
|
+
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
82
|
+
if (!messageIds || messageIds.length === 0) {
|
|
83
|
+
throw new index_js_2.HttpError('missing ids in receipt');
|
|
84
|
+
}
|
|
85
|
+
const node = {
|
|
86
|
+
tag: 'receipt',
|
|
87
|
+
attrs: {
|
|
88
|
+
id: messageIds[0]
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
92
|
+
if (isReadReceipt) {
|
|
93
|
+
node.attrs.t = (0, index_js_4.unixTimestampSeconds)().toString();
|
|
94
|
+
}
|
|
95
|
+
if (type === 'sender' && ((0, index_js_6.isPnUser)(jid) || (0, index_js_6.isLidUser)(jid))) {
|
|
96
|
+
node.attrs.recipient = jid;
|
|
97
|
+
node.attrs.to = participant;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
node.attrs.to = jid;
|
|
101
|
+
if (participant) {
|
|
102
|
+
node.attrs.participant = participant;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (type) {
|
|
106
|
+
node.attrs.type = type;
|
|
107
|
+
}
|
|
108
|
+
const remainingMessageIds = messageIds.slice(1);
|
|
109
|
+
if (remainingMessageIds.length) {
|
|
110
|
+
node.content = [
|
|
111
|
+
{
|
|
112
|
+
tag: 'list',
|
|
113
|
+
attrs: {},
|
|
114
|
+
content: remainingMessageIds.map(id => ({
|
|
115
|
+
tag: 'item',
|
|
116
|
+
attrs: { id }
|
|
117
|
+
}))
|
|
118
|
+
}
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
122
|
+
await sendNode(node);
|
|
123
|
+
};
|
|
124
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
|
125
|
+
const sendReceipts = async (keys, type) => {
|
|
126
|
+
const recps = (0, index_js_4.aggregateMessageKeysNotFromMe)(keys);
|
|
127
|
+
for (const { jid, participant, messageIds } of recps) {
|
|
128
|
+
await sendReceipt(jid, participant, messageIds, type);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/** Bulk read messages. Keys can be from different chats & participants */
|
|
132
|
+
const readMessages = async (keys) => {
|
|
133
|
+
const privacySettings = await fetchPrivacySettings();
|
|
134
|
+
// based on privacy settings, we have to change the read type
|
|
135
|
+
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
136
|
+
await sendReceipts(keys, readType);
|
|
137
|
+
};
|
|
138
|
+
/** Fetch all the devices we've to send a message to */
|
|
139
|
+
const getUSyncDevices = base.getUSyncDevices.bind(base);
|
|
140
|
+
/**
|
|
141
|
+
* Update Member Label
|
|
142
|
+
*/
|
|
143
|
+
const updateMemberLabel = (jid, memberLabel) => {
|
|
144
|
+
return relayMessage(jid, {
|
|
145
|
+
protocolMessage: {
|
|
146
|
+
type: index_js_1.proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
|
|
147
|
+
memberLabel: {
|
|
148
|
+
label: memberLabel?.slice(0, 30),
|
|
149
|
+
labelTimestamp: (0, index_js_4.unixTimestampSeconds)()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
additionalNodes: [
|
|
154
|
+
{
|
|
155
|
+
tag: 'meta',
|
|
156
|
+
attrs: {
|
|
157
|
+
tag_reason: 'user_update',
|
|
158
|
+
appdata: 'member_tag'
|
|
159
|
+
},
|
|
160
|
+
content: undefined
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const assertSessions = base.assertSessions.bind(base);
|
|
166
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
167
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
168
|
+
if (!authState.creds.me?.id) {
|
|
169
|
+
throw new index_js_2.HttpError('Not authenticated');
|
|
170
|
+
}
|
|
171
|
+
const protocolMessage = {
|
|
172
|
+
protocolMessage: {
|
|
173
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
174
|
+
type: index_js_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const meJid = (0, index_js_6.jidNormalizedUser)(authState.creds.me.id);
|
|
178
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
179
|
+
additionalAttributes: {
|
|
180
|
+
category: 'peer',
|
|
181
|
+
push_priority: 'high_force'
|
|
182
|
+
},
|
|
183
|
+
additionalNodes: [
|
|
184
|
+
{
|
|
185
|
+
tag: 'meta',
|
|
186
|
+
attrs: { appdata: 'default' }
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
return msgId;
|
|
191
|
+
};
|
|
192
|
+
const createParticipantNodes = base.createParticipantNodes.bind(base);
|
|
193
|
+
const relayMessage = base.relayMessage.bind(base);
|
|
194
|
+
const getMessageType = (message) => {
|
|
195
|
+
if (!message)
|
|
196
|
+
return 'text';
|
|
197
|
+
if (message.reactionMessage || message.encReactionMessage) {
|
|
198
|
+
return 'reaction';
|
|
199
|
+
}
|
|
200
|
+
if (message.pollCreationMessage ||
|
|
201
|
+
message.pollCreationMessageV2 ||
|
|
202
|
+
message.pollCreationMessageV3 ||
|
|
203
|
+
message.pollCreationMessageV5 ||
|
|
204
|
+
message.pollCreationMessageV6 ||
|
|
205
|
+
message.pollUpdateMessage) {
|
|
206
|
+
return 'poll';
|
|
207
|
+
}
|
|
208
|
+
if (message.eventMessage) {
|
|
209
|
+
return 'event';
|
|
210
|
+
}
|
|
211
|
+
if (getMediaType(message) !== '') {
|
|
212
|
+
return 'media';
|
|
213
|
+
}
|
|
214
|
+
return 'text';
|
|
215
|
+
};
|
|
216
|
+
const getMediaType = (message) => {
|
|
217
|
+
if (message.imageMessage) {
|
|
218
|
+
return 'image';
|
|
219
|
+
}
|
|
220
|
+
else if (message.videoMessage) {
|
|
221
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
222
|
+
}
|
|
223
|
+
else if (message.stickerMessage) {
|
|
224
|
+
return message.stickerMessage.isLottie ? '1p_sticker' : message.stickerMessage.isAvatar ? 'avatar_sticker' : 'sticker';
|
|
225
|
+
}
|
|
226
|
+
else if (message.audioMessage) {
|
|
227
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
228
|
+
}
|
|
229
|
+
else if (message.albumMessage) {
|
|
230
|
+
return 'collection';
|
|
231
|
+
}
|
|
232
|
+
else if (message.contactMessage) {
|
|
233
|
+
return 'vcard';
|
|
234
|
+
}
|
|
235
|
+
else if (message.documentMessage) {
|
|
236
|
+
return 'document';
|
|
237
|
+
}
|
|
238
|
+
else if (message.contactsArrayMessage) {
|
|
239
|
+
return 'contact_array';
|
|
240
|
+
}
|
|
241
|
+
else if (message.liveLocationMessage) {
|
|
242
|
+
return 'livelocation';
|
|
243
|
+
}
|
|
244
|
+
else if (message.stickerPackMessage) {
|
|
245
|
+
return 'sticker_pack';
|
|
246
|
+
}
|
|
247
|
+
else if (message.listMessage) {
|
|
248
|
+
return 'list';
|
|
249
|
+
}
|
|
250
|
+
else if (message.listResponseMessage) {
|
|
251
|
+
return 'list_response';
|
|
252
|
+
}
|
|
253
|
+
else if (message.buttonsResponseMessage) {
|
|
254
|
+
return 'buttons_response';
|
|
255
|
+
}
|
|
256
|
+
else if (message.orderMessage) {
|
|
257
|
+
return 'order';
|
|
258
|
+
}
|
|
259
|
+
else if (message.productMessage) {
|
|
260
|
+
return 'product';
|
|
261
|
+
}
|
|
262
|
+
else if (message.interactiveResponseMessage) {
|
|
263
|
+
return 'native_flow_response';
|
|
264
|
+
}
|
|
265
|
+
else if (message.extendedTextMessage?.matchedText || message.groupInviteMessage) {
|
|
266
|
+
return 'url';
|
|
267
|
+
}
|
|
268
|
+
// Kage: nota de compatibilidad.
|
|
269
|
+
else if ((message.extendedTextMessage?.text || message.conversation || '').includes('://wa.me/c/')) {
|
|
270
|
+
return 'cataloglink';
|
|
271
|
+
}
|
|
272
|
+
else if ((message.extendedTextMessage?.text || message.conversation || '').includes('://wa.me/p/')) {
|
|
273
|
+
return 'productlink';
|
|
274
|
+
}
|
|
275
|
+
return '';
|
|
276
|
+
};
|
|
277
|
+
const issuePrivacyTokens = async (jids, timestamp) => {
|
|
278
|
+
const t = (timestamp ?? (0, index_js_4.unixTimestampSeconds)()).toString();
|
|
279
|
+
const result = await query({
|
|
280
|
+
tag: 'iq',
|
|
281
|
+
attrs: {
|
|
282
|
+
to: index_js_6.S_WHATSAPP_NET,
|
|
283
|
+
type: 'set',
|
|
284
|
+
xmlns: 'privacy'
|
|
285
|
+
},
|
|
286
|
+
content: [
|
|
287
|
+
{
|
|
288
|
+
tag: 'tokens',
|
|
289
|
+
attrs: {},
|
|
290
|
+
content: jids.map(jid => ({
|
|
291
|
+
tag: 'token',
|
|
292
|
+
attrs: {
|
|
293
|
+
jid: (0, index_js_6.jidNormalizedUser)(jid),
|
|
294
|
+
t,
|
|
295
|
+
type: 'trusted_contact'
|
|
296
|
+
}
|
|
297
|
+
}))
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
});
|
|
301
|
+
return result;
|
|
302
|
+
};
|
|
303
|
+
const waUploadToServer = require('../Utils/messages-media.js')[Symbol.for('kage.advanced')].getWAUploadToServer(config, refreshMediaConn);
|
|
304
|
+
const waitForMsgMediaUpdate = (0, index_js_4.bindWaitForEvent)(ev, 'messages.media-update');
|
|
305
|
+
return {
|
|
306
|
+
...sock,
|
|
307
|
+
userDevicesCache,
|
|
308
|
+
devicesMutex,
|
|
309
|
+
issuePrivacyTokens,
|
|
310
|
+
assertSessions,
|
|
311
|
+
relayMessage,
|
|
312
|
+
sendReceipt,
|
|
313
|
+
sendReceipts,
|
|
314
|
+
readMessages,
|
|
315
|
+
refreshMediaConn,
|
|
316
|
+
// Function (not getter) so the spread in chats.ts preserves the live closure binding.
|
|
317
|
+
getMediaHost: () => mediaHost,
|
|
318
|
+
waUploadToServer,
|
|
319
|
+
fetchPrivacySettings,
|
|
320
|
+
sendPeerDataOperationMessage,
|
|
321
|
+
createParticipantNodes,
|
|
322
|
+
getUSyncDevices,
|
|
323
|
+
messageRetryManager,
|
|
324
|
+
updateMemberLabel,
|
|
325
|
+
updateMediaMessage: async (message) => {
|
|
326
|
+
const content = (0, index_js_4.assertMediaContent)(message.message);
|
|
327
|
+
const mediaKey = content.mediaKey;
|
|
328
|
+
const meId = authState.creds.me.id;
|
|
329
|
+
const node = (0, index_js_4.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
330
|
+
let error = undefined;
|
|
331
|
+
await Promise.all([
|
|
332
|
+
sendNode(node),
|
|
333
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
334
|
+
const result = update.find(c => c.key.id === message.key.id);
|
|
335
|
+
if (result) {
|
|
336
|
+
if (result.error) {
|
|
337
|
+
error = result.error;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
try {
|
|
341
|
+
const media = (0, index_js_4.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
342
|
+
if (media.result !== index_js_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
343
|
+
const resultStr = index_js_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
344
|
+
throw new index_js_2.HttpError(`Media re-upload failed by device (${resultStr})`, {
|
|
345
|
+
data: media,
|
|
346
|
+
statusCode: (0, index_js_4.getStatusCodeForMediaRetry)(media.result) || 404
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
content.directPath = media.directPath;
|
|
350
|
+
content.url = (0, index_js_4.getUrlFromDirectPath)(content.directPath, mediaHost);
|
|
351
|
+
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
error = err;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
})
|
|
360
|
+
]);
|
|
361
|
+
if (error) {
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
365
|
+
return message;
|
|
366
|
+
},
|
|
367
|
+
// Kage: actualización de compatibilidad.
|
|
368
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
369
|
+
var _a;
|
|
370
|
+
const userJid = authState.creds.me.id;
|
|
371
|
+
// Kage: actualización de compatibilidad.
|
|
372
|
+
if (Array.isArray(jid)) {
|
|
373
|
+
const { delayMs = 1500 } = options;
|
|
374
|
+
const allUsers = new Set();
|
|
375
|
+
const fullMsg = await (0, index_js_4.generateWAMessage)('status@broadcast', content, {
|
|
376
|
+
logger,
|
|
377
|
+
userJid,
|
|
378
|
+
upload: waUploadToServer,
|
|
379
|
+
mediaCache: config.mediaCache,
|
|
380
|
+
options: config.options,
|
|
381
|
+
...options,
|
|
382
|
+
messageId: (0, index_js_4.generateMessageIDV2)(userJid)
|
|
383
|
+
});
|
|
384
|
+
for (const id of jid) {
|
|
385
|
+
if ((0, index_js_6.isJidGroup)(id)) {
|
|
386
|
+
try {
|
|
387
|
+
const groupData = (cachedGroupMetadata ? await cachedGroupMetadata(id) : null) || await groupMetadata(id);
|
|
388
|
+
for (const participant of groupData.participants) {
|
|
389
|
+
if (allUsers.has(participant.id))
|
|
390
|
+
continue;
|
|
391
|
+
allUsers.add(participant.id);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
logger.error(`Error getting metadata group from ${id}: ${error}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else if (!allUsers.has(id)) {
|
|
399
|
+
allUsers.add(id);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
await relayMessage('status@broadcast', fullMsg.message, {
|
|
403
|
+
messageId: fullMsg.key.id,
|
|
404
|
+
statusJidList: Array.from(allUsers),
|
|
405
|
+
additionalNodes: [
|
|
406
|
+
{
|
|
407
|
+
tag: 'meta',
|
|
408
|
+
attrs: {},
|
|
409
|
+
content: [
|
|
410
|
+
{
|
|
411
|
+
tag: 'mentioned_users',
|
|
412
|
+
attrs: {},
|
|
413
|
+
content: jid.map(id => ({
|
|
414
|
+
tag: 'to',
|
|
415
|
+
attrs: { jid: id },
|
|
416
|
+
content: undefined
|
|
417
|
+
}))
|
|
418
|
+
}
|
|
419
|
+
]
|
|
420
|
+
}
|
|
421
|
+
]
|
|
422
|
+
});
|
|
423
|
+
if (config.emitOwnEvents) {
|
|
424
|
+
process.nextTick(async () => {
|
|
425
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
for (const id of jid) {
|
|
429
|
+
const isGroup = (0, index_js_6.isJidGroup)(id);
|
|
430
|
+
const sendType = isGroup ? 'groupStatusMentionMessage' : 'statusMentionMessage';
|
|
431
|
+
const mentionMsg = (0, index_js_4.generateWAMessageFromContent)(id, {
|
|
432
|
+
messageContextInfo: {
|
|
433
|
+
messageSecret: (0, node_crypto_1.randomBytes)(32)
|
|
434
|
+
},
|
|
435
|
+
[sendType]: {
|
|
436
|
+
message: {
|
|
437
|
+
protocolMessage: {
|
|
438
|
+
key: fullMsg.key,
|
|
439
|
+
type: 25
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}, {
|
|
444
|
+
userJid
|
|
445
|
+
});
|
|
446
|
+
await relayMessage(id, mentionMsg.message, {
|
|
447
|
+
additionalNodes: [
|
|
448
|
+
{
|
|
449
|
+
tag: 'meta',
|
|
450
|
+
attrs: isGroup ?
|
|
451
|
+
{ is_group_status_mention: 'true' } :
|
|
452
|
+
{ is_status_mention: 'true' },
|
|
453
|
+
content: undefined
|
|
454
|
+
}
|
|
455
|
+
]
|
|
456
|
+
});
|
|
457
|
+
if (config.emitOwnEvents) {
|
|
458
|
+
process.nextTick(async () => {
|
|
459
|
+
await messageMutex.mutex(() => upsertMessage(mentionMsg, 'append'));
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
await (0, index_js_4.delay)(delayMs);
|
|
463
|
+
}
|
|
464
|
+
return fullMsg;
|
|
465
|
+
}
|
|
466
|
+
else if ('disappearingMessagesInChat' in content && (0, index_js_6.isJidGroup)(jid)) {
|
|
467
|
+
const { disappearingMessagesInChat } = content;
|
|
468
|
+
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
469
|
+
? disappearingMessagesInChat
|
|
470
|
+
? index_js_3.WA_DEFAULT_EPHEMERAL
|
|
471
|
+
: 0
|
|
472
|
+
: disappearingMessagesInChat;
|
|
473
|
+
await groupToggleEphemeral(jid, value);
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
const fullMsg = await (0, index_js_4.generateWAMessage)(jid, content, {
|
|
477
|
+
logger,
|
|
478
|
+
userJid,
|
|
479
|
+
getUrlInfo: text => (0, link_preview_js_1.getUrlInfo)(text, {
|
|
480
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
481
|
+
fetchOpts: {
|
|
482
|
+
timeout: 3000,
|
|
483
|
+
...(httpRequestOptions || {})
|
|
484
|
+
},
|
|
485
|
+
logger,
|
|
486
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
487
|
+
}),
|
|
488
|
+
//TODO: CACHE
|
|
489
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
490
|
+
getCallLink: sock.createCallLink,
|
|
491
|
+
upload: waUploadToServer,
|
|
492
|
+
mediaCache: config.mediaCache,
|
|
493
|
+
options: config.options,
|
|
494
|
+
...options,
|
|
495
|
+
messageId: (0, index_js_4.generateMessageIDV2)(userJid)
|
|
496
|
+
});
|
|
497
|
+
const isNewsletter = (0, index_js_6.isJidNewsletter)(jid);
|
|
498
|
+
const isEventMsg = 'event' in content && !!content.event;
|
|
499
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
500
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
501
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
502
|
+
const isKeepMsg = 'keep' in content && !!content.keep;
|
|
503
|
+
const isPollMsg = 'poll' in content && !!content.poll;
|
|
504
|
+
const isQuizMsg = 'poll' in content && !!content.poll.pollType;
|
|
505
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
506
|
+
const isNeedBizAttrs = 'secureMetaServiceLabel' in content && !!content.secureMetaServiceLabel;
|
|
507
|
+
const additionalAttributes = options.additionalAttributes || {};
|
|
508
|
+
const additionalNodes = options.additionalNodes || [];
|
|
509
|
+
// required for delete
|
|
510
|
+
if (isDeleteMsg || isKeepMsg) {
|
|
511
|
+
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
512
|
+
if ((0, index_js_6.isJidGroup)(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
513
|
+
additionalAttributes.edit = '8';
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
additionalAttributes.edit = '7';
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else if (isEditMsg) {
|
|
520
|
+
additionalAttributes.edit = isNewsletter ? '3' : '1';
|
|
521
|
+
}
|
|
522
|
+
else if (isPinMsg) {
|
|
523
|
+
additionalAttributes.edit = '2';
|
|
524
|
+
}
|
|
525
|
+
else if (isPollMsg) {
|
|
526
|
+
if (!isNewsletter && isQuizMsg) {
|
|
527
|
+
throw new index_js_2.HttpError('Quiz are only allowed for newsletter', { statusCode: 400 });
|
|
528
|
+
}
|
|
529
|
+
additionalNodes.push({
|
|
530
|
+
tag: 'meta',
|
|
531
|
+
attrs: {
|
|
532
|
+
// Kage: nota de compatibilidad.
|
|
533
|
+
polltype: isQuizMsg ? 'quiz_creation' : 'creation',
|
|
534
|
+
contenttype: isPollMsg && isNewsletter ? 'text' : undefined
|
|
535
|
+
},
|
|
536
|
+
content: undefined
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
else if (isEventMsg) {
|
|
540
|
+
additionalNodes.push({
|
|
541
|
+
tag: 'meta',
|
|
542
|
+
attrs: {
|
|
543
|
+
event_type: 'creation'
|
|
544
|
+
},
|
|
545
|
+
content: undefined
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
// Kage: actualización de compatibilidad.
|
|
549
|
+
else if (isAiMsg) {
|
|
550
|
+
if (!((0, index_js_6.isPnUser)(jid) || (0, index_js_6.isLidUser)(jid))) {
|
|
551
|
+
throw new index_js_2.HttpError('AI icon on message are only allowed in private chat', { statusCode: 400 });
|
|
552
|
+
}
|
|
553
|
+
if ('messageContextInfo' in fullMsg.message && !!fullMsg.message.messageContextInfo) {
|
|
554
|
+
fullMsg.message.messageContextInfo.supportPayload = index_js_3.BIZ_BOT_SUPPORT_PAYLOAD;
|
|
555
|
+
}
|
|
556
|
+
;
|
|
557
|
+
additionalNodes.push({
|
|
558
|
+
tag: 'bot',
|
|
559
|
+
attrs: {
|
|
560
|
+
biz_bot: '1'
|
|
561
|
+
},
|
|
562
|
+
content: undefined
|
|
563
|
+
});
|
|
564
|
+
delete content.ai;
|
|
565
|
+
}
|
|
566
|
+
await relayMessage(jid, fullMsg.message, {
|
|
567
|
+
messageId: fullMsg.key.id,
|
|
568
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
569
|
+
addBizAttributes: isNeedBizAttrs,
|
|
570
|
+
statusJidList: options.statusJidList,
|
|
571
|
+
additionalAttributes,
|
|
572
|
+
additionalNodes
|
|
573
|
+
});
|
|
574
|
+
if (config.emitOwnEvents) {
|
|
575
|
+
process.nextTick(async () => {
|
|
576
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
// Kage: actualización de compatibilidad.
|
|
580
|
+
// Kage: nota de compatibilidad.
|
|
581
|
+
if ('album' in content) {
|
|
582
|
+
const { delayMs = 1500 } = options;
|
|
583
|
+
for (const albumMedia of content.album) {
|
|
584
|
+
const albumMsg = await (0, index_js_4.generateWAMessage)(jid, albumMedia, {
|
|
585
|
+
logger,
|
|
586
|
+
userJid,
|
|
587
|
+
upload: waUploadToServer,
|
|
588
|
+
mediaCache: config.mediaCache,
|
|
589
|
+
options: config.options,
|
|
590
|
+
...options,
|
|
591
|
+
messageId: (0, index_js_4.generateMessageIDV2)(userJid)
|
|
592
|
+
});
|
|
593
|
+
if (!(0, index_js_4.hasValidAlbumMedia)((0, index_js_4.normalizeMessageContent)(albumMsg.message))) {
|
|
594
|
+
throw new index_js_2.HttpError('Invalid message type for album', { statusCode: 400 });
|
|
595
|
+
}
|
|
596
|
+
(_a = albumMsg.message).messageContextInfo || (_a.messageContextInfo = {});
|
|
597
|
+
albumMsg.message.messageContextInfo.messageAssociation = {
|
|
598
|
+
parentMessageKey: fullMsg.key,
|
|
599
|
+
associationType: index_js_5.AssociationType.MEDIA_ALBUM
|
|
600
|
+
};
|
|
601
|
+
await relayMessage(jid, albumMsg.message, {
|
|
602
|
+
messageId: albumMsg.key.id,
|
|
603
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
604
|
+
addBizAttributes: isNeedBizAttrs,
|
|
605
|
+
statusJidList: options.statusJidList,
|
|
606
|
+
additionalAttributes,
|
|
607
|
+
additionalNodes
|
|
608
|
+
});
|
|
609
|
+
if (config.emitOwnEvents) {
|
|
610
|
+
process.nextTick(async () => {
|
|
611
|
+
await messageMutex.mutex(() => upsertMessage(albumMsg, 'append'));
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
await (0, index_js_4.delay)(delayMs);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return fullMsg;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
exports.attachAdvanced = attachAdvanced;
|