Freshsales and AI Call Studio
A new Freshsales contact is rung by your AI agent, and the outcome and summary are written back to that contact, 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 Freshsales and our API.
- Your Freshsales domain and API key, kept on that server.
- Our API key with contacts:write and calls:write.
What syncs, and which way?
From Freshsales to AI Call Studio
- New contacts, from a Freshsales workflow's webhook to your server, which adds them here and places the call.
From AI Call Studio to Freshsales
- From our call.completed webhook, your server writes the outcome and summary to the contact's custom fields, using Freshsales' own API.
What does not sync yet
- There is no built-in Freshsales connection yet: the recipe below is the connection.
The recipe
A new Freshsales contact is rung by your AI agent, and the outcome and summary are written back to that contact.
In Freshsales, add a Workflow on contact created with a Trigger Webhook action, pointed at your server or a connector rather than our API.
Your server upserts the contact here, found by number.
POST /api/v1/contactsThen it places the call. Each call is billed.
POST /api/calls/dialWhen the call ends, write the outcome with Freshsales' PUT /api/contacts/{id}.
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();
}
// 1. Freshsales 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_number || req.body.work_number,
name: [req.body.first_name, req.body.last_name].filter(Boolean).join(" "),
email: req.body.email,
source: "Freshsales",
custom_fields: { crm_id: crmId },
}, "crm-contact-" + crmId);
await db.saveCrmId(contact.id, crmId); // your own table: our contact id -> Freshsales 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 fetch("https://" + process.env.FRESHSALES_DOMAIN + ".myfreshworks.com/crm/sales/api/contacts/" + crmId, {
method: "PUT",
headers: { "Authorization": "Token token=" + process.env.FRESHSALES_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ contact: { custom_field: { cf_ai_call_outcome: call.disposition_label, cf_ai_call_summary: 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 →