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

max-bot-ts

v0.1.2

Published

TypeScript framework and SDK for building bots on MAX with polling, webhooks, sessions, and scenes.

Readme

max-bot-ts

TypeScript-фреймворк и SDK для разработки ботов на платформе MAX.

max-bot-ts дает практичный runtime для MAX с:

  • Bot и Context на основе middleware
  • long polling и webhook-обработчиком для Node.js
  • сессиями и легковесными сценами/FSM
  • типизированной API-оберткой и экспортируемыми моделями update/message/chat
  • хелперами для клавиатур, кнопок и вложений

Установка

npm install max-bot-ts

Требования:

  • Node.js 18+
  • валидный токен бота MAX

По умолчанию клиент использует https://platform-api.max.ru.

Быстрый старт

import { Bot, Keyboard } from 'max-bot-ts';

const bot = new Bot(process.env.BOT_TOKEN!);

bot.command('start', async (ctx) => {
  await ctx.reply('Привет из MAX', {
    attachments: [
      Keyboard.inlineKeyboard([
        [Keyboard.button.callback('Пинг', 'ping')],
      ]),
    ],
  });
});

bot.action('ping', async (ctx) => {
  await ctx.answerOnCallback({
    message: {
      text: 'pong',
    },
  });
});

await bot.start();

Polling

bot.start() запускает long polling и продолжает принимать обновления, пока не будет вызван bot.stop().

import { Bot } from 'max-bot-ts';

const bot = new Bot(process.env.BOT_TOKEN!);

bot.command('start', async (ctx) => {
  await ctx.reply('Бот запущен');
});

await bot.start({
  allowedUpdates: ['message_created', 'message_callback'],
});

Webhook

max-bot-ts поставляется с простым HTTP-обработчиком для Node.js, поэтому его можно встроить в свой сервер без дополнительного фреймворка.

import { createServer } from 'node:http';
import { Bot } from 'max-bot-ts';

const bot = new Bot(process.env.BOT_TOKEN!);
const webhook = bot.nodeWebhookHandler({
  secretToken: process.env.WEBHOOK_SECRET,
});

createServer(async (req, res) => {
  if (req.url !== '/a') {
    res.statusCode = 404;
    res.end('Not Found');
    return;
  }

  await webhook(req, res);
}).listen(4000);

Также можно создать callback, не привязанный к конкретному транспорту:

import { createWebhookCallback } from 'max-bot-ts/webhook';

const callback = createWebhookCallback(bot);
await callback(update);

Сессии

Используйте createSessionMiddleware, если нужен per-user или per-chat state.

import { Bot } from 'max-bot-ts';
import { createSessionMiddleware, MemorySessionStorage } from 'max-bot-ts/session';

type SessionData = {
  step?: 'idle' | 'waiting_phone';
};

const bot = new Bot(process.env.BOT_TOKEN!);

bot.use(createSessionMiddleware({
  storage: new MemorySessionStorage<SessionData>(),
  getSessionKey: (ctx) => ctx.chatId?.toString(),
  initial: () => ({ step: 'idle' }),
}));

Сцены

Для простых многошаговых сценариев используйте FSM и SceneManager.

import { Bot } from 'max-bot-ts';
import { FSM, SceneManager, type Scene } from 'max-bot-ts/scenes';

const bot = new Bot(process.env.BOT_TOKEN!);
const scenes = new SceneManager(new FSM());

const profileScene: Scene = {
  name: 'profile',
  async onEnter(ctx, fsm) {
    fsm.next('name');
    await ctx.reply('Отправьте ваше имя');
  },
  async onMessage(ctx, fsm) {
    if (fsm.state?.step === 'name') {
      fsm.leave();
      await ctx.reply(`Сохранено: ${ctx.message?.body.text ?? 'unknown'}`);
    }
  },
};

scenes.register(profileScene);

Экспорты пакета

  • max-bot-ts - основной API: Bot, Context, Composer, Api, Keyboard, вложения и re-export webhook/session/scenes
  • max-bot-ts/api - high-level API-клиент
  • max-bot-ts/core - примитивы бота и middleware-типы
  • max-bot-ts/helpers - хелперы клавиатур, кнопок, вложений и загрузки файлов
  • max-bot-ts/network/api - низкоуровневые API-модули и класс ошибки
  • max-bot-ts/polling - polling transport
  • max-bot-ts/webhook - webhook-хелперы
  • max-bot-ts/session - middleware и storage для сессий
  • max-bot-ts/scenes - FSM и менеджер сцен
  • max-bot-ts/types - экспортируемые типы Update, Message, Chat, BotInfo и связанных сущностей

Настройка клиента

Переопределить настройки клиента можно через конфиг Bot:

import { Bot } from 'max-bot-ts';

const bot = new Bot(process.env.BOT_TOKEN!, {
  clientOptions: {
    baseUrl: 'https://platform-api.max.ru',
  },
});

Значения по умолчанию:

  • baseUrl: https://platform-api.max.ru

Обработка ошибок

import { Bot } from 'max-bot-ts';

const bot = new Bot(process.env.BOT_TOKEN!);

bot.catch(async (error, ctx) => {
  console.error('Не удалось обработать update', ctx.update, error);
});

Ошибки API доступны как MaxError.

Разработка

npm run check --workspace max-bot-ts
npm run test --workspace max-bot-ts
npm run build --workspace max-bot-ts

Документация

Более подробные примечания по использованию находятся в docs/USAGE.md.