钉钉 AI 客服:情感分析应用

4 阅读1分钟

钉钉 AI 客服:情感分析应用

情感分析提升用户体验。


一、情感分类

情感标识处理
积极positive正常服务
中性neutral正常服务
消极negative重点关注
愤怒angry立即转人工

二、情感识别

2.1 基于规则

const NEGATIVE_WORDS = ['不满', '差评', '投诉', '垃圾', '骗人'];

function detectByRule(message) {
  for (const word of NEGATIVE_WORDS) {
    if (message.includes(word)) return 'negative';
  }
  return 'neutral';
}

2.2 基于 AI

async function detectByAI(message) {
  const response = await ai.chat(`
    分析以下文本的情感(positive/neutral/negative/angry):
    ${message}
    
    只返回情感标签。
  `);
  
  return response.trim().toLowerCase();
}

三、情感响应

3.1 响应策略

const RESPONSES = {
  positive: {
    tone: '友好',
    template: '很高兴为您服务!'
  },
  negative: {
    tone: '道歉',
    template: '非常抱歉给您带来不好的体验,我们会尽快解决。'
  },
  angry: {
    tone: '诚恳',
    template: '我理解您的心情,马上为您转接人工客服处理。'
  }
};

function generateResponse(sentiment, message) {
  const strategy = RESPONSES[sentiment];
  return `${strategy.template}\n\n${answerQuestion(message)}`;
}

四、实时监控

const sentimentHistory = [];

async function trackSentiment(userId, sentiment) {
  sentimentHistory.push({ userId, sentiment, time: Date.now() });
  
  // 告警
  const recent = sentimentHistory.filter(s => s.userId === userId && s.sentiment === 'negative');
  if (recent.length > 3) {
    await sendAlert(`用户 ${userId} 连续负面情绪,建议人工介入`);
  }
}

五、数据分析

5.1 情感趋势

SELECT 
  DATE(created_at) as date,
  sentiment,
  COUNT(*) as count
FROM sentiment_logs
GROUP BY DATE(created_at), sentiment
ORDER BY date;

5.2 负面原因分析

async function analyzeNegativeReasons() {
  const negative = await db.query(
    'SELECT message FROM sentiment_logs WHERE sentiment = "negative"'
  );
  
  // 用 AI 分析原因
  const reasons = await ai.chat(`
    分析以下负面反馈的主要原因:
    ${negative.map(n => n.message).join('\n')}
  `);
  
  return reasons;
}

六、效果评估

指标优化前优化后
投诉率5%2%
满意度80%92%
转人工率20%12%

项目地址:GitHub - dingtalk-connector-pro 有问题欢迎 Issue 或评论区交流