How viperadnan-git/telegram-forwarder-bot works
Project Overview
• This project is a Telegram bot built using the grammy framework and written in TypeScript.
• Its main purpose is to forward messages from one Telegram channel to one or more channels/groups.
• The bot uses webhooks to receive updates from Telegram servers and relies on environment variables (as shown in .env.sample) for configuration.
• A Redis database is used for storing channel IDs and configurations.
Main Components
a. Telegram Server:
• Represents the external Telegram API server responsible for sending webhook updates.
b. Webhook Server / Bot Entry Point:
• Use the main file (src/index.ts) as the entry point where the webhook endpoint is established.
• That the application is listening for incoming updates.
c. Bot Core / Command Handlers:
• Bot core (src/bot.ts) that initializes the grammy framework and sets up the webhook.
• Various command handlers located in the src/handlers directory:
• /start → handled in src/handlers/start.ts
• /help → handled in src/handlers/help.ts
• /set, /rem, /get → handled in src/handlers/set_chat.ts, rem_chat.ts, get_chat.ts, etc.
• /set_owner, /owner_only, etc.
• That these handlers process commands, perform validations (like owner-only commands), and forward messages.
d. Database / Storage Layer:
• Redis database connection integrated via src/database.ts.
e. Utility and Logging Modules:
• Auxiliary modules found in src/modules:
• Logger (src/modules/logger.ts) for logging operations.
• Utils (src/modules/utils.ts) for common utility functions.
• These support debugging and operational logging.
Relationships and Interactions
• How the Telegram server sends updates via webhooks to the Webhook Server.
• From the Webhook Server, the bot core dispatches incoming messages to the appropriate command handlers.
• The command handlers may interact with the Redis database to read or update configuration details.
• Feedback loop where processed messages or notifications are sent back to users via the Telegram API.
• Interactions between each handler and the shared modules (logger and utils) for common tasks.
Architectural Patterns & Design Principles
• The design follows a modular and layered architecture:
• Separation of concerns: command handlers, database interactions, and utility modules are in separate files.
• The project adheres to a clear command pattern where each bot command is encapsulated in its corresponding handler.
• Dependency Injection can be implied for passing configuration and database connections to various modules.
• Decoupling: the Telegram API interface is clearly separated from business logic (command processing) and data storage.
Final Summary
• External integrations (Telegram API, Redis)
• Internal architecture layers (webhook entry point, bot core, individual command handlers)
• Supporting modules (logger, utils)
• Data and command flow between the components.