Skip to content

Add file attachement feature#60

Merged
warengonzaga merged 48 commits intodevfrom
new/file-attachement
Jul 23, 2025
Merged

Add file attachement feature#60
warengonzaga merged 48 commits intodevfrom
new/file-attachement

Conversation

@warengonzaga
Copy link
Member

@warengonzaga warengonzaga commented Jul 16, 2025

Tasks

  • Send files from Telegram to Unthread
  • Send files from Unthread to Telegram (blocked)

Summary by CodeRabbit

  • New Features

    • Introduced a modular, SOLID-based command system with centralized registration, validation, and error handling for all bot commands.
    • Added new user commands: /profile, /cancel, /reset, /setemail, /viewemail.
    • Added new admin commands: /activate, /setup, /templates for advanced bot and group management.
    • Implemented profile management and email preference features, including dummy email support and onboarding flows.
    • Added support for file attachments in support tickets and agent replies, with robust stream-based processing and validation.
    • Introduced a global template system for customizable ticket and agent notification messages.
    • Enhanced environment configuration, requiring explicit admin user IDs and improved variable validation.
    • Added session cleanup background tasks for resource management.
  • Bug Fixes

    • Improved Markdown escaping and message content extraction to prevent formatting errors and enhance reliability.
    • Refined user and group configuration flows to prevent misconfiguration and ensure proper setup enforcement.
  • Documentation

    • Updated README and contributing guidelines with detailed setup, command usage, troubleshooting, and integration requirements.
    • Expanded environment variable documentation and added clarifications for configuration.
  • Chores

    • Added VSCode build tasks and updated .gitignore for new directories.
    • Enhanced logging, error classification, and permission auditing for improved maintainability and debugging.
  • Style

    • Refactored codebase for clarity, maintainability, and adherence to Clean Code and SOLID principles.

Copilot AI review requested due to automatic review settings July 16, 2025 16:19
@warengonzaga warengonzaga changed the base branch from main to dev July 16, 2025 16:20
@warengonzaga warengonzaga self-assigned this Jul 16, 2025
@warengonzaga warengonzaga marked this pull request as draft July 16, 2025 16:20
@warengonzaga
Copy link
Member Author

Issue:

  • Stream-based file processing does not show the uploaded file from the dashboard.

@warengonzaga warengonzaga linked an issue Jul 16, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements a comprehensive file attachment feature for the Telegram bot, enabling bidirectional file transfer between Telegram and Unthread platforms. However, the PR contains numerous utility files that appear unrelated to the core attachment functionality.

Key Changes

  • Added stream-based file attachment handling with memory optimization
  • Implemented utility modules for validation, permissions, and template management
  • Added type definitions for profile updates and attachment processing

Reviewed Changes

Copilot reviewed 47 out of 50 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/utils/attachmentHandler.ts Core file attachment handler with stream-based processing and memory optimization
src/utils/timeoutManager.ts Centralized timeout management for preventing memory leaks
src/utils/smartValidators.ts Advanced input validation with educational feedback
src/utils/simpleValidators.ts Basic input validation for professional users
src/utils/sessionTasks.ts Background session management and cleanup tasks
src/utils/retryUtils.ts Retry mechanisms with exponential backoff
src/utils/permissions.ts Permission validation and access control
src/utils/messageContentExtractor.ts Unified message content extraction utilities
src/utils/markdownEscape.ts Markdown text escaping for Telegram safety
src/utils/globalTemplateManager.ts Global template management system
src/utils/emailManager.ts Email management with validation
src/utils/botPermissions.ts Bot permission checking in groups
src/utils/adminManager.ts Admin profile and session management
src/types/index.ts Added profile update state type definitions
src/services/validationService.ts Setup validation service
Comments suppressed due to low confidence (1)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Caution

Review failed

Failed to post review comments.

📝 Walkthrough

Walkthrough

Sir, the codebase has undergone a comprehensive architectural transformation. A modular, SOLID-compliant command system has been introduced, featuring centralized registries, robust validation, error handling, and admin/session management. The update expands support for file attachments, globalizes template management, enhances environment validation, and introduces a suite of new utilities for permissions, email, validation, and memory-safe operations. Documentation and configuration files have been meticulously revised for clarity and operational precision.

Changes

Files / Groups Change Summary
.env.example, .env.railway, README.md, CONTRIBUTING.md Expanded environment variable documentation, added new variables (e.g., ADMIN_USERS, MY_COMPANY_NAME, BOT_USERNAME), clarified Redis requirements, updated quick start and troubleshooting, and enhanced contribution guidelines.
.github/chatmodes/WG Code Alchemist.chatmode.md, .github/chatmodes/WG Code Builder.chatmode.md, .github/chatmodes/WG Code Planner.chatmode.md, .github/chatmodes/WG Code Sentinel.chatmode.md Added new chat mode persona configuration files defining expert roles, communication styles, mission statements, and toolsets for specialized code, planning, and security reviews.
.gitignore Added context/ directory to ignored files.
.vscode/tasks.json Introduced a VSCode build task for the bot using yarn build and TypeScript problem matcher.
package.json Updated version to 1.0.0-rc1, revised description and keywords, reformatted fields, and updated dependencies (@wgtechlabs/log-engine, form-data, uuid, zod, node-fetch).
src/commands/base/BaseCommand.ts, src/commands/base/CommandRegistry.ts Introduced abstract base command class, command metadata, registry pattern for commands/processors, layered validation, authorization, and help generation.
src/commands/admin/AdminCommands.ts, src/commands/basic/InfoCommands.ts, src/commands/basic/SetEmailCommand.ts, src/commands/basic/StateCommands.ts, src/commands/basic/ViewEmailCommand.ts, src/commands/support/SupportCommandClean.ts Added modular command classes for admin, info, email, state, and support ticket flows with robust error handling, context validation, and interactive messaging.
src/commands/processors/ConversationProcessors.ts Implemented conversation processors for support ticket and DM setup flows using Chain of Responsibility, with validation, session management, and user feedback.
src/commands/utils/errorHandler.ts, src/commands/utils/uuidValidator.ts, src/commands/utils/validation.ts, src/commands/utils/markdownEscape.ts, src/commands/utils/simpleValidators.ts, src/commands/utils/smartValidators.ts, src/commands/utils/retryUtils.ts Added utility modules for structured error handling, UUID and input validation, Markdown escaping, simple and smart validators, and robust retry mechanisms.
src/commands/utils/globalTemplateManager.ts, src/config/globalTemplates.ts Introduced a singleton global template manager and simplified global template configuration for ticket events, with validation and rendering logic.
src/commands/index.ts Refactored to a modular, registry-driven command system; removed legacy inline handlers; centralized registration and execution.
src/config/env.ts Enhanced environment validation, added parsing for new variables, placeholder detection, and improved error reporting.
src/database/schema.sql Updated top comment, removed "Alpha Phase (Simplified)" suffix; no schema changes.
src/events/message.ts Added robust attachment detection and processing, improved command/caption handling, generalized conversation processing, and enhanced logging.
src/handlers/webhookMessage.ts Integrated global template system for agent/status messages, improved logging, and unified ticket lookup logic.
src/index.ts Adopted clean command architecture, enhanced logging, extended message handlers to more content types, and introduced session cleanup lifecycle management.
src/sdk/bots-brain/BotsStore.ts, src/sdk/types.ts Expanded persistent store with group config, admin profiles, setup/session management, and runtime validation schemas; updated user email handling.
src/services/unthread.ts Added multipart/form-data support for attachments, improved customer/user creation logic, enforced group setup, and refined error handling and display name logic.
src/services/validationService.ts Introduced a setup validation service for group chats, with detailed result reporting and user-friendly messaging.
src/types/index.ts Added PROFILE_EMAIL_UPDATE to SupportField enum and introduced ProfileUpdateState interface for email update workflows.
src/utils/adminManager.ts Added utilities for admin profile/session management, setup session lifecycle, and notification system for admin actions, with robust error handling and logging.
src/utils/attachmentHandler.ts Implemented a stream-based attachment handler for Telegram files with memory optimization, validation, direct Unthread upload, and detailed error/performance tracking.
src/utils/botPermissions.ts Added utilities for checking bot admin permissions, user interaction flows for missing permissions, and permission summary reporting.
src/utils/emailManager.ts Centralized email validation, dummy email generation, user email preference management, and pending agent message delivery logic.
src/utils/messageContentExtractor.ts Standardized message text and command extraction from Telegram messages, supporting captions and multiple message types.
src/utils/permissions.ts Provided admin permission validation, access control wrappers, and permission event logging.
src/utils/sessionTasks.ts Added periodic background task management for setup session cleanup and lifecycle logging.
src/utils/timeoutManager.ts Introduced a centralized timeout manager for memory-safe, tracked timeouts with cleanup routines and shutdown hooks.

Suggested labels

tweak

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai auto title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@warengonzaga
Copy link
Member Author

Update:

  • Dashboard/Unthread to Telegram file attachment is currently disabled due to API issues.

@warengonzaga warengonzaga marked this pull request as ready for review July 21, 2025 17:53
@warengonzaga warengonzaga merged commit a736322 into dev Jul 23, 2025
3 checks passed
@warengonzaga warengonzaga deleted the new/file-attachement branch July 23, 2025 16:01
@warengonzaga
Copy link
Member Author

Continuing the blocked feature here: #61

@coderabbitai coderabbitai bot mentioned this pull request Jul 23, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set up ESLint security plugin for code security Set up ESLint for code quality File attachment support for Telegram

2 participants