Last active
January 8, 2019 21:28
-
-
Save hmoenck/53e695d5dba085c83d556847605fab37 to your computer and use it in GitHub Desktop.
Slackpost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: slackpost <channel> <message> | |
# Setup: | |
# 1. Create an incoming webhook. Link can be found in https://api.slack.com/custom-integrations | |
# 2. Retrieve link like https://hooks.slack.com/services/T0XXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX | |
# 3. Add link to this script (webhook) | |
# 4. Add your slackhost | |
# 5. Profit | |
#This is a slightly adjusted version from: https://gist.github.com/dopiaza/6449505 | |
# Enter the name of your slack host here - the thing that appears in your URL: | |
# eg "fubioroboticslab" | |
slackhost="fubioroboticslab" | |
webhook="https://hooks.slack.com/services/T0XXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" | |
echo $1 | |
channel=$1 | |
if [[ $channel == "" ]] | |
then | |
echo "No channel specified" | |
exit 1 | |
fi | |
shift | |
text=$* | |
if [[ $text == "" ]] | |
then | |
echo "No text specified" | |
exit 1 | |
fi | |
escapedText=$(echo $text | sed 's/"/\"/g' | sed "s/'/\'/g" ) | |
json="{\"channel\": \"#$channel\", \"text\": \"$escapedText\"}" | |
curl -X POST -H 'Content-type: application/json' --data "$json" $webhook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment