Last active
July 23, 2019 20:33
-
-
Save augustohp/79edf957ec8c49a9e0d1b011fba5d5ad to your computer and use it in GitHub Desktop.
Sends a message to a room using webhook on Hangouts Chat
This file contains hidden or 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
#!/usr/bin/env sh | |
# | |
# Envia uma mensagem pro canal de Tecnologia no Hangouts Chat. | |
set -e | |
if [ ! -z "$DEBUG" ] | |
then | |
set -x | |
fi | |
APP_NAME=$(basename "$0") | |
CHAT_MESSAGE=${1:-""} | |
WEBHOOK_URL=${2:-""} | |
send_message() | |
{ | |
message="${1}" | |
chat_url="${2}" | |
curl -X POST \ | |
-H "Content-Type: application/json; charset=UTF-8" \ | |
-d "{\"text\": \"${message}\"}" \ | |
"${chat_url}" | |
return $? | |
} | |
display_help() | |
{ | |
cat <<-EOT | |
Usage: $APP_NAME <message> [webhook url] | |
EOT | |
} | |
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "help" ] | |
then | |
display_help | |
exit 0 | |
fi | |
if [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "version" ] | |
then | |
echo "$APP_NAME 1.0.0" | |
exit 0 | |
fi | |
if [ -z "$CHAT_MESSAGE" ] | |
then | |
echo "Error: A message is required to be sent. Use '$APP_NAME --help' for more information." 2>&1 | |
exit 2 | |
fi | |
send_message "$CHAT_MESSAGE" "$WEBHOOK_URL" | |
# vim: ft=sh sw=4 ts=4 ai noet: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment