Handing to a person
The hardest thing to build yourself, and the main reason not to.
A socket, a room, a reconnection policy and a protocol. Each one is possible alone and together they are the part of a custom interface most likely to be subtly wrong — in a way nobody notices until a customer is waiting on a reply that never arrives.
The states
| pending | Asked for, nobody has taken it. The agent has stopped answering. |
|---|---|
| active | A person has it. Visitor messages go to them; the agent stays out. |
| resolved | They finished. The agent answers again from the next message. |
| expired | Nobody came within an hour. Checked when the next message arrives, so the agent resumes then — a person can still pick it up later. |
Asking for a person
Minimal
const handoff = await chat.requestHuman(); // { id, status: "pending", waitMinutes: 10 }Realistic
const handoff = await chat.requestHuman({
reason: "Sofa arrived with a torn cushion — order HP-20931", // shown in the inbox
visitorName: "Sara", // optional
visitorEmail: "sara@example.com", // optional, must be an email
});
showBanner("Someone from the team will be with you shortly.");| reason | Optional, up to 500 characters. What the person in the inbox reads first. |
|---|---|
| visitorName | Optional, up to 100 characters. |
| visitorEmail | Optional. Must be a valid address, or the request is refused. |
| Returns | { id, status, waitMinutes } — the open request, and how many minutes the widget waits before it apologises for the delay (10). Use it for your own "still looking for someone" message. |
NoteAsking twice is safe
TipThe agent can ask too
handoff field on an event from ask().What happens next
const offs = [
chat.on("human", ({ name }) => showBanner(`${name} joined`)),
chat.on("message", (m) => append({ role: "human", text: m.content, author: m.authorName })),
chat.on("resolved", () => showBanner("Back to the assistant")),
];
// On unmount — every listener kept is a leak per mount
offs.forEach((off) => off());| human | { name } — somebody claimed the conversation. Fires when the server reports the status active. |
|---|---|
| message | { content, authorName?, timestamp? } — a reply from that person. Render it differently from the agent's. |
| resolved | They finished. The agent answers again from the next message. |
| typing | { who: "human", active } — the person is typing back (the server's agent_typing). See Feedback and typing. |
| error | TigerbaseError — live updates could not start, most often because socket.io-client is not installed. The HTTP calls still work. |
NoteThe agent stays out of it
ask() are still recorded and pushed to whoever is handling it — you do not have to suppress anything yourself.The socket is opened late, on purpose
Nothing connects until you call on() or requestHuman(). Before a handoff there is nothing to listen to, and a socket for every visitor who will never ask for a person is a connection per page view for nothing.
The socket identifies itself the way the server expects — the agent’s public key and the visitor id in the handshake’s auth, never in the URL — and the server checks the page’s domain against Allowed Domains exactly as it does for a message.
WarningIt needs socket.io-client installed
error event carrying a TigerbaseError (code unknown) that names the missing package, and requestHuman() still returns normally. Install it if you use handoff: npm i socket.io-client.chat.on("error", (err) => {
// Live updates are off. Fall back to polling handoffStatus().
console.warn(err.code, err.message);
startPolling();
});Without a socket
For an interface that cannot hold a connection open — a page that renders once, a polling context, or a runtime where the socket would not connect — ask over HTTP instead.
const status = await chat.handoffStatus();| { active: false } | No request is open: never asked, resolved, or lapsed unclaimed. |
|---|---|
| active: true | A request is open, and the response also carries id, status and agentMessages. |
| status | "pending" until a person claims it, then "active". |
| agentMessages | What people have written so far, oldest first — each { role: "agent", content, authorName?, timestamp? }. |
let shown = 0;
const timer = setInterval(async () => {
const s = await chat.handoffStatus();
if (!s.active) {
clearInterval(timer); // resolved or expired
showBanner("Back to the assistant");
return;
}
if (s.status === "active") showBanner("You're talking to the team");
s.agentMessages.slice(shown).forEach((m) =>
append({ role: "human", text: m.content, author: m.authorName }),
);
shown = s.agentMessages.length;
}, 4000);Offering it at all
The account can turn handoff off. Check before showing a button for something the account does not want offered.
{agent.handoffEnabled && (
<button onClick={() => chat.requestHuman({ reason: "Asked for a person" })}>
Talk to a person
</button>
)}NoteAn unclaimed request lapses quietly
handoffStatus() returns active: false from then on.