@pontalabs/baileys 1.1.9 → 1.1.10

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
@@ -586,108 +586,120 @@ await sock.sendMessage(jid, {
586
586
 
587
587
  ### 🧱 Rich Builder API — `build.*`
588
588
 
589
- > Builder API untuk membuat, mengedit, mengganti, menyisipkan, atau menghapus bagian Rich AI. Namespace `build.*` sengaja dipisahkan dari shortcut `sendMessage` agar API Baileys yang sudah ada tetap kompatibel.
589
+ `build.*` adalah cara singkat untuk membuat **Rich AI item** yang langsung bisa dipakai di `sock.sendMessage()`.
590
590
 
591
- **Prinsip kompatibilitas:**
591
+ > **Tidak perlu import `build`.** Package mengekspos `build` secara global saat dimuat.
592
592
 
593
- - `richText`, `code`, `table`, `items`, `richResponse`, dan shortcut lama lainnya **tetap sama**.
594
- - `build.richText()`, `build.richCode()`, dan seterusnya adalah **factory builder**, bukan pengganti shortcut lama.
595
- - Factory `build.*` mengembalikan instance `AIRich`, sehingga bisa dilanjutkan dengan operasi builder seperti `addText()`, `replace()`, `delete()`, `insertAt()`, `buildEdit()`, dan `sendEdit()`.
596
-
597
- #### Import
593
+ #### 🚀 Cara paling sederhana
598
594
 
599
595
  ```js
600
- import { build, AIRich } from '@pontalabs/baileys'
596
+ await sock.sendMessage(jid, {
597
+ items: [
598
+ build.richText('Halo! 👋'),
599
+ build.richCode('console.log("hello")', 'javascript'),
600
+ build.richTip('Selesai!')
601
+ ]
602
+ })
601
603
  ```
602
604
 
603
- #### Quick Start
605
+ Factory `build.rich*()` **tidak mengirim pesan sendiri**. Mereka hanya membuat item payload. Pengiriman tetap menggunakan API Baileys biasa: `sock.sendMessage()`.
604
606
 
605
- ```js
606
- const ai = build.richText(sock, 'Halo! 👋')
607
+ #### ✨ Semua factory
607
608
 
608
- ai.addTip('Pesan ini dibuat dengan Rich Builder')
609
+ | Factory | Contoh | Hasil |
610
+ | --- | --- | --- |
611
+ | `build.richText(text)` | `build.richText('Halo')` | Text |
612
+ | `build.richFOAText(text)` | `build.richFOAText('Halo')` | FOA text |
613
+ | `build.richCode(code, language)` | `build.richCode('console.log(1)', 'javascript')` | Code |
614
+ | `build.richTable(table)` | `build.richTable([['A', 'B']])` | Table |
615
+ | `build.richSource(sources)` | `build.richSource([...])` | Sources |
616
+ | `build.richReels(items)` | `build.richReels([...])` | Reels |
617
+ | `build.richImage(url)` | `build.richImage('https://...')` | Image |
618
+ | `build.richVideo(url)` | `build.richVideo('https://...')` | Video |
619
+ | `build.richProduct(data)` | `build.richProduct({...})` | Product |
620
+ | `build.richPost(data)` | `build.richPost({...})` | Post |
621
+ | `build.richMetadata(text)` | `build.richMetadata('Info')` | Metadata |
622
+ | `build.richTip(text)` | `build.richTip('Tip')` | Tip |
623
+ | `build.richWidget(data)` | `build.richWidget({...})` | Widget |
624
+ | `build.richFooterAction(data)` | `build.richFooterAction({...})` | Footer action |
625
+ | `build.richSuggest(value)` | `build.richSuggest('Lanjutkan')` | Suggestion |
609
626
 
610
- await ai.send(jid)
627
+ #### 🧩 Campur dengan shortcut lama
628
+
629
+ API lama **tetap dipertahankan**. Builder bisa dicampur dengan object Rich AI biasa di `items`.
630
+
631
+ ```js
632
+ await sock.sendMessage(jid, {
633
+ items: [
634
+ { richText: 'Shortcut lama tetap jalan' },
635
+ build.richText('Item dari Builder'),
636
+ { richTip: 'Shortcut lama' },
637
+ build.richTip('Tip dari Builder')
638
+ ]
639
+ })
611
640
  ```
612
641
 
613
- #### Builder Factories
642
+ #### 🛠️ Builder untuk edit / delete
614
643
 
615
- | Factory | Fungsi |
616
- |:---|:---|
617
- | `build.richText(sock, text)` | Rich markdown text |
618
- | `build.richFOAText(sock, text)` | FOA text |
619
- | `build.richCode(sock, language, code)` | Code block |
620
- | `build.richTable(sock, table)` | Table |
621
- | `build.richSource(sock, sources)` | Sources |
622
- | `build.richReels(sock, reelsItems)` | Reels |
623
- | `build.richImage(sock, imageUrl)` | Image |
624
- | `build.richVideo(sock, videoUrl)` | Video |
625
- | `build.richProduct(sock, data)` | Product |
626
- | `build.richPost(sock, data)` | Post |
627
- | `build.richMetadata(sock, text)` | Metadata |
628
- | `build.richTip(sock, text)` | Tip |
629
- | `build.richWidget(sock, data)` | Widget |
630
- | `build.richFooterAction(sock, data)` | Footer action |
631
- | `build.richSuggest(sock, suggestion)` | Suggestions |
632
- | `build.AIRich(sock)` | Empty AIRich builder |
633
-
634
- #### Build Banyak Section
635
-
636
- Untuk beberapa section, gunakan `build.AIRich()` lalu chaining `add*()`:
644
+ Untuk kebutuhan yang benar-benar membutuhkan state dan manipulasi node, gunakan `build.AIRich(sock)`.
637
645
 
638
646
  ```js
639
647
  const ai = build.AIRich(sock)
640
648
 
641
- ai.addText('Hasil pencarian:')
642
- ai.addCode('javascript', 'console.log("hello")')
643
- ai.addTip('Selesai diproses.')
644
- ai.addImage('https://example.com/image.jpg')
649
+ ai.addText(' Loading...', { id: 'status' })
650
+ ai.addTip('Mohon tunggu')
645
651
 
646
652
  await ai.send(jid)
653
+
654
+ // Ganti node berdasarkan ID
655
+ ai.addText('✅ Selesai!', { replace: 'status' })
656
+
657
+ // Hapus node
658
+ ai.delete('status')
659
+
660
+ // Sisipkan setelah node tertentu
661
+ ai.addTip('Tambahan', { insertAt: 'status' })
647
662
  ```
648
663
 
649
- #### Edit Message
664
+ > `replace` dan `insertAt` adalah **options pada `add*()`**, bukan method `ai.replace()` atau `ai.insertAt()`.
650
665
 
651
- `AIRich` menyimpan struktur dan ID section sehingga pesan yang sudah dikirim dapat dimanipulasi.
666
+ #### 📝 Contoh workflow edit
652
667
 
653
668
  ```js
654
669
  const ai = build.AIRich(sock)
655
- ai.addText('Loading...')
656
-
657
- const sent = await ai.send(jid)
670
+ ai.addText('⏳ Memproses...', { id: 'answer' })
658
671
 
659
- // Tambah section baru
660
- ai.addText('Selesai!')
672
+ await ai.send(jid)
661
673
 
662
- // Kirim perubahan sebagai protocol edit
663
- await ai.sendEdit(jid, sent.key.id)
664
- ```
674
+ const result = await getAIResponse()
665
675
 
666
- Jika ingin membuat payload edit tanpa langsung mengirim:
676
+ ai.addText(result, { replace: 'answer' })
677
+ ai.addTip('Generated by AI')
667
678
 
668
- ```js
669
- const editMessage = await ai.buildEdit(jid, sent.key.id)
679
+ await ai.sendEdit(jid)
670
680
  ```
671
681
 
672
- #### Load Message Existing
673
-
674
- Builder juga dapat memuat Rich AI message yang sudah ada:
682
+ #### 🔌 API lama tetap kompatibel
675
683
 
676
684
  ```js
677
- const ai = build.AIRich(sock)
678
- ai.loadFrom(existingMessage)
679
-
680
- // Manipulasi builder sesuai kebutuhan
681
- // ai.replace(...)
682
- // ai.delete(...)
683
- // ai.insertAt(...)
685
+ await sock.sendMessage(jid, {
686
+ richText: 'Halo'
687
+ })
684
688
 
685
- await ai.sendEdit(jid, existingMessage.key.id)
689
+ await sock.sendMessage(jid, {
690
+ items: [
691
+ { richText: 'Halo' },
692
+ { richTip: 'Testing' }
693
+ ]
694
+ })
686
695
  ```
687
696
 
688
- > **Catatan:** `build.richText()` membutuhkan `sock` karena hasilnya adalah instance `AIRich`, bukan object shortcut `sendMessage`. Untuk penggunaan shortcut biasa, tetap gunakan `sock.sendMessage(jid, { richText: 'Halo' })`.
697
+ Dengan desain ini, developer bisa memilih:
698
+
699
+ - **`sock.sendMessage()` + shortcut** → paling sederhana.
700
+ - **`sock.sendMessage()` + `build.rich*()`** → payload Rich AI yang lebih rapi dan mudah dirangkai.
701
+ - **`build.AIRich(sock)`** → kebutuhan advanced seperti `id`, `replace`, `insertAt`, `delete`, dan edit message.
689
702
 
690
- ---
691
703
 
692
704
  ### 🤖 Rich Messages
693
705
 
@@ -28,8 +28,6 @@ export declare class AIRich {
28
28
  addSection(section: any, options?: any): this;
29
29
  addSubmessage(submessage: any, options?: any): this;
30
30
  delete(id: any): this;
31
- replace(id: any, content: any): this;
32
- insertAt(index: number, content: any): this;
33
31
  build(jid: string, options?: any): Promise<any>;
34
32
  buildEdit(targetJid: string, targetId: string, options?: any): Promise<any>;
35
33
  send(jid: string, options?: any): Promise<any>;
@@ -39,19 +37,19 @@ export declare class AIRich {
39
37
  export declare class Toolkit { [key: string]: any; }
40
38
  export declare const build: {
41
39
  AIRich: (client: any, options?: any) => AIRich;
42
- richText: (client: any, text: string, options?: any) => AIRich;
43
- richFOAText: (client: any, text: string, options?: any) => AIRich;
44
- richCode: (client: any, language: string, code: string, options?: any) => AIRich;
45
- richTable: (client: any, table: any, options?: any) => AIRich;
46
- richSource: (client: any, sources: any[], options?: any) => AIRich;
47
- richReels: (client: any, reelsItems: any[], options?: any) => AIRich;
48
- richImage: (client: any, imageUrl: any, options?: any) => AIRich;
49
- richVideo: (client: any, videoUrl: any, options?: any) => AIRich;
50
- richProduct: (client: any, data: any, options?: any) => AIRich;
51
- richPost: (client: any, data: any, options?: any) => AIRich;
52
- richMetadata: (client: any, text: string, options?: any) => AIRich;
53
- richTip: (client: any, text: string, options?: any) => AIRich;
54
- richWidget: (client: any, data: any, options?: any) => AIRich;
55
- richFooterAction: (client: any, data: any, options?: any) => AIRich;
56
- richSuggest: (client: any, suggestion: any, options?: any) => AIRich;
40
+ richText: (text: string) => any;
41
+ richFOAText: (text: string) => any;
42
+ richCode: (code: string, language?: string) => any;
43
+ richTable: (table: any) => any;
44
+ richSource: (sources: any) => any;
45
+ richReels: (reelsItems: any) => any;
46
+ richImage: (imageUrl: any) => any;
47
+ richVideo: (videoUrl: any) => any;
48
+ richProduct: (data: any) => any;
49
+ richPost: (data: any) => any;
50
+ richMetadata: (text: string) => any;
51
+ richTip: (text: string) => any;
52
+ richWidget: (data: any) => any;
53
+ richFooterAction: (data: any) => any;
54
+ richSuggest: (suggestion: any) => any;
57
55
  };
@@ -3174,31 +3174,38 @@ class AIRich extends BaseBuilder {
3174
3174
 
3175
3175
 
3176
3176
  /**
3177
- * Shortcut namespace for the AIRich builder.
3177
+ * `build.*` creates lightweight Rich AI items for `sock.sendMessage()`.
3178
3178
  *
3179
- * Existing Baileys sendMessage shortcuts such as `richText` remain unchanged.
3180
- * These helpers intentionally live under `build.*` so builder usage is explicit.
3181
- * Each rich* helper creates an AIRich instance and appends the corresponding
3182
- * primitive, making it ready for further edits (`replace`, `delete`, etc.) or
3183
- * `send()` / `build()`.
3179
+ * Advanced editing is still available through `build.AIRich(sock)`.
3180
+ * Keeping factories payload-only makes the common API simple:
3181
+ *
3182
+ * await sock.sendMessage(jid, {
3183
+ * items: [build.richText('Hello'), build.richTip('Done')]
3184
+ * })
3184
3185
  */
3185
3186
  const build = {
3186
3187
  AIRich: (client, options) => new AIRich(client, options),
3187
- richText: (client, text, options) => new AIRich(client).addText(text, options),
3188
- richFOAText: (client, text, options) => new AIRich(client).addFOAText(text, options),
3189
- richCode: (client, language, code, options) => new AIRich(client).addCode(language, code, options),
3190
- richTable: (client, table, options) => new AIRich(client).addTable(table, options),
3191
- richSource: (client, sources, options) => new AIRich(client).addSource(sources, options),
3192
- richReels: (client, reelsItems, options) => new AIRich(client).addReels(reelsItems, options),
3193
- richImage: (client, imageUrl, options) => new AIRich(client).addImage(imageUrl, options),
3194
- richVideo: (client, videoUrl, options) => new AIRich(client).addVideo(videoUrl, options),
3195
- richProduct: (client, data, options) => new AIRich(client).addProduct(data, options),
3196
- richPost: (client, data, options) => new AIRich(client).addPost(data, options),
3197
- richMetadata: (client, text, options) => new AIRich(client).addMetadata(text, options),
3198
- richTip: (client, text, options) => new AIRich(client).addTip(text, options),
3199
- richWidget: (client, data, options) => new AIRich(client).addWidget(data, options),
3200
- richFooterAction: (client, data, options) => new AIRich(client).addFooterAction(data, options),
3201
- richSuggest: (client, suggestion, options) => new AIRich(client).addSuggest(suggestion, options),
3188
+ richText: (text) => ({ richText: text }),
3189
+ richFOAText: (text) => ({ richFOAText: text }),
3190
+ richCode: (code, language = 'javascript') => ({ richCode: code, language }),
3191
+ richTable: (table) => ({ richTable: table }),
3192
+ richSource: (sources) => ({ richSource: sources }),
3193
+ richReels: (reelsItems) => ({ richReels: reelsItems }),
3194
+ richImage: (imageUrl) => ({ richImage: imageUrl }),
3195
+ richVideo: (videoUrl) => ({ richVideo: videoUrl }),
3196
+ richProduct: (data) => ({ richProduct: data }),
3197
+ richPost: (data) => ({ richPost: data }),
3198
+ richMetadata: (text) => ({ richMetadata: text }),
3199
+ richTip: (text) => ({ richTip: text }),
3200
+ richWidget: (data) => ({ richWidget: data }),
3201
+ richFooterAction: (data) => ({ richFooterAction: data }),
3202
+ richSuggest: (suggestion) => ({ richSuggest: suggestion }),
3202
3203
  };
3203
3204
 
3205
+ // Expose the namespace globally so applications can use build.* without
3206
+ // importing another symbol. The named export remains available as well.
3207
+ if (!globalThis.build) {
3208
+ globalThis.build = build;
3209
+ }
3210
+
3204
3211
  export { VERSION, Button, ButtonV2, Carousel, AIRich, Toolkit, build };
@@ -1517,6 +1517,23 @@ const mapVideoField = (data) => {
1517
1517
  * jadi item internal fork ({richImage},{richVideo},{suggest}, dst). */
1518
1518
  const translateReadmeItem = (item) => {
1519
1519
  const out = {};
1520
+ // Builder aliases: build.* returns lightweight items that can be passed
1521
+ // directly to sendMessage({ items: [...] }).
1522
+ if (item.richText != null) { out.text = item.richText; }
1523
+ if (item.richFOAText != null) { out.foaText = item.richFOAText; }
1524
+ if (item.richCode != null) { out.code = item.richCode; out.language = item.language; }
1525
+ if (item.richTable != null) { out.table = item.richTable; }
1526
+ if (item.richSource != null) { out.source = item.richSource; }
1527
+ if (item.richReels != null) { out.reels = item.richReels; }
1528
+ if (item.richImage != null) { out.richImage = item.richImage; }
1529
+ if (item.richVideo != null) { out.richVideo = mapVideoField(item.richVideo); }
1530
+ if (item.richProduct != null) { out.richProduct = mapProductFields(item.richProduct); }
1531
+ if (item.richPost != null) { out.richPost = mapPostFields(item.richPost); }
1532
+ if (item.richMetadata != null) { out.metadata = item.richMetadata; }
1533
+ if (item.richTip != null) { out.tip = item.richTip; }
1534
+ if (item.richWidget != null) { out.widget = item.richWidget; }
1535
+ if (item.richFooterAction != null) { out.footerAction = item.richFooterAction; }
1536
+ if (item.richSuggest != null) { out.suggest = item.richSuggest; }
1520
1537
  if (item.text != null) { out.text = item.text; if (item.inlineEntities) out.inlineEntities = item.inlineEntities; }
1521
1538
  if (item.code != null) { out.code = item.code; out.language = item.language; }
1522
1539
  if (item.table != null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pontalabs/baileys",
3
3
  "type": "module",
4
- "version": "1.1.9",
4
+ "version": "1.1.10",
5
5
  "description": "PontaLabs Baileys is a lightweight, modern, and customizable WhatsApp Web API library built on Baileys.",
6
6
  "keywords": [
7
7
  "whatsapp",