# Build a personal bot

Connect a Telegram bot to a VM that sleeps, let a schedule answer each message with an agent, and keep its memory in a file.

Source: https://slashinfra.com/docs/build/personal-bots
Last modified: 2026-11-30T16:36:19.000Z

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

- An approved [account](https://app.slashinfra.com/) and an API key from the [API keys](https://app.slashinfra.com/keys) page. 
- A Telegram account and a bot token from [@BotFather](https://t.me/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.

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

## 1. Create the bot’s VM

Create the VM. The first request starts it.

### curl

```bash
curl -sS -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d '{"name":"personal-bot"}'
```

### Python

```python
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)
```

### TypeScript

```ts
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())
```

Output

```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](https://slashinfra.com/docs/agents/claude-code). The schedule in step 4 runs `claude`, and it needs that sign-in.

```bash
export VM=6f1c0f0e8a
```

## 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

```bash
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}'
```

### Python

```python
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)
```

### TypeScript

```ts
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())
```

Output

```text
{"address":"6f1c0f0e8a@slashinfra.dev","enabled":true,...}
```

## 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

```bash
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\"}"
```

### Python

```python
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)
```

### TypeScript

```ts
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())
```

Output

```text
{"bot_username":"build_1_bot","pair_code":"k3m9q2x7"}
```

## 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

```bash
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
```

### Python

```python
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)
```

### TypeScript

```ts
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())
```

Output

```text
{"name":"answer-telegram",...,"next_at":...}
```

## 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

| 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`](https://slashinfra.com/docs/api-reference/control/inbox#postSvmsByRefInboxTelegramPair), 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`](https://slashinfra.com/docs/api-reference/control/schedules#getSvmsByRefSchedulesByIdRuns), then sign in to Claude Code if the run failed. |

## Clean up

> Caution
> 
> 
> 
> Deletes the bot’s VM, its memory file and its saved messages. Copy the memory file first if you want to keep it. Deletion cannot be undone.

### curl

```bash
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/svms/$VM" \
-H "Authorization: Bearer $SI_API_KEY"
```

### Python

```python
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)
```

### TypeScript

```ts
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)
```

Output

```text
204
```

## Next

- [Email](https://slashinfra.com/docs/platform/email): the same inbox takes mail, which wakes the VM too. 
- [Schedules](https://slashinfra.com/docs/platform/schedules): the schedule rules, the minimum gap between runs and the message action. 
- [Sleep and wake](https://slashinfra.com/docs/how/sleep-and-wake): what the VM keeps while it sleeps, and what wakes it.
