UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.27 kB
import{hasConfiguredAccountValue}from"openclaw/plugin-sdk/account-core";import{collectConditionalChannelFieldAssignments,createChannelSecretContract,hasConfiguredSecretInputValue,hasOwnProperty}from"openclaw/plugin-sdk/channel-secret-basic-runtime";import{normalizeOptionalString}from"openclaw/plugin-sdk/string-coerce-runtime"; //!extensions/telegram/src/secret-contract.ts const channelSecrets=createChannelSecretContract({channelKey:`telegram`,account:[`botToken`,`webhookSecret`],channel:[`botToken`,`webhookSecret`],hasImplicitDefaultAccount:({channel:e,context:t})=>hasConfiguredAccountValue(e.botToken)||hasConfiguredAccountValue(e.tokenFile)||hasConfiguredAccountValue(t.env.TELEGRAM_BOT_TOKEN),collect(e){const{channel:t}=e;const n=normalizeOptionalString(t.tokenFile)??``;const accountTokenFile=e=>normalizeOptionalString(e.tokenFile)??``;collectConditionalChannelFieldAssignments({...e,field:`botToken`,topLevelActiveWithoutAccounts:n.length===0,topLevelInheritedAccountActive:({account:t,enabled:r})=>{if(!r||n.length>0)return false;return!hasConfiguredSecretInputValue(t.botToken,e.defaults)&&accountTokenFile(t).length===0},accountActive:({account:e,enabled:t})=>t&&accountTokenFile(e).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 r=normalizeOptionalString(t.webhookUrl)??``;const accountWebhookUrl=e=>hasOwnProperty(e,`webhookUrl`)?normalizeOptionalString(e.webhookUrl)??``:r;collectConditionalChannelFieldAssignments({...e,field:`webhookSecret`,topLevelActiveWithoutAccounts:r.length>0,topLevelInheritedAccountActive:({account:e,enabled:t})=>t&&!hasOwnProperty(e,`webhookSecret`)&&accountWebhookUrl(e).length>0,accountActive:({account:e,enabled:t})=>t&&accountWebhookUrl(e).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.`})}});const{secretTargetRegistryEntries,collectRuntimeConfigAssignments}=channelSecrets;export{collectRuntimeConfigAssignments as n,secretTargetRegistryEntries as r,channelSecrets as t};