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 = " + acc_sid + "/Messages.json";
//posting SMS
mp = Map();
hMap = Map();
hMap.put("Authorization","Basic " + base);
postv = postUrl(url,mp,hMap);
info postv;
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

    • Related Articles

    • [Zoho CRM] How to create a function for mass action button?

      In the function you are about to write, you can edit the Arguments. Let's say for example we're dealing with the Deals module, then what you want to do is add an argument mapping to the Deal ID field. I would suggest putting the mapping value as a ...
    • [Zoho CRM] Send Email Template Using Deluge in Zoho CRM

      How to send an email using an email template in a Deluge/Custom Function/Button? This function is used to send email using Zoho CRM email templates. We would have to get the template id by going to the respective template and edit it. In the URL of ...
    • [Zoho CRM] A Comprehensive Guide for Zoho CRM Wizards

      Unleashing the Power of Zoho CRM Wizards: A Comprehensive Guide What is CRM Wizards? Zoho CRM Wizards are a powerful tool designed to simplify and enhance the data entry process in Zoho CRM. They enable users to break down lengthy forms into a series ...
    • [Zoho CRM] Creating A Lead

      Leads in Zoho CRM can be created in several ways; Direct creation Import Social media connection (Facebook and Twitter) Zoho Mail integration Zoho Cliq (website ) integration To create directly, click on the '+' icon at the top right of the screen. ...
    • [Zoho CRM] Totalling from Related Records

      This function can be used to total a number from a related list. For example, you would like to calculate the revenue from the company based on the deals' amount. Notes: acctId = Accounts ID RelatedRecords = ...