Sending Twilio SMS Using Custom Function

[Zoho CRM] Sending Twilio SMS Using Custom Function

If you're using Twilio as your SMS provider in Zoho CRM, this is the way to automate SMS sending using Workflows and Custom Function. To do this, you have to be in the Enterprise edition or higher and you have to have permission from your administrator. 

You would also need to know your Twilio Account SID, authtoken and number. Simply login into your Twilio account > Console Dashboard > Project Info. You can see your Account SID there. You can also find the Auth Token section. That is your authtoken. If you have multiple authtokens, you have to use the primary one.



As for your numbers, navigate to Phone Numbers > Manage Numbers > Active Numbers.

After you have all the prerequisite information, proceed to Zoho CRM > Setup > Automation > Workflow Rules > Create a workflow. In this example, we are creating in the Leads module > key in the name of the workflow and determine your trigger and criteria. > Choose " Function" > Click "+ New Function" > Choose "Write your own". > Write this function:

Note: Map "leadId" to the Lead Id in the Argument Mapping as specified by the system for this particular example. If you're creating in another module, then map it to the record's Id respectively.

//Twilio Info:
tNumber = "<your Twilio phone number>";
acc_sid = "<your Twilio accound Id>";
auth_token = "<your Twilio auth token>";
//Get Lead Details
leadDet= zoho.crm.getRecordById("Leads",leadId.toLong());
//Get Lead's Name
fname = ifnull(zoho.crm.getRecordById("Leads",leadId).get("First_Name"),"");
lname = ifnull(zoho.crm.getRecordById("Leads",leadId).get("Last_Name"),"");
leadName = fname + " " + lname;
info "Lead Name: " + leadName;
//Determine recipient number
leadPhone = ifnull(leadDet.get("Mobile"),"");
// info leadPhone;
if(leadPhone != "")
{
mess = "<Enter your message here>";
info mess;
//preparing authorization parameters
auth = acc_sid + ":" + auth_token;
base = zoho.encryption.base64Encode(auth);
base = base.remove("\n");
url = "https://api.twilio.com/2010-04-01/Accounts/%22 + acc_sid + "/Messages.json";
//posting SMS
mp = Map();
mp.put("To",leadPhone.toString());
mp.put("From",tNumber);
mp.put("Body",mess);
hMap = Map();
hMap.put("Authorization","Basic " + base);
postv = postUrl(url,mp,hMap);
info postv;
}
else
{
info "Lead mobile is empty";
}
To test the function, you may save and execute after you're done and just input a Deal record's Zoho ID that can be found in the URL of the specific record.

Need more help on this? Contact us at support@aplikasi..us