Command Code Samples
We bring to you a list of use cases where using commands has deemed useful! We're building on our repository of sample code snippets to help you get started with Cliq Platform and Deluge.
/weather - Gets the current weather and weather forecast information
The use case shown here is to get the weather information for the day or get the forecast information for the upcoming five days.
What can you learn while creating this command?
- Command Parameters
- Using the 'arguments' parameter to get the string passed with a command.
- Post message on a card
Sample Command Syntax
To get the current weather details for a location: /weather -city Pleasanton
To get the weather forecast details for a location: /weather -city Pleasanton forecast
//Define new empty Map expressions, Message and Card - to post message on command execution. message = Map(); card = Map(); card.put("theme","modern-inline"); card.put("title","Weather Information"); //Store the user entries (options) in the a variable place = options.get("city"); locationURL = "http://dataservice.accuweather.com/locations/v1/cities/search?apikey=API_KEY&q=" + encodeurl(place) + ""; response = getURL(locationURL); // Convert the string response to a map to get the "Location Key" from the response. Store the location key in a variable. locationkey = response.toMap().get("Key"); // Any string passed while executing a command will be stored in"arguments" if(arguments.containsIgnoreCase("forecast")) { //API to get weather forecast for the specified location ForecastURL = "http://dataservice.accuweather.com/forecasts/v1/daily/5day/" + encodeurl(locationkey) + "?apikey=API_KEY"; forecastdata = getURL(ForecastURL); // Convert the response to a map. DailyForecasts = forecastdata.toMap().get("DailyForecasts"); // From the response obtained, get the information you would like to show in your command response. And organize it in a table and post as a message card! slides = List(); slidedata = Map(); slidedata.put("type","table"); rows = List(); for each DailyForecast in DailyForecasts { clock = DailyForecast.get("Date"); Time = clock.getDay()+"/"+clock.getMonth(); Temp = DailyForecast.get("Temperature").toMap().get("Minimum").toMap().get("Value"); Celsius = ((Temp - 32) * 0.5556).round(1) + "°C"; row = Map(); row.put("Date", Time); row.put("Temperature",Celsius); rows.add(row); } data = Map(); headers = List(); headers.add("Date"); headers.add("Temperature"); data.put("headers",headers); data.put("rows",rows); slidedata.put("data",data); slides.add(slidedata); message.put("slides",slides); message.put("text","Weather forecast for the next 5 days in "+place ); } else { CurrentWeatherURL = "http://dataservice.accuweather.com/currentconditions/v1/" + encodeurl(locationkey) + "?apikey=API_KEY"; // API to get current weather conditions for the specified location current_weather_data = getURL(CurrentWeatherURL); // Convert the string response to a map. WeatherInfo = current_weather_data.toMap(); // From the response obtained, get the information you would like to show in your command response. climateinfo = WeatherInfo.get("WeatherText"); climate = WeatherInfo.get("Temperature"); Metrics = climate.get("Metric"); Celcius = Metrics.get("Value"); Unit = Metrics.get("Unit"); // The required information from the response will be posted as a message message.put("text","The weather in " + place + " is " + climateinfo + " with a temparature of " + Celcius + "°" + Unit + ""); } //Post the message to a chat with the help of the deluge task : zoho.cliq.postToChat (); aa = zoho.cliq.postToChat(chat.get("id"),message); message.put ("card",card); return message;
/zohodocs - Search and share files from your Zoho Docs right from the chat window
Search for files in your Zoho Docs account by just typing /zohodocs. The default search will show a result of the recently used files. To search for any particular file, just typing the file name will show a list of suggestions for the file name.
What can you learn while creating this command?
- Command Suggestions
- Click to Execute Option
Sample Command Syntax :
/zohodocs (This will show a list of suggestions ) Select a file from the suggestion list shown and execute!
OR
/zohodocs Zylker (This will show the list of files with containing Zylker) Select a file and execute!