const lead = await fetchLead({ source: "webform", timestamp: Date.now() }); const lead = await fetchLead({ source: "webform", timestamp: Date.now() }); const lead = await fetchLead({ source: "webform", timestamp: Date.now() });
if (lead.score > 0.85) { sendAlert("HOT", lead.phone); } if (lead.score > 0.85) { sendAlert("HOT", lead.phone); } if (lead.score > 0.85) { sendAlert("HOT", lead.phone); }
{ "name": "Johnson", "email": "buyer@realty.com", "interest": "3BR condo" } { "name": "Johnson", "email": "buyer@realty.com", "interest": "3BR condo" } { "name": "Johnson", "email": "buyer@realty.com", "interest": "3BR condo" }
classifyLead(data) => ai.score({ budget, timeline, location }); classifyLead(data) => ai.score({ budget, timeline, location }); classifyLead(data) => ai.score({ budget, timeline, location });
await sheets.append({ leadId, status: "warm", followUp: "2d" }); await sheets.append({ leadId, status: "warm", followUp: "2d" }); await sheets.append({ leadId, status: "warm", followUp: "2d" });
POST /api/leads → { classification: "cold", nextAction: "drip-3" } POST /api/leads → { classification: "cold", nextAction: "drip-3" } POST /api/leads → { classification: "cold", nextAction: "drip-3" }
router.post("/webhook", async (req) => { const lead = req.body; }); router.post("/webhook", async (req) => { const lead = req.body; }); router.post("/webhook", async (req) => { const lead = req.body; });
const response = await openai.chat({ role: "system", content: prompt }); const response = await openai.chat({ role: "system", content: prompt }); const response = await openai.chat({ role: "system", content: prompt });
{ "temperature": 0.7, "model": "gpt-4", "max_tokens": 150 } { "temperature": 0.7, "model": "gpt-4", "max_tokens": 150 } { "temperature": 0.7, "model": "gpt-4", "max_tokens": 150 }
function routeLead(lead) { return lead.hot ? "sms" : "email"; } function routeLead(lead) { return lead.hot ? "sms" : "email"; } function routeLead(lead) { return lead.hot ? "sms" : "email"; }
INSERT INTO leads (name, phone, score) VALUES ($1, $2, $3); INSERT INTO leads (name, phone, score) VALUES ($1, $2, $3); INSERT INTO leads (name, phone, score) VALUES ($1, $2, $3);
const twilioClient = twilio(accountSid, authToken); const twilioClient = twilio(accountSid, authToken); const twilioClient = twilio(accountSid, authToken);
gmail.send({ to: agent.email, subject: "New Hot Lead!", body: html }); gmail.send({ to: agent.email, subject: "New Hot Lead!", body: html }); gmail.send({ to: agent.email, subject: "New Hot Lead!", body: html });
if (prefers === "sheets") { await appendRow(spreadsheetId, values); } if (prefers === "sheets") { await appendRow(spreadsheetId, values); } if (prefers === "sheets") { await appendRow(spreadsheetId, values); }
const aiDraft = await generateReply({ tone: "professional", context }); const aiDraft = await generateReply({ tone: "professional", context }); const aiDraft = await generateReply({ tone: "professional", context });
scheduler.schedule("2d", () => sendFollowUp(lead.email)); scheduler.schedule("2d", () => sendFollowUp(lead.email)); scheduler.schedule("2d", () => sendFollowUp(lead.email));
export const config = { runtime: "edge", regions: ["iad1"] }; export const config = { runtime: "edge", regions: ["iad1"] }; export const config = { runtime: "edge", regions: ["iad1"] };
match (lead.urgency) { "high" => alert(), "low" => queue() } match (lead.urgency) { "high" => alert(), "low" => queue() } match (lead.urgency) { "high" => alert(), "low" => queue() }