Public-safe multi-session automation runner for the Telegram mini app behind @cryptocandyfarm_bot.
This repository is based on a real working VPS runner and keeps the core behavior intact while removing local runtime artifacts, private credentials, and environment-specific state.
This repo is meant to show a practical automation architecture, not just dump code. It preserves the useful parts of the real runner:
- Telethon-based bootstrap from Telegram sessions
- authenticated game/task execution
- on-demand Turnstile solving only when the API asks for it
- per-session state, logs, retry, alerting, and scheduler patterns
Current maturity: public-safe showcase of a production-style runner
What that means:
- core multi-session runner logic is present
- dynamic scheduling, retry/backoff, and optional alerting are preserved
- public examples are sanitized
- live sessions, cookies, and secrets are intentionally excluded
- multi-session runner with isolated failures and retry backoff
- scheduler-aware looping based on per-session next due time
- Turnstile solving only when the upstream API explicitly requires it
- optional Telegram alerting for failures, recoveries, and periodic summaries
- public-safe packaging with runtime state, cookies, logs, and secrets excluded from the repository
- Retrieves
tgWebAppDatafrom a Telegram Mini App via Telethon session files - Authenticates against the CryptoCandyFarm API
- Stores per-session HTTP cookies for reuse
- Reads game state and harvests plants that are ready
- Fetches tasks and completes pending ones
- Optional free gift claiming from
game_state.gifts - Optional auto-heal for sick plants via fertilizer usage
- Optional auto-buy fertilizer flow with session allowlists and default-off policy
- Uses a Turnstile solver only when the API explicitly reports
needsCaptcha=true - Supports multi-session execution
- Uses a dynamic per-session scheduler instead of relying only on a fixed global sweep
- Writes structured logs and machine-readable status files
- Includes per-session retry and backoff so one failure does not stop the full runner
- Optional Telegram alerts for runner lifecycle, solver health, repeated failures, recoveries, and periodic summaries
- studying a practical Telegram Mini App automation runner
- learning how to combine session bootstrap, HTTP execution, optional captcha solving, and scheduler-driven looping
- using a public-safe reference for multi-session worker design with logs, status files, and alerts
- adapting the architecture to a private runner with your own credentials and deployment setup
Detailed flow diagrams live in docs/FLOWS.md.
| Area | Component | Execution model | Current status |
|---|---|---|---|
| Bootstrap | Telethon session -> Mini App launch | Telegram client automation | Included |
| Game loop | harvest + tasks + auth reuse | HTTP runner | Included |
| Captcha | Turnstile solver only when needed | External solver integration | Included |
| Multi-session | all sessions with spacing/backoff | Runner orchestration | Included |
| Scheduler | next due based wake-up | Internal runner logic | Included |
| Observability | logs + per-session status files | Local runtime outputs | Included |
| Alerting | runner lifecycle / failure / summaries | Optional Telegram notifier | Included |
Sanitized file examples:
- Python 3.10+
- Telethon for Telegram session access
- Requests for HTTP/API interaction
- JSON file state for lightweight runtime persistence
- Optional Telegram Bot API notifications
cryptocandyfarm_auto.py- main runnertelegram_alerts.py- Telegram alerting helperstart_cryptocandyfarm.sh- long-running launcher forscreen, tmux, or systemd-style wrappersrequirements.txt- Python dependencies.env.example- required and optional environment variablesconfig/alerting.example.json- example Telegram alert configurationdocs/- quickstart, deployment guidance, FAQ, flow notes, and visualsexamples/- sanitized sample status and log outputssessions/- optional local Telethon session directory, intentionally gitignoredlogs/- runtime logs, intentionally gitignoredstate/- cookies, status, and alert state, intentionally gitignored
- Tested for repository CI on Python 3.10, 3.11, and 3.12
- Intended for Linux or other environments where Telethon session files are available locally
- Best suited for VPS or long-running terminal sessions when used in loop mode
- Python 3.10+
- A Telegram API ID and API hash from your own Telegram developer app
- At least one authorized Telethon
.sessionfile - Optional Turnstile solver endpoint compatible with the configured API shape
Install dependencies:
git clone https://github.com/IndraLawliet13/cryptocandyfarm-automation.git
cd cryptocandyfarm-automation
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
chmod +x start_cryptocandyfarm.shPrepare config:
cp .env.example .env
cp config/alerting.example.json config/alerting.local.jsonRun a quick smoke test:
set -a
source .env
set +a
python3 cryptocandyfarm_auto.py --list-sessions
python3 cryptocandyfarm_auto.py --all-sessions --auto-captcha --verboseRun the full looping launcher:
./start_cryptocandyfarm.shCopy .env.example and provide your own values:
cp .env.example .envRequired variables:
CRYPTOCANDYFARM_TELEGRAM_API_IDCRYPTOCANDYFARM_TELEGRAM_API_HASH
Useful optional variables:
CRYPTOCANDYFARM_BOT_USERNAMEdefault:cryptocandyfarm_botCRYPTOCANDYFARM_BASE_URLdefault:https://cryptocandyfarm.xyzCRYPTOCANDYFARM_SESSIONS_DIRdefault behavior: use./sessions
To expose the variables in your shell:
set -a
source .env
set +aAlerting is optional.
Example local config:
cp config/alerting.example.json config/alerting.local.jsonSupported settings:
telegram_enabledtelegram_bot_tokentelegram_chat_idsummary_interval_secondsfailure_alert_thresholdssolver_healthcheck_path
Environment variables can override the JSON config:
CRYPTOCANDYFARM_TELEGRAM_ENABLEDCRYPTOCANDYFARM_TELEGRAM_BOT_TOKENCRYPTOCANDYFARM_TELEGRAM_CHAT_IDCRYPTOCANDYFARM_SUMMARY_INTERVAL_SECONDSCRYPTOCANDYFARM_FAILURE_ALERT_THRESHOLDS
Send a test alert:
python3 cryptocandyfarm_auto.py --test-telegramList discovered sessions:
python3 cryptocandyfarm_auto.py --list-sessionsRun one session once:
python3 cryptocandyfarm_auto.py --session your_session_name --auto-captcha --verboseRun one session with gifts + auto-heal:
python3 cryptocandyfarm_auto.py --session your_session_name --auto-captcha --claim-gifts --auto-heal --verboseRun all discovered sessions once:
python3 cryptocandyfarm_auto.py --all-sessions --auto-captchaRun continuously:
./start_cryptocandyfarm.shEnable auto-buy fertilizer only for selected sessions:
python3 cryptocandyfarm_auto.py --all-sessions --loop --auto-captcha --claim-gifts --auto-heal --auto-buy-fertilizer --auto-buy-fertilizer-sessions your_session_namePrint saved status files:
python3 cryptocandyfarm_auto.py --statusRuntime data is intentionally local-only and is written under:
logs/runner.loglogs/sessions/<session>.logstate/status/<session>.jsonstate/cookies/state/alerts/
Default runner behavior:
- discovers sessions from
--sessions-dir, thenCRYPTOCANDYFARM_SESSIONS_DIR, then./sessions - authenticates each account first
- reads game state
- can claim free gifts when
--claim-giftsis enabled - can auto-heal sick plants when
--auto-healis enabled - can auto-buy fertilizer when
--auto-buy-fertilizeris enabled, but only for sessions allowed by--auto-buy-fertilizer-sessions - harvests every plant in
readystate - fetches tasks
- completes up to
2pending tasks per cycle per account by default - schedules each session from plant/task state so the next due account wakes first
- keeps other sessions running even if one session fails
- applies escalating retry backoff for failing sessions
Does this repo include real sessions or cookies? No. Session files, cookies, logs, and live runtime state are intentionally excluded.
When does the Turnstile solver run?
Only when the API reports needsCaptcha=true and you run with --auto-captcha.
Can I use this as-is on my VPS? Treat it as a public-safe reference implementation. You still need your own Telegram API credentials, your own authorized Telethon sessions, and your own solver/runtime setup.
- Runtime cookies and status are stored under
state/ - Per-session logs are stored under
logs/sessions/ - Status files include scheduling hints like
next_delay_seconds,next_due_at, andnext_reason - Auto-buy fertilizer is intentionally a default-off policy because it spends in-game balance; enable it only with clear allowlists
- The script expects valid Telethon session files and will fail authentication if they are not authorized
- External changes in Telegram, the target API, network quality, or captcha handling can still break automation temporarily
- This repository focuses on the automation runner itself, not on shipping ready-to-run account data
- Success still depends on valid Telegram sessions, upstream API stability, and a working captcha solver when needed
- External platform changes can break task flows without any code changes in this repository
- Auto-buy fertilizer is intentionally guarded because it spends in-game balance
- add a dedicated operations/runbook doc for common manual recovery flows
- add more sanitized visuals for alerting and per-session state transitions
- document safer patterns for longer unattended deployment and log rotation review
- add a small architecture decision log for notable implementation choices
This repository intentionally does not include:
- private Telethon session files
- cookies or saved runtime state
- local runner logs
- Telegram bot tokens or chat IDs used in production
- hardcoded Telegram API credentials from the original host
You must provide your own credentials and local runtime files before running it.
This repository now includes a LICENSE file that explicitly states no open-source license has been granted yet. That is intentional. It removes ambiguity without guessing a permissive or copyleft license choice on behalf of the owner.
