Built motion from commit 55091a5c.|2.6.30
[motion2.git] / server / services / ami / dialer / utils / 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 _0x971d=['checkContactLowerLimitOriginate','createdAt','updatedAt','undefined','description','toUpperCase','toString','substring','XMD-','moment','../../../../config/logger','../../../../config/environment/shared','timezones','BLACKLIST','IS_DISACTIVED','NOT_ACTIVE','AVAILABLE_CONTACTS_FINISHED','INTERVAL_IS_NULL','INTERVAL_IS_OVERTIME','GLOBAL_INTERVAL_IS_OVERTIME','RECALLFAILEDTIMEOUT','RUNNING','TIMEZONE_UNKNOW','CAMPAIGN_STATUS','dialMethod','preview','isPreviewCampaign','type','ivr','outbound','isOutboundQueue','dialActive','isQueueCampaignActive','milliseconds','diff','seconds','getSeconds','message','available','loggedIn','paused','talking','pTalking','waiting','inUse','originated','Trunk','name','active','hasQueueCampaignDataChanged','dialTimezone','dialGlobalInterval','isNil','Interval','Intervals','isEmpty','UNKNOWN_TIMEZONE','SIP/','reachable','unmonitored','includes','status','TrunkBackup','ACTIVE','INACTIVE','DISACTIVED','UNREACHABLE_TRUNK','getQueueCampaignStatusMessage','getQueueCampaignActiveStatusMessage','match','isUndefined','format','\x22%s\x22\x20<%s>','string','getCallerId','pow','replace','random','error','[decrementOriginate]\x20queue\x20originate\x20value','length','[checkContactLowerLimitOriginate]\x20'];(function(_0x1468d5,_0x27eb4b){var _0x550f83=function(_0x3fecce){while(--_0x3fecce){_0x1468d5['push'](_0x1468d5['shift']());}};_0x550f83(++_0x27eb4b);}(_0x971d,0x1a3));var _0xd971=function(_0x4e5597,_0xf42177){_0x4e5597=_0x4e5597-0x0;var _0x5654f9=_0x971d[_0x4e5597];return _0x5654f9;};'use strict';var _=require('lodash');var moment=require(_0xd971('0x0'));var util=require('util');var logger=require(_0xd971('0x1'))('dialer');var timezones=require(_0xd971('0x2'))[_0xd971('0x3')];var CAMPAIGN_STATUS={'ACTIVE':'ACTIVE','BLACKLIST':_0xd971('0x4'),'CONTACTS_RESCHEDULED':'RESCHEDULED_CONTACTS','DEACTIVATED':'DEACTIVATED','DISACTIVED':_0xd971('0x5'),'EMPTY_INTERVAL':'INTERVAL_IS_EMPTY','INACTIVE':_0xd971('0x6'),'NO_AGENTS_LOGGED':'AGENTS_NOT_LOGGED','NO_AVAILABLE_CONTACTS':_0xd971('0x7'),'NULL_INTERVAL':_0xd971('0x8'),'OVERTIME_INTERVAL':_0xd971('0x9'),'OVERTIME_GLOBAL_INTERVAL':_0xd971('0xa'),'QUEUE_RECALL':'RECALLINQUEUE','RECALL_TIMEOUT':_0xd971('0xb'),'RUNNING':_0xd971('0xc'),'UNKNOWN_TIMEZONE':_0xd971('0xd'),'UNREACHABLE_TRUNK':'TRUNK_IS_NOT_REACHABLE'};exports[_0xd971('0xe')]=CAMPAIGN_STATUS;function isPreviewCampaign(_0x330117){return _0x330117[_0xd971('0xf')]===_0xd971('0x10');}exports[_0xd971('0x11')]=isPreviewCampaign;function isIVRCampaign(_0x15face){return _0x15face[_0xd971('0x12')]===_0xd971('0x13');}exports['isIVRCampaign']=isIVRCampaign;function isOutboundQueue(_0x5940f0){return _0x5940f0[_0xd971('0x12')]===_0xd971('0x14');}exports[_0xd971('0x15')]=isOutboundQueue;function isQueueCampaignActive(_0x987d3f){return _0x987d3f[_0xd971('0x16')];}exports[_0xd971('0x17')]=isQueueCampaignActive;function isIVRCampaignActive(_0x38b2d6){return _0x38b2d6['active'];}exports['isIVRCampaignActive']=isIVRCampaignActive;function getSeconds(_0xf2df45,_0x2a8e1e){var _0x5aee08=moment(_0xf2df45)[_0xd971('0x18')](0x0);var _0x6b39e2=moment(_0x2a8e1e)[_0xd971('0x18')](0x0);return _0x5aee08[_0xd971('0x19')](_0x6b39e2,_0xd971('0x1a'));}exports[_0xd971('0x1b')]=getSeconds;function hasQueueCampaignDataChanged(_0x22476d,_0x4ba093){var _0x41c514=![];var _0x32e3df=_0x22476d[_0xd971('0xf')]!==_0x4ba093['dialMethod']||_0x22476d[_0xd971('0x16')]!==_0x4ba093[_0xd971('0x16')]||_0x22476d[_0xd971('0x1c')]!==_0x4ba093[_0xd971('0x1c')];var _0x1728c9=_0x22476d[_0xd971('0x1d')]!==_0x4ba093[_0xd971('0x1d')]||_0x22476d[_0xd971('0x1e')]!==_0x4ba093[_0xd971('0x1e')]||_0x22476d['loggedInDb']!==_0x4ba093['loggedInDb']||_0x22476d[_0xd971('0x1f')]!==_0x4ba093['paused']||_0x22476d[_0xd971('0x20')]!==_0x4ba093[_0xd971('0x20')]||_0x22476d[_0xd971('0x21')]!==_0x4ba093[_0xd971('0x21')]||_0x22476d[_0xd971('0x22')]!==_0x4ba093['waiting']||_0x22476d[_0xd971('0x23')]!==_0x4ba093[_0xd971('0x23')]||_0x22476d[_0xd971('0x24')]!==_0x4ba093[_0xd971('0x24')];if(_0x22476d[_0xd971('0x25')]&&_0x4ba093['Trunk']){_0x41c514=_0x22476d[_0xd971('0x25')][_0xd971('0x26')]!==_0x4ba093[_0xd971('0x25')]['name']||_0x22476d['Trunk'][_0xd971('0x27')]!==_0x4ba093[_0xd971('0x25')]['active'];}return _0x32e3df||_0x1728c9||_0x41c514;}exports[_0xd971('0x28')]=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0x537cfd){var _0x302b92=null;var _0x358dc3=_0x537cfd[_0xd971('0x29')];if(_['isNil'](_0x537cfd[_0xd971('0x2a')])||_[_0xd971('0x2b')](_0x537cfd[_0xd971('0x2c')])||_[_0xd971('0x2b')](_0x537cfd[_0xd971('0x2c')][_0xd971('0x2d')])){_0x302b92=CAMPAIGN_STATUS['NULL_INTERVAL'];}else if(_[_0xd971('0x2e')](_0x537cfd[_0xd971('0x2a')])||_[_0xd971('0x2e')](_0x537cfd[_0xd971('0x2c')][_0xd971('0x2d')])){_0x302b92=CAMPAIGN_STATUS['EMPTY_INTERVAL'];}else if(_0x358dc3&&!timezones[_0x358dc3]){_0x302b92=CAMPAIGN_STATUS[_0xd971('0x2f')];}return _0x302b92;}function checkAnyValidTrunk(_0x95cadc,_0x11bec1){var _0x5d2b98=null;var _0xf74b6b=_0xd971('0x30');var _0x5ced31=[_0xd971('0x31'),_0xd971('0x32')];var _0x5ac11c=!![];if(_0x95cadc[_0xd971('0x25')]&&_0x95cadc[_0xd971('0x25')][_0xd971('0x27')]){_0xf74b6b+=_0x95cadc['Trunk'][_0xd971('0x26')];_0x5d2b98=_0x11bec1[_0xf74b6b];_0x5ac11c=_0x5ced31[_0xd971('0x33')](_0x5d2b98[_0xd971('0x34')]);}else if(_0x95cadc[_0xd971('0x35')]&&_0x95cadc['TrunkBackup'][_0xd971('0x27')]){_0xf74b6b+=_0x95cadc[_0xd971('0x35')]['name'];_0x5d2b98=_0x11bec1[_0xf74b6b];_0x5ac11c=_0x5ced31[_0xd971('0x33')](_0x5d2b98[_0xd971('0x34')]);}return _0x5ac11c;}function getQueueCampaignStatusMessage(_0x426057,_0x3a185d){var _0x3c1c99=CAMPAIGN_STATUS[_0xd971('0x36')];var _0x4b077a=isPreviewCampaign(_0x426057);if(!isQueueCampaignActive(_0x426057)){if(_0x4b077a){_0x3c1c99=CAMPAIGN_STATUS[_0xd971('0x37')];}else{if(_0x426057[_0xd971('0x24')]===0x0&&_0x426057['talking']===0x0&&_0x426057['waiting']===0x0&&(_0x426057[_0xd971('0x21')]||0x0)===0x0){_0x3c1c99=CAMPAIGN_STATUS[_0xd971('0x37')];}else{_0x3c1c99=CAMPAIGN_STATUS[_0xd971('0x38')];}}}else if(_0x426057[_0xd971('0x1e')]===0x0){_0x3c1c99=CAMPAIGN_STATUS['NO_AGENTS_LOGGED'];}else if(!checkAnyValidTrunk(_0x426057,_0x3a185d)){_0x3c1c99=CAMPAIGN_STATUS[_0xd971('0x39')];}else if(!isPreviewCampaign(_0x426057)){var _0x190395=checkAnyValidQueueCampaignInterval(_0x426057);if(_0x190395){_0x3c1c99=_0x190395;}}return _0x3c1c99;}exports[_0xd971('0x3a')]=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0x19d55b){var _0xc45644=CAMPAIGN_STATUS[_0xd971('0x38')];if(_0x19d55b[_0xd971('0x24')]===0x0&&_0x19d55b['talking']===0x0&&_0x19d55b[_0xd971('0x22')]===0x0&&(_0x19d55b['pTalking']||0x0)===0x0){_0xc45644=CAMPAIGN_STATUS['INACTIVE'];}return _0xc45644;}exports[_0xd971('0x3b')]=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x4ae420){var _0x4e88de=_0x4ae420[_0xd971('0x3c')](/"(.*?)"/);return _0x4e88de?_0x4e88de[0x1]:_0x4ae420;}exports['extractCalleridName']=extractCalleridName;function getCallerId(_0x19a264,_0x5ef0e4,_0x1167db){if(!_[_0xd971('0x3d')](_0x1167db)&&typeof _0x1167db==='string'&&!_['isEmpty'](_0x1167db)){if(!_[_0xd971('0x3d')](_0x5ef0e4)&&typeof _0x5ef0e4==='string'&&!_[_0xd971('0x2e')](_0x5ef0e4)){return util['format']('\x22%s\x22\x20<%s>',_0x5ef0e4,_0x1167db);}return util[_0xd971('0x3e')](_0xd971('0x3f'),_0x1167db,_0x1167db);}if(!_[_0xd971('0x3d')](_0x19a264)&&typeof _0x19a264===_0xd971('0x40')&&!_[_0xd971('0x2e')](_0x19a264)){return _0x19a264;}return'\x22\x22\x20<>';}exports[_0xd971('0x41')]=getCallerId;function getCallerIdRandom(_0x2e7541,_0x154b87){var _0xefead6;var _0x53c474;var _0x13b105;if(_0x154b87<=0x0){_0x154b87=0x1;}_0xefead6=new RegExp('\x5cw{0,'+_0x154b87+'}$');_0x53c474=Math[_0xd971('0x42')](0xa,_0x154b87-0x1);_0x13b105=Math[_0xd971('0x42')](0xa,_0x154b87)-0x1;return util[_0xd971('0x3e')]('%s',_[_0xd971('0x43')](_0x2e7541,_0xefead6,_[_0xd971('0x44')](_0x53c474,_0x13b105)['toString']()));}exports['getCallerIdRandom']=getCallerIdRandom;function decrementOriginate(_0x41460d,_0x113cb9){if(_0x41460d[_0xd971('0x24')]&&_0x41460d[_0xd971('0x24')]>0x0){_0x41460d[_0xd971('0x24')]-=0x1;}else{logger[_0xd971('0x45')](_0xd971('0x46'),_0x113cb9);}}exports['decrementOriginate']=decrementOriginate;function checkContactEmpty(_0x4b3787){return _0x4b3787&&_0x4b3787[_0xd971('0x47')]>0x0;}exports['checkContactEmpty']=checkContactEmpty;function erlangb(_0x323d07,_0x2e855b){if(_0x2e855b===0x0){return 0x0;}var _0x24c1c7=0x1;for(var _0x1404bc=0x1;_0x1404bc<=_0x2e855b;_0x1404bc+=0x1){_0x24c1c7=0x1+_0x24c1c7*_0x1404bc/_0x323d07;}return 0x1/_0x24c1c7;}exports['erlangb']=erlangb;function checkContactLowerLimitOriginate(_0x4d5b7b,_0xcde3a3,_0x1875c6){if(_0xcde3a3>_0x1875c6){for(var _0x3f0c30=0x0;_0x3f0c30<_0xcde3a3-_0x1875c6;_0x3f0c30+=0x1){decrementOriginate(_0x4d5b7b,_0xd971('0x48'));}}}exports[_0xd971('0x49')]=checkContactLowerLimitOriginate;function setXMDContactVariables(_0x2ec52f){var _0x29a189={};var _0x336453=['id',_0xd971('0x4a'),'tags',_0xd971('0x4b')];const _0x40dd75=0xfa;if(_0x2ec52f){for(var _0x200500 in _0x2ec52f){if(typeof _0x2ec52f[_0x200500]!==_0xd971('0x4c')){if(!_[_0xd971('0x2b')](_0x2ec52f[_0x200500])&&!_0x336453['includes'](_0x200500)){if(_0x200500===_0xd971('0x4d')&&_0x2ec52f[_0x200500]['length']>_0x40dd75){_0x29a189['XMD-'+_0x200500[_0xd971('0x4e')]()]=_0x2ec52f[_0x200500][_0xd971('0x4f')]()[_0xd971('0x50')](0x0,_0x40dd75);}else{_0x29a189[_0xd971('0x51')+_0x200500['toUpperCase']()]=_0x2ec52f[_0x200500];}}}}}return _0x29a189;}exports['setXMDContactVariables']=setXMDContactVariables;