Skip to content

Commit e911455

Browse files
committed
fix(telegram): honor topic requireMention precedence
1 parent 828b6be commit e911455

3 files changed

Lines changed: 114 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Docs: https://docs.openclaw.ai
7272
- Agents/subagents: refresh deferred final-delivery payloads when same-session completion output changes, so retried parent notifications use the final child summary instead of stale progress text. Thanks @vincentkoc.
7373
- Memory/wiki: preserve representation from both corpora in `corpus=all` searches while backfilling unused result capacity, so memory hits are not starved by numerically higher wiki integer scores. Fixes #77337. Thanks @hclsys.
7474
- Telegram: clean up tool-only draft previews after assistant message boundaries so transient `Surfacing...` tool-status bubbles do not linger when no matching final preview arrives. Thanks @BunsDev.
75+
- Telegram: let explicit forum-topic `requireMention` settings override persisted `/activate` and `/deactivate` state, so per-topic mention gates work consistently. Fixes #49864. Thanks @Panniantong.
7576
- Cron: surface failed isolated-run diagnostics in `cron show`, status, and run history when requested tools are unavailable, so blocked cron runs report the actual tool-policy failure instead of a misleading green result. Fixes #75763. Thanks @RyanSandoval.
7677
- TUI/escape abort: track the in-flight runId after `chat.send` resolves so pressing Esc during the gap before the first gateway event aborts the run instead of repeatedly printing `no active run`. Fixes #1296. Thanks @Lukavyi and @romneyda.
7778
- TUI/render: stop the long-token sanitizer from injecting literal spaces inside inline code spans, fenced code blocks, table borders, and bare hyphenated/dotted identifiers, so copied package names, entity IDs, and shell line-continuations stay byte-for-byte intact while narrow-terminal protection still chunks unidentifiable long prose tokens. Fixes #48432, #39505. Thanks @DocOellerson, @xeusoc, @CCcassiusdjs, @akramcodez, @brokemac79, @romneyda.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { getRuntimeConfig } from "openclaw/plugin-sdk/runtime-config-snapshot";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
4+
const { defaultRouteConfig } = vi.hoisted(() => ({
5+
defaultRouteConfig: {
6+
agents: {
7+
list: [{ id: "main", default: true }],
8+
},
9+
channels: { telegram: {} },
10+
messages: { groupChat: { mentionPatterns: [] } },
11+
},
12+
}));
13+
14+
vi.mock("openclaw/plugin-sdk/runtime-config-snapshot", async () => {
15+
const actual = await vi.importActual<
16+
typeof import("openclaw/plugin-sdk/runtime-config-snapshot")
17+
>("openclaw/plugin-sdk/runtime-config-snapshot");
18+
return {
19+
...actual,
20+
getRuntimeConfig: vi.fn(() => defaultRouteConfig),
21+
};
22+
});
23+
24+
const { buildTelegramMessageContextForTest } =
25+
await import("./bot-message-context.test-harness.js");
26+
27+
describe("buildTelegramMessageContext requireMention precedence", () => {
28+
function buildForumMessage(threadId = 99) {
29+
return {
30+
message_id: 1,
31+
chat: {
32+
id: -1001234567890,
33+
type: "supergroup" as const,
34+
title: "Forum",
35+
is_forum: true,
36+
},
37+
date: 1_700_000_000,
38+
text: "hello everyone",
39+
message_thread_id: threadId,
40+
from: { id: 42, first_name: "Alice" },
41+
};
42+
}
43+
44+
beforeEach(() => {
45+
vi.mocked(getRuntimeConfig).mockReturnValue(defaultRouteConfig as never);
46+
});
47+
48+
it("lets explicit topic requireMention=false override group requireMention=true", async () => {
49+
const ctx = await buildTelegramMessageContextForTest({
50+
message: buildForumMessage(),
51+
resolveGroupActivation: () => undefined,
52+
resolveGroupRequireMention: () => true,
53+
resolveTelegramGroupConfig: () => ({
54+
groupConfig: { requireMention: true },
55+
topicConfig: { requireMention: false },
56+
}),
57+
});
58+
59+
expect(ctx).not.toBeNull();
60+
});
61+
62+
it("lets explicit topic requireMention=false override mention activation", async () => {
63+
const resolveGroupActivation = vi.fn(() => true);
64+
65+
const ctx = await buildTelegramMessageContextForTest({
66+
message: buildForumMessage(),
67+
resolveGroupActivation,
68+
resolveGroupRequireMention: () => true,
69+
resolveTelegramGroupConfig: () => ({
70+
groupConfig: { requireMention: true },
71+
topicConfig: { requireMention: false },
72+
}),
73+
});
74+
75+
expect(ctx).not.toBeNull();
76+
expect(resolveGroupActivation).toHaveBeenCalledWith(
77+
expect.objectContaining({
78+
chatId: -1001234567890,
79+
messageThreadId: 99,
80+
sessionKey: "agent:main:telegram:group:-1001234567890:topic:99",
81+
}),
82+
);
83+
});
84+
85+
it("lets explicit topic requireMention=true override always activation", async () => {
86+
const ctx = await buildTelegramMessageContextForTest({
87+
message: buildForumMessage(),
88+
resolveGroupActivation: () => false,
89+
resolveGroupRequireMention: () => false,
90+
resolveTelegramGroupConfig: () => ({
91+
groupConfig: { requireMention: false },
92+
topicConfig: { requireMention: true },
93+
}),
94+
});
95+
96+
expect(ctx).toBeNull();
97+
});
98+
99+
it("keeps activation fallback when no topic requireMention is configured", async () => {
100+
const ctx = await buildTelegramMessageContextForTest({
101+
message: buildForumMessage(),
102+
resolveGroupActivation: () => false,
103+
resolveGroupRequireMention: () => true,
104+
resolveTelegramGroupConfig: () => ({
105+
groupConfig: { requireMention: true },
106+
topicConfig: { agentId: "main" },
107+
}),
108+
});
109+
110+
expect(ctx).not.toBeNull();
111+
});
112+
});

extensions/telegram/src/bot-message-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ export const buildTelegramMessageContext = async ({
411411
});
412412
const baseRequireMention = resolveGroupRequireMention(chatId);
413413
const requireMention = firstDefined(
414-
activationOverride,
415414
topicConfig?.requireMention,
415+
activationOverride,
416416
telegramGroupConfig?.requireMention,
417417
baseRequireMention,
418418
);

0 commit comments

Comments
 (0)