
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
pino-telegram-logger-transport
Advanced tools
A transport for Pino that forwards structured logs to the Telegram Bot API, supports media attachments, and ships ready-made adapters for NestJS, Fastify, and AWS Lambda
English version · Русская версия
A transport for Pino that forwards structured logs to the Telegram Bot API, supports media attachments, and ships ready-made adapters for NestJS, Fastify, and AWS Lambda. Private chats, supergroups, topics, and media uploads are supported out of the box.
Recent releases focused on three areas: safer delivery, safer formatting, and lower-noise operations.
undici.requestTimeoutMs, and timeout failures can be retried.logger.flush(callback) now waits for the real delivery pipeline, including retries and split text messages.maxQueueSize and overflowStrategy keep the in-memory queue bounded when Telegram slows down.failOnInitError adds a fail-fast startup mode for production deployments.redactKeys masks sensitive values inside the built-in Context, Error, and Extras blocks.time values no longer crash the formatter.splitLongMessages can send long text logs as ordered parts instead of cutting them off.minLevel, so errors and warnings can go to different chats.formatPreset: 'compact' | 'verbose' makes it easier to switch between dense operational logs and more detailed output.dedupWindowMs suppresses repeated text events inside a configurable time window.pino-telegram-cli check --probe-message verifies real send permissions, not just chat visibility.pino-telegram-cli generate-config --include-token keeps generated configs safe by default.18/20/24 and pino@9/10.import pino from 'pino';
const logger = pino({
transport: {
target: 'pino-telegram-logger-transport',
options: {
botToken: process.env.TELEGRAM_BOT_TOKEN!,
chatId: [
{ chatId: process.env.TELEGRAM_ALERTS_CHAT_ID!, minLevel: 'error' },
{ chatId: process.env.TELEGRAM_WARNINGS_CHAT_ID!, minLevel: 'warn' },
],
requestTimeoutMs: 10_000,
maxQueueSize: 1_000,
overflowStrategy: 'dropOldest',
failOnInitError: true,
splitLongMessages: true,
formatPreset: 'compact',
dedupWindowMs: 30_000,
},
},
});
minLevel.dedupWindowMs.Context, Error, and Extras sections.splitLongMessages.compact and verbose presets or provide a custom formatter.send function in direct-stream mode.pino@10pino@^9 on Node.js 18+pino@^10 on Node.js 20+npm install pino@^10 pino-telegram-logger-transport
# or
npm install pino@^9 pino-telegram-logger-transport
import pino from 'pino';
const logger = pino({
transport: {
target: 'pino-telegram-logger-transport',
options: {
botToken: process.env.TELEGRAM_BOT_TOKEN!,
chatId: process.env.TELEGRAM_CHAT_ID,
threadId: process.env.TELEGRAM_THREAD_ID,
minLevel: 'warn',
minDelayBetweenMessages: 200,
retryAttempts: 3,
},
},
});
logger.info({ context: { requestId: '42' } }, 'Hello, Telegram!');
The transport renders an HTML message similar to:
ℹ️ INFO — <b>Message</b> <b>Time:</b> 2025-09-17T16:35:00.000Z
<b>Context:</b>
<pre>{"requestId":"42"}</pre>
When the log contains err, an Error section with message and stack is added. Additional properties (besides level, time, msg, context, err) are rendered inside the Extras block.
retryAttempts, retryInitialDelay, retryBackoffFactor, retryMaxDelay.requestTimeoutMs (10000 ms by default) and retry timeout failures.retry_after hints returned by Telegram.retryAttempts: 1 to disable retries entirely.logger.warn({
messageType: 'photo',
mediaUrl: 'https://example.com/path/to/photo',
caption: 'Incident snapshot',
});
By default the formatter looks for messageType (text/photo/document), mediaUrl, mediaBuffer, mediaFilename, mediaContentType, and caption.
Binary payloads can be provided as Buffer, Uint8Array, ArrayBuffer, or { type: 'Buffer', data: number[] } objects.
Telegram limits media captions to 1024 characters, so keep caption within that budget.
pino({
transport: {
target: 'pino-telegram-logger-transport',
options: {
botToken,
chatId,
headings: {
time: 'Time',
context: 'Context',
error: 'Error',
extras: 'Extras',
},
includeExtras: false,
extraKeys: ['requestId', 'userId'],
},
},
});
Combine headings, includeExtras, extraKeys, contextKeys, maxMessageLength, and splitLongMessages to tailor the message format.
send Functionasync function sendToQueue(payload: TelegramSendPayload, method: TelegramMethod) {
console.log('Method:', method);
console.log('Payload:', JSON.stringify(payload, null, 2));
}
The send option receives the payload and the selected method. Legacy handlers that expect a single argument remain compatible: the second argument will be ignored.
Pass send, formatMessage, and onDeliveryError only through direct transport creation (const stream = telegramTransport(options); const logger = pino({}, stream);).
The transport.target mode serializes options and should be treated as serializable-only.
import { LoggerModule } from 'nestjs-pino';
import { createNestLoggerOptions } from 'pino-telegram-logger-transport';
LoggerModule.forRoot(
createNestLoggerOptions(
{
botToken: process.env.TELEGRAM_BOT_TOKEN!,
chatId: process.env.TELEGRAM_CHAT_ID!,
},
{
pinoHttp: {
level: 'info',
},
},
),
);
import fastify from 'fastify';
import { createFastifyLoggerOptions } from 'pino-telegram-logger-transport';
const app = fastify({
logger: createFastifyLoggerOptions({
botToken: process.env.TELEGRAM_BOT_TOKEN!,
chatId: process.env.TELEGRAM_CHAT_ID!,
}),
});
import pino from 'pino';
import { createLambdaLoggerOptions } from 'pino-telegram-logger-transport';
const logger = pino(
createLambdaLoggerOptions({
botToken: process.env.TELEGRAM_BOT_TOKEN!,
chatId: process.env.TELEGRAM_CHAT_ID!,
}),
);
export const handler = async (event: unknown) => {
logger.info({ event }, 'Lambda invoked');
// business logic
};
MIT
FAQs
A transport for Pino that forwards structured logs to the Telegram Bot API, supports media attachments, and ships ready-made adapters for NestJS, Fastify, and AWS Lambda
We found that pino-telegram-logger-transport demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.