|
@@ -11,6 +11,8 @@ import sys
|
|
|
import pjsua2 as pj
|
|
|
from enum import Enum
|
|
|
|
|
|
+from dns.resolver import Cache
|
|
|
+
|
|
|
from src.core.datasource import SIP_SERVER, SERVE_HOST
|
|
|
from src.core.voip.constant import *
|
|
|
|
|
@@ -181,6 +183,7 @@ class MyCall(pj.Call):
|
|
|
self.player = None
|
|
|
self.asr = None
|
|
|
self.session_id = kwargs.get('variable_sip_h_P-LIBRA-CallId')
|
|
|
+ self.device_id = kwargs.get('variable_sip_h_P-LIBRA-DeviceId')
|
|
|
|
|
|
print("self.session_id:", self.session_id)
|
|
|
# self.scripts = build_demo_script()
|
|
@@ -355,8 +358,7 @@ class MyCall(pj.Call):
|
|
|
self.agent.hangup(self.user_part)
|
|
|
elif action_code == 'transfer': # 转人工
|
|
|
print('todo 转人工')
|
|
|
- sip_headers = {'P-LIBRA-HangUpReason':'transferToAgent', 'P-LIBRA-ServiceId':'00000000000000000'}
|
|
|
- self.agent.hangup(self.user_part, **sip_headers)
|
|
|
+ self.agent.transfer(self.user_part, self.session_id, self.device_id)
|
|
|
|
|
|
class ToTextBotAgent:
|
|
|
def __init__(self, user_asr_text, call_agent):
|
|
@@ -483,6 +485,7 @@ class BotAgent:
|
|
|
self.calls = {}
|
|
|
self.ep = pj.Endpoint()
|
|
|
self.is_stopping = False
|
|
|
+ self.acd_service = None
|
|
|
threading.Thread(target=self.create_pjsua2, daemon=True).start()
|
|
|
|
|
|
def create_pjsua2(self):
|
|
@@ -541,6 +544,12 @@ class BotAgent:
|
|
|
while not self.is_stopping:
|
|
|
self.ep.libHandleEvents(100)
|
|
|
|
|
|
+ def transfer(self, user_part, call_id, device_id, service_id='00000000000000000'):
|
|
|
+ if self.acd_service:
|
|
|
+ self.acd_service.transfer_to_agent(call_id, device_id, service_id)
|
|
|
+ sip_headers = {'P-LIBRA-HangUpReason': 'transferToAgent', 'P-LIBRA-ServiceId': service_id}
|
|
|
+ self.hangup(user_part, **sip_headers)
|
|
|
+
|
|
|
def hangup(self, user_part, reason="NORMAL_CLEARING", **sip_headers):
|
|
|
call_op_param = pj.CallOpParam(True)
|
|
|
call_op_param.statusCode = pj.PJSIP_SC_OK
|