Sending messages to Slack using Incoming Webhook

Sending messages to Slack using Incoming Webhook

If your looking for easy and quick way to send messages to slack channels programmatically then you're at the right place, in this post I will walk you through how you can achieve just that using incoming webhooks, so let's get started.

  • First step before we do anything will be to create a new slack account if you don't have one.
  • Next you'll need to create a workspace , which is basically where people can work together.
  • Next step is to create a channel where you can send the messages to.

Once these things are done we can move to our main task i.e incoming webhooks.

search.PNG Go to slack app directory and search for incoming webhooks.

addtoslack.PNG You'll get an page like this, there click on add to slack


Select the channel where you want Incoming webhook to post messages to for me its test_channel and then click on add button, this will provide us with the webhook url which we can use to send messages to slack it will look to something like this :

Now you can use this webhook to send custom messages to slack here's an example using curl

curl -X POST --data-urlencode "payload={\"channel\": \"#test_channel\", \"username\": \"webhookbot\", \"text\": \"This is posted to #test_channel and comes from a bot named ghostfreak.\", \"icon_emoji\": \":ghost:\"}"

Replace the the above webhook with your own and your good to go.

message.PNG This will send the message to your slack channel like this. Word of caution remember to keep your webhook a secret as anyone with your webhook url will be able to send messages to your channel.

Further more we can also format the message as required more on that here. So using this approach we can send customized message to slack using our favorite http client and achieve cool things.

Until then........

Be Curious