ayushyadav7970824760/goldensellingstore_botPublic · Bot Template
AIThis Telegram store bot lets customers browse digital products and plans, apply coupons, add funds via UPI, and receive purchased keys. It includes a full admin panel for managing products, reordering items, setting reseller prices, viewing and removing key stock, configuring UPI payment details and update links, and checking user balances. Co-admins and resellers are supported, and support tickets are forwarded to the admin.
Commercedigital_storeadmin_panelupi_paymentsresellercouponskey_stock
146 commands0 envUpdated 2d agoCreated Sep 5, 2026
commands/_viewprod.js
javascript · 185 lines
1/**#command2name: /viewprod3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// =========================================================13// 📦 Shows a product's plans (Step 2 of the buy flow)14// ✅ CRITICAL BUG FIX: pehle "<tg-emoji emoji-id='X'></tg-emoji>" ek EMPTY15// tag tha (koi fallback character nahi) — Telegram ka HTML parser aise16// malformed tg-emoji tag par POORA MESSAGE hi reject kar deta hai. Isi17// wajah se product par click karne par plan-list screen kabhi aati hi nahi18// thi — poora buy flow yahi pe tootta tha!19// ✅ Photo-message-edit bug bhi fix, aur missing else-branch (fresh send)20// bhi add kiya.21// =========================================================22 23try {24 var productList = Bot.getProperty("stored_products") || [];25 var callbackId = request ? request.id : null;26 var chatId = chat.chatid;27 var messageId = request && request.message ? request.message.message_id : (request ? request.message_id : null);28 var isPhotoMsg = !!(request && request.message && request.message.photo);29 30 var userId = user.telegramid;31 var isReseller = Bot.getProperty("is_reseller_" + userId) === true;32 33 var productIndex = params ? params.trim() : "";34 if (productIndex === "") {35 var cbData = request && request.callback_query ? request.callback_query.data : "";36 productIndex = cbData.replace("/viewprod ", "").replace("viewprod ", "");37 }38 39 var selectedProduct = productList[Number(productIndex)];40 41 if (!selectedProduct) {42 if (callbackId) {43 try { Api.answerCallbackQuery({ callback_query_id: String(callbackId), text: "⚠️ Product not found!", show_alert: true }); } catch (e) {}44 }45 return;46 }47 48 // =====================================================49 // 🔧 OUT OF STOCK / UNDER MAINTENANCE — admin panel se "Toggle Product50 // Stock" se set kiya ja sakta hai. Agar product out-of-stock hai, prices51 // ki jagah maintenance notice dikhao aur yahin ruk jao.52 // =====================================================53 if (selectedProduct.out_of_stock === true) {54 var maintBackCategory = selectedProduct.category ? String(selectedProduct.category).toLowerCase() : "both";55 var maintBackCallback = (maintBackCategory === "root") ? "/buy_hack_cat root" : (maintBackCategory === "iphone") ? "/buy_hack_cat iphone" : "/buy_hack_cat nonroot";56 57 var maintText =58 "<blockquote>🛒 <b>" + selectedProduct.name.toUpperCase() + "</b></blockquote>\n" +59 "<blockquote>👇 <b>NOTICE: THIS PRODUCT IS CURRENTLY UNDER MAINTENANCE.</b></blockquote>\n\n" +60 "Please check back later or contact admin support.";61 62 var maintButtons = JSON.stringify({63 inline_keyboard: [[{ text: "Back", callback_data: maintBackCallback, style: "danger" }]]64 });65 66 if (messageId) {67 if (isPhotoMsg) {68 try { Api.deleteMessage({ chat_id: chatId, message_id: messageId }); } catch (e) {}69 Api.sendMessage({ chat_id: chatId, text: maintText, parse_mode: "HTML", reply_markup: maintButtons });70 } else {71 try {72 Api.editMessageText({ chat_id: chatId, message_id: Number(messageId), text: maintText, parse_mode: "HTML", reply_markup: maintButtons });73 } catch (e) {74 Api.sendMessage({ chat_id: chatId, text: maintText, parse_mode: "HTML", reply_markup: maintButtons });75 }76 }77 } else {78 Api.sendMessage({ chat_id: chatId, text: maintText, parse_mode: "HTML", reply_markup: maintButtons });79 }80 81 if (callbackId) {82 try { Api.answerCallbackQuery({ callback_query_id: String(callbackId) }); } catch (e) {}83 }84 return;85 }86 87 var planButtons = [];88 var plans = Array.isArray(selectedProduct.plans) ? selectedProduct.plans : [];89 90 // Legacy products ke liye default plans, lekin unhe temporary object91 // me use karte waqt buyitem handler ko bhi same fallback dena zaroori hai.92 if (plans.length === 0) {93 plans = [94 { days: "1", normal_price: "79", reseller_price: "65" },95 { days: "7", normal_price: "350", reseller_price: "300" }96 ];97 }98 99 for (var j = 0; j < plans.length; j++) {100 var plan = plans[j];101 var planUnit = plan.unit || "day";102 103 var cleanProdName = selectedProduct.name.trim().toUpperCase();104 var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();105 106 var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);107 var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;108 var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;109 110 var adminNormalPrice = Bot.getProperty(normalKey);111 var adminResellerPrice = Bot.getProperty(resellerKey);112 113 var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;114 var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;115 116 var displayPrice = isReseller ? currentReseller : currentNormal;117 var unitLabelWord = (planUnit === "hour") ? (Number(cleanPlanDays) === 1 ? "Hour" : "Hours") :118 (planUnit === "minute") ? (Number(cleanPlanDays) === 1 ? "Minute" : "Minutes") :119 (Number(cleanPlanDays) === 1 ? "Day" : "Days");120 var dayLabel = plan.durationDisplay || (cleanPlanDays + " " + unitLabelWord);121 122 // 🎉 Discount badge preview (auto-discount only, coupon shown later on confirm screen)123 var discPreviewKey1 = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();124 var discPreviewKey2 = "auto_discount_" + cleanProdName + "_ALL";125 var discPreview = Bot.getProperty(discPreviewKey1) || Bot.getProperty(discPreviewKey2) || Bot.getProperty("auto_discount_global") || 0;126 var badgeText = discPreview > 0 ? " 🎉-" + discPreview + "%" : "";127 128 planButtons.push([129 {130 text: "🛒 " + dayLabel + " — ₹" + displayPrice + badgeText,131 callback_data: "/buyitem " + productIndex + " " + j,132 style: "success",133 icon_custom_emoji_id: "6100657257605763582"134 }135 ]);136 }137 138 // ✅ NEW: Back button ab is product ki category wali list par le jaata hai139 // (Android Root / Android Non Root), generic /buy_hack (category-select) par nahi.140 var backCategory = selectedProduct.category ? String(selectedProduct.category).toLowerCase() : "both";141 var backCallback = (backCategory === "root") ? "/buy_hack_cat root" : (backCategory === "iphone") ? "/buy_hack_cat iphone" : "/buy_hack_cat nonroot";142 143 planButtons.push([144 {145 text: "𝑩𝒂𝒄𝒌 𝒕𝒐 𝑺𝒉𝒐𝒑",146 callback_data: backCallback,147 style: "danger",148 icon_custom_emoji_id: "5893163582194978381"149 }150 ]);151 152 // ✅ FIX: empty tg-emoji tag hata diya — ab sirf plain product emoji text hai153 var tierText = isReseller ? "RESELLER" : "USER";154 var planText =155 "<blockquote>🛒 <b>" + selectedProduct.name.toUpperCase() + "</b> 🛍️</blockquote>\n\n" +156 "<blockquote>👑 <b>Your Account Tier:</b> " + tierText + "</blockquote>\n\n" +157 "<blockquote>🛒 <b>Choose your access plan:</b></blockquote>";158 159 var replyMarkupStr = JSON.stringify({ inline_keyboard: planButtons });160 161 if (messageId) {162 if (isPhotoMsg) {163 try { Api.deleteMessage({ chat_id: chatId, message_id: messageId }); } catch (e) {}164 Api.sendMessage({ chat_id: chatId, text: planText, parse_mode: "HTML", reply_markup: replyMarkupStr });165 } else {166 Api.editMessageText({167 chat_id: chatId,168 message_id: Number(messageId),169 text: planText,170 parse_mode: "HTML",171 reply_markup: replyMarkupStr172 });173 }174 } else {175 // ✅ FIX: pehle is case me kuch bhejta hi nahi tha176 Api.sendMessage({ chat_id: chatId, text: planText, parse_mode: "HTML", reply_markup: replyMarkupStr });177 }178 179 if (callbackId) {180 try { Api.answerCallbackQuery({ callback_query_id: String(callbackId) }); } catch (e) {}181 }182 183} catch (err) {184 Bot.sendMessage("⚠️ View Product Error: " + err.message, { parse_mode: "HTML" });185}