Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/semklim/telegram_bot
Telegram bot for #bulochki))
https://github.com/semklim/telegram_bot
Last synced: about 2 months ago
JSON representation
Telegram bot for #bulochki))
- Host: GitHub
- URL: https://github.com/semklim/telegram_bot
- Owner: semklim
- Created: 2024-07-14T14:20:03.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-20T14:41:07.000Z (5 months ago)
- Last Synced: 2024-07-20T15:59:58.261Z (5 months ago)
- Language: TypeScript
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
🤖 Telegram Bot Bulochki
Bot based on [grammY](https://grammy.dev/) bot framework.
Project based on [telegram-bot-template](https://github.com/bot-base/telegram-bot-template).
## Features
- Scalable structure
- Config loading and validation
- Internationalization, language changing
- Graceful shutdown
- Logger (powered by [pino](https://github.com/pinojs/pino))
- Ultrafast and multi-runtime server (powered by [hono](https://github.com/honojs/hono))## Usage
Follow these steps to set up and run your bot:
1. **Environment Variables Setup**
Create an environment variables file by copying the provided example file:
```bash
cp .env.example .env
```
Open the newly created `.env` file and set the `BOT_TOKEN` environment variable.2. **Launching the Bot**
You can run your bot in both development and production modes.
**Development Mode:**
Install the required dependencies:
```bash
npm install
```
Start the bot in watch mode (auto-reload when code changes):
```bash
npm run dev
```**Production Mode:**
Install only production dependencies (no development dependencies):
```bash
npm install --only=prod
```Set `NODE_ENV` environment variable to `production` in your `.env` file.
Update `BOT_WEBHOOK` with the actual URL where your bot will receive updates.
Update `BOT_WEBHOOK_SECRET` with a random secret token.```dotenv
NODE_ENV=production
BOT_WEBHOOK=/webhook
BOT_WEBHOOK_SECRET=
```Start the bot in production mode:
```bash
npm start # with type checking (requires development dependencies)
# or
npm run start:force # skip type checking and start
```### List of Available Commands
- `npm run lint` — Lint source code.
- `npm run format` — Format source code.
- `npm run typecheck` — Run type checking.
- `npm run dev` — Start the bot in development mode.
- `npm run start` — Start the bot.
- `npm run start:force` — Starts the bot without type checking.### Directory Structure
```
project-root/
├── locales # Localization files
└── src
├── bot # Contains the code related to the bot
│ ├── callback-data # Callback data builders
│ ├── features # Implementations of bot features
│ ├── filters # Update filters
│ ├── handlers # Update handlers
│ ├── helpers # Utility functions
│ ├── keyboards # Keyboard builders
│ ├── middlewares # Middleware functions
│ ├── i18n.ts # Internationalization setup
│ ├── context.ts # Context object definition
│ └── index.ts # Bot entry point
├── server # Contains the code related to the web server
│ └── index.ts # Web server entry point
├── config.ts # Application config
├── logger.ts # Logging setup
└── main.ts # Application entry point
```## Environment Variables
Variable
Type
Description
NODE_ENV
String
Specifies the application environment. (development
orproduction
)
BOT_TOKEN
String
Telegram Bot API token obtained from @BotFather.
LOG_LEVEL
String
Optional.
Specifies the application log level.
For example, useinfo
for general logging. View the Pino documentation for more log level options.
Defaults toinfo
.
BOT_MODE
String
Optional.
Specifies method to receive incoming updates (polling
orwebhook
).
Default depends onNODE_ENV
(polling
fordevelopment
,webhook
forproduction
).
BOT_WEBHOOK
String
Optional inpolling
mode.
Webhook endpoint URL, used to configure webhook.
BOT_WEBHOOK_SECRET
String
Optional inpolling
mode.
A secret token that is used to ensure that a request is sent from Telegram, used to configure webhook.
BOT_SERVER_HOST
String
Optional. Specifies the server hostname.
Defaults to0.0.0.0
.
BOT_SERVER_PORT
Number
Optional. Specifies the server port.
Defaults to80
.
BOT_ALLOWED_UPDATES
Array of String
Optional. A JSON-serialized list of the update types you want your bot to receive. See Update for a complete list of available update types.
Defaults to an empty array (all update types exceptchat_member
,message_reaction
andmessage_reaction_count
).
BOT_ADMINS
Array of Number
Optional.
Administrator user IDs.
Use this to specify user IDs that have special privileges, such as executing/setcommands
.
Defaults to an empty array.