Slack webhooks are the tools used to facilitate how Slack apps receive, process, and send information and events in real-time. If you’re new to Slack webhooks, you’ve come to the right place.
In this post, we walk through the ins and outs of Slack webhooks:
Have you ever wondered how Slack apps are able to receive events from Slack seemingly as they happen? The answer is a webhook - or specifically on Slack, their Events API.
A webhook gives external applications (like Mio) the ability to get data pushed to them in real-time instead of having to go ask Slack if there are any relevant updates and then pull in that updated data for their users.
A webhook is a subset of the API family. Creating an API (Application Programmable Interface) is another way of saying that you are creating a way for other programmers to interface with the data in my application.
Traditional APIs follow a request/response pattern. If I want to manipulate data, I need to first send a request to the API endpoint, and then check the response status to make sure the system was able to handle my request without error.
Webhooks, also referred to as subscription or notification based APIs, cut the request/response loop in half.
Instead of initiating a data request from your external system, a subscription model allows programmers to sign up to be sent responses automatically anytime a relevant change is made to relevant data.
Prior to the existence of new data being pushed on-demand, developers had to use a pattern called polling.
A polling algorithm would continuously loop and check for updates using the request/response pattern.
This model took at least twice as long to get the data into your system and was more expensive from a computational resources perspective because the polling had to be running continuously.
In Texas, we have a saying: “it is as easy as pie”.
In order to start receiving webhooks, all you have to do is sign up for subscriptions and they get sent to the URL of your choice!
Below we will take you through the setup steps in our example.
A common use case within the Slack App community is to receive a notification when the home tab of your app is viewed so you can track interest and begin onboarding users.
Let’s take a look at how this can work using Slack’s Events API.
Step 1: Navigate to https://api.slack.com/apps and click “Create an App”.
Step 2: Turn on Event Subscriptions for your app and enter the webhook URL that you want your events posted.
This must be a valid URL that can receive HTTP POST, otherwise the Slack webhook will fail.
In order to verify your URL you must implement the webhook endpoint URL to handle the slack challenge successfully and respond with a 200 status code.
Step 3: Subscribe to the app_home_opened event.
Step 4: Enable a home tab for your app by first visiting the app home page and then scrolling down to the bottom to toggle the home screen to the on position.
Now all you have to do is wait…well, mostly.
You must first have the app installed into your development workspace.
Then you should see your app on the bottom left-hand side of the navigation menu in the “Apps” section.
Click on your app and navigate to the “Home” section of your app then your webhook should receive a post from Slack.
The HTTP POST payload sent by slack will be in JSON format.
Here is an example of what the body of the posted payload should look when it is received at your webhook URL endpoint.
At Mio, our core product utilizes the Events API to listen in Slack channels for messages and relay these to connected spaces on Google Chat.
Open APIs and webhooks have allowed us to translate messages from Slack to Google Chat and vice versa.
This allows you to stay in one messaging tool and chat with your colleagues on other platforms.
Everyone can collaborate together, share files, reply to message threads, and edit messages—all from their tool of choice.
Mio supports the following functionality to enable better collaboration:
Learn more about what we do and how we can help unlock your business communication here.