Browse Source

feat: 更新转接人&&fixbug

shanghui 3 months ago
parent
commit
0247638965

+ 5 - 0
src/core/callcenter/dao.py

@@ -466,6 +466,9 @@ class CallRecord(db.Model):
     update_by = db.Column(db.String(32), nullable=True, default="admin", comment='更新人')
     update_time = db.Column(db.DateTime, nullable=True, onupdate=datetime.now, comment='更新时间')
 
+    transfer_user_id = db.Column(db.BigInteger, nullable=True, comment='转接客服ID')
+    transfer_user_name = db.Column(db.String(255), nullable=True, comment='转接客服名字')
+
     def __repr__(self):
         return json.dumps(self.to_dict())
 
@@ -494,6 +497,8 @@ class CallRecord(db.Model):
             'create_time': self.create_time.isoformat() if self.create_time else None,
             'update_by': self.update_by,
             'update_time': self.update_time.isoformat() if self.update_time else None,
+            'transfer_user_id': self.transfer_user_id,
+            'transfer_user_name': self.transfer_user_name,
         }
 
 class BotRecords(db.Model):

+ 6 - 0
src/core/callcenter/data_handler.py

@@ -41,6 +41,12 @@ class DataHandleServer:
         if time_end and call_record.type==1:
             bot_record = BotRecords.query.filter(BotRecords.session == session_id).first()
             call_record.bussiness_type = bot_record.intent if bot_record else ''
+        # 如果记录是转人工并且有客服接通把客服更新到转接字段
+        if call_record.service_category==2 and kwargs.get('user_id'):
+           call_record.transfer_user_id = kwargs.get('user_id')
+           call_record.transfer_user_name = kwargs.get('user_name')
+           kwargs.pop('user_id', None)  # 删除 user_id,若不存在则不报错
+           kwargs.pop('user_name', None)
         # 动态更新字段
         for key, value in kwargs.items():
             if hasattr(call_record, key):

+ 12 - 2
src/core/datasource.py

@@ -13,6 +13,7 @@ import os
 from typing import List, Tuple
 from src.core import singleton
 from redis import StrictRedis, ConnectionPool
+from time import sleep
 
 SERVE_HOST = os.environ.get("SERVE_HOST")
 # SERVE_HOST = "192.168.100.159"
@@ -209,9 +210,18 @@ class RedisHandler:
         if expire:
             self.redis.expire(newkey, expire)
 
-    def publish(self, channel, message):
+    def publish(self, channel, message, retries=3):
         """发布消息到指定频道"""
-        self.redis.publish(channel, message)
+        # self.redis.publish(channel, message)
+        for attempt in range(retries):
+            try:
+                self.redis.publish(channel, message)
+                return  # 发布成功,退出方法
+            except Exception as e:
+                print( "Failed to publish message to channel '%s' on attempt %d: %s",channel, attempt + 1, e)
+                if attempt < retries - 1:
+                    sleep(1)  # 重试前等待一定时间
+        raise Exception(f"Failed to publish message to channel '{channel}' after {retries} attempts")
     def __del__(self):
         self.redis.close()
 

+ 1 - 1
src/core/voip/constant.py

@@ -4,6 +4,7 @@
 import os
 import mmh3
 import queue
+import pjsua2 as pj
 
 player_script_dir = '/code/src/core/voip/scripts/'
 
@@ -15,7 +16,6 @@ def murmur3_32(player_file):
 
 
 def build_audio_format():
-    import pjsua2 as pj
     fmt = pj.MediaFormatAudio()
     fmt.type = pj.PJMEDIA_TYPE_AUDIO
     fmt.id = pj.PJMEDIA_FORMAT_PCM