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.

59 lines
1.6 KiB

  1. #!/usr/bin/env sh
  2. #Support CallMeBot Whatsapp webhooks
  3. #CallMeBot_Phone_No=""
  4. #CallMeBot_apikey=""
  5. #SLACK_USERNAME=""
  6. #SLACK_WEBHOOK_URL=""
  7. #SLACK_CHANNEL=""
  8. #SLACK_USERNAME=""
  9. slack_send() {
  10. _subject="$1"
  11. _content="$2"
  12. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  13. _debug "_statusCode" "$_statusCode"
  14. SLACK_WEBHOOK_URL="${SLACK_WEBHOOK_URL:-$(_readaccountconf_mutable SLACK_WEBHOOK_URL)}"
  15. if [ -z "$SLACK_WEBHOOK_URL" ]; then
  16. SLACK_WEBHOOK_URL=""
  17. _err "You didn't specify a Slack webhook url SLACK_WEBHOOK_URL yet."
  18. return 1
  19. fi
  20. _saveaccountconf_mutable SLACK_WEBHOOK_URL "$SLACK_WEBHOOK_URL"
  21. SLACK_CHANNEL="${SLACK_CHANNEL:-$(_readaccountconf_mutable SLACK_CHANNEL)}"
  22. if [ -n "$SLACK_CHANNEL" ]; then
  23. _saveaccountconf_mutable SLACK_CHANNEL "$SLACK_CHANNEL"
  24. fi
  25. SLACK_USERNAME="${SLACK_USERNAME:-$(_readaccountconf_mutable SLACK_USERNAME)}"
  26. if [ -n "$SLACK_USERNAME" ]; then
  27. _saveaccountconf_mutable SLACK_USERNAME "$SLACK_USERNAME"
  28. fi
  29. export _H1="Content-Type: application/json"
  30. _content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)"
  31. _data="{\"text\": \"$_content\", "
  32. if [ -n "$SLACK_CHANNEL" ]; then
  33. _data="$_data\"channel\": \"$SLACK_CHANNEL\", "
  34. fi
  35. if [ -n "$SLACK_USERNAME" ]; then
  36. _data="$_data\"username\": \"$SLACK_USERNAME\", "
  37. fi
  38. _data="$_data\"mrkdwn\": \"true\"}"
  39. if _post "$_data" "$SLACK_WEBHOOK_URL"; then
  40. # shellcheck disable=SC2154
  41. if [ "$response" = "ok" ]; then
  42. _info "wa send success."
  43. return 0
  44. fi
  45. fi
  46. _err "wa send error."
  47. _err "$response"
  48. return 1
  49. }