vantuz 3.4.2 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +45 -45
- package/admin-keygen.js +51 -0
- package/cli.js +685 -585
- package/config.js +733 -733
- package/core/agent-loop.js +190 -190
- package/core/ai-provider.js +298 -261
- package/core/automation.js +523 -523
- package/core/brand-analyst.js +101 -0
- package/core/channels.js +167 -167
- package/core/dashboard.js +230 -230
- package/core/database.js +135 -37
- package/core/eia-monitor.js +3 -1
- package/core/engine.js +648 -636
- package/core/gateway.js +447 -447
- package/core/learning.js +214 -214
- package/core/license.js +113 -0
- package/core/marketplace-adapter.js +168 -168
- package/core/memory.js +190 -190
- package/core/migrations/001-initial-schema.sql +1 -1
- package/core/queue.js +120 -120
- package/core/self-healer.js +314 -314
- package/core/unified-product.js +214 -214
- package/core/vision-service.js +113 -113
- package/index.js +217 -174
- package/modules/crm/sentiment-crm.js +231 -231
- package/modules/healer/listing-healer.js +201 -201
- package/modules/oracle/predictor.js +214 -214
- package/modules/researcher/agent.js +169 -169
- package/modules/team/agents/base.js +92 -92
- package/modules/team/agents/dev.js +33 -33
- package/modules/team/agents/josh.js +40 -40
- package/modules/team/agents/marketing.js +33 -33
- package/modules/team/agents/milo.js +36 -36
- package/modules/team/index.js +78 -78
- package/modules/team/shared-memory.js +87 -87
- package/modules/war-room/competitor-tracker.js +250 -250
- package/modules/war-room/pricing-engine.js +308 -308
- package/nodes/warehouse.js +238 -238
- package/onboard.js +1 -1
- package/package.json +7 -5
- package/platforms/pttavm.js +14 -14
- package/plugins/vantuz/index.js +528 -528
- package/plugins/vantuz/memory/hippocampus.js +465 -465
- package/plugins/vantuz/package.json +20 -20
- package/plugins/vantuz/platforms/_template.js +118 -118
- package/plugins/vantuz/platforms/amazon.js +236 -236
- package/plugins/vantuz/platforms/ciceksepeti.js +166 -166
- package/plugins/vantuz/platforms/hepsiburada.js +180 -180
- package/plugins/vantuz/platforms/index.js +165 -165
- package/plugins/vantuz/platforms/n11.js +229 -229
- package/plugins/vantuz/platforms/pazarama.js +154 -154
- package/plugins/vantuz/platforms/pttavm.js +127 -127
- package/plugins/vantuz/platforms/trendyol.js +326 -326
- package/plugins/vantuz/services/alerts.js +253 -253
- package/plugins/vantuz/services/license.js +34 -34
- package/plugins/vantuz/services/scheduler.js +232 -232
- package/plugins/vantuz/tools/analytics.js +152 -152
- package/plugins/vantuz/tools/crossborder.js +187 -187
- package/plugins/vantuz/tools/nl-parser.js +211 -211
- package/plugins/vantuz/tools/product.js +110 -110
- package/plugins/vantuz/tools/quick-report.js +175 -175
- package/plugins/vantuz/tools/repricer.js +314 -314
- package/plugins/vantuz/tools/sentiment.js +115 -115
- package/plugins/vantuz/tools/vision.js +257 -257
- package/private.pem +28 -0
- package/public.pem +9 -0
- package/server/app.js +260 -260
- package/server/public/index.html +514 -514
- package/start.bat +33 -33
- package/vantuz.sqlite +0 -0
|
@@ -1,231 +1,231 @@
|
|
|
1
|
-
// modules/crm/sentiment-crm.js
|
|
2
|
-
// Sentiment CRM for Vantuz OS V2
|
|
3
|
-
// Analyzes reviews/questions, drafts brand-persona replies, escalates angry customers.
|
|
4
|
-
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { log } from '../../core/ai-provider.js';
|
|
8
|
-
|
|
9
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
10
|
-
// SENTIMENT ANALYSIS (Local / AI-Enhanced)
|
|
11
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
12
|
-
|
|
13
|
-
const SENTIMENT_KEYWORDS = {
|
|
14
|
-
angry: [
|
|
15
|
-
'rezalet', 'kötü', 'berbat', 'iade', 'şikayet', 'korkunç', 'sahtekarlık',
|
|
16
|
-
'dolandırıcı', 'cevap yok', 'pişman', 'lütfen çözün', 'iğrenç', 'saygısız',
|
|
17
|
-
'hala gelmedi', 'kırık', 'bozuk', 'yanlış ürün', 'parasını istiyorum'
|
|
18
|
-
],
|
|
19
|
-
happy: [
|
|
20
|
-
'mükemmel', 'harika', 'güzel', 'teşekkür', 'süper', 'hızlı', 'kaliteli',
|
|
21
|
-
'memnun', 'tavsiye', 'beğendim', 'perfect', 'çok iyi', 'bravo', 'başarılı'
|
|
22
|
-
],
|
|
23
|
-
confused: [
|
|
24
|
-
'ne zaman', 'nerede', 'nasıl', 'anlamadım', 'bilgi', 'soruyorum', 'cevap bekliyorum',
|
|
25
|
-
'açıklama', 'yardım', 'destek', 'merak ediyorum', 'ne oldu'
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Local sentiment detection (fast, no API call).
|
|
31
|
-
* @param {string} text
|
|
32
|
-
* @returns {{ sentiment: string, confidence: number, keywords: string[] }}
|
|
33
|
-
*/
|
|
34
|
-
function detectSentimentLocal(text) {
|
|
35
|
-
const lower = text.toLowerCase();
|
|
36
|
-
const found = { angry: [], happy: [], confused: [] };
|
|
37
|
-
|
|
38
|
-
for (const [sentiment, keywords] of Object.entries(SENTIMENT_KEYWORDS)) {
|
|
39
|
-
for (const kw of keywords) {
|
|
40
|
-
if (lower.includes(kw)) found[sentiment].push(kw);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Score: angry keywords weigh more
|
|
45
|
-
const scores = {
|
|
46
|
-
angry: found.angry.length * 2,
|
|
47
|
-
happy: found.happy.length * 1.5,
|
|
48
|
-
confused: found.confused.length * 1
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const winner = Object.entries(scores).sort((a, b) => b[1] - a[1])[0];
|
|
52
|
-
|
|
53
|
-
if (winner[1] === 0) {
|
|
54
|
-
return { sentiment: 'neutral', confidence: 0.5, keywords: [] };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
sentiment: winner[0],
|
|
59
|
-
confidence: Math.min(winner[1] / 5, 1),
|
|
60
|
-
keywords: found[winner[0]]
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
65
|
-
// BRAND PERSONA LOADER
|
|
66
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
67
|
-
|
|
68
|
-
function loadBrandTone() {
|
|
69
|
-
const brandPath = path.join(process.cwd(), 'workspace', 'BRAND.md');
|
|
70
|
-
try {
|
|
71
|
-
if (fs.existsSync(brandPath)) {
|
|
72
|
-
const content = fs.readFileSync(brandPath, 'utf-8').toLowerCase();
|
|
73
|
-
if (content.includes('samimi') || content.includes('friendly') || content.includes('emoji')) {
|
|
74
|
-
return 'friendly';
|
|
75
|
-
}
|
|
76
|
-
if (content.includes('premium') || content.includes('lüks') || content.includes('formal')) {
|
|
77
|
-
return 'formal';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
} catch (e) { /* ignore */ }
|
|
81
|
-
return 'professional'; // default
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
85
|
-
// CRM ENGINE
|
|
86
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
87
|
-
|
|
88
|
-
class SentimentCRM {
|
|
89
|
-
constructor() {
|
|
90
|
-
this.tone = loadBrandTone();
|
|
91
|
-
this.escalationCallbacks = []; // for angry customer alerts
|
|
92
|
-
this.processed = []; // recent analysis log
|
|
93
|
-
log('INFO', 'SentimentCRM initialized', { tone: this.tone });
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Register an escalation handler (webhook, Slack, WhatsApp).
|
|
98
|
-
*/
|
|
99
|
-
onEscalation(callback) {
|
|
100
|
-
this.escalationCallbacks.push(callback);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Analyze a customer message/review.
|
|
105
|
-
* @param {object} params
|
|
106
|
-
* @param {string} params.text - The message/review text.
|
|
107
|
-
* @param {string} params.customerName - Customer name.
|
|
108
|
-
* @param {string} params.platform - Source platform.
|
|
109
|
-
* @param {string} params.productBarcode - Related product barcode.
|
|
110
|
-
* @returns {{ sentiment, confidence, suggestedReply, escalated }}
|
|
111
|
-
*/
|
|
112
|
-
async analyze({ text, customerName = '', platform = '', productBarcode = '' }) {
|
|
113
|
-
const analysis = detectSentimentLocal(text);
|
|
114
|
-
|
|
115
|
-
// Generate reply suggestion
|
|
116
|
-
const suggestedReply = this._generateReply(analysis.sentiment, customerName, text);
|
|
117
|
-
|
|
118
|
-
// Escalate angry customers
|
|
119
|
-
let escalated = false;
|
|
120
|
-
if (analysis.sentiment === 'angry' && analysis.confidence >= 0.5) {
|
|
121
|
-
escalated = true;
|
|
122
|
-
this._escalate({
|
|
123
|
-
customerName,
|
|
124
|
-
platform,
|
|
125
|
-
text,
|
|
126
|
-
sentiment: analysis.sentiment,
|
|
127
|
-
confidence: analysis.confidence,
|
|
128
|
-
productBarcode
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const result = {
|
|
133
|
-
...analysis,
|
|
134
|
-
customerName,
|
|
135
|
-
platform,
|
|
136
|
-
productBarcode,
|
|
137
|
-
suggestedReply,
|
|
138
|
-
escalated,
|
|
139
|
-
analyzedAt: new Date().toISOString()
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
this.processed.push(result);
|
|
143
|
-
if (this.processed.length > 100) this.processed = this.processed.slice(-100);
|
|
144
|
-
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Batch analyze reviews.
|
|
150
|
-
*/
|
|
151
|
-
async analyzeBatch(reviews) {
|
|
152
|
-
const results = [];
|
|
153
|
-
for (const review of reviews) {
|
|
154
|
-
results.push(await this.analyze(review));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const summary = {
|
|
158
|
-
total: results.length,
|
|
159
|
-
angry: results.filter(r => r.sentiment === 'angry').length,
|
|
160
|
-
happy: results.filter(r => r.sentiment === 'happy').length,
|
|
161
|
-
confused: results.filter(r => r.sentiment === 'confused').length,
|
|
162
|
-
neutral: results.filter(r => r.sentiment === 'neutral').length,
|
|
163
|
-
escalated: results.filter(r => r.escalated).length
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
log('INFO', 'CRM batch analysis complete', summary);
|
|
167
|
-
return { results, summary };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
getRecent(limit = 20) {
|
|
171
|
-
return this.processed.slice(-limit);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
getStatus() {
|
|
175
|
-
const all = this.processed;
|
|
176
|
-
return {
|
|
177
|
-
tone: this.tone,
|
|
178
|
-
totalProcessed: all.length,
|
|
179
|
-
angryCount: all.filter(r => r.sentiment === 'angry').length,
|
|
180
|
-
escalatedCount: all.filter(r => r.escalated).length
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ─────────────────────────────────────────────────────────────────────
|
|
185
|
-
|
|
186
|
-
_generateReply(sentiment, customerName, originalText) {
|
|
187
|
-
const name = customerName ? ` ${customerName} Bey/Hanım` : '';
|
|
188
|
-
|
|
189
|
-
const replies = {
|
|
190
|
-
friendly: {
|
|
191
|
-
angry: `Merhaba${name} 🙏 Yaşadığınız bu sorun için çok üzgünüz! Hemen çözmek istiyoruz. Sipariş numaranızı paylaşır mısınız?`,
|
|
192
|
-
happy: `Teşekkürler${name} 🎉 Böyle güzel yorumlar bizi çok mutlu ediyor! Tekrar bekleriz 💜`,
|
|
193
|
-
confused: `Merhaba${name} 👋 Yardımcı olmak isteriz! Detayları paylaşır mısınız?`,
|
|
194
|
-
neutral: `Merhaba${name}, yorumunuz için teşekkürler! Başka sorunuz olursa yazabilirsiniz 😊`
|
|
195
|
-
},
|
|
196
|
-
formal: {
|
|
197
|
-
angry: `Sayın${name}, yaşadığınız olumsuzluktan dolayı özür dileriz. Konuyu derhal incelemeye alıyoruz. En kısa sürede size dönüş yapacağız.`,
|
|
198
|
-
happy: `Sayın${name}, değerli görüşleriniz için teşekkür ederiz. Memnuniyetiniz bizim için büyük önem taşımaktadır.`,
|
|
199
|
-
confused: `Sayın${name}, sorularınız için teşekkür ederiz. Konuyla ilgili size detaylı bilgi sunmak isteriz.`,
|
|
200
|
-
neutral: `Sayın${name}, yorumunuz için teşekkür ederiz.`
|
|
201
|
-
},
|
|
202
|
-
professional: {
|
|
203
|
-
angry: `Merhaba${name}, yaşadığınız sorun için özür dileriz. Konuyu inceliyoruz ve en kısa sürede dönüş yapacağız.`,
|
|
204
|
-
happy: `Merhaba${name}, güzel yorumunuz için teşekkürler! Tekrar bekleriz.`,
|
|
205
|
-
confused: `Merhaba${name}, yardımcı olmak isteriz. Lütfen detayları paylaşın.`,
|
|
206
|
-
neutral: `Merhaba${name}, yorumunuz için teşekkürler.`
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
return (replies[this.tone] || replies.professional)[sentiment] || replies.professional.neutral;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
_escalate(data) {
|
|
214
|
-
log('WARN', `🚨 ESCALATION: Kızgın müşteri — ${data.customerName || 'Anonim'} (${data.platform})`, data);
|
|
215
|
-
|
|
216
|
-
for (const cb of this.escalationCallbacks) {
|
|
217
|
-
try { cb(data); } catch (e) { /* swallow */ }
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
let crmInstance = null;
|
|
223
|
-
|
|
224
|
-
export function getSentimentCRM() {
|
|
225
|
-
if (!crmInstance) {
|
|
226
|
-
crmInstance = new SentimentCRM();
|
|
227
|
-
}
|
|
228
|
-
return crmInstance;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export default SentimentCRM;
|
|
1
|
+
// modules/crm/sentiment-crm.js
|
|
2
|
+
// Sentiment CRM for Vantuz OS V2
|
|
3
|
+
// Analyzes reviews/questions, drafts brand-persona replies, escalates angry customers.
|
|
4
|
+
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { log } from '../../core/ai-provider.js';
|
|
8
|
+
|
|
9
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
10
|
+
// SENTIMENT ANALYSIS (Local / AI-Enhanced)
|
|
11
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
12
|
+
|
|
13
|
+
const SENTIMENT_KEYWORDS = {
|
|
14
|
+
angry: [
|
|
15
|
+
'rezalet', 'kötü', 'berbat', 'iade', 'şikayet', 'korkunç', 'sahtekarlık',
|
|
16
|
+
'dolandırıcı', 'cevap yok', 'pişman', 'lütfen çözün', 'iğrenç', 'saygısız',
|
|
17
|
+
'hala gelmedi', 'kırık', 'bozuk', 'yanlış ürün', 'parasını istiyorum'
|
|
18
|
+
],
|
|
19
|
+
happy: [
|
|
20
|
+
'mükemmel', 'harika', 'güzel', 'teşekkür', 'süper', 'hızlı', 'kaliteli',
|
|
21
|
+
'memnun', 'tavsiye', 'beğendim', 'perfect', 'çok iyi', 'bravo', 'başarılı'
|
|
22
|
+
],
|
|
23
|
+
confused: [
|
|
24
|
+
'ne zaman', 'nerede', 'nasıl', 'anlamadım', 'bilgi', 'soruyorum', 'cevap bekliyorum',
|
|
25
|
+
'açıklama', 'yardım', 'destek', 'merak ediyorum', 'ne oldu'
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Local sentiment detection (fast, no API call).
|
|
31
|
+
* @param {string} text
|
|
32
|
+
* @returns {{ sentiment: string, confidence: number, keywords: string[] }}
|
|
33
|
+
*/
|
|
34
|
+
function detectSentimentLocal(text) {
|
|
35
|
+
const lower = text.toLowerCase();
|
|
36
|
+
const found = { angry: [], happy: [], confused: [] };
|
|
37
|
+
|
|
38
|
+
for (const [sentiment, keywords] of Object.entries(SENTIMENT_KEYWORDS)) {
|
|
39
|
+
for (const kw of keywords) {
|
|
40
|
+
if (lower.includes(kw)) found[sentiment].push(kw);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Score: angry keywords weigh more
|
|
45
|
+
const scores = {
|
|
46
|
+
angry: found.angry.length * 2,
|
|
47
|
+
happy: found.happy.length * 1.5,
|
|
48
|
+
confused: found.confused.length * 1
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const winner = Object.entries(scores).sort((a, b) => b[1] - a[1])[0];
|
|
52
|
+
|
|
53
|
+
if (winner[1] === 0) {
|
|
54
|
+
return { sentiment: 'neutral', confidence: 0.5, keywords: [] };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
sentiment: winner[0],
|
|
59
|
+
confidence: Math.min(winner[1] / 5, 1),
|
|
60
|
+
keywords: found[winner[0]]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
65
|
+
// BRAND PERSONA LOADER
|
|
66
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
67
|
+
|
|
68
|
+
function loadBrandTone() {
|
|
69
|
+
const brandPath = path.join(process.cwd(), 'workspace', 'BRAND.md');
|
|
70
|
+
try {
|
|
71
|
+
if (fs.existsSync(brandPath)) {
|
|
72
|
+
const content = fs.readFileSync(brandPath, 'utf-8').toLowerCase();
|
|
73
|
+
if (content.includes('samimi') || content.includes('friendly') || content.includes('emoji')) {
|
|
74
|
+
return 'friendly';
|
|
75
|
+
}
|
|
76
|
+
if (content.includes('premium') || content.includes('lüks') || content.includes('formal')) {
|
|
77
|
+
return 'formal';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (e) { /* ignore */ }
|
|
81
|
+
return 'professional'; // default
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
85
|
+
// CRM ENGINE
|
|
86
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
87
|
+
|
|
88
|
+
class SentimentCRM {
|
|
89
|
+
constructor() {
|
|
90
|
+
this.tone = loadBrandTone();
|
|
91
|
+
this.escalationCallbacks = []; // for angry customer alerts
|
|
92
|
+
this.processed = []; // recent analysis log
|
|
93
|
+
log('INFO', 'SentimentCRM initialized', { tone: this.tone });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Register an escalation handler (webhook, Slack, WhatsApp).
|
|
98
|
+
*/
|
|
99
|
+
onEscalation(callback) {
|
|
100
|
+
this.escalationCallbacks.push(callback);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Analyze a customer message/review.
|
|
105
|
+
* @param {object} params
|
|
106
|
+
* @param {string} params.text - The message/review text.
|
|
107
|
+
* @param {string} params.customerName - Customer name.
|
|
108
|
+
* @param {string} params.platform - Source platform.
|
|
109
|
+
* @param {string} params.productBarcode - Related product barcode.
|
|
110
|
+
* @returns {{ sentiment, confidence, suggestedReply, escalated }}
|
|
111
|
+
*/
|
|
112
|
+
async analyze({ text, customerName = '', platform = '', productBarcode = '' }) {
|
|
113
|
+
const analysis = detectSentimentLocal(text);
|
|
114
|
+
|
|
115
|
+
// Generate reply suggestion
|
|
116
|
+
const suggestedReply = this._generateReply(analysis.sentiment, customerName, text);
|
|
117
|
+
|
|
118
|
+
// Escalate angry customers
|
|
119
|
+
let escalated = false;
|
|
120
|
+
if (analysis.sentiment === 'angry' && analysis.confidence >= 0.5) {
|
|
121
|
+
escalated = true;
|
|
122
|
+
this._escalate({
|
|
123
|
+
customerName,
|
|
124
|
+
platform,
|
|
125
|
+
text,
|
|
126
|
+
sentiment: analysis.sentiment,
|
|
127
|
+
confidence: analysis.confidence,
|
|
128
|
+
productBarcode
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const result = {
|
|
133
|
+
...analysis,
|
|
134
|
+
customerName,
|
|
135
|
+
platform,
|
|
136
|
+
productBarcode,
|
|
137
|
+
suggestedReply,
|
|
138
|
+
escalated,
|
|
139
|
+
analyzedAt: new Date().toISOString()
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
this.processed.push(result);
|
|
143
|
+
if (this.processed.length > 100) this.processed = this.processed.slice(-100);
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Batch analyze reviews.
|
|
150
|
+
*/
|
|
151
|
+
async analyzeBatch(reviews) {
|
|
152
|
+
const results = [];
|
|
153
|
+
for (const review of reviews) {
|
|
154
|
+
results.push(await this.analyze(review));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const summary = {
|
|
158
|
+
total: results.length,
|
|
159
|
+
angry: results.filter(r => r.sentiment === 'angry').length,
|
|
160
|
+
happy: results.filter(r => r.sentiment === 'happy').length,
|
|
161
|
+
confused: results.filter(r => r.sentiment === 'confused').length,
|
|
162
|
+
neutral: results.filter(r => r.sentiment === 'neutral').length,
|
|
163
|
+
escalated: results.filter(r => r.escalated).length
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
log('INFO', 'CRM batch analysis complete', summary);
|
|
167
|
+
return { results, summary };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
getRecent(limit = 20) {
|
|
171
|
+
return this.processed.slice(-limit);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
getStatus() {
|
|
175
|
+
const all = this.processed;
|
|
176
|
+
return {
|
|
177
|
+
tone: this.tone,
|
|
178
|
+
totalProcessed: all.length,
|
|
179
|
+
angryCount: all.filter(r => r.sentiment === 'angry').length,
|
|
180
|
+
escalatedCount: all.filter(r => r.escalated).length
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
185
|
+
|
|
186
|
+
_generateReply(sentiment, customerName, originalText) {
|
|
187
|
+
const name = customerName ? ` ${customerName} Bey/Hanım` : '';
|
|
188
|
+
|
|
189
|
+
const replies = {
|
|
190
|
+
friendly: {
|
|
191
|
+
angry: `Merhaba${name} 🙏 Yaşadığınız bu sorun için çok üzgünüz! Hemen çözmek istiyoruz. Sipariş numaranızı paylaşır mısınız?`,
|
|
192
|
+
happy: `Teşekkürler${name} 🎉 Böyle güzel yorumlar bizi çok mutlu ediyor! Tekrar bekleriz 💜`,
|
|
193
|
+
confused: `Merhaba${name} 👋 Yardımcı olmak isteriz! Detayları paylaşır mısınız?`,
|
|
194
|
+
neutral: `Merhaba${name}, yorumunuz için teşekkürler! Başka sorunuz olursa yazabilirsiniz 😊`
|
|
195
|
+
},
|
|
196
|
+
formal: {
|
|
197
|
+
angry: `Sayın${name}, yaşadığınız olumsuzluktan dolayı özür dileriz. Konuyu derhal incelemeye alıyoruz. En kısa sürede size dönüş yapacağız.`,
|
|
198
|
+
happy: `Sayın${name}, değerli görüşleriniz için teşekkür ederiz. Memnuniyetiniz bizim için büyük önem taşımaktadır.`,
|
|
199
|
+
confused: `Sayın${name}, sorularınız için teşekkür ederiz. Konuyla ilgili size detaylı bilgi sunmak isteriz.`,
|
|
200
|
+
neutral: `Sayın${name}, yorumunuz için teşekkür ederiz.`
|
|
201
|
+
},
|
|
202
|
+
professional: {
|
|
203
|
+
angry: `Merhaba${name}, yaşadığınız sorun için özür dileriz. Konuyu inceliyoruz ve en kısa sürede dönüş yapacağız.`,
|
|
204
|
+
happy: `Merhaba${name}, güzel yorumunuz için teşekkürler! Tekrar bekleriz.`,
|
|
205
|
+
confused: `Merhaba${name}, yardımcı olmak isteriz. Lütfen detayları paylaşın.`,
|
|
206
|
+
neutral: `Merhaba${name}, yorumunuz için teşekkürler.`
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
return (replies[this.tone] || replies.professional)[sentiment] || replies.professional.neutral;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
_escalate(data) {
|
|
214
|
+
log('WARN', `🚨 ESCALATION: Kızgın müşteri — ${data.customerName || 'Anonim'} (${data.platform})`, data);
|
|
215
|
+
|
|
216
|
+
for (const cb of this.escalationCallbacks) {
|
|
217
|
+
try { cb(data); } catch (e) { /* swallow */ }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let crmInstance = null;
|
|
223
|
+
|
|
224
|
+
export function getSentimentCRM() {
|
|
225
|
+
if (!crmInstance) {
|
|
226
|
+
crmInstance = new SentimentCRM();
|
|
227
|
+
}
|
|
228
|
+
return crmInstance;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default SentimentCRM;
|