JavaScript SDK
The official zero-dependency library: REST client, real-time bridge client and webhook verification, for Node.js 18+.
On this page
REST client What the client handles for youFollow events Bridge client Verify a webhook Complete examplesThe official JavaScript library, with no dependencies at all, covers the whole platform. It lives in the sdk/javascript folder of Robert's repository; the RobertLink Minecraft plugin sits next to it, in sdk/minecraft.
| JavaScript | |
|---|---|
| Folder | sdk/javascript |
| Requirements | Node.js 18 or later (ESM) |
| Installation | npm install ./sdk/javascript |
| Import | import { RobertClient } from "robert-sdk" |
| Types | TypeScript provided (index.d.ts) |
| Tests | node --test |
baseUrl is Robert's address, https://robert-bot.com/ (the API address, …/api/v1, also works).
Another language?
The routes are described in an OpenAPI 3.1 specification that client generators (openapi-generator, oapi-codegen…) can read. For Minecraft, use the RobertLink plugin rather than an SDK.
REST client
import { RobertClient, RobertApiError } from "robert-sdk";
const robert = new RobertClient({
baseUrl: "https://robert-bot.com/",
apiKey: process.env.ROBERT_KEY, // rbt_…
guildId: "987654321098765432",
language: "en", // language of error messages
});
const guild = await robert.guild(); // guild.read
const { items: channels } = await robert.channels({ limit: 50 });
const member = await robert.member("123456789012345678"); // members.read
await robert.addRole("123456789012345678", "700000000000000005"); // members.write
await robert.addXp("123456789012345678", 100, { reason: "Quest completed" });
const sent = await robert.sendMessage(
{ channelId: "800000000000000002", content: "Hello!" },
{ idempotencyKey: "welcome-42" },
);
await robert.editMessage(sent.result.message_id, { channelId: "800000000000000002", content: "Hello everyone!" });
await robert.createCase({ userId: "123456789012345678", action: "timeout", reason: "Spam", duration: 600 });
try {
await robert.member("1");
} catch (err) {
if (err instanceof RobertApiError) console.log(err.status, err.code, err.message);
}
What the client handles for you
- One method per route:
guild,channels,roles,analytics,member,leaderboard,links,addRole,removeRole,addXp,addBalance,sendMessage,editMessage,action,waitForAction,cases,createCase,giveaways,createGiveaway,events,streamEvents,sseEvents,bridges,createBridge,updateBridge,deleteBridge,regenerateBridgeToken,webhooks,createWebhook,updateWebhook,deleteWebhook,webhookDeliveries,testWebhook,paginate…. - Writes through the bot: the SDK asks for
wait=trueby default (10 seconds at most) and gives you the result.{ wait: false }returns{ action_id, status: "pending" }to follow withaction(id)orwaitForAction(id). - Idempotency: with an idempotency key, a write is automatically replayed on
429,5xxor network error; without a key, never (so nothing is done twice). - Retries: reads are replayed 2 times on
429(perRetry-After),502,503,504and network errors. - Pagination:
for await (const role of robert.paginate((o) => robert.roles(o))). - Rate:
robert.rateLimitgives{ limit, remaining, reset }of the last response. - Security: no redirect is followed, the key never goes elsewhere.
- Errors:
RobertApiError(status,code,details,retryAfter),RobertNetworkError,WebhookSignatureError.
Follow events
for await (const event of robert.streamEvents({ types: ["member.join", "case.create"] })) {
console.log(event.type, event.data); // long-polling with automatic resume
}
sseEvents does the same through Server-Sent Events. See Events.
Bridge client
import { BridgeClient } from "robert-sdk";
const bridge = new BridgeClient({ baseUrl: "https://robert-bot.com/", token: process.env.ROBERT_BRIDGE_TOKEN }); // rbb_…
// Discord → your application
bridge.on("chat", (e) => console.log(`${e.author.name}: ${e.message}`));
bridge.on("command", async (e) => { // Robert checked role and whitelist: keep yours!
if (e.command !== "list") return bridge.commandResult(e.command_id, false, "Refused");
bridge.commandResult(e.command_id, true, "There are 3 players");
});
bridge.on("link_result", (e) => console.log(e.ok ? `linked to ${e.discord.name}` : "code refused"));
// your application → Discord (queued, sent in batches, replayed if Robert is unreachable)
bridge.chat({ uuid: "069a79f4-44e9-4726-a5be-fca90e38aaf5", name: "Steve" }, "Hi!");
bridge.death({ uuid: "069a79f4-44e9-4726-a5be-fca90e38aaf5", name: "Steve" }, "Steve fell from a high place");
await bridge.start({
heartbeat: () => ({ online: 3, max: 50, players: [], version: "My game 1.0", tps: 20 }),
}); // ends with bridge.stop()
The bridge client takes care of long-polling (or SSE), reconnection with exponential delay, the cursor, the send queue in batches of 50, the heartbeat every 30 seconds and the safeguards: chat and command events older than 120 seconds are ignored, so are duplicates, and the cursor is saved before running a command (at most one execution). Call flush() before exiting to empty the queue.
Send shortcuts: chat, join, leave, death, advancement, status, serverStart, serverStop, commandResult, linkConfirm.
Verify a webhook
import express from "express";
import { constructWebhookEvent, WebhookSignatureError } from "robert-sdk";
const app = express();
app.post("/hooks/robert", express.raw({ type: "application/json" }), (req, res) => {
try {
const event = constructWebhookEvent(req.body, req.headers, process.env.ROBERT_WEBHOOK_SECRET);
console.log(event.type, event.data);
res.sendStatus(204);
} catch (err) {
if (err instanceof WebhookSignatureError) return res.sendStatus(401);
throw err;
}
});
The clock tolerance is 300 seconds (toleranceSeconds, 0 to disable it). Details, and examples without the SDK (Python, Node.js, Java, PHP), are in Outgoing webhooks.
Complete examples
The SDK contains an examples/ folder:
| Example | What it shows |
|---|---|
generic-bridge |
A generic bridge: terminal ⇄ Discord |
status-bot |
A status bot: a message updated every minute (scopes guild.read, messages.write, bridges) |
webhook-receiver |
A webhook receiver with signature verification |
Spotted a mistake? Got a question? Let us know on the support server.