From 147eba11fd2f73bbb70af00a8ababe732824381d Mon Sep 17 00:00:00 2001 From: cpojer Date: Sun, 1 Feb 2026 10:07:59 +0900 Subject: [PATCH] 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. --- src/telegram/bot-handlers.ts | 3 +- src/telegram/bot-message-dispatch.ts | 5 ++-- src/telegram/bot-native-commands.ts | 42 ++++++++++++++++++++++++++-- src/telegram/bot.ts | 5 ++-- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/telegram/bot-handlers.ts b/src/telegram/bot-handlers.ts index 878b5c5d96..a5fcd2d212 100644 --- a/src/telegram/bot-handlers.ts +++ b/src/telegram/bot-handlers.ts @@ -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; diff --git a/src/telegram/bot-message-dispatch.ts b/src/telegram/bot-message-dispatch.ts index 4bc6b18236..13d02341e8 100644 --- a/src/telegram/bot-message-dispatch.ts +++ b/src/telegram/bot-message-dispatch.ts @@ -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, diff --git a/src/telegram/bot-native-commands.ts b/src/telegram/bot-native-commands.ts index a64d261a5a..c34d594361 100644 --- a/src/telegram/bot-native-commands.ts +++ b/src/telegram/bot-native-commands.ts @@ -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; + 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; + logger: ReturnType; +}; + 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({ diff --git a/src/telegram/bot.ts b/src/telegram/bot.ts index 2a83c32293..3d44bcba09 100644 --- a/src/telegram/bot.ts +++ b/src/telegram/bot.ts @@ -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) {