fix(cron): preserve telegram announce target + delivery truth

This commit is contained in:
Ayaan Zaidi
2026-02-23 10:22:35 +05:30
committed by Ayaan Zaidi
parent dcc52850c3
commit 03122e5933
12 changed files with 246 additions and 5 deletions

View File

@@ -143,4 +143,46 @@ describe("maybePersistResolvedTelegramTarget", () => {
expect.any(Object),
);
});
it("matches username targets case-insensitively", async () => {
readConfigFileSnapshotForWrite.mockResolvedValue({
snapshot: {
config: {
channels: {
telegram: {
defaultTo: "https://t.me/mychannel",
},
},
},
},
writeOptions: {},
});
loadCronStore.mockResolvedValue({
version: 1,
jobs: [{ id: "a", delivery: { channel: "telegram", to: "https://t.me/mychannel" } }],
});
await maybePersistResolvedTelegramTarget({
cfg: {} as OpenClawConfig,
rawTarget: "@MyChannel",
resolvedChatId: "-100123",
});
expect(writeConfigFile).toHaveBeenCalledWith(
expect.objectContaining({
channels: {
telegram: {
defaultTo: "-100123",
},
},
}),
expect.any(Object),
);
expect(saveCronStore).toHaveBeenCalledWith(
"/tmp/cron/jobs.json",
expect.objectContaining({
jobs: [{ id: "a", delivery: { channel: "telegram", to: "-100123" } }],
}),
);
});
});

View File

@@ -17,9 +17,17 @@ function asObjectRecord(value: unknown): Record<string, unknown> | null {
return value as Record<string, unknown>;
}
function normalizeTelegramLookupTargetForMatch(raw: string): string | undefined {
const normalized = normalizeTelegramLookupTarget(raw);
if (!normalized) {
return undefined;
}
return normalized.startsWith("@") ? normalized.toLowerCase() : normalized;
}
function normalizeTelegramTargetForMatch(raw: string): string | undefined {
const parsed = parseTelegramTarget(raw);
const normalized = normalizeTelegramLookupTarget(parsed.chatId);
const normalized = normalizeTelegramLookupTargetForMatch(parsed.chatId);
if (!normalized) {
return undefined;
}
@@ -49,7 +57,7 @@ function resolveLegacyRewrite(params: {
if (normalizeTelegramChatId(parsed.chatId)) {
return null;
}
const normalized = normalizeTelegramLookupTarget(parsed.chatId);
const normalized = normalizeTelegramLookupTargetForMatch(parsed.chatId);
if (!normalized) {
return null;
}