+ support for self-hosted telegram-bot-api instances

master
Dominika Liberda 2022-04-03 17:42:49 +02:00
parent 8952aca3f7
commit c8f9970487
1 changed files with 6 additions and 5 deletions

11
tg.sh
View File

@ -2,6 +2,7 @@
TELEGRAM_TOKEN=""
PARSE_MODE="MarkdownV2"
ESCAPE_ALL=false
API_URL="https://api.telegram.org"
# _escape_text(input_text)
function _escape() {
@ -38,32 +39,32 @@ function tg_send() {
-F caption="$text" \
-F parse_mode=$PARSE_MODE \
-F $type_snake=$5 \
"https://api.telegram.org/bot${TELEGRAM_TOKEN}/send${type}"
"${API_URL}/bot${TELEGRAM_TOKEN}/send${type}"
else
curl -s \
-F chat_id=$1 \
-F caption="$text" \
-F parse_mode=$PARSE_MODE \
-F $type_snake=@$3 \
"https://api.telegram.org/bot${TELEGRAM_TOKEN}/send${type}"
"${API_URL}/bot${TELEGRAM_TOKEN}/send${type}"
fi
else
curl -s \
-F chat_id=$1 \
-F text="$text" \
-F parse_mode=$PARSE_MODE \
"https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage"
"${API_URL}/bot${TELEGRAM_TOKEN}/sendMessage"
fi
}
# tg_get_me()
function tg_get_me() {
curl -s "https://api.telegram.org/bot${TELEGRAM_TOKEN}/getMe"
curl -s "${API_URL}/bot${TELEGRAM_TOKEN}/getMe"
}
# tg_get_messages(offset, timeout)
function _tg_get_updates() {
curl -s "https://api.telegram.org/bot${TELEGRAM_TOKEN}/getUpdates?offset=$1&timeout=p" | jq -c '.result[]'
curl -s "${API_URL}/bot${TELEGRAM_TOKEN}/getUpdates?offset=$1&timeout=p" | jq -c '.result[]'
}
function _on_msg() {