Skip to content

Commit d145260

Browse files
committed
Update to official API
1 parent 5e12845 commit d145260

27 files changed

+4650
-1166
lines changed

.claude/settings.local.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(pnpm add:*)",
5+
"Bash(npx jest:*)",
6+
"Bash(pnpm build:*)"
7+
],
8+
"deny": [],
9+
"ask": []
10+
}
11+
}

.env.example

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Required
22
BOT_TOKEN=your_telegram_bot_token_here
33
OPENROUTER_API_KEY=your_openrouter_api_key_here
4+
CURSOR_API_KEY=your_cursor_api_key_here
45

56
# Optional: OpenRouter model (default: openai/gpt-4.1)
67
OPENROUTER_MODEL=openai/gpt-4.1
@@ -15,4 +16,14 @@ ALLOWED_USERS=123456,789012
1516
DB_PATH=bot.db
1617

1718
# Custom prompt in case if you wanna add some custom instructions to this instance
18-
CUSTOM_PROMPT="Focus on repos with skipcalls prefix if user asks to add something"
19+
CUSTOM_PROMPT="Focus on repos with skipcalls prefix if user asks to add something"
20+
21+
# Optional: Cursor API caching TTLs (ms)
22+
# Cache repositories list to avoid strict rate limits (default 60000)
23+
CURSOR_REPOS_TTL_MS=60000
24+
# Cache models list for a couple hours (default 7200000)
25+
CURSOR_MODELS_TTL_MS=7200000
26+
27+
# Optional: Mention-only mode (default: false)
28+
# When true, bot only responds to messages that mention it (@botname)
29+
MENTION_ONLY_MODE=false

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ Thumbs.db
2222
# Temporary files
2323
*.tmp
2424
*.temp
25-
docs.md
25+
docs.md
26+
image-cache/

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [1.1.0] - 2025-09-10
4+
5+
Rebuild to work using official Cursor API.
6+
7+
## [1.0.0] - 2025-08-01~
48

59
Added voice message support with Google Gemini AI transcription and custom prompt configuration via `CUSTOM_PROMPT` environment variable. Refactored message processing logic and improved access control for better code maintainability.
610

README.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# Cursor AI Telegram Bot
22

3-
A powerful Telegram bot for managing Cursor AI Background Composers with intelligent task management and real-time monitoring.
3+
A powerful Telegram bot for managing Cursor Background Agents with intelligent task management and real-time monitoring.
44

55
## ✨ Features
66

7-
- 🤖 **AI Task Management**: Start, monitor, and manage Cursor AI coding tasks
8-
- 🔐 **Secure Authentication**: Cookie-based authentication with validation
9-
- 📊 **Real-time Monitoring**: Automatic task progress tracking and notifications
10-
- 💬 **Interactive Interface**: Telegram buttons for external links and actions
11-
- 🛡️ **Security**: Repository and user access control via environment variables
12-
- 📱 **User-friendly**: Simple commands with rich status information
13-
- 🎤 **Voice Messages**: AI-powered voice message transcription using Gemini
14-
- 📸 **Image Support**: Send photos to include in Cursor AI tasks (cached for 3 minutes)
15-
- ⚙️ **Customizable**: Custom prompts and instructions via environment variables
7+
- **AI Task Management**: Start, monitor, follow up, and manage Cursor AI tasks
8+
- **Secure Authentication**: Official API via `CURSOR_API_KEY` (no cookies)
9+
- **Real-time Monitoring**: Automatic task progress tracking and notifications
10+
- **Interactive Interface**: Telegram buttons for external links and actions
11+
- **Security**: Repository and user access control via environment variables
12+
- **User-friendly**: Simple commands with rich status information
13+
- **Voice Messages**: AI-powered voice message transcription using Gemini
14+
- **Image Support**: Send photos to include in Cursor AI tasks (cached for 3 minutes)
15+
- **Customizable**: Custom prompts and instructions via environment variables
1616

1717
### Quick Setup:
1818

1919
1. **Create Telegram Bot**: Message [@BotFather](https://t.me/BotFather)`/newbot`
2020
2. **Get your User ID**: Message [@userinfobot](https://t.me/userinfobot)
21-
3. **Deploy**: Click Railway button, add your `BOT_TOKEN` and `OPENROUTER_API_KEY`
21+
3. **Deploy**: Click Railway button, add your `BOT_TOKEN`, `OPENROUTER_API_KEY`, and `CURSOR_API_KEY`
2222
4. **Volume**: Railway will auto-create volume for `/app/data` (SQLite database storage)
23-
5. **Setup Cursor cookies**: Send your `WorkosCursorSessionToken` to the bot
23+
5. Done — no cookies required
2424

2525
## 🛠️ Local Development
2626

@@ -40,6 +40,7 @@ Create `.env` file:
4040
# Required
4141
BOT_TOKEN=your_telegram_bot_token_here
4242
OPENROUTER_API_KEY=your_openrouter_api_key_here
43+
CURSOR_API_KEY=your_cursor_api_key_here
4344
4445
# Optional: OpenRouter model (default: openai/gpt-4.1)
4546
OPENROUTER_MODEL=openai/gpt-4.1
@@ -57,17 +58,7 @@ GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key_here
5758
CUSTOM_PROMPT="Focus on repos with skipcalls prefix if user asks to add something"
5859
```
5960

60-
### 3. Setup Cursor API Cookies
61-
62-
1. Go to [https://cursor.com/agents](https://cursor.com/agents)
63-
2. Open Developer Tools (F12)
64-
3. Go to Network tab
65-
4. Refresh the page
66-
5. Find any request to cursor.com
67-
6. Copy the entire Cookie header value
68-
7. Send it to the bot. YOU NEED ONLY WorkosCursorSessionToken cookie value. Send it in format WorkosCursorSessionToken=...
69-
70-
### 4. Run the Bot
61+
### 3. Run the Bot
7162

7263
```bash
7364
pnpm run build
@@ -80,7 +71,6 @@ pnpm start
8071
|---------|-------------|
8172
| `/start` | Welcome message and setup guide |
8273
| `/tasks` | View your active tasks |
83-
| `/cookies` | Get cookie setup instructions |
8474
| `/help` | Show available commands |
8575
| 🎤 **Voice Messages** | Send voice messages for AI transcription and processing |
8676

@@ -91,6 +81,9 @@ pnpm start
9181
| `BOT_TOKEN` | Yes | Telegram bot token from @BotFather |
9282
| `OPENROUTER_API_KEY` | Yes | OpenRouter API key for AI functionality |
9383
| `OPENROUTER_MODEL` | No | OpenRouter model (default: 'openai/gpt-4.1') |
84+
| `CURSOR_API_KEY` | Yes | API key for official Cursor Background Agents API |
85+
| `CURSOR_REPOS_TTL_MS` | No | In-memory cache TTL for `/v0/repositories` (default: 60000) |
86+
| `CURSOR_MODELS_TTL_MS` | No | In-memory cache TTL for `/v0/models` (default: 7200000, i.e. 2 hours) |
9487
| `ALLOWED_REPOS` | No | Comma-separated list of allowed repository URLs |
9588
| `ALLOWED_USERS` | No | Comma-separated list of allowed Telegram user IDs |
9689
| `DB_PATH` | No | Database file path (defaults to 'bot.db', Railway: '/app/data/bot.db') |
@@ -99,9 +92,8 @@ pnpm start
9992

10093
## 🛡️ Security
10194

102-
- **No Cookie Exposure**: The bot never exposes actual cookie values
95+
- **No Secrets Exposure**: The bot never exposes API keys or secrets
10396
- **Repository/User Control**: Optional repository and user access control via environment variables
104-
- **Authentication Validation**: Cookies are validated before every operation
10597
- **Operation Tracking**: All actions are logged for audit purposes
10698

10799
## 📖 Usage Examples
@@ -160,7 +152,7 @@ Bot: 📊 Active Tasks (2):
160152

161153
## 🔄 Task Lifecycle
162154

163-
1. **Start**: Create background composer task in repository
155+
1. **Start**: Create background agent task in repository
164156
2. **Monitor**: Real-time status tracking and updates
165157
3. **Notify**: Automatic notifications on completion/failure
166158
4. **Manage**: Stop or cancel running tasks as needed
@@ -191,7 +183,7 @@ The bot uses SQLite with the following main tables:
191183
## 📝 API Integration
192184

193185
The bot integrates with:
194-
- **Cursor API**: For background composer management
186+
- **Cursor API**: For Background Agents management (official API)
195187
- **OpenRouter API**: For AI-powered interactions
196188
- **Telegram Bot API**: For messaging and user interface
197189

@@ -215,4 +207,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
215207

216208
---
217209

218-
**Ready to supercharge your Cursor AI workflow with intelligent automation!** 🚀
210+
**Ready to supercharge your Cursor AI workflow with intelligent automation!** 🚀

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/src'],
5+
testMatch: ['**/__tests__/**/*.test.ts'],
6+
collectCoverageFrom: [
7+
'src/**/*.ts',
8+
'!src/**/*.d.ts',
9+
'!src/index.ts',
10+
'!src/**/__tests__/**',
11+
],
12+
coverageDirectory: 'coverage',
13+
coverageReporters: ['text', 'lcov', 'html'],
14+
setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
15+
testTimeout: 30000,
16+
verbose: true,
17+
};

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
"name": "cursor-telegram-bot",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Telegram bot for managing Cursor AI background composers",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "tsc",
88
"dev": "tsc && node dist/index.js",
99
"dev:watch": "tsc --watch",
1010
"start": "node dist/index.js",
11-
"test": "echo \"Error: no test specified\" && exit 1"
11+
"start:30s": "tsc && node dist/bot-run-30s.js",
12+
"smoke": "tsc && node dist/smoke.js",
13+
"test": "jest",
14+
"test:watch": "jest --watch",
15+
"test:coverage": "jest --coverage"
1216
},
1317
"keywords": [
1418
"cursor",
@@ -17,10 +21,13 @@
1721
"bot",
1822
"background-composer"
1923
],
20-
"author": "",
21-
"license": "ISC",
24+
"author": "Hormold (Nikita Podelenko)",
25+
"license": "MIT",
2226
"devDependencies": {
27+
"@types/jest": "^30.0.0",
2328
"@types/node": "^20.19.7",
29+
"jest": "^30.1.3",
30+
"ts-jest": "^29.4.1",
2431
"typescript": "^5.8.3"
2532
},
2633
"dependencies": {
@@ -37,4 +44,4 @@
3744
"sharp": "^0.33.5",
3845
"zod": "^3.25.76"
3946
}
40-
}
47+
}

0 commit comments

Comments
 (0)