

Field Label | Field Type | Purpose |
Hot Lead Flag | Checkbox | Marks highly interested leads. |
Email Intent | Picklist | Stores detected intent such as Purchase Intent, General Inquiry, or Neutral. |
Intent Detected Time | Date-Time | Stores the last intent detection time. |
Alert Sent | Checkbox | Indicates whether an alert email was sent to the sales representative. |
We will continue using the following existing Lead fields in this implementation:
Existing Field | Purpose |
Lead Status | Updated to Interested when purchase intent is detected. |
Rating | Updated to Active for interested leads. |
Owner | Used to notify the assigned sales representative. |

leadData = zoho.crm.getRecordById("Leads", leadIdLong); leadName = leadData.get("Full_Name"); company = leadData.get("Company"); leadEmail = leadData.get("Email"); owner = leadData.get("Owner"); ownerName = owner.get("name"); ownerEmail = owner.get("email"); // Alert will be sent here ownerId = owner.get("id"); // Task will be assigned here |
emailsResp = invokeurl [ url: ".../Leads/{id}/Emails" ... ]; // Loop — find latest email sent by the Lead if(senderEmail.toLowerCase() == leadEmail.toLowerCase()) { isIncoming = true; latestIncomingEmail = email; // keep the most recent } |
analysisPrompt = "You are an enterprise-grade B2B sales intent detection AI. Analyze the incoming lead email and determine whether the customer shows strong and genuine PURCHASE_INTENT. Strong purchase intent includes asking for pricing, quotation, demo, free trial, implementation, onboarding, integrations, contract discussion, deployment timelines, budget approval, commercial discussion, next steps, or clear evaluation of the product for business adoption. Ignore greetings, thank you emails, support requests, informational questions, casual discussions, or unrelated conversations. Respond ONLY with YES if the lead is highly likely to purchase or actively evaluate the product for buying decision. Otherwise respond ONLY with NO.\n\nSubject:" + emailSubject + "\n\nEmail Content: " + cleanBody; ziaResponse = invokeurl [ url: ".../zia/smart_prompt/assistant" type: POST parameters: requestPayload.toString() ... ]; |
aiResponse = ziaResponse.get("assistant").get("details").get("data"); aiResponse = aiResponse.trim().toUpperCase(); if(aiResponse.contains("YES")) { hasPurchaseIntent = true; } |
updateMap.put("Hot_Lead_Flag", true); updateMap.put("Lead_Status", "Interested"); updateMap.put("Rating", "Hot"); updateMap.put("Email_Intent", "Purchase_Intent"); updateMap.put("Intent_Detected_Time", zoho.currenttime); |
taskMap.put("Subject", "HOT LEAD: " + leadName + " wants to buy!"); taskMap.put("Priority", "High"); taskMap.put("Due_Date", zoho.currentdate); taskMap.put("Owner", ownerId); |
noteMap.put("Note_Title", "Zia: Purchase Intent Detected"); noteMap.put("Note_Content", "From: " + customerEmail + "\nSubject: " + emailSubject + "\nKey content: " + noteContent); |
sendmail [ from: zoho.loginuserid to: ownerEmail subject: "HOT LEAD ALERT: " + leadName + " wants to buy!" message: emailHtml ]; |
sendmail [ from: zoho.loginuserid to: leadEmail subject: "Thank you for your interest - We'll follow up shortly" message: autoReplyHtml ]; |
Sending alert mail to the respective record owner
