fix(telegram): also check caption for bot media replies
Address Greptile review feedback: bot media messages (photo/video) use caption instead of text, so they would be incorrectly classified as system messages. Add !caption guard to the system message check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
8fdd1d2f05
commit
dc2aa1e21d
@@ -10,6 +10,7 @@ describe("buildTelegramMessageContext implicitMention forum system messages", ()
|
||||
*/
|
||||
async function buildGroupReplyCtx(params: {
|
||||
replyToMessageText?: string;
|
||||
replyToMessageCaption?: string;
|
||||
replyFromIsBot?: boolean;
|
||||
replyFromId?: number;
|
||||
}) {
|
||||
@@ -24,6 +25,9 @@ describe("buildTelegramMessageContext implicitMention forum system messages", ()
|
||||
reply_to_message: {
|
||||
message_id: 1,
|
||||
text: params.replyToMessageText ?? undefined,
|
||||
...(params.replyToMessageCaption != null
|
||||
? { caption: params.replyToMessageCaption }
|
||||
: {}),
|
||||
from: {
|
||||
id: params.replyFromId ?? BOT_ID,
|
||||
first_name: "OpenClaw",
|
||||
@@ -85,6 +89,19 @@ describe("buildTelegramMessageContext implicitMention forum system messages", ()
|
||||
expect(ctx?.ctxPayload?.WasMentioned).toBe(true);
|
||||
});
|
||||
|
||||
it("DOES trigger implicitMention for bot media messages with caption (not a system message)", async () => {
|
||||
// Media messages from the bot have caption but no text — they should
|
||||
// still count as real bot replies, not system messages.
|
||||
const ctx = await buildGroupReplyCtx({
|
||||
replyToMessageText: undefined,
|
||||
replyToMessageCaption: "Check out this image",
|
||||
replyFromIsBot: true,
|
||||
});
|
||||
|
||||
expect(ctx).not.toBeNull();
|
||||
expect(ctx?.ctxPayload?.WasMentioned).toBe(true);
|
||||
});
|
||||
|
||||
it("does NOT trigger implicitMention when reply is from a different user", async () => {
|
||||
const ctx = await buildGroupReplyCtx({
|
||||
replyToMessageText: "some message",
|
||||
|
||||
@@ -478,7 +478,10 @@ export const buildTelegramMessageContext = async ({
|
||||
const replyFromId = msg.reply_to_message?.from?.id;
|
||||
const replyToBotMessage = botId != null && replyFromId === botId;
|
||||
const isReplyToSystemMessage =
|
||||
replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text;
|
||||
replyToBotMessage &&
|
||||
msg.reply_to_message?.from?.is_bot === true &&
|
||||
!msg.reply_to_message?.text &&
|
||||
!msg.reply_to_message?.caption;
|
||||
const implicitMention = replyToBotMessage && !isReplyToSystemMessage;
|
||||
const canDetectMention = Boolean(botUsername) || mentionRegexes.length > 0;
|
||||
const mentionGate = resolveMentionGatingWithBypass({
|
||||
|
||||
Reference in New Issue
Block a user