ddddeca9e1ad8f0eb04efc1797df9774c9d37072
[motion2.git] / server / services / routing / server / applications / agent.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xff5b=['end','[%s][AGENT]\x20ROUTING\x20STOPPED','complete','[%s][AGENT]\x20ROUTING\x20END','close','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','stack','util','../../../../config/logger','string','number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','validate','error','[%s][AGENT]\x20%s','map','join','stop','find','timeout','createQueue','atimeout','channel','START:%s','rules'];(function(_0x3e3faa,_0x4c84ab){var _0x4b10bb=function(_0x4a6224){while(--_0x4a6224){_0x3e3faa['push'](_0x3e3faa['shift']());}};_0x4b10bb(++_0x4c84ab);}(_0xff5b,0x1e8));var _0xbff5=function(_0x349a72,_0x306ff4){_0x349a72=_0x349a72-0x0;var _0x9fb112=_0xff5b[_0x349a72];return _0x9fb112;};'use strict';var schema=require('validate');var _=require('lodash');var util=require(_0xbff5('0x0'));var seqqueue=require('seq-queue');var logger=require(_0xbff5('0x1'))('routing');var strategy=require('./strategy');var queue=schema({'name':{'type':_0xbff5('0x2'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0xbff5('0x3'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x867f7a,_0x206e16,_0x4735e2){return logger[_0xbff5('0x4')](util[_0xbff5('0x5')](_0xbff5('0x6'),_0x867f7a,_0x206e16[_0xbff5('0x7')],_0x4735e2));}function handleFindAgent(_0x1ab20a){return function(_0x4a30be){return _0x4a30be[_0xbff5('0x7')][_0xbff5('0x8')]()===_0x1ab20a[_0xbff5('0x8')]();};}exports['consequence']=function(_0x3b3639,_0x1843a0,_0xaad5b0,_0x8a1b4d){return function(_0x3832e2){try{var _0xc134e6={'name':_0x1843a0[0x0],'timeout':_0x1843a0[0x1]};var _0x44bc48=queue[_0xbff5('0x9')](_0xc134e6,{'typecast':!![]});if(_0x44bc48['length']){logger[_0xbff5('0xa')](_0xbff5('0xb'),_0x3b3639,_[_0xbff5('0xc')](_0x44bc48,'message')[_0xbff5('0xd')](',\x20'));_0x3832e2[_0xbff5('0xe')]();}else{var _0x40373c=_[_0xbff5('0xf')](_0xaad5b0['agents'],handleFindAgent(_0xc134e6[_0xbff5('0x7')]));if(_0x40373c){var _0x505b05=(_0xc134e6[_0xbff5('0x10')]||0xa)*0x3e8;var _0x4ca607,_0x28448b;var _0x3e49b9=seqqueue[_0xbff5('0x11')](_0x505b05);_0x3e49b9['id']=_0x3b3639;_0x3e49b9[_0xbff5('0x12')]=_0x505b05;_0x3e49b9['channel']=_0x8a1b4d[_0xbff5('0x13')];writeLog(_0x3b3639,_0x40373c,util[_0xbff5('0x5')](_0xbff5('0x14'),_0x505b05));_0xaad5b0[_0xbff5('0x15')][_0x3b3639]['on'](_0xbff5('0x16'),function(){logger[_0xbff5('0x4')](_0xbff5('0x17'),_0x3b3639);clearTimeout(_0x28448b);_0x28448b=undefined;_0x3e49b9['close']();if(_0xaad5b0[_0xbff5('0x15')][_0x3b3639]){delete _0xaad5b0[_0xbff5('0x15')][_0x3b3639];}_0x3832e2[_0xbff5('0xe')]();});_0xaad5b0[_0xbff5('0x15')][_0x3b3639]['on'](_0xbff5('0x18'),function(){if(_0xaad5b0['rules'][_0x3b3639]){delete _0xaad5b0[_0xbff5('0x15')][_0x3b3639];}});_0x28448b=setTimeout(function(){logger[_0xbff5('0x4')](_0xbff5('0x19'),_0x3b3639);clearTimeout(_0x28448b);_0x3e49b9[_0xbff5('0x1a')]();_0x3832e2['next']();},_0x505b05);strategy['agent'](_0x3e49b9,_0x40373c,_0xaad5b0,_0x8a1b4d);}else{logger[_0xbff5('0xa')](_0xbff5('0x1b'),_0x3b3639,_0xc134e6['name']);_0x3832e2['stop']();}}}catch(_0x22f9b4){console[_0xbff5('0x1c')](_0x22f9b4);logger[_0xbff5('0xa')]('[%s][QUEUE]\x20%s',_0x3b3639,_0x22f9b4[_0xbff5('0x1d')]);_0x3832e2[_0xbff5('0xe')]();}};};