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.

43 lines
1.4 KiB

  1. #!/usr/bin/bash
  2. #Support CallMeBot Whatsapp webhooks
  3. #CallMeBot_Phone_No=""
  4. #CallMeBot_apikey=""
  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_Phone_No="${CallMeBot_Phone_No:-$(_readaccountconf_mutable CallMeBot_Phone_No)}"
  11. if [ -z "$CallMeBot_Phone_No" ]; then
  12. CallMeBot_Phone_No=""
  13. _err "You didn't specify a Slack webhook url CallMeBot_Phone_No yet."
  14. return 1
  15. fi
  16. _saveaccountconf_mutable CallMeBot_Phone_No "$CallMeBot_Phone_No"
  17. CallMeBot_apikey="${CallMeBot_apikey:-$(_readaccountconf_mutable CallMeBot_apikey)}"
  18. if [ -n "$CallMeBot_apikey" ]; then
  19. _saveaccountconf_mutable CallMeBot_apikey "$CallMeBot_apikey"
  20. fi
  21. _waUrl="https://api.callmebot.com/whatsapp.php"
  22. _Phone_No="$(printf "%s" "$CallMeBot_Phone_No" | _url_encode)"
  23. _apikey="$(printf "%s" "$CallMeBot_apikey" | _url_encode)"
  24. _message="$(printf "$CQHTTP_CUSTOM_MSGHEAD *%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. }