You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 botconstbot=newBot("<token>");// Add the usual middleware, yada yadabot.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.