File size: 4,929 Bytes
de4493c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# HCY Audio System Clone

This project aims to replicate the functionality of the HCY Audio System Telegram Mini App. It consists of two main parts:

1.  **Frontend (React App)**: A web application that provides the audio system simulator interface, including an audio player, visualizer, and equalizer controls.
2.  **Backend (Telegram Bot)**: A Python Telegram bot that serves as the entry point for the Mini App.

## Project Structure

```
hcy_audiobot_clone/
β”œβ”€β”€ frontend/             # React web application
β”‚   β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.css
β”‚   β”‚   β”œβ”€β”€ App.js
β”‚   β”‚   β”œβ”€β”€ index.css
β”‚   β”‚   └── index.js
β”‚   β”œβ”€β”€ .gitignore
β”‚   β”œβ”€β”€ package.json
β”‚   └── README.md
β”œβ”€β”€ backend/              # Python Telegram bot
β”‚   β”œβ”€β”€ bot.py
β”‚   └── requirements.txt
└── README.md             # This file
```

## Setup and Running Instructions

### 1. Frontend (React App)

This is the web application that will be embedded as a Telegram Mini App. It provides the user interface for the audio system simulator.

**Prerequisites:**
*   Node.js (LTS version recommended)
*   npm or yarn

**Steps:**

1.  Navigate to the `frontend` directory:
    ```bash
    cd hcy_audiobot_clone/frontend
    ```

2.  Install the dependencies:
    ```bash
    npm install
    # or
    yarn install
    ```

3.  Start the development server:
    ```bash
    npm start
    # or
    yarn start
    ```
    This will usually open the app in your browser at `http://localhost:3000`.

4.  **Deployment**: For the Telegram Mini App to work, the frontend application needs to be hosted on a publicly accessible URL (e.g., Vercel, Netlify, GitHub Pages, or your own server). Once deployed, copy the URL of your deployed application. This URL will be used in the backend bot configuration.

### 2. Backend (Telegram Bot)

This is the Python bot that interacts with the Telegram API and launches the Mini App.

**Prerequisites:**
*   Python 3.8+
*   A Telegram Bot Token (obtainable from BotFather on Telegram)

**Steps:**

1.  Navigate to the `backend` directory:
    ```bash
    cd hcy_audiobot_clone/backend
    ```

2.  Create a virtual environment (recommended):
    ```bash
    python3 -m venv venv
    source venv/bin/activate
    ```

3.  Install the dependencies:
    ```bash
    pip install -r requirements.txt
    ```

4.  **Configure Environment Variables**: You need to set two environment variables:
    *   `TELEGRAM_BOT_TOKEN`: Your bot token obtained from BotFather.
    *   `WEB_APP_URL`: The public URL where your frontend React app is hosted (from step 4 of Frontend deployment).

    You can set these in your terminal before running the bot:
    ```bash
    export TELEGRAM_BOT_TOKEN="YOUR_BOT_TOKEN_HERE"
    export WEB_APP_URL="https://your-deployed-frontend-url.com"
    ```
    Replace `YOUR_BOT_TOKEN_HERE` and `https://your-deployed-frontend-url.com` with your actual values.

5.  Run the bot:
    ```bash
    python bot.py
    ```

### 3. How to use the Telegram Mini App

1.  Start your Telegram bot by sending the `/start` command.
2.  The bot will send you a message with an "Open HCY Audio System" button.
3.  Click the button to launch the Mini App directly within Telegram.

## Code Explanation

### Frontend (`frontend/src/App.js`)

*   **`AudioContext` and Nodes**: Initializes the Web Audio API for audio processing. It sets up an `AnalyserNode` for visualization, `GainNode` for volume control, and `BiquadFilterNode`s for bass and treble adjustments.
*   **Audio Playback**: A dummy MP3 file from `soundhelix.com` is used for demonstration. In a real application, you would allow users to upload or select their own audio files.
*   **Visualizer**: Uses an HTML5 `<canvas>` element to draw a frequency bar graph based on the audio data from the `AnalyserNode`.
*   **Controls**: Sliders for volume, bass, and treble allow real-time adjustment of the audio output.
*   **Telegram Mini App Integration**: Includes a basic `useEffect` hook to initialize `window.Telegram.WebApp`, which is essential for the web app to function within Telegram.

### Backend (`backend/bot.py`)

*   **`python-telegram-bot` library**: Used to interact with the Telegram Bot API.
*   **`/start` command handler**: When a user sends `/start`, the bot replies with an `InlineKeyboardButton` that contains a `WebAppInfo` object. This object specifies the `WEB_APP_URL` which points to your deployed React application.
*   **Environment Variables**: The bot token and web app URL are loaded from environment variables for security and flexibility.

This setup provides a functional clone of the HCY Audio System, allowing users to interact with an audio simulator directly within Telegram. You can further enhance the frontend with more advanced audio features, UI/UX improvements, and integrate with actual audio file uploads.