Module

x/grammy/mod.ts

The Telegram Bot Framework.
Go to Latest
import * as grammy from "https://deno.land/x/grammy@v1.11.1/mod.ts";

Classes

This class provides access to the full Telegram Bot API. All methods of the API have an equivalent on this class, with the most important parameters pulled up into the function signature, and the other parameters captured by an object.

This is the single most important class of grammY. It represents your bot.

This error is thrown when middleware throws. It simply wraps the original error (accessible via the error property), but also provides access to the respective context object that was processed while the error occurred.

The composer is the heart of the middleware system in grammY. It is also the superclass of Bot. Whenever you call use or on or some of the other methods on your bot, you are in fact using the underlying composer instance to register your middleware.

When your bot receives a message, Telegram sends an update object to your bot. The update contains information about the chat, the user, and of course the message itself. There are numerous other updates, too: https://core.telegram.org/bots/api#update

This class represents errors that are thrown by grammY because the Telegram Bot API responded with an error.

This class represents errors that are thrown by grammY because an HTTP call to the Telegram Bot API failed.

Use this class to simplify building an inline keyboard (something like this: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating).

An InputFile wraps a number of different sources for sending files.

Use this class to simplify building a custom keyboard (something like this: https://core.telegram.org/bots#keyboards).

The memory session storage is a built-in storage adapter that saves your session data in RAM using a regular JavaScript Map object. If you use this storage adapter, all sessions will be lost when your process terminates or restarts. Hence, you should only use it for short-lived data that is not important to persist.

Functions

You can use this function to transform an existing storage adapter, and add more features to it. Currently, you can add session migrations and expiry dates.

This is an advanced function of grammY.

This is an advanced function of grammY.

Session middleware provides a persistent data storage for your bot. You can use it to let your bot remember any data you want, for example the messages it sent or received in the past. This is done by attaching session data to every chat. The stored data is then provided on the context object under ctx.session.

Creates a callback function that you can pass to a web framework (such as express) if you want to run your bot via webhooks. Use it like this:

Interfaces

Options to pass to the API client that eventually connects to the Telegram Bot API server and makes the HTTP requests.

Options to pass to the bot when creating it.

When enhancing a storage adapter, it needs to be able to store additional information. It does this by wrapping the actual data inside an object, and adding more properties to this wrapper.

A lazy session flavor is a context flavor that holds a promise of some session data under ctx.session.

Middleware in the form of a container for a function.

Options for enhanced sessions

A mapping from version numbers to session migration functions. Each entry in this object has a version number as a key, and a function as a value.

Options that can be specified when running the bot via simple long polling.

A session flavor is a context flavor that holds session data under ctx.session.

Options for session middleware.

A storage adapter is an abstraction that provides read, write, and delete access to a storage solution of any kind. Storage adapters are used to keep session middleware independent of your database provider, and they allow you to pass your own storage solution.

A transformable API enhances the RawApi type by transformers.

Small utility interface that abstracts from webhook reply calls of different web frameworks.

Type Aliases

Type of a function that can perform an API call. Used for Transformers.

Type of the context object that is available inside the handlers for bot.callbackQuery.

Type of the middleware that can be passed to bot.callbackQuery.

Type of the context object that is available inside the handlers for bot.chatType.

Type of the middleware that can be passed to bot.chatType.

Type of the context object that is available inside the handlers for bot.command.

Type of the middleware that can be passed to bot.command.

Error handler that can be installed on a bot to catch error thrown by middleware.

This type infers which properties will be present on the given context object provided it matches the given filter query. If the filter query is a union type, the produced context object will be a union of possible combinations, hence allowing you to narrow down manually which of the properties are present.

Represents a filter query that can be passed to bot.on. There are three different kinds of filter queries: Level 1, Level 2, and Level 3. Check out the website to read about how filter queries work in grammY, and how to use them.

Middleware for a web framework. Creates a request-response handler for a request. The handler will be used to integrate with the compatible framework.

Type of the context object that is available inside the handlers for bot.gameQuery.

Type of the middleware that can be passed to bot.gameQuery.

Type of the context object that is available inside the handlers for bot.hears.

Type of the middleware that can be passed to bot.hears.

Type of the context object that is available inside the handlers for bot.inlineQuery.

Type of the middleware that can be passed to bot.inlineQuery.

Middleware for grammY, either as a function or as a container for a function.

Middleware in the form of a function.

Options for session middleware if multi sessions are used. Specify "type": "multi" in the options to use multi sessions.

A function of this type is passed as the second parameter to all middleware. Invoke it to call the downstream middleware and pass on the control flow.

Represents the raw Telegram Bot API with all methods specified 1:1 as documented on the website (https://core.telegram.org/bots/api).

API call transformers are functions that can access and modify the method and payload of an API call on the fly. This can be useful if you want to implement rate limiting or other things against the Telegram Bot API.