Slack

Slack Webhooks: A Deep Dive

Explore the world of Slack webhooks, uncovering their role in real-time data exchange, distinction from APIs, purpose in cutting-edge notification systems, and a step-by-step guide on how to utilize them.
Slack webhooks

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:

  1. What is a Slack webhook?
  2. Is a webhook an API?
  3. What is the purpose of a webhook?
  4. How do I get a webhook?
  5. What is a webhook example?
  6. How do I use Slack webhooks?
  7. What format will I receive Slack webhooks?
  8. How we use Slack webhooks to create Mio

What is a Slack webhook?

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.

Is a webhook an API?

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.  

What is the purpose of a webhook?

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. 

How do I get a webhook?

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.

What is a Webhook 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.

How do I use Slack webhooks?

Step 1: Navigate to https://api.slack.com/apps and click “Create an App”.

Create a Slack 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.

Event subscriptions

Step 3: Subscribe to the app_home_opened event.

Bot events

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.

Slack webhooks

How do I receive Slack webhooks?

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.

What format will I receive Slack webhooks?

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.

Slack webhook format

How we use the Slack webhook to create Mio

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:

  • Basic messages
  • Threaded messages
  • File uploads
  • Editing messages
  • Deleting messages
  • Emojis
  • GIFs

Learn more about what we do and how we can help unlock your business communication here.

Posted in:
Related stories
Google Chat
How to Connect Google Chat and Slack in 2024
Industry News
Mio enables cross-platform collaboration through partnership with Google Workspace and SADA
Slack
How To Set Custom Status Messages In Slack For Enhanced Team Collaboration

Get the latest news from Mio in your inbox.

Join over 4,000 people who get collaboration tips once a month.