Skip to content

Instantly share code, notes, and snippets.

@santaklouse
Created March 27, 2020 00:07
Show Gist options
  • Select an option

  • Save santaklouse/af2b200587ebd1e0f9f2a0a52439844f to your computer and use it in GitHub Desktop.

Select an option

Save santaklouse/af2b200587ebd1e0f9f2a0a52439844f to your computer and use it in GitHub Desktop.
Send message to telegram bot
#!/bin/sh
API_TOKEN='TG_API_TOKEN'
CHAT_ID='CHAT_ID'
if [ -z "$CHAT_ID" ]; then
echo 'Please, define CHAT_ID first! See "chat":{"id":xxxxxxx string below:'
/usr/bin/wget -qO - https://api.telegram.org/bot$API_TOKEN/getUpdates
exit 1
fi
MSG="<b>$(nvram get computer_name)</b>: $@"
if [ -z $@ ]; then
while read data; do
MSG=$MSG''$data
/usr/bin/wget -qs "https://api.telegram.org/bot$API_TOKEN/sendMessage?chat_id=$CHAT_ID&parse_mode=html&text=$MSG" 2>&1
if [ $? -eq 0 ]; then
echo 'Message sent successfully.'
else
echo 'Error while sending message!'
exit 1
fi;
exit 0;
done
fi;
/usr/bin/wget -qs "https://api.telegram.org/bot$API_TOKEN/sendMessage?chat_id=$CHAT_ID&parse_mode=html&text=$MSG" 2>&1
if [ $? -eq 0 ]; then
echo 'Message sent successfully.'
else
echo 'Error while sending message!'
exit 1
fi
@santaklouse
Copy link
Author

Example: Store in web and send link to telegram
grep -Hir "Message sent" / | pastebin | tg_say

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment