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.
Before you start
Section titled “Before you start”- 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.
export SI_API_KEY=si_...export TELEGRAM_BOT_TOKEN="$(cat ~/.telegram-token)"1. Create the bot’s VM
Section titled “1. Create the bot’s VM”Create the VM. The first request starts it.
curl -sS -X POST "https://api.slashinfra.com/svms" \ -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \ -d '{"name":"personal-bot"}'API reference: Control API operation
import os, requests
res = requests.post( "https://api.slashinfra.com/svms", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={"name": "personal-bot"},)res.raise_for_status()print(res.text)const res = await fetch('https://api.slashinfra.com/svms', { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'personal-bot' }),})if (!res.ok) throw new Error(`create failed: ${res.status}`)console.log(await res.text()){"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.
export VM=6f1c0f0e8a2. Turn on the inbox
Section titled “2. Turn on the inbox”The inbox accepts messages and wakes the VM for each one. It is off until you turn it on.
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}'API reference: Control API operation
import os, requests
res = requests.put( f"https://api.slashinfra.com/svms/{os.environ['VM']}/inbox", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={"enabled": True},)res.raise_for_status()print(res.text)const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}/inbox`, { method: 'PUT', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ enabled: true }),})if (!res.ok) throw new Error(`inbox failed: ${res.status}`)console.log(await res.text()){"address":"6f1c0f0e8a@slashinfra.dev","enabled":true,...}3. Connect the bot
Section titled “3. Connect the bot”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.
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\"}"API reference: Control API operation
import os, requests
res = requests.put( f"https://api.slashinfra.com/svms/{os.environ['VM']}/inbox/telegram", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={"bot_token": os.environ["TELEGRAM_BOT_TOKEN"]},)res.raise_for_status()print(res.text)const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}/inbox/telegram`, { method: 'PUT', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ bot_token: process.env.TELEGRAM_BOT_TOKEN! }),})if (!res.ok) throw new Error(`telegram failed: ${res.status}`)console.log(await res.text()){"bot_username":"build_1_bot","pair_code":"k3m9q2x7"}4. Schedule the replies
Section titled “4. Schedule the replies”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.
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.'"}}JSONAPI reference: Control API operation
import os, requests
prompt = ( "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.")res = requests.post( f"https://api.slashinfra.com/svms/{os.environ['VM']}/schedules", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={ "name": "answer-telegram", "cron": "*/5 * * * *", "timezone": "UTC", "action": {"type": "command", "command": f"cd /home/user && claude -p --permission-mode bypassPermissions '{prompt}'"}, },)res.raise_for_status()print(res.text)const prompt = '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.'
const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}/schedules`, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'answer-telegram', cron: '*/5 * * * *', timezone: 'UTC', action: { type: 'command', command: `cd /home/user && claude -p --permission-mode bypassPermissions '${prompt}'` }, }),})if (!res.ok) throw new Error(`schedule failed: ${res.status}`)console.log(await res.text()){"name":"answer-telegram",...,"next_at":...}Check it works
Section titled “Check it works”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.
If it doesn’t work
Section titled “If it doesn’t work”| 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.
Clean up
Section titled “Clean up”curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/svms/$VM" \ -H "Authorization: Bearer $SI_API_KEY"API reference: Control API operation
import os, requests
res = requests.delete( f"https://api.slashinfra.com/svms/{os.environ['VM']}", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},)print(res.status_code)const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}`, { method: 'DELETE', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },})console.log(res.status)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.