indrajitghosh20006/Igstore_01botPublic Β· Bot Template
AIThe bot provides an admin interface for a digital store, allowing the owner or coβadmins to add balances, products, plans, and categories. It supports payment workflows via UPI and Binance Pay, automatically generating QR codes and handling manual approval of deposits. The code patches inline keyboards to use premium emoji icons and includes helper functions for user and bot properties. Overall, it serves as a commerce management tool for a Telegram-based storefront.
Commercestoreadminbalanceproductplancategory
170 commands0 envUpdated 7h agoCreated Oct 30, 2026
commands/_.js
javascript Β· 244 lines
1/**#command2name: *3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// PREMIUM BUTTON ICONS13(function(){14 try {15 if (!JSON.__premiumPatched) {16 var __origStringify = JSON.stringify;17 JSON.stringify = function(value, replacer, space) {18 try {19 if (value && value.inline_keyboard && Array.isArray(value.inline_keyboard)) {20 var premiumIds = [21 "6143444134125379822",22 "6091379307907652768",23 "6147534454819661264",24 "6147817325660741985",25 "6235683689292897318",26 "6102856637343600044"27 ];28 var rows = value.inline_keyboard.map(function(row, ri) {29 if (!Array.isArray(row)) return row;30 return row.map(function(btn, bi) {31 if (!btn || typeof btn !== "object") return btn;32 var copy = {};33 for (var k in btn) copy[k] = btn[k];34 if (!copy.icon_custom_emoji_id) copy.icon_custom_emoji_id = premiumIds[(ri + bi) % premiumIds.length];35 return copy;36 });37 });38 var cloned = {};39 for (var key in value) cloned[key] = value[key];40 cloned.inline_keyboard = rows;41 return __origStringify.call(JSON, cloned, replacer, space);42 }43 } catch (e) {}44 return __origStringify.call(JSON, value, replacer, space);45 };46 JSON.__premiumPatched = true;47 }48 } catch (e) {}49})();50 51 52 53// =========================================================54// π‘οΈ WILDCARD FALLBACK / INPUT ROUTER55// Handles admin wizard replies that do not have a dedicated command.56// =========================================================57try {58 var msg = (typeof message !== 'undefined' && message) ? String(message).trim() : "";59 var uid = String(user.telegramid);60 var ownerId = String(Bot.getProperty("owner_id") || "7839151435");61 var isCoAdmin = Bot.getProperty("co_admin_" + uid);62 var isAdmin = (uid === ownerId || isCoAdmin);63 64 // -------------------------------------------------------65 // How-To-Use URL input: handle the actual Telegram message text directly.66 // This keeps the admin button flow reliable even when the generic `message`67 // variable is not populated by the runtime.68 // -------------------------------------------------------69 if (isAdmin) {70 var howLinkStepDirect = User.getProperty("set_how_link_step");71 var incomingTextDirect = (request && request.message && typeof request.message.text === "string")72 ? String(request.message.text).trim() : "";73 74 // How-To URL has priority over any stale demo-video session. This prevents the75 // old "Please send a Telegram video file" state from swallowing a URL.76 var looksLikeUrlDirect = /^https?:\/\//i.test(incomingTextDirect);77 var staleDemoSessionDirect = User.getProperty("demo_video_add_product");78 var shouldSaveHowLinkDirect = howLinkStepDirect === "waiting_input" ||79 (incomingTextDirect && looksLikeUrlDirect && staleDemoSessionDirect !== null &&80 staleDemoSessionDirect !== undefined && staleDemoSessionDirect !== "");81 82 if (shouldSaveHowLinkDirect && incomingTextDirect) {83 if (!looksLikeUrlDirect) {84 Bot.sendMessage("β Link http:// ya https:// se shuru honi chahiye!", {parse_mode:"HTML"});85 return;86 }87 Bot.setProperty("how_to_use_link", incomingTextDirect, "string");88 User.setProperty("set_how_link_step", null, "string");89 User.setProperty("demo_video_add_product", null, "string");90 Bot.sendMessage("β
<b>How To Use URL saved.</b>\n\n<code>" + incomingTextDirect.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">") + "</code>", {parse_mode:"HTML", reply_markup:JSON.stringify({inline_keyboard:[[{text:"β¬
οΈ Admin Panel",callback_data:"/admin",style:"primary"}]]})});91 return;92 }93 }94 95 // -------------------------------------------------------96 // Demo Video Manager input: accept Telegram video directly.97 // IMPORTANT: this is outside the text-only branch so actual video98 // updates are received and saved correctly.99 // -------------------------------------------------------100 if (isAdmin) {101 var demoAddIndexDirect = User.getProperty("demo_video_add_product");102 var incomingMessageDirect = request && request.message ? request.message : null;103 var incomingVideoDirect = (incomingMessageDirect && incomingMessageDirect.video) ? incomingMessageDirect.video :104 ((request && request.video) ? request.video : null);105 if (demoAddIndexDirect !== null && demoAddIndexDirect !== undefined && demoAddIndexDirect !== "") {106 if (incomingVideoDirect && incomingVideoDirect.file_id) {107 var dProductsDirect = Bot.getProperty("stored_products") || [];108 var dIndexDirect = Number(demoAddIndexDirect);109 if (!dProductsDirect[dIndexDirect]) { User.setProperty("demo_video_add_product", null, "string"); Bot.sendMessage("β Product not found.",{parse_mode:"HTML"}); return; }110 if (!Array.isArray(dProductsDirect[dIndexDirect].demo_videos)) dProductsDirect[dIndexDirect].demo_videos=[];111 var demoCaptionDirect = incomingMessageDirect && typeof incomingMessageDirect.caption === "string" ? incomingMessageDirect.caption :112 ((request && typeof request.caption === "string") ? request.caption : "");113 dProductsDirect[dIndexDirect].demo_videos.push({file_id:String(incomingVideoDirect.file_id),caption:String(demoCaptionDirect||""),added_at:new Date().toISOString()});114 Bot.setProperty("stored_products",dProductsDirect,"json");115 Bot.sendMessage("β
<b>Demo video saved.</b>\n\nNext video bhej sakte ho, ya Done dabao.",{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"β
Done",callback_data:"/demo_done",style:"success"},{text:"β Cancel",callback_data:"/demo_cancel",style:"danger"}]]})});116 return;117 }118 // Do not consume ordinary text here; How-To URL handling above gets first priority.119 if (!(incomingMessageDirect && incomingMessageDirect.text)) {120 Bot.sendMessage("π₯ Please send a Telegram video file. Caption optional hai.",{parse_mode:"HTML"});121 return;122 }123 }124 }125 126 if (isAdmin && msg) {127 // -------------------------------------------------------128 // Bunty API wizard129 // -------------------------------------------------------130 var buntyStep = User.getProperty("bunty_api_input_step");131 if (buntyStep) {132 var buntyCfg = Bot.getProperty("bunty_api_config") || {};133 if (buntyStep === "url") buntyCfg.url = msg;134 if (buntyStep === "api_token") buntyCfg.api_token = msg;135 if (buntyStep === "master_key") buntyCfg.master_key = msg;136 Bot.setProperty("bunty_api_config", buntyCfg, "json");137 User.setProperty("bunty_api_input_step", null, "string");138 Bot.sendMessage("β
<b>Bunty API value saved.</b>\n\nAb <code>/bunty_api</code> se configuration check karein.", {parse_mode:"HTML"});139 return;140 }141 142 // -------------------------------------------------------143 144 145 // -------------------------------------------------------146 // Manage Products wizard147 // -------------------------------------------------------148 var manageStepRaw = User.getProperty("manage_product_step");149 if (manageStepRaw) {150 var ms;151 try { ms = JSON.parse(String(manageStepRaw)); } catch(e0) { ms = null; }152 var products = Bot.getProperty("stored_products") || [];153 if (!ms || !products[Number(ms.product)]) {154 User.setProperty("manage_product_step", null, "string");155 Bot.sendMessage("β Product editing session expired. Please open Manage Products again.",{parse_mode:"HTML"});156 return;157 }158 var pIndex = Number(ms.product), p = products[pIndex];159 160 if (ms.type === "product_name") {161 p.name = msg;162 Bot.setProperty("stored_products", products, "json");163 User.setProperty("manage_product_step", null, "string");164 Bot.sendMessage("β
Product name updated to <b>"+msg.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")+"</b>.",{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"π¦ Manage This Product",callback_data:"/manage_product "+pIndex,style:"primary"}],[{text:"β¬
οΈ All Products",callback_data:"/manage_products",style:"primary"}]]})});165 return;166 }167 168 if (ms.type === "duration") {169 var dParts = msg.split("|").map(function(x){return x.trim();});170 if (dParts.length < 2 || !dParts[0] || !dParts[1]) {171 Bot.sendMessage("β Format: <code>DURATION | PID</code>",{parse_mode:"HTML"});172 return;173 }174 var pl = p.plans[Number(ms.plan)];175 if (!pl) { User.setProperty("manage_product_step", null, "string"); Bot.sendMessage("β Plan not found.",{parse_mode:"HTML"}); return; }176 var duration = dParts[0], pid = dParts[1];177 pl.durationDisplay = duration;178 pl.name_on_website = duration;179 pl.api_duration = duration;180 pl.pid = pid; pl.product_id = pid; pl.variant_id = pid;181 var dm = duration.toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes)(?:\s+(.+))?$/);182 if (dm) {183 pl.days = dm[1];184 pl.unit = /^h/.test(dm[2]) ? "hour" : (/^m/.test(dm[2]) ? "minute" : "day");185 }186 Bot.setProperty("stored_products", products, "json");187 User.setProperty("manage_product_step", null, "string");188 Bot.sendMessage("β
<b>Plan updated.</b>\nDuration: <code>"+duration+"</code>\nPID: <code>"+pid+"</code>",{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"π¦ Manage Product",callback_data:"/manage_product "+pIndex,style:"primary"}]]})});189 return;190 }191 192 if (ms.type === "prices") {193 var priceParts = msg.split("|").map(function(x){return x.trim();});194 if (priceParts.length < 2 || isNaN(Number(priceParts[0])) || isNaN(Number(priceParts[1]))) {195 Bot.sendMessage("β Format: <code>NORMAL_PRICE | RESELLER_PRICE</code>",{parse_mode:"HTML"});196 return;197 }198 var pl2 = p.plans[Number(ms.plan)];199 if (!pl2) { User.setProperty("manage_product_step", null, "string"); Bot.sendMessage("β Plan not found.",{parse_mode:"HTML"}); return; }200 pl2.normal_price = Number(priceParts[0]);201 pl2.reseller_price = Number(priceParts[1]);202 var cleanProd = String(p.name||"").trim().toUpperCase();203 var cleanDays = String(pl2.days||"").replace(/[^0-9.]/g, "");204 var unit = pl2.unit || "day";205 var suffix = unit === "day" ? cleanDays : (cleanDays + "_" + unit);206 if (cleanDays) {207 Bot.setProperty("price_normal_"+cleanProd+"_"+suffix, Number(priceParts[0]), "number");208 Bot.setProperty("price_reseller_"+cleanProd+"_"+suffix, Number(priceParts[1]), "number");209 }210 Bot.setProperty("stored_products", products, "json");211 User.setProperty("manage_product_step", null, "string");212 Bot.sendMessage("β
<b>Prices updated.</b>\nNormal: βΉ"+Number(priceParts[0]).toFixed(2)+"\nReseller: βΉ"+Number(priceParts[1]).toFixed(2),{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"π¦ Manage Product",callback_data:"/manage_product "+pIndex,style:"primary"}]]})});213 return;214 }215 216 if (ms.type === "add_plan") {217 var ap = msg.split("|").map(function(x){return x.trim();});218 if (ap.length < 4 || isNaN(Number(ap[2])) || isNaN(Number(ap[3]))) {219 Bot.sendMessage("β Format: <code>DURATION | PID | NORMAL_PRICE | RESELLER_PRICE</code>",{parse_mode:"HTML"});220 return;221 }222 var duration2=ap[0], pid2=ap[1], normal2=Number(ap[2]), reseller2=Number(ap[3]);223 var dm2=duration2.toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes)(?:\s+(.+))?$/);224 var unit2=dm2 ? (/^h/.test(dm2[2]) ? "hour" : (/^m/.test(dm2[2]) ? "minute" : "day")) : "day";225 var days2=dm2 ? dm2[1] : (duration2.match(/^([0-9]+(?:\.[0-9]+)?)/)||["0","0"])[1];226 if(!Array.isArray(p.plans)) p.plans=[];227 p.plans.push({days:days2,unit:unit2,durationDisplay:duration2,name_on_website:duration2,api_duration:duration2,pid:pid2,product_id:pid2,variant_id:pid2,normal_price:normal2,reseller_price:reseller2});228 var cp=String(p.name||"").trim().toUpperCase(), suffix2=unit2==="day"?String(days2):(String(days2)+"_"+unit2);229 Bot.setProperty("price_normal_"+cp+"_"+suffix2,normal2,"number");230 Bot.setProperty("price_reseller_"+cp+"_"+suffix2,reseller2,"number");231 Bot.setProperty("stored_products",products,"json");232 User.setProperty("manage_product_step",null,"string");233 Bot.sendMessage("β
<b>Plan added.</b>\nDuration: <code>"+duration2+"</code>\nPID: <code>"+pid2+"</code>",{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"π¦ Manage Product",callback_data:"/manage_product "+pIndex,style:"primary"}]]})});234 return;235 }236 }237 238 }239 240 // Any unmatched input returns to the normal start flow.241 Bot.run({ command: "/start" });242} catch (err) {243 try { Bot.sendMessage("β οΈ Kripya /start type karein.", { parse_mode: "HTML" }); } catch (e) {}244}