Send a WhatsApp message from Zoho CRM when a deal is won
When a deal closes in Zoho CRM, the customer should hear from you straight away, and for most Kenyan customers that means WhatsApp. This guide shows how to make Zoho send that message automatically, using a workflow rule, a Deluge custom function and the Qwela API. Nobody has to copy a phone number into WhatsApp by hand.
What you need
- Zoho CRM on the Professional edition or higher. Workflow automation is part of those editions.
- A Qwela account with a linked WhatsApp number and an API key (start a free trial).
- Phone numbers stored on your contacts, ideally with the country code.
The idea
A workflow rule watches the Deals module. When the stage becomes Closed Won, it calls a custom function. The function builds a short message and posts it to Qwela with invokeUrl, the Deluge command for calling external APIs. Qwela queues the message and sends it from your number.
Step 1: create the custom function
In Zoho CRM's setup, open the automation area and create a new function in the Deals module. Menu names move around between Zoho versions, so look for Workflows and then Functions. Give it three arguments mapped from the deal: contactName, contactPhone and dealName. Paste this code:
qwelaKey = "gw_your_key_here";
phone = ifnull(contactPhone, "").replaceAll("[^0-9+]", "");
if(phone == "")
{
info "No phone number on this contact, message not sent";
}
else
{
text = "Hi " + ifnull(contactName, "there") + ", thank you for choosing us. "
+ "Your order " + dealName + " is confirmed and we will be in touch shortly.";
payload = Map();
payload.put("to", phone);
payload.put("text", text);
response = invokeUrl
[
url: "https://qwela.jpl365.com/v1/messages"
type: POST
headers: {"Authorization": "Bearer " + qwelaKey, "content-type": "application/json"}
body: payload.toString()
detailed: true
];
if(response.get("responseCode") != 202)
{
info "Qwela error: " + response.get("responseText");
}
}
Using detailed: true returns the response code and body, so you can check for a 202, which means the message was queued, instead of assuming it worked. The replaceAll line strips spaces, dashes and brackets from the phone number. Qwela accepts numbers like +254712345678, 254712345678 and 0712345678.
Keep the API key out of plain sight
Pasting a key into a function works for a test, but for production store it somewhere safer, such as a Zoho organisation variable or connection that your admin controls, and read it from there. Anyone who can edit the function can see a key written inside it. If a key ever leaks, revoke it on the API keys page of the Qwela dashboard and create a new one.
Step 2: create the workflow rule
- Create a workflow rule on the Deals module.
- Set it to run when a record is created or edited, and add the condition Stage is Closed Won.
- Add an instant action of type Function and choose the function you just made.
- Map the arguments:
contactNameto the contact's name,contactPhoneto the contact's mobile or phone field, anddealNameto the deal name. - Save and activate the rule.
Set the rule to run only the first time the condition is met, so editing a closed deal later does not send the message again.
Test it safely
Create a test deal for a contact whose number is your own, move it to Closed Won, and check that the message arrives. If it does not, open the Messages page in the Qwela dashboard. It shows whether the request arrived and whether the message was sent or failed, and why.
More ideas with the same function
- A payment receipt when an invoice is marked paid. Zoho Books also supports Deluge custom functions in workflows.
- A reminder when a quote has been open for several days.
- An alert to your own number when a high-value lead arrives.
- Replies from customers, delivered to a webhook that adds a note to the matching contact.
Send responsibly
Only message customers who gave you their number for this kind of contact. A message confirming an order they just placed is exactly right. A promotional blast to old leads is not, and it is how numbers get restricted. See how to avoid a WhatsApp number ban for the full checklist.
At JPL365 we implement and customise Zoho for Kenyan businesses, including connections like this one. If you would like it set up and tested for you, talk to JPL365.