mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:00:42 +00: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");
|
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 () => {
|
it("reloads topic name from disk after cache reset", async () => {
|
||||||
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-telegram-topic-name-"));
|
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-telegram-topic-name-"));
|
||||||
const sessionStorePath = path.join(tempDir, "sessions.json");
|
const sessionStorePath = path.join(tempDir, "sessions.json");
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type BuildTelegramMessageContextForTestParams = {
|
|||||||
cfg?: Record<string, unknown>;
|
cfg?: Record<string, unknown>;
|
||||||
accountId?: string;
|
accountId?: string;
|
||||||
runtime?: BuildTelegramMessageContextParams["runtime"];
|
runtime?: BuildTelegramMessageContextParams["runtime"];
|
||||||
sessionRuntime?: BuildTelegramMessageContextParams["sessionRuntime"];
|
sessionRuntime?: BuildTelegramMessageContextParams["sessionRuntime"] | null;
|
||||||
resolveGroupActivation?: BuildTelegramMessageContextParams["resolveGroupActivation"];
|
resolveGroupActivation?: BuildTelegramMessageContextParams["resolveGroupActivation"];
|
||||||
resolveGroupRequireMention?: BuildTelegramMessageContextParams["resolveGroupRequireMention"];
|
resolveGroupRequireMention?: BuildTelegramMessageContextParams["resolveGroupRequireMention"];
|
||||||
resolveTelegramGroupConfig?: BuildTelegramMessageContextParams["resolveTelegramGroupConfig"];
|
resolveTelegramGroupConfig?: BuildTelegramMessageContextParams["resolveTelegramGroupConfig"];
|
||||||
@@ -59,6 +59,13 @@ export async function buildTelegramMessageContextForTest(
|
|||||||
> {
|
> {
|
||||||
const { vi } = await loadVitestModule();
|
const { vi } = await loadVitestModule();
|
||||||
const buildTelegramMessageContext = await loadBuildTelegramMessageContext();
|
const buildTelegramMessageContext = await loadBuildTelegramMessageContext();
|
||||||
|
const sessionRuntime =
|
||||||
|
params.sessionRuntime === null
|
||||||
|
? undefined
|
||||||
|
: {
|
||||||
|
...telegramMessageContextSessionRuntimeForTest,
|
||||||
|
...params.sessionRuntime,
|
||||||
|
};
|
||||||
return await buildTelegramMessageContext({
|
return await buildTelegramMessageContext({
|
||||||
primaryCtx: {
|
primaryCtx: {
|
||||||
message: {
|
message: {
|
||||||
@@ -85,10 +92,7 @@ export async function buildTelegramMessageContextForTest(
|
|||||||
recordChannelActivity: () => undefined,
|
recordChannelActivity: () => undefined,
|
||||||
...params.runtime,
|
...params.runtime,
|
||||||
},
|
},
|
||||||
sessionRuntime: {
|
sessionRuntime,
|
||||||
...telegramMessageContextSessionRuntimeForTest,
|
|
||||||
...params.sessionRuntime,
|
|
||||||
},
|
|
||||||
account: { accountId: params.accountId ?? "default" } as never,
|
account: { accountId: params.accountId ?? "default" } as never,
|
||||||
historyLimit: 0,
|
historyLimit: 0,
|
||||||
groupHistories: new Map(),
|
groupHistories: new Map(),
|
||||||
|
|||||||
@@ -149,9 +149,11 @@ export const buildTelegramMessageContext = async ({
|
|||||||
const resolvedThreadId = threadSpec.scope === "forum" ? threadSpec.id : undefined;
|
const resolvedThreadId = threadSpec.scope === "forum" ? threadSpec.id : undefined;
|
||||||
const replyThreadId = threadSpec.id;
|
const replyThreadId = threadSpec.id;
|
||||||
const dmThreadId = threadSpec.scope === "dm" ? threadSpec.id : undefined;
|
const dmThreadId = threadSpec.scope === "dm" ? threadSpec.id : undefined;
|
||||||
const topicNameCachePath = resolveTopicNameCachePath(
|
const topicNameCachePath = sessionRuntime?.resolveStorePath
|
||||||
sessionRuntime.resolveStorePath(cfg.session?.store, { agentId: account.accountId }),
|
? resolveTopicNameCachePath(
|
||||||
);
|
sessionRuntime.resolveStorePath(cfg.session?.store, { agentId: account.accountId }),
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
let topicName: string | undefined;
|
let topicName: string | undefined;
|
||||||
if (isForum && resolvedThreadId != null) {
|
if (isForum && resolvedThreadId != null) {
|
||||||
const ftCreated = msg.forum_topic_created;
|
const ftCreated = msg.forum_topic_created;
|
||||||
|
|||||||
Reference in New Issue
Block a user