Skip to main content
grammY ships with several powerful built-in utilities that enhance your bot development experience. These are included in the core package and don’t require additional dependencies.

Session Plugin

The session plugin provides persistent data storage for your bot, allowing you to remember information about users and chats across updates.

Basic Usage

Session Options

The session plugin accepts several configuration options:

Storage Adapters

By default, sessions are stored in memory and will be lost when your bot restarts. For production, use a storage adapter:
For persistent storage, use external adapters (see the grammY documentation for database adapters).

Custom Storage Adapter

You can create your own storage adapter:

Lazy Sessions

For better performance, especially in groups, use lazy sessions that only load data when accessed:

Multi Sessions

Manage multiple independent session namespaces:

Enhanced Sessions

Add migrations and expiry to sessions:

Keyboard Builders

grammY provides two keyboard builder classes for creating custom and inline keyboards easily.

Custom Keyboards (Keyboard)

Custom keyboards replace the user’s system keyboard:

Keyboard Options

Button Types

Button Styling

Keyboard Layout Methods

Removing Keyboards

Inline Keyboards (InlineKeyboard)

Inline keyboards appear directly below messages:

Inline Button Types

Inline Keyboard Styling

Dynamic Keyboards

Build keyboards from data:

Webhook Callback

The webhook callback utility makes it easy to run your bot on webhooks with any web framework.

Basic Usage

Supported Frameworks

grammY supports many web frameworks:

Webhook Options

Setting the Webhook

Before using webhooks, set the webhook URL:

Inline Query Result Builder

The InlineQueryResultBuilder helps create inline query results easily.

Basic Usage

Result Types

Custom Message Content

Override the sent message content:

With Inline Keyboard

Next Steps