@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.
@@ -0,0 +1,648 @@
1
+ import { MessengerBotOptions, MessengerBot } from '@dongdev/fca-unofficial';
2
+
3
+ /**
4
+ * A loose string type — behaves like `string` at runtime but preserves
5
+ * literal union autocomplete in the IDE via the `string & {}` trick.
6
+ */
7
+ type Loose = string & {};
8
+ /** Configuration options for the Conduit client. Extends {@link MessengerBotOptions}. */
9
+ interface ConduitClientConfig extends MessengerBotOptions {
10
+ }
11
+ /**
12
+ * Credentials used to authenticate the Conduit client with Facebook.
13
+ *
14
+ * Provide **one** of the following strategies (in order of recommendation):
15
+ * - `appstate` — array of appstate objects exported from a browser extension
16
+ * - `cookies` — raw cookie header string (`"c_user=...; xs=..."`)
17
+ * - `account` — email/password fallback (not recommended for production)
18
+ */
19
+ interface ConduitCredentials {
20
+ /** Facebook appstate — array of cookie-like objects. Recommended. */
21
+ appstate?: Loose[];
22
+ /** Raw cookie header string. */
23
+ cookies?: Loose;
24
+ /** Email/password login. Easily triggers checkpoints; avoid in production. */
25
+ account?: {
26
+ email: Loose;
27
+ password: Loose;
28
+ };
29
+ }
30
+ /**
31
+ * A message object shared across message events.
32
+ * Attachments are loosely typed until all shapes are confirmed.
33
+ */
34
+ interface Message {
35
+ threadID: string;
36
+ messageID: string;
37
+ senderID: string;
38
+ body: string;
39
+ attachments: any[];
40
+ mentions: Record<string, string>;
41
+ timestamp: string;
42
+ participantIDs: string[];
43
+ }
44
+ /**
45
+ * Base shape shared across all thread events fanned out from FCA `threadUpdate`.
46
+ * All thread sub-events include at minimum these fields.
47
+ */
48
+ interface ThreadEventBase {
49
+ threadID: string;
50
+ /** The user who performed the action. */
51
+ author: string;
52
+ participantIDs: string[];
53
+ }
54
+ /** Available on all Conduit event payloads. */
55
+ interface Sendable {
56
+ /** Send a message to the same thread. */
57
+ send(body: string): Promise<void>;
58
+ }
59
+ /** Available on message events only (`message:*`). */
60
+ interface Replyable extends Sendable {
61
+ /** Reply to this specific message. */
62
+ reply(body: string): Promise<void>;
63
+ /** React to this specific message with an emoji. */
64
+ react(emoji: string): Promise<void>;
65
+ }
66
+ /**
67
+ * Emitted when a new message is received. Maps to FCA `message`.
68
+ *
69
+ * @note FCA inconsistency: `timestamp` arrives as a string here,
70
+ * unlike `message_reply` where it is a number.
71
+ */
72
+ interface MessageCreatePayload extends Message, Replyable {
73
+ isGroup: boolean;
74
+ }
75
+ /** Emitted when a user replies to a message. Maps to FCA `message_reply`. */
76
+ interface MessageRespondPayload extends Message, Replyable {
77
+ isGroup: boolean;
78
+ /** The message being replied to. */
79
+ messageReply: Message;
80
+ }
81
+ /** Emitted when a message is unsent by its sender. Maps to FCA `message_unsend`. */
82
+ interface MessageRemovePayload extends Sendable {
83
+ threadID: string;
84
+ messageID: string;
85
+ senderID: string;
86
+ deletionTimestamp: number;
87
+ }
88
+ /** Emitted when a reaction is added or removed on a message. Maps to FCA `message_reaction`. */
89
+ interface MessageReactPayload extends Sendable {
90
+ threadID: string;
91
+ messageID: string;
92
+ /** The user who owns the message. */
93
+ senderID: string;
94
+ /** The user who reacted. */
95
+ reactorID: string;
96
+ reaction: string;
97
+ }
98
+ /** Emitted when a user starts or stops typing. Maps to FCA `typ`. */
99
+ interface MessageWritingPayload extends Sendable {
100
+ threadID: string;
101
+ senderID: string;
102
+ isTyping: boolean;
103
+ }
104
+ /** Emitted when a thread or message is marked as read. Maps to FCA `read_receipt`. */
105
+ interface MessageReadPayload extends Sendable {
106
+ threadID: string;
107
+ readerID: string;
108
+ time: string;
109
+ }
110
+ /**
111
+ * Emitted on any thread metadata change. Catch-all for the raw FCA `threadUpdate` event.
112
+ * For specific changes, prefer the narrower `thread:*` events.
113
+ */
114
+ interface ThreadUpdatePayload extends ThreadEventBase, Sendable {
115
+ logMessageType: string;
116
+ logMessageData: Record<string, any>;
117
+ }
118
+ /** Emitted when the group thread title is changed. Maps to FCA `threadUpdate` → `log:thread-name`. */
119
+ interface ThreadTitleChangePayload extends ThreadEventBase, Sendable {
120
+ /** The new thread title. */
121
+ name: string;
122
+ }
123
+ /** Emitted when the group photo is changed. Maps to FCA `threadUpdate` → `log:thread-image`. */
124
+ interface ThreadPhotoReplacedPayload extends ThreadEventBase, Sendable {
125
+ image: {
126
+ attachmentID: string;
127
+ width: number;
128
+ height: number;
129
+ url: string;
130
+ };
131
+ timestamp: string;
132
+ }
133
+ /** Emitted when the chat theme or color is changed. Maps to FCA `threadUpdate` → `log:thread-color`. */
134
+ interface ThreadThemeChangedPayload extends ThreadEventBase, Sendable {
135
+ themeColor: string;
136
+ gradient: string;
137
+ themeID: string;
138
+ accessibilityLabel: string;
139
+ themeName: string;
140
+ themeEmoji: string;
141
+ }
142
+ /** Emitted when a participant's nickname is changed. Maps to FCA `threadUpdate` → `log:user-nickname`. */
143
+ interface ThreadNicknameChangedPayload extends ThreadEventBase, Sendable {
144
+ /** The participant whose nickname was changed. */
145
+ participantID: string;
146
+ /** The new nickname. Empty string if cleared. */
147
+ nickname: string;
148
+ }
149
+ /** Emitted when a participant's admin status is changed. Maps to FCA `threadUpdate` → `log:thread-admins`. */
150
+ interface ThreadAdminChangedPayload extends ThreadEventBase, Sendable {
151
+ /** The participant whose admin status changed. */
152
+ targetID: string;
153
+ /** Whether the participant was promoted or demoted. */
154
+ adminEvent: "add_admin" | "remove_admin";
155
+ }
156
+ /** A participant added to a group thread. */
157
+ interface AddedParticipant {
158
+ fbid: string;
159
+ fullName: string;
160
+ }
161
+ /** Emitted when a user is added to a group thread. Maps to FCA `threadUpdate` → `log:subscribe`. */
162
+ interface UserCreatePayload extends ThreadEventBase, Sendable {
163
+ addedParticipants: AddedParticipant[];
164
+ }
165
+ /** Emitted when a user is removed from or leaves a group thread. Maps to FCA `threadUpdate` → `log:unsubscribe`. */
166
+ interface UserRemovePayload extends ThreadEventBase, Sendable {
167
+ /** The fbid of the participant who left or was removed. */
168
+ leftParticipantFbID: string;
169
+ }
170
+ /**
171
+ * All events emitted by the Conduit event bus.
172
+ *
173
+ * Thread sub-events (join, leave, title change, etc.) arrive as `threadUpdate` from
174
+ * FCA with a `logMessageType` discriminant — Conduit fans those out into the
175
+ * specific `thread:*` and `user:*` events below.
176
+ *
177
+ * @see https://github.com/dongp06/fca-unofficial — Section 15: Events Reference
178
+ */
179
+ interface ConduitEvents {
180
+ /** A new message was received. Maps to FCA `message`. */
181
+ "message:create": (data: MessageCreatePayload) => Promise<any>;
182
+ /** A message was unsent by its sender. Maps to FCA `message_unsend`. */
183
+ "message:remove": (data: MessageRemovePayload) => Promise<any>;
184
+ /** A reaction was added or removed on a message. Maps to FCA `message_reaction`. */
185
+ "message:react": (data: MessageReactPayload) => Promise<any>;
186
+ /** A reply was sent to an existing message. Maps to FCA `message_reply`. */
187
+ "message:respond": (data: MessageRespondPayload) => Promise<any>;
188
+ /** A user started or stopped typing. Maps to FCA `typ`. Requires `listenTyping: true`. */
189
+ "message:writing": (data: MessageWritingPayload) => Promise<any>;
190
+ /** A thread or message was marked as read. Maps to FCA `read_receipt`. */
191
+ "message:read": (data: MessageReadPayload) => Promise<any>;
192
+ /** A user was added to a group thread. Maps to FCA `threadUpdate` → `log:subscribe`. */
193
+ "user:create": (data: UserCreatePayload) => Promise<any>;
194
+ /** A user was removed from or left a group thread. Maps to FCA `threadUpdate` → `log:unsubscribe`. */
195
+ "user:remove": (data: UserRemovePayload) => Promise<any>;
196
+ /** Thread metadata changed (catch-all). Maps to raw FCA `threadUpdate`. */
197
+ "thread:update": (data: ThreadUpdatePayload) => Promise<any>;
198
+ /** The thread title was changed. Maps to FCA `threadUpdate` → `log:thread-name`. */
199
+ "thread:title_change": (data: ThreadTitleChangePayload) => Promise<any>;
200
+ /** The thread photo was changed. Maps to FCA `threadUpdate` → `log:thread-image`. */
201
+ "thread:photo_replaced": (data: ThreadPhotoReplacedPayload) => Promise<any>;
202
+ /** The thread theme/color was changed. Maps to FCA `threadUpdate` → `log:thread-color`. */
203
+ "thread:theme_changed": (data: ThreadThemeChangedPayload) => Promise<any>;
204
+ /** A participant's nickname was changed. Maps to FCA `threadUpdate` → `log:user-nickname`. */
205
+ "thread:nickname_changed": (data: ThreadNicknameChangedPayload) => Promise<any>;
206
+ /** A participant's admin status was changed. Maps to FCA `threadUpdate` → `log:thread-admins`. */
207
+ "thread:admin_changed": (data: ThreadAdminChangedPayload) => Promise<any>;
208
+ }
209
+ /** A middleware function for a specific Conduit event. */
210
+ type Middleware<K extends keyof ConduitEvents> = (data: Parameters<ConduitEvents[K]> extends [infer First, ...any[]] ? First : never, next?: () => Promise<void>) => Promise<void>;
211
+
212
+ /**
213
+ * Provides message-related API methods wrapping the underlying FCA client.
214
+ * Accessible via `client.messages`.
215
+ */
216
+ declare class ConduitMessagesAPI {
217
+ private readonly bot;
218
+ constructor(bot: MessengerBot);
219
+ /**
220
+ * Sends a message to a thread.
221
+ * @param body - The message text.
222
+ * @param threadID - The target thread ID.
223
+ */
224
+ send(body: string, threadID: string): Promise<any>;
225
+ /**
226
+ * Sends a quoted reply to a specific message.
227
+ * @param body - The reply text.
228
+ * @param threadID - The target thread ID.
229
+ * @param messageID - The message ID to reply to.
230
+ */
231
+ reply(body: string, threadID: string, messageID: string): Promise<any>;
232
+ /**
233
+ * Edits an existing message.
234
+ * @param messageID - The message ID to edit.
235
+ * @param body - The new message text.
236
+ */
237
+ edit(messageID: string, body: string): Promise<any>;
238
+ /**
239
+ * Unsends (retracts) a message sent by the bot.
240
+ * @param messageID - The message ID to unsend.
241
+ */
242
+ unsend(messageID: string): Promise<any>;
243
+ /**
244
+ * Deletes a message.
245
+ * @param messageID - The message ID to delete.
246
+ */
247
+ delete(messageID: string): Promise<any>;
248
+ /**
249
+ * Adds or removes a reaction on a message.
250
+ * @param emoji - The emoji reaction string.
251
+ * @param messageID - The target message ID.
252
+ * @param threadID - The thread the message belongs to.
253
+ */
254
+ react(emoji: string, messageID: string, threadID: string): Promise<any>;
255
+ /**
256
+ * Sends a typing indicator to a thread.
257
+ * @param threadID - The target thread ID.
258
+ */
259
+ sendTypingIndicator(threadID: string): Promise<any>;
260
+ /**
261
+ * Marks a message as read.
262
+ * @param messageID - The message ID to mark as read.
263
+ */
264
+ markAsRead(messageID: string): Promise<any>;
265
+ /**
266
+ * Uploads a file attachment and returns an attachment object.
267
+ * @param file - A readable stream or file buffer.
268
+ */
269
+ uploadAttachment(file: any): Promise<any>;
270
+ /**
271
+ * Forwards an existing attachment to another thread.
272
+ * @param attachmentID - The attachment ID to forward.
273
+ * @param threadID - The target thread ID.
274
+ */
275
+ forwardAttachment(attachmentID: string, threadID: string): Promise<any>;
276
+ /**
277
+ * Shares a contact card to a thread.
278
+ * @param userID - The user ID of the contact to share.
279
+ * @param threadID - The target thread ID.
280
+ */
281
+ shareContact(userID: string, threadID: string): Promise<any>;
282
+ /**
283
+ * Changes the color theme of a thread.
284
+ * @param color - The color hex string.
285
+ * @param threadID - The target thread ID.
286
+ */
287
+ changeThreadColor(color: string, threadID: string): Promise<any>;
288
+ /**
289
+ * Changes the quick-reaction emoji of a thread.
290
+ * @param emoji - The emoji string.
291
+ * @param threadID - The target thread ID.
292
+ */
293
+ changeThreadEmoji(emoji: string, threadID: string): Promise<any>;
294
+ /**
295
+ * Fetches a specific message by ID.
296
+ * @param messageID - The message ID to fetch.
297
+ */
298
+ getMessage(messageID: string): Promise<any>;
299
+ /**
300
+ * Returns all available thread color themes.
301
+ */
302
+ getThreadColors(): Promise<any>;
303
+ }
304
+
305
+ /**
306
+ * Provides thread-related API methods wrapping the underlying FCA client.
307
+ * Accessible via `client.threads`.
308
+ */
309
+ declare class ConduitThreadsAPI {
310
+ private readonly bot;
311
+ constructor(bot: MessengerBot);
312
+ /**
313
+ * Fetches detailed info about a thread.
314
+ * @param threadID - The thread ID to query.
315
+ */
316
+ getInfo(threadID: string): Promise<any>;
317
+ /**
318
+ * Fetches a paginated list of threads.
319
+ * @param limit - Number of threads to return.
320
+ * @param cursor - Pagination cursor, or `null` for the first page.
321
+ * @param folders - Folder filters e.g. `["INBOX"]`.
322
+ */
323
+ getList(limit: number, cursor: any, folders: string[]): Promise<any>;
324
+ /**
325
+ * Fetches message history for a thread.
326
+ * @param threadID - The thread ID to query.
327
+ * @param limit - Number of messages to return.
328
+ */
329
+ getHistory(threadID: string, limit: number): Promise<any>;
330
+ /**
331
+ * Searches for threads by name or keyword.
332
+ * @param query - The search query string.
333
+ */
334
+ search(query: string): Promise<any>;
335
+ /**
336
+ * Creates a new group conversation.
337
+ * @param userIDs - Array of user IDs to add to the group.
338
+ * @param name - Optional group name.
339
+ */
340
+ createGroup(userIDs: string[], name?: string): Promise<any>;
341
+ /**
342
+ * Adds a user to an existing group thread.
343
+ * @param userID - The user ID to add.
344
+ * @param threadID - The target group thread ID.
345
+ */
346
+ addUser(userID: string, threadID: string): Promise<any>;
347
+ /**
348
+ * Removes a user from a group thread.
349
+ * @param userID - The user ID to remove.
350
+ * @param threadID - The target group thread ID.
351
+ */
352
+ removeUser(userID: string, threadID: string): Promise<any>;
353
+ /**
354
+ * Promotes or demotes a user's admin status in a group.
355
+ * @param userID - The target user ID.
356
+ * @param threadID - The group thread ID.
357
+ * @param admin - `true` to promote, `false` to demote.
358
+ */
359
+ changeAdminStatus(userID: string, threadID: string, admin: boolean): Promise<any>;
360
+ /**
361
+ * Updates the group's profile image.
362
+ * @param image - A readable stream or file buffer.
363
+ * @param threadID - The target group thread ID.
364
+ */
365
+ changeGroupImage(image: any, threadID: string): Promise<any>;
366
+ /**
367
+ * Sets a participant's nickname in a thread.
368
+ * @param nickname - The new nickname. Pass an empty string to clear.
369
+ * @param threadID - The thread ID.
370
+ * @param userID - The target user ID.
371
+ */
372
+ changeNickname(nickname: string, threadID: string, userID: string): Promise<any>;
373
+ /**
374
+ * Changes the title of a group thread.
375
+ * @param title - The new group title.
376
+ * @param threadID - The target group thread ID.
377
+ */
378
+ setTitle(title: string, threadID: string): Promise<any>;
379
+ /**
380
+ * Creates a poll in a thread.
381
+ * @param title - The poll question.
382
+ * @param threadID - The target thread ID.
383
+ * @param options - Array of answer options.
384
+ */
385
+ createPoll(title: string, threadID: string, options: string[]): Promise<any>;
386
+ /**
387
+ * Deletes a thread.
388
+ * @param threadID - The thread ID to delete.
389
+ */
390
+ delete(threadID: string): Promise<any>;
391
+ /**
392
+ * Mutes or unmutes notifications for a thread.
393
+ * @param threadID - The target thread ID.
394
+ * @param muteUntil - Timestamp (ms) to mute until. Pass `-1` to mute indefinitely, `0` to unmute.
395
+ */
396
+ mute(threadID: string, muteUntil: number): Promise<any>;
397
+ /**
398
+ * Accepts or declines a message request.
399
+ * @param threadID - The thread ID of the request.
400
+ * @param accept - `true` to accept, `false` to decline.
401
+ */
402
+ handleMessageRequest(threadID: string, accept: boolean): Promise<any>;
403
+ }
404
+
405
+ /**
406
+ * Provides user-related API methods wrapping the underlying FCA client.
407
+ * Accessible via `client.users`.
408
+ */
409
+ declare class ConduitUsersAPI {
410
+ private readonly bot;
411
+ constructor(bot: MessengerBot);
412
+ /**
413
+ * Fetches info for one or more users by ID.
414
+ * @param userID - A single user ID or an array of user IDs.
415
+ */
416
+ getInfo(userID: string | string[]): Promise<any>;
417
+ /**
418
+ * Resolves a vanity URL or username to a Facebook user ID.
419
+ * @param vanity - The vanity name or profile URL slug.
420
+ */
421
+ getID(vanity: string): Promise<any>;
422
+ /**
423
+ * Returns the authenticated user's friends list.
424
+ */
425
+ getFriendsList(): Promise<any>;
426
+ }
427
+
428
+ /**
429
+ * Provides account-related API methods wrapping the underlying FCA client.
430
+ * Accessible via `client.account`.
431
+ */
432
+ declare class ConduitAccountAPI {
433
+ private readonly bot;
434
+ constructor(bot: MessengerBot);
435
+ /**
436
+ * Returns the logged-in user's Facebook ID.
437
+ */
438
+ getCurrentUserID(): string;
439
+ /**
440
+ * Blocks or unblocks a user.
441
+ * @param userID - The target user ID.
442
+ * @param block - `true` to block, `false` to unblock.
443
+ */
444
+ blockUser(userID: string, block: boolean): Promise<any>;
445
+ /**
446
+ * Accepts or declines a friend request.
447
+ * @param userID - The user ID who sent the request.
448
+ * @param accept - `true` to accept, `false` to decline.
449
+ */
450
+ handleFriendRequest(userID: string, accept: boolean): Promise<any>;
451
+ /**
452
+ * Removes a user from the friends list.
453
+ * @param userID - The target user ID.
454
+ */
455
+ unfriend(userID: string): Promise<any>;
456
+ /**
457
+ * Ends the current session and invalidates cookies.
458
+ */
459
+ logout(): Promise<any>;
460
+ }
461
+
462
+ /**
463
+ * High-level Messenger client that wraps the FCA unofficial API and exposes
464
+ * a middleware-based event system modelled after Express/Koa.
465
+ *
466
+ * @example
467
+ * ```ts
468
+ * const conduit = new ConduitClient(config);
469
+ * await conduit.login(credentials);
470
+ * conduit.on("message:text", async (ctx, next) => {
471
+ * console.log(ctx.body);
472
+ * await next();
473
+ * });
474
+ * ```
475
+ */
476
+ declare class ConduitClient {
477
+ /** Underlying FCA bot instance. `null` until {@link login} resolves. */
478
+ private _client;
479
+ /** Lazily-initialized messages API wrapper. */
480
+ private _messages;
481
+ /** Lazily-initialized threads API wrapper. */
482
+ private _threads;
483
+ /** Lazily-initialized users API wrapper. */
484
+ private _users;
485
+ /** Lazily-initialized account API wrapper. */
486
+ private _account;
487
+ /** Configuration forwarded to the FCA layer on login. */
488
+ private config;
489
+ /**
490
+ * Registry of middleware stacks keyed by Conduit event name.
491
+ * Each stack is executed in insertion order via {@link runStack}.
492
+ */
493
+ private middlewares;
494
+ /**
495
+ * Guards against registering the `threadUpdate` fan-out listener more than once,
496
+ * regardless of how many fan-out events are subscribed to.
497
+ */
498
+ private fanOutBound;
499
+ /**
500
+ * @param config - Client configuration passed through to the FCA bot.
501
+ */
502
+ constructor(config: ConduitClientConfig);
503
+ /**
504
+ * API for message operations.
505
+ *
506
+ * Provides methods for sending messages, replying to threads,
507
+ * reacting to messages, editing content, deleting messages,
508
+ * and other message-level interactions.
509
+ */
510
+ get messages(): ConduitMessagesAPI;
511
+ /**
512
+ * API for thread management operations.
513
+ *
514
+ * Includes functionality for retrieving thread data,
515
+ * managing participants, updating thread metadata (such as title),
516
+ * and handling thread-level features like polls.
517
+ */
518
+ get threads(): ConduitThreadsAPI;
519
+ /**
520
+ * API for user-related operations.
521
+ *
522
+ * Supports fetching user profiles, resolving user IDs,
523
+ * and accessing social graph data such as friends or connections.
524
+ */
525
+ get users(): ConduitUsersAPI;
526
+ /**
527
+ * API for account-level operations.
528
+ *
529
+ * Exposes actions tied to the authenticated account such as
530
+ * retrieving the current user ID, managing friend requests,
531
+ * blocking users, and logging out.
532
+ */
533
+ get account(): ConduitAccountAPI;
534
+ /**
535
+ * Authenticates with Messenger and initialises the underlying FCA bot.
536
+ * Must be called before any events can be received.
537
+ *
538
+ * @param credentials - App-state, cookies, or email/password credentials.
539
+ * @returns The current instance for chaining.
540
+ */
541
+ login(credentials: ConduitCredentials): Promise<this>;
542
+ /**
543
+ * Registers one or more middleware handlers for a Conduit event.
544
+ *
545
+ * The first call for a given event also binds the corresponding FCA listener.
546
+ * Fan-out events share a single `threadUpdate` FCA binding; all others get
547
+ * their own dedicated listener via {@link bindConduitEvent}.
548
+ *
549
+ * @param event - The Conduit event name to subscribe to.
550
+ * @param middlewares - Ordered middleware functions to push onto the stack.
551
+ * @returns The current instance for chaining.
552
+ */
553
+ on<K extends keyof ConduitEvents>(event: K, ...middlewares: Middleware<K>[]): this;
554
+ /**
555
+ * Registers middleware directly against a raw FCA event, bypassing the
556
+ * Conduit event abstraction entirely. Useful for events not yet mapped
557
+ * by the Conduit layer.
558
+ *
559
+ * @param event - Raw FCA event name.
560
+ * @param middlewares - Middleware functions receiving the raw FCA payload.
561
+ * @returns The current instance for chaining.
562
+ */
563
+ onFca(event: string, ...middlewares: ((data: any, next?: () => Promise<void>) => Promise<void>)[]): this;
564
+ /**
565
+ * Uses the raw legacy api. Not recommended as this do not
566
+ * have any type safety and auto-completion features. Use
567
+ * at your own risk.
568
+ *
569
+ * @returns The raw api context.
570
+ * */
571
+ get api(): any;
572
+ /**
573
+ * Translates a single Conduit event to its FCA equivalent and attaches a
574
+ * listener that enriches the raw payload before running the middleware stack.
575
+ *
576
+ * @param event - The Conduit event to bind.
577
+ */
578
+ private bindConduitEvent;
579
+ /**
580
+ * Returns the initialized Messenger client instance.
581
+ *
582
+ * This getter enforces the client lifecycle by ensuring that the underlying
583
+ * FCA bot has been created via {@link login} before any access is allowed.
584
+ *
585
+ * @throws {ConduitError} If the client has not been initialized yet (login not called).
586
+ * @returns {MessengerBot} The active Messenger bot instance.
587
+ */
588
+ private get client();
589
+ /**
590
+ * Attaches a single `threadUpdate` FCA listener that fans out to all
591
+ * relevant Conduit events based on the incoming `logMessageType`.
592
+ *
593
+ * `thread:update` always fires with the raw payload when its stack is
594
+ * non-empty. Specific sub-events (e.g. `thread:title_change`) fire only
595
+ * when their stack is also non-empty and a matching `logMessageType` exists.
596
+ *
597
+ * Calling this method more than once is a no-op.
598
+ */
599
+ private bindFanOutEvents;
600
+ /**
601
+ * Augments a raw FCA payload with convenience helpers scoped to the event.
602
+ *
603
+ * All events receive a `send` helper for replying to the source thread.
604
+ * Events in the `message:` namespace additionally receive:
605
+ * - `reply` — sends a quoted reply to the triggering message.
606
+ * - `react` — sets an emoji reaction on the triggering message.
607
+ *
608
+ * @param event - The Conduit event being enriched.
609
+ * @param raw - The raw FCA payload.
610
+ * @returns The enriched context object passed to middleware.
611
+ */
612
+ private enrich;
613
+ /**
614
+ * Executes a middleware stack sequentially, where each handler must call
615
+ * `next()` to advance to the following handler.
616
+ *
617
+ * @param stack - Ordered array of middleware functions to execute.
618
+ * @param data - The enriched event payload threaded through the stack.
619
+ */
620
+ private runStack;
621
+ }
622
+
623
+ declare const FCA_EVENT_MAP: {
624
+ readonly "message:create": "message";
625
+ readonly "message:remove": "message_unsend";
626
+ readonly "message:react": "message_reaction";
627
+ readonly "message:respond": "message_reply";
628
+ readonly "message:writing": "typ";
629
+ readonly "message:read": "read_receipt";
630
+ readonly "user:create": "event";
631
+ readonly "user:remove": "event";
632
+ readonly "thread:update": "event";
633
+ readonly "thread:title_change": "event";
634
+ readonly "thread:photo_replaced": "event";
635
+ readonly "thread:theme_changed": "event";
636
+ readonly "thread:nickname_changed": "event";
637
+ readonly "thread:admin_changed": "event";
638
+ };
639
+ type FcaEventName = (typeof FCA_EVENT_MAP)[keyof typeof FCA_EVENT_MAP];
640
+ declare function toFcaEvent(event: keyof ConduitEvents): FcaEventName;
641
+
642
+ declare class ConduitError extends Error {
643
+ constructor(message: string);
644
+ static new(message: string): ConduitError;
645
+ static uninitializedClient(): ConduitError;
646
+ }
647
+
648
+ export { type AddedParticipant, ConduitAccountAPI, ConduitClient, type ConduitClientConfig, type ConduitCredentials, ConduitError, type ConduitEvents, ConduitMessagesAPI, ConduitThreadsAPI, ConduitUsersAPI, type Loose, type Message, type MessageCreatePayload, type MessageReactPayload, type MessageReadPayload, type MessageRemovePayload, type MessageRespondPayload, type MessageWritingPayload, type Middleware, type Replyable, type Sendable, type ThreadAdminChangedPayload, type ThreadEventBase, type ThreadNicknameChangedPayload, type ThreadPhotoReplacedPayload, type ThreadThemeChangedPayload, type ThreadTitleChangePayload, type ThreadUpdatePayload, type UserCreatePayload, type UserRemovePayload, toFcaEvent };