Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
18df3dc0
Unverified
Commit
18df3dc0
authored
Jan 12, 2021
by
neil
Committed by
GitHub
Jan 12, 2021
Browse files
Merge pull request #3333 from mjbnz/patch-1
Add Telegram notify hook
parents
3725724c
584cc6de
Changes
1
Hide whitespace changes
Inline
Side-by-side
notify/telegram.sh
0 → 100644
View file @
18df3dc0
#!/usr/bin/env sh
#Support Telegram Bots
#TELEGRAM_BOT_APITOKEN=""
#TELEGRAM_BOT_CHATID=""
telegram_send
()
{
_subject
=
"
$1
"
_content
=
"
$2
"
_statusCode
=
"
$3
"
#0: success, 1: error 2($RENEW_SKIP): skipped
_debug
"_statusCode"
"
$_statusCode
"
TELEGRAM_BOT_APITOKEN
=
"
${
TELEGRAM_BOT_APITOKEN
:-
$(
_readaccountconf_mutable TELEGRAM_BOT_APITOKEN
)
}
"
if
[
-z
"
$TELEGRAM_BOT_APITOKEN
"
]
;
then
TELEGRAM_BOT_APITOKEN
=
""
_err
"You didn't specify a Telegram BOT API Token TELEGRAM_BOT_APITOKEN yet."
return
1
fi
_saveaccountconf_mutable TELEGRAM_BOT_APITOKEN
"
$TELEGRAM_BOT_APITOKEN
"
TELEGRAM_BOT_CHATID
=
"
${
TELEGRAM_BOT_CHATID
:-
$(
_readaccountconf_mutable TELEGRAM_BOT_CHATID
)
}
"
if
[
-z
"
$TELEGRAM_BOT_CHATID
"
]
;
then
TELEGRAM_BOT_CHATID
=
""
_err
"You didn't specify a Telegram Chat id TELEGRAM_BOT_CHATID yet."
return
1
fi
_saveaccountconf_mutable TELEGRAM_BOT_CHATID
"
$TELEGRAM_BOT_CHATID
"
_content
=
"
$(
printf
"*%s*
\n
%s"
"
$_subject
"
"
$_content
"
| _json_encode
)
"
_data
=
"{
\"
text
\"
:
\"
$_content
\"
, "
_data
=
"
$_data
\"
chat_id
\"
:
\"
$TELEGRAM_BOT_CHATID
\"
, "
_data
=
"
$_data
\"
parse_mode
\"
:
\"
markdown
\"
, "
_data
=
"
$_data
\"
disable_web_page_preview
\"
:
\"
1
\"
}"
export
_H1
=
"Content-Type: application/json"
_telegram_bot_url
=
"https://api.telegram.org/bot
${
TELEGRAM_BOT_APITOKEN
}
/sendMessage"
if
_post
"
$_data
"
"
$_telegram_bot_url
"
;
then
# shellcheck disable=SC2154
_message
=
$(
printf
"%s
\n
"
"
$response
"
|
sed
-n
's/.*"ok":\([^,]*\).*/\1/p'
)
if
[
"
$_message
"
=
"true"
]
;
then
_info
"telegram send success."
return
0
fi
fi
_err
"telegram send error."
_err
"
$response
"
return
1
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment