@sasadevofc/baileys 1.0.0-beta.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/.github/workflows/publish.yml +21 -0
- package/README.md +1 -0
- package/dist/auth/pairing.d.ts +7 -0
- package/dist/auth/pairing.d.ts.map +1 -0
- package/dist/auth/pairing.js +13 -0
- package/dist/auth/pairing.js.map +1 -0
- package/dist/auth/state.d.ts +14 -0
- package/dist/auth/state.d.ts.map +1 -0
- package/dist/auth/state.js +61 -0
- package/dist/auth/state.js.map +1 -0
- package/dist/auth/store.d.ts +16 -0
- package/dist/auth/store.d.ts.map +1 -0
- package/dist/auth/store.js +22 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +92 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/connection/handshake.d.ts +8 -0
- package/dist/connection/handshake.d.ts.map +1 -0
- package/dist/connection/handshake.js +12 -0
- package/dist/connection/handshake.js.map +1 -0
- package/dist/connection/socket.d.ts +19 -0
- package/dist/connection/socket.d.ts.map +1 -0
- package/dist/connection/socket.js +99 -0
- package/dist/connection/socket.js.map +1 -0
- package/dist/connection/transport.d.ts +8 -0
- package/dist/connection/transport.d.ts.map +1 -0
- package/dist/connection/transport.js +21 -0
- package/dist/connection/transport.js.map +1 -0
- package/dist/message/decoder.d.ts +7 -0
- package/dist/message/decoder.d.ts.map +1 -0
- package/dist/message/decoder.js +19 -0
- package/dist/message/decoder.js.map +1 -0
- package/dist/message/encoder.d.ts +7 -0
- package/dist/message/encoder.d.ts.map +1 -0
- package/dist/message/encoder.js +14 -0
- package/dist/message/encoder.js.map +1 -0
- package/dist/message/handler.d.ts +18 -0
- package/dist/message/handler.d.ts.map +1 -0
- package/dist/message/handler.js +87 -0
- package/dist/message/handler.js.map +1 -0
- package/dist/plugins/command.d.ts +10 -0
- package/dist/plugins/command.d.ts.map +1 -0
- package/dist/plugins/command.js +36 -0
- package/dist/plugins/command.js.map +1 -0
- package/dist/plugins/plugin-base.d.ts +11 -0
- package/dist/plugins/plugin-base.d.ts.map +1 -0
- package/dist/plugins/plugin-base.js +35 -0
- package/dist/plugins/plugin-base.js.map +1 -0
- package/dist/types/auth.d.ts +29 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/events.d.ts +54 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +3 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/messages.d.ts +30 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +3 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/plugin.d.ts +16 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +3 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/socket.d.ts +16 -0
- package/dist/types/socket.d.ts.map +1 -0
- package/dist/types/socket.js +3 -0
- package/dist/types/socket.js.map +1 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +14 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/retry.d.ts +2 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +18 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/throttle.d.ts +2 -0
- package/dist/utils/throttle.d.ts.map +1 -0
- package/dist/utils/throttle.js +14 -0
- package/dist/utils/throttle.js.map +1 -0
- package/examples/basic-bot.ts +29 -0
- package/examples/command-bot.ts +19 -0
- package/package.json +58 -0
- package/src/auth/pairing.ts +11 -0
- package/src/auth/state.ts +66 -0
- package/src/auth/store.ts +26 -0
- package/src/client.ts +119 -0
- package/src/config.ts +10 -0
- package/src/connection/handshake.ts +10 -0
- package/src/connection/socket.ts +109 -0
- package/src/connection/transport.ts +20 -0
- package/src/message/decoder.ts +13 -0
- package/src/message/encoder.ts +9 -0
- package/src/message/handler.ts +91 -0
- package/src/plugins/command.ts +40 -0
- package/src/plugins/plugin-base.ts +36 -0
- package/src/types/auth.ts +30 -0
- package/src/types/events.ts +60 -0
- package/src/types/messages.ts +34 -0
- package/src/types/plugin.ts +20 -0
- package/src/types/socket.ts +16 -0
- package/src/utils/logger.ts +10 -0
- package/src/utils/retry.ts +12 -0
- package/src/utils/throttle.ts +9 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { WAMessage, WAMessageUpdate } from './messages';
|
|
2
|
+
|
|
3
|
+
export interface ConnectionUpdate {
|
|
4
|
+
/** 'connecting' | 'open' | 'close' | 'qr' | 'pairing' | 'logged_in' */
|
|
5
|
+
status: string;
|
|
6
|
+
/** QR code string (base64 image) */
|
|
7
|
+
qr?: string;
|
|
8
|
+
/** Pairing code */
|
|
9
|
+
pairingCode?: string;
|
|
10
|
+
/** Error information */
|
|
11
|
+
error?: Error;
|
|
12
|
+
/** Whether the session was restored */
|
|
13
|
+
isNewSession?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface BaileysEventMap {
|
|
17
|
+
'connection.update': (update: ConnectionUpdate) => void;
|
|
18
|
+
'message.new': (msg: WAMessage) => void;
|
|
19
|
+
'message.update': (update: WAMessageUpdate) => void;
|
|
20
|
+
'message.receipt': (receipt: MessageReceipt) => void;
|
|
21
|
+
'group.participants.update': (update: GroupParticipantsUpdate) => void;
|
|
22
|
+
'presence.update': (update: PresenceUpdate) => void;
|
|
23
|
+
'contacts.update': (contacts: Contact[]) => void;
|
|
24
|
+
'reaction': (reaction: MessageReaction) => void;
|
|
25
|
+
'error': (error: Error) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MessageReceipt {
|
|
29
|
+
jid: string;
|
|
30
|
+
messageId: string;
|
|
31
|
+
status: 'delivered' | 'read' | 'played';
|
|
32
|
+
timestamp: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface GroupParticipantsUpdate {
|
|
36
|
+
groupJid: string;
|
|
37
|
+
action: 'add' | 'remove' | 'promote' | 'demote';
|
|
38
|
+
participants: string[];
|
|
39
|
+
actor?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PresenceUpdate {
|
|
43
|
+
jid: string;
|
|
44
|
+
status: 'available' | 'unavailable' | 'composing' | 'recording' | 'paused';
|
|
45
|
+
timestamp: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Contact {
|
|
49
|
+
jid: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
notify?: string;
|
|
52
|
+
verifiedName?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface MessageReaction {
|
|
56
|
+
messageId: string;
|
|
57
|
+
senderJid: string;
|
|
58
|
+
reaction: string; // emoji
|
|
59
|
+
timestamp: number;
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type WAMessageType = 'text' | 'image' | 'video' | 'audio' | 'document' | 'sticker' | 'reaction' | 'protocol';
|
|
2
|
+
|
|
3
|
+
export interface WAMessageBase {
|
|
4
|
+
id: string;
|
|
5
|
+
from: string; // JID of sender
|
|
6
|
+
to: string; // JID of recipient (chat)
|
|
7
|
+
timestamp: number;
|
|
8
|
+
messageType: WAMessageType;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TextMessage extends WAMessageBase {
|
|
12
|
+
messageType: 'text';
|
|
13
|
+
body: string;
|
|
14
|
+
mentionedJids?: string[];
|
|
15
|
+
quotedMessage?: Partial<WAMessage>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MediaMessage extends WAMessageBase {
|
|
19
|
+
messageType: 'image' | 'video' | 'audio' | 'document' | 'sticker';
|
|
20
|
+
mediaUrl?: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
fileSize?: number;
|
|
23
|
+
caption?: string;
|
|
24
|
+
thumbnail?: Buffer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type WAMessage = TextMessage | MediaMessage;
|
|
28
|
+
|
|
29
|
+
export interface WAMessageUpdate {
|
|
30
|
+
messageId: string;
|
|
31
|
+
status: 'edited' | 'deleted' | 'starred';
|
|
32
|
+
newBody?: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WAMessage, TextMessage } from './messages'; // đ Import TextMessage
|
|
2
|
+
import { BaileysClient } from '../client';
|
|
3
|
+
|
|
4
|
+
export type NextFunction = (err?: Error) => void;
|
|
5
|
+
|
|
6
|
+
export interface MiddlewareContext {
|
|
7
|
+
client: BaileysClient;
|
|
8
|
+
message: WAMessage;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type Middleware = (ctx: MiddlewareContext, next: NextFunction) => Promise<void> | void;
|
|
12
|
+
|
|
13
|
+
export interface CommandContext {
|
|
14
|
+
client: BaileysClient;
|
|
15
|
+
message: TextMessage; // đ āļ¯āˇāļąāˇ āļąāˇāˇāˇāļģāļ¯āˇ
|
|
16
|
+
args: string[];
|
|
17
|
+
commandName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type CommandHandler = (ctx: CommandContext) => Promise<void> | void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type WALoginMethod = 'qr' | 'pairing_code';
|
|
2
|
+
|
|
3
|
+
export interface SocketConfig {
|
|
4
|
+
/** WhatsApp multiâdevice WebSocket endpoint */
|
|
5
|
+
wsUrl: string;
|
|
6
|
+
/** Autoâreconnect on unexpected close */
|
|
7
|
+
autoReconnect: boolean;
|
|
8
|
+
/** Max reconnect attempts, -1 for infinite */
|
|
9
|
+
maxReconnectAttempts: number;
|
|
10
|
+
/** Delay between reconnections (ms) */
|
|
11
|
+
reconnectDelay: number;
|
|
12
|
+
/** Keepâalive interval (ms) */
|
|
13
|
+
keepAliveInterval: number;
|
|
14
|
+
/** Login method */
|
|
15
|
+
loginMethod: WALoginMethod;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
private level: string;
|
|
3
|
+
constructor(opts: { level: string }) {
|
|
4
|
+
this.level = opts.level || 'info';
|
|
5
|
+
}
|
|
6
|
+
info(...args: any[]) { console.log('[INFO]', ...args); }
|
|
7
|
+
error(...args: any[]) { console.error('[ERROR]', ...args); }
|
|
8
|
+
warn(...args: any[]) { console.warn('[WARN]', ...args); }
|
|
9
|
+
debug(...args: any[]) { console.debug('[DEBUG]', ...args); }
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export async function retry<T>(fn: () => Promise<T>, retries: number = 3, delayMs: number = 1000): Promise<T> {
|
|
2
|
+
let lastError: Error;
|
|
3
|
+
for (let i = 0; i < retries; i++) {
|
|
4
|
+
try {
|
|
5
|
+
return await fn();
|
|
6
|
+
} catch (err) {
|
|
7
|
+
lastError = err as Error;
|
|
8
|
+
if (i < retries - 1) await new Promise(res => setTimeout(res, delayMs));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
throw lastError!;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function throttle<T extends (...args: any[]) => any>(fn: T, limit: number): T {
|
|
2
|
+
let lastCall = 0;
|
|
3
|
+
return ((...args: any[]) => {
|
|
4
|
+
const now = Date.now();
|
|
5
|
+
if (now - lastCall < limit) return;
|
|
6
|
+
lastCall = now;
|
|
7
|
+
return fn(...args);
|
|
8
|
+
}) as unknown as T;
|
|
9
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"moduleResolution": "node"
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*.ts"],
|
|
18
|
+
"exclude": ["node_modules", "dist", "examples", "__tests__"]
|
|
19
|
+
}
|