Skip to content

habemuscode/examples

 
 

Repository files navigation

grammY Example Bots

This repository provides a number of example bots to help you get started.

  1. Create a bot with @BotFather, and get the bot token
  2. Clone this example repository
  3. Run npm install in the root directory of this repo
  4. Paste your token into the bot source file that you want to run (e.g. ./echo.ts)
  5. Run a bot with:
npm run bot <name>

# Example:
npm run bot echo

Hello World (echo)

A simple echo bot that echoes all text messages.

Send a Single Message (send-message)

Not a real bot, only illustrates how to manually send a single message once. Maybe useful for 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 where all data is generated at runtime.

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 real database. Therefore, using lazy sessions does not make much sense. This bot uses them anyway in order to illustrate how to use them.)

Runner Example (runner)

Illustrates how to use the @grammyjs/runner package that is useful for large bots.

Scaling Example (scaling)

An advanced but minimal example bot that demonstrates a viable directory structure, for the collective orchestration of custom context flavors, transformers, sessions with initial data, composers, and routers.

Illustrates how to run a bot using a local Bot API server via Docker.

Illustrates how to run a bot using a local Bot API server with a reverse proxy and self-signed certificate via Docker.

Please Contribute

We could need some more examples here, e.g. about

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

and other things.

About

Example bots to help you get started with grammY

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 97.4%
  • Dockerfile 1.5%
  • Shell 1.1%