|
1 | | -//Imagine: whenever a user submits a ticket (Incident, HR Case, etc.), the system analyzes the tone of the message — like frustrated, urgent, calm, confused — and automatically adjusts the ticket priority, or routes it to a specific team (like “Empathy Response Desk |
| 1 | +//Scenario: whenever a user submits a ticket (Incident, HR Case, etc.), the system analyzes the tone of the message - like frustrated, urgent, calm, confused |
| 2 | +// and automatically adjusts the ticket priority, or routes it to a specific team (like “Empathy Response Desk) |
| 3 | + |
| 4 | +var EmotionAnalyzer = Class.create(); |
| 5 | +EmotionAnalyzer.prototype = { |
| 6 | + initialize: function() {}, |
| 7 | + |
| 8 | + detectEmotion: function(text) { |
| 9 | + try { |
| 10 | + // ---- Mock Sentiment Logic (No external API) ---- |
| 11 | + text = text.toLowerCase(); |
| 12 | + var score = 0; |
| 13 | + var negativeWords = ['angry', 'frustrated', 'bad', 'urgent', 'hate', 'delay']; |
| 14 | + var positiveWords = ['thank', 'happy', 'great', 'awesome', 'love']; |
| 15 | + |
| 16 | + negativeWords.forEach(function(word) { |
| 17 | + if (text.includes(word)) score -= 1; |
| 18 | + }); |
| 19 | + positiveWords.forEach(function(word) { |
| 20 | + if (text.includes(word)) score += 1; |
| 21 | + }); |
| 22 | + |
| 23 | + var sentiment = (score > 0) ? 'positive' : (score < 0) ? 'negative' : 'neutral'; |
| 24 | + return { sentiment: sentiment, score: Math.abs(score / 3) }; |
| 25 | + } catch (e) { |
| 26 | + gs.error("EmotionAnalyzer error: " + e.message); |
| 27 | + return { sentiment: 'neutral', score: 0 }; |
| 28 | + } |
| 29 | + }, |
| 30 | + |
| 31 | + type: 'EmotionAnalyzer' |
| 32 | +}; |
0 commit comments