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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bot-router

v1.0.3

Published

Ротер для ботов

Downloads

2

Readme

Роутер для ботов

Импортирование

const { Router } = requier('bot-router'); //es5

or

import { Router } from 'bot-router'; //es6

Создание

const route = new Router({
  devMode: true //стандартное заначение {false}
})

Использование

import TelegramBot from "node-telegram-bot-api";
const TOKEN = '5796185493:AAHXakbzP_8tqMbmJSXL0GMvcqyvOJ8EAy0';
const bot = new TelegramBot(TOKEN, { polling: true });
//Не обязательно использовать модули для телеграмма

import { routing, PAGE_BACK, PAGE_END, PAGE_START, PAGE_START_UP, VIEW_START } from  './routers'

const route = new Router({
  routers: routing, // Использовать не обязательно
  devMode: true // Стандартное заначение {false}
})

bot.on('message', async (msg) => {
  const userId = msg.from?.id ||msg.chat.id;
  const pageId = await router.activePage(userId);

  if (msg.text == `/start`) return await router.pushPage(PAGE_START, userId, {
    view_id: VIEW_START,
  })
  
  if (router.getLocation(pageId, PAGE_START)) return await router.pushPage(PAGE_START_UP, userId, {
    view_id: VIEW_START,
    params: {text: msg.text}
  })

  if (router.getLocation(pageId, PAGE_START_UP)) return  await router.pushPage(PAGE_END, userId, {
    view_id: VIEW_START,
    params: { text: msg.text, old_text: pageId.params.text }
  });
});

router.listen(`NEW_PAGE`, async (data) => {
  console.log(`NEW_PAGE`, data);
  const  userId  = data.user_id;
  if (router.getLocation(data.page_id, PAGE_START)) return bot.sendMessage(data.user_id, `Напишите текст`)

  if (router.getLocation(data.page_id, PAGE_START_UP)) return bot.sendMessage(data.user_id, `Еще раз напишите текст`)

  if (router.getLocation(data.page_id, PAGE_END)) {
    await router.pushPage(PAGE_BACK, userId, {});
    return bot.sendMessage(data.user_id, `Готово, вот: \n\n1 Текст:${data.params.old_text}\n2 Текст: ${data.params.text}`, {
      reply_markup: {
        inline_keyboard: [
          [{ text:  `Назад`, callback_data: router.getCustomViews(PAGE_BACK) }]
        ]
      }
    });
  }
})


router.listen(`BACK_PAGE`, async (data) => {
  console.log(`BACK`, data)
  if (router.getLocation(data.page_id, PAGE_END)) {
    router.backPage(``, data.user_id);
    return bot.sendMessage(data.user_id, `Отмена сработала`);
  }
})


bot.on(`callback_query`, async (msg) => {
  const { data, id } = msg;
  if (data) {
   if (router.getLocation(data, PAGE_BACK)) {
     bot.answerCallbackQuery(id);
     router.popPage(msg.from.id);
   }
  }
})    

./routers

export const VIEW_START = `view_start`;

export const PAGE_START =`PAGE_START`;
export const PAGE_START_UP = `PAGE_START_UP`;
export const PAGE_BACK = `PAGE_BACK`;
export const PAGE_END = `PAGE_END`;

export const routing = {
  PAGE_START: "page_starting",
  PAGE_START_UP: "page_start_up",
  PAGE_BACK: "page_back",
  PAGE_END: "page_end",
}

Использование Redis

 import { Router, Redis } from 'bot-router';
 
 const redis = new Redis(`redis://127.0.0.1:6379/`);
 async function startRedis() {
  await redis.init();
 }
 start().catch((error) => console.log(error));

 const route = new Router({
  redis: redis,
  devMode: true, //стандартное заначение {false}
})