@boruto_vk7/baileys 1.0.0 → 1.0.2

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Lia@Changes 09-04-26 [WIP]
2
+ * Boruto@Changes 09-04-26 [WIP]
3
3
  * Adds support for tables and code blocks with richResponseMessage (wrapped inside botForwardedMessage).
4
4
  *
5
5
  * If you use or copy this code, please credit my name or project.
@@ -46,7 +46,7 @@ export const tokenizeCode = (code, language = 'javascript') => {
46
46
  }
47
47
  return blocks;
48
48
  };
49
- // Lia@Changes 09-04-26 --- Inject buffer into unifiedResponse.data to support proper rendering of rich messages (ex: tables and code blocks)
49
+ // Boruto@Changes 09-04-26 --- Inject buffer into unifiedResponse.data to support proper rendering of rich messages (ex: tables and code blocks)
50
50
  export const toUnified = (submessages) =>
51
51
  ({
52
52
  response_id: randomUUID(),
@@ -157,7 +157,7 @@ export const toUnified = (submessages) =>
157
157
  return submessage;
158
158
  })
159
159
  });
160
- // Lia@Note 17-04-26 --- WIP
160
+ // Boruto@Note 17-04-26 --- WIP
161
161
  export const buildAdditionalBotMetadataContext = (submessages) => {
162
162
  const sources = [];
163
163
  const mediaDetailsMetadataList = [];
@@ -335,7 +335,7 @@ export const prepareRichResponseMessage = (content) => {
335
335
  forwardOrigin: 4
336
336
  }
337
337
  });
338
- // Lia@Note 17-04-26 --- TODO: Fill mediaDetailsMetadataList and sources field
338
+ // Boruto@Note 17-04-26 --- TODO: Fill mediaDetailsMetadataList and sources field
339
339
  const { sources, mediaDetailsMetadataList } = buildAdditionalBotMetadataContext(submessages);
340
340
  const botMetadata = message.messageContextInfo.botMetadata;
341
341
  if (sources.length > 0) {
@@ -346,7 +346,7 @@ export const prepareRichResponseMessage = (content) => {
346
346
  }
347
347
  return message;
348
348
  }
349
- // Lia@Note 17-04-26 --- signature and certificateChain for proofs[] field
349
+ // Boruto@Note 17-04-26 --- signature and certificateChain for proofs[] field
350
350
  export const botMetadataSignature = () => {
351
351
  const signature = new Uint8Array(64);
352
352
  getRandomValues(signature);
@@ -364,7 +364,7 @@ export const wrapToBotForwardedMessage = (richResponseMessage) =>
364
364
  messageContextInfo: {
365
365
  botMetadata: {
366
366
  pluginMetadata: {},
367
- // Lia@Note 09-04-26 --- TODO: Fill verificationMetadata field
367
+ // Boruto@Note 09-04-26 --- TODO: Fill verificationMetadata field
368
368
  verificationMetadata: {
369
369
  proofs: [
370
370
  {
@@ -0,0 +1,387 @@
1
+ /**
2
+ * Boruto@Changes 09-04-26 [WIP]
3
+ * Adds support for tables and code blocks with richResponseMessage (wrapped inside botForwardedMessage).
4
+ *
5
+ * If you use or copy this code, please credit my name or project.
6
+ * @itsBorutoaa/baileys
7
+ */
8
+ import { getRandomValues, randomUUID, randomBytes } from 'crypto';
9
+ import { BOT_RENDERING_CONFIG_METADATA, DONATE_URL, LEXER_REGEX } from '../Defaults/index.js';
10
+ import { LANGUAGE_KEYWORDS } from '../WABinary/constants.js';
11
+ import { CodeHighlightType, RichSubMessageType } from '../Types/RichType.js';
12
+ import { proto } from '../../WAProto/index.js';
13
+ import { unixTimestampSeconds } from './generics.js';
14
+ const textEncoder = new TextEncoder();
15
+ const NOOP = new Set([]);
16
+ export const tokenizeCode = (code, language = 'javascript') => {
17
+ const keywords = LANGUAGE_KEYWORDS[language] || NOOP;
18
+ const blocks = [];
19
+ LEXER_REGEX.lastIndex = 0;
20
+ let match;
21
+ while ((match = LEXER_REGEX.exec(code)) !== null) {
22
+ if (match[1]) {
23
+ blocks.push({ highlightType: CodeHighlightType.COMMENT, codeContent: match[1] });
24
+ }
25
+ else if (match[2]) {
26
+ blocks.push({ highlightType: CodeHighlightType.STRING, codeContent: match[2] });
27
+ }
28
+ else if (match[3]) {
29
+ blocks.push({
30
+ highlightType: keywords.has(match[3]) ? CodeHighlightType.KEYWORD : CodeHighlightType.METHOD,
31
+ codeContent: match[3],
32
+ });
33
+ }
34
+ else if (match[4]) {
35
+ blocks.push({
36
+ highlightType: keywords.has(match[4]) ? CodeHighlightType.KEYWORD : CodeHighlightType.DEFAULT,
37
+ codeContent: match[4],
38
+ });
39
+ }
40
+ else if (match[5]) {
41
+ blocks.push({ highlightType: CodeHighlightType.NUMBER, codeContent: match[5] });
42
+ }
43
+ else {
44
+ blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: match[6] });
45
+ }
46
+ }
47
+ return blocks;
48
+ };
49
+ // Boruto@Changes 09-04-26 --- Inject buffer into unifiedResponse.data to support proper rendering of rich messages (ex: tables and code blocks)
50
+ export const toUnified = (submessages) =>
51
+ ({
52
+ response_id: randomUUID(),
53
+ sections: submessages.map((submessage, index) => {
54
+ switch (submessage.messageType) {
55
+ case RichSubMessageType.CODE:
56
+ const codeMetadata = submessage.codeMetadata;
57
+ return {
58
+ view_model: {
59
+ primitive: {
60
+ language: codeMetadata.codeLanguage,
61
+ code_blocks: codeMetadata.codeBlocks.map((block) => ({ content: block.codeContent, type: CodeHighlightType[block.highlightType] })),
62
+ __typename: 'GenAICodeUXPrimitive'
63
+ },
64
+ __typename: 'GenAISingleLayoutViewModel'
65
+ }
66
+ };
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 || '@itsBorutoaa/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
+ case RichSubMessageType.LATEX:
90
+ const latexMetadata = submessage.latexMetadata;
91
+ const item = {
92
+ latex_expression: latexMetadata.expressions[0]?.latexExpression,
93
+ font_height: latexMetadata.expressions[0]?.fontHeight,
94
+ padding: 15,
95
+ latex_image: {
96
+ url: latexMetadata.expressions[0]?.url,
97
+ width: latexMetadata.expressions[0]?.width || 388,
98
+ height: latexMetadata.expressions[0]?.height || 160
99
+ }
100
+ };
101
+ return {
102
+ view_model: {
103
+ primitive: {
104
+ item,
105
+ ...item,
106
+ __typename: 'GenAILatexUXPrimitive'
107
+ },
108
+ __typename: 'GenAISingleLayoutViewModel'
109
+ }
110
+ };
111
+ case RichSubMessageType.TABLE:
112
+ const tableMetadata = submessage.tableMetadata;
113
+ return {
114
+ view_model: {
115
+ primitive: {
116
+ title: tableMetadata.title,
117
+ rows: tableMetadata.rows.map((row) => ({ is_header: row.isHeading, cells: row.items, markdown_cells: [] })),
118
+ __typename: 'GenATableUXPrimitive'
119
+ },
120
+ __typename: 'GenAISingleLayoutViewModel'
121
+ }
122
+ };
123
+ case RichSubMessageType.TEXT:
124
+ const shouldAddInlineEntity = index == 0;
125
+ const inlineEntity = [{
126
+ key: 'Starseed',
127
+ metadata: {
128
+ reference_id: 1,
129
+ reference_url: DONATE_URL,
130
+ reference_title: 'For Donation via Saweria',
131
+ reference_display_name: 'Donate',
132
+ sources: [{
133
+ source_type: 'THIRD_PARTY',
134
+ source_display_name: 'Donate',
135
+ source_subtitle: '',
136
+ source_url: DONATE_URL
137
+ }],
138
+ __typename: 'GenAISearchCitationItem'
139
+ }
140
+ }];
141
+ const textEntity = shouldAddInlineEntity ?
142
+ '{{Starseed}}¹{{/Starseed}}' :
143
+ '';
144
+ return {
145
+ view_model: {
146
+ primitive: {
147
+ text: submessage.messageText + textEntity,
148
+ inline_entities: shouldAddInlineEntity ?
149
+ inlineEntity :
150
+ [],
151
+ __typename: 'GenAIMarkdownTextUXPrimitive'
152
+ },
153
+ __typename: 'GenAISingleLayoutViewModel'
154
+ }
155
+ };
156
+ }
157
+ return submessage;
158
+ })
159
+ });
160
+ // Boruto@Note 17-04-26 --- WIP
161
+ export const buildAdditionalBotMetadataContext = (submessages) => {
162
+ const sources = [];
163
+ const mediaDetailsMetadataList = [];
164
+ for (let i = 0; i < submessages.length; i++) {
165
+ const submessage = submessages[i];
166
+ switch (submessage.messageType) {
167
+ case RichSubMessageType.CONTENT_ITEMS:
168
+ const itemsMetadata = submessage.contentItemsMetadata.itemsMetadata;
169
+ for (let n = 0; n < itemsMetadata.length; n++) {
170
+ const reelItem = itemsMetadata[n].reelItem;
171
+ sources.push({
172
+ provider: 0,
173
+ thumbnailCdnUrl: reelItem.thumbnailUrl,
174
+ sourceProviderUrl: reelItem.videoUrl,
175
+ sourceQuery: '',
176
+ faviconCdnUrl: '',
177
+ citationNumber: i + 1,
178
+ sourceTitle: reelItem.title
179
+ });
180
+ mediaDetailsMetadataList.push({
181
+ id: randomBytes(32).toString('hex'),
182
+ previewMedia: {
183
+ fileSha256: '',
184
+ mediaKey: '',
185
+ fileEncSha256: '',
186
+ directPath: '',
187
+ mediaKeyTimestamp: unixTimestampSeconds(),
188
+ mimetype: 'image/jpeg'
189
+ }
190
+ });
191
+ }
192
+ break;
193
+ case RichSubMessageType.LATEX:
194
+ const expressions = submessage.latexMetadata.expressions;
195
+ for (let n = 0; n < expressions.length; n++) {
196
+ const expression = expressions[n];
197
+ mediaDetailsMetadataList.push({
198
+ id: randomBytes(32).toString('hex'),
199
+ previewMedia: {
200
+ fileSha256: '',
201
+ mediaKey: '',
202
+ fileEncSha256: '',
203
+ directPath: '',
204
+ mediaKeyTimestamp: unixTimestampSeconds(),
205
+ mimetype: 'image/jpeg'
206
+ }
207
+ });
208
+ }
209
+ break;
210
+ }
211
+ }
212
+ return { sources, mediaDetailsMetadataList };
213
+ }
214
+ export const prepareRichResponseMessage = (content) => {
215
+ const { code, contentText, expressions, footerText, headerText, items, language, richResponse, table, text, title } = content;
216
+ let submessages = [];
217
+ if (Array.isArray(richResponse)) {
218
+ submessages = richResponse.map((submessage) => {
219
+ if (submessage.text) {
220
+ return {
221
+ messageType: RichSubMessageType.TEXT,
222
+ messageText: submessage.text
223
+ };
224
+ }
225
+ else if (submessage.code) {
226
+ return {
227
+ messageType: RichSubMessageType.CODE,
228
+ codeMetadata: {
229
+ codeLanguage: submessage.language,
230
+ codeBlocks: submessage.code
231
+ }
232
+ };
233
+ }
234
+ else if (submessage.expressions) {
235
+ return {
236
+ messageType: RichSubMessageType.LATEX,
237
+ latexMetadata: {
238
+ text: submessage.text,
239
+ expressions: submessage.expressions
240
+ }
241
+ };
242
+ }
243
+ else if (submessage.items) {
244
+ return {
245
+ messageType: RichSubMessageType.CONTENT_ITEMS,
246
+ contentItemsMetadata: {
247
+ itemsMetadata: submessage.items
248
+ }
249
+ };
250
+ }
251
+ else if (submessage.table) {
252
+ return {
253
+ messageType: RichSubMessageType.TABLE,
254
+ tableMetadata: {
255
+ title: submessage.title,
256
+ rows: submessage.table
257
+ }
258
+ };
259
+ }
260
+ return submessage;
261
+ });
262
+ }
263
+ else {
264
+ if (headerText) {
265
+ submessages.push({
266
+ messageType: RichSubMessageType.TEXT,
267
+ messageText: headerText
268
+ });
269
+ }
270
+ if (contentText) {
271
+ submessages.push({
272
+ messageType: RichSubMessageType.TEXT,
273
+ messageText: contentText
274
+ });
275
+ }
276
+ if (code) {
277
+ language ??= 'javascript';
278
+ submessages.push({
279
+ messageType: RichSubMessageType.CODE,
280
+ codeMetadata: {
281
+ codeLanguage: language,
282
+ codeBlocks: tokenizeCode(code, language)
283
+ }
284
+ });
285
+ }
286
+ else if (expressions) {
287
+ submessages.push({
288
+ messageType: RichSubMessageType.LATEX,
289
+ latexMetadata: {
290
+ text,
291
+ expressions
292
+ }
293
+ });
294
+ }
295
+ else if (items) {
296
+ submessages.push({
297
+ messageType: RichSubMessageType.CONTENT_ITEMS,
298
+ contentItemsMetadata: {
299
+ itemsMetadata: items.map((item) => ({ reelItem: item })),
300
+ contentType: proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
301
+ }
302
+ });
303
+ }
304
+ else if (table) {
305
+ const tableRows = table.map((items, index) => ({
306
+ isHeading: index == 0,
307
+ items
308
+ }));
309
+ submessages.push({
310
+ messageType: RichSubMessageType.TABLE,
311
+ tableMetadata: {
312
+ title,
313
+ rows: tableRows
314
+ }
315
+ });
316
+ }
317
+ if (footerText) {
318
+ submessages.push({
319
+ messageType: RichSubMessageType.TEXT,
320
+ messageText: footerText
321
+ });
322
+ }
323
+ }
324
+ const unified = toUnified(submessages);
325
+ const message = wrapToBotForwardedMessage({
326
+ submessages,
327
+ messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
328
+ unifiedResponse: {
329
+ data: textEncoder.encode(JSON.stringify(unified))
330
+ },
331
+ contextInfo: {
332
+ isForwarded: true,
333
+ forwardingScore: 1,
334
+ forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
335
+ forwardOrigin: 4
336
+ }
337
+ });
338
+ // Boruto@Note 17-04-26 --- TODO: Fill mediaDetailsMetadataList and sources field
339
+ const { sources, mediaDetailsMetadataList } = buildAdditionalBotMetadataContext(submessages);
340
+ const botMetadata = message.messageContextInfo.botMetadata;
341
+ if (sources.length > 0) {
342
+ botMetadata.richResponseSourcesMetadata = { sources };
343
+ }
344
+ if (mediaDetailsMetadataList.length > 0) {
345
+ botMetadata.unifiedResponseMutation = { mediaDetailsMetadataList };
346
+ }
347
+ return message;
348
+ }
349
+ // Boruto@Note 17-04-26 --- signature and certificateChain for proofs[] field
350
+ export const botMetadataSignature = () => {
351
+ const signature = new Uint8Array(64);
352
+ getRandomValues(signature);
353
+ return signature;
354
+ }
355
+ export const botMetadataCertificate = (length = 700) => {
356
+ const certificate = new Uint8Array(length);
357
+ certificate[0] = 48;
358
+ certificate[1] = 130;
359
+ getRandomValues(certificate.subarray(2));
360
+ return certificate;
361
+ }
362
+ export const wrapToBotForwardedMessage = (richResponseMessage) =>
363
+ ({
364
+ messageContextInfo: {
365
+ botMetadata: {
366
+ pluginMetadata: {},
367
+ // Boruto@Note 09-04-26 --- TODO: Fill verificationMetadata field
368
+ verificationMetadata: {
369
+ proofs: [
370
+ {
371
+ certificateChain: [
372
+ botMetadataCertificate(684),
373
+ botMetadataCertificate(892)
374
+ ],
375
+ version: 1,
376
+ useCase: 1,
377
+ signature: botMetadataSignature()
378
+ }
379
+ ]
380
+ },
381
+ botRenderingConfigMetadata: BOT_RENDERING_CONFIG_METADATA
382
+ }
383
+ },
384
+ botForwardedMessage: {
385
+ message: { richResponseMessage }
386
+ }
387
+ });
@@ -3,7 +3,7 @@ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
3
3
  import { proto } from '../../WAProto/index.js';
4
4
  import { initAuthCreds } from './auth-utils.js';
5
5
  import { BufferJSON } from './generics.js';
6
- // Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
6
+ // Boruto@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
7
7
  const FLUSH_TIMEOUT_MS = 3000;
8
8
  export const useSingleFileAuthState = async (fileName) => {
9
9
  const cache = new Map();
@@ -112,7 +112,7 @@ export function binaryNodeToString(node, i = 0) {
112
112
  return tag + content;
113
113
  }
114
114
  /**
115
- * Lia@Changes 30-01-26
115
+ * Boruto@Changes 30-01-26
116
116
  * ---
117
117
  * Produce the binary node (WABinary-like JSON shape) required for the specific
118
118
  * interactive button / list type.
@@ -0,0 +1,13 @@
1
+ import makeWASocket from './Socket/index.js';
2
+ export * from '../WAProto/index.js';
3
+ export * from './Utils/index.js';
4
+ export * from './Types/index.js';
5
+ export * from './Defaults/index.js';
6
+ export * from './Store/index.js';
7
+ export * from './WABinary/index.js';
8
+ export * from './WAM/index.js';
9
+ export * from './WAUSync/index.js';
10
+ export { makeWASocket };
11
+ export default makeWASocket;
12
+ export { sayLog, inputLog, infoLog, successLog, errorLog, warningLog, debugLog, commandLog, connectLog, disconnectLog, loadLog, unloadLog, apiLog, dbLog, eventLog, scraperLog, cacheLog, authLog, rateLimitLog, startLog, shutdownLog } from './logger.js';
13
+ successLog("Baileys Mod by Eduh dev ☝️🤓");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boruto_vk7/baileys",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",
@@ -35,7 +35,7 @@
35
35
  "whatsapp-web"
36
36
  ],
37
37
  "homepage": "https://github.com/boruto_vk7/baileys#readme",
38
- "author": "Lia Wynn",
38
+ "author": "Boruto Wynn",
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
41
  "@adiwajshing/keyed-db": "^0.2.4",