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

telegram-chat-notifier

v1.0.3

Published

A simple Node.js library to send formatted messages to a Telegram chat using a bot. Supports MarkdownV2 formatting and automatic rate limit handling.

Readme

TelegramChatNotifier

A simple Node.js library to send formatted messages to a Telegram chat using a bot. Supports MarkdownV2 formatting and automatic rate limit handling.

Installation

npm install telegram-chat-notifier

Usage

1. Set up your Telegram Bot

  • Create a bot via @BotFather on Telegram and obtain your bot token.
  • Add your bot to your desired chat/group and obtain the chat ID (see How to get chat ID).

2. Configure Environment Variables

Set the following environment variables in your project or system:

  • TELEGRAM_BOT_TOKEN: Your Telegram bot token
  • TELEGRAM_CHAT_ID: The chat ID to send messages to

Alternatively, you can pass these as options to the function.

3. Send a Message

const { sendMessage } = require('telegram-chat-notifier');

(async () => {
  const result = await sendMessage(
    'Hello',
    'This is a test message!'
  );
  console.log(result);
})();

With Custom Options

const { sendMessage } = require('telegram-chat-notifier');

(async () => {
  const result = await sendMessage(
    'Custom Title',
    'Custom body',
    {
      TELEGRAM_BOT_TOKEN: 'YOUR_BOT_TOKEN',
      TELEGRAM_CHAT_ID: 'YOUR_CHAT_ID',
      retries: 2 // Optional: number of retry attempts on rate limit
    }
  );
  console.log(result);
})();

4. Example: Using with Express.js

You can integrate the Telegram-chat-notifier into an Express.js route to send notifications from your web server:

const express = require('express');
const telegram = require('telegram-chat-notifier');

/* gets the TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID from the .env file */
require('dotenv').config(); 

const app = express();
app.use(express.json());

app.post('/example1',  (req, res) => {
  const { title, body } = req.body;
 
  telegram.sendMessage(title, body);   //"fire and forget" approach.

  return res.send('hello world');
  
});

app.post('/example2', async (req, res) => {
  const { title, body } = req.body;
  const result = await telegram.sendMessage(title, body);
  if (result.success) {
    res.status(200).json({ message: 'Notification sent!', data: result.data });
  } else {
    res.status(500).json({ error: result.error });
  }
});

app.post('/example3', async (req, res) => {
  const { title, body } = req.body;
  
  //alternatively you can pass the bot token and the chat id as options
  const result = await telegram.sendMessage(title, body,{
      TELEGRAM_BOT_TOKEN: 'YOUR_BOT_TOKEN',
      TELEGRAM_CHAT_ID: 'YOUR_CHAT_ID'
  });
  if (result.success) {
    res.status(200).json({ message: 'Notification sent!', data: result.data });
  } else {
    res.status(500).json({ error: result.error });
  }

});



const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

API

sendMessage(title, body, options)

  • title (string): The message title (will be bolded)
  • body (string): The message body
  • options (object, optional):
    • TELEGRAM_BOT_TOKEN (string): Telegram bot token (overrides env var)
    • TELEGRAM_CHAT_ID (string): Telegram chat ID (overrides env var)
    • retries (number): Number of retry attempts on rate limit (default: 3)

Returns:

  • On success: { success: 1, data: <Telegram API response> }
  • On failure: { success: 0, error: <error message> }

How to get chat ID

  1. Start a chat with your bot or add it to a group.
  2. Send a message.
  3. Use the following URL in your browser (replace BOT_TOKEN): https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
  4. Look for chat.id in the response JSON.

License

MIT