ai-chatbot/lib/notifications/dingtalk-robot-config.ts
Your Name 38c10d616b
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add dingtalk robot update notifications
2026-05-01 01:45:59 +08:00

38 lines
988 B
TypeScript

export const DINGTALK_ROBOT_NOTIFICATION_CONFIG_KEY =
"dingtalk_robot_notification_config";
export type DingTalkRobotNotificationConfig = {
enabled: boolean;
webhookUrl: string;
secret: string;
};
export const defaultDingTalkRobotNotificationConfig: DingTalkRobotNotificationConfig =
{
enabled: false,
webhookUrl: "",
secret: "",
};
function normalizeRobotString(value: unknown) {
return String(value || "")
.replace(/[\u2028\u2029]/g, "")
.replace(/[\u0000-\u001F\u007F]/g, "")
.trim();
}
export function normalizeDingTalkRobotNotificationConfig(
value: unknown,
): DingTalkRobotNotificationConfig {
if (!value || typeof value !== "object" || Array.isArray(value)) {
return defaultDingTalkRobotNotificationConfig;
}
const raw = value as Partial<DingTalkRobotNotificationConfig>;
return {
enabled: raw.enabled === true,
webhookUrl: normalizeRobotString(raw.webhookUrl),
secret: normalizeRobotString(raw.secret),
};
}