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.
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.
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).
Your server upserts the lead as a contact, found by number.
POST /api/v1/contactsAdd it to a calling campaign, so it is rung within the campaign's hours. Each call is billed.
POST /api/v1/campaigns/{campaign_id}/contactsWhen 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
// 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.
Read next
HubSpot
After every AI call, the outcome, summary and score are written to the HubSpot contact the lead came from, through your own field map.
Read more →Zoho CRM
After every AI call, the outcome, summary and score are written to the matching Zoho CRM record, found by its id or by phone, through your field map.
Read more →Developers
The API, signed webhooks, the quickstart and recipes with code.
Read more →