Created
January 13, 2026 02:47
-
-
Save ivankristianto/8b82c5552b20009039d387f94f3a4eef to your computer and use it in GitHub Desktop.
Alias command to send to Telegram Bot
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
| # Prerequisites | |
| # Before running the container, you need two things from Telegram: | |
| # Bot Token: Create a bot by messaging @BotFather on Telegram and sending /newbot. | |
| # Chat ID: Message your new bot (e.g., say "Hello"), | |
| # then visit https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates to find the "id" inside the chat object | |
| # (it will be a number like 123456789). | |
| # Send command | |
| # tt -m "Your message here" | |
| # Remember to escape the message | |
| # Now you can send message from your Code Agent to your Telegram | |
| # Send to telegram | |
| # Telegram Notification Function | |
| tt() { | |
| # 1. Configuration (Replace these with your actual keys) | |
| local BOT_TOKEN="<replace-with-your-token" #name of your bot | |
| local CHAT_ID="<your chat id>" | |
| # 2. Variable to hold the message | |
| local MESSAGE="" | |
| # 3. Handle flags (like -m) | |
| while getopts ":m:" opt; do | |
| case $opt in | |
| m) MESSAGE="$OPTARG" | |
| ;; | |
| \?) echo "Invalid option -$OPTARG" >&2; return 1 | |
| ;; | |
| esac | |
| done | |
| # 4. Fallback: If no -m flag, use the first argument, or default to "Ping" | |
| if [ -z "$MESSAGE" ]; then | |
| shift $((OPTIND -1)) | |
| MESSAGE="${1:-Ping}" | |
| fi | |
| # 5. Send the request | |
| curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \ | |
| -d chat_id="${CHAT_ID}" \ | |
| -d text="${MESSAGE}" > /dev/null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment