@grammyjs/runner

中文文档
2.0.3发布于 2023/03/23MITTypeScriptCommonJS近 30 天下载 243.2万

Scale grammY bots that use long polling

原始使用文档
文档目录7 节
  1. Do I Need This?
  2. Quickstart
  3. Concurrency Is Hard
  4. Resources
  5. grammY runner in the grammY documentation
  6. grammY runner API Reference
  7. grammY Example Bots

grammY runner


While the core of grammY is extremely efficient, the package does not ship with a built-in mechanism for long polling at scale. (It does scale well with webhooks, though.)

The grammY runner solves this by providing you with a sophisticated mechanism that can pull updates concurrently from the Telegram servers, and in turn execute your bot's middleware stack concurrently, all while catching errors, timeouts, and giving you full control over how much load is applied to your server.

Do I Need This?

Use the grammY runner package if

  • your bot needs to process a lot of updates (more than 1K/hour), or
  • your bot performs long-running operations such as large file transfers.

Do not use grammY runner if

  • you are just getting started with grammY, or
  • your bot is running on webhooks.

Quickstart

Here is a quickstart for you, but the real documentation is here on the website. The runner package has many more features, and they are documented there.

npm i @grammyjs/runner

Import run from @grammyjs/runner, and replace bot.start() with run(bot). It is that simple. Done!


Okay okay, here is some example code:

import { Bot } from "grammy";
import { run } from "@grammyjs/runner";

// Create bot
const bot = new Bot("<token>");

// Add the usual middleware, yada yada
bot.on("message", (ctx) => ctx.reply("Got your message."));

// Run it concurrently!
run(bot);

Concurrency Is Hard

grammY runner makes it trivial to have very high update throughput. However, concurrency is generally very hard to get right, so please read this section in the docs.

Resources

grammY runner in the grammY documentation

—more verbose documentation about concurrency in grammY.

grammY runner API Reference

—documentation of everything that grammY runner exports.

grammY Example Bots

—repository full of example bots, look our for those that demonstrate how to use grammY runner.

版本与发布记录

@grammyjs/runner 共发布 17 个版本,首次发布于 2021/03/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.3latest2023/03/233 年前
2.0.22023/03/203 年前
2.0.12023/03/203 年前
2.0.02023/03/193 年前
1.0.42022/08/024 年前
1.0.32021/11/234 年前

关于 @grammyjs/runner 的常见问题

@grammyjs/runner 是什么?

Scale grammY bots that use long polling

如何安装 @grammyjs/runner?

在项目目录运行 npm install @grammyjs/runner,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:grammy(^1.13.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@grammyjs/runner 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@grammyjs/runner 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@grammyjs/runner 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.20.0 || >=14.13.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@grammyjs/runner 可以商用吗?

@grammyjs/runner 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@grammyjs/runner 的下载量有多少?

根据 npm 官方下载统计,@grammyjs/runner 在 2026/10/17 – 2026/11/15 这 30 天内被下载 2,432,416 次,日均约 81,081 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@grammyjs/runner 还在维护吗?

最新版本 2.0.3 发布于 2023/03/23(3 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/03/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。