From ad2237bd7ea0778d310e4c1c2a23257cac6f4bba Mon Sep 17 00:00:00 2001 From: Satoshi Qazi Muhammed Date: Thu, 22 Oct 2026 23:37:49 +0400 Subject: [PATCH] telegram-bot: keep message bodies out of the log, load the keyring alone Every Telegram call logged its full request body and the echoed reply. Those bodies hold what users write, the assistant's answers and, from the KRD bot's create-wallet button, the generated seed phrase, so the seed reached the container log in clear. Calls now log the method and chat id, replies only whether they failed and why, and incoming updates only their id and kind. The bot imported @pezkuwi/api to build a Keyring. That package brings in every type definition and rxjs; each worker spent ~40 s and ~300 MB loading it, and a worker that expired and was replaced kept adding to the container's memory until the 1 GB limit killed it after about eight hours. @pezkuwi/keyring is the same Keyring without the API. --- supabase/functions/telegram-bot/index.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/supabase/functions/telegram-bot/index.ts b/supabase/functions/telegram-bot/index.ts index c4bf0c0..0cc6985 100644 --- a/supabase/functions/telegram-bot/index.ts +++ b/supabase/functions/telegram-bot/index.ts @@ -7,7 +7,10 @@ */ import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'; -import { Keyring } from 'npm:@pezkuwi/api@16.5.36'; +// The keyring alone, not @pezkuwi/api: the API package pulls in every type +// definition and rxjs, which made each worker boot take ~40 s and ~300 MB for +// a bot whose only chain work is deriving an address. +import { Keyring } from 'npm:@pezkuwi/keyring@14.0.25'; import { cryptoWaitReady } from 'npm:@pezkuwi/util-crypto@14.0.25'; import * as bip39 from 'https://esm.sh/@scure/bip39@1.2.1'; import { wordlist } from 'https://esm.sh/@scure/bip39@1.2.1/wordlists/english'; @@ -522,7 +525,9 @@ interface TelegramUpdate { // ── Telegram API helper ───────────────────────────────────────────── async function sendTelegramRequest(token: string, method: string, body: Record) { - console.log(`[Telegram] Calling ${method}`, JSON.stringify(body)); + // Only the method and chat are logged. Bodies carry what users wrote, the + // assistant's replies and, from the create-wallet button, a seed phrase. + console.log(`[Telegram] Calling ${method}`, `chat=${body.chat_id ?? '-'}`); if (!token) { console.error('[Telegram] BOT_TOKEN is not set!'); @@ -536,7 +541,12 @@ async function sendTelegramRequest(token: string, method: string, body: Record { const botId = getBotId(req); const botToken = BOT_TOKENS[botId] || BOT_TOKENS.main; const update: TelegramUpdate = await req.json(); - console.log(`[Bot:${botId}] Received update:`, JSON.stringify(update)); + const kind = update.message ? 'message' : update.callback_query ? 'callback' : 'other'; + console.log(`[Bot:${botId}] Received update ${update.update_id} (${kind})`); // Handle message if (update.message?.text) {