|
@@ -93,7 +93,8 @@ app.cache = {'devices':{},
|
|
|
'ustates':{},
|
|
'ustates':{},
|
|
|
'pstates':{},
|
|
'pstates':{},
|
|
|
'queues':{},
|
|
'queues':{},
|
|
|
- 'calls':{}}
|
|
|
|
|
|
|
+ 'calls':{},
|
|
|
|
|
+ 'cel_calls':{}}
|
|
|
|
|
|
|
|
manager = Manager(
|
|
manager = Manager(
|
|
|
loop=main_loop,
|
|
loop=main_loop,
|
|
@@ -207,6 +208,62 @@ async def newchannelCallback(mngr: Manager, msg: Message):
|
|
|
'callerId': cid,
|
|
'callerId': cid,
|
|
|
'did': did,
|
|
'did': did,
|
|
|
'callId': uid})
|
|
'callId': uid})
|
|
|
|
|
+
|
|
|
|
|
+@manager.register_event('CEL')
|
|
|
|
|
+async def celCallback(mngr: Manager, msg: Message):
|
|
|
|
|
+ if (msg.EventName == 'CHAN_START') and (msg.LinkedID == msg.UniqueID): #save first msg
|
|
|
|
|
+ app.cache['cel_calls'][msg.LinkedID] = msg
|
|
|
|
|
+ app.cache['cel_calls'][msg.LinkedID]['channels'] = {}
|
|
|
|
|
+ if (msg.LinkedID in app.cache['cel_calls']):
|
|
|
|
|
+ first_message = app.cache['cel_calls'][msg.LinkedID]
|
|
|
|
|
+ cid = first_message.CallerIDnum
|
|
|
|
|
+ uid = first_message.LinkedID
|
|
|
|
|
+ if cid is not None and len(cid)<7: #for local calls only
|
|
|
|
|
+ if (msg.EventName == 'CHAN_START') and msg.Context in ('from-queue') and ('HTTP_CLIENT' in app.config): #start dial
|
|
|
|
|
+ app.cache['cel_calls'][msg.LinkedID]['channels'][msg.Exten] = msg.Channel
|
|
|
|
|
+ app.logger.warning('NEW CALLING LIST {}'.format(','.join(app.cache['cel_calls'][uid]['channels'].keys())))
|
|
|
|
|
+
|
|
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
|
|
+ values={'device': cid})
|
|
|
|
|
+ if (row is not None) and (row['url'].startswith('http')):
|
|
|
|
|
+ values = {'users': list(app.cache['cel_calls'][uid]['channels'].keys()),
|
|
|
|
|
+ 'state': 'group_ringing',
|
|
|
|
|
+ 'callId': uid}
|
|
|
|
|
+ app.logger.warning('call usrl {} values {}'.format(row['url'],values))
|
|
|
|
|
+ reply = await app.config['HTTP_CLIENT'].post(row['url'],
|
|
|
|
|
+ json=values)
|
|
|
|
|
+ else:
|
|
|
|
|
+ app.logger.warning('no url for {}'.format(cid))
|
|
|
|
|
+ if (msg.EventName == 'CHAN_END') and msg.Context in ('from-queue') and ('HTTP_CLIENT' in app.config) and ('answered' not in first_message):#end dial
|
|
|
|
|
+ called = msg.CallerIDname
|
|
|
|
|
+ app.cache['cel_calls'][uid]['channels'].pop(called, False)
|
|
|
|
|
+ app.logger.warning('NEW CALLING LIST {}'.format(','.join(app.cache['cel_calls'][uid]['channels'].keys())))
|
|
|
|
|
+
|
|
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
|
|
+ values={'device': cid})
|
|
|
|
|
+ if (row is not None) and (row['url'].startswith('http')):
|
|
|
|
|
+ values = {'users': list(app.cache['cel_calls'][uid]['channels'].keys()),
|
|
|
|
|
+ 'state': 'group_ringing',
|
|
|
|
|
+ 'callId': uid}
|
|
|
|
|
+ app.logger.warning('call usrl {} values {}'.format(row['url'],values))
|
|
|
|
|
+ reply = await app.config['HTTP_CLIENT'].post(row['url'],
|
|
|
|
|
+ json=values)
|
|
|
|
|
+ if (msg.EventName == 'ANSWER') and (msg.Application == 'AppDial') and (msg.LinkedID in app.cache['cel_calls']) and ('HTTP_CLIENT' in app.config):
|
|
|
|
|
+ called = msg.Exten
|
|
|
|
|
+ app.cache['cel_calls'][msg.LinkedID]['answered']=1;
|
|
|
|
|
+ app.logger.warning('answered {}'.format(called))
|
|
|
|
|
+
|
|
|
|
|
+ row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
|
|
|
|
|
+ values={'device': cid})
|
|
|
|
|
+ if (row is not None) and (row['url'].startswith('http')):
|
|
|
|
|
+ values = {'user': called, 'state': 'group_answer', 'callId': uid}
|
|
|
|
|
+ app.logger.warning('call usrl {} values {}'.format(row['url'],values))
|
|
|
|
|
+ reply = await app.config['HTTP_CLIENT'].post(row['url'],
|
|
|
|
|
+ json=values)
|
|
|
|
|
+ if (msg.EventName == 'LINKEDID_END'):
|
|
|
|
|
+ app.cache['cel_calls'].pop(msg.LinkedID,False);
|
|
|
|
|
+ app.logger.warning('Left Calls {}'.format(','.join(app.cache['cel_calls'].keys())))
|
|
|
|
|
+
|
|
|
|
|
|
|
|
async def getCDR(start=None,
|
|
async def getCDR(start=None,
|
|
|
end=None,
|
|
end=None,
|