Built motion from commit b0a9a629.|2.6.33
[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 _0xe9b8=['checkContactLowerLimitOriginate','createdAt','undefined','XMD-','substring','toUpperCase','setXMDContactVariables','lodash','../../../../config/logger','dialer','../../../../config/environment/shared','ACTIVE','RESCHEDULED_CONTACTS','DEACTIVATED','INTERVAL_IS_EMPTY','NOT_ACTIVE','AGENTS_NOT_LOGGED','GLOBAL_INTERVAL_IS_OVERTIME','RECALLINQUEUE','RUNNING','TRUNK_IS_NOT_REACHABLE','CAMPAIGN_STATUS','preview','isPreviewCampaign','type','isIVRCampaign','outbound','isOutboundQueue','isQueueCampaignActive','active','isIVRCampaignActive','milliseconds','diff','seconds','dialMethod','dialActive','message','available','loggedIn','loggedInDb','talking','pTalking','waiting','inUse','originated','Trunk','name','hasQueueCampaignDataChanged','dialTimezone','isNil','dialGlobalInterval','Interval','isEmpty','Intervals','EMPTY_INTERVAL','reachable','unmonitored','includes','status','TrunkBackup','INACTIVE','DISACTIVED','NO_AGENTS_LOGGED','getQueueCampaignStatusMessage','extractCalleridName','string','isUndefined','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','\x5cw{0,','pow','random','toString','getCallerIdRandom','decrementOriginate','length','checkContactEmpty','erlangb','[checkContactLowerLimitOriginate]\x20'];(function(_0x153e91,_0x25ba85){var _0x10863d=function(_0x23e46e){while(--_0x23e46e){_0x153e91['push'](_0x153e91['shift']());}};_0x10863d(++_0x25ba85);}(_0xe9b8,0xf7));var _0x8e9b=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xe9b8[_0x14add3];return _0x4a174f;};'use strict';var _=require(_0x8e9b('0x0'));var moment=require('moment');var util=require('util');var logger=require(_0x8e9b('0x1'))(_0x8e9b('0x2'));var timezones=require(_0x8e9b('0x3'))['timezones'];var CAMPAIGN_STATUS={'ACTIVE':_0x8e9b('0x4'),'BLACKLIST':'BLACKLIST','CONTACTS_RESCHEDULED':_0x8e9b('0x5'),'DEACTIVATED':_0x8e9b('0x6'),'DISACTIVED':'IS_DISACTIVED','EMPTY_INTERVAL':_0x8e9b('0x7'),'INACTIVE':_0x8e9b('0x8'),'NO_AGENTS_LOGGED':_0x8e9b('0x9'),'NO_AVAILABLE_CONTACTS':'AVAILABLE_CONTACTS_FINISHED','NULL_INTERVAL':'INTERVAL_IS_NULL','OVERTIME_INTERVAL':'INTERVAL_IS_OVERTIME','OVERTIME_GLOBAL_INTERVAL':_0x8e9b('0xa'),'QUEUE_RECALL':_0x8e9b('0xb'),'RECALL_TIMEOUT':'RECALLFAILEDTIMEOUT','RUNNING':_0x8e9b('0xc'),'UNKNOWN_TIMEZONE':'TIMEZONE_UNKNOW','UNREACHABLE_TRUNK':_0x8e9b('0xd')};exports[_0x8e9b('0xe')]=CAMPAIGN_STATUS;function isPreviewCampaign(_0x268c70){return _0x268c70['dialMethod']===_0x8e9b('0xf');}exports[_0x8e9b('0x10')]=isPreviewCampaign;function isIVRCampaign(_0x4fa5d0){return _0x4fa5d0[_0x8e9b('0x11')]==='ivr';}exports[_0x8e9b('0x12')]=isIVRCampaign;function isOutboundQueue(_0x459145){return _0x459145[_0x8e9b('0x11')]===_0x8e9b('0x13');}exports[_0x8e9b('0x14')]=isOutboundQueue;function isQueueCampaignActive(_0x4d719a){return _0x4d719a['dialActive'];}exports[_0x8e9b('0x15')]=isQueueCampaignActive;function isIVRCampaignActive(_0x549ae4){return _0x549ae4[_0x8e9b('0x16')];}exports[_0x8e9b('0x17')]=isIVRCampaignActive;function getSeconds(_0x238e9c,_0x54a520){var _0x5c86da=moment(_0x238e9c)['milliseconds'](0x0);var _0x1b6158=moment(_0x54a520)[_0x8e9b('0x18')](0x0);return _0x5c86da[_0x8e9b('0x19')](_0x1b6158,_0x8e9b('0x1a'));}exports['getSeconds']=getSeconds;function hasQueueCampaignDataChanged(_0x52bdb9,_0x18c47e){var _0x2142d2=![];var _0x560bba=_0x52bdb9[_0x8e9b('0x1b')]!==_0x18c47e[_0x8e9b('0x1b')]||_0x52bdb9[_0x8e9b('0x1c')]!==_0x18c47e['dialActive']||_0x52bdb9[_0x8e9b('0x1d')]!==_0x18c47e[_0x8e9b('0x1d')];var _0x5b3f28=_0x52bdb9['available']!==_0x18c47e[_0x8e9b('0x1e')]||_0x52bdb9[_0x8e9b('0x1f')]!==_0x18c47e['loggedIn']||_0x52bdb9[_0x8e9b('0x20')]!==_0x18c47e[_0x8e9b('0x20')]||_0x52bdb9['paused']!==_0x18c47e['paused']||_0x52bdb9['talking']!==_0x18c47e[_0x8e9b('0x21')]||_0x52bdb9[_0x8e9b('0x22')]!==_0x18c47e[_0x8e9b('0x22')]||_0x52bdb9[_0x8e9b('0x23')]!==_0x18c47e['waiting']||_0x52bdb9[_0x8e9b('0x24')]!==_0x18c47e[_0x8e9b('0x24')]||_0x52bdb9[_0x8e9b('0x25')]!==_0x18c47e[_0x8e9b('0x25')];if(_0x52bdb9[_0x8e9b('0x26')]&&_0x18c47e[_0x8e9b('0x26')]){_0x2142d2=_0x52bdb9[_0x8e9b('0x26')][_0x8e9b('0x27')]!==_0x18c47e['Trunk'][_0x8e9b('0x27')]||_0x52bdb9['Trunk'][_0x8e9b('0x16')]!==_0x18c47e[_0x8e9b('0x26')][_0x8e9b('0x16')];}return _0x560bba||_0x5b3f28||_0x2142d2;}exports[_0x8e9b('0x28')]=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0x40e494){var _0x392f47=null;var _0x559041=_0x40e494[_0x8e9b('0x29')];if(_[_0x8e9b('0x2a')](_0x40e494[_0x8e9b('0x2b')])||_[_0x8e9b('0x2a')](_0x40e494[_0x8e9b('0x2c')])||_[_0x8e9b('0x2a')](_0x40e494[_0x8e9b('0x2c')]['Intervals'])){_0x392f47=CAMPAIGN_STATUS['NULL_INTERVAL'];}else if(_['isEmpty'](_0x40e494[_0x8e9b('0x2b')])||_[_0x8e9b('0x2d')](_0x40e494[_0x8e9b('0x2c')][_0x8e9b('0x2e')])){_0x392f47=CAMPAIGN_STATUS[_0x8e9b('0x2f')];}else if(_0x559041&&!timezones[_0x559041]){_0x392f47=CAMPAIGN_STATUS['UNKNOWN_TIMEZONE'];}return _0x392f47;}function checkAnyValidTrunk(_0x588210,_0x53ffa2){var _0x5ada94=null;var _0x2db2ea='SIP/';var _0x242064=[_0x8e9b('0x30'),_0x8e9b('0x31')];var _0x45e096=!![];if(_0x588210[_0x8e9b('0x26')]&&_0x588210[_0x8e9b('0x26')][_0x8e9b('0x16')]){_0x2db2ea+=_0x588210[_0x8e9b('0x26')][_0x8e9b('0x27')];_0x5ada94=_0x53ffa2[_0x2db2ea];_0x45e096=_0x242064[_0x8e9b('0x32')](_0x5ada94[_0x8e9b('0x33')]);}else if(_0x588210[_0x8e9b('0x34')]&&_0x588210['TrunkBackup'][_0x8e9b('0x16')]){_0x2db2ea+=_0x588210[_0x8e9b('0x34')][_0x8e9b('0x27')];_0x5ada94=_0x53ffa2[_0x2db2ea];_0x45e096=_0x242064['includes'](_0x5ada94[_0x8e9b('0x33')]);}return _0x45e096;}function getQueueCampaignStatusMessage(_0x20d4cb,_0x493515){var _0x245fdb=CAMPAIGN_STATUS[_0x8e9b('0x4')];var _0x5873a2=isPreviewCampaign(_0x20d4cb);if(!isQueueCampaignActive(_0x20d4cb)){if(_0x5873a2){_0x245fdb=CAMPAIGN_STATUS[_0x8e9b('0x35')];}else{if(_0x20d4cb['originated']===0x0&&_0x20d4cb['talking']===0x0&&_0x20d4cb['waiting']===0x0&&(_0x20d4cb[_0x8e9b('0x22')]||0x0)===0x0){_0x245fdb=CAMPAIGN_STATUS['INACTIVE'];}else{_0x245fdb=CAMPAIGN_STATUS[_0x8e9b('0x36')];}}}else if(_0x20d4cb[_0x8e9b('0x1f')]===0x0){_0x245fdb=CAMPAIGN_STATUS[_0x8e9b('0x37')];}else if(!checkAnyValidTrunk(_0x20d4cb,_0x493515)){_0x245fdb=CAMPAIGN_STATUS['UNREACHABLE_TRUNK'];}else if(!isPreviewCampaign(_0x20d4cb)){var _0x338d8e=checkAnyValidQueueCampaignInterval(_0x20d4cb);if(_0x338d8e){_0x245fdb=_0x338d8e;}}return _0x245fdb;}exports[_0x8e9b('0x38')]=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0x4267bd){var _0x22e4ae=CAMPAIGN_STATUS[_0x8e9b('0x36')];if(_0x4267bd[_0x8e9b('0x25')]===0x0&&_0x4267bd[_0x8e9b('0x21')]===0x0&&_0x4267bd[_0x8e9b('0x23')]===0x0&&(_0x4267bd[_0x8e9b('0x22')]||0x0)===0x0){_0x22e4ae=CAMPAIGN_STATUS[_0x8e9b('0x35')];}return _0x22e4ae;}exports['getQueueCampaignActiveStatusMessage']=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x5cb4ee){var _0x226ed9=_0x5cb4ee['match'](/"(.*?)"/);return _0x226ed9?_0x226ed9[0x1]:_0x5cb4ee;}exports[_0x8e9b('0x39')]=extractCalleridName;function getCallerId(_0x117e37,_0x3d0fb3,_0x59c871){if(!_['isUndefined'](_0x59c871)&&typeof _0x59c871===_0x8e9b('0x3a')&&!_['isEmpty'](_0x59c871)){if(!_[_0x8e9b('0x3b')](_0x3d0fb3)&&typeof _0x3d0fb3===_0x8e9b('0x3a')&&!_[_0x8e9b('0x2d')](_0x3d0fb3)){return util[_0x8e9b('0x3c')](_0x8e9b('0x3d'),_0x3d0fb3,_0x59c871);}return util['format'](_0x8e9b('0x3d'),_0x59c871,_0x59c871);}if(!_[_0x8e9b('0x3b')](_0x117e37)&&typeof _0x117e37===_0x8e9b('0x3a')&&!_[_0x8e9b('0x2d')](_0x117e37)){return _0x117e37;}return _0x8e9b('0x3e');}exports['getCallerId']=getCallerId;function getCallerIdRandom(_0x5f1328,_0x44f945){var _0x537e12;var _0x36aacd;var _0x4878c8;if(_0x44f945<=0x0){_0x44f945=0x1;}_0x537e12=new RegExp(_0x8e9b('0x3f')+_0x44f945+'}$');_0x36aacd=Math['pow'](0xa,_0x44f945-0x1);_0x4878c8=Math[_0x8e9b('0x40')](0xa,_0x44f945)-0x1;return util[_0x8e9b('0x3c')]('%s',_['replace'](_0x5f1328,_0x537e12,_[_0x8e9b('0x41')](_0x36aacd,_0x4878c8)[_0x8e9b('0x42')]()));}exports[_0x8e9b('0x43')]=getCallerIdRandom;function decrementOriginate(_0x30b517,_0x53c6da){if(_0x30b517[_0x8e9b('0x25')]&&_0x30b517['originated']>0x0){_0x30b517[_0x8e9b('0x25')]-=0x1;}else{logger['error']('[decrementOriginate]\x20queue\x20originate\x20value',_0x53c6da);}}exports[_0x8e9b('0x44')]=decrementOriginate;function checkContactEmpty(_0x9e1aa7){return _0x9e1aa7&&_0x9e1aa7[_0x8e9b('0x45')]>0x0;}exports[_0x8e9b('0x46')]=checkContactEmpty;function erlangb(_0x168ccb,_0x2577b3){if(_0x2577b3===0x0){return 0x0;}var _0x288aa3=0x1;for(var _0x3ff026=0x1;_0x3ff026<=_0x2577b3;_0x3ff026+=0x1){_0x288aa3=0x1+_0x288aa3*_0x3ff026/_0x168ccb;}return 0x1/_0x288aa3;}exports[_0x8e9b('0x47')]=erlangb;function checkContactLowerLimitOriginate(_0x388bbd,_0x21ce39,_0xce655f){if(_0x21ce39>_0xce655f){for(var _0x57086e=0x0;_0x57086e<_0x21ce39-_0xce655f;_0x57086e+=0x1){decrementOriginate(_0x388bbd,_0x8e9b('0x48'));}}}exports[_0x8e9b('0x49')]=checkContactLowerLimitOriginate;function setXMDContactVariables(_0x35449a){var _0x541b3c={};var _0x3bf8a3=['id',_0x8e9b('0x4a'),'tags','updatedAt'];const _0x219321=0xfa;if(_0x35449a){for(var _0x376fea in _0x35449a){if(typeof _0x35449a[_0x376fea]!==_0x8e9b('0x4b')){if(!_[_0x8e9b('0x2a')](_0x35449a[_0x376fea])&&!_0x3bf8a3['includes'](_0x376fea)){if(_0x376fea==='description'&&_0x35449a[_0x376fea][_0x8e9b('0x45')]>_0x219321){_0x541b3c[_0x8e9b('0x4c')+_0x376fea['toUpperCase']()]=_0x35449a[_0x376fea][_0x8e9b('0x42')]()[_0x8e9b('0x4d')](0x0,_0x219321);}else{_0x541b3c[_0x8e9b('0x4c')+_0x376fea[_0x8e9b('0x4e')]()]=_0x35449a[_0x376fea];}}}}}return _0x541b3c;}exports[_0x8e9b('0x4f')]=setXMDContactVariables;