@kangwifi-pro/waliwa 2.1.0 → 3.0.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/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/advanced/features.d.ts +0 -0
- package/dist/advanced/features.d.ts.map +0 -0
- package/dist/advanced/features.js +0 -0
- package/dist/advanced/features.js.map +0 -0
- package/dist/auth/auth-state.d.ts +0 -0
- package/dist/auth/auth-state.d.ts.map +0 -0
- package/dist/auth/auth-state.js +0 -0
- package/dist/auth/auth-state.js.map +0 -0
- package/dist/auth/pairing-code.d.ts +0 -0
- package/dist/auth/pairing-code.d.ts.map +0 -0
- package/dist/auth/pairing-code.js +0 -0
- package/dist/auth/pairing-code.js.map +0 -0
- package/dist/auth/qr-code.d.ts +0 -0
- package/dist/auth/qr-code.d.ts.map +0 -0
- package/dist/auth/qr-code.js +0 -0
- package/dist/auth/qr-code.js.map +0 -0
- package/dist/calls/handler.d.ts +0 -0
- package/dist/calls/handler.d.ts.map +0 -0
- package/dist/calls/handler.js +0 -0
- package/dist/calls/handler.js.map +0 -0
- package/dist/community/audio-transcription.d.ts +0 -0
- package/dist/community/audio-transcription.d.ts.map +0 -0
- package/dist/community/audio-transcription.js +0 -0
- package/dist/community/audio-transcription.js.map +0 -0
- package/dist/community/bulk-operations.d.ts +0 -0
- package/dist/community/bulk-operations.d.ts.map +0 -0
- package/dist/community/bulk-operations.js +0 -0
- package/dist/community/bulk-operations.js.map +0 -0
- package/dist/community/community-fixes.d.ts +0 -0
- package/dist/community/community-fixes.d.ts.map +0 -0
- package/dist/community/community-fixes.js +0 -0
- package/dist/community/community-fixes.js.map +0 -0
- package/dist/community/contacts-manager.d.ts +0 -0
- package/dist/community/contacts-manager.d.ts.map +0 -0
- package/dist/community/contacts-manager.js +0 -0
- package/dist/community/contacts-manager.js.map +0 -0
- package/dist/community/disappearing.d.ts +0 -0
- package/dist/community/disappearing.d.ts.map +0 -0
- package/dist/community/disappearing.js +0 -0
- package/dist/community/disappearing.js.map +0 -0
- package/dist/community/index.d.ts +0 -0
- package/dist/community/index.d.ts.map +0 -0
- package/dist/community/index.js +0 -0
- package/dist/community/index.js.map +0 -0
- package/dist/community/live-location.d.ts +0 -0
- package/dist/community/live-location.d.ts.map +0 -0
- package/dist/community/live-location.js +0 -0
- package/dist/community/live-location.js.map +0 -0
- package/dist/community/message-extras.d.ts +0 -0
- package/dist/community/message-extras.d.ts.map +0 -0
- package/dist/community/message-extras.js +0 -0
- package/dist/community/message-extras.js.map +0 -0
- package/dist/community/newsletter-extended.d.ts +0 -0
- package/dist/community/newsletter-extended.d.ts.map +0 -0
- package/dist/community/newsletter-extended.js +0 -0
- package/dist/community/newsletter-extended.js.map +0 -0
- package/dist/community/privacy-manager.d.ts +0 -0
- package/dist/community/privacy-manager.d.ts.map +0 -0
- package/dist/community/privacy-manager.js +0 -0
- package/dist/community/privacy-manager.js.map +0 -0
- package/dist/community/profile-manager.d.ts +0 -0
- package/dist/community/profile-manager.d.ts.map +0 -0
- package/dist/community/profile-manager.js +0 -0
- package/dist/community/profile-manager.js.map +0 -0
- package/dist/community/status-extended.d.ts +0 -0
- package/dist/community/status-extended.d.ts.map +0 -0
- package/dist/community/status-extended.js +0 -0
- package/dist/community/status-extended.js.map +0 -0
- package/dist/community/sticker-manager.d.ts +0 -0
- package/dist/community/sticker-manager.d.ts.map +0 -0
- package/dist/community/sticker-manager.js +0 -0
- package/dist/community/sticker-manager.js.map +0 -0
- package/dist/core/binary.d.ts +0 -0
- package/dist/core/binary.d.ts.map +0 -0
- package/dist/core/binary.js +0 -0
- package/dist/core/binary.js.map +0 -0
- package/dist/core/client-payload.d.ts +0 -0
- package/dist/core/client-payload.d.ts.map +0 -0
- package/dist/core/client-payload.js +0 -0
- package/dist/core/client-payload.js.map +0 -0
- package/dist/core/crypto.d.ts +0 -0
- package/dist/core/crypto.d.ts.map +0 -0
- package/dist/core/crypto.js +0 -0
- package/dist/core/crypto.js.map +0 -0
- package/dist/core/noise.d.ts +0 -0
- package/dist/core/noise.d.ts.map +0 -0
- package/dist/core/noise.js +0 -0
- package/dist/core/noise.js.map +0 -0
- package/dist/events/emitter.d.ts +0 -0
- package/dist/events/emitter.d.ts.map +0 -0
- package/dist/events/emitter.js +0 -0
- package/dist/events/emitter.js.map +0 -0
- package/dist/features/index.d.ts +0 -0
- package/dist/features/index.d.ts.map +0 -0
- package/dist/features/index.js +0 -0
- package/dist/features/index.js.map +0 -0
- package/dist/fixes/index.d.ts +0 -0
- package/dist/fixes/index.d.ts.map +0 -0
- package/dist/fixes/index.js +0 -0
- package/dist/fixes/index.js.map +0 -0
- package/dist/groups/management.d.ts +0 -0
- package/dist/groups/management.d.ts.map +0 -0
- package/dist/groups/management.js +0 -0
- package/dist/groups/management.js.map +0 -0
- package/dist/helpers/automation.d.ts +84 -0
- package/dist/helpers/automation.d.ts.map +1 -0
- package/dist/helpers/automation.js +245 -0
- package/dist/helpers/automation.js.map +1 -0
- package/dist/helpers/builder.d.ts +263 -0
- package/dist/helpers/builder.d.ts.map +1 -0
- package/dist/helpers/builder.js +446 -0
- package/dist/helpers/builder.js.map +1 -0
- package/dist/helpers/command.d.ts +130 -0
- package/dist/helpers/command.d.ts.map +1 -0
- package/dist/helpers/command.js +281 -0
- package/dist/helpers/command.js.map +1 -0
- package/dist/helpers/defaults.d.ts +2 -0
- package/dist/helpers/defaults.d.ts.map +1 -1
- package/dist/helpers/defaults.js +5 -3
- package/dist/helpers/defaults.js.map +1 -1
- package/dist/helpers/media.d.ts +0 -0
- package/dist/helpers/media.d.ts.map +1 -1
- package/dist/helpers/media.js +0 -0
- package/dist/helpers/media.js.map +1 -1
- package/dist/helpers/message.d.ts +0 -0
- package/dist/helpers/message.d.ts.map +1 -1
- package/dist/helpers/message.js +0 -0
- package/dist/helpers/message.js.map +1 -1
- package/dist/helpers/plugin.d.ts +77 -0
- package/dist/helpers/plugin.d.ts.map +1 -0
- package/dist/helpers/plugin.js +180 -0
- package/dist/helpers/plugin.js.map +1 -0
- package/dist/helpers/sticker.d.ts +0 -0
- package/dist/helpers/sticker.d.ts.map +1 -1
- package/dist/helpers/sticker.js +0 -0
- package/dist/helpers/sticker.js.map +1 -1
- package/dist/index.d.ts +23 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -23
- package/dist/index.js.map +1 -1
- package/dist/messages/media.d.ts +0 -0
- package/dist/messages/media.d.ts.map +0 -0
- package/dist/messages/media.js +0 -0
- package/dist/messages/media.js.map +0 -0
- package/dist/messages/message-encoder.d.ts +0 -0
- package/dist/messages/message-encoder.d.ts.map +0 -0
- package/dist/messages/message-encoder.js +0 -0
- package/dist/messages/message-encoder.js.map +0 -0
- package/dist/messages/send.d.ts +0 -0
- package/dist/messages/send.d.ts.map +0 -0
- package/dist/messages/send.js +0 -0
- package/dist/messages/send.js.map +0 -0
- package/dist/recovery/index.d.ts +0 -0
- package/dist/recovery/index.d.ts.map +0 -0
- package/dist/recovery/index.js +0 -0
- package/dist/recovery/index.js.map +0 -0
- package/dist/skdm/index.d.ts +0 -0
- package/dist/skdm/index.d.ts.map +0 -0
- package/dist/skdm/index.js +0 -0
- package/dist/skdm/index.js.map +0 -0
- package/dist/socket/hybrid.d.ts +0 -0
- package/dist/socket/hybrid.d.ts.map +0 -0
- package/dist/socket/hybrid.js +0 -0
- package/dist/socket/hybrid.js.map +0 -0
- package/dist/socket/wa-socket.d.ts +0 -0
- package/dist/socket/wa-socket.d.ts.map +0 -0
- package/dist/socket/wa-socket.js +0 -0
- package/dist/socket/wa-socket.js.map +0 -0
- package/dist/socket/ws-socket.d.ts +0 -0
- package/dist/socket/ws-socket.d.ts.map +0 -0
- package/dist/socket/ws-socket.js +0 -0
- package/dist/socket/ws-socket.js.map +0 -0
- package/dist/types/index.d.ts +0 -0
- package/dist/types/index.d.ts.map +0 -0
- package/dist/types/index.js +0 -0
- package/dist/types/index.js.map +0 -0
- package/dist/utils/jid.d.ts +0 -0
- package/dist/utils/jid.d.ts.map +0 -0
- package/dist/utils/jid.js +0 -0
- package/dist/utils/jid.js.map +0 -0
- package/dist/utils/logger.d.ts +0 -0
- package/dist/utils/logger.d.ts.map +0 -0
- package/dist/utils/logger.js +0 -0
- package/dist/utils/logger.js.map +0 -0
- package/dist/utils/retry.d.ts +0 -0
- package/dist/utils/retry.d.ts.map +0 -0
- package/dist/utils/retry.js +0 -0
- package/dist/utils/retry.js.map +0 -0
- package/package.json +12 -12
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waliwa - MessageBuilder (inspired by zaileys + baileys-mbuilder)
|
|
3
|
+
*
|
|
4
|
+
* Fluent chaining API untuk build dan send messages.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const builder = new MessageBuilder(sock);
|
|
9
|
+
* await builder
|
|
10
|
+
* .to(jid)
|
|
11
|
+
* .text('Hello!')
|
|
12
|
+
* .reply(message)
|
|
13
|
+
* .mentions(['user@s.whatsapp.net'])
|
|
14
|
+
* .send();
|
|
15
|
+
*
|
|
16
|
+
* // With media
|
|
17
|
+
* await builder.to(jid).image(buffer, { caption: 'Check this!' }).send();
|
|
18
|
+
*
|
|
19
|
+
* // With buttons
|
|
20
|
+
* await builder.to(jid).text('Choose:').buttons([
|
|
21
|
+
* { label: 'Yes', id: 'yes' },
|
|
22
|
+
* { label: 'No', id: 'no' }
|
|
23
|
+
* ]).send();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface ButtonDef {
|
|
27
|
+
label: string;
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CarouselCard {
|
|
31
|
+
image?: Buffer | string;
|
|
32
|
+
title?: string;
|
|
33
|
+
text?: string;
|
|
34
|
+
buttons?: ButtonDef[];
|
|
35
|
+
}
|
|
36
|
+
export interface AlbumItem {
|
|
37
|
+
type: 'image' | 'video' | 'audio';
|
|
38
|
+
buffer: Buffer;
|
|
39
|
+
caption?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class MessageBuilder {
|
|
42
|
+
private sock;
|
|
43
|
+
private recipient;
|
|
44
|
+
private content;
|
|
45
|
+
private options;
|
|
46
|
+
private quotedMsg;
|
|
47
|
+
private mentionsList;
|
|
48
|
+
private isViewOnce;
|
|
49
|
+
private isEphemeral;
|
|
50
|
+
private ephemeralExpiration;
|
|
51
|
+
constructor(sock: any);
|
|
52
|
+
/**
|
|
53
|
+
* Set recipient
|
|
54
|
+
*/
|
|
55
|
+
to(jid: string): this;
|
|
56
|
+
/**
|
|
57
|
+
* Set text content
|
|
58
|
+
*/
|
|
59
|
+
text(content: string): this;
|
|
60
|
+
/**
|
|
61
|
+
* Set image
|
|
62
|
+
*/
|
|
63
|
+
image(buffer: Buffer, opts?: {
|
|
64
|
+
caption?: string;
|
|
65
|
+
mimetype?: string;
|
|
66
|
+
}): this;
|
|
67
|
+
/**
|
|
68
|
+
* Set video
|
|
69
|
+
*/
|
|
70
|
+
video(buffer: Buffer, opts?: {
|
|
71
|
+
caption?: string;
|
|
72
|
+
mimetype?: string;
|
|
73
|
+
gifPlayback?: boolean;
|
|
74
|
+
}): this;
|
|
75
|
+
/**
|
|
76
|
+
* Set audio
|
|
77
|
+
*/
|
|
78
|
+
audio(buffer: Buffer, opts?: {
|
|
79
|
+
ptt?: boolean;
|
|
80
|
+
mimetype?: string;
|
|
81
|
+
}): this;
|
|
82
|
+
/**
|
|
83
|
+
* Set document
|
|
84
|
+
*/
|
|
85
|
+
document(buffer: Buffer, opts?: {
|
|
86
|
+
fileName?: string;
|
|
87
|
+
mimetype?: string;
|
|
88
|
+
caption?: string;
|
|
89
|
+
}): this;
|
|
90
|
+
/**
|
|
91
|
+
* Set sticker
|
|
92
|
+
*/
|
|
93
|
+
sticker(buffer: Buffer): this;
|
|
94
|
+
/**
|
|
95
|
+
* Set location
|
|
96
|
+
*/
|
|
97
|
+
location(lat: number, lon: number, opts?: {
|
|
98
|
+
name?: string;
|
|
99
|
+
address?: string;
|
|
100
|
+
}): this;
|
|
101
|
+
/**
|
|
102
|
+
* Set contact (vCard)
|
|
103
|
+
*/
|
|
104
|
+
contact(vcard: string, displayName?: string): this;
|
|
105
|
+
/**
|
|
106
|
+
* Set poll
|
|
107
|
+
*/
|
|
108
|
+
poll(question: string, options: string[], opts?: {
|
|
109
|
+
selectableCounts?: number[];
|
|
110
|
+
}): this;
|
|
111
|
+
/**
|
|
112
|
+
* Set buttons (interactive)
|
|
113
|
+
*/
|
|
114
|
+
buttons(btns: ButtonDef[], opts?: {
|
|
115
|
+
text?: string;
|
|
116
|
+
footer?: string;
|
|
117
|
+
header?: string;
|
|
118
|
+
}): this;
|
|
119
|
+
/**
|
|
120
|
+
* Set carousel cards
|
|
121
|
+
*/
|
|
122
|
+
carousel(cards: CarouselCard[], opts?: {
|
|
123
|
+
text?: string;
|
|
124
|
+
}): this;
|
|
125
|
+
/**
|
|
126
|
+
* Set list message
|
|
127
|
+
*/
|
|
128
|
+
list(opts: {
|
|
129
|
+
title: string;
|
|
130
|
+
text: string;
|
|
131
|
+
buttonText: string;
|
|
132
|
+
sections: Array<{
|
|
133
|
+
title: string;
|
|
134
|
+
rows: Array<{
|
|
135
|
+
title: string;
|
|
136
|
+
rowId: string;
|
|
137
|
+
description?: string;
|
|
138
|
+
}>;
|
|
139
|
+
}>;
|
|
140
|
+
}): this;
|
|
141
|
+
/**
|
|
142
|
+
* Set reaction
|
|
143
|
+
*/
|
|
144
|
+
reaction(emoji: string, key: any): this;
|
|
145
|
+
/**
|
|
146
|
+
* Reply to message
|
|
147
|
+
*/
|
|
148
|
+
reply(message: any): this;
|
|
149
|
+
/**
|
|
150
|
+
* Set mentions
|
|
151
|
+
*/
|
|
152
|
+
mentions(jids: string[]): this;
|
|
153
|
+
/**
|
|
154
|
+
* Mention all group participants
|
|
155
|
+
*/
|
|
156
|
+
mentionAll(): Promise<this>;
|
|
157
|
+
/**
|
|
158
|
+
* Set view-once
|
|
159
|
+
*/
|
|
160
|
+
viewOnce(): this;
|
|
161
|
+
/**
|
|
162
|
+
* Set ephemeral
|
|
163
|
+
*/
|
|
164
|
+
ephemeral(seconds: number): this;
|
|
165
|
+
/**
|
|
166
|
+
* Build the message content object
|
|
167
|
+
*/
|
|
168
|
+
build(): any;
|
|
169
|
+
/**
|
|
170
|
+
* Send the message
|
|
171
|
+
*/
|
|
172
|
+
send(): Promise<any>;
|
|
173
|
+
/**
|
|
174
|
+
* Forward to another chat
|
|
175
|
+
*/
|
|
176
|
+
forwardTo(jid: string): Promise<any>;
|
|
177
|
+
/**
|
|
178
|
+
* Broadcast to multiple recipients
|
|
179
|
+
*/
|
|
180
|
+
broadcast(jids: string[], delayMs?: number): Promise<any[]>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Simple Button Builder (from baileys-mbuilder concept)
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const msg = new ButtonBuilder()
|
|
188
|
+
* .text('Choose an option:')
|
|
189
|
+
* .button('Yes', 'yes_id')
|
|
190
|
+
* .button('No', 'no_id')
|
|
191
|
+
* .footer('Powered by Waliwa')
|
|
192
|
+
* .build();
|
|
193
|
+
* await sock.sendMessage(jid, msg);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export declare class ButtonBuilder {
|
|
197
|
+
private bodyText;
|
|
198
|
+
private buttons;
|
|
199
|
+
private footerText;
|
|
200
|
+
private headerText;
|
|
201
|
+
private viewOnceFlag;
|
|
202
|
+
text(t: string): this;
|
|
203
|
+
button(label: string, id: string): this;
|
|
204
|
+
footer(t: string): this;
|
|
205
|
+
header(t: string): this;
|
|
206
|
+
viewOnce(): this;
|
|
207
|
+
build(): any;
|
|
208
|
+
send(sock: any, jid: string): Promise<any>;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Carousel Builder (from baileys-mbuilder concept)
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const msg = new CarouselBuilder()
|
|
216
|
+
* .card(c => c.title('Product A').text('$10').button('Buy', 'buy_a'))
|
|
217
|
+
* .card(c => c.title('Product B').text('$20').button('Buy', 'buy_b'))
|
|
218
|
+
* .build();
|
|
219
|
+
* await sock.sendMessage(jid, msg);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export declare class CarouselBuilder {
|
|
223
|
+
private cards;
|
|
224
|
+
card(callback: (builder: CardBuilder) => void): this;
|
|
225
|
+
build(): any;
|
|
226
|
+
send(sock: any, jid: string): Promise<any>;
|
|
227
|
+
}
|
|
228
|
+
declare class CardBuilder {
|
|
229
|
+
private card;
|
|
230
|
+
image(src: Buffer | string): this;
|
|
231
|
+
title(t: string): this;
|
|
232
|
+
text(t: string): this;
|
|
233
|
+
button(label: string, id: string): this;
|
|
234
|
+
build(): any;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* AI Rich Response Builder (from baileys-mbuilder concept)
|
|
238
|
+
* Supports hyperlinks [text](url), LaTeX, citations, code blocks
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const msg = new AIRichBuilder()
|
|
243
|
+
* .text('Visit [Google](https://google.com) for details')
|
|
244
|
+
* .build();
|
|
245
|
+
* await sock.sendMessage(jid, msg);
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export declare class AIRichBuilder {
|
|
249
|
+
private bodyText;
|
|
250
|
+
private extractFlag;
|
|
251
|
+
private hyperlinkFlag;
|
|
252
|
+
private citationFlag;
|
|
253
|
+
private latexFlag;
|
|
254
|
+
text(t: string): this;
|
|
255
|
+
extract(enabled: boolean): this;
|
|
256
|
+
hyperlink(enabled: boolean): this;
|
|
257
|
+
citation(enabled: boolean): this;
|
|
258
|
+
latex(enabled: boolean): this;
|
|
259
|
+
build(): any;
|
|
260
|
+
send(sock: any, jid: string): Promise<any>;
|
|
261
|
+
}
|
|
262
|
+
export {};
|
|
263
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/helpers/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,mBAAmB,CAAa;IAExC,YAAY,IAAI,EAAE,GAAG,EAEpB;IAED;;OAEG;IACH,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAGpB;IAED;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAG1B;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,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E,EAAE,MAAM,GAAG,IAAI,CAQtC;IAED,KAAK,IAAI,GAAG,CAAsB;CACnC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,SAAS,CAAiB;IAElC,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAoC;IACzD,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAA6C;IAC5E,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAA+C;IAChF,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAA8C;IAC9E,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAA2C;IAExE,KAAK,IAAI,GAAG,CAkCX;IAEK,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAE/C;CACF"}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Waliwa - MessageBuilder (inspired by zaileys + baileys-mbuilder)
|
|
4
|
+
*
|
|
5
|
+
* Fluent chaining API untuk build dan send messages.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const builder = new MessageBuilder(sock);
|
|
10
|
+
* await builder
|
|
11
|
+
* .to(jid)
|
|
12
|
+
* .text('Hello!')
|
|
13
|
+
* .reply(message)
|
|
14
|
+
* .mentions(['user@s.whatsapp.net'])
|
|
15
|
+
* .send();
|
|
16
|
+
*
|
|
17
|
+
* // With media
|
|
18
|
+
* await builder.to(jid).image(buffer, { caption: 'Check this!' }).send();
|
|
19
|
+
*
|
|
20
|
+
* // With buttons
|
|
21
|
+
* await builder.to(jid).text('Choose:').buttons([
|
|
22
|
+
* { label: 'Yes', id: 'yes' },
|
|
23
|
+
* { label: 'No', id: 'no' }
|
|
24
|
+
* ]).send();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.AIRichBuilder = exports.CarouselBuilder = exports.ButtonBuilder = exports.MessageBuilder = void 0;
|
|
29
|
+
class MessageBuilder {
|
|
30
|
+
sock;
|
|
31
|
+
recipient = '';
|
|
32
|
+
content = {};
|
|
33
|
+
options = {};
|
|
34
|
+
quotedMsg = null;
|
|
35
|
+
mentionsList = [];
|
|
36
|
+
isViewOnce = false;
|
|
37
|
+
isEphemeral = false;
|
|
38
|
+
ephemeralExpiration = 0;
|
|
39
|
+
constructor(sock) {
|
|
40
|
+
this.sock = sock;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set recipient
|
|
44
|
+
*/
|
|
45
|
+
to(jid) {
|
|
46
|
+
this.recipient = jid;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Set text content
|
|
51
|
+
*/
|
|
52
|
+
text(content) {
|
|
53
|
+
this.content.text = content;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set image
|
|
58
|
+
*/
|
|
59
|
+
image(buffer, opts = {}) {
|
|
60
|
+
this.content.image = buffer;
|
|
61
|
+
if (opts.caption)
|
|
62
|
+
this.content.caption = opts.caption;
|
|
63
|
+
if (opts.mimetype)
|
|
64
|
+
this.content.mimetype = opts.mimetype;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set video
|
|
69
|
+
*/
|
|
70
|
+
video(buffer, opts = {}) {
|
|
71
|
+
this.content.video = buffer;
|
|
72
|
+
if (opts.caption)
|
|
73
|
+
this.content.caption = opts.caption;
|
|
74
|
+
if (opts.mimetype)
|
|
75
|
+
this.content.mimetype = opts.mimetype;
|
|
76
|
+
if (opts.gifPlayback)
|
|
77
|
+
this.content.gifPlayback = opts.gifPlayback;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set audio
|
|
82
|
+
*/
|
|
83
|
+
audio(buffer, opts = {}) {
|
|
84
|
+
this.content.audio = buffer;
|
|
85
|
+
this.content.ptt = opts.ptt ?? false;
|
|
86
|
+
if (opts.mimetype)
|
|
87
|
+
this.content.mimetype = opts.mimetype;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Set document
|
|
92
|
+
*/
|
|
93
|
+
document(buffer, opts = {}) {
|
|
94
|
+
this.content.document = buffer;
|
|
95
|
+
if (opts.fileName)
|
|
96
|
+
this.content.fileName = opts.fileName;
|
|
97
|
+
if (opts.mimetype)
|
|
98
|
+
this.content.mimetype = opts.mimetype;
|
|
99
|
+
if (opts.caption)
|
|
100
|
+
this.content.caption = opts.caption;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Set sticker
|
|
105
|
+
*/
|
|
106
|
+
sticker(buffer) {
|
|
107
|
+
this.content.sticker = buffer;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set location
|
|
112
|
+
*/
|
|
113
|
+
location(lat, lon, opts = {}) {
|
|
114
|
+
this.content.location = {
|
|
115
|
+
degreesLatitude: lat,
|
|
116
|
+
degreesLongitude: lon,
|
|
117
|
+
...(opts.name ? { name: opts.name } : {}),
|
|
118
|
+
...(opts.address ? { address: opts.address } : {})
|
|
119
|
+
};
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Set contact (vCard)
|
|
124
|
+
*/
|
|
125
|
+
contact(vcard, displayName) {
|
|
126
|
+
this.content.contact = { displayName: displayName ?? '', vcard };
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Set poll
|
|
131
|
+
*/
|
|
132
|
+
poll(question, options, opts = {}) {
|
|
133
|
+
this.content.poll = {
|
|
134
|
+
name: question,
|
|
135
|
+
values: options,
|
|
136
|
+
selectableCounts: opts.selectableCounts ?? [1]
|
|
137
|
+
};
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Set buttons (interactive)
|
|
142
|
+
*/
|
|
143
|
+
buttons(btns, opts = {}) {
|
|
144
|
+
this.content.buttons = btns.map(b => ({
|
|
145
|
+
buttonId: b.id,
|
|
146
|
+
buttonText: { displayText: b.label },
|
|
147
|
+
type: 1
|
|
148
|
+
}));
|
|
149
|
+
if (opts.text)
|
|
150
|
+
this.content.text = opts.text;
|
|
151
|
+
if (opts.footer)
|
|
152
|
+
this.content.footer = opts.footer;
|
|
153
|
+
if (opts.header)
|
|
154
|
+
this.content.title = opts.header;
|
|
155
|
+
this.content.buttonText = opts.text ?? '';
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Set carousel cards
|
|
160
|
+
*/
|
|
161
|
+
carousel(cards, opts = {}) {
|
|
162
|
+
this.content.carouselMessage = {
|
|
163
|
+
cards: cards.map(c => ({
|
|
164
|
+
...(c.image ? { image: c.image } : {}),
|
|
165
|
+
...(c.title ? { title: c.title } : {}),
|
|
166
|
+
...(c.text ? { body: c.text } : {}),
|
|
167
|
+
...(c.buttons ? { buttons: c.buttons.map(b => ({
|
|
168
|
+
buttonId: b.id,
|
|
169
|
+
buttonText: { displayText: b.label },
|
|
170
|
+
type: 1
|
|
171
|
+
})) } : {})
|
|
172
|
+
}))
|
|
173
|
+
};
|
|
174
|
+
if (opts.text)
|
|
175
|
+
this.content.text = opts.text;
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Set list message
|
|
180
|
+
*/
|
|
181
|
+
list(opts) {
|
|
182
|
+
this.content.listMessage = opts;
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Set reaction
|
|
187
|
+
*/
|
|
188
|
+
reaction(emoji, key) {
|
|
189
|
+
this.content.react = { text: emoji, key };
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Reply to message
|
|
194
|
+
*/
|
|
195
|
+
reply(message) {
|
|
196
|
+
this.quotedMsg = message;
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Set mentions
|
|
201
|
+
*/
|
|
202
|
+
mentions(jids) {
|
|
203
|
+
this.mentionsList = jids;
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Mention all group participants
|
|
208
|
+
*/
|
|
209
|
+
async mentionAll() {
|
|
210
|
+
if (!this.recipient.endsWith('@g.us'))
|
|
211
|
+
return this;
|
|
212
|
+
const metadata = await this.sock.groupMetadata(this.recipient);
|
|
213
|
+
this.mentionsList = metadata.participants.map((p) => p.id);
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Set view-once
|
|
218
|
+
*/
|
|
219
|
+
viewOnce() {
|
|
220
|
+
this.isViewOnce = true;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Set ephemeral
|
|
225
|
+
*/
|
|
226
|
+
ephemeral(seconds) {
|
|
227
|
+
this.isEphemeral = true;
|
|
228
|
+
this.ephemeralExpiration = seconds;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Build the message content object
|
|
233
|
+
*/
|
|
234
|
+
build() {
|
|
235
|
+
const content = { ...this.content };
|
|
236
|
+
if (this.mentionsList.length > 0) {
|
|
237
|
+
content.mentions = this.mentionsList;
|
|
238
|
+
}
|
|
239
|
+
if (this.isViewOnce) {
|
|
240
|
+
content.viewOnce = true;
|
|
241
|
+
}
|
|
242
|
+
if (this.isEphemeral) {
|
|
243
|
+
content.ephemeralExpiration = this.ephemeralExpiration;
|
|
244
|
+
}
|
|
245
|
+
const options = {};
|
|
246
|
+
if (this.quotedMsg) {
|
|
247
|
+
options.quoted = this.quotedMsg;
|
|
248
|
+
}
|
|
249
|
+
return { content, options };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Send the message
|
|
253
|
+
*/
|
|
254
|
+
async send() {
|
|
255
|
+
const { content, options } = this.build();
|
|
256
|
+
return this.sock.sendMessage(this.recipient, content, options);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Forward to another chat
|
|
260
|
+
*/
|
|
261
|
+
async forwardTo(jid) {
|
|
262
|
+
const { content } = this.build();
|
|
263
|
+
return this.sock.sendMessage(jid, content);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Broadcast to multiple recipients
|
|
267
|
+
*/
|
|
268
|
+
async broadcast(jids, delayMs = 1000) {
|
|
269
|
+
const { content, options } = this.build();
|
|
270
|
+
const results = [];
|
|
271
|
+
for (const jid of jids) {
|
|
272
|
+
try {
|
|
273
|
+
const result = await this.sock.sendMessage(jid, content, options);
|
|
274
|
+
results.push({ jid, success: true, result });
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
results.push({ jid, success: false, error: err.message });
|
|
278
|
+
}
|
|
279
|
+
if (delayMs > 0) {
|
|
280
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return results;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.MessageBuilder = MessageBuilder;
|
|
287
|
+
/**
|
|
288
|
+
* Simple Button Builder (from baileys-mbuilder concept)
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const msg = new ButtonBuilder()
|
|
293
|
+
* .text('Choose an option:')
|
|
294
|
+
* .button('Yes', 'yes_id')
|
|
295
|
+
* .button('No', 'no_id')
|
|
296
|
+
* .footer('Powered by Waliwa')
|
|
297
|
+
* .build();
|
|
298
|
+
* await sock.sendMessage(jid, msg);
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
class ButtonBuilder {
|
|
302
|
+
bodyText = '';
|
|
303
|
+
buttons = [];
|
|
304
|
+
footerText = '';
|
|
305
|
+
headerText = '';
|
|
306
|
+
viewOnceFlag = false;
|
|
307
|
+
text(t) { this.bodyText = t; return this; }
|
|
308
|
+
button(label, id) {
|
|
309
|
+
if (this.buttons.length >= 3)
|
|
310
|
+
throw new Error('Max 3 buttons');
|
|
311
|
+
this.buttons.push({
|
|
312
|
+
buttonId: id,
|
|
313
|
+
buttonText: { displayText: label },
|
|
314
|
+
type: 1
|
|
315
|
+
});
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
footer(t) { this.footerText = t; return this; }
|
|
319
|
+
header(t) { this.headerText = t; return this; }
|
|
320
|
+
viewOnce() { this.viewOnceFlag = true; return this; }
|
|
321
|
+
build() {
|
|
322
|
+
return {
|
|
323
|
+
text: this.bodyText,
|
|
324
|
+
buttons: this.buttons,
|
|
325
|
+
footer: this.footerText,
|
|
326
|
+
title: this.headerText,
|
|
327
|
+
...(this.viewOnceFlag ? { viewOnce: true } : {})
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
async send(sock, jid) {
|
|
331
|
+
return sock.sendMessage(jid, this.build());
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
exports.ButtonBuilder = ButtonBuilder;
|
|
335
|
+
/**
|
|
336
|
+
* Carousel Builder (from baileys-mbuilder concept)
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const msg = new CarouselBuilder()
|
|
341
|
+
* .card(c => c.title('Product A').text('$10').button('Buy', 'buy_a'))
|
|
342
|
+
* .card(c => c.title('Product B').text('$20').button('Buy', 'buy_b'))
|
|
343
|
+
* .build();
|
|
344
|
+
* await sock.sendMessage(jid, msg);
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
class CarouselBuilder {
|
|
348
|
+
cards = [];
|
|
349
|
+
card(callback) {
|
|
350
|
+
const builder = new CardBuilder();
|
|
351
|
+
callback(builder);
|
|
352
|
+
this.cards.push(builder.build());
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
build() {
|
|
356
|
+
return {
|
|
357
|
+
carouselMessage: {
|
|
358
|
+
cards: this.cards
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
async send(sock, jid) {
|
|
363
|
+
return sock.sendMessage(jid, this.build());
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
exports.CarouselBuilder = CarouselBuilder;
|
|
367
|
+
class CardBuilder {
|
|
368
|
+
card = {};
|
|
369
|
+
image(src) {
|
|
370
|
+
this.card.image = src;
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
title(t) { this.card.title = t; return this; }
|
|
374
|
+
text(t) { this.card.body = t; return this; }
|
|
375
|
+
button(label, id) {
|
|
376
|
+
if (!this.card.buttons)
|
|
377
|
+
this.card.buttons = [];
|
|
378
|
+
this.card.buttons.push({
|
|
379
|
+
buttonId: id,
|
|
380
|
+
buttonText: { displayText: label },
|
|
381
|
+
type: 1
|
|
382
|
+
});
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
build() { return this.card; }
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* AI Rich Response Builder (from baileys-mbuilder concept)
|
|
389
|
+
* Supports hyperlinks [text](url), LaTeX, citations, code blocks
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* const msg = new AIRichBuilder()
|
|
394
|
+
* .text('Visit [Google](https://google.com) for details')
|
|
395
|
+
* .build();
|
|
396
|
+
* await sock.sendMessage(jid, msg);
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
class AIRichBuilder {
|
|
400
|
+
bodyText = '';
|
|
401
|
+
extractFlag = true;
|
|
402
|
+
hyperlinkFlag = true;
|
|
403
|
+
citationFlag = true;
|
|
404
|
+
latexFlag = true;
|
|
405
|
+
text(t) { this.bodyText = t; return this; }
|
|
406
|
+
extract(enabled) { this.extractFlag = enabled; return this; }
|
|
407
|
+
hyperlink(enabled) { this.hyperlinkFlag = enabled; return this; }
|
|
408
|
+
citation(enabled) { this.citationFlag = enabled; return this; }
|
|
409
|
+
latex(enabled) { this.latexFlag = enabled; return this; }
|
|
410
|
+
build() {
|
|
411
|
+
let text = this.bodyText;
|
|
412
|
+
if (this.hyperlinkFlag) {
|
|
413
|
+
// Convert [text](url) to WA native hyperlinks
|
|
414
|
+
text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, label, url) => {
|
|
415
|
+
return `${label} (${url})`;
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
// Build extended text message with rich content
|
|
419
|
+
const content = {
|
|
420
|
+
text: text,
|
|
421
|
+
extendedTextMessage: {
|
|
422
|
+
text: text
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
// Extract URLs for contextInfo
|
|
426
|
+
if (this.extractFlag) {
|
|
427
|
+
const urls = (this.bodyText.match(/https?:\/\/[^\s)]+/g) || []);
|
|
428
|
+
if (urls.length > 0) {
|
|
429
|
+
content.contextInfo = {
|
|
430
|
+
externalAdReply: {
|
|
431
|
+
title: 'AI Response',
|
|
432
|
+
body: 'Powered by Waliwa',
|
|
433
|
+
mediaType: 1,
|
|
434
|
+
sourceUrl: urls[0]
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return content;
|
|
440
|
+
}
|
|
441
|
+
async send(sock, jid) {
|
|
442
|
+
return sock.sendMessage(jid, this.build());
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
exports.AIRichBuilder = AIRichBuilder;
|
|
446
|
+
//# sourceMappingURL=builder.js.map
|