Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion notify/telegram.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/env sh
#!/usr/bin/bash

#Support Telegram Bots

#TELEGRAM_BOT_APITOKEN=""
#TELEGRAM_BOT_CHATID=""
#TELEGRAM_BOT_URLBASE=""
#TELEGRAM_BOT_THREADID=""

# To get TELEGRAM_BOT_THREADID, just copy the link of the message from the thread.
# https://t.me/c/123456789/XXX/1520 - XXX is the TELEGRAM_BOT_THREADID

telegram_send() {
_subject="$1"
Expand All @@ -28,6 +32,12 @@ telegram_send() {
fi
_saveaccountconf_mutable TELEGRAM_BOT_CHATID "$TELEGRAM_BOT_CHATID"

TELEGRAM_BOT_THREADID="${TELEGRAM_BOT_THREADID:-$(_readaccountconf_mutable TELEGRAM_BOT_THREADID)}"
if [ -z "$TELEGRAM_BOT_THREADID" ]; then
TELEGRAM_BOT_THREADID=""
fi
_saveaccountconf_mutable TELEGRAM_BOT_THREADID "$TELEGRAM_BOT_THREADID"

TELEGRAM_BOT_URLBASE="${TELEGRAM_BOT_URLBASE:-$(_readaccountconf_mutable TELEGRAM_BOT_URLBASE)}"
if [ -z "$TELEGRAM_BOT_URLBASE" ]; then
TELEGRAM_BOT_URLBASE="https://api.telegram.org"
Expand All @@ -39,6 +49,9 @@ telegram_send() {
_content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)"
_data="{\"text\": \"$_content\", "
_data="$_data\"chat_id\": \"$TELEGRAM_BOT_CHATID\", "
if [ -n "$TELEGRAM_BOT_THREADID" ]; then
_data="$_data\"message_thread_id\": \"$TELEGRAM_BOT_THREADID\", "
fi
_data="$_data\"parse_mode\": \"MarkdownV2\", "
_data="$_data\"disable_web_page_preview\": \"1\"}"

Expand Down