Azure Functions is an event driven, compute-on-demand experience that extends the existing Azure application platform with capabilities to implement code triggered by events occurring in virtually any Azure or 3rd party service as well as on-premises systems. Azure Functions allows developers to take action by connecting to data sources or messaging solutions, thus making it easy to process and react to events. Azure Functions scale based on demand and you pay only for the resources you consume.
Slack is a messaging app for teams
OpenWeather is a platform that collects, processes, and distributes information about our planet through easy to use tools and APIs.
I’ve just ended up my experiments with Azure functions and now I want to share my experience with you.
I’ve started working with Slack and I saw that it supports a pretty API which allows us to easily create chat bots or apps or any integrations that we want. I’ve started with Slack bot API and created a bot which was just calling the OpenWeather API to take information about local temperature, but then I’ve decided to create something more comfortable for users.
The idea is that someone in chat could type in a command like /temperature with only one input parameter [city], then the service will get information from OpenWeather and output the current temperature to chat. To implement this idea we could use Slack Slash Command feature.
To do that follow the link . If you’ve already registered at Slack you’ll see the following page:
Then if you add your new slash command (for me it’s /temperature), you’ll see a configuration page:
Here you see that we need an URL of the service that will be generating our slash command messages. For that need we use Azure Functions service, let’s switch to Azure page. You have to add a new resource from Azure Market that is named Function App:
If you’re not familiar with how Azure works you could check tutorials from Azure Website.
When you end up configuring the Function App and it will be deployed to Azure you should open an Function App resource page. Then you’ll see the greetings page which provides some help for new users:
Let’s click on New Function and choose HttpTrigger (I’ve chosen Node.js version):
This code exports a function that will be used by slack slash command, up to that you could see the link that should be inserted to the slack command configuration page.
The last thing that we should get is an OpenWeatherMap account. After registration you will receive an API key that we will use to send requests to OpenWeather.
At last you’ll need to insert the following code to Azure Functions code editor, just change the OPENWEATHER_APP_ID variable:
If you’ve done everything right, you could try typing /temperature YourCity from Slack chat:
Azure Factory is a very powerful tool for building lightweight services. Also Slack team made awesome work to create so simple to use api and integrations.
Hope you’ve enjoyed this article or mini-tutorial. Thanks for reading!
Links and References
1 Azure Functions — https://azure.microsoft.com/en-us/services/functions/
2 Slack Official Website — https://slack.com/
3 OpenWeatherMap About — http://openweathermap.org/owm-platform
4 Slack Slash Commands — https://api.slack.com/slash-commands
5 My Slack Slash Commands — https://my.slack.com/services/new/slash-commands
6 Azure Website — https://azure.microsoft.com/en-us/
7 OpenWeatherMap Website — http://openweathermap.org/