|
@@ -11,6 +11,7 @@ import sys
|
|
|
import pjsua2 as pj
|
|
|
from enum import Enum
|
|
|
|
|
|
+from src.core.callcenter.cache import Cache
|
|
|
from src.core.datasource import SIP_SERVER, SERVE_HOST
|
|
|
from src.core.voip.constant import *
|
|
|
|
|
@@ -479,8 +480,8 @@ class ToTextBotAgent:
|
|
|
@singleton_keys
|
|
|
class BotAgent:
|
|
|
|
|
|
- def __init__(self, logger, user_part_range=range(1001, 1011), host=SIP_SERVER, port="5060", password="slibra@#123456"):
|
|
|
- self.logger = logger
|
|
|
+ def __init__(self, app, user_part_range=range(1001, 1011), host=SIP_SERVER, port="5060", password="slibra@#123456"):
|
|
|
+ self.logger = app.logger
|
|
|
self.user_part_range, self.host, self.port, self.password = user_part_range, host, port, password
|
|
|
self.user_part_pool = queue.Queue(maxsize=len(user_part_range))
|
|
|
self.accounts = {}
|
|
@@ -488,6 +489,7 @@ class BotAgent:
|
|
|
self.ep = pj.Endpoint()
|
|
|
self.is_stopping = False
|
|
|
self.acd_service = None
|
|
|
+ self.cache = Cache(app)
|
|
|
threading.Thread(target=self.create_pjsua2, daemon=True).start()
|
|
|
|
|
|
def create_pjsua2(self):
|
|
@@ -548,10 +550,16 @@ class BotAgent:
|
|
|
|
|
|
def transfer(self, user_part, call_id, device_id, service_id='00000000000000000'):
|
|
|
if self.acd_service:
|
|
|
- threading.Thread(target=self.acd_service.transfer_to_agent, args=(call_id, device_id, service_id, user_part)).start()
|
|
|
- # self.acd_service.transfer_to_agent(call_id, device_id, service_id, user_part)
|
|
|
+ self.acd_service.transfer_to_agent(call_id, device_id, service_id, user_part)
|
|
|
# sip_headers = {'P-LIBRA-HangUpReason': 'transferToAgent', 'P-LIBRA-ServiceId': service_id}
|
|
|
- # self.hangup(user_part)
|
|
|
+ try_count = 10
|
|
|
+ while try_count >0:
|
|
|
+ if self.cache.get_need_play_hold_music(call_id):
|
|
|
+ self.hangup(user_part)
|
|
|
+ self.cache.del_need_play_hold_music(call_id)
|
|
|
+ break
|
|
|
+ time.sleep(1)
|
|
|
+
|
|
|
|
|
|
def hangup(self, user_part, reason="NORMAL_CLEARING", **sip_headers):
|
|
|
call_op_param = pj.CallOpParam(True)
|