@theophilusdev/conduit 1.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/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # conduit
2
+
3
+ [![GitHub](https://img.shields.io/badge/github-TheophilusWorks%2Fconduit-blue?logo=github)](https://github.com/TheophilusWorks/conduit)
4
+
5
+ > A lightweight TypeScript wrapper around [`@dongdev/fca-unofficial`](https://github.com/dongp06/fca-unofficial) with a clean, middleware-based event system.
6
+
7
+ ```ts
8
+ const conduit = new ConduitClient({ listenEvents: true });
9
+ await conduit.login({ appstate });
10
+
11
+ conduit.on("message:create", async (ctx) => {
12
+ await ctx.reply(`hey, you said: ${ctx.body}`);
13
+ });
14
+ ```
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install conduit
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```ts
25
+ import { ConduitClient } from "conduit";
26
+ import appstate from "./appstate.json" assert { type: "json" };
27
+
28
+ const conduit = new ConduitClient({ listenEvents: true });
29
+
30
+ await conduit.login({ appstate });
31
+
32
+ conduit.on("message:create", async (ctx, next) => {
33
+ if (ctx.body === "ping") {
34
+ await ctx.reply("pong");
35
+ return;
36
+ }
37
+ await next();
38
+ });
39
+ ```
40
+
41
+ ## Authentication
42
+
43
+ Pass **one** of the following to `.login()`:
44
+
45
+ | Strategy | Field | Notes |
46
+ | ---------------- | ------------------------------------ | ------------------------------------------------- |
47
+ | App state | `appstate` | Recommended |
48
+ | Raw cookies | `cookies` | Cookie header string |
49
+ | Email + password | `account.email` / `account.password` | Triggers checkpoints easily — avoid in production |
50
+
51
+ ```ts
52
+ // appstate (recommended)
53
+ await conduit.login({ appstate: [...] });
54
+
55
+ // raw cookies
56
+ await conduit.login({ cookies: "c_user=...; xs=..." });
57
+
58
+ // email/password (not recommended)
59
+ await conduit.login({ account: { email: "...", password: "..." } });
60
+ ```
61
+
62
+ ## Events
63
+
64
+ Register handlers with `.on(event, ...middlewares)`. Handlers receive an enriched context object and an optional `next` function to pass control down the stack.
65
+
66
+ All events include a `send(body)` helper. Events in the `message:*` namespace additionally include `reply(body)` and `react(emoji)`.
67
+
68
+ ### Message Events
69
+
70
+ | Event | Trigger |
71
+ | ----------------- | -------------------------------------------------------------- |
72
+ | `message:create` | New message received |
73
+ | `message:respond` | Reply to an existing message |
74
+ | `message:remove` | Message unsent by sender |
75
+ | `message:react` | Reaction added or removed |
76
+ | `message:writing` | User started or stopped typing (requires `listenTyping: true`) |
77
+ | `message:read` | Thread or message marked as read |
78
+
79
+ ### User Events
80
+
81
+ | Event | Trigger |
82
+ | ------------- | -------------------------------------------- |
83
+ | `user:create` | User added to a group thread |
84
+ | `user:remove` | User left or was removed from a group thread |
85
+
86
+ ### Thread Events
87
+
88
+ | Event | Trigger |
89
+ | ------------------------- | ------------------------------------------ |
90
+ | `thread:update` | Any thread metadata change (catch-all) |
91
+ | `thread:title_change` | Group title updated |
92
+ | `thread:photo_replaced` | Group photo changed |
93
+ | `thread:theme_changed` | Chat theme or color changed |
94
+ | `thread:nickname_changed` | A participant's nickname changed |
95
+ | `thread:admin_changed` | A participant promoted or demoted as admin |
96
+
97
+ ## Middleware
98
+
99
+ `.on()` accepts multiple handlers. Each must call `next()` to pass control to the next one.
100
+
101
+ ```ts
102
+ conduit.on(
103
+ "message:create",
104
+ async (ctx, next) => {
105
+ console.log("middleware 1");
106
+ await next();
107
+ },
108
+ async (ctx, next) => {
109
+ console.log("middleware 2");
110
+ await next();
111
+ },
112
+ );
113
+ ```
114
+
115
+ ## Raw FCA Access
116
+
117
+ For events or methods not yet covered by conduit, you can drop down to the raw FCA layer:
118
+
119
+ ```ts
120
+ // raw FCA event
121
+ conduit.onFca("presence", async (data) => {
122
+ console.log(data);
123
+ });
124
+
125
+ // raw FCA api (no type safety)
126
+ conduit.api.getThreadList(10, null, ["INBOX"]);
127
+ ```
128
+
129
+ ## API Reference
130
+
131
+ See [docs/DOCS.md](docs/DOCS.md) for the full API reference covering `client.messages`, `client.threads`, `client.users`, and `client.account`.
132
+
133
+ ## License
134
+
135
+ GNU GPL v3 © [theophilusdev](https://github.com/TheophilusWorks)
136
+
137
+ ---
138
+
139
+ Built on top of [`@dongdev/fca-unofficial`](https://github.com/dongp06/fca-unofficial). Credit to dongp06 and all contributors to the fca-unofficial project.