Created
April 10, 2021 01:20
-
-
Save dalibor-sojic/f8e059e84a473506e2f9433fe0f4b566 to your computer and use it in GitHub Desktop.
Telegram Bot sending messages. Source: https://bogomolov.tech/Telegram-notification-on-SSH-login/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GROUP_ID="xxxx" | |
BOT_TOKEN="xxxx" | |
# this 3 checks (if) are not necessary but should be convenient | |
if [ "$1" == "-h" ]; then | |
echo "Usage: `basename $0` \"text message\"" | |
exit 0 | |
fi | |
if [ -z "$1" ]; then | |
echo "Add message text as second arguments" | |
exit 0 | |
fi | |
if [ "$#" -ne 1 ]; then | |
echo "You can pass only one argument. For string with spaces put it on quotes" | |
exit 0 | |
fi | |
curl -s --data "text=$1" --data "chat_id=$GROUP_ID" --data "parse_mode=html" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment