← Back to Blog

How to Run an AI Telegram Bot Agent with OE Runtime

Connect your Telegram bot to OE Runtime and automate message monitoring and notifications. The agent reads recent bot updates, summarises incoming messages, and sends AI-composed notifications back to any chat — all from a single YAML file with no code.

Step 1
Verify Bot Connection
Call getMe to confirm the bot is live and note its username and ID.
Step 2
Read Recent Updates
Fetch the last 10 messages sent to the bot. Note chat IDs, senders, and message text.
Step 3
Send Notification
Compose and send an AI-written summary notification to the target chat.

Prerequisites: Create a Telegram Bot

  1. Open Telegram and search for @BotFather
  2. Send /newbot and follow the prompts to name your bot
  3. Copy the Bot Token BotFather gives you (format: 123456789:ABCdef...)
  4. To find your chat_id: send any message to your bot, then call https://api.telegram.org/bot<TOKEN>/getUpdates in a browser — look for message.chat.id in the response

The Agent YAML

Create a file called agent.yaml inside a telegram/ directory:

name: Telegram Notifier
description: Read recent Telegram messages and send a summary notification
instructions: |
  You are a Telegram bot agent. Read recent updates from the bot and send notification messages.
  Always confirm the bot is connected before reading messages.
  Complete all steps fully before writing your report.
steps:
  - name: Verify Bot Connection
    content: |
      Call the Telegram connector:
      GET /getMe
      Note the bot username, id, and display name to confirm the connection is working.

  - name: Read Recent Updates
    content: |
      Call the Telegram connector:
      GET /getUpdates with params: { "limit": "10", "allowed_updates": "message" }
      For each message note: chat_id, from username, message text, and date.
      Remember the chat_id from the most recent message — you will use it to send the reply.
      If no updates are found, note that the bot has no recent messages and skip the next step.

  - name: Send Summary Notification
    content: |
      Compose a brief summary of the recent messages.
      Use the chat_id from the most recent update (from Step 2).
      Send it via the Telegram connector:
      POST /sendMessage with body:
      {
        "chat_id": <chat_id from Step 2>,
        "text": "<your summary message>",
        "parse_mode": "Markdown"
      }

  - name: Report
    content: |
      Summarize what was done:
      - Bot name and username confirmed
      - Number of recent messages read
      - Summary of message content
      - Notification sent to chat_id (confirm with message_id returned)
connectors:
  - connection_name: My Telegram Bot
    connection_type: telegram

The Config File

Create oe-config.json in the same directory. The Telegram Bot Token is embedded directly in the baseUrl — no separate auth header is required:

{
  "llm": {
    "provider": "openai",
    "model": "gpt-4o",
    "apiKey": "YOUR_OPENAI_API_KEY"
  },
  "server": {
    "enabled": false,
    "port": 3333,
    "apiKey": "your-secret-api-key"
  },
  "connectors": [
    {
      "connection_name": "My Telegram Bot",
      "connection_type": "telegram",
      "baseUrl": "https://api.telegram.org/botYOUR_BOT_TOKEN"
    }
  ]
}

Replace YOUR_BOT_TOKEN with the token from BotFather. The token becomes part of the URL — this is how the Telegram Bot API authenticates requests.

Download OE Runtime

OE Runtime — Direct Downloads

Run the Agent

Windows

# Run the agent (pass your chat_id as a param)
oe-runtime-win.exe telegram/agent.yaml --config telegram/oe-config.json

macOS

# Make executable (first time only)
chmod +x oe-runtime-macos

# Run the agent
oe-runtime-macos telegram/agent.yaml --config telegram/oe-config.json

Linux

# Make executable (first time only)
chmod +x oe-runtime-linux

# Run the agent
oe-runtime-linux telegram/agent.yaml --config telegram/oe-config.json

macOS Gatekeeper: On first run, macOS may block the binary. Go to System Settings → Privacy & Security → click "Allow Anyway" next to oe-runtime-macos.

No chat_id needed: The agent reads the chat_id automatically from the most recent message in getUpdates. Just send any message to your bot before running the agent and it will reply to that chat.

Running as an API Server

Add --serve to start OE Runtime as an HTTP server on port 3333:

oe-runtime-win.exe --serve --config telegram/oe-config.json

Then trigger the agent via API:

curl -X POST http://localhost:3333/run \
  -H "Content-Type: application/json" \
  -d '{"yaml": "telegram/agent.yaml", "params": {}}'

Use Cases

Build your own agents with OE Runtime

Download OE Runtime and run any AI agent locally or as a server — no cloud required.

Get OE Runtime →