Here's a complete Deluge script that integrates Zoho SalesIQ with Zoho Creator to automate form entries via chat/voice inputs, including handling mandatory fields:
// Deluge Script for Zoho SalesIQ to Zoho Creator Integration
// This script processes chat/voice inputs and creates records in Zoho Creator
// ===== CONFIGURATION =====
formName = "Customer_Orders"; // Your Zoho Creator form name
mandatoryFields = List();
mandatoryFields.add("Customer_Name");
mandatoryFields.add("Product");
mandatoryFields.add("Quantity");
mandatoryFields.add("Delivery_Date");
// ===== MAIN FUNCTION =====
processSalesIQMessage(visitorMessage, chatSession)
{
try
{
// Initialize or retrieve conversation context
context = getConversationContext(chatSession.get("id"));
// Parse the visitor message
parsed = parseVisitorMessage(visitorMessage, context);
// If we're missing mandatory fields, prompt for them
if(parsed.get("status") == "missing_fields")
{
missingFields = parsed.get("missing_fields");
prompt = buildMissingFieldsPrompt(missingFields);
// Update context with current state
updateConversationContext(chatSession.get("id"), context);
// Send response back to SalesIQ
return {"response": prompt, "context": context};
}
// If we have all required data, create the record
if(parsed.get("status") == "complete")
{
// Create the record in Zoho Creator
createResponse = createCreatorRecord(parsed.get("data"));
// Clear the conversation context
clearConversationContext(chatSession.get("id"));
if(createResponse.get("code") == 3000) // Success
{
return {"response": "Success! Your order #" + createResponse.get("ID") + " has been created.", "context": null};
}
else
{
return {"response": "Sorry, I couldn't create the order. Please try again later.", "context": context};
}
}
// For partial updates
return {"response": parsed.get("response"), "context": context};
}
catch (e)
{
// Log the error
logError(e, {"visitorMessage": visitorMessage, "chatSession": chatSession});
return {"response": "Sorry, I encountered an error processing your request.", "context": null};
}
}
// ===== HELPER FUNCTIONS =====
// Get or initialize conversation context
getConversationContext(sessionId)
{
// Try to get existing context from SalesIQ custom fields
context = zoho.salesiq.getVisitorCustomField(sessionId, "creator_context");
if(context == null || context == "")
{
context = Map();
foreach field in mandatoryFields
{
context.put(field, "");
}
context.put("status", "collecting_data");
}
else
{
context = context.toMap();
}
return context;
}
// Update conversation context in SalesIQ
updateConversationContext(sessionId, context)
{
zoho.salesiq.setVisitorCustomField(sessionId, "creator_context", context.toString());
}
// Clear conversation context
clearConversationContext(sessionId)
{
zoho.salesiq.setVisitorCustomField(sessionId, "creator_context", "");
}
// Parse visitor message and extract data
parseVisitorMessage(message, context)
{
result = Map();
// Check for specific patterns in the message
// Example: "I want to order 5 laptops for John Doe"
orderPattern = message.getMatch("order (\\d+) (.+) for (.+)");
if(orderPattern.size() > 0)
{
context.put("Quantity", orderPattern.get(1));
context.put("Product", orderPattern.get(2));
context.put("Customer_Name", orderPattern.get(3));
}
// Check for date patterns
datePattern = message.getMatch("(today|tomorrow|\\d{2}/\\d{2}/\\d{4})");
if(datePattern.size() > 0)
{
dateValue = datePattern.get(0);
if(dateValue == "today")
{
context.put("Delivery_Date", zoho.currentdate.toString());
}
else if(dateValue == "tomorrow")
{
context.put("Delivery_Date", zoho.currentdate.addDay(1).toString());
}
else
{
context.put("Delivery_Date", dateValue);
}
}
// Check if all mandatory fields are filled
missing = List();
foreach field in mandatoryFields
{
if(context.get(field) == null || context.get(field) == "")
{
missing.add(field);
}
}
if(missing.size() > 0)
{
result.put("status", "missing_fields");
result.put("missing_fields", missing);
result.put("context", context);
return result;
}
else
{
result.put("status", "complete");
result.put("data", context);
return result;
}
}
// Build prompt for missing fields
buildMissingFieldsPrompt(missingFields)
{
if(missingFields.size() == 1)
{
return "Please provide the " + missingFields.get(0).replace("_", " ") + ":";
}
else
{
prompt = "I need a few more details to complete your order:\n";
foreach field in missingFields
{
prompt = prompt + "- " + field.replace("_", " ") + "\n";
}
prompt = prompt + "Please provide these details.";
return prompt;
}
}
// Create record in Zoho Creator
createCreatorRecord(data)
{
// Map SalesIQ data to Creator fields
recordData = Map();
recordData.put("Customer_Name", data.get("Customer_Name"));
recordData.put("Product", data.get("Product"));
recordData.put("Quantity", data.get("Quantity").toLong());
recordData.put("Delivery_Date", data.get("Delivery_Date"));
// Add any additional fields
recordData.put("Order_Source", "SalesIQ Chat");
recordData.put("Order_Date", zoho.currentdate);
// Create the record
response = zoho.creator.createRecord(
"your_account_name", // Replace with your account name
"your_app_name", // Replace with your app name
formName,
recordData,
{"Authorization": "Zoho-oauthtoken " + zoho.admin.getOAuthToken()}
);
return response;
}
// Error logging
logError(error, context)
{
errorData = Map();
errorData.put("Error_Message", error.toString());
errorData.put("Error_Context", context.toString());
errorData.put("Timestamp", zoho.currenttime);
// Log to a Creator form
zoho.creator.createRecord(
"your_account_name",
"your_app_name",
"Error_Logs",
errorData,
{"Authorization": "Zoho-oauthtoken " + zoho.admin.getOAuthToken()}
);
}
// ===== VOICE PROCESSING FUNCTION =====
processVoiceInput(voiceData, chatSession)
{
try
{
// Convert voice to text (using Zoho Voice API)
textInput = zoho.voice.recognize(voiceData);
// Process the text input
return processSalesIQMessage(textInput, chatSession);
}
catch (e)
{
logError(e, {"voiceData": voiceData, "chatSession": chatSession});
return {"response": "Sorry, I couldn't process your voice input.", "context": null};
}
}
Implementation Instructions:
-
Set up the SalesIQ Webhook:
- Go to Zoho SalesIQ → Settings → Webhooks
- Create a new webhook that triggers on chat messages
- Point it to your Zoho Creator function URL
-
Create the Zoho Creator Custom Function:
- In your Creator app, create a new Custom Function
- Paste this Deluge code
- Replace placeholders (
your_account_name, your_app_name, form fields)
-
Configure Mandatory Fields:
- Update the
mandatoryFields list with your actual required fields
- Adjust the field mapping in
createCreatorRecord() as needed
-
Add Voice Processing (Optional):
- If using voice, ensure you have Zoho Voice API enabled
- The
processVoiceInput function handles voice-to-text conversion
Example Conversation Flow:
Visitor: "I want to order 10 laptops for John Doe"
Bot: "Please provide the delivery date (today/tomorrow/DD-MM-YYYY):"
Visitor: "tomorrow"
Bot: "Success! Your order #ORD-1001 has been created."
Key Features:
- Context Management: Maintains conversation state across multiple messages
- Mandatory Field Handling: Identifies and prompts for missing information
- Natural Language Processing: Extracts data from semi-structured messages
- Voice Support: Processes voice inputs through Zoho's speech recognition
- Error Handling: Logs errors to a Creator form for debugging
Enhancements You Can Add: