Skip to content

Commit 4f92b1f

Browse files
committed
fix(telegram): allow topic cache without session runtime
1 parent 6eafb5f commit 4f92b1f

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

extensions/telegram/src/bot-message-context.dm-threads.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,29 @@ describe("buildTelegramMessageContext group sessions without forum", () => {
168168
expect(ctx?.ctxPayload?.TopicName).toBe("Deployments");
169169
});
170170

171+
it("handles forum messages without session runtime overrides", async () => {
172+
const ctx = await buildTelegramMessageContextForTest({
173+
message: {
174+
message_id: 3,
175+
chat: { id: -1001234567890, type: "supergroup", title: "Test Forum", is_forum: true },
176+
date: 1700000002,
177+
text: "@bot hello",
178+
message_thread_id: 99,
179+
from: { id: 42, first_name: "Alice" },
180+
reply_to_message: {
181+
message_id: 2,
182+
forum_topic_created: { name: "Deployments", icon_color: 0x6fb9f0 },
183+
},
184+
},
185+
options: { forceWasMentioned: true },
186+
resolveGroupActivation: () => true,
187+
sessionRuntime: null,
188+
});
189+
190+
expect(ctx).not.toBeNull();
191+
expect(ctx?.ctxPayload?.TopicName).toBe("Deployments");
192+
});
193+
171194
it("reloads topic name from disk after cache reset", async () => {
172195
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-telegram-topic-name-"));
173196
const sessionStorePath = path.join(tempDir, "sessions.json");

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type BuildTelegramMessageContextForTestParams = {
3636
cfg?: Record<string, unknown>;
3737
accountId?: string;
3838
runtime?: BuildTelegramMessageContextParams["runtime"];
39-
sessionRuntime?: BuildTelegramMessageContextParams["sessionRuntime"];
39+
sessionRuntime?: BuildTelegramMessageContextParams["sessionRuntime"] | null;
4040
resolveGroupActivation?: BuildTelegramMessageContextParams["resolveGroupActivation"];
4141
resolveGroupRequireMention?: BuildTelegramMessageContextParams["resolveGroupRequireMention"];
4242
resolveTelegramGroupConfig?: BuildTelegramMessageContextParams["resolveTelegramGroupConfig"];
@@ -59,6 +59,13 @@ export async function buildTelegramMessageContextForTest(
5959
> {
6060
const { vi } = await loadVitestModule();
6161
const buildTelegramMessageContext = await loadBuildTelegramMessageContext();
62+
const sessionRuntime =
63+
params.sessionRuntime === null
64+
? undefined
65+
: {
66+
...telegramMessageContextSessionRuntimeForTest,
67+
...params.sessionRuntime,
68+
};
6269
return await buildTelegramMessageContext({
6370
primaryCtx: {
6471
message: {
@@ -85,10 +92,7 @@ export async function buildTelegramMessageContextForTest(
8592
recordChannelActivity: () => undefined,
8693
...params.runtime,
8794
},
88-
sessionRuntime: {
89-
...telegramMessageContextSessionRuntimeForTest,
90-
...params.sessionRuntime,
91-
},
95+
sessionRuntime,
9296
account: { accountId: params.accountId ?? "default" } as never,
9397
historyLimit: 0,
9498
groupHistories: new Map(),

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ export const buildTelegramMessageContext = async ({
149149
const resolvedThreadId = threadSpec.scope === "forum" ? threadSpec.id : undefined;
150150
const replyThreadId = threadSpec.id;
151151
const dmThreadId = threadSpec.scope === "dm" ? threadSpec.id : undefined;
152-
const topicNameCachePath = resolveTopicNameCachePath(
153-
sessionRuntime.resolveStorePath(cfg.session?.store, { agentId: account.accountId }),
154-
);
152+
const topicNameCachePath = sessionRuntime?.resolveStorePath
153+
? resolveTopicNameCachePath(
154+
sessionRuntime.resolveStorePath(cfg.session?.store, { agentId: account.accountId }),
155+
)
156+
: undefined;
155157
let topicName: string | undefined;
156158
if (isForum && resolvedThreadId != null) {
157159
const ftCreated = msg.forum_topic_created;

0 commit comments

Comments
 (0)