XylotrechusZ

XylotrechusZ Shell

: /home/matican/.acme.sh/notify/ [ drwxrwxr-x ]
Uname: Linux premium72.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software: LiteSpeed
PHP version: 8.2.29 [ PHP INFO ] PHP os: Linux
Server Ip: 198.54.125.95
Your Ip: 216.73.216.35
User: matican (532) | Group: matican (531)
Safe Mode: OFF
Disable Function:
NONE

name : teams.sh
#!/bin/bash

#Support Microsoft Teams webhooks

#TEAMS_WEBHOOK_URL=""

teams_send() {
  _subject="$1"
  _content="$2"
  _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  _debug "_statusCode" "$_statusCode"

  _color_success="Good"
  _color_danger="Attention"
  _color_muted="Accent"

  TEAMS_WEBHOOK_URL="${TEAMS_WEBHOOK_URL:-$(_readaccountconf_mutable TEAMS_WEBHOOK_URL)}"
  if [ -z "$TEAMS_WEBHOOK_URL" ]; then
    TEAMS_WEBHOOK_URL=""
    _err "You didn't specify a Microsoft Teams webhook url TEAMS_WEBHOOK_URL yet."
    return 1
  fi
  _saveaccountconf_mutable TEAMS_WEBHOOK_URL "$TEAMS_WEBHOOK_URL"

  export _H1="Content-Type: application/json"

  _subject=$(echo "$_subject" | _json_encode)
  _content=$(echo "$_content" | _json_encode)

  case "$_statusCode" in
  0)
    _color="${TEAMS_SUCCESS_COLOR:-$_color_success}"
    ;;
  1)
    _color="${TEAMS_ERROR_COLOR:-$_color_danger}"
    ;;
  2)
    _color="${TEAMS_SKIP_COLOR:-$_color_muted}"
    ;;
  esac

  _data="{
    \"type\": \"message\",
    \"attachments\": [
        {
            \"contentType\": \"application/vnd.microsoft.card.adaptive\",
            \"contentUrl\": null,
            \"content\": {
                \"schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",
                \"type\": \"AdaptiveCard\",
                \"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 ! _contains "$response" error; then
      _info "teams send success."
      return 0
    fi
  fi
  _err "teams send error."
  _err "$response"
  return 1
}
© 2025 XylotrechusZ