Browse Source

Merge branch 'develop' of ssh://gitlab.fuxicarbon.com:1111/client_service/voice-gateway-service into develop

Davidliu 3 months ago
parent
commit
eff684a5c1

+ 1 - 1
src/core/callcenter/agent.py

@@ -207,7 +207,7 @@ class AgentEventService:
 
             if CHANNEL_ANSWER == event_name:
                 self.agent_state_service.busy(saas_id, agent.agent_num, agent.phone_num)
-                self.data_handle_server.update_record(call_id, status=1)
+                self.data_handle_server.update_record(call_id, status=1, transfer_user_id=agent.user_id,transfer_user_name=agent.agent_name)
                 if is_agent:
                     self.agent_monitor_service.update_calling(agent_monitor)
                     self.push_handler.push_on_agent_work_report(saas_id, flow_id, agent_num, call_id, AgentScene.ROBOT, WorkStatus.AGENT_ANSWER_INCOMING, "座席接通呼入电话! internal")

+ 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):

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

@@ -37,10 +37,20 @@ class DataHandleServer:
     @with_app_context
     def update_record(self, session_id, **kwargs):
         call_record = CallRecord.query.filter(CallRecord.session_id == session_id).first()
+
         time_end = kwargs.get('time_end')
+        user_id =  kwargs.get('user_id')
+        user_name = kwargs.get('user_name')
         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 ''
+        # 如果记录是转人工并且有客服接通把客服更新到转接字段
+        self.app.logger.debug(f"Received kwargs: {kwargs} user_id:{user_id},user_name:{user_name}")
+        # if call_record.service_category==2 and user_id:
+        #    call_record.transfer_user_id = user_id
+        #    call_record.transfer_user_name =user_name
+        #    kwargs.pop('user_id', None)
+        #    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