Skip to content

Telegram: threaded conversation support - #1597

Merged
steipete merged 6 commits into
openclaw:mainfrom
rohannagpal:feat/telegram-dm-threads
Jan 25, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
rohannagpal:feat/telegram-dm-threads

Conversation

@rohannagpal

Copy link
Copy Markdown
Contributor

Summary

Adds DM thread awareness to Telegram sessions and improves inbound logging to
make DM threads observable and testable.

Why

Adds support for threaded conversations in Telegram.

How

  • Derives a thread-aware session key for DM topics so each thread becomes its
    own session context.
  • Keeps DM history limits stable by stripping thread suffixes when parsing
    session keys.
  • Adds verbose raw-update logging so inbound DM thread ids are visible during
    debugging.
  • Adjusts DM command targeting to respect thread-aware session keys.
  • Adds coverage for DM thread keying, DM command targeting, and DM history-
    limit parsing.

Tests

  • pnpm test (Full suite, vm)
  • pnpm test src/telegram/bot-message-context.DM-threads.test.ts
  • pnpm test src/telegram/bot.test.ts
  • pnpm test src/agents/pi-embedded-runner.get-DM-history-limit-from-session- key.returns-undefined-sessionkey-is-undefined.test.ts

Manual testing

  • With DM threads enabled, I sent two DM messages in different threads and
    confirmed distinct sessions in /status and different message_thread_id
    values in logs.
  • With DM threads disabled, I sent DM messages and confirmed
    message_thread_id was absent in logs and sessions behaved as a single
    thread.

Breaking changes

None.

Changelog

Added entries under 2026.1.23 (Unreleased).

AI assistance

  • AI-assisted: Yes
  • Testing: Fully tested (Unit + integration + manual DM checks)
  • Prompts/logs: Available in session history and vm logs if needed
  • Understanding: I tested it thoroughly, used /review in codex, and skimmed
    through the code.

@steipete steipete self-assigned this Jan 25, 2026
@steipete
steipete merged commit 06a7e1e into openclaw:main Jan 25, 2026
@steipete

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: a7b13c4\n- Merge commit: 06a7e1e\n\nThanks @rohannagpal!

@e-jung

e-jung commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

hi - i'm not technical but i was dealing with a routing issue and this is what my ai agent fixed/suggested:

Summary for GitHub Comment
PR #1597 introduced a regression bug that affects all direct message channels (Telegram, Slack, Discord, iMessage, Signal, LINE, WebChat).

What the PR was trying to do:
Add support for Telegram DM threads so each thread gets its own session context.

The Bug:
In the code that updates delivery routing when a DM message arrives, it always uses route.mainSessionKey (points to main webchat session) instead of the correctly calculated sessionKey variable.

Impact: When you send a DM from Telegram/Slack/etc., the main session's routing gets corrupted - messages show as coming from wrong channel, and responses get routed to web UI instead of back to Telegram.

Simple fix: Change one line in each channel file:
// Wrong (current code):
sessionKey: route.mainSessionKey
// Should be:
sessionKey: sessionKey

This bug exists in 6 different channel files:

  • telegram/bot-message-context.js (line 392) - Fixed locally
  • slack/monitor/message-handler/prepare.js (line 441)
  • discord/monitor/message-handler.process.js (line 230)
  • line/bot-message-context.js (lines 221, 350)
  • imessage/monitor/monitor-provider.js (line 457)
  • signal/monitor/event-handler.js (line 114)
  • web/auto-reply/monitor/process-message.js (line 221)

The fix is identical for all channels - just swap route.mainSessionKey to sessionKey in the updateLastRoute call.

@zhixianio

Copy link
Copy Markdown
Contributor

Hi @rohannagpal! Thanks for this feature 🙌

I'm on 2026.1.24-3 with DM topics fully enabled (BotFather setting on, thread UI visible in Telegram). However, messages from different DM threads still go to the same session (agent:main:telegram:dm: without thread suffix).

I checked the gateway logs but don't see any message_thread_id being logged. Is there a way to enable verbose/raw update logging to verify if Telegram is actually sending message_thread_id for DM threads?

Any pointers appreciated!

@rohannagpal

Copy link
Copy Markdown
Contributor Author

@louzhixian this works for me:

  • Set file log level to debug: clawdbot config set logging.level debug
  • Restart the gateway.
  • Send a DM message and look for telegram update: lines in the gateway logs; they include message_thread_id if Telegram sends it.

@zhixianio

Copy link
Copy Markdown
Contributor

Thanks a lot!

@rohannagpal

Copy link
Copy Markdown
Contributor Author

@e-jung my changes did not touch any of the lines highlighted in your comment. What exactly is the routing issue that you are/were running into?

@zhixianio

Copy link
Copy Markdown
Contributor

@rohannagpal Somehow the bot told me that it can see the separated sessions now, thanks!
Btw, any plan to support the drafting message sending api? Messages in threads are duplicated during generating process which is king of annoying 😂

@rohannagpal

rohannagpal commented Jan 26, 2026 via email

Copy link
Copy Markdown
Contributor Author

rodrigouroz pushed a commit to rodrigouroz/openclaw that referenced this pull request Jan 26, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
dgarson pushed a commit to dgarson/clawdbot that referenced this pull request Feb 2, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
dustin-olenslager pushed a commit to dustin-olenslager/ironclaw-supreme that referenced this pull request Mar 24, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
zeekay pushed a commit to Dream-AI-4444/bot that referenced this pull request Sep 11, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
* Telegram: isolate dm topic sessions

* Tests: cap vitest workers

* Tests: cap Vitest workers on CI macOS

* Tests: avoid timer-based pi-ai stream mock

* Tests: increase embedded runner timeout

* fix: harden telegram dm thread handling (openclaw#1597) (thanks @rohannagpal)

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants