Files
html/api/wedroid-telegram-alert.php
2026-04-12 22:57:03 +02:00

26 lines
1.3 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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);
}