Built motion from commit 06eb8eb0.|2.6.31
[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 _0xeb27=['RECALLFAILEDTIMEOUT','RUNNING','TIMEZONE_UNKNOW','TRUNK_IS_NOT_REACHABLE','dialMethod','isPreviewCampaign','type','ivr','isIVRCampaign','outbound','isOutboundQueue','dialActive','active','isIVRCampaignActive','milliseconds','diff','seconds','getSeconds','message','available','loggedIn','paused','talking','pTalking','waiting','inUse','originated','Trunk','name','hasQueueCampaignDataChanged','isNil','dialGlobalInterval','Interval','isEmpty','Intervals','EMPTY_INTERVAL','UNKNOWN_TIMEZONE','SIP/','reachable','unmonitored','includes','status','TrunkBackup','INACTIVE','DISACTIVED','NO_AGENTS_LOGGED','UNREACHABLE_TRUNK','getQueueCampaignStatusMessage','getQueueCampaignActiveStatusMessage','match','extractCalleridName','string','isUndefined','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','\x5cw{0,','pow','replace','random','error','[decrementOriginate]\x20queue\x20originate\x20value','decrementOriginate','checkContactEmpty','[checkContactLowerLimitOriginate]\x20','checkContactLowerLimitOriginate','updatedAt','undefined','length','XMD-','toUpperCase','toString','setXMDContactVariables','../../../../config/logger','dialer','timezones','ACTIVE','BLACKLIST','DEACTIVATED','IS_DISACTIVED','NOT_ACTIVE','AGENTS_NOT_LOGGED','AVAILABLE_CONTACTS_FINISHED','INTERVAL_IS_NULL','INTERVAL_IS_OVERTIME','GLOBAL_INTERVAL_IS_OVERTIME'];(function(_0x36ed48,_0x1ee0d4){var _0x51c63a=function(_0x2d0a40){while(--_0x2d0a40){_0x36ed48['push'](_0x36ed48['shift']());}};_0x51c63a(++_0x1ee0d4);}(_0xeb27,0x9f));var _0x7eb2=function(_0x24cd66,_0x5e1ca9){_0x24cd66=_0x24cd66-0x0;var _0x320cf4=_0xeb27[_0x24cd66];return _0x320cf4;};'use strict';var _=require('lodash');var moment=require('moment');var util=require('util');var logger=require(_0x7eb2('0x0'))(_0x7eb2('0x1'));var timezones=require('../../../../config/environment/shared')[_0x7eb2('0x2')];var CAMPAIGN_STATUS={'ACTIVE':_0x7eb2('0x3'),'BLACKLIST':_0x7eb2('0x4'),'CONTACTS_RESCHEDULED':'RESCHEDULED_CONTACTS','DEACTIVATED':_0x7eb2('0x5'),'DISACTIVED':_0x7eb2('0x6'),'EMPTY_INTERVAL':'INTERVAL_IS_EMPTY','INACTIVE':_0x7eb2('0x7'),'NO_AGENTS_LOGGED':_0x7eb2('0x8'),'NO_AVAILABLE_CONTACTS':_0x7eb2('0x9'),'NULL_INTERVAL':_0x7eb2('0xa'),'OVERTIME_INTERVAL':_0x7eb2('0xb'),'OVERTIME_GLOBAL_INTERVAL':_0x7eb2('0xc'),'QUEUE_RECALL':'RECALLINQUEUE','RECALL_TIMEOUT':_0x7eb2('0xd'),'RUNNING':_0x7eb2('0xe'),'UNKNOWN_TIMEZONE':_0x7eb2('0xf'),'UNREACHABLE_TRUNK':_0x7eb2('0x10')};exports['CAMPAIGN_STATUS']=CAMPAIGN_STATUS;function isPreviewCampaign(_0xd67b29){return _0xd67b29[_0x7eb2('0x11')]==='preview';}exports[_0x7eb2('0x12')]=isPreviewCampaign;function isIVRCampaign(_0x1911d2){return _0x1911d2[_0x7eb2('0x13')]===_0x7eb2('0x14');}exports[_0x7eb2('0x15')]=isIVRCampaign;function isOutboundQueue(_0x3ef33b){return _0x3ef33b[_0x7eb2('0x13')]===_0x7eb2('0x16');}exports[_0x7eb2('0x17')]=isOutboundQueue;function isQueueCampaignActive(_0x3319bb){return _0x3319bb[_0x7eb2('0x18')];}exports['isQueueCampaignActive']=isQueueCampaignActive;function isIVRCampaignActive(_0x1a0b19){return _0x1a0b19[_0x7eb2('0x19')];}exports[_0x7eb2('0x1a')]=isIVRCampaignActive;function getSeconds(_0x1f6e54,_0x3eb7df){var _0x37f445=moment(_0x1f6e54)[_0x7eb2('0x1b')](0x0);var _0x244fe1=moment(_0x3eb7df)['milliseconds'](0x0);return _0x37f445[_0x7eb2('0x1c')](_0x244fe1,_0x7eb2('0x1d'));}exports[_0x7eb2('0x1e')]=getSeconds;function hasQueueCampaignDataChanged(_0x3a960c,_0x2096ae){var _0x17a55f=![];var _0x410375=_0x3a960c['dialMethod']!==_0x2096ae[_0x7eb2('0x11')]||_0x3a960c['dialActive']!==_0x2096ae['dialActive']||_0x3a960c[_0x7eb2('0x1f')]!==_0x2096ae[_0x7eb2('0x1f')];var _0xf543ed=_0x3a960c[_0x7eb2('0x20')]!==_0x2096ae['available']||_0x3a960c[_0x7eb2('0x21')]!==_0x2096ae['loggedIn']||_0x3a960c['loggedInDb']!==_0x2096ae['loggedInDb']||_0x3a960c[_0x7eb2('0x22')]!==_0x2096ae[_0x7eb2('0x22')]||_0x3a960c[_0x7eb2('0x23')]!==_0x2096ae['talking']||_0x3a960c['pTalking']!==_0x2096ae[_0x7eb2('0x24')]||_0x3a960c[_0x7eb2('0x25')]!==_0x2096ae[_0x7eb2('0x25')]||_0x3a960c[_0x7eb2('0x26')]!==_0x2096ae['inUse']||_0x3a960c['originated']!==_0x2096ae[_0x7eb2('0x27')];if(_0x3a960c[_0x7eb2('0x28')]&&_0x2096ae['Trunk']){_0x17a55f=_0x3a960c[_0x7eb2('0x28')][_0x7eb2('0x29')]!==_0x2096ae[_0x7eb2('0x28')][_0x7eb2('0x29')]||_0x3a960c[_0x7eb2('0x28')][_0x7eb2('0x19')]!==_0x2096ae[_0x7eb2('0x28')][_0x7eb2('0x19')];}return _0x410375||_0xf543ed||_0x17a55f;}exports[_0x7eb2('0x2a')]=hasQueueCampaignDataChanged;function checkAnyValidQueueCampaignInterval(_0x57449e){var _0x5c9478=null;var _0x5a959f=_0x57449e['dialTimezone'];if(_[_0x7eb2('0x2b')](_0x57449e[_0x7eb2('0x2c')])||_[_0x7eb2('0x2b')](_0x57449e[_0x7eb2('0x2d')])||_[_0x7eb2('0x2b')](_0x57449e['Interval']['Intervals'])){_0x5c9478=CAMPAIGN_STATUS['NULL_INTERVAL'];}else if(_['isEmpty'](_0x57449e['dialGlobalInterval'])||_[_0x7eb2('0x2e')](_0x57449e[_0x7eb2('0x2d')][_0x7eb2('0x2f')])){_0x5c9478=CAMPAIGN_STATUS[_0x7eb2('0x30')];}else if(_0x5a959f&&!timezones[_0x5a959f]){_0x5c9478=CAMPAIGN_STATUS[_0x7eb2('0x31')];}return _0x5c9478;}function checkAnyValidTrunk(_0x349053,_0x47b3c6){var _0x3bf4a5=null;var _0x231938=_0x7eb2('0x32');var _0x2127a3=[_0x7eb2('0x33'),_0x7eb2('0x34')];var _0xef17e1=!![];if(_0x349053[_0x7eb2('0x28')]&&_0x349053[_0x7eb2('0x28')][_0x7eb2('0x19')]){_0x231938+=_0x349053[_0x7eb2('0x28')][_0x7eb2('0x29')];_0x3bf4a5=_0x47b3c6[_0x231938];_0xef17e1=_0x2127a3[_0x7eb2('0x35')](_0x3bf4a5[_0x7eb2('0x36')]);}else if(_0x349053[_0x7eb2('0x37')]&&_0x349053[_0x7eb2('0x37')][_0x7eb2('0x19')]){_0x231938+=_0x349053[_0x7eb2('0x37')][_0x7eb2('0x29')];_0x3bf4a5=_0x47b3c6[_0x231938];_0xef17e1=_0x2127a3['includes'](_0x3bf4a5[_0x7eb2('0x36')]);}return _0xef17e1;}function getQueueCampaignStatusMessage(_0x543331,_0x2c0812){var _0x568177=CAMPAIGN_STATUS[_0x7eb2('0x3')];var _0x1f2ea2=isPreviewCampaign(_0x543331);if(!isQueueCampaignActive(_0x543331)){if(_0x1f2ea2){_0x568177=CAMPAIGN_STATUS[_0x7eb2('0x38')];}else{if(_0x543331[_0x7eb2('0x27')]===0x0&&_0x543331[_0x7eb2('0x23')]===0x0&&_0x543331[_0x7eb2('0x25')]===0x0&&(_0x543331[_0x7eb2('0x24')]||0x0)===0x0){_0x568177=CAMPAIGN_STATUS[_0x7eb2('0x38')];}else{_0x568177=CAMPAIGN_STATUS[_0x7eb2('0x39')];}}}else if(_0x543331[_0x7eb2('0x21')]===0x0){_0x568177=CAMPAIGN_STATUS[_0x7eb2('0x3a')];}else if(!checkAnyValidTrunk(_0x543331,_0x2c0812)){_0x568177=CAMPAIGN_STATUS[_0x7eb2('0x3b')];}else if(!isPreviewCampaign(_0x543331)){var _0x3daccf=checkAnyValidQueueCampaignInterval(_0x543331);if(_0x3daccf){_0x568177=_0x3daccf;}}return _0x568177;}exports[_0x7eb2('0x3c')]=getQueueCampaignStatusMessage;function getQueueCampaignActiveStatusMessage(_0x3f47ac){var _0x34435f=CAMPAIGN_STATUS['DISACTIVED'];if(_0x3f47ac[_0x7eb2('0x27')]===0x0&&_0x3f47ac['talking']===0x0&&_0x3f47ac['waiting']===0x0&&(_0x3f47ac['pTalking']||0x0)===0x0){_0x34435f=CAMPAIGN_STATUS['INACTIVE'];}return _0x34435f;}exports[_0x7eb2('0x3d')]=getQueueCampaignActiveStatusMessage;function extractCalleridName(_0x157808){var _0x482cc8=_0x157808[_0x7eb2('0x3e')](/"(.*?)"/);return _0x482cc8?_0x482cc8[0x1]:_0x157808;}exports[_0x7eb2('0x3f')]=extractCalleridName;function getCallerId(_0x341303,_0x596d59,_0x2056b1){if(!_['isUndefined'](_0x2056b1)&&typeof _0x2056b1===_0x7eb2('0x40')&&!_[_0x7eb2('0x2e')](_0x2056b1)){if(!_[_0x7eb2('0x41')](_0x596d59)&&typeof _0x596d59==='string'&&!_[_0x7eb2('0x2e')](_0x596d59)){return util[_0x7eb2('0x42')](_0x7eb2('0x43'),_0x596d59,_0x2056b1);}return util[_0x7eb2('0x42')](_0x7eb2('0x43'),_0x2056b1,_0x2056b1);}if(!_[_0x7eb2('0x41')](_0x341303)&&typeof _0x341303===_0x7eb2('0x40')&&!_[_0x7eb2('0x2e')](_0x341303)){return _0x341303;}return _0x7eb2('0x44');}exports['getCallerId']=getCallerId;function getCallerIdRandom(_0x3a3bf3,_0x180846){var _0x46d6fa;var _0x338274;var _0x172f57;if(_0x180846<=0x0){_0x180846=0x1;}_0x46d6fa=new RegExp(_0x7eb2('0x45')+_0x180846+'}$');_0x338274=Math[_0x7eb2('0x46')](0xa,_0x180846-0x1);_0x172f57=Math[_0x7eb2('0x46')](0xa,_0x180846)-0x1;return util[_0x7eb2('0x42')]('%s',_[_0x7eb2('0x47')](_0x3a3bf3,_0x46d6fa,_[_0x7eb2('0x48')](_0x338274,_0x172f57)['toString']()));}exports['getCallerIdRandom']=getCallerIdRandom;function decrementOriginate(_0x11145f,_0x261aee){if(_0x11145f[_0x7eb2('0x27')]&&_0x11145f[_0x7eb2('0x27')]>0x0){_0x11145f[_0x7eb2('0x27')]-=0x1;}else{logger[_0x7eb2('0x49')](_0x7eb2('0x4a'),_0x261aee);}}exports[_0x7eb2('0x4b')]=decrementOriginate;function checkContactEmpty(_0x598057){return _0x598057&&_0x598057['length']>0x0;}exports[_0x7eb2('0x4c')]=checkContactEmpty;function erlangb(_0x155065,_0x2f9045){if(_0x2f9045===0x0){return 0x0;}var _0x401347=0x1;for(var _0x2a8eb5=0x1;_0x2a8eb5<=_0x2f9045;_0x2a8eb5+=0x1){_0x401347=0x1+_0x401347*_0x2a8eb5/_0x155065;}return 0x1/_0x401347;}exports['erlangb']=erlangb;function checkContactLowerLimitOriginate(_0x2e8cf8,_0x25661f,_0x2a55d0){if(_0x25661f>_0x2a55d0){for(var _0x32571d=0x0;_0x32571d<_0x25661f-_0x2a55d0;_0x32571d+=0x1){decrementOriginate(_0x2e8cf8,_0x7eb2('0x4d'));}}}exports[_0x7eb2('0x4e')]=checkContactLowerLimitOriginate;function setXMDContactVariables(_0x2d51e4){var _0x5954b1={};var _0x41ca8d=['id','createdAt','tags',_0x7eb2('0x4f')];const _0x2dfcff=0xfa;if(_0x2d51e4){for(var _0x3ea7c1 in _0x2d51e4){if(typeof _0x2d51e4[_0x3ea7c1]!==_0x7eb2('0x50')){if(!_[_0x7eb2('0x2b')](_0x2d51e4[_0x3ea7c1])&&!_0x41ca8d[_0x7eb2('0x35')](_0x3ea7c1)){if(_0x3ea7c1==='description'&&_0x2d51e4[_0x3ea7c1][_0x7eb2('0x51')]>_0x2dfcff){_0x5954b1[_0x7eb2('0x52')+_0x3ea7c1[_0x7eb2('0x53')]()]=_0x2d51e4[_0x3ea7c1][_0x7eb2('0x54')]()['substring'](0x0,_0x2dfcff);}else{_0x5954b1[_0x7eb2('0x52')+_0x3ea7c1[_0x7eb2('0x53')]()]=_0x2d51e4[_0x3ea7c1];}}}}}return _0x5954b1;}exports[_0x7eb2('0x55')]=setXMDContactVariables;