Integrations

Get Call Results: CDR + Recording

After a call ends, fetch its record and recording and store them in your application.

When a call ends, your backend looks up its call record (CDR) and its recording, and stores what your users need: status, duration, numbers and recording.

How it works

call ends ─▶ TryVox ── Hangup webhook (CallUUID) ──▶ your backend
                         ├─ GET /v1/account/{auth_id}/cdr/{CallUUID}               → numbers, duration, how it ended
                         └─ GET /v1/account/{auth_id}/recordings?call_uuid={CallUUID} → the recording, if any
                       ─▶ your CRM / app

Before you start

  • A call ID: CallUUID from the Hangup webhook, or the request_uuid from Make a Call. See Receive Call Events.
  • The shared tryvox.js and .env.
  • For a recording, the call must have been recorded.

Example

call-results.js
// After a call: fetch its record (CDR) and recording, to store in your app.
// Run: npm run call-results -- <call_uuid>   (call_uuid = CallUUID from the Hangup webhook)

import { realpathSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
import { API_URL, tryvox } from './tryvox.js';

export async function getCallResult(callUUID) {
  // The call record. Written a few seconds after the call ends, so a 404 right
  // after hangup just means "try again shortly".
  const { data } = await tryvox('GET', `/v1/account/{auth_id}/cdr/${encodeURIComponent(callUUID)}`);
  const cdr = data.cdr;

  // The recording, if the call was recorded. Its status is "pending" while the
  // file is still being stored.
  const recordings = await tryvox('GET', `/v1/account/{auth_id}/recordings?call_uuid=${encodeURIComponent(callUUID)}`);
  const rec = recordings.data[0];

  return {
    callUUID: cdr.uuid,
    from: cdr.caller_id_number,
    to: cdr.destination_number,
    direction: cdr.call_direction,
    answered: cdr.billsec > 0,
    seconds: cdr.billsec,
    hangupCause: cdr.hangup_cause,
    recording: rec
      ? {
          id: rec.id,
          status: rec.status, // available | pending
          // Needs your TryVox credentials, so download it server-side (or proxy it).
          streamUrl: `${API_URL}/v1/account/${rec.account_id}/recordings/${rec.id}/stream`,
        }
      : null,
  };
}

// Run directly from the command line?
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
  const callUUID = process.argv[2];
  if (!callUUID) throw new Error('usage: npm run call-results -- <call_uuid>');
  console.log(await getCallResult(callUUID));
}
npm run call-results -- 550e8400-e29b-41d4-a716-446655440000
{
  callUUID: '550e8400-e29b-41d4-a716-446655440000',
  from: '+918045671234',
  to: '+919812345678',
  direction: 'outbound',
  answered: true,
  seconds: 134,
  hangupCause: 'NORMAL_CLEARING',
  recording: { id: '0e4b2c1a-…', status: 'available', streamUrl: 'https://api.tryvox.io/v1/account/TJab12cd34/recordings/0e4b2c1a-…/stream' }
}

What your app can show:

Call status: Completed
Duration: 134 seconds
Recording: Available

To fetch results as soon as a call ends, call it from your webhook handler, for example inside handleCallEvent() in platform.js:

if (event.Event === 'Hangup') setTimeout(() => getCallResult(event.CallUUID).then(saveToCrm), 10_000);

What happens

  • The CDR detail comes back as {"data": {"cdr": {...}, "stream_cdrs": [...]}}. The example reads data.cdr.
  • The recordings list is filtered to the one call. status is pending while the file is still being stored, then available.
  • streamUrl needs your TryVox credentials. Download the file on your server, or proxy it to your users. Don't put the link with credentials in a browser.

Production note

  • The recording isn't in the webhook. call.ended and Hangup events don't carry a recording URL, so look it up as shown.
  • Fetch a little after hangup. The CDR is written a few seconds after the call ends and the recording is uploaded after that. Treat a 404 or a pending recording as "retry shortly".
  • Status words such as completed or busy come from the Hangup webhook's Status. The CDR gives the raw hangup_cause and billsec.

On this page