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
ProfileTelegram
146 commands0 envUpdated 2d agoCreated Sep 5, 2026
Back to folder

commands/_sync_api_products.js

javascript · 124 lines

Raw
1/**#command2name: /sync_api_products3answer: 4keyboard: 5parse_mode: markdown6aliases: /syncproducts7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12try {13  var adminId = Bot.getProperty("owner_id") || "8477746023";14  var currentChatId = (typeof chat !== 'undefined' && chat && chat.chatid) ? String(chat.chatid) : null;15  16  if (currentChatId !== adminId) {17    Bot.sendMessage("❌ Restricted! Only owner can sync products.");18    return;19  }20 21  // API Details22  var apiUrl = "https://adminpanels.shop/api/reseller_v1.php";23  var apiKey = "e4cc5a87b1731d4e43cb97cfe2ecff95";24  25  Bot.sendMessage("⏳ <b>Syncing products from API...</b>\n\n<i>Fetching and adding all products. This may take a moment.</i>", { parse_mode: "HTML" });26 27  try {28    // Fetch from API29    var response = Api.call("GET", apiUrl + "?api_key=" + apiKey + "&action=getproducts", null, null, 30000);30    31    if (!response || !response.ok) {32      throw new Error("API request failed: " + (response ? response.statusText : "No response"));33    }34 35    var data = response.json();36    37    if (!data || data.status === "error") {38      throw new Error(data && data.msg ? data.msg : "API returned error");39    }40 41    // Parse products from API response42    var importedProducts = [];43    var productSource = data.products || data.data || [];44    45    if (!Array.isArray(productSource)) {46      throw new Error("Invalid product format from API");47    }48 49    for (var i = 0; i < productSource.length; i++) {50      var apiProduct = productSource[i];51      var product = {52        id: apiProduct.id || apiProduct.product_id || String(i),53        name: apiProduct.name || apiProduct.product_name || "Unknown",54        description: apiProduct.description || apiProduct.desc || "",55        plans: []56      };57 58      // Handle plans/pricing tiers59      var plansSource = apiProduct.plans || apiProduct.pricing || [];60      if (typeof plansSource === 'object' && !Array.isArray(plansSource)) {61        plansSource = [plansSource];62      }63 64      for (var j = 0; j < plansSource.length; j++) {65        var apiPlan = plansSource[j];66        var plan = {67          id: apiPlan.id || apiPlan.plan_id || String(j),68          name: apiPlan.name || apiPlan.plan_name || ("Plan " + (j + 1)),69          days: apiPlan.days || apiPlan.duration || 30,70          durationDisplay: apiPlan.durationDisplay || (apiPlan.days + " Days") || "30 Days",71          price: Number(apiPlan.price) || Number(apiPlan.cost) || 0,72          reseller_price: Number(apiPlan.reseller_price) || Number(apiPlan.reseller_cost) || Number(apiPlan.price) || 073        };74        product.plans.push(plan);75      }76 77      if (product.plans.length > 0) {78        importedProducts.push(product);79      }80    }81 82    if (importedProducts.length === 0) {83      throw new Error("No valid products found in API response");84    }85 86    // Save to bot storage87    Bot.setProperty("stored_products", importedProducts, "json");88 89    // Create success report90    var reportMsg = "<blockquote><b>✅ PRODUCTS SYNCED SUCCESSFULLY!</b></blockquote>\n\n";91    reportMsg += "<b>📊 SYNC REPORT:</b>\n";92    reportMsg += "• <b>Total Products:</b> " + importedProducts.length + "\n";93    reportMsg += "• <b>API Source:</b> <code>adminpanels.shop</code>\n\n";94    95    reportMsg += "<b>📋 PRODUCT LISTING:</b>\n";96    for (var k = 0; k < importedProducts.length; k++) {97      var prod = importedProducts[k];98      reportMsg += "\n<b>" + (k + 1) + ". " + prod.name + "</b>\n";99      reportMsg += "   <i>ID:</i> <code>" + prod.id + "</code>\n";100      reportMsg += "   <i>Plans:</i> " + prod.plans.length + " tier(s)\n";101      102      for (var p = 0; p < Math.min(prod.plans.length, 3); p++) {103        var pl = prod.plans[p];104        reportMsg += "      • " + pl.name + " (" + pl.durationDisplay + "): ₹" + pl.price + " / ₹" + pl.reseller_price + "\n";105      }106      if (prod.plans.length > 3) {107        reportMsg += "      • ... and " + (prod.plans.length - 3) + " more\n";108      }109    }110 111    Bot.sendMessage(reportMsg, { parse_mode: "HTML" });112 113  } catch (apiErr) {114    Bot.sendMessage(115      "<blockquote><b>❌ SYNC FAILED</b></blockquote>\n\n" +116      "<b>Error:</b> <code>" + apiErr.message + "</code>\n\n" +117      "<i>Check API URL, key, and network connectivity.</i>",118      { parse_mode: "HTML" }119    );120  }121 122} catch (err) {123  Bot.sendMessage("Admin Sync Error: " + err.message);124}