8007fce101fe67abc5ac37368bcabff5e2c8b5dd
[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 _0x876f=['[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','../../../../config/logger','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','length','error','[%s][AGENT]\x20%s','map','message','join','stop','find','createQueue','atimeout','channel','format','START:%s','rules','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x876f,0xdc));var _0xf876=function(_0x3f6453,_0x22aafe){_0x3f6453=_0x3f6453-0x0;var _0x318184=_0x876f[_0x3f6453];return _0x318184;};'use strict';var schema=require(_0xf876('0x0'));var _=require(_0xf876('0x1'));var util=require(_0xf876('0x2'));var seqqueue=require(_0xf876('0x3'));var logger=require(_0xf876('0x4'))('routing');var strategy=require('./strategy');var queue=schema({'name':{'type':_0xf876('0x5'),'required':!![],'message':_0xf876('0x6')},'timeout':{'type':_0xf876('0x7'),'message':_0xf876('0x8')}});function writeLog(_0x33c60f,_0x4b646b,_0x4e4f64){return logger[_0xf876('0x9')](util['format'](_0xf876('0xa'),_0x33c60f,_0x4b646b['name'],_0x4e4f64));}function handleFindAgent(_0x693ef2){return function(_0xdc22ff){return _0xdc22ff[_0xf876('0xb')][_0xf876('0xc')]()===_0x693ef2[_0xf876('0xc')]();};}exports['consequence']=function(_0x45de7b,_0x263c78,_0x1b3d5c,_0x2b8b63){return function(_0x3c78ef){try{var _0x3b453b={'name':_0x263c78[0x0],'timeout':_0x263c78[0x1]};var _0x44288c=queue[_0xf876('0x0')](_0x3b453b,{'typecast':!![]});if(_0x44288c[_0xf876('0xd')]){logger[_0xf876('0xe')](_0xf876('0xf'),_0x45de7b,_[_0xf876('0x10')](_0x44288c,_0xf876('0x11'))[_0xf876('0x12')](',\x20'));_0x3c78ef[_0xf876('0x13')]();}else{var _0x4787a0=_[_0xf876('0x14')](_0x1b3d5c['agents'],handleFindAgent(_0x3b453b['name']));if(_0x4787a0){var _0x1dc320=(_0x3b453b['timeout']||0xa)*0x3e8;var _0x2f2740,_0x367d52;var _0x3aaf9a=seqqueue[_0xf876('0x15')](_0x1dc320);_0x3aaf9a['id']=_0x45de7b;_0x3aaf9a[_0xf876('0x16')]=_0x1dc320;_0x3aaf9a['channel']=_0x2b8b63[_0xf876('0x17')];writeLog(_0x45de7b,_0x4787a0,util[_0xf876('0x18')](_0xf876('0x19'),_0x1dc320));_0x1b3d5c[_0xf876('0x1a')][_0x45de7b]['on']('end',function(){logger['info']('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x45de7b);clearTimeout(_0x367d52);_0x367d52=undefined;_0x3aaf9a[_0xf876('0x1b')]();if(_0x1b3d5c['rules'][_0x45de7b]){delete _0x1b3d5c[_0xf876('0x1a')][_0x45de7b];}_0x3c78ef[_0xf876('0x13')]();});_0x1b3d5c['rules'][_0x45de7b]['on'](_0xf876('0x1c'),function(){if(_0x1b3d5c[_0xf876('0x1a')][_0x45de7b]){delete _0x1b3d5c[_0xf876('0x1a')][_0x45de7b];}});_0x367d52=setTimeout(function(){logger[_0xf876('0x9')](_0xf876('0x1d'),_0x45de7b);clearTimeout(_0x367d52);_0x3aaf9a[_0xf876('0x1b')]();_0x3c78ef[_0xf876('0x1e')]();},_0x1dc320);strategy[_0xf876('0x1f')](_0x3aaf9a,_0x4787a0,_0x1b3d5c,_0x2b8b63);}else{logger[_0xf876('0xe')](_0xf876('0x20'),_0x45de7b,_0x3b453b[_0xf876('0xb')]);_0x3c78ef[_0xf876('0x13')]();}}}catch(_0x545073){console[_0xf876('0x21')](_0x545073);logger[_0xf876('0xe')](_0xf876('0x22'),_0x45de7b,_0x545073[_0xf876('0x23')]);_0x3c78ef[_0xf876('0x13')]();}};};