@itsliaaa/baileys 0.1.22 → 0.1.24
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/README.md +7 -5
- package/lib/Defaults/index.js +3 -5
- package/lib/Socket/messages-send.js +6 -5
- package/lib/Utils/messages.js +9 -15
- package/lib/Utils/rich-message-utils.js +270 -179
- package/lib/WABinary/constants.js +73 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -453,10 +453,11 @@ sock.sendMessage(jid, {
|
|
|
453
453
|
|
|
454
454
|
```javascript
|
|
455
455
|
sock.sendMessage(jid, {
|
|
456
|
-
|
|
456
|
+
headerText: '## Example Usage',
|
|
457
|
+
contentText: '---'
|
|
457
458
|
code: 'console.log("Hello, World!")',
|
|
458
|
-
|
|
459
|
-
|
|
459
|
+
language: 'javascript',
|
|
460
|
+
footerText: 'Pretty simple, right?'
|
|
460
461
|
})
|
|
461
462
|
```
|
|
462
463
|
|
|
@@ -464,14 +465,15 @@ sock.sendMessage(jid, {
|
|
|
464
465
|
|
|
465
466
|
```javascript
|
|
466
467
|
sock.sendMessage(jid, {
|
|
467
|
-
|
|
468
|
+
headerText: '## Comparison between Node.js, Bun, and Deno',
|
|
469
|
+
contentText: '---',
|
|
468
470
|
title: 'Runtime Comparison',
|
|
469
471
|
table: [
|
|
470
472
|
['', 'Node.js', 'Bun', 'Deno'],
|
|
471
473
|
['Engine', 'V8 (C++)', 'JavaScriptCore (C++)', 'V8 (C++)'],
|
|
472
474
|
['Performance', '4/5', '5/5', '4/5']
|
|
473
475
|
],
|
|
474
|
-
|
|
476
|
+
footerText: 'Does this help clarify the differences?'
|
|
475
477
|
})
|
|
476
478
|
```
|
|
477
479
|
|
package/lib/Defaults/index.js
CHANGED
|
@@ -142,9 +142,7 @@ export const TimeMs = {
|
|
|
142
142
|
Day: 24 * 60 * 60 * 1000,
|
|
143
143
|
Week: 7 * 24 * 60 * 60 * 1000
|
|
144
144
|
};
|
|
145
|
-
export const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
|
|
149
|
-
forwardOrigin: 4
|
|
145
|
+
export const BOT_RENDERING_CONFIG_METADATA = {
|
|
146
|
+
bloksVersioningId: '0903aa5f7f47de66789d5f4c86d3bd6e05e4bc3ff85e454a9f907d5ed7fef97c',
|
|
147
|
+
pixelDensity: 2.75
|
|
150
148
|
};
|
|
@@ -481,9 +481,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
481
481
|
extraAttrs['mediatype'] = mediaType;
|
|
482
482
|
}
|
|
483
483
|
if (isNewsletter) {
|
|
484
|
-
if (innerMessage.productMessage) {
|
|
485
|
-
extraAttrs['mediatype'] = 'image'; // Lia@Note 02-02-26 --- Treat product message as image message to avoid the "479" error (✷‿✷)
|
|
486
|
-
}
|
|
487
484
|
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
488
485
|
const bytes = encodeNewsletterMessage(patched);
|
|
489
486
|
// Lia@Changes 08-02-26 --- Add "additionalNodes" for newsletter too (っ˘̩╭╮˘̩)っ
|
|
@@ -819,7 +816,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
819
816
|
stanza.content.push(...additionalNodes);
|
|
820
817
|
}
|
|
821
818
|
// Lia@Changes 30-01-26 --- Add Biz Binary Node to support button messages
|
|
822
|
-
|
|
819
|
+
let alreadyHasBizNode = false;
|
|
820
|
+
if (!addBizAttributes) {
|
|
821
|
+
alreadyHasBizNode = additionalNodes.some(node => node.tag === 'biz');
|
|
822
|
+
}
|
|
823
|
+
if ((!alreadyHasBizNode && shouldIncludeBizBinaryNode(innerMessage)) || addBizAttributes) {
|
|
823
824
|
const bizNode = getBizBinaryNode(innerMessage, addBizAttributes);
|
|
824
825
|
stanza.content.push(bizNode);
|
|
825
826
|
}
|
|
@@ -1196,7 +1197,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1196
1197
|
// Lia@Changes 30-01-26 --- Add support for AI label in message when "ai" is true, but works only in private chat
|
|
1197
1198
|
else if (isAiMsg) {
|
|
1198
1199
|
if (!(isPnUser(jid) || isLidUser(jid))) {
|
|
1199
|
-
throw new Boom('AI
|
|
1200
|
+
throw new Boom('AI icon on message are only allowed in private chat', { statusCode: 400 });
|
|
1200
1201
|
}
|
|
1201
1202
|
if ('messageContextInfo' in fullMsg.message && !!fullMsg.message.messageContextInfo) {
|
|
1202
1203
|
fullMsg.message.messageContextInfo.supportPayload = BIZ_BOT_SUPPORT_PAYLOAD;
|
package/lib/Utils/messages.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isPnUser, isLidUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast,
|
|
|
10
10
|
import { sha256 } from './crypto.js';
|
|
11
11
|
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
12
12
|
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getImageProcessingLibrary, getRawMediaUploadData, getStream, toBuffer } from './messages-media.js';
|
|
13
|
-
import {
|
|
13
|
+
import { prepareRichResponseMessage } from './rich-message-utils.js';
|
|
14
14
|
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
15
15
|
const MIMETYPE_MAP = {
|
|
16
16
|
image: 'image/jpeg',
|
|
@@ -695,6 +695,14 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
695
695
|
delete message.raw;
|
|
696
696
|
return message;
|
|
697
697
|
}
|
|
698
|
+
// Lia@Changes 09-04-26 --- Add support for code block, latex, reels carousel, table with richResponseMessage
|
|
699
|
+
else if (hasNonNullishProperty(message, 'code') ||
|
|
700
|
+
hasNonNullishProperty(message, 'expressions') ||
|
|
701
|
+
hasNonNullishProperty(message, 'items') ||
|
|
702
|
+
hasNonNullishProperty(message, 'table') ||
|
|
703
|
+
hasNonNullishProperty(message, 'richResponse')) {
|
|
704
|
+
m = prepareRichResponseMessage(message);
|
|
705
|
+
}
|
|
698
706
|
else if (hasNonNullishProperty(message, 'text')) {
|
|
699
707
|
const extContent = { text: message.text };
|
|
700
708
|
let urlInfo = message.linkPreview;
|
|
@@ -1018,16 +1026,6 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1018
1026
|
expectedVideoCount: videoCount
|
|
1019
1027
|
};
|
|
1020
1028
|
}
|
|
1021
|
-
// Lia@Changes 09-04-26 --- Add support for code block and table
|
|
1022
|
-
else if (hasNonNullishProperty(message, 'code')) {
|
|
1023
|
-
m.richResponseMessage = prepareRichCodeBlock(message);
|
|
1024
|
-
}
|
|
1025
|
-
else if (hasNonNullishProperty(message, 'table')) {
|
|
1026
|
-
m.richResponseMessage = prepareRichTable(message);
|
|
1027
|
-
}
|
|
1028
|
-
else if (hasNonNullishProperty(message, 'richResponse')) {
|
|
1029
|
-
m.richResponseMessage = prepareRichResponseMessage(message.richResponse);
|
|
1030
|
-
}
|
|
1031
1029
|
else {
|
|
1032
1030
|
m = await prepareWAMessageMedia(message, options);
|
|
1033
1031
|
}
|
|
@@ -1419,10 +1417,6 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1419
1417
|
m = { viewOnceMessageV2Extension: { message: m } };
|
|
1420
1418
|
delete message.viewOnceV2Extension;
|
|
1421
1419
|
}
|
|
1422
|
-
// Lia@Note 09-04-26 --- Wrap richResponseMessage into botForwardedMessage
|
|
1423
|
-
if (!!m.richResponseMessage) {
|
|
1424
|
-
m = wrapToBotForwardedMessage(m)
|
|
1425
|
-
}
|
|
1426
1420
|
if (hasOptionalProperty(message, 'edit')) {
|
|
1427
1421
|
m = {
|
|
1428
1422
|
protocolMessage: {
|
|
@@ -4,83 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* If you use or copy this code, please credit my name or project.
|
|
6
6
|
*/
|
|
7
|
-
import { randomUUID } from 'crypto';
|
|
8
|
-
import {
|
|
7
|
+
import { getRandomValues, randomUUID, randomBytes } from 'crypto';
|
|
8
|
+
import { BOT_RENDERING_CONFIG_METADATA, LEXER_REGEX } from '../Defaults/index.js';
|
|
9
|
+
import { LANGUAGE_KEYWORDS } from '../WABinary/constants.js';
|
|
9
10
|
import { CodeHighlightType, RichSubMessageType } from '../Types/RichType.js';
|
|
11
|
+
import { proto } from '../../WAProto/index.js';
|
|
12
|
+
import { unixTimestampSeconds } from './generics.js';
|
|
10
13
|
const textEncoder = new TextEncoder();
|
|
11
|
-
const CPP_KEYWORDS = new Set([
|
|
12
|
-
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor', 'bool', 'break', 'case',
|
|
13
|
-
'catch', 'char', 'class', 'compl', 'concept', 'const', 'consteval', 'constexpr', 'constinit',
|
|
14
|
-
'const_cast', 'continue', 'co_await', 'co_return', 'co_yield', 'decltype', 'default', 'delete',
|
|
15
|
-
'do', 'double', 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'false', 'float',
|
|
16
|
-
'for', 'friend', 'goto', 'if', 'inline', 'int', 'long', 'mutable', 'namespace', 'new', 'noexcept',
|
|
17
|
-
'not', 'not_eq', 'nullptr', 'operator', 'or', 'or_eq', 'private', 'protected', 'public', 'register',
|
|
18
|
-
'reinterpret_cast', 'requires', 'return', 'short', 'signed', 'sizeof', 'static', 'static_assert',
|
|
19
|
-
'static_cast', 'struct', 'switch', 'template', 'this', 'thread_local', 'throw', 'true', 'try',
|
|
20
|
-
'typedef', 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual', 'void', 'volatile',
|
|
21
|
-
'wchar_t', 'while', 'xor', 'xor_eq'
|
|
22
|
-
]);
|
|
23
|
-
const CSS_KEYWORDS = new Set([
|
|
24
|
-
'import', 'media', 'font-face', 'keyframes', 'supports', 'charset',
|
|
25
|
-
'important', 'root', 'hover', 'active', 'focus', 'visited', 'before', 'after',
|
|
26
|
-
'not', 'nth-child', 'first-child', 'last-child', 'only-child',
|
|
27
|
-
'none', 'inherit', 'initial', 'unset', 'auto', 'transparent', 'currentcolor'
|
|
28
|
-
]);
|
|
29
|
-
const GO_KEYWORDS = new Set([
|
|
30
|
-
'break', 'default', 'func', 'interface', 'select', 'case', 'defer', 'go', 'map', 'struct',
|
|
31
|
-
'chan', 'else', 'goto', 'package', 'switch', 'const', 'fallthrough', 'if', 'range', 'type',
|
|
32
|
-
'continue', 'for', 'import', 'return', 'var', 'true', 'false', 'nil'
|
|
33
|
-
]);
|
|
34
|
-
const HTML_KEYWORDS = new Set([
|
|
35
|
-
'html', 'head', 'body', 'title', 'meta', 'link', 'script', 'style',
|
|
36
|
-
'header', 'footer', 'main', 'section', 'article', 'aside', 'nav',
|
|
37
|
-
'div', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'a', 'img',
|
|
38
|
-
'ul', 'ol', 'li', 'table', 'tr', 'td', 'th', 'thead', 'tbody',
|
|
39
|
-
'form', 'input', 'button', 'select', 'textarea', 'label', 'option',
|
|
40
|
-
'canvas', 'svg', 'iframe', 'video', 'audio', 'source'
|
|
41
|
-
]);
|
|
42
|
-
const JS_KEYWORDS = new Set([
|
|
43
|
-
'import', 'export', 'from', 'default', 'as',
|
|
44
|
-
'const', 'let', 'var', 'function', 'class', 'extends', 'new',
|
|
45
|
-
'return', 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'break', 'continue',
|
|
46
|
-
'try', 'catch', 'finally', 'throw',
|
|
47
|
-
'async', 'await', 'yield',
|
|
48
|
-
'typeof', 'instanceof', 'in', 'of', 'delete', 'void',
|
|
49
|
-
'true', 'false', 'null', 'undefined', 'NaN', 'Infinity',
|
|
50
|
-
'this', 'super', 'static', 'get', 'set',
|
|
51
|
-
'debugger', 'with'
|
|
52
|
-
]);
|
|
53
|
-
const PYTHON_KEYWORDS = new Set([
|
|
54
|
-
'import', 'from', 'as', 'def', 'class', 'return', 'if', 'elif', 'else',
|
|
55
|
-
'for', 'while', 'break', 'continue', 'try', 'except', 'finally', 'raise',
|
|
56
|
-
'with', 'yield', 'lambda', 'pass', 'del', 'global', 'nonlocal', 'assert',
|
|
57
|
-
'True', 'False', 'None', 'and', 'or', 'not', 'in', 'is', 'async', 'await',
|
|
58
|
-
'self', 'print'
|
|
59
|
-
]);
|
|
60
|
-
const RUST_KEYWORDS = new Set([
|
|
61
|
-
'as', 'break', 'const', 'continue', 'crate', 'else', 'enum', 'extern', 'false', 'fn', 'for',
|
|
62
|
-
'if', 'impl', 'in', 'let', 'loop', 'match', 'mod', 'move', 'mut', 'pub', 'ref', 'return',
|
|
63
|
-
'self', 'Self', 'static', 'struct', 'super', 'trait', 'true', 'type', 'unsafe', 'use',
|
|
64
|
-
'where', 'while', 'async', 'await', 'dyn', 'abstract', 'become', 'box', 'do', 'final',
|
|
65
|
-
'macro', 'override', 'priv', 'typeof', 'unsized', 'virtual', 'yield'
|
|
66
|
-
]);
|
|
67
14
|
const NOOP = new Set([]);
|
|
68
|
-
export const LANGUAGE_KEYWORDS = {
|
|
69
|
-
css: CSS_KEYWORDS,
|
|
70
|
-
html: HTML_KEYWORDS,
|
|
71
|
-
javascript: JS_KEYWORDS,
|
|
72
|
-
typescript: JS_KEYWORDS,
|
|
73
|
-
js: JS_KEYWORDS,
|
|
74
|
-
ts: JS_KEYWORDS,
|
|
75
|
-
python: PYTHON_KEYWORDS,
|
|
76
|
-
py: PYTHON_KEYWORDS,
|
|
77
|
-
go: GO_KEYWORDS,
|
|
78
|
-
golang: GO_KEYWORDS,
|
|
79
|
-
cpp: CPP_KEYWORDS,
|
|
80
|
-
'c++': CPP_KEYWORDS,
|
|
81
|
-
rust: RUST_KEYWORDS,
|
|
82
|
-
rs: RUST_KEYWORDS,
|
|
83
|
-
};
|
|
84
15
|
export const tokenizeCode = (code, language = 'javascript') => {
|
|
85
16
|
const keywords = LANGUAGE_KEYWORDS[language] || NOOP;
|
|
86
17
|
const blocks = [];
|
|
@@ -115,160 +46,320 @@ export const tokenizeCode = (code, language = 'javascript') => {
|
|
|
115
46
|
return blocks;
|
|
116
47
|
};
|
|
117
48
|
// Lia@Changes 09-04-26 --- Inject buffer into unifiedResponse.data to support proper rendering of rich messages (ex: tables and code blocks)
|
|
118
|
-
const toUnified = (submessages) =>
|
|
49
|
+
export const toUnified = (submessages) =>
|
|
119
50
|
({
|
|
120
51
|
response_id: randomUUID(),
|
|
121
52
|
sections: submessages.map((submessage) => {
|
|
122
53
|
switch (submessage.messageType) {
|
|
123
|
-
case RichSubMessageType.
|
|
54
|
+
case RichSubMessageType.CODE:
|
|
55
|
+
const codeMetadata = submessage.codeMetadata;
|
|
124
56
|
return {
|
|
125
57
|
view_model: {
|
|
126
|
-
primitive: {
|
|
58
|
+
primitive: {
|
|
59
|
+
language: codeMetadata.codeLanguage,
|
|
60
|
+
code_blocks: codeMetadata.codeBlocks.map((block) => ({ content: block.codeContent, type: CodeHighlightType[block.highlightType] })),
|
|
61
|
+
__typename: 'GenAICodeUXPrimitive'
|
|
62
|
+
},
|
|
127
63
|
__typename: 'GenAISingleLayoutViewModel'
|
|
128
64
|
}
|
|
129
65
|
};
|
|
130
|
-
|
|
66
|
+
break;
|
|
67
|
+
case RichSubMessageType.CONTENT_ITEMS:
|
|
68
|
+
return {
|
|
69
|
+
view_model: {
|
|
70
|
+
primitives: submessage.contentItemsMetadata.itemsMetadata.map((item) => {
|
|
71
|
+
const reelItem = item.reelItem
|
|
72
|
+
return {
|
|
73
|
+
reels_url: reelItem.videoUrl,
|
|
74
|
+
thumbnail_url: reelItem.thumbnailUrl,
|
|
75
|
+
creator: reelItem.creator || '@itsliaaa/baileys',
|
|
76
|
+
avatar_url: reelItem.profileIconUrl,
|
|
77
|
+
reels_title: reelItem.title,
|
|
78
|
+
likes_count: reelItem.likesCount || 0,
|
|
79
|
+
shares_count: reelItem.sharesCount || 0,
|
|
80
|
+
view_count: reelItem.viewCount || 0,
|
|
81
|
+
reel_source: reelItem.reelSource || 'IG',
|
|
82
|
+
is_verified: reelItem.isVerified || false,
|
|
83
|
+
__typename: 'GenAIReelPrimitive'
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
__typename: 'GenAIHScrollLayoutViewModel'
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
break;
|
|
90
|
+
case RichSubMessageType.LATEX:
|
|
91
|
+
const latexMetadata = submessage.latexMetadata;
|
|
92
|
+
const item = {
|
|
93
|
+
latex_expression: latexMetadata.expressions[0]?.latexExpression,
|
|
94
|
+
font_height: latexMetadata.expressions[0]?.fontHeight,
|
|
95
|
+
padding: 15,
|
|
96
|
+
latex_image: {
|
|
97
|
+
url: latexMetadata.expressions[0]?.url,
|
|
98
|
+
width: latexMetadata.expressions[0]?.width || 388,
|
|
99
|
+
height: latexMetadata.expressions[0]?.height || 160
|
|
100
|
+
}
|
|
101
|
+
};
|
|
131
102
|
return {
|
|
132
103
|
view_model: {
|
|
133
104
|
primitive: {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
__typename: '
|
|
105
|
+
item,
|
|
106
|
+
...item,
|
|
107
|
+
__typename: 'GenAILatexUXPrimitive'
|
|
137
108
|
},
|
|
138
109
|
__typename: 'GenAISingleLayoutViewModel'
|
|
139
110
|
}
|
|
140
111
|
};
|
|
141
|
-
|
|
112
|
+
break;
|
|
113
|
+
case RichSubMessageType.TABLE:
|
|
114
|
+
const tableMetadata = submessage.tableMetadata;
|
|
142
115
|
return {
|
|
143
116
|
view_model: {
|
|
144
117
|
primitive: {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
__typename: '
|
|
118
|
+
title: tableMetadata.title,
|
|
119
|
+
rows: tableMetadata.rows.map((row) => ({ is_header: row.isHeading, cells: row.items, markdown_cells: [] })),
|
|
120
|
+
__typename: 'GenATableUXPrimitive'
|
|
148
121
|
},
|
|
149
122
|
__typename: 'GenAISingleLayoutViewModel'
|
|
150
123
|
}
|
|
151
124
|
};
|
|
125
|
+
break;
|
|
126
|
+
case RichSubMessageType.TEXT:
|
|
127
|
+
return {
|
|
128
|
+
view_model: {
|
|
129
|
+
primitive: { text: submessage.messageText, inline_entities: [], __typename: 'GenAIMarkdownTextUXPrimitive' },
|
|
130
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
break;
|
|
152
134
|
}
|
|
153
135
|
return submessage;
|
|
154
136
|
})
|
|
155
137
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
138
|
+
// Lia@Note 17-04-26 --- WIP
|
|
139
|
+
export const buildAdditionalBotMetadataContext = (submessages) => {
|
|
140
|
+
const sources = [];
|
|
141
|
+
const mediaDetailsMetadataList = [];
|
|
142
|
+
for (let i = 0; i < submessages.length; i++) {
|
|
143
|
+
const submessage = submessages[i];
|
|
144
|
+
switch (submessage.messageType) {
|
|
145
|
+
case RichSubMessageType.CONTENT_ITEMS:
|
|
146
|
+
const itemsMetadata = submessage.contentItemsMetadata.itemsMetadata;
|
|
147
|
+
for (let n = 0; n < itemsMetadata.length; n++) {
|
|
148
|
+
const reelItem = itemsMetadata[n].reelItem;
|
|
149
|
+
sources.push({
|
|
150
|
+
provider: 0,
|
|
151
|
+
thumbnailCdnUrl: reelItem.thumbnailUrl,
|
|
152
|
+
sourceProviderUrl: reelItem.videoUrl,
|
|
153
|
+
sourceQuery: '',
|
|
154
|
+
faviconCdnUrl: '',
|
|
155
|
+
citationNumber: i + 1,
|
|
156
|
+
sourceTitle: reelItem.title
|
|
157
|
+
});
|
|
158
|
+
mediaDetailsMetadataList.push({
|
|
159
|
+
id: randomBytes(32).toString('hex'),
|
|
160
|
+
previewMedia: {
|
|
161
|
+
fileSha256: '',
|
|
162
|
+
mediaKey: '',
|
|
163
|
+
fileEncSha256: '',
|
|
164
|
+
directPath: '',
|
|
165
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
166
|
+
mimetype: 'image/jpeg'
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case RichSubMessageType.LATEX:
|
|
172
|
+
const expressions = submessage.latexMetadata.expressions;
|
|
173
|
+
for (let n = 0; n < expressions.length; n++) {
|
|
174
|
+
const expression = expressions[n];
|
|
175
|
+
mediaDetailsMetadataList.push({
|
|
176
|
+
id: randomBytes(32).toString('hex'),
|
|
177
|
+
previewMedia: {
|
|
178
|
+
fileSha256: '',
|
|
179
|
+
mediaKey: '',
|
|
180
|
+
fileEncSha256: '',
|
|
181
|
+
directPath: '',
|
|
182
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
183
|
+
mimetype: 'image/jpeg'
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
170
188
|
}
|
|
171
|
-
});
|
|
172
|
-
if (footer) {
|
|
173
|
-
submessages.push({
|
|
174
|
-
messageType: 2,
|
|
175
|
-
messageText: footer
|
|
176
|
-
});
|
|
177
189
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
190
|
+
return { sources, mediaDetailsMetadataList };
|
|
191
|
+
}
|
|
192
|
+
export const prepareRichResponseMessage = (content) => {
|
|
193
|
+
const { code, contentText, expressions, footerText, headerText, items, language, richResponse, table, text, title } = content;
|
|
194
|
+
let submessages = [];
|
|
195
|
+
if (Array.isArray(richResponse)) {
|
|
196
|
+
submessages = richResponse.map((submessage) => {
|
|
197
|
+
if (submessage.text) {
|
|
198
|
+
return {
|
|
199
|
+
messageType: RichSubMessageType.TEXT,
|
|
200
|
+
messageText: submessage.text
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
else if (submessage.code) {
|
|
204
|
+
return {
|
|
205
|
+
messageType: RichSubMessageType.CODE,
|
|
206
|
+
codeMetadata: {
|
|
207
|
+
codeLanguage: submessage.language,
|
|
208
|
+
codeBlocks: submessage.code
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
else if (submessage.expressions) {
|
|
213
|
+
return {
|
|
214
|
+
messageType: RichSubMessageType.LATEX,
|
|
215
|
+
latexMetadata: {
|
|
216
|
+
text: submessage.text,
|
|
217
|
+
expressions: submessage.expressions
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
else if (submessage.items) {
|
|
222
|
+
return {
|
|
223
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
224
|
+
contentItemsMetadata: {
|
|
225
|
+
itemsMetadata: submessage.items
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
else if (submessage.table) {
|
|
230
|
+
return {
|
|
231
|
+
messageType: RichSubMessageType.TABLE,
|
|
232
|
+
tableMetadata: {
|
|
233
|
+
title: submessage.title,
|
|
234
|
+
rows: submessage.table
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return submessage;
|
|
198
239
|
});
|
|
199
240
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
241
|
+
else {
|
|
242
|
+
if (headerText) {
|
|
243
|
+
submessages.push({
|
|
244
|
+
messageType: RichSubMessageType.TEXT,
|
|
245
|
+
messageText: headerText
|
|
246
|
+
});
|
|
205
247
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
const unified = toUnified(submessages);
|
|
214
|
-
return {
|
|
215
|
-
submessages,
|
|
216
|
-
messageType: 1,
|
|
217
|
-
unifiedResponse: {
|
|
218
|
-
data: textEncoder.encode(JSON.stringify(unified))
|
|
219
|
-
},
|
|
220
|
-
contextInfo: FORWARDED_AI_BOT_INFO
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
export const prepareRichResponseMessage = (content) => {
|
|
224
|
-
const submessages = content.map((submessage) => {
|
|
225
|
-
if (submessage.text) {
|
|
226
|
-
return {
|
|
227
|
-
messageType: 2,
|
|
228
|
-
messageText: submessage.text
|
|
229
|
-
};
|
|
248
|
+
if (contentText) {
|
|
249
|
+
submessages.push({
|
|
250
|
+
messageType: RichSubMessageType.TEXT,
|
|
251
|
+
messageText: contentText
|
|
252
|
+
});
|
|
230
253
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
254
|
+
if (code) {
|
|
255
|
+
language ??= 'javascript';
|
|
256
|
+
submessages.push({
|
|
257
|
+
messageType: RichSubMessageType.CODE,
|
|
234
258
|
codeMetadata: {
|
|
235
|
-
codeLanguage:
|
|
236
|
-
codeBlocks:
|
|
259
|
+
codeLanguage: language,
|
|
260
|
+
codeBlocks: tokenizeCode(code, language)
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
else if (expressions) {
|
|
265
|
+
submessages.push({
|
|
266
|
+
messageType: RichSubMessageType.LATEX,
|
|
267
|
+
latexMetadata: {
|
|
268
|
+
text,
|
|
269
|
+
expressions
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
else if (items) {
|
|
274
|
+
submessages.push({
|
|
275
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
276
|
+
contentItemsMetadata: {
|
|
277
|
+
itemsMetadata: items.map((item) => ({ reelItem: item })),
|
|
278
|
+
contentType: proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
|
|
237
279
|
}
|
|
238
|
-
};
|
|
280
|
+
});
|
|
239
281
|
}
|
|
240
|
-
else if (
|
|
241
|
-
|
|
242
|
-
|
|
282
|
+
else if (table) {
|
|
283
|
+
const tableRows = table.map((items, index) => ({
|
|
284
|
+
isHeading: index == 0,
|
|
285
|
+
items
|
|
286
|
+
}));
|
|
287
|
+
submessages.push({
|
|
288
|
+
messageType: RichSubMessageType.TABLE,
|
|
243
289
|
tableMetadata: {
|
|
244
|
-
title
|
|
245
|
-
rows:
|
|
290
|
+
title,
|
|
291
|
+
rows: tableRows
|
|
246
292
|
}
|
|
247
|
-
};
|
|
293
|
+
});
|
|
248
294
|
}
|
|
249
|
-
|
|
250
|
-
|
|
295
|
+
if (footerText) {
|
|
296
|
+
submessages.push({
|
|
297
|
+
messageType: RichSubMessageType.TEXT,
|
|
298
|
+
messageText: footerText
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
251
302
|
const unified = toUnified(submessages);
|
|
252
|
-
|
|
303
|
+
const message = wrapToBotForwardedMessage({
|
|
253
304
|
submessages,
|
|
254
|
-
messageType:
|
|
305
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
255
306
|
unifiedResponse: {
|
|
256
307
|
data: textEncoder.encode(JSON.stringify(unified))
|
|
257
308
|
},
|
|
258
|
-
contextInfo:
|
|
259
|
-
|
|
309
|
+
contextInfo: {
|
|
310
|
+
isForwarded: true,
|
|
311
|
+
forwardingScore: 1,
|
|
312
|
+
forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
|
|
313
|
+
forwardOrigin: 4
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
// Lia@Note 17-04-26 --- TODO: Fill mediaDetailsMetadataList and sources field
|
|
317
|
+
const { sources, mediaDetailsMetadataList } = buildAdditionalBotMetadataContext(submessages);
|
|
318
|
+
const botMetadata = message.messageContextInfo.botMetadata;
|
|
319
|
+
if (sources.length > 0) {
|
|
320
|
+
botMetadata.richResponseSourcesMetadata = { sources };
|
|
321
|
+
}
|
|
322
|
+
if (mediaDetailsMetadataList.length > 0) {
|
|
323
|
+
botMetadata.unifiedResponseMutation = { mediaDetailsMetadataList };
|
|
324
|
+
}
|
|
325
|
+
return message;
|
|
260
326
|
}
|
|
261
|
-
|
|
327
|
+
// Lia@Note 17-04-26 --- signature and certificateChain for proofs[] field
|
|
328
|
+
export const botMetadataSignature = () => {
|
|
329
|
+
const signature = new Uint8Array(64);
|
|
330
|
+
getRandomValues(signature);
|
|
331
|
+
return signature;
|
|
332
|
+
}
|
|
333
|
+
export const botMetadataCertificate = (length = 700) => {
|
|
334
|
+
const certificate = new Uint8Array(length);
|
|
335
|
+
certificate[0] = 48;
|
|
336
|
+
certificate[1] = 130;
|
|
337
|
+
getRandomValues(certificate.subarray(2));
|
|
338
|
+
return certificate;
|
|
339
|
+
}
|
|
340
|
+
export const wrapToBotForwardedMessage = (richResponseMessage) =>
|
|
262
341
|
({
|
|
263
342
|
messageContextInfo: {
|
|
264
343
|
botMetadata: {
|
|
344
|
+
pluginMetadata: {},
|
|
265
345
|
// Lia@Note 09-04-26 --- TODO: Fill verificationMetadata field
|
|
266
|
-
verificationMetadata: {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
346
|
+
verificationMetadata: {
|
|
347
|
+
proofs: [
|
|
348
|
+
{
|
|
349
|
+
certificateChain: [
|
|
350
|
+
botMetadataCertificate(684),
|
|
351
|
+
botMetadataCertificate(892)
|
|
352
|
+
],
|
|
353
|
+
version: 1,
|
|
354
|
+
useCase: 1,
|
|
355
|
+
signature: botMetadataSignature()
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
},
|
|
359
|
+
botRenderingConfigMetadata: BOT_RENDERING_CONFIG_METADATA
|
|
271
360
|
}
|
|
272
361
|
},
|
|
273
|
-
botForwardedMessage: {
|
|
362
|
+
botForwardedMessage: {
|
|
363
|
+
message: { richResponseMessage }
|
|
364
|
+
}
|
|
274
365
|
});
|
|
@@ -1297,4 +1297,76 @@ for (const [i, DOUBLE_BYTE_TOKEN] of DOUBLE_BYTE_TOKENS.entries()) {
|
|
|
1297
1297
|
for (const [j, element] of DOUBLE_BYTE_TOKEN.entries()) {
|
|
1298
1298
|
TOKEN_MAP[element] = { dict: i, index: j };
|
|
1299
1299
|
}
|
|
1300
|
-
}
|
|
1300
|
+
}
|
|
1301
|
+
export const CPP_KEYWORDS = new Set([
|
|
1302
|
+
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor', 'bool', 'break', 'case',
|
|
1303
|
+
'catch', 'char', 'class', 'compl', 'concept', 'const', 'consteval', 'constexpr', 'constinit',
|
|
1304
|
+
'const_cast', 'continue', 'co_await', 'co_return', 'co_yield', 'decltype', 'default', 'delete',
|
|
1305
|
+
'do', 'double', 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'false', 'float',
|
|
1306
|
+
'for', 'friend', 'goto', 'if', 'inline', 'int', 'long', 'mutable', 'namespace', 'new', 'noexcept',
|
|
1307
|
+
'not', 'not_eq', 'nullptr', 'operator', 'or', 'or_eq', 'private', 'protected', 'public', 'register',
|
|
1308
|
+
'reinterpret_cast', 'requires', 'return', 'short', 'signed', 'sizeof', 'static', 'static_assert',
|
|
1309
|
+
'static_cast', 'struct', 'switch', 'template', 'this', 'thread_local', 'throw', 'true', 'try',
|
|
1310
|
+
'typedef', 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual', 'void', 'volatile',
|
|
1311
|
+
'wchar_t', 'while', 'xor', 'xor_eq'
|
|
1312
|
+
]);
|
|
1313
|
+
export const CSS_KEYWORDS = new Set([
|
|
1314
|
+
'import', 'media', 'font-face', 'keyframes', 'supports', 'charset',
|
|
1315
|
+
'important', 'root', 'hover', 'active', 'focus', 'visited', 'before', 'after',
|
|
1316
|
+
'not', 'nth-child', 'first-child', 'last-child', 'only-child',
|
|
1317
|
+
'none', 'inherit', 'initial', 'unset', 'auto', 'transparent', 'currentcolor'
|
|
1318
|
+
]);
|
|
1319
|
+
export const GO_KEYWORDS = new Set([
|
|
1320
|
+
'break', 'default', 'func', 'interface', 'select', 'case', 'defer', 'go', 'map', 'struct',
|
|
1321
|
+
'chan', 'else', 'goto', 'package', 'switch', 'const', 'fallthrough', 'if', 'range', 'type',
|
|
1322
|
+
'continue', 'for', 'import', 'return', 'var', 'true', 'false', 'nil'
|
|
1323
|
+
]);
|
|
1324
|
+
export const HTML_KEYWORDS = new Set([
|
|
1325
|
+
'html', 'head', 'body', 'title', 'meta', 'link', 'script', 'style',
|
|
1326
|
+
'header', 'footer', 'main', 'section', 'article', 'aside', 'nav',
|
|
1327
|
+
'div', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'a', 'img',
|
|
1328
|
+
'ul', 'ol', 'li', 'table', 'tr', 'td', 'th', 'thead', 'tbody',
|
|
1329
|
+
'form', 'input', 'button', 'select', 'textarea', 'label', 'option',
|
|
1330
|
+
'canvas', 'svg', 'iframe', 'video', 'audio', 'source'
|
|
1331
|
+
]);
|
|
1332
|
+
export const JS_KEYWORDS = new Set([
|
|
1333
|
+
'import', 'export', 'from', 'default', 'as',
|
|
1334
|
+
'const', 'let', 'var', 'function', 'class', 'extends', 'new',
|
|
1335
|
+
'return', 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'break', 'continue',
|
|
1336
|
+
'try', 'catch', 'finally', 'throw',
|
|
1337
|
+
'async', 'await', 'yield',
|
|
1338
|
+
'typeof', 'instanceof', 'in', 'of', 'delete', 'void',
|
|
1339
|
+
'true', 'false', 'null', 'undefined', 'NaN', 'Infinity',
|
|
1340
|
+
'this', 'super', 'static', 'get', 'set',
|
|
1341
|
+
'debugger', 'with'
|
|
1342
|
+
]);
|
|
1343
|
+
export const PYTHON_KEYWORDS = new Set([
|
|
1344
|
+
'import', 'from', 'as', 'def', 'class', 'return', 'if', 'elif', 'else',
|
|
1345
|
+
'for', 'while', 'break', 'continue', 'try', 'except', 'finally', 'raise',
|
|
1346
|
+
'with', 'yield', 'lambda', 'pass', 'del', 'global', 'nonlocal', 'assert',
|
|
1347
|
+
'True', 'False', 'None', 'and', 'or', 'not', 'in', 'is', 'async', 'await',
|
|
1348
|
+
'self', 'print'
|
|
1349
|
+
]);
|
|
1350
|
+
export const RUST_KEYWORDS = new Set([
|
|
1351
|
+
'as', 'break', 'const', 'continue', 'crate', 'else', 'enum', 'extern', 'false', 'fn', 'for',
|
|
1352
|
+
'if', 'impl', 'in', 'let', 'loop', 'match', 'mod', 'move', 'mut', 'pub', 'ref', 'return',
|
|
1353
|
+
'self', 'Self', 'static', 'struct', 'super', 'trait', 'true', 'type', 'unsafe', 'use',
|
|
1354
|
+
'where', 'while', 'async', 'await', 'dyn', 'abstract', 'become', 'box', 'do', 'final',
|
|
1355
|
+
'macro', 'override', 'priv', 'typeof', 'unsized', 'virtual', 'yield'
|
|
1356
|
+
]);
|
|
1357
|
+
export const LANGUAGE_KEYWORDS = {
|
|
1358
|
+
css: CSS_KEYWORDS,
|
|
1359
|
+
html: HTML_KEYWORDS,
|
|
1360
|
+
javascript: JS_KEYWORDS,
|
|
1361
|
+
typescript: JS_KEYWORDS,
|
|
1362
|
+
js: JS_KEYWORDS,
|
|
1363
|
+
ts: JS_KEYWORDS,
|
|
1364
|
+
python: PYTHON_KEYWORDS,
|
|
1365
|
+
py: PYTHON_KEYWORDS,
|
|
1366
|
+
go: GO_KEYWORDS,
|
|
1367
|
+
golang: GO_KEYWORDS,
|
|
1368
|
+
cpp: CPP_KEYWORDS,
|
|
1369
|
+
'c++': CPP_KEYWORDS,
|
|
1370
|
+
rust: RUST_KEYWORDS,
|
|
1371
|
+
rs: RUST_KEYWORDS,
|
|
1372
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itsliaaa/baileys",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Enhanced Baileys v7 with fixed newsletter media upload, plus support for interactive messages, albums, and more message types.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"baileys",
|
|
25
25
|
"baileys-fork",
|
|
26
26
|
"baileys-mod",
|
|
27
|
+
"interactive-messages",
|
|
27
28
|
"js-whatsapp",
|
|
28
29
|
"multi-device",
|
|
29
30
|
"whatsapp",
|