mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:54:31 +00:00
fix(cron): preserve telegram announce target + delivery truth
This commit is contained in:
@@ -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" } }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user