grammY Framework Reference

website·Indexed 34 days ago

https://grammy.dev

API reference and documentation for grammY, a framework for building Telegram bots. Includes detailed type definitions for v4.0.0 and documentation for official plugins such as Menu, Hydrate, Router, Files, Auto-retry, Stream, Throttler, and Commands.

Tokens
229K
Snippets
1.6K
Records
2.1K
Agent score
71%

What's inside grammY

  1. Overview of the @grammyjs/i18n plugin

    The @grammyjs/i18n plugin enables multi-language support (localization) for grammy bots. It is based on the Fluent localization system by Mozilla, allowing developers to move hard-coded strings into external translation files (.ftl). The plugin automatically determines the user's locale and provides a ctx.t() method to retrieve the translated text.
  2. Overview of ratelimiter middleware

    The ratelimiter plugin is a middleware for grammY and Telegraf bots designed to deflect spam. It tracks incoming requests by a unique key (defaulting to from.id) and dismisses requests that exceed a defined limit. Note that this limits requests processed by your bot, not the incoming requests from Telegram servers themselves.
  3. Introduction to grammY framework

    grammY is a framework used for creating Telegram bots. It is compatible with TypeScript and JavaScript and can be executed in Node.js, Deno, and browser environments.
  4. Overview of Entity Parser (entity-parser)

    The entity-parser plugin converts Telegram entities into semantic HTML. It is specifically designed for rare cases where Telegram-formatted text must be used outside of Telegram, such as displaying messages on a web page. For most other use cases, it is recommended to send text and entities back to Telegram directly rather than converting them to HTML.
  5. Overview of the Parse Mode plugin

    The Parse Mode plugin simplifies the creation of styled Telegram messages. Instead of manually tracking offsets and lengths for MessageEntity objects, developers can use a declarative API to compose richly formatted text. The plugin provides two main approaches: the fmt tagged template function for natural text composition and the FormattedString class for programmatic, chainable construction.
  6. Overview of the grammY framework

    grammY is an open-source framework designed for creating chat bots for the Telegram Messenger. It abstracts the tedious parts of the bot development process to simplify bot creation.
  7. Overview of ConversationMenuControlPanel

    The ConversationMenuControlPanel is a control panel used for managing conversational menus. It allows developers to update the menu state, close the menu (removing all buttons), or perform manual navigation between different conversational menus.
  8. Overview of grammY Sessions

    Sessions in grammY provide an elegant way to store data on a per-chat basis. The session middleware automatically loads data from a storage provider into ctx.session before handlers run and saves any modifications back to the storage after handlers finish. This removes the need to manually communicate with a database for every update.

    When to use sessions vs. a traditional database:

    • Use Sessions when: You need isolated storage per chat, the data is only used by the bot, the format is standard JavaScript objects, and the size is typically under 3 MB per chat.
    • Use a Database when: You need to access the same data across multiple chats, the data must be shared with other systems (e.g., a web server), you need to store large binary files, or you require database transactions.
  9. Overview of the grammY Hydration Plugin

    The hydrate plugin enhances grammY by attaching useful methods directly to API call results and objects within the context (ctx). This eliminates the need to manually pass chat IDs and message IDs to ctx.api or bot.api for common operations. For example, instead of calling ctx.api.editMessageText(chatId, messageId, text), you can call message.editText(text) directly on the message object.
    // WITHOUT hydrate
    const statusMessage = await ctx.reply("Processing");
    await ctx.api.editMessageText(ctx.chat.id, statusMessage.message_id, "Done!");
    
    // WITH hydrate
    const statusMessage = await ctx.reply("Processing");
    await statusMessage.editText("Done!");
  10. Overview of ReplayControls

    ReplayControls is an object passed by the ReplayEngine to a replay function during execution. It provides a set of controls to manage how the replay behaves, including the ability to interrupt the flow, cancel the process, mark non-repeatable actions, and create checkpoints for state recovery.
  11. Overview of grammY for Telegram Bot Development

    grammY is a library designed to simplify the creation of Telegram bots. A Telegram bot is an automated user account that interacts with users via HTTP requests. grammY abstracts the underlying HTTP communication with Telegram servers, allowing developers to use high-level methods like sendMessage to interact with users.
  12. Overview of DecayingDeque

    A DecayingDeque is a specialized doubly linked list that acts as a queue for tasks (called drifts). It manages task execution via a worker function and automatically removes elements from the queue when a task either completes or exceeds a specified taskTimeout. This behavior causes the queue to 'decay' as elements are removed from arbitrary positions upon completion, while new elements are appended to the tail.