Skip to content

Build a personal bot

A Telegram bot answers your messages from a VM that sleeps between them. A message wakes the VM. A schedule runs an agent every five minutes. The agent answers the unread messages, and it keeps its memory in a file on the VM’s disk.

  • An approved account and an API key from the API keys page.
  • A Telegram account and a bot token from @BotFather.
  • Python 3.12 with requests, or Node 22, for the Python and TypeScript tabs.

Set these once in your terminal. Keep the token in a file, so it stays out of your shell history.

Terminal window
export SI_API_KEY=si_...
export TELEGRAM_BOT_TOKEN="$(cat ~/.telegram-token)"

Create the VM. The first request starts it.

Terminal window
curl -sS -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d '{"name":"personal-bot"}'
Output
{"id":"6f1c0f0e8a","generation":1,...}

Set VM to the id in the reply. Then sign in to Claude Code in the VM, from its terminal in the dashboard, as in Fix a failing test with Claude Code. The schedule in step 4 runs claude, and it needs that sign-in.

Terminal window
export VM=6f1c0f0e8a

The inbox accepts messages and wakes the VM for each one. It is off until you turn it on.

Terminal window
curl -sS -X PUT "https://api.slashinfra.com/svms/$VM/inbox" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d '{"enabled":true}'
Output
{"address":"6f1c0f0e8a@slashinfra.dev","enabled":true,...}

Send the token to the API. The reply holds a pairing code. Send /start and the code to your bot in Telegram within ten minutes. Pairing adds your Telegram user to the users whose messages reach the inbox.

Terminal window
curl -sS -X PUT "https://api.slashinfra.com/svms/$VM/inbox/telegram" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d "{\"bot_token\":\"$TELEGRAM_BOT_TOKEN\"}"
Output
{"bot_username":"build_1_bot","pair_code":"k3m9q2x7"}

The schedule runs every five minutes. Each run starts Claude Code in the VM. The agent reads its memory file, answers each unread message with inbox reply, and adds a line about each answer to the same file. A due schedule wakes the VM, so the run works even when the VM sleeps. --permission-mode bypassPermissions lets Claude Code edit files and run commands without asking. A job has no one to answer a prompt, and the agent works inside its own VM.

Terminal window
curl -sS -X POST "https://api.slashinfra.com/svms/$VM/schedules" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" -d @- <<'JSON'
{"name":"answer-telegram","cron":"*/5 * * * *","timezone":"UTC",
"action":{"type":"command","command":"cd /home/user && claude -p --permission-mode bypassPermissions 'Read /home/user/memory.md if it exists. Answer each message from inbox ls --unread with inbox reply, using the memory for earlier messages. Then add one line about each answer to /home/user/memory.md.'"}}
JSON
Output
{"name":"answer-telegram",...,"next_at":...}

Send /start and the pairing code to the bot, then leave the VM with nothing running for at least 60 seconds so that it sleeps. Send the bot a message. The message wakes the VM and lands in its inbox. The next five-minute run answers it, and that run starts within about 90 seconds of its time.

Send a second message that refers to the first, such as “what did I ask before?”. The reply uses the memory file, which holds one line for each earlier answer.

Symptom Cause Fix
Step 3 answers with inbox_disabled The inbox is off. Run step 2 again.
The bot gives no answer to /start The pairing code expired after ten minutes. Make a new code with POST /svms/{ref}/inbox/telegram/pair, then send /start with it.
No reply, and the memory file is missing The schedule did not run, or Claude Code is not signed in. List the runs with GET /svms/{ref}/schedules/{id}/runs, then sign in to Claude Code if the run failed.

Scroll horizontally to see all columns.

Terminal window
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/svms/$VM" \
-H "Authorization: Bearer $SI_API_KEY"
Output
204
  • Email: the same inbox takes mail, which wakes the VM too.
  • Schedules: the schedule rules, the minimum gap between runs and the message action.
  • Sleep and wake: what the VM keeps while it sleeps, and what wakes it.