mirror of
https://github.com/plantroon/acme.sh.git
synced 2024-11-17 20:01:46 +00:00
Update callmebotWhatsApp.sh
Added CallMeBot API for WhatsApp Notifications.
This commit is contained in:
parent
5b42aea9e7
commit
d440b2f2b2
@ -1,59 +1,44 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/bash
|
||||||
|
|
||||||
#Support CallMeBot Whatsapp webhooks
|
#Support CallMeBot Whatsapp webhooks
|
||||||
|
|
||||||
#CallMeBot_Phone_No=""
|
#CallMeBot_Phone_No=""
|
||||||
#CallMeBot_apikey=""
|
#CallMeBot_apikey=""
|
||||||
#SLACK_USERNAME=""
|
|
||||||
|
|
||||||
#SLACK_WEBHOOK_URL=""
|
callmebotWhatsApp_send() {
|
||||||
#SLACK_CHANNEL=""
|
|
||||||
#SLACK_USERNAME=""
|
|
||||||
|
|
||||||
slack_send() {
|
|
||||||
_subject="$1"
|
_subject="$1"
|
||||||
_content="$2"
|
_content="$2"
|
||||||
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
|
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
|
||||||
_debug "_statusCode" "$_statusCode"
|
_debug "_statusCode" "$_statusCode"
|
||||||
|
|
||||||
SLACK_WEBHOOK_URL="${SLACK_WEBHOOK_URL:-$(_readaccountconf_mutable SLACK_WEBHOOK_URL)}"
|
CallMeBot_Phone_No="${CallMeBot_Phone_No:-$(_readaccountconf_mutable CallMeBot_Phone_No)}"
|
||||||
if [ -z "$SLACK_WEBHOOK_URL" ]; then
|
if [ -z "$CallMeBot_Phone_No" ]; then
|
||||||
SLACK_WEBHOOK_URL=""
|
CallMeBot_Phone_No=""
|
||||||
_err "You didn't specify a Slack webhook url SLACK_WEBHOOK_URL yet."
|
_err "You didn't specify a Slack webhook url CallMeBot_Phone_No yet."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_saveaccountconf_mutable SLACK_WEBHOOK_URL "$SLACK_WEBHOOK_URL"
|
_saveaccountconf_mutable CallMeBot_Phone_No "$CallMeBot_Phone_No"
|
||||||
|
|
||||||
SLACK_CHANNEL="${SLACK_CHANNEL:-$(_readaccountconf_mutable SLACK_CHANNEL)}"
|
CallMeBot_apikey="${CallMeBot_apikey:-$(_readaccountconf_mutable CallMeBot_apikey)}"
|
||||||
if [ -n "$SLACK_CHANNEL" ]; then
|
if [ -n "$CallMeBot_apikey" ]; then
|
||||||
_saveaccountconf_mutable SLACK_CHANNEL "$SLACK_CHANNEL"
|
_saveaccountconf_mutable CallMeBot_apikey "$CallMeBot_apikey"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SLACK_USERNAME="${SLACK_USERNAME:-$(_readaccountconf_mutable SLACK_USERNAME)}"
|
_waUrl="https://api.callmebot.com/whatsapp.php"
|
||||||
if [ -n "$SLACK_USERNAME" ]; then
|
|
||||||
_saveaccountconf_mutable SLACK_USERNAME "$SLACK_USERNAME"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export _H1="Content-Type: application/json"
|
_Phone_No="$(printf "%s" "$CallMeBot_Phone_No" | _url_encode)"
|
||||||
|
_apikey="$(printf "%s" "$CallMeBot_apikey" | _url_encode)"
|
||||||
|
_message="$(printf "$CQHTTP_CUSTOM_MSGHEAD *%s*\\n%s" "$_subject" "$_content" | _url_encode)"
|
||||||
|
|
||||||
_content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)"
|
_finalUrl="$_waUrl?phone=$_Phone_No&apikey=$_apikey&text=$_message"
|
||||||
_data="{\"text\": \"$_content\", "
|
response="$(_get "$_finalUrl")"
|
||||||
if [ -n "$SLACK_CHANNEL" ]; then
|
|
||||||
_data="$_data\"channel\": \"$SLACK_CHANNEL\", "
|
|
||||||
fi
|
|
||||||
if [ -n "$SLACK_USERNAME" ]; then
|
|
||||||
_data="$_data\"username\": \"$SLACK_USERNAME\", "
|
|
||||||
fi
|
|
||||||
_data="$_data\"mrkdwn\": \"true\"}"
|
|
||||||
|
|
||||||
if _post "$_data" "$SLACK_WEBHOOK_URL"; then
|
if [ "$?" = "0" ] && _contains ".<p><b>Message queued.</b> You will receive it in a few seconds."; then
|
||||||
# shellcheck disable=SC2154
|
_info "wa send success."
|
||||||
if [ "$response" = "ok" ]; then
|
return 0
|
||||||
_info "wa send success."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
_err "wa send error."
|
_err "wa send error."
|
||||||
_err "$response"
|
_debug "URL" "$_finalUrl"
|
||||||
|
_debug "Response" "$response"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user