mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
// Msteams plugin module implements approval auth behavior.
|
|
import { createChannelApprovalAuth } from "openclaw/plugin-sdk/approval-auth-runtime";
|
|
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
import type { OpenClawConfig } from "../runtime-api.js";
|
|
import { normalizeMSTeamsMessagingTarget } from "./resolve-allowlist.js";
|
|
|
|
const MSTEAMS_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
|
function normalizeMSTeamsApproverId(value: string | number): string | undefined {
|
|
const normalized = normalizeMSTeamsMessagingTarget(String(value));
|
|
const id = normalizeOptionalLowercaseString(
|
|
normalized?.startsWith("user:") ? normalized.slice("user:".length) : normalized,
|
|
);
|
|
return id && MSTEAMS_ID_RE.test(id) ? id : undefined;
|
|
}
|
|
|
|
function resolveMSTeamsChannelConfig(cfg: OpenClawConfig) {
|
|
return cfg.channels?.msteams;
|
|
}
|
|
|
|
export const msTeamsApprovalAuth = createChannelApprovalAuth({
|
|
channelLabel: "Microsoft Teams",
|
|
resolveInputs: ({ cfg }) => {
|
|
const channel = resolveMSTeamsChannelConfig(cfg);
|
|
return { allowFrom: channel?.allowFrom, defaultTo: channel?.defaultTo };
|
|
},
|
|
normalizeApprover: normalizeMSTeamsApproverId,
|
|
normalizeSenderId: (value) => {
|
|
const trimmed = normalizeOptionalLowercaseString(value);
|
|
if (!trimmed) {
|
|
return undefined;
|
|
}
|
|
return MSTEAMS_ID_RE.test(trimmed) ? trimmed : undefined;
|
|
},
|
|
}).approvalAuth;
|