You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

  1. #!/bin/bash
  2. #Support Rocketchat webhooks
  3. #ROCKETCHAT_WEBHOOK_URL="https://xxxxx/hooks/xxxx"
  4. rocketchat_send() {
  5. _subject="$1"
  6. _content="$2"
  7. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  8. _debug "_statusCode" "$_statusCode"
  9. ROCKETCHAT_WEBHOOK_URL="${ROCKETCHAT_WEBHOOK_URL:-$(_readaccountconf_mutable ROCKETCHAT_WEBHOOK_URL)}"
  10. if [ -z "$ROCKETCHAT_WEBHOOK_URL" ]; then
  11. ROCKETCHAT_WEBHOOK_URL=""
  12. _err "You didn't specify a webhook URL yet."
  13. _err "Please check documentation here : https://docs.rocket.chat/administrator-guides/integrations"
  14. return 1
  15. fi
  16. _saveaccountconf_mutable ROCKETCHAT_WEBHOOK_URL "$ROCKETCHAT_WEBHOOK_URL"
  17. export _H1="Content-Type: application/json"
  18. _content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)"
  19. _data="{\"text\": \"$_content\" }"
  20. response="$(_post "$_data" "$ROCKETCHAT_WEBHOOK_URL")"
  21. if [ "$?" = "0" ] && _contains "$response" "true"; then
  22. _info "rocketchat send success."
  23. return 0
  24. fi
  25. _err "rocketchat send error."
  26. _err "$response"
  27. return 1
  28. }