Node.js 24 أو أحدث
المثال يقرأ الغرف من API ويحتفظ بالغرف غير الخاصة. أضف cache وrate limiting في تطبيقك حسب معدل الزيارات.
JavaScript
// Node.js 24+. Run on your own server, not in a cross-origin browser script.
const response = await fetch('https://chat.egytag.com/api/rooms', {
headers: { Accept: 'application/json' },
signal: AbortSignal.timeout(8000)
});
if (!response.ok) throw new Error(`Chat Live HTTP ${response.status}`);
const data = await response.json();
if (!data.ok || !Array.isArray(data.rooms)) throw new Error('Bad response');
const rooms = data.rooms.filter(r => !r.private && !r.hidden);
console.log(rooms.map(r => ({ title: r.title, slug: r.slug, online: r.online })));Python مع requests
نفذ الأمر pip install requests أولًا. يعرض المثال الغرف المسموح بالدخول إليها وفق نتيجة خدمة الاكتشاف.
Python
# Python 3, requires: pip install requests
import requests
url = 'https://chat.egytag.com/api/discovery'
response = requests.get(url, timeout=8)
response.raise_for_status()
data = response.json()
if not data.get('ok'):
raise RuntimeError('Chat Live discovery failed')
for room in data.get('rooms', []):
if room.get('joinable') and room.get('slug'):
print(room['title'], room['slug'], room.get('online', 0))PHP باستخدام cURL
يتطلب امتداد PHP cURL. افحص حالة HTTP ولا تعرض نص API مباشرة كـHTML من دون ترميز.
PHP
<?php
// Server-side PHP (with cURL enabled).
$ch = curl_init('https://chat.egytag.com/api/rooms');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 8,
CURLOPT_HTTPHEADER => ['Accept: application/json'],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status !== 200) {
throw new RuntimeException('Chat Live API request failed');
}
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
foreach (($data['rooms'] ?? []) as $room) {
if (empty($room['private']) && empty($room['hidden'])) {
echo htmlspecialchars($room['title'], ENT_QUOTES, 'UTF-8') . "\n";
}
}كيف تنتقل من النتائج إلى الغرفة؟
استخدم slug المسترجع بعد التحقق منه، ووجّه المستخدم إلى رابط Chat Live الرسمي. لا تحاول إعادة تنفيذ تسجيل الدخول أو استخراج الكوكيز في موقع خارجي.
JavaScript
// Your backend returns the official URL; it does NOT proxy user messages.
function officialRoomLink(slug, lang = 'ar') {
if (!/^[a-z0-9-]{1,80}$/.test(slug)) throw Error('Invalid slug');
return `https://chat.egytag.com/${lang === 'en' ? 'en' : 'ar'}/room/${slug}`;
}