Built motion from commit 7ab0e143.|2.5.49
[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 _0xe7c1=['channel','START:%s','rules','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','error','log','stack','seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','toLowerCase','consequence','validate','length','[%s][AGENT]\x20%s','map','message','stop','find','name','timeout','createQueue','atimeout'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xe7c1,0x18d));var _0x1e7c=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0xe7c1[_0xa464c9];return _0x3d73c4;};'use strict';var schema=require('validate');var _=require('lodash');var util=require('util');var seqqueue=require(_0x1e7c('0x0'));var logger=require(_0x1e7c('0x1'))(_0x1e7c('0x2'));var strategy=require(_0x1e7c('0x3'));var queue=schema({'name':{'type':_0x1e7c('0x4'),'required':!![],'message':_0x1e7c('0x5')},'timeout':{'type':_0x1e7c('0x6'),'message':_0x1e7c('0x7')}});function writeLog(_0x1472c6,_0x5cae4d,_0x3d9534){return logger[_0x1e7c('0x8')](util[_0x1e7c('0x9')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x1472c6,_0x5cae4d['name'],_0x3d9534));}function handleFindAgent(_0x10d30f){return function(_0x5363fd){return _0x5363fd['name'][_0x1e7c('0xa')]()===_0x10d30f['toLowerCase']();};}exports[_0x1e7c('0xb')]=function(_0x3cef20,_0x21b493,_0x1db98a,_0x256fae){return function(_0x57f995){try{var _0x1119f9={'name':_0x21b493[0x0],'timeout':_0x21b493[0x1]};var _0x110b5b=queue[_0x1e7c('0xc')](_0x1119f9,{'typecast':!![]});if(_0x110b5b[_0x1e7c('0xd')]){logger['error'](_0x1e7c('0xe'),_0x3cef20,_[_0x1e7c('0xf')](_0x110b5b,_0x1e7c('0x10'))['join'](',\x20'));_0x57f995[_0x1e7c('0x11')]();}else{var _0x5cc077=_[_0x1e7c('0x12')](_0x1db98a['agents'],handleFindAgent(_0x1119f9[_0x1e7c('0x13')]));if(_0x5cc077){var _0xeeb356=(_0x1119f9[_0x1e7c('0x14')]||0xa)*0x3e8;var _0xa60eb,_0x821bc9;var _0x3cad14=seqqueue[_0x1e7c('0x15')](_0xeeb356);_0x3cad14['id']=_0x3cef20;_0x3cad14[_0x1e7c('0x16')]=_0xeeb356;_0x3cad14[_0x1e7c('0x17')]=_0x256fae[_0x1e7c('0x17')];writeLog(_0x3cef20,_0x5cc077,util['format'](_0x1e7c('0x18'),_0xeeb356));_0x1db98a[_0x1e7c('0x19')][_0x3cef20]['on']('end',function(){logger[_0x1e7c('0x8')](_0x1e7c('0x1a'),_0x3cef20);clearTimeout(_0x821bc9);_0x821bc9=undefined;_0x3cad14[_0x1e7c('0x1b')]();if(_0x1db98a[_0x1e7c('0x19')][_0x3cef20]){delete _0x1db98a[_0x1e7c('0x19')][_0x3cef20];}_0x57f995['stop']();});_0x1db98a[_0x1e7c('0x19')][_0x3cef20]['on'](_0x1e7c('0x1c'),function(){if(_0x1db98a[_0x1e7c('0x19')][_0x3cef20]){delete _0x1db98a[_0x1e7c('0x19')][_0x3cef20];}});_0x821bc9=setTimeout(function(){logger[_0x1e7c('0x8')](_0x1e7c('0x1d'),_0x3cef20);clearTimeout(_0x821bc9);_0x3cad14[_0x1e7c('0x1b')]();_0x57f995[_0x1e7c('0x1e')]();},_0xeeb356);strategy[_0x1e7c('0x1f')](_0x3cad14,_0x5cc077,_0x1db98a,_0x256fae);}else{logger[_0x1e7c('0x20')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x3cef20,_0x1119f9[_0x1e7c('0x13')]);_0x57f995[_0x1e7c('0x11')]();}}}catch(_0x5cc9a1){console[_0x1e7c('0x21')](_0x5cc9a1);logger[_0x1e7c('0x20')]('[%s][QUEUE]\x20%s',_0x3cef20,_0x5cc9a1[_0x1e7c('0x22')]);_0x57f995[_0x1e7c('0x11')]();}};};