Update teams notify script to support new notification setup using workflows instead of connectors being fased out.

Color support has been dropped since this has no support inside adaptive-card
This commit is contained in:
Joris van den Dries 2024-07-24 12:05:57 +02:00
parent 5cded5b53e
commit 7aaa9583fa

69
notify/teams.sh Normal file → Executable file
View File

@ -3,10 +3,6 @@
#Support Microsoft Teams webhooks #Support Microsoft Teams webhooks
#TEAMS_WEBHOOK_URL="" #TEAMS_WEBHOOK_URL=""
#TEAMS_THEME_COLOR=""
#TEAMS_SUCCESS_COLOR=""
#TEAMS_ERROR_COLOR=""
#TEAMS_SKIP_COLOR=""
teams_send() { teams_send() {
_subject="$1" _subject="$1"
@ -14,9 +10,9 @@ teams_send() {
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode" _debug "_statusCode" "$_statusCode"
_color_success="2cbe4e" # green _color_success="Good" # green
_color_danger="cb2431" # red _color_danger="Attention" # red
_color_muted="586069" # gray _color_muted="Accent" # gray
TEAMS_WEBHOOK_URL="${TEAMS_WEBHOOK_URL:-$(_readaccountconf_mutable TEAMS_WEBHOOK_URL)}" TEAMS_WEBHOOK_URL="${TEAMS_WEBHOOK_URL:-$(_readaccountconf_mutable TEAMS_WEBHOOK_URL)}"
if [ -z "$TEAMS_WEBHOOK_URL" ]; then if [ -z "$TEAMS_WEBHOOK_URL" ]; then
@ -26,26 +22,6 @@ teams_send() {
fi fi
_saveaccountconf_mutable TEAMS_WEBHOOK_URL "$TEAMS_WEBHOOK_URL" _saveaccountconf_mutable TEAMS_WEBHOOK_URL "$TEAMS_WEBHOOK_URL"
TEAMS_THEME_COLOR="${TEAMS_THEME_COLOR:-$(_readaccountconf_mutable TEAMS_THEME_COLOR)}"
if [ -n "$TEAMS_THEME_COLOR" ]; then
_saveaccountconf_mutable TEAMS_THEME_COLOR "$TEAMS_THEME_COLOR"
fi
TEAMS_SUCCESS_COLOR="${TEAMS_SUCCESS_COLOR:-$(_readaccountconf_mutable TEAMS_SUCCESS_COLOR)}"
if [ -n "$TEAMS_SUCCESS_COLOR" ]; then
_saveaccountconf_mutable TEAMS_SUCCESS_COLOR "$TEAMS_SUCCESS_COLOR"
fi
TEAMS_ERROR_COLOR="${TEAMS_ERROR_COLOR:-$(_readaccountconf_mutable TEAMS_ERROR_COLOR)}"
if [ -n "$TEAMS_ERROR_COLOR" ]; then
_saveaccountconf_mutable TEAMS_ERROR_COLOR "$TEAMS_ERROR_COLOR"
fi
TEAMS_SKIP_COLOR="${TEAMS_SKIP_COLOR:-$(_readaccountconf_mutable TEAMS_SKIP_COLOR)}"
if [ -n "$TEAMS_SKIP_COLOR" ]; then
_saveaccountconf_mutable TEAMS_SKIP_COLOR "$TEAMS_SKIP_COLOR"
fi
export _H1="Content-Type: application/json" export _H1="Content-Type: application/json"
_subject=$(echo "$_subject" | _json_encode) _subject=$(echo "$_subject" | _json_encode)
@ -63,16 +39,35 @@ teams_send() {
;; ;;
esac esac
_color=$(echo "$_color" | tr -cd 'a-fA-F0-9') _data="{
if [ -z "$_color" ]; then \"type\": \"message\",
_color=$(echo "${TEAMS_THEME_COLOR:-$_color_muted}" | tr -cd 'a-fA-F0-9') \"attachments\": [
fi {
\"contentType\": \"application/vnd.microsoft.card.adaptive\",
_data="{\"title\": \"$_subject\"," \"contentUrl\": null,
if [ -n "$_color" ]; then \"content\": {
_data="$_data\"themeColor\": \"$_color\", " \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",
fi \"type\": \"AdaptiveCard\",
_data="$_data\"text\": \"$_content\"}" \"version\": \"1.2\",
\"body\": [
{
\"type\": \"TextBlock\",
\"size\": \"large\",
\"weight\": \"bolder\",
\"wrap\": true,
\"color\": \"$_color\",
\"text\": \"$_subject\"
},
{
\"type\": \"TextBlock\",
\"text\": \"$_content\",
\"wrap\": true
}
]
}
}
]
}"
if response=$(_post "$_data" "$TEAMS_WEBHOOK_URL"); then if response=$(_post "$_data" "$TEAMS_WEBHOOK_URL"); then
if ! _contains "$response" error; then if ! _contains "$response" error; then