{ "name": "get_product_data", "description": "Pobierz dane produktu ze sklepu WooCommerce. Podaj ID produktu, SKU lub frazę do wyszukania. Gdy wyszukiwanie zwróci wiele wyników, przedstaw nazwy użytkownikowi i zapytaj o konkretny produkt.", "color": "linear-gradient(rgb(100,180,200), rgb(50,130,170))", "iconSrc": "", "schema": "[{\"id\":0,\"property\":\"productId\",\"description\":\"ID produktu WooCommerce\",\"type\":\"number\",\"required\":false},{\"id\":1,\"property\":\"sku\",\"description\":\"SKU produktu\",\"type\":\"string\",\"required\":false},{\"id\":2,\"property\":\"search\",\"description\":\"Fraza do wyszukania produktu po nazwie lub opisie\",\"type\":\"string\",\"required\":false}]", "func": "const fetch = require('node-fetch')\n\nconst base = String(($vars && ($vars.relay_base || $vars.webhook_base)) || 'http://localhost:8080').replace(/\\/$/,'')\nconst secret = String(($vars && $vars.relay_shared_secret) || '')\n\nconst productId = typeof $productId !== 'undefined' && $productId ? Number($productId) : 0\nconst sku = typeof $sku !== 'undefined' && $sku ? String($sku) : ''\nconst search = typeof $search !== 'undefined' && $search ? String($search) : ''\n\nif (!productId && !sku && !search) return 'Błąd: podaj productId, sku lub search'\nif (!secret) return 'Błąd: brak $vars.relay_shared_secret'\n\ntry {\n const body = {}\n if (productId > 0) body.productId = productId\n if (sku) body.sku = sku\n if (search) body.search = search\n\n const res = await fetch(`${base}/tools/get_product_data`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${secret}`\n },\n body: JSON.stringify(body)\n })\n const data = await res.json()\n if (data.ok) {\n const result = data.data\n if (Array.isArray(result)) {\n if (result.length === 0) return 'Nie znaleziono produktów pasujących do podanej frazy.'\n if (result.length === 1) return JSON.stringify(result[0], null, 2)\n const idMap = result.map(p => p.name + ': ' + p.id).join(', ')\n const list = result.map((p, i) => `${i + 1}. ${p.name} — ${p.price ? p.price + ' ' + (data.currency_symbol || 'PLN') : 'brak ceny'}`).join('\\n')\n return `Znaleziono ${result.length} produktów:\\n${list}\\n\\n[INSTRUKCJA: Zapytaj użytkownika, który produkt go interesuje (pokaż numery i nazwy, nie ID). Gdy wybierze, wywołaj narzędzie ponownie z odpowiednim productId. Mapowanie: ${idMap}]`\n }\n return JSON.stringify(result, null, 2)\n }\n return `Błąd: ${data.message || JSON.stringify(data)}`\n} catch (error) {\n return `Błąd połączenia: ${error?.message || String(error)}`\n}\n" }