Built motion from commit e1760111.|2.6.18
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 40461c7..53ef618 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5fc3=['],\x20EndUser\x20schema','sys_user?sysparm_query=phone%3D','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','type','nameField','customField','idField','content','toString','string','toLowerCase','Variable','name',']\x20getTicket\x20input\x20crm','outbound','assign','getString','Subjects','Descriptions','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketId','ticketNumber','number',']\x20getTicket\x20crm','label','label_entry','incident','Incident','Incident\x20-\x20','push','all',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','Tags','map','%26sysparm_record_row%3D1%26sysparm_record_rows%3D39','%26sysparm_record_list%3Dactive%253Dtrue','%255EORDERBYDESCnumber','/nav_to.do?uri=incident.do?sys_id%3D','format','user:%s','emit','trigger:browser:url','sysparm_display_value=true','remoteUri','stripTrailingSlash','serverUrl','%s/api/now/table/','isNil','email','calleridnum','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...','inspect','lodash','bluebird','util','md5','ioredis','./util','../../../../config/environment','servicenow','redis','defaults','socket.io-emitter','GET','then','length','adminId','info','],\x20getAdminUser\x20crm','catch','error','toUpperCase','userEmail','],\x20getUser\x20entity','result','active','true','sys_id','userId','message','adminEmail','],\x20createEndUser\x20input\x20crm','POST','sys_user?','endUserNumber','System'];(function(_0x5e8584,_0xab5d1f){var _0x500b5a=function(_0x5b4223){while(--_0x5b4223){_0x5e8584['push'](_0x5e8584['shift']());}};_0x500b5a(++_0xab5d1f);}(_0x5fc3,0xa8));var _0x35fc=function(_0x255ac0,_0x3f6645){_0x255ac0=_0x255ac0-0x0;var _0x437bf1=_0x5fc3[_0x255ac0];return _0x437bf1;};'use strict';var _=require(_0x35fc('0x0'));var Promise=require(_0x35fc('0x1'));var rp=require('request-promise');var util=require(_0x35fc('0x2'));var md5=require(_0x35fc('0x3'));var Redis=require(_0x35fc('0x4'));var intUtil=require(_0x35fc('0x5'));var config=require(_0x35fc('0x6'));var logger=require('../../../../config/logger')(_0x35fc('0x7'));config[_0x35fc('0x8')]=_[_0x35fc('0x9')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x35fc('0xa'))(new Redis(config['redis']));function getAdminUser(_0x16e153,_0x27524f,_0xc72d93,_0x1e5f90,_0x34ff19,_0xf9d3a6){return new Promise(function(_0x2051ab,_0x565f95){var _0x1083a9={'method':_0x35fc('0xb'),'uri':_0x1e5f90+'sys_user?sysparm_query=user_name%3Dadmin'+'&'+_0x34ff19+'&'+_0xf9d3a6,'auth':_0x27524f,'json':!![]};return rp(_0x1083a9)[_0x35fc('0xc')](function(_0x33f491){if(_0x33f491['result'][_0x35fc('0xd')]>0x0){_0xc72d93[_0x35fc('0xe')]=_0x33f491['result'][0x0]['sys_id'];}logger[_0x35fc('0xf')]('['+[_0x16e153['toUpperCase']()]+_0x35fc('0x10'),_0xc72d93);_0x2051ab(_0xc72d93);})[_0x35fc('0x11')](function(_0x2a6ad2){logger[_0x35fc('0x12')]('['+[_0x16e153[_0x35fc('0x13')]()]+']',_0x2a6ad2['message']);_0x565f95(_0x2a6ad2['message']);});});}function getUser(_0x5eac0f,_0x558364,_0x398b67,_0x229d56,_0x53b898){return function(_0x154958){logger[_0x35fc('0xf')]('['+[_0x5eac0f[_0x35fc('0x13')]()]+'],\x20getUser\x20input\x20crm',_0x154958);return new Promise(function(_0x26ba54,_0x45c8b7){if(intUtil['validateEmail'](_0x154958[_0x35fc('0x14')])){var _0x363e47={'method':_0x35fc('0xb'),'uri':_0x398b67+'sys_user?sysparm_query=email%3D'+_0x154958[_0x35fc('0x14')]+'&'+_0x229d56+'&'+_0x53b898,'auth':_0x558364,'json':!![]};logger[_0x35fc('0xf')]('['+[_0x5eac0f[_0x35fc('0x13')]()]+'],\x20getUser\x20rp\x20obj',_0x363e47);return rp(_0x363e47)[_0x35fc('0xc')](function(_0x350a27){logger[_0x35fc('0xf')]('['+[_0x5eac0f[_0x35fc('0x13')]()]+_0x35fc('0x15'),_0x350a27);if(_0x350a27[_0x35fc('0x16')][_0x35fc('0xd')]>0x0&&String(_0x350a27[_0x35fc('0x16')][0x0][_0x35fc('0x17')])===_0x35fc('0x18')){_0x154958['userId']=_0x350a27[_0x35fc('0x16')][0x0][_0x35fc('0x19')];}else{_0x154958[_0x35fc('0x1a')]=_0x154958[_0x35fc('0xe')];_0x154958[_0x35fc('0x14')]=_0x154958['adminEmail'];}logger[_0x35fc('0xf')]('['+[_0x5eac0f[_0x35fc('0x13')]()]+'],\x20getUser\x20crm',_0x154958);_0x26ba54(_0x154958);})[_0x35fc('0x11')](function(_0x5a93df){logger[_0x35fc('0x12')]('['+[_0x5eac0f['toUpperCase']()]+']',_0x5a93df[_0x35fc('0x1b')]);_0x45c8b7(_0x5a93df['message']);});}else{logger[_0x35fc('0xf')]('['+[_0x5eac0f[_0x35fc('0x13')]()]+']\x20using\x20admin\x20profile');_0x154958['userId']=_0x154958[_0x35fc('0xe')];_0x154958['userEmail']=_0x154958[_0x35fc('0x1c')];_0x26ba54(_0x154958);}});};}function createEndUser(_0x1a5d92,_0x57001c,_0x26b7cb,_0x645eac,_0x383837){logger[_0x35fc('0xf')]('['+[_0x1a5d92[_0x35fc('0x13')]()]+_0x35fc('0x1d'),_0x26b7cb);return new Promise(function(_0x11ccdb,_0x451f0c){var _0x54aedc={'method':_0x35fc('0x1e'),'uri':_0x645eac+_0x35fc('0x1f')+_0x383837,'body':{'user_name':_0x26b7cb[_0x35fc('0x20')],'roles':'user','first_name':_0x26b7cb[_0x35fc('0x20')],'active':_0x35fc('0x18'),'date_format':_0x35fc('0x21'),'phone':_0x26b7cb[_0x35fc('0x20')]},'auth':_0x57001c,'json':!![]};return rp(_0x54aedc)[_0x35fc('0xc')](function(_0x103181){logger[_0x35fc('0xf')]('['+[_0x1a5d92[_0x35fc('0x13')]()]+_0x35fc('0x22'),_0x103181[_0x35fc('0x16')]);_0x26b7cb['endUserId']=_0x103181['result'][_0x35fc('0x19')];_0x11ccdb(_0x26b7cb);})['catch'](function(_0x37b394){logger[_0x35fc('0x12')]('['+[_0x1a5d92[_0x35fc('0x13')]()]+']',_0x37b394[_0x35fc('0x1b')]);_0x451f0c(_0x37b394[_0x35fc('0x1b')]);});});}function getEndUser(_0x12e78f,_0x4e43b4,_0x3fe193,_0x330a14,_0x46b9ef){return function(_0x4441d8){logger[_0x35fc('0xf')]('['+[_0x12e78f[_0x35fc('0x13')]()]+'],\x20getEndUser\x20input\x20crm',_0x4441d8);return new Promise(function(_0x2483be,_0x38193d){var _0x1fecdf={'method':'GET','uri':_0x3fe193+_0x35fc('0x23')+_0x4441d8['endUserNumber']+'&'+_0x330a14+'&'+_0x46b9ef,'auth':_0x4e43b4,'json':!![]};return rp(_0x1fecdf)[_0x35fc('0xc')](function(_0x33a377){if(_0x33a377[_0x35fc('0x16')][_0x35fc('0xd')]>0x0){_0x4441d8['endUserId']=_0x33a377['result'][0x0]['sys_id'];logger[_0x35fc('0xf')]('['+[_0x12e78f['toUpperCase']()]+_0x35fc('0x24'),_0x4441d8);_0x2483be(_0x4441d8);}else{return createEndUser(_0x12e78f,_0x4e43b4,_0x4441d8,_0x3fe193,_0x330a14)['then'](function(_0x9c6b65){logger[_0x35fc('0xf')]('['+[_0x12e78f[_0x35fc('0x13')]()]+_0x35fc('0x25'),_0x9c6b65);_0x2483be(_0x9c6b65);});}})[_0x35fc('0x11')](function(_0x3313fa){logger[_0x35fc('0x12')]('['+[_0x12e78f['toUpperCase']()]+']',_0x3313fa[_0x35fc('0x1b')]);_0x38193d(_0x3313fa[_0x35fc('0x1b')]);});});};}function getCustomFields(_0x4e0ce3,_0x1feda5){var _0x1ccc41={};if(_0x4e0ce3[_0x35fc('0xd')]>0x0){_[_0x35fc('0x26')](_0x4e0ce3,function(_0x813866){if(_0x813866[_0x35fc('0x27')]==='string'&&_0x813866[_0x35fc('0x28')]&&!_0x813866[_0x35fc('0x29')]){_0x1ccc41[_0x813866[_0x35fc('0x2a')]['toLowerCase']()]=_0x813866[_0x35fc('0x2b')][_0x35fc('0x2c')]();}else if(_0x813866['type']===_0x35fc('0x2d')&&_0x813866[_0x35fc('0x2a')]&&_0x813866[_0x35fc('0x29')]){_0x1ccc41[_0x813866[_0x35fc('0x2a')][_0x35fc('0x2e')]()]=_0x813866[_0x35fc('0x2b')][_0x35fc('0x2c')]();}else if(_0x813866[_0x35fc('0x27')]==='variable'&&_0x813866['variableName']&&_0x813866[_0x35fc('0x2a')]&&_0x813866[_0x35fc('0x29')]){_0x1ccc41[_0x813866['idField']['toLowerCase']()]=_0x1feda5[_0x813866['variableName']][_0x35fc('0x2c')]();}else if(_0x813866[_0x35fc('0x27')]==='customVariable'&&_0x813866[_0x35fc('0x2f')]&&_0x813866[_0x35fc('0x2f')][_0x35fc('0x30')]&&_0x813866[_0x35fc('0x2a')]&&_0x813866['customField']){_0x1ccc41[_0x813866['idField']['toLowerCase']()]=_0x1feda5[_0x813866['Variable']['name'][_0x35fc('0x2e')]()][_0x35fc('0x2c')]();}});}return _0x1ccc41;}function getTicket(_0x4fc5bc,_0x119925,_0x56cf1f,_0x13d16c,_0x40797d,_0x350237){return function(_0x2de5d1){logger[_0x35fc('0xf')]('['+[_0x4fc5bc['toUpperCase']()]+_0x35fc('0x31'),_0x2de5d1);return new Promise(function(_0x2c25d5,_0x4fd3d8){var _0x18181b=_0x4fc5bc[_0x35fc('0x2e')]()===_0x35fc('0x32')?_0x2de5d1[_0x35fc('0x1a')]:_0x2de5d1['endUserId'];var _0x3666a5={'method':'POST','uri':_0x56cf1f+'incident'+'?'+_0x350237,'body':Object[_0x35fc('0x33')]({},{'active':_0x35fc('0x18'),'caller_id':_0x18181b,'assigned_to':_0x2de5d1[_0x35fc('0x1a')],'short_description':intUtil[_0x35fc('0x34')](_0x13d16c[_0x35fc('0x35')],_0x40797d,'\x20'),'description':intUtil[_0x35fc('0x34')](_0x13d16c[_0x35fc('0x36')],_0x40797d,'\x0a')},getCustomFields(_0x13d16c[_0x35fc('0x37')],_0x40797d)),'auth':_0x119925,'json':!![]};return rp(_0x3666a5)['then'](function(_0x3e2961){logger[_0x35fc('0xf')]('['+[_0x4fc5bc[_0x35fc('0x13')]()]+_0x35fc('0x38'),_0x3e2961[_0x35fc('0x16')]);_0x2de5d1[_0x35fc('0x39')]=_0x3e2961[_0x35fc('0x16')][_0x35fc('0x19')];_0x2de5d1[_0x35fc('0x3a')]=_0x3e2961[_0x35fc('0x16')][_0x35fc('0x3b')];logger[_0x35fc('0xf')]('['+[_0x4fc5bc[_0x35fc('0x13')]()]+_0x35fc('0x3c'),_0x2de5d1);_0x2c25d5(_0x2de5d1);})['catch'](function(_0x553ed6){logger[_0x35fc('0x12')]('['+[_0x4fc5bc[_0x35fc('0x13')]()]+']',_0x553ed6[_0x35fc('0x1b')]);_0x4fd3d8(_0x553ed6[_0x35fc('0x1b')]);});});};}function createRemoteTag(_0x3ee296,_0x3e6494,_0x4a4798,_0x4f024c){return new Promise(function(_0x388521,_0x19b2ce){var _0x395d63={'method':_0x35fc('0x1e'),'uri':_0x4a4798+'label'+'?'+_0x4f024c,'body':{'short_description':_0x3ee296,'global':!![],'active':!![],'name':_0x3ee296},'auth':_0x3e6494,'json':!![]};return rp(_0x395d63)[_0x35fc('0xc')](function(_0x13281f){var _0x4965d2=_0x13281f[_0x35fc('0x16')][_0x35fc('0x19')];_0x388521(_0x4965d2);});});}function getRemoteTag(_0x590faa,_0x3e12e4,_0x1ab472,_0x26118e,_0x18f18b){return new Promise(function(_0x5e4018,_0x4de34b){var _0x502a15={'method':_0x35fc('0xb'),'uri':_0x1ab472+_0x35fc('0x3d')+'?sysparm_query=name%3D'+_0x590faa+'&'+_0x26118e,'auth':_0x3e12e4,'json':!![]};return rp(_0x502a15)[_0x35fc('0xc')](function(_0x1f89b3){if(_0x1f89b3[_0x35fc('0x16')][_0x35fc('0xd')]>0x0){var _0x46c59b=_0x1f89b3['result'][0x0][_0x35fc('0x19')];_0x5e4018(_0x46c59b);}else{return createRemoteTag(_0x590faa,_0x3e12e4,_0x1ab472,_0x26118e)[_0x35fc('0xc')](function(_0x39d470){_0x5e4018(_0x39d470);});}});});}function assignTagToIncident(_0x509e77,_0x304dba,_0x1dbf5a,_0x47fb1a,_0x35a676){return new Promise(function(_0x164c7b,_0x1c46b1){var _0x1c4c33={'method':_0x35fc('0x1e'),'uri':_0x1dbf5a+_0x35fc('0x3e')+'?'+_0x35a676,'body':{'label':_0x509e77,'table':_0x35fc('0x3f'),'id_type':_0x35fc('0x40'),'table_key':_0x47fb1a['ticketId'],'title':_0x35fc('0x41')+_0x47fb1a[_0x35fc('0x3a')],'id_display':_0x47fb1a[_0x35fc('0x3a')]},'auth':_0x304dba,'json':!![]};return rp(_0x1c4c33)['then'](function(_0x243871){_0x164c7b();})['catch'](function(){_0x164c7b();});});}function manageTags(_0x4ceacc,_0x5d4a39,_0x23b54f,_0xb1c68a,_0x39a1ee,_0x13901c,_0x3d06b8){return new Promise(function(_0x4bbea0,_0x579f5a){var _0x5353ea=[];_0x5d4a39['forEach'](function(_0x51d231){_0x5353ea[_0x35fc('0x42')](getRemoteTag(_0x51d231,_0x23b54f,_0xb1c68a,_0x13901c,_0x3d06b8));});return Promise[_0x35fc('0x43')](_0x5353ea)[_0x35fc('0xc')](function(_0x3ef680){if(_0x3ef680['length']){logger[_0x35fc('0xf')]('['+[_0x4ceacc[_0x35fc('0x13')]()]+_0x35fc('0x44'),_0x3ef680);var _0x1b0063=[];_0x3ef680[_0x35fc('0x26')](function(_0x1d0e53){_0x1b0063[_0x35fc('0x42')](assignTagToIncident(_0x1d0e53,_0x23b54f,_0xb1c68a,_0x39a1ee,_0x13901c));});return Promise[_0x35fc('0x43')](_0x1b0063)[_0x35fc('0xc')](function(){_0x4bbea0();})['catch'](function(){_0x4bbea0();});}else{_0x4bbea0();}});});}function getTags(_0x35d7c8,_0x47c75f,_0xfbd737,_0x9029e3,_0x2ac8e1,_0x2bc76c){return function(_0x4bdde7){return new Promise(function(_0x465c14,_0x4af592){var _0x4e2835=[];var _0x5f1d4a=_0x9029e3[_0x35fc('0x45')];if(_0x5f1d4a&&_0x5f1d4a['length']>0x0){_0x4e2835=_[_0x35fc('0x46')](_0x5f1d4a,'name');}if(_0x4e2835[_0x35fc('0xd')]>0x0){return manageTags(_0x35d7c8,_0x4e2835,_0x47c75f,_0xfbd737,_0x4bdde7,_0x2ac8e1,_0x2bc76c)['then'](function(){_0x465c14(_0x4bdde7);});}else{_0x465c14(_0x4bdde7);}});};}function emit(_0x42a53a,_0x455b84,_0x3400f0){var _0x1d81a5='%26sysparm_record_target%3Dincident'+_0x35fc('0x47')+_0x35fc('0x48')+_0x35fc('0x49');var _0x5df92d={'uri':_0x42a53a+_0x35fc('0x4a')+_0x3400f0+_0x1d81a5};io['to'](util[_0x35fc('0x4b')](_0x35fc('0x4c'),_0x455b84))[_0x35fc('0x4d')](_0x35fc('0x4e'),_0x5df92d);}exports['cs']=function(_0x2c4309,_0x2ee98b,_0x4464d5,_0x5159a0,_0x28a44b,_0x2008b3,_0x2600d2,_0x4a926d){var _0x1c88d8={};var _0x1b76f0={'user':_0x2008b3['username'],'pass':_0x2008b3['password']};var _0x3969d3='sysparm_limit=1';var _0x223ad3=_0x35fc('0x4f');_0x2008b3[_0x35fc('0x50')]=intUtil[_0x35fc('0x51')](_0x2008b3[_0x35fc('0x50')]);_0x2008b3[_0x35fc('0x52')]=intUtil[_0x35fc('0x51')](_0x2008b3[_0x35fc('0x52')]);var _0x10b725=util[_0x35fc('0x4b')](_0x35fc('0x53'),_0x2008b3[_0x35fc('0x50')]);_0x1c88d8[_0x35fc('0x14')]=!_[_0x35fc('0x54')](_0x5159a0)?_0x5159a0[_0x35fc('0x55')]:null;_0x1c88d8[_0x35fc('0x1c')]=_0x2008b3[_0x35fc('0x55')];_0x1c88d8[_0x35fc('0x20')]=_0x4a926d[_0x35fc('0x2e')]()===_0x35fc('0x32')?_0x2ee98b['destcalleridnum']:_0x2ee98b[_0x35fc('0x56')];_0x1c88d8['callDirection']=_0x4a926d===_0x35fc('0x57')||_0x4a926d===_0x35fc('0x58')?_0x35fc('0x57'):_0x35fc('0x32');var _0x25af78=util[_0x35fc('0x4b')](_0x35fc('0x59'),_0x2008b3[_0x35fc('0x52')],_0x2ee98b[_0x35fc('0x5a')],md5(_0x2ee98b[_0x35fc('0x5a')]));if(_0x28a44b&&_0x28a44b[_0x35fc('0x5b')]){logger['info'](_0x35fc('0x5c'),_0x35fc('0x5d'));_0x2ee98b[_0x35fc('0x5e')]=_0x25af78;}else if(_0x2600d2&&_0x2600d2[_0x35fc('0x5f')]&&_0x2600d2[_0x35fc('0x5f')]!==_0x35fc('0x60')){logger['info'](_0x35fc('0x61'),_0x35fc('0x5d'));_0x2ee98b[_0x35fc('0x5e')]=_0x25af78;}else{_0x2ee98b[_0x35fc('0x5e')]='';}return getAdminUser(_0x4a926d,_0x1b76f0,_0x1c88d8,_0x10b725,_0x223ad3,_0x3969d3)[_0x35fc('0xc')](getUser(_0x4a926d,_0x1b76f0,_0x10b725,_0x223ad3,_0x3969d3))[_0x35fc('0xc')](getEndUser(_0x4a926d,_0x1b76f0,_0x10b725,_0x223ad3,_0x3969d3))[_0x35fc('0xc')](getTicket(_0x4a926d,_0x1b76f0,_0x10b725,_0x4464d5,_0x2ee98b,_0x223ad3))[_0x35fc('0xc')](function(_0xa92234){logger['info'](util[_0x35fc('0x4b')]('The\x20ticket\x20ID\x20is:\x20%s',_0xa92234[_0x35fc('0x39')]));logger[_0x35fc('0xf')](util['format'](_0x35fc('0x62'),_0x4a926d));if(_0x4a926d!==_0x35fc('0x58')){logger[_0x35fc('0xf')]('['+[_0x4a926d[_0x35fc('0x13')]()]+']',_0x35fc('0x63'));emit(_0x2008b3[_0x35fc('0x50')],_0x5159a0[_0x35fc('0x30')],_0xa92234[_0x35fc('0x39')]);}})[_0x35fc('0x11')](function(_0x5806bf){logger['error']('['+[_0x4a926d['toUpperCase']()]+']\x20Error\x20running\x20ServiceNow\x20integration',util[_0x35fc('0x64')](_0x5806bf,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0x752f=['emit','username','password','sysparm_limit=1','sysparm_display_value=true','remoteUri','stripTrailingSlash','serverUrl','%s/api/now/table/','email','destcalleridnum','callDirection','queue','unmanaged','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','[OUTBOUND]','The\x20ticket\x20ID\x20is:\x20%s','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','inspect','lodash','bluebird','request-promise','ioredis','./util','../../../../config/environment','../../../../config/logger','redis','defaults','localhost','socket.io-emitter','GET','then','result','length','adminId','sys_id','info','catch','toUpperCase','message','],\x20getUser\x20input\x20crm','userEmail','sys_user?sysparm_query=email%3D','],\x20getUser\x20rp\x20obj','],\x20getUser\x20entity','active','true','userId','error',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','endUserNumber','System','sys_user?sysparm_query=phone%3D','],\x20createEndUser\x20crm','includes','string','type','nameField','toLowerCase','toString','picklist','customField','idField','content','variable','variableName','customVariable','Variable','name','outbound','endUserId','POST','assign','getString','Subjects','Descriptions','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketId',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','label_entry','Incident','ticketNumber','push','forEach','all','Tags','map','%26sysparm_record_target%3Dincident','%26sysparm_record_row%3D1%26sysparm_record_rows%3D39','%26sysparm_record_list%3Dactive%253Dtrue','%255EORDERBYDESCnumber','format','user:%s'];(function(_0x26d228,_0x3213b8){var _0x4a663a=function(_0xa23f3e){while(--_0xa23f3e){_0x26d228['push'](_0x26d228['shift']());}};_0x4a663a(++_0x3213b8);}(_0x752f,0x152));var _0xf752=function(_0x5ab934,_0x2a3f34){_0x5ab934=_0x5ab934-0x0;var _0x417750=_0x752f[_0x5ab934];return _0x417750;};'use strict';var _=require(_0xf752('0x0'));var Promise=require(_0xf752('0x1'));var rp=require(_0xf752('0x2'));var util=require('util');var md5=require('md5');var Redis=require(_0xf752('0x3'));var intUtil=require(_0xf752('0x4'));var config=require(_0xf752('0x5'));var logger=require(_0xf752('0x6'))('servicenow');config[_0xf752('0x7')]=_[_0xf752('0x8')](config[_0xf752('0x7')],{'host':_0xf752('0x9'),'port':0x18eb});var io=require(_0xf752('0xa'))(new Redis(config[_0xf752('0x7')]));function getAdminUser(_0x21d520,_0x19d146,_0x434de3,_0x141c92,_0x764d5,_0x1d59a4){return new Promise(function(_0x458b66,_0x471d1d){var _0x15def7={'method':_0xf752('0xb'),'uri':_0x141c92+'sys_user?sysparm_query=user_name%3Dadmin'+'&'+_0x764d5+'&'+_0x1d59a4,'auth':_0x19d146,'json':!![]};return rp(_0x15def7)[_0xf752('0xc')](function(_0x5a8dd1){if(_0x5a8dd1[_0xf752('0xd')][_0xf752('0xe')]>0x0){_0x434de3[_0xf752('0xf')]=_0x5a8dd1[_0xf752('0xd')][0x0][_0xf752('0x10')];}logger[_0xf752('0x11')]('['+[_0x21d520['toUpperCase']()]+'],\x20getAdminUser\x20crm',_0x434de3);_0x458b66(_0x434de3);})[_0xf752('0x12')](function(_0x56ab08){logger['error']('['+[_0x21d520[_0xf752('0x13')]()]+']',_0x56ab08[_0xf752('0x14')]);_0x471d1d(_0x56ab08[_0xf752('0x14')]);});});}function getUser(_0x143f7f,_0x413e0b,_0x74b713,_0x208d53,_0x3612d5){return function(_0x5e05d5){logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x15'),_0x5e05d5);return new Promise(function(_0x3cc66c,_0x444b0f){if(intUtil['validateEmail'](_0x5e05d5[_0xf752('0x16')])){var _0x58b7e0={'method':_0xf752('0xb'),'uri':_0x74b713+_0xf752('0x17')+_0x5e05d5['userEmail']+'&'+_0x208d53+'&'+_0x3612d5,'auth':_0x413e0b,'json':!![]};logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x18'),_0x58b7e0);return rp(_0x58b7e0)[_0xf752('0xc')](function(_0x5c96e4){logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x19'),_0x5c96e4);if(_0x5c96e4[_0xf752('0xd')][_0xf752('0xe')]>0x0&&String(_0x5c96e4[_0xf752('0xd')][0x0][_0xf752('0x1a')])===_0xf752('0x1b')){_0x5e05d5[_0xf752('0x1c')]=_0x5c96e4[_0xf752('0xd')][0x0][_0xf752('0x10')];}else{_0x5e05d5[_0xf752('0x1c')]=_0x5e05d5[_0xf752('0xf')];_0x5e05d5[_0xf752('0x16')]=_0x5e05d5['adminEmail'];}logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+'],\x20getUser\x20crm',_0x5e05d5);_0x3cc66c(_0x5e05d5);})[_0xf752('0x12')](function(_0x13da4a){logger[_0xf752('0x1d')]('['+[_0x143f7f['toUpperCase']()]+']',_0x13da4a['message']);_0x444b0f(_0x13da4a[_0xf752('0x14')]);});}else{logger['info']('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x1e'));_0x5e05d5[_0xf752('0x1c')]=_0x5e05d5[_0xf752('0xf')];_0x5e05d5[_0xf752('0x16')]=_0x5e05d5['adminEmail'];_0x3cc66c(_0x5e05d5);}});};}function createEndUser(_0xc72a47,_0x185075,_0x4ae405,_0x4d0e39,_0x13cb58){logger[_0xf752('0x11')]('['+[_0xc72a47[_0xf752('0x13')]()]+_0xf752('0x1f'),_0x4ae405);return new Promise(function(_0x146e7b,_0x5bf9a5){var _0x951e1c={'method':'POST','uri':_0x4d0e39+'sys_user?'+_0x13cb58,'body':{'user_name':_0x4ae405['endUserNumber'],'roles':'user','first_name':_0x4ae405[_0xf752('0x20')],'active':_0xf752('0x1b'),'date_format':_0xf752('0x21'),'phone':_0x4ae405[_0xf752('0x20')]},'auth':_0x185075,'json':!![]};return rp(_0x951e1c)[_0xf752('0xc')](function(_0x2b3e30){logger[_0xf752('0x11')]('['+[_0xc72a47['toUpperCase']()]+'],\x20EndUser\x20schema',_0x2b3e30['result']);_0x4ae405['endUserId']=_0x2b3e30[_0xf752('0xd')]['sys_id'];_0x146e7b(_0x4ae405);})[_0xf752('0x12')](function(_0x4fe619){logger['error']('['+[_0xc72a47['toUpperCase']()]+']',_0x4fe619[_0xf752('0x14')]);_0x5bf9a5(_0x4fe619[_0xf752('0x14')]);});});}function getEndUser(_0x25cbed,_0x4d2b60,_0x599f01,_0x1b2f69,_0x37c8f0){return function(_0x3aa7cc){logger['info']('['+[_0x25cbed[_0xf752('0x13')]()]+'],\x20getEndUser\x20input\x20crm',_0x3aa7cc);return new Promise(function(_0x10cee6,_0x5634aa){var _0x5dfd61={'method':'GET','uri':_0x599f01+_0xf752('0x22')+_0x3aa7cc['endUserNumber']+'&'+_0x1b2f69+'&'+_0x37c8f0,'auth':_0x4d2b60,'json':!![]};return rp(_0x5dfd61)['then'](function(_0x209191){if(_0x209191['result'][_0xf752('0xe')]>0x0){_0x3aa7cc['endUserId']=_0x209191[_0xf752('0xd')][0x0]['sys_id'];logger[_0xf752('0x11')]('['+[_0x25cbed[_0xf752('0x13')]()]+'],\x20getEndUser\x20crm',_0x3aa7cc);_0x10cee6(_0x3aa7cc);}else{return createEndUser(_0x25cbed,_0x4d2b60,_0x3aa7cc,_0x599f01,_0x1b2f69)[_0xf752('0xc')](function(_0x15735d){logger[_0xf752('0x11')]('['+[_0x25cbed['toUpperCase']()]+_0xf752('0x23'),_0x15735d);_0x10cee6(_0x15735d);});}})[_0xf752('0x12')](function(_0x1ec8b8){logger[_0xf752('0x1d')]('['+[_0x25cbed[_0xf752('0x13')]()]+']',_0x1ec8b8['message']);_0x5634aa(_0x1ec8b8['message']);});});};}function getCustomFields(_0x1e801a,_0x52e9ae){var _0x4c23b9={};if(_0x1e801a[_0xf752('0xe')]>0x0){_['forEach'](_0x1e801a,function(_0x504805){if(_[_0xf752('0x24')]([_0xf752('0x25'),'picklist'],_0x504805[_0xf752('0x26')])&&_0x504805[_0xf752('0x27')]&&!_0x504805['customField']){_0x4c23b9[_0x504805['nameField'][_0xf752('0x28')]()]=_0x504805['content'][_0xf752('0x29')]();}else if(_[_0xf752('0x24')]([_0xf752('0x25'),_0xf752('0x2a')],_0x504805[_0xf752('0x26')])&&_0x504805['idField']&&_0x504805[_0xf752('0x2b')]){_0x4c23b9[_0x504805[_0xf752('0x2c')][_0xf752('0x28')]()]=_0x504805[_0xf752('0x2d')][_0xf752('0x29')]();}else if(_0x504805[_0xf752('0x26')]===_0xf752('0x2e')&&_0x504805[_0xf752('0x2f')]&&_0x504805[_0xf752('0x2c')]&&_0x504805[_0xf752('0x2b')]){_0x4c23b9[_0x504805['idField'][_0xf752('0x28')]()]=_0x52e9ae[_0x504805[_0xf752('0x2f')]]['toString']();}else if(_0x504805[_0xf752('0x26')]===_0xf752('0x30')&&_0x504805[_0xf752('0x31')]&&_0x504805['Variable'][_0xf752('0x32')]&&_0x504805['idField']&&_0x504805[_0xf752('0x2b')]){_0x4c23b9[_0x504805[_0xf752('0x2c')][_0xf752('0x28')]()]=_0x52e9ae[_0x504805[_0xf752('0x31')][_0xf752('0x32')][_0xf752('0x28')]()]['toString']();}});}return _0x4c23b9;}function getTicket(_0x2dc3d2,_0x50ff8c,_0x273747,_0x2b46e4,_0x5cf1e2,_0x3a9f0f){return function(_0x3159a3){logger['info']('['+[_0x2dc3d2['toUpperCase']()]+']\x20getTicket\x20input\x20crm',_0x3159a3);return new Promise(function(_0x588ac9,_0x59bc30){var _0x3a8244=_0x2dc3d2[_0xf752('0x28')]()===_0xf752('0x33')?_0x3159a3[_0xf752('0x1c')]:_0x3159a3[_0xf752('0x34')];var _0x3a6928={'method':_0xf752('0x35'),'uri':_0x273747+'incident'+'?'+_0x3a9f0f,'body':Object[_0xf752('0x36')]({},{'active':'true','caller_id':_0x3a8244,'assigned_to':_0x3159a3['userId'],'short_description':intUtil[_0xf752('0x37')](_0x2b46e4[_0xf752('0x38')],_0x5cf1e2,'\x20'),'description':intUtil[_0xf752('0x37')](_0x2b46e4[_0xf752('0x39')],_0x5cf1e2,'\x0a')},getCustomFields(_0x2b46e4[_0xf752('0x3a')],_0x5cf1e2)),'auth':_0x50ff8c,'json':!![]};return rp(_0x3a6928)['then'](function(_0x1445f3){logger[_0xf752('0x11')]('['+[_0x2dc3d2['toUpperCase']()]+_0xf752('0x3b'),_0x1445f3['result']);_0x3159a3[_0xf752('0x3c')]=_0x1445f3[_0xf752('0xd')][_0xf752('0x10')];_0x3159a3['ticketNumber']=_0x1445f3['result']['number'];logger[_0xf752('0x11')]('['+[_0x2dc3d2[_0xf752('0x13')]()]+_0xf752('0x3d'),_0x3159a3);_0x588ac9(_0x3159a3);})[_0xf752('0x12')](function(_0x1e87b2){logger[_0xf752('0x1d')]('['+[_0x2dc3d2[_0xf752('0x13')]()]+']',_0x1e87b2[_0xf752('0x14')]);_0x59bc30(_0x1e87b2[_0xf752('0x14')]);});});};}function createRemoteTag(_0x71133a,_0x37b87e,_0x26e1b9,_0x4251ca){return new Promise(function(_0x55182f,_0x459914){var _0xf857a={'method':_0xf752('0x35'),'uri':_0x26e1b9+_0xf752('0x3e')+'?'+_0x4251ca,'body':{'short_description':_0x71133a,'global':!![],'active':!![],'name':_0x71133a},'auth':_0x37b87e,'json':!![]};return rp(_0xf857a)[_0xf752('0xc')](function(_0x265f6b){var _0x3aa752=_0x265f6b['result']['sys_id'];_0x55182f(_0x3aa752);});});}function getRemoteTag(_0x8f2a46,_0x852006,_0x56dda4,_0x58aba3,_0x3a066a){return new Promise(function(_0x43afe8,_0x32aa32){var _0xeb8983={'method':_0xf752('0xb'),'uri':_0x56dda4+_0xf752('0x3e')+_0xf752('0x3f')+_0x8f2a46+'&'+_0x58aba3,'auth':_0x852006,'json':!![]};return rp(_0xeb8983)[_0xf752('0xc')](function(_0x2a3e7b){if(_0x2a3e7b[_0xf752('0xd')][_0xf752('0xe')]>0x0){var _0x5dbbe8=_0x2a3e7b[_0xf752('0xd')][0x0][_0xf752('0x10')];_0x43afe8(_0x5dbbe8);}else{return createRemoteTag(_0x8f2a46,_0x852006,_0x56dda4,_0x58aba3)[_0xf752('0xc')](function(_0x5e06ca){_0x43afe8(_0x5e06ca);});}});});}function assignTagToIncident(_0x25ec45,_0x52461e,_0x72a1af,_0x56ce8a,_0x2513d6){return new Promise(function(_0x922751,_0x2953cf){var _0x213b47={'method':_0xf752('0x35'),'uri':_0x72a1af+_0xf752('0x40')+'?'+_0x2513d6,'body':{'label':_0x25ec45,'table':'incident','id_type':_0xf752('0x41'),'table_key':_0x56ce8a['ticketId'],'title':'Incident\x20-\x20'+_0x56ce8a[_0xf752('0x42')],'id_display':_0x56ce8a[_0xf752('0x42')]},'auth':_0x52461e,'json':!![]};return rp(_0x213b47)[_0xf752('0xc')](function(_0x4cfbbf){_0x922751();})[_0xf752('0x12')](function(){_0x922751();});});}function manageTags(_0xe0ebb2,_0x2e70a0,_0x1bb8c3,_0x220550,_0x59dc74,_0x4a3101,_0x553224){return new Promise(function(_0x4eba59,_0x50487a){var _0x59a287=[];_0x2e70a0['forEach'](function(_0x319c8d){_0x59a287[_0xf752('0x43')](getRemoteTag(_0x319c8d,_0x1bb8c3,_0x220550,_0x4a3101,_0x553224));});return Promise['all'](_0x59a287)[_0xf752('0xc')](function(_0x3b6751){if(_0x3b6751[_0xf752('0xe')]){logger[_0xf752('0x11')]('['+[_0xe0ebb2[_0xf752('0x13')]()]+']\x20arrayPromises:\x20IDs\x20in\x20table\x20label',_0x3b6751);var _0x26a5dc=[];_0x3b6751[_0xf752('0x44')](function(_0x1073cd){_0x26a5dc[_0xf752('0x43')](assignTagToIncident(_0x1073cd,_0x1bb8c3,_0x220550,_0x59dc74,_0x4a3101));});return Promise[_0xf752('0x45')](_0x26a5dc)[_0xf752('0xc')](function(){_0x4eba59();})[_0xf752('0x12')](function(){_0x4eba59();});}else{_0x4eba59();}});});}function getTags(_0x460ae5,_0x92ef26,_0x4df6b2,_0x7df053,_0x423d75,_0x197837){return function(_0x59100c){return new Promise(function(_0x157f10,_0x265e12){var _0x62d444=[];var _0x36e3f3=_0x7df053[_0xf752('0x46')];if(_0x36e3f3&&_0x36e3f3[_0xf752('0xe')]>0x0){_0x62d444=_[_0xf752('0x47')](_0x36e3f3,_0xf752('0x32'));}if(_0x62d444['length']>0x0){return manageTags(_0x460ae5,_0x62d444,_0x92ef26,_0x4df6b2,_0x59100c,_0x423d75,_0x197837)[_0xf752('0xc')](function(){_0x157f10(_0x59100c);});}else{_0x157f10(_0x59100c);}});};}function emit(_0x1d80bf,_0x5b07b2,_0x2a4061){var _0x3a9e3b=_0xf752('0x48')+_0xf752('0x49')+_0xf752('0x4a')+_0xf752('0x4b');var _0x399c11={'uri':_0x1d80bf+'/nav_to.do?uri=incident.do?sys_id%3D'+_0x2a4061+_0x3a9e3b};io['to'](util[_0xf752('0x4c')](_0xf752('0x4d'),_0x5b07b2))[_0xf752('0x4e')]('trigger:browser:url',_0x399c11);}exports['cs']=function(_0x51a381,_0x4d4d46,_0x2ae0c2,_0x2a62b5,_0x4eb2ce,_0x566bc7,_0x5505cd,_0x43b017){var _0x21c4b9={};var _0x20ade9={'user':_0x566bc7[_0xf752('0x4f')],'pass':_0x566bc7[_0xf752('0x50')]};var _0x94d5b0=_0xf752('0x51');var _0x2d3afe=_0xf752('0x52');_0x566bc7[_0xf752('0x53')]=intUtil[_0xf752('0x54')](_0x566bc7['remoteUri']);_0x566bc7['serverUrl']=intUtil['stripTrailingSlash'](_0x566bc7[_0xf752('0x55')]);var _0x165a4d=util[_0xf752('0x4c')](_0xf752('0x56'),_0x566bc7[_0xf752('0x53')]);_0x21c4b9[_0xf752('0x16')]=!_['isNil'](_0x2a62b5)?_0x2a62b5[_0xf752('0x57')]:null;_0x21c4b9['adminEmail']=_0x566bc7[_0xf752('0x57')];_0x21c4b9[_0xf752('0x20')]=_0x43b017['toLowerCase']()==='outbound'?_0x4d4d46[_0xf752('0x58')]:_0x4d4d46['calleridnum'];_0x21c4b9[_0xf752('0x59')]=_0x43b017===_0xf752('0x5a')||_0x43b017===_0xf752('0x5b')?'queue':_0xf752('0x33');var _0x56105c=util[_0xf752('0x4c')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x566bc7[_0xf752('0x55')],_0x4d4d46[_0xf752('0x5c')],md5(_0x4d4d46[_0xf752('0x5c')]));if(_0x4eb2ce&&_0x4eb2ce[_0xf752('0x5d')]){logger['info'](_0xf752('0x5e'),_0xf752('0x5f'));_0x4d4d46[_0xf752('0x60')]=_0x56105c;}else if(_0x5505cd&&_0x5505cd[_0xf752('0x61')]&&_0x5505cd['recordingFormat']!=='none'){logger[_0xf752('0x11')](_0xf752('0x62'),_0xf752('0x5f'));_0x4d4d46[_0xf752('0x60')]=_0x56105c;}else{_0x4d4d46['recordingURL']='';}return getAdminUser(_0x43b017,_0x20ade9,_0x21c4b9,_0x165a4d,_0x2d3afe,_0x94d5b0)[_0xf752('0xc')](getUser(_0x43b017,_0x20ade9,_0x165a4d,_0x2d3afe,_0x94d5b0))[_0xf752('0xc')](getEndUser(_0x43b017,_0x20ade9,_0x165a4d,_0x2d3afe,_0x94d5b0))[_0xf752('0xc')](getTicket(_0x43b017,_0x20ade9,_0x165a4d,_0x2ae0c2,_0x4d4d46,_0x2d3afe))[_0xf752('0xc')](function(_0xa41921){logger[_0xf752('0x11')](util[_0xf752('0x4c')](_0xf752('0x63'),_0xa41921[_0xf752('0x3c')]));logger[_0xf752('0x11')](util['format'](_0xf752('0x64'),_0x43b017));if(_0x43b017!==_0xf752('0x5b')){logger['info']('['+[_0x43b017[_0xf752('0x13')]()]+']',_0xf752('0x65'));emit(_0x566bc7[_0xf752('0x53')],_0x2a62b5[_0xf752('0x32')],_0xa41921[_0xf752('0x3c')]);}})[_0xf752('0x12')](function(_0xed3f5c){logger[_0xf752('0x1d')]('['+[_0x43b017['toUpperCase']()]+_0xf752('0x66'),util[_0xf752('0x67')](_0xed3f5c,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file