Install
@cusuai/node signs a logged-in customer for the web widget. It does not mount a chat UI. Most servers only need identifySign.
npm install @cusuai/node Keep the identify secret in the environment. The route must require your own session. Read visitorId from the body. Read the customer id and traits from that session.
import { identifySign } from "@cusuai/node";
app.post("/api/cusu-identify", (req, res) => {
const visitorId = String(req.body.visitorId ?? "").trim();
if (!visitorId) {
res.status(400).json({ message: "visitorId required" });
return;
}
res.json(
identifySign({
isk: process.env.CUSU_IDENTIFY_SECRET,
visitorId,
externalId: req.user.id,
traits: {
name: req.user.name,
email: req.user.email
}
})
);
}); The response is { externalId, name?, email?, phone?, gender?, signedAt, signature }. The browser sends it straight to identify.
const visitorId = document.cookie
.split("; ")
.find((row) => row.startsWith("cusu_vid="))
?.split("=")[1];
const identity = await fetch("/api/cusu-identify", {
method: "POST",
headers: { "content-type": "application/json" },
credentials: "same-origin",
body: JSON.stringify({ visitorId })
}).then((response) => response.json());
Cusu.identify(identity.externalId, identity); On sign-out, call Cusu.reset() before the next identify. The payload that gets signed is documented in Identify. Every export is in the reference.