Code Studio & Web IDE
Edit multi-file codebases in real-time with syntax highlighting, automatic linting, and zero deployment latency.
The In-Browser Cloud IDE
Botlify includes a full-featured web code editor located in Bot Studio → Code Editor. You can view, create, edit, and organize multiple files right from your browser or mobile device.
Key Studio Features
- Multi-File Project Support: Create modular projects with helper files (e.g.
includes/database.php,handlers/callback.php). - Real-Time Syntax Validation: Before saving, Botlify runs strict PHP syntax checks. If a parse or syntax error is found, it warns you immediately to prevent breaking live production webhooks.
- Zero-Restart Hot Reloading: Changes saved to
index.phpare active immediately on the next incoming Telegram update. No server restarts or redeployment delays required!
Standard Starter Template Structure
index.php (Minimal Clean Template)
<?php
declare(strict_types=1);
// 1. Load Botlify Environment Variables
$envFile = __DIR__ . '/.env';
$ENV = [];
if (is_file($envFile)) {
foreach (file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
$line = trim($line);
if ($line === '' || $line[0] === '#' || !str_contains($line, '=')) continue;
[$k, $v] = explode('=', $line, 2);
$ENV[trim($k)] = trim(trim($v), "'\"");
}
}
define('BOT_TOKEN', $ENV['BOT_TOKEN'] ?? '');
define('ADMIN_CHAT_ID', $ENV['ADMIN_CHAT_ID'] ?? '');
// 2. Fast Telegram API Dispatcher
function bot(string $method, array $params = []): array {
$ch = curl_init('https://api.telegram.org/bot' . BOT_TOKEN . '/' . $method);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($params),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_TIMEOUT => 15
]);
$res = curl_exec($ch);
return json_decode((string)$res, true) ?: ['ok' => false];
}
// 3. Receive & Process Incoming Update
$update = json_decode((string)file_get_contents('php://input'), true);
if (!$update) exit('ok');
$msg = $update['message'] ?? null;
if ($msg && !empty($msg['text'])) {
$chatId = $msg['chat']['id'];
$text = trim($msg['text']);
if ($text === '/start') {
bot('sendMessage', [
'chat_id' => $chatId,
'text' => "👋 Hello! Your Botlify Cloud bot is live and responsive.",
'parse_mode' => 'HTML'
]);
}
}
exit('ok');
Platform Auto-Injected System Environment Variables (.env)
When you deploy or manage a bot on Botlify Cloud, the platform automatically provisions an isolated .env file in your bot's root directory. You never need to hardcode sensitive tokens or IDs directly into your PHP scripts.
The 3 Locked Core System Variables
Botlify Cloud automatically synchronizes and locks these three variables with the platform database:
Botlify Cloud automatically synchronizes and locks these three variables with the platform database:
BOT_TOKEN— The unique Telegram Bot API token issued by @BotFather.ADMIN_CHAT_ID— The numeric Telegram Chat ID of the bot administrator/owner used for/adminaccess.BOT_USERNAME— The public Telegram username of the bot (without the@prefix).
| Variable Name | Sample Value | Platform Behavior & Usage in PHP |
|---|---|---|
BOT_TOKEN |
7123456789:AAHq_EXAMPLE_TOKEN... |
Auto-injected from your BotFather token. Used by bot() helper to dispatch Telegram API requests. |
ADMIN_CHAT_ID |
123456789 |
Auto-injected from your Telegram numeric User ID. Checked on incoming updates to grant /admin and broadcast access. |
BOT_USERNAME |
MySuperBot |
Auto-injected from Telegram. Used for dynamic referral links (e.g. https://t.me/MySuperBot?start=ref123). |
How to Read System Variables in index.php
Use this native, zero-dependency parser at the top of your index.php:
PHP — Native .env System Variables Loader
<?php
declare(strict_types=1);
// 1. Auto-Load System Credentials from .env
$envFile = __DIR__ . '/.env';
$ENV = [];
if (is_file($envFile)) {
foreach (file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
$line = trim($line);
if ($line !== '' && $line[0] !== '#' && str_contains($line, '=')) {
[$k, $v] = explode('=', $line, 2);
$ENV[trim($k)] = trim(trim($v), "'\"");
}
}
}
// 2. Define Immutable Platform Constants
define('BOT_TOKEN', $ENV['BOT_TOKEN'] ?? (getenv('BOT_TOKEN') ?: ''));
define('ADMIN_CHAT_ID', (string)($ENV['ADMIN_CHAT_ID'] ?? (getenv('ADMIN_CHAT_ID') ?: '')));
define('BOT_USERNAME', (string)($ENV['BOT_USERNAME'] ?? (getenv('BOT_USERNAME') ?: '')));
// 3. Security Guard
if (BOT_TOKEN === '') {
exit("Error: BOT_TOKEN is missing in .env\n");
}