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

A request waits for a person, is taken, and is closed. An unclaimed one lapses after an hour.
pendingAsked for, nobody has taken it. The agent has stopped answering.
activeA person has it. Visitor messages go to them; the agent stays out.
resolvedThey finished. The agent answers again from the next message.
expiredNobody 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

ts
const handoff = await chat.requestHuman();   // { id, status: "pending", waitMinutes: 10 }

Realistic

Harbor & Pine — a damaged delivery
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.");
reasonOptional, up to 500 characters. What the person in the inbox reads first.
visitorNameOptional, up to 100 characters.
visitorEmailOptional. 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

If a request is already open this returns that one rather than stacking duplicates in the account’s inbox. You do not need to track whether you have asked.

TipThe agent can ask too

You do not have to put a button on screen for a person to be fetched. The agent can decide on its own mid-answer, and you will see it as a handoff field on an event from ask().

What happens next

What the server sends over the socket, and the event each one becomes.
Events
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.
resolvedThey 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.
errorTigerbaseError — 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

While a person is on the conversation the agent does not answer at all. Visitor messages sent with 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

The socket library is an optional peer, loaded the first time the socket is needed. Without it nothing is thrown from a call you did not make: the conversation emits an 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.
Knowing when live updates are off
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.

handoffStatus()
const status = await chat.handoffStatus();
{ active: false }No request is open: never asked, resolved, or lapsed unclaimed.
active: trueA request is open, and the response also carries id, status and agentMessages.
status"pending" until a person claims it, then "active".
agentMessagesWhat people have written so far, oldest first — each { role: "agent", content, authorName?, timestamp? }.
Polling
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.

components/Chat.tsx
{agent.handoffEnabled && (
  <button onClick={() => chat.requestHuman({ reason: "Asked for a person" })}>
    Talk to a person
  </button>
)}

NoteAn unclaimed request lapses quietly

A request nobody claims for an hour expires, and the agent resumes on the visitor’s next message, so nobody is left talking to no one. No event is sent when that happens — it is noticed when the next message arrives. If you are polling, handoffStatus() returns active: false from then on.