Skip to content

Instantly share code, notes, and snippets.

@khiemdoan
Last active November 29, 2023 04:35
Show Gist options
  • Save khiemdoan/4a3a63cf5fc38ca4784693408f18224d to your computer and use it in GitHub Desktop.
Save khiemdoan/4a3a63cf5fc38ca4784693408f18224d to your computer and use it in GitHub Desktop.
Send message to Telegram in terminal
#!/bin/bash
CHAT_ID=<chat_id>
BOT_TOKEN=<bot_token>
# 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=$CHAT_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null
# chmod +x telegram-send.sh
# sudo mv telegram-send.sh /usr/bin/telegram-send
# sudo chown root:root /usr/bin/telegram-send
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment