1.0.0 • Published 5 months ago

@dieugene/kak-dela-bot v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Template Telegram Bot

This repository contains a template for creating Telegram bots with a robust architecture and extensive feature set. It's designed to be a foundation for building various types of Telegram bots with AI capabilities, user management, and advanced dialog handling.

🚀 Features

Core Functionality

  • Dialog Management: Built-in dialog system using @dialogai/dialog-class
  • User Management: Comprehensive user control system via @dialogai/user-controller
  • AI Integration: LangChain integration for AI/LLM capabilities
  • Database Support: YDB (Yandex Database) integration
  • File Handling: Support for various file types (documents, photos, audio, video)
  • Voice Message Processing: Built-in voice message recognition
  • Session Management: Advanced session handling and cleanup
  • Error Handling: Comprehensive error management system
  • Admin Functions: Built-in administrative capabilities
  • Onboarding: Customizable onboarding flow
  • Queue System: Support for queues and timers
  • Logging: Integrated logging system

Technical Stack

  • Runtime: Node.js
  • Telegram API: Telegraf library
  • Dialog System: @dialogai/dialog-class - for building dialogs
  • User Management: @dialogai/user-controller - for user data management (get_user_data, set_user_data)
  • Database:
    • @dieugene/key-object-db or @dieugene/ydb - for storing profiles and events
  • Utilities:
    • @dieugene/utils - for link generation and command parsing
    • @dieugene/sessions - for session management
    • @dieugene/tg-messages-cache - for message caching
    • @dieugene/callbacks - for inline button handling
  • AI/LLM: @langchain/openai - for AI-powered features
  • Additional Tools: QR code generation (qrcode npm package)

📋 Data Structure

Identifiers and Timestamps

  • All string identifiers use UUID format
  • Timestamps (created_on) are stored as Unix time
  • Dates are stored in ISO date format

🔧 Implementation Guidelines

Dialog Implementation

The template uses @dialogai/dialog-class for building natural conversations. This module provides:

  • Dialog state management
  • Natural conversation flow
  • Integration with message caching and sessions

User Management

The template uses @dialogai/user-controller for user data management with basic operations:

  • get_user_data - retrieve user information
  • set_user_data - store user information

File Handling

The template supports file handling through Telegram's API with:

  • Document upload and processing
  • Photo handling
  • Audio and video message support
  • Voice message recognition

Inline Buttons

The template uses @dieugene/callbacks for handling inline buttons:

  • Registration of callback functions
  • Parameter passing through callbacks
  • Callback lifecycle management

Database Usage

The template supports two database options:

  • @dieugene/key-object-db - for key-object storage
  • @dieugene/ydb - for Yandex Database integration

🛠️ Getting Started

  1. Clone the repository
  2. Install dependencies:
    npm install
  3. Configure environment variables
  4. Set up your database connection
  5. Start the bot:
    npm start

📦 Module Integration

Career Dialog Bot Integration

The template is compatible with @dieugene/career-dialog-bot for file handling:

  • Uses the same architectural components
  • Supports resume and portfolio management
  • Implements file processing workflows

File Processing Workflow

  1. Handle file uploads through Telegram events
  2. Store file metadata in user database
  3. Process files as needed (e.g., resume parsing)
  4. Manage file access and updates

🔐 Security Considerations

  1. Never expose API keys in the code
  2. Implement proper user authentication
  3. Validate all user inputs
  4. Use secure session management
  5. Implement rate limiting where necessary

📝 Best Practices

  1. Always use UUID for identifiers
  2. Implement proper error handling
  3. Use the built-in logging system
  4. Follow the established dialog patterns
  5. Implement proper session cleanup
  6. Use the callback system for inline buttons
  7. Maintain proper database indexing

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.