Skip to content

Instantly share code, notes, and snippets.

@nagataka
Created March 4, 2020 19:28
Show Gist options
  • Save nagataka/8062d9a0ce0e1fdaaa0176ac902140bc to your computer and use it in GitHub Desktop.
Save nagataka/8062d9a0ce0e1fdaaa0176ac902140bc to your computer and use it in GitHub Desktop.
Send a slack notification
#!/bin/bash
set -eu
### Incoming WebHooks URL
WEBHOOKURL="https://hooks.slack.com/services/FILL_YOUR_WEBHOOKURL"
### channel
CHANNEL=${CHANNEL:-"#notifications"}
### sender name
BOTNAME=${BOTNAME:-"notifyme-bot"}
# BOTNAME=${BOTNAME:-"${HOSTNAME}"}
### slack icon
FACEICON=${FACEICON:-":ghost:"}
### user_id
USERID="Uxxxxxxxx" # User your user_id (not user name)
#################### Config payload ####################
PAYLOAD=`cat << EOS
payload={
"channel": "${CHANNEL}",
"username": "${BOTNAME}",
"text": "Hey <@${USERID}> your code just finished running",
"icon_emoji": "${FACEICON}"
}
EOS`
# Send the payload
curl -X POST --data-urlencode "$PAYLOAD" "${WEBHOOKURL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment