mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 09:48:39 +00:00
refactor: share account-scoped config adapter accessors
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
buildAccountScopedDmSecurityPolicy,
|
||||
collectOpenGroupPolicyRestrictSendersWarnings,
|
||||
mapAllowFromEntries,
|
||||
createScopedAccountConfigAccessors,
|
||||
} from "openclaw/plugin-sdk";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
@@ -34,6 +34,17 @@ const meta = {
|
||||
systemImage: "message.fill",
|
||||
};
|
||||
|
||||
const lineConfigAccessors = createScopedAccountConfigAccessors({
|
||||
resolveAccount: ({ cfg, accountId }) =>
|
||||
getLineRuntime().channel.line.resolveLineAccount({ cfg, accountId: accountId ?? undefined }),
|
||||
resolveAllowFrom: (account: ResolvedLineAccount) => account.config.allowFrom,
|
||||
formatAllowFrom: (allowFrom) =>
|
||||
allowFrom
|
||||
.map((entry) => String(entry).trim())
|
||||
.filter(Boolean)
|
||||
.map((entry) => entry.replace(/^line:(?:user:)?/i, "")),
|
||||
});
|
||||
|
||||
function patchLineAccountConfig(
|
||||
cfg: OpenClawConfig,
|
||||
lineConfig: LineConfig,
|
||||
@@ -147,19 +158,7 @@ export const linePlugin: ChannelPlugin<ResolvedLineAccount> = {
|
||||
configured: Boolean(account.channelAccessToken?.trim() && account.channelSecret?.trim()),
|
||||
tokenSource: account.tokenSource ?? undefined,
|
||||
}),
|
||||
resolveAllowFrom: ({ cfg, accountId }) =>
|
||||
mapAllowFromEntries(
|
||||
getLineRuntime().channel.line.resolveLineAccount({ cfg, accountId: accountId ?? undefined })
|
||||
.config.allowFrom,
|
||||
),
|
||||
formatAllowFrom: ({ allowFrom }) =>
|
||||
allowFrom
|
||||
.map((entry) => String(entry).trim())
|
||||
.filter(Boolean)
|
||||
.map((entry) => {
|
||||
// LINE sender IDs are case-sensitive; keep original casing.
|
||||
return entry.replace(/^line:(?:user:)?/i, "");
|
||||
}),
|
||||
...lineConfigAccessors,
|
||||
},
|
||||
security: {
|
||||
resolveDmPolicy: ({ cfg, accountId, account }) => {
|
||||
|
||||
Reference in New Issue
Block a user