Skip to content

Instantly share code, notes, and snippets.

@siteshen
Created January 17, 2015 04:54
Show Gist options
  • Save siteshen/be345fb162fb661e7b7d to your computer and use it in GitHub Desktop.
Save siteshen/be345fb162fb661e7b7d to your computer and use it in GitHub Desktop.
Slack client in bash
#!/bin/bash
# https://your-team.slack.com/services/new/incoming-webhook
WEBHOOK_URL=''
CHANNEL='#dev'
USERNAME='sentry'
iCON_URL='https://slack.global.ssl.fastly.net/17635/img/services/sentry_128.png'
function post_message() {
payload="{'username': '$USERNAME', 'text': '$AT_USER $1', 'channel': '$CHANNEL', 'icon_url': '$ICON_URL'}"
json=$(echo $payload | sed -e "s/'/\"/g")
curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' -X POST -d "$json" "$WEBHOOK_URL"
}
if [[ $# -eq 0 ]]; then
echo "usage: $0 message"
exit 1
else
post_message $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment