Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 297afd3..7388828 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 _0x160f=['POST','assign','getString','Descriptions','Fields','ticketId','ticketNumber',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','label_entry','incident','Incident','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','trigger:browser:url','password','sysparm_limit=1','sysparm_display_value=true','remoteUri','stripTrailingSlash','serverUrl','%s/api/now/table/','email','outbound','calleridnum','callDirection','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','recordingURL','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!','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','util','ioredis','./util','../../../../config/environment','../../../../config/logger','servicenow','redis','localhost','sys_user?sysparm_query=user_name%3Dadmin','then','length','adminId','result','sys_id','info','],\x20getAdminUser\x20crm','error','toUpperCase','message','],\x20getUser\x20input\x20crm','userEmail','GET','sys_user?sysparm_query=email%3D','],\x20getUser\x20rp\x20obj','],\x20getUser\x20entity','active','true','userId','adminEmail','],\x20getUser\x20crm','catch',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','endUserNumber','user','System','],\x20EndUser\x20schema','endUserId','sys_user?sysparm_query=phone%3D','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','includes','string','picklist','nameField','customField','toLowerCase','content','toString','idField','type','variable','variableName','customVariable','Variable','name'];(function(_0x40b6ae,_0x10a643){var _0x55ea53=function(_0x405cc0){while(--_0x405cc0){_0x40b6ae['push'](_0x40b6ae['shift']());}};_0x55ea53(++_0x10a643);}(_0x160f,0x1ef));var _0xf160=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x160f[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xf160('0x0'));var Promise=require(_0xf160('0x1'));var rp=require(_0xf160('0x2'));var util=require(_0xf160('0x3'));var md5=require('md5');var Redis=require(_0xf160('0x4'));var intUtil=require(_0xf160('0x5'));var config=require(_0xf160('0x6'));var logger=require(_0xf160('0x7'))(_0xf160('0x8'));config[_0xf160('0x9')]=_['defaults'](config[_0xf160('0x9')],{'host':_0xf160('0xa'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function getAdminUser(_0x41e909,_0x5b76c8,_0x4bf890,_0x496014,_0x383de0,_0x90608){return new Promise(function(_0x393f70,_0x2736b8){var _0x5e09c6={'method':'GET','uri':_0x496014+_0xf160('0xb')+'&'+_0x383de0+'&'+_0x90608,'auth':_0x5b76c8,'json':!![]};return rp(_0x5e09c6)[_0xf160('0xc')](function(_0x3ab49e){if(_0x3ab49e['result'][_0xf160('0xd')]>0x0){_0x4bf890[_0xf160('0xe')]=_0x3ab49e[_0xf160('0xf')][0x0][_0xf160('0x10')];}logger[_0xf160('0x11')]('['+[_0x41e909['toUpperCase']()]+_0xf160('0x12'),_0x4bf890);_0x393f70(_0x4bf890);})['catch'](function(_0x1496b6){logger[_0xf160('0x13')]('['+[_0x41e909[_0xf160('0x14')]()]+']',_0x1496b6[_0xf160('0x15')]);_0x2736b8(_0x1496b6[_0xf160('0x15')]);});});}function getUser(_0x31f7ae,_0x2643ba,_0x172337,_0x1396ba,_0x59ac02){return function(_0x477e4d){logger[_0xf160('0x11')]('['+[_0x31f7ae[_0xf160('0x14')]()]+_0xf160('0x16'),_0x477e4d);return new Promise(function(_0x51824b,_0x36a978){if(intUtil['validateEmail'](_0x477e4d[_0xf160('0x17')])){var _0x1cf6ba={'method':_0xf160('0x18'),'uri':_0x172337+_0xf160('0x19')+_0x477e4d[_0xf160('0x17')]+'&'+_0x1396ba+'&'+_0x59ac02,'auth':_0x2643ba,'json':!![]};logger[_0xf160('0x11')]('['+[_0x31f7ae[_0xf160('0x14')]()]+_0xf160('0x1a'),_0x1cf6ba);return rp(_0x1cf6ba)[_0xf160('0xc')](function(_0x4a58d9){logger[_0xf160('0x11')]('['+[_0x31f7ae[_0xf160('0x14')]()]+_0xf160('0x1b'),_0x4a58d9);if(_0x4a58d9['result'][_0xf160('0xd')]>0x0&&String(_0x4a58d9[_0xf160('0xf')][0x0][_0xf160('0x1c')])===_0xf160('0x1d')){_0x477e4d[_0xf160('0x1e')]=_0x4a58d9[_0xf160('0xf')][0x0][_0xf160('0x10')];}else{_0x477e4d['userId']=_0x477e4d[_0xf160('0xe')];_0x477e4d[_0xf160('0x17')]=_0x477e4d[_0xf160('0x1f')];}logger[_0xf160('0x11')]('['+[_0x31f7ae['toUpperCase']()]+_0xf160('0x20'),_0x477e4d);_0x51824b(_0x477e4d);})[_0xf160('0x21')](function(_0x4a8003){logger['error']('['+[_0x31f7ae[_0xf160('0x14')]()]+']',_0x4a8003[_0xf160('0x15')]);_0x36a978(_0x4a8003[_0xf160('0x15')]);});}else{logger['info']('['+[_0x31f7ae[_0xf160('0x14')]()]+_0xf160('0x22'));_0x477e4d[_0xf160('0x1e')]=_0x477e4d[_0xf160('0xe')];_0x477e4d[_0xf160('0x17')]=_0x477e4d[_0xf160('0x1f')];_0x51824b(_0x477e4d);}});};}function createEndUser(_0x5d0cc8,_0x4d7165,_0x48145e,_0x26e7b9,_0x16a5fa){logger[_0xf160('0x11')]('['+[_0x5d0cc8[_0xf160('0x14')]()]+_0xf160('0x23'),_0x48145e);return new Promise(function(_0x563103,_0x55f9c3){var _0x329d6b={'method':'POST','uri':_0x26e7b9+'sys_user?'+_0x16a5fa,'body':{'user_name':_0x48145e[_0xf160('0x24')],'roles':_0xf160('0x25'),'first_name':_0x48145e['endUserNumber'],'active':_0xf160('0x1d'),'date_format':_0xf160('0x26'),'phone':_0x48145e['endUserNumber']},'auth':_0x4d7165,'json':!![]};return rp(_0x329d6b)['then'](function(_0x4b3ef4){logger['info']('['+[_0x5d0cc8[_0xf160('0x14')]()]+_0xf160('0x27'),_0x4b3ef4[_0xf160('0xf')]);_0x48145e[_0xf160('0x28')]=_0x4b3ef4[_0xf160('0xf')][_0xf160('0x10')];_0x563103(_0x48145e);})['catch'](function(_0x5495b5){logger['error']('['+[_0x5d0cc8[_0xf160('0x14')]()]+']',_0x5495b5['message']);_0x55f9c3(_0x5495b5['message']);});});}function getEndUser(_0x4ddeb8,_0x36b854,_0x4dbe9d,_0x1930b8,_0x1653ab){return function(_0x272efe){logger[_0xf160('0x11')]('['+[_0x4ddeb8[_0xf160('0x14')]()]+'],\x20getEndUser\x20input\x20crm',_0x272efe);return new Promise(function(_0x105edd,_0x2a7fcd){var _0x15070a={'method':'GET','uri':_0x4dbe9d+_0xf160('0x29')+_0x272efe[_0xf160('0x24')]+'&'+_0x1930b8+'&'+_0x1653ab,'auth':_0x36b854,'json':!![]};return rp(_0x15070a)[_0xf160('0xc')](function(_0x22d152){if(_0x22d152[_0xf160('0xf')][_0xf160('0xd')]>0x0){_0x272efe['endUserId']=_0x22d152['result'][0x0][_0xf160('0x10')];logger[_0xf160('0x11')]('['+[_0x4ddeb8[_0xf160('0x14')]()]+_0xf160('0x2a'),_0x272efe);_0x105edd(_0x272efe);}else{return createEndUser(_0x4ddeb8,_0x36b854,_0x272efe,_0x4dbe9d,_0x1930b8)[_0xf160('0xc')](function(_0x24d668){logger[_0xf160('0x11')]('['+[_0x4ddeb8[_0xf160('0x14')]()]+_0xf160('0x2b'),_0x24d668);_0x105edd(_0x24d668);});}})[_0xf160('0x21')](function(_0x1e65d4){logger[_0xf160('0x13')]('['+[_0x4ddeb8[_0xf160('0x14')]()]+']',_0x1e65d4[_0xf160('0x15')]);_0x2a7fcd(_0x1e65d4[_0xf160('0x15')]);});});};}function getCustomFields(_0x256ce7,_0x161f06){var _0xb29fb4={};if(_0x256ce7[_0xf160('0xd')]>0x0){_[_0xf160('0x2c')](_0x256ce7,function(_0x13241c){if(_[_0xf160('0x2d')]([_0xf160('0x2e'),_0xf160('0x2f')],_0x13241c['type'])&&_0x13241c[_0xf160('0x30')]&&!_0x13241c[_0xf160('0x31')]){_0xb29fb4[_0x13241c[_0xf160('0x30')][_0xf160('0x32')]()]=_0x13241c[_0xf160('0x33')][_0xf160('0x34')]();}else if(_[_0xf160('0x2d')](['string',_0xf160('0x2f')],_0x13241c['type'])&&_0x13241c[_0xf160('0x35')]&&_0x13241c[_0xf160('0x31')]){_0xb29fb4[_0x13241c['idField'][_0xf160('0x32')]()]=_0x13241c[_0xf160('0x33')][_0xf160('0x34')]();}else if(_0x13241c[_0xf160('0x36')]===_0xf160('0x37')&&_0x13241c[_0xf160('0x38')]&&_0x13241c[_0xf160('0x35')]&&_0x13241c['customField']){_0xb29fb4[_0x13241c[_0xf160('0x35')][_0xf160('0x32')]()]=_0x161f06[_0x13241c[_0xf160('0x38')]][_0xf160('0x34')]();}else if(_0x13241c[_0xf160('0x36')]===_0xf160('0x39')&&_0x13241c[_0xf160('0x3a')]&&_0x13241c[_0xf160('0x3a')][_0xf160('0x3b')]&&_0x13241c[_0xf160('0x35')]&&_0x13241c[_0xf160('0x31')]){_0xb29fb4[_0x13241c['idField']['toLowerCase']()]=_0x161f06[_0x13241c[_0xf160('0x3a')][_0xf160('0x3b')][_0xf160('0x32')]()][_0xf160('0x34')]();}});}return _0xb29fb4;}function getTicket(_0x211c42,_0x152cf9,_0x4a542f,_0xb3bc25,_0x5abc6a,_0x55ab52){return function(_0x44fd52){logger[_0xf160('0x11')]('['+[_0x211c42['toUpperCase']()]+']\x20getTicket\x20input\x20crm',_0x44fd52);return new Promise(function(_0x2f1648,_0x2681f2){var _0x3e2cdb=_0x211c42[_0xf160('0x32')]()==='outbound'?_0x44fd52['userId']:_0x44fd52['endUserId'];var _0x50a97d={'method':_0xf160('0x3c'),'uri':_0x4a542f+'incident'+'?'+_0x55ab52,'body':Object[_0xf160('0x3d')]({},{'active':_0xf160('0x1d'),'caller_id':_0x3e2cdb,'assigned_to':_0x44fd52[_0xf160('0x1e')],'short_description':intUtil[_0xf160('0x3e')](_0xb3bc25['Subjects'],_0x5abc6a,'\x20'),'description':intUtil[_0xf160('0x3e')](_0xb3bc25[_0xf160('0x3f')],_0x5abc6a,'\x0a')},getCustomFields(_0xb3bc25[_0xf160('0x40')],_0x5abc6a)),'auth':_0x152cf9,'json':!![]};return rp(_0x50a97d)['then'](function(_0x386d30){logger[_0xf160('0x11')]('['+[_0x211c42[_0xf160('0x14')]()]+']\x20POST\x20incident\x20entity\x20schema',_0x386d30[_0xf160('0xf')]);_0x44fd52[_0xf160('0x41')]=_0x386d30[_0xf160('0xf')][_0xf160('0x10')];_0x44fd52[_0xf160('0x42')]=_0x386d30['result']['number'];logger[_0xf160('0x11')]('['+[_0x211c42['toUpperCase']()]+_0xf160('0x43'),_0x44fd52);_0x2f1648(_0x44fd52);})[_0xf160('0x21')](function(_0x53d9c3){logger['error']('['+[_0x211c42[_0xf160('0x14')]()]+']',_0x53d9c3[_0xf160('0x15')]);_0x2681f2(_0x53d9c3['message']);});});};}function createRemoteTag(_0x2d1b68,_0x22fd05,_0x28605d,_0x405d7e){return new Promise(function(_0x5f3ded,_0x3a8807){var _0x53792f={'method':_0xf160('0x3c'),'uri':_0x28605d+_0xf160('0x44')+'?'+_0x405d7e,'body':{'short_description':_0x2d1b68,'global':!![],'active':!![],'name':_0x2d1b68},'auth':_0x22fd05,'json':!![]};return rp(_0x53792f)[_0xf160('0xc')](function(_0x170ca4){var _0x41de39=_0x170ca4['result'][_0xf160('0x10')];_0x5f3ded(_0x41de39);});});}function getRemoteTag(_0x47d0d8,_0x3a5396,_0x1229cd,_0x39628d,_0x19c1ed){return new Promise(function(_0x402eb1,_0x342fbf){var _0x11855b={'method':_0xf160('0x18'),'uri':_0x1229cd+_0xf160('0x44')+_0xf160('0x45')+_0x47d0d8+'&'+_0x39628d,'auth':_0x3a5396,'json':!![]};return rp(_0x11855b)['then'](function(_0x484093){if(_0x484093[_0xf160('0xf')][_0xf160('0xd')]>0x0){var _0x5b6cf6=_0x484093[_0xf160('0xf')][0x0][_0xf160('0x10')];_0x402eb1(_0x5b6cf6);}else{return createRemoteTag(_0x47d0d8,_0x3a5396,_0x1229cd,_0x39628d)[_0xf160('0xc')](function(_0x51665c){_0x402eb1(_0x51665c);});}});});}function assignTagToIncident(_0x499937,_0x12ab32,_0x352ddb,_0x5eeab6,_0x3243c6){return new Promise(function(_0x1de36a,_0x4b3224){var _0x2cbe17={'method':_0xf160('0x3c'),'uri':_0x352ddb+_0xf160('0x46')+'?'+_0x3243c6,'body':{'label':_0x499937,'table':_0xf160('0x47'),'id_type':_0xf160('0x48'),'table_key':_0x5eeab6[_0xf160('0x41')],'title':'Incident\x20-\x20'+_0x5eeab6[_0xf160('0x42')],'id_display':_0x5eeab6[_0xf160('0x42')]},'auth':_0x12ab32,'json':!![]};return rp(_0x2cbe17)[_0xf160('0xc')](function(_0x1364bc){_0x1de36a();})[_0xf160('0x21')](function(){_0x1de36a();});});}function manageTags(_0x5a1be3,_0x1d22bb,_0x518b7d,_0x3a7fa2,_0x31aadc,_0xdc5bcb,_0x9c1101){return new Promise(function(_0x52a471,_0x41553d){var _0x492d5b=[];_0x1d22bb[_0xf160('0x2c')](function(_0x28e84d){_0x492d5b[_0xf160('0x49')](getRemoteTag(_0x28e84d,_0x518b7d,_0x3a7fa2,_0xdc5bcb,_0x9c1101));});return Promise[_0xf160('0x4a')](_0x492d5b)[_0xf160('0xc')](function(_0x51ba63){if(_0x51ba63['length']){logger[_0xf160('0x11')]('['+[_0x5a1be3[_0xf160('0x14')]()]+_0xf160('0x4b'),_0x51ba63);var _0x3d8c6c=[];_0x51ba63[_0xf160('0x2c')](function(_0x2d4591){_0x3d8c6c['push'](assignTagToIncident(_0x2d4591,_0x518b7d,_0x3a7fa2,_0x31aadc,_0xdc5bcb));});return Promise[_0xf160('0x4a')](_0x3d8c6c)[_0xf160('0xc')](function(){_0x52a471();})[_0xf160('0x21')](function(){_0x52a471();});}else{_0x52a471();}});});}function getTags(_0x352063,_0x18313b,_0x22499a,_0x2ad82e,_0x3fe3e0,_0x53b347){return function(_0x1818f8){return new Promise(function(_0x5a196e,_0x236f0f){var _0x41f292=[];var _0x2c9042=_0x2ad82e[_0xf160('0x4c')];if(_0x2c9042&&_0x2c9042[_0xf160('0xd')]>0x0){_0x41f292=_[_0xf160('0x4d')](_0x2c9042,'name');}if(_0x41f292[_0xf160('0xd')]>0x0){return manageTags(_0x352063,_0x41f292,_0x18313b,_0x22499a,_0x1818f8,_0x3fe3e0,_0x53b347)[_0xf160('0xc')](function(){_0x5a196e(_0x1818f8);});}else{_0x5a196e(_0x1818f8);}});};}function emit(_0x134fd9,_0x517653,_0x1fa959){var _0x407a4a='%26sysparm_record_target%3Dincident'+_0xf160('0x4e')+_0xf160('0x4f')+_0xf160('0x50');var _0x53ad31={'uri':_0x134fd9+_0xf160('0x51')+_0x1fa959+_0x407a4a};io['to'](util[_0xf160('0x52')](_0xf160('0x53'),_0x517653))['emit'](_0xf160('0x54'),_0x53ad31);}exports['cs']=function(_0x136919,_0x17fa01,_0xd67a1d,_0x25901d,_0x15a214,_0x2094e1,_0x58843d,_0x797ba1){var _0x35769c={};var _0x361b43={'user':_0x2094e1['username'],'pass':_0x2094e1[_0xf160('0x55')]};var _0x46e889=_0xf160('0x56');var _0x1ea18e=_0xf160('0x57');_0x2094e1[_0xf160('0x58')]=intUtil[_0xf160('0x59')](_0x2094e1[_0xf160('0x58')]);_0x2094e1['serverUrl']=intUtil[_0xf160('0x59')](_0x2094e1[_0xf160('0x5a')]);var _0xd488f0=util[_0xf160('0x52')](_0xf160('0x5b'),_0x2094e1[_0xf160('0x58')]);_0x35769c[_0xf160('0x17')]=!_['isNil'](_0x25901d)?_0x25901d[_0xf160('0x5c')]:null;_0x35769c[_0xf160('0x1f')]=_0x2094e1['email'];_0x35769c['endUserNumber']=_0x797ba1[_0xf160('0x32')]()===_0xf160('0x5d')?_0x17fa01['destcalleridnum']:_0x17fa01[_0xf160('0x5e')];_0x35769c[_0xf160('0x5f')]=_0x797ba1==='queue'||_0x797ba1===_0xf160('0x60')?'queue':_0xf160('0x5d');var _0x355226=util[_0xf160('0x52')](_0xf160('0x61'),_0x2094e1['serverUrl'],_0x17fa01[_0xf160('0x62')],md5(_0x17fa01[_0xf160('0x62')]));if(_0x15a214&&_0x15a214[_0xf160('0x63')]){logger[_0xf160('0x11')](_0xf160('0x64'),'Recording\x20is\x20enabled!');_0x17fa01[_0xf160('0x65')]=_0x355226;}else if(_0x58843d&&_0x58843d[_0xf160('0x66')]&&_0x58843d[_0xf160('0x66')]!==_0xf160('0x67')){logger[_0xf160('0x11')](_0xf160('0x68'),_0xf160('0x69'));_0x17fa01[_0xf160('0x65')]=_0x355226;}else{_0x17fa01[_0xf160('0x65')]='';}return getAdminUser(_0x797ba1,_0x361b43,_0x35769c,_0xd488f0,_0x1ea18e,_0x46e889)[_0xf160('0xc')](getUser(_0x797ba1,_0x361b43,_0xd488f0,_0x1ea18e,_0x46e889))[_0xf160('0xc')](getEndUser(_0x797ba1,_0x361b43,_0xd488f0,_0x1ea18e,_0x46e889))['then'](getTicket(_0x797ba1,_0x361b43,_0xd488f0,_0xd67a1d,_0x17fa01,_0x1ea18e))[_0xf160('0xc')](function(_0x1dc546){logger[_0xf160('0x11')](util[_0xf160('0x52')](_0xf160('0x6a'),_0x1dc546['ticketId']));logger[_0xf160('0x11')](util[_0xf160('0x52')](_0xf160('0x6b'),_0x797ba1));if(_0x797ba1!==_0xf160('0x60')){logger[_0xf160('0x11')]('['+[_0x797ba1[_0xf160('0x14')]()]+']',_0xf160('0x6c'));emit(_0x2094e1[_0xf160('0x58')],_0x25901d[_0xf160('0x3b')],_0x1dc546[_0xf160('0x41')]);}})[_0xf160('0x21')](function(_0x4efd88){logger[_0xf160('0x13')]('['+[_0x797ba1['toUpperCase']()]+_0xf160('0x6d'),util[_0xf160('0x6e')](_0x4efd88,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file