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.
- Zoho CRM with Twilio
- Obtain Twilio credentials for authentication
- Build a sample Twilio extension
- Send an SMS on & Lead creation
- Send an SMS on Contact creation
- Send text SMS
- Send SMS on Task
- Send SMS for Event Participants
- Send SMS for Event Relatedto
- 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
- Simple token based authentication that makes use of Custom Variables.
- 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.
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
- Log in to Zoho Developer Console and click Build Extensions for Zoho CRM
- Click Create Extension
- Fill the following information in the Create Extension page:
- Extension Name : Twilio
- Unique Namespace : Twilio (Choose a unique namespace. This cannot be changed later)
- Short Description : Integrate Twilio with Zoho CRM
- Click Create. Your new extension will appear in the Extensions page of your Zoho Developers Console.
Create and invoke custom variables
- Log in to Zoho Developer Console and click Extensions for Zoho CRM.
- Select the extension that you would like to add the custom variable to.
- Click Custom Properties in the left pane, then click Create.
- Provide the following details:
- Field Name : Authtoken
- API Name : Authtoken
- Value : Value obtained from your Twilio Account
- 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
- In the Zoho Developer Console, click Automate in the left pane, then select Workflow
- Select the Rules tab and click Create Rule Button.
- In the New Rule page, fill in the details as given below,
Basic Information
- Module: Leads
- Rule Name: SendSMSonLeadCreation
- Description: Text message upon creating a lead.
- Click Next
Rule Trigger
- Execute Based on : Select A Record Action
- Select Create and click Next
Rule Criteria
- None
- Click Next
Actions
In the Instant Actions
- Go to Call Custom Functions and click +
In the Function editor area:
- 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.
- //Replace the identifiers highlighted in bold with your extension-specific values
- m = Map();
- m.put("type","CurrentUser");
- resp = zoho.crm.invokeConnector("crm.getusers",m);
- response = resp.get("response").toMap();
- indMobile = response.get("users").toMap().get("mobile");
- leadId = lead.get("Leads.ID");
- datamap = Map();
- datamap.put("module","Leads");
- datamap.put("id",leadId);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- resp1 = resp.get("response").toMap();
- reqq = resp1.get("data").toMap();
- fullName = reqq.get("Last_Name");
- mobile = reqq.get("Mobile");
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- msg = zoho.crm.getOrgVariable("twilio__UsersMessage");
- messageToBeSent = fullName + mobile + msg;
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",indMobile);
- mappp.put("From",tmobile);
- mappp.put("Body",messageToBeSent);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info respp;
4. Click Save.
Define Functions and Signals
Functions are the standalone Deluge functions that can be invoked as REST API's.
- In Zoho developer console, click Automate in the left pane and select Functions.
- Click the New Function and provide the function name:
- Function Name : IncomingSMS
- Write the following deluge function in the editor area and click Save:
- //Replace the identifiers highlighted in bold with your extension-specific values
- resp = crmAPIRequest;
- twilioResp = resp.get("parameters").toMap();
- fromNumber = twilioResp.get("From");
- messageContent = twilioResp.get("Body");
- LeadRespList = zoho.crm.searchRecords("Leads","(Mobile|=|" + fromNumber + ")");
- for each LeadResp in LeadRespList
- {
- LeadId = LeadResp.get("id");
- if(LeadId == null || LeadId == "")
- {
- LeadId = "";
- }
- }
- ContactRespList = zoho.crm.searchRecords("Contacts","(Mobile|=|" + fromNumber + ")");
- for each ContactResp in ContactRespList
- {
- FinalId = ContactResp.get("id");
- if(FinalId == null || FinalId == "")
- {
- FinalId = "";
- }
- }
- updateMap = {"twilio__Incoming_Message_Content":messageContent,"CustomModule1_Name":"Incoming SMS","twilio__Lead":LeadId,"twilio__Contact":FinalId,"twilio__Direction":"Inbound"};
- m = Map();
- l = List();
- l.add(updateMap);
- m.put("module","twilio__SMS_Texts");
- m.put("data",l);
- resp = zoho.crm.invokeConnector("crm.create",m);
- signalleadResp = zoho.crm.getRecordById("Leads",LeadId.toLong());
- Leademail = signalleadResp.get("Email");
- if(Leademail != "" || Leademail != null)
- {
- signalMap = Map();
- signalMap.put("signal_namespace","twilio.incomingsmssignal");
- signalMap.put("email",Leademail);
- signalMap.put("subject","Incoming SMS");
- signalMap.put("message",messageContent);
- actionsList = List();
- actionMap = Map();
- actionMap.put("type","link");
- actionMap.put("display_name","View Email");
- actionMap.put("url","www.google.com");
- actionsList.add(actionMap);
- signalMap.put("actions",actionsList);
- result = zoho.crm.invokeConnector("raisesignal",signalMap);
- info result;
- }
- signalcontactResp = zoho.crm.getRecordById("Contacts",FinalId.toLong());
- Contactemail = signalcontactResp.get("Email");
- if(Contactemail != "" || Contactemail != null)
- {
- signalMapx = Map();
- signalMapx.put("signal_namespace","twilio.incomingsmssignal");
- signalMapx.put("email",Contactemail);
- signalMapx.put("subject","Incoming SMS");
- signalMapx.put("message",messageContent);
- actionsListx = List();
- actionMapx = Map();
- actionMapx.put("type","link");
- actionMapx.put("display_name","View Email");
- actionMapx.put("url","www.google.com");
- actionsListx.add(actionMapx);
- signalMapx.put("actions",actionsListx);
- resultx = zoho.crm.invokeConnector("raisesignal",signalMapx);
- info resultx;
- }
- return "";
Signals are notifications that you receive in your CRM account about your customers' interactions with you across various communication channels.
- In Zoho Developer Console click Automate in the left pane and select Signals
- Click the Define Signal button.
- Enter the details as shown below:
- Signal Name : IncomingSMSSignal
- Namespace: Incomingsmssignal
- Click Save.
Test the Extension
- Click Test Your Extension in the top right corner of the Zoho developer console.
- Click the Leads Module.
- Select a particular Lead record and copy the Lead ID provided in the address bar at the top.
Execute the Custom function
- In the Zoho developer console, click Automate located in the left Pane.
- Select Workflow, then select the Custom Functions tab.
- Select SendSMSonLeadCreation and click Edit.
- 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.
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
- In the Zoho Developer Console, click Automate in the left pane and click Workflow.
- Select the Rules tab and click the Create Rule button
- Fill in the details as shown below:
Basic Information
- Module: Contacts
- Rule Name: SMSOnContactCreate
- Description: Text message upon creating a contact.
- Click Next
Rule Trigger
- Execute Based on : Select A Record Action
- Select Create and click Next
Rule Criteria
- None
- Click Next
Actions
In the Instant Actions
- Go to Call Custom Functions and click +
In the Function editor area give
- 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.
- //Replace the identifiers highlighted in bold with your extension-specific values
- m = Map();
- m.put("type","CurrentUser");
- resp = zoho.crm.invokeConnector("crm.getusers",m);
- response = resp.get("response").toMap();
- indMobile = response.get("users").toMap().get("mobile");
- contactId = contact.get("Contacts.ID");
- datamap = Map();
- datamap.put("module","Contacts");
- datamap.put("id",contactId);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- resp1 = resp.get("response").toMap();
- reqq = resp1.get("data").toMap();
- fullName = reqq.get("Last_Name");
- mobile = reqq.get("Mobile");
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- msg = zoho.crm.getOrgVariable("twilio__UsersMessage");
- messageToBeSent = fullName + mobile + msg;
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",indMobile);
- mappp.put("From",tmobile);
- mappp.put("Body",messageToBeSent);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info respp;
4. In the Workflow page, click Save.
Test the Extension
- Click Test your Extension, located in the top-right corner of the Zoho Developer Console.
- Click the Contacts Module.
- Select a Contact record and copy the Contact ID provided in the address bar at the top.
Execute the Custom function
- In the Zoho developer console, click Automate in the Left pane.
- Select Workflow, then select the Custom Functions tab.
- Select SMSOnContactCreate and click Edit.
- 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
- In the Zoho Developer Console, click Modules in the Left pane.
- Select the Modules tab and click the Create New Module button.
- 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
- In the Zoho Developer Console, click Customize in the Left pane.
- Select the Fields tab.
- Select SMS Texts from the Module List and click New Custom Field.
- 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
- In the Zoho Developer Console, click Automate in the left pane and click Workflow.
- Select the Rules tab and click Create Rule button
- Fill in the details as shown below:
Basic Information
- Module: SMS Texts
- Rule Name: send text sms
- Description: Text message on association of a lead with a contact
- Click Next
Rule Trigger
- Execute Based on : Select A Record Action
- Select Create and click Next
Rule Criteria
- None
- Click Next
Actions
In the Instant Actions section,
- Go to Call Custom Functions and click +
In the Function editor area:
- 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.
- //Replace the identifiers highlighted in bold with your extension-specific values
- idz = sms_texts.get("twilio__SMS_Texts.ID");
- datamap = Map();
- datamap.put("module","twilio__SMS_Texts");
- datamap.put("id",idz);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- respMap = resp.get("response").toMap();
- msg = respMap.get("data").toMap();
- CustomSMSMessage = msg.get("twilio__Custom_SMS_Message");
- if(CustomSMSMessage == null)
- {
- info "No SMS Content";
- }
- else
- {
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- mapp = Map();
- mapp.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("From",tmobile);
- if(msg.get("twilio__Contact") != null && msg.get("twilio__Lead") != null)
- {
- leadIdz = msg.get("twilio__Lead").toMap();
- leadId = leadIdz.get("id");
- data1map = Map();
- data1map.put("module","Leads");
- data1map.put("id",leadId);
- resp1 = zoho.crm.invokeConnector("crm.get",data1map);
- resppMap = resp1.get("response").toMap();
- users1 = resppMap.get("data");
- temp1 = users1.replaceAll("[","",true);
- usersVal1 = temp1.replaceAll("]","",false).toMap();
- Mobile = usersVal1.get("Mobile");
- contactIdz = msg.get("twilio__Contact").toMap();
- contactId = contactIdz.get("id");
- data2map = Map();
- data2map.put("module","Contacts");
- data2map.put("id",contactId);
- resp2 = zoho.crm.invokeConnector("crm.get",data2map);
- resp2Map = resp2.get("response").toMap();
- users2 = resp2Map.get("data");
- temp2 = users2.replaceAll("[","",true);
- usersVal2 = temp2.replaceAll("]","",false).toMap();
- Mobile1 = usersVal2.get("Mobile");
- mappp.put("To",Mobile);
- mappp.put("Body",CustomSMSMessage);
- mappp.remove("To");
- mappp.remove("Body");
- mappp.put("To",Mobile1);
- mappp.put("Body",CustomSMSMessage);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,mapp);
- info "respp:: " + respp;
- }
- else if(msg.get("twilio__Lead") != null && msg.get("twilio__Contact") == null)
- {
- leadIdz = msg.get("twilio__Lead").toMap();
- leadId = leadIdz.get("id");
- data1map = Map();
- data1map.put("module","Leads");
- data1map.put("id",leadId);
- resp1 = zoho.crm.invokeConnector("crm.get",data1map);
- resppMap = resp1.get("response").toMap();
- users1 = resppMap.get("data");
- temp1 = users1.replaceAll("[","",true);
- usersVal1 = temp1.replaceAll("]","",false).toMap();
- Mobile = usersVal1.get("Mobile");
- mappp.put("To",Mobile);
- mappp.put("Body",CustomSMSMessage);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,mapp);
- info "respp::: " + respp;
- }
- else if(msg.get("twilio__Contact") != null && msg.get("twilio__Lead") == null)
- {
- contactIdz = msg.get("twilio__Contact").toMap();
- contactId = contactIdz.get("id");
- data2map = Map();
- data2map.put("module","Contacts");
- data2map.put("id",contactId);
- resp2 = zoho.crm.invokeConnector("crm.get",data2map);
- resp2Map = resp2.get("response").toMap();
- users2 = resp2Map.get("data");
- temp2 = users2.replaceAll("[","",true);
- usersVal2 = temp2.replaceAll("]","",false).toMap();
- Mobile1 = usersVal2.get("Mobile");
- mappp.put("To",Mobile1);
- mappp.put("Body",CustomSMSMessage);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,mapp);
- info "respp:::: " + respp;
- }
- else
- {
- info "No Number to send message!";
- }
- }
4. Click Save.
Test the Extension
- Click Test Your Extension located in the top right-corner of the Zoho Developer Console.
- Click the SMS Texts Module.
- Click +, located in the top right corner
- Enter the following values in the fields:
- SMS Texts Name : Incoming SMS(Mandatory field)
- Enter the data for the other fields
- Select a contact from the contact list and a lead from the lead list for Contact and Lead custom fields.
- Custom SMS Message : test (any message)
- Direction : Inbound/Outbound
- Save the record and copy the SMS Texts Id from the address bar.
Execute the Custom function
- In the Zoho Developer Console, click Automate in the Left pane.
- Select Workflow, then select Custom Functions tab.
- Select send Text SMS and click Edit.
- 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
- In the Zoho Developer Console, click Automate in the left pane and click Workflow
- Select the Rules tab and click Create Rule button
- Fill the details as shown below:
Basic Information
- Module: Tasks
- Rule Name: Send SMS on Task
- Description: Text alert message upon reminding task
- Click Next
Rule Trigger
- Execute Based on : Select A Date Field Value and select Due date
- Date of execution : Select Before
- Time of execution : 10.00 AM
- Execution cycle : Once
- Select Create and click Next
Rule Criteria
- None
- Click Next
Actions
In the Instant Actions section,
- Go to Call Custom Functions and click +
In the Function editor area:
- 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:
- //Replace the identifiers highlighted in bold with your extension-specific values
- taskId = task.get("Tasks.ID");
- datamap = Map();
- datamap.put("module","Tasks");
- datamap.put("id",taskId);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- respMap = resp.get("response").toMap();
- users = respMap.get("data");
- temp = users.removeFirstOccurence("[");
- dataVal = temp.removeLastOccurence("]").toMap();
- se_module = dataVal.get("$se_module");
- if(se_module == "Leads")
- {
- What_Id = dataVal.get("What_Id").toMap();
- leadId = What_Id.get("id");
- datamapx = Map();
- datamapx.put("module","Leads");
- datamapx.put("id",leadId);
- respx = zoho.crm.invokeConnector("crm.get",datamapx);
- respMapx = respx.get("response").toMap();
- usersx = respMapx.get("data");
- tempx = usersx.removeFirstOccurence("[");
- dataValx = tempx.removeLastOccurence("]").toMap();
- mobile = dataValx.get("Mobile");
- }
- else
- {
- Who_Id = dataVal.get("Who_Id").toMap();
- contactId = Who_Id.get("id");
- datamapx = Map();
- datamapx.put("module","Contacts");
- datamapx.put("id",contactId);
- respx = zoho.crm.invokeConnector("crm.get",datamapx);
- respMapx = respx.get("response").toMap();
- usersx = respMapx.get("data");
- tempx = usersx.removeFirstOccurence("[");
- dataValx = tempx.removeLastOccurence("]").toMap();
- mobile = dataValx.get("Mobile");
- }
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body","This is an alert for your task deadline You have only two days left!");
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info "respp:::" + respp;
4. Click Save.
Test the Extension
- Click Test Your Extension located in the top right corner of the Zoho Developer Console.
- Click the Activites tab and select +Task in the top-right corner.
- Click Create Task and fill it up with the following information:
- Subject: A new task(Mandatory Field)
- Due date: Select an upcoming date
- Select appropriate values for a either a Contact or a Lead
- Select values for any of the following : Accounts, Potential, Product, Case, Campaign, Vendor or Quote
- Status : In progress
- Priority : High
- Click Save and copy the respective Task ID from the address bar.
Execute the Custom function
- In the Zoho Developer Console, click Automate located in the Left pane.
- Select Workflow and in the Workflow page select Custom Functions tab.
- In Workflow Custom Functions, select Send SMSon Task and click Edit.
- 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
- In the Zoho Developer Console, click Automate in the left pane and click Workflow
- Select the Rules tab and click the Create Rule button
- Fill the details as shown below,
Basic Information
- Module: Events
- Rule Name: Send SMS For Event Participants
- Description: Text alert message to the Event Participants
- Click Next
Rule Trigger
- Execute Based on : Select A Date Field Value and select Choose a Date Field
- Date of execution : Select Before
- Time of execution : 10.00 AM
- Execution cycle : Once
- Select Create and click Next
Rule Criteria
- None
- Click Next
Actions
In the Instant Actions seection,
- Go to Call Custom Functions and click +
In the Function editor area:
- 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.
- //Replace the identifiers highlighted in bold with your extension-specific values
- eventId = event.get("Events.ID");
- datamap = Map();
- datamap.put("module","Events");
- datamap.put("id",eventId);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- respMap = resp.get("response").toMap();
- users = respMap.get("data").toMap();
- participants = users.get("Participants");
- for each indMap in participants
- {
- if(indMap.get("type") == "contact")
- {
- contactId = indMap.get("participant");
- datamapc = Map();
- datamapc.put("module","Contacts");
- datamapc.put("id",contactId);
- respc = zoho.crm.invokeConnector("crm.get",datamapc);
- respMapc = respc.get("response").toMap();
- usersc = respMapc.get("data").toMap();
- mobile = usersc.get("Mobile");
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body","This is alert for your event !");
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info "respp: " + respp;
- }
- else if(indMap.get("type") == "lead")
- {
- leadId = indMap.get("participant");
- datamapc = Map();
- datamapc.put("module","Leads");
- datamapc.put("id",leadId);
- respc = zoho.crm.invokeConnector("crm.get",datamapc);
- respMapc = respc.get("response").toMap();
- usersc = respMapc.get("data").toMap();
- mobile = usersc.get("Mobile");
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body","This is alert for your event !");
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info "respp::: " + respp;
- }
- }
4. Click Save.
Test the extension
- Click Test Your Extension in the top-right corner of the Zoho Developer Console.
- Click the Activites tab and select +Event located in the top-right corner.
- 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
- In the Zoho Developer Console, click Automate located in the Left pane.
- Select Workflow, then select the Custom Functions tab.
- Select Send SMS For Event Participants and click Edit.
- Click the Execute button and enter the Event ID obtained in the previous step.
- Click Submit.
The following API response will be generated and an alert SMS will be sent to one or more event participants.
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
- In the Zoho Developer Console, click Automate in the left pane and click Workflow
- Select the Rules tab and click the Create Rule button.
- Fill in the details as shown below:
Basic Information
- Module: Events
- Rule Name: Send SMS For Event RelatedTo
- Description: Text a confirmation message to the related people of the Event
- Click Next
Rule Trigger
- Execute Based on : Select A Date Field Value and select Choose a Date Field
- Date of execution : Select Before
- Time of execution : 10.00 AM
- Execution cycle : Once
- Select Create and click Next
Rule Criteria
- None
- Click Next
Actions
In the Instant Actions section:
- Go to Call Custom Functions and click +
In the Function editor area:
- 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:
- //Replace the identifiers highlighted in bold with your extension-specific values
- eventId = event.get("Events.ID");
- datamap = Map();
- datamap.put("module","Events");
- datamap.put("id",eventId);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- respMap = resp.get("response").toMap();
- users = respMap.get("data").toMap();
- participants = users.get("Participants");
- for each indMap in participants
- {
- if(indMap.get("type") == "contact")
- {
- contactId = indMap.get("participant");
- datamapc = Map();
- datamapc.put("module","Contacts");
- datamapc.put("id",contactId);
- respc = zoho.crm.invokeConnector("crm.get",datamapc);
- respMapc = respc.get("response").toMap();
- usersc = respMapc.get("data").toMap();
- mobile = usersc.get("Mobile");
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__AuthToken");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body","This is alert for your event !");
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info "respp: " + respp;
- }
- else if(indMap.get("type") == "lead")
- {
- leadId = indMap.get("participant");
- datamapc = Map();
- datamapc.put("module","Leads");
- datamapc.put("id",leadId);
- respc = zoho.crm.invokeConnector("crm.get",datamapc);
- respMapc = respc.get("response").toMap();
- usersc = respMapc.get("data").toMap();
- mobile = usersc.get("Mobile");
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__AuthToken");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body","This is alert for your event !");
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info "respp:: " + respp;
- }
- }
4. Click Save.
Test the extension
- Click Test Your Extension in the top-right corner of the Zoho Developer Console.
- Click the Activities tab and select +Event located in the top-right corner.
- Select any of the Event Records already created.
- Click Edit and select the field Relatedto. (This will show only related leads or contacts)
- Select a record from the Lead or Contact.
- Click Save.
- Copy the Event ID from the address bar.
Execute the Custom function
- In the Zoho Developer Console, click Automate in the Left pane.
- Select Workflow, then select Custom Functions tab.
- Select Send SMS For Event Relatedto and click Edit.
- Click the Execute button and enter the Event ID obtained in the previous step.
- 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.
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
- In the Zoho Developer Console, click Customize, and select Links and Buttons tab in the Customization page.
- Click Create New Button.
- Provide the following details:
- In which module would you like to create a new button?' Select Contacts
- 'What would you like to name the button?' Type Send Bulk SMS
- 'Where would you like to place the button?' Select List View Page
- 'What action would you like the button to perform?' Select Writing Custom Function
- 'Give the function name' Type Send SMS on Contacts
Write the following Deluge script in the editor:
- //Replace the identifiers highlighted in bold with your extension-specific values
- contactid = contact.get("Contacts.ID").toList("|||");
- flag = 0;
- for each abc in contactid
- {
- datamap = Map();
- datamap.put("module","Contacts");
- datamap.put("id",abc);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- respMap = resp.get("response").toMap();
- users = respMap.get("data").toMap();
- mobile = users.get("Mobile");
- if(mobile == null || mobile == "")
- {
- flag = 1;
- }
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- msg = zoho.crm.getOrgVariable("twilio__UsersMessage");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- first = users.get("First Name");
- if(first == null)
- {
- first = "";
- }
- last = resp.get("Last Name");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body",msg);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info respp;
- updateMap = {"twilio.Msg_Content_For_Bulk_SMS":msg,"twilio.SMS_Texts_Name":"Send Through Bulk Contact","twilio.Contact":abc,"twilio.Direction":"Outbound"};
- m = Map();
- l = List();
- l.add(updateMap);
- m.put("module","twilio.SMS_Texts");
- m.put("data",l);
- resp = zoho.crm.invokeConnector("crm.create",m);
- info resp;
- }
- if(flag == 0)
- {
- return "SMS Sent !";
- }
- else
- {
- return "Some Mobile Number Missing ! Can't Send SMS to those Contacts";
- }
- info respp;
4. Click Save to Button.
Test the extension
- Click Test Your Extension located in the top-right corner of the Zoho Developer Console.
- Click the Contacts Module and select multiple contacts from List View.
- Click the Send Bulk SMS button, which appears at the top of the Custom List View page. It will display, 'Message Sent.'
- To test the above operation navigate to the SMS Texts module.
- Select the latest Send Through Bulk Contact SMS Text Name.
- Copy the Contact ID of the Contact that appears in that SMS text.
Execute the Custom function
- In the Zoho Developer Console, Click Customize in the left pane.
- Select the Send Bulk SMS button.
- Select the function Send SMS on Contacts and click Edit
- Execute the Custom Button code.
- 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:
- //Replace the identifiers highlighted in bold with your extension-specific values
- leadid = lead.get("Leads.ID").toList("|||");
- flag = 0;
- for each abc in leadid
- {
- datamap = Map();
- datamap.put("module","Leads");
- datamap.put("id",abc);
- resp = zoho.crm.invokeConnector("crm.get",datamap);
- respMap = resp.get("response").toMap();
- users = respMap.get("data").toMap();
- mobile = users.get("Mobile");
- if(mobile == null || mobile == "")
- {
- flag = 1;
- }
- tmobile = zoho.crm.getOrgVariable("twilio__TwilioMobileNumber");
- twilioAccSId = zoho.crm.getOrgVariable("twilio__AccountsSID");
- authtokenTwilio = zoho.crm.getOrgVariable("twilio__Authtoken");
- msg = zoho.crm.getOrgVariable("twilio.Users Message");
- baseEncoded = zoho.encryption.base64Encode(twilioAccSId + ":" + authtokenTwilio);
- encode = baseEncoded.removeFirstOccurence("\n");
- first = users.get("First Name");
- if(first == null)
- {
- first = "";
- }
- last = resp.get("Last Name");
- headermap = Map();
- headermap.put("Authorization","Basic " + encode);
- mappp = Map();
- mappp.put("To",mobile);
- mappp.put("From",tmobile);
- mappp.put("Body",msg);
- respp = postUrl("https://api.twilio.com/2010-04-01/Accounts/%22 + twilioAccSId + "/Messages.json",mappp,headermap);
- info respp;
- updateMap = {"twilio.Msg_Content_For_Bulk_SMS":msg,"twilio.SMS_Texts_Name":"Send Through Bulk Leads","twilio.Lead":abc,"twilio.Direction":"Outbound"};
- m = Map();
- l = List();
- l.add(updateMap);
- m.put("module","twilio.SMS_Texts");
- m.put("data",l);
- resp = zoho.crm.invokeConnector("crm.create",m);
- }
- if(flag == 0)
- {
- return "SMS Sent !";
- }
- else
- {
- return "Some Mobile Numbers are Missing ! Can't Send SMS to Those Leads";
- }