Skip to content

bug(telegram): auto-generated group intro tells users the wrong @handle #243

Description

@chrisbonilla95

Bug

When the bot is added to a group it posts an auto-generated intro that is written by the model — handleMyChatMember calls run("telegram", eventPrompt) in src/commands/telegram.ts. The event prompt asks the model to "explain how to trigger me" but never tells it the bot's own @username, so the model has to guess its own handle. It can guess wrong: in a multi-bot setup it told members to mention a different bot's handle, leaving them with a mention that does nothing.

How to reproduce

Add the bot (e.g. @your_bot) to a group. The intro may say something like "tag me with @some_other_name" instead of @your_bot. The daemon already knows the correct username (botUsername, populated from getMe at startup and from the my_chat_member update) — it just isn't passed into the prompt.

Root cause

The added-to-group handler builds the prompt inline, without the handle:

const eventPrompt =
  `[Telegram system event] I was added to a ${chat.type}.\n` +
  `Group title: ${wrapUntrusted("group-title", chatName)}\n` +
  `Group id: ${chat.id}\n` +
  `Added by: ${wrapUntrusted("adder-username", addedBy)}\n` +
  "Write a short first message for the group. It should confirm I was added and explain how to trigger me.";

botUsername is in scope at this point but unused.

Fix

Extract the prompt into a small, exported, testable helper that includes the already-loaded botUsername and instructs the model to use that exact handle. Fall back to the original wording when the username isn't loaded yet (byte-identical to today):

export function buildGroupAddedPrompt(chatType, chatTitle, chatId, addedBy, botUsername) {
  const base =
    `[Telegram system event] I was added to a ${chatType}.\n` +
    `Group title: ${wrapUntrusted("group-title", chatTitle)}\n` +
    `Group id: ${chatId}\n` +
    `Added by: ${wrapUntrusted("adder-username", addedBy)}\n`;
  const intro = "Write a short first message for the group. It should confirm I was added and explain how to trigger me";
  if (!botUsername) return base + intro + ".";
  const mention = `@${botUsername}`;
  return base +
    `My Telegram handle is ${mention}; users can only trigger me by mentioning that exact handle.\n` +
    intro + `, telling them to mention me as ${mention} (use this exact handle — do not invent a different name).`;
}

The untrusted group-title / adder-username stay wrapUntrusted-wrapped; only the bot's own handle is added.

Branch (implemented, with unit tests): https://github.com/chrisbonilla95/claudeclaw/tree/fix/group-added-intro-handle
(diff vs master: master...chrisbonilla95:claudeclaw:fix/group-added-intro-handle) — happy to open a PR.


Posted by Claude after discussing with @chrisbonilla95

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions