60281f5dc2578216ab7de215bdb0a102e6ee7b53
[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 _0x1f88=['XMD-','toUpperCase','moment','util','../../../../config/logger','dialer','../../../../config/environment/shared','timezones','ACTIVE','BLACKLIST','IS_DISACTIVED','INTERVAL_IS_EMPTY','NOT_ACTIVE','AGENTS_NOT_LOGGED','AVAILABLE_CONTACTS_FINISHED','RECALLINQUEUE','RECALLFAILEDTIMEOUT','RUNNING','TIMEZONE_UNKNOW','TRUNK_IS_NOT_REACHABLE','CAMPAIGN_STATUS','dialMethod','preview','isPreviewCampaign','ivr','isIVRCampaign','type','outbound','isQueueCampaignActive','isIVRCampaignActive','milliseconds','diff','getSeconds','dialActive','available','loggedIn','loggedInDb','paused','talking','pTalking','waiting','inUse','originated','Trunk','name','active','hasQueueCampaignDataChanged','dialTimezone','isNil','dialGlobalInterval','Interval','NULL_INTERVAL','isEmpty','Intervals','EMPTY_INTERVAL','UNKNOWN_TIMEZONE','SIP/','unmonitored','includes','TrunkBackup','status','INACTIVE','DISACTIVED','NO_AGENTS_LOGGED','UNREACHABLE_TRUNK','string','isUndefined','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','getCallerId','\x5cw{0,','pow','random','toString','getCallerIdRandom','[decrementOriginate]\x20queue\x20originate\x20value','decrementOriginate','length','checkContactEmpty','erlangb','[checkContactLowerLimitOriginate]\x20','checkContactLowerLimitOriginate','createdAt','updatedAt','undefined','description','substring'];(function(_0x3949b5,_0x4bd4ae){var _0x3ace93=function(_0x4361db){while(--_0x4361db){_0x3949b5['push'](_0x3949b5['shift']());}};_0x3ace93(++_0x4bd4ae);}(_0x1f88,0x10a));var _0x81f8=function(_0x4fafa9,_0x134473){_0x4fafa9=_0x4fafa9-0x0;var _0x5ba9a2=_0x1f88[_0x4fafa9];return _0x5ba9a2;};'use strict';var _=require('lodash');var moment=require(_0x81f8('0x0'));var util=require(_0x81f8('0x1'));var logger=require(_0x81f8('0x2'))(_0x81f8('0x3'));var timezones=require(_0x81f8('0x4'))[_0x81f8('0x5')];var CAMPAIGN_STATUS={'ACTIVE':_0x81f8('0x6'),'BLACKLIST':_0x81f8('0x7'),'CONTACTS_RESCHEDULED':'RESCHEDULED_CONTACTS','DEACTIVATED':'DEACTIVATED','DISACTIVED':_0x81f8('0x8'),'EMPTY_INTERVAL':_0x81f8('0x9'),'INACTIVE':_0x81f8('0xa'),'NO_AGENTS_LOGGED':_0x81f8('0xb'),'NO_AVAILABLE_CONTACTS':_0x81f8('0xc'),'NULL_INTERVAL':'INTERVAL_IS_NULL','OVERTIME_INTERVAL':'INTERVAL_IS_OVERTIME','OVERTIME_GLOBAL_INTERVAL':'GLOBAL_INTERVAL_IS_OVERTIME','QUEUE_RECALL':_0x81f8('0xd'),'RECALL_TIMEOUT':_0x81f8('0xe'),'RUNNING':_0x81f8('0xf'),'UNKNOWN_TIMEZONE':_0x81f8('0x10'),'UNREACHABLE_TRUNK':_0x81f8('0x11')};exports[_0x81f8('0x12')]=CAMPAIGN_STATUS;function isPreviewCampaign(_0x5b67cc){return _0x5b67cc[_0x81f8('0x13')]===_0x81f8('0x14');}exports[_0x81f8('0x15')]=isPreviewCampaign;function isIVRCampaign(_0x485607){return _0x485607['type']===_0x81f8('0x16');}exports[_0x81f8('0x17')]=isIVRCampaign;function isOutboundQueue(_0x55af98){return _0x55af98[_0x81f8('0x18')]===_0x81f8('0x19');}exports['isOutboundQueue']=isOutboundQueue;function isQueueCampaignActive(_0x15348c){return _0x15348c['dialActive'];}exports[_0x81f8('0x1a')]=isQueueCampaignActive;function isIVRCampaignActive(_0x386e0f){return _0x386e0f['active'];}exports[_0x81f8('0x1b')]=isIVRCampaignActive;function getSeconds(_0x3b2a16,_0xfe70bf){var _0x1e0311=moment(_0x3b2a16)[_0x81f8('0x1c')](0x0);var _0x42f957=moment(_0xfe70bf)[_0x81f8('0x1c')](0x0);return _0x1e0311[_0x81f8('0x1d')](_0x42f957,'seconds');}exports[_0x81f8('0x1e')]=getSeconds;function hasQueueCampaignDataChanged(_0x3348d2,_0x4e63d0){var _0x114083=![];var _0x508b2a=_0x3348d2[_0x81f8('0x13')]!==_0x4e63d0[_0x81f8('0x13')]||_0x3348d2[_0x81f8('0x1f')]!==_0x4e63d0[_0x81f8('0x1f')]||_0x3348d2['message']!==_0x4e63d0['message'];var _0x3917f6=_0x3348d2['available']!==_0x4e63d0[_0x81f8('0x20')]||_0x3348d2[_0x81f8('0x21')]!==_0x4e63d0[_0x81f8('0x21')]||_0x3348d2[_0x81f8('0x22')]!==_0x4e63d0['loggedInDb']||_0x3348d2[_0x81f8('0x23')]!==_0x4e63d0[_0x81f8('0x23')]||_0x3348d2[_0x81f8('0x24')]!==_0x4e63d0[_0x81f8('0x24')]||_0x3348d2[_0x81f8('0x25')]!==_0x4e63d0[_0x81f8('0x25')]||_0x3348d2[_0x81f8('0x26')]!==_0x4e63d0[_0x81f8('0x26')]||_0x3348d2[_0x81f8('0x27')]!==_0x4e63d0[_0x81f8('0x27')]||_0x3348d2['originated']!==_0x4e63d0[_0x81f8('0x28')];if(_0x3348d2[_0x81f8('0x29')]&&_0x4e63d0['Trunk']){_0x114083=_0x3348d2[_0x81f8('0x29')][_0x81f8('0x2a')]!==_0x4e63d0[_0x81f8('0x29')]['name']||_0x3348d2[_0x81f8('0x29')][_0x81f8('0x2b')]!==_0x4e63d0['Trunk'][_0x81f8('0x2b')];}return _0x508b2a||_0x3917f6||_0x114083;}exports[_0x81f8('0x2c')]=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0xb44752){var _0x35218a=null;var _0x162bbb=_0xb44752[_0x81f8('0x2d')];if(_[_0x81f8('0x2e')](_0xb44752[_0x81f8('0x2f')])||_[_0x81f8('0x2e')](_0xb44752[_0x81f8('0x30')])||_[_0x81f8('0x2e')](_0xb44752[_0x81f8('0x30')]['Intervals'])){_0x35218a=CAMPAIGN_STATUS[_0x81f8('0x31')];}else if(_[_0x81f8('0x32')](_0xb44752[_0x81f8('0x2f')])||_['isEmpty'](_0xb44752['Interval'][_0x81f8('0x33')])){_0x35218a=CAMPAIGN_STATUS[_0x81f8('0x34')];}else if(_0x162bbb&&!timezones[_0x162bbb]){_0x35218a=CAMPAIGN_STATUS[_0x81f8('0x35')];}return _0x35218a;}function checkAnyValidTrunk(_0x13f57a,_0x3080b4){var _0x4277f3=null;var _0x1a594b=_0x81f8('0x36');var _0xe5802f=['reachable',_0x81f8('0x37')];var _0xec7c8c=!![];if(_0x13f57a[_0x81f8('0x29')]&&_0x13f57a['Trunk'][_0x81f8('0x2b')]){_0x1a594b+=_0x13f57a['Trunk'][_0x81f8('0x2a')];_0x4277f3=_0x3080b4[_0x1a594b];_0xec7c8c=_0xe5802f[_0x81f8('0x38')](_0x4277f3['status']);}else if(_0x13f57a[_0x81f8('0x39')]&&_0x13f57a[_0x81f8('0x39')][_0x81f8('0x2b')]){_0x1a594b+=_0x13f57a[_0x81f8('0x39')][_0x81f8('0x2a')];_0x4277f3=_0x3080b4[_0x1a594b];_0xec7c8c=_0xe5802f[_0x81f8('0x38')](_0x4277f3[_0x81f8('0x3a')]);}return _0xec7c8c;}function getQueueCampaignStatusMessage(_0x2583b4,_0x7bbf5f){var _0x5089e1=CAMPAIGN_STATUS[_0x81f8('0x6')];var _0x1266ba=isPreviewCampaign(_0x2583b4);if(!isQueueCampaignActive(_0x2583b4)){if(_0x1266ba){_0x5089e1=CAMPAIGN_STATUS['INACTIVE'];}else{if(_0x2583b4[_0x81f8('0x28')]===0x0&&_0x2583b4['talking']===0x0&&_0x2583b4[_0x81f8('0x26')]===0x0&&(_0x2583b4[_0x81f8('0x25')]||0x0)===0x0){_0x5089e1=CAMPAIGN_STATUS[_0x81f8('0x3b')];}else{_0x5089e1=CAMPAIGN_STATUS[_0x81f8('0x3c')];}}}else if(_0x2583b4[_0x81f8('0x21')]===0x0){_0x5089e1=CAMPAIGN_STATUS[_0x81f8('0x3d')];}else if(!checkAnyValidTrunk(_0x2583b4,_0x7bbf5f)){_0x5089e1=CAMPAIGN_STATUS[_0x81f8('0x3e')];}else if(!isPreviewCampaign(_0x2583b4)){var _0xb13ffc=checkAnyValidQueueCampaignInterval(_0x2583b4);if(_0xb13ffc){_0x5089e1=_0xb13ffc;}}return _0x5089e1;}exports['getQueueCampaignStatusMessage']=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0x3382ac){var _0x4606e8=CAMPAIGN_STATUS[_0x81f8('0x3c')];if(_0x3382ac['originated']===0x0&&_0x3382ac[_0x81f8('0x24')]===0x0&&_0x3382ac[_0x81f8('0x26')]===0x0&&(_0x3382ac['pTalking']||0x0)===0x0){_0x4606e8=CAMPAIGN_STATUS['INACTIVE'];}return _0x4606e8;}exports['getQueueCampaignActiveStatusMessage']=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x285e49){var _0x1ed546=_0x285e49['match'](/"(.*?)"/);return _0x1ed546?_0x1ed546[0x1]:_0x285e49;}exports['extractCalleridName']=extractCalleridName;function getCallerId(_0xdb92d9,_0x448c94,_0x53ec5e){if(!_['isUndefined'](_0x53ec5e)&&typeof _0x53ec5e===_0x81f8('0x3f')&&!_[_0x81f8('0x32')](_0x53ec5e)){if(!_[_0x81f8('0x40')](_0x448c94)&&typeof _0x448c94===_0x81f8('0x3f')&&!_['isEmpty'](_0x448c94)){return util[_0x81f8('0x41')](_0x81f8('0x42'),_0x448c94,_0x53ec5e);}return util[_0x81f8('0x41')](_0x81f8('0x42'),_0x53ec5e,_0x53ec5e);}if(!_[_0x81f8('0x40')](_0xdb92d9)&&typeof _0xdb92d9===_0x81f8('0x3f')&&!_[_0x81f8('0x32')](_0xdb92d9)){return _0xdb92d9;}return _0x81f8('0x43');}exports[_0x81f8('0x44')]=getCallerId;function getCallerIdRandom(_0x35922b,_0x217fa1){var _0x9c399;var _0x2dc72a;var _0x13ea92;if(_0x217fa1<=0x0){_0x217fa1=0x1;}_0x9c399=new RegExp(_0x81f8('0x45')+_0x217fa1+'}$');_0x2dc72a=Math[_0x81f8('0x46')](0xa,_0x217fa1-0x1);_0x13ea92=Math['pow'](0xa,_0x217fa1)-0x1;return util[_0x81f8('0x41')]('%s',_['replace'](_0x35922b,_0x9c399,_[_0x81f8('0x47')](_0x2dc72a,_0x13ea92)[_0x81f8('0x48')]()));}exports[_0x81f8('0x49')]=getCallerIdRandom;function decrementOriginate(_0x4f7209,_0x56d4c3){if(_0x4f7209[_0x81f8('0x28')]&&_0x4f7209[_0x81f8('0x28')]>0x0){_0x4f7209[_0x81f8('0x28')]-=0x1;}else{logger['error'](_0x81f8('0x4a'),_0x56d4c3);}}exports[_0x81f8('0x4b')]=decrementOriginate;function checkContactEmpty(_0x3590c3){return _0x3590c3&&_0x3590c3[_0x81f8('0x4c')]>0x0;}exports[_0x81f8('0x4d')]=checkContactEmpty;function erlangb(_0x37f4d4,_0x9eec9d){if(_0x9eec9d===0x0){return 0x0;}var _0x2ac33a=0x1;for(var _0x22bef0=0x1;_0x22bef0<=_0x9eec9d;_0x22bef0+=0x1){_0x2ac33a=0x1+_0x2ac33a*_0x22bef0/_0x37f4d4;}return 0x1/_0x2ac33a;}exports[_0x81f8('0x4e')]=erlangb;function checkContactLowerLimitOriginate(_0x2546c6,_0x24b2eb,_0x4895ff){if(_0x24b2eb>_0x4895ff){for(var _0x1edb7b=0x0;_0x1edb7b<_0x24b2eb-_0x4895ff;_0x1edb7b+=0x1){decrementOriginate(_0x2546c6,_0x81f8('0x4f'));}}}exports[_0x81f8('0x50')]=checkContactLowerLimitOriginate;function setXMDContactVariables(_0xb1824f){var _0x1da83b={};var _0x1d25e1=['id',_0x81f8('0x51'),'tags',_0x81f8('0x52')];const _0x44f7e0=0xfa;if(_0xb1824f){for(var _0x139ebb in _0xb1824f){if(typeof _0xb1824f[_0x139ebb]!==_0x81f8('0x53')){if(!_['isNil'](_0xb1824f[_0x139ebb])&&!_0x1d25e1[_0x81f8('0x38')](_0x139ebb)){if(_0x139ebb===_0x81f8('0x54')&&_0xb1824f[_0x139ebb][_0x81f8('0x4c')]>_0x44f7e0){_0x1da83b['XMD-'+_0x139ebb['toUpperCase']()]=_0xb1824f[_0x139ebb][_0x81f8('0x48')]()[_0x81f8('0x55')](0x0,_0x44f7e0);}else{_0x1da83b[_0x81f8('0x56')+_0x139ebb[_0x81f8('0x57')]()]=_0xb1824f[_0x139ebb];}}}}}return _0x1da83b;}exports['setXMDContactVariables']=setXMDContactVariables;