@kangwifi-pro/waliwa 3.0.0 → 3.0.1

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/dist/index.d.ts CHANGED
@@ -37,7 +37,7 @@ export { MessageBuilder, ButtonBuilder, CarouselBuilder, AIRichBuilder, type But
37
37
  export { CommandSystem, type CommandContext, type CommandOptions, type CommandSystemOptions } from './helpers/command.js';
38
38
  export { AutoRejectCall, AutoRead, AutoPresence, Broadcast, Scheduler, RateLimiter } from './helpers/automation.js';
39
39
  export { PluginRegistry, PluginLoader, definePlugin, type Plugin, type PluginContext } from './helpers/plugin.js';
40
- export declare const VERSION = "3.0.0";
40
+ export declare const VERSION = "3.0.1";
41
41
  export declare const LIBRARY_NAME = "waliwa";
42
42
  export declare const BASED_ON = "Baileys 7 + zaileys + baileys-mbuilder";
43
43
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ Object.defineProperty(exports, "PluginRegistry", { enumerable: true, get: functi
86
86
  Object.defineProperty(exports, "PluginLoader", { enumerable: true, get: function () { return plugin_js_1.PluginLoader; } });
87
87
  Object.defineProperty(exports, "definePlugin", { enumerable: true, get: function () { return plugin_js_1.definePlugin; } });
88
88
  // ============== Version ==============
89
- exports.VERSION = '3.0.0';
89
+ exports.VERSION = '3.0.1';
90
90
  exports.LIBRARY_NAME = 'waliwa';
91
91
  exports.BASED_ON = 'Baileys 7 + zaileys + baileys-mbuilder';
92
92
  //# sourceMappingURL=index.js.map
package/docs/API.md ADDED
@@ -0,0 +1,311 @@
1
+ # API Reference
2
+
3
+ ## Core (Baileys 7 Re-exports)
4
+
5
+ | Export | Description |
6
+ |--------|-------------|
7
+ | `makeWASocket(config)` | Create WA socket (Baileys 7) |
8
+ | `useMultiFileAuthState(folder)` | File-based auth state |
9
+ | `useMultiFileAuthState` as `useAuthState` | Alias |
10
+ | `BufferJSON` | JSON serialization helpers |
11
+ | `proto` | Protobuf definitions |
12
+ | `Browsers` | Browser presets |
13
+ | `DisconnectReason` | Disconnect reason enum |
14
+ | `fetchLatestBaileysVersion()` | Fetch latest WA version |
15
+ | `getContentType(msg)` | Get message content type |
16
+ | `getDevice(msg)` | Get device info |
17
+ | `jidDecode(jid)` | Decode JID |
18
+ | `jidEncode(user, server)` | Encode JID |
19
+ | `jidNormalizedUser(jid)` | Normalize JID |
20
+ | `S_WHATSAPP_NET` | `"s.whatsapp.net"` constant |
21
+
22
+ ## Waliwa Exports
23
+
24
+ ### quickStart
25
+
26
+ ```typescript
27
+ quickStart({
28
+ authFolder: string,
29
+ browser?: [string, string, string],
30
+ printQRInTerminal?: boolean, // default: true
31
+ autoReconnect?: boolean, // default: true
32
+ reconnectDelayMs?: number, // default: 5000
33
+ markOnlineOnConnect?: boolean, // default: true
34
+ syncFullHistory?: boolean, // default: false
35
+ onOpen?: () => void,
36
+ onClose?: (statusCode: number, shouldReconnect: boolean) => void
37
+ }): Promise<WASocket>
38
+ ```
39
+
40
+ ### makeWASocketWithDefaults
41
+
42
+ Same as quickStart but accepts `authState` directly instead of `authFolder`.
43
+
44
+ ### MessageBuilder
45
+
46
+ ```typescript
47
+ new MessageBuilder(sock)
48
+ .to(jid)
49
+ .text(content) // Set text
50
+ .image(buffer, opts?) // Set image
51
+ .video(buffer, opts?) // Set video
52
+ .audio(buffer, opts?) // Set audio
53
+ .document(buffer, opts) // Set document
54
+ .sticker(buffer) // Set sticker
55
+ .location(lat, lon, opts?) // Set location
56
+ .contact(vcard, name?) // Set contact
57
+ .poll(question, options, opts?) // Set poll
58
+ .buttons(btns, opts?) // Set buttons
59
+ .carousel(cards, opts?) // Set carousel
60
+ .list(opts) // Set list message
61
+ .reply(message) // Reply to message
62
+ .mentions(jids) // Set mentions
63
+ .mentionAll() // Mention all group members (async)
64
+ .viewOnce() // View once
65
+ .ephemeral(seconds) // Ephemeral
66
+ .send() // Send (async)
67
+ .forwardTo(jid) // Forward (async)
68
+ .broadcast(jids, delayMs) // Broadcast (async)
69
+ ```
70
+
71
+ ### ButtonBuilder
72
+
73
+ ```typescript
74
+ new ButtonBuilder()
75
+ .text(body)
76
+ .button(label, id) // max 3
77
+ .footer(text)
78
+ .header(text)
79
+ .viewOnce()
80
+ .build() // returns content object
81
+ .send(sock, jid) // send directly
82
+ ```
83
+
84
+ ### CarouselBuilder
85
+
86
+ ```typescript
87
+ new CarouselBuilder()
88
+ .card(c => c
89
+ .image(src)
90
+ .title(text)
91
+ .text(text)
92
+ .button(label, id)
93
+ )
94
+ .build()
95
+ .send(sock, jid)
96
+ ```
97
+
98
+ ### AIRichBuilder
99
+
100
+ ```typescript
101
+ new AIRichBuilder()
102
+ .text(content) // supports [text](url) syntax
103
+ .extract(enabled?) // default: true
104
+ .hyperlink(enabled?) // default: true
105
+ .citation(enabled?) // default: true
106
+ .latex(enabled?) // default: true
107
+ .build()
108
+ .send(sock, jid)
109
+ ```
110
+
111
+ ### CommandSystem
112
+
113
+ ```typescript
114
+ new CommandSystem(sock, {
115
+ prefix: '!' | ['!', '/'],
116
+ ownerIds?: string[],
117
+ caseSensitive?: boolean // default: false
118
+ })
119
+
120
+ cmd.command(name | string[], handler)
121
+ cmd.command(name | string[], options, handler)
122
+ cmd.use(middleware)
123
+ cmd.ban(jid)
124
+ cmd.unban(jid)
125
+ cmd.addOwner(jid)
126
+ cmd.getCommands()
127
+ cmd.attach()
128
+ ```
129
+
130
+ #### CommandContext
131
+
132
+ Properties: `sock`, `message`, `jid`, `sender`, `text`, `command`, `args`, `fullText`, `isGroup`, `isFromMe`, `isOwner`, `senderName`, `quoted`, `mentions`
133
+
134
+ Methods: `reply(text)`, `replyWithMedia(buffer)`, `react(emoji)`, `sendTyping()`, `sendRecording()`, `stopTyping()`
135
+
136
+ ### AutoRejectCall
137
+
138
+ ```typescript
139
+ new AutoRejectCall(sock)
140
+ .start()
141
+ .allow(jid)
142
+ .stop()
143
+ ```
144
+
145
+ ### AutoRead
146
+
147
+ ```typescript
148
+ new AutoRead(sock, { excludeGroups?: boolean })
149
+ .start()
150
+ .stop()
151
+ ```
152
+
153
+ ### AutoPresence
154
+
155
+ ```typescript
156
+ new AutoPresence(sock)
157
+ .start()
158
+ .stop()
159
+ ```
160
+
161
+ ### Broadcast
162
+
163
+ ```typescript
164
+ new Broadcast(sock, defaultDelayMs?)
165
+ .send(jids, content, { delayMs?, onProgress? }) // returns [{ jid, success, error? }]
166
+ .sendText(jids, text, opts?)
167
+ ```
168
+
169
+ ### Scheduler
170
+
171
+ ```typescript
172
+ new Scheduler(sock)
173
+ .schedule(id, jid, content, delayMs) // returns id
174
+ .cancel(id) // returns boolean
175
+ .list() // returns [{ id, jid }]
176
+ .cancelAll()
177
+ ```
178
+
179
+ ### RateLimiter
180
+
181
+ ```typescript
182
+ new RateLimiter()
183
+ .setLimit(jid, max, windowMs)
184
+ .canSend(jid) // returns boolean
185
+ .getRemaining(jid) // returns number
186
+ .reset(jid)
187
+ ```
188
+
189
+ ### PluginRegistry
190
+
191
+ ```typescript
192
+ new PluginRegistry(sock)
193
+ .register(plugin, config?)
194
+ .unregister(name)
195
+ .get(name) // returns Plugin
196
+ .list() // returns [{ name, version, description }]
197
+ .has(name) // returns boolean
198
+ .unloadAll()
199
+ ```
200
+
201
+ ### PluginLoader
202
+
203
+ ```typescript
204
+ new PluginLoader(sock)
205
+ .getRegistry() // returns PluginRegistry
206
+ .loadFromDir(dir) // load all .js/.mjs files
207
+ .loadFile(filePath) // load single file
208
+ ```
209
+
210
+ ### definePlugin
211
+
212
+ ```typescript
213
+ definePlugin({
214
+ name: string,
215
+ version?: string,
216
+ description?: string,
217
+ dependencies?: string[],
218
+ onLoad?: (ctx) => void | Promise<void>,
219
+ onUnload?: () => void | Promise<void>,
220
+ onMessage?: (msg, ctx) => void | Promise<void>,
221
+ onConnectionUpdate?: (update, ctx) => void | Promise<void>,
222
+ commands?: Array<{ name, description?, handler }>
223
+ }): Plugin
224
+ ```
225
+
226
+ ### MediaHelper
227
+
228
+ Static methods:
229
+
230
+ | Method | Description |
231
+ |--------|-------------|
232
+ | `downloadFromMessage(sock, msg)` | Download media dari message |
233
+ | `downloadFromUrl(url)` | Download dari URL |
234
+ | `resizeImage(buffer, w, h, opts?)` | Resize image |
235
+ | `toWebP(buffer, opts?)` | Convert ke WebP |
236
+ | `toJPEG(buffer, quality?)` | Convert ke JPEG |
237
+ | `toPNG(buffer)` | Convert ke PNG |
238
+ | `getMetadata(buffer)` | Get { width, height, format, size } |
239
+ | `getMimeType(filename)` | Get MIME dari filename |
240
+ | `getExtension(mimetype)` | Get extension dari MIME |
241
+ | `saveToFile(buffer, path)` | Save ke file |
242
+ | `readFromFile(path)` | Read file ke buffer |
243
+ | `compress(buffer, quality?)` | Compress image |
244
+ | `createThumbnail(buffer, size?)` | Create thumbnail |
245
+ | `rotate(buffer, degrees)` | Rotate image |
246
+ | `flip(buffer, direction)` | Flip horizontal/vertical |
247
+ | `grayscale(buffer)` | Grayscale |
248
+ | `blur(buffer, sigma?)` | Blur |
249
+ | `addWatermark(buffer, text, opts?)` | Add text watermark |
250
+ | `toDataUrl(buffer, mimetype)` | Convert ke data URL |
251
+ | `fromDataUrl(dataUrl)` | Convert dari data URL |
252
+ | `formatSize(bytes)` | Format bytes ke human-readable |
253
+
254
+ ### StickerHelper
255
+
256
+ Static methods:
257
+
258
+ | Method | Description |
259
+ |--------|-------------|
260
+ | `fromImage(buffer, opts?)` | Sticker dari image |
261
+ | `fromVideo(buffer, opts?)` | Animated sticker dari video |
262
+ | `fromText(text, opts?)` | Sticker dari text |
263
+ | `fromFile(path, opts?)` | Sticker dari file |
264
+ | `fromUrl(url, opts?)` | Sticker dari URL |
265
+ | `normalize(buffer)` | Resize ke 512x512 WebP |
266
+ | `isWebP(buffer)` | Check jika WebP |
267
+ | `getDimensions(buffer)` | Get { width, height } |
268
+
269
+ StickerOptions: `{ pack?, author?, categories?, quality?, width?, height?, background?, fit? }`
270
+
271
+ ### MessageHelper
272
+
273
+ Static methods:
274
+
275
+ | Method | Description |
276
+ |--------|-------------|
277
+ | `getText(msg)` | Extract text dari message |
278
+ | `hasMedia(msg)` | Check jika ada media |
279
+ | `getMediaType(msg)` | Get media type string |
280
+ | `getSender(msg)` | Get sender JID |
281
+ | `getChat(msg)` | Get chat JID |
282
+ | `isFromMe(msg)` | Check jika dari bot |
283
+ | `isGroupMessage(msg)` | Check jika dari grup |
284
+ | `getMentions(msg)` | Get mentioned JIDs |
285
+ | `getQuoted(msg)` | Get quoted message |
286
+ | `reply(sock, msg, text, opts?)` | Reply ke message |
287
+ | `sendText(sock, jid, text, opts?)` | Send text |
288
+ | `sendWithMentions(sock, jid, text, jids)` | Send dengan mentions |
289
+ | `mentionAll(sock, groupJid, text?)` | Mention all members |
290
+ | `forward(sock, toJid, msg)` | Forward message |
291
+ | `delete(sock, msg)` | Delete message |
292
+ | `react(sock, msg, emoji)` | React ke message |
293
+ | `markAsRead(sock, key)` | Mark as read |
294
+ | `sendTyping(sock, jid)` | Typing indicator |
295
+ | `sendRecording(sock, jid)` | Recording indicator |
296
+ | `stopTyping(sock, jid)` | Stop typing |
297
+ | `formatTimestamp(ts)` | Format timestamp |
298
+ | `parseCommand(msg, prefix?)` | Parse command |
299
+ | `isCommand(msg, prefix?)` | Check jika command |
300
+ | `extractUrls(text)` | Extract URLs |
301
+ | `hasUrl(msg)` | Check jika ada URL |
302
+ | `getStatus(msg)` | Get message status |
303
+ | `isEmpty(msg)` | Check jika empty |
304
+
305
+ ## Constants
306
+
307
+ | Export | Value |
308
+ |--------|-------|
309
+ | `VERSION` | `'3.0.0'` |
310
+ | `LIBRARY_NAME` | `'waliwa'` |
311
+ | `BASED_ON` | `'Baileys 7 + zaileys + baileys-mbuilder'` |
@@ -0,0 +1,204 @@
1
+ # Examples
2
+
3
+ Complete examples untuk berbagai use case.
4
+
5
+ ## 1. Echo Bot
6
+
7
+ ```typescript
8
+ import { quickStart, MessageHelper } from '@kangwifi-pro/waliwa';
9
+
10
+ const sock = await quickStart({ authFolder: './auth' });
11
+
12
+ sock.ev.on('messages.upsert', async ({ messages, type }) => {
13
+ if (type !== 'notify') return;
14
+ for (const msg of messages) {
15
+ if (MessageHelper.isFromMe(msg)) continue;
16
+ const text = MessageHelper.getText(msg);
17
+ if (text) await MessageHelper.reply(sock, msg, `Echo: ${text}`);
18
+ }
19
+ });
20
+ ```
21
+
22
+ ## 2. Command Bot
23
+
24
+ ```typescript
25
+ import { quickStart, CommandSystem } from '@kangwifi-pro/waliwa';
26
+
27
+ const sock = await quickStart({ authFolder: './auth' });
28
+
29
+ const cmd = new CommandSystem(sock, { prefix: '!', ownerIds: ['628xxx@s.whatsapp.net'] });
30
+
31
+ cmd.command('ping', async (ctx) => {
32
+ await ctx.reply('pong! 🏓');
33
+ });
34
+
35
+ cmd.command('menu', async (ctx) => {
36
+ const commands = cmd.getCommands();
37
+ const menu = commands.map(c => `!${c.name} - ${c.description || ''}`).join('\n');
38
+ await ctx.reply(`*Menu*\n\n${menu}`);
39
+ });
40
+
41
+ cmd.command('kick', { adminOnly: true, cooldown: 5000 }, async (ctx) => {
42
+ const target = ctx.mentions[0] || ctx.quoted?.participant;
43
+ if (!target) return ctx.reply('Tag atau reply user');
44
+ await sock.groupParticipantsUpdate(ctx.jid, [target], 'remove');
45
+ });
46
+
47
+ cmd.use(async (ctx, next) => {
48
+ console.log(`[${ctx.senderName}] ${ctx.fullText}`);
49
+ await next();
50
+ });
51
+
52
+ cmd.attach();
53
+ ```
54
+
55
+ ## 3. Sticker Bot
56
+
57
+ ```typescript
58
+ import { quickStart, MessageHelper, MediaHelper, StickerHelper } from '@kangwifi-pro/waliwa';
59
+
60
+ const sock = await quickStart({ authFolder: './auth' });
61
+
62
+ sock.ev.on('messages.upsert', async ({ messages, type }) => {
63
+ if (type !== 'notify') return;
64
+ for (const msg of messages) {
65
+ if (MessageHelper.isFromMe(msg)) continue;
66
+ const text = MessageHelper.getText(msg);
67
+
68
+ if (text === '!sticker' && MessageHelper.hasMedia(msg)) {
69
+ await MessageHelper.sendTyping(sock, msg.key.remoteJid);
70
+ const buffer = await MediaHelper.downloadFromMessage(sock, msg);
71
+ const sticker = await StickerHelper.fromImage(buffer, { pack: 'Waliwa', author: 'Bot' });
72
+ await sock.sendMessage(msg.key.remoteJid, { sticker });
73
+ await MessageHelper.stopTyping(sock, msg.key.remoteJid);
74
+ }
75
+ }
76
+ });
77
+ ```
78
+
79
+ ## 4. Auto Bot (Read + Reject Call + Typing)
80
+
81
+ ```typescript
82
+ import { quickStart, AutoRead, AutoRejectCall, AutoPresence, CommandSystem } from '@kangwifi-pro/waliwa';
83
+
84
+ const sock = await quickStart({ authFolder: './auth' });
85
+
86
+ // Enable auto features
87
+ new AutoRead(sock).start();
88
+ new AutoRejectCall(sock).start();
89
+ new AutoPresence(sock).start();
90
+
91
+ // Commands
92
+ const cmd = new CommandSystem(sock, { prefix: '!' });
93
+ cmd.command('ping', async (ctx) => ctx.reply('pong!'));
94
+ cmd.attach();
95
+ ```
96
+
97
+ ## 5. Broadcast Bot
98
+
99
+ ```typescript
100
+ import { quickStart, Broadcast } from '@kangwifi-pro/waliwa';
101
+
102
+ const sock = await quickStart({ authFolder: './auth' });
103
+
104
+ const broadcast = new Broadcast(sock, 2000); // 2s delay between sends
105
+
106
+ // Broadcast to all group participants
107
+ sock.ev.on('messages.upsert', async ({ messages }) => {
108
+ for (const msg of messages) {
109
+ if (msg.message?.conversation === '!broadcast') {
110
+ const jid = msg.key.remoteJid;
111
+ if (!jid.endsWith('@g.us')) return;
112
+
113
+ const metadata = await sock.groupMetadata(jid);
114
+ const targets = metadata.participants.map(p => p.id);
115
+
116
+ const results = await broadcast.sendText(targets, '📢 Announcement!');
117
+ const success = results.filter(r => r.success).length;
118
+ await sock.sendMessage(jid, { text: `✅ Sent to ${success}/${targets.length}` });
119
+ }
120
+ }
121
+ });
122
+ ```
123
+
124
+ ## 6. Plugin-based Bot
125
+
126
+ ```typescript
127
+ import { quickStart, PluginLoader } from '@kangwifi-pro/waliwa';
128
+
129
+ const sock = await quickStart({ authFolder: './auth' });
130
+
131
+ const loader = new PluginLoader(sock);
132
+ await loader.loadFromDir('./plugins');
133
+
134
+ // plugins/ping.ts:
135
+ // export default definePlugin({
136
+ // name: 'ping',
137
+ // onMessage: async (msg, ctx) => {
138
+ // if (msg.message?.conversation === '!ping') {
139
+ // await ctx.sock.sendMessage(msg.key.remoteJid, { text: 'pong!' });
140
+ // }
141
+ // }
142
+ // });
143
+ ```
144
+
145
+ ## 7. Message Builder Bot
146
+
147
+ ```typescript
148
+ import { quickStart, MessageBuilder } from '@kangwifi-pro/waliwa';
149
+
150
+ const sock = await quickStart({ authFolder: './auth' });
151
+
152
+ sock.ev.on('messages.upsert', async ({ messages }) => {
153
+ for (const msg of messages) {
154
+ if (msg.message?.conversation === '!menu') {
155
+ const builder = new MessageBuilder(sock);
156
+ await builder
157
+ .to(msg.key.remoteJid)
158
+ .text('Choose an option:')
159
+ .buttons([
160
+ { label: 'Info', id: 'info' },
161
+ { label: 'Help', id: 'help' },
162
+ { label: 'Cancel', id: 'cancel' }
163
+ ])
164
+ .footer('Powered by Waliwa')
165
+ .reply(msg)
166
+ .send();
167
+ }
168
+ }
169
+ });
170
+ ```
171
+
172
+ ## 8. Scheduler Bot
173
+
174
+ ```typescript
175
+ import { quickStart, Scheduler, CommandSystem } from '@kangwifi-pro/waliwa';
176
+
177
+ const sock = await quickStart({ authFolder: './auth' });
178
+ const scheduler = new Scheduler(sock);
179
+
180
+ const cmd = new CommandSystem(sock, { prefix: '!' });
181
+
182
+ // !remind 10 Check the oven
183
+ cmd.command('remind', async (ctx) => {
184
+ const minutes = parseInt(ctx.args[0]);
185
+ const text = ctx.args.slice(1).join(' ');
186
+ if (!minutes || !text) return ctx.reply('Usage: !remind <minutes> <text>');
187
+
188
+ const id = `remind-${Date.now()}`;
189
+ scheduler.schedule(id, ctx.jid, { text: `⏰ Reminder: ${text}` }, minutes * 60 * 1000);
190
+ await ctx.reply(`✅ Reminder set for ${minutes} minutes`);
191
+ });
192
+
193
+ // !cancel <id>
194
+ cmd.command('cancel', { ownerOnly: true }, async (ctx) => {
195
+ const id = ctx.args[0];
196
+ if (scheduler.cancel(id)) {
197
+ await ctx.reply(`✅ Cancelled: ${id}`);
198
+ } else {
199
+ await ctx.reply('❌ Not found');
200
+ }
201
+ });
202
+
203
+ cmd.attach();
204
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangwifi-pro/waliwa",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "WhatsApp library based on Baileys 7 + zaileys + baileys-mbuilder. Super lightweight with MessageBuilder, CommandSystem, Automation, Plugin system, Media/Sticker helpers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,6 +44,7 @@
44
44
  },
45
45
  "files": [
46
46
  "dist/**/*",
47
+ "docs/**/*",
47
48
  "README.md",
48
49
  "LICENSE"
49
50
  ],