Skip to content

Commit 880ece8

Browse files
Create EmotionAnalyzer.js
An AI-powered ServiceNow innovation that automatically analyzes the tone and emotion of user-submitted tickets (like incidents or HR cases) to detect frustration, urgency, or satisfaction.
1 parent d6ddf0a commit 880ece8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

Comments
 (0)