Skip to content

Native command replies route to default Telegram account when AccountId missing from context #4344

@TheMattBerman

Description

@TheMattBerman

Bug Description

When using multiple Telegram bot accounts bound to different agents, native slash commands (like /reset, /new) send their confirmation messages to the default account instead of the account that received the command.

Reproduction Steps

  1. Configure multiple Telegram bot accounts with bindings to different agents:
"accounts": {
  "default": { "name": "Jean Luc", "botToken": "..." },
  "stealads-builder": { "name": "StealAds Builder", "botToken": "..." }
},
"bindings": [
  { "agentId": "stealads-builder", "match": { "channel": "telegram", "accountId": "stealads-builder" } }
]
  1. Send /reset to the stealads-builder bot (non-default account)
  2. Expected: Only stealads-builder responds with "✅ New session started"
  3. Actual: Both stealads-builder AND the default bot respond with "✅ New session started"

Root Cause

In src/telegram/bot-native-commands.ts, the ctxPayload passed to finalizeInboundContext is missing the AccountId field:

const ctxPayload = finalizeInboundContext({
    // ... other fields
    OriginatingChannel: "telegram",
    OriginatingTo: \`telegram:\${chatId}\`,
    // AccountId is MISSING!
});

When get-reply-run.ts sends the reset confirmation via routeReply:

await routeReply({
    accountId: ctx.AccountId,  // undefined!
    // ...
});

The undefined accountId flows through to resolveTelegramAccount({ accountId: undefined }), which returns the DEFAULT account due to normalizeAccountId() returning "default" for falsy values.

Fix

Add AccountId: accountId to the context payload in bot-native-commands.ts (around line 242):

const ctxPayload = finalizeInboundContext({
    // ... existing fields
    OriginatingChannel: "telegram",
    OriginatingTo: \`telegram:\${chatId}\`,
    AccountId: accountId,  // ADD THIS LINE
});

The accountId variable is already available in scope from the function parameters.

Verified Fix

We manually patched dist/telegram/bot-native-commands.js and confirmed the fix works - after adding AccountId: accountId, the cross-account message routing no longer occurs.

Environment

  • Clawdbot version: 2026.1.24-3
  • Multiple Telegram accounts configured with agent bindings
  • WSL2 Ubuntu

Workaround

Manually patch dist/telegram/bot-native-commands.js line ~242 to add AccountId: accountId, after the OriginatingTo line, then restart the gateway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions