Skip to content

Instantly share code, notes, and snippets.

@josue
Last active May 15, 2019
Embed
What would you like to do?
Slackme - quick send to slack hook
#!/bin/bash
function slackme {
local MESSAGE=${1}
if [ "${MESSAGE}" == "" ]; then
echo "Missing first param: slackme {message}"
return
fi
if [ "${SLACK_HOOK_URL}" == "" ]; then
echo "Missing env var: SLACK_HOOK_URL"
return
fi
local CHANNEL=${2:-"general"}
local USERNAME=${3:-"slackme"}
local ICON_EMOJI=${4:-":robot_face:"}
local JSON_DATA='{"channel":"#'${CHANNEL}'", "username":"'${USERNAME}'", "icon_emoji":"'${ICON_EMOJI}'", "text": "'${MESSAGE}'"}'
curl -s -XPOST -H 'Content-type: application/json' --data "${JSON_DATA}" "${SLACK_HOOK_URL}" >/dev/null
}
# params
SLACK_URL=${SLACK_HOOK_URL:-"https://hooks.slack.com/services/......"}
# main
slackme "$@"
@josue
Copy link
Author

josue commented Jul 12, 2018

Download:

curl -LO https://gist.githubusercontent.com/josue/3b83a78cd99016dd828cada2de7c4c3a/raw/slackme.sh && chmod +x slackme.sh

Usage:

export SLACK_HOOK_URL="https://hooks.slack.com/services/......"

./slackme.sh "hello world" "some-room"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment