Skip to main content
Module

x/grammy_runner/mod.ts

Scale grammY bots
Latest
import * as grammyRunner from "https://deno.land/x/grammy_runner@v2.0.3/mod.ts";

Classes

A BotWorker instance is a like a Bot instance in the sense that it can process updates. It is different from Bot because it cannot pull in these updates, so it cannot be be started or stopped. Instead, it has to receive these updates from a central Bot instance that fetches updates.

A decaying deque is a special kind of doubly linked list that serves as a queue for a special kind of nodes, called drifts.

Functions

Creates an update sink that handles updates in batches. In other words, all updates of one batch are processed concurrently, but one batch has to be done processing before the next batch will be processed.

Creates an update sink that handles updates concurrently. In other words, new updates will be fetched—and their processing will be started—before the processing of older updates completes. The maximal number of concurrently handled updates can be limited (default: 500).

Creates a runner that pulls in updates from the supplied source, and passes them to the supplied sink. Returns a handle that lets you control the runner, e.g. start it.

Creates an update sink that handles updates sequentially, i.e. one after another. No update will be processed before the previous update has not either been processed, or its processing has failed and the error has been handled.

Creates an update source based on the given update supplier.

Takes a grammY bot and returns an update fetcher function for it. The returned function has built-in retrying behavior that can be configured. After every successful fetching operation, the offset parameter is correctly incremented. As a result, you can simply invoke the created function multiple times in a row, and you will obtain new updates every time.

Creates middleware that distributes updates across cores.

Runs a grammY bot with long polling. Updates are processed concurrently with a default maximum concurrency of 500 updates. Calls to getUpdates will be slowed down and the limit parameter will be adjusted as soon as this load limit is reached.

Using a runner for grammY allows your bot to run middleware concurrently. This has the benefit that multiple messages can be processed concurrently, hence making your bot drastically more scalable, but it comes at the cost that race conditions may occur because some messages need to be processed in order.

Interfaces

Options that can be passed to the call to getUpdates when the runner fetches new a new batch of updates.

This handle gives you control over a runner. It allows you to stop the bot, start it again, and check whether it is running.

Options to be passed to the runner created internally by run(bot).

Options to be passed to run(bot, options). Collects the options for the underlying update source, runner, and update sink.

Options for creating an update sink.

Options controlling how the update source operates.

Update consumers are objects that can process an update from the Telegram Bot API. When you call run(bot), such an object will be created automatically for you. The passed bot will process the updates.

An update sink is an object that acts as the sink for updates for a runner. It features a handle function that takes in a batch of updates in the form of an array. It returns a promise that should resolve with a positive integral number soon as the sink is ready to handle further updates. The resolved number indicates how many updates the sink is ready to handle next.

An update source is an object that acts as the source of updates for a runner. It features an async generator of updates that produces batches of updates in the form of arrays.

Update suppliers are objects that can fetch a number of new updates from the Telegram Bot API. When you call run(bot), such an object will be created automatically for you. It uses the passed bot to fetch updates.