get_product_data.json 4.5 KB

12345678
  1. {
  2. "name": "get_product_data",
  3. "description": "IMPORTANT: Always reply to the customer in their own language — the exact language they write in. Never switch to Polish unless the customer writes in Polish.\n\nPobierz dane produktu ze sklepu WooCommerce. Wywołaj gdy użytkownik pyta o konkretny produkt, jego cenę, opis lub dostępność. Szukaj po fragmencie nazwy (parametr search). Nigdy nie generuj informacji o produktach samodzielnie — zawsze wywołaj to narzędzie. Gdy użytkownik pyta o cenę lub dostępność konkretnego czynnika chłodniczego (R134a, R1234yf, R12) bez podawania marki auta — wyszukaj bezpośrednio po nazwie, nie pytaj o dane pojazdu.\n\nZawsze przekazuj parametr language z wykrytym językiem klienta (kod WPML, np. pl, de, en) — wymagany do wyświetlenia nazw i cen w odpowiednim języku i walucie.\n\nGdy wyszukiwanie zwróci wiele wyników, przedstaw numery i nazwy użytkownikowi i zapytaj o wybór. Następnie wywołaj narzędzie z productId (NIGDY nie szukaj ponownie po nazwie po tym jak użytkownik wybrał).",
  4. "color": "linear-gradient(rgb(100,180,200), rgb(50,130,170))",
  5. "iconSrc": "",
  6. "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},{\"id\":3,\"property\":\"language\",\"description\":\"Kod języka WPML wykryty z wiadomości klienta (np. pl, de, en, fr, cs, tr). Wymagany do podania cen w odpowiedniej walucie.\",\"type\":\"string\",\"required\":false},{\"id\":4,\"property\":\"currency\",\"description\":\"Nadpisanie waluty — podaj kod ISO 4217 (np. EUR, CZK, PLN) gdy użytkownik wyraźnie prosi o ceny w konkretnej walucie niezależnie od jego języka. Opcjonalne.\",\"type\":\"string\",\"required\":false}]",
  7. "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) : ''\nconst language = typeof $language !== 'undefined' && $language ? String($language) : ''\nconst currency = typeof $currency !== 'undefined' && $currency ? String($currency).toUpperCase().trim() : ''\n\nif (!productId && !sku && !search) return 'Error: provide productId, sku or search'\nif (!secret) return 'Error: missing $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 if (language) body.language = language\n if (currency) body.currency = currency\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 const currencyCode = data.currency || 'PLN'\n const currencyNote = data.currency_fallback && data.currency_note ? '\\n[NOTE: ' + data.currency_note + ']' : ''\n if (Array.isArray(result)) {\n if (result.length === 0) return 'No products found matching the search phrase.'\n if (result.length === 1) return JSON.stringify(result[0], null, 2) + (currencyNote ? '\\n' + currencyNote : '')\n const idMap = result.map((p, i) => `${i + 1}=${p.id}`).join(', ')\n const list = result.map((p, i) => `${i + 1}. ${p.name} — ${p.price ? p.price + ' ' + currencyCode : 'no price'}`).join('\\n')\n return `Found ${result.length} products:\\n${list}${currencyNote}\\n\\n[INSTRUCTION: Show the numbered list to the user. When user picks a number N or names a product from the list, use the Number→ID map to get the productId, then call this tool with ONLY productId=<that id>. NEVER search by name again — that causes an infinite loop.\\nNumber→ID: ${idMap}]`\n }\n return JSON.stringify(result, null, 2) + (currencyNote ? '\\n' + currencyNote : '')\n }\n return `Error: ${data.message || JSON.stringify(data)}`\n} catch (error) {\n return `Connection error: ${error?.message || String(error)}`\n}\n"
  8. }