Create and execute Slash commands
Slash commands can be used for various operations such as fetching the traffic updates, weather updates, creating notes, adding tasks, updating tasks and much more.
In this page, you can find the step by step guide to create a slash command to fetch the weather report of a particular location for the next 7 days. This will provide you with an overview of the command creation, operation addition and command execution process.
Create a command
To create a command to fetch the weather forecast:
- Follow steps provided here to create a new command.
- In the Trusted Domains field, provide the URL using which the command will be executed.
- In this case we're using the URL: https://api.weatherapi.com
Add an operation
Follow the steps provided here to add an operation to fetch the weather report for a specific location:
- Choose Text as the Argument type, and add two Text arguments to get the number of days for which you want the forecast for and the location.
- Provide the name for the arguments as location and days respectively and mark them as mandatory.
- Provide the URL: https://api.weatherapi.com/v1/forecast.json?q=${location}&days=${days} in the URL field of the API information.
- Choose the Method as GET.
- In the Params field, provide the key param and in the value field provide the API key fetched for your account from https://www.weatherapi.com/my/.
Write a custom function to display data
Use the code given below to write a Custom function to display the data fetched in a table format.
// To get the result of the api executed, use the param 'data'.
info data;
response = data.get("response");
if(response.containKey("error"))
{
return {"slides":{{"type":"alert","data":response.get("error").get("message"),"severity":"error"}}};
}
forecastDayList = response.get("forecast").get('forecastday');
tableRows = {};
for each dayForecast in forecastDayList
{
forecastDayObj = dayForecast.get("day");
tableRows.add({"Date":dayForecast.get("date"),"Avg Temp(Deg Celcius)":forecastDayObj.get("avgtemp_c"),"Precipitation(Mm)":forecastDayObj.get("totalprecip_mm"),"Weather Forecast":forecastDayObj.get("condition").get("text")});
}
TableCode = {"slides":{{"type":"table","title":"Weather forecast at " + response.get("location").get("name"),"headers":{'Date','Avg Temp(Deg Celcius)','Precipitation(Mm)','Weather Forecast'},"rows":tableRows}}};
return TableCode;
Save the Custom Function to display the fetched data in the preferred format.
Execute the command
Once you create a command, add an operation and save it, the command will be installed and ready to use from the Mail Assistant.
- Open the Mail Assistant by pressing Command+K (Apple)or Control+K (Windows).
- Invoke the command by typing the Command Name (/<commandname>)
- Invoke the operation (<operation>)
- Provide the number of days and location of the place for which you want to fetch the weather report.
- The report will be fetched and shown in the table format.
Once you obtain the data in the preferred format you can use the Insert to compose option to populate the data in the email composer and send the email.