فهرست منبع

feat: 增加外呼机器人实体

余尚辉 6 ماه پیش
والد
کامیت
ee283e8d74
1فایلهای تغییر یافته به همراه127 افزوده شده و 0 حذف شده
  1. 127 0
      src/core/callcenter/model.py

+ 127 - 0
src/core/callcenter/model.py

@@ -459,3 +459,130 @@ class RouteGateway:
     #             f"called_prefix={self.called_prefix}, profile={self.profile}, "
     #             f"sip_header1={self.sip_header1}, sip_header2={self.sip_header2}, "
     #             f"sip_header3={self.sip_header3}, status={self.status})")
+
+
+
+
+
+
+
+#机器人外呼
+class OutboundRobotRequestParams:
+    def __init__(self, node_id=None, user_id=None, session_id=None, record_id=None,
+                 task_id=None, event_type=None, asr_text=None, key_input=None):
+        self.node_id = node_id  # 节点id
+        self.user_id = user_id  # 用户id
+        self.session_id = session_id  # 会话id
+        self.record_id = record_id  # 唯一标识
+        self.task_id = task_id  # 机器人任务id
+        self.event_type = event_type  # 1:电话接通,2:用户语音asr结果上传,3:用户按键输入,4:用户挂断电话,5:读取外呼结果(可在外呼过程中调用,不一定在结束之后),6:用户不说话超时,7:TTS或录音文件播放完毕或被打断,8:ASR错误导致挂断电话,9:TTS错误导致挂断电话,10:其它系统错误导致挂断电话
+        self.asr_text = asr_text  # asr识别的文本
+        self.key_input = key_input  # 用户按键输入
+
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
+    # def __repr__(self):
+    #     return (f"OutboundRobotRequestParams(node_id={self.node_id}, user_id={self.user_id}, "
+    #             f"session_id={self.session_id}, record_id={self.record_id}, task_id={self.task_id}, "
+    #             f"event_type={self.event_type}, asr_text={self.asr_text}, key_input={self.key_input})")
+
+
+
+class OutboundRobotResponseAction:
+    def __init__(self, action_code=None, action_content=None):
+        self.action_code = action_code         # normal:正常通话;hang:挂断;transfer:转人工
+        self.action_content = action_content   # 动作内容
+
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_data):
+        return cls(
+            action_code=json_data.get("action_code"),
+            action_content=json_data.get("action_content")
+        )
+
+
+class OutboundRobotResponseContent:
+    def __init__(self, content_type=None, content=None, voice_url=None, voice_content=None):
+        self.content_type = content_type   # 播放类型
+        self.content = content             # 播放内容
+        self.voice_url = voice_url         # 语音地址
+        self.voice_content = voice_content # 语音文本
+
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_data):
+        return cls(
+            content_type=json_data.get("content_type"),
+            content=json_data.get("content"),
+            voice_url=json_data.get("voice_url"),
+            voice_content=json_data.get("voice_content")
+        )
+
+
+class OutboundRobotResponseResponseData:
+    def __init__(self, node_id=None, contents=None, interruptable=None, wait_time=None,
+                 action=None, talk_time_out=None):
+        self.node_id = node_id   # 节点id
+        self.contents = contents if contents is not None else []   # 内容列表
+        self.interruptable = interruptable   # 是否可打断
+        self.wait_time = wait_time   # 用户静默时长
+        self.action = action        # 动作代码
+        self.talk_time_out = talk_time_out     # 用户通话时长
+
+    def to_json_string(self):
+        return json.dumps({
+            "node_id": self.node_id,
+            "contents": [content.__dict__ for content in self.contents],
+            "interruptable": self.interruptable,
+            "wait_time": self.wait_time,
+            "action": self.action.__dict__ if self.action else None,
+            "talk_time_out": self.talk_time_out
+        }, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_data):
+        contents = [OutboundRobotResponseContent.from_json(item) for item in json_data.get("contents", [])]
+        action = OutboundRobotResponseAction.from_json(json_data.get("action", {})) if json_data.get("action") else None
+        return cls(
+            node_id=json_data.get("node_id"),
+            contents=contents,
+            interruptable=json_data.get("interruptable"),
+            wait_time=json_data.get("wait_time"),
+            action=action,
+            talk_time_out=json_data.get("talk_time_out")
+        )
+
+
+class OutboundRobotResponseResponse:
+    def __init__(self, data=None, message=None, code=None):
+        self.data = data if data is not None else OutboundRobotResponseResponseData()
+        self.message = message
+        self.code = code
+
+    def to_json_string(self):
+        return json.dumps({
+            "data": json.loads(self.data.to_json_string()),
+            "message": self.message,
+            "code": self.code
+        }, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        response_data = OutboundRobotResponseResponseData.from_json(data.get("data", {}))
+        return cls(
+            data=response_data,
+            message=data.get("message"),
+            code=data.get("code")
+        )