Per-Topic AI Routing in Telegram Forums with OpenClaw

When you have six projects and one AI assistant, you need six conversations — not one.

The Problem

I run multiple projects out of a single Telegram group. Before this setup, every message to my AI assistant (Asere) landed in the same conversation thread. Ask about a Redmine deployment? Same context as a Brazilian motorcycle rental app. Ask about an Odoo invoice? Same session as a chatbot platform discussion.

Context pollution kills productivity. The AI doesn't know which project you're talking about, so it either guesses wrong or asks clarifying questions that slow everything down.

The Setup

Telegram has a feature called Forum Groups — they're essentially Discord-style topic channels inside a regular group. Each topic gets its own thread. OpenClaw (the framework powering Asere) added native per-topic routing in version 2026.3.7.

Here's what I wanted:

  • One Telegram group ("Zczoft") with a topic per project
  • Each topic gets its own AI session with project-specific context
  • Asere knows which project he's in — Odoo IDs, code paths, server IPs, tech stack — without me repeating it every time

Creating Topics with Telethon

You can't create forum topics through the Bot API. You need the Telegram Client API, which means Telethon (Python):

from telethon.tl.functions.messages import CreateForumTopicRequest

result = await client(CreateForumTopicRequest(
    peer=entity,
    title="Mobílli",
    icon_color=0xFF93B2,  # pink
    random_id=random_id
))
topic_id = result.updates[1].message.id

One gotcha that cost me 30 minutes: it's messages.CreateForumTopicRequest, not channels.CreateForumTopicRequest. The Telethon docs aren't super clear on this, and auto-complete will happily suggest the wrong one.

I created four topics: Mobílli (pink), Trabitat/Falitech (blue), OK CarHire (yellow), and Somos Más (green). Color-coding helps when scanning the group.

Bot Admin Headaches

The bot needs to be a group admin with the manage_topics permission. Sounds simple, but Telethon's client.edit_admin() helper doesn't expose the manage_topics flag. You have to drop to the raw API:

from telethon.tl.functions.channels import EditAdminRequest
from telethon.tl.types import ChatAdminRights

await client(EditAdminRequest(
    channel=entity,
    user_id=bot_entity,
    admin_rights=ChatAdminRights(
        post_messages=True,
        edit_messages=True,
        delete_messages=True,
        manage_topics=True
    ),
    rank="AI Assistant"
))

Also, the bot needs privacy mode off (or admin status) to receive all group messages. Otherwise Telegram only forwards messages that explicitly mention the bot.

OpenClaw Configuration

Here's where it gets interesting. OpenClaw's config lets you define per-topic settings under channels.telegram.groups:

{
  "channels": {
    "telegram": {
      "groups": {
        "-1003772478485": {
          "topics": {
            "42": {
              "enabled": true,
              "requireMention": false,
              "systemPrompt": "You are working on Mobílli..."
            }
          }
        }
      }
    }
  }
}

Each topic gets:

  • Its own session: agent:asere:telegram:group:<id>:topic:<threadId> — completely isolated from other topics
  • A custom system prompt: I pack it with everything Asere needs — Odoo project ID, relevant repo paths, staging/production URLs, tech stack, deployment commands
  • Independent mention behavior: some topics require @mention, others respond to everything

What Changed

Before: one conversation, constant context-switching, "wait, which project are we talking about?"

After:

  • Drop into the Mobílli topic → Asere is already in Brazil mode
  • Switch to Trabitat → different session, different context, chatbot platform knowledge loaded
  • Jump to OK CarHire → Odoo 18, Punta Cana, vehicle rental domain

No context bleeding. No "remind me which server." Each topic is a fresh workspace with the right tools pre-loaded.

The Real Win

This isn't just about organizing chat threads. It's about reducing the cognitive load on both sides — I don't have to re-explain context, and the AI doesn't waste tokens figuring out which project I mean.

The setup took about two hours (including debugging the wrong Telethon function and the group policy misconfiguration). The time saved per day easily pays that back.

If you're running multiple projects through a single AI assistant, per-topic routing is the difference between "useful tool" and "indispensable teammate."


Built with OpenClaw. Topic creation via Telethon 1.42.0. All config examples simplified for readability.

← Back to Blog