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.
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-10-22 23:37:49 +04:00
1 parent 07cd642051
commit ad2237bd7e
1 file changed
+15 -4
+15 -4
View File
@@ -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<string, unknown>) {
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<s
});
const result = await response.json();
console.log(`[Telegram] Response:`, JSON.stringify(result));
// A successful reply echoes the sent message back, so only failures are
// described.
console.log(
`[Telegram] Response: ok=${result.ok}`,
result.ok ? '' : `${result.error_code} ${result.description}`
);
return result;
}
@@ -853,7 +863,8 @@ serve(async (req: Request) => {
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) {