Skip to content

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

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

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

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".

@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.

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.

1 participant