From d1026c9744ee9e24eeef0009a299a480db4c9ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=81=D0=B5=D0=BB=D1=8C?= Date: Mon, 16 Nov 2026 21:57:36 +0500 Subject: [PATCH 1/2] PEP-180: a long message (up to 60 000 characters) goes into the chat and a task's discussion whole; the analyst reads it whole; Telegram gets a shortened copy Co-Authored-By: Claude Opus 5.5 --- apps/bot/src/telegram.ts | 18 +++++++++++++++ apps/web/app/(app)/chats/[chat]/page.tsx | 2 +- apps/web/app/(app)/t/[key]/tabs.tsx | 2 +- apps/web/components/StoryProduct.tsx | 2 +- packages/core/src/analyst-chat.ts | 3 ++- packages/core/src/tasks.ts | 6 ++++- packages/runner/src/chats.ts | 28 +++--------------------- packages/shared/src/i18n/en/bot.ts | 1 + packages/shared/src/i18n/en/runner.ts | 1 + packages/shared/src/i18n/kk/bot.ts | 1 + packages/shared/src/i18n/kk/runner.ts | 1 + packages/testkit/test/chats.test.ts | 14 ++++++++++++ 12 files changed, 49 insertions(+), 30 deletions(-) diff --git a/apps/bot/src/telegram.ts b/apps/bot/src/telegram.ts index e5160921..8d6f75e6 100644 --- a/apps/bot/src/telegram.ts +++ b/apps/bot/src/telegram.ts @@ -1,3 +1,4 @@ +import { m as tr } from "@peppa/shared/i18n"; // Minimal Telegram Bot API client. The base URL is configurable so tests can point it at // mock-telegram (packages/testkit). @@ -48,6 +49,18 @@ export interface InlineButton { url?: string; } +const TG_TEXT_MAX = 4096; +const TG_CLIP_NOTE_TEXT = tr("(полностью — на сайте Peppa FACTORY)"); +const TG_CLIP_NOTE = "\n\n… " + TG_CLIP_NOTE_TEXT; + +/** PEP-180: a text that fits Telegram — cut at the last line break before the limit. */ +export function clipForTelegram(text: string): string { + if (text.length <= TG_TEXT_MAX) return text; + const room = TG_TEXT_MAX - TG_CLIP_NOTE.length; + const cut = text.lastIndexOf("\n", room); + return `${text.slice(0, cut > room / 2 ? cut : room)}${TG_CLIP_NOTE}`; +} + export class TelegramError extends Error { readonly method: string; readonly code: number; @@ -71,6 +84,11 @@ export class TelegramApi { } async call(method: string, params: Record = {}, timeoutMs = 15_000): Promise { + // PEP-180: Telegram refuses texts over 4096 characters — a long message goes shortened (cut at a + // line break, so no HTML tag is left open), with a note that the whole text is on the site. + if ((method === "sendMessage" || method === "editMessageText") && typeof params.text === "string" && params.text.length > TG_TEXT_MAX) { + params = { ...params, text: clipForTelegram(params.text) }; + } let res: Response; try { res = await fetch(`${this.baseUrl}/bot${this.token}/${method}`, { diff --git a/apps/web/app/(app)/chats/[chat]/page.tsx b/apps/web/app/(app)/chats/[chat]/page.tsx index bb07b7a5..d4961c67 100644 --- a/apps/web/app/(app)/chats/[chat]/page.tsx +++ b/apps/web/app/(app)/chats/[chat]/page.tsx @@ -273,7 +273,7 @@ export default async function ChatPage({ params, searchParams }: { params: Promi ) : (
-