Monitor chats

There are three ways to follow a chat:

  • Wait. One request that returns when the chat finishes or needs you. Best for scripts and agents.
  • Poll. Fetch the chat whenever you like.
  • Live stream. Every message and change, the moment it happens.

To be called instead of asking, use webhooks.

Wait

curl "https://api.refundhunter.io/api/tasks/$TASK_ID/wait?timeout=50" \
  -H "Authorization: Bearer $CHATTER_API_KEY"

It returns with a reason: finished, needs_help, new_messages (when you pass after), or timeout if nothing happened within the time you gave (up to 50 seconds). On timeout, call again. POST /api/tasks/wait does the same for a list of chats. Both are covered in Build an agent workflow.

Polling

curl https://api.refundhunter.io/api/tasks/$TASK_ID \
  -H "Authorization: Bearer $CHATTER_API_KEY"

What to look at:

FieldMeaning
statusscheduled, queued, idle, running, then one of the final values: completed, failed, cancelled
stateFiner progress while running: navigating, waiting_for_agent, in_conversation, ...
statusLineOne line from the AI on where the chat stands
transcriptEvery message so far. sender is customer (your side), agent (the retailer's rep) or system
activeInterventionPresent when the AI needs your help. See Step in
resultPresent when finished: status, summary, resolution

A good loop: poll every 5 to 10 seconds, stop on a final status, and act when activeIntervention appears. Chats usually take several minutes, much of it waiting in the retailer's queue.

GET /api/tasks returns all your chats in one request, which is cheaper than polling many ids one by one. Add view=summary to leave out transcripts, and GET /api/tasks/{id}/messages?after=N to fetch only new messages. The limit is 120 requests a minute for the whole account.

Reading the result

{
  "status": "completed",
  "result": {
    "status": "resolved",
    "summary": "Rep approved a full refund of $129.99 to the original payment method.",
    "resolution": "refund",
    "durationMs": 412000
  }
}

result.status is the outcome: resolved, unresolved, failed, timed_out or cancelled. Facts the AI pulled out of the chat (case number, refund amount, rep name) are saved on the linked order: see Orders and CSV upload.

Live stream

Open a WebSocket to wss://api.refundhunter.io and send your key as the first message, within 5 seconds:

{ "type": "auth", "token": "ck_live_..." }

You get { "type": "auth:ok" }, then a snapshot with all your chats, then events as they happen.

import WebSocket from 'ws';

const ws = new WebSocket('wss://api.refundhunter.io');
ws.on('open', () => ws.send(JSON.stringify({ type: 'auth', token: process.env.CHATTER_API_KEY })));
ws.on('message', (raw) => {
  const event = JSON.parse(raw);
  if (event.type === 'agent:message') console.log(event.agentId, event.messages);
  if (event.type === 'agent:intervention_requested') console.log('needs help:', event.intervention.reason);
  if (event.type === 'agent:completed') console.log('done:', event.result.status, event.result.summary);
});

In every event, agentId is the task id.

Events

EventWhenPayload
snapshotRight after connectingagents: all your chats
agent:tracked / agents:trackedNew chat(s) createdagent / agents
agent:state_changedProgress changesoldState, newState
agent:messageNew chat messagesmessages
agent:status_lineThe AI's one-line summary changesstatusLine
agent:typingSomeone is typingwho (support or ai), isTyping
agent:intervention_requestedThe AI needs your helpintervention
agent:intervention_resolvedA help request was answered
agent:pause_changedThe AI was paused or resumedisPaused
agent:completedThe chat finishedstate, result
agent:failedThe chat could not runerror
draft:created / draft:deletedDrafts changedagents / agentIds
order:updated, order:attempt_added, order:detail_added, order:detail_verified, order:event_addedAn order changedthe order, attempt, detail or event
usage:updatedCredits were usedcredits
errorA command you sent was refusedcode, message

Commands

You can also act over the same connection. Each mirrors a REST endpoint.

{ "type": "inject_message", "agentId": "<task id>", "content": "Please check again, the order shows delivered." }
{ "type": "pause_agent", "agentId": "<task id>" }
{ "type": "resume_agent", "agentId": "<task id>" }
{ "type": "resolve_intervention", "agentId": "<task id>", "response": { "action": "ignore_and_push" } }

If a command is refused you get an error event saying why. The connection allows 60 messages a minute. If it drops, reconnect and authenticate again; the new snapshot brings you up to date.