Auto-Suggestion Tool for Customer Queries

Auto-Suggestion Tool for Customer Queries

Find the best responses to customer questions instantly.

Suggested responses will appear here.

Keywords: ${item.keywords}

`).join(''); if(state.kb.length === 0) kbListEl.innerHTML = `

No knowledge base items yet.

`; }; const renderLog = () => { if (state.log.length === 0) { logPlaceholder.classList.remove('hidden'); logContent.classList.add('hidden'); } else { logPlaceholder.classList.add('hidden'); logContent.classList.remove('hidden'); logTableBody.innerHTML = state.log.map(item => ` ${item.timestamp.toLocaleString()} ${item.query} ${item.topSuggestion} `).join(''); } }; // --- INITIALIZATION & EVENT HANDLERS --- window.copyToClipboard = (id) => { const item = state.kb.find(i => i.id == id); if(item) navigator.clipboard.writeText(item.response); }; function initialize() { getSuggestionsBtn.addEventListener('click', handleGetSuggestions); addKbForm.addEventListener('submit', handleAddKbItem); downloadPdfBtn.addEventListener('click', generatePdf); renderAll(); } const switchTab = (tabName) => { state.currentTab = tabName; Object.values(tabButtons).forEach(b => b.classList.remove('active')); Object.values(tabContents).forEach(c => c.classList.add('hidden')); if(tabButtons[tabName]) tabButtons[tabName].classList.add('active'); if(tabContents[tabName]) tabContents[tabName].classList.remove('hidden'); }; Object.keys(tabButtons).forEach(k => tabButtons[k]?.addEventListener('click', () => switchTab(k))); // --- PDF GENERATION --- async function generatePdf() { if (!state.lastQueryAnalysis) { alert('Please analyze a query first to generate a report.'); return; } const { jsPDF } = window.jspdf; document.getElementById('pdf-report-date').textContent = `Generated: ${new Date().toLocaleString()}`; document.getElementById('pdf-query-box').textContent = state.lastQueryAnalysis.query; document.getElementById('pdf-suggestions-container').innerHTML = state.lastQueryAnalysis.suggestions.map(s => `

${s.title}

${s.response}

`).join(''); const pdfContainer = document.getElementById('pdf-container'); pdfContainer.classList.remove('invisible', '-left-[9999px]'); try { const canvas = await html2canvas(document.getElementById('pdf-report'), { scale: 2 }); const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jsPDF({ orientation: 'p', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, pdfHeight); pdf.save('Query_Suggestion_Report.pdf'); } catch (error) { console.error("PDF generation failed:", error); } finally { pdfContainer.classList.add('invisible', '-left-[9999px]'); } } initialize(); });
Scroll to Top