mirror of
https://github.com/acmesh-official/acme.sh.git
synced 2026-08-13 12:33:30 +02:00
Add notify waha support
This commit is contained in:
parent
ebb5cc4981
commit
237f2d9c3b
1 changed files with 75 additions and 0 deletions
75
notify/waha.sh
Executable file
75
notify/waha.sh
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#Support WAHA (WhatsApp HTTP API) - free, self-hosted WhatsApp API
|
||||
#https://waha.devlike.pro/
|
||||
|
||||
#Required:
|
||||
#WAHA_URL="http://localhost:3000"
|
||||
#WAHA_CHAT_ID="1234567890@c.us"
|
||||
|
||||
#Optional:
|
||||
#WAHA_API_KEY=""
|
||||
#WAHA_SESSION="default"
|
||||
|
||||
waha_send() {
|
||||
_subject="$1"
|
||||
_content="$2"
|
||||
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
|
||||
_debug "_subject" "$_subject"
|
||||
_debug "_content" "$_content"
|
||||
_debug "_statusCode" "$_statusCode"
|
||||
|
||||
WAHA_URL="${WAHA_URL:-$(_readaccountconf_mutable WAHA_URL)}"
|
||||
if [ -z "$WAHA_URL" ]; then
|
||||
WAHA_URL=""
|
||||
_err "You didn't specify the WAHA server url WAHA_URL yet."
|
||||
_err "Example: export WAHA_URL=\"http://localhost:3000\""
|
||||
return 1
|
||||
fi
|
||||
_saveaccountconf_mutable WAHA_URL "$WAHA_URL"
|
||||
|
||||
WAHA_CHAT_ID="${WAHA_CHAT_ID:-$(_readaccountconf_mutable WAHA_CHAT_ID)}"
|
||||
if [ -z "$WAHA_CHAT_ID" ]; then
|
||||
WAHA_CHAT_ID=""
|
||||
_err "You didn't specify the WhatsApp chat id WAHA_CHAT_ID yet."
|
||||
_err "Example: export WAHA_CHAT_ID=\"1234567890@c.us\""
|
||||
return 1
|
||||
fi
|
||||
_saveaccountconf_mutable WAHA_CHAT_ID "$WAHA_CHAT_ID"
|
||||
|
||||
WAHA_API_KEY="${WAHA_API_KEY:-$(_readaccountconf_mutable WAHA_API_KEY)}"
|
||||
if [ "$WAHA_API_KEY" ]; then
|
||||
_saveaccountconf_mutable WAHA_API_KEY "$WAHA_API_KEY"
|
||||
fi
|
||||
|
||||
WAHA_SESSION="${WAHA_SESSION:-$(_readaccountconf_mutable WAHA_SESSION)}"
|
||||
if [ -z "$WAHA_SESSION" ]; then
|
||||
WAHA_SESSION="default"
|
||||
else
|
||||
_saveaccountconf_mutable WAHA_SESSION "$WAHA_SESSION"
|
||||
fi
|
||||
|
||||
_content=$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)
|
||||
|
||||
_data="{\"chatId\": \"$WAHA_CHAT_ID\", "
|
||||
_data="$_data\"text\": \"$_content\", "
|
||||
_data="$_data\"session\": \"$WAHA_SESSION\"}"
|
||||
|
||||
_debug "_data" "$_data"
|
||||
|
||||
export _H1="Content-Type: application/json"
|
||||
if [ "$WAHA_API_KEY" ]; then
|
||||
export _H2="X-Api-Key: $WAHA_API_KEY"
|
||||
fi
|
||||
|
||||
_waha_url="${WAHA_URL}/api/sendText"
|
||||
response="$(_post "$_data" "$_waha_url" "" "POST" "application/json")"
|
||||
|
||||
if [ "$?" = "0" ] && _contains "$response" "id"; then
|
||||
_info "waha send success."
|
||||
return 0
|
||||
fi
|
||||
_err "waha send error."
|
||||
_err "$response"
|
||||
return 1
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue