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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tell-js

v1.1.3

Published

A logging library to send alerts to a Telegram bot.

Downloads

20

Readme

tell-js

npm version NPM Downloads License: GPL v3

A lightweight and easy-to-use Node.js logging library that sends alerts via Telegram bots.

Features

  • Simple and intuitive API
  • Supports multiple log levels (info, error, warn, log)
  • Sends log messages directly to your Telegram chat
  • Easy integration with existing Node.js projects

Installation

npm install tell-js

Usage

import Tell from 'tell-js';

const logger = new Tell({
    chatId: "YOUR_CHAT_ID",
    botToken: "YOUR_BOT_TOKEN"
});

logger.info("This is information");
logger.error("This is an error message");
logger.warn("This is a warning message");
logger.log("A regular log message.");

Configuration

To use tell-js, you need to provide two pieces of information:

  1. Telegram Bot Token
  2. Chat ID

Creating a Telegram Bot Token

  1. Open Telegram and search for the @BotFather bot.
  2. Start a chat and send the command /newbot.
  3. Follow the prompts to choose a name and username for your bot.
  4. Once created, BotFather will provide you with a token. This is your BOT_TOKEN.

Getting Your Chat ID

  1. Start a chat with your newly created bot.
  2. Send a message to the bot.
  3. Open this URL in your browser, replacing <BOT_TOKEN> with your actual bot token:
    https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
  4. Look for the "chat":{"id": field in the response. The number after it is your CHAT_ID.

Integrating with Winston

import winston from 'winston';
import Tell from 'tell-js';
import { Writable } from 'stream';

const tell = new Tell({
    chatId: "YOUR_CHAT_ID",
    botToken: "YOUR_BOT_TOKEN"
});

const logger = winston.createLogger({
    transports: [
        new winston.transports.Console(),
        new winston.transports.Stream({
            stream: new Writable({
                write: (msg: string) => {
                    // Use tell-js methods here.
                    tell.log(msg);
                    return true;
                }                
            })
        })
    ]
});

FAQ

  1. Q: Is there a message size limit? A: Yes, Telegram has a limit of 4096 characters per message. If your log message exceeds this, it will be split into multiple messages.

  2. Q: Can I use this in a browser environment? A: No, tell-js is designed for Node.js environments only, as it requires access to server-side resources.

  3. Q: How secure is it to send logs via Telegram? A: While Telegram provides encryption, we recommend not logging sensitive information like passwords or API keys.

Troubleshooting

  • Messages not sending: Ensure your bot token and chat ID are correct.
  • Rate limiting issues: Check your rateLimit setting and Telegram's rate limit policies.
  • "Bot not initialized" error: Make sure you've created the Tell instance before using logging methods.

API Reference

new Tell(options)

Creates a new Tell instance.

  • options.chatId: Your Telegram chat ID (string)
  • options.botToken: Your Telegram bot token (string)

Methods

  • logger.info(message): Sends an info-level message
  • logger.error(message): Sends an error-level message
  • logger.warn(message): Sends a warning-level message
  • logger.log(message): Sends a regular log message

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GNU General Public License v3.0 License - see the LICENSE file for details.

Support

If you encounter any problems or have any questions, please open an issue on the GitHub repository or send an email to the maintainer.

Changelog

See CHANGELOG.md for a detailed history of changes to tell-js.

Acknowledgements

  • Thanks to the Telegram team for their excellent bot API.
  • Inspired by the logging strategy of @levelsio for his projects.