Skip to content

Code examples

Last updated: 2026-06-01

Runnable snippets for the most common integration jobs. All examples use the JavaScript SDK; the same patterns work in Python, Go, and .NET.

Sync extensions to your HRIS

const { data } = await client.extensions.list({ pageSize: 200 });
for (const ext of data) {
  await hris.upsertEmployee({
    employeeId: ext.email,
    extension: ext.number,
    presence: ext.presence,
  });
}

Screen-pop on inbound call (Node + Socket.IO)

client.events.subscribe([30011]).on("event", (e) => {
  if (e.data.state !== "ringing" || e.data.direction !== "inbound") return;
  const agentSocket = sockets.get(e.data.to); // map extension -> connected agent
  if (!agentSocket) return;
  agentSocket.emit("screen-pop", {
    caller: e.data.from,
    callId: e.data.call_id,
  });
});

Daily CDR export to S3

const job = await client.cdr.startExport({
  from: yesterdayStart,
  to: yesterdayEnd,
  format: "csv",
});
const url = await client.cdr.waitForExport(job.id);
const csv = await (await fetch(url)).text();
await s3.putObject({ Bucket: "audit", Key: `cdr/${date}.csv`, Body: csv });

Click-to-call from a CRM

// POST /click-to-call?ext=101&number=%2B46812345678
app.post("/click-to-call", async (req, res) => {
  await client.calls.originate({ from: req.query.ext, to: req.query.number });
  res.send("ringing");
});

Forward voicemail transcripts to Slack

client.events.subscribe([30015]).on("event", async (e) => {
  const transcript = await client.voicemail.transcript({ id: e.data.voicemail_id });
  await slack.chat.postMessage({
    channel: "#voicemail",
    text: `New voicemail for ${e.data.extension} from ${e.data.from}\n>${transcript.text}`,
  });
});

Need a snippet that's not here? Open a request in the changelog discussion.