From tgmock
Guide per-project setup for tgmock bot testing. Use this skill whenever a user wants to set up, configure, or install tgmock for their Telegram bot project — even if they just say "I want to test my bot" or "set up testing" without mentioning tgmock by name. Also use when they hit setup-related errors like "Bot exited before ready" or "port in use".
How this skill is triggered — by the user, by Claude, or both
Slash command
/tgmock:setupThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are helping the user configure tgmock for their Telegram bot project.
You are helping the user configure tgmock for their Telegram bot project.
which tgmock && tgmock mcp --help > /dev/null 2>&1 && echo "ok"
If not installed:
pipx install "tgmock[mcp]"
Add these to the project's .env file:
# Required
TGMOCK_BOT_COMMAND=python main.py # command to start your bot
TGMOCK_READY_LOG=Bot starting # substring in bot output that means "ready"
# For compiled languages (Go, Rust) — pre-build before starting
# TGMOCK_BUILD_COMMAND=go build -o /tmp/mybot ./cmd/server
# TGMOCK_BOT_COMMAND=/tmp/mybot
# Optional overrides
# TGMOCK_PORT=8999
# TGMOCK_STARTUP_TIMEOUT=30
# TGMOCK_AUTO_PATCH=true # enabled by default for Python bots
Or configure in pyproject.toml:
[tool.tgmock]
bot_command = "python main.py"
ready_log = "Bot starting"
How to find TGMOCK_READY_LOG: look at what your bot prints when it's ready to receive messages. For aiogram bots it's usually "Bot starting" or "Polling started". Run the bot command and look at the first log lines.
For Python bots (aiogram, python-telegram-bot, etc.), tgmock automatically patches HTTP clients (aiohttp, httpx) so your bot talks to the mock server without any code changes. This is enabled by default — just configure .env and go.
To disable auto-patching (e.g. if you already have BOT_API_BASE support):
TGMOCK_AUTO_PATCH=false
If auto-patch is disabled or you're using a non-Python bot, add BOT_API_BASE support manually. tgmock injects BOT_API_BASE automatically — the bot must use it to redirect API calls to the mock server.
For aiogram 3.x — add these lines to main.py:
import os
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.client.telegram import TelegramAPIServer
api_base = os.environ.get("BOT_API_BASE")
if api_base:
session = AiohttpSession(api=TelegramAPIServer.from_base(api_base))
bot = Bot(token=config.bot_token, session=session)
else:
bot = Bot(token=config.bot_token)
For python-telegram-bot:
import os
base_url = os.environ.get("BOT_API_BASE", "https://api.telegram.org/bot")
application = Application.builder().token(TOKEN).base_url(base_url).build()
For Go (telegram-bot-api):
bot, err := tgbotapi.NewBotAPIWithAPIEndpoint(token, os.Getenv("BOT_API_BASE")+"/bot%s/%s")
For Node.js (telegraf):
const bot = new Telegraf(token, {
telegram: { apiRoot: process.env.BOT_API_BASE || 'https://api.telegram.org' }
})
Use tg_start to test. If it fails, tg_logs will show what the bot printed.
tg_start → tg_send("hello") → tg_snapshot → tg_stop
Common issues:
tg_logs.tg_stop first.python or python3. For virtual envs, use the full path: TGMOCK_BOT_COMMAND=.venv/bin/python main.py.npx claudepluginhub azdaev/tgmock --plugin tgmockDiagnoses, debugs, deploys, and monitors Telegram bots with structured health checks, webhook/polling diagnostics, environment validation, and safe restart checklists.
Implements Telegram bots with full Bot API support: BotFather setup, messages, webhooks, inline keyboards, groups, channels. Node.js and Python boilerplates.
Provides CLI for Telegram Bot API using bot tokens: authenticate, send messages, read chats, get info, manage multi-bot setups. For CI/CD and server-side messaging automation.