Journeys Through Search
Zoho CRM integrations

Send SMS from Zoho CRM with Twilio: the Deluge pattern we use

A button on the lead, a Deluge function, the Twilio API, and the text logged on the record. Here is the pattern step by step, with the gotchas that break it.

Journeys Through Search · Updated · 3 min read

In short

  • Keep the Twilio Account SID, Auth Token and sending number in CRM Variables, and add .toString() when you read them.
  • Check the phone number and the Approved to SMS field before you call Twilio.
  • Wrap the call in try/catch and check the response for a message sid. A response is not a sent text.
  • Log every send, and every failure, on the record.
  • Map button arguments with the field picker. Typed merge fields arrive as plain text.

What you are building to send SMS from Zoho CRM

A button on the record

A custom button on Leads, Deals, Contacts or Accounts that runs a Deluge function.

A Deluge send function

It reads the record, checks the number and consent, and calls Twilio.

The Twilio Messages API

Twilio sends the text from your number.

An SMS record in Zoho CRM

The message, the result and the time saved on the record it was sent from.

Before you start

  • A Twilio account and a sending number, with the carrier registration Twilio requires for business texting done.
  • An Approved to SMS checkbox on the modules you text from.
  • A module for SMS records, related to Leads, Deals and Contacts, to hold the message history.
  • Phone numbers stored in one format. Twilio expects E.164, like +15555550100.

Step 1: Store the Twilio credentials in CRM Variables

Add three CRM Variables (org variables) in Zoho CRM: the Account SID, the Auth Token and the sending number. Keeping them out of the function code means a token change is one edit, and the token is not copied into every function that sends.

Step 2: Write the Deluge function that sends the SMS

Take the record ID as an argument

Fetch the record with zoho.crm.getRecordById, so the function works from current data.

Null check the phone number

If the mobile or phone field is empty, stop and return a clear message. Do not call Twilio with a blank To.

Check consent

If Approved to SMS is not checked, stop and return "Not approved to SMS".

Format the number

Strip spaces, dashes and brackets, and add the country code, so the number is in E.164.

Build the auth header

Base64 encode "AccountSID:AuthToken" with zoho.encryption.base64Encode and send it as "Basic" plus the encoded value.

Call Twilio inside try/catch

Use invokeurl with type POST to the Messages.json URL for your account, with To, From and Body as parameters. Catch any exception and log it.

Step 3: Check the Twilio response

Getting a response back does not mean the text went out. Read it before you report success.

  • Success: the response has a message sid and a status such as queued. Save the sid on the SMS record.
  • Error: the response has a code and a message, such as an invalid To number. Save both on the SMS record and show the message to the rep.
  • No response or an exception: log it as failed, and send an alert so someone looks.

Step 4: Log the text on the Zoho CRM record

Create an SMS record for every attempt: the body, the to and from numbers, the status, the Twilio sid or the error, and the user who sent it. Relate it to the lead, deal or contact, so the next rep sees the whole conversation.

Failed sends belong in the log too. A list view of failed texts is the fastest way to spot a bad number format or an expired token.

Talk through your project

A free call about your integration, your CRM or whatever you are stuck on. Honest advice, even if you never hire us. No obligation.

Book a free call →

Step 5: Add the custom button and map its arguments

In the module's settings, add a custom button that runs your function. Then map the function's arguments, like the record ID, to fields.

Step 6: Receive Twilio replies in Zoho CRM

Sending is half of it. For replies, point your Twilio number's incoming message webhook at a Twilio Function. The function passes the message to Zoho CRM, where it is matched by phone number and saved on the record. A text from a new number can create a lead.

When to move from a button to a widget

A button sends one message from one field. When reps need to pick the number to send from, choose a template, schedule a text or see the history while they type, build a widget. The widget calls the same Deluge function, so the credentials stay on the server.

Want help with this?

Book a free call about your CRM, integrations or reporting, or map your systems first with our free tech stack diagram builder.