@pontalabs/baileys 1.1.8 → 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 +117 -0
- package/lib/Socket/messages-send.js +10 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/mbuilder.d.ts +55 -0
- package/lib/Utils/mbuilder.js +3211 -0
- package/lib/Utils/messages.js +4 -0
- package/lib/Utils/rich-message-utils.d.ts +2 -1
- package/lib/Utils/rich-message-utils.js +52 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -584,6 +584,123 @@ await sock.sendMessage(jid, {
|
|
|
584
584
|
|
|
585
585
|
---
|
|
586
586
|
|
|
587
|
+
### 🧱 Rich Builder API — `build.*`
|
|
588
|
+
|
|
589
|
+
`build.*` adalah cara singkat untuk membuat **Rich AI item** yang langsung bisa dipakai di `sock.sendMessage()`.
|
|
590
|
+
|
|
591
|
+
> **Tidak perlu import `build`.** Package mengekspos `build` secara global saat dimuat.
|
|
592
|
+
|
|
593
|
+
#### 🚀 Cara paling sederhana
|
|
594
|
+
|
|
595
|
+
```js
|
|
596
|
+
await sock.sendMessage(jid, {
|
|
597
|
+
items: [
|
|
598
|
+
build.richText('Halo! 👋'),
|
|
599
|
+
build.richCode('console.log("hello")', 'javascript'),
|
|
600
|
+
build.richTip('Selesai!')
|
|
601
|
+
]
|
|
602
|
+
})
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
Factory `build.rich*()` **tidak mengirim pesan sendiri**. Mereka hanya membuat item payload. Pengiriman tetap menggunakan API Baileys biasa: `sock.sendMessage()`.
|
|
606
|
+
|
|
607
|
+
#### ✨ Semua factory
|
|
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 |
|
|
626
|
+
|
|
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
|
+
})
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
#### 🛠️ Builder untuk edit / delete
|
|
643
|
+
|
|
644
|
+
Untuk kebutuhan yang benar-benar membutuhkan state dan manipulasi node, gunakan `build.AIRich(sock)`.
|
|
645
|
+
|
|
646
|
+
```js
|
|
647
|
+
const ai = build.AIRich(sock)
|
|
648
|
+
|
|
649
|
+
ai.addText('⏳ Loading...', { id: 'status' })
|
|
650
|
+
ai.addTip('Mohon tunggu')
|
|
651
|
+
|
|
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' })
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
> `replace` dan `insertAt` adalah **options pada `add*()`**, bukan method `ai.replace()` atau `ai.insertAt()`.
|
|
665
|
+
|
|
666
|
+
#### 📝 Contoh workflow edit
|
|
667
|
+
|
|
668
|
+
```js
|
|
669
|
+
const ai = build.AIRich(sock)
|
|
670
|
+
ai.addText('⏳ Memproses...', { id: 'answer' })
|
|
671
|
+
|
|
672
|
+
await ai.send(jid)
|
|
673
|
+
|
|
674
|
+
const result = await getAIResponse()
|
|
675
|
+
|
|
676
|
+
ai.addText(result, { replace: 'answer' })
|
|
677
|
+
ai.addTip('Generated by AI')
|
|
678
|
+
|
|
679
|
+
await ai.sendEdit(jid)
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
#### 🔌 API lama tetap kompatibel
|
|
683
|
+
|
|
684
|
+
```js
|
|
685
|
+
await sock.sendMessage(jid, {
|
|
686
|
+
richText: 'Halo'
|
|
687
|
+
})
|
|
688
|
+
|
|
689
|
+
await sock.sendMessage(jid, {
|
|
690
|
+
items: [
|
|
691
|
+
{ richText: 'Halo' },
|
|
692
|
+
{ richTip: 'Testing' }
|
|
693
|
+
]
|
|
694
|
+
})
|
|
695
|
+
```
|
|
696
|
+
|
|
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.
|
|
702
|
+
|
|
703
|
+
|
|
587
704
|
### 🤖 Rich Messages
|
|
588
705
|
|
|
589
706
|
> All rich messages are sent via standard `sendMessage` and rendered as AI bot messages in WhatsApp. Use the appropriate key instead of `text`, `image`, `video`, etc.
|
|
@@ -1347,6 +1347,16 @@ export const makeMessagesSocket = (config) => {
|
|
|
1347
1347
|
additionalAttributes,
|
|
1348
1348
|
additionalNodes
|
|
1349
1349
|
});
|
|
1350
|
+
// Semua AI Rich memakai bypass-download secara default; opt-out dengan bypassDownload:false.
|
|
1351
|
+
const isRichAiContent = !!(fullMsg.message?.botForwardedMessage?.message?.richResponseMessage || fullMsg.message?.richResponseMessage);
|
|
1352
|
+
if (isRichAiContent && options.bypassDownload !== false) {
|
|
1353
|
+
const editMessage = await generateWAMessageFromContent(jid, {
|
|
1354
|
+
botForwardedMessage: { message: { protocolMessage: {
|
|
1355
|
+
key: { remoteJid: jid, fromMe: true, id: fullMsg.key.id }, type: 14, editedMessage: fullMsg.message
|
|
1356
|
+
} } }
|
|
1357
|
+
}, { messageId: generateMessageIDV2(sock.user?.id) });
|
|
1358
|
+
await relayMessage(jid, editMessage.message, { messageId: editMessage.key.id });
|
|
1359
|
+
}
|
|
1350
1360
|
if (config.emitOwnEvents) {
|
|
1351
1361
|
process.nextTick(async () => {
|
|
1352
1362
|
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
package/lib/Utils/index.d.ts
CHANGED
package/lib/Utils/index.js
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
|
2
|
+
export declare class Button { constructor(client: any, options?: any); loadFrom(data: any): this; build(jid: string, options?: any): any; send(jid: string, options?: any): Promise<any>; [key: string]: any; }
|
|
3
|
+
export declare class ButtonV2 { constructor(client: any, options?: any); loadFrom(data: any): this; build(jid: string, options?: any): any; send(jid: string, options?: any): Promise<any>; [key: string]: any; }
|
|
4
|
+
export declare class Carousel { constructor(client: any, options?: any); loadFrom(data: any): this; build(jid: string, options?: any): any; send(jid: string, options?: any): Promise<any>; [key: string]: any; }
|
|
5
|
+
export declare class AIRich {
|
|
6
|
+
constructor(client: any, options?: { dynamic?: boolean; unsupportedTypeAlert?: boolean });
|
|
7
|
+
loadFrom(msg: any): this;
|
|
8
|
+
setResponseId(id: string): this;
|
|
9
|
+
refreshResponseId(): this;
|
|
10
|
+
setBotResponseId(id: string): this;
|
|
11
|
+
refreshBotResponseId(): this;
|
|
12
|
+
createAlert(type: any): any;
|
|
13
|
+
addText(text: string, options?: any): this;
|
|
14
|
+
addFOAText(text: string, options?: any): this;
|
|
15
|
+
addCode(language: string, code: string, options?: any): this;
|
|
16
|
+
addTable(table: any, options?: any): this;
|
|
17
|
+
addSource(sources?: any[], options?: any): this;
|
|
18
|
+
addReels(reelsItems?: any[], options?: any): this;
|
|
19
|
+
addImage(imageUrl: any, options?: any): this;
|
|
20
|
+
addVideo(videoUrl: any, options?: any): this;
|
|
21
|
+
addProduct(data?: any, options?: any): this;
|
|
22
|
+
addPost(data?: any, options?: any): this;
|
|
23
|
+
addMetadata(text: string, options?: any): this;
|
|
24
|
+
addTip(text: string, options?: any): this;
|
|
25
|
+
addWidget(data: any, options?: any): this;
|
|
26
|
+
addFooterAction(data: any, options?: any): this;
|
|
27
|
+
addSuggest(suggestion: any, options?: any): this;
|
|
28
|
+
addSection(section: any, options?: any): this;
|
|
29
|
+
addSubmessage(submessage: any, options?: any): this;
|
|
30
|
+
delete(id: any): this;
|
|
31
|
+
build(jid: string, options?: any): Promise<any>;
|
|
32
|
+
buildEdit(targetJid: string, targetId: string, options?: any): Promise<any>;
|
|
33
|
+
send(jid: string, options?: any): Promise<any>;
|
|
34
|
+
sendEdit(jid?: string, id?: string, options?: any): Promise<any>;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
export declare class Toolkit { [key: string]: any; }
|
|
38
|
+
export declare const build: {
|
|
39
|
+
AIRich: (client: 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;
|
|
55
|
+
};
|