Loading Auto Spares...
0

Login

No account? Register

Auto Spares Solution

Premium wholesaler of original automobile spare parts since 2020

Shop by Brand

Stock last updated: Loading...

Our Products

Premium Auto Parts

Supplying high-quality components since 2020.

Explore Products
5000+ Parts
200+ Clients
98% Satisfaction
24H Processing

About Us

Your trusted partner for auto parts.

Investors

Growth opportunities.

Policies

Privacy, shipping, returns.

Contact

Email: contact@autosparessolution.com

Your Cart (Sales Invoice)

Subtotal:0.00
GST (18%):0.00
Total:0.00

Bulk Order Upload (Excel/CSV)

Ready. Choose file and click Process.
Loading product database...
0
Total: ₹0.00
Auto Spares AI ● Online
👋 Namaste! I'm your AI Sales Assistant.
Ask me about parts, prices, or stock.

🔍 0801BA0285N 🔍 Clutch Plate 🔍 Brake Pad 💰 Price Check
// ===== Function to send WhatsApp message ===== async function sendWhatsAppMessage(toNumber, message) { const url = `https://graph.facebook.com/v18.0/${WHATSAPP_CONFIG.phoneNumberId}/messages`; try { const response = await fetch(url, { method: 'POST', headers: { 'Authorization': `Bearer ${WHATSAPP_CONFIG.accessToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ messaging_product: 'whatsapp', to: toNumber, type: 'text', text: { body: message } }) }); const data = await response.json(); console.log('✅ WhatsApp message sent:', data); return data; } catch (error) { console.error('❌ WhatsApp error:', error); } } // ===== Helper: Calculate Price with GST ===== function aiPriceWithGST(product) { const billingPrice = product.price || product.list_value || 0; const gstRate = product.gst || 18; const gstAmount = billingPrice * (gstRate / 100); return { billingPrice: billingPrice, mrp: product.mrp || 0, listValue: product.list_value || 0, gstRate: gstRate, gstAmount: gstAmount, priceWithGST: billingPrice + gstAmount }; } // ===== Helper: Format Product for WhatsApp ===== function formatWhatsAppProduct(product, index = 0) { const prices = aiPriceWithGST(product); const stockStatus = product.stock > 0 ? `✅ ${product.stock} pcs in stock` : '❌ Out of Stock'; let reply = `${index + 1}. *${product.part}*\n`; reply += `📝 ${product.desc || 'N/A'}\n`; if (product.brand && product.brand !== 'Unknown') { reply += `🏷️ Brand: ${product.brand}`; if (product.make && product.make !== 'Unknown' && product.make !== product.brand) { reply += ` | Make: ${product.make}`; } reply += `\n`; } if (product.type) { reply += `📊 Type: ${product.type}`; if (product.finish) { reply += ` | Finish: ${product.finish}`; } reply += `\n`; } // ✅ FULL PRICE BREAKDOWN if (prices.listValue > 0) { reply += `💰 LIST PRICE: ₹${prices.listValue.toFixed(2)}\n`; } if (prices.mrp > 0 && prices.mrp !== prices.listValue) { reply += `💰 MRP PRICE: ₹${prices.mrp.toFixed(2)}\n`; } else if (prices.mrp > 0) { reply += `💰 MRP PRICE: ₹${prices.mrp.toFixed(2)}\n`; } if (prices.billingPrice > 0) { reply += `💳 Billing Price: ₹${prices.billingPrice.toFixed(2)}\n`; reply += `🧾 GST (${prices.gstRate}%): ₹${prices.gstAmount.toFixed(2)}\n`; reply += `💳 Price incl. GST: ₹${prices.priceWithGST.toFixed(2)}\n`; } // Stock & Packaging reply += `📦 ${stockStatus}`; if (product.box_qty > 0) { reply += ` | Box: ${product.box_qty}`; } if (product.carton > 0) { reply += ` | Carton: ${product.carton}`; } reply += `\n`; return reply; } // ===== Process incoming message with enhanced AI ===== function processWhatsAppMessage(message) { const query = message.toLowerCase().trim(); // Check if it's a help request if (query === 'help' || query === 'hi' || query === 'hello' || query === 'start') { return `👋 *Welcome to Auto Spares Solution!* I'm your AI Sales Assistant. Here's what I can help with: 🔍 *Search Parts* Send part number: "0801BA0285N" Send description: "clutch plate" 💰 *Check Price* "Price 0801BA0285N" 📦 *Check Stock* "Stock 0801BA0285N" 🛒 *Place Order* "Order 0801BA0285N 2" "0801BA0285N 2" 📞 *Call:* 9830300193 🛒 *Shop:* https://autosparessolution.com *How can I help you today?* 🚗`; } // Check if it's a price/stock/order command const isPriceQuery = query.includes('price') || query.includes('cost') || query.includes('rate'); const isStockQuery = query.includes('stock') || query.includes('available') || query.includes('have'); const isOrderQuery = query.includes('order') || query.includes('buy') || query.includes('purchase'); // Extract potential part number from query let partQuery = query; if (isPriceQuery || isStockQuery || isOrderQuery) { const words = query.split(' '); for (const word of words) { if (word.length >= 4 && word.match(/^[A-Z0-9]{4,}/i)) { partQuery = word; break; } } } // Search for products let results = []; if (window.allProducts && window.allProducts.length > 0) { const searchTerm = partQuery.toLowerCase().trim(); results = window.allProducts.filter(p => { const part = (p.part || '').toLowerCase(); const desc = (p.desc || '').toLowerCase(); const brand = (p.brand || '').toLowerCase(); const make = (p.make || '').toLowerCase(); return part.includes(searchTerm) || desc.includes(searchTerm) || brand.includes(searchTerm) || make.includes(searchTerm); }); // Sort: exact matches first results.sort((a, b) => { const aPart = a.part.toLowerCase(); const bPart = b.part.toLowerCase(); if (aPart === partQuery && bPart !== partQuery) return -1; if (bPart === partQuery && aPart !== partQuery) return 1; return (b.stock || 0) - (a.stock || 0); }); } // If we have results if (results.length > 0) { // If it's a specific command (price/stock/order), handle differently if (isPriceQuery || isStockQuery || isOrderQuery) { const product = results[0]; const prices = aiPriceWithGST(product); let reply = ''; if (isPriceQuery) { reply = `💰 *Price: ${product.part}*\n\n`; reply += `📝 ${product.desc || 'N/A'}\n`; if (product.brand && product.brand !== 'Unknown') { reply += `🏷️ Brand: ${product.brand}\n`; } if (prices.listValue > 0) { reply += `💰 LIST PRICE: ₹${prices.listValue.toFixed(2)}\n`; } if (prices.mrp > 0) { reply += `💰 MRP PRICE: ₹${prices.mrp.toFixed(2)}\n`; } reply += `💳 Billing Price: ₹${prices.billingPrice.toFixed(2)}\n`; reply += `🧾 GST (${prices.gstRate}%): ₹${prices.gstAmount.toFixed(2)}\n`; reply += `💳 *Total: ₹${prices.priceWithGST.toFixed(2)} (incl. GST)*\n\n`; reply += `🛒 Order: https://autosparessolution.com`; } else if (isStockQuery) { reply = `📦 *Stock: ${product.part}*\n\n`; reply += `📝 ${product.desc || 'N/A'}\n`; reply += `📦 ${product.stock > 0 ? `✅ ${product.stock} pcs available` : '❌ Out of Stock'}`; if (product.box_qty > 0) { reply += ` | Box: ${product.box_qty}`; } if (product.carton > 0) { reply += ` | Carton: ${product.carton}`; } reply += `\n\n🛒 Order: https://autosparessolution.com`; } else if (isOrderQuery) { reply = `🛒 *Order: ${product.part}*\n\n`; reply += `📝 ${product.desc || 'N/A'}\n`; const prices2 = aiPriceWithGST(product); reply += `💰 ₹${prices2.priceWithGST.toFixed(2)} (incl. GST)\n`; reply += `📦 ${product.stock > 0 ? `✅ ${product.stock} pcs available` : '❌ Out of Stock'}\n\n`; if (product.stock > 0) { reply += `✅ *Confirm order?* Click: https://autosparessolution.com`; } else { reply += `🔔 *We'll notify you when back in stock!*`; } } return reply; } // General search - Show all results with full details let reply = `🔍 *Found ${results.length} result(s)*\n\n`; const display = results.slice(0, 5); display.forEach((p, index) => { reply += formatWhatsAppProduct(p, index); reply += `\n`; }); if (results.length > 5) { reply += `_+ ${results.length - 5} more results_\n\n`; } reply += `━━━━━━━━━━━━━━━━━━━━\n`; reply += `🛒 *To order:* Send part number with quantity\n`; reply += `📝 *Example:* "${results[0]?.part} 2"\n`; reply += `━━━━━━━━━━━━━━━━━━━━\n`; reply += `🛒 *Order:* https://autosparessolution.com\n`; reply += `📞 *Call:* 9830300193\n\n`; reply += `💬 *Quick Commands:*\n`; reply += `- "Price ${results[0]?.part}" → Check price\n`; reply += `- "Stock ${results[0]?.part}" → Check availability`; return reply; } else { // No results - Try Gemini AI or fallback let reply = `❌ *I couldn't find "${message}" in our inventory.* 💡 *Try these options:* 1️⃣ Send a part number like *0801BA0285N* 2️⃣ Send a description like *clutch plate* 3️⃣ Send a brand name like *M&M* 📋 *Quick Commands:* - "Price 0801BA0285N" → Check price - "Stock 0801BA0285N" → Check availability - "0801BA0285N 2" → Add 2 to cart 📞 *Call:* 9830300193 🛒 *Shop:* https://autosparessolution.com`; return reply; } } // ===== Test function ===== async function testWhatsApp() { console.log('🧪 Testing WhatsApp AI...\n'); const testScenarios = [ { message: '0801BA0285N', description: 'Part search' }, { message: 'Price 0801BA0285N', description: 'Price check' }, { message: 'Stock 0801BA0285N', description: 'Stock check' }, { message: 'Order 0801BA0285N', description: 'Order' }, { message: 'clutch plate', description: 'Description search' }, { message: 'help', description: 'Help' } ]; for (const scenario of testScenarios) { console.log(`\n📩 Testing: "${scenario.message}" (${scenario.description})`); console.log('━'.repeat(40)); const reply = processWhatsAppMessage(scenario.message); console.log(reply); console.log('━'.repeat(40)); } } // ===== Send a test WhatsApp message ===== async function sendTestWhatsApp() { console.log('📱 Sending test WhatsApp message...'); const testMessage = `🚀 *ASSIST AI Test*\n\n` + `✅ WhatsApp API is working!\n` + `📱 Business Number: ${WHATSAPP_CONFIG.businessPhone}\n` + `🆔 Phone Number ID: ${WHATSAPP_CONFIG.phoneNumberId}\n\n` + `🎉 Your AI Sales Assistant is now ready!\n\n` + `💬 *Try these commands:*\n` + `📦 "Stock 0801BA0285N"\n` + `💰 "Price 0801BA0285N"\n` + `🛒 "Order 0801BA0285N"`; await sendWhatsAppMessage('919038899962', testMessage); } // Expose functions globally window.sendWhatsAppMessage = sendWhatsAppMessage; window.processWhatsAppMessage = processWhatsAppMessage; window.testWhatsApp = testWhatsApp; window.sendTestWhatsApp = sendTestWhatsApp; window.formatWhatsAppProduct = formatWhatsAppProduct; window.aiPriceWithGST = aiPriceWithGST; console.log('📱 WhatsApp AI Ready!'); console.log('📞 Business Number:', WHATSAPP_CONFIG.businessPhone); console.log('🆔 Phone Number ID:', WHATSAPP_CONFIG.phoneNumberId); console.log('🔑 Token:', WHATSAPP_CONFIG.accessToken.substring(0, 20) + '...'); console.log('\n💡 Available functions:'); console.log(' testWhatsApp() - Test all scenarios'); console.log(' sendTestWhatsApp() - Send actual WhatsApp message'); console.log(' processWhatsAppMessage("message") - Process a message');