mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
83bf0379c9
* refactor(channels): share plugin contract scaffolds * fix: preserve channel config hint metadata * chore: refresh Plugin SDK API baseline * ci: refresh plugin SDK surface budget * fix(ci): allow read-only state database boundary * fix(ci): dedupe read-only state database boundary
82 lines
3.1 KiB
TypeScript
82 lines
3.1 KiB
TypeScript
// Telegram plugin module implements secret contract behavior.
|
|
import {
|
|
collectConditionalChannelFieldAssignments,
|
|
createChannelSecretTargetRegistryEntries,
|
|
getChannelSurface,
|
|
hasConfiguredSecretInputValue,
|
|
hasOwnProperty,
|
|
type ResolverContext,
|
|
type SecretDefaults,
|
|
} from "openclaw/plugin-sdk/channel-secret-basic-runtime";
|
|
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
|
|
export const secretTargetRegistryEntries = createChannelSecretTargetRegistryEntries({
|
|
channelKey: "telegram",
|
|
account: ["botToken", "webhookSecret"],
|
|
channel: ["botToken", "webhookSecret"],
|
|
});
|
|
|
|
export function collectRuntimeConfigAssignments(params: {
|
|
config: { channels?: Record<string, unknown> };
|
|
defaults?: SecretDefaults;
|
|
context: ResolverContext;
|
|
}): void {
|
|
const resolved = getChannelSurface(params.config, "telegram");
|
|
if (!resolved) {
|
|
return;
|
|
}
|
|
const { channel: telegram, surface } = resolved;
|
|
const baseTokenFile = normalizeOptionalString(telegram.tokenFile) ?? "";
|
|
const accountTokenFile = (account: Record<string, unknown>) =>
|
|
normalizeOptionalString(account.tokenFile) ?? "";
|
|
collectConditionalChannelFieldAssignments({
|
|
channelKey: "telegram",
|
|
field: "botToken",
|
|
channel: telegram,
|
|
surface,
|
|
defaults: params.defaults,
|
|
context: params.context,
|
|
topLevelActiveWithoutAccounts: baseTokenFile.length === 0,
|
|
topLevelInheritedAccountActive: ({ account, enabled }) => {
|
|
if (!enabled || baseTokenFile.length > 0) {
|
|
return false;
|
|
}
|
|
const accountBotTokenConfigured = hasConfiguredSecretInputValue(
|
|
account.botToken,
|
|
params.defaults,
|
|
);
|
|
return !accountBotTokenConfigured && accountTokenFile(account).length === 0;
|
|
},
|
|
accountActive: ({ account, enabled }) => enabled && accountTokenFile(account).length === 0,
|
|
topInactiveReason:
|
|
"no enabled Telegram surface inherits this top-level botToken (tokenFile is configured).",
|
|
accountInactiveReason: "Telegram account is disabled or tokenFile is configured.",
|
|
});
|
|
const baseWebhookUrl = normalizeOptionalString(telegram.webhookUrl) ?? "";
|
|
const accountWebhookUrl = (account: Record<string, unknown>) =>
|
|
hasOwnProperty(account, "webhookUrl")
|
|
? (normalizeOptionalString(account.webhookUrl) ?? "")
|
|
: baseWebhookUrl;
|
|
collectConditionalChannelFieldAssignments({
|
|
channelKey: "telegram",
|
|
field: "webhookSecret",
|
|
channel: telegram,
|
|
surface,
|
|
defaults: params.defaults,
|
|
context: params.context,
|
|
topLevelActiveWithoutAccounts: baseWebhookUrl.length > 0,
|
|
topLevelInheritedAccountActive: ({ account, enabled }) =>
|
|
enabled && !hasOwnProperty(account, "webhookSecret") && accountWebhookUrl(account).length > 0,
|
|
accountActive: ({ account, enabled }) => enabled && accountWebhookUrl(account).length > 0,
|
|
topInactiveReason:
|
|
"no enabled Telegram webhook surface inherits this top-level webhookSecret (webhook mode is not active).",
|
|
accountInactiveReason:
|
|
"Telegram account is disabled or webhook mode is not active for this account.",
|
|
});
|
|
}
|
|
|
|
export const channelSecrets = {
|
|
secretTargetRegistryEntries,
|
|
collectRuntimeConfigAssignments,
|
|
};
|