openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
15 lines • 11.8 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{o as hasConfiguredSecretInput}from"./types.secrets-UWdyCdE6.mjs";import{n as normalizeAccountId,t as DEFAULT_ACCOUNT_ID}from"./account-id-3yqrEsRn.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{t as defineChannelSetupContract}from"./setup-contract-OX3vOUb4.mjs";import{n as getChatChannelMeta}from"./chat-meta-CPf8a-2D.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import{t as formatDocsLink}from"./links-C_FK9uVv.mjs";import{t as createSetupTranslator}from"./i18n-B77_oMGl.mjs";import{a as mergeTelegramAccountConfig,n as listTelegramAccountIds}from"./account-selection-CSIzQZif.mjs";import{n as applySetupAccountConfigPatch,r as createEnvPatchedAccountSetupAdapter}from"./setup-helpers-AzpIWWec.mjs";import{N as splitSetupEntries,a as createAllowFromSection,b as patchChannelConfigForAccount,j as setSetupChannelEnabled,s as createStandardChannelSetupStatus,w as promptResolvedAllowFrom}from"./setup-wizard-helpers-k68PnsC_.mjs";import{n as defineTokenCredential}from"./setup-credential-1B_CKTVL.mjs";import"./setup-CylWArcc.mjs";import"./setup-runtime-CIBJpC8W.mjs";import"./channel-setup-B5AhNmeg.mjs";import"./setup-tools-CPykgh4_.mjs";import{a as createScopedChannelConfigAdapter,t as adaptScopedAccountAccessor}from"./channel-config-helpers-CNBYUNFE.mjs";import{t as formatAllowFromLowercase}from"./allow-from-CGbgsBUC.mjs";import{t as createChannelDmPolicy}from"./channel-dm-policy-C8gYPqYm.mjs";import"./channel-plugin-common-CBkK1n_P.mjs";import{i as resolveTelegramAccount,r as resolveDefaultTelegramAccountId}from"./accounts-CHjEWHkL.mjs";import{r as normalizeTelegramAllowFromEntry,t as isNumericTelegramSenderUserId}from"./allow-from-Cl7XrCrw.mjs";import{r as inspectTelegramAccount}from"./account-inspect-QgH_f1ZJ.mjs";import{n as singleAccountKeysToMove,t as namedAccountPromotionKeys}from"./setup-contract-BFAO2sCZ.mjs";import{t as TelegramChannelConfigSchema}from"./config-schema-DleBvwgP.mjs";import{n as collectRuntimeConfigAssignments,r as secretTargetRegistryEntries}from"./secret-contract-nQoCnPc1.mjs";
//!extensions/telegram/src/config-adapter.ts
function resolveTelegramConfigAccessorAccount(e){const n=normalizeAccountId(e.accountId??resolveDefaultTelegramAccountId(e.cfg));return{config:mergeTelegramAccountConfig(e.cfg,n)}}const telegramConfigAdapter=createScopedChannelConfigAdapter({sectionKey:`telegram`,listAccountIds:listTelegramAccountIds,resolveAccount:adaptScopedAccountAccessor(resolveTelegramAccount),resolveAccessorAccount:resolveTelegramConfigAccessorAccount,inspectAccount:adaptScopedAccountAccessor(inspectTelegramAccount),defaultAccountId:resolveDefaultTelegramAccountId,clearBaseFields:[`botToken`,`tokenFile`,`name`],resolveAllowFrom:e=>e.config.allowFrom,formatAllowFrom:e=>formatAllowFromLowercase({allowFrom:e,stripPrefixRe:/^(telegram|tg):/i}),resolveDefaultTo:e=>e.config.defaultTo});
//!extensions/telegram/src/setup-core.ts
const t$1=createSetupTranslator();const channel$2=`telegram`;function getTelegramTokenHelpLines(){return[t$1(`wizard.telegram.tokenHelpOpenBotFather`),t$1(`wizard.telegram.tokenHelpNewBot`),t$1(`wizard.telegram.tokenHelpCopyToken`),t$1(`wizard.telegram.tokenHelpWebApp`,{url:`https://t.me/BotFather?startapp`}),t$1(`wizard.telegram.tokenEnvTip`),t$1(`wizard.channels.docs`,{link:formatDocsLink(`/telegram`)}),t$1(`wizard.telegram.website`,{url:`https://openclaw.ai`})]}function getTelegramUserIdHelpLines(){return[t$1(`wizard.telegram.userIdHelpLogs`,{command:formatCliCommand(`openclaw logs --follow`)}),t$1(`wizard.telegram.userIdHelpGetUpdates`),t$1(`wizard.telegram.userIdHelpThirdParty`),t$1(`wizard.channels.docs`,{link:formatDocsLink(`/telegram`)}),t$1(`wizard.telegram.website`,{url:`https://openclaw.ai`})]}function parseTelegramAllowFromId(e){const n=normalizeTelegramAllowFromEntry(e);return isNumericTelegramSenderUserId(n)?n:null}async function promptTelegramAllowFromForAccount(e){const n=e.accountId??resolveDefaultTelegramAccountId(e.cfg);const r=resolveTelegramAccount({cfg:e.cfg,accountId:n});await e.prompter.note(getTelegramUserIdHelpLines().join(`
`),t$1(`wizard.telegram.userIdTitle`));const i=await promptResolvedAllowFrom({prompter:e.prompter,existing:r.config.allowFrom??[],message:t$1(`wizard.telegram.allowFromPrompt`),placeholder:`123456789`,label:t$1(`wizard.telegram.allowlistTitle`),parseInputs:splitSetupEntries,parseId:parseTelegramAllowFromId,invalidWithoutTokenNote:t$1(`wizard.telegram.allowFromInvalid`),resolveEntries:async({entries:e})=>e.map(e=>{const n=parseTelegramAllowFromId(e);return{input:e,resolved:Boolean(n),id:n}})});return applyTelegramAllowFrom(e.cfg,n,i)}function applyTelegramAllowFrom(e,n,r){return patchChannelConfigForAccount({cfg:e,channel:channel$2,accountId:n,patch:{dmPolicy:`allowlist`,allowFrom:r},setupSurface:telegramSetupAdapter})}const telegramSetupAdapter={...createEnvPatchedAccountSetupAdapter({channelKey:channel$2,defaultAccountOnlyEnvError:`TELEGRAM_BOT_TOKEN can only be used for the default account.`,missingCredentialError:`Telegram requires token or --token-file (or --use-env).`,hasCredentials:e=>Boolean(e.token||e.tokenFile),buildPatch:e=>e.tokenFile?{tokenFile:e.tokenFile}:e.token?{botToken:e.token}:{}}),singleAccountKeysToMove,namedAccountPromotionKeys};const telegramSetupContract=defineChannelSetupContract({fields:{token:{kind:`string`,sensitive:true,cli:{flags:`--token <token>`,description:`Telegram bot token`}},tokenFile:{kind:`string`,sensitive:true,cli:{flags:`--token-file <path>`,description:`Telegram bot token file`}},useEnv:{kind:`boolean`,cli:{flags:`--use-env`,description:`Use TELEGRAM_BOT_TOKEN`},envVars:[`TELEGRAM_BOT_TOKEN`]}},legacyAdapter:telegramSetupAdapter});
//!extensions/telegram/src/setup-plugin.ts
const TELEGRAM_CHANNEL=`telegram`;function createTelegramSetupPluginBase(e){return{id:TELEGRAM_CHANNEL,setupContract:e.setupContract,meta:{...getChatChannelMeta(TELEGRAM_CHANNEL),quickstartAllowFrom:true},setupWizard:e.setupWizard,capabilities:{chatTypes:[`direct`,`group`,`channel`,`thread`],reactions:true,reactionSlots:`single`,threads:true,media:true,tts:{voice:{synthesisTarget:`voice-note`,captionedFinalText:true}},polls:true,nativeCommands:true,blockStreaming:true},reload:{configPrefixes:[`channels.telegram`],noopPrefixes:[`messages.inbound`,`messages.ackReactionScope`,...[`dmPolicy`,`allowFrom`,`groupAllowFrom`,`groupPolicy`,`replyToMode`,`streaming`,`textChunkLimit`].flatMap(e=>[`channels.telegram.${e}`,`channels.telegram.accounts.*.${e}`])]},configSchema:TelegramChannelConfigSchema,config:{...telegramConfigAdapter,hasConfiguredState:({env:e})=>typeof e?.TELEGRAM_BOT_TOKEN===`string`&&e.TELEGRAM_BOT_TOKEN.trim().length>0,isConfigured:(e,n)=>{const r=inspectTelegramAccount({cfg:n,accountId:e.accountId});return r.configured&&Boolean(r.token.trim())},unconfiguredReason:(e,n)=>{const r=inspectTelegramAccount({cfg:n,accountId:e.accountId});return r.stateReason??(r.tokenStatus===`configured_unavailable`?`not configured: token ${r.tokenSource} is configured but unavailable`:`not configured`)},describeAccount:(e,n)=>{const r=inspectTelegramAccount({cfg:n,accountId:e.accountId});return{accountId:e.accountId,name:e.name,enabled:e.enabled,configured:r.configured,tokenSource:r.tokenSource,tokenStatus:r.tokenStatus}}},secrets:{secretTargetRegistryEntries,collectRuntimeConfigAssignments}}}
//!extensions/telegram/src/setup-surface.helpers.ts
const channel$1=`telegram`;function ensureTelegramDefaultGroupMentionGate(e,n){const r=resolveTelegramAccount({cfg:e,accountId:n});const i=r.config.groups?.[`*`];if(i?.requireMention!==void 0)return e;return patchChannelConfigForAccount({cfg:e,channel:channel$1,accountId:n,patch:{groups:{...r.config.groups,"*":{...i,requireMention:true}}},setupSurface:telegramSetupAdapter})}function shouldShowTelegramDmAccessWarning(e,n){const r=mergeTelegramAccountConfig(e,n);const i=Array.isArray(r.allowFrom)&&r.allowFrom.some(e=>normalizeOptionalString(String(e)));return(r.dmPolicy??`pairing`)===`pairing`&&!i}function buildTelegramDmAccessWarningLines(e){const n=e==="default"?`channels.telegram`:`channels.telegram.accounts.${e}`;return[`Your bot is using DM policy: pairing.`,`Any Telegram user who discovers the bot can send pairing requests.`,`For private use, configure an allowlist with your Telegram user id:`,` `+formatCliCommand(`openclaw config set ${n}.dmPolicy "allowlist"`),` `+formatCliCommand(`openclaw config set ${n}.allowFrom '["YOUR_USER_ID"]'`),`Docs: ${formatDocsLink(`/channels/pairing`,`channels/pairing`)}`]}const telegramSetupDmPolicy=createChannelDmPolicy({label:`Telegram`,channel:channel$1,resolveAccount:(e,n)=>{const r=n??resolveDefaultTelegramAccountId(e);return{accountId:r,config:mergeTelegramAccountConfig(e,r)}},applyPatch:({cfg:e,requestedAccountId:n,account:r,patch:i})=>n==null&&r.accountId!=="default"?applySetupAccountConfigPatch({cfg:e,channelKey:channel$1,accountId:r.accountId,patch:i}):patchChannelConfigForAccount({cfg:e,channel:channel$1,accountId:r.accountId,patch:i,setupSurface:telegramSetupAdapter}),promptAllowFrom:promptTelegramAllowFromForAccount});
//!extensions/telegram/src/setup-surface.ts
const t=createSetupTranslator();const channel=`telegram`;const telegramSetupWizard={channel,status:createStandardChannelSetupStatus({channelLabel:`Telegram`,configuredLabel:t(`wizard.channels.statusConfigured`),unconfiguredLabel:t(`wizard.channels.statusNeedsToken`),configuredHint:t(`wizard.channels.statusRecommendedConfigured`),unconfiguredHint:t(`wizard.channels.statusRecommendedNewcomerFriendly`),configuredScore:1,unconfiguredScore:10,resolveConfigured:({cfg:e,accountId:n})=>(n?[n]:listTelegramAccountIds(e)).some(n=>inspectTelegramAccount({cfg:e,accountId:n}).configured)}),prepare:async({cfg:e,accountId:n,credentialValues:r})=>({cfg:ensureTelegramDefaultGroupMentionGate(e,n),credentialValues:r}),credentials:[defineTokenCredential({inputKey:`token`,configKey:`botToken`,configuredFields:[`botToken`,`tokenFile`],providerHint:channel,credentialLabel:t(`wizard.telegram.botToken`),preferredEnvVar:`TELEGRAM_BOT_TOKEN`,helpTitle:t(`wizard.telegram.botToken`),helpLines:getTelegramTokenHelpLines(),envPrompt:t(`wizard.telegram.tokenEnvPrompt`),keepPrompt:t(`wizard.telegram.tokenKeepPrompt`),inputPrompt:t(`wizard.telegram.tokenInputPrompt`),allowEnv:({accountId:e})=>e===DEFAULT_ACCOUNT_ID,resolveAccount:({cfg:e,accountId:n})=>resolveTelegramAccount({cfg:e,accountId:n}),hasConfiguredValue:e=>hasConfiguredSecretInput(e.config.botToken)||Boolean(e.config.tokenFile?.trim()),resolvedValue:e=>normalizeOptionalString(e.token),envValue:({accountId:e})=>e==="default"?normalizeOptionalString(process.env.TELEGRAM_BOT_TOKEN):void 0})],allowFrom:createAllowFromSection({helpTitle:t(`wizard.telegram.userIdTitle`),helpLines:getTelegramUserIdHelpLines(),message:t(`wizard.telegram.allowFromPrompt`),placeholder:`123456789`,invalidWithoutCredentialNote:t(`wizard.telegram.allowFromInvalid`),parseInputs:splitSetupEntries,parseId:parseTelegramAllowFromId,apply:async({cfg:e,accountId:n,allowFrom:r})=>applyTelegramAllowFrom(e,n,r)}),finalize:async({cfg:e,accountId:n,prompter:r})=>{if(!shouldShowTelegramDmAccessWarning(e,n))return;await r.note(buildTelegramDmAccessWarningLines(n).join(`
`),`Telegram DM access warning`)},dmPolicy:telegramSetupDmPolicy,disable:e=>setSetupChannelEnabled(e,channel,false)};
//!extensions/telegram/src/channel.setup.ts
const telegramSetupPlugin=createTelegramSetupPluginBase({setupWizard:telegramSetupWizard,setupContract:telegramSetupContract});export{resolveTelegramConfigAccessorAccount as a,telegramSetupContract as i,telegramSetupWizard as n,telegramConfigAdapter as o,createTelegramSetupPluginBase as r,telegramSetupPlugin as t};