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

tg-bot-stats

v1.0.4

Published

A package for collecting and visualizing bot statistics

Readme

tg-bot-stats

npm version License: MIT

Russian version: README in Russian

A lightweight Node.js package for collecting and visualizing bot interaction statistics using SQLite for storage and Chart.js for visualization.

Features

  • 📊 Collect button click statistics from your bot
  • 💾 Store data in SQLite database
  • 📈 Visualize statistics with interactive charts
  • 🕒 Track clicks over time (hourly, daily, monthly)
  • 🔍 View detailed click information
  • 🛠️ Customizable data schema

Installation

npm install tg-bot-stats

Quick Start

import TgBotStats from 'tg-bot-stats';

// Initialize with custom schema
const statsBot = new TgBotStats({
    dbPath: "./src/databases/bot_stats.db",
    defaultSchema: {
        eventId: "TEXT",
        userId: "TEXT",
        username: "TEXT",
        timestamp: "DATETIME",
        additionalData: "TEXT",
    },
});

// Record a button click
await statsBot.recordClick({
  eventId: 'start_button',
  userId: 'user123',
  additionalData: { platform: 'telegram' }
});

// Launch dashboard
statsBot.startDashboard({
    port: 8888,
});

API Documentation

new TgBotStats(options)

Creates a new statistics collector instance.

Options:

  • dbPath (String): Path to SQLite database file (default: './bot-stats.db')
  • defaultSchema (Object): Database schema definition (default: basic button click schema)

Methods

recordClick(data)

Records a button click event.

Parameters:

  • data (Object): Click data object containing at least eventId

Returns: Promise that resolves when record is saved

getEventStats(eventId)

Gets all recorded clicks for a specific button.

Parameters:

  • eventId (String): Button identifier

Returns: Promise that resolves with array of click records

getAllStats()

Gets aggregated statistics for all buttons.

Returns: Promise that resolves with summary statistics object

getTimeSeriesStats(period)

Gets time-based statistics.

Parameters:

  • period (String): 'hour', 'day', 'month', or 'year' (default: 'day')

Returns: Promise that resolves with time series data

startDashboard(options)

Starts the statistics dashboard web server.

Options:

  • port (Number): Port to listen on (default: 3000)

Dashboard Features

  1. Interactive Charts:

    • Line chart showing clicks over time
    • Bar chart showing total clicks per button
  2. Time Period Selection:

    • View data grouped by hour, day, month, or year
  3. Detailed View:

    • Click on any button in the bar chart to see detailed click records

Customization

Custom Data Schema

Extend the default schema to store additional information:

const statsBot = new TgBotStats({
  defaultSchema: {
    eventId: 'TEXT',
    userId: 'TEXT',
    timestamp: 'DATETIME',
    additionalData: 'TEXT',
    // Your custom fields:
    chatType: 'TEXT',
    messageLength: 'INTEGER'
  }
});

Examples

Telegram Bot Example

import TgBotStats from 'tg-bot-stats';
import TelegramBot from 'node-telegram-bot-api';

const statsBot = new TgBotStats();
const bot = new TelegramBot(process.env.TELEGRAM_TOKEN, { polling: true });

bot.onText(/\/start/, async (msg) => {
  await statsBot.recordClick({
    eventId: 'start_command',
    userId: msg.from.id.toString(),
    additionalData: {
      username: msg.from.username,
      language: msg.from.language_code
    }
  });
  
  await bot.sendMessage(msg.chat.id, 'Welcome!');
});

// Start dashboard
statsBot.startDashboard({ port: 9999 });

License

MIT © Osipov Sergey