Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 297afd3..f44c68f 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(_0x325e39,_0x347804){var _0x549c94=function(_0x4fa574){while(--_0x4fa574){_0x325e39['push'](_0x325e39['shift']());}};_0x549c94(++_0x347804);}(_0x5fc3,0xa8));var _0x35fc=function(_0x2df724,_0x411382){_0x2df724=_0x2df724-0x0;var _0x1b2504=_0x5fc3[_0x2df724];return _0x1b2504;};'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 _0xf49f=['sys_user?sysparm_query=phone%3D','endUserId','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','includes','string','picklist','type','nameField','customField','toLowerCase','content','idField','toString','variable','variableName','Variable','name',']\x20getTicket\x20input\x20crm','outbound','incident','assign','getString','Subjects','Descriptions','Fields','ticketId','ticketNumber',']\x20getTicket\x20crm','?sysparm_query=name%3D','label_entry','Incident\x20-\x20','all','push','map','%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','password','sysparm_limit=1','remoteUri','stripTrailingSlash','serverUrl','isNil','email','callDirection','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','[QUEUE]','recordingFormat','[OUTBOUND]','Recording\x20is\x20enabled!','recordingURL','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','inspect','lodash','bluebird','request-promise','util','ioredis','./util','../../../../config/logger','redis','defaults','socket.io-emitter','then','result','length','adminId','sys_id','info','toUpperCase','],\x20getAdminUser\x20crm','catch','error','message','validateEmail','GET','sys_user?sysparm_query=email%3D','],\x20getUser\x20rp\x20obj','],\x20getUser\x20entity','true','userId','userEmail','adminEmail','],\x20getUser\x20crm',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','POST','sys_user?','user','System','endUserNumber','],\x20getEndUser\x20input\x20crm'];(function(_0x7ff301,_0x6d922c){var _0x4f88a7=function(_0xb2e5db){while(--_0xb2e5db){_0x7ff301['push'](_0x7ff301['shift']());}};_0x4f88a7(++_0x6d922c);}(_0xf49f,0xab));var _0xff49=function(_0xbf41f9,_0x1a8466){_0xbf41f9=_0xbf41f9-0x0;var _0x54fa67=_0xf49f[_0xbf41f9];return _0x54fa67;};'use strict';var _=require(_0xff49('0x0'));var Promise=require(_0xff49('0x1'));var rp=require(_0xff49('0x2'));var util=require(_0xff49('0x3'));var md5=require('md5');var Redis=require(_0xff49('0x4'));var intUtil=require(_0xff49('0x5'));var config=require('../../../../config/environment');var logger=require(_0xff49('0x6'))('servicenow');config[_0xff49('0x7')]=_[_0xff49('0x8')](config[_0xff49('0x7')],{'host':'localhost','port':0x18eb});var io=require(_0xff49('0x9'))(new Redis(config['redis']));function getAdminUser(_0x5c3e1d,_0x3f6fe7,_0x4e937a,_0x164b60,_0xa58a93,_0x141431){return new Promise(function(_0x16f33a,_0x4d56bb){var _0x56e624={'method':'GET','uri':_0x164b60+'sys_user?sysparm_query=user_name%3Dadmin'+'&'+_0xa58a93+'&'+_0x141431,'auth':_0x3f6fe7,'json':!![]};return rp(_0x56e624)[_0xff49('0xa')](function(_0x1e417c){if(_0x1e417c[_0xff49('0xb')][_0xff49('0xc')]>0x0){_0x4e937a[_0xff49('0xd')]=_0x1e417c[_0xff49('0xb')][0x0][_0xff49('0xe')];}logger[_0xff49('0xf')]('['+[_0x5c3e1d[_0xff49('0x10')]()]+_0xff49('0x11'),_0x4e937a);_0x16f33a(_0x4e937a);})[_0xff49('0x12')](function(_0x17ba71){logger[_0xff49('0x13')]('['+[_0x5c3e1d[_0xff49('0x10')]()]+']',_0x17ba71[_0xff49('0x14')]);_0x4d56bb(_0x17ba71[_0xff49('0x14')]);});});}function getUser(_0x1bc8ee,_0x56efad,_0x316f1a,_0x2ec749,_0x399963){return function(_0x3e766f){logger[_0xff49('0xf')]('['+[_0x1bc8ee[_0xff49('0x10')]()]+'],\x20getUser\x20input\x20crm',_0x3e766f);return new Promise(function(_0x2048fd,_0x2e9758){if(intUtil[_0xff49('0x15')](_0x3e766f['userEmail'])){var _0x428cb4={'method':_0xff49('0x16'),'uri':_0x316f1a+_0xff49('0x17')+_0x3e766f['userEmail']+'&'+_0x2ec749+'&'+_0x399963,'auth':_0x56efad,'json':!![]};logger['info']('['+[_0x1bc8ee['toUpperCase']()]+_0xff49('0x18'),_0x428cb4);return rp(_0x428cb4)[_0xff49('0xa')](function(_0x3dacc0){logger['info']('['+[_0x1bc8ee[_0xff49('0x10')]()]+_0xff49('0x19'),_0x3dacc0);if(_0x3dacc0[_0xff49('0xb')][_0xff49('0xc')]>0x0&&String(_0x3dacc0[_0xff49('0xb')][0x0]['active'])===_0xff49('0x1a')){_0x3e766f[_0xff49('0x1b')]=_0x3dacc0[_0xff49('0xb')][0x0][_0xff49('0xe')];}else{_0x3e766f[_0xff49('0x1b')]=_0x3e766f[_0xff49('0xd')];_0x3e766f[_0xff49('0x1c')]=_0x3e766f[_0xff49('0x1d')];}logger[_0xff49('0xf')]('['+[_0x1bc8ee[_0xff49('0x10')]()]+_0xff49('0x1e'),_0x3e766f);_0x2048fd(_0x3e766f);})[_0xff49('0x12')](function(_0x44664a){logger[_0xff49('0x13')]('['+[_0x1bc8ee['toUpperCase']()]+']',_0x44664a['message']);_0x2e9758(_0x44664a[_0xff49('0x14')]);});}else{logger[_0xff49('0xf')]('['+[_0x1bc8ee[_0xff49('0x10')]()]+_0xff49('0x1f'));_0x3e766f[_0xff49('0x1b')]=_0x3e766f[_0xff49('0xd')];_0x3e766f['userEmail']=_0x3e766f['adminEmail'];_0x2048fd(_0x3e766f);}});};}function createEndUser(_0x795e4,_0x213aa4,_0x176c6f,_0x408ffb,_0xf62f34){logger['info']('['+[_0x795e4['toUpperCase']()]+_0xff49('0x20'),_0x176c6f);return new Promise(function(_0x3904f2,_0x307db3){var _0x4e6dce={'method':_0xff49('0x21'),'uri':_0x408ffb+_0xff49('0x22')+_0xf62f34,'body':{'user_name':_0x176c6f['endUserNumber'],'roles':_0xff49('0x23'),'first_name':_0x176c6f['endUserNumber'],'active':'true','date_format':_0xff49('0x24'),'phone':_0x176c6f[_0xff49('0x25')]},'auth':_0x213aa4,'json':!![]};return rp(_0x4e6dce)['then'](function(_0x36e882){logger['info']('['+[_0x795e4['toUpperCase']()]+'],\x20EndUser\x20schema',_0x36e882[_0xff49('0xb')]);_0x176c6f['endUserId']=_0x36e882['result'][_0xff49('0xe')];_0x3904f2(_0x176c6f);})[_0xff49('0x12')](function(_0x5ea3b0){logger[_0xff49('0x13')]('['+[_0x795e4[_0xff49('0x10')]()]+']',_0x5ea3b0[_0xff49('0x14')]);_0x307db3(_0x5ea3b0[_0xff49('0x14')]);});});}function getEndUser(_0x45083f,_0x24f0d2,_0x5bd9c9,_0x324c7f,_0xee9d81){return function(_0x333880){logger[_0xff49('0xf')]('['+[_0x45083f[_0xff49('0x10')]()]+_0xff49('0x26'),_0x333880);return new Promise(function(_0x543f7a,_0x5845ec){var _0x3c777e={'method':_0xff49('0x16'),'uri':_0x5bd9c9+_0xff49('0x27')+_0x333880[_0xff49('0x25')]+'&'+_0x324c7f+'&'+_0xee9d81,'auth':_0x24f0d2,'json':!![]};return rp(_0x3c777e)[_0xff49('0xa')](function(_0x3a2322){if(_0x3a2322['result'][_0xff49('0xc')]>0x0){_0x333880[_0xff49('0x28')]=_0x3a2322[_0xff49('0xb')][0x0][_0xff49('0xe')];logger[_0xff49('0xf')]('['+[_0x45083f[_0xff49('0x10')]()]+_0xff49('0x29'),_0x333880);_0x543f7a(_0x333880);}else{return createEndUser(_0x45083f,_0x24f0d2,_0x333880,_0x5bd9c9,_0x324c7f)['then'](function(_0x14b344){logger[_0xff49('0xf')]('['+[_0x45083f[_0xff49('0x10')]()]+_0xff49('0x2a'),_0x14b344);_0x543f7a(_0x14b344);});}})[_0xff49('0x12')](function(_0x479e8d){logger[_0xff49('0x13')]('['+[_0x45083f[_0xff49('0x10')]()]+']',_0x479e8d[_0xff49('0x14')]);_0x5845ec(_0x479e8d[_0xff49('0x14')]);});});};}function getCustomFields(_0x3636e4,_0x39241f){var _0x20dd82={};if(_0x3636e4[_0xff49('0xc')]>0x0){_[_0xff49('0x2b')](_0x3636e4,function(_0x274172){if(_[_0xff49('0x2c')]([_0xff49('0x2d'),_0xff49('0x2e')],_0x274172[_0xff49('0x2f')])&&_0x274172[_0xff49('0x30')]&&!_0x274172[_0xff49('0x31')]){_0x20dd82[_0x274172[_0xff49('0x30')][_0xff49('0x32')]()]=_0x274172[_0xff49('0x33')]['toString']();}else if(_[_0xff49('0x2c')](['string',_0xff49('0x2e')],_0x274172[_0xff49('0x2f')])&&_0x274172[_0xff49('0x34')]&&_0x274172[_0xff49('0x31')]){_0x20dd82[_0x274172['idField']['toLowerCase']()]=_0x274172[_0xff49('0x33')][_0xff49('0x35')]();}else if(_0x274172['type']===_0xff49('0x36')&&_0x274172[_0xff49('0x37')]&&_0x274172[_0xff49('0x34')]&&_0x274172[_0xff49('0x31')]){_0x20dd82[_0x274172['idField']['toLowerCase']()]=_0x39241f[_0x274172[_0xff49('0x37')]][_0xff49('0x35')]();}else if(_0x274172['type']==='customVariable'&&_0x274172[_0xff49('0x38')]&&_0x274172['Variable'][_0xff49('0x39')]&&_0x274172[_0xff49('0x34')]&&_0x274172[_0xff49('0x31')]){_0x20dd82[_0x274172['idField'][_0xff49('0x32')]()]=_0x39241f[_0x274172[_0xff49('0x38')][_0xff49('0x39')]['toLowerCase']()][_0xff49('0x35')]();}});}return _0x20dd82;}function getTicket(_0xbcac0d,_0x387ed9,_0x52daa7,_0xf5ebe,_0x484c09,_0x5db8d8){return function(_0x282401){logger[_0xff49('0xf')]('['+[_0xbcac0d[_0xff49('0x10')]()]+_0xff49('0x3a'),_0x282401);return new Promise(function(_0x410d1b,_0xc59157){var _0x41ac04=_0xbcac0d['toLowerCase']()===_0xff49('0x3b')?_0x282401['userId']:_0x282401[_0xff49('0x28')];var _0x4e3982={'method':'POST','uri':_0x52daa7+_0xff49('0x3c')+'?'+_0x5db8d8,'body':Object[_0xff49('0x3d')]({},{'active':_0xff49('0x1a'),'caller_id':_0x41ac04,'assigned_to':_0x282401['userId'],'short_description':intUtil[_0xff49('0x3e')](_0xf5ebe[_0xff49('0x3f')],_0x484c09,'\x20'),'description':intUtil['getString'](_0xf5ebe[_0xff49('0x40')],_0x484c09,'\x0a')},getCustomFields(_0xf5ebe[_0xff49('0x41')],_0x484c09)),'auth':_0x387ed9,'json':!![]};return rp(_0x4e3982)['then'](function(_0x482eba){logger[_0xff49('0xf')]('['+[_0xbcac0d[_0xff49('0x10')]()]+']\x20POST\x20incident\x20entity\x20schema',_0x482eba[_0xff49('0xb')]);_0x282401[_0xff49('0x42')]=_0x482eba[_0xff49('0xb')][_0xff49('0xe')];_0x282401[_0xff49('0x43')]=_0x482eba[_0xff49('0xb')]['number'];logger[_0xff49('0xf')]('['+[_0xbcac0d[_0xff49('0x10')]()]+_0xff49('0x44'),_0x282401);_0x410d1b(_0x282401);})[_0xff49('0x12')](function(_0x53e95b){logger[_0xff49('0x13')]('['+[_0xbcac0d[_0xff49('0x10')]()]+']',_0x53e95b[_0xff49('0x14')]);_0xc59157(_0x53e95b['message']);});});};}function createRemoteTag(_0x503cf9,_0x406331,_0x8ba3d6,_0x3e6b96){return new Promise(function(_0xf60283,_0x5e660c){var _0x170e49={'method':'POST','uri':_0x8ba3d6+'label'+'?'+_0x3e6b96,'body':{'short_description':_0x503cf9,'global':!![],'active':!![],'name':_0x503cf9},'auth':_0x406331,'json':!![]};return rp(_0x170e49)[_0xff49('0xa')](function(_0x5249da){var _0x1d053e=_0x5249da[_0xff49('0xb')][_0xff49('0xe')];_0xf60283(_0x1d053e);});});}function getRemoteTag(_0x222903,_0x4335ad,_0x4cef8e,_0x53e1ac,_0x5643dd){return new Promise(function(_0x3bf8a2,_0x246415){var _0x228d0d={'method':_0xff49('0x16'),'uri':_0x4cef8e+'label'+_0xff49('0x45')+_0x222903+'&'+_0x53e1ac,'auth':_0x4335ad,'json':!![]};return rp(_0x228d0d)[_0xff49('0xa')](function(_0x3b2542){if(_0x3b2542[_0xff49('0xb')][_0xff49('0xc')]>0x0){var _0x56f8ee=_0x3b2542[_0xff49('0xb')][0x0][_0xff49('0xe')];_0x3bf8a2(_0x56f8ee);}else{return createRemoteTag(_0x222903,_0x4335ad,_0x4cef8e,_0x53e1ac)['then'](function(_0x3bb9c9){_0x3bf8a2(_0x3bb9c9);});}});});}function assignTagToIncident(_0x4c4e77,_0x203136,_0x599f85,_0x4969d7,_0x4a2c9c){return new Promise(function(_0x3cf4e0,_0x1ea98e){var _0x167d90={'method':_0xff49('0x21'),'uri':_0x599f85+_0xff49('0x46')+'?'+_0x4a2c9c,'body':{'label':_0x4c4e77,'table':_0xff49('0x3c'),'id_type':'Incident','table_key':_0x4969d7[_0xff49('0x42')],'title':_0xff49('0x47')+_0x4969d7[_0xff49('0x43')],'id_display':_0x4969d7[_0xff49('0x43')]},'auth':_0x203136,'json':!![]};return rp(_0x167d90)['then'](function(_0x35fb79){_0x3cf4e0();})[_0xff49('0x12')](function(){_0x3cf4e0();});});}function manageTags(_0x2ca23a,_0x11500e,_0x328403,_0x8bd875,_0x4dced8,_0x3a784c,_0x320f6c){return new Promise(function(_0x1b38eb,_0x2bf7d4){var _0x54c38f=[];_0x11500e[_0xff49('0x2b')](function(_0x4497f1){_0x54c38f['push'](getRemoteTag(_0x4497f1,_0x328403,_0x8bd875,_0x3a784c,_0x320f6c));});return Promise[_0xff49('0x48')](_0x54c38f)[_0xff49('0xa')](function(_0x3e1775){if(_0x3e1775[_0xff49('0xc')]){logger[_0xff49('0xf')]('['+[_0x2ca23a[_0xff49('0x10')]()]+']\x20arrayPromises:\x20IDs\x20in\x20table\x20label',_0x3e1775);var _0x16af4c=[];_0x3e1775[_0xff49('0x2b')](function(_0x413e86){_0x16af4c[_0xff49('0x49')](assignTagToIncident(_0x413e86,_0x328403,_0x8bd875,_0x4dced8,_0x3a784c));});return Promise[_0xff49('0x48')](_0x16af4c)[_0xff49('0xa')](function(){_0x1b38eb();})[_0xff49('0x12')](function(){_0x1b38eb();});}else{_0x1b38eb();}});});}function getTags(_0x4a8277,_0x20e7fb,_0x34538d,_0x3bd4a3,_0x273c70,_0x414867){return function(_0x1d36a8){return new Promise(function(_0x22c268,_0x2cec94){var _0x2818d6=[];var _0x4e40d3=_0x3bd4a3['Tags'];if(_0x4e40d3&&_0x4e40d3[_0xff49('0xc')]>0x0){_0x2818d6=_[_0xff49('0x4a')](_0x4e40d3,_0xff49('0x39'));}if(_0x2818d6[_0xff49('0xc')]>0x0){return manageTags(_0x4a8277,_0x2818d6,_0x20e7fb,_0x34538d,_0x1d36a8,_0x273c70,_0x414867)[_0xff49('0xa')](function(){_0x22c268(_0x1d36a8);});}else{_0x22c268(_0x1d36a8);}});};}function emit(_0xd48661,_0x5aef7a,_0x4d7432){var _0x447cf3=_0xff49('0x4b')+_0xff49('0x4c')+_0xff49('0x4d')+'%255EORDERBYDESCnumber';var _0x122874={'uri':_0xd48661+_0xff49('0x4e')+_0x4d7432+_0x447cf3};io['to'](util[_0xff49('0x4f')](_0xff49('0x50'),_0x5aef7a))[_0xff49('0x51')](_0xff49('0x52'),_0x122874);}exports['cs']=function(_0x2fd5e9,_0x12b174,_0x1daed2,_0x1d738b,_0x2188fa,_0x521049,_0xcd740c,_0x20c0a9){var _0x4d36f5={};var _0x2fff95={'user':_0x521049[_0xff49('0x53')],'pass':_0x521049[_0xff49('0x54')]};var _0x5e5ecf=_0xff49('0x55');var _0x1d2f7c='sysparm_display_value=true';_0x521049[_0xff49('0x56')]=intUtil[_0xff49('0x57')](_0x521049[_0xff49('0x56')]);_0x521049['serverUrl']=intUtil['stripTrailingSlash'](_0x521049[_0xff49('0x58')]);var _0x3c1780=util[_0xff49('0x4f')]('%s/api/now/table/',_0x521049[_0xff49('0x56')]);_0x4d36f5[_0xff49('0x1c')]=!_[_0xff49('0x59')](_0x1d738b)?_0x1d738b[_0xff49('0x5a')]:null;_0x4d36f5[_0xff49('0x1d')]=_0x521049[_0xff49('0x5a')];_0x4d36f5[_0xff49('0x25')]=_0x20c0a9[_0xff49('0x32')]()===_0xff49('0x3b')?_0x12b174['destcalleridnum']:_0x12b174['calleridnum'];_0x4d36f5[_0xff49('0x5b')]=_0x20c0a9===_0xff49('0x5c')||_0x20c0a9===_0xff49('0x5d')?'queue':_0xff49('0x3b');var _0x174f40=util[_0xff49('0x4f')](_0xff49('0x5e'),_0x521049[_0xff49('0x58')],_0x12b174[_0xff49('0x5f')],md5(_0x12b174['uniqueid']));if(_0x2188fa&&_0x2188fa['monitor_format']){logger[_0xff49('0xf')](_0xff49('0x60'),'Recording\x20is\x20enabled!');_0x12b174['recordingURL']=_0x174f40;}else if(_0xcd740c&&_0xcd740c[_0xff49('0x61')]&&_0xcd740c[_0xff49('0x61')]!=='none'){logger[_0xff49('0xf')](_0xff49('0x62'),_0xff49('0x63'));_0x12b174[_0xff49('0x64')]=_0x174f40;}else{_0x12b174[_0xff49('0x64')]='';}return getAdminUser(_0x20c0a9,_0x2fff95,_0x4d36f5,_0x3c1780,_0x1d2f7c,_0x5e5ecf)['then'](getUser(_0x20c0a9,_0x2fff95,_0x3c1780,_0x1d2f7c,_0x5e5ecf))[_0xff49('0xa')](getEndUser(_0x20c0a9,_0x2fff95,_0x3c1780,_0x1d2f7c,_0x5e5ecf))[_0xff49('0xa')](getTicket(_0x20c0a9,_0x2fff95,_0x3c1780,_0x1daed2,_0x12b174,_0x1d2f7c))[_0xff49('0xa')](function(_0x1461da){logger['info'](util['format']('The\x20ticket\x20ID\x20is:\x20%s',_0x1461da[_0xff49('0x42')]));logger['info'](util[_0xff49('0x4f')](_0xff49('0x65'),_0x20c0a9));if(_0x20c0a9!=='unmanaged'){logger[_0xff49('0xf')]('['+[_0x20c0a9[_0xff49('0x10')]()]+']',_0xff49('0x66'));emit(_0x521049[_0xff49('0x56')],_0x1d738b[_0xff49('0x39')],_0x1461da[_0xff49('0x42')]);}})[_0xff49('0x12')](function(_0xdd6032){logger['error']('['+[_0x20c0a9[_0xff49('0x10')]()]+_0xff49('0x67'),util[_0xff49('0x68')](_0xdd6032,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file