Initialization
The Bot Studio server is the core component that makes the platform functional. It renders page content using different rendering engines, connects to databases, handles bots, and more. This documentation category, titled "Server", explains how the server operates.
Server Initialization Process
When the server starts, it loads all environment variables. These may include the running mode (either production or development), secret keys, and codes used in Bot Studio, among other settings. The server then executes the following initialization processes:
1. Setting Custom Variables (Development)
In this step, if certain variables are not provided, they are automatically set to default values. This ensures that the development environment is configured correctly without manual intervention.
2. Checking Python Version
This step verifies the installed Python version. If Python is not installed, the server returns a warning message, prompting our engineers to install Python.
3. Fetching Disposable Email Addresses List
This step fetches a list of disposable email addresses used to detect and block temporary email addresses from accessing the website.
This step only runs in production mode. In development mode, disposable email addresses are not checked.
4. Initiating Databases
This step initializes all necessary databases, ensuring they are ready for use by the server and connected applications.
5. Removing Expired Codes
This step removes all expired codes used for actions such as resetting account passwords or verifying email addresses. This helps maintain security and system hygiene.
6. Backup (Production)
In production mode, this step sets up a backup timer to create hourly backups of the databases. A maximum of 40 backups are stored; older backups are deleted to maintain this limit. This means the maximum time deleted data is stored is 40 hours.
7. Creating HTTP Server
In this step, an HTTP server is created to handle incoming requests and connect the server to platform handlers. Several middlewares are added to the HTTP server for various functionalities:
- CORS (Cross-Origin Resource Sharing): Handles cross-origin requests.
- GZIP Compression: Compresses request sizes.
- Cookie Handling: Manages incoming cookies from websites.
- Response Timing Header: Adds a header to each response indicating the response preparation time.
- User-Agent Logging: Captures information about the request's user agent (e.g., browser version).
- Client-Side Content Serving: Serves web pages and other client-side content.
- Request Size Limit: Sets the maximum request size to 250 KB.
- Rate Limiting: Limits the maximum number of requests to 150 requests per minute.
- Request Logging: Logs incoming requests.
- Router Middleware: Routes incoming requests to the appropriate handlers.
- SSR Rendering Engine: Changes the default SSR rendering engine to EJS.
After configuring these settings, the server listens on port 3000. In production mode, requests are redirected to this port using Cloudflare. Additionally, a WebSocket server is set up on the existing HTTP server for connecting platform handlers.
8. Running Specified Handlers (Development)
In development mode, only one specified platform handler is run for debugging purposes. In production mode, all handlers run simultaneously.
9. Removing Non-Active Accounts and Turning Off Non-Active Bots
This step removes all inactive accounts and accounts scheduled for removal. Activity on an account, such as changing a bot's configuration or updating bot data, is logged. Accounts with no activity in the last 365 days, that are not verified, and have no online bots, are removed.
Accounts scheduled for removal only if they were inactive for 1 day are also deleted, along with all associated bots, stored encoded passwords, sessions, etc.
Non-active bots, defined as bots with no processes for 15 days or bots that have never been executed and the account has been inactive for the last 15 days, will be turned off.
10. Removing Inactive Sessions
Inactive sessions, defined as sessions with no activity from any devices for the last 30 days, are removed from the databases to enhance security.
11. Creating Logs
Logs are created at specified intervals (e.g., every 1 minute). These logs include details about the server's resource usage, aiding in performance monitoring and debugging.
After completing these steps, the server is fully initialized. Subsequent processes depend on the loaded modules and specific server configurations.