Generic Slack Notifier

81 words, est. 1 min
#!/bin/bash -e
function sendmessage(){
  echo '{"text":  "'${1}'" }' > /tmp/slack-tmp.txt

  curl -X POST \
  -H 'Content-type: application/json' \
  -d @/tmp/slack-tmp.txt \
  "https:/xx/xx/xx"
}

function sendfile(){
  jq -n --arg msg "$(cat $1 | grep -o ' .\+')" \
     '{"text":  $msg }' > /tmp/slack-tmp.txt

  curl -X POST \
  -H 'Content-type: application/json' \
  -d @/tmp/slack-tmp.txt \
  "https:/xx/xx/xx"
}

if test -f "$1"; then
    sendfile "${1}"
else
    sendmessage "${1}"
fi

A hack job that sends either the content of a file (mangled) or a message.

This post was first published at