Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 3038bf5..f44c68f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf685=['endUserId','error','sys_user?sysparm_query=phone%3D','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','string','picklist','type','nameField','customField','content','idField','toLowerCase','toString','variable','variableName','customVariable','Variable','name',']\x20getTicket\x20input\x20crm','outbound','POST','incident','assign','getString','Subjects',']\x20POST\x20incident\x20entity\x20schema','ticketId','ticketNumber','number',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','label_entry','Incident','Incident\x20-\x20','push',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','all','Tags','map','%26sysparm_record_target%3Dincident','%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','username','password','sysparm_limit=1','sysparm_display_value=true','remoteUri','serverUrl','stripTrailingSlash','isNil','email','destcalleridnum','calleridnum','callDirection','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','inspect','lodash','bluebird','request-promise','util','md5','ioredis','./util','../../../../config/environment','../../../../config/logger','servicenow','redis','defaults','localhost','socket.io-emitter','GET','sys_user?sysparm_query=user_name%3Dadmin','then','result','length','adminId','sys_id','info','toUpperCase','],\x20getAdminUser\x20crm','catch','message','],\x20getUser\x20input\x20crm','validateEmail','userEmail','sys_user?sysparm_query=email%3D','],\x20getUser\x20entity','true','userId','adminEmail','],\x20getUser\x20crm','sys_user?','user','endUserNumber','],\x20EndUser\x20schema'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0xf685,0x1a1));var _0x5f68=function(_0x25b0e9,_0x36bd89){_0x25b0e9=_0x25b0e9-0x0;var _0x4aa7ea=_0xf685[_0x25b0e9];return _0x4aa7ea;};'use strict';var _=require(_0x5f68('0x0'));var Promise=require(_0x5f68('0x1'));var rp=require(_0x5f68('0x2'));var util=require(_0x5f68('0x3'));var md5=require(_0x5f68('0x4'));var Redis=require(_0x5f68('0x5'));var intUtil=require(_0x5f68('0x6'));var config=require(_0x5f68('0x7'));var logger=require(_0x5f68('0x8'))(_0x5f68('0x9'));config[_0x5f68('0xa')]=_[_0x5f68('0xb')](config[_0x5f68('0xa')],{'host':_0x5f68('0xc'),'port':0x18eb});var io=require(_0x5f68('0xd'))(new Redis(config[_0x5f68('0xa')]));function getAdminUser(_0x587e05,_0x33d57c,_0x280367,_0x19a8ff,_0x5d26f9,_0x2b6f10){return new Promise(function(_0x39cedd,_0x246ae5){var _0x26cf28={'method':_0x5f68('0xe'),'uri':_0x19a8ff+_0x5f68('0xf')+'&'+_0x5d26f9+'&'+_0x2b6f10,'auth':_0x33d57c,'json':!![]};return rp(_0x26cf28)[_0x5f68('0x10')](function(_0x10f78b){if(_0x10f78b[_0x5f68('0x11')][_0x5f68('0x12')]>0x0){_0x280367[_0x5f68('0x13')]=_0x10f78b[_0x5f68('0x11')][0x0][_0x5f68('0x14')];}logger[_0x5f68('0x15')]('['+[_0x587e05[_0x5f68('0x16')]()]+_0x5f68('0x17'),_0x280367);_0x39cedd(_0x280367);})[_0x5f68('0x18')](function(_0x218551){logger['error']('['+[_0x587e05[_0x5f68('0x16')]()]+']',_0x218551[_0x5f68('0x19')]);_0x246ae5(_0x218551[_0x5f68('0x19')]);});});}function getUser(_0x496704,_0x3ef4d1,_0xcc6810,_0x100fa6,_0x3f1f84){return function(_0xbf0eda){logger[_0x5f68('0x15')]('['+[_0x496704[_0x5f68('0x16')]()]+_0x5f68('0x1a'),_0xbf0eda);return new Promise(function(_0x156f9c,_0x48b6be){if(intUtil[_0x5f68('0x1b')](_0xbf0eda[_0x5f68('0x1c')])){var _0x460fc8={'method':'GET','uri':_0xcc6810+_0x5f68('0x1d')+_0xbf0eda[_0x5f68('0x1c')]+'&'+_0x100fa6+'&'+_0x3f1f84,'auth':_0x3ef4d1,'json':!![]};logger['info']('['+[_0x496704['toUpperCase']()]+'],\x20getUser\x20rp\x20obj',_0x460fc8);return rp(_0x460fc8)[_0x5f68('0x10')](function(_0x3bef07){logger[_0x5f68('0x15')]('['+[_0x496704[_0x5f68('0x16')]()]+_0x5f68('0x1e'),_0x3bef07);if(_0x3bef07[_0x5f68('0x11')][_0x5f68('0x12')]>0x0&&String(_0x3bef07['result'][0x0]['active'])===_0x5f68('0x1f')){_0xbf0eda[_0x5f68('0x20')]=_0x3bef07['result'][0x0][_0x5f68('0x14')];}else{_0xbf0eda[_0x5f68('0x20')]=_0xbf0eda['adminId'];_0xbf0eda[_0x5f68('0x1c')]=_0xbf0eda[_0x5f68('0x21')];}logger[_0x5f68('0x15')]('['+[_0x496704[_0x5f68('0x16')]()]+_0x5f68('0x22'),_0xbf0eda);_0x156f9c(_0xbf0eda);})[_0x5f68('0x18')](function(_0x3aa2d4){logger['error']('['+[_0x496704[_0x5f68('0x16')]()]+']',_0x3aa2d4['message']);_0x48b6be(_0x3aa2d4[_0x5f68('0x19')]);});}else{logger[_0x5f68('0x15')]('['+[_0x496704[_0x5f68('0x16')]()]+']\x20using\x20admin\x20profile');_0xbf0eda[_0x5f68('0x20')]=_0xbf0eda['adminId'];_0xbf0eda['userEmail']=_0xbf0eda[_0x5f68('0x21')];_0x156f9c(_0xbf0eda);}});};}function createEndUser(_0x4c153d,_0x48a25c,_0x34a595,_0x4d2878,_0x53d665){logger[_0x5f68('0x15')]('['+[_0x4c153d[_0x5f68('0x16')]()]+'],\x20createEndUser\x20input\x20crm',_0x34a595);return new Promise(function(_0x5c8742,_0x468e29){var _0x443c68={'method':'POST','uri':_0x4d2878+_0x5f68('0x23')+_0x53d665,'body':{'user_name':_0x34a595['endUserNumber'],'roles':_0x5f68('0x24'),'first_name':_0x34a595['endUserNumber'],'active':_0x5f68('0x1f'),'date_format':'System','phone':_0x34a595[_0x5f68('0x25')]},'auth':_0x48a25c,'json':!![]};return rp(_0x443c68)['then'](function(_0x5d68c3){logger[_0x5f68('0x15')]('['+[_0x4c153d[_0x5f68('0x16')]()]+_0x5f68('0x26'),_0x5d68c3[_0x5f68('0x11')]);_0x34a595[_0x5f68('0x27')]=_0x5d68c3[_0x5f68('0x11')]['sys_id'];_0x5c8742(_0x34a595);})[_0x5f68('0x18')](function(_0x398c71){logger[_0x5f68('0x28')]('['+[_0x4c153d[_0x5f68('0x16')]()]+']',_0x398c71[_0x5f68('0x19')]);_0x468e29(_0x398c71['message']);});});}function getEndUser(_0x167905,_0x673484,_0x10cba6,_0x100bd4,_0xa777e4){return function(_0x3744c9){logger[_0x5f68('0x15')]('['+[_0x167905['toUpperCase']()]+'],\x20getEndUser\x20input\x20crm',_0x3744c9);return new Promise(function(_0x4f06df,_0x564f14){var _0x134d59={'method':_0x5f68('0xe'),'uri':_0x10cba6+_0x5f68('0x29')+_0x3744c9[_0x5f68('0x25')]+'&'+_0x100bd4+'&'+_0xa777e4,'auth':_0x673484,'json':!![]};return rp(_0x134d59)[_0x5f68('0x10')](function(_0x2fa673){if(_0x2fa673['result'][_0x5f68('0x12')]>0x0){_0x3744c9['endUserId']=_0x2fa673['result'][0x0][_0x5f68('0x14')];logger[_0x5f68('0x15')]('['+[_0x167905[_0x5f68('0x16')]()]+_0x5f68('0x2a'),_0x3744c9);_0x4f06df(_0x3744c9);}else{return createEndUser(_0x167905,_0x673484,_0x3744c9,_0x10cba6,_0x100bd4)[_0x5f68('0x10')](function(_0x33f929){logger[_0x5f68('0x15')]('['+[_0x167905[_0x5f68('0x16')]()]+_0x5f68('0x2b'),_0x33f929);_0x4f06df(_0x33f929);});}})[_0x5f68('0x18')](function(_0x24ba7a){logger[_0x5f68('0x28')]('['+[_0x167905[_0x5f68('0x16')]()]+']',_0x24ba7a[_0x5f68('0x19')]);_0x564f14(_0x24ba7a[_0x5f68('0x19')]);});});};}function getCustomFields(_0x536373,_0x3c12ec){var _0x3a84cf={};if(_0x536373[_0x5f68('0x12')]>0x0){_[_0x5f68('0x2c')](_0x536373,function(_0x2f738b){if(_['includes']([_0x5f68('0x2d'),_0x5f68('0x2e')],_0x2f738b[_0x5f68('0x2f')])&&_0x2f738b[_0x5f68('0x30')]&&!_0x2f738b[_0x5f68('0x31')]){_0x3a84cf[_0x2f738b[_0x5f68('0x30')]['toLowerCase']()]=_0x2f738b[_0x5f68('0x32')]['toString']();}else if(_['includes']([_0x5f68('0x2d'),'picklist'],_0x2f738b[_0x5f68('0x2f')])&&_0x2f738b[_0x5f68('0x33')]&&_0x2f738b[_0x5f68('0x31')]){_0x3a84cf[_0x2f738b[_0x5f68('0x33')][_0x5f68('0x34')]()]=_0x2f738b[_0x5f68('0x32')][_0x5f68('0x35')]();}else if(_0x2f738b[_0x5f68('0x2f')]===_0x5f68('0x36')&&_0x2f738b[_0x5f68('0x37')]&&_0x2f738b[_0x5f68('0x33')]&&_0x2f738b[_0x5f68('0x31')]){_0x3a84cf[_0x2f738b[_0x5f68('0x33')][_0x5f68('0x34')]()]=_0x3c12ec[_0x2f738b[_0x5f68('0x37')]][_0x5f68('0x35')]();}else if(_0x2f738b[_0x5f68('0x2f')]===_0x5f68('0x38')&&_0x2f738b[_0x5f68('0x39')]&&_0x2f738b[_0x5f68('0x39')]['name']&&_0x2f738b[_0x5f68('0x33')]&&_0x2f738b[_0x5f68('0x31')]){_0x3a84cf[_0x2f738b['idField'][_0x5f68('0x34')]()]=_0x3c12ec[_0x2f738b[_0x5f68('0x39')][_0x5f68('0x3a')][_0x5f68('0x34')]()][_0x5f68('0x35')]();}});}return _0x3a84cf;}function getTicket(_0x4e8fc5,_0x32774c,_0x364eaa,_0x32247e,_0x109cca,_0x2ea10a){return function(_0x55077c){logger[_0x5f68('0x15')]('['+[_0x4e8fc5[_0x5f68('0x16')]()]+_0x5f68('0x3b'),_0x55077c);return new Promise(function(_0x35f4bf,_0x16ca2f){var _0x48d1f2=_0x4e8fc5[_0x5f68('0x34')]()===_0x5f68('0x3c')?_0x55077c[_0x5f68('0x20')]:_0x55077c[_0x5f68('0x27')];var _0x12e2f4={'method':_0x5f68('0x3d'),'uri':_0x364eaa+_0x5f68('0x3e')+'?'+_0x2ea10a,'body':Object[_0x5f68('0x3f')]({},{'active':_0x5f68('0x1f'),'caller_id':_0x48d1f2,'assigned_to':_0x55077c[_0x5f68('0x20')],'short_description':intUtil[_0x5f68('0x40')](_0x32247e[_0x5f68('0x41')],_0x109cca,'\x20'),'description':intUtil[_0x5f68('0x40')](_0x32247e['Descriptions'],_0x109cca,'\x0a')},getCustomFields(_0x32247e['Fields'],_0x109cca)),'auth':_0x32774c,'json':!![]};return rp(_0x12e2f4)[_0x5f68('0x10')](function(_0x5b70c7){logger[_0x5f68('0x15')]('['+[_0x4e8fc5['toUpperCase']()]+_0x5f68('0x42'),_0x5b70c7[_0x5f68('0x11')]);_0x55077c[_0x5f68('0x43')]=_0x5b70c7[_0x5f68('0x11')][_0x5f68('0x14')];_0x55077c[_0x5f68('0x44')]=_0x5b70c7[_0x5f68('0x11')][_0x5f68('0x45')];logger[_0x5f68('0x15')]('['+[_0x4e8fc5[_0x5f68('0x16')]()]+_0x5f68('0x46'),_0x55077c);_0x35f4bf(_0x55077c);})[_0x5f68('0x18')](function(_0x381876){logger[_0x5f68('0x28')]('['+[_0x4e8fc5[_0x5f68('0x16')]()]+']',_0x381876['message']);_0x16ca2f(_0x381876['message']);});});};}function createRemoteTag(_0x420642,_0x2c88a4,_0x45bc66,_0x39866e){return new Promise(function(_0x500988,_0x1c9933){var _0x4fc96d={'method':_0x5f68('0x3d'),'uri':_0x45bc66+_0x5f68('0x47')+'?'+_0x39866e,'body':{'short_description':_0x420642,'global':!![],'active':!![],'name':_0x420642},'auth':_0x2c88a4,'json':!![]};return rp(_0x4fc96d)[_0x5f68('0x10')](function(_0x563bf0){var _0x432edc=_0x563bf0[_0x5f68('0x11')]['sys_id'];_0x500988(_0x432edc);});});}function getRemoteTag(_0x46b1b8,_0x5d066c,_0x3c31fa,_0x1386b8,_0x485516){return new Promise(function(_0x29c874,_0x5f34c3){var _0x581193={'method':_0x5f68('0xe'),'uri':_0x3c31fa+_0x5f68('0x47')+_0x5f68('0x48')+_0x46b1b8+'&'+_0x1386b8,'auth':_0x5d066c,'json':!![]};return rp(_0x581193)[_0x5f68('0x10')](function(_0x305168){if(_0x305168[_0x5f68('0x11')][_0x5f68('0x12')]>0x0){var _0x33e860=_0x305168['result'][0x0]['sys_id'];_0x29c874(_0x33e860);}else{return createRemoteTag(_0x46b1b8,_0x5d066c,_0x3c31fa,_0x1386b8)[_0x5f68('0x10')](function(_0x2f2102){_0x29c874(_0x2f2102);});}});});}function assignTagToIncident(_0x5c41d7,_0x2020ae,_0x4d23f4,_0x25b0c7,_0x163433){return new Promise(function(_0x7d8475,_0x438b64){var _0x45cacb={'method':_0x5f68('0x3d'),'uri':_0x4d23f4+_0x5f68('0x49')+'?'+_0x163433,'body':{'label':_0x5c41d7,'table':_0x5f68('0x3e'),'id_type':_0x5f68('0x4a'),'table_key':_0x25b0c7['ticketId'],'title':_0x5f68('0x4b')+_0x25b0c7['ticketNumber'],'id_display':_0x25b0c7[_0x5f68('0x44')]},'auth':_0x2020ae,'json':!![]};return rp(_0x45cacb)[_0x5f68('0x10')](function(_0x34e2d2){_0x7d8475();})['catch'](function(){_0x7d8475();});});}function manageTags(_0x5337ea,_0x480173,_0x45e81c,_0x47339d,_0x47d12f,_0x8a74bf,_0x523a3c){return new Promise(function(_0x136d98,_0x3e59c9){var _0x2a7296=[];_0x480173[_0x5f68('0x2c')](function(_0x2cd931){_0x2a7296[_0x5f68('0x4c')](getRemoteTag(_0x2cd931,_0x45e81c,_0x47339d,_0x8a74bf,_0x523a3c));});return Promise['all'](_0x2a7296)[_0x5f68('0x10')](function(_0x531148){if(_0x531148['length']){logger[_0x5f68('0x15')]('['+[_0x5337ea[_0x5f68('0x16')]()]+_0x5f68('0x4d'),_0x531148);var _0x2a87ee=[];_0x531148[_0x5f68('0x2c')](function(_0x4d8df9){_0x2a87ee[_0x5f68('0x4c')](assignTagToIncident(_0x4d8df9,_0x45e81c,_0x47339d,_0x47d12f,_0x8a74bf));});return Promise[_0x5f68('0x4e')](_0x2a87ee)[_0x5f68('0x10')](function(){_0x136d98();})[_0x5f68('0x18')](function(){_0x136d98();});}else{_0x136d98();}});});}function getTags(_0x29cc56,_0x37ec32,_0x255172,_0x3b7d3c,_0x207a32,_0x4c3207){return function(_0x597d1e){return new Promise(function(_0x1029f8,_0x519b91){var _0x7e4612=[];var _0x400fa2=_0x3b7d3c[_0x5f68('0x4f')];if(_0x400fa2&&_0x400fa2[_0x5f68('0x12')]>0x0){_0x7e4612=_[_0x5f68('0x50')](_0x400fa2,_0x5f68('0x3a'));}if(_0x7e4612[_0x5f68('0x12')]>0x0){return manageTags(_0x29cc56,_0x7e4612,_0x37ec32,_0x255172,_0x597d1e,_0x207a32,_0x4c3207)[_0x5f68('0x10')](function(){_0x1029f8(_0x597d1e);});}else{_0x1029f8(_0x597d1e);}});};}function emit(_0x39b7cc,_0x1fea20,_0x16a174){var _0x293122=_0x5f68('0x51')+_0x5f68('0x52')+_0x5f68('0x53')+_0x5f68('0x54');var _0x5cf5bb={'uri':_0x39b7cc+_0x5f68('0x55')+_0x16a174+_0x293122};io['to'](util[_0x5f68('0x56')](_0x5f68('0x57'),_0x1fea20))[_0x5f68('0x58')](_0x5f68('0x59'),_0x5cf5bb);}exports['cs']=function(_0x103d08,_0x355788,_0xf12103,_0x459159,_0x38930c,_0x576fd4,_0x43a761,_0x263b69){var _0x4b2c31={};var _0x3f0478={'user':_0x576fd4[_0x5f68('0x5a')],'pass':_0x576fd4[_0x5f68('0x5b')]};var _0x4b1c6b=_0x5f68('0x5c');var _0x4e803d=_0x5f68('0x5d');_0x576fd4[_0x5f68('0x5e')]=intUtil['stripTrailingSlash'](_0x576fd4[_0x5f68('0x5e')]);_0x576fd4[_0x5f68('0x5f')]=intUtil[_0x5f68('0x60')](_0x576fd4[_0x5f68('0x5f')]);var _0x5d9db7=util[_0x5f68('0x56')]('%s/api/now/table/',_0x576fd4[_0x5f68('0x5e')]);_0x4b2c31[_0x5f68('0x1c')]=!_[_0x5f68('0x61')](_0x459159)?_0x459159[_0x5f68('0x62')]:null;_0x4b2c31[_0x5f68('0x21')]=_0x576fd4[_0x5f68('0x62')];_0x4b2c31[_0x5f68('0x25')]=_0x263b69['toLowerCase']()===_0x5f68('0x3c')?_0x355788[_0x5f68('0x63')]:_0x355788[_0x5f68('0x64')];_0x4b2c31[_0x5f68('0x65')]=_0x263b69===_0x5f68('0x66')||_0x263b69===_0x5f68('0x67')?_0x5f68('0x66'):_0x5f68('0x3c');var _0x39da9c=util['format'](_0x5f68('0x68'),_0x576fd4['serverUrl'],_0x355788[_0x5f68('0x69')],md5(_0x355788[_0x5f68('0x69')]));if(_0x38930c&&_0x38930c['monitor_format']){logger[_0x5f68('0x15')]('[QUEUE]',_0x5f68('0x6a'));_0x355788[_0x5f68('0x6b')]=_0x39da9c;}else if(_0x43a761&&_0x43a761[_0x5f68('0x6c')]&&_0x43a761[_0x5f68('0x6c')]!==_0x5f68('0x6d')){logger[_0x5f68('0x15')]('[OUTBOUND]',_0x5f68('0x6a'));_0x355788[_0x5f68('0x6b')]=_0x39da9c;}else{_0x355788['recordingURL']='';}return getAdminUser(_0x263b69,_0x3f0478,_0x4b2c31,_0x5d9db7,_0x4e803d,_0x4b1c6b)[_0x5f68('0x10')](getUser(_0x263b69,_0x3f0478,_0x5d9db7,_0x4e803d,_0x4b1c6b))[_0x5f68('0x10')](getEndUser(_0x263b69,_0x3f0478,_0x5d9db7,_0x4e803d,_0x4b1c6b))[_0x5f68('0x10')](getTicket(_0x263b69,_0x3f0478,_0x5d9db7,_0xf12103,_0x355788,_0x4e803d))[_0x5f68('0x10')](function(_0x1c056e){logger[_0x5f68('0x15')](util[_0x5f68('0x56')]('The\x20ticket\x20ID\x20is:\x20%s',_0x1c056e[_0x5f68('0x43')]));logger[_0x5f68('0x15')](util['format'](_0x5f68('0x6e'),_0x263b69));if(_0x263b69!=='unmanaged'){logger['info']('['+[_0x263b69[_0x5f68('0x16')]()]+']',_0x5f68('0x6f'));emit(_0x576fd4['remoteUri'],_0x459159[_0x5f68('0x3a')],_0x1c056e[_0x5f68('0x43')]);}})[_0x5f68('0x18')](function(_0x31ef1b){logger[_0x5f68('0x28')]('['+[_0x263b69[_0x5f68('0x16')]()]+_0x5f68('0x70'),util[_0x5f68('0x71')](_0x31ef1b,{'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