telegram final gas code ✅ telegram autopilot message

// ========================================== // 🌟 ULTIMATE MASTER CODE: RSS+AI HYBRID ENGINE v3.0 (FINAL) 🌟 // (Question-Style Hooks, Zero Hallucination, No Fantasy Tips) // ========================================== // 1. MASTER CONFIGURATION const CONFIG = { BOT_TOKEN: "7965440217:AAH1EdJWEbSsvepELbp3C-D-hVSAQGtXSJ0", GROQ_API_KEY: "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", CRICKET_CHAT_ID: "-1002145760397", NEET_CHAT_ID: "-1003384842247", CRICKET_USERNAME: "@CricketNewsFresh", NEET_USERNAME: "@NEETAspirantsNotes", NEWS_RSS: "https://timesofindia.indiatimes.com/rssfeeds/9131688.cms", JOBS_RSS: "https://www.employmentnews.gov.in/NewEmp/RSS.aspx", CRICKET_RSS: "http://static.cricinfo.com/rss/livescores.xml" }; // 🔥 The Master Formatting & Hook Rule const FORMAT_RULE = "LANGUAGE RULE: Write explanations in Hindi (Hinglish). Always use words like 'ham', 'hame', 'hamari' instead of 'main' or 'mujhe'. \nFORMATTING RULE: Structure the post point-wise. Use ** for bolding (e.g. **Heading**). STRICTLY DO NOT use any HTML tags like or
. Use emojis and double line breaks."; // ========================================== // 2. UTILITY & RSS FUNCTIONS // ========================================== function getNeetCountdown() { var today = new Date(); var examDate = new Date("May 2, 2027"); var timeDiff = examDate.getTime() - today.getTime(); var daysLeft = Math.ceil(timeDiff / (1000 * 3600 * 24)); return "\n\n⏳ **Target NEET 2027:** Approx " + daysLeft + " Days Left! Keep hustling! 🔥"; } function isDuplicateURL(url) { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Posted_URLs"); if (!sheet) return false; var data = sheet.getDataRange().getValues(); for (var i = 1; i < data.length; i++) { if (data[i][2] === url) return true; } return false; } function logPostedURL(title, url) { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Posted_URLs"); if (sheet) sheet.appendRow([new Date(), title, url]); } function getLatestRSS(feedUrl) { try { var response = UrlFetchApp.fetch(feedUrl, {muteHttpExceptions: true}); var xml = response.getContentText(); var document = XmlService.parse(xml); var items = document.getRootElement().getChild('channel').getChildren('item'); for (var i = 0; i < items.length; i++) { var title = items[i].getChildText('title') || ""; var link = items[i].getChildText('link') || ""; var description = items[i].getChildText('description') || ""; if (!isDuplicateURL(link)) { logPostedURL(title, link); return { title: title, link: link, description: description }; } } } catch(e) { Logger.log("RSS Error: " + e.message); } return null; } // ========================================== // 3. GROQ API & BULLETPROOF FORMATTER // ========================================== function callGroq(promptText) { const url = "https://api.groq.com/openai/v1/chat/completions"; const payload = { "model": "llama-3.3-70b-versatile", "messages": [{ "role": "user", "content": promptText }], "temperature": 0.2 }; const options = { "method": "post", "contentType": "application/json", "headers": { "Authorization": "Bearer " + CONFIG.GROQ_API_KEY }, "payload": JSON.stringify(payload), "muteHttpExceptions": true }; const response = UrlFetchApp.fetch(url, options); const json = JSON.parse(response.getContentText()); if (json.choices && json.choices.length > 0) return json.choices[0].message.content; else throw new Error("Groq API Error"); } function processAIText(rawText) { var text = rawText.replace(/```html/g, "").replace(/```/g, ""); text = text.replace(//g, ""); text = text.replace(/\*\*(.*?)\*\*/g, "$1"); return text.trim(); } // ========================================== // 4. SMART AI CONTENT GENERATOR (The "Re-Command" Template Setup) // ========================================== function generateAutoContent(timeSlot, isSunday, isLastSunday) { var sheet = SpreadsheetApp.getActiveSpreadsheet(); // ---------------------------------------------------- // 🏏 CRICKET LOGIC (Beautiful Template + 100% Real Facts) // ---------------------------------------------------- var cricketSheet = sheet.getSheetByName("Cricket_Posts"); var liveMatchData = getLatestRSS(CONFIG.CRICKET_RSS); var cricketPrompt = ""; if (liveMatchData) { cricketPrompt = `You are a professional Cricket Admin for Telegram. RAW DATA: Title: "${liveMatchData.title}", Details: "${liveMatchData.description}". STEP 1: Analyze the raw data internally (do not print this step). STEP 2: Generate the post using EXACTLY this beautiful template structure below. DO NOT invent Pitch, Toss, or Playing XI (as it's not in raw data). DO NOT give fantasy tips. Use 'ham', 'hame', 'hamari' in Hinglish. TEMPLATE FORMAT TO FOLLOW STRICTLY: 🏏 **[Match Teams Name] - [Live Score Update OR Match Result]!** 🏆 🔥 **[Team 1 vs Team 2]** 🔥 📊 **SCORECARD:** [Provide the exact real scores beautifully formatted] 🏏 **MATCH INSIGHT:** [Write a detailed 3-4 line paragraph in Hinglish explaining the current tension, situation, or final result based ONLY on the raw data. Make it sound professional and engaging.] Toh dosto, aapke hisaab se [Ask a relevant engaging question based on the match]? Niche ⬇️ reaction ya comment mein batayein! 🔗 Apne doston ko invite karein: ${CONFIG.CRICKET_USERNAME} ${FORMAT_RULE}`; } else { cricketPrompt = `You are a professional Cricket Admin. Today there is no live match. STEP 1: Think of an amazing Cricket Record or Trivia. STEP 2: Write a detailed post using this EXACT template: 🏏 **Cricket Trivia of the Day!** 🏆 🔥 **[Topic/Player Name]** 🔥 📖 **DID YOU KNOW?** [Explain the record/trivia in a detailed, engaging 3-4 line Hinglish paragraph using ham/hame/hamari] Toh dosto, kya aapko yeh record pata tha? Niche ⬇️ reaction mein batayein! 🔗 Apne doston ko invite karein: ${CONFIG.CRICKET_USERNAME} ${FORMAT_RULE}`; } try { var cleanCricketText = processAIText(callGroq(cricketPrompt)); var cricketKeyboard = {"inline_keyboard": [[{"text": "🚀 Share Update", "url": "https://t.me/share/url?url=https://t.me/CricketNewsFresh&text=Latest%20Cricket%20Update!"}]]}; cricketSheet.appendRow([new Date(), cleanCricketText, "Pending", JSON.stringify(cricketKeyboard)]); } catch (e) { Logger.log(e); } // ---------------------------------------------------- // 🩺 NEET & EDUCATION LOGIC (Beautiful Template) // ---------------------------------------------------- var neetSheet = sheet.getSheetByName("NEET_Posts"); var neetPrompt = ""; var neetKeyboard = {"inline_keyboard": [[{"text": "🚀 Share with Friends", "url": "https://t.me/share/url?url=https://t.me/NEETAspirantsNotes"}]]}; if (isLastSunday && timeSlot === "Morning") { neetPrompt = `Write a beautifully formatted announcement post. TEMPLATE: 📣 **ATTENTION FUTURE DOCTORS!** 🩺 [Write a detailed encouraging 3-line paragraph that 'Aaj shaam 5 baje se 7 baje tak hamari group chat open rahegi. Apne doubts taiyar rakhein!'] 🔗 Join for daily notes: ${CONFIG.NEET_USERNAME}\n\n${FORMAT_RULE}`; } else if (isSunday) { neetPrompt = `Write a beautifully formatted Sunday Motivation post. TEMPLATE: 🌟 **SUNDAY RECAP & MOTIVATION** 🌟 [Write a detailed, uplifting 4-line paragraph about taking a break and planning for the next week using ham/hame/hamari] 🔗 Join for daily notes: ${CONFIG.NEET_USERNAME}\n\n${FORMAT_RULE}`; } else { if (timeSlot === "Morning") { var newsItem = getLatestRSS(CONFIG.NEWS_RSS); var newsText = newsItem ? "Real Education News: " + newsItem.title : "General Biology Fact."; neetPrompt = `You are a NEET Mentor. STEP 1: Analyze this fact/news: "${newsText}". STEP 2: Write a detailed post using this EXACT template: 🌅 **Good Morning Future Doctors!** 🩺 ✨ **DAILY MOTIVATION:** [Provide a strong quote and explain its meaning in 2 lines] 📰 **AAJ KI UPDATE:** [Explain the news/fact detailed in Hinglish. Do not invent fake data.] 🧠 **WORD OF THE DAY:** **[Word]** - [Meaning in Hinglish] Hamari taiyari kaisi chal rahi hai? Niche ⬇️ reaction mein batayein! 🔗 Join for daily notes: ${CONFIG.NEET_USERNAME} ${FORMAT_RULE}`; if (newsItem) neetKeyboard = {"inline_keyboard": [[{"text": "📰 Read Full News", "url": newsItem.link}]]}; } else if (timeSlot === "Afternoon") { var jobItem = getLatestRSS(CONFIG.JOBS_RSS); if (jobItem) { neetPrompt = `Write a beautifully formatted Job Alert. TEMPLATE: 💼 **NEW OPPORTUNITY ALERT!** 🚀 📌 **[For Students / Job Seekers]** 📝 **Details:** [Format "${jobItem.title}" clearly without inventing eligibility] 🔗 Apply here: ${jobItem.link} 🔗 Join for updates: ${CONFIG.NEET_USERNAME}\n\n${FORMAT_RULE}`; neetKeyboard = {"inline_keyboard": [[{"text": "✅ Apply Now", "url": jobItem.link}]]}; } else { neetPrompt = `Write a beautifully formatted Career Tip. TEMPLATE: 💼 **CAREER GUIDE TIPS** 🚀 📌 **[For UG/PG Students]** [Write a detailed 4-point guide on building a good resume or interview prep using ham/hame] 🔗 Join for updates: ${CONFIG.NEET_USERNAME}\n\n${FORMAT_RULE}`; } } else if (timeSlot === "Evening") { neetPrompt = `Write a beautifully formatted Study Hack. TEMPLATE: 📚 **EXAM MASTERY TIPS** 🎯 [Write 3 detailed, highly actionable time management or study hacks using ham/hame] 🔗 Join for notes: ${CONFIG.NEET_USERNAME}\n\n${FORMAT_RULE}`; } else if (timeSlot === "Night") { neetPrompt = `Write a beautifully formatted MCQ Quiz. TEMPLATE: 🧠 **DAILY TEST YOUR KNOWLEDGE!** 🩺 **Question:** [Challenging Biology Question] A) [Option] B) [Option] C) [Option] D) [Option] **Correct answer:** [Correct Option] **Explanation:** [Detailed explanation in Hinglish using ham/hame/hamari] Copyright ${CONFIG.NEET_USERNAME}\n\n${FORMAT_RULE}`; neetKeyboard = { "inline_keyboard": [ [{"text": "A", "callback_data": "wrong_A"}, {"text": "B", "callback_data": "wrong_B"}], [{"text": "C (Correct)", "callback_data": "correct_C"}, {"text": "D", "callback_data": "wrong_D"}] ] }; } } try { var rawText = processAIText(callGroq(neetPrompt)); var countdownStr = getNeetCountdown().replace(/\*\*(.*?)\*\*/g, "$1"); var cleanNeetText = rawText + countdownStr; neetSheet.appendRow([new Date(), cleanNeetText, "Pending", JSON.stringify(neetKeyboard)]); } catch (error) { Logger.log(error); } } // ========================================== // 5. TELEGRAM AUTO-POSTER & CLEANUP // ========================================== function autoPostToTelegram() { var sheet = SpreadsheetApp.getActiveSpreadsheet(); var lock = LockService.getScriptLock(); if (!lock.tryLock(10000)) return; function processSheet(sheetName, chatId) { var dataSheet = sheet.getSheetByName(sheetName); if (!dataSheet) return; var lastRow = dataSheet.getLastRow(); if (lastRow < 2) return; var data = dataSheet.getRange(2, 1, lastRow - 1, 4).getValues(); for (var i = 0; i < data.length; i++) { if (data[i][1] !== "" && (data[i][2] === "" || data[i][2] === "Pending")) { var replyMarkup = data[i][3] ? JSON.parse(data[i][3]) : null; var result = sendMessage(CONFIG.BOT_TOKEN, chatId, data[i][1], replyMarkup); dataSheet.getRange(i + 2, 3).setValue(result === "Success" ? "Sent" : "Failed: " + result); break; } } } try { processSheet("Cricket_Posts", CONFIG.CRICKET_CHAT_ID); processSheet("NEET_Posts", CONFIG.NEET_CHAT_ID); } finally { lock.releaseLock(); } } function sendMessage(botToken, chatId, text, replyMarkup) { var payload = { "chat_id": chatId, "text": text, "parse_mode": "HTML" }; if (replyMarkup) payload["reply_markup"] = replyMarkup; var options = { "method": "post", "contentType": "application/json", "payload": JSON.stringify(payload), "muteHttpExceptions": true }; try { var json = JSON.parse(UrlFetchApp.fetch("https://api.telegram.org/bot" + botToken + "/sendMessage", options).getContentText()); return json.ok ? "Success" : json.description; } catch(e) { return e.message; } } function cleanupOldPosts() { var sheet = SpreadsheetApp.getActiveSpreadsheet(); var sheetsToClean = ["Cricket_Posts", "NEET_Posts"]; var sevenDaysAgo = new Date(); sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7); for (var s = 0; s < sheetsToClean.length; s++) { var dataSheet = sheet.getSheetByName(sheetsToClean[s]); if (!dataSheet) continue; var data = dataSheet.getRange(2, 1, dataSheet.getLastRow() - 1, 3).getValues(); for (var i = data.length - 1; i >= 0; i--) { var postDate = new Date(data[i][0]); if (data[i][2] === "Sent" && !isNaN(postDate.getTime()) && postDate < sevenDaysAgo) { dataSheet.deleteRow(i + 2); } } } } // ========================================== // ⭐ 6. MASTER TRIGGER (Run this via Time-Driven Trigger) // ========================================== function runMasterAutoPilot() { var date = new Date(); var currentHour = date.getHours(); var dayOfWeek = date.getDay(); var isSunday = (dayOfWeek === 0); var nextWeekMonth = new Date(date.getTime() + 7 * 24 * 60 * 60 * 1000).getMonth(); var isLastSunday = isSunday && (date.getMonth() !== nextWeekMonth); var timeSlot = "Evening"; if (currentHour >= 7 && currentHour <= 10) timeSlot = "Morning"; else if (currentHour >= 12 && currentHour <= 15) timeSlot = "Afternoon"; else if (currentHour >= 19 && currentHour <= 23) timeSlot = "Night"; generateAutoContent(timeSlot, isSunday, isLastSunday); SpreadsheetApp.flush(); Utilities.sleep(3000); autoPostToTelegram(); cleanupOldPosts(); } // ========================================== // 7. WEBHOOK (Popups) // ========================================== function doPost(e) { if (!e || !e.postData) return ContentService.createTextOutput("OK"); var data = JSON.parse(e.postData.contents); if (data.callback_query) { var msg = data.callback_query.data.startsWith("correct_") ? "Correct Answer! 🔥 You are one step closer to your Goal!" : "Oops! Wrong Answer ❌. Study hard & try again!"; var payload = { "callback_query_id": data.callback_query.id, "text": msg, "show_alert": true }; UrlFetchApp.fetch("https://api.telegram.org/bot" + CONFIG.BOT_TOKEN + "/answerCallbackQuery", { "method": "post", "contentType": "application/json", "payload": JSON.stringify(payload) }); } return ContentService.createTextOutput("OK"); }