@itsliaaa/baileys 0.1.19 → 0.1.20
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 +47 -3
- package/lib/Utils/messages.js +6 -3
- package/lib/Utils/rich-message-utils.js +108 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@itsliaaa/baileys)
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
+
A lightweight fork of Baileys with practical fixes and small but meaningful improvements.
|
|
7
|
+
<br><br>
|
|
6
8
|
<a href="https://www.npmjs.com/package/@itsliaaa/baileys">
|
|
7
9
|
<img src="https://img.shields.io/npm/v/@itsliaaa/baileys?color=FFFFFF&labelColor=red&logo=npm&logoColor=white&style=for-the-badge"/>
|
|
8
10
|
</a>
|
|
@@ -23,11 +25,11 @@
|
|
|
23
25
|
</a>
|
|
24
26
|
</p>
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
☕ For donation: [Saweria](https://saweria.co/itsliaaa)
|
|
27
29
|
|
|
28
30
|
### ✨ Highlights
|
|
29
31
|
|
|
30
|
-
This fork
|
|
32
|
+
This fork designed for production use with a focus on clarity and safety:
|
|
31
33
|
|
|
32
34
|
- 🚫 No obfuscation. Easy to read and audit.
|
|
33
35
|
- 🚫 No auto-follow channel (newsletter) behavior.
|
|
@@ -47,6 +49,7 @@ This fork focuses on clarity and safety:
|
|
|
47
49
|
- [group status messages](#4%EF%B8%8F⃣-group-status)
|
|
48
50
|
- [status mention messages](#%EF%B8%8F-status-mention)
|
|
49
51
|
- [sticker pack messages](#-sticker-pack)
|
|
52
|
+
- [rich response messages](#-rich-response)
|
|
50
53
|
- [messages with code blocks](#-message-with-code-block)
|
|
51
54
|
- [messages with tables](#-message-with-table)
|
|
52
55
|
- [payment-related messages](#-sending-payment-messages) (payment requests, invites, orders, invoices).
|
|
@@ -314,7 +317,7 @@ const vcard = 'BEGIN:VCARD\n'
|
|
|
314
317
|
|
|
315
318
|
sock.sendMessage(jid, {
|
|
316
319
|
contacts: {
|
|
317
|
-
displayName: 'Lia',
|
|
320
|
+
displayName: 'Lia Wynn',
|
|
318
321
|
contacts: [
|
|
319
322
|
{ vcard }
|
|
320
323
|
]
|
|
@@ -405,6 +408,47 @@ sock.sendMessage([jidA, jidB, jidC], {
|
|
|
405
408
|
})
|
|
406
409
|
```
|
|
407
410
|
|
|
411
|
+
##### ✨ Rich Response
|
|
412
|
+
|
|
413
|
+
> [!NOTE]
|
|
414
|
+
`richResponse[]` is a representation of [`submessages[]`](https://baileys.wiki/docs/api/namespaces/proto/interfaces/IAIRichResponseSubMessage) inside `richResponseMessage`.
|
|
415
|
+
|
|
416
|
+
> [!TIP]
|
|
417
|
+
You can still use the original [`submessages[]`](https://baileys.wiki/docs/api/namespaces/proto/interfaces/IAIRichResponseSubMessage) field directly.
|
|
418
|
+
> The code example below is just an implementation using a helper, not a required structure.
|
|
419
|
+
|
|
420
|
+
```javascript
|
|
421
|
+
sock.sendMessage(jid, {
|
|
422
|
+
richResponse: [{
|
|
423
|
+
text: 'Example Usage',
|
|
424
|
+
}, {
|
|
425
|
+
language: 'javascript',
|
|
426
|
+
code: [{
|
|
427
|
+
highlightType: 0,
|
|
428
|
+
codeContent: 'console.log("Hello, World!")'
|
|
429
|
+
}]
|
|
430
|
+
}, {
|
|
431
|
+
text: 'Pretty simple, right?\n'
|
|
432
|
+
}, {
|
|
433
|
+
text: 'Comparison between Node.js, Bun, and Deno',
|
|
434
|
+
}, {
|
|
435
|
+
title: 'Runtime Comparison',
|
|
436
|
+
table: [{
|
|
437
|
+
isHeading: true,
|
|
438
|
+
items: ['', 'Node.js', 'Bun', 'Deno']
|
|
439
|
+
}, {
|
|
440
|
+
isHeading: false,
|
|
441
|
+
items: ['Engine', 'V8 (C++)', 'JavaScriptCore (C++)', 'V8 (C++)']
|
|
442
|
+
}, {
|
|
443
|
+
isHeading: false,
|
|
444
|
+
items: ['Performance', '4/5', '5/5', '4/5']
|
|
445
|
+
}]
|
|
446
|
+
}, {
|
|
447
|
+
text: 'Does this help clarify the differences?'
|
|
448
|
+
}]
|
|
449
|
+
})
|
|
450
|
+
```
|
|
451
|
+
|
|
408
452
|
##### 🧾 Message with Code Block
|
|
409
453
|
|
|
410
454
|
```javascript
|
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 { prepareRichCodeBlock, 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',
|
|
@@ -1020,10 +1020,13 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1020
1020
|
}
|
|
1021
1021
|
// Lia@Changes 09-04-26 --- Add support for code block and table
|
|
1022
1022
|
else if (hasNonNullishProperty(message, 'code')) {
|
|
1023
|
-
m.richResponseMessage =
|
|
1023
|
+
m.richResponseMessage = prepareRichCodeBlock(message);
|
|
1024
1024
|
}
|
|
1025
1025
|
else if (hasNonNullishProperty(message, 'table')) {
|
|
1026
|
-
m.richResponseMessage =
|
|
1026
|
+
m.richResponseMessage = prepareRichTable(message);
|
|
1027
|
+
}
|
|
1028
|
+
else if (hasNonNullishProperty(message, 'richResponse')) {
|
|
1029
|
+
m.richResponseMessage = prepareRichResponseMessage(message.richResponse);
|
|
1027
1030
|
}
|
|
1028
1031
|
else {
|
|
1029
1032
|
m = await prepareWAMessageMedia(message, options);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Lia@Changes 09-04-26 [WIP]
|
|
3
|
-
*
|
|
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.
|
|
4
6
|
*/
|
|
7
|
+
import { randomUUID } from 'crypto';
|
|
5
8
|
import { FORWARDED_AI_BOT_INFO, LEXER_REGEX } from '../Defaults/index.js';
|
|
6
|
-
import { CodeHighlightType } from '../Types/RichType.js';
|
|
9
|
+
import { CodeHighlightType, RichSubMessageType } from '../Types/RichType.js';
|
|
10
|
+
const textEncoder = new TextEncoder();
|
|
7
11
|
const CPP_KEYWORDS = new Set([
|
|
8
12
|
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor', 'bool', 'break', 'case',
|
|
9
13
|
'catch', 'char', 'class', 'compl', 'concept', 'const', 'consteval', 'constexpr', 'constinit',
|
|
@@ -110,18 +114,46 @@ export const tokenizeCode = (code, language = 'javascript') => {
|
|
|
110
114
|
}
|
|
111
115
|
return blocks;
|
|
112
116
|
};
|
|
113
|
-
|
|
117
|
+
// 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) =>
|
|
114
119
|
({
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
response_id: randomUUID(),
|
|
121
|
+
sections: submessages.map((submessage) => {
|
|
122
|
+
switch (submessage.messageType) {
|
|
123
|
+
case RichSubMessageType.TEXT:
|
|
124
|
+
return {
|
|
125
|
+
view_model: {
|
|
126
|
+
primitive: { text: submessage.messageText, inline_entities: [], __typename: 'GenAIMarkdownTextUXPrimitive' },
|
|
127
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
case RichSubMessageType.TABLE:
|
|
131
|
+
return {
|
|
132
|
+
view_model: {
|
|
133
|
+
primitive: {
|
|
134
|
+
title: submessage.tableMetadata.title,
|
|
135
|
+
rows: submessage.tableMetadata.rows.map((row) => ({ is_header: row.isHeading, cells: row.items })),
|
|
136
|
+
__typename: 'GenATableUXPrimitive'
|
|
137
|
+
},
|
|
138
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
case RichSubMessageType.CODE:
|
|
142
|
+
return {
|
|
143
|
+
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
|
+
},
|
|
149
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
150
|
+
}
|
|
151
|
+
};
|
|
120
152
|
}
|
|
121
|
-
|
|
122
|
-
|
|
153
|
+
return submessage;
|
|
154
|
+
})
|
|
123
155
|
});
|
|
124
|
-
export const
|
|
156
|
+
export const prepareRichCodeBlock = ({ header, code, footer, language } = {}) => {
|
|
125
157
|
language ??= 'javascript'
|
|
126
158
|
const submessages = [];
|
|
127
159
|
if (header) {
|
|
@@ -143,13 +175,17 @@ export const generateRichCodeBlock = ({ header, code, footer, language } = {}) =
|
|
|
143
175
|
messageText: footer
|
|
144
176
|
});
|
|
145
177
|
}
|
|
146
|
-
|
|
178
|
+
const unified = toUnified(submessages);
|
|
179
|
+
return {
|
|
147
180
|
submessages,
|
|
148
181
|
messageType: 1,
|
|
182
|
+
unifiedResponse: {
|
|
183
|
+
data: textEncoder.encode(JSON.stringify(unified))
|
|
184
|
+
},
|
|
149
185
|
contextInfo: FORWARDED_AI_BOT_INFO
|
|
150
|
-
}
|
|
186
|
+
};
|
|
151
187
|
};
|
|
152
|
-
export const
|
|
188
|
+
export const prepareRichTable = ({ header, title, table, footer } = {}) => {
|
|
153
189
|
const tableRows = table.map((items, index) => ({
|
|
154
190
|
isHeading: index == 0,
|
|
155
191
|
items
|
|
@@ -174,9 +210,65 @@ export const generateRichTable = ({ header, title, table, footer } = {}) => {
|
|
|
174
210
|
messageText: footer
|
|
175
211
|
});
|
|
176
212
|
}
|
|
177
|
-
|
|
213
|
+
const unified = toUnified(submessages);
|
|
214
|
+
return {
|
|
178
215
|
submessages,
|
|
179
216
|
messageType: 1,
|
|
217
|
+
unifiedResponse: {
|
|
218
|
+
data: textEncoder.encode(JSON.stringify(unified))
|
|
219
|
+
},
|
|
180
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
|
+
};
|
|
230
|
+
}
|
|
231
|
+
else if (submessage.code) {
|
|
232
|
+
return {
|
|
233
|
+
messageType: 5,
|
|
234
|
+
codeMetadata: {
|
|
235
|
+
codeLanguage: submessage.language,
|
|
236
|
+
codeBlocks: submessage.code
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
else if (submessage.table) {
|
|
241
|
+
return {
|
|
242
|
+
messageType: 4,
|
|
243
|
+
tableMetadata: {
|
|
244
|
+
title: submessage.title,
|
|
245
|
+
rows: submessage.table
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return submessage;
|
|
181
250
|
});
|
|
182
|
-
|
|
251
|
+
const unified = toUnified(submessages);
|
|
252
|
+
return {
|
|
253
|
+
submessages,
|
|
254
|
+
messageType: 1,
|
|
255
|
+
unifiedResponse: {
|
|
256
|
+
data: textEncoder.encode(JSON.stringify(unified))
|
|
257
|
+
},
|
|
258
|
+
contextInfo: FORWARDED_AI_BOT_INFO
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export const wrapToBotForwardedMessage = (message) =>
|
|
262
|
+
({
|
|
263
|
+
messageContextInfo: {
|
|
264
|
+
botMetadata: {
|
|
265
|
+
// Lia@Note 09-04-26 --- TODO: Fill verificationMetadata field
|
|
266
|
+
verificationMetadata: {},
|
|
267
|
+
botRenderingConfigMetadata: {
|
|
268
|
+
bloksVersioningId: '0903aa5f7f47de66789d5f4c86d3bd6e05e4bc3ff85e454a9f907d5ed7fef97c',
|
|
269
|
+
pixelDensity: 2.75
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
botForwardedMessage: { message }
|
|
274
|
+
});
|