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.

47 lines
1.3 KiB

  1. #!/usr/bin/env sh
  2. #Support feishu webhooks api
  3. #required
  4. #FEISHU_WEBHOOK="xxxx"
  5. #optional
  6. #FEISHU_KEYWORD="yyyy"
  7. # subject content statusCode
  8. feishu_send() {
  9. _subject="$1"
  10. _content="$2"
  11. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  12. _debug "_subject" "$_subject"
  13. _debug "_content" "$_content"
  14. _debug "_statusCode" "$_statusCode"
  15. FEISHU_WEBHOOK="${FEISHU_WEBHOOK:-$(_readaccountconf_mutable FEISHU_WEBHOOK)}"
  16. if [ -z "$FEISHU_WEBHOOK" ]; then
  17. FEISHU_WEBHOOK=""
  18. _err "You didn't specify a feishu webhooks FEISHU_WEBHOOK yet."
  19. _err "You can get yours from https://www.feishu.cn"
  20. return 1
  21. fi
  22. _saveaccountconf_mutable FEISHU_WEBHOOK "$FEISHU_WEBHOOK"
  23. FEISHU_KEYWORD="${FEISHU_KEYWORD:-$(_readaccountconf_mutable FEISHU_KEYWORD)}"
  24. if [ "$FEISHU_KEYWORD" ]; then
  25. _saveaccountconf_mutable FEISHU_KEYWORD "$FEISHU_KEYWORD"
  26. fi
  27. _content=$(echo "$_content" | _json_encode)
  28. _subject=$(echo "$_subject" | _json_encode)
  29. _data="{\"msg_type\": \"text\", \"content\": {\"text\": \"[$FEISHU_KEYWORD]\n$_subject\n$_content\"}}"
  30. response="$(_post "$_data" "$FEISHU_WEBHOOK" "" "POST" "application/json")"
  31. if [ "$?" = "0" ] && _contains "$response" "StatusCode\":0"; then
  32. _info "feishu webhooks event fired success."
  33. return 0
  34. fi
  35. _err "feishu webhooks event fired error."
  36. _err "$response"
  37. return 1
  38. }