Integration

LeadSquared and AI Call Studio

Each new LeadSquared lead gets an AI call, and the outcome comes back to the lead as a field update and an activity, through our API and webhooks.

Via our API Your developer, or ours, connects it with our API and signed webhooks: a ready recipe shows how.

All integrations

What you enter

  • A small server or connector of yours, between LeadSquared and our API.
  • Your LeadSquared access key, secret key and regional API host, kept on that server.
  • Our API key with contacts:write and campaigns:write.

What syncs, and which way?

From LeadSquared to AI Call Studio

  • New leads, from a LeadSquared automation's webhook to your server, which adds them here and to a calling campaign.

From AI Call Studio to LeadSquared

  • From our call.completed webhook, your server updates the lead and posts an activity with the summary, using LeadSquared's own API.

What does not sync yet

  • There is no built-in LeadSquared connection yet: the recipe below is the connection.

The recipe

Each new LeadSquared lead gets an AI call, and the outcome comes back to the lead as a field update and an activity your counsellors can see.

  • Permission contacts:write
  • Permission campaigns:write
  • Event call.completed
  • Event lead.captured
  • Places billed calls
  1. In LeadSquared, add an Automation on new leads with a Webhook action pointing at your server or a connector, not at our API (it needs our Bearer header).

  2. Your server upserts the lead as a contact, found by number. POST /api/v1/contacts

  3. Add it to a calling campaign, so it is rung within the campaign's hours. Each call is billed. POST /api/v1/campaigns/{campaign_id}/contacts

  4. When the call ends, update the lead with Lead.Update and post an activity with the summary, on your account's regional API host. 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();
}

const LSQ = "https://" + process.env.LSQ_HOST + "/v2";   // your region's API host
const auth = "accessKey=" + process.env.LSQ_ACCESS_KEY + "&secretKey=" + process.env.LSQ_SECRET_KEY;

// 1. LeadSquared sends a new lead to this URL.
app.post("/from-crm", express.json(), async (req, res) => {
  const lead = req.body;
  const contact = await ours("/api/v1/contacts", {
    phone: lead.Mobile || lead.Phone,
    name: [lead.FirstName, lead.LastName].filter(Boolean).join(" "),
    email: lead.EmailAddress,
    source: "LeadSquared",
    custom_fields: { crm_id: lead.ProspectID },
  }, "lsq-contact-" + lead.ProspectID);
  await db.saveCrmId(contact.id, lead.ProspectID);
  await ours(`/api/v1/campaigns/${process.env.CAMPAIGN_ID}/contacts`, {   // billed: the campaign rings them
    contacts: [{ phone: contact.phone, name: contact.name }],
  }, "lsq-campaign-" + lead.ProspectID);
  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 fetch(LSQ + "/LeadManagement.svc/Lead.Update?leadId=" + crmId + "&" + auth, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify([{ Attribute: "mx_Call_Outcome", Value: call.disposition_label }]),
      });
      await fetch(LSQ + "/ProspectActivity.svc/Create?" + auth, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ RelatedProspectId: crmId, ActivityEvent: Number(process.env.LSQ_ACTIVITY_CODE), ActivityNote: call.summary }),
      });
    }
  }
  res.sendStatus(200);
});

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.
  • API access is on Growth and above. Without it every request answers 402, and the key works again once the plan includes it.

Put AI Call Studio on your phone lines.

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