|
@@ -13,6 +13,9 @@ import socketserver
|
|
|
import concurrent.futures
|
|
|
from http.server import BaseHTTPRequestHandler
|
|
|
from http.server import HTTPServer
|
|
|
+import src.core.callcenter.utils.call_cache_util as CacheUtil
|
|
|
+from src.core.callcenter.constant.constant import AT, CO, SK, saasId
|
|
|
+from src.core.callcenter.constant.esl_constant import SIP_HEADER, SPLIT, SOFIA, ORIGINATE, PARK
|
|
|
import src.core.callcenter.utils.esl_event_util as EslEventUtil
|
|
|
import src.core.callcenter.handler as event_handler
|
|
|
from src.core.callcenter.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
@@ -26,9 +29,11 @@ class InboundClient:
|
|
|
self.is_stopping = False
|
|
|
self.handler_table = self.scan_esl_event_handlers()
|
|
|
self.default_event_handler = DefaultEslEventHandler(self)
|
|
|
+ self.host, self.port, self.password = 'localhost', '8021', '4918257983818884358'
|
|
|
self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1) for x in range(self.thread_num)}
|
|
|
|
|
|
- self.host, self.port, self.password = 'localhost', '8021', '4918257983818884358'
|
|
|
+ gw = CacheUtil.getRouteGetway(saasId)
|
|
|
+ self.make_call(gw, '63366692', '13241676588', 'C111111111', 'D1111111')
|
|
|
|
|
|
def scan_esl_event_handlers(self):
|
|
|
import inspect
|
|
@@ -54,7 +59,7 @@ class InboundClient:
|
|
|
self.con = ESL.ESLconnection(self.host, self.port, self.password)
|
|
|
if self.con.connected():
|
|
|
print('inbound esl connected ... ')
|
|
|
- self.con.events('plain', 'all')
|
|
|
+ self.con.events('plain', 'all')
|
|
|
while not self.is_stopping:
|
|
|
e = self.con.recvEvent()
|
|
|
|
|
@@ -106,7 +111,147 @@ class InboundClient:
|
|
|
except:
|
|
|
traceback.print_exc()
|
|
|
|
|
|
+ def make_call(self, route_gateway, display, called, call_id, device_id, timeout=30, originate_timeout=30, *sip_headers):
|
|
|
+
|
|
|
+
|
|
|
+ if route_gateway.caller_prefix:
|
|
|
+ display = f"{route_gateway.caller_prefix}{display}"
|
|
|
+ if route_gateway.called_prefix:
|
|
|
+ called = f"{route_gateway.called_prefix}{called}"
|
|
|
+
|
|
|
+ sip_buffer = []
|
|
|
+ if sip_headers:
|
|
|
+ sip_buffer = [f"{SIP_HEADER}{header}" for header in sip_headers]
|
|
|
+
|
|
|
+ params = {
|
|
|
+ "callId": call_id,
|
|
|
+ "deviceId": device_id,
|
|
|
+ "caller": display,
|
|
|
+ "called": called,
|
|
|
+ }
|
|
|
+
|
|
|
+ if route_gateway.sip_header1:
|
|
|
+ sip_header1 = self.expression(route_gateway.sip_header1, params)
|
|
|
+ sip_buffer.append(f"{SIP_HEADER}{sip_header1}")
|
|
|
+
|
|
|
+ if route_gateway.sip_header2:
|
|
|
+ sip_header2 = self.expression(route_gateway.sip_header2, params)
|
|
|
+ sip_buffer.append(f"{SIP_HEADER}{sip_header2}")
|
|
|
+
|
|
|
+ if route_gateway.sip_header3:
|
|
|
+ sip_buffer.append(f"{SIP_HEADER}{route_gateway.sip_header3}")
|
|
|
+
|
|
|
+ builder = [
|
|
|
+ "{return_ring_ready=true,",
|
|
|
+ f"sip_contact_user={display},",
|
|
|
+ "ring_asr=true,",
|
|
|
+ "absolute_codec_string=codecs,",
|
|
|
+ f"origination_caller_id_number={display},",
|
|
|
+ f"origination_caller_id_name={display},",
|
|
|
+ f"origination_uuid={device_id},",
|
|
|
+ ]
|
|
|
+
|
|
|
+ if originate_timeout:
|
|
|
+ builder.append(f"originate_timeout={originate_timeout},")
|
|
|
+
|
|
|
+ if sip_buffer:
|
|
|
+ builder.append(f"{SPLIT}".join(sip_buffer))
|
|
|
+
|
|
|
+ builder.append("}")
|
|
|
+ builder.append(f"{SOFIA}{SK}{route_gateway.profile}{SK}{called}{PARK}")
|
|
|
+ cmd = "".join(builder)
|
|
|
+ print(cmd)
|
|
|
+
|
|
|
+
|
|
|
+ def call_timeout(self, call_id, device_id, timeout):
|
|
|
+ """呼叫超时主动挂机"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def send_args(self, device_id, name, arg):
|
|
|
+ msg = ESL.ESLevent("sendmsg", device_id)
|
|
|
+ msg.addHeader("call-command", "execute")
|
|
|
+ msg.addHeader("execute-app-name", name)
|
|
|
+ msg.addHeader("execute-app-arg", arg)
|
|
|
+ self.con.sendEvent(msg)
|
|
|
+
|
|
|
+ def bridge_call(self, call_id, device_id1, device_id2):
|
|
|
+ """桥接电话"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def transfer_call(self, _from, _to):
|
|
|
+ """转接"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def answer(self, device_id):
|
|
|
+ """应答"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def hangup_call(self, call_id, device_id):
|
|
|
+ """挂机"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def play_file(self, call_id, device_id, file):
|
|
|
+ """放音"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def broadcast(self, uuid, path, smf):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def break0(self, uuid, all, sync):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def hold(self, smf, uuid, display):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def get_var(self, uuid, var):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def set_var(self, uuid, var, val):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def multi_set_var(self, uuid, params):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def record(self, uuid, action, path, limit):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def transfer(self, uuid, smf, dest, dialplan, context):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def insert(self, device_id):
|
|
|
+ """强插"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def bridge_break(self, device_id):
|
|
|
+ """拆线"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def stop_play(self, device_id):
|
|
|
+ """关闭播放音乐"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def hold_play(self, device_id, play):
|
|
|
+ """向a-leg插播tts音乐(无限播放)"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def play_timeout(self, call_id, timeout):
|
|
|
+ """播放超时主动挂机"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def listen(self, device_id1, device_id2, aleg, bleg):
|
|
|
+ """监听"""
|
|
|
+ pass
|
|
|
+
|
|
|
+ def expression(self, template, params):
|
|
|
+
|
|
|
+ for key, value in params.items():
|
|
|
+ template = template.replace(f"${{{key}}}", str(value))
|
|
|
+ return template
|
|
|
+
|
|
|
def stop(self):
|
|
|
+ for k, v in self.executors.items():
|
|
|
+ v.shutdown()
|
|
|
+ self.con.disconnect()
|
|
|
self.is_stopping = True
|
|
|
|
|
|
|
|
@@ -162,12 +307,3 @@ class InboundClient:
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-def main():
|
|
|
- on = InboundClient()
|
|
|
-
|
|
|
-
|
|
|
- threading.Thread(target=on.start, args=()).start()
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- main()
|