--- title: "Zoho Cliq Bots" date: 2026-12-05T00:00:00Z draft: false description: "Zoho Cliq bot handlers, incoming webhooks and tokens, message actions and Deluge connections, with copy-paste snippets for quick integrations." categories: ["tools"] tags: ["zoho", "cliq", "bot", "deluge", "webhook", "integration"] --- ## Overview Zoho Cliq can be extended with bots, message actions, webhooks and connections, all scripted in Deluge from the console (Profile > Bots & Tools). This page is the short path to a working integration: what to use when, the variables each handler gets, and snippets to paste and adapt. Host depends on your data centre (`cliq.zoho.com`, `.in`, `.eu`, `.com.au`). Snippets use `cliq.zoho.in`. ## Setup ```text 1. Bots & Tools > Bots > Create unique name, letters/digits/underscore (no hyphens), e.g. mybuddy 2. Add the bot to the channels it must work in 3. Bots & Tools > Connections create a Zoho Cliq connection (scopes below), authorise it 4. Bots & Tools > Webhook Tokens generate a token (max 5 per user), keep it out of git 5. Bot > Edit Handlers paste the handler code 6. Test in a sandbox channel first ``` ## Choosing a Piece | Need | Use | |---|---| | Run something on one specific message with a click | Message action | | Commands by typing (`@mybuddy status`) | Mention handler | | A script, CI job or service posts into Cliq | Incoming webhook handler + webhook token | | Greet users | Welcome handler | | Read or write threads and chats from Deluge | Connection to Cliq | | Create a ticket or issue in another service | Message action or mention + connection to it | | Plain alert, no logic | `zoho.cliq.postToChannelAsBot(...)` | ```text Bot identity + handlers + incoming URL. Not for "click on one message". Message action menu entry on a message. Can start a thread. Cannot post as the bot by itself. Connection stored credential Deluge uses for you. Skip it for public APIs or a plain secret header. ``` ## Bot Handlers Console: Bots & Tools > Bots > your bot > Edit Handlers. Every handler returns a Map; an empty Map says nothing. Read the comment at the top of the editor for the exact variable names. | Handler | Fires when | Variables | |---|---|---| | Welcome | User subscribes or returns | `newuser`, `user` | | Mention | Bot is mentioned | `message`, `mentions`, `user`, `chat` | | Participation | A person writes in a chat the bot is in | `operation`, `data`, `chat` | | Incoming Webhook | HTTP POST to the bot's incoming URL | `http_method`, `params`, `headers`, `body` | | Message action | Click on a message | `message`, `messages`, `attachments`, `user`, `mentions`, `chat`, `location` | ### Mention Command Router ```deluge response = Map(); raw = message.toString().trim(); // mention already removed cmd = raw; rest = ""; if(raw.contains(" ")) { cmd = raw.getPrefix(" "); rest = raw.getSuffix(" "); } cmd = cmd.toLowerCase(); if(cmd == "ping") { text = "pong"; } else if(cmd == "status") { text = "All good. Args: " + rest; } else { text = "Commands: *ping*, *status *"; } response.put("text", text); return response; ``` ### Echo Handler (see what you really receive) ```deluge response = Map(); out = "message: " + ifnull(message, "-").toString() + "\n" + "user: " + ifnull(user, "-").toString() + "\n" + "chat: " + ifnull(chat, "-").toString(); info out; // shows in the execution log if(out.length() > 3500) { out = out.subString(0, 3500); } response.put("text", out); return response; ``` ### Handy Fields ```deluge chat.get("chat_type") // "channel", "thread", ... chat.get("channel_unique_name") // in a channel chat.get("parent_resource").toString().toMap().get("channel_unique_name") // in a thread user.get("id").toString() user.get("first_name") ``` ### Posting From Code ```deluge // into a channel as the bot zoho.cliq.postToChannelAsBot("channel_unique_name", "mybuddy", "text"); // debugging: write to the execution log info "value: " + someVar; ``` ## Webhooks & Tokens A webhook token (Bots & Tools > Webhook Tokens) authenticates inbound calls as the user who generated it. Treat it like a password: store it outside git (`chmod 600` file), rotate by generating a new one. ```bash # Post to the bot's incoming webhook (handler receives the JSON as `body`) curl -s -X POST "https://cliq.zoho.in/api/v2/bots/mybuddy/incoming?zapikey=$CLIQ_KEY" \ -H 'Content-Type: application/json' \ -d '{"title":"Build finished","detail":"main passed in 4m12s"}' ``` ```bash # Same from a script, building safe JSON with jq jq -n --arg t "$1" --arg d "${2:-}" '{title:$t, detail:$d}' | curl -s -o /dev/null -w 'HTTP %{http_code}\n' -X POST \ "https://cliq.zoho.in/api/v2/bots/mybuddy/incoming?zapikey=$CLIQ_KEY" \ -H 'Content-Type: application/json' --data @- ``` HTTP 200 means the webhook accepted the call, not that the post worked: check the handler log. ### Incoming Webhook Handler (router) ```deluge response = Map(); raw = body.toString(); if(!raw.trim().startsWith("{")) { // another service's event: echo it while you learn its shape if(raw.length() > 3000) { raw = raw.subString(0, 3000); } zoho.cliq.postToChannelAsBot("sandbox_channel", "mybuddy", "Event:\n" + raw); return response; } payload = body.toMap(); if(payload.get("chat_id") != null) { // post text into a chat or thread as the bot, through the connection msg = Map(); msg.put("text", payload.get("text").toString()); hdr = Map(); hdr.put("Content-Type", "application/json"); r = invokeurl [ url: "https://cliq.zoho.in/api/v2/chats/" + payload.get("chat_id").toString() + "/message?bot_unique_name=mybuddy" type: POST parameters: msg.toString() headers: hdr connection: "myconnection" ]; if(r.toString().toLowerCase().contains("error")) { response.put("text", "post failed: " + r.toString()); } return response; } if(payload.get("title") != null) { zoho.cliq.postToChannelAsBot("sandbox_channel", "mybuddy", "*" + payload.get("title") + "*\n" + payload.get("detail")); } return response; ``` ### Calling Your Own Service From Cliq ```deluge mh = Map(); mh.put("X-My-Secret", "PASTE_SHARED_SECRET"); // keep real secrets out of git mh.put("Content-Type", "application/json"); res = invokeurl [ url: "https://example.com/hook" type: POST parameters: payload.toString() headers: mh ]; info res; ``` ## Connections A connection is a named credential: put `connection: "name"` in `invokeurl` and Zoho adds and refreshes the token. The name is the link name shown in the console. ```text Kinds Zoho services (Cliq, Desk, CRM, Creator, Catalyst), prebuilt third-party (GitHub, Google, Slack), custom (OAuth 2 client id and secret, or an API key) Create Bots & Tools > Connections > create > pick service > name > scopes > authorise Identity calls run as the authorising user; use a dedicated account for production Login user option "use credentials of login user": each user authorises their own account Scopes ZohoCliq.Messages.READ (read threads), ZohoCliq.Webhooks.CREATE (post, start threads) New scope reauthorise the connection ``` ```deluge // GET through a connection res = invokeurl [ url: "https://cliq.zoho.in/api/v2/chats/" + chatId + "/messages?limit=100" type: GET connection: "myconnection" ]; info res; ``` ```deluge // create a GitHub issue from a message through another connection issue = Map(); issue.put("title", "From Cliq"); issue.put("body", message.get("text").toString()); hdr = Map(); hdr.put("Content-Type", "application/json"); r = invokeurl [ url: "https://api.github.com/repos/OWNER/REPO/issues" type: POST parameters: issue.toString() headers: hdr connection: "githubcon" ]; info r; // a 200 with an error body is common: always log ``` ### Cliq REST Through a Connection | Job | Call | |---|---| | Recent messages of a chat or thread | `GET /api/v2/chats/{chat_id}/messages?limit=100` | | One message | `GET /api/v2/chats/{chat_id}/messages/{message_id}` | | The message a thread started from | `GET /api/v3/threads/{thread_chat_id}/messages/main` | | Post to a chat or thread (shows the connection owner) | `POST /api/v3/chats/{chat_id}/messages` `{"text":"..."}` | | Post as the bot | `POST /api/v2/chats/{chat_id}/message?bot_unique_name={bot}` `{"text":"..."}` | | Start a thread under a channel message | `POST /api/v3/channelsbyname/{channel}/messages` `{"text":"...","thread_message_id":""}` | Useful message keys: `content.text`, `sender.id` (bots start with `b-`), `type`, `thread_information.chat_id`, `time`, `id`. ## Message Actions Console: Bots & Tools > Message Actions > create > set access > edit code. A generic name (for example "Buddy") lets you add more actions later. The returned `text` is shown only to the person who clicked. ```deluge response = Map(); if(chat.get("chat_type") != "channel") { response.put("text", "Use this on a channel message."); return response; } channelName = ifnull(chat.get("channel_unique_name"), "").toString(); chatId = chat.get("id").toString(); msgId = message.get("id").toString(); hdr = Map(); hdr.put("Content-Type", "application/json"); // 1. use the message's thread, or start one under it threadChat = ""; ti = message.get("thread_information"); if(ti != null) { threadChat = ti.toString().toMap().get("chat_id").toString(); } else { body = Map(); body.put("text", "#Noted"); body.put("thread_message_id", msgId); invokeurl [ url: "https://cliq.zoho.in/api/v3/channelsbyname/" + channelName + "/messages" type: POST parameters: body.toString() headers: hdr connection: "myconnection" ]; // 2. re-read the message to learn the new thread's chat id r2 = invokeurl [ url: "https://cliq.zoho.in/api/v2/chats/" + chatId + "/messages/" + msgId type: GET connection: "myconnection" ]; ti2 = r2.toString().toMap().get("thread_information"); if(ti2 != null) { threadChat = ti2.toString().toMap().get("chat_id").toString(); } } if(threadChat == "") { response.put("text", "Could not find the thread id."); return response; } response.put("text", "Done."); return response; ``` To post as the bot from a message action, call the bot's own incoming webhook (the connection call posts as its owner and ignores the bot name): ```deluge hook = Map(); hook.put("chat_id", threadChat); hook.put("text", "#Checking"); hook.put("bot_unique_name", "mybuddy"); hdr = Map(); hdr.put("Content-Type", "application/json"); invokeurl [ url: "https://cliq.zoho.in/api/v2/bots/mybuddy/incoming?zapikey=PASTE_WEBHOOK_TOKEN" type: POST parameters: hook.toString() headers: hdr ]; ``` ### Why a Message Action Instead of a Mention ```text A mention as the first message of a new thread is never delivered to the bot. The action works on the message itself, can create the thread, and needs no typing. ``` ## Limits ```text Messages posted by other bots or integrations never reach a handler you can write. Use a message action (click) or a scheduled job that reads the channel through a connection. A bot cannot start a thread: the first message of a thread shows the connection owner. A message posted as a bot never returns its id: post by chat id through a connection. A connection call ignores the bot name; the v2 chat endpoint with ?bot_unique_name= honours it. A channel can hold at most 10 bots. Access is by channel, not by user: keep an allowed-channels list and check it in the handler. ``` ## Troubleshooting | Symptom | Cause | Fix | |---|---|---| | `Variable 'x' is not defined` on save | Guessed variable name | Use the names in the editor's top comment | | Webhook returns 200, nothing in Cliq | 200 only means accepted | Check the handler log; bot needs channel membership | | First mention in a new thread does nothing | Not delivered to bots | Use a message action | | Invalid or expired token | Authoriser revoked or changed password | Reauthorise the connection | | Permission error on a call | Scope missing when authorised | Add the scope, reauthorise | | Connection not found | Wrong link name | Copy the name from the console | | Post shows your name, not the bot's | Connection posts show the owner | `?bot_unique_name=` on the v2 chat endpoint, or `postToChannelAsBot` | | Bot's own status messages read back as replies | They look human when posted through a connection | Start them with a marker such as `*#` and skip those | | Ids contain `%20` | Cliq encodes spaces in some ids | Normalise ids before storing | | Secret leaked into a chat | Filled handler pasted as text | Rotate it, and share filled handlers only by clipboard | ## Quick Reference | Item | Value | |---|---| | Bot incoming URL | `https://cliq.zoho.in/api/v2/bots/{bot}/incoming?zapikey={token}` | | Webhook token limit | 5 per user | | Post as bot (Deluge) | `zoho.cliq.postToChannelAsBot(channel, bot, text)` | | Use a connection | `invokeurl [ url: ... type: GET connection: "name" ]` | | Debug | `info value;` then read the execution log | | Reply | `response = Map(); response.put("text", "..."); return response;` | | Bot unique name | letters, digits, underscore; no hyphens | ## See Also - [Bots](https://www.zoho.com/cliq/help/platform/bots.html) and [Bot handlers](https://www.zoho.com/cliq/help/platform/bothandlers.html) - [Mentions handler](https://www.zoho.com/cliq/help/platform/bot-mentionshandler.html), [Participation handler](https://www.zoho.com/cliq/help/platform/bot-participation-handler.html), [Incoming webhook handler](https://www.zoho.com/cliq/help/platform/bot-incomingwebhookhandler.html) - [Webhook tokens](https://www.zoho.com/cliq/help/platform/webhook-tokens.html) - [Message actions](https://www.zoho.com/cliq/help/platform/messageactions.html) and [handler](https://www.zoho.com/cliq/help/platform/messageaction-handlers.html) - [Connections in Cliq](https://www.zoho.com/cliq/help/platform/connections.html), [Deluge connections](https://www.zoho.com/deluge/help/connections.html) - [Invoke URL in Cliq](https://www.zoho.com/cliq/help/platform/invoke-url.html), [Deluge invokeURL](https://www.zoho.com/deluge/help/webhook/invokeurl-api-task.html) - [Cliq responses](https://www.zoho.com/cliq/help/platform/cliq-responses.html) (cards, buttons, forms, banners) - [REST API v2](https://www.zoho.com/cliq/help/restapi/v2/), [Messages v3](https://www.zoho.com/cliq/help/restapi/v3/messages/) - [curl](/tools/curl/) and [jq](/tools/jq/) for testing webhooks