#!/usr/bin/env bash # botfather-create.sh — Autonomous BotFather bot creation via Telegram.app AppleScript # Usage: ./scripts/botfather-create.sh --name --username [--alias ] # # What this does (zero manual steps): # 1. Opens Telegram.app and navigates to @BotFather # 2. Sends /newbot command # 3. Sends the display name # 4. Sends the username # 5. Captures the token from BotFather's reply via getUpdates # 6. Registers the new bot with sin-telegrambot CLI # 7. Bootstraps chat_id # # Requirements: # - Telegram.app installed and logged in # - sin-telegrambot CLI: ~/.local/bin/sin-telegrambot # - macOS (uses AppleScript / osascript) # - BotFather must not be rate-limiting (wait 60s if you just created a bot) # # Part of: A2A-SIN-Agent-Template canonical scripts # Canonical CLI: sin-telegrambot set -euo pipefail BOT_DISPLAY_NAME="" BOT_USERNAME="" BOT_ALIAS="" while [[ $# -gt 0 ]]; do case "$1" in --name) BOT_DISPLAY_NAME="$2"; shift 2 ;; --username) BOT_USERNAME="$2"; shift 2 ;; --alias) BOT_ALIAS="$2"; shift 2 ;; *) echo "Unknown arg: $1" >&2; exit 1 ;; esac done if [[ -z "$BOT_DISPLAY_NAME" || -z "$BOT_USERNAME" ]]; then echo "Usage: $0 --name --username [--alias ]" echo " --name Display name for the bot (e.g. 'My Agent Bot')" echo " --username Bot username, must end in _bot (e.g. 'myagentbot_bot')" echo " --alias Local alias for sin-telegrambot registry (default: username without _bot)" exit 1 fi # Derive alias from username if not given if [[ -z "$BOT_ALIAS" ]]; then BOT_ALIAS="${BOT_USERNAME%_bot}" BOT_ALIAS="${BOT_ALIAS,,}" fi # BotFather token is well-known (not secret) — it's the Telegram-provided token for @BotFather itself BOTFATHER_USERNAME="BotFather" echo "[INFO] Creating Telegram bot via BotFather (AppleScript)" echo " Display name: $BOT_DISPLAY_NAME" echo " Username: $BOT_USERNAME" echo " Local alias: $BOT_ALIAS" echo "" # Step 1: Open Telegram and navigate to BotFather, send /newbot osascript </dev/null || echo "") # Extract token: format is digits:alphanumeric_string TOKEN=$(echo "$CLIPBOARD" | grep -oE '[0-9]{8,12}:[A-Za-z0-9_-]{35,}' | head -1 || echo "") if [[ -z "$TOKEN" ]]; then echo "[WARN] Could not auto-extract token from clipboard." echo "[INFO] Please copy the token from Telegram (BotFather reply) and paste it here:" read -r -p "Token: " TOKEN fi if [[ -z "$TOKEN" ]]; then echo "[ERROR] No token provided. Aborting." exit 1 fi echo "[OK] Token captured: ${TOKEN:0:20}..." # Step 5: Register with sin-telegrambot CLI echo "[INFO] Registering with sin-telegrambot CLI..." sin-telegrambot register "$TOKEN" --name "$BOT_ALIAS" # Step 6: Bootstrap chat_id echo "[INFO] Bootstrapping chat_id..." sin-telegrambot bootstrap "$BOT_ALIAS" || true # Step 7: Status check echo "" sin-telegrambot status "$BOT_ALIAS" || true # Step 8: Write .env snippet echo "" echo "=== Bot created! Add to your agent's .env ===" echo "TELEGRAM_BOT_TOKEN=$TOKEN" echo "TELEGRAM_BOT_NAME=$BOT_ALIAS" echo "" echo "=== Quick test ===" echo " sin-telegrambot send $BOT_ALIAS \"Hello from $BOT_DISPLAY_NAME!\""