@pontalabs/baileys 1.1.10 → 1.2.1
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 +44 -0
- package/lib/Socket/messages-send.js +21 -3
- package/lib/Utils/mbuilder.d.ts +2 -0
- package/lib/Utils/mbuilder.js +18 -3
- package/lib/Utils/messages.js +1 -0
- package/lib/Utils/rich-message-utils.js +18 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -604,12 +604,34 @@ await sock.sendMessage(jid, {
|
|
|
604
604
|
|
|
605
605
|
Factory `build.rich*()` **tidak mengirim pesan sendiri**. Mereka hanya membuat item payload. Pengiriman tetap menggunakan API Baileys biasa: `sock.sendMessage()`.
|
|
606
606
|
|
|
607
|
+
#### ⏱️ Delay antar build
|
|
608
|
+
|
|
609
|
+
Kalau setiap item builder ingin dikirim sebagai **pesan terpisah**, gunakan `buildDelay` dalam milidetik:
|
|
610
|
+
|
|
611
|
+
```js
|
|
612
|
+
await sock.sendMessage(jid, {
|
|
613
|
+
items: [
|
|
614
|
+
build.richText('Build 1'),
|
|
615
|
+
build.richText('Build 2'),
|
|
616
|
+
build.richTip('Build 3')
|
|
617
|
+
],
|
|
618
|
+
buildDelay: 1000
|
|
619
|
+
})
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
Urutannya menjadi `Build 1 → tunggu 1 detik → Build 2 → tunggu 1 detik → Build 3`.
|
|
623
|
+
|
|
624
|
+
Tanpa `buildDelay`, perilaku `items` lama tetap dipakai: semua item digabung menjadi **satu Rich AI message**.
|
|
625
|
+
|
|
626
|
+
> `buildDelay` hanya berlaku untuk `items`. Nilai dalam milidetik harus lebih besar dari `0`.
|
|
627
|
+
|
|
607
628
|
#### ✨ Semua factory
|
|
608
629
|
|
|
609
630
|
| Factory | Contoh | Hasil |
|
|
610
631
|
| --- | --- | --- |
|
|
611
632
|
| `build.richText(text)` | `build.richText('Halo')` | Text |
|
|
612
633
|
| `build.richFOAText(text)` | `build.richFOAText('Halo')` | FOA text |
|
|
634
|
+
| `build.richHtml(html)` | `build.richHtml('<html>...</html>')` | HTML WebView |
|
|
613
635
|
| `build.richCode(code, language)` | `build.richCode('console.log(1)', 'javascript')` | Code |
|
|
614
636
|
| `build.richTable(table)` | `build.richTable([['A', 'B']])` | Table |
|
|
615
637
|
| `build.richSource(sources)` | `build.richSource([...])` | Sources |
|
|
@@ -639,6 +661,28 @@ await sock.sendMessage(jid, {
|
|
|
639
661
|
})
|
|
640
662
|
```
|
|
641
663
|
|
|
664
|
+
#### 🌐 HTML WebView
|
|
665
|
+
|
|
666
|
+
`build.richHtml()` membuat primitive HTML Rich AI seperti webview. HTML dikirim sebagai payload langsung ke primitive `GenAIaeacdsnwHtmlPrimitive`.
|
|
667
|
+
|
|
668
|
+
```js
|
|
669
|
+
const html = `<!DOCTYPE html>
|
|
670
|
+
<html>
|
|
671
|
+
<body style="margin:0;padding:20px;font-family:Arial">
|
|
672
|
+
<h2>🎮 Game Center</h2>
|
|
673
|
+
<button onclick="document.body.innerHTML += '<p>Clicked!</p>'">
|
|
674
|
+
Play
|
|
675
|
+
</button>
|
|
676
|
+
</body>
|
|
677
|
+
</html>`
|
|
678
|
+
|
|
679
|
+
await sock.sendMessage(jid, {
|
|
680
|
+
items: [build.richHtml(html)]
|
|
681
|
+
})
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
Karena HTML berjalan di sisi client/webview, gunakan HTML/JavaScript yang memang kamu kontrol dan sesuaikan dengan dukungan client WhatsApp yang dituju.
|
|
685
|
+
|
|
642
686
|
#### 🛠️ Builder untuk edit / delete
|
|
643
687
|
|
|
644
688
|
Untuk kebutuhan yang benar-benar membutuhkan state dan manipulasi node, gunakan `build.AIRich(sock)`.
|
|
@@ -155,7 +155,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
155
155
|
return null;
|
|
156
156
|
}
|
|
157
157
|
jid = jidNormalizedUser(jid);
|
|
158
|
-
|
|
158
|
+
let sendMessage;
|
|
159
|
+
return { jid, user };
|
|
159
160
|
})
|
|
160
161
|
.filter(jid => jid !== null);
|
|
161
162
|
let mgetDevices;
|
|
@@ -1126,8 +1127,25 @@ export const makeMessagesSocket = (config) => {
|
|
|
1126
1127
|
}
|
|
1127
1128
|
return album;
|
|
1128
1129
|
},
|
|
1129
|
-
sendMessage: async (jid, content, options = {}) => {
|
|
1130
|
+
sendMessage: (sendMessage = async (jid, content, options = {}) => {
|
|
1130
1131
|
const userJid = authState.creds.me.id;
|
|
1132
|
+
|
|
1133
|
+
// `buildDelay` sends each item in `content.items` as its own Rich AI
|
|
1134
|
+
// message, waiting between items. Without buildDelay, the existing
|
|
1135
|
+
// mixed-items behavior is unchanged (all items are one Rich AI message).
|
|
1136
|
+
if (content && !Array.isArray(jid) && Array.isArray(content.items) && content.items.length > 1) {
|
|
1137
|
+
const buildDelay = Number(options.buildDelay ?? content.buildDelay ?? 0);
|
|
1138
|
+
if (Number.isFinite(buildDelay) && buildDelay > 0) {
|
|
1139
|
+
const sendOptions = { ...options };
|
|
1140
|
+
delete sendOptions.buildDelay;
|
|
1141
|
+
const results = [];
|
|
1142
|
+
for (let index = 0; index < content.items.length; index++) {
|
|
1143
|
+
if (index > 0) await delay(buildDelay);
|
|
1144
|
+
results.push(await sendMessage(jid, content.items[index], sendOptions));
|
|
1145
|
+
}
|
|
1146
|
+
return results;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1131
1149
|
// Update rahmi's userJid in case it changed after login
|
|
1132
1150
|
if (rahmi && userJid) rahmi.userJid = userJid;
|
|
1133
1151
|
if (Array.isArray(jid)) {
|
|
@@ -1400,7 +1418,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1400
1418
|
}
|
|
1401
1419
|
return fullMsg;
|
|
1402
1420
|
}
|
|
1403
|
-
},
|
|
1421
|
+
}),
|
|
1404
1422
|
sendTable: async (jid, title, headers, rows, quoted, options = {}) => {
|
|
1405
1423
|
const { message, messageId } = generateTableContent(title, headers, rows, quoted, options);
|
|
1406
1424
|
await relayMessage(jid, message, { messageId });
|
package/lib/Utils/mbuilder.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class AIRich {
|
|
|
12
12
|
createAlert(type: any): any;
|
|
13
13
|
addText(text: string, options?: any): this;
|
|
14
14
|
addFOAText(text: string, options?: any): this;
|
|
15
|
+
addHtml(html: string, options?: any): this;
|
|
15
16
|
addCode(language: string, code: string, options?: any): this;
|
|
16
17
|
addTable(table: any, options?: any): this;
|
|
17
18
|
addSource(sources?: any[], options?: any): this;
|
|
@@ -39,6 +40,7 @@ export declare const build: {
|
|
|
39
40
|
AIRich: (client: any, options?: any) => AIRich;
|
|
40
41
|
richText: (text: string) => any;
|
|
41
42
|
richFOAText: (text: string) => any;
|
|
43
|
+
richHtml: (html: string) => any;
|
|
42
44
|
richCode: (code: string, language?: string) => any;
|
|
43
45
|
richTable: (table: any) => any;
|
|
44
46
|
richSource: (sources: any) => any;
|
package/lib/Utils/mbuilder.js
CHANGED
|
@@ -1333,6 +1333,22 @@ class AIRich extends BaseBuilder {
|
|
|
1333
1333
|
});
|
|
1334
1334
|
}
|
|
1335
1335
|
|
|
1336
|
+
addHtml(html, { id, replace, insertAt } = {}) {
|
|
1337
|
+
if (typeof html !== 'string') throw new TypeError('HTML must be a string');
|
|
1338
|
+
const section = {
|
|
1339
|
+
view_model: {
|
|
1340
|
+
primitive: {
|
|
1341
|
+
__typename: 'GenAIaeacdsnwHtmlPrimitive',
|
|
1342
|
+
payload: html,
|
|
1343
|
+
trusted_sources: []
|
|
1344
|
+
},
|
|
1345
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
const submessage = this.createAlert('GenAIaeacdsnwHtmlPrimitive');
|
|
1349
|
+
return this._addContent(section, submessage, { id, replace, insertAt });
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1336
1352
|
addFOAText(text, { id, replace, insertAt } = {}) {
|
|
1337
1353
|
if (typeof text !== 'string') {
|
|
1338
1354
|
throw new TypeError('Text must be a string');
|
|
@@ -3204,8 +3220,7 @@ const build = {
|
|
|
3204
3220
|
|
|
3205
3221
|
// Expose the namespace globally so applications can use build.* without
|
|
3206
3222
|
// importing another symbol. The named export remains available as well.
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
}
|
|
3223
|
+
// Always refresh the global namespace so newly added builder methods are available.
|
|
3224
|
+
globalThis.build = build;
|
|
3210
3225
|
|
|
3211
3226
|
export { VERSION, Button, ButtonV2, Carousel, AIRich, Toolkit, build };
|
package/lib/Utils/messages.js
CHANGED
|
@@ -595,6 +595,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
595
595
|
hasNonNullishProperty(message, 'footerAction') ||
|
|
596
596
|
hasNonNullishProperty(message, 'metadata') ||
|
|
597
597
|
hasNonNullishProperty(message, 'foaText') ||
|
|
598
|
+
hasNonNullishProperty(message, 'richHtml') ||
|
|
598
599
|
hasNonNullishProperty(message, 'contentText')) {
|
|
599
600
|
m = prepareRichResponseMessage(message);
|
|
600
601
|
}
|
|
@@ -775,6 +775,20 @@ const makeMetadataSub = (text, typename = 'GenAIMetadataTextPrimitive', prefix =
|
|
|
775
775
|
sub: { messageType: RichSubMessageType.TEXT, messageText: text },
|
|
776
776
|
section: { view_model: { primitive: { text: prefix + text, __typename: typename }, __typename: 'GenAISingleLayoutViewModel' } }
|
|
777
777
|
});
|
|
778
|
+
/** Rich HTML WebView primitive. The HTML is rendered as a trusted Rich AI webview payload. */
|
|
779
|
+
const makeHtmlSection = (html) => {
|
|
780
|
+
if (typeof html !== 'string') throw new TypeError('HTML must be a string');
|
|
781
|
+
return {
|
|
782
|
+
view_model: {
|
|
783
|
+
primitive: {
|
|
784
|
+
__typename: 'GenAIaeacdsnwHtmlPrimitive',
|
|
785
|
+
payload: html,
|
|
786
|
+
trusted_sources: []
|
|
787
|
+
},
|
|
788
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
};
|
|
778
792
|
const makeWidgetSection = (data) => {
|
|
779
793
|
const items = Array.isArray(data) ? data : [data];
|
|
780
794
|
const widgets = items.map(item => ({
|
|
@@ -825,7 +839,7 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
825
839
|
map: mapContent, latex, contentItems,
|
|
826
840
|
// sub-types baru (prefixed 'rich' agar tidak konflik dengan media biasa)
|
|
827
841
|
richImage, richVideo, reels, source, richProduct, richPost, tip, suggest,
|
|
828
|
-
richWidget, widget, richFooterAction, footerAction, richMetadata, metadata, richFOAText, foaText,
|
|
842
|
+
richWidget, widget, richFooterAction, footerAction, richMetadata, metadata, richFOAText, foaText, richHtml,
|
|
829
843
|
// opsi tambahan (belum ada di versi ponta.zip semula)
|
|
830
844
|
aiForwarded
|
|
831
845
|
} = content;
|
|
@@ -914,6 +928,7 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
914
928
|
if (sub.footerAction != null) return push(null, makeFooterActionSection(sub.footerAction));
|
|
915
929
|
if (sub.metadata != null) { const built = makeMetadataSub(sub.metadata); return push(built.sub, built.section); }
|
|
916
930
|
if (sub.foaText != null) { const built = makeMetadataSub(sub.foaText, 'FOATextPrimitive'); return push(built.sub, built.section); }
|
|
931
|
+
if (sub.richHtml != null) return push(null, makeHtmlSection(sub.richHtml));
|
|
917
932
|
// passthrough — kalau sudah bentuk proto submessage manual
|
|
918
933
|
return push(sub, buildUnifiedSection(sub));
|
|
919
934
|
};
|
|
@@ -951,6 +966,7 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
951
966
|
if (richFooterAction ?? footerAction) buildOne({ footerAction: richFooterAction ?? footerAction });
|
|
952
967
|
if (richMetadata ?? metadata) buildOne({ metadata: richMetadata ?? metadata });
|
|
953
968
|
if (richFOAText ?? foaText) buildOne({ foaText: richFOAText ?? foaText });
|
|
969
|
+
if (richHtml != null) buildOne({ richHtml });
|
|
954
970
|
|
|
955
971
|
/* links — bisa dikombinasi dengan tipe lain di atas */
|
|
956
972
|
if (links && Array.isArray(links)) {
|
|
@@ -1521,6 +1537,7 @@ const translateReadmeItem = (item) => {
|
|
|
1521
1537
|
// directly to sendMessage({ items: [...] }).
|
|
1522
1538
|
if (item.richText != null) { out.text = item.richText; }
|
|
1523
1539
|
if (item.richFOAText != null) { out.foaText = item.richFOAText; }
|
|
1540
|
+
if (item.richHtml != null) { out.richHtml = item.richHtml; }
|
|
1524
1541
|
if (item.richCode != null) { out.code = item.richCode; out.language = item.language; }
|
|
1525
1542
|
if (item.richTable != null) { out.table = item.richTable; }
|
|
1526
1543
|
if (item.richSource != null) { out.source = item.richSource; }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pontalabs/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"description": "PontaLabs Baileys is a lightweight, modern, and customizable WhatsApp Web API library built on Baileys.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@eslint/eslintrc": "^3.3.1",
|
|
62
62
|
"@eslint/js": "^9.31.0",
|
|
63
63
|
"@types/jest": "^30.0.0",
|
|
64
|
-
"@types/node": "^20.
|
|
64
|
+
"@types/node": "^20.0.0",
|
|
65
65
|
"@types/ws": "^8.0.0",
|
|
66
66
|
"@typescript-eslint/eslint-plugin": "^8",
|
|
67
67
|
"@typescript-eslint/parser": "^8",
|