Built motion from commit 9d0783e6.|2.6.13
[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 _0xe0ba=['RECALLINQUEUE','RECALLFAILEDTIMEOUT','TRUNK_IS_NOT_REACHABLE','CAMPAIGN_STATUS','dialMethod','preview','isPreviewCampaign','type','ivr','isIVRCampaign','outbound','isOutboundQueue','dialActive','isQueueCampaignActive','active','isIVRCampaignActive','milliseconds','seconds','getSeconds','message','loggedIn','loggedInDb','paused','talking','pTalking','waiting','inUse','originated','Trunk','name','dialTimezone','dialGlobalInterval','isNil','Interval','Intervals','NULL_INTERVAL','isEmpty','EMPTY_INTERVAL','reachable','unmonitored','includes','status','TrunkBackup','DISACTIVED','NO_AGENTS_LOGGED','UNREACHABLE_TRUNK','getQueueCampaignStatusMessage','INACTIVE','match','string','isUndefined','\x22%s\x22\x20<%s>','format','\x22\x22\x20<>','getCallerId','\x5cw{0,','pow','replace','random','toString','getCallerIdRandom','error','[decrementOriginate]\x20queue\x20originate\x20value\x20is\x20negative','decrementOriginate','erlangb','lodash','moment','util','dialer','../../../../config/environment/shared','timezones','ACTIVE','RESCHEDULED_CONTACTS','DEACTIVATED','IS_DISACTIVED','AGENTS_NOT_LOGGED','AVAILABLE_CONTACTS_FINISHED','INTERVAL_IS_OVERTIME','GLOBAL_INTERVAL_IS_OVERTIME'];(function(_0x227d99,_0x48c20e){var _0x759e24=function(_0x3e9e0f){while(--_0x3e9e0f){_0x227d99['push'](_0x227d99['shift']());}};_0x759e24(++_0x48c20e);}(_0xe0ba,0x90));var _0xae0b=function(_0xbd08b4,_0x4790ed){_0xbd08b4=_0xbd08b4-0x0;var _0x314f1e=_0xe0ba[_0xbd08b4];return _0x314f1e;};'use strict';var _=require(_0xae0b('0x0'));var moment=require(_0xae0b('0x1'));var util=require(_0xae0b('0x2'));var logger=require('../../../../config/logger')(_0xae0b('0x3'));var timezones=require(_0xae0b('0x4'))[_0xae0b('0x5')];var CAMPAIGN_STATUS={'ACTIVE':_0xae0b('0x6'),'BLACKLIST':'BLACKLIST','CONTACTS_RESCHEDULED':_0xae0b('0x7'),'DEACTIVATED':_0xae0b('0x8'),'DISACTIVED':_0xae0b('0x9'),'EMPTY_INTERVAL':'INTERVAL_IS_EMPTY','INACTIVE':'NOT_ACTIVE','NO_AGENTS_LOGGED':_0xae0b('0xa'),'NO_AVAILABLE_CONTACTS':_0xae0b('0xb'),'NULL_INTERVAL':'INTERVAL_IS_NULL','OVERTIME_INTERVAL':_0xae0b('0xc'),'OVERTIME_GLOBAL_INTERVAL':_0xae0b('0xd'),'QUEUE_RECALL':_0xae0b('0xe'),'RECALL_TIMEOUT':_0xae0b('0xf'),'RUNNING':'RUNNING','UNKNOWN_TIMEZONE':'TIMEZONE_UNKNOW','UNREACHABLE_TRUNK':_0xae0b('0x10')};exports[_0xae0b('0x11')]=CAMPAIGN_STATUS;function isPreviewCampaign(_0x1d76fb){return _0x1d76fb[_0xae0b('0x12')]===_0xae0b('0x13');}exports[_0xae0b('0x14')]=isPreviewCampaign;function isIVRCampaign(_0x407fa4){return _0x407fa4[_0xae0b('0x15')]===_0xae0b('0x16');}exports[_0xae0b('0x17')]=isIVRCampaign;function isOutboundQueue(_0x3bc1f8){return _0x3bc1f8[_0xae0b('0x15')]===_0xae0b('0x18');}exports[_0xae0b('0x19')]=isOutboundQueue;function isQueueCampaignActive(_0x346f35){return _0x346f35[_0xae0b('0x1a')];}exports[_0xae0b('0x1b')]=isQueueCampaignActive;function isIVRCampaignActive(_0x3c4016){return _0x3c4016[_0xae0b('0x1c')];}exports[_0xae0b('0x1d')]=isIVRCampaignActive;function getSeconds(_0x433bee,_0x3374e3){var _0x2d7701=moment(_0x433bee)[_0xae0b('0x1e')](0x0);var _0xac5e80=moment(_0x3374e3)['milliseconds'](0x0);return _0x2d7701['diff'](_0xac5e80,_0xae0b('0x1f'));}exports[_0xae0b('0x20')]=getSeconds;function hasQueueCampaignDataChanged(_0x3cf864,_0xc53945){var _0x2212ed=![];var _0x4df00e=_0x3cf864[_0xae0b('0x12')]!==_0xc53945['dialMethod']||_0x3cf864['dialActive']!==_0xc53945[_0xae0b('0x1a')]||_0x3cf864[_0xae0b('0x21')]!==_0xc53945[_0xae0b('0x21')];var _0x4f0461=_0x3cf864['available']!==_0xc53945['available']||_0x3cf864[_0xae0b('0x22')]!==_0xc53945[_0xae0b('0x22')]||_0x3cf864[_0xae0b('0x23')]!==_0xc53945['loggedInDb']||_0x3cf864[_0xae0b('0x24')]!==_0xc53945[_0xae0b('0x24')]||_0x3cf864[_0xae0b('0x25')]!==_0xc53945['talking']||_0x3cf864[_0xae0b('0x26')]!==_0xc53945[_0xae0b('0x26')]||_0x3cf864[_0xae0b('0x27')]!==_0xc53945[_0xae0b('0x27')]||_0x3cf864[_0xae0b('0x28')]!==_0xc53945['inUse']||_0x3cf864[_0xae0b('0x29')]!==_0xc53945[_0xae0b('0x29')];if(_0x3cf864[_0xae0b('0x2a')]&&_0xc53945[_0xae0b('0x2a')]){_0x2212ed=_0x3cf864[_0xae0b('0x2a')][_0xae0b('0x2b')]!==_0xc53945[_0xae0b('0x2a')][_0xae0b('0x2b')]||_0x3cf864[_0xae0b('0x2a')][_0xae0b('0x1c')]!==_0xc53945[_0xae0b('0x2a')]['active'];}return _0x4df00e||_0x4f0461||_0x2212ed;}exports['hasQueueCampaignDataChanged']=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0x58efc6){var _0x1db846=null;var _0x49c486=_0x58efc6[_0xae0b('0x2c')];if(_['isNil'](_0x58efc6[_0xae0b('0x2d')])||_[_0xae0b('0x2e')](_0x58efc6[_0xae0b('0x2f')])||_[_0xae0b('0x2e')](_0x58efc6[_0xae0b('0x2f')][_0xae0b('0x30')])){_0x1db846=CAMPAIGN_STATUS[_0xae0b('0x31')];}else if(_[_0xae0b('0x32')](_0x58efc6[_0xae0b('0x2d')])||_['isEmpty'](_0x58efc6[_0xae0b('0x2f')][_0xae0b('0x30')])){_0x1db846=CAMPAIGN_STATUS[_0xae0b('0x33')];}else if(_0x49c486&&!timezones[_0x49c486]){_0x1db846=CAMPAIGN_STATUS['UNKNOWN_TIMEZONE'];}return _0x1db846;}function checkAnyValidTrunk(_0x2eba21,_0x348b5c){var _0x4245a6=null;var _0x4b4a64='SIP/';var _0x14dd9a=[_0xae0b('0x34'),_0xae0b('0x35')];var _0x56afd7=!![];if(_0x2eba21['Trunk']&&_0x2eba21[_0xae0b('0x2a')]['active']){_0x4b4a64+=_0x2eba21[_0xae0b('0x2a')][_0xae0b('0x2b')];_0x4245a6=_0x348b5c[_0x4b4a64];_0x56afd7=_0x14dd9a[_0xae0b('0x36')](_0x4245a6[_0xae0b('0x37')]);}else if(_0x2eba21[_0xae0b('0x38')]&&_0x2eba21[_0xae0b('0x38')]['active']){_0x4b4a64+=_0x2eba21[_0xae0b('0x38')][_0xae0b('0x2b')];_0x4245a6=_0x348b5c[_0x4b4a64];_0x56afd7=_0x14dd9a['includes'](_0x4245a6[_0xae0b('0x37')]);}return _0x56afd7;}function getQueueCampaignStatusMessage(_0x68fd43,_0x260262){var _0x3a5717=CAMPAIGN_STATUS[_0xae0b('0x6')];var _0x150187=isPreviewCampaign(_0x68fd43);if(!isQueueCampaignActive(_0x68fd43)){if(_0x150187){_0x3a5717=CAMPAIGN_STATUS['INACTIVE'];}else{if(_0x68fd43[_0xae0b('0x29')]===0x0&&_0x68fd43[_0xae0b('0x25')]===0x0&&_0x68fd43['waiting']===0x0&&(_0x68fd43[_0xae0b('0x26')]||0x0)===0x0){_0x3a5717=CAMPAIGN_STATUS['INACTIVE'];}else{_0x3a5717=CAMPAIGN_STATUS[_0xae0b('0x39')];}}}else if(_0x68fd43[_0xae0b('0x22')]===0x0){_0x3a5717=CAMPAIGN_STATUS[_0xae0b('0x3a')];}else if(!checkAnyValidTrunk(_0x68fd43,_0x260262)){_0x3a5717=CAMPAIGN_STATUS[_0xae0b('0x3b')];}else if(!isPreviewCampaign(_0x68fd43)){var _0x1e1525=checkAnyValidQueueCampaignInterval(_0x68fd43);if(_0x1e1525){_0x3a5717=_0x1e1525;}}return _0x3a5717;}exports[_0xae0b('0x3c')]=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0xdc1907){var _0x1cd519=CAMPAIGN_STATUS['DISACTIVED'];if(_0xdc1907[_0xae0b('0x29')]===0x0&&_0xdc1907[_0xae0b('0x25')]===0x0&&_0xdc1907[_0xae0b('0x27')]===0x0&&(_0xdc1907['pTalking']||0x0)===0x0){_0x1cd519=CAMPAIGN_STATUS[_0xae0b('0x3d')];}return _0x1cd519;}exports['getQueueCampaignActiveStatusMessage']=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x552341){var _0x5a1919=_0x552341[_0xae0b('0x3e')](/"(.*?)"/);return _0x5a1919?_0x5a1919[0x1]:_0x552341;}exports['extractCalleridName']=extractCalleridName;function getCallerId(_0x5f5142,_0x25bec1,_0x17a489){if(!_['isUndefined'](_0x17a489)&&typeof _0x17a489===_0xae0b('0x3f')&&!_[_0xae0b('0x32')](_0x17a489)){if(!_[_0xae0b('0x40')](_0x25bec1)&&typeof _0x25bec1===_0xae0b('0x3f')&&!_[_0xae0b('0x32')](_0x25bec1)){return util['format'](_0xae0b('0x41'),_0x25bec1,_0x17a489);}return util[_0xae0b('0x42')](_0xae0b('0x41'),_0x17a489,_0x17a489);}if(!_[_0xae0b('0x40')](_0x5f5142)&&typeof _0x5f5142===_0xae0b('0x3f')&&!_[_0xae0b('0x32')](_0x5f5142)){return _0x5f5142;}return _0xae0b('0x43');}exports[_0xae0b('0x44')]=getCallerId;function getCallerIdRandom(_0x359fc1,_0x43d05c){var _0x49956d;var _0x29c5e6;var _0x93bc9a;if(_0x43d05c<=0x0){_0x43d05c=0x1;}_0x49956d=new RegExp(_0xae0b('0x45')+_0x43d05c+'}$');_0x29c5e6=Math[_0xae0b('0x46')](0xa,_0x43d05c-0x1);_0x93bc9a=Math[_0xae0b('0x46')](0xa,_0x43d05c)-0x1;return util[_0xae0b('0x42')]('%s',_[_0xae0b('0x47')](_0x359fc1,_0x49956d,_[_0xae0b('0x48')](_0x29c5e6,_0x93bc9a)[_0xae0b('0x49')]()));}exports[_0xae0b('0x4a')]=getCallerIdRandom;function decrementOriginate(_0x339cc7){if(_0x339cc7[_0xae0b('0x29')]&&_0x339cc7[_0xae0b('0x29')]>0x0){_0x339cc7[_0xae0b('0x29')]-=0x1;}else{logger[_0xae0b('0x4b')](_0xae0b('0x4c'));}}exports[_0xae0b('0x4d')]=decrementOriginate;function checkContactEmpty(_0x1669f6){return _0x1669f6&&_0x1669f6['length']>0x0;}exports['checkContactEmpty']=checkContactEmpty;function erlangb(_0x296949,_0x29f32a){if(_0x29f32a===0x0){return 0x0;}var _0x184f1c=0x1;for(var _0x4f9344=0x1;_0x4f9344<=_0x29f32a;_0x4f9344+=0x1){_0x184f1c=0x1+_0x184f1c*_0x4f9344/_0x296949;}return 0x1/_0x184f1c;}exports[_0xae0b('0x4e')]=erlangb;function checkContactLowerLimitOriginate(_0x28227f,_0x3b20cf,_0x45824a){if(_0x3b20cf>_0x45824a){for(var _0x5d53ec=0x0;_0x5d53ec<_0x3b20cf-_0x45824a;_0x5d53ec+=0x1){decrementOriginate(_0x28227f);}}}exports['checkContactLowerLimitOriginate']=checkContactLowerLimitOriginate;