Skip to content

[AI-Assisted] Add Telegram topics/forum support#334

Closed
RandyVentures wants to merge 4 commits intoopenclaw:mainfrom
RandyVentures:feat/telegram-topics-support
Closed

[AI-Assisted] Add Telegram topics/forum support#334
RandyVentures wants to merge 4 commits intoopenclaw:mainfrom
RandyVentures:feat/telegram-topics-support

Conversation

@RandyVentures
Copy link
Copy Markdown
Contributor

@RandyVentures RandyVentures commented Jan 6, 2026

What & Why

Adds support for Telegram Topics (forum channels). Currently, Clawdbot doesn't preserve the thread context when replying in forum groups - all replies go to the general topic.

This PR:

  • Extracts message_thread_id from incoming messages
  • Passes thread ID to all outgoing message types (text, photo, video, audio, documents)
  • Includes thread info in message envelope for context
  • Adds ThreadId and ThreadName to template context

Testing

  • ✅ Fully tested in production Telegram group with Topics enabled
  • ✅ Verified replies stay in correct topic threads
  • ✅ Passes npm run lint

AI-Assisted Development

  • ✅ Built with Claude (Sonnet 4)
  • ✅ Code reviewed and tested by human
  • ✅ Developer confirms understanding of changes
  • ✅ Changes are straightforward - extracting and passing thread IDs through the message pipeline

Development Context

Initial request: User noticed replies weren't staying in the correct topic/forum thread in Telegram groups with Topics enabled.

Approach:

  1. Identified that Telegram's message_thread_id field wasn't being captured
  2. Added thread ID extraction in incoming message handler
  3. Threaded it through the entire message pipeline (envelope, context, delivery)
  4. Added to all outgoing message types (sendMessage, sendPhoto, sendVideo, sendAudio, sendDocument)

Key changes:

  • bot.ts: Extract thread ID from incoming, pass through to delivery, add message_thread_id param to all Telegram API calls
  • envelope.ts: Include thread info in message envelope display
  • templating.ts: Add ThreadId/ThreadName to context for potential future use

Related

Fixes topic/forum support for Telegram groups using the forum feature.

- Extract message_thread_id from incoming messages
- Pass thread ID to all outgoing message types (text, photo, video, audio, documents)
- Include thread info in message envelope for context
- Add ThreadId and ThreadName to template context
- Integrated media group handling from upstream
- Maintained thread ID extraction and passing
- Updated envelope format (surface -> provider, UTC timestamps)
- Added CommandSource field to template context
- All Telegram API calls now include message_thread_id parameter
- Test thread ID extraction from message_thread_id
- Test ThreadId inclusion in context payload
- Test message_thread_id parameter in sendMessage
- Test message_thread_id parameter in sendPhoto
- Test message_thread_id parameter in sendAnimation
- Test undefined thread ID for non-forum messages

All tests passing (42 total, 5 new for topics)
@steipete
Copy link
Copy Markdown
Contributor

steipete commented Jan 7, 2026

Landed integrated Telegram forum topics support in main: b1d0a98c. Topic-isolated session keys, message_thread_id routing + typing, ctx fields, docs + tests. Credited you as co-author + changelog mention with PR #321/#333/#334. Thanks!

@steipete steipete closed this Jan 7, 2026
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* chore: conflict resolution

* chore: checkou tfrom main
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
* feat: tool journal/diagnostics

* feat: journal fixes

* feat(ui): add error boundary component with retry & friendly messages

- New error-boundary.ts component with renderError/renderErrorIf helpers
- Custom element <error-boundary> with auto-retry and exponential backoff
- friendlyError() maps raw errors to user-friendly messages + suggestions
- Supports severity levels (danger/warning/info), compact mode, dismiss
- Collapsible technical details section
- ARIA compliance with role=alert and aria-live
- Replaces all inline callout danger patterns across 23 view files
- Consistent error UX across agents, channels, sessions, config, etc.

* Web: reset retry timers on error changes (openclaw#273)

* Gateway: unify exec approvals with tool approval flow (openclaw#319)

* Gateway: unify exec approvals

* Gateway: guard exec approval resolves

* Feat/pr review monitor (openclaw#313)

* minor fixes

* feat: monitor AI PR review comments

* PR review monitor: add pagination config (openclaw#324)

* Codex/review branch changes and identify issues (openclaw#325)

* minor fixes

* feat: monitor AI PR review comments

* PR review monitor: add pagination config

* UI: reset auto-retry timers on error changes (openclaw#328)

* feat(ui): add error boundary component with retry & friendly messages

- New error-boundary.ts component with renderError/renderErrorIf helpers
- Custom element <error-boundary> with auto-retry and exponential backoff
- friendlyError() maps raw errors to user-friendly messages + suggestions
- Supports severity levels (danger/warning/info), compact mode, dismiss
- Collapsible technical details section
- ARIA compliance with role=alert and aria-live
- Replaces all inline callout danger patterns across 23 view files
- Consistent error UX across agents, channels, sessions, config, etc.

* Web: reset retry timers on error changes (openclaw#273)

* UI: reset auto-retry timers on error changes

* Add execution layer runtime parity gap analysis (openclaw#280)

* Add execution layer runtime parity gap analysis

Comprehensive analysis of Pi Runtime vs Claude Agent SDK feature
gaps in the unified execution layer, with 20 prioritized next steps.

https://claude.ai/code/session_017oEzmayzdirGAKmSw2ryQZ

* Meridia: wire multi-factor scoring into capture hook

* merge/minor fixes for ui/*

* Meridia: add per-capture graph fanout queue with retries

* Meridia: enforce sanitization before persistence and fanout

* Meridia: complete Tier2 vector probing and Postgres vector support

---------

Co-authored-by: Claude <[email protected]>

* Codex/review branch changes and identify issues (openclaw#325)

* minor fixes

* feat: monitor AI PR review comments

* PR review monitor: add pagination config

* Work queue: add heartbeat leases (openclaw#329)

* fix: duplicate lines on main

* Tools: clarify work_item refs and workstream (openclaw#332)

Co-authored-by: Claude Opus 4.6 <[email protected]>

* Config: clarify agents.list placement, accept agents.list in web import, and document guidance (openclaw#331)

* Config: clarify agents.list validation

* Web: tighten agents list import validation

* Sessions: align label limits (openclaw#333)

* Work queue: add work item refs support (openclaw#312)

* Tests: update migration count

* Tools: accept refs in work_item tool

* Work queue: link Codex tasks to PRs (post GitHub comments) (openclaw#337)

* Work queue: link codex tasks to PRs

* Work queue: skip branchPrefix-only PR lookup

* Claude/runtime orchestrator tools eu d uu (openclaw#327)

* feat(agents): add runtime tool-approval orchestrator with approvals.tools config

- Add approvals.tools config types + zod schema (enabled, mode, timeoutMs, policy, routing, classifier)
- Create tool-approval orchestrator module (decision engine, param redaction, gateway integration)
- Integrate orchestrator into before-tool-call wrapper path (runs after plugin hooks, before execution)
- Add ToolApprovalBlockedError with stable machine-readable error shape
- Add 90 tests covering all mode/decision/risk branches
- Backward-compatible: no behavior change when approvals.tools is missing or disabled

* feat: upgrade /approve and Discord handler to canonical tool approvals

- /approve now queries tool.approvals.get for canonical records and resolves
  via tool.approval.resolve (with requestHash); falls back to legacy
  exec.approval.resolve when no canonical record is found
- Discord handler listens for tool.approval.requested/resolved events and
  renders generic tool approval embeds for non-exec tools
- resolveApproval prefers tool.approval.resolve when requestHash is cached,
  keeping legacy exec path for backward compatibility
- Updated command description to 'tool approval requests'
- Added shouldHandleToolApproval for canonical event filtering
- Extended tests with canonical, legacy-fallback, and gateway-error scenarios

* refactor: rename .clawdbrain → .openclaw and fix repo/domain references

- Settings dir: ~/.clawdbrain → ~/.openclaw
- Repo references: openclaw/clawdbrain → dgarson/clawdbrain
- Domain: clawdbrain.bot → openclaw.ai
- CLI command: clawdbrain login → openclaw login
- 48 files changed across src/, docs/, apps/web/, ui/

* cron timeout fixes

* feat(agents): wire tool approval context from config into tool creation path

- Inject approvals.tools config into wrapToolWithBeforeToolCallHook context
- Populate channel field from messageProvider via resolveGatewayMessageChannel
- Wire callGatewayTool as the gateway call adapter for approval requests
- Approval context is only constructed when approvals.tools exists and is enabled

* fix: address review gaps in tool approval handler

- Exec dedup: store canonical request for exec tools and defer embed
  creation by 200ms so the legacy mirror gets first shot; if the mirror
  never arrives, fall back to a generic tool embed (future-proofs against
  legacy event removal)
- Extract sendToolApprovalEmbed to eliminate code duplication
- Add buildApprovalCustomId / parseApprovalData generic aliases (same
  wire format, clearer naming for non-exec tool code paths)
- Add alias identity tests

* fix: minor tool approval request fixes

* auto-reply/approval integration fix

* include exec approval doc

* fix: agent-runner-execution integration into auto-reply, executor/kernel fixes

* more work on agent runner and memory/heartbeta integration

* lots of tests resulting from unification of exec kernel; refactored

* Redact arrays in approval helper

* lancedb fixes

* more fixes/test updates

* fix: minor problem

* fix: restore proper non-throwing session label truncation

---------

Co-authored-by: Claude <[email protected]>

* Tool approval/protocol cleanup (openclaw#334)

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* chore: conflict resolution

* chore: checkou tfrom main

* Codex/map paramssummary to exec command field (openclaw#342)

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* chore: conflict resolution

* chore: checkou tfrom main

* Tool approvals: preserve exec command

* Codex/add web inbox for tool approvals (openclaw#339)

* Web: add tool approval inbox support

* Web: fallback approval resolution

* Web: fall back to agent approvals when IDs differ (openclaw#263)

* memclawd: scaffold phase 0 service foundation (openclaw#330)

* memclawd: apply oxfmt

* Memclawd: add client samples and align pipeline config

* Codex/implement work item refs system d2mkjz (openclaw#344)

* Tools: clarify work_item refs and workstream

* Tests: update migration count

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>

* Codex/review branch changes and identify issues kuj3uy (openclaw#343)

* Tests: update migration count

* Tools: accept refs in work_item tool

* Work queue: add refs reindex command

* Work queue: align refs migration and add refs-reindex CLI (openclaw#345)

* Tests: update migration count

* Work queue: move refs backfill to 004 migration

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* chore: conflict resolution

* chore: checkou tfrom main

* Tool approvals: preserve exec command details (openclaw#340)

* Claude/runtime orchestrator tools eu d uu (openclaw#327)

* feat(agents): add runtime tool-approval orchestrator with approvals.tools config

- Add approvals.tools config types + zod schema (enabled, mode, timeoutMs, policy, routing, classifier)
- Create tool-approval orchestrator module (decision engine, param redaction, gateway integration)
- Integrate orchestrator into before-tool-call wrapper path (runs after plugin hooks, before execution)
- Add ToolApprovalBlockedError with stable machine-readable error shape
- Add 90 tests covering all mode/decision/risk branches
- Backward-compatible: no behavior change when approvals.tools is missing or disabled

* feat: upgrade /approve and Discord handler to canonical tool approvals

- /approve now queries tool.approvals.get for canonical records and resolves
  via tool.approval.resolve (with requestHash); falls back to legacy
  exec.approval.resolve when no canonical record is found
- Discord handler listens for tool.approval.requested/resolved events and
  renders generic tool approval embeds for non-exec tools
- resolveApproval prefers tool.approval.resolve when requestHash is cached,
  keeping legacy exec path for backward compatibility
- Updated command description to 'tool approval requests'
- Added shouldHandleToolApproval for canonical event filtering
- Extended tests with canonical, legacy-fallback, and gateway-error scenarios

* refactor: rename .clawdbrain → .openclaw and fix repo/domain references

- Settings dir: ~/.clawdbrain → ~/.openclaw
- Repo references: openclaw/clawdbrain → dgarson/clawdbrain
- Domain: clawdbrain.bot → openclaw.ai
- CLI command: clawdbrain login → openclaw login
- 48 files changed across src/, docs/, apps/web/, ui/

* cron timeout fixes

* feat(agents): wire tool approval context from config into tool creation path

- Inject approvals.tools config into wrapToolWithBeforeToolCallHook context
- Populate channel field from messageProvider via resolveGatewayMessageChannel
- Wire callGatewayTool as the gateway call adapter for approval requests
- Approval context is only constructed when approvals.tools exists and is enabled

* fix: address review gaps in tool approval handler

- Exec dedup: store canonical request for exec tools and defer embed
  creation by 200ms so the legacy mirror gets first shot; if the mirror
  never arrives, fall back to a generic tool embed (future-proofs against
  legacy event removal)
- Extract sendToolApprovalEmbed to eliminate code duplication
- Add buildApprovalCustomId / parseApprovalData generic aliases (same
  wire format, clearer naming for non-exec tool code paths)
- Add alias identity tests

* fix: minor tool approval request fixes

* auto-reply/approval integration fix

* include exec approval doc

* fix: agent-runner-execution integration into auto-reply, executor/kernel fixes

* more work on agent runner and memory/heartbeta integration

* lots of tests resulting from unification of exec kernel; refactored

* Redact arrays in approval helper

* lancedb fixes

* more fixes/test updates

* fix: minor problem

* fix: restore proper non-throwing session label truncation

---------

Co-authored-by: Claude <[email protected]>

* Tool approval/protocol cleanup (openclaw#334)

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* infra: consolidate tool approval types and clean protocol schema

* infra: bridge tool approval routing config into forwarder

* agents: enrich tool approval decision engine with config resolution and reason codes

* test: update tool approval tests for protocol and decision engine changes

* chore: conflict resolution

* chore: checkou tfrom main

* Tool approvals: preserve exec command

---------

Co-authored-by: Claude <[email protected]>

* chore: cleanup fixes

---------

Co-authored-by: Claude <[email protected]>
GGzili pushed a commit to GGzili/moltbot that referenced this pull request Mar 16, 2026
67d6e403d Merge pull request openclaw#352 from Zhumin-lv-wn/fix/card-finalize-use-accumulated-content
bddb4427f fix(card): fix AI Card streaming finalization bugs
c535af6c5 Merge pull request openclaw#350 from Zhumin-lv-wn/fix/card-finalize-use-accumulated-content
d044bf291 fix(card): fix AI Card streaming finalization bugs
de7b25ced Merge pull request openclaw#344 from ming1523/pr/dingtalk-thinking-reaction-clean-main-20260315
c66604576 test(dingtalk): 补充 emoji 模式说明与测试
ca98030cf merge(main): 同步最新主线并清理 PR344 冲突
60071fc60 refactor(dingtalk): 收敛 ack reaction API 调用
0babd7cbe chore(todo): regroup PRs under task checklist items
27922ce76 fix(dingtalk): 补齐 ackReaction review 收尾
e7998195b feat(dingtalk): 支持 ackReaction emoji 模式
094b6bd15 merge(main): 解决 PR344 与主线冲突
110d12deb test(dingtalk): 补强 ackReaction 自定义文本覆盖
8b8fd1482 feat(dingtalk): align ack reaction config with official docs
3c86d7a72 Merge pull request openclaw#348 from Zhumin-lv-wn/fix/card-finalize-use-accumulated-content
9f20a89f8 test(card): verify finalize uses accumulated content across multi-turn tool calls
12762e872 fix(card): use accumulated content for AI Card finalization
f2bd84788 chore(todo): align latest issue/pr findings into existing hierarchy
00a80263a Merge pull request openclaw#346 from aoxiaotian-ai/fix/inbound-handler-textToSend-type
a2a897ab1 fix(inbound-handler): guard textToSend undefined in card final/tool deliver
50e44f212 Merge pull request openclaw#313 from bkloveming/fix/peer-id-lazy-preload-for-delivery-queue
04e3b98c8 Merge pull request openclaw#311 from LazyBug1E0CF/fix/dingtalk-reply-media
bb6da5d38 test: cover inbound reply media delivery paths
883a7931a fix: deliver MEDIA attachments in inbound reply handler
418a4b450 Merge pull request openclaw#341 from Zhumin-lv-wn/perf/streaming-response-optimization
2f1d906b8 fix: retry peer-id preload on top-level failures
9ede8d331 fix: harden peer-id preload idempotency and coverage
413517940 fix: lazy-preload peer ID registry to fix 400 errors in delivery queue
e29e36072 Merge pull request openclaw#343 from soimy/codex/fix-dingtalk-idle-reconnect
dc1f5194e Merge pull request openclaw#248 from androidshu/codex/fix-action-send-mediaurl-upload
e22a8b781 test(integration): cover actions.send mediaUrl redirect upload chain
fb626f1b4 Merge remote-tracking branch 'origin/main' into codex/pr-248
d1c012877 fix(dingtalk): harden mediaUrl prepare and redirect DNS pinning
332cddd23 feat(dingtalk): parse pdf/docx text into context (openclaw#298)
d435be58c fix: address copilot review feedback
34edb2178 fix: restore connection manager heartbeat monitoring
db3071c3e fix: stabilize dingtalk stream reconnect baseline
95a3fbbd8 fix: add curly braces for early returns (lint curly rule)
a691fe2dc Merge branch 'soimy:main' into perf/streaming-response-optimization
dee2ad1eb docs: clarify thinking always streams; add answerPrefix threshold tests
298cea5e1 fix: answerPrefix threshold and disableBlockStreaming condition
0579f1281 feat(dingtalk): add AI Card streaming optimization with CardDraftController
2aec0034e Revert "Merge pull request openclaw#332 from ming1523/pr/dingtalk-thinking-reaction-main-20260314"
ee259200c Merge pull request openclaw#332 from ming1523/pr/dingtalk-thinking-reaction-main-20260314
b0f4f7762 fix(dingtalk): prefer thinking reaction feedback
41abbc12a fix(dingtalk): tighten thinking reaction gating
06a6f5d0f feat(dingtalk): add native thinking reaction feedback
5970a7af1 chore(todo): align latest issue/pr findings into existing hierarchy
862bfca8f fix: add connection manager heartbeat
e30c2f0da refactor: remove unsupported socket idle reconnect path
bf4a1233c fix: avoid idle reconnects on quiet stream connections
e49cd9f44 Revert "feat(dingtalk): 增加异步回执模式" (openclaw#334)
54dff048e chore: add .playwright to .gitignore for generated files
e76461b29 chore(todo): align latest issue/pr findings into existing hierarchy
3aea182c6 Merge pull request openclaw#231 from huww98/fix/stop-reason
c296ff109 Merge pull request openclaw#295 from ming1523/pr/async-mode-connector-borrow-20260311
bcfd1db7d fix: don't supress stop reason
e00f8f324 docs: add README table of contents
53fe911fd Merge remote-tracking branch 'origin/main' into pr-check-295
79f583443 fix(dingtalk): keep control aliases off async path
4ac48703b fix(dingtalk): force markdown replies in async mode
cfda4c05c docs(dingtalk): trim unrelated README drift from async ack PR
a9198437a fix(dingtalk): keep async inflight lock until completion
97638c7cf fix(dingtalk): tighten async ack delivery semantics
061305ef2 fix(dingtalk): import async mode config type
84f092c80 feat(dingtalk): add async ack mode for inbound messages

git-subtree-dir: extensions/dingtalk
git-subtree-split: 67d6e403db157e08d7658186756c4cbd16f9fd0c
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.

3 participants