<?php
namespace App;


final class Utils
{
public static function apiUrl(string $path): string
{ return rtrim(Env::get('TELEGRAM_API','https://api.telegram.org'),'/').'/bot'.Env::get('TELEGRAM_BOT_TOKEN').'/'.$path; }


public static function tgRequest(string $method, array $params): array
{
$ch = curl_init(self::apiUrl($method));
curl_setopt_array($ch,[
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>$params,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_CONNECTTIMEOUT=>10,
CURLOPT_TIMEOUT=>30,
]);
$out = curl_exec($ch); if ($out===false) throw new \RuntimeException('curl error: '.curl_error($ch));
$data = json_decode($out, true);
if (!($data['ok'] ?? false)) throw new \RuntimeException('Telegram error: '.($data['description'] ?? 'unknown'));
return $data['result'] ?? [];
}
}