18 var _0xf4f4=['recordingURL','recordingFormat','none','The\x20ticket\x20ID\x20is:\x20%s','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...','inspect','lodash','bluebird','util','md5','ioredis','./util','../../../../config/environment','servicenow','defaults','redis','localhost','socket.io-emitter','GET','sys_user?sysparm_query=user_name%3Dadmin','then','length','adminId','result','sys_id','info','toUpperCase','catch','error','message','],\x20getUser\x20input\x20crm','validateEmail','userEmail','sys_user?sysparm_query=email%3D','],\x20getUser\x20rp\x20obj','],\x20getUser\x20entity','active','true','userId','adminEmail','],\x20getUser\x20crm',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','POST','sys_user?','user','endUserNumber','],\x20EndUser\x20schema','endUserId','],\x20getEndUser\x20input\x20crm','sys_user?sysparm_query=phone%3D','forEach','string','picklist','type','nameField','customField','content','toString','includes','variable','idField','toLowerCase','variableName','customVariable','Variable','name',']\x20getTicket\x20input\x20crm','outbound','incident','assign','getString','Fields','ticketId','ticketNumber','number','label','?sysparm_query=name%3D','label_entry','Incident','Incident\x20-\x20','push','all',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','Tags','%26sysparm_record_target%3Dincident','%26sysparm_record_row%3D1%26sysparm_record_rows%3D39','%26sysparm_record_list%3Dactive%253Dtrue','/nav_to.do?uri=incident.do?sys_id%3D','format','user:%s','emit','trigger:browser:url','username','sysparm_limit=1','sysparm_display_value=true','remoteUri','stripTrailingSlash','%s/api/now/table/','email','destcalleridnum','calleridnum','callDirection','unmanaged','queue','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','Recording\x20is\x20enabled!'];(function(_0x27236a,_0x59bc6b){var _0x34a6a3=function(_0x2d661f){while(--_0x2d661f){_0x27236a['push'](_0x27236a['shift']());}};_0x34a6a3(++_0x59bc6b);}(_0xf4f4,0xe3));var _0x4f4f=function(_0x36b941,_0x292375){_0x36b941=_0x36b941-0x0;var _0x2e5a6b=_0xf4f4[_0x36b941];return _0x2e5a6b;};'use strict';var _=require(_0x4f4f('0x0'));var Promise=require(_0x4f4f('0x1'));var rp=require('request-promise');var util=require(_0x4f4f('0x2'));var md5=require(_0x4f4f('0x3'));var Redis=require(_0x4f4f('0x4'));var intUtil=require(_0x4f4f('0x5'));var config=require(_0x4f4f('0x6'));var logger=require('../../../../config/logger')(_0x4f4f('0x7'));config['redis']=_[_0x4f4f('0x8')](config[_0x4f4f('0x9')],{'host':_0x4f4f('0xa'),'port':0x18eb});var io=require(_0x4f4f('0xb'))(new Redis(config[_0x4f4f('0x9')]));function getAdminUser(_0x249f8a,_0x2faba9,_0x3768d7,_0x48f6b9,_0xc066a4,_0x38d110){return new Promise(function(_0x39e36b,_0x2d86d1){var _0x116f22={'method':_0x4f4f('0xc'),'uri':_0x48f6b9+_0x4f4f('0xd')+'&'+_0xc066a4+'&'+_0x38d110,'auth':_0x2faba9,'json':!![]};return rp(_0x116f22)[_0x4f4f('0xe')](function(_0x49b9cf){if(_0x49b9cf['result'][_0x4f4f('0xf')]>0x0){_0x3768d7[_0x4f4f('0x10')]=_0x49b9cf[_0x4f4f('0x11')][0x0][_0x4f4f('0x12')];}logger[_0x4f4f('0x13')]('['+[_0x249f8a[_0x4f4f('0x14')]()]+'],\x20getAdminUser\x20crm',_0x3768d7);_0x39e36b(_0x3768d7);})[_0x4f4f('0x15')](function(_0x5e476d){logger[_0x4f4f('0x16')]('['+[_0x249f8a[_0x4f4f('0x14')]()]+']',_0x5e476d[_0x4f4f('0x17')]);_0x2d86d1(_0x5e476d[_0x4f4f('0x17')]);});});}function getUser(_0x4c849f,_0x19f2fd,_0x4c68f4,_0x47ab66,_0x58de77){return function(_0x422894){logger[_0x4f4f('0x13')]('['+[_0x4c849f[_0x4f4f('0x14')]()]+_0x4f4f('0x18'),_0x422894);return new Promise(function(_0x2d5e5d,_0x1777eb){if(intUtil[_0x4f4f('0x19')](_0x422894[_0x4f4f('0x1a')])){var _0x929a0b={'method':_0x4f4f('0xc'),'uri':_0x4c68f4+_0x4f4f('0x1b')+_0x422894[_0x4f4f('0x1a')]+'&'+_0x47ab66+'&'+_0x58de77,'auth':_0x19f2fd,'json':!![]};logger['info']('['+[_0x4c849f[_0x4f4f('0x14')]()]+_0x4f4f('0x1c'),_0x929a0b);return rp(_0x929a0b)[_0x4f4f('0xe')](function(_0x201c60){logger[_0x4f4f('0x13')]('['+[_0x4c849f[_0x4f4f('0x14')]()]+_0x4f4f('0x1d'),_0x201c60);if(_0x201c60[_0x4f4f('0x11')][_0x4f4f('0xf')]>0x0&&String(_0x201c60[_0x4f4f('0x11')][0x0][_0x4f4f('0x1e')])===_0x4f4f('0x1f')){_0x422894[_0x4f4f('0x20')]=_0x201c60[_0x4f4f('0x11')][0x0]['sys_id'];}else{_0x422894['userId']=_0x422894['adminId'];_0x422894[_0x4f4f('0x1a')]=_0x422894[_0x4f4f('0x21')];}logger['info']('['+[_0x4c849f[_0x4f4f('0x14')]()]+_0x4f4f('0x22'),_0x422894);_0x2d5e5d(_0x422894);})[_0x4f4f('0x15')](function(_0x2ec92a){logger[_0x4f4f('0x16')]('['+[_0x4c849f[_0x4f4f('0x14')]()]+']',_0x2ec92a[_0x4f4f('0x17')]);_0x1777eb(_0x2ec92a['message']);});}else{logger[_0x4f4f('0x13')]('['+[_0x4c849f[_0x4f4f('0x14')]()]+_0x4f4f('0x23'));_0x422894[_0x4f4f('0x20')]=_0x422894[_0x4f4f('0x10')];_0x422894['userEmail']=_0x422894[_0x4f4f('0x21')];_0x2d5e5d(_0x422894);}});};}function createEndUser(_0xaf3de1,_0x7180f8,_0x5deda9,_0x534075,_0x4c2490){logger[_0x4f4f('0x13')]('['+[_0xaf3de1['toUpperCase']()]+_0x4f4f('0x24'),_0x5deda9);return new Promise(function(_0x39c1a8,_0x2e688a){var _0x5eb7c9={'method':_0x4f4f('0x25'),'uri':_0x534075+_0x4f4f('0x26')+_0x4c2490,'body':{'user_name':_0x5deda9['endUserNumber'],'roles':_0x4f4f('0x27'),'first_name':_0x5deda9[_0x4f4f('0x28')],'active':_0x4f4f('0x1f'),'date_format':'System','phone':_0x5deda9[_0x4f4f('0x28')]},'auth':_0x7180f8,'json':!![]};return rp(_0x5eb7c9)[_0x4f4f('0xe')](function(_0x59bdb0){logger['info']('['+[_0xaf3de1[_0x4f4f('0x14')]()]+_0x4f4f('0x29'),_0x59bdb0[_0x4f4f('0x11')]);_0x5deda9[_0x4f4f('0x2a')]=_0x59bdb0[_0x4f4f('0x11')][_0x4f4f('0x12')];_0x39c1a8(_0x5deda9);})[_0x4f4f('0x15')](function(_0x373626){logger[_0x4f4f('0x16')]('['+[_0xaf3de1[_0x4f4f('0x14')]()]+']',_0x373626['message']);_0x2e688a(_0x373626['message']);});});}function getEndUser(_0x39d8d5,_0x4dfc79,_0x20890c,_0x423c89,_0x227151){return function(_0x4215da){logger[_0x4f4f('0x13')]('['+[_0x39d8d5[_0x4f4f('0x14')]()]+_0x4f4f('0x2b'),_0x4215da);return new Promise(function(_0x24834a,_0x2f53b3){var _0x19785e={'method':_0x4f4f('0xc'),'uri':_0x20890c+_0x4f4f('0x2c')+_0x4215da['endUserNumber']+'&'+_0x423c89+'&'+_0x227151,'auth':_0x4dfc79,'json':!![]};return rp(_0x19785e)[_0x4f4f('0xe')](function(_0x502017){if(_0x502017[_0x4f4f('0x11')][_0x4f4f('0xf')]>0x0){_0x4215da[_0x4f4f('0x2a')]=_0x502017[_0x4f4f('0x11')][0x0][_0x4f4f('0x12')];logger[_0x4f4f('0x13')]('['+[_0x39d8d5[_0x4f4f('0x14')]()]+'],\x20getEndUser\x20crm',_0x4215da);_0x24834a(_0x4215da);}else{return createEndUser(_0x39d8d5,_0x4dfc79,_0x4215da,_0x20890c,_0x423c89)[_0x4f4f('0xe')](function(_0x17dceb){logger[_0x4f4f('0x13')]('['+[_0x39d8d5['toUpperCase']()]+'],\x20createEndUser\x20crm',_0x17dceb);_0x24834a(_0x17dceb);});}})[_0x4f4f('0x15')](function(_0x95a296){logger[_0x4f4f('0x16')]('['+[_0x39d8d5[_0x4f4f('0x14')]()]+']',_0x95a296[_0x4f4f('0x17')]);_0x2f53b3(_0x95a296[_0x4f4f('0x17')]);});});};}function getCustomFields(_0x1c012d,_0x1ff7f3){var _0x2eb6c8={};if(_0x1c012d[_0x4f4f('0xf')]>0x0){_[_0x4f4f('0x2d')](_0x1c012d,function(_0x21eea7){if(_['includes']([_0x4f4f('0x2e'),_0x4f4f('0x2f')],_0x21eea7[_0x4f4f('0x30')])&&_0x21eea7[_0x4f4f('0x31')]&&!_0x21eea7[_0x4f4f('0x32')]){_0x2eb6c8[_0x21eea7['nameField']['toLowerCase']()]=_0x21eea7[_0x4f4f('0x33')][_0x4f4f('0x34')]();}else if(_[_0x4f4f('0x35')]([_0x4f4f('0x2e'),'picklist'],_0x21eea7[_0x4f4f('0x30')])&&_0x21eea7['idField']&&_0x21eea7[_0x4f4f('0x32')]){_0x2eb6c8[_0x21eea7['idField']['toLowerCase']()]=_0x21eea7[_0x4f4f('0x33')]['toString']();}else if(_0x21eea7[_0x4f4f('0x30')]===_0x4f4f('0x36')&&_0x21eea7['variableName']&&_0x21eea7[_0x4f4f('0x37')]&&_0x21eea7[_0x4f4f('0x32')]){_0x2eb6c8[_0x21eea7['idField'][_0x4f4f('0x38')]()]=_0x1ff7f3[_0x21eea7[_0x4f4f('0x39')]][_0x4f4f('0x34')]();}else if(_0x21eea7[_0x4f4f('0x30')]===_0x4f4f('0x3a')&&_0x21eea7[_0x4f4f('0x3b')]&&_0x21eea7[_0x4f4f('0x3b')][_0x4f4f('0x3c')]&&_0x21eea7[_0x4f4f('0x37')]&&_0x21eea7[_0x4f4f('0x32')]){_0x2eb6c8[_0x21eea7[_0x4f4f('0x37')][_0x4f4f('0x38')]()]=_0x1ff7f3[_0x21eea7[_0x4f4f('0x3b')][_0x4f4f('0x3c')][_0x4f4f('0x38')]()]['toString']();}});}return _0x2eb6c8;}function getTicket(_0x636b63,_0x531d36,_0x5a0063,_0x31349a,_0x4363c9,_0x5cf4da){return function(_0x12fb0d){logger[_0x4f4f('0x13')]('['+[_0x636b63[_0x4f4f('0x14')]()]+_0x4f4f('0x3d'),_0x12fb0d);return new Promise(function(_0x222511,_0x545dd6){var _0xd4625a=_0x636b63[_0x4f4f('0x38')]()===_0x4f4f('0x3e')?_0x12fb0d[_0x4f4f('0x20')]:_0x12fb0d[_0x4f4f('0x2a')];var _0x433787={'method':_0x4f4f('0x25'),'uri':_0x5a0063+_0x4f4f('0x3f')+'?'+_0x5cf4da,'body':Object[_0x4f4f('0x40')]({},{'active':'true','caller_id':_0xd4625a,'assigned_to':_0x12fb0d[_0x4f4f('0x20')],'short_description':intUtil[_0x4f4f('0x41')](_0x31349a['Subjects'],_0x4363c9,'\x20'),'description':intUtil['getString'](_0x31349a['Descriptions'],_0x4363c9,'\x0a')},getCustomFields(_0x31349a[_0x4f4f('0x42')],_0x4363c9)),'auth':_0x531d36,'json':!![]};return rp(_0x433787)[_0x4f4f('0xe')](function(_0x3a2ae3){logger['info']('['+[_0x636b63[_0x4f4f('0x14')]()]+']\x20POST\x20incident\x20entity\x20schema',_0x3a2ae3[_0x4f4f('0x11')]);_0x12fb0d[_0x4f4f('0x43')]=_0x3a2ae3[_0x4f4f('0x11')][_0x4f4f('0x12')];_0x12fb0d[_0x4f4f('0x44')]=_0x3a2ae3[_0x4f4f('0x11')][_0x4f4f('0x45')];logger[_0x4f4f('0x13')]('['+[_0x636b63[_0x4f4f('0x14')]()]+']\x20getTicket\x20crm',_0x12fb0d);_0x222511(_0x12fb0d);})['catch'](function(_0x36cfcf){logger[_0x4f4f('0x16')]('['+[_0x636b63['toUpperCase']()]+']',_0x36cfcf['message']);_0x545dd6(_0x36cfcf[_0x4f4f('0x17')]);});});};}function createRemoteTag(_0x319563,_0x15fd73,_0x55a5e4,_0x4a7622){return new Promise(function(_0x27c7fc,_0x3205ef){var _0x179998={'method':_0x4f4f('0x25'),'uri':_0x55a5e4+_0x4f4f('0x46')+'?'+_0x4a7622,'body':{'short_description':_0x319563,'global':!![],'active':!![],'name':_0x319563},'auth':_0x15fd73,'json':!![]};return rp(_0x179998)[_0x4f4f('0xe')](function(_0xe66fc){var _0x26a879=_0xe66fc[_0x4f4f('0x11')][_0x4f4f('0x12')];_0x27c7fc(_0x26a879);});});}function getRemoteTag(_0x1d8188,_0x50280a,_0x585c06,_0x376aea,_0x136d83){return new Promise(function(_0x161943,_0x58f349){var _0x4b4e7e={'method':_0x4f4f('0xc'),'uri':_0x585c06+'label'+_0x4f4f('0x47')+_0x1d8188+'&'+_0x376aea,'auth':_0x50280a,'json':!![]};return rp(_0x4b4e7e)[_0x4f4f('0xe')](function(_0x1c6489){if(_0x1c6489['result'][_0x4f4f('0xf')]>0x0){var _0xf18746=_0x1c6489[_0x4f4f('0x11')][0x0]['sys_id'];_0x161943(_0xf18746);}else{return createRemoteTag(_0x1d8188,_0x50280a,_0x585c06,_0x376aea)[_0x4f4f('0xe')](function(_0x324179){_0x161943(_0x324179);});}});});}function assignTagToIncident(_0x1d48fb,_0x58a5dd,_0x2b01da,_0x16f162,_0x3fedae){return new Promise(function(_0x53ea7c,_0x90f8d7){var _0x5418cd={'method':_0x4f4f('0x25'),'uri':_0x2b01da+_0x4f4f('0x48')+'?'+_0x3fedae,'body':{'label':_0x1d48fb,'table':_0x4f4f('0x3f'),'id_type':_0x4f4f('0x49'),'table_key':_0x16f162[_0x4f4f('0x43')],'title':_0x4f4f('0x4a')+_0x16f162[_0x4f4f('0x44')],'id_display':_0x16f162[_0x4f4f('0x44')]},'auth':_0x58a5dd,'json':!![]};return rp(_0x5418cd)[_0x4f4f('0xe')](function(_0x36f369){_0x53ea7c();})[_0x4f4f('0x15')](function(){_0x53ea7c();});});}function manageTags(_0x5ba1e2,_0x4794fe,_0x297c9c,_0xc47aa2,_0x5d1fdf,_0x46bc73,_0x43908e){return new Promise(function(_0x151c75,_0x1ac3bc){var _0x561411=[];_0x4794fe[_0x4f4f('0x2d')](function(_0x213163){_0x561411[_0x4f4f('0x4b')](getRemoteTag(_0x213163,_0x297c9c,_0xc47aa2,_0x46bc73,_0x43908e));});return Promise[_0x4f4f('0x4c')](_0x561411)[_0x4f4f('0xe')](function(_0x5e2ef4){if(_0x5e2ef4[_0x4f4f('0xf')]){logger['info']('['+[_0x5ba1e2[_0x4f4f('0x14')]()]+_0x4f4f('0x4d'),_0x5e2ef4);var _0x2da4ea=[];_0x5e2ef4[_0x4f4f('0x2d')](function(_0x132b97){_0x2da4ea[_0x4f4f('0x4b')](assignTagToIncident(_0x132b97,_0x297c9c,_0xc47aa2,_0x5d1fdf,_0x46bc73));});return Promise['all'](_0x2da4ea)['then'](function(){_0x151c75();})[_0x4f4f('0x15')](function(){_0x151c75();});}else{_0x151c75();}});});}function getTags(_0x4c42fd,_0x4252fa,_0xd67430,_0x46ba03,_0x1156f9,_0x468782){return function(_0x211fbb){return new Promise(function(_0x37ad3a,_0x346ebb){var _0x356224=[];var _0x2b288f=_0x46ba03[_0x4f4f('0x4e')];if(_0x2b288f&&_0x2b288f['length']>0x0){_0x356224=_['map'](_0x2b288f,'name');}if(_0x356224[_0x4f4f('0xf')]>0x0){return manageTags(_0x4c42fd,_0x356224,_0x4252fa,_0xd67430,_0x211fbb,_0x1156f9,_0x468782)[_0x4f4f('0xe')](function(){_0x37ad3a(_0x211fbb);});}else{_0x37ad3a(_0x211fbb);}});};}function emit(_0x49c7c4,_0x21f344,_0x3dfcdb){var _0x43d6c0=_0x4f4f('0x4f')+_0x4f4f('0x50')+_0x4f4f('0x51')+'%255EORDERBYDESCnumber';var _0x3961e8={'uri':_0x49c7c4+_0x4f4f('0x52')+_0x3dfcdb+_0x43d6c0};io['to'](util[_0x4f4f('0x53')](_0x4f4f('0x54'),_0x21f344))[_0x4f4f('0x55')](_0x4f4f('0x56'),_0x3961e8);}exports['cs']=function(_0x1d756b,_0x7f5e70,_0x5d1913,_0x3fa4b5,_0x297b40,_0x3c9a28,_0x38232d,_0x5f0efc){var _0x627a24={};var _0x4a3b82={'user':_0x3c9a28[_0x4f4f('0x57')],'pass':_0x3c9a28['password']};var _0x57ee5b=_0x4f4f('0x58');var _0xa19f8f=_0x4f4f('0x59');_0x3c9a28[_0x4f4f('0x5a')]=intUtil['stripTrailingSlash'](_0x3c9a28[_0x4f4f('0x5a')]);_0x3c9a28['serverUrl']=intUtil[_0x4f4f('0x5b')](_0x3c9a28['serverUrl']);var _0x403a61=util[_0x4f4f('0x53')](_0x4f4f('0x5c'),_0x3c9a28['remoteUri']);_0x627a24[_0x4f4f('0x1a')]=!_['isNil'](_0x3fa4b5)?_0x3fa4b5[_0x4f4f('0x5d')]:null;_0x627a24[_0x4f4f('0x21')]=_0x3c9a28[_0x4f4f('0x5d')];_0x627a24[_0x4f4f('0x28')]=_0x5f0efc[_0x4f4f('0x38')]()===_0x4f4f('0x3e')?_0x7f5e70[_0x4f4f('0x5e')]:_0x7f5e70[_0x4f4f('0x5f')];_0x627a24[_0x4f4f('0x60')]=_0x5f0efc==='queue'||_0x5f0efc===_0x4f4f('0x61')?_0x4f4f('0x62'):_0x4f4f('0x3e');var _0x14e4f3=util[_0x4f4f('0x53')](_0x4f4f('0x63'),_0x3c9a28['serverUrl'],_0x7f5e70[_0x4f4f('0x64')],md5(_0x7f5e70[_0x4f4f('0x64')]));if(_0x297b40&&_0x297b40[_0x4f4f('0x65')]){logger[_0x4f4f('0x13')]('[QUEUE]',_0x4f4f('0x66'));_0x7f5e70[_0x4f4f('0x67')]=_0x14e4f3;}else if(_0x38232d&&_0x38232d[_0x4f4f('0x68')]&&_0x38232d['recordingFormat']!==_0x4f4f('0x69')){logger[_0x4f4f('0x13')]('[OUTBOUND]',_0x4f4f('0x66'));_0x7f5e70[_0x4f4f('0x67')]=_0x14e4f3;}else{_0x7f5e70[_0x4f4f('0x67')]='';}return getAdminUser(_0x5f0efc,_0x4a3b82,_0x627a24,_0x403a61,_0xa19f8f,_0x57ee5b)[_0x4f4f('0xe')](getUser(_0x5f0efc,_0x4a3b82,_0x403a61,_0xa19f8f,_0x57ee5b))[_0x4f4f('0xe')](getEndUser(_0x5f0efc,_0x4a3b82,_0x403a61,_0xa19f8f,_0x57ee5b))[_0x4f4f('0xe')](getTicket(_0x5f0efc,_0x4a3b82,_0x403a61,_0x5d1913,_0x7f5e70,_0xa19f8f))['then'](function(_0x6d0984){logger[_0x4f4f('0x13')](util[_0x4f4f('0x53')](_0x4f4f('0x6a'),_0x6d0984[_0x4f4f('0x43')]));logger[_0x4f4f('0x13')](util['format'](_0x4f4f('0x6b'),_0x5f0efc));if(_0x5f0efc!==_0x4f4f('0x61')){logger[_0x4f4f('0x13')]('['+[_0x5f0efc['toUpperCase']()]+']',_0x4f4f('0x6c'));emit(_0x3c9a28[_0x4f4f('0x5a')],_0x3fa4b5[_0x4f4f('0x3c')],_0x6d0984[_0x4f4f('0x43')]);}})[_0x4f4f('0x15')](function(_0x53be08){logger[_0x4f4f('0x16')]('['+[_0x5f0efc['toUpperCase']()]+']\x20Error\x20running\x20ServiceNow\x20integration',util[_0x4f4f('0x6d')](_0x53be08,{'showHidden':!![],'depth':null}));});};