Internal Communication Optimizer

Internal Communication Optimizer

Analyze your communication patterns and refine your messages for clarity and impact.

Communication Volume by Channel

Sentiment Analysis (Last 30 Days)

Analyzing...

`; analyzeBtn.disabled = true; const prompt = `As an expert communication coach, analyze the following internal team message. Provide feedback on its clarity, tone, and engagement potential. Then, provide a revised, improved version of the message. Format your response with ## Feedback, ## Revised Message. \n\nOriginal Message:\n"${message}"`; try { let chatHistory = [{ role: "user", parts: [{ text: prompt }] }]; const payload = { contents: chatHistory }; const apiKey = ""; // Provided by environment const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`; const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); const result = await response.json(); if (result.candidates && result.candidates[0].content.parts[0].text) { const feedbackText = result.candidates[0].content.parts[0].text; // Basic markdown to HTML conversion const formattedFeedback = feedbackText .replace(/## (.*?)\n/g, '

$1

') .replace(/\* (.*?)\n/g, '
  • $1
  • ') .replace(/\n/g, '
    '); feedbackContainer.innerHTML = `
    ${formattedFeedback}
    `; } else { throw new Error("Invalid response from API"); } } catch (error) { console.error("Error with AI analysis:", error); feedbackContainer.innerHTML = `

    Could not get feedback. Please try again.

    `; } finally { analyzeBtn.disabled = false; } } // --- SETTINGS UI --- function renderChannelSettings() { const container = document.getElementById('channelSettingsContainer'); container.innerHTML = channels.map((channel, index) => `
    `).join(''); container.querySelectorAll('.remove-channel-btn').forEach(btn => { btn.addEventListener('click', (e) => { channels.splice(e.target.dataset.index, 1); renderChannelSettings(); }); }); } addChannelBtn.addEventListener('click', () => { channels.push(''); renderChannelSettings(); }); // --- PDF GENERATION --- async function generatePdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.text("Communication Analysis Report", 20, 20); // In a real app, you would add charts as images and more data doc.text("This is a placeholder for the full report.", 20, 40); doc.save("Communication-Report.pdf"); } // --- TAB NAVIGATION --- function switchTab(tabIndex) { currentTabIndex = tabIndex; tabsContainer.querySelectorAll('button').forEach((btn, index) => { btn.classList.toggle('tab-active', index === tabIndex); btn.classList.toggle('tab-inactive', index !== tabIndex); }); tabContents.forEach((content, index) => { content.classList.toggle('hidden', index !== tabIndex); }); updateButtonStates(); } function updateButtonStates() { prevBtn.disabled = currentTabIndex === 0; nextBtn.disabled = currentTabIndex === tabs.length - 1; prevBtn.classList.toggle('opacity-50', prevBtn.disabled); nextBtn.classList.toggle('opacity-50', nextBtn.disabled); } // --- EVENT LISTENERS --- tabsContainer.querySelectorAll('button').forEach((btn, index) => btn.addEventListener('click', () => switchTab(index))); prevBtn.addEventListener('click', () => { if (currentTabIndex > 0) switchTab(currentTabIndex - 1); }); nextBtn.addEventListener('click', () => { if (currentTabIndex < tabs.length - 1) switchTab(currentTabIndex + 1); }); saveProfileBtn.addEventListener('click', saveUserConfig); saveChannelsBtn.addEventListener('click', saveUserConfig); downloadPdfBtn.addEventListener('click', generatePdf); analyzeBtn.addEventListener('click', analyzeMessage); // --- INITIALIZATION --- initializeFirebase(); updateButtonStates(); });
    Scroll to Top