Introduction to Slash Commands in Cliq

Introduction to Slash Commands in Cliq

In Steve Jobs' words,

The most precious resource we all have is time.


And rightly so, aren't we all looking for quick ways to perform our tasks? Automating even the most trivial actions, can save us some time and make us more productive. If you are looking for an interface to quickly carry out your actions, then Slash Command is the answer. So today, lets learn about slash commands and also try programming a simple command. 

Now that I've kindled your curiosity, let me give a brief overview about slash commands. Slash commands is an interface, with a fixed syntax and can be triggered to complete your task or perform an action right inside the chat window. If using a slash command is easy, creating one is way more easier and interesting. More about creating and managing slash commands are explained in our help page. Additionally, watch this video on how to create and execute a slash command!



Let us try building a command /weather that can fetch you the weather information of a location. The use case we are looking at here, is to get the weather details for the day or to fetch the weather forecast details for the upcoming five days. 
  
The next step would be to get necessary APIs. The APIs used are from https://developer.accuweather.com/apis. Once you source out the necessary APIs, create the command by giving the name, description, hint followed by command parameters. 

The command parameters (options) we require here are :
- city : To get the location from the user. ( Drop a hint to the user to mention the place name! ) 
 
The command execution flow is given in the flowchart below:


Breaking down the command execution flow in 2 simple steps: 
 
1. Each location is assigned with a location key. To get the weather details for a location, the first step would be to get this location key for the place mentioned in the command input parameter. 
 
2. This location key is then used in either the current conditions URL or the weather forecast conditions URL. This again depends on the command input. 
 
Take a look at the /weather command execution code: 
 
  1. //Define new empty Map expressions, Message and Card - to post message on command execution. 

  2. message = Map(); 
  3. card = Map(); 
  4. card.put("theme","modern-inline"); 
  5. card.put("title","Weather Information"); 

  6. //Store the user entries (options) in the a variable 

  7. place = options.get("city"); 
  8. locationURL = "http://dataservice.accuweather.com/locations/v1/cities/search?apikey=API_KEY&q=" + encodeurl(place) + ""; 
  9. response = getURL(locationURL); 

  10. // Convert the string response to a map to get the "Location Key" from the response. Store the location key in a variable. 
  11. locationkey = response.toMap().get("Key"); 

  12. // Any string passed while executing a command will be stored in"arguments" 

  13. if(arguments.containsIgnoreCase("forecast")) 
  14. //API to get weather forecast for the specified location 
  15. ForecastURL = "http://dataservice.accuweather.com/forecasts/v1/daily/5day/" + encodeurl(locationkey) + "?apikey=API_KEY"; 
  16. forecastdata = getURL(ForecastURL); 

  17. // Convert the response to a map. 
  18. DailyForecasts = forecastdata.toMap().get("DailyForecasts"); 

  19. // 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! 
  20. slides = List(); 
  21. slidedata = Map(); 
  22. slidedata.put("type","table"); 
  23. rows = List(); 
  24. for each DailyForecast in DailyForecasts 
  25. clock = DailyForecast.get("Date"); 
  26. Time = clock.getDay()+"/"+clock.getMonth(); 
  27. Temp = DailyForecast.get("Temperature").toMap().get("Minimum").toMap().get("Value"); 
  28. Celsius = ((Temp - 32) * 0.5556).round(1) + "°C"; 
  29. row = Map(); 
  30. row.put("Date", Time); 
  31. row.put("Temperature",Celsius); 
  32. rows.add(row); 
  33. }
  34. data = Map(); 
  35. headers = List(); 
  36. headers.add("Date"); 
  37. headers.add("Temperature"); 
  38. data.put("headers",headers); 
  39. data.put("rows",rows); 
  40. slidedata.put("data",data); 
  41. slides.add(slidedata); 
  42. message.put("slides",slides); 
  43. message.put("text","Weather forecast for the next 5 days in "+place ); 

  44. }
  45. else 
  46. CurrentWeatherURL = "http://dataservice.accuweather.com/currentconditions/v1/" + encodeurl(locationkey) + "?apikey=API_KEY"; 

  47. // API to get current weather conditions for the specified location 
  48. current_weather_data = getURL(CurrentWeatherURL); 

  49. // Convert the string response to a map. 
  50. WeatherInfo = current_weather_data.toMap(); 

  51. // From the response obtained, get the information you would like to show in your command response. 
  52. climateinfo = WeatherInfo.get("WeatherText"); 
  53. climate = WeatherInfo.get("Temperature"); 
  54. Metrics = climate.get("Metric"); 
  55. Celcius = Metrics.get("Value"); 
  56. Unit = Metrics.get("Unit"); 

  57. // The required information from the response will be posted as a message 
  58. message.put("text","The weather in " + place + " is " + climateinfo + " with a temparature of " + Celcius + "°" + Unit + ""); 

  59. //Post the message to a chat with the help of the deluge task : zoho.cliq.postToChat (); 
  60. aa = zoho.cliq.postToChat(chat.get("id"),message); 
  61. message.put ("card",card); 
  62. return message; 

And that's how you can use a simple slash command to fetch weather details, right inside your chat window! Let us know how this post helped you. Feel free to post your queries , suggestions here!

Cheers,
Manasa 
Cliq                   

    • Sticky Posts

    • Customer payment alerts in Zoho Cliq

      For businesses that depend on cash flow, payment updates are essential for operational decision-making and go beyond simple accounting entries. The sales team needs to be notified when invoices are cleared so that upcoming orders can be released. In contrast,
    • Automating Employee Birthday Notifications in Zoho Cliq

      Have you ever missed a birthday and felt like the office Grinch? Fear not, the Cliq Developer Platform has got your back! With Zoho Cliq's Schedulers, you can be the office party-cipant who never forgets a single cake, balloon, or awkward rendition of
    • Accelerate Github code reviews with Zoho Cliq Platform's link handlers

      Code reviews are critical, and they can get buried in conversations or lost when using multiple tools. With the Cliq Platform's link handlers, let's transform shared Github pull request links into interactive, real-time code reviews on channels. Share
    • App Spotlight : PagerDuty for Zoho Cliq

      App Spotlight brings you hand-picked apps to enhance the power of your Zoho apps and tools. Visit the Zoho Marketplace to explore all of our apps, integrations, and extensions. In today's fast-paced world, seizing every moment is essential for operational
    • Automate your status with Cliq Schedulers

      Imagine enjoying your favorite homemade meal during a peaceful lunch break, when suddenly there's a PING! A notification pops up and ruins your moment of zen. Even worse, you might be in a vital product development sprint, only to be derailed by a "quick