diff --git a/ui/operator/app.js b/ui/operator/app.js index 33b4469..1cbbe73 100644 --- a/ui/operator/app.js +++ b/ui/operator/app.js @@ -606,6 +606,31 @@ function customerHashSeed(item, fallback = 0) { return [...raw].reduce((acc, char, index) => (acc + char.charCodeAt(0) * (index + 1)) % 997, fallback); } +function normalizedCustomerTags(item) { + return Array.isArray(item?.tags) + ? item.tags.map((tag) => String(tag || '').trim().toLowerCase()).filter(Boolean) + : []; +} + +function isFacebookCustomer(item) { + const tags = normalizedCustomerTags(item); + return tags.includes('facebook') || tags.includes('facebook-lead'); +} + +function isFacebookLeadInteraction(item) { + const subject = String(item?.subject || item?.title || '').trim().toLowerCase(); + if (subject.startsWith('[facebook]')) { + return true; + } + + const customerId = item?.customer_id || item?.customerId || ''; + if (!customerId) { + return false; + } + const customer = state.customers.items.find((entry) => entry.customer_id === customerId) || null; + return isFacebookCustomer(customer); +} + function customerInitials(name) { const parts = String(name || '') .trim() @@ -619,6 +644,9 @@ function customerInitials(name) { } function customerLeadSourceMeta(item, index) { + if (isFacebookCustomer(item)) { + return { label: 'Facebook', className: 'lead-badge source-facebook' }; + } const variants = [ { label: 'Instagram', className: 'lead-badge source-instagram' }, { label: 'WhatsApp', className: 'lead-badge source-whatsapp' }, @@ -629,6 +657,9 @@ function customerLeadSourceMeta(item, index) { } function customerLeadStatusMeta(item, index) { + if (isFacebookCustomer(item)) { + return { label: 'Новый', className: 'lead-badge status-new' }; + } const variants = [ { label: 'Переговоры', className: 'lead-badge status-negotiation' }, { label: 'Квалификация', className: 'lead-badge status-qualification' }, @@ -656,7 +687,9 @@ function customerLeadScoreClass(score) { } function customerLeadCompany(item) { - const tags = Array.isArray(item?.tags) ? item.tags.filter(Boolean) : []; + const tags = (Array.isArray(item?.tags) ? item.tags : []) + .map((tag) => String(tag || '').trim()) + .filter((tag) => tag && !['facebook', 'facebook-lead', 'hot-lead'].includes(tag.toLowerCase())); if (tags.length) { return tags[0]; } @@ -3620,12 +3653,14 @@ async function createInteraction() { function renderInteractionCard(item) { const meta = statusMeta(item.status); + const facebookLead = isFacebookLeadInteraction(item); const cardClass = item.status === 'escalated' ? 'pipeline-card escalated' : item.status === 'closed' ? 'pipeline-card closed' : 'pipeline-card'; const badges = [ + facebookLead ? 'Facebook' : '', `${escapeHtml(channelLabel(item.channel))}`, item.queue_id ? `${escapeHtml(item.queue_id)}` : '', item.assigned_to ? `${escapeHtml(item.assigned_to)}` : '', @@ -3643,6 +3678,7 @@ function renderInteractionCard(item) {