bbae7e40fc91473273f320f923c9136168c5096f
[motion2.git] / server / services / ami / preview / index.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 _0x4bb5=['VoiceQueueId','lookAgent','execCall','[Preview][execCall][success]','Queue:\x20','\x20IdHopper:\x20','custom:agentcalled','called','Calling','[Preview][execCall][failure]','Call\x20failed','[Blacklist][error]','Contact\x20in\x20black\x20List','active','SIP/%s','reachable','run','execRun','pick','unlock','unlockContact','recallme','validateContact','isValid','checkIsBlackList','[Preview][checkIsBlackList]','[Preview][getContactPreview]','Call\x20unsuccessful','isEmpty','Empty\x20Contact','[Preview][validateContact][Empty\x20Campaign]','Empty\x20Campaign','[Preview][validateContact][Trunk\x20not\x20work]','\x20Trunk\x20is\x20not\x20active','\x20Trunk\x20Backup\x20is\x20not\x20active','Trunk\x20not\x20work','[Preview][validateContact][Campaign\x20Active]','\x20Not\x20Active','campaign\x20Name:\x20','Is\x20Valid','SIP/%s/%s%s','trim','substring','dialCutDigit','getCallerId','dialRandomLastDigitCallerIdNumber','originatecalleridname','addVariables','merge','toLowerVariables','variablesAction','[originated][increment]','OriginateError','[originateFailure][logOriginateFailure]','actionid','clone','isFailure','idContact','rejected','starttime','Answer','[callProgressDetectingAgent][logAnswer]','[syncHangup][talking]','cause','[syncHangup][talking][cause]','statedesc','dialQueueProject','channelstate','transfer','[syncHangup][talking][transfer]','syncDialEnd','destuniqueid','addVariable','variables','filterKey','keys','value','[syncVarSet][Preview]','inspect','transfertargetlinkedid','transfererlinkedid','util','lodash','bluebird','uuid','ioredis','../../../config/environment','../../../config/logger','preview','actionPreview','../ami','./rpcDb','./action','./util/util','redis','localhost','socket.io-emitter','prototype','enqueue','tail','sequence','campaignsPreview','voiceQueues','trunks','actions','agents','clockClearZombieChannels','syncOriginateResponse','bind','hangup','syncHangupRequest','dialend','newexten','syncNewExten','varset','syncVarSet','attendedtransfer','syncAttendedTransfer','blindtransfer','syncBlindTransfer','loopCampaigns','emit','outbound','name','strategy','answered','available','loggedIn','pTalking','sumBillable','sumDuration','sumHoldTime','type','unmanaged','abandoned','waiting','dialActive','dialMethod','dialOriginateCallerIdName','dialOriginateCallerIdNumber','dialPrefix','outboundAnswerAgiCallsDay','outboundAnswerCallsDay','outboundBlacklistCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundDropCallsDayCallersExit','outboundDropCallsDayTimeout','outboundNoAnswerCallsDay','outboundOriginateFailureCallsDay','outboundReCallsDay','outboundRejectCallsDay','outboundUnknownCallsDay','outboundAbandonedCallsDay','predictiveIntervalAnsweredCalls','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalDroppedCallsTimeout','predictiveIntervalErlangCalls','predictiveIntervalErlangCallsDroppedCalls','predictiveIntervalHitRate','predictiveIntervalMultiplicativeFactor','predictiveIntervalPauses','predictiveIntervalAvailable','message','erlangCallToSecond','erlangBusyFactor','startPredictive','Trunk','callerid','Interval','md5','format','voice:queue:%s','voice_queue:save','info','voice_queue_channel:remove','sendMessageOneNotActive','originated','NOT_ACTIVE','logger','\x20is\x20not\x20active','[CampaignPreview]\x20Campaign\x20Queue:\x20','\x20is\x20disactive','syncCampaigns','hasOwnProperty','clearZombieChannels','setMessage','recallMe','clearZombieChannel','[clearZombieChannels][talking]','Queue','queue','stringify','dialAnswer','UserId','Action','status','channel','catch','No\x20such\x20channel','updateOriginated','decrementTalkink','[clearZombieChannel]','loggerError','[Dialer][checkChannel][pTalking][Preview]','[Dialer][checkChannel][Preview]','size','getContactRecallMe','agentReadyId','then','isNil','length','getDiff','scheduledat','dialRecallMeTimeout','Agent','voicePause','logger2','[RecallMe]','disableContact','YYYY-MM-DD\x20HH:mm:ss','logCustomer','RecallInQueue','dialRecallInQueue','createBody','createCustomerHistory','[HistoryDialRecallInQueue][historyCatch]','RecallFailedTimeout','[HistoryRecallClose]','createCustomerFinal','[getContactRecallMe]','IsNotLoggedIn','AGENTS_NOT_LOGGED','isActive','isTrunkReachable','TrunkBackup','TRUNK_IS_NOT_REACHABLE','ACTIVE','callProgressDetectingCustomer','outboundNoSuchCallsDay','countnosuchnumberretry','countglobal','totalGlobal','NoSuchNumber','custom:agentnosuchnumber','dialGlobalMaxRetry','Global','[callProgressDetectingCustomer][logNoSuchGlobal]','rescheduleContact','scheduledAt','dialNoSuchNumberRetryFrequency','unlockAgent','activeContact','linkedid','ANSWER','responsetime','answertime','[syncHangup][talking][increment]','uniqueid','pTalking:\x20','custom:agentConnectPreview','buildAcw','custom:agentcomplete','buildObj','complete','total','[16]','[callProgressDetectingCustomer][logAnswer]','[callProgressDetectingCustomer][logAnswerGlobal]','crateCustomerReportQueue','[syncHangup][talking][decrement]','\x20Queue','BUSY','countbusyretry','busy','[callProgressDetectingCustomer][logBusy]','cloneAction','[callProgressDetectingCustomer][logBusyGlobal]','dialBusyMaxRetry','dialBusyRetryFrequency','NOANSWER','countnoanswerretry','NoAnswer','[callProgressDetectingCustomer][logNoAnswerGlobal]','dialNoAnswerMaxRetry','[callProgressDetectingCustomer][logNoAnswer]','dialNoAnswerRetryFrequency','countcongestionretry','congestion','[callProgressDetectingCustomer][logCongestion]','dialCongestionMaxRetry','CANCEL','countagentrejectretry','AgentReject','custom:agentreject','agentreject','[syncHangupRequest][logAgentReject]','[callProgressDetectingCustomer][logAgentReject]','dialAgentRejectMaxRetry','dialAgentRejectRetryFrequency','ABANDONED','countabandonedretry','[callProgressDetectingCustomer][logAbandoned]','countabandonedetry','dialAbandonedMaxRety','dialAbandonedRetryFrequency','[default]','[Dialer][decrementTalkink][no\x20Hangup][Preview]','dialstatus','[callProgressDetectingCustomer][logUnknown]','[callProgressDetectingCustomer][logUnknownGlobal]','[callProgressDetectingCustomer]','[originated][decrement][callProgressDetectingCustomer]','originated:\x20','destlinkedid','callProgressDetectingAgent','isUndefined','object','logAgent','createAgentHistory','[callProgressDetectingAgent][logNoAnswer]','Busy','Congestion','AnswerAGI','[callProgressDetectingAgent][logAnswerAGI]','reason','[callProgressDetectingAgent][logCongestion]','[callProgressDetectingAgent]','[originated][decrement][callProgressDetectingAgent]','checkInBlack','Contact','phone'];(function(_0x54a761,_0x431fd4){var _0x37d1da=function(_0x5ca617){while(--_0x5ca617){_0x54a761['push'](_0x54a761['shift']());}};_0x37d1da(++_0x431fd4);}(_0x4bb5,0x19f));var _0x54bb=function(_0x1ba3a5,_0x2e3fd1){_0x1ba3a5=_0x1ba3a5-0x0;var _0x3a96e8=_0x4bb5[_0x1ba3a5];return _0x3a96e8;};'use strict';var util=require(_0x54bb('0x0'));var _=require(_0x54bb('0x1'));var BPromise=require(_0x54bb('0x2'));var uuid=require(_0x54bb('0x3'));var moment=require('moment');var md5=require('md5');var Redis=require(_0x54bb('0x4'));var config=require(_0x54bb('0x5'));var logger=require(_0x54bb('0x6'))(_0x54bb('0x7'));var loggerAction=require(_0x54bb('0x6'))(_0x54bb('0x8'));var ami=require(_0x54bb('0x9'));var rpcDb=require(_0x54bb('0xa'));var Action=require(_0x54bb('0xb'));var ut=require(_0x54bb('0xc'));config['redis']=_['defaults'](config[_0x54bb('0xd')],{'host':_0x54bb('0xe'),'port':0x18eb});var io=require(_0x54bb('0xf'))(new Redis(config[_0x54bb('0xd')]));var Sequence=function(){};Sequence[_0x54bb('0x10')][_0x54bb('0x11')]=function(_0x3954df){this['tail']=this[_0x54bb('0x12')]?this[_0x54bb('0x12')]['finally'](_0x3954df):_0x3954df();};function Preview(_0x36870c){this[_0x54bb('0x13')]=new Sequence();this[_0x54bb('0x14')]=_0x36870c[_0x54bb('0x15')];this[_0x54bb('0x16')]=_0x36870c[_0x54bb('0x16')];this[_0x54bb('0x17')]={};this['agents']=_0x36870c[_0x54bb('0x18')];this[_0x54bb('0x19')]=0x0;ami['on']('originateresponse',this[_0x54bb('0x1a')][_0x54bb('0x1b')](this));ami['on'](_0x54bb('0x1c'),this['syncHangup']['bind'](this));ami['on']('hanguprequest',this[_0x54bb('0x1d')]['bind'](this));ami['on'](_0x54bb('0x1e'),this['syncDialEnd'][_0x54bb('0x1b')](this));ami['on'](_0x54bb('0x1f'),this[_0x54bb('0x20')][_0x54bb('0x1b')](this));ami['on'](_0x54bb('0x21'),this[_0x54bb('0x22')][_0x54bb('0x1b')](this));ami['on'](_0x54bb('0x23'),this[_0x54bb('0x24')][_0x54bb('0x1b')](this));ami['on'](_0x54bb('0x25'),this[_0x54bb('0x26')][_0x54bb('0x1b')](this));this[_0x54bb('0x27')](this[_0x54bb('0x14')]);}function emit(_0x1d35a3,_0x381644,_0x28e9f4){io['to'](_0x1d35a3)[_0x54bb('0x28')](_0x381644,_0x28e9f4);}function emitCampaignPreview(_0x45967c){if(_0x45967c['type']===_0x54bb('0x29')){var _0x577a73={'id':_0x45967c['id'],'name':_0x45967c[_0x54bb('0x2a')],'strategy':_0x45967c[_0x54bb('0x2b')],'answered':_0x45967c[_0x54bb('0x2c')],'available':_0x45967c[_0x54bb('0x2d')],'loggedIn':_0x45967c[_0x54bb('0x2e')],'pTalking':_0x45967c[_0x54bb('0x2f')],'sumBillable':_0x45967c[_0x54bb('0x30')],'sumDuration':_0x45967c[_0x54bb('0x31')],'sumHoldTime':_0x45967c[_0x54bb('0x32')]||0x0,'talking':_0x45967c['talking'],'total':_0x45967c['total'],'type':_0x45967c[_0x54bb('0x33')],'unmanaged':_0x45967c[_0x54bb('0x34')],'abandoned':_0x45967c[_0x54bb('0x35')],'waiting':_0x45967c[_0x54bb('0x36')],'loggedInDb':_0x45967c['loggedInDb'],'dialActive':_0x45967c[_0x54bb('0x37')],'dialMethod':_0x45967c[_0x54bb('0x38')],'dialOriginateCallerIdName':_0x45967c[_0x54bb('0x39')],'dialOriginateCallerIdNumber':_0x45967c[_0x54bb('0x3a')],'dialOriginateTimeout':_0x45967c['dialOriginateTimeout'],'dialPrefix':_0x45967c[_0x54bb('0x3b')],'outboundAnswerAgiCallsDay':_0x45967c[_0x54bb('0x3c')],'outboundAnswerCallsDay':_0x45967c[_0x54bb('0x3d')],'outboundBlacklistCallsDay':_0x45967c[_0x54bb('0x3e')],'outboundBusyCallsDay':_0x45967c[_0x54bb('0x3f')],'outboundCongestionCallsDay':_0x45967c[_0x54bb('0x40')],'outboundDropCallsDayACS':_0x45967c['outboundDropCallsDayACS'],'outboundDropCallsDayCallersExit':_0x45967c[_0x54bb('0x41')],'outboundDropCallsDayTimeout':_0x45967c[_0x54bb('0x42')],'outboundNoAnswerCallsDay':_0x45967c[_0x54bb('0x43')],'outboundNoSuchCallsDay':_0x45967c['outboundNoSuchCallsDay'],'outboundOriginateFailureCallsDay':_0x45967c[_0x54bb('0x44')],'outboundReCallsDay':_0x45967c[_0x54bb('0x45')],'outboundRejectCallsDay':_0x45967c[_0x54bb('0x46')],'outboundUnknownCallsDay':_0x45967c[_0x54bb('0x47')],'outboundAbandonedCallsDay':_0x45967c[_0x54bb('0x48')],'predictiveIntervalAnsweredCalls':_0x45967c[_0x54bb('0x49')],'predictiveIntervalAvgHoldtime':_0x45967c[_0x54bb('0x4a')],'predictiveIntervalAvgTalktime':_0x45967c[_0x54bb('0x4b')],'predictiveIntervalDroppedCallsCallersExit':_0x45967c[_0x54bb('0x4c')],'predictiveIntervalDroppedCallsTimeout':_0x45967c[_0x54bb('0x4d')],'predictiveIntervalErlangCalls':_0x45967c[_0x54bb('0x4e')],'predictiveIntervalErlangCallsDroppedCalls':_0x45967c[_0x54bb('0x4f')],'predictiveIntervalHitRate':_0x45967c[_0x54bb('0x50')],'predictiveIntervalMultiplicativeFactor':_0x45967c[_0x54bb('0x51')],'predictiveIntervalPauses':_0x45967c[_0x54bb('0x52')],'predictiveIntervalAvailable':_0x45967c[_0x54bb('0x53')],'predictiveIntervalTotalCalls':_0x45967c['predictiveIntervalTotalCalls'],'message':_0x45967c[_0x54bb('0x54')],'originated':_0x45967c['originated'],'erlangCalls':_0x45967c['erlangCalls'],'erlangCallToSecond':_0x45967c[_0x54bb('0x55')],'erlangAbandonmentRate':_0x45967c['erlangAbandonmentRate'],'erlangBusyFactor':_0x45967c[_0x54bb('0x56')],'startPredictive':_0x45967c[_0x54bb('0x57')],'startProgressive':_0x45967c['startProgressive']};if(_0x45967c['Trunk']){_0x577a73[_0x54bb('0x58')]={'id':_0x45967c[_0x54bb('0x58')]['id'],'name':_0x45967c['Trunk'][_0x54bb('0x2a')],'active':_0x45967c[_0x54bb('0x58')]['active'],'callerid':_0x45967c[_0x54bb('0x58')][_0x54bb('0x59')]};}if(_0x45967c[_0x54bb('0x5a')]){_0x577a73[_0x54bb('0x5a')]={'id':_0x45967c[_0x54bb('0x5a')]['id'],'name':_0x45967c['Interval'][_0x54bb('0x2a')]};}var _0x5c15a0=md5(JSON['stringify'](_0x577a73));if(_0x45967c[_0x54bb('0x5b')]!==_0x5c15a0){_0x45967c[_0x54bb('0x5b')]=_0x5c15a0;emit(util[_0x54bb('0x5c')](_0x54bb('0x5d'),_0x577a73[_0x54bb('0x2a')]),_0x54bb('0x5e'),_0x577a73);}}}function emitVoiceQueueChannelRemove(_0x539d84){logger[_0x54bb('0x5f')]('[DEBUG]\x20Emit\x20voice_queue_channel:remove\x20event',JSON['stringify'](_0x539d84));emit(util['format'](_0x54bb('0x5d'),_0x539d84[_0x54bb('0x2a')]),_0x54bb('0x60'),_0x539d84);}function notSendMessagesQueue(_0x389e7e){if(_0x389e7e[_0x54bb('0x61')]){if(_0x389e7e[_0x54bb('0x62')]===0x0&&_0x389e7e['pTalking']===0x0){_0x389e7e[_0x54bb('0x61')]=![];_0x389e7e['available']=0x0;_0x389e7e['paused']=0x0;_0x389e7e[_0x54bb('0x54')]=_0x54bb('0x63');ut[_0x54bb('0x64')]('[CampaignPreview]\x20Campaign\x20Queue:\x20',_0x389e7e['name']+_0x54bb('0x65'));}else{_0x389e7e[_0x54bb('0x54')]='IS_DISACTIVED';ut[_0x54bb('0x64')](_0x54bb('0x66'),_0x389e7e[_0x54bb('0x2a')]+_0x54bb('0x67'));}emitCampaignPreview(_0x389e7e);}}Preview['prototype'][_0x54bb('0x27')]=function(){var _0x47ae46=this;setInterval(function(){_0x47ae46[_0x54bb('0x68')]();},0x7cf);};Preview[_0x54bb('0x10')][_0x54bb('0x68')]=function(){var _0x495dba=this['campaignsPreview'];this['clockClearZombieChannels']+=0x1;for(var _0x1400ef in _0x495dba){if(_0x495dba[_0x54bb('0x69')](_0x1400ef)&&(_0x495dba[_0x1400ef][_0x54bb('0x38')]===_0x54bb('0x7')||_0x495dba[_0x1400ef][_0x54bb('0x38')]==='booked')&&_0x495dba[_0x1400ef][_0x54bb('0x33')]==='outbound'){if(this[_0x54bb('0x19')]>0x7){this['clockClearZombieChannels']=0x0;this[_0x54bb('0x6a')]();}}if(_0x495dba['hasOwnProperty'](_0x1400ef)&&_0x495dba[_0x1400ef][_0x54bb('0x38')]===_0x54bb('0x7')&&_0x495dba[_0x1400ef][_0x54bb('0x33')]===_0x54bb('0x29')){if(_0x495dba[_0x1400ef][_0x54bb('0x37')]){this[_0x54bb('0x6b')](_0x495dba[_0x1400ef]);this[_0x54bb('0x6c')](_0x495dba[_0x1400ef]);}else{notSendMessagesQueue(_0x495dba[_0x1400ef]);}}}};Preview['prototype'][_0x54bb('0x6d')]=function(_0x3bee77){var _0x865e0a=this;this[_0x54bb('0x13')][_0x54bb('0x11')](function(){if(!_['isNil'](_0x865e0a[_0x54bb('0x17')][_0x3bee77])){loggerAction[_0x54bb('0x5f')](_0x54bb('0x6e'),_0x3bee77,_0x54bb('0x6f'),_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x70')],'originated:\x20',JSON[_0x54bb('0x71')](_0x865e0a['campaignsPreview'][_0x865e0a['actions'][_0x3bee77][_0x54bb('0x70')]]['originated']),'pTalking:\x20',JSON[_0x54bb('0x71')](_0x865e0a[_0x54bb('0x14')][_0x865e0a[_0x54bb('0x17')][_0x3bee77]['queue']][_0x54bb('0x2f')]),JSON[_0x54bb('0x71')](_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x72')]),JSON[_0x54bb('0x71')](_['pick'](_0x865e0a[_0x54bb('0x17')][_0x3bee77],['contactId',_0x54bb('0x73'),'VoiceQueueId','ListId'])));return ami[_0x54bb('0x74')]({'action':_0x54bb('0x75'),'channel':_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x76')]})[_0x54bb('0x77')](function(_0x3a6fb8){if(_0x3a6fb8[_0x54bb('0x54')]===_0x54bb('0x78')){setTimeout(function(){if(_0x865e0a['actions'][_0x3bee77]){ut[_0x54bb('0x79')](_0x865e0a[_0x54bb('0x14')][_0x865e0a[_0x54bb('0x17')][_0x3bee77]['queue']],'[clearZombieChannel]');if(_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x72')]===!![]){ut[_0x54bb('0x7a')](_0x865e0a[_0x54bb('0x14')][_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x70')]],_0x54bb('0x7b'));ut[_0x54bb('0x7c')](_0x54bb('0x7d')+_0x3bee77,_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x70')]);}ut[_0x54bb('0x7c')](_0x54bb('0x7e')+_0x3bee77,_0x865e0a[_0x54bb('0x17')][_0x3bee77][_0x54bb('0x70')]);delete _0x865e0a[_0x54bb('0x17')][_0x3bee77];}},0x2328);}});}});};Preview[_0x54bb('0x10')][_0x54bb('0x6a')]=function(){var _0x212e34=this;loggerAction['info']('[action]',_[_0x54bb('0x7f')](this[_0x54bb('0x17')]));for(var _0x511d09 in this[_0x54bb('0x17')]){if(_0x212e34['actions']['hasOwnProperty'](_0x511d09)){_0x212e34[_0x54bb('0x6d')](_0x511d09);}}};Preview[_0x54bb('0x10')]['recallMe']=function(_0x21b1d6){var _0x1e21e6=this;rpcDb[_0x54bb('0x80')](_0x21b1d6['id'],ut[_0x54bb('0x81')](this[_0x54bb('0x18')]))[_0x54bb('0x82')](function(_0x147673){if(!_[_0x54bb('0x83')](_0x147673)){for(var _0x497fee=0x0;_0x497fee<_0x147673[_0x54bb('0x84')];_0x497fee+=0x1){if(ut[_0x54bb('0x85')](_0x147673[_0x497fee][_0x54bb('0x86')])<_0x21b1d6[_0x54bb('0x87')]*0x3c){if(_0x147673[_0x497fee][_0x54bb('0x88')]&&!_0x147673[_0x497fee]['Agent'][_0x54bb('0x89')]){_0x1e21e6['run'](_0x147673[_0x497fee]['id'])[_0x54bb('0x82')](ut['logger2']('[RecallMe]'))['catch'](ut[_0x54bb('0x8a')](_0x54bb('0x8b')));}else{rpcDb[_0x54bb('0x8c')](_0x147673[_0x497fee]['id']);}}else{var _0x3530fc=new Action(_0x147673[_0x497fee],_0x21b1d6);_0x3530fc['starttime']=moment()[_0x54bb('0x5c')](_0x54bb('0x8d'));_0x21b1d6['outboundReCallsDay']+=0x1;ut[_0x54bb('0x8e')](_0x3530fc,0x17,_0x54bb('0x8f'));if(_0x21b1d6[_0x54bb('0x90')]){rpcDb['rescheduleContactInQueue'](ut[_0x54bb('0x91')](_0x147673[_0x497fee]));rpcDb[_0x54bb('0x92')](_0x3530fc,_0x54bb('0x93'));}else{ut[_0x54bb('0x8e')](_0x3530fc,0x16,_0x54bb('0x94'));rpcDb[_0x54bb('0x92')](_0x3530fc,_0x54bb('0x95'));rpcDb[_0x54bb('0x96')](_0x3530fc,_0x54bb('0x95'));}}}}})[_0x54bb('0x77')](ut[_0x54bb('0x8a')](_0x54bb('0x97')));};Preview[_0x54bb('0x10')][_0x54bb('0x6b')]=function(_0x28fcd0){_0x28fcd0['sendMessageOneNotActive']=!![];if(ut[_0x54bb('0x98')](_0x28fcd0[_0x54bb('0x2e')])){_0x28fcd0['message']=_0x54bb('0x99');}else if(!ut[_0x54bb('0x9a')](_0x28fcd0['dialActive'])){_0x28fcd0[_0x54bb('0x54')]='NOT_ACTIVE';}else if(!this[_0x54bb('0x9b')](_0x28fcd0[_0x54bb('0x58')])){if(!this[_0x54bb('0x9b')](_0x28fcd0[_0x54bb('0x9c')])){_0x28fcd0[_0x54bb('0x54')]=_0x54bb('0x9d');}else{_0x28fcd0[_0x54bb('0x54')]=_0x54bb('0x9e');}}else{_0x28fcd0[_0x54bb('0x54')]=_0x54bb('0x9e');}emitCampaignPreview(_0x28fcd0);};Preview[_0x54bb('0x10')][_0x54bb('0x9f')]=function(_0x567f4b,_0x459f92,_0x5b0941){var _0x589569=this;var _0x1c7182=this[_0x54bb('0x17')][_0x459f92];var _0x56cacd=this[_0x54bb('0x14')][_0x1c7182[_0x54bb('0x70')]];var _0x4db774;if(_0x56cacd){switch(_0x5b0941){case'1':_0x56cacd[_0x54bb('0xa0')]+=0x1;_0x1c7182[_0x54bb('0xa1')]+=0x1;_0x1c7182[_0x54bb('0xa2')]=ut[_0x54bb('0xa3')](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0x0,_0x54bb('0xa4'));ami[_0x54bb('0x28')](_0x54bb('0xa5'),ut['buildObj'](_0x1c7182,'nosuchnumber'));rpcDb['createCustomerHistory'](_0x1c7182,'[callProgressDetectingCustomer][logNoSuch]');if(ut[_0x54bb('0xa3')](_0x1c7182)>=_0x56cacd[_0x54bb('0xa6')]){_0x4db774=ut['cloneAction'](_0x1c7182,0xf,_0x54bb('0xa7'));rpcDb[_0x54bb('0x96')](_0x4db774,_0x54bb('0xa8'));}else{if(_0x1c7182['countnosuchnumberretry']>=_0x56cacd['dialNoSuchNumberMaxRetry']){rpcDb[_0x54bb('0x96')](_0x1c7182,'[callProgressDetectingCustomer][logNoSuchGlobal]');}else{rpcDb[_0x54bb('0xa9')](ut[_0x54bb('0xaa')](_0x1c7182,'countnosuchnumberretry',_0x56cacd[_0x54bb('0xab')]),_0x1c7182[_0x54bb('0xac')],_0x1c7182[_0x54bb('0xad')]);}}delete this[_0x54bb('0x17')][_0x567f4b[_0x54bb('0xae')]];break;case _0x54bb('0xaf'):var _0x25d176=moment()[_0x54bb('0x5c')](_0x54bb('0x8d'));_0x1c7182[_0x54bb('0xb0')]=_0x25d176;_0x1c7182[_0x54bb('0xb1')]=_0x25d176;_0x1c7182[_0x54bb('0x72')]=!![];_0x56cacd[_0x54bb('0x2f')]+=0x1;logger['info'](_0x54bb('0xb2'),_0x1c7182[_0x54bb('0xb3')],'\x20Queue',_0x56cacd['name'],_0x54bb('0xb4'),_0x56cacd[_0x54bb('0x2f')]);ami['emit']('custom:agentconnect',ut['buildObj'](_0x1c7182,'connect'));if(_0x56cacd['acw']){ami['emit'](_0x54bb('0xb5'),ut[_0x54bb('0xb6')](_0x1c7182));}break;case'16':ami['emit'](_0x54bb('0xb7'),ut['buildObj'](_0x1c7182,'complete'));emitVoiceQueueChannelRemove(ut[_0x54bb('0xb8')](_0x1c7182,_0x54bb('0xb9')));_0x56cacd[_0x54bb('0x3d')]+=0x1;_0x56cacd[_0x54bb('0xba')]+=0x1;_0x56cacd[_0x54bb('0x2c')]+=0x1;ut[_0x54bb('0x7a')](_0x56cacd,_0x54bb('0xbb'));_0x1c7182['countglobal']=ut['totalGlobal'](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0x4,'Answer');rpcDb[_0x54bb('0x92')](_0x1c7182,_0x54bb('0xbc'));rpcDb[_0x54bb('0x96')](_0x1c7182,_0x54bb('0xbd'));rpcDb[_0x54bb('0xbe')](_0x1c7182);_0x56cacd[_0x54bb('0x31')]+=_0x1c7182['talktime'];_0x56cacd[_0x54bb('0x30')]+=_0x1c7182['talktime'];logger[_0x54bb('0x5f')](_0x54bb('0xbf'),_0x1c7182[_0x54bb('0xb3')],_0x54bb('0xc0'),_0x56cacd['name'],_0x54bb('0xb4'),_0x56cacd[_0x54bb('0x2f')]);delete this[_0x54bb('0x17')][_0x567f4b[_0x54bb('0xae')]];break;case _0x54bb('0xc1'):_0x56cacd['outboundBusyCallsDay']+=0x1;_0x1c7182[_0x54bb('0xc2')]+=0x1;_0x1c7182[_0x54bb('0xa2')]=ut['totalGlobal'](_0x1c7182);ut['logCustomer'](_0x1c7182,0x5,'Busy');ami['emit']('custom:agentbusy',ut[_0x54bb('0xb8')](_0x1c7182,_0x54bb('0xc3')));rpcDb['createCustomerHistory'](_0x1c7182,_0x54bb('0xc4'));if(ut[_0x54bb('0xa3')](_0x1c7182)>=_0x56cacd[_0x54bb('0xa6')]){_0x4db774=ut[_0x54bb('0xc5')](_0x1c7182,0xf,_0x54bb('0xa7'));rpcDb['createCustomerFinal'](_0x4db774,_0x54bb('0xc6'));}else{if(_0x1c7182[_0x54bb('0xc2')]>=_0x56cacd[_0x54bb('0xc7')]){rpcDb[_0x54bb('0x96')](_0x1c7182,'[callProgressDetectingCustomer][logBusy]');}else{rpcDb[_0x54bb('0xa9')](ut[_0x54bb('0xaa')](_0x1c7182,'countbusyretry',_0x56cacd[_0x54bb('0xc8')]),_0x1c7182[_0x54bb('0xac')],_0x1c7182['activeContact']);}}break;case _0x54bb('0xc9'):_0x56cacd[_0x54bb('0x43')]+=0x1;_0x1c7182[_0x54bb('0xca')]+=0x1;_0x1c7182['countglobal']=ut[_0x54bb('0xa3')](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0x3,_0x54bb('0xcb'));ami['emit']('custom:agentnoanswer',ut['buildObj'](_0x1c7182,'noanswer'));rpcDb[_0x54bb('0x92')](_0x1c7182,'[callProgressDetectingCustomer][logNoAnswer]');if(ut[_0x54bb('0xa3')](_0x1c7182)>=_0x56cacd[_0x54bb('0xa6')]){_0x4db774=ut[_0x54bb('0xc5')](_0x1c7182,0xf,_0x54bb('0xa7'));rpcDb[_0x54bb('0x96')](_0x4db774,_0x54bb('0xcc'));}else{if(_0x1c7182[_0x54bb('0xca')]>=_0x56cacd[_0x54bb('0xcd')]){rpcDb[_0x54bb('0x96')](_0x1c7182,_0x54bb('0xce'));}else{rpcDb[_0x54bb('0xa9')](ut[_0x54bb('0xaa')](_0x1c7182,_0x54bb('0xca'),_0x56cacd[_0x54bb('0xcf')]),_0x1c7182['unlockAgent'],_0x1c7182[_0x54bb('0xad')]);}}break;case'CONGESTION':_0x56cacd[_0x54bb('0x40')]+=0x1;_0x1c7182[_0x54bb('0xd0')]+=0x1;_0x1c7182['countglobal']=ut[_0x54bb('0xa3')](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0x8,'Congestion');ami[_0x54bb('0x28')]('custom:agentcongestion',ut[_0x54bb('0xb8')](_0x1c7182,_0x54bb('0xd1')));rpcDb['createCustomerHistory'](_0x1c7182,_0x54bb('0xd2'));if(ut[_0x54bb('0xa3')](_0x1c7182)>=_0x56cacd[_0x54bb('0xa6')]){_0x4db774=ut[_0x54bb('0xc5')](_0x1c7182,0xf,_0x54bb('0xa7'));rpcDb[_0x54bb('0x96')](_0x4db774,'[callProgressDetectingCustomer][logCongestionGlobal]');}else{if(_0x1c7182[_0x54bb('0xd0')]>=_0x56cacd[_0x54bb('0xd3')]){rpcDb['createCustomerFinal'](_0x1c7182,_0x54bb('0xd2'));}else{rpcDb[_0x54bb('0xa9')](ut[_0x54bb('0xaa')](_0x1c7182,'countcongestionretry',_0x56cacd[_0x54bb('0xc8')]),_0x1c7182[_0x54bb('0xac')],_0x1c7182[_0x54bb('0xad')]);}}break;case _0x54bb('0xd4'):_0x56cacd[_0x54bb('0x46')]+=0x1;_0x1c7182[_0x54bb('0xd5')]+=0x1;_0x1c7182[_0x54bb('0xa2')]=ut[_0x54bb('0xa3')](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0x14,_0x54bb('0xd6'));ami[_0x54bb('0x28')](_0x54bb('0xd7'),ut['buildObj'](_0x1c7182,_0x54bb('0xd8')));rpcDb[_0x54bb('0x92')](_0x1c7182,_0x54bb('0xd9'));if(ut['totalGlobal'](_0x1c7182)>=_0x56cacd['dialGlobalMaxRetry']){_0x4db774=ut[_0x54bb('0xc5')](_0x1c7182,0x14,_0x54bb('0xd6'));rpcDb[_0x54bb('0x96')](_0x4db774,_0x54bb('0xda'));}else{if(_0x1c7182[_0x54bb('0xd5')]>=_0x56cacd[_0x54bb('0xdb')]){rpcDb[_0x54bb('0x96')](_0x1c7182,'[callProgressDetectingCustomer][logAgentReject]');}else{rpcDb[_0x54bb('0xa9')](ut['scheduledAt'](_0x1c7182,_0x54bb('0xd5'),_0x56cacd[_0x54bb('0xdc')]),_0x1c7182['unlockAgent'],_0x1c7182[_0x54bb('0xad')]);}}break;case _0x54bb('0xdd'):_0x56cacd[_0x54bb('0x48')]+=0x1;_0x1c7182[_0x54bb('0xde')]+=0x1;_0x1c7182['countglobal']=ut['totalGlobal'](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0xb,'Abandoned');rpcDb[_0x54bb('0x92')](_0x1c7182,'[callProgressDetectingCustomer][logAbandoned]');if(ut[_0x54bb('0xa3')](_0x1c7182)>=_0x56cacd[_0x54bb('0xa6')]){_0x4db774=ut[_0x54bb('0xc5')](_0x1c7182,0xf,_0x54bb('0xa7'));rpcDb[_0x54bb('0x96')](_0x4db774,_0x54bb('0xdf'));}else{if(_0x1c7182[_0x54bb('0xe0')]>=_0x56cacd[_0x54bb('0xe1')]){rpcDb[_0x54bb('0x96')](_0x1c7182,_0x54bb('0xdf'));}else{rpcDb[_0x54bb('0xa9')](ut['scheduledAt'](_0x1c7182,_0x54bb('0xde'),_0x56cacd[_0x54bb('0xe2')]),_0x1c7182['unlockAgent'],_0x1c7182[_0x54bb('0xad')]);}}break;default:if(_0x1c7182[_0x54bb('0x72')]){ut[_0x54bb('0x7a')](_0x56cacd,_0x54bb('0xe3'));ut[_0x54bb('0x7c')](_0x54bb('0xe4')+_0x56cacd['name'],_0x567f4b);}_0x56cacd[_0x54bb('0x47')]+=0x1;_0x1c7182['countglobal']=ut[_0x54bb('0xa3')](_0x1c7182);ut[_0x54bb('0x8e')](_0x1c7182,0xc,_0x567f4b['cause-txt']||_0x567f4b[_0x54bb('0xe5')]);rpcDb[_0x54bb('0x92')](_0x1c7182,_0x54bb('0xe6'));if(ut[_0x54bb('0xa3')](_0x1c7182)>=_0x56cacd[_0x54bb('0xa6')]){_0x4db774=ut[_0x54bb('0xc5')](_0x1c7182,0xf,'Global');rpcDb['createCustomerFinal'](_0x4db774,_0x54bb('0xe7'));}else{rpcDb[_0x54bb('0x96')](_0x1c7182,'[callProgressDetectingCustomer][logUnknownGlobal]');}delete this['actions'][_0x567f4b[_0x54bb('0xae')]];}if(!(_0x1c7182[_0x54bb('0x72')]&&_0x5b0941==='16')){ut[_0x54bb('0x79')](_0x56cacd,_0x54bb('0xe8'));logger[_0x54bb('0x5f')](_0x54bb('0xe9'),_0x1c7182[_0x54bb('0xb3')],_0x54bb('0xc0'),_0x56cacd[_0x54bb('0x2a')],_0x54bb('0xea'),_0x56cacd['originated']);}if(_0x5b0941!==_0x54bb('0xaf')){delete this['actions'][_0x567f4b[_0x54bb('0xae')]];delete this[_0x54bb('0x17')][_0x567f4b[_0x54bb('0xeb')]];}}};Preview[_0x54bb('0x10')][_0x54bb('0xec')]=function(_0x5d6727,_0x5a32c9,_0x54e05e){if(_['isUndefined'](_0x5a32c9)&&'object'!==typeof _0x5a32c9){return;}if(_[_0x54bb('0xed')](_0x54e05e)&&_0x54bb('0xee')!==typeof _0x54e05e){return;}switch(_0x54e05e['reason']){case'0':ut[_0x54bb('0xef')](_0x5d6727,0x0,_0x54bb('0xa4'));rpcDb[_0x54bb('0xf0')](_0x5d6727,'[callProgressDetectingAgent][logNoSuch]');break;case'3':ut[_0x54bb('0xef')](_0x5d6727,0x3,_0x54bb('0xcb'));rpcDb[_0x54bb('0xf0')](_0x5d6727,_0x54bb('0xf1'));break;case'5':ut[_0x54bb('0xef')](_0x5d6727,0x5,_0x54bb('0xf2'));rpcDb['createAgentHistory'](_0x5d6727,'[callProgressDetectingAgent][logBusy]');break;case'8':ut[_0x54bb('0xef')](_0x5d6727,0x8,_0x54bb('0xf3'));rpcDb[_0x54bb('0xf0')](_0x5d6727,'[callProgressDetectingAgent][logCongestion]');break;case'22':ut['logAgent'](_0x5d6727,0x16,_0x54bb('0xf4'));rpcDb[_0x54bb('0xf0')](_0x5d6727,_0x54bb('0xf5'));break;default:ut['logAgent'](_0x5d6727,0xc,_0x54e05e[_0x54bb('0xf6')]);rpcDb[_0x54bb('0xf0')](_0x5d6727,_0x54bb('0xf7'));}ut[_0x54bb('0x79')](_0x5a32c9,_0x54bb('0xf8'));logger['info'](_0x54bb('0xf9'),_0x5d6727['uniqueid'],'\x20Queue',_0x5a32c9['name'],_0x54bb('0xea'),_0x5a32c9[_0x54bb('0x62')]);delete this['actions'][_0x5d6727[_0x54bb('0xb3')]];};Preview[_0x54bb('0x10')][_0x54bb('0xfa')]=function(_0x897d38,_0x448c4c,_0x319bfe,_0x16652e,_0x4f79e8){var _0x83729=this;return new BPromise(function(_0xe2830,_0x593344){if(_[_0x54bb('0x83')](_0x448c4c)||_[_0x54bb('0x83')](_0x448c4c[_0x54bb('0xfb')])||_[_0x54bb('0x83')](_0x448c4c['Contact'][_0x54bb('0xfc')])||_[_0x54bb('0x83')](_0x448c4c[_0x54bb('0xfd')])){_0x593344(ut['message']('Contact\x20is\x20undefined',_0x16652e,_0x4f79e8));return;}var _0xe78ec6=uuid['v4']();var _0x518c0b=_0x83729[_0x54bb('0x14')][_0x448c4c[_0x54bb('0x6f')][_0x54bb('0x2a')]];var _0x553a8e=_0x319bfe?_0x83729[_0x54bb('0x18')][_0x319bfe]['id']:undefined;_0x83729[_0x54bb('0x17')][_0xe78ec6]=new Action(_0x448c4c,_0x518c0b,_0xe78ec6,_0x319bfe,_0x553a8e);var _0x472e8e=_0x83729[_0x54bb('0x17')][_0xe78ec6];_0x472e8e['unlockAgent']=_0x16652e;_0x472e8e[_0x54bb('0xad')]=_0x4f79e8;_0x472e8e[_0x54bb('0xfe')]=_0x319bfe;if(_['isEmpty'](_0x897d38)){_0x83729[_0x54bb('0xff')](_0x472e8e,_0x518c0b,_0x448c4c,_0x319bfe)[_0x54bb('0x82')](function(_0x25b10b){logger['info'](_0x54bb('0x100'),_0x54bb('0x101')+_0x472e8e[_0x54bb('0x70')]+_0x54bb('0x102')+_0x472e8e['idContact'],JSON[_0x54bb('0x71')](_0x25b10b));ami['emit'](_0x54bb('0x103'),ut[_0x54bb('0xb8')](_0x472e8e,_0x54bb('0x104')));_0xe2830(ut[_0x54bb('0x54')](_0x54bb('0x105')));})['catch'](function(_0x1b6843){ut[_0x54bb('0x64')](_0x54bb('0x106'),_0x1b6843);_0x593344(ut[_0x54bb('0x54')](_0x54bb('0x107'),_0x16652e,_0x4f79e8));});}else{_0x518c0b[_0x54bb('0x3e')]+=0x1;ut['logBlacklist'](_0x472e8e);rpcDb['createHistory'](_0x472e8e,_0x54bb('0x108'));delete _0x83729[_0x54bb('0x17')][_0xe78ec6];_0x593344(ut[_0x54bb('0x54')](_0x54bb('0x109'),_0x16652e,_0x4f79e8));}});};Preview[_0x54bb('0x10')]['isTrunkReachable']=function(_0x3e7f15){return!_[_0x54bb('0x83')](_0x3e7f15)&&!_[_0x54bb('0x83')](_0x3e7f15['name'])&&!_[_0x54bb('0x83')](_0x3e7f15['active'])&&_0x3e7f15[_0x54bb('0x10a')]&&!_[_0x54bb('0x83')](this['trunks'][util[_0x54bb('0x5c')](_0x54bb('0x10b'),_0x3e7f15[_0x54bb('0x2a')])])&&!_['isNil'](this[_0x54bb('0x16')][util[_0x54bb('0x5c')]('SIP/%s',_0x3e7f15[_0x54bb('0x2a')])]['status'])&&(this[_0x54bb('0x16')][util[_0x54bb('0x5c')](_0x54bb('0x10b'),_0x3e7f15[_0x54bb('0x2a')])][_0x54bb('0x75')]===_0x54bb('0x10c')||this[_0x54bb('0x16')][util[_0x54bb('0x5c')](_0x54bb('0x10b'),_0x3e7f15[_0x54bb('0x2a')])]['status']==='unmonitored');};Preview[_0x54bb('0x10')][_0x54bb('0x10d')]=function(_0x4c406c,_0xf8933d){var _0x2f0e69=this;return new BPromise(function(_0x44040a,_0x449af3){_0x2f0e69[_0x54bb('0x10e')](_0x4c406c,_0xf8933d)['then'](function(_0x2e7329){_0x44040a(_[_0x54bb('0x10f')](_0x2e7329,[_0x54bb('0x54')]));})['catch'](function(_0x200d12){if(_0x200d12[_0x54bb('0x110')]){rpcDb[_0x54bb('0x111')](_0x4c406c);}if(_0x200d12['active']){rpcDb['disableContact'](_0x4c406c);}_0x449af3(_[_0x54bb('0x10f')](_0x200d12,[_0x54bb('0x54')]));});});};Preview[_0x54bb('0x10')][_0x54bb('0x10e')]=function(_0x4e302b,_0x1c6680){var _0x4f40c6=this;return new BPromise(function(_0x4d2da9,_0x1004b3){var _0x1996ee,_0x5d9ebf;rpcDb['getContactPreview'](_0x4e302b)[_0x54bb('0x82')](function(_0x74c9ba){if(!_['isNil'](_0x74c9ba[0x0])){_0x5d9ebf=_0x74c9ba[0x0]['recallme']?![]:!![];_0x1996ee=_0x74c9ba[0x0][_0x54bb('0x112')]?!![]:![];_0x1996ee=_0x1c6680?!![]:_0x1996ee;}var _0x272f93=_0x4f40c6[_0x54bb('0x113')](_0x74c9ba);if(_0x272f93[_0x54bb('0x114')]){rpcDb[_0x54bb('0x115')](_['pick'](_0x74c9ba[0x0],['VoiceQueueId','Contact.phone']))[_0x54bb('0x82')](function(_0x2034a2){_0x4f40c6[_0x54bb('0xfa')](_0x2034a2,_0x74c9ba[0x0],_0x1c6680,_0x5d9ebf,_0x1996ee)[_0x54bb('0x82')](function(_0x4b013d){_0x4d2da9(_0x4b013d);})[_0x54bb('0x77')](function(_0x3c4fe5){_0x1004b3(_0x3c4fe5);});})[_0x54bb('0x77')](function(_0x4b6eaf){ut[_0x54bb('0x64')](_0x54bb('0x116'),_0x4b6eaf);_0x1004b3(ut[_0x54bb('0x54')]('Call\x20unsuccessful',_0x5d9ebf,_0x1996ee));});}else{_0x1004b3(ut[_0x54bb('0x54')](_0x272f93[_0x54bb('0x54')],_0x5d9ebf,_0x1996ee));}})[_0x54bb('0x77')](function(_0xd5bf15){ut['logger'](_0x54bb('0x117'),_0xd5bf15);_0x1004b3(ut['message'](_0x54bb('0x118'),![],!![]));});});};Preview[_0x54bb('0x10')][_0x54bb('0x113')]=function(_0x4a6617){if(_[_0x54bb('0x83')](_0x4a6617)||_[_0x54bb('0x119')](_0x4a6617)||!_[_0x54bb('0x83')](_0x4a6617[0x0][_0x54bb('0x88')])&&_[_0x54bb('0x83')](_0x4a6617[0x0][_0x54bb('0x88')][_0x54bb('0x2a')])){ut[_0x54bb('0x64')]('[Preview][validateContact][Empty\x20Contact]',_0x4a6617);return{'isValid':![],'message':_0x54bb('0x11a')};}var _0x107d7d=this[_0x54bb('0x14')][_0x4a6617[0x0][_0x54bb('0x6f')][_0x54bb('0x2a')]];_0x107d7d[_0x54bb('0x54')]=_0x54bb('0x9e');if(_[_0x54bb('0x83')](_0x107d7d)){ut[_0x54bb('0x64')](_0x54bb('0x11b'),_0x107d7d);return{'isValid':![],'message':_0x54bb('0x11c')};}if(!this['isTrunkReachable'](_0x107d7d[_0x54bb('0x58')])){ut[_0x54bb('0x64')](_0x54bb('0x11d'),'campaign\x20Name:\x20'+_0x107d7d[_0x54bb('0x2a')]+_0x54bb('0x11e'));if(!this[_0x54bb('0x9b')](_0x107d7d[_0x54bb('0x9c')])){ut['logger'](_0x54bb('0x11d'),_0x107d7d[_0x54bb('0x2a')]+_0x54bb('0x11f'));return{'isValid':![],'message':_0x54bb('0x120')};}}if(!ut[_0x54bb('0x9a')](_0x107d7d['dialActive'])){ut[_0x54bb('0x64')](_0x54bb('0x121'),_0x107d7d['name']+_0x54bb('0x122'));return{'isValid':![],'message':_0x54bb('0x123')+_0x107d7d[_0x54bb('0x2a')]+_0x54bb('0x122')};}return{'isValid':!![],'message':_0x54bb('0x124')};};Preview[_0x54bb('0x10')][_0x54bb('0xff')]=function(_0x1d942e,_0x281f37,_0x215b68,_0x9e7677){var _0xc417b8=this;return new BPromise(function(_0x55a4b1,_0x483bc8){var _0x2918ac=_0x1d942e[_0x54bb('0xb3')];var _0x597ab6=_0xc417b8[_0x54bb('0x9b')](_0x281f37[_0x54bb('0x58')])?util['format'](_0x54bb('0x125'),_0x281f37[_0x54bb('0x58')][_0x54bb('0x2a')],_[_0x54bb('0x83')](_0x281f37[_0x54bb('0x3b')])?'':_0x281f37[_0x54bb('0x3b')][_0x54bb('0x126')]()||'',_0x281f37['dialCutDigit']>0x0?_0x215b68[_0x54bb('0xfb')][_0x54bb('0xfc')][_0x54bb('0x127')](_0x281f37[_0x54bb('0x128')]):_0x215b68['Contact'][_0x54bb('0xfc')]):util[_0x54bb('0x5c')](_0x54bb('0x125'),_['isNil'](_0x281f37[_0x54bb('0x9c')])?_0x281f37['Trunk'][_0x54bb('0x2a')]:_0x281f37[_0x54bb('0x9c')][_0x54bb('0x2a')],_[_0x54bb('0x83')](_0x281f37['dialPrefix'])?'':_0x281f37[_0x54bb('0x3b')]['trim']()||'',_0x281f37[_0x54bb('0x128')]>0x0?_0x215b68['Contact'][_0x54bb('0xfc')][_0x54bb('0x127')](_0x281f37['dialCutDigit']):_0x215b68[_0x54bb('0xfb')][_0x54bb('0xfc')]);var _0x138d05=_0xc417b8[_0x54bb('0x9b')](_0x281f37[_0x54bb('0x58')])?ut[_0x54bb('0x129')](_0x281f37[_0x54bb('0x58')][_0x54bb('0x59')],_0x281f37[_0x54bb('0x39')],_0x281f37['dialRandomLastDigitCallerIdNumber']>0x0?ut['getCallerIdRandom'](_0x281f37[_0x54bb('0x3a')],_0x281f37[_0x54bb('0x12a')]):_0x281f37[_0x54bb('0x3a')]):ut[_0x54bb('0x129')](_['isNil'](_0x281f37[_0x54bb('0x9c')])?_0x281f37[_0x54bb('0x58')][_0x54bb('0x59')]:_0x281f37['TrunkBackup'][_0x54bb('0x59')],_0x281f37[_0x54bb('0x39')],_0x281f37[_0x54bb('0x12a')]>0x0?ut['getCallerIdRandom'](_0x281f37[_0x54bb('0x3a')],_0x281f37[_0x54bb('0x12a')]):_0x281f37['dialOriginateCallerIdNumber']);if(_0x138d05){_0x1d942e[_0x54bb('0x12b')]=ut['extractCalleridName'](_0x138d05);_0x1d942e['originatecalleridnum']=ut['extractCalleridNumber'](_0x138d05);}var _0x15275f=ut[_0x54bb('0x12c')](_0x281f37,_0x215b68,_0x597ab6,_0x138d05,_0x2918ac,_0x1d942e);_[_0x54bb('0x12d')](_0x1d942e,ut[_0x54bb('0x12e')](_0x15275f));_0x1d942e['starttime']=moment()[_0x54bb('0x5c')](_0x54bb('0x8d'));ami['Action'](ut[_0x54bb('0x12f')](_0x1d942e,_0x281f37,_0x15275f,_0x1d942e[_0x54bb('0xad')],_0x9e7677))['then'](function(_0x1272f){_0x281f37['originated']+=0x1;logger[_0x54bb('0x5f')](_0x54bb('0x130'),_0x2918ac,_0x54bb('0xc0'),_0x281f37['name'],_0x54bb('0xea'),_0x281f37[_0x54bb('0x62')]);_0x55a4b1(_0x1272f);})[_0x54bb('0x77')](function(_0x561602){ut[_0x54bb('0xef')](_0x1d942e,0xe,_0x54bb('0x131'));rpcDb[_0x54bb('0xf0')](_0x1d942e,_0x54bb('0x132'));_0x483bc8(_0x561602);});});};Preview[_0x54bb('0x10')]['syncNewExten']=function(_0x359387){if(this['actions'][_0x359387['linkedid']]){this[_0x54bb('0x17')][_0x359387['linkedid']][_0x54bb('0x76')]=_0x359387[_0x54bb('0x76')];}};Preview['prototype'][_0x54bb('0x1a')]=function(_0x40f0e2){var _0x485f8c=this;var _0x4276e7=this['actions'][_0x40f0e2[_0x54bb('0x133')]];if(_0x4276e7){if(_0x4276e7['lookAgent']&&this[_0x54bb('0x18')][_0x4276e7[_0x54bb('0xfe')]]){ut['logLookAgent'](_0x4276e7,this[_0x54bb('0x18')][_0x4276e7[_0x54bb('0xfe')]][_0x54bb('0x2a')],this[_0x54bb('0x18')][_0x4276e7[_0x54bb('0xfe')]]['id']);}var _0x3c45e5=_[_0x54bb('0x134')](_0x4276e7);_0x3c45e5['responsetime']=moment()[_0x54bb('0x5c')](_0x54bb('0x8d'));var _0x409bcb=_0x485f8c[_0x54bb('0x14')][_0x4276e7[_0x54bb('0x70')]];if(ut[_0x54bb('0x135')](_0x40f0e2['response'])){if(_0x4276e7[_0x54bb('0xac')]){rpcDb[_0x54bb('0x111')](_0x4276e7[_0x54bb('0x136')]);}if(_0x4276e7['activeContact']){rpcDb[_0x54bb('0x8c')](_0x4276e7['idContact']);}ami[_0x54bb('0x28')]('custom:agentringnoanswer',ut[_0x54bb('0xb8')](_0x4276e7,_0x54bb('0x137')));this[_0x54bb('0xec')](_0x3c45e5,_0x409bcb,_0x40f0e2);}else{_0x4276e7[_0x54bb('0x138')]=moment()[_0x54bb('0x5c')](_0x54bb('0x8d'));ut[_0x54bb('0xef')](_0x3c45e5,0x4,_0x54bb('0x139'));rpcDb['createAgentHistory'](_0x3c45e5,_0x54bb('0x13a'));}}};Preview['prototype']['syncHangup']=function(_0x530e06){var _0x5100fd=this;var _0x13e224=this[_0x54bb('0x17')][_0x530e06['linkedid']];var _0x273f06;if(_0x13e224){_0x273f06=this['campaignsPreview'][_0x13e224['queue']];logger['info'](_0x54bb('0x13b'),_0x530e06[_0x54bb('0xae')],_0x54bb('0xc0'),_0x273f06[_0x54bb('0x2a')],_0x54bb('0xb4'),_0x273f06['pTalking']);}if(this[_0x54bb('0x17')][_0x530e06['linkedid']]&&_0x530e06['linkedid']!==_0x530e06['uniqueid']){if(_0x530e06[_0x54bb('0x13c')]==='16'&&this['actions'][_0x530e06['linkedid']][_0x54bb('0x72')]){this['callProgressDetectingCustomer'](_0x530e06,_0x530e06[_0x54bb('0xae')],_0x530e06['cause']);}else if(this[_0x54bb('0x17')][_0x530e06[_0x54bb('0xae')]][_0x54bb('0x72')]){logger[_0x54bb('0x5f')](_0x54bb('0x13d'),_0x530e06[_0x54bb('0xae')],_0x530e06[_0x54bb('0x13c')],_0x54bb('0xc0'),_0x273f06[_0x54bb('0x2a')],_0x54bb('0xb4'),_0x273f06[_0x54bb('0x2f')]);this['callProgressDetectingCustomer'](_0x530e06,_0x530e06[_0x54bb('0xae')],_0x530e06['cause']);}}else if(_0x13e224&&_[_0x54bb('0x83')](_0x13e224[_0x54bb('0x13e')])&&_0x273f06[_0x54bb('0x13f')]&&_0x530e06[_0x54bb('0xae')]===_0x530e06[_0x54bb('0xb3')]&&_[_0x54bb('0x83')](_0x530e06[_0x54bb('0xf6')])&&_0x530e06[_0x54bb('0x13c')]==='16'&&_0x530e06[_0x54bb('0x140')]==='6'&&_['isUndefined'](_0x13e224[_0x54bb('0x141')])){if(_0x13e224['unlockAgent']){rpcDb[_0x54bb('0x111')](_0x13e224[_0x54bb('0x136')]);}if(_0x13e224[_0x54bb('0xad')]){rpcDb['disableContact'](_0x13e224[_0x54bb('0x136')]);}_0x530e06[_0x54bb('0xf6')]='22';this['callProgressDetectingAgent'](_0x13e224,_0x273f06,_0x530e06);}else if(_0x13e224&&_0x13e224[_0x54bb('0x141')]){if(_0x530e06['cause']==='16'&&this[_0x54bb('0x17')][_0x530e06[_0x54bb('0xae')]][_0x54bb('0x72')]){logger[_0x54bb('0x5f')](_0x54bb('0x142'),_0x530e06['linkedid'],_0x530e06[_0x54bb('0x13c')],'\x20Queue',_0x273f06[_0x54bb('0x2a')],'pTalking:\x20',_0x273f06['pTalking']);this[_0x54bb('0x9f')](_0x530e06,_0x530e06[_0x54bb('0xae')],_0x530e06[_0x54bb('0x13c')]);}else if(this[_0x54bb('0x17')][_0x530e06[_0x54bb('0xae')]][_0x54bb('0x72')]){logger[_0x54bb('0x5f')](_0x54bb('0x13d'),_0x530e06['linkedid'],_0x530e06[_0x54bb('0x13c')],_0x54bb('0xc0'),_0x273f06[_0x54bb('0x2a')],_0x54bb('0xb4'),_0x273f06[_0x54bb('0x2f')]);this['callProgressDetectingCustomer'](_0x530e06,_0x530e06['linkedid'],_0x530e06[_0x54bb('0x13c')]);}}};Preview['prototype'][_0x54bb('0x143')]=function(_0x10c0c3){if(this[_0x54bb('0x17')][_0x10c0c3['destlinkedid']]&&_0x10c0c3[_0x54bb('0xeb')]!==_0x10c0c3[_0x54bb('0x144')]){this['callProgressDetectingCustomer'](_0x10c0c3,_0x10c0c3[_0x54bb('0xeb')],_0x10c0c3[_0x54bb('0xe5')]);}};Preview[_0x54bb('0x10')][_0x54bb('0x1d')]=function(_0x132aa7){if(this['actions'][_0x132aa7[_0x54bb('0xae')]]&&_0x132aa7[_0x54bb('0xae')]!==_0x132aa7[_0x54bb('0xb3')]&&!this[_0x54bb('0x17')][_0x132aa7[_0x54bb('0xae')]][_0x54bb('0x72')]){if(_0x132aa7[_0x54bb('0x13c')]==='1'){this['callProgressDetectingCustomer'](_0x132aa7,_0x132aa7[_0x54bb('0xae')],_0x132aa7[_0x54bb('0x13c')]);}}};Preview[_0x54bb('0x10')][_0x54bb('0x145')]=function(_0x10553d,_0x4f9da8,_0x5a9d97){if(this[_0x54bb('0x17')][_0x10553d]){if(_[_0x54bb('0x83')](this[_0x54bb('0x17')][_0x10553d][_0x54bb('0x146')])){this[_0x54bb('0x17')][_0x10553d]['variables']={};}this['actions'][_0x10553d][_0x54bb('0x146')][_0x4f9da8]=_0x5a9d97;}};Preview[_0x54bb('0x10')][_0x54bb('0x22')]=function(_0x179ff6){try{if(!_[_0x54bb('0x83')](_0x179ff6)){if(ut[_0x54bb('0x147')](_[_0x54bb('0x148')](_0x179ff6['variable'])[0x0])){this['addVariable'](_0x179ff6[_0x54bb('0xb3')],_['keys'](_0x179ff6['variable'])[0x0],_0x179ff6[_0x54bb('0x149')]);}}}catch(_0x3e9c6f){logger['error'](_0x54bb('0x14a'),util[_0x54bb('0x14b')](_0x3e9c6f,{'showHidden':![],'depth':null}));}};Preview[_0x54bb('0x10')]['syncAttendedTransfer']=function(_0xe91530){if(_0xe91530){if(this['actions'][_0xe91530[_0x54bb('0x14c')]]){this[_0x54bb('0x17')][_0xe91530[_0x54bb('0x14c')]][_0x54bb('0x141')]=!![];}}};Preview[_0x54bb('0x10')][_0x54bb('0x26')]=function(_0x1d684e){if(_0x1d684e){if(this[_0x54bb('0x17')][_0x1d684e['transfererlinkedid']]){this['actions'][_0x1d684e[_0x54bb('0x14d')]]['transfer']=!![];}}};module['exports']=Preview;