mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 16:53:45 +02:00
fix(telegram): allow topic cache without session runtime
This commit is contained in:
@@ -168,6 +168,29 @@ describe("buildTelegramMessageContext group sessions without forum", () => {
|
||||
expect(ctx?.ctxPayload?.TopicName).toBe("Deployments");
|
||||
});
|
||||
|
||||
it("handles forum messages without session runtime overrides", async () => {
|
||||
const ctx = await buildTelegramMessageContextForTest({
|
||||
message: {
|
||||
message_id: 3,
|
||||
chat: { id: -1001234567890, type: "supergroup", title: "Test Forum", is_forum: true },
|
||||
date: 1700000002,
|
||||
text: "@bot hello",
|
||||
message_thread_id: 99,
|
||||
from: { id: 42, first_name: "Alice" },
|
||||
reply_to_message: {
|
||||
message_id: 2,
|
||||
forum_topic_created: { name: "Deployments", icon_color: 0x6fb9f0 },
|
||||
},
|
||||
},
|
||||
options: { forceWasMentioned: true },
|
||||
resolveGroupActivation: () => true,
|
||||
sessionRuntime: null,
|
||||
});
|
||||
|
||||
expect(ctx).not.toBeNull();
|
||||
expect(ctx?.ctxPayload?.TopicName).toBe("Deployments");
|
||||
});
|
||||
|
||||
it("reloads topic name from disk after cache reset", async () => {
|
||||
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-telegram-topic-name-"));
|
||||
const sessionStorePath = path.join(tempDir, "sessions.json");
|
||||
|
||||
@@ -36,7 +36,7 @@ type BuildTelegramMessageContextForTestParams = {
|
||||
cfg?: Record<string, unknown>;
|
||||
accountId?: string;
|
||||
runtime?: BuildTelegramMessageContextParams["runtime"];
|
||||
sessionRuntime?: BuildTelegramMessageContextParams["sessionRuntime"];
|
||||
sessionRuntime?: BuildTelegramMessageContextParams["sessionRuntime"] | null;
|
||||
resolveGroupActivation?: BuildTelegramMessageContextParams["resolveGroupActivation"];
|
||||
resolveGroupRequireMention?: BuildTelegramMessageContextParams["resolveGroupRequireMention"];
|
||||
resolveTelegramGroupConfig?: BuildTelegramMessageContextParams["resolveTelegramGroupConfig"];
|
||||
@@ -59,6 +59,13 @@ export async function buildTelegramMessageContextForTest(
|
||||
> {
|
||||
const { vi } = await loadVitestModule();
|
||||
const buildTelegramMessageContext = await loadBuildTelegramMessageContext();
|
||||
const sessionRuntime =
|
||||
params.sessionRuntime === null
|
||||
? undefined
|
||||
: {
|
||||
...telegramMessageContextSessionRuntimeForTest,
|
||||
...params.sessionRuntime,
|
||||
};
|
||||
return await buildTelegramMessageContext({
|
||||
primaryCtx: {
|
||||
message: {
|
||||
@@ -85,10 +92,7 @@ export async function buildTelegramMessageContextForTest(
|
||||
recordChannelActivity: () => undefined,
|
||||
...params.runtime,
|
||||
},
|
||||
sessionRuntime: {
|
||||
...telegramMessageContextSessionRuntimeForTest,
|
||||
...params.sessionRuntime,
|
||||
},
|
||||
sessionRuntime,
|
||||
account: { accountId: params.accountId ?? "default" } as never,
|
||||
historyLimit: 0,
|
||||
groupHistories: new Map(),
|
||||
|
||||
@@ -149,9 +149,11 @@ export const buildTelegramMessageContext = async ({
|
||||
const resolvedThreadId = threadSpec.scope === "forum" ? threadSpec.id : undefined;
|
||||
const replyThreadId = threadSpec.id;
|
||||
const dmThreadId = threadSpec.scope === "dm" ? threadSpec.id : undefined;
|
||||
const topicNameCachePath = resolveTopicNameCachePath(
|
||||
sessionRuntime.resolveStorePath(cfg.session?.store, { agentId: account.accountId }),
|
||||
);
|
||||
const topicNameCachePath = sessionRuntime?.resolveStorePath
|
||||
? resolveTopicNameCachePath(
|
||||
sessionRuntime.resolveStorePath(cfg.session?.store, { agentId: account.accountId }),
|
||||
)
|
||||
: undefined;
|
||||
let topicName: string | undefined;
|
||||
if (isForum && resolvedThreadId != null) {
|
||||
const ftCreated = msg.forum_topic_created;
|
||||
|
||||
Reference in New Issue
Block a user