Skip to content

Instantly share code, notes, and snippets.

@ptzn
Created January 19, 2016 07:50
Show Gist options
  • Save ptzn/4d55a4d6196f93e2fb2e to your computer and use it in GitHub Desktop.
Save ptzn/4d55a4d6196f93e2fb2e to your computer and use it in GitHub Desktop.
# usage:
# say hello; notify #=> "Done" message will be sent on success and "Ooops" on error
# say hello; notify "in far far away galaxy" #=> "in far far away galaxy" message will be sent on success and "Ooops" on error
notify() {
local exit_code=$?
local api_key="PUT_API_KEY"
local chat_id="PUT_CHAT_ID_HERE"
local success
local error="Ooops"
if [[ -z $1 ]]; then
success="Done"
else
success=$1
fi
if [[ exit_code -eq 0 ]]; then
curl -s -o /dev/null "https://api.telegram.org/bot149630834:${api_key}/sendMessage?chat_id=${chat_id}&text=${success}"
else
curl -s -o /dev/null "https://api.telegram.org/bot149630834:${api_key}/sendMessage?chat_id=${chat_id}&text=${error}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment