Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active April 18, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/5adaab3712fe6cd37ace21ab3e9e0c72 to your computer and use it in GitHub Desktop.
Save ruanbekker/5adaab3712fe6cd37ace21ab3e9e0c72 to your computer and use it in GitHub Desktop.
Create a Webhook in Slack

Slack Webhooks

Configuration for Slack Webhooks

Configuration

Head over to:

  • https://{your-team}.slack.com/apps/manage/custom-integrations

Select Incoming Webhooks:

Select Add Configuration:

Select the channel it should post to:

Select Add Incoming Webhook Integration.

Save the webhook url that will look like this:

https://hooks.slack.com/services/ABCDEFGHI/ZXCVBNMAS/AbCdEfGhJiKlOpRQwErTyUiO

You can then further configure the integration.

Sending Messages

curl -XPOST -d 'payload={"channel": "#system_events", "username": "My-WebhookBot", "text": "This is posted to #general and comes from a bot named <https://alert-system.com/alerts/1234|webhookbot> for details!", "icon_emoji": ":borat:"}' https://hooks.slack.com/services/xx/xx/xx

Will result in:

image

Message Attachment, Error:

curl -XPOST -d 'payload={"channel": "#system_events", "username": "My-WebhookBot", "text": "*Incoming Alert!*", "icon_emoji": ":borat:", "attachments":[{"fallback":"New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>","pretext":"New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>","color":"#D00000","fields":[{"title":"Notes","value":"This is much easier than I thought it would be.","short":false}]}]}}' https://hooks.slack.com/services/xx/xx/xx

Results in:

image

Message Attachment, OK:

curl -XPOST -d 'payload={"channel": "#system_events", "username": "My-WebhookBot", "text": "*Status Update:*", "icon_emoji": ":borat:", "attachments":[{"fallback":"New open task has been closed [OK]: <http://url_to_task|Test out Slack message attachments>","pretext":"Task has been closed [OK]: <http://url_to_task|Test out Slack message attachments>","color":"#28B463","fields":[{"title":"Notes","value":"The error has been resolved and the status is OK","short":false}]}]}}' https://hooks.slack.com/services/xx/xx/xx

Results in:

image

Resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment