Skip to content

Instantly share code, notes, and snippets.

@lionel-deglise
Created September 14, 2017 08:36
Show Gist options
  • Save lionel-deglise/b5a41797ab377d6448756fde91675a87 to your computer and use it in GitHub Desktop.
Save lionel-deglise/b5a41797ab377d6448756fde91675a87 to your computer and use it in GitHub Desktop.
Slack notification with cURL
#!/bin/bash
function post_to_slack () {
# format message as a code block ```${msg}```
SLACK_MESSAGE="\`\`\`$1\`\`\`"
SLACK_URL=https://hooks.slack.com/services/your-service-identifier-part-here
case "$2" in
INFO)
SLACK_ICON=':slack:'
;;
WARNING)
SLACK_ICON=':warning:'
;;
ERROR)
SLACK_ICON=':bangbang:'
;;
*)
SLACK_ICON=':slack:'
;;
esac
curl -X POST --data "payload={\"text\": \"${SLACK_ICON} ${SLACK_MESSAGE}\"}" ${SLACK_URL}
}
post_to_slack "Hello, World" "INFO"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment