Explorar el Código

разделение записей

svetlana hace 3 años
padre
commit
cb2408f899
Se han modificado 1 ficheros con 55 adiciones y 4 borrados
  1. 55 4
      app/app.py

+ 55 - 4
app/app.py

@@ -219,16 +219,20 @@ async def celCallback(mngr: Manager, msg: Message):
     extra = json.loads(msg.Extra)
     app.logger.warning('EXTRA {} '.format(extra));
     if ('transferee_channel_uniqueid' in extra) and ('channel2_uniqueid' in extra):
-      first = extra['transferee_channel_uniqueid'];
-      second = extra['channel2_uniqueid']
+      first = extra['transferee_channel_uniqueid']; #unique
+      second = extra['channel2_uniqueid']   #linked
+      #amiStopMixMonitor(first);
+      #amiStartMixMonitor(first,"{}/{}-{}-{}.wav".format(date.today().strftime("%Y/%m/%d"), msg.Exten, msg.CallerIDnum, msg.UniqueID));#2022/03/11/external-2534-1934-20220311-122726-1647001646.56557.wav
+      #amiStopMixMonitor(second);
       app.cache['cel_calls'][lid]['transfers'].append((first,second)) #no cdr in db here
       app.logger.warning('first {} {}'.format(first,second))
-      
+    
   if ((msg.EventName == 'CHAN_START') and (lid == msg.UniqueID)):    #save first msg
     app.cache['cel_calls'][lid] = msg
     app.cache['cel_calls'][lid]['current_channels'] = {}
     app.cache['cel_calls'][lid]['all_channels'] = {}
     app.cache['cel_calls'][lid]['transfers'] = []
+    #app.cache['cel_calls'][lid]['mix_monitors'] = []
     
   if (lid in app.cache['cel_calls']):
     firstMessage = app.cache['cel_calls'][lid]
@@ -298,6 +302,7 @@ async def celCallback(mngr: Manager, msg: Message):
           if ('WebCallId' in app.cache['cel_calls'][msg.linkedid]):
             _cb['WebCallId'] = app.cache['cel_calls'][msg.linkedid]['WebCallId']
           reply = await doCallback('groupAnswered', _cb)
+          
     if ((msg.Application == 'Queue') and
         (firstMessage.Context == 'from-pstn')):
       if (msg.EventName == 'APP_START'):
@@ -317,14 +322,20 @@ async def celCallback(mngr: Manager, msg: Message):
               'queue': msg.Exten,
               'agents': [q.user for q in app.cache['queues'][msg.Exten]]}
           reply = await doCallback('queueLeave', _cb)
+          
+    #if ((msg.EventName == 'APP_START')  and (msg.Application == 'MixMonitor')):
+    #  app.cache['cel_calls'][lid]['mix_monitors'].append(msg.Channel)
+    #if ((msg.EventName == 'APP_END')  and (msg.Application == 'MixMonitor')):
+    #  app.cache['cel_calls'][lid]['mix_monitors'].remove(msg.Channel)
+    
     if (msg.EventName == 'LINKEDID_END'):
       for t in firstMessage['transfers']:
         app.logger.warning('first {}'.format(t))
         (f,s) = t
         await db.execute(query='update cdr set transfer_from=(select distinct linkedid from cdr where uniqueid=:first) where linkedid=:second;',values={'first': f,'second': s})
-
       app.cache['cel_calls'].pop(lid, False)
       app.cache['cel_queue_calls'].pop(lid, False)
+      
     if (msg.EventName == 'USER_DEFINED') and (msg.UserDefType == 'SETVARIABLE'):
       varname, value = msg.AppData.split(',')[1].split('=')[0:2]
       app.cache['cel_calls'][lid][varname]=value
@@ -533,6 +544,46 @@ async def amiPJSIPShowAors():
     app.logger.warning('AorsList: {}'.format(','.join(aors.keys())))
   return successReply(aors)
 
+
+async def amiStartMixMonitor(channel,filename):
+  '''AMI MixMonitor
+  Parameters:
+    channel (string):channel to start mixmonitor
+    filename (string): file name
+
+  Returns:
+    string: None if SetVar was successfull, error message overwise
+  '''
+  reply = await manager.send_action({'Action': 'MixMonitor',
+                                     'Channel': channel,
+                                     'options': 'ai(LOCAL_MIXMON_ID)',
+                                     'File': filename})
+  app.logger.warning('MixMonitor({}, {})'.format(channel, filename))
+  if isinstance(reply, Message):
+    if reply.success:
+      return None
+    else:
+      return reply.message
+  return 'AMI error'
+  
+async def amiStopMixMonitor(channel):
+  '''AMI StopMixMonitor
+  Parameters:
+    channel (string):channel to stop mixmonitor
+
+  Returns:
+    string: None if SetVar was successfull, error message overwise
+  '''
+  reply = await manager.send_action({'Action': 'StopMixMonitor',
+                                     'Channel': channel})
+  app.logger.warning('StopMixMonitor({})'.format(channel))
+  if isinstance(reply, Message):
+    if reply.success:
+      return None
+    else:
+      return reply.message
+  return 'AMI error'
+  
 async def amiUserEvent(name, data):
   '''AMI UserEvent
   Generates AMI Event using AMI action UserEvent with name and data supplied.