26 lines
1.3 KiB
PHP
26 lines
1.3 KiB
PHP
<?php
|
||
/**
|
||
* WEDROID Telegram Alert v1.0
|
||
* Sends alerts to Yanis via Telegram bot
|
||
*/
|
||
function telegramAlert($message, $level = 'info') {
|
||
// Get bot token from DB or config
|
||
$pdo = new PDO("pgsql:host=127.0.0.1;dbname=adx_system","postgres","");
|
||
$r = $pdo->query("SELECT config_value FROM admin.wevia_config WHERE config_key='telegram_bot_token' LIMIT 1")->fetch(PDO::FETCH_ASSOC);
|
||
$token = $r['value'] ?? '';
|
||
$r2 = $pdo->query("SELECT config_value FROM admin.wevia_config WHERE config_key='telegram_chat_id' LIMIT 1")->fetch(PDO::FETCH_ASSOC);
|
||
$chatId = $r2['value'] ?? '';
|
||
|
||
if (!$token || !$chatId) return ['ok'=>false, 'error'=>'Telegram not configured. Set telegram_bot_token + telegram_chat_id in admin.wevia_config'];
|
||
|
||
$icons = ['info'=>'ℹ️','warning'=>'⚠️','error'=>'🔴','success'=>'✅','critical'=>'🚨'];
|
||
$icon = $icons[$level] ?? '📌';
|
||
$text = "$icon *WEDROID $level*\n$message\n_" . date('H:i:s') . "_";
|
||
|
||
$ch = curl_init("https://api.telegram.org/bot$token/sendMessage");
|
||
curl_setopt_array($ch, [CURLOPT_POST=>true, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5,
|
||
CURLOPT_POSTFIELDS=>['chat_id'=>$chatId, 'text'=>$text, 'parse_mode'=>'Markdown']]);
|
||
$r = curl_exec($ch); curl_close($ch);
|
||
return json_decode($r, true);
|
||
}
|