# SPG Support Suite Pro — cPanel / subdomain deployment

This package includes both Termux long-polling and cPanel WSGI webhook modes. **Do not run both modes with the same bot token at the same time.** Stop the Termux bot before registering the webhook.

## Before you start

Your Game Lite plan must actually provide **Setup Python App / Python Selector or a WSGI-compatible Passenger application**, a supported Python version (prefer 3.11+), outbound HTTPS access, virtualenv/pip access, a persistent application process, and an HTTPS subdomain. Generic cPanel can support WSGI/Python, but a particular hosting plan may disable it. If the feature is missing, ask the provider; uploading `.py` files to `public_html` alone does not run a Telegram bot.

## 1. Create the application

1. Create a subdomain, for example `support.example.com`, and enable SSL/HTTPS.
2. In cPanel, open **Setup Python App** (or the host's equivalent) and create a Python application.
3. Use an application root outside the public web directory if possible, e.g. `spg_support_app`.
4. Set the application URL to the subdomain root.
5. Upload the contents of this package folder into that application root. `passenger_wsgi.py`, `webhook_wsgi.py`, `spg_support_bot.py`, `config.py`, the banner, and `requirements.txt` should be beside each other.
6. Set the startup file to `passenger_wsgi.py` and the entry point/callable to `application`.
7. Use one WSGI/Passenger application process while using SQLite. Do not expose the SQLite database, config file, logs, backups, or app root as public static files.

## 2. Install dependencies

Use the exact virtual-environment activation command shown in cPanel's Python App page, then run from the app root:

```bash
python -m pip install -r requirements.txt
```

Do not upgrade the hosting system's pip package globally. Install dependencies only in the application's virtual environment.

## 3. Configure the bot

Edit `config.py`. You only need to edit these three values:

- `BOT_TOKEN`: your new token from `@BotFather`.
- `OWNER_IDS`: your numeric Telegram ID, as a list, for example `[123456789]`.
- `HEAD_MANAGER_IDS`: your head manager's numeric ID, as a list, for example `[987654321]`. Use `[]` if no head manager is configured yet.

Do not edit a webhook secret or webhook URL in `config.py`. The secret is generated and stored privately in `.spg_webhook_secret`. The actual subdomain URL is passed one time to the setup command below. Keep `config.py`, `.spg_webhook_secret`, the database, and logs private.

## 4. Run the one-time installer and register the webhook

Stop the Termux bot first; polling and webhook mode cannot operate together with the same token. In cPanel Terminal, activate the virtual environment shown by the Python App page, move to the application root, and run this command. Replace the sample host with your actual HTTPS subdomain:

```bash
bash setup_cpanel.sh https://support.example.com/webhook
```

This installs dependencies in the activated app virtualenv, runs the offline self-check, generates the private webhook secret automatically, and registers the Telegram webhook. It prints the webhook URL, pending update count, and Telegram's last webhook error (if any).

## 5. Restart and test

After the setup command finishes, use the **Restart** button for this Python app in cPanel. Then visit:

`https://support.example.com/health`

Expected response: `{"ok":true,"mode":"webhook"}`. If you get 503, check the Passenger log, verify the three config values, and confirm the application root is writable so the secret/database can be created. Then test `/start` from Telegram.

If moving back to Termux polling, stop the cPanel app and run the following from the same virtualenv/app root:

```bash
python remove_webhook.py
```

Then start `python spg_support_bot.py` in Termux. Do not run both modes at once.

## Important platform limits

- Telegram's pending updates are not guaranteed to be retained for more than 24 hours. This app stores each webhook update in SQLite before replying HTTP 200, then processes it from the durable inbox; after processing, ticket/outbox data persists locally.
- cPanel shared hosting can sleep/restart processes, cap CPU/RAM, restrict outgoing requests or Python apps, and limit concurrency. Confirm those permissions with Game Lite support.
- This SQLite + single WSGI worker deployment is an initial/low-to-moderate traffic deployment, **not** a promise to support millions of users. At that scale, use a VPS/managed service, PostgreSQL, a durable queue such as Redis Streams/RabbitMQ, multiple monitored worker processes, external object storage for large media, rate limits, and off-site backups.
- Never run the Termux polling process and cPanel webhook against the same bot token simultaneously.
