Skip to main content

Command Palette

Search for a command to run...

Build an AI Agent That Notifies You on Telegram Using Claude Code Channels

15-minute setup: Claude Code + OpenClaw + Telegram for real-time agent alerts on your phone.

Published
5 min read
U
I'm building payment rails for agent-to-agent payments

I've been running Claude Code as my primary agent for months. It writes code, deploys services, manages trading systems, monitors infrastructure. One thing always bugged me: when something happened at 3 AM, I'd find out at 9 AM by reading logs.

Claude Code Channels changed that. And Telegram is the perfect delivery endpoint.

This tutorial walks through the full setup: Claude Code running on your machine, connected via channels to a Telegram bot that pushes real-time notifications to your phone. Trading alerts, deployment failures, monitoring events, whatever your agent surfaces.

What you're building

The stack:

  • Claude Code running as your agent (local or remote)
  • OpenClaw as the channel bridge (manages message routing between Claude Code and external services)
  • Telegram Bot as your notification endpoint
  • Your phone getting push notifications when your agent has something to say

Total setup time: about 15 minutes.

Step 1: Set up a Telegram bot

Open Telegram, search for @BotFather, and start a chat.

/newbot

BotFather asks for a name and username. Pick something descriptive. I use AgentAlerts_bot but anything works.

You'll get a token that looks like this:

7891234567:AAHx_your-bot-token-here

Save that. You need it in a minute.

Now get your chat ID. The simplest way: message your new bot, then hit this URL in a browser:

https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates

Find "chat":{"id":123456789} in the response. That number is your chat ID.

Step 2: Install and configure OpenClaw

If you don't have OpenClaw installed:

npm install -g openclaw
openclaw init

OpenClaw manages channels. A channel is a connection between your agent and an external messaging service. Telegram is a built-in channel type.

Add Telegram to your OpenClaw config (usually ~/.openclaw/config.yaml):

channels:
  telegram:
    type: telegram
    token: "7891234567:AAHx_your-bot-token-here"
    allowFrom:
      - "your-telegram-username"
    chatId: 123456789

The allowFrom field restricts who can send commands back to your agent through Telegram. Lock this down.

Start the gateway:

openclaw gateway start

Test the connection:

openclaw gateway status

You should see telegram: connected in the output.

Step 3: Configure Claude Code channels

Claude Code Channels let Claude Code send and receive messages through external services. OpenClaw acts as the bridge.

In your workspace, your agent can now use the message tool to send to Telegram:

// Inside your agent's tool calls
message({
  action: "send",
  channel: "telegram",
  target: "123456789",
  message: "BTC crossed $72,000. Current position: +2.3%"
})

That's it. Your agent sends a message, OpenClaw routes it through the Telegram bot, and it hits your phone as a push notification.

Step 4: Build useful alert patterns

The raw capability is simple. The value is in what you trigger on.

Trading alerts

If you're running trading bots (we run BTC perp traders, range traders, and Polymarket bots), wire up threshold alerts:

# In your trading loop
if current_pnl > threshold or drawdown > max_drawdown:
    send_telegram_alert(
        f"Trading alert: {strategy_name}\n"
        f"P&L: ${current_pnl:.2f}\n"
        f"Drawdown: {drawdown:.1f}%\n"
        f"Action: {'HOLD' if within_limits else 'REVIEW'}"
    )

Deployment notifications

After a CI run completes or a Docker container restarts:

# In your deployment script
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
  -d "chat_id=${CHAT_ID}" \
  -d "text=Deploy complete: agentpay-mcp v2.1.3 -> production"

Infrastructure monitoring

Agent checks system health and reports anomalies:

# Health check loop
if docker_container_unhealthy(container):
    alert(f"Container {container} unhealthy. Restarting...")
    restart_container(container)
    alert(f"Container {container} restarted. Status: {get_status(container)}")

Cron failure alerts

When a scheduled job fails, you want to know immediately, not next morning:

if cron_job.consecutive_errors >= 3:
    alert(
        f"Cron alert: {cron_job.name}\n"
        f"Errors: {cron_job.consecutive_errors} consecutive\n"
        f"Last error: {cron_job.last_error[:200]}"
    )

Step 5: Two-way communication

Channels aren't just for outbound. You can send commands back through Telegram and your agent will process them.

Message your bot:

check trading status

Your agent receives this through the channel, processes it, and responds through Telegram:

Trading Status (March 20, 2026):
- BTC Perp: +$63.29 (92% win rate)
- Grid Trader: +$55.06 (500 trades)
- Bond Harvest: +$145.65 (6 open)
Total: +$219.00

This turns Telegram into a mobile command interface for your agent stack.

What I actually use this for

Three things dominate my notification feed:

  1. Trading threshold alerts when any position crosses a P&L or drawdown limit. I get maybe 2-3 of these per day. Enough to stay informed, not enough to be noise.

  2. CI/deployment results when GitHub Actions complete or Docker containers restart. These come in bursts during active development.

  3. Daily summaries where the agent compiles a morning briefing, sends it at 7 AM. Market conditions, overnight trading results, pending tasks, system health. One message, full context.

The Telegram setup took 15 minutes. It's saved me hours of log-reading and dashboard-checking. Your agent already knows what's happening. Channels just let it tell you.

Common gotchas

Bot token security: Don't commit your bot token to git. Use environment variables or a secrets manager. OpenClaw's config file should be in .gitignore.

Rate limits: Telegram's bot API allows about 30 messages per second. If your agent is chatty, batch messages or add a cooldown.

Message formatting: Telegram supports basic HTML (<b>, <i>, <code>) and Markdown in messages. Use parse_mode: "HTML" for richer formatting.

Chat ID gotcha: Group chat IDs are negative numbers. Direct message chat IDs are positive. If you're sending to a group, make sure you're using the right ID.

This article was written with AI assistance. All technical claims, code, and architectural decisions were validated by the author.