Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 71dfd0b..f44c68f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xac56=['GET','sys_user?sysparm_query=user_name%3Dadmin','result','length','adminId','sys_id','info','toUpperCase','],\x20getAdminUser\x20crm','catch','error','message','],\x20getUser\x20input\x20crm','validateEmail','sys_user?sysparm_query=email%3D','userEmail','],\x20getUser\x20rp\x20obj','then','active','true','userId','adminEmail','],\x20getUser\x20crm',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','POST','sys_user?','user','endUserNumber','System','],\x20EndUser\x20schema','endUserId','],\x20getEndUser\x20input\x20crm','sys_user?sysparm_query=phone%3D','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','includes','picklist','type','nameField','customField','content','string','idField','toLowerCase','toString','customVariable','Variable','name',']\x20getTicket\x20input\x20crm','outbound','incident','assign','getString','Subjects','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketId','number',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','label_entry','Incident','Incident\x20-\x20','ticketNumber','push',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','all','Tags','%26sysparm_record_list%3Dactive%253Dtrue','/nav_to.do?uri=incident.do?sys_id%3D','format','user:%s','username','password','sysparm_limit=1','remoteUri','stripTrailingSlash','serverUrl','%s/api/now/table/','isNil','email','destcalleridnum','calleridnum','callDirection','queue','unmanaged','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','The\x20ticket\x20ID\x20is:\x20%s','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','inspect','lodash','bluebird','util','md5','ioredis','./util','../../../../config/environment','redis','defaults','localhost','socket.io-emitter'];(function(_0x49c1f2,_0x468abb){var _0x2058c9=function(_0x333245){while(--_0x333245){_0x49c1f2['push'](_0x49c1f2['shift']());}};_0x2058c9(++_0x468abb);}(_0xac56,0x1b1));var _0x6ac5=function(_0x2f953b,_0x1f85fa){_0x2f953b=_0x2f953b-0x0;var _0x31def7=_0xac56[_0x2f953b];return _0x31def7;};'use strict';var _=require(_0x6ac5('0x0'));var Promise=require(_0x6ac5('0x1'));var rp=require('request-promise');var util=require(_0x6ac5('0x2'));var md5=require(_0x6ac5('0x3'));var Redis=require(_0x6ac5('0x4'));var intUtil=require(_0x6ac5('0x5'));var config=require(_0x6ac5('0x6'));var logger=require('../../../../config/logger')('servicenow');config[_0x6ac5('0x7')]=_[_0x6ac5('0x8')](config[_0x6ac5('0x7')],{'host':_0x6ac5('0x9'),'port':0x18eb});var io=require(_0x6ac5('0xa'))(new Redis(config[_0x6ac5('0x7')]));function getAdminUser(_0x59a671,_0x4e3009,_0x5d5355,_0x1b8371,_0x59ad5c,_0x3edac5){return new Promise(function(_0x7bd514,_0x4c2374){var _0x16cc47={'method':_0x6ac5('0xb'),'uri':_0x1b8371+_0x6ac5('0xc')+'&'+_0x59ad5c+'&'+_0x3edac5,'auth':_0x4e3009,'json':!![]};return rp(_0x16cc47)['then'](function(_0x4b0861){if(_0x4b0861[_0x6ac5('0xd')][_0x6ac5('0xe')]>0x0){_0x5d5355[_0x6ac5('0xf')]=_0x4b0861[_0x6ac5('0xd')][0x0][_0x6ac5('0x10')];}logger[_0x6ac5('0x11')]('['+[_0x59a671[_0x6ac5('0x12')]()]+_0x6ac5('0x13'),_0x5d5355);_0x7bd514(_0x5d5355);})[_0x6ac5('0x14')](function(_0x44a746){logger[_0x6ac5('0x15')]('['+[_0x59a671[_0x6ac5('0x12')]()]+']',_0x44a746[_0x6ac5('0x16')]);_0x4c2374(_0x44a746[_0x6ac5('0x16')]);});});}function getUser(_0x4b9d91,_0x3d336f,_0x55b393,_0x3daacb,_0x29efc9){return function(_0x19b079){logger[_0x6ac5('0x11')]('['+[_0x4b9d91['toUpperCase']()]+_0x6ac5('0x17'),_0x19b079);return new Promise(function(_0x3c1ea2,_0x2d654e){if(intUtil[_0x6ac5('0x18')](_0x19b079['userEmail'])){var _0x493d79={'method':_0x6ac5('0xb'),'uri':_0x55b393+_0x6ac5('0x19')+_0x19b079[_0x6ac5('0x1a')]+'&'+_0x3daacb+'&'+_0x29efc9,'auth':_0x3d336f,'json':!![]};logger[_0x6ac5('0x11')]('['+[_0x4b9d91['toUpperCase']()]+_0x6ac5('0x1b'),_0x493d79);return rp(_0x493d79)[_0x6ac5('0x1c')](function(_0x19de8a){logger[_0x6ac5('0x11')]('['+[_0x4b9d91[_0x6ac5('0x12')]()]+'],\x20getUser\x20entity',_0x19de8a);if(_0x19de8a[_0x6ac5('0xd')]['length']>0x0&&String(_0x19de8a[_0x6ac5('0xd')][0x0][_0x6ac5('0x1d')])===_0x6ac5('0x1e')){_0x19b079[_0x6ac5('0x1f')]=_0x19de8a[_0x6ac5('0xd')][0x0][_0x6ac5('0x10')];}else{_0x19b079[_0x6ac5('0x1f')]=_0x19b079[_0x6ac5('0xf')];_0x19b079[_0x6ac5('0x1a')]=_0x19b079[_0x6ac5('0x20')];}logger[_0x6ac5('0x11')]('['+[_0x4b9d91[_0x6ac5('0x12')]()]+_0x6ac5('0x21'),_0x19b079);_0x3c1ea2(_0x19b079);})[_0x6ac5('0x14')](function(_0x14eac8){logger[_0x6ac5('0x15')]('['+[_0x4b9d91[_0x6ac5('0x12')]()]+']',_0x14eac8[_0x6ac5('0x16')]);_0x2d654e(_0x14eac8[_0x6ac5('0x16')]);});}else{logger[_0x6ac5('0x11')]('['+[_0x4b9d91[_0x6ac5('0x12')]()]+_0x6ac5('0x22'));_0x19b079[_0x6ac5('0x1f')]=_0x19b079[_0x6ac5('0xf')];_0x19b079['userEmail']=_0x19b079[_0x6ac5('0x20')];_0x3c1ea2(_0x19b079);}});};}function createEndUser(_0x59fc6b,_0x3bf48d,_0x1827af,_0x1d7fe6,_0x99aa23){logger['info']('['+[_0x59fc6b[_0x6ac5('0x12')]()]+_0x6ac5('0x23'),_0x1827af);return new Promise(function(_0x3ac83d,_0x1a0cec){var _0x3f37d7={'method':_0x6ac5('0x24'),'uri':_0x1d7fe6+_0x6ac5('0x25')+_0x99aa23,'body':{'user_name':_0x1827af['endUserNumber'],'roles':_0x6ac5('0x26'),'first_name':_0x1827af[_0x6ac5('0x27')],'active':_0x6ac5('0x1e'),'date_format':_0x6ac5('0x28'),'phone':_0x1827af[_0x6ac5('0x27')]},'auth':_0x3bf48d,'json':!![]};return rp(_0x3f37d7)[_0x6ac5('0x1c')](function(_0x46360d){logger[_0x6ac5('0x11')]('['+[_0x59fc6b['toUpperCase']()]+_0x6ac5('0x29'),_0x46360d[_0x6ac5('0xd')]);_0x1827af[_0x6ac5('0x2a')]=_0x46360d[_0x6ac5('0xd')][_0x6ac5('0x10')];_0x3ac83d(_0x1827af);})[_0x6ac5('0x14')](function(_0x23ca97){logger['error']('['+[_0x59fc6b[_0x6ac5('0x12')]()]+']',_0x23ca97['message']);_0x1a0cec(_0x23ca97['message']);});});}function getEndUser(_0x585f97,_0x1851e7,_0x50dddc,_0xad620c,_0x426907){return function(_0x48403b){logger['info']('['+[_0x585f97[_0x6ac5('0x12')]()]+_0x6ac5('0x2b'),_0x48403b);return new Promise(function(_0x3a1480,_0x16dc33){var _0x3ea2b0={'method':'GET','uri':_0x50dddc+_0x6ac5('0x2c')+_0x48403b[_0x6ac5('0x27')]+'&'+_0xad620c+'&'+_0x426907,'auth':_0x1851e7,'json':!![]};return rp(_0x3ea2b0)[_0x6ac5('0x1c')](function(_0x50ca18){if(_0x50ca18['result']['length']>0x0){_0x48403b[_0x6ac5('0x2a')]=_0x50ca18[_0x6ac5('0xd')][0x0][_0x6ac5('0x10')];logger[_0x6ac5('0x11')]('['+[_0x585f97[_0x6ac5('0x12')]()]+_0x6ac5('0x2d'),_0x48403b);_0x3a1480(_0x48403b);}else{return createEndUser(_0x585f97,_0x1851e7,_0x48403b,_0x50dddc,_0xad620c)[_0x6ac5('0x1c')](function(_0x1a7b32){logger[_0x6ac5('0x11')]('['+[_0x585f97[_0x6ac5('0x12')]()]+_0x6ac5('0x2e'),_0x1a7b32);_0x3a1480(_0x1a7b32);});}})['catch'](function(_0x118a84){logger[_0x6ac5('0x15')]('['+[_0x585f97[_0x6ac5('0x12')]()]+']',_0x118a84['message']);_0x16dc33(_0x118a84[_0x6ac5('0x16')]);});});};}function getCustomFields(_0x4e6a76,_0x2593d5){var _0x128e7f={};if(_0x4e6a76[_0x6ac5('0xe')]>0x0){_[_0x6ac5('0x2f')](_0x4e6a76,function(_0x21398c){if(_[_0x6ac5('0x30')](['string',_0x6ac5('0x31')],_0x21398c[_0x6ac5('0x32')])&&_0x21398c[_0x6ac5('0x33')]&&!_0x21398c[_0x6ac5('0x34')]){_0x128e7f[_0x21398c['nameField']['toLowerCase']()]=_0x21398c[_0x6ac5('0x35')]['toString']();}else if(_[_0x6ac5('0x30')]([_0x6ac5('0x36'),_0x6ac5('0x31')],_0x21398c[_0x6ac5('0x32')])&&_0x21398c[_0x6ac5('0x37')]&&_0x21398c[_0x6ac5('0x34')]){_0x128e7f[_0x21398c[_0x6ac5('0x37')][_0x6ac5('0x38')]()]=_0x21398c[_0x6ac5('0x35')][_0x6ac5('0x39')]();}else if(_0x21398c[_0x6ac5('0x32')]==='variable'&&_0x21398c['variableName']&&_0x21398c['idField']&&_0x21398c[_0x6ac5('0x34')]){_0x128e7f[_0x21398c['idField'][_0x6ac5('0x38')]()]=_0x2593d5[_0x21398c['variableName']][_0x6ac5('0x39')]();}else if(_0x21398c[_0x6ac5('0x32')]===_0x6ac5('0x3a')&&_0x21398c[_0x6ac5('0x3b')]&&_0x21398c[_0x6ac5('0x3b')][_0x6ac5('0x3c')]&&_0x21398c[_0x6ac5('0x37')]&&_0x21398c['customField']){_0x128e7f[_0x21398c[_0x6ac5('0x37')]['toLowerCase']()]=_0x2593d5[_0x21398c[_0x6ac5('0x3b')][_0x6ac5('0x3c')][_0x6ac5('0x38')]()]['toString']();}});}return _0x128e7f;}function getTicket(_0x53c74a,_0xfafa86,_0x3d46d5,_0x346cf9,_0x15d8ac,_0x32a743){return function(_0x51a7dc){logger[_0x6ac5('0x11')]('['+[_0x53c74a[_0x6ac5('0x12')]()]+_0x6ac5('0x3d'),_0x51a7dc);return new Promise(function(_0xc6b9ed,_0xe74459){var _0x5287e5=_0x53c74a[_0x6ac5('0x38')]()===_0x6ac5('0x3e')?_0x51a7dc[_0x6ac5('0x1f')]:_0x51a7dc[_0x6ac5('0x2a')];var _0x57f18={'method':_0x6ac5('0x24'),'uri':_0x3d46d5+_0x6ac5('0x3f')+'?'+_0x32a743,'body':Object[_0x6ac5('0x40')]({},{'active':_0x6ac5('0x1e'),'caller_id':_0x5287e5,'assigned_to':_0x51a7dc[_0x6ac5('0x1f')],'short_description':intUtil[_0x6ac5('0x41')](_0x346cf9[_0x6ac5('0x42')],_0x15d8ac,'\x20'),'description':intUtil[_0x6ac5('0x41')](_0x346cf9['Descriptions'],_0x15d8ac,'\x0a')},getCustomFields(_0x346cf9[_0x6ac5('0x43')],_0x15d8ac)),'auth':_0xfafa86,'json':!![]};return rp(_0x57f18)[_0x6ac5('0x1c')](function(_0x2417f0){logger[_0x6ac5('0x11')]('['+[_0x53c74a[_0x6ac5('0x12')]()]+_0x6ac5('0x44'),_0x2417f0[_0x6ac5('0xd')]);_0x51a7dc[_0x6ac5('0x45')]=_0x2417f0['result'][_0x6ac5('0x10')];_0x51a7dc['ticketNumber']=_0x2417f0['result'][_0x6ac5('0x46')];logger[_0x6ac5('0x11')]('['+[_0x53c74a[_0x6ac5('0x12')]()]+_0x6ac5('0x47'),_0x51a7dc);_0xc6b9ed(_0x51a7dc);})[_0x6ac5('0x14')](function(_0x332934){logger[_0x6ac5('0x15')]('['+[_0x53c74a[_0x6ac5('0x12')]()]+']',_0x332934['message']);_0xe74459(_0x332934[_0x6ac5('0x16')]);});});};}function createRemoteTag(_0x4b75d0,_0x14aed0,_0x23784d,_0xfac6d4){return new Promise(function(_0x3a7214,_0x178ec1){var _0x2f183c={'method':_0x6ac5('0x24'),'uri':_0x23784d+_0x6ac5('0x48')+'?'+_0xfac6d4,'body':{'short_description':_0x4b75d0,'global':!![],'active':!![],'name':_0x4b75d0},'auth':_0x14aed0,'json':!![]};return rp(_0x2f183c)[_0x6ac5('0x1c')](function(_0x57c1ee){var _0x1d9732=_0x57c1ee[_0x6ac5('0xd')][_0x6ac5('0x10')];_0x3a7214(_0x1d9732);});});}function getRemoteTag(_0x23237c,_0x5669ce,_0x367272,_0x24537b,_0x58cf8f){return new Promise(function(_0x32a5fc,_0x5af599){var _0x18e9bd={'method':_0x6ac5('0xb'),'uri':_0x367272+_0x6ac5('0x48')+_0x6ac5('0x49')+_0x23237c+'&'+_0x24537b,'auth':_0x5669ce,'json':!![]};return rp(_0x18e9bd)[_0x6ac5('0x1c')](function(_0x40f593){if(_0x40f593[_0x6ac5('0xd')][_0x6ac5('0xe')]>0x0){var _0x19fb6d=_0x40f593[_0x6ac5('0xd')][0x0][_0x6ac5('0x10')];_0x32a5fc(_0x19fb6d);}else{return createRemoteTag(_0x23237c,_0x5669ce,_0x367272,_0x24537b)[_0x6ac5('0x1c')](function(_0x351168){_0x32a5fc(_0x351168);});}});});}function assignTagToIncident(_0x30cd76,_0x44ddd8,_0x139914,_0x1202ef,_0x172efd){return new Promise(function(_0x4dbf8c,_0x35d58b){var _0x6f88e0={'method':_0x6ac5('0x24'),'uri':_0x139914+_0x6ac5('0x4a')+'?'+_0x172efd,'body':{'label':_0x30cd76,'table':'incident','id_type':_0x6ac5('0x4b'),'table_key':_0x1202ef[_0x6ac5('0x45')],'title':_0x6ac5('0x4c')+_0x1202ef['ticketNumber'],'id_display':_0x1202ef[_0x6ac5('0x4d')]},'auth':_0x44ddd8,'json':!![]};return rp(_0x6f88e0)[_0x6ac5('0x1c')](function(_0x429421){_0x4dbf8c();})[_0x6ac5('0x14')](function(){_0x4dbf8c();});});}function manageTags(_0x3eb084,_0x1b1057,_0x17abdf,_0x5947b2,_0x5c58dc,_0x3f27cb,_0x503a5c){return new Promise(function(_0x2f9dc2,_0x9110c){var _0x2d0714=[];_0x1b1057[_0x6ac5('0x2f')](function(_0x3e0460){_0x2d0714[_0x6ac5('0x4e')](getRemoteTag(_0x3e0460,_0x17abdf,_0x5947b2,_0x3f27cb,_0x503a5c));});return Promise['all'](_0x2d0714)['then'](function(_0x5610dd){if(_0x5610dd[_0x6ac5('0xe')]){logger[_0x6ac5('0x11')]('['+[_0x3eb084[_0x6ac5('0x12')]()]+_0x6ac5('0x4f'),_0x5610dd);var _0x47c0c2=[];_0x5610dd['forEach'](function(_0x1149d7){_0x47c0c2['push'](assignTagToIncident(_0x1149d7,_0x17abdf,_0x5947b2,_0x5c58dc,_0x3f27cb));});return Promise[_0x6ac5('0x50')](_0x47c0c2)[_0x6ac5('0x1c')](function(){_0x2f9dc2();})[_0x6ac5('0x14')](function(){_0x2f9dc2();});}else{_0x2f9dc2();}});});}function getTags(_0x266317,_0x2d8fa5,_0x3c244f,_0x102f2f,_0x196a42,_0x250e97){return function(_0x5e597b){return new Promise(function(_0x49e42d,_0x1d52d6){var _0x50c23e=[];var _0x4d1feb=_0x102f2f[_0x6ac5('0x51')];if(_0x4d1feb&&_0x4d1feb['length']>0x0){_0x50c23e=_['map'](_0x4d1feb,'name');}if(_0x50c23e[_0x6ac5('0xe')]>0x0){return manageTags(_0x266317,_0x50c23e,_0x2d8fa5,_0x3c244f,_0x5e597b,_0x196a42,_0x250e97)[_0x6ac5('0x1c')](function(){_0x49e42d(_0x5e597b);});}else{_0x49e42d(_0x5e597b);}});};}function emit(_0x4a1762,_0x23d749,_0x16f12a){var _0x593f89='%26sysparm_record_target%3Dincident'+'%26sysparm_record_row%3D1%26sysparm_record_rows%3D39'+_0x6ac5('0x52')+'%255EORDERBYDESCnumber';var _0x9e8fd5={'uri':_0x4a1762+_0x6ac5('0x53')+_0x16f12a+_0x593f89};io['to'](util[_0x6ac5('0x54')](_0x6ac5('0x55'),_0x23d749))['emit']('trigger:browser:url',_0x9e8fd5);}exports['cs']=function(_0x4b74ed,_0x114df6,_0x10d09d,_0x187b8b,_0x40b879,_0xc6a44,_0x483543,_0x1451e1){var _0x394915={};var _0x873a44={'user':_0xc6a44[_0x6ac5('0x56')],'pass':_0xc6a44[_0x6ac5('0x57')]};var _0x461dc9=_0x6ac5('0x58');var _0x5443eb='sysparm_display_value=true';_0xc6a44[_0x6ac5('0x59')]=intUtil[_0x6ac5('0x5a')](_0xc6a44[_0x6ac5('0x59')]);_0xc6a44[_0x6ac5('0x5b')]=intUtil[_0x6ac5('0x5a')](_0xc6a44[_0x6ac5('0x5b')]);var _0x2b1e5e=util[_0x6ac5('0x54')](_0x6ac5('0x5c'),_0xc6a44[_0x6ac5('0x59')]);_0x394915['userEmail']=!_[_0x6ac5('0x5d')](_0x187b8b)?_0x187b8b['email']:null;_0x394915['adminEmail']=_0xc6a44[_0x6ac5('0x5e')];_0x394915[_0x6ac5('0x27')]=_0x1451e1[_0x6ac5('0x38')]()==='outbound'?_0x114df6[_0x6ac5('0x5f')]:_0x114df6[_0x6ac5('0x60')];_0x394915[_0x6ac5('0x61')]=_0x1451e1===_0x6ac5('0x62')||_0x1451e1===_0x6ac5('0x63')?_0x6ac5('0x62'):_0x6ac5('0x3e');var _0x5197a3=util[_0x6ac5('0x54')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0xc6a44[_0x6ac5('0x5b')],_0x114df6[_0x6ac5('0x64')],md5(_0x114df6[_0x6ac5('0x64')]));if(_0x40b879&&_0x40b879['monitor_format']){logger['info'](_0x6ac5('0x65'),_0x6ac5('0x66'));_0x114df6[_0x6ac5('0x67')]=_0x5197a3;}else if(_0x483543&&_0x483543[_0x6ac5('0x68')]&&_0x483543[_0x6ac5('0x68')]!==_0x6ac5('0x69')){logger[_0x6ac5('0x11')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x114df6[_0x6ac5('0x67')]=_0x5197a3;}else{_0x114df6[_0x6ac5('0x67')]='';}return getAdminUser(_0x1451e1,_0x873a44,_0x394915,_0x2b1e5e,_0x5443eb,_0x461dc9)['then'](getUser(_0x1451e1,_0x873a44,_0x2b1e5e,_0x5443eb,_0x461dc9))[_0x6ac5('0x1c')](getEndUser(_0x1451e1,_0x873a44,_0x2b1e5e,_0x5443eb,_0x461dc9))['then'](getTicket(_0x1451e1,_0x873a44,_0x2b1e5e,_0x10d09d,_0x114df6,_0x5443eb))['then'](function(_0x55bdea){logger[_0x6ac5('0x11')](util[_0x6ac5('0x54')](_0x6ac5('0x6a'),_0x55bdea['ticketId']));logger['info'](util[_0x6ac5('0x54')](_0x6ac5('0x6b'),_0x1451e1));if(_0x1451e1!==_0x6ac5('0x63')){logger[_0x6ac5('0x11')]('['+[_0x1451e1[_0x6ac5('0x12')]()]+']',_0x6ac5('0x6c'));emit(_0xc6a44[_0x6ac5('0x59')],_0x187b8b['name'],_0x55bdea[_0x6ac5('0x45')]);}})['catch'](function(_0x340b13){logger[_0x6ac5('0x15')]('['+[_0x1451e1[_0x6ac5('0x12')]()]+_0x6ac5('0x6d'),util[_0x6ac5('0x6e')](_0x340b13,{'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