This project is a generic Telegram bot built with Node.js, Telegraf, and Express, using TypeScript. The bot is designed to send audio files from a predefined pool of MP3 files when a specific command is issued.
telegram-bot
├── src
│ ├── app.ts # Entry point of the application
│ ├── bot
│ │ ├── commands
│ │ │ ├── index.ts # Exports all command handlers
│ │ │ └── audioCommand.ts # Handles the audio command
│ │ ├── middleware
│ │ │ └── index.ts # Middleware functions for processing updates
│ │ └── index.ts # Initializes the Telegraf bot
│ ├── server
│ │ ├── routes
│ │ │ └── index.ts # Sets up routes for the Express server
│ │ └── index.ts # Starts the Express server
│ ├── utils
│ │ └── audioManager.ts # Utility functions for managing audio files
│ └── types
│ └── index.ts # TypeScript interfaces and types
├── audio
│ └── .gitkeep # Keeps the audio directory in version control
├── package.json # npm configuration file
├── tsconfig.json # TypeScript configuration file
├── .env.example # Example of environment variables
└── README.md # Project documentation
-
Clone the repository:
git clone <repository-url> cd telegram-bot -
Install dependencies:
npm install -
Configure environment variables:
- Copy
.env.exampleto.envand fill in the required values, especially the Telegram bot token.
- Copy
-
Run the bot:
npm start
- To send an audio file, use the command defined in the bot. The bot will respond with a random audio file from the pool of MP3 files located in the
audiodirectory.
Feel free to submit issues or pull requests for improvements or bug fixes.