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.

44 lines
1.4 KiB

  1. #!/usr/bin/env sh
  2. #Support CallMeBot Whatsapp webhooks
  3. #CALLMEBOT_YOUR_PHONE_NO=""
  4. #CALLMEBOT_API_KEY=""
  5. callmebotWhatsApp_send() {
  6. _subject="$1"
  7. _content="$2"
  8. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  9. _debug "_statusCode" "$_statusCode"
  10. CALLMEBOT_YOUR_PHONE_NO="${CALLMEBOT_YOUR_PHONE_NO:-$(_readaccountconf_mutable CALLMEBOT_YOUR_PHONE_NO)}"
  11. if [ -z "$CALLMEBOT_YOUR_PHONE_NO" ]; then
  12. CALLMEBOT_YOUR_PHONE_NO=""
  13. _err "You didn't specify a Slack webhook url CALLMEBOT_YOUR_PHONE_NO yet."
  14. return 1
  15. fi
  16. _saveaccountconf_mutable CALLMEBOT_YOUR_PHONE_NO "$CALLMEBOT_YOUR_PHONE_NO"
  17. CALLMEBOT_API_KEY="${CALLMEBOT_API_KEY:-$(_readaccountconf_mutable CALLMEBOT_API_KEY)}"
  18. if [ "$CALLMEBOT_API_KEY" ]; then
  19. _saveaccountconf_mutable CALLMEBOT_API_KEY "$CALLMEBOT_API_KEY"
  20. fi
  21. _waUrl="https://api.callmebot.com/whatsapp.php"
  22. _Phone_No="$(printf "%s" "$CALLMEBOT_YOUR_PHONE_NO" | _url_encode)"
  23. _apikey="$(printf "%s" "$CALLMEBOT_API_KEY" | _url_encode)"
  24. _message="$(printf "*%s*\\n%s" "$_subject" "$_content" | _url_encode)"
  25. _finalUrl="$_waUrl?phone=$_Phone_No&apikey=$_apikey&text=$_message"
  26. response="$(_get "$_finalUrl")"
  27. if [ "$?" = "0" ] && _contains ".<p><b>Message queued.</b> You will receive it in a few seconds."; then
  28. _info "wa send success."
  29. return 0
  30. fi
  31. _err "wa send error."
  32. _debug "URL" "$_finalUrl"
  33. _debug "Response" "$response"
  34. return 1
  35. }