Developer use case

New CRM lead to AI call

A lead created in your CRM is rung by your AI agent within a minute, and the call's outcome is written back to that lead.

All use cases

Before you start

  • A live key with contacts:write and calls:write.
  • An automation in your CRM that can send a webhook on a new lead.
  • API access is on Growth and above. Without it every request answers 402, and the key works again once the plan includes it.

How it works

A lead created in your CRM is rung by your AI agent within a minute, and the call's outcome is written back to that lead.

  • Permission contacts:write
  • Permission calls:write
  • Event call.completed
  • Event lead.captured
  • Places billed calls
  1. In your CRM, add an automation on new leads that sends a webhook to your server or a connector. It cannot point at our API directly, because our API needs your key in a Bearer header.

  2. Your server adds or updates the lead as a contact, found by number, so a lead sent twice is one contact. Keep the CRM's record id on the contact. POST /api/v1/contacts

  3. Then it places the call, with an Idempotency-Key made from the CRM's record id, so a retried webhook never rings twice. Each call is billed. POST /api/calls/dial

  4. When the call ends, its outcome, summary and score arrive at your webhook. Write them to the CRM record you kept. call.completed

Your server (Node)
// Every delivery is signed: check it before you trust the body.
const crypto = require("crypto");
function signed(rawBody, header, secret) {
  const want = "sha256=" + crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
  return header && crypto.timingSafeEqual(Buffer.from(header), Buffer.from(want));
}

async function ours(path, body, idempotencyKey) {
  const res = await fetch("https://aicallstudio.com" + path, {
    method: "POST",
    headers: {
      "Authorization": "Bearer " + process.env.AICALLSTUDIO_KEY,
      "Content-Type": "application/json",
      "Idempotency-Key": idempotencyKey,
    },
    body: JSON.stringify(body),
  });
  if (!res.ok) throw new Error(path + " failed: " + res.status);
  return res.json();
}

// 1. your CRM sends a new lead to this URL.
app.post("/from-crm", express.json(), async (req, res) => {
  const crmId = req.body.id;
  const contact = await ours("/api/v1/contacts", {
    phone: req.body.mobile || req.body.phone,
    name: req.body.name,
    email: req.body.email,
    source: "your CRM",
    custom_fields: { crm_id: crmId },
  }, "crm-contact-" + crmId);
  await db.saveCrmId(contact.id, crmId);           // your own table: our contact id -> your CRM id
  await ours("/api/calls/dial", {                   // billed: this rings the lead
    phone: contact.phone,
    agent_id: process.env.AGENT_ID,
    name: contact.name,
  }, "crm-call-" + crmId);
  res.sendStatus(200);
});

// 2. Our webhook: call.completed goes back to the CRM record.
app.post("/aicallstudio", express.raw({ type: "*/*" }), async (req, res) => {
  if (!signed(req.body, req.get("X-Aicallstudio-Signature"), process.env.WEBHOOK_SECRET)) return res.sendStatus(401);
  const { event, data } = JSON.parse(req.body);
  if (event === "call.completed") {
    const call = data.call;
    const crmId = await db.crmIdFor(call.contact_id);
    if (crmId) {
      await crm.updateLead(crmId, {             // your CRM's own API
        call_outcome: call.disposition_label,
        call_summary: call.summary,
        call_score: call.score,
      });
    }
  }
  res.sendStatus(200);
});

Is my CRM built in already?

HubSpot, Zoho CRM, Salesforce, Odoo, eBhaya and NeoDove have a built-in connection: the outcome of every call is written to the matching record with no code, and new leads can reach us from the CRM's own webhook. See Integrations. Use this recipe for any other CRM, or for fields the built-in connection does not cover.

Costs and what to watch

  • Every call the API places is a real call to a real person, billed from your wallet like any other call, at your plan's rates. Try it on your own number first.

Put AI Call Studio on your phone lines.

Book a 30-minute walkthrough, or call us right now: +91 922 222 1378