mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 01:11:37 +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
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { resolveTextChunkLimit } from "../../../src/auto-reply/chunk.js";
|
|
import { getChannelDock } from "../../../src/channels/dock.js";
|
|
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
import { resolveAccountEntry } from "../../../src/routing/account-lookup.js";
|
|
import { normalizeAccountId } from "../../../src/routing/session-key.js";
|
|
|
|
const DEFAULT_TELEGRAM_DRAFT_STREAM_MIN = 200;
|
|
const DEFAULT_TELEGRAM_DRAFT_STREAM_MAX = 800;
|
|
|
|
export function resolveTelegramDraftStreamingChunking(
|
|
cfg: OpenClawConfig | undefined,
|
|
accountId?: string | null,
|
|
): {
|
|
minChars: number;
|
|
maxChars: number;
|
|
breakPreference: "paragraph" | "newline" | "sentence";
|
|
} {
|
|
const providerChunkLimit = getChannelDock("telegram")?.outbound?.textChunkLimit;
|
|
const textLimit = resolveTextChunkLimit(cfg, "telegram", accountId, {
|
|
fallbackLimit: providerChunkLimit,
|
|
});
|
|
const normalizedAccountId = normalizeAccountId(accountId);
|
|
const accountCfg = resolveAccountEntry(cfg?.channels?.telegram?.accounts, normalizedAccountId);
|
|
const draftCfg = accountCfg?.draftChunk ?? cfg?.channels?.telegram?.draftChunk;
|
|
|
|
const maxRequested = Math.max(
|
|
1,
|
|
Math.floor(draftCfg?.maxChars ?? DEFAULT_TELEGRAM_DRAFT_STREAM_MAX),
|
|
);
|
|
const maxChars = Math.max(1, Math.min(maxRequested, textLimit));
|
|
const minRequested = Math.max(
|
|
1,
|
|
Math.floor(draftCfg?.minChars ?? DEFAULT_TELEGRAM_DRAFT_STREAM_MIN),
|
|
);
|
|
const minChars = Math.min(minRequested, maxChars);
|
|
const breakPreference =
|
|
draftCfg?.breakPreference === "newline" || draftCfg?.breakPreference === "sentence"
|
|
? draftCfg.breakPreference
|
|
: "paragraph";
|
|
return { minChars, maxChars, breakPreference };
|
|
}
|