Built motion from commit e02f907f.|2.6.14
[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 _0x1e63=['loggedInDb','paused','talking','pTalking','waiting','inUse','originated','Trunk','name','dialGlobalInterval','isNil','Interval','Intervals','NULL_INTERVAL','isEmpty','EMPTY_INTERVAL','SIP/','unmonitored','includes','status','TrunkBackup','INACTIVE','DISACTIVED','NO_AGENTS_LOGGED','UNREACHABLE_TRUNK','getQueueCampaignStatusMessage','getQueueCampaignActiveStatusMessage','extractCalleridName','isUndefined','string','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','getCallerId','\x5cw{0,','pow','replace','random','toString','getCallerIdRandom','error','decrementOriginate','checkContactEmpty','erlangb','checkContactLowerLimitOriginate','lodash','moment','../../../../config/logger','../../../../config/environment/shared','ACTIVE','BLACKLIST','RESCHEDULED_CONTACTS','DEACTIVATED','IS_DISACTIVED','INTERVAL_IS_EMPTY','NOT_ACTIVE','AGENTS_NOT_LOGGED','AVAILABLE_CONTACTS_FINISHED','INTERVAL_IS_NULL','INTERVAL_IS_OVERTIME','GLOBAL_INTERVAL_IS_OVERTIME','RECALLINQUEUE','RECALLFAILEDTIMEOUT','RUNNING','TIMEZONE_UNKNOW','TRUNK_IS_NOT_REACHABLE','CAMPAIGN_STATUS','dialMethod','preview','isPreviewCampaign','type','ivr','outbound','isOutboundQueue','dialActive','active','isIVRCampaignActive','milliseconds','diff','seconds','message','available','loggedIn'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x1e63,0x126));var _0x31e6=function(_0x77984a,_0x3c05ae){_0x77984a=_0x77984a-0x0;var _0x277be9=_0x1e63[_0x77984a];return _0x277be9;};'use strict';var _=require(_0x31e6('0x0'));var moment=require(_0x31e6('0x1'));var util=require('util');var logger=require(_0x31e6('0x2'))('dialer');var timezones=require(_0x31e6('0x3'))['timezones'];var CAMPAIGN_STATUS={'ACTIVE':_0x31e6('0x4'),'BLACKLIST':_0x31e6('0x5'),'CONTACTS_RESCHEDULED':_0x31e6('0x6'),'DEACTIVATED':_0x31e6('0x7'),'DISACTIVED':_0x31e6('0x8'),'EMPTY_INTERVAL':_0x31e6('0x9'),'INACTIVE':_0x31e6('0xa'),'NO_AGENTS_LOGGED':_0x31e6('0xb'),'NO_AVAILABLE_CONTACTS':_0x31e6('0xc'),'NULL_INTERVAL':_0x31e6('0xd'),'OVERTIME_INTERVAL':_0x31e6('0xe'),'OVERTIME_GLOBAL_INTERVAL':_0x31e6('0xf'),'QUEUE_RECALL':_0x31e6('0x10'),'RECALL_TIMEOUT':_0x31e6('0x11'),'RUNNING':_0x31e6('0x12'),'UNKNOWN_TIMEZONE':_0x31e6('0x13'),'UNREACHABLE_TRUNK':_0x31e6('0x14')};exports[_0x31e6('0x15')]=CAMPAIGN_STATUS;function isPreviewCampaign(_0x7399d9){return _0x7399d9[_0x31e6('0x16')]===_0x31e6('0x17');}exports[_0x31e6('0x18')]=isPreviewCampaign;function isIVRCampaign(_0x4db513){return _0x4db513[_0x31e6('0x19')]===_0x31e6('0x1a');}exports['isIVRCampaign']=isIVRCampaign;function isOutboundQueue(_0x11b22e){return _0x11b22e[_0x31e6('0x19')]===_0x31e6('0x1b');}exports[_0x31e6('0x1c')]=isOutboundQueue;function isQueueCampaignActive(_0x10a3e0){return _0x10a3e0[_0x31e6('0x1d')];}exports['isQueueCampaignActive']=isQueueCampaignActive;function isIVRCampaignActive(_0x83840b){return _0x83840b[_0x31e6('0x1e')];}exports[_0x31e6('0x1f')]=isIVRCampaignActive;function getSeconds(_0x3bf3f6,_0x29f738){var _0x22e5b4=moment(_0x3bf3f6)[_0x31e6('0x20')](0x0);var _0xdbb9c3=moment(_0x29f738)[_0x31e6('0x20')](0x0);return _0x22e5b4[_0x31e6('0x21')](_0xdbb9c3,_0x31e6('0x22'));}exports['getSeconds']=getSeconds;function hasQueueCampaignDataChanged(_0x5c4f43,_0x3dbdda){var _0x433089=![];var _0x36bfaa=_0x5c4f43['dialMethod']!==_0x3dbdda[_0x31e6('0x16')]||_0x5c4f43[_0x31e6('0x1d')]!==_0x3dbdda[_0x31e6('0x1d')]||_0x5c4f43[_0x31e6('0x23')]!==_0x3dbdda[_0x31e6('0x23')];var _0x5599d0=_0x5c4f43[_0x31e6('0x24')]!==_0x3dbdda[_0x31e6('0x24')]||_0x5c4f43[_0x31e6('0x25')]!==_0x3dbdda['loggedIn']||_0x5c4f43['loggedInDb']!==_0x3dbdda[_0x31e6('0x26')]||_0x5c4f43[_0x31e6('0x27')]!==_0x3dbdda[_0x31e6('0x27')]||_0x5c4f43['talking']!==_0x3dbdda[_0x31e6('0x28')]||_0x5c4f43['pTalking']!==_0x3dbdda[_0x31e6('0x29')]||_0x5c4f43[_0x31e6('0x2a')]!==_0x3dbdda[_0x31e6('0x2a')]||_0x5c4f43[_0x31e6('0x2b')]!==_0x3dbdda[_0x31e6('0x2b')]||_0x5c4f43[_0x31e6('0x2c')]!==_0x3dbdda[_0x31e6('0x2c')];if(_0x5c4f43[_0x31e6('0x2d')]&&_0x3dbdda[_0x31e6('0x2d')]){_0x433089=_0x5c4f43[_0x31e6('0x2d')][_0x31e6('0x2e')]!==_0x3dbdda[_0x31e6('0x2d')][_0x31e6('0x2e')]||_0x5c4f43[_0x31e6('0x2d')][_0x31e6('0x1e')]!==_0x3dbdda[_0x31e6('0x2d')][_0x31e6('0x1e')];}return _0x36bfaa||_0x5599d0||_0x433089;}exports['hasQueueCampaignDataChanged']=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0xeaae0e){var _0x4022ed=null;var _0x955380=_0xeaae0e['dialTimezone'];if(_['isNil'](_0xeaae0e[_0x31e6('0x2f')])||_[_0x31e6('0x30')](_0xeaae0e[_0x31e6('0x31')])||_[_0x31e6('0x30')](_0xeaae0e['Interval'][_0x31e6('0x32')])){_0x4022ed=CAMPAIGN_STATUS[_0x31e6('0x33')];}else if(_[_0x31e6('0x34')](_0xeaae0e[_0x31e6('0x2f')])||_['isEmpty'](_0xeaae0e[_0x31e6('0x31')][_0x31e6('0x32')])){_0x4022ed=CAMPAIGN_STATUS[_0x31e6('0x35')];}else if(_0x955380&&!timezones[_0x955380]){_0x4022ed=CAMPAIGN_STATUS['UNKNOWN_TIMEZONE'];}return _0x4022ed;}function checkAnyValidTrunk(_0xd8e09c,_0xf1edac){var _0x1f67bb=null;var _0x59456f=_0x31e6('0x36');var _0x4fbc6e=['reachable',_0x31e6('0x37')];var _0x286a63=!![];if(_0xd8e09c[_0x31e6('0x2d')]&&_0xd8e09c[_0x31e6('0x2d')][_0x31e6('0x1e')]){_0x59456f+=_0xd8e09c[_0x31e6('0x2d')][_0x31e6('0x2e')];_0x1f67bb=_0xf1edac[_0x59456f];_0x286a63=_0x4fbc6e[_0x31e6('0x38')](_0x1f67bb[_0x31e6('0x39')]);}else if(_0xd8e09c[_0x31e6('0x3a')]&&_0xd8e09c[_0x31e6('0x3a')][_0x31e6('0x1e')]){_0x59456f+=_0xd8e09c[_0x31e6('0x3a')]['name'];_0x1f67bb=_0xf1edac[_0x59456f];_0x286a63=_0x4fbc6e[_0x31e6('0x38')](_0x1f67bb['status']);}return _0x286a63;}function getQueueCampaignStatusMessage(_0x398404,_0x52f12d){var _0x2ae0e7=CAMPAIGN_STATUS[_0x31e6('0x4')];var _0x24a499=isPreviewCampaign(_0x398404);if(!isQueueCampaignActive(_0x398404)){if(_0x24a499){_0x2ae0e7=CAMPAIGN_STATUS['INACTIVE'];}else{if(_0x398404[_0x31e6('0x2c')]===0x0&&_0x398404[_0x31e6('0x28')]===0x0&&_0x398404[_0x31e6('0x2a')]===0x0&&(_0x398404[_0x31e6('0x29')]||0x0)===0x0){_0x2ae0e7=CAMPAIGN_STATUS[_0x31e6('0x3b')];}else{_0x2ae0e7=CAMPAIGN_STATUS[_0x31e6('0x3c')];}}}else if(_0x398404['loggedIn']===0x0){_0x2ae0e7=CAMPAIGN_STATUS[_0x31e6('0x3d')];}else if(!checkAnyValidTrunk(_0x398404,_0x52f12d)){_0x2ae0e7=CAMPAIGN_STATUS[_0x31e6('0x3e')];}else if(!isPreviewCampaign(_0x398404)){var _0x2c17e4=checkAnyValidQueueCampaignInterval(_0x398404);if(_0x2c17e4){_0x2ae0e7=_0x2c17e4;}}return _0x2ae0e7;}exports[_0x31e6('0x3f')]=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0x269dce){var _0x411484=CAMPAIGN_STATUS[_0x31e6('0x3c')];if(_0x269dce[_0x31e6('0x2c')]===0x0&&_0x269dce[_0x31e6('0x28')]===0x0&&_0x269dce[_0x31e6('0x2a')]===0x0&&(_0x269dce['pTalking']||0x0)===0x0){_0x411484=CAMPAIGN_STATUS[_0x31e6('0x3b')];}return _0x411484;}exports[_0x31e6('0x40')]=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x25920){var _0x56416e=_0x25920['match'](/"(.*?)"/);return _0x56416e?_0x56416e[0x1]:_0x25920;}exports[_0x31e6('0x41')]=extractCalleridName;function getCallerId(_0x22ec25,_0xbc6469,_0x2ba777){if(!_[_0x31e6('0x42')](_0x2ba777)&&typeof _0x2ba777===_0x31e6('0x43')&&!_[_0x31e6('0x34')](_0x2ba777)){if(!_[_0x31e6('0x42')](_0xbc6469)&&typeof _0xbc6469===_0x31e6('0x43')&&!_[_0x31e6('0x34')](_0xbc6469)){return util[_0x31e6('0x44')]('\x22%s\x22\x20<%s>',_0xbc6469,_0x2ba777);}return util[_0x31e6('0x44')](_0x31e6('0x45'),_0x2ba777,_0x2ba777);}if(!_[_0x31e6('0x42')](_0x22ec25)&&typeof _0x22ec25===_0x31e6('0x43')&&!_[_0x31e6('0x34')](_0x22ec25)){return _0x22ec25;}return _0x31e6('0x46');}exports[_0x31e6('0x47')]=getCallerId;function getCallerIdRandom(_0x22173e,_0x5954b6){var _0x26a582;var _0x375702;var _0x54db53;if(_0x5954b6<=0x0){_0x5954b6=0x1;}_0x26a582=new RegExp(_0x31e6('0x48')+_0x5954b6+'}$');_0x375702=Math['pow'](0xa,_0x5954b6-0x1);_0x54db53=Math[_0x31e6('0x49')](0xa,_0x5954b6)-0x1;return util[_0x31e6('0x44')]('%s',_[_0x31e6('0x4a')](_0x22173e,_0x26a582,_[_0x31e6('0x4b')](_0x375702,_0x54db53)[_0x31e6('0x4c')]()));}exports[_0x31e6('0x4d')]=getCallerIdRandom;function decrementOriginate(_0x430672){if(_0x430672[_0x31e6('0x2c')]&&_0x430672[_0x31e6('0x2c')]>0x0){_0x430672['originated']-=0x1;}else{logger[_0x31e6('0x4e')]('[decrementOriginate]\x20queue\x20originate\x20value\x20is\x20negative');}}exports[_0x31e6('0x4f')]=decrementOriginate;function checkContactEmpty(_0x1446fb){return _0x1446fb&&_0x1446fb['length']>0x0;}exports[_0x31e6('0x50')]=checkContactEmpty;function erlangb(_0x2922cc,_0x5b6a28){if(_0x5b6a28===0x0){return 0x0;}var _0x456bdb=0x1;for(var _0x581ba9=0x1;_0x581ba9<=_0x5b6a28;_0x581ba9+=0x1){_0x456bdb=0x1+_0x456bdb*_0x581ba9/_0x2922cc;}return 0x1/_0x456bdb;}exports[_0x31e6('0x51')]=erlangb;function checkContactLowerLimitOriginate(_0x4d4c17,_0x2f7a37,_0x3e6a74){if(_0x2f7a37>_0x3e6a74){for(var _0x222100=0x0;_0x222100<_0x2f7a37-_0x3e6a74;_0x222100+=0x1){decrementOriginate(_0x4d4c17);}}}exports[_0x31e6('0x52')]=checkContactLowerLimitOriginate;