Skip to content

fix(telegram): keep numeric chat ids for announce targets#44169

Closed
hugh-agent wants to merge 1 commit intoopenclaw:mainfrom
hugh-agent:fix/telegram-group-announce-target
Closed

fix(telegram): keep numeric chat ids for announce targets#44169
hugh-agent wants to merge 1 commit intoopenclaw:mainfrom
hugh-agent:fix/telegram-group-announce-target

Conversation

@hugh-agent
Copy link
Copy Markdown

Summary

  • keep Telegram announce targets as raw numeric chat IDs in resolveAnnounceTargetFromKey
  • preserve topic/thread IDs for Telegram group/topic delivery
  • add a focused test covering plain group and topic session keys

Problem

When sessions_send / nested announce delivery targeted a Telegram group session, resolveAnnounceTargetFromKey(...) routed the target through channel target normalization and produced values like group:-1001720118846.

Later, Telegram send-path validation rejected that target with:

Telegram recipient must be a numeric chat ID

This broke agent-to-agent announce delivery into Telegram groups, even though the underlying session key already contained the correct numeric chat ID.

Fix

For Telegram, bypass messaging target normalization in resolveAnnounceTargetFromKey(...) and keep the resolved announce target as the raw numeric chat ID. Thread/topic IDs are still extracted and preserved separately.

Repro

  • create or reuse a Telegram group session key like agent:main:telegram:group:-1001720118846
  • use sessions_send / nested announce flow targeting that session
  • before this change, delivery attempts can fail with Telegram recipient must be a numeric chat ID

Notes

I could not run the repo Vitest target in this environment because project dependencies are not installed in the cloned repo, but I added a focused unit test for the helper.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Mar 12, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 12, 2026

Greptile Summary

This PR attempts to fix Telegram announce target resolution by bypassing the normalizeTarget call for the "telegram" channel and returning the raw chat ID instead of a prefixed form like "group:-1001720118846". The fix and accompanying tests are well-scoped — but there is a critical off-by-one in the implementation: the Telegram branch returns kindTarget rather than id, and kindTarget is still built as "group:<id>" (line 61). Both new tests expect to: "-1001720118846" and will fail against the current code.

  • The fix in resolveAnnounceTargetFromKey should use id (the bare numeric string) rather than kindTarget in the normalizedChannel === "telegram" branch — kindTarget still carries the group: prefix that the Telegram send-path rejects.
  • The two new test cases correctly specify the desired behavior (raw numeric to for plain group and topic session keys); they serve as a good regression harness once the one-word change (kindTargetid) is applied.

Confidence Score: 1/5

  • Not safe to merge — the core fix uses kindTarget instead of id, so the group: prefix is not removed and the bug persists; both new tests will fail.
  • The Telegram bypass branch returns kindTarget ("group:-1001720118846") rather than id ("-1001720118846"). This means to is still a prefixed string, exactly what the Telegram send-path rejects. The fix is one word away from being correct (id instead of kindTarget), but in its current state the code does not solve the reported problem and the tests it introduces will fail.
  • src/agents/tools/sessions-send-helpers.ts — lines 63-68, the normalized assignment for Telegram
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/tools/sessions-send-helpers.ts
Line: 63-68

Comment:
**Fix still includes `group:` prefix for Telegram targets**

The fix assigns `normalized = kindTarget` for Telegram, but `kindTarget` for a group session key is `"group:<id>"` (computed at line 61: `return kind === "channel" ? \`channel:${id}\` : \`group:${id}\``). So `to` ends up as `"group:-1001720118846"` — the same prefixed form that caused the original validation failure — not the raw numeric `"-1001720118846"` expected by both new tests.

Tracing through `"agent:main:telegram:group:-1001720118846"`:
- `kind = "group"`, `id = "-1001720118846"`
- `kindTarget = "group:-1001720118846"` (line 61)
- `normalized = kindTarget = "group:-1001720118846"` (new branch)
- `to = "group:-1001720118846"` — test expects `"-1001720118846"`**test fails**

The fix should use `id` (the bare numeric value) instead of `kindTarget`:

```suggestion
  const normalized =
    normalizedChannel === "telegram"
      ? id
      : normalizedChannel
        ? getChannelPlugin(normalizedChannel)?.messaging?.normalizeTarget?.(kindTarget)
        : undefined;
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: bc02ee8

Comment thread src/agents/tools/sessions-send-helpers.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc02ee80b4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tools/sessions-send-helpers.ts Outdated
@hugh-agent
Copy link
Copy Markdown
Author

Addressed the review feedback in a follow-up commit.

  • switched the Telegram branch in resolveAnnounceTargetFromKey(...) from kindTarget to the bare id
  • kept threadId / topic extraction unchanged
  • reran the narrow regression test:
    • corepack pnpm exec vitest run src/agents/tools/sessions-send-helpers.test.ts ✅ (2/2)

This should close the group:<id> vs numeric chat ID issue called out in review.

@hugh-agent hugh-agent force-pushed the fix/telegram-group-announce-target branch from efba53f to 74dfe71 Compare March 12, 2026 23:56
@hugh-agent
Copy link
Copy Markdown
Author

Refreshed this PR on top of the latest main to keep the diff current and drop stale merge-base noise. No semantic change intended beyond rebasing the fix onto current upstream.

@steipete
Copy link
Copy Markdown
Contributor

Closing this as implemented after Codex review.

Current main already resolves Telegram announce targets to bare numeric chat IDs, preserves topic/thread IDs separately, and ships a regression test for the exact session-key shape in this PR. The same implementation is already present in release v2026.4.23, so there is no remaining delta for this PR to land.

What I checked:

  • Current helper implementation: On current main, resolveAnnounceTargetFromKey(...) parses the session key, delegates session-aware target shaping to the channel plugin, and returns threadId separately. This is the announce path relevant to the PR. (src/agents/tools/sessions-send-helpers.ts:26, 5fe333ada85a)
  • Current Telegram regression test: Current tests already assert that agent:main:telegram:group:-100123:topic:99 resolves to to: "-100123" with threadId: "99", matching the behavior this PR wants. (src/agents/tools/sessions-send-helpers.test.ts:24, 5fe333ada85a)
  • Telegram session-key parsing: The bundled Telegram channel plugin resolves session conversation ids into chatId plus optional topicId, so announce routing keeps the numeric chat id and carries the topic separately. (extensions/telegram/src/session-conversation.ts:3, 5fe333ada85a)
  • Telegram target normalization and send contract: Telegram target parsing strips the legacy telegram:group: internal form to the bare numeric id, and the send path still rejects non-numeric recipients. That means the current code already covers the bug described in this PR. (extensions/telegram/src/targets.ts:10, 5fe333ada85a)
  • Numeric recipient requirement remains enforced: The Telegram send path still throws Telegram recipient must be a numeric chat ID when a recipient cannot be normalized to a numeric id, which is the exact failure mode described in the PR body. (extensions/telegram/src/send.ts:301, 5fe333ada85a)
  • Already shipped in latest release: The same announce-helper/test and Telegram session-target files are already present in release tag v2026.4.23; diffing that tag against current main for these files produced no changes. (a9797214338b)

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review notes: reviewed against 5fe333ada85a; fix evidence: release v2026.4.23, commit a9797214338b.

@steipete steipete closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants