Skip to product menu
close
  • Recent Launches
    Press Space or Enter to display list of options
EXPLORE ALL PRODUCTS

Recent Launches

New

Payroll software with automated tax payments and filing.

Try now
New

Robotic process automation software to automate high-volume, rule-based tasks.

Try for free
New

Low-code IoT platform and solutions for connected businesses.

Try now
New

Business formation service to launch and grow your businesses.

Try now
New

Privacy-friendly application analytics solution.

Try for free

Sales

 
CRM

Comprehensive CRM platform for customer-facing teams.

CRM
 
Bigin

Simple CRM for small businesses moving from spreadsheets.

Bigin
 
Forms

Build online forms for every business need.

Forms
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Sign

Digital signature app for businesses.

Sign
 
RouteIQ

Comprehensive sales map visualization and optimal route planning solution.

RouteIQ
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
Suites
CRM Plus

Unified platform to deliver top-notch customer experience.

CRM Plus

Marketing

 
Social

All-in-one social media management software.

Social
 
Campaigns

Create, send, and track targeted email campaigns that drive sales.

Campaigns
 
Forms

Build online forms for every business need.

Forms
 
Survey

Design surveys to reach and interact with your audience.

Survey
 
Sites

Online website builder with extensive customisation options.

Sites
 
PageSense

Website conversion optimization and personalisation platform.

PageSense
 
Backstage

End-to-end event management software.

Backstage
 
Webinar

Webinar platform for webcasting online webinars.

Webinar
 
Marketing Automation

All-in-one marketing automation software.

Marketing Automation
 
LandingPage

Smart landing page builder to increase conversion rates

LandingPage
 
Publish

Manage all your local business listings on a single platform.

Publish
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Sign

Digital signature app for businesses.

Sign
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
LeadChain

Sync, manage, and convert leads across channels seamlessly.

LeadChain
 
NEW
CommunitySpaces

Online community platform for individuals and businesses to grow their network and brand.

CommunitySpaces
 
Suites
Marketing Plus

Unified marketing platform for marketing teams.

Marketing Plus

Commerce

 
Commerce

eCommerce platform to manage and market your online store.

Commerce

Service

 
Desk

Helpdesk software to deliver great customer support.

Desk
 
Assist

Remote support and unattended remote access software.

Assist
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
FSM

End-to-end field service management platform for service businesses.

FSM
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Suites
Service Plus

Unified platform for customer service and support teams.

Service Plus

Finance

 
Books

Powerful accounting platform for growing businesses.

Books
 
FREE
Invoice

100% Free invoicing solution.

Invoice
 
Expense

Effortless expense reporting platform.

Expense
 
Inventory

Powerful stock management and inventory control software.

Inventory
 
Billing

End-to-end billing solution for your business.

Billing
 
Checkout

Collect payments online with custom branded pages.

Checkout
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Practice

Practice management software for accounting firms.

Practice
 
Sign

Digital signature app for businesses.

Sign
 
Commerce

eCommerce platform to manage and market your online store.

Commerce
 
Suites
Finance Plus

All-in-one suite to manage your operations and finances.

Finance Plus

Email and Collaboration

 
Mail

Secure email service for teams of all sizes.

Mail
 
Meeting

Online meeting software for all your video conferencing & webinar needs.

Meeting
 
Writer

Word processor for focused writing and discussions.

Writer
 
Sheet

Spreadsheet software for collaborative teams.

Sheet
 
Show

Create, edit, and share slides with a sleek presentation app.

Show
 
Notebook

Beautiful home for all your notes.

Notebook
 
Cliq

Stay in touch with teams no matter where you are.

Cliq
 
Connect

Employee experience platform to communicate, engage, and build positive employee relations.

Connect
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
TeamInbox

Shared inboxes for teams.

TeamInbox
 
WorkDrive

Online file management for teams.

WorkDrive
 
Sign

Digital signature app for businesses.

Sign
 
Office Suite

Powerful collaborative work platform for teams.

Office Suite
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
Calendar

Online business calendar to manage events and schedule appointments.

Calendar
 
Learn

Knowledge and learning management platform.

Learn
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
ToDo

Collaborative task management for individuals and teams.

ToDo
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
FREE
PDF Editor

Collaborative online PDF editing tool.

PDF Editor
 
Suites
Workplace

Application suite built to improve team productivity and collaboration.

Workplace

Human Resources

 
People

Organize, automate, and simplify your HR processes.

People
 
Recruit

Intuitive recruiting platform built to provide hiring solutions.

Recruit
 
Expense

Effortless expense reporting platform.

Expense
 
Workerly

Manage temporary staffing with an employee scheduling solution.

Workerly
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
Shifts

Employee scheduling and time tracking app.

Shifts
 
Sign

Digital signature app for businesses.

Sign
 
Suites
People Plus

Comprehensive HR platform for seamless employee experiences.

People Plus

Security and IT Management

 
Creator

Build custom apps to simplify business processes.

Creator
 
Directory

Workforce identity and access management solution for cloud businesses.

Directory
 
FREE
OneAuth

Secure multi-factor authenticator (MFA) for all your online accounts.

OneAuth
 
Vault

Online password manager for teams.

Vault
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Toolkit

Complete resource for any admin-related lookup queries.

Toolkit
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
Assist

Remote support and unattended remote access software.

Assist
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA

BI and Analytics

 
Analytics

Modern self-service BI and analytics platform.

Analytics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
 
NEW
IoT

Harnessing IoT analytics for real-time operational intelligence.

IoT

Project Management

 
Projects

Manage, track, and collaborate on projects with teams.

Projects
 
Sprints

Planning and tracking tool for scrum teams.

Sprints
 
BugTracker

Automatic bug tracking software for managing bugs.

BugTracker
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo

Developer Platforms

 
Creator

Build custom apps to simplify business processes.

Creator
 
Flow

Automate business workflows by creating smart integrations.

Flow
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
 
NEW
Apptics

Application analytics for all apps.

Apptics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
NEW
IoT

Build, deploy, and scale IoT solutions for connected businesses.

IoT
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep

IoT

 
NEW
IoT

Low-code IoT platform and solutions for connected businesses.

IoT

Search Result

 
CRM Plus

Unified platform to deliver top-notch customer experience.

Try now
CRM Plus
 
Service Plus

Unified platform for customer service and support teams.

Try now
Service Plus
 
Finance Plus

All-in-one suite to manage your operations and finances.

Try now
Finance Plus
 
People Plus

Comprehensive HR platform for seamless employee experiences.

Try now
People Plus
 
Workplace

Application suite built to improve team productivity and collaboration.

Try now
Workplace
 
Marketing Plus

Unified marketing platform for marketing teams.

Try now
Marketing Plus
 
All-in-one suite

Zoho One

The Operating System for Business

Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.

TRY ZOHO ONE
Zoho One
Zoho Marketplace

With over 2000 ready-to-use extensions across 40+ categories, connect your favorite business tools with the Zoho products you already use.

EXPLORE MARKETPLACE
Marketplace
Skip to main content

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.

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.

This guide will help a developer to

  1. Obtain Twilio credentials for authentication
  2. Build a sample Twilio extension

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:
    • Extension Name : Twilio
    • Unique Namespace : Twilio (Choose a unique namespace. This cannot be changed later)
    • 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:
    • Field Name  : Authtoken
    • API Name  : Authtoken
    • 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

  • 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/" + twilioAccSId + "/Messages.json",mappp,headermap);
info respp;

  1. 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 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.

  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:
    • Signal Name  : IncomingSMSSignal
    • 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 consoleclick 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.

(ii) 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

  • 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/" + twilioAccSId + "/Messages.json",mappp,headermap);
info respp;

  1. 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.

(iii) 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 Consoleclick 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

Label

Datatype

Contact

Lookup

Lookup type :Contacts

Related list label :SMS Texts

Custom SMS Message

Single Line

Length :200

Direction

Pick List

Values : Outbound, Inbound

Incoming Message Content

Single Line

Length:250

Lead

Lookup

Lookup type :Leads

Related list label :SMS Texts

Message Content for Bulk SMS

Single Line

Length :200

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

  • 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/" + 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/" + 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/" + twilioAccSId + "/Messages.json",mappp,mapp);
          info "respp:::: " + respp;
     }
     else
     {
          info "No Number to send message!";
     }
}

  1. 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:
    • 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
  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:

(iv)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 Work flow
  2. Select the Rules tab and click Create Rule button
  3. 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/" + twilioAccSId + "/Messages.json",mappp,headermap);
info "respp:::" + respp;

  1. 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:
    • 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
  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:

(v) 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

  • 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 Participants in 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/" + 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/" + twilioAccSId + "/Messages.json",mappp,headermap);
          info "respp::: " + respp;
     }
}

  1. 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 Consoleclick 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.

(vi) 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

  • 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/" + 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/" + twilioAccSId + "/Messages.json",mappp,headermap);
          info "respp:: " + respp;
     }
}

  1. 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 Consoleclick 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.

(vii) 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:
    • '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/" + 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;

  1. 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:

//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/" + 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";
}