@rosyn/whats 0.0.0-stage → 0.1.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/README.md +354 -2
- package/assets/banner.jpg +0 -0
- package/dist/client/index.d.ts +96 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +224 -0
- package/dist/client/index.js.map +1 -0
- package/dist/codec/index.d.ts +8 -0
- package/dist/codec/index.d.ts.map +1 -0
- package/dist/codec/index.js +157 -0
- package/dist/codec/index.js.map +1 -0
- package/dist/compat/extensions.d.ts +219 -0
- package/dist/compat/extensions.d.ts.map +1 -0
- package/dist/compat/extensions.js +717 -0
- package/dist/compat/extensions.js.map +1 -0
- package/dist/compat/index.d.ts +41 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +2500 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/errors/index.d.ts +15 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +26 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.d.ts +12 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +48 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/media/index.d.ts +22 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +88 -0
- package/dist/media/index.js.map +1 -0
- package/dist/proto/index.d.ts +401 -0
- package/dist/proto/index.d.ts.map +1 -0
- package/dist/proto/index.js +1342 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/protocol/jid.d.ts +36 -0
- package/dist/protocol/jid.d.ts.map +1 -0
- package/dist/protocol/jid.js +95 -0
- package/dist/protocol/jid.js.map +1 -0
- package/dist/protocol/tokens.d.ts +3 -0
- package/dist/protocol/tokens.d.ts.map +1 -0
- package/dist/protocol/tokens.js +4 -0
- package/dist/protocol/tokens.js.map +1 -0
- package/dist/protocol/wabin.d.ts +8 -0
- package/dist/protocol/wabin.d.ts.map +1 -0
- package/dist/protocol/wabin.js +256 -0
- package/dist/protocol/wabin.js.map +1 -0
- package/dist/signal/index.d.ts +22 -0
- package/dist/signal/index.d.ts.map +1 -0
- package/dist/signal/index.js +62 -0
- package/dist/signal/index.js.map +1 -0
- package/dist/signal/protocol.d.ts +139 -0
- package/dist/signal/protocol.d.ts.map +1 -0
- package/dist/signal/protocol.js +620 -0
- package/dist/signal/protocol.js.map +1 -0
- package/dist/storage/index.d.ts +59 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +65 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/transport/websocket.d.ts +32 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +153 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types/index.d.ts +111 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/native/rosyn_whats_engine.node +0 -0
- package/package.json +54 -4
package/README.md
CHANGED
|
@@ -1,3 +1,355 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @rosyn/whats
|
|
4
|
+
|
|
5
|
+
Independent Multi-Device WhatsApp Messaging Library powered by **Rust**, **RosynDB**, and **RosynSession** for **Bun** and **Node.js**.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
- **RosynDB** (`packages/database` — `rosyn-db-engine`): Independent custom relational SQL engine in Rust (SQL lexer, recursive-descent parser, AST, semantic coercion, B-Tree indexes, versioned `.rdb` 4KB page manager with CRC32 checksums, bounded LRU buffer pool with pinning, append-only WAL with crash recovery, snapshot MVCC, savepoints, and AES-256-GCM encryption). Zero SQLite or external DB dependencies.
|
|
10
|
+
- **RosynSession** (`packages/session` — `rosyn-session-engine`): Lightweight, lazy-loaded, multi-account isolated session store backed by RosynDB with 9 normalized relational tables, bounded LRU+TTL caches, `CLEAN -> DIRTY -> PERSISTING -> CLEAN` dirty tracking, incremental batch persistence, and per-account AES-256-GCM key separation.
|
|
11
|
+
- **Native Engine** (`packages/native` — `rosyn-whats-engine`): N-API bindings exposing X25519/XEdDSA key operations, Noise_XX transport framing, HKDF-SHA256 media encryption, and hardened BinaryNode codec.
|
|
12
|
+
- **TypeScript SDK & Compat Layer** (`packages/whats`): `createClient` plus a Baileys-compatible `makeWASocket` / `useMultiFileAuthState` API backed by compact compressed SQL auth (`rosyn_auth.rdb`).
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Authentication & Compact Storage**: QR code & 8-char pairing code (`requestPairingCode`), ADV device-sign verification, `rosyn_auth.rdb` compressed SQL auth store with automatic Signal session/message-key pruning.
|
|
17
|
+
- **Signal E2EE & LID/PN Resolution**: Full X3DH + Double Ratchet (DM & `deviceSentMessage`), Group `SenderKey` (`skmsg` + `SenderKeyDistributionMessage`), automatic `<receipt type="retry">` handling, and transparent `@lid` -> `@s.whatsapp.net` resolution.
|
|
18
|
+
- **Messaging & Rich Media**:
|
|
19
|
+
- Text, ExtendedText (replies/`quoted`, mentions, `isGroupStatus`), React (`react`), Edit (`edit`), Delete/Revoke (`delete`), Poll (`poll`), Location (`location`), Contacts/vCard (`contacts`).
|
|
20
|
+
- Image, Video, Video Note (`ptv`), Audio/PTT (auto duration & 128-sample waveform via `ffmpeg`), Document, Sticker, and Sticker Pack (`stickerPack` with STORED ZIP + thumbnail upload).
|
|
21
|
+
- Interactive Native Flow, Carousel cards, Legacy Buttons, and `sendButtons` shorthand (`single_select`, `cta_url`, `cta_copy`, `quick_reply`).
|
|
22
|
+
- Media download (`downloadMediaMessage`), reupload retry (`updateMediaMessage`), and `readMessages` / per-chat `sendPresenceUpdate` (`composing` / `recording` / `paused`).
|
|
23
|
+
- **Groups & Communities**: `groupMetadata`, `groupFetchAllParticipating`, `groupCreate`, `groupLeave`, `groupParticipantsUpdate`, `groupSettingUpdate`, `groupUpdateSubject`, `groupUpdateDescription`, `groupInviteCode`, `groupRevokeInvite`, `groupAcceptInvite`, `groupGetInviteInfo`, `groupToggleEphemeral`, `groupMemberAddMode`, `groupJoinApprovalMode`, `groupRequestParticipants*`, and `community*` APIs, plus real-time `groups.update` & `group-participants.update` events.
|
|
24
|
+
- **Newsletters (Channels)**: Sending plaintext text/media to `@newsletter`, `newsletterMetadata`, `newsletterCreate`, `newsletterUpdate*`, `newsletterFollow`/`Unfollow`, `newsletterMute`/`Unmute`, `newsletterSubscribers`, `newsletterReactMessage`, `newsletterFetchMessages`.
|
|
25
|
+
- **Profile, Privacy, Business & App State**: `onWhatsApp`, `executeUSyncQuery`, `profilePictureUrl`, `updateProfile*`, `fetchStatus`, `fetchBlocklist`, `updateBlockStatus`, `fetchPrivacySettings`, `update*Privacy`, `presenceSubscribe`, `rejectCall`, `createCallLink`, Business/Catalog APIs, and `chatModify` / `star` / `appPatch`.
|
|
26
|
+
|
|
27
|
+
## Quick Start (`makeWASocket`)
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import makeWASocket, { useMultiFileAuthState } from "@rosyn/whats";
|
|
31
|
+
|
|
32
|
+
const { state, saveCreds } = await useMultiFileAuthState("./sessions");
|
|
33
|
+
const sock = makeWASocket({ auth: state });
|
|
34
|
+
|
|
35
|
+
sock.ev.on("creds.update", saveCreds);
|
|
36
|
+
sock.ev.on("messages.upsert", async ({ messages }) => {
|
|
37
|
+
const m = messages[0];
|
|
38
|
+
if (!m?.message || m.key.fromMe) return;
|
|
39
|
+
await sock.sendMessage(m.key.remoteJid!, { text: "Hello from @rosyn/whats!" }, { quoted: m });
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start (`createClient`)
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { createClient } from "@rosyn/whats";
|
|
47
|
+
|
|
48
|
+
const client = createClient({
|
|
49
|
+
storage: { type: "rosyndb", path: "./data/main.rdb" },
|
|
50
|
+
session: {
|
|
51
|
+
lazyLoad: true,
|
|
52
|
+
cache: { maxEntries: 500, maxMemoryBytes: 32 * 1024 * 1024, ttl: 300_000 },
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
client.on("connection.update", (u) => console.log(u));
|
|
57
|
+
await client.connect();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage Examples
|
|
61
|
+
|
|
62
|
+
### Pairing Code & Message Listener
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import makeWASocket, { DisconnectReason, useMultiFileAuthState } from "@rosyn/whats";
|
|
66
|
+
|
|
67
|
+
const { state, saveCreds } = await useMultiFileAuthState("./sessions");
|
|
68
|
+
const sock = makeWASocket({ auth: state });
|
|
69
|
+
|
|
70
|
+
sock.ev.on("creds.update", saveCreds);
|
|
71
|
+
|
|
72
|
+
if (!state.creds.registered) {
|
|
73
|
+
const code = await sock.requestPairingCode("6281234567890");
|
|
74
|
+
console.log("Pairing code:", code);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
sock.ev.on("connection.update", ({ connection, lastDisconnect }) => {
|
|
78
|
+
if (connection === "open") console.log("Connected:", sock.user?.id);
|
|
79
|
+
if (connection === "close") {
|
|
80
|
+
const code = (lastDisconnect?.error as any)?.output?.statusCode;
|
|
81
|
+
console.log("Closed:", code, code !== DisconnectReason.loggedOut);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
sock.ev.on("messages.upsert", async ({ messages }) => {
|
|
86
|
+
const m = messages[0];
|
|
87
|
+
if (!m?.message || m.key.fromMe) return;
|
|
88
|
+
const jid = m.key.remoteJid!;
|
|
89
|
+
const text = m.message.conversation || m.message.extendedTextMessage?.text || "";
|
|
90
|
+
if (text === ".ping") {
|
|
91
|
+
await sock.sendMessage(jid, { text: "Pong!" }, { quoted: m });
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Media, Voice Note (128-Sample Waveform), PTV & Download
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import fs from "node:fs";
|
|
100
|
+
import { downloadMediaMessage } from "@rosyn/whats";
|
|
101
|
+
|
|
102
|
+
// Image & Video
|
|
103
|
+
await sock.sendMessage(jid, {
|
|
104
|
+
image: fs.readFileSync("./foto.jpg"),
|
|
105
|
+
caption: "Image caption",
|
|
106
|
+
}, { quoted: m });
|
|
107
|
+
|
|
108
|
+
await sock.sendMessage(jid, {
|
|
109
|
+
video: fs.readFileSync("./video.mp4"),
|
|
110
|
+
caption: "Video caption",
|
|
111
|
+
gifPlayback: false,
|
|
112
|
+
}, { quoted: m });
|
|
113
|
+
|
|
114
|
+
// Video Note (PTV)
|
|
115
|
+
await sock.sendMessage(jid, {
|
|
116
|
+
video: fs.readFileSync("./note.mp4"),
|
|
117
|
+
ptv: true,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Voice Note (auto duration & 128-sample waveform via ffmpeg)
|
|
121
|
+
await sock.sendMessage(jid, {
|
|
122
|
+
audio: fs.readFileSync("./menu.ogg"),
|
|
123
|
+
mimetype: "audio/ogg; codecs=opus",
|
|
124
|
+
ptt: true,
|
|
125
|
+
}, { quoted: m });
|
|
126
|
+
|
|
127
|
+
// Document & Sticker
|
|
128
|
+
await sock.sendMessage(jid, {
|
|
129
|
+
document: fs.readFileSync("./file.pdf"),
|
|
130
|
+
mimetype: "application/pdf",
|
|
131
|
+
fileName: "report.pdf",
|
|
132
|
+
caption: "Monthly report",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await sock.sendMessage(jid, {
|
|
136
|
+
sticker: fs.readFileSync("./sticker.webp"),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Download media & retry expired media
|
|
140
|
+
const mediaBuffer = await downloadMediaMessage(m, "buffer");
|
|
141
|
+
const refreshed = await sock.updateMediaMessage(m);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Sticker Pack (`stickerPack`)
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
await sock.sendMessage(jid, {
|
|
148
|
+
stickerPack: {
|
|
149
|
+
name: "My Sticker Pack",
|
|
150
|
+
publisher: "RosynWhats",
|
|
151
|
+
caption: "Check out this pack!",
|
|
152
|
+
description: "Custom pack",
|
|
153
|
+
cover: fs.readFileSync("./cover.webp"),
|
|
154
|
+
stickers: [
|
|
155
|
+
{ sticker: fs.readFileSync("./s1.webp"), isAnimated: false, emojis: ["🔥"] },
|
|
156
|
+
{ sticker: fs.readFileSync("./s2.webp"), isAnimated: true, emojis: ["😂"] },
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
}, { quoted: m });
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### React, Edit, Delete, Poll, Location, Contacts & Group Status
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
// Reaction
|
|
166
|
+
await sock.sendMessage(jid, { react: { text: "🔥", key: m.key } });
|
|
167
|
+
|
|
168
|
+
// Edit & Delete (Revoke)
|
|
169
|
+
const sent = await sock.sendMessage(jid, { text: "Initial message" });
|
|
170
|
+
await sock.sendMessage(jid, { edit: sent.key, text: "Edited message" });
|
|
171
|
+
await sock.sendMessage(jid, { delete: m.key });
|
|
172
|
+
|
|
173
|
+
// Poll
|
|
174
|
+
await sock.sendMessage(jid, {
|
|
175
|
+
poll: { name: "Choose one:", values: ["Option A", "Option B"], selectableCount: 1 },
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Location
|
|
179
|
+
await sock.sendMessage(jid, {
|
|
180
|
+
location: {
|
|
181
|
+
degreesLatitude: -6.2088,
|
|
182
|
+
degreesLongitude: 106.8456,
|
|
183
|
+
name: "Jakarta",
|
|
184
|
+
address: "Indonesia",
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Contacts (single or multiple vCards)
|
|
189
|
+
await sock.sendMessage(jid, {
|
|
190
|
+
contacts: {
|
|
191
|
+
displayName: "Support",
|
|
192
|
+
contacts: [
|
|
193
|
+
{
|
|
194
|
+
displayName: "Owner",
|
|
195
|
+
vcard: "BEGIN:VCARD\nVERSION:3.0\nFN:Owner\nTEL;type=CELL:+6281234567890\nEND:VCARD",
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Group Status (SWGC)
|
|
202
|
+
await sock.sendMessage(groupJid, {
|
|
203
|
+
text: "Group status update",
|
|
204
|
+
contextInfo: { isGroupStatus: true, participant: sock.user.id },
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Interactive Buttons (`sendButtons` & `interactiveButtons`)
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
// Shorthand sendButtons (single_select, cta_url, cta_copy, quick_reply)
|
|
212
|
+
await sock.sendButtons(jid, {
|
|
213
|
+
image: fs.readFileSync("./banner.jpg"),
|
|
214
|
+
text: "Select an option:",
|
|
215
|
+
footer: "Theresav Bot",
|
|
216
|
+
messageParams: {
|
|
217
|
+
bottom_sheet: { in_thread_buttons_limit: 1, list_title: "Menu", button_title: "Open Menu" },
|
|
218
|
+
},
|
|
219
|
+
buttons: [
|
|
220
|
+
{
|
|
221
|
+
title: "Menu",
|
|
222
|
+
icon: "DEFAULT",
|
|
223
|
+
sections: [
|
|
224
|
+
{
|
|
225
|
+
title: "Categories",
|
|
226
|
+
rows: [
|
|
227
|
+
{ title: "All Commands", description: "View all features", id: ".menu all" },
|
|
228
|
+
{ title: "Owner", description: "Owner info", id: ".owner" },
|
|
229
|
+
],
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{ displayText: "Website", url: "https://example.com" },
|
|
234
|
+
{ displayText: "Copy Code", copyCode: "ROSYN-2026" },
|
|
235
|
+
{ displayText: "Ping", id: ".ping" },
|
|
236
|
+
],
|
|
237
|
+
}, { quoted: m });
|
|
238
|
+
|
|
239
|
+
// Raw nativeFlow interactiveButtons
|
|
240
|
+
await sock.sendMessage(jid, {
|
|
241
|
+
text: "Native Flow",
|
|
242
|
+
footer: "Footer",
|
|
243
|
+
interactiveButtons: [
|
|
244
|
+
{ name: "quick_reply", buttonParamsJson: JSON.stringify({ display_text: "OK", id: ".ok" }) },
|
|
245
|
+
],
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Carousel Cards (`cards`)
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
await sock.sendMessage(jid, {
|
|
253
|
+
title: "Product Catalog",
|
|
254
|
+
text: "Swipe to browse items",
|
|
255
|
+
footer: "Rosyn Shop",
|
|
256
|
+
cards: [
|
|
257
|
+
{
|
|
258
|
+
title: "Item 1",
|
|
259
|
+
body: "First card description",
|
|
260
|
+
footer: "Rp 50.000",
|
|
261
|
+
image: fs.readFileSync("./item1.jpg"),
|
|
262
|
+
buttons: [
|
|
263
|
+
{ name: "quick_reply", buttonParamsJson: JSON.stringify({ display_text: "Buy 1", id: ".buy 1" }) },
|
|
264
|
+
],
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
title: "Item 2",
|
|
268
|
+
body: "Second card description",
|
|
269
|
+
footer: "Rp 75.000",
|
|
270
|
+
image: fs.readFileSync("./item2.jpg"),
|
|
271
|
+
buttons: [
|
|
272
|
+
{ name: "cta_url", buttonParamsJson: JSON.stringify({ display_text: "Details", url: "https://example.com/2" }) },
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
}, { quoted: m });
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Groups & Communities
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
const meta = await sock.groupMetadata(groupJid);
|
|
283
|
+
const allGroups = await sock.groupFetchAllParticipating();
|
|
284
|
+
|
|
285
|
+
const created = await sock.groupCreate("New Group", ["6281234567890@s.whatsapp.net"]);
|
|
286
|
+
await sock.groupUpdateSubject(groupJid, "Updated Title");
|
|
287
|
+
await sock.groupUpdateDescription(groupJid, "Group rules...");
|
|
288
|
+
await sock.groupSettingUpdate(groupJid, "announcement"); // "announcement" | "not_announcement" | "locked" | "unlocked"
|
|
289
|
+
await sock.groupParticipantsUpdate(groupJid, ["6281234567890@s.whatsapp.net"], "promote");
|
|
290
|
+
await sock.groupToggleEphemeral(groupJid, 86400); // 24h disappearing messages
|
|
291
|
+
|
|
292
|
+
const code = await sock.groupInviteCode(groupJid);
|
|
293
|
+
const newCode = await sock.groupRevokeInvite(groupJid);
|
|
294
|
+
const info = await sock.groupGetInviteInfo(code!);
|
|
295
|
+
await sock.groupAcceptInvite(code!);
|
|
296
|
+
|
|
297
|
+
const pending = await sock.groupRequestParticipantsList(groupJid);
|
|
298
|
+
await sock.groupRequestParticipantsUpdate(groupJid, ["6281234567890@s.whatsapp.net"], "approve");
|
|
299
|
+
|
|
300
|
+
// Real-time group events
|
|
301
|
+
sock.ev.on("groups.update", (updates) => console.log("Group updated:", updates));
|
|
302
|
+
sock.ev.on("group-participants.update", (ev) => console.log("Participants changed:", ev));
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Newsletters (Channels)
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
const ch = await sock.newsletterMetadata("invite", "0029VaXXXXXX");
|
|
309
|
+
await sock.newsletterFollow(ch.id);
|
|
310
|
+
await sock.sendMessage("120363433405105703@newsletter", { text: "Channel update!" });
|
|
311
|
+
await sock.newsletterReactMessage("120363433405105703@newsletter", "123", "❤️");
|
|
312
|
+
await sock.newsletterMute("120363433405105703@newsletter");
|
|
313
|
+
await sock.newsletterUnfollow(ch.id);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Profile, Presence, Privacy, Calls & App State
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
// Number check & profile
|
|
320
|
+
const [check] = await sock.onWhatsApp("6281234567890");
|
|
321
|
+
const ppUrl = await sock.profilePictureUrl(jid, "image");
|
|
322
|
+
const [status] = await sock.fetchStatus(jid);
|
|
323
|
+
await sock.updateProfileName("Rosyn Bot");
|
|
324
|
+
await sock.updateProfileStatus("Online");
|
|
325
|
+
|
|
326
|
+
// Read receipts, typing indicator & presence
|
|
327
|
+
await sock.readMessages([m.key]);
|
|
328
|
+
await sock.sendPresenceUpdate("composing", jid); // "composing" | "recording" | "paused"
|
|
329
|
+
await sock.presenceSubscribe(jid);
|
|
330
|
+
|
|
331
|
+
// Blocklist & privacy
|
|
332
|
+
const blocked = await sock.fetchBlocklist();
|
|
333
|
+
await sock.updateBlockStatus(jid, "unblock");
|
|
334
|
+
const privacy = await sock.fetchPrivacySettings();
|
|
335
|
+
await sock.updateLastSeenPrivacy("contacts");
|
|
336
|
+
|
|
337
|
+
// Reject incoming call
|
|
338
|
+
sock.ev.on("call", async ([call]) => {
|
|
339
|
+
if (call?.status === "offer") await sock.rejectCall(call.id, call.from);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// Chat mutations (App State)
|
|
343
|
+
await sock.chatModify({ archive: true }, jid);
|
|
344
|
+
await sock.chatModify({ pin: true }, jid);
|
|
345
|
+
await sock.chatModify({ mute: Date.now() + 8 * 3600_000 }, jid);
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Development & Testing
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
npm run typecheck
|
|
352
|
+
npm run build:ts
|
|
353
|
+
npm run test:node
|
|
354
|
+
npm run test:bun
|
|
355
|
+
```
|
|
Binary file
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type EventListener } from "../events/index.js";
|
|
2
|
+
import { type WABinaryNode } from "../protocol/wabin.js";
|
|
3
|
+
import type { AuthUpdate, ClientEvents, ConnectionState, PersistenceStatus, RosynClientConfig, SessionMetadata } from "../types/index.js";
|
|
4
|
+
export declare class RosynWhatsClient {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly accountId;
|
|
7
|
+
private readonly accountIdentifier;
|
|
8
|
+
private readonly store;
|
|
9
|
+
private readonly signal;
|
|
10
|
+
private readonly bus;
|
|
11
|
+
private transport?;
|
|
12
|
+
private state;
|
|
13
|
+
private auth?;
|
|
14
|
+
private metadata?;
|
|
15
|
+
private loggedOut;
|
|
16
|
+
private closed;
|
|
17
|
+
constructor(config: RosynClientConfig);
|
|
18
|
+
on<K extends keyof ClientEvents>(event: K, listener: EventListener<ClientEvents[K]>): () => void;
|
|
19
|
+
off<K extends keyof ClientEvents>(event: K, listener: EventListener<ClientEvents[K]>): void;
|
|
20
|
+
connect(options?: {
|
|
21
|
+
liveTransport?: boolean;
|
|
22
|
+
wsUrl?: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
sendNode(node: WABinaryNode): void;
|
|
25
|
+
encryptPeerMessage(peerId: string, text: string): {
|
|
26
|
+
counter: number;
|
|
27
|
+
ciphertext: Buffer;
|
|
28
|
+
};
|
|
29
|
+
decryptPeerMessage(peerId: string, ciphertext: Uint8Array): string | undefined;
|
|
30
|
+
disconnect(reason?: string): Promise<void>;
|
|
31
|
+
logout(): Promise<void>;
|
|
32
|
+
destroy(): Promise<void>;
|
|
33
|
+
getConnectionState(): ConnectionState;
|
|
34
|
+
getSessionMetadata(): SessionMetadata | undefined;
|
|
35
|
+
restoreSession(): Promise<SessionMetadata | undefined>;
|
|
36
|
+
flushSession(): Promise<number>;
|
|
37
|
+
putAuthRecord(key: string, data: Uint8Array): void;
|
|
38
|
+
getAuthRecord(key: string): Buffer | null;
|
|
39
|
+
getPersistenceStatus(): PersistenceStatus;
|
|
40
|
+
sendMessage(to: string, content: {
|
|
41
|
+
text: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
id: string;
|
|
44
|
+
to: string;
|
|
45
|
+
status: "sent";
|
|
46
|
+
}>;
|
|
47
|
+
sendMedia(to: string, media: {
|
|
48
|
+
kind: "image" | "video" | "audio" | "document" | "sticker";
|
|
49
|
+
data: Uint8Array;
|
|
50
|
+
mimetype: string;
|
|
51
|
+
caption?: string;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
to: string;
|
|
55
|
+
bytes: number;
|
|
56
|
+
}>;
|
|
57
|
+
sendReaction(to: string, targetMessageId: string, emoji: string): Promise<{
|
|
58
|
+
id: string;
|
|
59
|
+
to: string;
|
|
60
|
+
emoji: string;
|
|
61
|
+
}>;
|
|
62
|
+
sendPoll(to: string, name: string, options: readonly string[]): Promise<{
|
|
63
|
+
id: string;
|
|
64
|
+
to: string;
|
|
65
|
+
name: string;
|
|
66
|
+
options: readonly string[];
|
|
67
|
+
}>;
|
|
68
|
+
sendLocation(to: string, latitude: number, longitude: number): Promise<{
|
|
69
|
+
id: string;
|
|
70
|
+
to: string;
|
|
71
|
+
latitude: number;
|
|
72
|
+
longitude: number;
|
|
73
|
+
}>;
|
|
74
|
+
sendContact(to: string, displayName: string, vcard: string): Promise<{
|
|
75
|
+
id: string;
|
|
76
|
+
to: string;
|
|
77
|
+
displayName: string;
|
|
78
|
+
vcard: string;
|
|
79
|
+
}>;
|
|
80
|
+
getGroups(): Promise<Array<{
|
|
81
|
+
id: string;
|
|
82
|
+
subject: string;
|
|
83
|
+
}>>;
|
|
84
|
+
getContacts(): Promise<Array<{
|
|
85
|
+
id: string;
|
|
86
|
+
name?: string;
|
|
87
|
+
}>>;
|
|
88
|
+
getProfile(): Promise<{
|
|
89
|
+
accountId: string;
|
|
90
|
+
identifier: string;
|
|
91
|
+
device?: AuthUpdate;
|
|
92
|
+
}>;
|
|
93
|
+
updatePresence(presence: "available" | "unavailable" | "composing" | "recording"): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
export declare function createClient(config: RosynClientConfig): RosynWhatsClient;
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK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,UAAU,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,UAAU,CAAA;KAAE,CAAC;IAIrF,cAAc,CAAC,QAAQ,EAAE,WAAW,GAAG,aAAa,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9G;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB,CAExE"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ValidationError } from "../errors/index.js";
|
|
3
|
+
import { TypedEventBus } from "../events/index.js";
|
|
4
|
+
import { proto } from "../proto/index.js";
|
|
5
|
+
import { decodeWABinaryNode, encodeWABinaryNode } from "../protocol/wabin.js";
|
|
6
|
+
import { RosynSignalEngine } from "../signal/index.js";
|
|
7
|
+
import { RosynSessionStorage } from "../storage/index.js";
|
|
8
|
+
import { WhatsAppWebSocketTransport } from "../transport/websocket.js";
|
|
9
|
+
const sharedStores = new Map();
|
|
10
|
+
function acquireStore(config) {
|
|
11
|
+
const key = `${config.storage.path}::${config.masterSecret ?? "rosyn-default-secret"}`;
|
|
12
|
+
const existing = sharedStores.get(key);
|
|
13
|
+
if (existing) {
|
|
14
|
+
existing.refs++;
|
|
15
|
+
return existing.store;
|
|
16
|
+
}
|
|
17
|
+
const store = new RosynSessionStorage({
|
|
18
|
+
dbPath: config.storage.path,
|
|
19
|
+
masterSecret: config.masterSecret ?? "rosyn-default-secret",
|
|
20
|
+
maxEntries: config.session?.cache?.maxEntries,
|
|
21
|
+
maxMemoryBytes: config.session?.cache?.maxMemoryBytes,
|
|
22
|
+
ttlMs: config.session?.cache?.ttl,
|
|
23
|
+
});
|
|
24
|
+
sharedStores.set(key, { store, refs: 1 });
|
|
25
|
+
return store;
|
|
26
|
+
}
|
|
27
|
+
function releaseStore(config) {
|
|
28
|
+
const key = `${config.storage.path}::${config.masterSecret ?? "rosyn-default-secret"}`;
|
|
29
|
+
const existing = sharedStores.get(key);
|
|
30
|
+
if (!existing)
|
|
31
|
+
return;
|
|
32
|
+
existing.refs--;
|
|
33
|
+
if (existing.refs <= 0) {
|
|
34
|
+
existing.store.close();
|
|
35
|
+
sharedStores.delete(key);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class RosynWhatsClient {
|
|
39
|
+
config;
|
|
40
|
+
accountId;
|
|
41
|
+
accountIdentifier;
|
|
42
|
+
store;
|
|
43
|
+
signal;
|
|
44
|
+
bus = new TypedEventBus();
|
|
45
|
+
transport;
|
|
46
|
+
state = "close";
|
|
47
|
+
auth;
|
|
48
|
+
metadata;
|
|
49
|
+
loggedOut = false;
|
|
50
|
+
closed = false;
|
|
51
|
+
constructor(config) {
|
|
52
|
+
if (!config.storage || config.storage.type !== "rosyndb" || !config.storage.path) {
|
|
53
|
+
throw new ValidationError("storage.type='rosyndb' and storage.path are required");
|
|
54
|
+
}
|
|
55
|
+
this.config = config;
|
|
56
|
+
this.accountId = config.accountId ?? `acc_${randomUUID()}`;
|
|
57
|
+
this.accountIdentifier = config.accountIdentifier ?? `${this.accountId}@s.whatsapp.net`;
|
|
58
|
+
this.store = acquireStore(config);
|
|
59
|
+
this.signal = new RosynSignalEngine(this.store, this.accountId);
|
|
60
|
+
const existing = this.store.listAccounts().find((a) => a.id === this.accountId);
|
|
61
|
+
if (existing) {
|
|
62
|
+
this.metadata = existing;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.metadata = this.store.createAccount(this.accountId, this.accountIdentifier);
|
|
66
|
+
this.bus.emit("session.update", { event: "SESSION_CREATED", accountId: this.accountId });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
on(event, listener) {
|
|
70
|
+
return this.bus.on(event, listener);
|
|
71
|
+
}
|
|
72
|
+
off(event, listener) {
|
|
73
|
+
this.bus.off(event, listener);
|
|
74
|
+
}
|
|
75
|
+
async connect(options) {
|
|
76
|
+
if (this.closed) {
|
|
77
|
+
throw new ValidationError("Client has been destroyed");
|
|
78
|
+
}
|
|
79
|
+
this.state = "connecting";
|
|
80
|
+
this.bus.emit("connection.update", { connection: "connecting" });
|
|
81
|
+
this.auth = this.store.provisionDevice(this.accountId, `dev_${this.accountId}`, 1001);
|
|
82
|
+
this.bus.emit("auth.update", this.auth);
|
|
83
|
+
if (options?.liveTransport) {
|
|
84
|
+
const ephPub = Buffer.from(this.auth.noisePublicKeyHex, "hex");
|
|
85
|
+
this.transport = new WhatsAppWebSocketTransport({
|
|
86
|
+
onFrame: (frame) => {
|
|
87
|
+
if (frame[0] === 0x00 || frame[0] === 0x02) {
|
|
88
|
+
try {
|
|
89
|
+
const node = decodeWABinaryNode(frame);
|
|
90
|
+
if (node.tag === "iq" && node.attrs.type === "set") {
|
|
91
|
+
this.bus.emit("connection.update", { connection: "connecting", qr: node.attrs.id });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Handshake frame
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
onClose: (_code, reason) => {
|
|
100
|
+
this.state = "close";
|
|
101
|
+
this.bus.emit("connection.update", { connection: "close", lastDisconnectReason: reason });
|
|
102
|
+
},
|
|
103
|
+
}, options.wsUrl);
|
|
104
|
+
this.transport.initNoise();
|
|
105
|
+
await this.transport.connect();
|
|
106
|
+
const hello = proto.HandshakeMessage.encode({ clientHello: { ephemeral: ephPub } });
|
|
107
|
+
this.transport.sendFramed(Buffer.from(hello));
|
|
108
|
+
}
|
|
109
|
+
this.state = "open";
|
|
110
|
+
this.bus.emit("connection.update", { connection: "open" });
|
|
111
|
+
}
|
|
112
|
+
sendNode(node) {
|
|
113
|
+
if (!this.transport) {
|
|
114
|
+
throw new ValidationError("Live transport is not connected");
|
|
115
|
+
}
|
|
116
|
+
this.transport.sendFramed(encodeWABinaryNode(node));
|
|
117
|
+
}
|
|
118
|
+
encryptPeerMessage(peerId, text) {
|
|
119
|
+
const encoded = proto.Message.encode({ conversation: text });
|
|
120
|
+
return this.signal.encrypt(peerId, encoded);
|
|
121
|
+
}
|
|
122
|
+
decryptPeerMessage(peerId, ciphertext) {
|
|
123
|
+
const pt = this.signal.decrypt(peerId, ciphertext);
|
|
124
|
+
return proto.Message.decode(pt).conversation;
|
|
125
|
+
}
|
|
126
|
+
async disconnect(reason = "client_disconnect") {
|
|
127
|
+
await this.flushSession();
|
|
128
|
+
this.state = "close";
|
|
129
|
+
this.bus.emit("connection.update", { connection: "close", lastDisconnectReason: reason });
|
|
130
|
+
}
|
|
131
|
+
async logout() {
|
|
132
|
+
this.state = "close";
|
|
133
|
+
if (!this.loggedOut) {
|
|
134
|
+
this.loggedOut = true;
|
|
135
|
+
this.store.destroyAccount(this.accountId);
|
|
136
|
+
}
|
|
137
|
+
this.bus.emit("session.update", { event: "SESSION_DESTROYED", accountId: this.accountId });
|
|
138
|
+
this.bus.emit("connection.update", { connection: "close", lastDisconnectReason: "logout" });
|
|
139
|
+
}
|
|
140
|
+
async destroy() {
|
|
141
|
+
if (this.closed)
|
|
142
|
+
return;
|
|
143
|
+
if (!this.loggedOut) {
|
|
144
|
+
await this.flushSession();
|
|
145
|
+
}
|
|
146
|
+
this.closed = true;
|
|
147
|
+
this.state = "close";
|
|
148
|
+
this.bus.clear();
|
|
149
|
+
releaseStore(this.config);
|
|
150
|
+
}
|
|
151
|
+
getConnectionState() {
|
|
152
|
+
return this.state;
|
|
153
|
+
}
|
|
154
|
+
getSessionMetadata() {
|
|
155
|
+
return this.metadata;
|
|
156
|
+
}
|
|
157
|
+
async restoreSession() {
|
|
158
|
+
const found = this.store.listAccounts().find((a) => a.id === this.accountId);
|
|
159
|
+
this.metadata = found;
|
|
160
|
+
if (found) {
|
|
161
|
+
this.bus.emit("session.update", { event: "SESSION_RESTORED", accountId: this.accountId });
|
|
162
|
+
}
|
|
163
|
+
return found;
|
|
164
|
+
}
|
|
165
|
+
async flushSession() {
|
|
166
|
+
this.bus.emit("session.persistence", {
|
|
167
|
+
event: "SESSION_WRITE_STARTED",
|
|
168
|
+
accountId: this.accountId,
|
|
169
|
+
recordsWritten: 0,
|
|
170
|
+
});
|
|
171
|
+
const written = this.store.flushAccount(this.accountId);
|
|
172
|
+
this.bus.emit("session.persistence", {
|
|
173
|
+
event: "SESSION_WRITE_COMPLETED",
|
|
174
|
+
accountId: this.accountId,
|
|
175
|
+
recordsWritten: written,
|
|
176
|
+
});
|
|
177
|
+
return written;
|
|
178
|
+
}
|
|
179
|
+
putAuthRecord(key, data) {
|
|
180
|
+
this.store.putSignalSession(this.accountId, key, data);
|
|
181
|
+
}
|
|
182
|
+
getAuthRecord(key) {
|
|
183
|
+
return this.store.getSignalSession(this.accountId, key);
|
|
184
|
+
}
|
|
185
|
+
getPersistenceStatus() {
|
|
186
|
+
return this.store.getMetrics();
|
|
187
|
+
}
|
|
188
|
+
async sendMessage(to, content) {
|
|
189
|
+
const id = `msg_${randomUUID()}`;
|
|
190
|
+
this.store.putSignalSession(this.accountId, to, new TextEncoder().encode(JSON.stringify({ lastMsg: id })));
|
|
191
|
+
return { id, to, status: "sent" };
|
|
192
|
+
}
|
|
193
|
+
async sendMedia(to, media) {
|
|
194
|
+
return { id: `media_${randomUUID()}`, to, bytes: media.data.byteLength };
|
|
195
|
+
}
|
|
196
|
+
async sendReaction(to, targetMessageId, emoji) {
|
|
197
|
+
return { id: `react_${targetMessageId}`, to, emoji };
|
|
198
|
+
}
|
|
199
|
+
async sendPoll(to, name, options) {
|
|
200
|
+
return { id: `poll_${randomUUID()}`, to, name, options };
|
|
201
|
+
}
|
|
202
|
+
async sendLocation(to, latitude, longitude) {
|
|
203
|
+
return { id: `loc_${randomUUID()}`, to, latitude, longitude };
|
|
204
|
+
}
|
|
205
|
+
async sendContact(to, displayName, vcard) {
|
|
206
|
+
return { id: `contact_${randomUUID()}`, to, displayName, vcard };
|
|
207
|
+
}
|
|
208
|
+
async getGroups() {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
async getContacts() {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
async getProfile() {
|
|
215
|
+
return { accountId: this.accountId, identifier: this.accountIdentifier, device: this.auth };
|
|
216
|
+
}
|
|
217
|
+
async updatePresence(presence) {
|
|
218
|
+
this.bus.emit("presence.update", { id: this.accountIdentifier, presence });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export function createClient(config) {
|
|
222
|
+
return new RosynWhatsClient(config);
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=index.js.map
|