DevConda — blog-workspace

Run Cursor Agent from Telegram

When should you read this?

You want to talk to a coding agent from your phone – check logs, tweak a script, ask for status – without remote-desktop into your machine and without setting up Slack. Cursor Automations are fine for cloud cron jobs. The chat you actually care about usually needs your working tree, env files, and local scripts. This post is that setup: Telegram in, local Cursor agent out.

What you are building

Phone (Telegram)
    <->  Bot API
Node bridge on the PC (always on)
    <->  @cursor/sdk  Agent.create / resume / send
Local Cursor agent (cwd = your repo)
    <->
Same disk: secrets/, scripts/, working tree
Telegram to local Cursor agent through a Node bridge
Telegram to local Cursor agent through a Node bridge

Three rules that keep the design honest:

  1. Telegram does not talk to Cursor by itself. Something on your machine has to call both APIs.
  2. The bridge polls Telegram. Cursor does not poll your bot. Idle getUpdates does not burn Cursor usage.
  3. A Telegram session is not your IDE chat. It has its own agentId. /new starts a new one.
The bridge polls Telegram; the agent does not
The bridge polls Telegram; the agent does not

Why not Slack (for a solo operator)

Slack fits teams and channels. For one person and one bot:

  • Create a bot, keep the token on disk, store your chat id.
  • No workspace admin work just to DM yourself.
  • Charts and screenshots are a single sendPhoto.

If you need channels and threads later, use Slack. For "me and the agent," Telegram is enough.

The bridge process

This is a long-running Node script, not an HTTP server bound to a port.

On start it:

  1. Loads TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, and CURSOR_API_KEY from a gitignored secrets/ folder.
  2. Calls Telegram getMe, then loops on getUpdates (long poll).
  3. Ignores every chat except yours.
  4. Handles /help and /new in the bridge.
  5. For anything else: Agent.resume(agentId) (or create), send, wait, then sendMessage back (split to fit Telegram’s length limit).
One user message: getUpdates to sendMessage
One user message: getUpdates to sendMessage

If you send Telegram text from PowerShell 5, do not put Korean (or other non-ASCII) as string literals in the .ps1. Read UTF-8 template files with an explicit UTF-8 encoding. Prefer JSON UTF-8 bytes or curl --data-binary over default form encoding.

Local vs cloud agent

Local vs cloud agent: cwd and secrets
Local vs cloud agent: cwd and secrets
Local (local: { cwd })Cloud
ModelHosted by Cursor either waySame
FilesYour working treeFresh clone
Secretssecrets/ on diskInject via env / dashboard
Best whenThe PC stays onThe PC is off, or you need many parallel runs

"Local" means the agent loop and filesystem run on your PC. The model still runs on Cursor’s side. Agent.send bills like other Cursor agent use – even a short "hi" counts. Bridge-only /help does not.

If the PC is always on for this workflow, moving only the bridge to EC2 mostly adds latency and cost. Keep the bridge next to the agent.

Daily push without Windows Task Scheduler

Cursor Automations are a clean way to run a cloud agent on a cron. If you want the same local agent that already owns the Telegram thread, schedule inside the bridge:

  • About every 20 seconds, read the local timezone (for example Asia/Seoul).
  • At a fixed clock time, once per calendar day, enqueue a job – for example:
    1. Run a cost or health report script and send charts to Telegram.
    2. Ask the local agent for a short status summary from live APIs or logs, not from stale folders.

Put DM handling and that daily job on one promise chain so they do not overlap mid-run.

Operability on Windows

Details that matter after the first successful DM:

  • If you start the bridge inside a Cursor IDE terminal, closing the IDE can kill the bot. Prefer a hidden host (for example a PowerShell NotifyIcon tray app).
  • Tray menu: status, Restart, Quit.
  • A small .exe launcher plus a desktop shortcut is easier to pin to the taskbar than a .vbs (Windows often blocks scripted "Pin to taskbar").
  • Never commit bot tokens or CURSOR_API_KEY. Rotate anything that was pasted into a chat.
Daily job inside the bridge plus Windows tray menu
Daily job inside the bridge plus Windows tray menu

What this is not

  • Not a drop-in for Cursor Automations when you want cloud-only cron with no PC.
  • Not a shared team inbox – gate on your chat id.
  • Not the same transcript as the IDE chat. Use /new when context goes stale, and seed the agent to check live state before it suggests next steps.

Minimal checklist

  1. BotFather token -> secrets/telegram.env (chat id is yours, not the bot id prefix).
  2. Cursor API key -> secrets/cursor.env.
  3. Bridge cwd = the repo the agent should read and edit.
  4. Keep the process running (tray / shortcut). Confirm a DM round-trip.
  5. Optional: in-process daily job for reports plus a short agent summary.

After that, you can drive the agent from Telegram. The repo and secrets stay on the PC.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *