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