Skip to main content

Automatically Assign Chats in Wati Based on Lead Owner in Zoho CRM

Updated this week

Summary

Want to automatically assign incoming chats to the right sales owner in Wati? This guide shows you how to check if a user already exists in Zoho CRM and assign their chat to the correct Lead Owner. If the user is new, you can send them a welcome message instead. This setup helps ensure faster responses and better customer experience.

Note: This feature requires either the Pro or Business plan on Wati.

Instructions

Overview of the Solution

You'll set up a chatbot in Wati that does the following when a user starts a conversation:

  • Checks if the user exists in Zoho CRM using their phone number.

  • If the user exists:

  • Retrieves the Lead Owner from Zoho.

  • Assigns the chat to that Lead Owner in Wati.

  • If the user doesn't exist:

  • Sends a welcome message.

  • If the Zoho API token has expired:

  • Refreshes the token and retries.

How to Set Up the Chatbot & Assign Conversations

1. Default Chatbot Setup

  • Configure the chatbot to automatically launch whenever a user starts a new conversation.

2. Check for Stored Access Token

  • The system checks if an access token (needed for API calls) is already saved in the contact's Custom Attributes.

  • If the token exists → Use it in Step 3 (API Call).

  • If not → Proceed to get a new token (explained later).

3. Search for Lead in Zoho CRM

  • Make an API call to Zoho CRM's "Search Records" endpoint.

  • Pass the user's phone number to check if they are an existing lead.

4. Handle API Responses

Status Code

What it means

Action to take

200 (Success)

A lead exists, and the response includes the Lead Owner's name.

Use "Set a Condition" + "Assign Agent" to route the chat to the Lead Owner.

204 (No Content)

No lead exists for this phone number (new user).

Treat them as a new lead and proceed with your default chatbot flow.

401 (Unauthorized)

The access token has expired.

Refresh the access token before making further API calls.

Steps to Set This Up

1. Download the Chatbot Template

Download the ready-to-use chatbot template: Check Zoho Lead Owner and Assign Chat.json

This template contains the required flows to connect Wati with Zoho CRM.

2. Import the Template into Wati

  • Go to Automation > Chatbots in your Wati account.

  • Click Import JSON.

  • Upload the downloaded chatbot template.

3. Update Your Zoho API Details

In the first webhook node of your chatbot flow:

Update your Zoho API Endpoint.

Add your Access Token.

4. Generate a Zoho CRM Access Token (If Needed)

If you already have an access token for Zoho CRM, skip to Step 5.

To generate a new Access Token:

  1. Go to the Zoho API Console: api-console.zoho.com

  2. Create a Self Client to get your:

  3. client_id

  4. client_secret

  5. code

  6. Use the following command to generate your access token:

curl --location --request POST 'https://accounts.zoho.com/oauth/v2/token?grant_type=authorization_code&client_id=<Enter Client ID>&client_secret=<Enter Client Secret>&code=<Enter Code>'

Your token will look like this:Zoho-oauthtoken 1000.xxxxxxxxxxx.xxxxxxxxxxxx

5. Add the Access Token to the Second Webhook Node

In the second webhook node:

  • Go to Customize Headers.

  • Add your Zoho CRM Access Token in the Authorization field.

6. Understand How the Chatbot Logic Works

The chatbot uses Zoho's API to search for a user based on their phone number.

Case 1: User Exists in Zoho (Status Code: 200)

  • The API will return the Lead Owner.

  • Use the Set a Condition node to check if the Lead Owner matches an agent name in Wati.

  • If it matches, use the Assign Agent node to assign the chat to that agent.

Case 2: User Does Not Exist in Zoho (Status Code: 204)

  • Treat this user as new.

  • Send them a welcome message.

Case 3: Access Token Expired (Status Code: 401)

  • Use another webhook node to refresh the token.

  • Make an API call with your client_id, client_secret, and refresh_token:

curl --location --request POST 'https://accounts.zoho.com/oauth/v2/token' \
-H 'Content-Type: application/json' \
-d '{
"grant_type": "refresh_token",
"client_id": "<Enter Client ID>",
"client_secret": "<Enter Client Secret>",
"refresh_token": "<Enter Refresh Token>"
}'

Final Notes

This setup helps you:

  • Automatically assign chats to the right sales owner.

  • Provide a better customer experience with faster responses.

  • Handle new users smoothly with a welcome message.

  • Keep your Zoho token management automated.

Frequently Asked Questions (FAQs)

General Questions

1. What is the purpose of this chatbot setup in Wati?

→ The chatbot setup helps automatically assign incoming chats to the correct Lead Owner from Zoho CRM based on the user's phone number. If the user does not exist in Zoho CRM, the chatbot sends a welcome message.

2. What Wati plan is required to use this feature?

→ This feature requires either the Pro or Business plan on Wati.

3. What happens if the user is already in Zoho CRM?

→ The chatbot retrieves the Lead Owner associated with the user and assigns the chat to that sales owner in Wati.

4. What happens if the user is not found in Zoho CRM?

→ The chatbot treats the user as new and sends a welcome message.

Setup & Configuration

5. Where can I get the chatbot template for this setup?

→ You can download the ready-to-use chatbot template Check Zoho Lead Owner and Assign Chat.json provided in the guide.

6. How do I import the chatbot template into Wati?

→ Go to Automation > Chatbots in your Wati account, click Import JSON, and upload the downloaded template.

7. What Zoho CRM details do I need to configure in the chatbot?

→ You need to add your Zoho API Endpoint and Access Token in the relevant webhook nodes of the chatbot flow.

8. How do I generate a new Zoho CRM Access Token?

→ Go to the Zoho API Console (api-console.zoho.com), create a Self Client, and use the provided client_id, client_secret, and code to generate the access token using the provided curl command.

9. Where should I add the Zoho CRM Access Token in the chatbot?

→ Add your Access Token in the Authorization field of the second webhook node by customizing the headers.

Token Management

10. What happens if the Zoho CRM Access Token expires?

→ The chatbot detects the 401 Unauthorized status code and uses the Zoho Refresh Token API to generate a new Access Token automatically.

11. Where is the new Access Token saved after refreshing?

→ The new token is saved in a dummy contact (for example, phone number 22222222) in Wati for future use.

Chatbot Logic

12. How does the chatbot decide which agent to assign a chat to?

→ If the API response returns a Lead Owner's name from Zoho CRM, the chatbot checks if it matches an agent's name in Wati. If it matches, the chat is assigned to that agent.

13. What happens if there is no matching agent in Wati?

→ If no matching agent is found, you can configure the chatbot to follow your default flow, such as sending a welcome message or assigning the chat to a default agent.

Troubleshooting

14. What should I do if the chatbot does not assign chats correctly?

→ Verify that:

  • The Access Token is correctly added.

  • The phone number format in Zoho matches the one users provide.

  • The Lead Owner's name in Zoho matches the agent's name in Wati.

15. How can I test if the chatbot setup works correctly?

→ You can simulate a user conversation in Wati and check if the chatbot:

  • Identifies existing leads in Zoho.

  • Assigns the chat to the correct agent.

  • Sends a welcome message to new users.

  • Refreshes the token automatically if expired.

Did this answer your question?