mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
Merge commit from fork
This commit is contained in:
65
src/config/telegram-webhook-secret.test.ts
Normal file
65
src/config/telegram-webhook-secret.test.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { validateConfigObject } from "./config.js";
|
||||
|
||||
describe("Telegram webhook config", () => {
|
||||
it("accepts webhookUrl when webhookSecret is configured", () => {
|
||||
const res = validateConfigObject({
|
||||
channels: {
|
||||
telegram: {
|
||||
webhookUrl: "https://example.com/telegram-webhook",
|
||||
webhookSecret: "secret",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects webhookUrl without webhookSecret", () => {
|
||||
const res = validateConfigObject({
|
||||
channels: {
|
||||
telegram: {
|
||||
webhookUrl: "https://example.com/telegram-webhook",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.issues[0]?.path).toBe("channels.telegram.webhookSecret");
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts account webhookUrl when base webhookSecret is configured", () => {
|
||||
const res = validateConfigObject({
|
||||
channels: {
|
||||
telegram: {
|
||||
webhookSecret: "secret",
|
||||
accounts: {
|
||||
ops: {
|
||||
webhookUrl: "https://example.com/telegram-webhook",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects account webhookUrl without webhookSecret", () => {
|
||||
const res = validateConfigObject({
|
||||
channels: {
|
||||
telegram: {
|
||||
accounts: {
|
||||
ops: {
|
||||
webhookUrl: "https://example.com/telegram-webhook",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.issues[0]?.path).toBe("channels.telegram.accounts.ops.webhookSecret");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -164,6 +164,43 @@ export const TelegramConfigSchema = TelegramAccountSchemaBase.extend({
|
||||
'channels.telegram.dmPolicy="open" requires channels.telegram.allowFrom to include "*"',
|
||||
});
|
||||
validateTelegramCustomCommands(value, ctx);
|
||||
|
||||
const baseWebhookUrl = typeof value.webhookUrl === "string" ? value.webhookUrl.trim() : "";
|
||||
const baseWebhookSecret =
|
||||
typeof value.webhookSecret === "string" ? value.webhookSecret.trim() : "";
|
||||
if (baseWebhookUrl && !baseWebhookSecret) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "channels.telegram.webhookUrl requires channels.telegram.webhookSecret",
|
||||
path: ["webhookSecret"],
|
||||
});
|
||||
}
|
||||
if (!value.accounts) {
|
||||
return;
|
||||
}
|
||||
for (const [accountId, account] of Object.entries(value.accounts)) {
|
||||
if (!account) {
|
||||
continue;
|
||||
}
|
||||
if (account.enabled === false) {
|
||||
continue;
|
||||
}
|
||||
const accountWebhookUrl =
|
||||
typeof account.webhookUrl === "string" ? account.webhookUrl.trim() : "";
|
||||
if (!accountWebhookUrl) {
|
||||
continue;
|
||||
}
|
||||
const accountSecret =
|
||||
typeof account.webhookSecret === "string" ? account.webhookSecret.trim() : "";
|
||||
if (!accountSecret && !baseWebhookSecret) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
"channels.telegram.accounts.*.webhookUrl requires channels.telegram.webhookSecret or channels.telegram.accounts.*.webhookSecret",
|
||||
path: ["accounts", accountId, "webhookSecret"],
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const DiscordDmSchema = z
|
||||
|
||||
Reference in New Issue
Block a user