Skip to content

Sobhan-SRZA/template-bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Telegram Bot Handler - Telegraf.js Framework

A High-Performance Telegram Bot Framework
✨ Modern Architecture | 🚀 Optimized Performance | 🧩 Modular Design

License Telegraf Version Node.js TypeScript

🌟 Key Features

  • 🛡️ Advanced Anti-Crash System
  • 💾 Multi-Database Support (JSON/MySQL/MongoDB)
  • ⚡ Modern Command Handler with Cooldown
  • 📝 Colorful Console Logging
  • 🔄 Native TypeScript Support
  • 🤖 Full Telegram Bot API Coverage

📦 Core Dependencies

Package Version Purpose
telegraf 4.16.3 Telegram Bot Framework
quick.db 9.1.7 Database Management
dotenv 16.4.7 Environment Variables
colors 1.4.0 Console Coloring
typescript 5.5.4 TypeScript Compiler

🚀 Quick Start

  1. Install dependencies:

    npm install
  2. Configure environment:

    • Copy example.env to .env
    token="YOUR_TELEGRAM_BOT_TOKEN"
    database_type="json"
  3. Build & Run:

    npm start

    Or you can use this:

    npm run dev

    Then:

    node .

⌨️ Creating Commands

  1. Create new file in src/commands/ (e.g.: ping.ts)
  2. Use this template:
import CommandType from "../types/command";

const command: CommandType = {
  data: {
    name: "ping",
    description: "Check bot latency"
  },
  category: "misc",
  cooldown: 3,
  run: async (client, ctx) => {
    await ctx.reply("🏓 Pong!");
  }
};

export default command;

🎭 Creating Events

  1. Create new file in src/events/ (e.g.: messages.ts)
  2. Use this template:
import { NarrowedContext } from "telegraf";
import { Message, Update } from "telegraf/typings/core/types/typegram";
import { MyContext } from "../types/MessageContext";

const event: EventType = {
  name: "message",
  run: async (client, message: NarrowedContext<MyContext, Update.MessageUpdate<Message>>) => {
    console.log(`New message from @${ctx.from?.username}`);
  }
};

export default event;

📂 Project Structure

telegram-bot-handler/
├── dist/            # Compiled JS
├── src/
│   ├── commands/    # Command handlers
│   ├── handlers/    # Event handlers
│   ├── classes/     # Core classes
│   ├── functions/   # Functions
│   ├── utils/       # Utilities
│   └── types/       # TypeScript types
├── .env             # Environment variables
├── config.ts        # Main configuration
└── package.json     # Dependencies

⚙️ Configuration Options

Create a .env file in the root directory. Make sure to provide values for at least token and database_type.
Below is an example configuration:

# Bot token (required)
token="YOUR_TELEGRAM_BOT_TOKEN"

# Database type (required): options are "mysql" | "sql" | "mongodb" | "json"
database_type="json"

# (Optional) If using MongoDB:
database_mongoURL="your-mongo-url"

# (Optional) If using MySQL:
database_msql_host="your-mysql-host"
database_msql_user="your-mysql-user"
database_msql_password="your-mysql-password"
database_msql_database="your-mysql-database"

# Support server invite link (optional)
support_url="https://discord.gg/yourInvite"

# Source owners (optional, comma-separated list of owner IDs)
owners='["123456789", "987654321"]'

# Anti crash controller (optional)
anti_crash="true"

# Send console errors to Discord (optional)
logger="true"

📜 License

This project is licensed under the BSD 3-Clause License.

Copyright (c) 2024 Sobhan-SRZA & Persian Caesar
All rights reserved.

👥 Maintainers

🌟 Contributions are welcome! Please open an issue or PR for suggestions.


Need Help?
Join our support server: Persian Caesar Discord

This version includes:

  1. Clear visual hierarchy with emojis
  2. Version badges for key components
  3. Step-by-step setup guide
  4. Code examples for commands/events
  5. Configuration reference
  6. Project structure visualization
  7. License and contribution guidelines

Contact