cc0cef36d0bd658897ec4ca0b45a8dad31c2462f
[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 _0xa504=['validate','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','map','message','agents','timeout','createQueue','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0xa504,0x128));var _0x4a50=function(_0x5980c0,_0x3af95b){_0x5980c0=_0x5980c0-0x0;var _0x5c3fe1=_0xa504[_0x5980c0];return _0x5c3fe1;};'use strict';var schema=require(_0x4a50('0x0'));var _=require(_0x4a50('0x1'));var util=require(_0x4a50('0x2'));var seqqueue=require(_0x4a50('0x3'));var logger=require(_0x4a50('0x4'))(_0x4a50('0x5'));var strategy=require(_0x4a50('0x6'));var queue=schema({'name':{'type':'string','required':!![],'message':_0x4a50('0x7')},'timeout':{'type':_0x4a50('0x8'),'message':_0x4a50('0x9')}});function writeLog(_0x36887d,_0x3ba890,_0x1c7210){return logger[_0x4a50('0xa')](util[_0x4a50('0xb')](_0x4a50('0xc'),_0x36887d,_0x3ba890['name'],_0x1c7210));}function handleFindAgent(_0x200d6c){return function(_0x2755f3){return _0x2755f3[_0x4a50('0xd')]['toLowerCase']()===_0x200d6c[_0x4a50('0xe')]();};}exports[_0x4a50('0xf')]=function(_0x5e7661,_0x5bd916,_0x17ec3f,_0x27cc40){return function(_0x15e5a7){try{var _0x365e9a={'name':_0x5bd916[0x0],'timeout':_0x5bd916[0x1]};var _0x3f5561=queue[_0x4a50('0x0')](_0x365e9a,{'typecast':!![]});if(_0x3f5561[_0x4a50('0x10')]){logger[_0x4a50('0x11')](_0x4a50('0x12'),_0x5e7661,_[_0x4a50('0x13')](_0x3f5561,_0x4a50('0x14'))['join'](',\x20'));_0x15e5a7['stop']();}else{var _0xaf1a8a=_['find'](_0x17ec3f[_0x4a50('0x15')],handleFindAgent(_0x365e9a['name']));if(_0xaf1a8a){var _0xa9acd5=(_0x365e9a[_0x4a50('0x16')]||0xa)*0x3e8;var _0x85c926,_0x2abe23;var _0x21e969=seqqueue[_0x4a50('0x17')](_0xa9acd5);_0x21e969['id']=_0x5e7661;_0x21e969[_0x4a50('0x18')]=_0xa9acd5;_0x21e969[_0x4a50('0x19')]=_0x27cc40[_0x4a50('0x19')];writeLog(_0x5e7661,_0xaf1a8a,util[_0x4a50('0xb')](_0x4a50('0x1a'),_0xa9acd5));_0x17ec3f[_0x4a50('0x1b')][_0x5e7661]['on'](_0x4a50('0x1c'),function(){logger[_0x4a50('0xa')](_0x4a50('0x1d'),_0x5e7661);clearTimeout(_0x2abe23);_0x2abe23=undefined;_0x21e969[_0x4a50('0x1e')]();if(_0x17ec3f[_0x4a50('0x1b')][_0x5e7661]){delete _0x17ec3f[_0x4a50('0x1b')][_0x5e7661];}_0x15e5a7[_0x4a50('0x1f')]();});_0x17ec3f[_0x4a50('0x1b')][_0x5e7661]['on'](_0x4a50('0x20'),function(){if(_0x17ec3f[_0x4a50('0x1b')][_0x5e7661]){delete _0x17ec3f[_0x4a50('0x1b')][_0x5e7661];}});_0x2abe23=setTimeout(function(){logger['info'](_0x4a50('0x21'),_0x5e7661);clearTimeout(_0x2abe23);_0x21e969['close']();_0x15e5a7[_0x4a50('0x22')]();},_0xa9acd5);strategy[_0x4a50('0x23')](_0x21e969,_0xaf1a8a,_0x17ec3f,_0x27cc40);}else{logger[_0x4a50('0x11')](_0x4a50('0x24'),_0x5e7661,_0x365e9a['name']);_0x15e5a7[_0x4a50('0x1f')]();}}}catch(_0x3d59f9){console['log'](_0x3d59f9);logger[_0x4a50('0x11')]('[%s][QUEUE]\x20%s',_0x5e7661,_0x3d59f9['stack']);_0x15e5a7['stop']();}};};