| name | add-skill-trains |
| description | Add UK train departure/arrival information to NanoTars via National Rail Darwin API. Guides through free API token registration and configures environment. Triggers on "add trains", "train times", "national rail", "uk trains setup". |
Add UK Trains
Configures live UK train departure and arrival data for agent containers using the National Rail Darwin API.
Preflight
Before installing, verify NanoTars is set up:
[ -d node_modules ] && echo "DEPS: ok" || echo "DEPS: missing"
docker image inspect nanoclaw-agent:latest &>/dev/null && echo "IMAGE: ok" || echo "IMAGE: not built"
if grep -q "ANTHROPIC_API_KEY\|CLAUDE_CODE_OAUTH_TOKEN" .env 2>/dev/null || [ -f "$HOME/.claude/.credentials.json" ]; then echo "AUTH: ok"; else echo "AUTH: missing"; fi
If any check fails, tell the user to run /nanotars-setup first and stop.
Step 1: Check Existing Configuration
grep "^NATIONAL_RAIL_TOKEN=" .env 2>/dev/null && echo "ALREADY_CONFIGURED" || echo "NEEDS_SETUP"
If ALREADY_CONFIGURED, ask the user if they want to reconfigure or test the existing token.
Step 2: Register for Darwin API Token
Tell the user:
You need a free Darwin API token from National Rail. Here's how:
- Go to https://realtime.nationalrail.co.uk/OpenLDBWSRegistration/
- Fill in the registration form (name, email, reason: "personal use")
- You'll receive an email with your API token
- Paste the token here when ready
Wait for the user to provide the token.
Step 3: Save to .env
sed -i '/^NATIONAL_RAIL_TOKEN=/d' .env
echo 'NATIONAL_RAIL_TOKEN=THE_TOKEN_HERE' >> .env
Step 4: Install Plugin
cp -r ${CLAUDE_PLUGIN_ROOT}/files/ plugins/trains/
chmod +x plugins/trains/container-skills/scripts/trains.py
Step 5: Plugin Configuration
By default this plugin is available to all groups and channel types. To restrict access, edit plugins/trains/plugin.json and set:
"groups" to specific group folder names (e.g., ["main"]) instead of ["*"]
"channels" to specific channel types (e.g., ["whatsapp"]) instead of ["*"]
Ask the user if they want to restrict access. Most users will keep the defaults.
Step 6: Test the Token
source .env
[ -n "$NATIONAL_RAIL_TOKEN" ] && echo "OK - token is set (${#NATIONAL_RAIL_TOKEN} chars)" || echo "FAILED - NATIONAL_RAIL_TOKEN is empty"
For a deeper test (optional -- the Darwin API can be slow):
source .env
python3 plugins/trains/container-skills/scripts/trains.py departures PAD --rows 3
If it fails:
- HTTP 401: Token is invalid or not yet activated (can take a few minutes after registration)
- Connection timeout: Network issue, try again
Step 7: Build and Restart
npm run build
nanotars restart
Verify
Send a WhatsApp message like "when's the next train from Didcot to Paddington?"
Per-group overrides: If a specific group needs a different National Rail token, add NATIONAL_RAIL_TOKEN=... to groups/{folder}/.env. See /create-skill-plugin for details.
Remove
rm -rf plugins/trains/
- Remove env vars from .env:
sed -i '/^NATIONAL_RAIL_TOKEN=/d' .env
- Rebuild and restart