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

telegraf-middleware-console-time

v2.1.0

Published

Quick and dirty way to see whats incoming to your Telegraf Telegram bot while developing

Downloads

1,800

Readme

telegraf-middleware-console-time

NPM Version node Dependency Status Dev Dependency Status

Quick and dirty way to see what's incoming to your Telegraf or grammY Telegram bot while developing

When testing your bot it's nice to know what's coming in and how long it did take to process this request.

This library is not meant for usage in production. It's meant for debugging purposes.

In production the individual request wouldn't be as interesting as the general kind of request. For example not taking a look onto a specific '/start' command but onto all /start messages. This is kind of the opposite of what this library tries to achieve: Helping with understanding individual requests.

Install

$ npm install telegraf-middleware-console-time

Usage

Test your implementation

const {generateUpdateMiddleware} = require('telegraf-middleware-console-time');

const bot = new Bot(…);

// Other middlewares unrelated to your code
bot.use(…);

// Check your implementation for each telegram update (only when not in production)
if (process.env['NODE_ENV'] !== 'production') {
    bot.use(generateUpdateMiddleware());
}

// Your implementation
bot.command('start', …);

This will output something like this:

2020-03-31T14:32:36.974Z 490af message Edgar 6 /start: 926.247ms
2020-03-31T14:32:57.750Z 490ag message Edgar 6 /start: 914.764ms
2020-03-31T14:33:01.188Z 490ah message Edgar 5 /stop: 302.666ms
2020-03-31T14:46:11.385Z 490ai message Edgar 6 /start: 892.452ms

The 490af is the update_id.

The number before the commands is the total length of the content. This is helpful when considering max length for stuff like callback data.

The content itself is shortened in order to prevent log spamming.

Test a middleware

When you create your own middleware or assume slow timings of another middleware you can use these middlewares to create a timing profile

const {generateBeforeMiddleware, generateAfterMiddleware} = require('telegraf-middleware-console-time');

const bot = new Bot(…);

// Use BeforeMiddleware before loading the to be tested middleware
bot.use(generateBeforeMiddleware('foo'))

// Middleware to be tested
bot.use(…)

// Use AfterMiddleware after loading the to be tested middleware (with the same label)
bot.use(generateAfterMiddleware('foo'))

// Other middlewares / implementations (they will take the 'inner' amount of time when used)
bot.use(…)
bot.on(…, …)

This will output something like this:

490ai foo before: 304.185ms
490ai foo inner: 83.122ms
490ai foo after: 501.028ms
490ai foo total: 891.849ms

This indicates the checked middleware alone took 800ms and isnt as performant as maybe needed.