tg is a Go CLI for Telegram Bot API workflows used by agents.
It currently supports:
- Sending text messages via
sendMessage - One-shot polling via
getUpdates - Continuous long polling via
watch - Webhook clearing/info for switching between webhooks and polling
- Config/state in
~/.tgby default
go build -o tg ../tg config init
./tg bot add A --token 123456:ABCDEF... --chat-id 123456789 --description "primary bot" --default
./tg bot add B --token 654321:ZYX... --chat-id @alerts --description "backup bot"
./tg send "hello from tg"
./tg --bot B watch --timeout 30By default, config is loaded from ~/.tg/config.toml.
default_bot = "A"
api_base_url = "https://api.telegram.org"
http_timeout_seconds = 30
poll_timeout_seconds = 25
poll_limit = 100
auto_delete_webhook = false
state_file = "~/.tg/state.json"
output = "summary"
[bots.A]
token = "123456:ABCDEF..."
default_chat_id = "123456789"
description = "primary bot"
[bots.B]
token = "654321:ZYX..."
default_chat_id = "@alerts"
description = "backup bot"tg config init writes a commented example block into the file so you can add or edit bot entries by hand.
For send, chat resolution is --chat-id first, then the selected bot's default_chat_id.
Environment overrides are also supported:
TG_CONFIGTG_TOKENTG_BOTTG_API_BASE_URLTG_HTTP_TIMEOUTTG_POLL_TIMEOUTTG_POLL_LIMITTG_AUTO_DELETE_WEBHOOKTG_STATE_FILETG_OUTPUT
./tg send "hello"
./tg --bot A send "hello from bot A"
./tg send --chat-id @otherchannel --parse-mode MarkdownV2 "*hi*"
echo "stdin text" | ./tg send --stdin./tg poll --timeout 20 --limit 50
./tg --bot B poll --json --save-offset
./tg poll --json --save-offset./tg --bot A watch --timeout 30
./tg watch --json --state --delete-webhook./tg --bot A webhook info
./tg --bot A webhook clear --drop-pending-updates./tg bot add A --token 123456:ABCDEF... --chat-id 123456789 --description "primary bot" --default
./tg bot add B --token 654321:ZYX... --chat-id @alerts
./tg bot list
./tg bot default B
./tg bot rm Atg replyto reply directly to an incoming update/message idtg send-photo/tg send-documentwith local file uploadstg runmode: command router for/commandsand callback queriestg tail --chat-id ...to filter incoming updates by chattg ackand offset checkpoints with named consumerstg webhook servefor local webhook debuggingtg media get <file_id>helper aroundgetFiletg rate/ throughput controls for bulk sends