@pontalabs/baileys 1.1.7 → 1.1.9
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 +105 -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 +57 -0
- package/lib/Utils/mbuilder.js +3204 -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 +35 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -584,6 +584,111 @@ await sock.sendMessage(jid, {
|
|
|
584
584
|
|
|
585
585
|
---
|
|
586
586
|
|
|
587
|
+
### 🧱 Rich Builder API — `build.*`
|
|
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.
|
|
590
|
+
|
|
591
|
+
**Prinsip kompatibilitas:**
|
|
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
|
|
598
|
+
|
|
599
|
+
```js
|
|
600
|
+
import { build, AIRich } from '@pontalabs/baileys'
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
#### Quick Start
|
|
604
|
+
|
|
605
|
+
```js
|
|
606
|
+
const ai = build.richText(sock, 'Halo! 👋')
|
|
607
|
+
|
|
608
|
+
ai.addTip('Pesan ini dibuat dengan Rich Builder')
|
|
609
|
+
|
|
610
|
+
await ai.send(jid)
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
#### Builder Factories
|
|
614
|
+
|
|
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*()`:
|
|
637
|
+
|
|
638
|
+
```js
|
|
639
|
+
const ai = build.AIRich(sock)
|
|
640
|
+
|
|
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')
|
|
645
|
+
|
|
646
|
+
await ai.send(jid)
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
#### Edit Message
|
|
650
|
+
|
|
651
|
+
`AIRich` menyimpan struktur dan ID section sehingga pesan yang sudah dikirim dapat dimanipulasi.
|
|
652
|
+
|
|
653
|
+
```js
|
|
654
|
+
const ai = build.AIRich(sock)
|
|
655
|
+
ai.addText('Loading...')
|
|
656
|
+
|
|
657
|
+
const sent = await ai.send(jid)
|
|
658
|
+
|
|
659
|
+
// Tambah section baru
|
|
660
|
+
ai.addText('Selesai!')
|
|
661
|
+
|
|
662
|
+
// Kirim perubahan sebagai protocol edit
|
|
663
|
+
await ai.sendEdit(jid, sent.key.id)
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
Jika ingin membuat payload edit tanpa langsung mengirim:
|
|
667
|
+
|
|
668
|
+
```js
|
|
669
|
+
const editMessage = await ai.buildEdit(jid, sent.key.id)
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
#### Load Message Existing
|
|
673
|
+
|
|
674
|
+
Builder juga dapat memuat Rich AI message yang sudah ada:
|
|
675
|
+
|
|
676
|
+
```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(...)
|
|
684
|
+
|
|
685
|
+
await ai.sendEdit(jid, existingMessage.key.id)
|
|
686
|
+
```
|
|
687
|
+
|
|
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' })`.
|
|
689
|
+
|
|
690
|
+
---
|
|
691
|
+
|
|
587
692
|
### 🤖 Rich Messages
|
|
588
693
|
|
|
589
694
|
> 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,57 @@
|
|
|
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
|
+
replace(id: any, content: any): this;
|
|
32
|
+
insertAt(index: number, content: any): this;
|
|
33
|
+
build(jid: string, options?: any): Promise<any>;
|
|
34
|
+
buildEdit(targetJid: string, targetId: string, options?: any): Promise<any>;
|
|
35
|
+
send(jid: string, options?: any): Promise<any>;
|
|
36
|
+
sendEdit(jid?: string, id?: string, options?: any): Promise<any>;
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}
|
|
39
|
+
export declare class Toolkit { [key: string]: any; }
|
|
40
|
+
export declare const build: {
|
|
41
|
+
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;
|
|
57
|
+
};
|