From c21b46c73df2db7626c30c025c184cc5a7967b19 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 31 Jan 2022 12:41:19 -0800 Subject: [PATCH] Create gchat.sh --- notify/gchat.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 notify/gchat.sh diff --git a/notify/gchat.sh b/notify/gchat.sh new file mode 100644 index 00000000..39d9123e --- /dev/null +++ b/notify/gchat.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +# Support Schmoogle Gchat webhooks +# start with exporting your Spaces webhook with - export GCHAT_WEBHOOK_URL="https://chat.googleapis.com/v1/spaces/xxxxxxxxxxxx" +# add the hook with - acme.sh --set-notify --notify-hook gchat + +gchat_send() { + _subject="$1" + _content="$2" + _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped + _debug "_statusCode" "$_statusCode" + + GCHAT_WEBHOOK_URL="${GCHAT_WEBHOOK_URL:-$(_readaccountconf_mutable GCHAT_WEBHOOK_URL)}" + if [ -z "$GCHAT_WEBHOOK_URL" ]; then + GCHAT_WEBHOOK_URL="" + _err "You didn't specify a Gchat webhook url. export GCHAT_WEBHOOK_URL=\"https://chat.googleapis.com/v1/spaces/xxxxxxx\"" + return 1 + fi + _saveaccountconf_mutable GCHAT_WEBHOOK_URL "$GCHAT_WEBHOOK_URL" + + export _H1="Content-Type: application/json" + + _content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)" + _data="{\"text\": \"$_content\"}" + + if _post "$_data" "$GCHAT_WEBHOOK_URL"; then + if [ "$?" = "0" ]; then + _info "gchat send success." + return 0 + fi + fi + _err "gchat send error." + _err "$response" + return 1 +}