mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:54:33 +00:00
refactor(slack): reuse shared account merge helper
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { hasConfiguredSecretInput, normalizeSecretInputString } from "../config/types.secrets.js";
|
import { hasConfiguredSecretInput, normalizeSecretInputString } from "../config/types.secrets.js";
|
||||||
import type { SlackAccountConfig } from "../config/types.slack.js";
|
import type { SlackAccountConfig } from "../config/types.slack.js";
|
||||||
import { resolveAccountEntry } from "../routing/account-lookup.js";
|
|
||||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||||
import { resolveDefaultSlackAccountId, type SlackTokenSource } from "./accounts.js";
|
import {
|
||||||
|
mergeSlackAccountConfig,
|
||||||
|
resolveDefaultSlackAccountId,
|
||||||
|
type SlackTokenSource,
|
||||||
|
} from "./accounts.js";
|
||||||
|
|
||||||
export type SlackCredentialStatus = "available" | "configured_unavailable" | "missing";
|
export type SlackCredentialStatus = "available" | "configured_unavailable" | "missing";
|
||||||
|
|
||||||
@@ -39,21 +42,6 @@ export type InspectedSlackAccount = {
|
|||||||
channels?: SlackAccountConfig["channels"];
|
channels?: SlackAccountConfig["channels"];
|
||||||
};
|
};
|
||||||
|
|
||||||
function resolveSlackAccountConfig(
|
|
||||||
cfg: OpenClawConfig,
|
|
||||||
accountId: string,
|
|
||||||
): SlackAccountConfig | undefined {
|
|
||||||
return resolveAccountEntry(cfg.channels?.slack?.accounts, accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeSlackAccountConfig(cfg: OpenClawConfig, accountId: string): SlackAccountConfig {
|
|
||||||
const { accounts: _ignored, ...base } = (cfg.channels?.slack ?? {}) as SlackAccountConfig & {
|
|
||||||
accounts?: unknown;
|
|
||||||
};
|
|
||||||
const account = resolveSlackAccountConfig(cfg, accountId) ?? {};
|
|
||||||
return { ...base, ...account };
|
|
||||||
}
|
|
||||||
|
|
||||||
function inspectSlackToken(value: unknown): {
|
function inspectSlackToken(value: unknown): {
|
||||||
token?: string;
|
token?: string;
|
||||||
source: Exclude<SlackTokenSource, "env">;
|
source: Exclude<SlackTokenSource, "env">;
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ function resolveAccountConfig(
|
|||||||
return resolveAccountEntry(cfg.channels?.slack?.accounts, accountId);
|
return resolveAccountEntry(cfg.channels?.slack?.accounts, accountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeSlackAccountConfig(cfg: OpenClawConfig, accountId: string): SlackAccountConfig {
|
export function mergeSlackAccountConfig(
|
||||||
|
cfg: OpenClawConfig,
|
||||||
|
accountId: string,
|
||||||
|
): SlackAccountConfig {
|
||||||
const { accounts: _ignored, ...base } = (cfg.channels?.slack ?? {}) as SlackAccountConfig & {
|
const { accounts: _ignored, ...base } = (cfg.channels?.slack ?? {}) as SlackAccountConfig & {
|
||||||
accounts?: unknown;
|
accounts?: unknown;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user