TypeScript SDK
Run scoped bot operations with TypeScript and Effect.
Source-compatible installation in the TypeScript guideimport { Effect } from "effect";
import { SoulFire } from "@soulfiremc/sdk";
const baseUrl = process.env.SOULFIRE_URL;
const token = process.env.SOULFIRE_TOKEN;
if (!baseUrl || !token) {
throw new Error("Set SOULFIRE_URL and SOULFIRE_TOKEN first");
}
const program = Effect.scoped(
Effect.gen(function* () {
const client = yield* SoulFire.connect({ baseUrl, token });
const record = (yield* client.instances()).find(
(item) => item.friendlyName === "Docs tutorial",
);
if (!record) throw new Error("Create the Docs tutorial instance first");
const instance = client.instance(record.id);
const account = (yield* instance.bots()).find(
(item) => item.accountName === "DocsBot_1",
);
if (!account) throw new Error("Add the DocsBot_1 account first");
const bot = instance.bot(account.profileId);
yield* Effect.addFinalizer(() => bot.stop().pipe(Effect.orDie));
yield* bot.start();
yield* bot.waitForOnline();
yield* bot.chat.send("Hello from the TypeScript tutorial");
console.log(`Sent chat from ${account.accountName}; stopping the bot`);
}),
);
await Effect.runPromise(program);