chore: Manually fix TypeScript errors uncovered by sorting imports.

Some TypeScript checks are order dependent, and the fixed types were `any`/`unknown`, TypeScript just didn't report it before for some reason.
This commit is contained in:
cpojer
2026-02-01 10:07:59 +09:00
parent f06dd8df06
commit 147eba11fd
4 changed files with 47 additions and 8 deletions

View File

@@ -15,6 +15,7 @@ import { writeConfigFile } from "../config/io.js";
import { danger, logVerbose, warn } from "../globals.js";
import { withTelegramApiErrorLogging } from "./api-logging.js";
import { firstDefined, isSenderAllowed, normalizeAllowFromWithStore } from "./bot-access.js";
import { RegisterTelegramHandlerParams } from "./bot-native-commands.js";
import { MEDIA_GROUP_TIMEOUT_MS, type MediaGroupEntry } from "./bot-updates.js";
import { resolveMedia } from "./bot/delivery.js";
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
@@ -37,7 +38,7 @@ export const registerTelegramHandlers = ({
shouldSkipUpdate,
processMessage,
logger,
}) => {
}: RegisterTelegramHandlerParams) => {
const TELEGRAM_TEXT_FRAGMENT_START_THRESHOLD_CHARS = 4000;
const TELEGRAM_TEXT_FRAGMENT_MAX_GAP_MS = 1500;
const TELEGRAM_TEXT_FRAGMENT_MAX_ID_GAP = 1;

View File

@@ -14,6 +14,7 @@ import { removeAckReactionAfterReply } from "../channels/ack-reactions.js";
import { logAckFailure, logTypingFailure } from "../channels/logging.js";
import { createReplyPrefixContext } from "../channels/reply-prefix.js";
import { createTypingCallbacks } from "../channels/typing.js";
import { OpenClawConfig } from "../config/config.js";
import { resolveMarkdownTableMode } from "../config/markdown-tables.js";
import { danger, logVerbose } from "../globals.js";
import { deliverReplies } from "./bot/delivery.js";
@@ -23,7 +24,7 @@ import { cacheSticker, describeStickerImage } from "./sticker-cache.js";
const EMPTY_RESPONSE_FALLBACK = "No response generated. Please try again.";
async function resolveStickerVisionSupport(cfg, agentId) {
async function resolveStickerVisionSupport(cfg: OpenClawConfig, agentId: string) {
try {
const catalog = await loadModelCatalog({ config: cfg });
const defaultModel = resolveDefaultModelForAgent({ cfg, agentId });
@@ -48,7 +49,7 @@ export const dispatchTelegramMessage = async ({
telegramCfg,
opts,
resolveBotTopicsEnabled,
}) => {
}: any) => {
const {
ctxPayload,
primaryCtx,

View File

@@ -30,6 +30,7 @@ import {
TELEGRAM_COMMAND_NAME_PATTERN,
} from "../config/telegram-custom-commands.js";
import { danger, logVerbose } from "../globals.js";
import { getChildLogger } from "../logging.js";
import {
executePluginCommand,
getPluginCommandSpecs,
@@ -39,6 +40,8 @@ import { resolveAgentRoute } from "../routing/resolve-route.js";
import { resolveThreadSessionKeys } from "../routing/session-key.js";
import { withTelegramApiErrorLogging } from "./api-logging.js";
import { firstDefined, isSenderAllowed, normalizeAllowFromWithStore } from "./bot-access.js";
import { TelegramUpdateKeyContext } from "./bot-updates.js";
import { TelegramBotOptions } from "./bot.js";
import { deliverReplies } from "./bot/delivery.js";
import {
buildSenderName,
@@ -65,6 +68,33 @@ type TelegramCommandAuthResult = {
commandAuthorized: boolean;
};
export type RegisterTelegramHandlerParams = {
cfg: OpenClawConfig;
accountId: string;
bot: Bot;
mediaMaxBytes: number;
opts: TelegramBotOptions;
runtime: RuntimeEnv;
telegramCfg: TelegramAccountConfig;
groupAllowFrom?: Array<string | number>;
resolveGroupPolicy: (chatId: string | number) => ChannelGroupPolicy;
resolveTelegramGroupConfig: (
chatId: string | number,
messageThreadId?: number,
) => { groupConfig?: TelegramGroupConfig; topicConfig?: TelegramTopicConfig };
shouldSkipUpdate: (ctx: TelegramUpdateKeyContext) => boolean;
processMessage: (
ctx: unknown,
allMedia: Array<{ path: string; contentType?: string }>,
storeAllowFrom: string[],
options?: {
messageIdOverride?: string;
forceWasMentioned?: boolean;
},
) => Promise<void>;
logger: ReturnType<typeof getChildLogger>;
};
type RegisterTelegramNativeCommandsParams = {
bot: Bot;
cfg: OpenClawConfig;
@@ -84,7 +114,7 @@ type RegisterTelegramNativeCommandsParams = {
chatId: string | number,
messageThreadId?: number,
) => { groupConfig?: TelegramGroupConfig; topicConfig?: TelegramTopicConfig };
shouldSkipUpdate: (ctx: unknown) => boolean;
shouldSkipUpdate: (ctx: TelegramUpdateKeyContext) => boolean;
opts: { token: string };
};
@@ -267,7 +297,10 @@ export const registerTelegramNativeCommands = ({
? listSkillCommandsForAgents(boundAgentIds ? { cfg, agentIds: boundAgentIds } : { cfg })
: [];
const nativeCommands = nativeEnabled
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
? listNativeCommandSpecsForConfig(cfg, {
skillCommands,
provider: "telegram",
})
: [];
const reservedCommands = new Set(
listNativeCommandSpecs().map((command) => command.name.toLowerCase()),
@@ -442,7 +475,10 @@ export const registerTelegramNativeCommands = ({
const dmThreadId = !isGroup ? messageThreadId : undefined;
const threadKeys =
dmThreadId != null
? resolveThreadSessionKeys({ baseSessionKey, threadId: String(dmThreadId) })
? resolveThreadSessionKeys({
baseSessionKey,
threadId: String(dmThreadId),
})
: null;
const sessionKey = threadKeys?.sessionKey ?? baseSessionKey;
const tableMode = resolveMarkdownTableMode({

View File

@@ -2,6 +2,7 @@ import type { ApiClientOptions } from "grammy";
// @ts-nocheck
import { sequentialize } from "@grammyjs/runner";
import { apiThrottler } from "@grammyjs/transformer-throttler";
import { ReactionTypeEmoji } from "@grammyjs/types";
import { Bot, webhookCallback } from "grammy";
import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
import type { RuntimeEnv } from "../runtime.js";
@@ -417,11 +418,11 @@ export function createTelegramBot(opts: TelegramBotOptions) {
// Detect added reactions
const oldEmojis = new Set(
reaction.old_reaction
.filter((r): r is { type: "emoji"; emoji: string } => r.type === "emoji")
.filter((r): r is ReactionTypeEmoji => r.type === "emoji")
.map((r) => r.emoji),
);
const addedReactions = reaction.new_reaction
.filter((r): r is { type: "emoji"; emoji: string } => r.type === "emoji")
.filter((r): r is ReactionTypeEmoji => r.type === "emoji")
.filter((r) => !oldEmojis.has(r.emoji));
if (addedReactions.length === 0) {