telegram-bot

A set of project rules for connecting OpenClaw agents to Telegram, a messaging service. It covers creating a bot, storing its token and chat ID, sending plain-text messages, and handling message formatting safely.

In plain words
What is it for?
Use it when setting up or modifying Telegram bot messaging for OpenClaw agents, including finding the destination chat and sending text through Telegram’s API.
Why use it?
It gives developers the required setup details and avoids Telegram rejecting messages because dynamic text contains characters that conflict with Markdown formatting.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mergisi/openclaw-rules/telegram-bot
Clone the repo
git clone --depth 1 https://github.com/mergisi/openclaw-rules
Per session 640 This file is loaded in full into every session.
When invoked 640 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00640 $0.00640
Opus 5 $0.00320 $0.00320
Sonnet 5 $0.00128 $0.00128
Haiku 4.5 $0.00064 $0.00064

Measured 2d ago against content hash 33878337da1c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

telegram-bot scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

project-rules/telegram-bot.mdc · 87 lines

How it starts

The opening of the file, as written. The whole thing — 87 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Telegram Bot Integration

When setting up or modifying Telegram bot integration for OpenClaw agents.

Setup

  1. Create a bot via @BotFather on Telegram
  2. Save the token (format: 1234567890:ABCdefGHIjklMNOpqrSTUvwxYZ)
  3. Get your chat ID by messaging @userinfobot
  4. Add to secrets: TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID

Sending Messages

function sendTelegram(token, chatId, text) {
  return new Promise((resolve, reject) => {
    const body = JSON.stringify({ chat_id: chatId, text: text });
    const req = require("https").request({
      hostname: "api.telegram.org",
      path: `/bot${token}/sendMessage`,
      method: "POST",
      headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) },
    }, res => {
      let b = "";
      res.on("data", d => b += d);
      res.on("end", () => resolve(JSON.parse(b)));
    });
    req.on("error", reject);
    req.write(body);
    req.end();
  });
}

Important: Use Plain Text

Never use parse_mode: "Markdown" or parse_mode: "MarkdownV2". Dynamic content (URLs, titles, code) often contains []_* characters that break Markdown parsing and cause "Bad Request: can't parse entities" errors.

Always send plain text. If you need formatting, use parse_mode: "HTML" which is more forgiving.

Message Length Limits

Telegram messages have a 4096 character limit. For long reports:

function sendLongMessage(token, chatId, text) {
  const chunks = [];
  const lines = text.split("\n");
  let current = "";

  for (const line of lines) {
    if ((current + "\n" + line).length > 4000) {
      chunks.push(current);
      current = line;
    } else {
      current += (current ? "\n" : "") + line;
    }
  }
  if (current) chunks.push(current);

  return chunks.reduce((p, chunk, i) =>
    p.then(() => sendTelegram(token, chatId, chunk))
      .then(() => i < chunks.length - 1 ? new Promise(r => setTimeout(r, 500)) : null),
    Promise.resolve()
  );
}

Read the full file on GitHub · 87 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 87 lines · 640 tokens per session scan A 33878337da1c

Subscribe to this mod's changes

telegram-bot is a cursor rule published in the GitHub repository mergisi/openclaw-rules (2 stars, last pushed 6mo ago), licensed MIT. It adds 640 tokens to every session, about $0.0032 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.