@theophilusdev/conduit
    Preparing search index...

    Class ConduitClient

    High-level Messenger client built on top of the FCA unofficial API.

    Provides:

    • middleware-based event system (Koa-style)
    • typed APIs for messages, threads, users, and account control
    • automatic event enrichment and dispatch layer
    • internal typed event bus for ConduitMessageCollector and waitResponse

    All FCA events are funneled through dedicated FCA event bindings, normalized, enriched with helper methods, then dispatched onto both the middleware stack and the internal typed event bus.

    const conduit = new ConduitClient(config);
    await conduit.login(credentials);

    conduit.on("message:create", async (ctx, next) => {
    console.log(ctx.body);
    await next();
    });
    Index

    Constructors

    Accessors

    • get api(): any

      Raw FCA API access without type safety.

      Use only when Conduit APIs do not expose the functionality you need.

      Returns any

      client.api.getThreadList(10, null, ["INBOX"]);
      

    Methods

    • Creates a ConduitMessageCollector backed by the internal typed event bus.

      Collectors receive fully enriched Conduit payloads, not raw FCA events. The payload type is automatically derived as a union of all event payloads in the events array.

      Type Parameters

      Parameters

      Returns ConduitMessageCollector<K>

      A running ConduitMessageCollector instance.

      const collector = client.collect({
      timeout: 30_000,
      events: ["message:respond", "message:react"] as const,
      });

      collector.on("collect", (event) => {
      if (event.type === "message:react") console.log(event.reaction);
      else console.log(event.body);
      });
    • Manually emits a Conduit event, running it through both the internal event bus and the full middleware stack. Useful for synthetic events

      Type Parameters

      Parameters

      • event: K

        The Conduit event name to emit.

      • payload: Parameters<ConduitEvents[K]>[0]

        The fully formed payload to dispatch.

      Returns Promise<void>

    • Registers middleware for a Conduit event.

      Middleware executes sequentially and must call next() to continue the chain. Multiple middlewares can be registered per event.

      Type Parameters

      Parameters

      • event: K

        The Conduit event name to listen for.

      • ...middlewares: Middleware<K>[]

        Ordered middleware stack to register.

      Returns this

      client.on("message:create", async (ctx, next) => {
      if (ctx.body === "ping") return ctx.reply("pong");
      await next();
      });
    • Registers middleware on raw FCA events, bypassing the Conduit enrichment layer entirely.

      Useful for unsupported or experimental FCA events not yet mapped to Conduit event names.

      Parameters

      • event: string

        Raw FCA event name.

      • ...middlewares: ((data: any, next?: () => Promise<void>) => Promise<void>)[]

        Ordered middleware stack to register.

      Returns this

    • Waits for a single matching message and resolves with it.

      Internally creates a ConduitMessageCollector with max: 1 and resolves on the first collected payload, or rejects on timeout.

      Type Parameters

      • K extends readonly (keyof ConduitEvents)[] = ["message:respond"]
      • D = never

      Parameters

      • OptionaleventsOrOptions: K | Omit<CollectorOptions<K>, "max"> & { default?: D }
      • Optionaloptions: Omit<CollectorOptions<K>, "max"> & { default?: D }

        Collector options minus max, which is forced to 1. Pass default to resolve with a fallback value on timeout instead of throwing.

      Returns Promise<D | CollectorPayload<K>>

      A promise resolving with the first matching payload, or the default value on timeout.

      // Throws on timeout
      const reply = await client.waitResponse({
      timeout: 15_000,
      filter: (msg) => msg.senderID === expectedID,
      });

      // Resolves with null on timeout — no try/catch needed
      const reply = await client.waitResponse({
      timeout: 15_000,
      filter: (msg) => msg.senderID === expectedID,
      default: null,
      });
      if (!reply) return ctx.send("you took too long!");