@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 +78 -66
- package/lib/Utils/mbuilder.d.ts +15 -17
- package/lib/Utils/mbuilder.js +28 -21
- package/lib/Utils/rich-message-utils.js +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -586,108 +586,120 @@ await sock.sendMessage(jid, {
|
|
|
586
586
|
|
|
587
587
|
### 🧱 Rich Builder API — `build.*`
|
|
588
588
|
|
|
589
|
-
|
|
589
|
+
`build.*` adalah cara singkat untuk membuat **Rich AI item** yang langsung bisa dipakai di `sock.sendMessage()`.
|
|
590
590
|
|
|
591
|
-
**
|
|
591
|
+
> **Tidak perlu import `build`.** Package mengekspos `build` secara global saat dimuat.
|
|
592
592
|
|
|
593
|
-
|
|
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
|
-
|
|
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
|
-
|
|
605
|
+
Factory `build.rich*()` **tidak mengirim pesan sendiri**. Mereka hanya membuat item payload. Pengiriman tetap menggunakan API Baileys biasa: `sock.sendMessage()`.
|
|
604
606
|
|
|
605
|
-
|
|
606
|
-
const ai = build.richText(sock, 'Halo! 👋')
|
|
607
|
+
#### ✨ Semua factory
|
|
607
608
|
|
|
608
|
-
|
|
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
|
-
|
|
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
|
|
642
|
+
#### 🛠️ Builder untuk edit / delete
|
|
614
643
|
|
|
615
|
-
|
|
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('
|
|
642
|
-
ai.
|
|
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
|
-
|
|
664
|
+
> `replace` dan `insertAt` adalah **options pada `add*()`**, bukan method `ai.replace()` atau `ai.insertAt()`.
|
|
650
665
|
|
|
651
|
-
|
|
666
|
+
#### 📝 Contoh workflow edit
|
|
652
667
|
|
|
653
668
|
```js
|
|
654
669
|
const ai = build.AIRich(sock)
|
|
655
|
-
ai.addText('
|
|
656
|
-
|
|
657
|
-
const sent = await ai.send(jid)
|
|
670
|
+
ai.addText('⏳ Memproses...', { id: 'answer' })
|
|
658
671
|
|
|
659
|
-
|
|
660
|
-
ai.addText('Selesai!')
|
|
672
|
+
await ai.send(jid)
|
|
661
673
|
|
|
662
|
-
|
|
663
|
-
await ai.sendEdit(jid, sent.key.id)
|
|
664
|
-
```
|
|
674
|
+
const result = await getAIResponse()
|
|
665
675
|
|
|
666
|
-
|
|
676
|
+
ai.addText(result, { replace: 'answer' })
|
|
677
|
+
ai.addTip('Generated by AI')
|
|
667
678
|
|
|
668
|
-
|
|
669
|
-
const editMessage = await ai.buildEdit(jid, sent.key.id)
|
|
679
|
+
await ai.sendEdit(jid)
|
|
670
680
|
```
|
|
671
681
|
|
|
672
|
-
####
|
|
673
|
-
|
|
674
|
-
Builder juga dapat memuat Rich AI message yang sudah ada:
|
|
682
|
+
#### 🔌 API lama tetap kompatibel
|
|
675
683
|
|
|
676
684
|
```js
|
|
677
|
-
|
|
678
|
-
|
|
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
|
|
689
|
+
await sock.sendMessage(jid, {
|
|
690
|
+
items: [
|
|
691
|
+
{ richText: 'Halo' },
|
|
692
|
+
{ richTip: 'Testing' }
|
|
693
|
+
]
|
|
694
|
+
})
|
|
686
695
|
```
|
|
687
696
|
|
|
688
|
-
|
|
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
|
|
package/lib/Utils/mbuilder.d.ts
CHANGED
|
@@ -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: (
|
|
43
|
-
richFOAText: (
|
|
44
|
-
richCode: (
|
|
45
|
-
richTable: (
|
|
46
|
-
richSource: (
|
|
47
|
-
richReels: (
|
|
48
|
-
richImage: (
|
|
49
|
-
richVideo: (
|
|
50
|
-
richProduct: (
|
|
51
|
-
richPost: (
|
|
52
|
-
richMetadata: (
|
|
53
|
-
richTip: (
|
|
54
|
-
richWidget: (
|
|
55
|
-
richFooterAction: (
|
|
56
|
-
richSuggest: (
|
|
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
|
};
|
package/lib/Utils/mbuilder.js
CHANGED
|
@@ -3174,31 +3174,38 @@ class AIRich extends BaseBuilder {
|
|
|
3174
3174
|
|
|
3175
3175
|
|
|
3176
3176
|
/**
|
|
3177
|
-
*
|
|
3177
|
+
* `build.*` creates lightweight Rich AI items for `sock.sendMessage()`.
|
|
3178
3178
|
*
|
|
3179
|
-
*
|
|
3180
|
-
*
|
|
3181
|
-
*
|
|
3182
|
-
*
|
|
3183
|
-
*
|
|
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: (
|
|
3188
|
-
richFOAText: (
|
|
3189
|
-
richCode: (
|
|
3190
|
-
richTable: (
|
|
3191
|
-
richSource: (
|
|
3192
|
-
richReels: (
|
|
3193
|
-
richImage: (
|
|
3194
|
-
richVideo: (
|
|
3195
|
-
richProduct: (
|
|
3196
|
-
richPost: (
|
|
3197
|
-
richMetadata: (
|
|
3198
|
-
richTip: (
|
|
3199
|
-
richWidget: (
|
|
3200
|
-
richFooterAction: (
|
|
3201
|
-
richSuggest: (
|
|
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