Ver Fonte

ringing events

svetlana há 3 anos atrás
pai
commit
9aee0efe24
1 ficheiros alterados com 24 adições e 9 exclusões
  1. 24 9
      app/app.py

+ 24 - 9
app/app.py

@@ -208,22 +208,37 @@ async def newchannelCallback(mngr: Manager, msg: Message):
              'callId': uid}
       if (msg.linkedid in  app.cache['cel_calls']) and ('WebCallId' in app.cache['cel_calls'][msg.linkedid]):
         _cb['WebCallId'] = app.cache['cel_calls'][msg.linkedid]['WebCallId']
-      reply = await doCallback(device, _cb)
+      #reply = await doCallback(device, _cb)
 
 @manager.register_event('CEL')
 async def celCallback(mngr: Manager, msg: Message):
-  #app.logger.warning('CEL {}'.format(msg))
+  app.logger.warning('CEL {}'.format(msg))
   lid = msg.LinkedID
   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'] = {}
+    
   if (lid in app.cache['cel_calls']):
     firstMessage = app.cache['cel_calls'][lid]
     cid = firstMessage.CallerIDnum
     if firstMessage.CallerIDnum in app.cache['usermap']:
         cid = app.cache['usermap'][firstMessage.CallerIDnum]
     uid = firstMessage.LinkedID
+    if (msg.EventName == 'CHAN_START') and (lid != msg.UniqueID) and (not msg.Channel.startswith('Local/')):
+        if (firstMessage.Context == 'from-pstn') or (firstMessage.get('groupCall',False)):
+           device = msg.CallerIDnum
+           user = app.cache['usermap'][device]
+           did = firstMessage.Exten
+           _cb = {'user': user,
+             'device': device,
+             'state': 'ringing',
+             'callerId': cid,
+             'did': did,
+             'callId': uid} 
+           if ('WebCallId' in app.cache['cel_calls'][msg.linkedid]):
+             _cb['WebCallId'] = app.cache['cel_calls'][msg.linkedid]['WebCallId']
+           reply = await doCallback('device', _cb)
     if ((msg.Application == 'Queue') and
         (msg.EventName == 'APP_START') and 
         (firstMessage.Context == 'from-internal') and 
@@ -857,14 +872,14 @@ async def rebindLostDevices():
 
 async def userStateChangeCallback(user, state, prevState = None):
   reply = None
+  device = None
   if ('HTTP_CLIENT' in app.config) and (user in app.cache['devicemap']):
-    row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
-                             values={'device': app.cache['devicemap'][user]})
-    if row is not None:
-      reply = await app.config['HTTP_CLIENT'].post(row['url'],
-                                                   json={'user': user,
-                                                         'state': state,
-                                                         'prev_state':prevState})
+    device = app.cache['devicemap'][user]
+    if device is not None:
+      _cb = {'user': user,
+             'state': state,
+             'prev_state':prevState}
+      reply = await doCallback(device, _cb)
 
   app.logger.warning('{} changed state to: {}'.format(user, state))
   return reply