Built motion from commit da24aabd.|2.6.20
[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 _0x9f45=['getQueueCampaignActiveStatusMessage','match','extractCalleridName','isUndefined','string','format','\x22%s\x22\x20<%s>','getCallerId','\x5cw{0,','pow','replace','random','toString','getCallerIdRandom','error','[decrementOriginate]\x20queue\x20originate\x20value\x20is\x20negative','decrementOriginate','length','checkContactEmpty','erlangb','checkContactLowerLimitOriginate','createdAt','description','tags','updatedAt','%s%s','toUpperCase','moment','../../../../config/logger','../../../../config/environment/shared','timezones','ACTIVE','BLACKLIST','RESCHEDULED_CONTACTS','DEACTIVATED','INTERVAL_IS_EMPTY','AGENTS_NOT_LOGGED','INTERVAL_IS_NULL','INTERVAL_IS_OVERTIME','RUNNING','TIMEZONE_UNKNOW','dialMethod','preview','type','ivr','isIVRCampaign','outbound','isOutboundQueue','dialActive','isQueueCampaignActive','isIVRCampaignActive','milliseconds','seconds','getSeconds','message','available','loggedIn','loggedInDb','paused','talking','pTalking','waiting','inUse','originated','Trunk','name','active','hasQueueCampaignDataChanged','dialTimezone','isNil','dialGlobalInterval','Interval','Intervals','NULL_INTERVAL','isEmpty','SIP/','reachable','unmonitored','includes','TrunkBackup','status','INACTIVE','NO_AGENTS_LOGGED','UNREACHABLE_TRUNK'];(function(_0x228ce2,_0x4d48f3){var _0x3bf15e=function(_0x3eaa78){while(--_0x3eaa78){_0x228ce2['push'](_0x228ce2['shift']());}};_0x3bf15e(++_0x4d48f3);}(_0x9f45,0x16b));var _0x59f4=function(_0x3d8b21,_0x32f40d){_0x3d8b21=_0x3d8b21-0x0;var _0x5889f8=_0x9f45[_0x3d8b21];return _0x5889f8;};'use strict';var _=require('lodash');var moment=require(_0x59f4('0x0'));var util=require('util');var logger=require(_0x59f4('0x1'))('dialer');var timezones=require(_0x59f4('0x2'))[_0x59f4('0x3')];var CAMPAIGN_STATUS={'ACTIVE':_0x59f4('0x4'),'BLACKLIST':_0x59f4('0x5'),'CONTACTS_RESCHEDULED':_0x59f4('0x6'),'DEACTIVATED':_0x59f4('0x7'),'DISACTIVED':'IS_DISACTIVED','EMPTY_INTERVAL':_0x59f4('0x8'),'INACTIVE':'NOT_ACTIVE','NO_AGENTS_LOGGED':_0x59f4('0x9'),'NO_AVAILABLE_CONTACTS':'AVAILABLE_CONTACTS_FINISHED','NULL_INTERVAL':_0x59f4('0xa'),'OVERTIME_INTERVAL':_0x59f4('0xb'),'OVERTIME_GLOBAL_INTERVAL':'GLOBAL_INTERVAL_IS_OVERTIME','QUEUE_RECALL':'RECALLINQUEUE','RECALL_TIMEOUT':'RECALLFAILEDTIMEOUT','RUNNING':_0x59f4('0xc'),'UNKNOWN_TIMEZONE':_0x59f4('0xd'),'UNREACHABLE_TRUNK':'TRUNK_IS_NOT_REACHABLE'};exports['CAMPAIGN_STATUS']=CAMPAIGN_STATUS;function isPreviewCampaign(_0xfee607){return _0xfee607[_0x59f4('0xe')]===_0x59f4('0xf');}exports['isPreviewCampaign']=isPreviewCampaign;function isIVRCampaign(_0x1608fb){return _0x1608fb[_0x59f4('0x10')]===_0x59f4('0x11');}exports[_0x59f4('0x12')]=isIVRCampaign;function isOutboundQueue(_0x11fc23){return _0x11fc23['type']===_0x59f4('0x13');}exports[_0x59f4('0x14')]=isOutboundQueue;function isQueueCampaignActive(_0x7e645c){return _0x7e645c[_0x59f4('0x15')];}exports[_0x59f4('0x16')]=isQueueCampaignActive;function isIVRCampaignActive(_0x4f50d9){return _0x4f50d9['active'];}exports[_0x59f4('0x17')]=isIVRCampaignActive;function getSeconds(_0x169112,_0x1f5d5c){var _0x5a2796=moment(_0x169112)['milliseconds'](0x0);var _0x39a4ff=moment(_0x1f5d5c)[_0x59f4('0x18')](0x0);return _0x5a2796['diff'](_0x39a4ff,_0x59f4('0x19'));}exports[_0x59f4('0x1a')]=getSeconds;function hasQueueCampaignDataChanged(_0x4b3c66,_0x321905){var _0x26f1c4=![];var _0x242b0b=_0x4b3c66['dialMethod']!==_0x321905[_0x59f4('0xe')]||_0x4b3c66[_0x59f4('0x15')]!==_0x321905[_0x59f4('0x15')]||_0x4b3c66[_0x59f4('0x1b')]!==_0x321905[_0x59f4('0x1b')];var _0x107db9=_0x4b3c66[_0x59f4('0x1c')]!==_0x321905[_0x59f4('0x1c')]||_0x4b3c66[_0x59f4('0x1d')]!==_0x321905[_0x59f4('0x1d')]||_0x4b3c66[_0x59f4('0x1e')]!==_0x321905[_0x59f4('0x1e')]||_0x4b3c66[_0x59f4('0x1f')]!==_0x321905[_0x59f4('0x1f')]||_0x4b3c66[_0x59f4('0x20')]!==_0x321905['talking']||_0x4b3c66[_0x59f4('0x21')]!==_0x321905[_0x59f4('0x21')]||_0x4b3c66[_0x59f4('0x22')]!==_0x321905[_0x59f4('0x22')]||_0x4b3c66[_0x59f4('0x23')]!==_0x321905[_0x59f4('0x23')]||_0x4b3c66[_0x59f4('0x24')]!==_0x321905[_0x59f4('0x24')];if(_0x4b3c66['Trunk']&&_0x321905[_0x59f4('0x25')]){_0x26f1c4=_0x4b3c66[_0x59f4('0x25')][_0x59f4('0x26')]!==_0x321905[_0x59f4('0x25')][_0x59f4('0x26')]||_0x4b3c66[_0x59f4('0x25')][_0x59f4('0x27')]!==_0x321905[_0x59f4('0x25')][_0x59f4('0x27')];}return _0x242b0b||_0x107db9||_0x26f1c4;}exports[_0x59f4('0x28')]=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0x1a5749){var _0x3edee0=null;var _0x4c2b77=_0x1a5749[_0x59f4('0x29')];if(_[_0x59f4('0x2a')](_0x1a5749[_0x59f4('0x2b')])||_['isNil'](_0x1a5749[_0x59f4('0x2c')])||_[_0x59f4('0x2a')](_0x1a5749[_0x59f4('0x2c')][_0x59f4('0x2d')])){_0x3edee0=CAMPAIGN_STATUS[_0x59f4('0x2e')];}else if(_[_0x59f4('0x2f')](_0x1a5749[_0x59f4('0x2b')])||_[_0x59f4('0x2f')](_0x1a5749['Interval'][_0x59f4('0x2d')])){_0x3edee0=CAMPAIGN_STATUS['EMPTY_INTERVAL'];}else if(_0x4c2b77&&!timezones[_0x4c2b77]){_0x3edee0=CAMPAIGN_STATUS['UNKNOWN_TIMEZONE'];}return _0x3edee0;}function checkAnyValidTrunk(_0x573e5f,_0x54f532){var _0x49318b=null;var _0x4a2d96=_0x59f4('0x30');var _0xd8eaa6=[_0x59f4('0x31'),_0x59f4('0x32')];var _0x343ec7=!![];if(_0x573e5f[_0x59f4('0x25')]&&_0x573e5f[_0x59f4('0x25')][_0x59f4('0x27')]){_0x4a2d96+=_0x573e5f[_0x59f4('0x25')]['name'];_0x49318b=_0x54f532[_0x4a2d96];_0x343ec7=_0xd8eaa6[_0x59f4('0x33')](_0x49318b['status']);}else if(_0x573e5f['TrunkBackup']&&_0x573e5f['TrunkBackup'][_0x59f4('0x27')]){_0x4a2d96+=_0x573e5f[_0x59f4('0x34')][_0x59f4('0x26')];_0x49318b=_0x54f532[_0x4a2d96];_0x343ec7=_0xd8eaa6[_0x59f4('0x33')](_0x49318b[_0x59f4('0x35')]);}return _0x343ec7;}function getQueueCampaignStatusMessage(_0x40d99a,_0x164bdb){var _0x2c88e2=CAMPAIGN_STATUS[_0x59f4('0x4')];var _0x52bec9=isPreviewCampaign(_0x40d99a);if(!isQueueCampaignActive(_0x40d99a)){if(_0x52bec9){_0x2c88e2=CAMPAIGN_STATUS[_0x59f4('0x36')];}else{if(_0x40d99a[_0x59f4('0x24')]===0x0&&_0x40d99a[_0x59f4('0x20')]===0x0&&_0x40d99a['waiting']===0x0&&(_0x40d99a[_0x59f4('0x21')]||0x0)===0x0){_0x2c88e2=CAMPAIGN_STATUS['INACTIVE'];}else{_0x2c88e2=CAMPAIGN_STATUS['DISACTIVED'];}}}else if(_0x40d99a[_0x59f4('0x1d')]===0x0){_0x2c88e2=CAMPAIGN_STATUS[_0x59f4('0x37')];}else if(!checkAnyValidTrunk(_0x40d99a,_0x164bdb)){_0x2c88e2=CAMPAIGN_STATUS[_0x59f4('0x38')];}else if(!isPreviewCampaign(_0x40d99a)){var _0xe02c7f=checkAnyValidQueueCampaignInterval(_0x40d99a);if(_0xe02c7f){_0x2c88e2=_0xe02c7f;}}return _0x2c88e2;}exports['getQueueCampaignStatusMessage']=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0x4ad768){var _0x50ea46=CAMPAIGN_STATUS['DISACTIVED'];if(_0x4ad768['originated']===0x0&&_0x4ad768['talking']===0x0&&_0x4ad768[_0x59f4('0x22')]===0x0&&(_0x4ad768[_0x59f4('0x21')]||0x0)===0x0){_0x50ea46=CAMPAIGN_STATUS['INACTIVE'];}return _0x50ea46;}exports[_0x59f4('0x39')]=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x9d3f35){var _0x15992b=_0x9d3f35[_0x59f4('0x3a')](/"(.*?)"/);return _0x15992b?_0x15992b[0x1]:_0x9d3f35;}exports[_0x59f4('0x3b')]=extractCalleridName;function getCallerId(_0x208fcd,_0x3daba6,_0x54696d){if(!_[_0x59f4('0x3c')](_0x54696d)&&typeof _0x54696d===_0x59f4('0x3d')&&!_[_0x59f4('0x2f')](_0x54696d)){if(!_[_0x59f4('0x3c')](_0x3daba6)&&typeof _0x3daba6===_0x59f4('0x3d')&&!_['isEmpty'](_0x3daba6)){return util[_0x59f4('0x3e')](_0x59f4('0x3f'),_0x3daba6,_0x54696d);}return util[_0x59f4('0x3e')]('\x22%s\x22\x20<%s>',_0x54696d,_0x54696d);}if(!_[_0x59f4('0x3c')](_0x208fcd)&&typeof _0x208fcd===_0x59f4('0x3d')&&!_[_0x59f4('0x2f')](_0x208fcd)){return _0x208fcd;}return'\x22\x22\x20<>';}exports[_0x59f4('0x40')]=getCallerId;function getCallerIdRandom(_0x137699,_0x10cf46){var _0x308343;var _0xe5b22e;var _0x4e306d;if(_0x10cf46<=0x0){_0x10cf46=0x1;}_0x308343=new RegExp(_0x59f4('0x41')+_0x10cf46+'}$');_0xe5b22e=Math[_0x59f4('0x42')](0xa,_0x10cf46-0x1);_0x4e306d=Math[_0x59f4('0x42')](0xa,_0x10cf46)-0x1;return util['format']('%s',_[_0x59f4('0x43')](_0x137699,_0x308343,_[_0x59f4('0x44')](_0xe5b22e,_0x4e306d)[_0x59f4('0x45')]()));}exports[_0x59f4('0x46')]=getCallerIdRandom;function decrementOriginate(_0x2a1b2e){if(_0x2a1b2e[_0x59f4('0x24')]&&_0x2a1b2e[_0x59f4('0x24')]>0x0){_0x2a1b2e[_0x59f4('0x24')]-=0x1;}else{logger[_0x59f4('0x47')](_0x59f4('0x48'));}}exports[_0x59f4('0x49')]=decrementOriginate;function checkContactEmpty(_0x184352){return _0x184352&&_0x184352[_0x59f4('0x4a')]>0x0;}exports[_0x59f4('0x4b')]=checkContactEmpty;function erlangb(_0x18188e,_0x41b939){if(_0x41b939===0x0){return 0x0;}var _0x420edf=0x1;for(var _0x11ecba=0x1;_0x11ecba<=_0x41b939;_0x11ecba+=0x1){_0x420edf=0x1+_0x420edf*_0x11ecba/_0x18188e;}return 0x1/_0x420edf;}exports[_0x59f4('0x4c')]=erlangb;function checkContactLowerLimitOriginate(_0x133c4a,_0x70ca7c,_0x32b3ac){if(_0x70ca7c>_0x32b3ac){for(var _0x1f731a=0x0;_0x1f731a<_0x70ca7c-_0x32b3ac;_0x1f731a+=0x1){decrementOriginate(_0x133c4a);}}}exports[_0x59f4('0x4d')]=checkContactLowerLimitOriginate;function setXMDContactVariables(_0x2d939f){var _0x59ef39={};var _0x21c4f9=['id',_0x59f4('0x4e'),_0x59f4('0x4f'),_0x59f4('0x50'),_0x59f4('0x51')];if(_0x2d939f){for(var _0x8b51b5 in _0x2d939f){if(typeof _0x2d939f[_0x8b51b5]!=='undefined'){if(!_['isNil'](_0x2d939f[_0x8b51b5])&&!_0x21c4f9[_0x59f4('0x33')](_0x8b51b5)){_0x59ef39[util[_0x59f4('0x3e')](_0x59f4('0x52'),'XMD-',_0x8b51b5[_0x59f4('0x53')]())]=_0x2d939f[_0x8b51b5];}}}}return _0x59ef39;}exports['setXMDContactVariables']=setXMDContactVariables;