/examples

Examples to help you get started with grammY

Primary LanguageTypeScriptMIT LicenseMIT

grammY Examples

This repository contains various bots and setups to help you get started with grammY.

  1. Contact @BotFather to create a bot and get its token.
  2. Clone the epository.
  3. Paste your bot’s token to the source files of the examples you would like to run (e.g. ./echo.ts).
  4. Run npm install from the root.
  5. Run the examples this way:
npm run bot <name>

# For example, to run the echo example:
npm run bot echo

Hello World (echo)

A simple bot that echoes the text messages it receives.

Send a Single Message (send-message)

Not a real bot, only an illustration of sending a single message once. Might useful in scripts.

Nested Menus (menu)

Advanced menu example bot that lets you manage different dishes (Pasta, Pizza, Sushi, Entrecôte) via a nested menu structure. It shows how to build more complex menus when all the data is generated at runtime.

Menus with Media (menu-with-photo)

Similar to the nested menu example, but with photos.

Sessions (stats)

Full-blown example bot that counts messages in a chat and stores the statistics in session objects.

Lazy Sessions (stats-lazy)

Full-blown example bot that counts photos in a chat and stores the statistics using lazy sessions. The advantage of lazy sessions is that the storage is only queried whenever data is actually needed.

(Note that this bot stores data in-memory, it does not connect to a database. Therefore, using lazy sessions does not make much sense. This bot is only an illustratation on how to use them.)

Runner Example (runner)

Illustrates how to use the grammY runner to run large bots.

Scaling Example (scaling)

NOTE: This example is not endorsement of any directory structure. See Awesome grammY for live examples instead.

A minimal example bot that demonstrates how various grammY objects can be orchestrated together, including custom context flavors, transformers, sessions with initial data, composers, and routers.

Example bot that can run on Vercel.

Example bot that can run on Deno Deploy.

Example bot that can run on Deta.

Example bot that can run on Supabase Edge Functions.

Use Docker to setup a local Bot API server and run your bot on it.

Use Docker to setup a local Bot API server with a self-signed TLS certificate, and run your bot on it.

Please Contribute

We could have some more examples here, for example:

  • command handling
  • filter queries
  • inline keyboards
  • file support

and other things.