Skip to content

Per-chat personas and isolated contexts via Telegram forum topics #14

Description

@mattmezza

Summary

Allow multiple concurrent chats, each bound to its own persona and its own conversation context,
following the existing Telegram interaction model.

Background

History is already keyed by (channel, user_id, chat_id) and the session system prompt is
snapshotted per chat, so isolated contexts already exist by construction. Two gaps remain: (1) a
chat→persona binding, and (2) a way to run several contexts within Telegram.

Proposed approach

Primary — Telegram forum topics. In a group with topics enabled, each message carries
message_thread_id / is_topic_message. Fold the thread id into the context key
(chat_id = f"{chat_id}:{thread_id}") so every topic is a separate context natively, with its own
scrollback. Bind a persona per thread via topic-name → persona, or a /persona <name> command
storing the mapping in a small chat_persona(chat_id -> persona) table. The General topic maps to
the default persona.

Fallback (no group) — modal rooms in a 1:1 DM. /room <name> switches the active room
(synthetic chat_id + persona) until switched again. Modal, so the bot should echo the active
persona on switch to avoid sending to the wrong one.

UX & product

  • Onboarding is the hard part and is self-guiding: when the bot is added to a group it detects
    topics support and replies with a short, illustrated walkthrough (enable Topics, promote the bot,
    one topic per persona). A /setup_topics helper checks the group and reports what's missing.
  • Admin UI: a Chats page listing active chats/threads and their bound persona, with rebind —
    responsive/touch-friendly at phone width, using consistent list/card components.
  • On the go (Telegram): binding happens entirely in-app via /persona inside a topic; inline
    buttons pick the persona for a new topic. Consistent inline-keyboard conventions throughout.
  • Mobile-first: the whole flow is native to the Telegram phone app — no web UI is required to
    create or use a themed chat; lean into it.

Setup & onboarding

  • Works with a single default context if the user never makes a group (no setup required, works out
    of the box).
  • The group/topic path is opt-in; surfaced as an optional wizard step ("set up multiple chats?")
    that links to the in-Telegram walkthrough.

Acceptance criteria

  • Two topics in the same group keep fully separate histories and personas.
  • /persona rebinds only the current thread.
  • Adding the bot to a topics-enabled group yields a clear, mobile-only setup path with no web UI;
    the Chats page is usable at phone width.
  • No regression to the default 1:1 DM flow.

Related

  • Depends on: persona profiles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    newNew additiontodoPlanned / not yet started

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions