Code Monkey home page Code Monkey logo

examples's Introduction

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 repository.
  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 be 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.