refactor: trim telegram helper exports

This commit is contained in:
Peter Steinberger
2026-05-01 17:12:04 +01:00
parent 84a3b50c11
commit d5736710a9
32 changed files with 48 additions and 53 deletions

View File

@@ -2,7 +2,7 @@ import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime";
export type TelegramApiLogger = (message: string) => void;
type TelegramApiLogger = (message: string) => void;
type TelegramApiLoggingParams<T> = {
operation: string;

View File

@@ -1,4 +1,4 @@
export const TELEGRAM_CALLBACK_DATA_MAX_BYTES = 64;
const TELEGRAM_CALLBACK_DATA_MAX_BYTES = 64;
const TELEGRAM_APPROVE_ALLOW_ALWAYS_PATTERN =
/^\/approve(?:@[^\s]+)?\s+[A-Za-z0-9][A-Za-z0-9._:-]*\s+allow-always$/i;

View File

@@ -14,7 +14,7 @@ export type NormalizedAllowFrom = {
invalidEntries: string[];
};
export type AllowFromMatch = AllowlistMatch<"wildcard" | "id">;
type AllowFromMatch = AllowlistMatch<"wildcard" | "id">;
const warnedInvalidEntries = new Set<string>();
const log = createSubsystemLogger("telegram/bot-access");

View File

@@ -27,7 +27,7 @@ export type TelegramLogger = {
info: (obj: Record<string, unknown>, msg: string) => void;
};
export type ResolveTelegramGroupConfig = (
type ResolveTelegramGroupConfig = (
chatId: string | number,
messageThreadId?: number,
) => {
@@ -35,16 +35,16 @@ export type ResolveTelegramGroupConfig = (
topicConfig?: TelegramTopicConfig;
};
export type ResolveGroupActivation = (params: {
type ResolveGroupActivation = (params: {
chatId: string | number;
agentId?: string;
messageThreadId?: number;
sessionKey?: string;
}) => boolean | undefined;
export type ResolveGroupRequireMention = (chatId: string | number) => boolean;
type ResolveGroupRequireMention = (chatId: string | number) => boolean;
export type TelegramMessageContextRuntimeOverrides = Partial<
type TelegramMessageContextRuntimeOverrides = Partial<
Pick<
typeof import("./bot-message-context.runtime.js"),
| "createStatusReactionController"

View File

@@ -1,4 +1,4 @@
export type TelegramMediaContextPayload = {
type TelegramMediaContextPayload = {
MediaPath?: string;
MediaUrl?: string;
MediaType?: string;

View File

@@ -6,12 +6,12 @@ import { normalizeOptionalString, readStringValue } from "openclaw/plugin-sdk/te
import { withTelegramApiErrorLogging } from "./api-logging.js";
import { normalizeTelegramCommandName, TELEGRAM_COMMAND_NAME_PATTERN } from "./command-config.js";
export const TELEGRAM_MAX_COMMANDS = 100;
const TELEGRAM_MAX_COMMANDS = 100;
export const TELEGRAM_TOTAL_COMMAND_TEXT_BUDGET = 5700;
const TELEGRAM_COMMAND_RETRY_RATIO = 0.8;
const TELEGRAM_MIN_COMMAND_DESCRIPTION_LENGTH = 1;
export type TelegramMenuCommand = {
type TelegramMenuCommand = {
command: string;
description: string;
};

View File

@@ -19,7 +19,7 @@ type TelegramMediaFileRef =
| NonNullable<Message["document"]>
| NonNullable<Message["sticker"]>;
export type TelegramPrimaryMedia = {
type TelegramPrimaryMedia = {
placeholder: string;
fileRef: TelegramMediaFileRef;
};

View File

@@ -1,8 +1,8 @@
import type { TelegramTextEntity } from "./body-helpers.js";
export const TELEGRAM_NATIVE_QUOTE_MAX_LENGTH = 1024;
const TELEGRAM_NATIVE_QUOTE_MAX_LENGTH = 1024;
export type TelegramNativeQuoteCandidate = {
type TelegramNativeQuoteCandidate = {
text: string;
position?: number;
entities?: unknown[];

View File

@@ -21,7 +21,7 @@ export function markReplyApplied(progress: DeliveryProgress, replyToId?: number)
}
}
export function markDelivered(progress: DeliveryProgress): void {
function markDelivered(progress: DeliveryProgress): void {
progress.hasDelivered = true;
}

View File

@@ -3,7 +3,7 @@ import type { ChatFullInfo, Message, UserFromGetMe } from "@grammyjs/types";
/** App-specific stream mode for Telegram stream previews. */
export type TelegramStreamMode = "off" | "partial" | "block";
export type TelegramGetFile = () => Promise<{ file_path?: string }>;
type TelegramGetFile = () => Promise<{ file_path?: string }>;
export type TelegramChatDetails = {
id?: number | string;
available_reactions?: ChatFullInfo["available_reactions"] | null;

View File

@@ -8,7 +8,7 @@ import { sanitizeTelegramCallbackData } from "./approval-callback-data.js";
export type TelegramButtonStyle = "danger" | "success" | "primary";
export type TelegramInlineButton = {
type TelegramInlineButton = {
text: string;
callback_data: string;
style?: TelegramButtonStyle;

View File

@@ -5,7 +5,7 @@ import type {
TelegramTopicConfig,
} from "openclaw/plugin-sdk/config-types";
export type TelegramErrorPolicy = "always" | "once" | "silent";
type TelegramErrorPolicy = "always" | "once" | "silent";
type TelegramErrorConfig =
| TelegramAccountConfig

View File

@@ -10,7 +10,7 @@ import {
} from "openclaw/plugin-sdk/text-runtime";
import { renderMarkdownWithMarkers } from "openclaw/plugin-sdk/text-runtime";
export type TelegramFormattedChunk = {
type TelegramFormattedChunk = {
html: string;
text: string;
};

View File

@@ -11,12 +11,12 @@ import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/runti
import { isSenderAllowed, type NormalizedAllowFrom } from "./bot-access.js";
import { firstDefined } from "./bot-access.js";
export type TelegramGroupBaseBlockReason =
type TelegramGroupBaseBlockReason =
| "group-disabled"
| "topic-disabled"
| "group-override-unauthorized";
export type TelegramGroupBaseAccessResult =
type TelegramGroupBaseAccessResult =
| { allowed: true }
| { allowed: false; reason: TelegramGroupBaseBlockReason };
@@ -91,14 +91,14 @@ export const evaluateTelegramGroupBaseAccess = (params: {
return { allowed: true };
};
export type TelegramGroupPolicyBlockReason =
type TelegramGroupPolicyBlockReason =
| "group-policy-disabled"
| "group-policy-allowlist-no-sender"
| "group-policy-allowlist-empty"
| "group-policy-allowlist-unauthorized"
| "group-chat-not-allowed";
export type TelegramGroupPolicyAccessResult =
type TelegramGroupPolicyAccessResult =
| { allowed: true; groupPolicy: "open" | "disabled" | "allowlist" }
| {
allowed: false;

View File

@@ -7,7 +7,7 @@ type TelegramGroups = Record<string, TelegramGroupConfig>;
type MigrationScope = "account" | "global";
export type TelegramGroupMigrationResult = {
type TelegramGroupMigrationResult = {
migrated: boolean;
skippedExisting: boolean;
scopes: MigrationScope[];

View File

@@ -7,7 +7,7 @@ import {
type PluginInteractiveRegistration,
} from "openclaw/plugin-sdk/plugin-runtime";
export type TelegramInteractiveButtons = Array<
type TelegramInteractiveButtons = Array<
Array<{ text: string; callback_data: string; style?: "danger" | "success" | "primary" }>
>;
@@ -52,7 +52,7 @@ export type TelegramInteractiveHandlerRegistration = PluginInteractiveRegistrati
"telegram"
>;
export type TelegramInteractiveDispatchContext = Omit<
type TelegramInteractiveDispatchContext = Omit<
TelegramInteractiveHandlerContext,
| "callback"
| "respond"

View File

@@ -1,10 +1,10 @@
export type LaneDeliverySnapshot = {
type LaneDeliverySnapshot = {
delivered: boolean;
skippedNonSilent: number;
failedNonSilent: number;
};
export type LaneDeliveryStateTracker = {
type LaneDeliveryStateTracker = {
markDelivered: () => void;
markNonSilentSkip: () => void;
markNonSilentFailure: () => void;

View File

@@ -1,6 +1,6 @@
import { resolveChannelPreviewStreamMode } from "openclaw/plugin-sdk/channel-streaming";
export type TelegramPreviewStreamMode = "off" | "partial" | "block";
type TelegramPreviewStreamMode = "off" | "partial" | "block";
export function resolveTelegramPreviewStreamMode(
params: {

View File

@@ -57,7 +57,7 @@ function isPartialReasoningTagPrefix(text: string): boolean {
return REASONING_TAG_PREFIXES.some((prefix) => prefix.startsWith(trimmed));
}
export type TelegramReasoningSplit = {
type TelegramReasoningSplit = {
reasoningText?: string;
answerText?: string;
};
@@ -90,7 +90,7 @@ export function splitTelegramReasoningText(text?: string): TelegramReasoningSpli
return { reasoningText, answerText };
}
export type BufferedFinalAnswer = {
type BufferedFinalAnswer = {
payload: ReplyPayload;
text: string;
};

View File

@@ -2,7 +2,7 @@ import type { MessageEntity } from "@grammyjs/types";
import { buildTelegramThreadParams, type TelegramThreadSpec } from "./bot/helpers.js";
import { normalizeTelegramReplyToMessageId } from "./outbound-params.js";
export type TelegramReplyParameters = {
type TelegramReplyParameters = {
message_id: number;
allow_sending_without_reply: true;
quote?: string;
@@ -10,7 +10,7 @@ export type TelegramReplyParameters = {
quote_entities?: MessageEntity[];
};
export type TelegramThreadReplyParams = {
type TelegramThreadReplyParams = {
message_thread_id?: number;
reply_parameters?: TelegramReplyParameters;
reply_to_message_id?: number;

View File

@@ -1,5 +1,4 @@
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
export type { TelegramRuntime } from "./runtime.types.js";
import type { TelegramRuntime } from "./runtime.types.js";
const {

View File

@@ -3,13 +3,13 @@ import type { PluginRuntime } from "openclaw/plugin-sdk/channel-core";
import type { TelegramMonitorFn } from "./monitor.types.js";
export type TelegramProbeFn = typeof import("./probe.js").probeTelegram;
export type TelegramAuditCollectFn = typeof import("./audit.js").collectTelegramUnmentionedGroupIds;
export type TelegramAuditMembershipFn = typeof import("./audit.js").auditTelegramGroupMembership;
export type TelegramSendFn = typeof import("./send.js").sendMessageTelegram;
export type TelegramResolveTokenFn = typeof import("./token.js").resolveTelegramToken;
type TelegramAuditCollectFn = typeof import("./audit.js").collectTelegramUnmentionedGroupIds;
type TelegramAuditMembershipFn = typeof import("./audit.js").auditTelegramGroupMembership;
type TelegramSendFn = typeof import("./send.js").sendMessageTelegram;
type TelegramResolveTokenFn = typeof import("./token.js").resolveTelegramToken;
type BasePluginRuntimeChannel = PluginRuntime extends { channel: infer T } ? T : never;
export type TelegramChannelRuntime = {
type TelegramChannelRuntime = {
probeTelegram?: TelegramProbeFn;
collectTelegramUnmentionedGroupIds?: TelegramAuditCollectFn;
auditTelegramGroupMembership?: TelegramAuditMembershipFn;
@@ -19,7 +19,7 @@ export type TelegramChannelRuntime = {
messageActions?: ChannelMessageActionAdapter;
};
export interface TelegramRuntimeChannel extends BasePluginRuntimeChannel {
interface TelegramRuntimeChannel extends BasePluginRuntimeChannel {
telegram?: TelegramChannelRuntime;
}

View File

@@ -5,7 +5,6 @@ import {
hasOwnProperty,
type ResolverContext,
type SecretDefaults,
type SecretTargetRegistryEntry,
} from "openclaw/plugin-sdk/channel-secret-basic-runtime";
function normalizeOptionalString(value: unknown): string | undefined {
@@ -61,7 +60,7 @@ export const secretTargetRegistryEntries = [
includeInConfigure: true,
includeInAudit: true,
},
] satisfies SecretTargetRegistryEntry[];
] satisfies import("openclaw/plugin-sdk/channel-secret-basic-runtime").SecretTargetRegistryEntry[];
export function collectRuntimeConfigAssignments(params: {
config: { channels?: Record<string, unknown> };

View File

@@ -11,7 +11,7 @@ import {
} from "openclaw/plugin-sdk/command-primitives-runtime";
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
export type TelegramSequentialKeyContext = {
type TelegramSequentialKeyContext = {
chat?: { id?: number };
me?: UserFromGetMe;
message?: Message;

View File

@@ -30,7 +30,7 @@ export const TELEGRAM_USER_ID_HELP_LINES = [
"Website: https://openclaw.ai",
];
export function normalizeTelegramAllowFromInput(raw: string): string {
function normalizeTelegramAllowFromInput(raw: string): string {
return raw
.trim()
.replace(/^(telegram|tg):/i, "")

View File

@@ -15,7 +15,6 @@ import {
parseTelegramAllowFromId,
TELEGRAM_TOKEN_HELP_LINES,
TELEGRAM_USER_ID_HELP_LINES,
telegramSetupAdapter,
} from "./setup-core.js";
import {
buildTelegramDmAccessWarningLines,
@@ -109,5 +108,3 @@ export const telegramSetupWizard: ChannelSetupWizard = {
dmPolicy: telegramSetupDmPolicy,
disable: (cfg) => setSetupChannelEnabled(cfg, channel, false),
};
export { parseTelegramAllowFromId, telegramSetupAdapter };

View File

@@ -31,7 +31,7 @@ import { collectRuntimeConfigAssignments, secretTargetRegistryEntries } from "./
import { telegramSecurityAdapter } from "./security.js";
import { namedAccountPromotionKeys, singleAccountKeysToMove } from "./setup-contract.js";
export const TELEGRAM_CHANNEL = "telegram" as const;
const TELEGRAM_CHANNEL = "telegram" as const;
type TelegramConfigAccessorAccount = {
config: TelegramAccountConfig;

View File

@@ -88,7 +88,7 @@ const TELEGRAM_SUPPORTED_REACTION_EMOJIS = new Set<TelegramReactionEmoji>(
TELEGRAM_SUPPORTED_REACTION_EMOJI_LIST,
);
export const TELEGRAM_STATUS_REACTION_VARIANTS: Record<StatusReactionEmojiKey, string[]> = {
const TELEGRAM_STATUS_REACTION_VARIANTS: Record<StatusReactionEmojiKey, string[]> = {
queued: ["👀", "👍", "🔥"],
thinking: ["🤔", "🤓", "👀"],
tool: ["🔥", "⚡", "👍"],

View File

@@ -35,7 +35,7 @@ async function loadTelegramSendModule() {
type TelegramBindingTargetKind = "subagent" | "acp";
export type TelegramThreadBindingRecord = {
type TelegramThreadBindingRecord = {
accountId: string;
conversationId: string;
targetKind: TelegramBindingTargetKind;
@@ -55,7 +55,7 @@ type StoredTelegramBindingState = {
bindings: TelegramThreadBindingRecord[];
};
export type TelegramThreadBindingManager = {
type TelegramThreadBindingManager = {
accountId: string;
shouldPersistMutations: () => boolean;
getIdleTimeoutMs: () => number;

View File

@@ -10,7 +10,7 @@ import {
resolveSecretInputString,
} from "openclaw/plugin-sdk/secret-input";
export type TelegramTokenSource = "env" | "tokenFile" | "config" | "none";
type TelegramTokenSource = "env" | "tokenFile" | "config" | "none";
export type TelegramTokenResolution = BaseTokenResolution & {
source: TelegramTokenSource;

View File

@@ -6,7 +6,7 @@ const MAX_ENTRIES = 2_048;
const TOPIC_NAME_CACHE_STATE_KEY = Symbol.for("openclaw.telegramTopicNameCacheState");
const DEFAULT_TOPIC_NAME_CACHE_KEY = "__default__";
export type TopicEntry = {
type TopicEntry = {
name: string;
iconColor?: number;
iconCustomEmojiId?: string;

View File

@@ -1,6 +1,6 @@
import { isVoiceCompatibleAudio } from "openclaw/plugin-sdk/media-runtime";
export function resolveTelegramVoiceDecision(opts: {
function resolveTelegramVoiceDecision(opts: {
wantsVoice: boolean;
contentType?: string | null;
fileName?: string | null;