# Trigger Service **Repository Path**: fenixnix/trigger-service ## Basic Information - **Project Name**: Trigger Service - **Description**: A tiny FastAPI service that maps HTTP routes to local shell commands, with a built-in admin UI. Drop in a config, hit a URL, run a script. That's it. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-15 - **Last Updated**: 2026-06-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TeleTrig A tiny FastAPI service that maps HTTP routes to local shell commands, with a built-in admin UI. Drop in a config, hit a URL, run a script. That's it. > Useful for: webhook receivers, "one-button" automation, hooking dumb tools into smart ones, > giving your homelab a poor-man's job runner. ## Features - **JSON-driven routes** — no code change to add a new endpoint - **Hot-reload** — new routes are served without restarting (via dispatch middleware + runtime registration on POST) - **Markdown help at `/`** — `GET /` (or `/help`) returns `help.md` as `text/markdown`, friendly to AI agents - **Admin UI at `/ui`** for CRUD + dry-run testing - **Same handler for GET and POST** — fire it from anything (browser, curl, IFTTT, Shortcuts…) - **Per-route `timeout`, `shell`, `cwd`** so you don't have to babysit weird commands - Single-file modules, ~200 LOC total. Read it in one sitting. ## Quick start One-liner — creates the venv, installs deps, seeds `routes.json`, starts the server: ```bash # Windows run.bat # macOS / Linux ./run.sh ``` Or do it manually: ```bash git clone https://gitee.com/fenixnix/trigger-service.git cd trigger-service python -m venv .venv . .venv/Scripts/activate # PowerShell: .venv\Scripts\Activate.ps1 pip install -r requirements.txt cp routes.example.json routes.json python main.py ``` Open for the admin UI, for the markdown help (great for AI agents), or for the OpenAPI page. ## Configuration A route is a JSON object keyed by URL path: ```json { "/util/calc": { "command": "calc.exe", "description": "Open Windows calculator", "timeout": 5, "shell": false, "cwd": null } } ``` | Field | Type | Default | Notes | |---------------|---------|---------|-------| | `command` | string | — | Command line. With `shell: false` it's split via `shlex` (Windows-safe, non-POSIX). | | `description` | string | `""` | Free-form. | | `timeout` | int | `30` | Seconds. Process is killed past this. | | `shell` | bool | `false` | Pass to OS shell. Required for pipes/redirects/builtins. | | `cwd` | string | `null` | Working directory for the child process. | > Reserved paths: `/`, `/ui`, `/help`, anything under `/admin`, `/docs`, `/openapi.json`, `/redoc`, `/static/*`. ## Admin API | Method | Path | Body / Query | Purpose | |--------|------------------|----------------------------------|-------------------------------| | GET | `/admin/routes` | — | List all configured routes | | POST | `/admin/routes` | `RouteEntry` JSON | Create or update a route | | DELETE | `/admin/routes` | `?path=/util/calc` | Delete a route | | POST | `/admin/test` | `RouteEntry` JSON | Dry-run a command (no write) | `RouteEntry` schema: ```json { "path": "/util/echo", "command": "echo hi", "description": "optional", "timeout": 30, "shell": true, "cwd": null } ``` Example: ```bash curl -X POST http://localhost:7170/admin/routes \ -H "Content-Type: application/json" \ -d "{\"path\":\"/util/echo\",\"command\":\"echo hi\",\"shell\":true}" curl http://localhost:7170/util/echo ``` ## Response shape Every triggered route returns: ```json { "ok": true, "exit_code": 0, "stdout": "...", "stderr": "", "elapsed": 0.123, "command": "echo hi" } ``` HTTP status is `200` on success, `500` on non-zero exit / timeout / spawn error, `404` if the path isn't configured. ## Security This service literally runs commands on your box. **Do not expose it to the public internet without a reverse proxy + auth** (basic auth, mTLS, Tailscale, whatever). There is no built-in authentication — by design, to keep it small. Run it on `127.0.0.1` or behind a trusted gateway. ## AI agent usage `GET /` returns `help.md` as `text/markdown; charset=utf-8`. An agent only needs the host to bootstrap: ```bash curl -s http://HOST:7170/ # read the manual curl -s http://HOST:7170/admin/routes # list tasks curl -s -X POST http://HOST:7170/admin/routes \ -H "Content-Type: application/json" \ -d '{"path":"/util/echo","command":"echo hi","shell":true}' curl -s http://HOST:7170/util/echo # trigger curl -s -X DELETE "http://HOST:7170/admin/routes?path=/util/echo" ``` Task routes (user-defined) and management API (`/admin/*`) are kept on disjoint namespaces so an agent can't accidentally collide them. Edit `help.md` to customize what the agent sees — it's plain markdown loaded at request time. ## Project layout ``` teletrig/ ├── main.py # FastAPI app, dynamic dispatch, admin endpoints ├── config_manager.py # routes.json load/save with a thread lock ├── executor.py # subprocess runner (timeout, shell, cwd) ├── help.md # markdown manual served at GET / and /help ├── ui.html # admin UI (single-file, no build) ├── routes.example.json # sample config — copy to routes.json ├── run.bat / run.sh # one-liner installer + launcher ├── requirements.txt ├── pyproject.toml └── LICENSE ``` ## Development ```bash pip install -e ".[dev]" ruff check . ``` ## License MIT — see [LICENSE](./LICENSE).