-
-
Save gvaughn/0cf577e36685784b8b3920d71058f884 to your computer and use it in GitHub Desktop.
post message to slack
This file contains 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
#!bash -e | |
TOKEN= # slack token is generate from: https://api.slack.com/web | |
CHANNEL= # name of channels or group | |
MESSAGE= # message | |
NICK= # bot name | |
IS_PRIVATE= # 1 or 0 | |
if [ $IS_PRIVATE -eq 1 ]; then | |
API_TYPE=groups | |
else | |
API_TYPE=channels | |
fi | |
# channel info | |
CHANNELS_RESPONSE=$(curl "https://slack.com/api/$API_TYPE.list?token=$TOKEN") | |
CHANNEL_ID=$(echo $CHANNELS_RESPONSE | jq ".${API_TYPE}[]" | jq "if .name == \"$CHANNEL\" then .id else null end" -M -c -r | grep -v null) | |
# post message | |
curl -X POST \ | |
-F token=$TOKEN \ | |
-F channel=$CHANNEL_ID \ | |
-F "text=$MESSAGE" \ | |
-F username=$NICK \ | |
https://slack.com/api/chat.postMessage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment