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:
| Field | Meaning |
|---|---|
status | scheduled, queued, idle, running, then one of the final values: completed, failed, cancelled |
state | Finer progress while running: navigating, waiting_for_agent, in_conversation, ... |
statusLine | One line from the AI on where the chat stands |
transcript | Every message so far. sender is customer (your side), agent (the retailer's rep) or system |
activeIntervention | Present when the AI needs your help. See Step in |
result | Present 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
| Event | When | Payload |
|---|---|---|
snapshot | Right after connecting | agents: all your chats |
agent:tracked / agents:tracked | New chat(s) created | agent / agents |
agent:state_changed | Progress changes | oldState, newState |
agent:message | New chat messages | messages |
agent:status_line | The AI's one-line summary changes | statusLine |
agent:typing | Someone is typing | who (support or ai), isTyping |
agent:intervention_requested | The AI needs your help | intervention |
agent:intervention_resolved | A help request was answered | |
agent:pause_changed | The AI was paused or resumed | isPaused |
agent:completed | The chat finished | state, result |
agent:failed | The chat could not run | error |
draft:created / draft:deleted | Drafts changed | agents / agentIds |
order:updated, order:attempt_added, order:detail_added, order:detail_verified, order:event_added | An order changed | the order, attempt, detail or event |
usage:updated | Credits were used | credits |
error | A command you sent was refused | code, 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.