mirror of https://github.com/openclaw/openclaw.git
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import {
|
|
normalizeAccountId,
|
|
patchScopedAccountConfig,
|
|
prepareScopedSetupConfig,
|
|
setTopLevelChannelDmPolicyWithAllowFrom,
|
|
type ChannelSetupAdapter,
|
|
type DmPolicy,
|
|
type OpenClawConfig,
|
|
} from "openclaw/plugin-sdk/setup";
|
|
import { applyBlueBubblesConnectionConfig } from "./config-apply.js";
|
|
|
|
const channel = "bluebubbles" as const;
|
|
|
|
export function setBlueBubblesDmPolicy(cfg: OpenClawConfig, dmPolicy: DmPolicy): OpenClawConfig {
|
|
return setTopLevelChannelDmPolicyWithAllowFrom({
|
|
cfg,
|
|
channel,
|
|
dmPolicy,
|
|
});
|
|
}
|
|
|
|
export function setBlueBubblesAllowFrom(
|
|
cfg: OpenClawConfig,
|
|
accountId: string,
|
|
allowFrom: string[],
|
|
): OpenClawConfig {
|
|
return patchScopedAccountConfig({
|
|
cfg,
|
|
channelKey: channel,
|
|
accountId,
|
|
patch: { allowFrom },
|
|
ensureChannelEnabled: false,
|
|
ensureAccountEnabled: false,
|
|
});
|
|
}
|
|
|
|
export const blueBubblesSetupAdapter: ChannelSetupAdapter = {
|
|
resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
|
|
applyAccountName: ({ cfg, accountId, name }) =>
|
|
prepareScopedSetupConfig({
|
|
cfg,
|
|
channelKey: channel,
|
|
accountId,
|
|
name,
|
|
}),
|
|
validateInput: ({ input }) => {
|
|
if (!input.httpUrl && !input.password) {
|
|
return "BlueBubbles requires --http-url and --password.";
|
|
}
|
|
if (!input.httpUrl) {
|
|
return "BlueBubbles requires --http-url.";
|
|
}
|
|
if (!input.password) {
|
|
return "BlueBubbles requires --password.";
|
|
}
|
|
return null;
|
|
},
|
|
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
const next = prepareScopedSetupConfig({
|
|
cfg,
|
|
channelKey: channel,
|
|
accountId,
|
|
name: input.name,
|
|
migrateBaseName: true,
|
|
});
|
|
return applyBlueBubblesConnectionConfig({
|
|
cfg: next,
|
|
accountId,
|
|
patch: {
|
|
serverUrl: input.httpUrl,
|
|
password: input.password,
|
|
webhookPath: input.webhookPath,
|
|
},
|
|
onlyDefinedFields: true,
|
|
});
|
|
},
|
|
};
|