mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-25 17:02:46 +00:00
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
import type { TelegramInlineButtonsScope } from "../../../src/config/types.telegram.js";
|
|
import { listTelegramAccountIds, resolveTelegramAccount } from "./accounts.js";
|
|
|
|
const DEFAULT_INLINE_BUTTONS_SCOPE: TelegramInlineButtonsScope = "allowlist";
|
|
|
|
function normalizeInlineButtonsScope(value: unknown): TelegramInlineButtonsScope | undefined {
|
|
if (typeof value !== "string") {
|
|
return undefined;
|
|
}
|
|
const trimmed = value.trim().toLowerCase();
|
|
if (
|
|
trimmed === "off" ||
|
|
trimmed === "dm" ||
|
|
trimmed === "group" ||
|
|
trimmed === "all" ||
|
|
trimmed === "allowlist"
|
|
) {
|
|
return trimmed as TelegramInlineButtonsScope;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function resolveInlineButtonsScopeFromCapabilities(
|
|
capabilities: unknown,
|
|
): TelegramInlineButtonsScope {
|
|
if (!capabilities) {
|
|
return DEFAULT_INLINE_BUTTONS_SCOPE;
|
|
}
|
|
if (Array.isArray(capabilities)) {
|
|
const enabled = capabilities.some(
|
|
(entry) => String(entry).trim().toLowerCase() === "inlinebuttons",
|
|
);
|
|
return enabled ? "all" : "off";
|
|
}
|
|
if (typeof capabilities === "object") {
|
|
const inlineButtons = (capabilities as { inlineButtons?: unknown }).inlineButtons;
|
|
return normalizeInlineButtonsScope(inlineButtons) ?? DEFAULT_INLINE_BUTTONS_SCOPE;
|
|
}
|
|
return DEFAULT_INLINE_BUTTONS_SCOPE;
|
|
}
|
|
|
|
export function resolveTelegramInlineButtonsScope(params: {
|
|
cfg: OpenClawConfig;
|
|
accountId?: string | null;
|
|
}): TelegramInlineButtonsScope {
|
|
const account = resolveTelegramAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
return resolveInlineButtonsScopeFromCapabilities(account.config.capabilities);
|
|
}
|
|
|
|
export function isTelegramInlineButtonsEnabled(params: {
|
|
cfg: OpenClawConfig;
|
|
accountId?: string | null;
|
|
}): boolean {
|
|
if (params.accountId) {
|
|
return resolveTelegramInlineButtonsScope(params) !== "off";
|
|
}
|
|
const accountIds = listTelegramAccountIds(params.cfg);
|
|
if (accountIds.length === 0) {
|
|
return resolveTelegramInlineButtonsScope(params) !== "off";
|
|
}
|
|
return accountIds.some(
|
|
(accountId) => resolveTelegramInlineButtonsScope({ cfg: params.cfg, accountId }) !== "off",
|
|
);
|
|
}
|
|
|
|
export { resolveTelegramTargetChatType } from "./targets.js";
|