Building a Twilio Extension

Building a Twilio Extension

Twilio is a cloud communication platform that allows developers to integrate their application programmatically to make and receive voice calls and text messages using its Web service API. The following core topics will assist developers in understanding and building a Twilio extension.

  1. Zoho CRM with Twilio
  2. Obtain Twilio credentials for authentication
  3. Build a sample Twilio extension
  4. Send an SMS on & Lead creation
  5. Send an SMS on Contact creation
  6. Send text SMS
  7. Send SMS on Task
  8. Send SMS for Event Participants
  9. Send SMS for Event Relatedto
  10. Send Bulk SMS to Leads and Contacts

Zoho CRM with Twilio

A Twilio extension is created as a third party extension to Zoho CRM for sending SMS to the CRM Account owner and its users while performing various actions on built-in and custom modules.

Obtain Twilio credentials for authentication

Integration of Twilio with Zoho CRM is enabled with the help of the Zoho developer console. To start building this integration, a developer must know the type of authentication and authorization protocols followed by Twilio. Basically there are two types of authentication mechanisms that are in practice.They are
  1. Simple token based authentication that makes use of Custom Variables.
  2. OAuth or OAuth2.0 protocols-based authentication that requires the creation of Connectors.
For building our sample extension with Twilio, we follow the simple token-based authentication using Custom Variables. All requests to Twilio's REST API require you to authenticate using two important authentication parameters namely Account SID and Auth Token. These two mandatory parameters can be used as the custom variables to setup the extension.

To integrate Twilio into zohoCRM, a Twilio account is needed.

Login to https://www.twilio.com/ and get  the credentials after signing up. Obtain the Account SID and Auth Token.

Build a sample Twilio extension

The following Twilio extension with Zoho CRM sends an SMS to the intended recipients, based on various actions performed through different modules of Zoho CRM.

Send an SMS on Lead Creation

The primary functionality is to send an SMS to the CRM Account and its users upon creating or importing a new a lead in the leads module.

Creating a new extension
  1. Log in to Zoho Developer Console and click Build Extensions for Zoho CRM
  2. Click Create Extension
  3. Fill the following information in the Create Extension page:
    1. Extension Name : Twilio
    2. Unique Namespace : Twilio (Choose a unique namespace. This cannot be changed later)
    3. Short Description : Integrate Twilio with Zoho CRM
  4. Click Create. Your new extension will appear in the Extensions page of your Zoho Developers Console.
Create and invoke custom variables
  1. Log in to Zoho Developer Console and click Extensions for Zoho CRM.
  2. Select the extension that you would like to add the custom variable to.
  3. Click Custom Properties in the left pane, then click Create.
  4. Provide the following details:
    1. Field Name : Authtoken
    2. API Name : Authtoken
    3. Value : Value obtained from your Twilio Account
  5. Click Save.
Create all the other custom variables related to AccountsSID, TwilioMobileNumber and UsersMessage in a similar fashion.

All the organization variables will now be set and saved.

Setup the work flow
  1. In the Zoho Developer Console, click Automate in the left pane, then select Workflow
  2. Select the Rules tab and click Create Rule Button.
  3. In the New Rule page, fill in the details as given below,
Basic Information
  1. Module: Leads
  2. Rule Name: SendSMSonLeadCreation
  3. Description: Text message upon creating a lead.
  4. Click Next 
Rule Trigger
  1. Execute Based on : Select A Record Action
  2. Select Create and click Next
Rule Criteria
  1. None
  2. Click Next
Actions
In the Instant Actions
  1. Go to Call Custom Functions and click  +
In the Function editor area:
  1. Workflow Custom Function : type SendSMSonLeadCreation in the text box provided, then select Leads
Write the following custom function given in Deluge script into the editor area and Click the button Save&Associate.
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. m = Map();
  3. m.put("type","CurrentUser");
  4. resp = zoho.crm.invokeConnector("crm.getusers",m);
  5. response = resp.get("response").toMap();
  6. indMobile = response.get("users").toMap().get("mobile");
  7. leadId = lead.get("Leads.ID");
  8. datamap = Map();
  9. datamap.put("module","Leads");
  10. datamap.put("id",leadId);
  11. resp = zoho.crm.invokeConnector("crm.get",datamap);
  12. resp1 = resp.get("response").toMap();
  13. reqq = resp1.get("data").toMap();
  14. fullName = reqq.get("Last_Name");
  15. mobile = reqq.get("Mobile");
  16. tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  17. twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  18. authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  19. msg = zoho.crm.getOrgVariable("twilio__UsersMessage");
  20. messageToBeSent = fullName + mobile + msg;
  21. baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  22. encode = baseEncoded.removeFirstOccurence("\n");
  23. headermap = Map();
  24. headermap.put("Authorization","Basic " + encode);
  25. mappp = Map();
  26. mappp.put("To",indMobile);
  27. mappp.put("From",tmobile);
  28. mappp.put("Body",messageToBeSent);
  29. respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  30. info respp;
      4. Click Save.

Define Functions and Signals
Functions are the standalone Deluge functions that can be invoked as REST API's.
  1. In Zoho developer console, click Automate in the left pane and select Functions.
  2. Click the New Function and provide the function name:
    1. Function Name : IncomingSMS
  3. Write the following deluge function in the editor area and click Save:
  4. //Replace the identifiers highlighted in bold with your extension-specific values
  5. resp = crmAPIRequest;
  6. twilioResp = resp.get("parameters").toMap();
  7. fromNumber = twilioResp.get("From");
  8. messageContent = twilioResp.get("Body");
  9. LeadRespList = zoho.crm.searchRecords("Leads","(Mobile|=|" + fromNumber + ")");
  10. for each LeadResp in LeadRespList
  11. {
  12.      LeadId = LeadResp.get("id");
  13.      if(LeadId == null || LeadId == "")
  14.      {
  15.           LeadId = "";
  16.      }
  17. }
  18. ContactRespList = zoho.crm.searchRecords("Contacts","(Mobile|=|" + fromNumber + ")");
  19. for each ContactResp in ContactRespList
  20. {
  21.      FinalId = ContactResp.get("id");
  22.      if(FinalId == null || FinalId == "")
  23.      {
  24.           FinalId = "";
  25.      }
  26. }
  27. updateMap = {"twilio__Incoming_Message_Content":messageContent,"CustomModule1_Name":"Incoming SMS","twilio__Lead":LeadId,"twilio__Contact":FinalId,"twilio__Direction":"Inbound"};
  28. m = Map();
  29. l = List();
  30. l.add(updateMap);
  31. m.put("module","twilio__SMS_Texts");
  32. m.put("data",l);
  33. resp = zoho.crm.invokeConnector("crm.create",m);
  34. signalleadResp = zoho.crm.getRecordById("Leads",LeadId.toLong());
  35. Leademail = signalleadResp.get("Email");
  36. if(Leademail != "" || Leademail != null)
  37. {
  38.      signalMap = Map();
  39.      signalMap.put("signal_namespace","twilio.incomingsmssignal");
  40.      signalMap.put("email",Leademail);
  41.      signalMap.put("subject","Incoming SMS");
  42.      signalMap.put("message",messageContent);
  43.      actionsList = List();
  44.      actionMap = Map();
  45.      actionMap.put("type","link");
  46.      actionMap.put("display_name","View Email");
  47.      actionMap.put("url","www.google.com");
  48.      actionsList.add(actionMap);
  49.      signalMap.put("actions",actionsList);
  50.      result = zoho.crm.invokeConnector("raisesignal",signalMap);
  51.      info result;
  52. }
  53. signalcontactResp = zoho.crm.getRecordById("Contacts",FinalId.toLong());
  54. Contactemail = signalcontactResp.get("Email");
  55. if(Contactemail != "" || Contactemail != null)
  56. {
  57.      signalMapx = Map();
  58.      signalMapx.put("signal_namespace","twilio.incomingsmssignal");
  59.      signalMapx.put("email",Contactemail);
  60.      signalMapx.put("subject","Incoming SMS");
  61.      signalMapx.put("message",messageContent);
  62.      actionsListx = List();
  63.      actionMapx = Map();
  64.      actionMapx.put("type","link");
  65.      actionMapx.put("display_name","View Email");
  66.      actionMapx.put("url","www.google.com");
  67.      actionsListx.add(actionMapx);
  68.      signalMapx.put("actions",actionsListx);
  69.      resultx = zoho.crm.invokeConnector("raisesignal",signalMapx);
  70.      info resultx;
  71. }
  72. return "";

Signals are notifications that you receive in your CRM account about your customers' interactions with you across various communication channels.
  1. In Zoho Developer Console click Automate in the left pane and select Signals
  2. Click the Define Signal button.
  3. Enter the details as shown below:
    1. Signal Name : IncomingSMSSignal
    2. Namespace: Incomingsmssignal
  4. Click Save.
Test the Extension
  1. Click Test Your Extension in the top right corner of the Zoho developer console.
  2. Click the Leads Module.
  3. Select a particular Lead record and copy the Lead ID provided in the address bar at the top.
Execute the Custom function
  1. In the Zoho developer console, click Automate located in the left Pane.
  2. Select Workflow, then select the Custom Functions tab.
  3. Select SendSMSonLeadCreation and click Edit.
  4. Click the Execute button, enter the Lead ID that was created in the previous step, and click Submit.


The following API response will be generated



Upon successful testing, the CRM Account owner and users will receive an SMS of the respective lead details while they are being created or imported.

Send an SMS on Contact creation

Another similar functionality is used to send an SMS to the CRM Account and its users whenever a new contact is created or a lead is converted to a contact, or a contact is imported from an external resource in the Contacts module. Fewer changes are needed in the above steps with respect to the work flow rule and custom function. The changes to be reflected are below:

Set up the work flow
  1. In the Zoho Developer Console, click Automate in the left pane and click Workflow.
  2. Select the Rules tab and click the Create Rule button
  3. Fill in the details as shown below:
Basic Information
  1. Module: Contacts
  2. Rule Name: SMSOnContactCreate
  3. Description: Text message upon creating a contact.
  4. Click Next 
Rule Trigger
  1. Execute Based on : Select A Record Action
  2. Select Create and click Next
Rule Criteria
  1. None
  2. Click Next
Actions
In the Instant Actions
  1. Go to Call Custom Functions and click  +
In the Function editor area give
  1. Workflow Custom Function : Type SMSOnContactCreate in the text box provided and select Contacts
Write the following custom function given in Deluge script into the editor area and Click the Save&Associate button.
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. m = Map();
  3. m.put("type","CurrentUser");
  4. resp = zoho.crm.invokeConnector("crm.getusers",m);
  5. response = resp.get("response").toMap();
  6. indMobile = response.get("users").toMap().get("mobile");
  7. contactId = contact.get("Contacts.ID");
  8. datamap = Map();
  9. datamap.put("module","Contacts");
  10. datamap.put("id",contactId);
  11. resp = zoho.crm.invokeConnector("crm.get",datamap);
  12. resp1 = resp.get("response").toMap();
  13. reqq = resp1.get("data").toMap();
  14. fullName = reqq.get("Last_Name");
  15. mobile = reqq.get("Mobile");
  16. tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  17. twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  18. authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  19. msg = zoho.crm.getOrgVariable("twilio__UsersMessage");
  20. messageToBeSent = fullName + mobile + msg;
  21. baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  22. encode = baseEncoded.removeFirstOccurence("\n");
  23. headermap = Map();
  24. headermap.put("Authorization","Basic " + encode);
  25. mappp = Map();
  26. mappp.put("To",indMobile);
  27. mappp.put("From",tmobile);
  28. mappp.put("Body",messageToBeSent);
  29. respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  30. info respp;
      4. In the Workflow page, click Save.

Test the Extension
  1. Click Test your Extension, located in the top-right corner of the Zoho Developer Console.
  2. Click the Contacts Module.
  3. Select a Contact record and copy the Contact ID provided in the address bar at the top.
Execute the Custom function
  1. In the Zoho developer console, click Automate in the Left pane.
  2. Select Workflow, then select the Custom Functions tab.
  3. Select  SMSOnContactCreate and click Edit.
  4. Click the Execute button, enter the Contact ID created in the previous step, then click Submit.


The following API response will be generated.


Upon successful testing, the CRM Account owner and users will receive an SMS of the relevant contact details that are being created or imported.

Send text SMS

The next custom functionality is to send an individual SMS to a lead whenever a contact is associated with that particular lead. A new custom module, called SMS Texts must be created to achieve this functionality.

Create a Custom module SMS Texts
  1. In the Zoho Developer Console, click Modules in the Left pane.
  2. Select the Modules tab and click the Create New Module button.
  3. Enter the module name as 'SMS Texts' and click Save.
A new custom module, SMS Texts will be created.

Create  Custom fields in the SMS Texts module
  1. In the Zoho Developer Console, click Customize in the Left pane.
  2. Select the Fields tab.
  3. Select SMS Texts from the Module List and click New Custom Field.
  4. Create the following custom fields in SMS Texts : Create Custom Field


The following structure shows the structure of customized SMS Texts module.


Set up the work flow
  1. In the Zoho Developer Console, click Automate in the left pane and click Workflow.
  2. Select the Rules tab and click Create Rule button
  3. Fill in the details as shown below:
Basic Information
  1. Module: SMS Texts
  2. Rule Name: send text sms
  3. Description: Text message on association of a lead with a contact
  4. Click Next 
Rule Trigger
  1. Execute Based on : Select A Record Action
  2. Select Create and click Next
Rule Criteria
  1. None
  2. Click Next
Actions
In the Instant Actions section,
  1. Go to Call Custom Functions and click  +
In the Function editor area:
  1. Workflow Custom Function : Type send text SMS in the text box provided and select custom module1(SMS Texts).
Write the following custom function given in Deluge script into the editor area and Click the Save&Associate button.
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. idz = sms_texts.get("twilio__SMS_Texts.ID");
  3. datamap = Map();
  4. datamap.put("module","twilio__SMS_Texts");
  5. datamap.put("id",idz);
  6. resp = zoho.crm.invokeConnector("crm.get",datamap);
  7. respMap = resp.get("response").toMap();
  8. msg = respMap.get("data").toMap();
  9. CustomSMSMessage = msg.get("twilio__Custom_SMS_Message");
  10. if(CustomSMSMessage == null)
  11. {
  12.      info "No SMS Content";
  13. }
  14. else
  15. {
  16.      tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  17.      twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  18.      authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  19.      baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  20.      encode = baseEncoded.removeFirstOccurence("\n");
  21.      mapp = Map();
  22.      mapp.put("Authorization","Basic " + encode);
  23.      mappp = Map();
  24.      mappp.put("From",tmobile);
  25.      if(msg.get("twilio__Contact") != null && msg.get("twilio__Lead") != null)
  26.      {
  27.           leadIdz = msg.get("twilio__Lead").toMap();
  28.           leadId = leadIdz.get("id");
  29.           data1map = Map();
  30.           data1map.put("module","Leads");
  31.           data1map.put("id",leadId);
  32.           resp1 = zoho.crm.invokeConnector("crm.get",data1map);
  33.           resppMap = resp1.get("response").toMap();
  34.           users1 = resppMap.get("data");
  35.           temp1 = users1.replaceAll("[","",true);
  36.           usersVal1 = temp1.replaceAll("]","",false).toMap();
  37.           Mobile = usersVal1.get("Mobile");
  38.           contactIdz = msg.get("twilio__Contact").toMap();
  39.           contactId = contactIdz.get("id");
  40.           data2map = Map();
  41.           data2map.put("module","Contacts");
  42.           data2map.put("id",contactId);
  43.           resp2 = zoho.crm.invokeConnector("crm.get",data2map);
  44.           resp2Map = resp2.get("response").toMap();
  45.           users2 = resp2Map.get("data");
  46.           temp2 = users2.replaceAll("[","",true);
  47.           usersVal2 = temp2.replaceAll("]","",false).toMap();
  48.           Mobile1 = usersVal2.get("Mobile");
  49.           mappp.put("To",Mobile);
  50.           mappp.put("Body",CustomSMSMessage);
  51.           mappp.remove("To");
  52.           mappp.remove("Body");
  53.           mappp.put("To",Mobile1);
  54.           mappp.put("Body",CustomSMSMessage);
  55.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,mapp);
  56.           info "respp:: " + respp;
  57.      }
  58.      else if(msg.get("twilio__Lead") != null && msg.get("twilio__Contact") == null)
  59.      {
  60.           leadIdz = msg.get("twilio__Lead").toMap();
  61.           leadId = leadIdz.get("id");
  62.           data1map = Map();
  63.           data1map.put("module","Leads");
  64.           data1map.put("id",leadId);
  65.           resp1 = zoho.crm.invokeConnector("crm.get",data1map);
  66.           resppMap = resp1.get("response").toMap();
  67.           users1 = resppMap.get("data");
  68.           temp1 = users1.replaceAll("[","",true);
  69.           usersVal1 = temp1.replaceAll("]","",false).toMap();
  70.           Mobile = usersVal1.get("Mobile");
  71.           mappp.put("To",Mobile);
  72.           mappp.put("Body",CustomSMSMessage);
  73.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,mapp);
  74.           info "respp::: " + respp;
  75.      }
  76.      else if(msg.get("twilio__Contact") != null && msg.get("twilio__Lead") == null)
  77.      {
  78.           contactIdz = msg.get("twilio__Contact").toMap();
  79.           contactId = contactIdz.get("id");
  80.           data2map = Map();
  81.           data2map.put("module","Contacts");
  82.           data2map.put("id",contactId);
  83.           resp2 = zoho.crm.invokeConnector("crm.get",data2map);
  84.           resp2Map = resp2.get("response").toMap();
  85.           users2 = resp2Map.get("data");
  86.           temp2 = users2.replaceAll("[","",true);
  87.           usersVal2 = temp2.replaceAll("]","",false).toMap();
  88.           Mobile1 = usersVal2.get("Mobile");
  89.           mappp.put("To",Mobile1);
  90.           mappp.put("Body",CustomSMSMessage);
  91.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,mapp);
  92.           info "respp:::: " + respp;
  93.      }
  94.      else
  95.      {
  96.           info "No Number to send message!";
  97.      }
  98. }
      4. Click Save.

Test the Extension
  1. Click Test Your Extension located in the top right-corner of the Zoho Developer Console.
  2. Click the SMS Texts Module.
  3. Click +, located in the top right corner
  4. Enter the following values in the fields:
    1. SMS Texts Name : Incoming SMS(Mandatory field)
    2. Enter the data for the other fields
    3. Select a contact from the contact list and a lead from the lead list for Contact and Lead custom fields.
    4. Custom SMS Message : test (any message)
    5. Direction  : Inbound/Outbound
  5. Save the record and copy the SMS Texts Id from the address bar.

Execute the Custom function
  1. In the Zoho Developer Console, click Automate in the Left pane.
  2. Select Workflow, then select Custom Functions tab.
  3. Select  send Text SMS and click Edit.
  4. Click the Execute button and enter the SMS Texts ID that was created in the previous step into the following screen, then click Submit.


The following API response will be generated upon successful execution of the custom function:



Send SMS on Task

This is a functionality to send an SMS alert message to a lead record or a contact record whenever a task is defined with that specific lead or contact.
Set up the work flow
  1. In the Zoho Developer Console, click Automate in the left pane and click Workflow
  2. Select the Rules tab and click Create Rule button
  3. Fill the details as shown below:
Basic Information
  1. Module: Tasks
  2. Rule Name: Send SMS on Task
  3. Description: Text alert message upon reminding task
  4. Click Next 
Rule Trigger
  1. Execute Based on : Select A Date Field Value and select Due date
  2. Date of execution : Select Before
  3. Time of execution : 10.00 AM
  4. Execution cycle : Once
  5. Select Create and click Next
Rule Criteria
  1. None
  2. Click Next
Actions
In the Instant Actions section,
  1. Go to Call Custom Functions and click  +
In the Function editor area:
  1. Workflow Custom Function : Type Send SMS on Task in the text box provided and select Tasks
Write the following custom function given in Deluge script in the editor area and click the Save&Associate button:
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. taskId = task.get("Tasks.ID");
  3. datamap = Map();
  4. datamap.put("module","Tasks");
  5. datamap.put("id",taskId);
  6. resp = zoho.crm.invokeConnector("crm.get",datamap);
  7. respMap = resp.get("response").toMap();
  8. users = respMap.get("data");
  9. temp = users.removeFirstOccurence("[");
  10. dataVal = temp.removeLastOccurence("]").toMap();
  11. se_module = dataVal.get("$se_module");
  12. if(se_module == "Leads")
  13. {
  14.      What_Id = dataVal.get("What_Id").toMap();
  15.      leadId = What_Id.get("id");
  16.      datamapx = Map();
  17.      datamapx.put("module","Leads");
  18.      datamapx.put("id",leadId);
  19.      respx = zoho.crm.invokeConnector("crm.get",datamapx);
  20.      respMapx = respx.get("response").toMap();
  21.      usersx = respMapx.get("data");
  22.      tempx = usersx.removeFirstOccurence("[");
  23.      dataValx = tempx.removeLastOccurence("]").toMap();
  24.      mobile = dataValx.get("Mobile");
  25. }
  26. else
  27. {
  28.      Who_Id = dataVal.get("Who_Id").toMap();
  29.      contactId = Who_Id.get("id");
  30.      datamapx = Map();
  31.      datamapx.put("module","Contacts");
  32.      datamapx.put("id",contactId);
  33.      respx = zoho.crm.invokeConnector("crm.get",datamapx);
  34.      respMapx = respx.get("response").toMap();
  35.      usersx = respMapx.get("data");
  36.      tempx = usersx.removeFirstOccurence("[");
  37.      dataValx = tempx.removeLastOccurence("]").toMap();
  38.      mobile = dataValx.get("Mobile");
  39. }
  40. tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  41. twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  42. authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  43. baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  44. encode = baseEncoded.removeFirstOccurence("\n");
  45. headermap = Map();
  46. headermap.put("Authorization","Basic " + encode);
  47. mappp = Map();
  48. mappp.put("To",mobile);
  49. mappp.put("From",tmobile);
  50. mappp.put("Body","This is an alert for your task deadline You have only two days left!");
  51. respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  52. info "respp:::" + respp;
      4. Click Save.

Test the Extension
  1. Click Test Your Extension located in the top right corner of the Zoho Developer Console.
  2. Click the Activites tab and select +Task in the top-right corner.
  3. Click Create Task and fill it up with the following information:
    1. Subject: A new task(Mandatory Field)
    2. Due date: Select an upcoming date
    3. Select appropriate values for a either a Contact or a Lead
    4. Select values for any of the following : Accounts, Potential, Product, Case, Campaign, Vendor or Quote
    5. Status : In progress
    6. Priority : High
  4. Click Save and copy the respective Task ID from the address bar.
Execute the Custom function
  1. In the Zoho Developer Console, click Automate located in the Left pane.
  2. Select Workflow and in the Workflow page select Custom Functions tab.
  3. In Workflow Custom Functions, select  Send SMSon Task and click Edit.
  4. Click the button Execute and enter the Task ID created in the previous step, then click Submit.

The following API response will be generated with the alert message sent to the respective lead or contact when there are two more days left to complete the task:


Send SMS for Event Participants

This functionality is used to send SMS alerts to all the Participants of an event scheduled by a Lead or a Contact.

Set up the work flow
  1. In the Zoho Developer Console, click Automate in the left pane and click Workflow
  2. Select the Rules tab and click the Create Rule button
  3. Fill the details as shown below,
Basic Information
  1. Module: Events
  2. Rule Name: Send SMS For Event Participants
  3. Description: Text alert message to the Event Participants
  4. Click Next 
Rule Trigger
  1. Execute Based on : Select A Date Field Value and select Choose a Date Field
  2. Date of execution : Select Before
  3. Time of execution : 10.00 AM
  4. Execution cycle : Once
  5. Select Create and click Next
Rule Criteria
  1. None
  2. Click Next
Actions
In the Instant Actions seection,
  1. Go to Call Custom Functions and click  +
In the Function editor area:
  1. Workflow Custom Function : Type Send SMS For Event Participantsin the text box provided and select Events
Write the following custom function given in Deluge script into the editor area and Click the Save&Associate button.
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. eventId = event.get("Events.ID");
  3. datamap = Map();
  4. datamap.put("module","Events");
  5. datamap.put("id",eventId);
  6. resp = zoho.crm.invokeConnector("crm.get",datamap);
  7. respMap = resp.get("response").toMap();
  8. users = respMap.get("data").toMap();
  9. participants = users.get("Participants");
  10. for each indMap in participants
  11. {
  12.      if(indMap.get("type") == "contact")
  13.      {
  14.           contactId = indMap.get("participant");
  15.           datamapc = Map();
  16.           datamapc.put("module","Contacts");
  17.           datamapc.put("id",contactId);
  18.           respc = zoho.crm.invokeConnector("crm.get",datamapc);
  19.           respMapc = respc.get("response").toMap();
  20.           usersc = respMapc.get("data").toMap();
  21.           mobile = usersc.get("Mobile");
  22.           tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  23.           twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  24.           authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  25.           baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  26.           encode = baseEncoded.removeFirstOccurence("\n");
  27.           headermap = Map();
  28.           headermap.put("Authorization","Basic " + encode);
  29.           mappp = Map();
  30.           mappp.put("To",mobile);
  31.           mappp.put("From",tmobile);
  32.           mappp.put("Body","This is alert for your event !");
  33.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  34.           info "respp: " + respp;
  35.      }
  36.      else if(indMap.get("type") == "lead")
  37.      {
  38.           leadId = indMap.get("participant");
  39.           datamapc = Map();
  40.           datamapc.put("module","Leads");
  41.           datamapc.put("id",leadId);
  42.           respc = zoho.crm.invokeConnector("crm.get",datamapc);
  43.           respMapc = respc.get("response").toMap();
  44.           usersc = respMapc.get("data").toMap();
  45.           mobile = usersc.get("Mobile");
  46.           tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  47.           twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  48.           authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  49.           baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  50.           encode = baseEncoded.removeFirstOccurence("\n");
  51.           headermap = Map();
  52.           headermap.put("Authorization","Basic " + encode);
  53.           mappp = Map();
  54.           mappp.put("To",mobile);
  55.           mappp.put("From",tmobile);
  56.           mappp.put("Body","This is alert for your event !");
  57.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  58.           info "respp::: " + respp;
  59.      }
  60. }
      4. Click Save.

Test the extension
  1. Click Test Your Extension in the top-right corner of the Zoho Developer Console.
  2. Click the Activites tab and select +Event located in the top-right corner.
  3. Enter the relevant information needed to create an event, as shown in the following screen:


      4. Click Save. An event named 'A Meet Up' will be created in the Activities list.
      5. Copy the Event ID of the created Event.

Execute the Custom function
  1. In the Zoho Developer Console, click Automate located in the Left pane.
  2. Select Workflow, then select the Custom Functions tab.
  3. Select Send SMS For Event Participants and click Edit.
  4. Click the Execute button and enter the Event ID obtained in the previous step.
  5. Click Submit.
The following API response will be generated and an alert SMS will be sent to one or more event participants.
 


Send SMS for Event Relatedto

This functionality is used to send confirmation SMS to the related leads or related contacts who are a part of the specific event scheduled.

Set up the work flow
  1. In the Zoho Developer Console, click Automate in the left pane and click Workflow
  2. Select the Rules tab and click the Create Rule button.
  3. Fill in the details as shown below:
Basic Information
  1. Module: Events
  2. Rule Name: Send SMS For Event RelatedTo
  3. Description: Text a confirmation message to the related people of the Event
  4. Click Next 
Rule Trigger
  1. Execute Based on : Select A Date Field Value and select Choose a Date Field
  2. Date of execution : Select Before
  3. Time of execution : 10.00 AM
  4. Execution cycle : Once
  5. Select Create and click Next
Rule Criteria
  1. None
  2. Click Next
Actions
In the Instant Actions section:
  1. Go to Call Custom Functions and click  +
In the Function editor area:
  1. Workflow Custom Function : Type Send SMS For Event Relatedto in the text box provided and select Events
Write the following custom function given in Deluge script into the editor area and Click the button Save&Associate:
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. eventId = event.get("Events.ID");
  3. datamap = Map();
  4. datamap.put("module","Events");
  5. datamap.put("id",eventId);
  6. resp = zoho.crm.invokeConnector("crm.get",datamap);
  7. respMap = resp.get("response").toMap();
  8. users = respMap.get("data").toMap();
  9. participants = users.get("Participants");
  10. for each indMap in participants
  11. {
  12.      if(indMap.get("type") == "contact")
  13.      {
  14.           contactId = indMap.get("participant");
  15.           datamapc = Map();
  16.           datamapc.put("module","Contacts");
  17.           datamapc.put("id",contactId);
  18.           respc = zoho.crm.invokeConnector("crm.get",datamapc);
  19.           respMapc = respc.get("response").toMap();
  20.           usersc = respMapc.get("data").toMap();
  21.           mobile = usersc.get("Mobile");
  22.           tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  23.           twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  24.           authtokenTwilio = zoho.crm.getOrgVariable("twilio__AuthToken");
  25.           baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  26.           encode = baseEncoded.removeFirstOccurence("\n");
  27.           headermap = Map();
  28.           headermap.put("Authorization","Basic " + encode);
  29.           mappp = Map();
  30.           mappp.put("To",mobile);
  31.           mappp.put("From",tmobile);
  32.           mappp.put("Body","This is alert for your event !");
  33.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  34.           info "respp: " + respp;
  35.      }
  36.      else if(indMap.get("type") == "lead")
  37.      {
  38.           leadId = indMap.get("participant");
  39.           datamapc = Map();
  40.           datamapc.put("module","Leads");
  41.           datamapc.put("id",leadId);
  42.           respc = zoho.crm.invokeConnector("crm.get",datamapc);
  43.           respMapc = respc.get("response").toMap();
  44.           usersc = respMapc.get("data").toMap();
  45.           mobile = usersc.get("Mobile");
  46.           tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  47.           twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  48.           authtokenTwilio = zoho.crm.getOrgVariable("twilio__AuthToken");
  49.           baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  50.           encode = baseEncoded.removeFirstOccurence("\n");
  51.           headermap = Map();
  52.           headermap.put("Authorization","Basic " + encode);
  53.           mappp = Map();
  54.           mappp.put("To",mobile);
  55.           mappp.put("From",tmobile);
  56.           mappp.put("Body","This is alert for your event !");
  57.           respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  58.           info "respp:: " + respp;
  59.      }
  60. }
      4. Click Save.

Test the extension
  1. Click Test Your Extension in the top-right corner of the Zoho Developer Console.
  2. Click the Activities tab and select +Event located in the top-right corner.
  3. Select any of the Event Records already created.
  4. Click Edit and select the field Relatedto. (This will show only related leads or contacts)
  5. Select a record from the Lead or Contact.
  6. Click Save.
  7. Copy the Event ID from the address bar.
Execute the Custom function
  1. In the Zoho Developer Console, click Automate in the Left pane.
  2. Select Workflow, then select Custom Functions tab.
  3. Select  Send SMS For Event Relatedto and click Edit.
  4. Click the Execute button and enter the Event ID obtained in the previous step.
  5. Click Submit.
The following API response will be generated and a confirmation SMS will be sent to the people who are related to the specific event.


Send Bulk SMS to Leads and Contacts

This functionality is used to send a bulk SMS to selected leads and selected contacts in the Leads and Contacts modules respectively.

Create Customized Buttons
  1. In the Zoho Developer Console, click Customize, and select Links and Buttons tab in the Customization page.
  2. Click Create New Button.
  3. Provide the following details:
    1. In which module would you like to create a new button?' Select Contacts
    2. 'What would you like to name the button?' Type Send Bulk SMS
    3. 'Where would you like to place the button?' Select List View Page
    4. 'What action would you like the button to perform?' Select Writing Custom Function
    5. 'Give the function name' Type Send SMS on Contacts
Write the following Deluge script in the editor:
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. contactid = contact.get("Contacts.ID").toList("|||");
  3. flag = 0;
  4. for each abc in contactid
  5. {
  6.      datamap = Map();
  7.      datamap.put("module","Contacts");
  8.      datamap.put("id",abc);
  9.      resp = zoho.crm.invokeConnector("crm.get",datamap);
  10.      respMap = resp.get("response").toMap();
  11.      users = respMap.get("data").toMap();
  12.      mobile = users.get("Mobile");
  13.      if(mobile == null || mobile == "")
  14.      {
  15.           flag = 1;
  16.      }
  17.      tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  18.      twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  19.      authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  20.      msg = zoho.crm.getOrgVariable("twilio__UsersMessage");
  21.      baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  22.      encode = baseEncoded.removeFirstOccurence("\n");
  23.      first = users.get("First Name");
  24.      if(first == null)
  25.      {
  26.           first = "";
  27.      }
  28.      last = resp.get("Last Name");
  29.      headermap = Map();
  30.      headermap.put("Authorization","Basic " + encode);
  31.      mappp = Map();
  32.      mappp.put("To",mobile);
  33.      mappp.put("From",tmobile);
  34.      mappp.put("Body",msg);
  35.      respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  36.      info respp;
  37.      updateMap = {"twilio.Msg_Content_For_Bulk_SMS":msg,"twilio.SMS_Texts_Name":"Send Through Bulk Contact","twilio.Contact":abc,"twilio.Direction":"Outbound"};
  38.      m = Map();
  39.      l = List();
  40.      l.add(updateMap);
  41.      m.put("module","twilio.SMS_Texts");
  42.      m.put("data",l);
  43.      resp = zoho.crm.invokeConnector("crm.create",m);
  44.      info resp;
  45. }
  46. if(flag == 0)
  47. {
  48.      return "SMS Sent !";
  49. }
  50. else
  51. {
  52.      return "Some Mobile Number Missing ! Can't Send SMS to those Contacts";
  53. }
  54. info respp;

      4. Click Save to Button.

Test the extension
  1. Click Test Your Extension located in the top-right corner of the Zoho Developer Console.
  2. Click the Contacts Module and select multiple contacts from List View.
  3. Click the Send Bulk SMS button, which appears at the top of the Custom List View page. It will display, 'Message Sent.'
  4. To test the above operation navigate to the SMS Texts module.
  5. Select the latest Send Through Bulk Contact SMS Text Name.
  6. Copy the Contact ID of the Contact that appears in that SMS text.
Execute the Custom function
  1. In the Zoho Developer Console, Click Customize in the left pane.
  2. Select the Send Bulk SMS button.
  3. Select the function Send SMS on Contacts and click Edit
  4. Execute the Custom Button code.
  5. Paste the Contact ID obtained in the previous step and click Submit
The following API response will be generated and the message will be sent to the respective contact. To test this with multiple contacts, select the Contact IDs individually from the contacts list and execute the custom button.


Repeat the same steps by creating another Button called Send Bulk SMS in the Leads module and execute the custom button. The custom function code in Deluge Script for this functionality is provided below:
  1. //Replace the identifiers highlighted in bold with your extension-specific values
  2. leadid = lead.get("Leads.ID").toList("|||");
  3. flag = 0;
  4. for each abc in leadid
  5. {
  6.      datamap = Map();
  7.      datamap.put("module","Leads");
  8.      datamap.put("id",abc);
  9.      resp = zoho.crm.invokeConnector("crm.get",datamap);
  10.      respMap = resp.get("response").toMap();
  11.      users = respMap.get("data").toMap();
  12.      mobile = users.get("Mobile");
  13.      if(mobile == null || mobile == "")
  14.      {
  15.           flag = 1;
  16.      }
  17.      tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
  18.      twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
  19.      authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
  20.      msg = zoho.crm.getOrgVariable("twilio.Users Message");
  21.      baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
  22.      encode = baseEncoded.removeFirstOccurence("\n");
  23.      first = users.get("First Name");
  24.      if(first == null)
  25.      {
  26.          first = "";
  27.      }
  28.      last = resp.get("Last Name");
  29.      headermap = Map();
  30.      headermap.put("Authorization","Basic " + encode);
  31.      mappp = Map();
  32.      mappp.put("To",mobile);
  33.      mappp.put("From",tmobile);
  34.      mappp.put("Body",msg);
  35.      respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
  36.      info respp;
  37.      updateMap = {"twilio.Msg_Content_For_Bulk_SMS":msg,"twilio.SMS_Texts_Name":"Send Through Bulk Leads","twilio.Lead":abc,"twilio.Direction":"Outbound"};
  38.      m = Map();
  39.      l = List();
  40.      l.add(updateMap);
  41.      m.put("module","twilio.SMS_Texts");
  42.      m.put("data",l);
  43.      resp = zoho.crm.invokeConnector("crm.create",m);
  44. }
  45. if(flag == 0)
  46. {
  47.      return "SMS Sent !";
  48. }
  49. else
  50. {
  51.      return "Some Mobile Numbers are Missing ! Can't Send SMS to Those Leads";
  52. }

    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION






                          Quick Links Workflow Automation Data Collection
                          Web Forms Enterprise Begin Data Collection
                          Interactive Forms Workplace Data Collection App
                          Encrypted Forms Customer Service Accessible Forms
                          Digital Forms Marketing Forms for Small Business
                          HTML Forms Education Forms for Enterprise
                          Contact Forms E-commerce Forms for any business
                          Lead Generation Forms Healthcare Forms for Startups
                          Wordpress Forms Customer onboarding Order Forms for Small Business
                          No Code Forms Construction RSVP tool for holidays
                          Free Forms Travel
                          Prefill Forms Non-Profit

                          Intake Forms Legal
                          Mobile App
                          Form Designer HR
                          Mobile Forms
                          Card Forms Food Offline Forms
                          Assign Forms Photography
                          Mobile Forms Features
                          Translate Forms Real EstateKiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for Forms Alternatives
                          Holiday Forms Google Forms alternative 
                          Form to PDF Jotform alternative





                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                Manage your brands on social media

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • Building a GoToMeeting Extension

                                                                                                                The GoToMeeting extension enables users to schedule meetings, invite users, and keep track of the meetings when they have joined within Zoho CRM. With GoToMeeting you can utilize HD video conferencing and screen sharing. With this extension installed ...
                                                                                                              • Building a Client Side Application

                                                                                                                This guide will help you with the following: Create a Connected App Internal Hosting  External Hosting  Create the "Helloworld" Widget  Setup the files structure for "HelloWorld" Widget  Register the Event Listeners  This guide will furnish you with ...
                                                                                                              • Building a Real Estate CRM

                                                                                                                Zoho Developer Console allows developers to transform your CRM into an industry specific CRM solution. A real estate CRM needs to manage comprehensive and comparative details about properties, offer ease in handling Buyer and Client data and provide ...
                                                                                                              • Publishing an Extension

                                                                                                                Once you've finished building your extension, it must be published to make it available for customers. The Zoho Developer Console gives you two options to publish your extension  Publish your extension privately   List it publicly on the Zoho ...
                                                                                                              • Building a Server Side Application

                                                                                                                You can create an extension to provide single sign-on using Zoho CRM to a number of web and mobile applications using SAML and OAuth 2.0 protocols. Read this link to know more about creating a connected application with any third-party web service. ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources