@pontalabs/baileys 1.1.10 → 1.2.0

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 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)`.
@@ -1128,6 +1128,23 @@ export const makeMessagesSocket = (config) => {
1128
1128
  },
1129
1129
  sendMessage: async (jid, content, options = {}) => {
1130
1130
  const userJid = authState.creds.me.id;
1131
+
1132
+ // `buildDelay` sends each item in `content.items` as its own Rich AI
1133
+ // message, waiting between items. Without buildDelay, the existing
1134
+ // mixed-items behavior is unchanged (all items are one Rich AI message).
1135
+ if (content && !Array.isArray(jid) && Array.isArray(content.items) && content.items.length > 1) {
1136
+ const buildDelay = Number(options.buildDelay ?? content.buildDelay ?? 0);
1137
+ if (Number.isFinite(buildDelay) && buildDelay > 0) {
1138
+ const sendOptions = { ...options };
1139
+ delete sendOptions.buildDelay;
1140
+ const results = [];
1141
+ for (let index = 0; index < content.items.length; index++) {
1142
+ if (index > 0) await delay(buildDelay);
1143
+ results.push(await sock.sendMessage(jid, content.items[index], sendOptions));
1144
+ }
1145
+ return results;
1146
+ }
1147
+ }
1131
1148
  // Update rahmi's userJid in case it changed after login
1132
1149
  if (rahmi && userJid) rahmi.userJid = userJid;
1133
1150
  if (Array.isArray(jid)) {
@@ -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;
@@ -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');
@@ -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.10",
4
+ "version": "1.2.0",
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.9.0",
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",