DEV Community

Václav Makeš
Václav Makeš

Posted on

Sending messages using Slack Webhooks

Slack documentation has part about sending messages with webhooks.

It works great, but there is missing information about details. We can send custom message with emoji, username and selected channel.

{
  "text": "My message.",
  "channel": "notifications_channel",
  "username": "My custom robot name",
  "icon_emoji": "rocket"
}
Enter fullscreen mode Exit fullscreen mode

When you send it from script or CI server you can use curl in format:

curl -X POST \
  -H 'Content-type: application/json' \
  --data "{'text':'My message.', 'channel':'notifications_channel', 'username':'My custom robot name', 'icon_emoji':'rocket'}" \
  $SLACK_WEBHOOK_URL
Enter fullscreen mode Exit fullscreen mode

How message in Slack looks? First message is ours, second is from Trello application for comparation.

Custom Slack message send with webhook

Top comments (0)