Send Slack messages from anywhere using Webhook Integration
I started working at a new company called Mercury FX International. We specialize in foreign exchange and I help maintain and innovate the software that we use. This can range from menial tasks such as fixing minor bugs to major projects like integrations into financial systems and working with new cryptocurrencies.
While working on a tool that fed information into our system, I needed a way to notify our team if the process ever failed. At first we sent an email out but I stumbled upon the Slack API and was hooked. I ended up configuring a Slack bot which would send messages to a dedicated channel if the process ever failed. That way it would not interfere with other communication and we would easily be able to see new notifications because it had its own channel.
This integration was so easy I wanted to write a short article on how to achieve it. I will show you how to setup the Slack bot and then demonstrate using the API in Postman to send a simple message.
Setting up a Slack bot
- Navigate to https://api.slack.com/apps. You will need to be authenticated.
- Click on Create New App on the following screen:
- Input a name for your new bot and select the workspace that the bot should send messages in (note that this cannot be changed. If you're worried about spamming your colleagues with test messages fret not - you can send test messages to yourself).
- Click Create App when you're done.
- Open the newly created bot and select Incoming Webhooks on the left menu.
- Turn Incoming Webhooks to On
- Scroll to the bottom of the page and click on Add New Webhook to Workspace
- Here you will add the Slack bot to a particular channel in the workspace (for testing purposes I added the bot to my own channel so as to not disrupt anyone else).
- Click Allow to add the bot to the channel.
Using our new Slack bot
Now that we have created a Slack bot and granted them access to a particular channel in our Slack workspace, we can use a very simple REST API to send messages from the bot.
In this example, I will simple use Postman to make the requests. These REST requests can be made in almost any programming language though.
- Open Postman and create a new
POSTrequest using the specified Webhook URL
- Send the following raw body text as type
- Click Send and you should receive an HTTP code 200 in Postman. If you open Slack and you should see your new message:
That's all there is to it. Slack has made their API so simple that it can be integrated into almost any existing system. This is a great way to modernize software that you might be maintaining where notifications are required. Just don't get too excited and spam your users with status updates.
Like what you read?
If you liked what you just read and found it useful, please consider buying me a coffee as a token of your support. It brings a warm fuzzy feeling inside!Buy me a coffee