backslash interpretations, ensure valid chat id

This commit is contained in:
realies
2019-01-04 08:59:31 +00:00
parent 45cc30e541
commit 6d3dd3eff7
@@ -240,17 +240,17 @@
$STORED_TOKEN=$(cat /boot/config/telegram/token) || "";
if [[ ! -f /boot/config/telegram/token || "$STORED_TOKEN" != "$BOT_TOKEN" ]]; then
mkdir -p /boot/config/telegram;
echo -e "$BOT_TOKEN" > /boot/config/telegram/token;
echo $BOT_TOKEN > /boot/config/telegram/token;
fi
if [[ ! -f /boot/config/telegram/chatid || "$STORED_TOKEN" != "$BOT_TOKEN" ]]; then
mkdir -p /boot/config/telegram;
curl https://api.telegram.org/bot$BOT_TOKEN/getUpdates | jq ".result | last .message .chat .id" > /boot/config/telegram/chatid;
LASTCHATID=$(curl https://api.telegram.org/bot$BOT_TOKEN/getUpdates | jq ".result | last .message .chat .id");
[[ $LASTCHATID =~ ^[0-9]+$ ]] && echo $LASTCHATID > /boot/config/telegram/chatid;
fi
CHATID=$(cat /boot/config/telegram/chatid);
MESSAGE=$(echo -e "$(hostname): $TITLE
$MESSAGE");
MESSAGE=$(echo -e "$(hostname): $TITLE\n$MESSAGE");
curl -G -v "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" --data-urlencode "chat_id=$CHATID" --data-urlencode "text=$MESSAGE" 2>&1;
]]>
</Script>