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:
parent
f06dd8df06
commit
147eba11fd
4 changed files with 47 additions and 8 deletions
|
|
@ -15,6 +15,7 @@ import { writeConfigFile } from "../config/io.js";
|
||||||
import { danger, logVerbose, warn } from "../globals.js";
|
import { danger, logVerbose, warn } from "../globals.js";
|
||||||
import { withTelegramApiErrorLogging } from "./api-logging.js";
|
import { withTelegramApiErrorLogging } from "./api-logging.js";
|
||||||
import { firstDefined, isSenderAllowed, normalizeAllowFromWithStore } from "./bot-access.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 { MEDIA_GROUP_TIMEOUT_MS, type MediaGroupEntry } from "./bot-updates.js";
|
||||||
import { resolveMedia } from "./bot/delivery.js";
|
import { resolveMedia } from "./bot/delivery.js";
|
||||||
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
|
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
|
||||||
|
|
@ -37,7 +38,7 @@ export const registerTelegramHandlers = ({
|
||||||
shouldSkipUpdate,
|
shouldSkipUpdate,
|
||||||
processMessage,
|
processMessage,
|
||||||
logger,
|
logger,
|
||||||
}) => {
|
}: RegisterTelegramHandlerParams) => {
|
||||||
const TELEGRAM_TEXT_FRAGMENT_START_THRESHOLD_CHARS = 4000;
|
const TELEGRAM_TEXT_FRAGMENT_START_THRESHOLD_CHARS = 4000;
|
||||||
const TELEGRAM_TEXT_FRAGMENT_MAX_GAP_MS = 1500;
|
const TELEGRAM_TEXT_FRAGMENT_MAX_GAP_MS = 1500;
|
||||||
const TELEGRAM_TEXT_FRAGMENT_MAX_ID_GAP = 1;
|
const TELEGRAM_TEXT_FRAGMENT_MAX_ID_GAP = 1;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { removeAckReactionAfterReply } from "../channels/ack-reactions.js";
|
||||||
import { logAckFailure, logTypingFailure } from "../channels/logging.js";
|
import { logAckFailure, logTypingFailure } from "../channels/logging.js";
|
||||||
import { createReplyPrefixContext } from "../channels/reply-prefix.js";
|
import { createReplyPrefixContext } from "../channels/reply-prefix.js";
|
||||||
import { createTypingCallbacks } from "../channels/typing.js";
|
import { createTypingCallbacks } from "../channels/typing.js";
|
||||||
|
import { OpenClawConfig } from "../config/config.js";
|
||||||
import { resolveMarkdownTableMode } from "../config/markdown-tables.js";
|
import { resolveMarkdownTableMode } from "../config/markdown-tables.js";
|
||||||
import { danger, logVerbose } from "../globals.js";
|
import { danger, logVerbose } from "../globals.js";
|
||||||
import { deliverReplies } from "./bot/delivery.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.";
|
const EMPTY_RESPONSE_FALLBACK = "No response generated. Please try again.";
|
||||||
|
|
||||||
async function resolveStickerVisionSupport(cfg, agentId) {
|
async function resolveStickerVisionSupport(cfg: OpenClawConfig, agentId: string) {
|
||||||
try {
|
try {
|
||||||
const catalog = await loadModelCatalog({ config: cfg });
|
const catalog = await loadModelCatalog({ config: cfg });
|
||||||
const defaultModel = resolveDefaultModelForAgent({ cfg, agentId });
|
const defaultModel = resolveDefaultModelForAgent({ cfg, agentId });
|
||||||
|
|
@ -48,7 +49,7 @@ export const dispatchTelegramMessage = async ({
|
||||||
telegramCfg,
|
telegramCfg,
|
||||||
opts,
|
opts,
|
||||||
resolveBotTopicsEnabled,
|
resolveBotTopicsEnabled,
|
||||||
}) => {
|
}: any) => {
|
||||||
const {
|
const {
|
||||||
ctxPayload,
|
ctxPayload,
|
||||||
primaryCtx,
|
primaryCtx,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import {
|
||||||
TELEGRAM_COMMAND_NAME_PATTERN,
|
TELEGRAM_COMMAND_NAME_PATTERN,
|
||||||
} from "../config/telegram-custom-commands.js";
|
} from "../config/telegram-custom-commands.js";
|
||||||
import { danger, logVerbose } from "../globals.js";
|
import { danger, logVerbose } from "../globals.js";
|
||||||
|
import { getChildLogger } from "../logging.js";
|
||||||
import {
|
import {
|
||||||
executePluginCommand,
|
executePluginCommand,
|
||||||
getPluginCommandSpecs,
|
getPluginCommandSpecs,
|
||||||
|
|
@ -39,6 +40,8 @@ import { resolveAgentRoute } from "../routing/resolve-route.js";
|
||||||
import { resolveThreadSessionKeys } from "../routing/session-key.js";
|
import { resolveThreadSessionKeys } from "../routing/session-key.js";
|
||||||
import { withTelegramApiErrorLogging } from "./api-logging.js";
|
import { withTelegramApiErrorLogging } from "./api-logging.js";
|
||||||
import { firstDefined, isSenderAllowed, normalizeAllowFromWithStore } from "./bot-access.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 { deliverReplies } from "./bot/delivery.js";
|
||||||
import {
|
import {
|
||||||
buildSenderName,
|
buildSenderName,
|
||||||
|
|
@ -65,6 +68,33 @@ type TelegramCommandAuthResult = {
|
||||||
commandAuthorized: boolean;
|
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 = {
|
type RegisterTelegramNativeCommandsParams = {
|
||||||
bot: Bot;
|
bot: Bot;
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
|
|
@ -84,7 +114,7 @@ type RegisterTelegramNativeCommandsParams = {
|
||||||
chatId: string | number,
|
chatId: string | number,
|
||||||
messageThreadId?: number,
|
messageThreadId?: number,
|
||||||
) => { groupConfig?: TelegramGroupConfig; topicConfig?: TelegramTopicConfig };
|
) => { groupConfig?: TelegramGroupConfig; topicConfig?: TelegramTopicConfig };
|
||||||
shouldSkipUpdate: (ctx: unknown) => boolean;
|
shouldSkipUpdate: (ctx: TelegramUpdateKeyContext) => boolean;
|
||||||
opts: { token: string };
|
opts: { token: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -267,7 +297,10 @@ export const registerTelegramNativeCommands = ({
|
||||||
? listSkillCommandsForAgents(boundAgentIds ? { cfg, agentIds: boundAgentIds } : { cfg })
|
? listSkillCommandsForAgents(boundAgentIds ? { cfg, agentIds: boundAgentIds } : { cfg })
|
||||||
: [];
|
: [];
|
||||||
const nativeCommands = nativeEnabled
|
const nativeCommands = nativeEnabled
|
||||||
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
|
? listNativeCommandSpecsForConfig(cfg, {
|
||||||
|
skillCommands,
|
||||||
|
provider: "telegram",
|
||||||
|
})
|
||||||
: [];
|
: [];
|
||||||
const reservedCommands = new Set(
|
const reservedCommands = new Set(
|
||||||
listNativeCommandSpecs().map((command) => command.name.toLowerCase()),
|
listNativeCommandSpecs().map((command) => command.name.toLowerCase()),
|
||||||
|
|
@ -442,7 +475,10 @@ export const registerTelegramNativeCommands = ({
|
||||||
const dmThreadId = !isGroup ? messageThreadId : undefined;
|
const dmThreadId = !isGroup ? messageThreadId : undefined;
|
||||||
const threadKeys =
|
const threadKeys =
|
||||||
dmThreadId != null
|
dmThreadId != null
|
||||||
? resolveThreadSessionKeys({ baseSessionKey, threadId: String(dmThreadId) })
|
? resolveThreadSessionKeys({
|
||||||
|
baseSessionKey,
|
||||||
|
threadId: String(dmThreadId),
|
||||||
|
})
|
||||||
: null;
|
: null;
|
||||||
const sessionKey = threadKeys?.sessionKey ?? baseSessionKey;
|
const sessionKey = threadKeys?.sessionKey ?? baseSessionKey;
|
||||||
const tableMode = resolveMarkdownTableMode({
|
const tableMode = resolveMarkdownTableMode({
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import type { ApiClientOptions } from "grammy";
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { sequentialize } from "@grammyjs/runner";
|
import { sequentialize } from "@grammyjs/runner";
|
||||||
import { apiThrottler } from "@grammyjs/transformer-throttler";
|
import { apiThrottler } from "@grammyjs/transformer-throttler";
|
||||||
|
import { ReactionTypeEmoji } from "@grammyjs/types";
|
||||||
import { Bot, webhookCallback } from "grammy";
|
import { Bot, webhookCallback } from "grammy";
|
||||||
import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
|
import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
|
|
@ -417,11 +418,11 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||||
// Detect added reactions
|
// Detect added reactions
|
||||||
const oldEmojis = new Set(
|
const oldEmojis = new Set(
|
||||||
reaction.old_reaction
|
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),
|
.map((r) => r.emoji),
|
||||||
);
|
);
|
||||||
const addedReactions = reaction.new_reaction
|
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));
|
.filter((r) => !oldEmojis.has(r.emoji));
|
||||||
|
|
||||||
if (addedReactions.length === 0) {
|
if (addedReactions.length === 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue