Command Execution Handler

Implementing the Command Execution Handler

What are execution handlers?

When a user triggers a command, a deluge function mapped to the command gets executed and renders a response. Upon triggering a command, certain attributes are passed to the deluge code. They are listed below:

Attribute NameDescription
argumentsWhole string present after the command name.
chatChat details in which the command is executed. 
userDetails of the user executing the command.
optionsOptions Map helps in reforming the command output according to the user requirement
mentionsDetails of the user/channel/bot mentioned.
attachmentsArray of deluge file objects.
selectionsSelections made by the user from the suggestions provided.
locationDetails of the current location of the user.

Rendering a response:

The return value on executing a command can either be visible to the command executor only or can be posted as a response message to the chat with the help of the deluge task, zoho.cliq.postToChat


The /traffic command can get the traffic details when mention the from and to locations! Take a look at the sample syntax given below and refer the screenshots to see the command's response.

from = options.get("from");
to = options.get("to");
fromLoc = "";
toLoc = "";
mapUrl = "" + encodeurl(from) + "/" + encodeurl(to) + "/";
resp = getUrl("" + encodeurl(from) + "&destinations=" + encodeurl(to) + "&departure_time=now&key=");
info resp;
status = resp.toMap().get("status");
if(status == "OK")
    if(fromLoc == "")
        fromLoc = resp.toMap().get("origin_addresses").get(0);
        fromLoc = fromLoc.replaceall("\"","");
        cnt = fromLoc.getOccurenceCount(",");
        if(cnt >= 1)
            city = fromLoc.substring(0,fromLoc.indexof(","));
            fromLoc = city;
    if(toLoc == "")
        toLoc = resp.toMap().get("destination_addresses").get(0);
        toLoc = toLoc.replaceall("\"","");
        cnt = toLoc.getOccurenceCount(",");
        if(cnt >= 1)
            city = toLoc.substring(0,toLoc.indexof(","));
            toLoc = city;
    elem = resp.toMap().get("rows").get(0).get("elements").get(0).toMap();
    message = Map();
    if(elem.get("status") == "OK")
        duration = elem.get("duration").toMap().get("text");
        distance = elem.get("distance").toMap().get("text");
        card = Map();
        card.put("title",fromLoc + " <-> " + toLoc);
        message.put("text",distance + " \n(Actual, " + duration + ")\n[more..](" + mapUrl + ")");
        message.put("text","Couldn't locate.. Try [here](" + mapUrl + ")");
    return message;
    message = Map();
    message.put("text","Sorry, traffic is currently unavailable");
    return message;

Slash Command Syntax

Slash Command Response on Execution

Related Articles:

Introduction to command creation and execution in Cliq

Learn how to create and execute a simple /weather command

Slash Command Series: Build a command to create polls!

This article gives an overview of command parameters, how to use them and how you can build a /poll command to conduct polls in Cliq 

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: