indrajitghosh20006/Testseller_01botPublic · Bot Template
AIThis bot provides an admin‑controlled system for managing user balances, products, and reseller roles. It includes commands to add balances (via manual input, Binance Pay, or UPI), approve and credit payments, and set up product listings with categories and pricing. Admins can also add resellers, view reseller info, and manage stock entries. The bot uses built‑in TeleBotHost APIs such as Bot, Api, HTTP, and Libs for database operations and message handling.
Commerceadminbalanceproductresellerpaymentsbinance
138 commands0 envUpdated 17h agoCreated Sep 27, 2026
commands/_viewprod.js
javascript · 169 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 var planButtons = [];49 var plans = selectedProduct.plans || [];50 51 if (plans.length === 0) {52 plans = [53 { days: "1", normal_price: "79", reseller_price: "65" },54 { days: "7", normal_price: "350", reseller_price: "300" }55 ];56 }57 58 for (var j = 0; j < plans.length; j++) {59 var plan = plans[j];60 var planUnit = plan.unit || "day";61 62 var cleanProdName = selectedProduct.name.trim().toUpperCase();63 var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();64 65 var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);66 var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;67 var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;68 69 var adminNormalPrice = Bot.getProperty(normalKey);70 var adminResellerPrice = Bot.getProperty(resellerKey);71 72 var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;73 var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;74 75 var displayPrice = isReseller ? currentReseller : currentNormal;76 var unitLabelWord = (planUnit === "hour") ? (Number(cleanPlanDays) === 1 ? "Hour" : "Hours") :77 (planUnit === "minute") ? (Number(cleanPlanDays) === 1 ? "Minute" : "Minutes") :78 (Number(cleanPlanDays) === 1 ? "Day" : "Days");79 var dayLabel = plan.durationDisplay || (cleanPlanDays + " " + unitLabelWord);80 81 // 🎉 Discount badge preview (auto-discount only, coupon shown later on confirm screen)82 var discPreviewKey1 = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();83 var discPreviewKey2 = "auto_discount_" + cleanProdName + "_ALL";84 var discPreview = Bot.getProperty(discPreviewKey1) || Bot.getProperty(discPreviewKey2) || Bot.getProperty("auto_discount_global") || 0;85 var badgeText = discPreview > 0 ? " 🎉-" + discPreview + "%" : "";86 87 var isPlanOOS = plan.out_of_stock === true;88 var stockLabel = isPlanOOS ? "NO" : "YES";89 var apiAvailable = (selectedProduct.id || selectedProduct.pid) ? "YES" : "NO";90 var availability = selectedProduct.maintenance === true ? "NO" : "YES";91 var planInfo =92 "<tg-emoji emoji-id='6147936236125298267'>⏳</tg-emoji> <b>Validity:</b> " + dayLabel + "\n" +93 "<tg-emoji emoji-id='6100657257605763582'>✅</tg-emoji> <b>Availability:</b> " + availability + "\n" +94 "<tg-emoji emoji-id='6039605143601680423'>📦</tg-emoji> <b>Stock:</b> " + stockLabel + "\n" +95 "<tg-emoji emoji-id='6215386799133433653'>🔗</tg-emoji> <b>API Available:</b> " + apiAvailable;96 planButtons.push([97 {98 text: (isPlanOOS ? "🟠 " : "🛒 ") + dayLabel + " — ₹" + displayPrice + (isPlanOOS ? " — OUT OF STOCK" : badgeText),99 callback_data: isPlanOOS ? "/plan_oos" : "/buyitem " + productIndex + " " + j,100 style: isPlanOOS ? "danger" : "primary",101 icon_custom_emoji_id: isPlanOOS ? "6143299028655280273" : "6100657257605763582"102 }103 ]);104 }105 106 // 📊 Direct status + features — no separate "View Status" button.107 var statusEmoji = selectedProduct.maintenance === true ? "🔴" : (plans.some(function(pl){ return pl.out_of_stock === true; }) ? "🟠" : "🟢");108 var statusLabel = selectedProduct.maintenance === true ? "MAINTENANCE" : (plans.length && plans.every(function(pl){ return pl.out_of_stock === true; }) ? "OUT OF STOCK" : "AVAILABLE");109 var featureLines = "";110 var features = Array.isArray(selectedProduct.features) ? selectedProduct.features : [];111 for (var fi=0; fi<features.length; fi++) {112 featureLines += "<tg-emoji emoji-id='6102856637343600044'>✨</tg-emoji> <b>" + String(features[fi]) + "</b>\n";113 }114 var directInfo =115 "<blockquote>" + statusEmoji + " <b>STATUS: " + statusLabel + "</b></blockquote>\n" +116 (featureLines ? "<b>PRODUCT FEATURES</b>\n" + featureLines + "\n" : "") +117 "<b>SELECT YOUR PLAN</b>\n\n";118 119 // ✅ NEW: Back button ab is product ki category wali list par le jaata hai120 // (Android Root / Android Non Root), generic /buy_hack (category-select) par nahi.121 var backCategory = selectedProduct.category ? String(selectedProduct.category).toLowerCase() : "both";122 var backCallback = (backCategory === "root") ? "/buy_hack_cat root" : (backCategory === "iphone") ? "/buy_hack_cat iphone" : "/buy_hack_cat nonroot";123 124 if (selectedProduct.demo_video) {125 planButtons.push([{ text: "▶️ Demo Video", callback_data: "/demo_video " + productIndex, style: "success", icon_custom_emoji_id: "5258077307985207053" }]);126 }127 128 planButtons.push([129 {130 text: "Back to Shop",131 callback_data: backCallback,132 style: "danger",133 icon_custom_emoji_id: "5893163582194978381"134 }135 ]);136 137 // ✅ FIX: empty tg-emoji tag hata diya — ab sirf plain product emoji text hai138 var planText =139 "<blockquote><tg-emoji emoji-id='6102856637343600044'>👑</tg-emoji> <b>PRODUCT: " + selectedProduct.name.toUpperCase() + "</b></blockquote>\n\n" +140 directInfo +141 "<blockquote><tg-emoji emoji-id='6093854128193152827'>🎉</tg-emoji> Select your validity plan below to proceed with the secure order <tg-emoji emoji-id='6091571559233755994'>👉</tg-emoji></blockquote>";142 143 var replyMarkupStr = JSON.stringify({ inline_keyboard: planButtons });144 145 if (messageId) {146 if (isPhotoMsg) {147 try { Api.deleteMessage({ chat_id: chatId, message_id: messageId }); } catch (e) {}148 Api.sendMessage({ chat_id: chatId, text: planText, parse_mode: "HTML", reply_markup: replyMarkupStr });149 } else {150 Api.editMessageText({151 chat_id: chatId,152 message_id: Number(messageId),153 text: planText,154 parse_mode: "HTML",155 reply_markup: replyMarkupStr156 });157 }158 } else {159 // ✅ FIX: pehle is case me kuch bhejta hi nahi tha160 Api.sendMessage({ chat_id: chatId, text: planText, parse_mode: "HTML", reply_markup: replyMarkupStr });161 }162 163 if (callbackId) {164 try { Api.answerCallbackQuery({ callback_query_id: String(callbackId) }); } catch (e) {}165 }166 167} catch (err) {168 Bot.sendMessage("⚠️ View Product Error: " + err.message, { parse_mode: "HTML" });169}