@itsliaaa/baileys 0.1.22 → 0.1.23
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/lib/Defaults/index.js
CHANGED
|
@@ -142,6 +142,10 @@ export const TimeMs = {
|
|
|
142
142
|
Day: 24 * 60 * 60 * 1000,
|
|
143
143
|
Week: 7 * 24 * 60 * 60 * 1000
|
|
144
144
|
};
|
|
145
|
+
export const BOT_RENDERING_CONFIG_METADATA = {
|
|
146
|
+
bloksVersioningId: '0903aa5f7f47de66789d5f4c86d3bd6e05e4bc3ff85e454a9f907d5ed7fef97c',
|
|
147
|
+
pixelDensity: 2.75
|
|
148
|
+
};
|
|
145
149
|
export const FORWARDED_AI_BOT_INFO = {
|
|
146
150
|
isForwarded: true,
|
|
147
151
|
forwardingScore: 1,
|
|
@@ -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 { prepareRichCodeBlock, prepareRichResponseMessage, prepareRichTable, wrapToBotForwardedMessage } from './rich-message-utils.js';
|
|
13
|
+
import { prepareRichCodeBlock, prepareRichLatex, prepareRichReels, prepareRichResponseMessage, prepareRichTable, wrapToBotForwardedMessage } from './rich-message-utils.js';
|
|
14
14
|
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
15
15
|
const MIMETYPE_MAP = {
|
|
16
16
|
image: 'image/jpeg',
|
|
@@ -1018,10 +1018,16 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1018
1018
|
expectedVideoCount: videoCount
|
|
1019
1019
|
};
|
|
1020
1020
|
}
|
|
1021
|
-
// Lia@Changes 09-04-26 --- Add support for code block
|
|
1021
|
+
// Lia@Changes 09-04-26 --- Add support for code block, latex, reels carousel, table with richResponseMessage
|
|
1022
1022
|
else if (hasNonNullishProperty(message, 'code')) {
|
|
1023
1023
|
m.richResponseMessage = prepareRichCodeBlock(message);
|
|
1024
1024
|
}
|
|
1025
|
+
else if (hasNonNullishProperty(message, 'expressions')) {
|
|
1026
|
+
m.richResponseMessage = prepareRichLatex(message);
|
|
1027
|
+
}
|
|
1028
|
+
else if (hasNonNullishProperty(message, 'items')) {
|
|
1029
|
+
m.richResponseMessage = prepareRichReels(message);
|
|
1030
|
+
}
|
|
1025
1031
|
else if (hasNonNullishProperty(message, 'table')) {
|
|
1026
1032
|
m.richResponseMessage = prepareRichTable(message);
|
|
1027
1033
|
}
|
|
@@ -5,82 +5,12 @@
|
|
|
5
5
|
* If you use or copy this code, please credit my name or project.
|
|
6
6
|
*/
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
|
-
import { FORWARDED_AI_BOT_INFO, LEXER_REGEX } from '../Defaults/index.js';
|
|
8
|
+
import { BOT_RENDERING_CONFIG_METADATA, FORWARDED_AI_BOT_INFO, 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';
|
|
10
12
|
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
13
|
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
14
|
export const tokenizeCode = (code, language = 'javascript') => {
|
|
85
15
|
const keywords = LANGUAGE_KEYWORDS[language] || NOOP;
|
|
86
16
|
const blocks = [];
|
|
@@ -115,15 +45,62 @@ export const tokenizeCode = (code, language = 'javascript') => {
|
|
|
115
45
|
return blocks;
|
|
116
46
|
};
|
|
117
47
|
// 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) =>
|
|
48
|
+
export const toUnified = (submessages) =>
|
|
119
49
|
({
|
|
120
50
|
response_id: randomUUID(),
|
|
121
51
|
sections: submessages.map((submessage) => {
|
|
122
52
|
switch (submessage.messageType) {
|
|
123
|
-
case RichSubMessageType.
|
|
53
|
+
case RichSubMessageType.CODE:
|
|
124
54
|
return {
|
|
125
55
|
view_model: {
|
|
126
|
-
primitive: {
|
|
56
|
+
primitive: {
|
|
57
|
+
language: submessage.codeMetadata.codeLanguage,
|
|
58
|
+
code_blocks: submessage.codeMetadata.codeBlocks.map((block) => ({ content: block.codeContent, type: CodeHighlightType[block.highlightType] })),
|
|
59
|
+
__typename: 'GenAICodeUXPrimitive'
|
|
60
|
+
},
|
|
61
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
case RichSubMessageType.CONTENT_ITEMS:
|
|
65
|
+
return {
|
|
66
|
+
view_model: {
|
|
67
|
+
primitives: submessage.contentItemsMetadata.itemsMetadata.map((item) => {
|
|
68
|
+
const reelItem = item.reelItem
|
|
69
|
+
return {
|
|
70
|
+
reels_url: reelItem.videoUrl,
|
|
71
|
+
thumbnail_url: reelItem.thumbnailUrl,
|
|
72
|
+
creator: reelItem.creator || '@itsliaaa/baileys',
|
|
73
|
+
avatar_url: reelItem.profileIconUrl,
|
|
74
|
+
reels_title: reelItem.title,
|
|
75
|
+
likes_count: reelItem.likesCount || 0,
|
|
76
|
+
shares_count: reelItem.sharesCount || 0,
|
|
77
|
+
view_count: reelItem.viewCount || 0,
|
|
78
|
+
reel_source: reelItem.reelSource || 'IG',
|
|
79
|
+
is_verified: reelItem.isVerified || false,
|
|
80
|
+
__typename: 'GenAIReelPrimitive'
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
__typename: 'GenAIHScrollLayoutViewModel'
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
case RichSubMessageType.LATEX:
|
|
87
|
+
const item = {
|
|
88
|
+
latex_expression: submessage.latexMetadata.expressions[0]?.latexExpression,
|
|
89
|
+
font_height: submessage.latexMetadata.expressions[0]?.fontHeight,
|
|
90
|
+
padding: 15,
|
|
91
|
+
latex_image: {
|
|
92
|
+
url: submessage.latexMetadata.expressions[0]?.url,
|
|
93
|
+
width: submessage.latexMetadata.expressions[0]?.width || 388,
|
|
94
|
+
height: submessage.latexMetadata.expressions[0]?.height || 160
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
view_model: {
|
|
99
|
+
primitive: {
|
|
100
|
+
item,
|
|
101
|
+
...item,
|
|
102
|
+
__typename: 'GenAILatexUXPrimitive'
|
|
103
|
+
},
|
|
127
104
|
__typename: 'GenAISingleLayoutViewModel'
|
|
128
105
|
}
|
|
129
106
|
};
|
|
@@ -132,20 +109,16 @@ const toUnified = (submessages) =>
|
|
|
132
109
|
view_model: {
|
|
133
110
|
primitive: {
|
|
134
111
|
title: submessage.tableMetadata.title,
|
|
135
|
-
rows: submessage.tableMetadata.rows.map((row) => ({ is_header: row.isHeading, cells: row.items })),
|
|
112
|
+
rows: submessage.tableMetadata.rows.map((row) => ({ is_header: row.isHeading, cells: row.items, markdown_cells: [] })),
|
|
136
113
|
__typename: 'GenATableUXPrimitive'
|
|
137
114
|
},
|
|
138
115
|
__typename: 'GenAISingleLayoutViewModel'
|
|
139
116
|
}
|
|
140
117
|
};
|
|
141
|
-
case RichSubMessageType.
|
|
118
|
+
case RichSubMessageType.TEXT:
|
|
142
119
|
return {
|
|
143
120
|
view_model: {
|
|
144
|
-
primitive: {
|
|
145
|
-
language: submessage.codeMetadata.codeLanguage,
|
|
146
|
-
code_blocks: submessage.codeMetadata.codeBlocks.map((block) => ({ content: block.codeContent, type: CodeHighlightType[block.highlightType] })),
|
|
147
|
-
__typename: 'GenAICodeUXPrimitive'
|
|
148
|
-
},
|
|
121
|
+
primitive: { text: submessage.messageText, inline_entities: [], __typename: 'GenAIMarkdownTextUXPrimitive' },
|
|
149
122
|
__typename: 'GenAISingleLayoutViewModel'
|
|
150
123
|
}
|
|
151
124
|
};
|
|
@@ -158,12 +131,12 @@ export const prepareRichCodeBlock = ({ header, code, footer, language } = {}) =>
|
|
|
158
131
|
const submessages = [];
|
|
159
132
|
if (header) {
|
|
160
133
|
submessages.push({
|
|
161
|
-
messageType:
|
|
134
|
+
messageType: RichSubMessageType.TEXT,
|
|
162
135
|
messageText: header
|
|
163
136
|
});
|
|
164
137
|
}
|
|
165
138
|
submessages.push({
|
|
166
|
-
messageType:
|
|
139
|
+
messageType: RichSubMessageType.CODE,
|
|
167
140
|
codeMetadata: {
|
|
168
141
|
codeLanguage: language,
|
|
169
142
|
codeBlocks: tokenizeCode(code, language)
|
|
@@ -171,14 +144,76 @@ export const prepareRichCodeBlock = ({ header, code, footer, language } = {}) =>
|
|
|
171
144
|
});
|
|
172
145
|
if (footer) {
|
|
173
146
|
submessages.push({
|
|
174
|
-
messageType:
|
|
147
|
+
messageType: RichSubMessageType.TEXT,
|
|
175
148
|
messageText: footer
|
|
176
149
|
});
|
|
177
150
|
}
|
|
178
151
|
const unified = toUnified(submessages);
|
|
179
152
|
return {
|
|
180
153
|
submessages,
|
|
181
|
-
messageType:
|
|
154
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
155
|
+
unifiedResponse: {
|
|
156
|
+
data: textEncoder.encode(JSON.stringify(unified))
|
|
157
|
+
},
|
|
158
|
+
contextInfo: FORWARDED_AI_BOT_INFO
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
export const prepareRichReels = ({ header, items, footer } = {}) => {
|
|
162
|
+
const submessages = [];
|
|
163
|
+
if (header) {
|
|
164
|
+
submessages.push({
|
|
165
|
+
messageType: RichSubMessageType.TEXT,
|
|
166
|
+
messageText: header
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
submessages.push({
|
|
170
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
171
|
+
contentItemsMetadata: {
|
|
172
|
+
itemsMetadata: items.map((item) => ({ reelItem: item })),
|
|
173
|
+
contentType: proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
if (footer) {
|
|
177
|
+
submessages.push({
|
|
178
|
+
messageType: RichSubMessageType.TEXT,
|
|
179
|
+
messageText: footer
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const unified = toUnified(submessages);
|
|
183
|
+
return {
|
|
184
|
+
submessages,
|
|
185
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
186
|
+
unifiedResponse: {
|
|
187
|
+
data: textEncoder.encode(JSON.stringify(unified))
|
|
188
|
+
},
|
|
189
|
+
contextInfo: FORWARDED_AI_BOT_INFO
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
export const prepareRichLatex = ({ header, text, expressions, footer } = {}) => {
|
|
193
|
+
const submessages = [];
|
|
194
|
+
if (header) {
|
|
195
|
+
submessages.push({
|
|
196
|
+
messageType: RichSubMessageType.TEXT,
|
|
197
|
+
messageText: header
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
submessages.push({
|
|
201
|
+
messageType: RichSubMessageType.LATEX,
|
|
202
|
+
latexMetadata: {
|
|
203
|
+
text,
|
|
204
|
+
expressions
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
if (footer) {
|
|
208
|
+
submessages.push({
|
|
209
|
+
messageType: RichSubMessageType.TEXT,
|
|
210
|
+
messageText: footer
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const unified = toUnified(submessages);
|
|
214
|
+
return {
|
|
215
|
+
submessages,
|
|
216
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
182
217
|
unifiedResponse: {
|
|
183
218
|
data: textEncoder.encode(JSON.stringify(unified))
|
|
184
219
|
},
|
|
@@ -193,12 +228,12 @@ export const prepareRichTable = ({ header, title, table, footer } = {}) => {
|
|
|
193
228
|
const submessages = [];
|
|
194
229
|
if (header) {
|
|
195
230
|
submessages.push({
|
|
196
|
-
messageType:
|
|
231
|
+
messageType: RichSubMessageType.TEXT,
|
|
197
232
|
messageText: header
|
|
198
233
|
});
|
|
199
234
|
}
|
|
200
235
|
submessages.push({
|
|
201
|
-
messageType:
|
|
236
|
+
messageType: RichSubMessageType.TABLE,
|
|
202
237
|
tableMetadata: {
|
|
203
238
|
title,
|
|
204
239
|
rows: tableRows
|
|
@@ -206,14 +241,14 @@ export const prepareRichTable = ({ header, title, table, footer } = {}) => {
|
|
|
206
241
|
});
|
|
207
242
|
if (footer) {
|
|
208
243
|
submessages.push({
|
|
209
|
-
messageType:
|
|
244
|
+
messageType: RichSubMessageType.TEXT,
|
|
210
245
|
messageText: footer
|
|
211
246
|
});
|
|
212
247
|
}
|
|
213
248
|
const unified = toUnified(submessages);
|
|
214
249
|
return {
|
|
215
250
|
submessages,
|
|
216
|
-
messageType:
|
|
251
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
217
252
|
unifiedResponse: {
|
|
218
253
|
data: textEncoder.encode(JSON.stringify(unified))
|
|
219
254
|
},
|
|
@@ -224,22 +259,39 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
224
259
|
const submessages = content.map((submessage) => {
|
|
225
260
|
if (submessage.text) {
|
|
226
261
|
return {
|
|
227
|
-
messageType:
|
|
262
|
+
messageType: RichSubMessageType.TEXT,
|
|
228
263
|
messageText: submessage.text
|
|
229
264
|
};
|
|
230
265
|
}
|
|
231
266
|
else if (submessage.code) {
|
|
232
267
|
return {
|
|
233
|
-
messageType:
|
|
268
|
+
messageType: RichSubMessageType.CODE,
|
|
234
269
|
codeMetadata: {
|
|
235
270
|
codeLanguage: submessage.language,
|
|
236
271
|
codeBlocks: submessage.code
|
|
237
272
|
}
|
|
238
273
|
};
|
|
239
274
|
}
|
|
275
|
+
else if (submessage.expressions) {
|
|
276
|
+
return {
|
|
277
|
+
messageType: RichSubMessageType.LATEX,
|
|
278
|
+
latexMetadata: {
|
|
279
|
+
text: submessage.text,
|
|
280
|
+
expressions: submessage.expressions
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
else if (submessage.items) {
|
|
285
|
+
return {
|
|
286
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
287
|
+
contentItemsMetadata: {
|
|
288
|
+
itemsMetadata: submessage.items
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
240
292
|
else if (submessage.table) {
|
|
241
293
|
return {
|
|
242
|
-
messageType:
|
|
294
|
+
messageType: RichSubMessageType.TABLE,
|
|
243
295
|
tableMetadata: {
|
|
244
296
|
title: submessage.title,
|
|
245
297
|
rows: submessage.table
|
|
@@ -251,7 +303,7 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
251
303
|
const unified = toUnified(submessages);
|
|
252
304
|
return {
|
|
253
305
|
submessages,
|
|
254
|
-
messageType:
|
|
306
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
255
307
|
unifiedResponse: {
|
|
256
308
|
data: textEncoder.encode(JSON.stringify(unified))
|
|
257
309
|
},
|
|
@@ -264,10 +316,7 @@ export const wrapToBotForwardedMessage = (message) =>
|
|
|
264
316
|
botMetadata: {
|
|
265
317
|
// Lia@Note 09-04-26 --- TODO: Fill verificationMetadata field
|
|
266
318
|
verificationMetadata: {},
|
|
267
|
-
botRenderingConfigMetadata:
|
|
268
|
-
bloksVersioningId: '0903aa5f7f47de66789d5f4c86d3bd6e05e4bc3ff85e454a9f907d5ed7fef97c',
|
|
269
|
-
pixelDensity: 2.75
|
|
270
|
-
}
|
|
319
|
+
botRenderingConfigMetadata: BOT_RENDERING_CONFIG_METADATA
|
|
271
320
|
}
|
|
272
321
|
},
|
|
273
322
|
botForwardedMessage: { message }
|
|
@@ -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.23",
|
|
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",
|