|
1 | | -import { |
2 | | - inspectDiscordAccount, |
3 | | - type InspectedDiscordAccount, |
4 | | -} from "../../extensions/discord/src/account-inspect.js"; |
5 | | -import { |
6 | | - inspectSlackAccount, |
7 | | - type InspectedSlackAccount, |
8 | | -} from "../../extensions/slack/src/account-inspect.js"; |
9 | | -import { |
10 | | - inspectTelegramAccount, |
11 | | - type InspectedTelegramAccount, |
12 | | -} from "../../extensions/telegram/src/account-inspect.js"; |
13 | 1 | import type { OpenClawConfig } from "../config/config.js"; |
14 | 2 | import type { ChannelId } from "./plugins/types.js"; |
15 | 3 |
|
| 4 | +type DiscordInspectModule = typeof import("./read-only-account-inspect.discord.runtime.js"); |
| 5 | +type SlackInspectModule = typeof import("./read-only-account-inspect.slack.runtime.js"); |
| 6 | +type TelegramInspectModule = typeof import("./read-only-account-inspect.telegram.runtime.js"); |
| 7 | + |
| 8 | +let discordInspectModulePromise: Promise<DiscordInspectModule> | undefined; |
| 9 | +let slackInspectModulePromise: Promise<SlackInspectModule> | undefined; |
| 10 | +let telegramInspectModulePromise: Promise<TelegramInspectModule> | undefined; |
| 11 | + |
| 12 | +function loadDiscordInspectModule() { |
| 13 | + discordInspectModulePromise ??= import("./read-only-account-inspect.discord.runtime.js"); |
| 14 | + return discordInspectModulePromise; |
| 15 | +} |
| 16 | + |
| 17 | +function loadSlackInspectModule() { |
| 18 | + slackInspectModulePromise ??= import("./read-only-account-inspect.slack.runtime.js"); |
| 19 | + return slackInspectModulePromise; |
| 20 | +} |
| 21 | + |
| 22 | +function loadTelegramInspectModule() { |
| 23 | + telegramInspectModulePromise ??= import("./read-only-account-inspect.telegram.runtime.js"); |
| 24 | + return telegramInspectModulePromise; |
| 25 | +} |
| 26 | + |
16 | 27 | export type ReadOnlyInspectedAccount = |
17 | | - | InspectedDiscordAccount |
18 | | - | InspectedSlackAccount |
19 | | - | InspectedTelegramAccount; |
| 28 | + | Awaited<ReturnType<DiscordInspectModule["inspectDiscordAccount"]>> |
| 29 | + | Awaited<ReturnType<SlackInspectModule["inspectSlackAccount"]>> |
| 30 | + | Awaited<ReturnType<TelegramInspectModule["inspectTelegramAccount"]>>; |
20 | 31 |
|
21 | | -export function inspectReadOnlyChannelAccount(params: { |
| 32 | +export async function inspectReadOnlyChannelAccount(params: { |
22 | 33 | channelId: ChannelId; |
23 | 34 | cfg: OpenClawConfig; |
24 | 35 | accountId?: string | null; |
25 | | -}): ReadOnlyInspectedAccount | null { |
| 36 | +}): Promise<ReadOnlyInspectedAccount | null> { |
26 | 37 | if (params.channelId === "discord") { |
| 38 | + const { inspectDiscordAccount } = await loadDiscordInspectModule(); |
27 | 39 | return inspectDiscordAccount({ |
28 | 40 | cfg: params.cfg, |
29 | 41 | accountId: params.accountId, |
30 | 42 | }); |
31 | 43 | } |
32 | 44 | if (params.channelId === "slack") { |
| 45 | + const { inspectSlackAccount } = await loadSlackInspectModule(); |
33 | 46 | return inspectSlackAccount({ |
34 | 47 | cfg: params.cfg, |
35 | 48 | accountId: params.accountId, |
36 | 49 | }); |
37 | 50 | } |
38 | 51 | if (params.channelId === "telegram") { |
| 52 | + const { inspectTelegramAccount } = await loadTelegramInspectModule(); |
39 | 53 | return inspectTelegramAccount({ |
40 | 54 | cfg: params.cfg, |
41 | 55 | accountId: params.accountId, |
|
0 commit comments