Workflow Rules are a set of actions (alerts, tasks and field updates) that are executed when certain specified conditions are met. These rules automate the process of sending email alerts, assigning tasks and updating certain fields of a record when a rule is triggered. Here in our case, we use workflow rules to send an SMS.


The workflow rules can be anything. You can create a workflow that triggers a message on any activity like lead creation, lead subscription or unsubscription, etc.,


In this document, we will depict you step by step procedure to create a workflow to automate sending SMSes.


Send SMS on Lead creation

  1. In Zoho CRM console, click on settings then select Workflow Rules
  2. Click on Create Rule
  3. In the New Rule page, fill in the details
  4. Click Next




For Rule Trigger

  • Execute Based on, Select A Record Action
  • Select Create and click Next



Rule Criteria

  • Select Leads matching certain conditions
  • Select Mobile from the dropdown and then select isn’t and set the value as null
  • Click Next



Actions

In the Instant Actions,

  • Select Function from the list
  • Click on New Function then select Write your own
  • In the below function {sender_id} is a parameter which will be replaced with GMP sender_id


Sender ID Approval


Sender_id should be in Approved status in your Kaleyra account

In the Function editor area write the following custom function given in Deluge script into the editor area.


num = mobNumber;
api_key = apiKey;
myMap = Map();
myMap.put("to",num);
myMap.put("api_key",apiKey);
sender = 'kaleyra';
myURL = "https://api-global.kaleyra.com/v4/?sender="+ sender+"&method=sms&message=Congrats you were added as a lead in zoho crm";
res = postUrl(myURL,myMap,false);
info res;
code = res.getJSON("responseCode");
if(code == "200")
{
map = Map();
dateTime = now;
y = dateTime.getYear();
m = dateTime.getMonth();
d = dateTime.getDay();
name = "SMS sent-" + y + "-" + m + "-" + d;
msg = "Congrats you were added as a lead in zoho crm";
response = res.getJSON("responseText");
data = response.getJSON("data").toJSONList();
for each i in data
{
msgId = i.getJSON("id");
}
map.put("Name",name);
map.put("kaleyrasms1__Message",msg);
map.put("kaleyrasms1__Mobile",num);
map.put("kaleyrasms1__Sender_Id",sender);
map.put("kaleyrasms1__Recipient",recipient);
map.put("kaleyrasms1__Sent_Time",dateTime);
map.put("kaleyrasms1__Reference_Id",msgId);
info map;
response = zoho.crm.createRecord("kaleyrasms1__Kaleyra_SMS_History",map);
info response;
}





  • Click on Edit Arguments
  • First create a parameter called MobNumber and assign Mobile to it
  • Click on Add, then specify apiKey and assign from the dropdown Kaleyra SMS APIKEY and recipient ID to it. Recipient ID is the lead id that you can choose from the dropdown.
  • Click on Save
  • Provide an appropriate function name
  • Click Save and Associate
  • Click Save


By using the script, the triggered SMS can be seen directly in Kaleyra SMS history


Send SMS on Contact creation


Follow the steps below to Set up the workflow:

  1. In Zoho CRM console, click on settings then select Workflow Rules
  2. Click on Create Rule
  3. In the New Rule page, fill in the details as given below
  4. Click Next



For Rule Trigger

  1. Execute Based on, Select A Record Action
  2. Select Create and click Next

Rule Criteria

  1. Select Contacts matching certain conditions
  2. Select Mobile from the dropdown and then select isn’t and set the value as null



  1. Click Next

Actions

  • In the Instant Actions
  • Select Function from the list
  • Click on New Function then select Write your own

In the Function, editor area write the following custom function given in Deluge script into the editor area.


myMap = Map();
myMap.put("to",mobNumber);
myMap.put("api_key",apiKey);
sender = 'kaleyra';
myURL = "https://api-global.kaleyra.com/v4/?sender=" + sender + "&method=sms&message=Congrats you were added as a contact in zoho crm";
res = postUrl(myURL,myMap,false);
info res;
code = res.getJSON("responseCode");
if(code == "200")
{
map = Map();
dateTime = now;
y = dateTime.getYear();
m = dateTime.getMonth();
d = dateTime.getDay();
name = "SMS sent-" + y + "-" + m + "-" + d;
msg = "Congrats you were added as a contact in zoho crm";
response = res.getJSON("responseText");
data = response.getJSON("data").toJSONList();
for each i in data
{
msgId = i.getJSON("id");
}
map.put("Name",name);
map.put("kaleyrasms1__Message",msg);
map.put("kaleyrasms1__Mobile",mobNumber);
map.put("kaleyrasms1__Sender_Id",sender);
map.put("kaleyrasms1__Recipient",recipient);
map.put("kaleyrasms1__Sent_Time",dateTime);
map.put("kaleyrasms1__Reference_Id",msgId);
info map;
response = zoho.crm.createRecord("kaleyrasms1__Contact_SMS_History",map);
info response;
}



  • Click on Edit Arguments
    • First create a parameter called MobNumber and assign Mobile to it
    • Click on Add, then specify apiKey and assign from the dropdown Kaleyra SMS APIKEY and ContactID to it. Contact ID is the lead id that you can choose from the dropdown.
    • Click on Save
    • Provide an appropriate function name
    • Click Save and Associate
    • Click Save

By using the script, the triggered SMS can be seen directly in Contact SMS history




  • Click on Save
  • Provide an appropriate function name
  • Click Save and Associate
  • Click Save


Send SMS for Event Participants

  • In Zoho CRM console, click on settings then select Workflow Rules
  • Click on Create Rule
  • In the New Rule page, fill in the details as given below
  • Click Next

For Rule Trigger

  • Execute Based on , On a Date/Time
  • Then provide details as specified in the image given below
  • Click Next



Rule Criteria

  • Select All Events
  • Click Next

Actions

  • Select Function from the list
  • Click on New Function then select Write your own
  • In the below function {sender_id} is a parameter which will be replaced with GMP sender_id

In the Function editor area write the following custom function given in Deluge script into the editor area.



api_key = apiKey;
eventId = eventid;
response = zoho.crm.getRecordById("Events",eventId);
info response;
par = response.getJSON("Participants").toJSONList();
type = par.getJSON("type");
if(type == "lead")
{
leadid = par.getJSON("participant");
leadId = leadid.toLong();
resp = zoho.crm.getRecordById("Leads",leadId);
num = resp.getJSON("Mobile").toJSONList();
}
else if(type == "contact")
{
contactid = par.getJSON("participant");
contactId = contactid.toLong();
resp = zoho.crm.getRecordById("Contacts",contactId);
num = resp.getJSON("Mobile").toJSONList();
}
msg = "You are invited to participate in an event created by " + hostname;
myMap = Map();
myMap.put("to",num);
myMap.put("api_key",apiKey);
myMap.put("message",msg);
myURL = "https://api-global.kaleyra.com/v4/?sender={sender_id}&method=sms";
res = postUrl(myURL,myMap,false);
info res;


  • Click on Edit Arguments
  • First create a parameter called eventid and assign eventId to it




  • Click on Add, then specify apiKey and assign the custom apiKey value to it
  • Click on Add, then specify hostname and assign Host to it




  • Click on Save
  • Provide an appropriate function name
  • Click Save and Associate
  • Click Save and you are done