@codexverified/baileys 2.7.5
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 +233 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8051 -0
- package/WAProto/index.js +289292 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/index.js +158 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.js +428 -0
- package/lib/Signal/lid-mapping.js +280 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/aigroups.js +315 -0
- package/lib/Socket/business.js +407 -0
- package/lib/Socket/chats.js +1831 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/graphql.js +899 -0
- package/lib/Socket/groups.js +549 -0
- package/lib/Socket/index.js +79 -0
- package/lib/Socket/interactive-handler.js +600 -0
- package/lib/Socket/interop.js +563 -0
- package/lib/Socket/managed-account.js +208 -0
- package/lib/Socket/messages-recv.js +2144 -0
- package/lib/Socket/messages-send.js +2030 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +226 -0
- package/lib/Socket/privacy.js +446 -0
- package/lib/Socket/registration.js +428 -0
- package/lib/Socket/socket.js +1017 -0
- package/lib/Socket/username.js +229 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-cache-manager-store.js +89 -0
- package/lib/Store/make-in-memory-store.js +420 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +48 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.js +301 -0
- package/lib/Utils/bot-planning-replay.js +169 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.js +885 -0
- package/lib/Utils/companion-reg-client-utils.js +32 -0
- package/lib/Utils/consumer-application.js +102 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.js +484 -0
- package/lib/Utils/event-buffer.js +589 -0
- package/lib/Utils/generics.js +388 -0
- package/lib/Utils/group-history.js +56 -0
- package/lib/Utils/history.js +130 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +34 -0
- package/lib/Utils/jid-display-normalization.js +209 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-composer.js +467 -0
- package/lib/Utils/message-inspect.js +67 -0
- package/lib/Utils/message-retry-manager.js +241 -0
- package/lib/Utils/messages-media.js +1006 -0
- package/lib/Utils/messages.js +1851 -0
- package/lib/Utils/meta-ai-msmsg.js +130 -0
- package/lib/Utils/meta-compositing.js +194 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +527 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.js +439 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.js +120 -0
- package/lib/Utils/use-single-file-auth-state.js +96 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.js +206 -0
- package/lib/Utils/voip-rekey.js +20 -0
- package/lib/Utils/welcome-flow.js +217 -0
- package/lib/WABinary/constants.js +1463 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.js +227 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +201 -0
- package/lib/WAUSync/USyncUser.js +54 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +286 -0
- package/lib/index.js +18 -0
- package/package.json +121 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { generateMessageIDV2 } from './generics.js';
|
|
3
|
+
|
|
4
|
+
// NOTE: tokenizeCode / CodeHighlightType / RichSubMessageType are intentionally
|
|
5
|
+
// kept module-local here @codexverified/baileys already exports these from
|
|
6
|
+
// lib/Utils/rich-message-utils.js and lib/Types/RichType.js. The baron composer
|
|
7
|
+
// implementation is preserved internally so the generator helpers stay faithful.
|
|
8
|
+
|
|
9
|
+
const JS_KEYWORDS = new Set([
|
|
10
|
+
'import',
|
|
11
|
+
'export',
|
|
12
|
+
'from',
|
|
13
|
+
'default',
|
|
14
|
+
'as',
|
|
15
|
+
'const',
|
|
16
|
+
'let',
|
|
17
|
+
'var',
|
|
18
|
+
'function',
|
|
19
|
+
'class',
|
|
20
|
+
'extends',
|
|
21
|
+
'new',
|
|
22
|
+
'return',
|
|
23
|
+
'if',
|
|
24
|
+
'else',
|
|
25
|
+
'for',
|
|
26
|
+
'while',
|
|
27
|
+
'do',
|
|
28
|
+
'switch',
|
|
29
|
+
'case',
|
|
30
|
+
'break',
|
|
31
|
+
'continue',
|
|
32
|
+
'try',
|
|
33
|
+
'catch',
|
|
34
|
+
'finally',
|
|
35
|
+
'throw',
|
|
36
|
+
'async',
|
|
37
|
+
'await',
|
|
38
|
+
'yield',
|
|
39
|
+
'typeof',
|
|
40
|
+
'instanceof',
|
|
41
|
+
'in',
|
|
42
|
+
'of',
|
|
43
|
+
'delete',
|
|
44
|
+
'void',
|
|
45
|
+
'true',
|
|
46
|
+
'false',
|
|
47
|
+
'null',
|
|
48
|
+
'undefined',
|
|
49
|
+
'NaN',
|
|
50
|
+
'Infinity',
|
|
51
|
+
'this',
|
|
52
|
+
'super',
|
|
53
|
+
'static',
|
|
54
|
+
'get',
|
|
55
|
+
'set',
|
|
56
|
+
'debugger',
|
|
57
|
+
'with'
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const PYTHON_KEYWORDS = new Set([
|
|
61
|
+
'import',
|
|
62
|
+
'from',
|
|
63
|
+
'as',
|
|
64
|
+
'def',
|
|
65
|
+
'class',
|
|
66
|
+
'return',
|
|
67
|
+
'if',
|
|
68
|
+
'elif',
|
|
69
|
+
'else',
|
|
70
|
+
'for',
|
|
71
|
+
'while',
|
|
72
|
+
'break',
|
|
73
|
+
'continue',
|
|
74
|
+
'try',
|
|
75
|
+
'except',
|
|
76
|
+
'finally',
|
|
77
|
+
'raise',
|
|
78
|
+
'with',
|
|
79
|
+
'yield',
|
|
80
|
+
'lambda',
|
|
81
|
+
'pass',
|
|
82
|
+
'del',
|
|
83
|
+
'global',
|
|
84
|
+
'nonlocal',
|
|
85
|
+
'assert',
|
|
86
|
+
'True',
|
|
87
|
+
'False',
|
|
88
|
+
'None',
|
|
89
|
+
'and',
|
|
90
|
+
'or',
|
|
91
|
+
'not',
|
|
92
|
+
'in',
|
|
93
|
+
'is',
|
|
94
|
+
'async',
|
|
95
|
+
'await',
|
|
96
|
+
'self',
|
|
97
|
+
'print'
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
const LANGUAGE_KEYWORDS = {
|
|
101
|
+
javascript: JS_KEYWORDS,
|
|
102
|
+
typescript: JS_KEYWORDS,
|
|
103
|
+
js: JS_KEYWORDS,
|
|
104
|
+
ts: JS_KEYWORDS,
|
|
105
|
+
python: PYTHON_KEYWORDS,
|
|
106
|
+
py: PYTHON_KEYWORDS
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const CodeHighlightType = {
|
|
110
|
+
DEFAULT: 0,
|
|
111
|
+
KEYWORD: 1,
|
|
112
|
+
METHOD: 2,
|
|
113
|
+
STRING: 3,
|
|
114
|
+
NUMBER: 4,
|
|
115
|
+
COMMENT: 5
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const RichSubMessageType = {
|
|
119
|
+
UNKNOWN: 0,
|
|
120
|
+
GRID_IMAGE: 1,
|
|
121
|
+
TEXT: 2,
|
|
122
|
+
INLINE_IMAGE: 3,
|
|
123
|
+
TABLE: 4,
|
|
124
|
+
CODE: 5,
|
|
125
|
+
DYNAMIC: 6,
|
|
126
|
+
MAP: 7,
|
|
127
|
+
LATEX: 8,
|
|
128
|
+
CONTENT_ITEMS: 9
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const tokenizeCode = (codeStr, language = 'javascript') => {
|
|
132
|
+
const keywords = LANGUAGE_KEYWORDS[language] || JS_KEYWORDS;
|
|
133
|
+
const blocks = [];
|
|
134
|
+
const lines = codeStr.split('\n');
|
|
135
|
+
for (let li = 0; li < lines.length; li++) {
|
|
136
|
+
const line = lines[li];
|
|
137
|
+
const isLast = li === lines.length - 1;
|
|
138
|
+
const nl = isLast ? '' : '\n';
|
|
139
|
+
if (!line.trim()) {
|
|
140
|
+
blocks.push({
|
|
141
|
+
highlightType: CodeHighlightType.DEFAULT,
|
|
142
|
+
codeContent: line + nl
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (line.trim().startsWith('//') || line.trim().startsWith('#')) {
|
|
147
|
+
blocks.push({
|
|
148
|
+
highlightType: CodeHighlightType.COMMENT,
|
|
149
|
+
codeContent: line + nl
|
|
150
|
+
});
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const regex =
|
|
154
|
+
/(\/\/.*$|#.*$)|(["'`](?:[^"'`\\]|\\.)*["'`])|(\b\d+(?:\.\d+)?\b)|(\b[a-zA-Z_$][\w$]*\b)|([^\s\w$"'`]+)|(\s+)/g;
|
|
155
|
+
let match;
|
|
156
|
+
const tokens = [];
|
|
157
|
+
while ((match = regex.exec(line)) !== null) {
|
|
158
|
+
const val = match[0];
|
|
159
|
+
if (match[1]) {
|
|
160
|
+
tokens.push({
|
|
161
|
+
highlightType: CodeHighlightType.COMMENT,
|
|
162
|
+
codeContent: val
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else if (match[2]) {
|
|
166
|
+
tokens.push({
|
|
167
|
+
highlightType: CodeHighlightType.STRING,
|
|
168
|
+
codeContent: val
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else if (match[3]) {
|
|
172
|
+
tokens.push({
|
|
173
|
+
highlightType: CodeHighlightType.NUMBER,
|
|
174
|
+
codeContent: val
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
else if (match[4]) {
|
|
178
|
+
if (keywords.has(val)) {
|
|
179
|
+
tokens.push({
|
|
180
|
+
highlightType: CodeHighlightType.KEYWORD,
|
|
181
|
+
codeContent: val
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const after = line.slice(regex.lastIndex).trimStart();
|
|
186
|
+
if (after.startsWith('(')) {
|
|
187
|
+
tokens.push({
|
|
188
|
+
highlightType: CodeHighlightType.METHOD,
|
|
189
|
+
codeContent: val
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
tokens.push({
|
|
194
|
+
highlightType: CodeHighlightType.DEFAULT,
|
|
195
|
+
codeContent: val
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
tokens.push({
|
|
202
|
+
highlightType: CodeHighlightType.DEFAULT,
|
|
203
|
+
codeContent: val
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (tokens.length === 0) {
|
|
208
|
+
blocks.push({
|
|
209
|
+
highlightType: CodeHighlightType.DEFAULT,
|
|
210
|
+
codeContent: line + nl
|
|
211
|
+
});
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const merged = [];
|
|
215
|
+
for (const t of tokens) {
|
|
216
|
+
const prev = merged.length > 0 ? merged[merged.length - 1] : undefined;
|
|
217
|
+
if (prev && prev.highlightType === t.highlightType) {
|
|
218
|
+
prev.codeContent += t.codeContent;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
merged.push({ ...t });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (merged.length > 0) {
|
|
225
|
+
merged[merged.length - 1].codeContent += nl;
|
|
226
|
+
}
|
|
227
|
+
blocks.push(...merged);
|
|
228
|
+
}
|
|
229
|
+
return blocks;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const buildRichContextInfo = (quoted, options = {}) => {
|
|
233
|
+
const ctxInfo = {
|
|
234
|
+
forwardingScore: 1,
|
|
235
|
+
isForwarded: true,
|
|
236
|
+
forwardedAiBotMessageInfo: { botJid: options.botJid ? options.botJid : '867051314767696@bot' },
|
|
237
|
+
forwardOrigin: 4,
|
|
238
|
+
...(options.mentions ? { mentionedJid: options.mentions } : {})
|
|
239
|
+
};
|
|
240
|
+
if (quoted?.key) {
|
|
241
|
+
ctxInfo.stanzaId = quoted.key.id;
|
|
242
|
+
ctxInfo.participant = quoted.key.participant || quoted.sender || quoted.key.remoteJid;
|
|
243
|
+
ctxInfo.quotedMessage = quoted.message;
|
|
244
|
+
}
|
|
245
|
+
return ctxInfo;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const buildBotForwardedMessage = (submessages, contextInfo, unifiedResponse) => {
|
|
249
|
+
const richResponse = {
|
|
250
|
+
messageType: 1,
|
|
251
|
+
submessages,
|
|
252
|
+
contextInfo
|
|
253
|
+
};
|
|
254
|
+
if (unifiedResponse) {
|
|
255
|
+
richResponse.unifiedResponse = unifiedResponse;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
botForwardedMessage: {
|
|
259
|
+
message: {
|
|
260
|
+
richResponseMessage: richResponse
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export const generateTableContent = (title, headers, rows, quoted, options = {}) => {
|
|
267
|
+
const { footer, headerText } = options;
|
|
268
|
+
const tableRows = [{ items: headers, isHeading: true }, ...rows.map(row => ({ items: row.map(String) }))];
|
|
269
|
+
const submessages = [];
|
|
270
|
+
if (headerText) {
|
|
271
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
272
|
+
}
|
|
273
|
+
submessages.push({
|
|
274
|
+
messageType: 4,
|
|
275
|
+
tableMetadata: { title, rows: tableRows }
|
|
276
|
+
});
|
|
277
|
+
if (footer) {
|
|
278
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
279
|
+
}
|
|
280
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
281
|
+
return {
|
|
282
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
283
|
+
messageId: generateMessageIDV2()
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export const generateListContent = (title, items, quoted, options = {}) => {
|
|
288
|
+
const { footer, headerText } = options;
|
|
289
|
+
const tableRows = items.map(item => ({
|
|
290
|
+
items: Array.isArray(item) ? item.map(String) : [String(item)]
|
|
291
|
+
}));
|
|
292
|
+
const submessages = [];
|
|
293
|
+
if (headerText) {
|
|
294
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
295
|
+
}
|
|
296
|
+
submessages.push({
|
|
297
|
+
messageType: 4,
|
|
298
|
+
tableMetadata: { title, rows: tableRows }
|
|
299
|
+
});
|
|
300
|
+
if (footer) {
|
|
301
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
302
|
+
}
|
|
303
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
304
|
+
return {
|
|
305
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
306
|
+
messageId: generateMessageIDV2()
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export const generateCodeBlockContent = (code, quoted, options = {}) => {
|
|
311
|
+
const { title, footer, language = 'javascript' } = options;
|
|
312
|
+
const submessages = [];
|
|
313
|
+
if (title) {
|
|
314
|
+
submessages.push({ messageType: 2, messageText: title });
|
|
315
|
+
}
|
|
316
|
+
submessages.push({
|
|
317
|
+
messageType: 5,
|
|
318
|
+
codeMetadata: {
|
|
319
|
+
codeLanguage: language,
|
|
320
|
+
codeBlocks: tokenizeCode(code, language)
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
if (footer) {
|
|
324
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
325
|
+
}
|
|
326
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
327
|
+
return {
|
|
328
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
329
|
+
messageId: generateMessageIDV2()
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
export const generateLatexContent = (quoted, options) => {
|
|
334
|
+
const { text, expressions, headerText, footer } = options;
|
|
335
|
+
const submessages = [];
|
|
336
|
+
if (headerText) {
|
|
337
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
338
|
+
}
|
|
339
|
+
const latexExpressions = expressions.map(expr => {
|
|
340
|
+
const entry = {
|
|
341
|
+
latexExpression: expr.latexExpression,
|
|
342
|
+
url: expr.url,
|
|
343
|
+
width: expr.width,
|
|
344
|
+
height: expr.height
|
|
345
|
+
};
|
|
346
|
+
if (expr.fontHeight !== undefined) entry.fontHeight = expr.fontHeight;
|
|
347
|
+
if (expr.imageTopPadding !== undefined) entry.imageTopPadding = expr.imageTopPadding;
|
|
348
|
+
if (expr.imageLeadingPadding !== undefined) entry.imageLeadingPadding = expr.imageLeadingPadding;
|
|
349
|
+
if (expr.imageBottomPadding !== undefined) entry.imageBottomPadding = expr.imageBottomPadding;
|
|
350
|
+
if (expr.imageTrailingPadding !== undefined) entry.imageTrailingPadding = expr.imageTrailingPadding;
|
|
351
|
+
return entry;
|
|
352
|
+
});
|
|
353
|
+
submessages.push({
|
|
354
|
+
messageType: 8,
|
|
355
|
+
latexMetadata: {
|
|
356
|
+
text: text || '',
|
|
357
|
+
expressions: latexExpressions
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
if (footer) {
|
|
361
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
362
|
+
}
|
|
363
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
364
|
+
return {
|
|
365
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
366
|
+
messageId: generateMessageIDV2()
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
export const generateLatexImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
371
|
+
const { text, expressions, headerText, footer } = options;
|
|
372
|
+
const submessages = [];
|
|
373
|
+
if (headerText) {
|
|
374
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
375
|
+
}
|
|
376
|
+
const latexExpressions = await Promise.all(
|
|
377
|
+
expressions.map(async expr => {
|
|
378
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
|
|
379
|
+
const uploadResult = await uploadFn(buffer, 'image');
|
|
380
|
+
const imageUrl = uploadResult.url || uploadResult.directPath;
|
|
381
|
+
return {
|
|
382
|
+
latexExpression: expr.latexExpression,
|
|
383
|
+
url: imageUrl,
|
|
384
|
+
width,
|
|
385
|
+
height
|
|
386
|
+
};
|
|
387
|
+
})
|
|
388
|
+
);
|
|
389
|
+
submessages.push({
|
|
390
|
+
messageType: 8,
|
|
391
|
+
latexMetadata: {
|
|
392
|
+
text: text || '',
|
|
393
|
+
expressions: latexExpressions
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
if (footer) {
|
|
397
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
398
|
+
}
|
|
399
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
400
|
+
return {
|
|
401
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
402
|
+
messageId: generateMessageIDV2()
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
export const generateLatexInlineImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
407
|
+
const { text, expressions, headerText, footer } = options;
|
|
408
|
+
const submessages = [];
|
|
409
|
+
if (headerText) {
|
|
410
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
411
|
+
}
|
|
412
|
+
if (text) {
|
|
413
|
+
submessages.push({ messageType: 2, messageText: text });
|
|
414
|
+
}
|
|
415
|
+
for (const expr of expressions) {
|
|
416
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
|
|
417
|
+
const uploadResult = await uploadFn(buffer, 'image');
|
|
418
|
+
const imageUrl = uploadResult.url || uploadResult.directPath;
|
|
419
|
+
submessages.push({
|
|
420
|
+
messageType: 3,
|
|
421
|
+
imageMetadata: {
|
|
422
|
+
imageUrl: {
|
|
423
|
+
imagePreviewUrl: imageUrl,
|
|
424
|
+
imageHighResUrl: imageUrl
|
|
425
|
+
},
|
|
426
|
+
imageText: expr.latexExpression,
|
|
427
|
+
alignment: 2
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
if (footer) {
|
|
432
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
433
|
+
}
|
|
434
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
435
|
+
return {
|
|
436
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
437
|
+
messageId: generateMessageIDV2()
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
export const captureUnifiedResponse = (msg) => {
|
|
442
|
+
const botFwd = msg?.botForwardedMessage?.message;
|
|
443
|
+
if (!botFwd) return null;
|
|
444
|
+
const rich = botFwd.richResponseMessage;
|
|
445
|
+
if (!rich?.unifiedResponse?.data) return null;
|
|
446
|
+
return {
|
|
447
|
+
unifiedResponse: { data: rich.unifiedResponse.data },
|
|
448
|
+
submessages: rich.submessages || [],
|
|
449
|
+
contextInfo: rich.contextInfo || {}
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
export const generateUnifiedResponseContent = (quoted, captured) => {
|
|
454
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
455
|
+
return {
|
|
456
|
+
message: buildBotForwardedMessage(captured.submessages, ctxInfo, captured.unifiedResponse),
|
|
457
|
+
messageId: generateMessageIDV2()
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
export const generateRichMessageContent = (submessages, quoted, options) => {
|
|
462
|
+
const ctxInfo = buildRichContextInfo(quoted, options);
|
|
463
|
+
return {
|
|
464
|
+
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
465
|
+
messageId: generateMessageIDV2()
|
|
466
|
+
};
|
|
467
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { isLidUser, jidEncode } from '../WABinary/index.js';
|
|
3
|
+
|
|
4
|
+
// Message inspection helpers
|
|
5
|
+
// Ported from baron-baileys-v2 Utils/message-inspect.js. Only the helpers that
|
|
6
|
+
// were not already present in lib/Utils/messages.js are exported here the
|
|
7
|
+
// shared ones (getContentType, normalizeMessageContent, extractMessageContent,
|
|
8
|
+
// downloadMediaMessage, assertMediaContent, getDevice, ) live in messages.js.
|
|
9
|
+
|
|
10
|
+
/** Check if a WebMessageInfo has a scheduled reveal time (ConditionalRevealMessage) */
|
|
11
|
+
export const isScheduledMessage = (msg) => !!msg?.scheduledMessageMetadata?.scheduledTime;
|
|
12
|
+
|
|
13
|
+
/** Get scheduled reveal time of a message as a Date, or null */
|
|
14
|
+
export const getScheduledMessageTime = (msg) => {
|
|
15
|
+
const t = msg?.scheduledMessageMetadata?.scheduledTime;
|
|
16
|
+
if (!t) return null;
|
|
17
|
+
return new Date(Number(t) * 1000);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Extract PaymentInfo from a WebMessageInfo (the payment status field, not the message content) */
|
|
21
|
+
export const getMessagePaymentInfo = (msg) => msg?.paymentInfo || msg?.quotedPaymentInfo || null;
|
|
22
|
+
|
|
23
|
+
/** Get all comment metadata from a WebMessageInfo */
|
|
24
|
+
export const getMessageCommentMetadata = (msg) => msg?.commentMetadata || null;
|
|
25
|
+
|
|
26
|
+
/** Get all message add-ons (reactions, poll updates, pins) from a WebMessageInfo */
|
|
27
|
+
export const getMessageAddOns = (msg) => msg?.messageAddOns || [];
|
|
28
|
+
|
|
29
|
+
/** Get the quiz correct answer from a poll creation message, if it's a quiz */
|
|
30
|
+
export const getPollCorrectAnswer = (pollMsg) => {
|
|
31
|
+
const poll =
|
|
32
|
+
pollMsg?.pollCreationMessage ||
|
|
33
|
+
pollMsg?.pollCreationMessageV2 ||
|
|
34
|
+
pollMsg?.pollCreationMessageV3 ||
|
|
35
|
+
pollMsg?.pollCreationMessageV5 ||
|
|
36
|
+
pollMsg?.pollCreationMessageV6;
|
|
37
|
+
if (!poll) return null;
|
|
38
|
+
const isQuiz = poll.pollType === proto.Message.PollType?.QUIZ || poll.pollType === 1;
|
|
39
|
+
return isQuiz ? poll.correctAnswer?.optionName || null : null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Normalizes a bare user id to @s.whatsapp.net. Does not convert LIDPN; use lidMapping / PN in key.remoteJidAlt when needed. */
|
|
43
|
+
export const toJid = (id) => {
|
|
44
|
+
if (!id) return '';
|
|
45
|
+
if (id.includes('@')) return id;
|
|
46
|
+
return `${id}@s.whatsapp.net`;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Returns the peer LID JID when the key is LID-primary (decode sets remoteJid/participant to @lid when WA sends LID). */
|
|
50
|
+
export const getSenderLid = (message) => {
|
|
51
|
+
const k = message.key;
|
|
52
|
+
if (!k) {
|
|
53
|
+
return { jid: '', lid: '' };
|
|
54
|
+
}
|
|
55
|
+
const jid = k.participant || k.remoteJid || '';
|
|
56
|
+
if (jid.endsWith('@lid') || jid.endsWith('@hosted.lid')) {
|
|
57
|
+
return { jid, lid: jid };
|
|
58
|
+
}
|
|
59
|
+
if (k.lid && typeof k.lid === 'string') {
|
|
60
|
+
const lid = k.lid.includes('@') ? k.lid : jidEncode(k.lid, 'lid');
|
|
61
|
+
return { jid, lid };
|
|
62
|
+
}
|
|
63
|
+
if (k.participantLid && isLidUser(k.participantLid)) {
|
|
64
|
+
return { jid, lid: k.participantLid };
|
|
65
|
+
}
|
|
66
|
+
return { jid, lid: '' };
|
|
67
|
+
};
|