npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

logs-service

v2.0.2

Published

Send logs to telegram bot. Optional you can send logs to CloudWatch service too

Readme

Telegram Logger Service

Description

The Telegram Logger is a TypeScript class designed to send application logs to a Telegram bot and optionally to Amazon CloudWatch. This tool is useful for logging important events or errors from your applications and receiving immediate notifications through Telegram. This service connects to the Telegram API to send formatted log messages, providing detailed information about the log type, the service generating it, and the log message. Additionally, if configured correctly, the logs can also be sent to an Amazon CloudWatch log group for storage and analysis.

Installation

npm install logs-service

Creating an Instance of TelegramLogger

To create an instance of TelegramLogger, you need to provide the following parameters:

  • botToken: The Telegram bot token.
  • chatId: The ID of the Telegram chat where logs will be sent.
  • logGroupName (optional): The name of the CloudWatch log group (only if you want to send logs to CloudWatch).
  • logStreamName (optional): The name of the CloudWatch log stream (only if you want to send logs to CloudWatch).

Example:

import { TelegramLogger } from "logs-service";

const logger = new TelegramLogger('YOUR_BOT_TOKEN', 'YOUR_CHAT_ID', 'YOUR_LOG_GROUP_NAME', 'YOUR_LOG_STREAM_NAME');

Sending Logs

To send a log, you can use the sendLog method. This method formats the message and sends it both to Telegram and, optionally, to CloudWatch if the CloudWatch parameters are configured correctly.

Example:

const log = {
  date: 'Date in string format',
  logType: 'INFO',
  service: 'YourServiceName',
  message: 'This is a log message'
};

// Send log to Telegram and to CloudWatch if configured
await logger.sendLog(log, true);  // 'true' activates sending to CloudWatch

Configuring AWS SDK

If you want to send logs to CloudWatch, make sure to configure the AWS SDK with the proper credentials. Here is an example of a basic configuration:

Example:

import { config } from 'aws-sdk';

// Configure AWS credentials (you can use your preferred method)
config.update({
  region: 'us-east-1', // Define your AWS region
  accessKeyId: 'YOUR_AWS_ACCESS_KEY_ID', 
  secretAccessKey: 'YOUR_AWS_SECRET_ACCESS_KEY'
});

Parameters of the TelegramLogger Class

| Parameter | Type | Description | Required | |----------------|--------|-----------------------------------------------------------|----------| | botToken | string | The Telegram bot token | Yes | | chatId | string | The Telegram chat ID where the logs will be sent | Yes | | logGroupName | string | The CloudWatch log group name (optional) | No | | logStreamName| string | The CloudWatch log stream name (optional) | No |

Dependencies

  • pino: ^9.6.0 - For logging and formatting logs.
  • aws-sdk: ^2.1692.0 - For interacting with Amazon CloudWatch.

Methods

sendLog(log: Log, sendMessageLambda: boolean = false): Promise

Sends a log to Telegram and, if configured, to CloudWatch. If sendMessageLambda is set to true, the log will also be sent to CloudWatch.

Parameters:

  • log: The log object to send. It must follow the Log interface.
  • sendMessageLambda (optional): If set to true, logs will also be sent to CloudWatch.

sendToLambda(logGroupName: string, logStreamName: string, message: string): Promise

Sends the log message to CloudWatch if the configuration is enabled.

Full Example

import { TelegramLogger } from './TelegramLogger';
import { config } from 'aws-sdk';

config.update({
  region: 'us-east-1',
  accessKeyId: 'YOUR_AWS_ACCESS_KEY_ID',
  secretAccessKey: 'YOUR_AWS_SECRET_ACCESS_KEY',
});

const logger = new TelegramLogger('YOUR_BOT_TOKEN', 'YOUR_CHAT_ID', 'YOUR_LOG_GROUP_NAME', 'YOUR_LOG_STREAM_NAME');

const log = {
  date: new Date(),
  logType: 'ERROR',
  service: 'MyApp',
  message: 'An error occurred while processing the request.',
};

logger.sendLog(log, true); // Send to Telegram and CloudWatch

License

MIT