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                   

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Convert a message on Cliq into a task on Zoho Connect

                                                Message actions in Cliq are a great way to transform messages in a conversation into actionable work items. In this post, we'll see how to build a custom message action that'll let you add a message as a task to board on Zoho Connect. If you haven't created
                                              • Cliq Bots - Post message to a bot using the command line!

                                                If you had read our post on how to post a message to a channel in a simple one-line command, then this sure is a piece of cake for you guys! For those of you, who are reading this for the first time, don't worry! Just read on. This post is all about how
                                              • Cliq Bots - How to make a bot respond to your messages?

                                                Bots are just like your buddies with whom you can interact. They carry out your tasks, keep you notified about your to-dos and come in handy when you need constant updates from a third party application.  So, how can you make your bot respond to a message? The bot message handler is a piece of code triggered when a message is sent to the bot. Message handlers help you customise your bot responses to make it look conversational. The message input from the user can be either a string or an option selected
                                              • Cliq Bots - Get notifications about any action on an application with the incoming webhook handler!

                                                Webhooks can be used to get notified about events happening in other applications inside Cliq. All bots in Cliq have their own incoming webhook endpoint. This makes it simple to post messages to the bot from external applications. Unlike the send message
                                              • The Slash Command Series - Types of Command Suggestions

                                                Hi Everybody! I hope you guys tried the /zdocs command and now have an idea of how command suggestions with click to execute work. If you have no clue of what command suggestion is, I recommend you to take a look at all the Slash Command Series posts, especially the one on Command Suggestions ! This post is all about the different types of command suggestions.  Customise your command suggestions  Did you know you could customise your command suggestion list with a title, description, image? Well,


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now