mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:22:47 +00:00
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: {
|
async function buildGroupReplyCtx(params: {
|
||||||
replyToMessageText?: string;
|
replyToMessageText?: string;
|
||||||
|
replyToMessageCaption?: string;
|
||||||
replyFromIsBot?: boolean;
|
replyFromIsBot?: boolean;
|
||||||
replyFromId?: number;
|
replyFromId?: number;
|
||||||
}) {
|
}) {
|
||||||
@@ -24,6 +25,9 @@ describe("buildTelegramMessageContext implicitMention forum system messages", ()
|
|||||||
reply_to_message: {
|
reply_to_message: {
|
||||||
message_id: 1,
|
message_id: 1,
|
||||||
text: params.replyToMessageText ?? undefined,
|
text: params.replyToMessageText ?? undefined,
|
||||||
|
...(params.replyToMessageCaption != null
|
||||||
|
? { caption: params.replyToMessageCaption }
|
||||||
|
: {}),
|
||||||
from: {
|
from: {
|
||||||
id: params.replyFromId ?? BOT_ID,
|
id: params.replyFromId ?? BOT_ID,
|
||||||
first_name: "OpenClaw",
|
first_name: "OpenClaw",
|
||||||
@@ -85,6 +89,19 @@ describe("buildTelegramMessageContext implicitMention forum system messages", ()
|
|||||||
expect(ctx?.ctxPayload?.WasMentioned).toBe(true);
|
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 () => {
|
it("does NOT trigger implicitMention when reply is from a different user", async () => {
|
||||||
const ctx = await buildGroupReplyCtx({
|
const ctx = await buildGroupReplyCtx({
|
||||||
replyToMessageText: "some message",
|
replyToMessageText: "some message",
|
||||||
|
|||||||
@@ -478,7 +478,10 @@ export const buildTelegramMessageContext = async ({
|
|||||||
const replyFromId = msg.reply_to_message?.from?.id;
|
const replyFromId = msg.reply_to_message?.from?.id;
|
||||||
const replyToBotMessage = botId != null && replyFromId === botId;
|
const replyToBotMessage = botId != null && replyFromId === botId;
|
||||||
const isReplyToSystemMessage =
|
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 implicitMention = replyToBotMessage && !isReplyToSystemMessage;
|
||||||
const canDetectMention = Boolean(botUsername) || mentionRegexes.length > 0;
|
const canDetectMention = Boolean(botUsername) || mentionRegexes.length > 0;
|
||||||
const mentionGate = resolveMentionGatingWithBypass({
|
const mentionGate = resolveMentionGatingWithBypass({
|
||||||
|
|||||||
Reference in New Issue
Block a user