35247-vm/includes/telegram_api.php
Flatlogic Bot e0d884de80 123
2025-10-26 18:48:58 +00:00

25 lines
681 B
PHP

<?php
function getSubscriberCount($channel_id, $token) {
// Prepend "@" if it's a public channel username without it
if (strpos($channel_id, '@') !== 0 && strpos($channel_id, '-') !== 0) {
$channel_id = '@' . $channel_id;
}
$url = "https://api.telegram.org/bot{$token}/getChatMemberCount?chat_id=" . urlencode($channel_id);
$response = @file_get_contents($url);
if ($response === FALSE) {
// Could log an error here
return null;
}
$data = json_decode($response, true);
if (isset($data['ok']) && $data['ok'] === true) {
return $data['result'];
}
// Could log $data['description']
return null;
}
?>