Skip to content

Instantly share code, notes, and snippets.

@ohaiibuzzle
Last active April 17, 2026 02:21
Show Gist options
  • Select an option

  • Save ohaiibuzzle/eefd75d0683f3482ad74bc7b7def23d4 to your computer and use it in GitHub Desktop.

Select an option

Save ohaiibuzzle/eefd75d0683f3482ad74bc7b7def23d4 to your computer and use it in GitHub Desktop.
#!/bin/bash
source /etc/telegram/telegram.conf
if [ -z "$BOT_TOKEN" ] || [ -z "$CHAT_ID" ]; then
echo "Error: BOT_TOKEN and CHAT_ID must be set in /etc/telegram/telegram.conf"
exit 1
fi
# Function to send a message to Telegram
send_telegram_message() {
local message="$1"
# If message is too long (ie > 2048 characters), send it as a file instead
if [ ${#message} -lt 2048 ]; then
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d "chat_id=$CHAT_ID&text=$message" -o /dev/null
else
echo "$message" | curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendDocument" \
-F "chat_id=$CHAT_ID" \
-F "document=@-;filename=message.txt" -o /dev/null
fi
}
show_chat_id() {
curl -s "https://api.telegram.org/bot$BOT_TOKEN/getUpdates" | jq -r '.result[] | .message.chat.id'
}
# Main execution
if [ "$1" == "-" ]; then
message=$(cat)
else
message="$1"
fi
send_telegram_message "$message"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment