Skip to content

Conversation

Huxiake
Copy link

@Huxiake Huxiake commented Jul 20, 2025

Summary by CodeRabbit

  • New Features

    • Introduced multi-session support, allowing management of multiple independent WhatsApp sessions on a single server.
    • Added a web UI for viewing, creating, configuring, and managing sessions, including QR code login, proxy settings, and Chatwoot integration.
    • Provided RESTful API endpoints for session management, QR code retrieval, messaging, proxy testing, and Chatwoot operations.
    • Enabled proxy support and configuration for individual sessions.
    • Included comprehensive documentation and client usage examples.
  • Bug Fixes

    • Improved proxy protocol handling and native proxy application for browser sessions.
  • Documentation

    • Added a detailed usage guide covering setup, API endpoints, deployment, and troubleshooting.
  • Style

    • Introduced a responsive and modern CSS stylesheet for the web UI.
  • Chores

    • Added new dependencies and updated existing ones for enhanced functionality and compatibility.
  • Tests

    • Included standalone scripts and test utilities for QR code and event debugging.

- 代理修复:
  - 安装 http-proxy-agent 依赖。
  - 使用 axios 替代内置 http 模块,并添加 User-Agent,解决了 socket hang up 的问题。
- 会话删除修复:
  - 将删除逻辑从 fs.rmSync 改为 fs-extra.remove,增强了可靠性。
  - 调整了 removeSession 的操作顺序,先从内存中删除会话,再执行清理,彻底解决了因竞态条件导致的会话“复活”问题。
- 代码清理:
  - 移除了前端未使用的 SOCKS5 代理配置模态框及其相关JS代码。
- 流程改进:
  - 承诺在每次修改后运行 npm run build 进行构建验证。
Copy link

coderabbitai bot commented Jul 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a comprehensive multi-session architecture for managing multiple WhatsApp sessions within a single server instance. It adds a robust session manager, RESTful API, web management UI, extensive configuration and proxy support, Chatwoot integration, and a suite of supporting utilities, models, and documentation. The changes span backend logic, frontend assets, configuration, and developer tools.

Changes

File(s) / Path(s) Summary of Changes
MULTI_SESSION_USAGE.md Added detailed documentation for multi-session usage, API endpoints, frontend integration, deployment, and troubleshooting.
bin/multi-session.js, src/cli/multiSessionServer.ts, src/cli/multiSessionRoutes.ts Introduced new entrypoint and server logic for multi-session mode, including CLI, Express setup, and route mounting.
src/controllers/SessionManager.ts Added a SessionManager class for in-memory and persistent management of multiple WhatsApp sessions, including QR handling, proxy updates, and lifecycle methods.
src/api/MultiSessionAPI.ts Implemented a RESTful API router for session management (create, delete, restart, QR, proxy, Chatwoot, etc.).
src/config/multiSessionConfig.ts Added configuration utilities for multi-session defaults, validation, and environment variable handling.
src/config/puppeteer.config.js Introduced Puppeteer configuration for browser automation, user agent, and viewport.
src/controllers/auth.js, src/controllers/browser.js, src/controllers/events.js, src/controllers/initializer.js, src/controllers/patch_manager.js, src/controllers/launch_checks.js, src/controllers/popup/index.js, src/controllers/script_preloader.js Added new modules for authentication, browser/page setup, event emission, session initialization, patch/license management, integrity checks, popup QR UI, and script preloading.
src/api/model/*.js (multiple files) Added enums, constants, and type definitions for chat, call, message, config, errors, events, group metadata, media, and more.
src/api/Client.ts Added getIp and handleChatwootWebhook methods to the Client class.
src/cli/integrations/chatwoot.ts Refactored for multi-session Chatwoot integration; added multi-session management and status tracking.
src/structures/Collector.js, src/structures/MessageCollector.js Introduced generic and message-specific collector classes for asynchronous event-driven collection.
src/structures/preProcessors.js Added message preprocessors for media handling, decryption, and cloud upload.
src/utils/tools.js, src/utils/pid_utils.js Added utility functions for file, string, process, and user agent handling.
src/logging/logging.js, src/logging/custom_transport.js Introduced advanced logging setup with redaction, rotating files, syslog, and custom transports.
src/build/build-postman.js Added script to generate Postman collections from API methods.
src/index.js New central export module, aggregating key components and utilities.
package.json, tsconfig.json Added/updated dependencies and TypeScript configuration for new features.
demo/server.js, demo/server.ts Added demo server scripts for webhook and proxy usage examples.
debug_proxy_config.js, debug_qr.js, simple_test.js, test_qr_events.js Added standalone scripts for debugging proxy configs, QR code generation, and event monitoring.
sessions/827test/config.json Added example session configuration with proxy and session options.
web-ui/index.html, web-ui/assets/css/style.css, web-ui/assets/js/app.js Introduced a new web UI for session management, including modals, QR code display, proxy editing, Chatwoot integration, and responsive design.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebUI
    participant MultiSessionAPI
    participant SessionManager
    participant WhatsAppClient

    User->>WebUI: Open dashboard / create session
    WebUI->>MultiSessionAPI: POST /api/v1/sessions (with config)
    MultiSessionAPI->>SessionManager: createSession(sessionId, config, waitForQR)
    SessionManager->>WhatsAppClient: Initialize client session
    WhatsAppClient-->>SessionManager: Emits QR code event
    SessionManager-->>MultiSessionAPI: Returns session status + QR code
    MultiSessionAPI-->>WebUI: Session info + QR code (base64/image)
    WebUI-->>User: Display QR code for scanning

    User->>WebUI: Request session actions (restart, delete, edit proxy)
    WebUI->>MultiSessionAPI: (PATCH/DELETE/PUT) /api/v1/sessions/:id
    MultiSessionAPI->>SessionManager: Perform action (restart/remove/updateProxy)
    SessionManager->>WhatsAppClient: Apply changes
    SessionManager-->>MultiSessionAPI: Updated session status
    MultiSessionAPI-->>WebUI: Updated session info
    WebUI-->>User: Update UI
Loading
sequenceDiagram
    participant WebUI
    participant MultiSessionAPI
    participant SessionManager
    participant ChatwootIntegration

    WebUI->>MultiSessionAPI: POST /api/v1/sessions/:id/chatwoot (setup)
    MultiSessionAPI->>ChatwootIntegration: initSessionChatwoot(sessionId, config)
    ChatwootIntegration-->>MultiSessionAPI: Status (webhook verified, etc.)
    MultiSessionAPI-->>WebUI: Chatwoot setup result

    WebUI->>MultiSessionAPI: POST /api/v1/sessions/:id/chatwoot/webhook
    MultiSessionAPI->>SessionManager: getClient(sessionId)
    SessionManager->>WhatsAppClient: handleChatwootWebhook(webhookData)
    WhatsAppClient-->>SessionManager: Webhook processed
    SessionManager-->>MultiSessionAPI: Result
    MultiSessionAPI-->>WebUI: Webhook response
Loading

Poem

🐇
A warren of sessions, all hopping with glee,
Managed by code, both clever and free.
With QR codes for doors and proxies for trails,
A dashboard for humans—no more login fails!
Chatwoot now listens, the logs gently spin,
Oh what a fine warren for WhatsApp to begin!
🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm warn deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-20T16_04_50_736Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 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.

Copy link

promptless bot commented Jul 20, 2025

📝 Documentation updates detected!

New suggestion: Add comprehensive multi-session mode documentation

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.

1 participant