How to Send Messages to Slack Using Incoming Webhooks

How to Send Messages to Slack Using Incoming Webhooks

In September of this year we introduced Webhooks to Marble. They are an amazing way to send alerts to your Slack channel. Many tools, such as, Polar or Marble, allow you to use and set up these webhooks to receive messages when an event inside their app fires.

Today you will learn how you can configure a Slack webhook and make sure you receive notifications in your Slack channel!

Creating a Slack App

In order for us to receive webhook events, we first need to create a Slack app.

To get started, head over to the Slack API Dashboard. On this dashboard, make your way to the top right and hit the Create New App button.

This should bring up a little modal where you get the option to create an app from scratch; this is the option we need to select for our webhook app.

After selecting the configuration for our app, we are asked to provide a name and workspace for our app. The workspace should be the one we plan on sending webhook events to, as we do not intend to publish our app.

And that's it; we are now the proud owner of a Slack app. Pretty easy, right?

Creating a Slack Webhook

Since we've got our Slack app now, we can move on to creating a webhook. For that we simply need to head over to the Features menu on the side and select Incoming Webhooks.

In here we now need to activate incoming webhooks; we can do so by flipping the toggle button in the top right corner as such:

Scrolling down now reveals a button to create a new webhook.

This button redirects us to an authorization screen. Here we need to point the webhook to a channel in our Slack workspace. Optionally, we can also send Slack webhooks to direct messages of a member.

After we picked a channel for our webhook to deliver messages and events to, we need to click Allow and authorize our app.

After authorizing, you should be greeted with a green "Success!" message at the top of the page. And that's it; we have now created our very own incoming webhook for our Slack workspace.

How to Get Slack Webhook URL

And last but not least, we need to obtain our webhook URL that services like Polar can send messages and events to. For that, simply scroll down to where we previously were and hit the copy button next to the webhook we just created!

Perfect! We can now use this URL to receive incoming webhooks directly in our Slack channel. However, please make sure you keep this URL safe and secure, as it can be used to spam your channel and flood it with unwanted messages.

Sending Messages to Slack

To send messages to Slack, we can simply send a POST request to said URL. Here is what an example cURL request would look like:

curl --location 'https://hooks.slack.com/services/R01M2ZPPPNX/F23HRDCPL9Q/d9k3J8sGw7L0CnzqwYrtOvoM' \
--header 'Content-Type: application/json' \
--data '{
    "text": "Hello, Slack!"
}'

Please make sure to set the headers correctly, similar to the example above! Slack also provides us with a helpful guide on how to make your webhooks look incredible!

If you are now looking to integrate a Slack webhook somewhere, look no further than Marble. Marble is a headless CMS that sends webhook events whenever your content changes. We provide a native way to send webhooks to Slack as long as you have a webhook URL.