Built motion from commit 0900f080.|2.5.45
[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 _0x509b=['[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','validate','length','error','map','message','stop','find','agents','timeout','atimeout','channel','START:%s','rules','end','info','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','log','[%s][QUEUE]\x20%s','stack','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','format'];(function(_0xe25ee9,_0x1f6d98){var _0x56c669=function(_0x32e81a){while(--_0x32e81a){_0xe25ee9['push'](_0xe25ee9['shift']());}};_0x56c669(++_0x1f6d98);}(_0x509b,0x6a));var _0xb509=function(_0x58d1a5,_0x4aa6a3){_0x58d1a5=_0x58d1a5-0x0;var _0x3c5943=_0x509b[_0x58d1a5];return _0x3c5943;};'use strict';var schema=require('validate');var _=require(_0xb509('0x0'));var util=require(_0xb509('0x1'));var seqqueue=require(_0xb509('0x2'));var logger=require(_0xb509('0x3'))(_0xb509('0x4'));var strategy=require(_0xb509('0x5'));var queue=schema({'name':{'type':_0xb509('0x6'),'required':!![],'message':_0xb509('0x7')},'timeout':{'type':_0xb509('0x8'),'message':_0xb509('0x9')}});function writeLog(_0xa3c539,_0x579aa,_0xdfa13c){return logger['info'](util[_0xb509('0xa')](_0xb509('0xb'),_0xa3c539,_0x579aa[_0xb509('0xc')],_0xdfa13c));}function handleFindAgent(_0x48df6a){return function(_0x375e53){return _0x375e53[_0xb509('0xc')][_0xb509('0xd')]()===_0x48df6a[_0xb509('0xd')]();};}exports[_0xb509('0xe')]=function(_0x14b203,_0x4b8007,_0x4f6b4a,_0x2d6046){return function(_0x162893){try{var _0x3dc1e8={'name':_0x4b8007[0x0],'timeout':_0x4b8007[0x1]};var _0xd205cc=queue[_0xb509('0xf')](_0x3dc1e8,{'typecast':!![]});if(_0xd205cc[_0xb509('0x10')]){logger[_0xb509('0x11')]('[%s][AGENT]\x20%s',_0x14b203,_[_0xb509('0x12')](_0xd205cc,_0xb509('0x13'))['join'](',\x20'));_0x162893[_0xb509('0x14')]();}else{var _0x17e0ab=_[_0xb509('0x15')](_0x4f6b4a[_0xb509('0x16')],handleFindAgent(_0x3dc1e8[_0xb509('0xc')]));if(_0x17e0ab){var _0x486222=(_0x3dc1e8[_0xb509('0x17')]||0xa)*0x3e8;var _0x4b010d,_0x5e2480;var _0x5da88c=seqqueue['createQueue'](_0x486222);_0x5da88c['id']=_0x14b203;_0x5da88c[_0xb509('0x18')]=_0x486222;_0x5da88c[_0xb509('0x19')]=_0x2d6046['channel'];writeLog(_0x14b203,_0x17e0ab,util[_0xb509('0xa')](_0xb509('0x1a'),_0x486222));_0x4f6b4a[_0xb509('0x1b')][_0x14b203]['on'](_0xb509('0x1c'),function(){logger[_0xb509('0x1d')](_0xb509('0x1e'),_0x14b203);clearTimeout(_0x5e2480);_0x5e2480=undefined;_0x5da88c[_0xb509('0x1f')]();if(_0x4f6b4a['rules'][_0x14b203]){delete _0x4f6b4a[_0xb509('0x1b')][_0x14b203];}_0x162893['stop']();});_0x4f6b4a[_0xb509('0x1b')][_0x14b203]['on'](_0xb509('0x20'),function(){if(_0x4f6b4a[_0xb509('0x1b')][_0x14b203]){delete _0x4f6b4a[_0xb509('0x1b')][_0x14b203];}});_0x5e2480=setTimeout(function(){logger['info'](_0xb509('0x21'),_0x14b203);clearTimeout(_0x5e2480);_0x5da88c['close']();_0x162893[_0xb509('0x22')]();},_0x486222);strategy[_0xb509('0x23')](_0x5da88c,_0x17e0ab,_0x4f6b4a,_0x2d6046);}else{logger[_0xb509('0x11')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x14b203,_0x3dc1e8[_0xb509('0xc')]);_0x162893[_0xb509('0x14')]();}}}catch(_0x1c9159){console[_0xb509('0x24')](_0x1c9159);logger[_0xb509('0x11')](_0xb509('0x25'),_0x14b203,_0x1c9159[_0xb509('0x26')]);_0x162893['stop']();}};};