refactor(telegram): share plugin base config
This commit is contained in:
parent
7e9c46d7dd
commit
e820c255bc
@ -1,69 +1,13 @@
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
getChatChannelMeta,
|
||||
TelegramConfigSchema,
|
||||
type ChannelPlugin,
|
||||
} from "openclaw/plugin-sdk/telegram";
|
||||
import { type ChannelPlugin } from "openclaw/plugin-sdk/telegram";
|
||||
import { type ResolvedTelegramAccount } from "./accounts.js";
|
||||
import type { TelegramProbe } from "./probe.js";
|
||||
import { telegramSetupAdapter } from "./setup-core.js";
|
||||
import { telegramSetupWizard } from "./setup-surface.js";
|
||||
import {
|
||||
findTelegramTokenOwnerAccountId,
|
||||
formatDuplicateTelegramTokenReason,
|
||||
telegramConfigAccessors,
|
||||
telegramConfigBase,
|
||||
} from "./shared.js";
|
||||
import { createTelegramPluginBase } from "./shared.js";
|
||||
|
||||
export const telegramSetupPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProbe> = {
|
||||
id: "telegram",
|
||||
meta: {
|
||||
...getChatChannelMeta("telegram"),
|
||||
quickstartAllowFrom: true,
|
||||
},
|
||||
setupWizard: telegramSetupWizard,
|
||||
capabilities: {
|
||||
chatTypes: ["direct", "group", "channel", "thread"],
|
||||
reactions: true,
|
||||
threads: true,
|
||||
media: true,
|
||||
polls: true,
|
||||
nativeCommands: true,
|
||||
blockStreaming: true,
|
||||
},
|
||||
reload: { configPrefixes: ["channels.telegram"] },
|
||||
configSchema: buildChannelConfigSchema(TelegramConfigSchema),
|
||||
config: {
|
||||
...telegramConfigBase,
|
||||
isConfigured: (account, cfg) => {
|
||||
if (!account.token?.trim()) {
|
||||
return false;
|
||||
}
|
||||
return !findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId });
|
||||
},
|
||||
unconfiguredReason: (account, cfg) => {
|
||||
if (!account.token?.trim()) {
|
||||
return "not configured";
|
||||
}
|
||||
const ownerAccountId = findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId });
|
||||
if (!ownerAccountId) {
|
||||
return "not configured";
|
||||
}
|
||||
return formatDuplicateTelegramTokenReason({
|
||||
accountId: account.accountId,
|
||||
ownerAccountId,
|
||||
});
|
||||
},
|
||||
describeAccount: (account, cfg) => ({
|
||||
accountId: account.accountId,
|
||||
name: account.name,
|
||||
enabled: account.enabled,
|
||||
configured:
|
||||
Boolean(account.token?.trim()) &&
|
||||
!findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }),
|
||||
tokenSource: account.tokenSource,
|
||||
}),
|
||||
...telegramConfigAccessors,
|
||||
},
|
||||
setup: telegramSetupAdapter,
|
||||
...createTelegramPluginBase({
|
||||
setupWizard: telegramSetupWizard,
|
||||
setup: telegramSetupAdapter,
|
||||
}),
|
||||
};
|
||||
|
||||
@ -15,11 +15,9 @@ import { resolveExecApprovalCommandDisplay } from "openclaw/plugin-sdk/infra-run
|
||||
import { buildExecApprovalPendingReplyPayload } from "openclaw/plugin-sdk/infra-runtime";
|
||||
import { parseTelegramTopicConversation } from "openclaw/plugin-sdk/telegram";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
buildTokenChannelStatusSummary,
|
||||
clearAccountEntryFields,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
getChatChannelMeta,
|
||||
listTelegramDirectoryGroupsFromConfig,
|
||||
listTelegramDirectoryPeersFromConfig,
|
||||
PAIRING_APPROVED_MESSAGE,
|
||||
@ -27,7 +25,6 @@ import {
|
||||
resolveConfiguredFromCredentialStatuses,
|
||||
resolveTelegramGroupRequireMention,
|
||||
resolveTelegramGroupToolPolicy,
|
||||
TelegramConfigSchema,
|
||||
type ChannelPlugin,
|
||||
type ChannelMessageActionAdapter,
|
||||
type OpenClawConfig,
|
||||
@ -54,10 +51,10 @@ import { sendTypingTelegram } from "./send.js";
|
||||
import { telegramSetupAdapter } from "./setup-core.js";
|
||||
import { telegramSetupWizard } from "./setup-surface.js";
|
||||
import {
|
||||
createTelegramPluginBase,
|
||||
findTelegramTokenOwnerAccountId,
|
||||
formatDuplicateTelegramTokenReason,
|
||||
telegramConfigAccessors,
|
||||
telegramConfigBase,
|
||||
} from "./shared.js";
|
||||
import { collectTelegramStatusIssues } from "./status-issues.js";
|
||||
import { parseTelegramTarget } from "./targets.js";
|
||||
@ -66,8 +63,6 @@ type TelegramSendFn = ReturnType<
|
||||
typeof getTelegramRuntime
|
||||
>["channel"]["telegram"]["sendMessageTelegram"];
|
||||
|
||||
const meta = getChatChannelMeta("telegram");
|
||||
|
||||
type TelegramSendOptions = NonNullable<Parameters<TelegramSendFn>[2]>;
|
||||
|
||||
function buildTelegramSendOptions(params: {
|
||||
@ -324,12 +319,10 @@ function readTelegramAllowlistConfig(account: ResolvedTelegramAccount) {
|
||||
}
|
||||
|
||||
export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProbe> = {
|
||||
id: "telegram",
|
||||
meta: {
|
||||
...meta,
|
||||
quickstartAllowFrom: true,
|
||||
},
|
||||
setupWizard: telegramSetupWizard,
|
||||
...createTelegramPluginBase({
|
||||
setupWizard: telegramSetupWizard,
|
||||
setup: telegramSetupAdapter,
|
||||
}),
|
||||
pairing: {
|
||||
idLabel: "telegramUserId",
|
||||
normalizeAllowEntry: (entry) => entry.replace(/^(telegram|tg):/i, ""),
|
||||
@ -347,49 +340,6 @@ export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProb
|
||||
);
|
||||
},
|
||||
},
|
||||
capabilities: {
|
||||
chatTypes: ["direct", "group", "channel", "thread"],
|
||||
reactions: true,
|
||||
threads: true,
|
||||
media: true,
|
||||
polls: true,
|
||||
nativeCommands: true,
|
||||
blockStreaming: true,
|
||||
},
|
||||
reload: { configPrefixes: ["channels.telegram"] },
|
||||
configSchema: buildChannelConfigSchema(TelegramConfigSchema),
|
||||
config: {
|
||||
...telegramConfigBase,
|
||||
isConfigured: (account, cfg) => {
|
||||
if (!account.token?.trim()) {
|
||||
return false;
|
||||
}
|
||||
return !findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId });
|
||||
},
|
||||
unconfiguredReason: (account, cfg) => {
|
||||
if (!account.token?.trim()) {
|
||||
return "not configured";
|
||||
}
|
||||
const ownerAccountId = findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId });
|
||||
if (!ownerAccountId) {
|
||||
return "not configured";
|
||||
}
|
||||
return formatDuplicateTelegramTokenReason({
|
||||
accountId: account.accountId,
|
||||
ownerAccountId,
|
||||
});
|
||||
},
|
||||
describeAccount: (account, cfg) => ({
|
||||
accountId: account.accountId,
|
||||
name: account.name,
|
||||
enabled: account.enabled,
|
||||
configured:
|
||||
Boolean(account.token?.trim()) &&
|
||||
!findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }),
|
||||
tokenSource: account.tokenSource,
|
||||
}),
|
||||
...telegramConfigAccessors,
|
||||
},
|
||||
allowlist: {
|
||||
supportsScope: ({ scope }) => scope === "dm" || scope === "group" || scope === "all",
|
||||
readConfig: ({ cfg, accountId }) =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user