Built motion from commit e1760111.|2.6.18
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 71dfd0b..53ef618 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 _0x752f=['emit','username','password','sysparm_limit=1','sysparm_display_value=true','remoteUri','stripTrailingSlash','serverUrl','%s/api/now/table/','email','destcalleridnum','callDirection','queue','unmanaged','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','[OUTBOUND]','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','ioredis','./util','../../../../config/environment','../../../../config/logger','redis','defaults','localhost','socket.io-emitter','GET','then','result','length','adminId','sys_id','info','catch','toUpperCase','message','],\x20getUser\x20input\x20crm','userEmail','sys_user?sysparm_query=email%3D','],\x20getUser\x20rp\x20obj','],\x20getUser\x20entity','active','true','userId','error',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','endUserNumber','System','sys_user?sysparm_query=phone%3D','],\x20createEndUser\x20crm','includes','string','type','nameField','toLowerCase','toString','picklist','customField','idField','content','variable','variableName','customVariable','Variable','name','outbound','endUserId','POST','assign','getString','Subjects','Descriptions','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketId',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','label_entry','Incident','ticketNumber','push','forEach','all','Tags','map','%26sysparm_record_target%3Dincident','%26sysparm_record_row%3D1%26sysparm_record_rows%3D39','%26sysparm_record_list%3Dactive%253Dtrue','%255EORDERBYDESCnumber','format','user:%s'];(function(_0x26d228,_0x3213b8){var _0x4a663a=function(_0xa23f3e){while(--_0xa23f3e){_0x26d228['push'](_0x26d228['shift']());}};_0x4a663a(++_0x3213b8);}(_0x752f,0x152));var _0xf752=function(_0x5ab934,_0x2a3f34){_0x5ab934=_0x5ab934-0x0;var _0x417750=_0x752f[_0x5ab934];return _0x417750;};'use strict';var _=require(_0xf752('0x0'));var Promise=require(_0xf752('0x1'));var rp=require(_0xf752('0x2'));var util=require('util');var md5=require('md5');var Redis=require(_0xf752('0x3'));var intUtil=require(_0xf752('0x4'));var config=require(_0xf752('0x5'));var logger=require(_0xf752('0x6'))('servicenow');config[_0xf752('0x7')]=_[_0xf752('0x8')](config[_0xf752('0x7')],{'host':_0xf752('0x9'),'port':0x18eb});var io=require(_0xf752('0xa'))(new Redis(config[_0xf752('0x7')]));function getAdminUser(_0x21d520,_0x19d146,_0x434de3,_0x141c92,_0x764d5,_0x1d59a4){return new Promise(function(_0x458b66,_0x471d1d){var _0x15def7={'method':_0xf752('0xb'),'uri':_0x141c92+'sys_user?sysparm_query=user_name%3Dadmin'+'&'+_0x764d5+'&'+_0x1d59a4,'auth':_0x19d146,'json':!![]};return rp(_0x15def7)[_0xf752('0xc')](function(_0x5a8dd1){if(_0x5a8dd1[_0xf752('0xd')][_0xf752('0xe')]>0x0){_0x434de3[_0xf752('0xf')]=_0x5a8dd1[_0xf752('0xd')][0x0][_0xf752('0x10')];}logger[_0xf752('0x11')]('['+[_0x21d520['toUpperCase']()]+'],\x20getAdminUser\x20crm',_0x434de3);_0x458b66(_0x434de3);})[_0xf752('0x12')](function(_0x56ab08){logger['error']('['+[_0x21d520[_0xf752('0x13')]()]+']',_0x56ab08[_0xf752('0x14')]);_0x471d1d(_0x56ab08[_0xf752('0x14')]);});});}function getUser(_0x143f7f,_0x413e0b,_0x74b713,_0x208d53,_0x3612d5){return function(_0x5e05d5){logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x15'),_0x5e05d5);return new Promise(function(_0x3cc66c,_0x444b0f){if(intUtil['validateEmail'](_0x5e05d5[_0xf752('0x16')])){var _0x58b7e0={'method':_0xf752('0xb'),'uri':_0x74b713+_0xf752('0x17')+_0x5e05d5['userEmail']+'&'+_0x208d53+'&'+_0x3612d5,'auth':_0x413e0b,'json':!![]};logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x18'),_0x58b7e0);return rp(_0x58b7e0)[_0xf752('0xc')](function(_0x5c96e4){logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x19'),_0x5c96e4);if(_0x5c96e4[_0xf752('0xd')][_0xf752('0xe')]>0x0&&String(_0x5c96e4[_0xf752('0xd')][0x0][_0xf752('0x1a')])===_0xf752('0x1b')){_0x5e05d5[_0xf752('0x1c')]=_0x5c96e4[_0xf752('0xd')][0x0][_0xf752('0x10')];}else{_0x5e05d5[_0xf752('0x1c')]=_0x5e05d5[_0xf752('0xf')];_0x5e05d5[_0xf752('0x16')]=_0x5e05d5['adminEmail'];}logger[_0xf752('0x11')]('['+[_0x143f7f[_0xf752('0x13')]()]+'],\x20getUser\x20crm',_0x5e05d5);_0x3cc66c(_0x5e05d5);})[_0xf752('0x12')](function(_0x13da4a){logger[_0xf752('0x1d')]('['+[_0x143f7f['toUpperCase']()]+']',_0x13da4a['message']);_0x444b0f(_0x13da4a[_0xf752('0x14')]);});}else{logger['info']('['+[_0x143f7f[_0xf752('0x13')]()]+_0xf752('0x1e'));_0x5e05d5[_0xf752('0x1c')]=_0x5e05d5[_0xf752('0xf')];_0x5e05d5[_0xf752('0x16')]=_0x5e05d5['adminEmail'];_0x3cc66c(_0x5e05d5);}});};}function createEndUser(_0xc72a47,_0x185075,_0x4ae405,_0x4d0e39,_0x13cb58){logger[_0xf752('0x11')]('['+[_0xc72a47[_0xf752('0x13')]()]+_0xf752('0x1f'),_0x4ae405);return new Promise(function(_0x146e7b,_0x5bf9a5){var _0x951e1c={'method':'POST','uri':_0x4d0e39+'sys_user?'+_0x13cb58,'body':{'user_name':_0x4ae405['endUserNumber'],'roles':'user','first_name':_0x4ae405[_0xf752('0x20')],'active':_0xf752('0x1b'),'date_format':_0xf752('0x21'),'phone':_0x4ae405[_0xf752('0x20')]},'auth':_0x185075,'json':!![]};return rp(_0x951e1c)[_0xf752('0xc')](function(_0x2b3e30){logger[_0xf752('0x11')]('['+[_0xc72a47['toUpperCase']()]+'],\x20EndUser\x20schema',_0x2b3e30['result']);_0x4ae405['endUserId']=_0x2b3e30[_0xf752('0xd')]['sys_id'];_0x146e7b(_0x4ae405);})[_0xf752('0x12')](function(_0x4fe619){logger['error']('['+[_0xc72a47['toUpperCase']()]+']',_0x4fe619[_0xf752('0x14')]);_0x5bf9a5(_0x4fe619[_0xf752('0x14')]);});});}function getEndUser(_0x25cbed,_0x4d2b60,_0x599f01,_0x1b2f69,_0x37c8f0){return function(_0x3aa7cc){logger['info']('['+[_0x25cbed[_0xf752('0x13')]()]+'],\x20getEndUser\x20input\x20crm',_0x3aa7cc);return new Promise(function(_0x10cee6,_0x5634aa){var _0x5dfd61={'method':'GET','uri':_0x599f01+_0xf752('0x22')+_0x3aa7cc['endUserNumber']+'&'+_0x1b2f69+'&'+_0x37c8f0,'auth':_0x4d2b60,'json':!![]};return rp(_0x5dfd61)['then'](function(_0x209191){if(_0x209191['result'][_0xf752('0xe')]>0x0){_0x3aa7cc['endUserId']=_0x209191[_0xf752('0xd')][0x0]['sys_id'];logger[_0xf752('0x11')]('['+[_0x25cbed[_0xf752('0x13')]()]+'],\x20getEndUser\x20crm',_0x3aa7cc);_0x10cee6(_0x3aa7cc);}else{return createEndUser(_0x25cbed,_0x4d2b60,_0x3aa7cc,_0x599f01,_0x1b2f69)[_0xf752('0xc')](function(_0x15735d){logger[_0xf752('0x11')]('['+[_0x25cbed['toUpperCase']()]+_0xf752('0x23'),_0x15735d);_0x10cee6(_0x15735d);});}})[_0xf752('0x12')](function(_0x1ec8b8){logger[_0xf752('0x1d')]('['+[_0x25cbed[_0xf752('0x13')]()]+']',_0x1ec8b8['message']);_0x5634aa(_0x1ec8b8['message']);});});};}function getCustomFields(_0x1e801a,_0x52e9ae){var _0x4c23b9={};if(_0x1e801a[_0xf752('0xe')]>0x0){_['forEach'](_0x1e801a,function(_0x504805){if(_[_0xf752('0x24')]([_0xf752('0x25'),'picklist'],_0x504805[_0xf752('0x26')])&&_0x504805[_0xf752('0x27')]&&!_0x504805['customField']){_0x4c23b9[_0x504805['nameField'][_0xf752('0x28')]()]=_0x504805['content'][_0xf752('0x29')]();}else if(_[_0xf752('0x24')]([_0xf752('0x25'),_0xf752('0x2a')],_0x504805[_0xf752('0x26')])&&_0x504805['idField']&&_0x504805[_0xf752('0x2b')]){_0x4c23b9[_0x504805[_0xf752('0x2c')][_0xf752('0x28')]()]=_0x504805[_0xf752('0x2d')][_0xf752('0x29')]();}else if(_0x504805[_0xf752('0x26')]===_0xf752('0x2e')&&_0x504805[_0xf752('0x2f')]&&_0x504805[_0xf752('0x2c')]&&_0x504805[_0xf752('0x2b')]){_0x4c23b9[_0x504805['idField'][_0xf752('0x28')]()]=_0x52e9ae[_0x504805[_0xf752('0x2f')]]['toString']();}else if(_0x504805[_0xf752('0x26')]===_0xf752('0x30')&&_0x504805[_0xf752('0x31')]&&_0x504805['Variable'][_0xf752('0x32')]&&_0x504805['idField']&&_0x504805[_0xf752('0x2b')]){_0x4c23b9[_0x504805[_0xf752('0x2c')][_0xf752('0x28')]()]=_0x52e9ae[_0x504805[_0xf752('0x31')][_0xf752('0x32')][_0xf752('0x28')]()]['toString']();}});}return _0x4c23b9;}function getTicket(_0x2dc3d2,_0x50ff8c,_0x273747,_0x2b46e4,_0x5cf1e2,_0x3a9f0f){return function(_0x3159a3){logger['info']('['+[_0x2dc3d2['toUpperCase']()]+']\x20getTicket\x20input\x20crm',_0x3159a3);return new Promise(function(_0x588ac9,_0x59bc30){var _0x3a8244=_0x2dc3d2[_0xf752('0x28')]()===_0xf752('0x33')?_0x3159a3[_0xf752('0x1c')]:_0x3159a3[_0xf752('0x34')];var _0x3a6928={'method':_0xf752('0x35'),'uri':_0x273747+'incident'+'?'+_0x3a9f0f,'body':Object[_0xf752('0x36')]({},{'active':'true','caller_id':_0x3a8244,'assigned_to':_0x3159a3['userId'],'short_description':intUtil[_0xf752('0x37')](_0x2b46e4[_0xf752('0x38')],_0x5cf1e2,'\x20'),'description':intUtil[_0xf752('0x37')](_0x2b46e4[_0xf752('0x39')],_0x5cf1e2,'\x0a')},getCustomFields(_0x2b46e4[_0xf752('0x3a')],_0x5cf1e2)),'auth':_0x50ff8c,'json':!![]};return rp(_0x3a6928)['then'](function(_0x1445f3){logger[_0xf752('0x11')]('['+[_0x2dc3d2['toUpperCase']()]+_0xf752('0x3b'),_0x1445f3['result']);_0x3159a3[_0xf752('0x3c')]=_0x1445f3[_0xf752('0xd')][_0xf752('0x10')];_0x3159a3['ticketNumber']=_0x1445f3['result']['number'];logger[_0xf752('0x11')]('['+[_0x2dc3d2[_0xf752('0x13')]()]+_0xf752('0x3d'),_0x3159a3);_0x588ac9(_0x3159a3);})[_0xf752('0x12')](function(_0x1e87b2){logger[_0xf752('0x1d')]('['+[_0x2dc3d2[_0xf752('0x13')]()]+']',_0x1e87b2[_0xf752('0x14')]);_0x59bc30(_0x1e87b2[_0xf752('0x14')]);});});};}function createRemoteTag(_0x71133a,_0x37b87e,_0x26e1b9,_0x4251ca){return new Promise(function(_0x55182f,_0x459914){var _0xf857a={'method':_0xf752('0x35'),'uri':_0x26e1b9+_0xf752('0x3e')+'?'+_0x4251ca,'body':{'short_description':_0x71133a,'global':!![],'active':!![],'name':_0x71133a},'auth':_0x37b87e,'json':!![]};return rp(_0xf857a)[_0xf752('0xc')](function(_0x265f6b){var _0x3aa752=_0x265f6b['result']['sys_id'];_0x55182f(_0x3aa752);});});}function getRemoteTag(_0x8f2a46,_0x852006,_0x56dda4,_0x58aba3,_0x3a066a){return new Promise(function(_0x43afe8,_0x32aa32){var _0xeb8983={'method':_0xf752('0xb'),'uri':_0x56dda4+_0xf752('0x3e')+_0xf752('0x3f')+_0x8f2a46+'&'+_0x58aba3,'auth':_0x852006,'json':!![]};return rp(_0xeb8983)[_0xf752('0xc')](function(_0x2a3e7b){if(_0x2a3e7b[_0xf752('0xd')][_0xf752('0xe')]>0x0){var _0x5dbbe8=_0x2a3e7b[_0xf752('0xd')][0x0][_0xf752('0x10')];_0x43afe8(_0x5dbbe8);}else{return createRemoteTag(_0x8f2a46,_0x852006,_0x56dda4,_0x58aba3)[_0xf752('0xc')](function(_0x5e06ca){_0x43afe8(_0x5e06ca);});}});});}function assignTagToIncident(_0x25ec45,_0x52461e,_0x72a1af,_0x56ce8a,_0x2513d6){return new Promise(function(_0x922751,_0x2953cf){var _0x213b47={'method':_0xf752('0x35'),'uri':_0x72a1af+_0xf752('0x40')+'?'+_0x2513d6,'body':{'label':_0x25ec45,'table':'incident','id_type':_0xf752('0x41'),'table_key':_0x56ce8a['ticketId'],'title':'Incident\x20-\x20'+_0x56ce8a[_0xf752('0x42')],'id_display':_0x56ce8a[_0xf752('0x42')]},'auth':_0x52461e,'json':!![]};return rp(_0x213b47)[_0xf752('0xc')](function(_0x4cfbbf){_0x922751();})[_0xf752('0x12')](function(){_0x922751();});});}function manageTags(_0xe0ebb2,_0x2e70a0,_0x1bb8c3,_0x220550,_0x59dc74,_0x4a3101,_0x553224){return new Promise(function(_0x4eba59,_0x50487a){var _0x59a287=[];_0x2e70a0['forEach'](function(_0x319c8d){_0x59a287[_0xf752('0x43')](getRemoteTag(_0x319c8d,_0x1bb8c3,_0x220550,_0x4a3101,_0x553224));});return Promise['all'](_0x59a287)[_0xf752('0xc')](function(_0x3b6751){if(_0x3b6751[_0xf752('0xe')]){logger[_0xf752('0x11')]('['+[_0xe0ebb2[_0xf752('0x13')]()]+']\x20arrayPromises:\x20IDs\x20in\x20table\x20label',_0x3b6751);var _0x26a5dc=[];_0x3b6751[_0xf752('0x44')](function(_0x1073cd){_0x26a5dc[_0xf752('0x43')](assignTagToIncident(_0x1073cd,_0x1bb8c3,_0x220550,_0x59dc74,_0x4a3101));});return Promise[_0xf752('0x45')](_0x26a5dc)[_0xf752('0xc')](function(){_0x4eba59();})[_0xf752('0x12')](function(){_0x4eba59();});}else{_0x4eba59();}});});}function getTags(_0x460ae5,_0x92ef26,_0x4df6b2,_0x7df053,_0x423d75,_0x197837){return function(_0x59100c){return new Promise(function(_0x157f10,_0x265e12){var _0x62d444=[];var _0x36e3f3=_0x7df053[_0xf752('0x46')];if(_0x36e3f3&&_0x36e3f3[_0xf752('0xe')]>0x0){_0x62d444=_[_0xf752('0x47')](_0x36e3f3,_0xf752('0x32'));}if(_0x62d444['length']>0x0){return manageTags(_0x460ae5,_0x62d444,_0x92ef26,_0x4df6b2,_0x59100c,_0x423d75,_0x197837)[_0xf752('0xc')](function(){_0x157f10(_0x59100c);});}else{_0x157f10(_0x59100c);}});};}function emit(_0x1d80bf,_0x5b07b2,_0x2a4061){var _0x3a9e3b=_0xf752('0x48')+_0xf752('0x49')+_0xf752('0x4a')+_0xf752('0x4b');var _0x399c11={'uri':_0x1d80bf+'/nav_to.do?uri=incident.do?sys_id%3D'+_0x2a4061+_0x3a9e3b};io['to'](util[_0xf752('0x4c')](_0xf752('0x4d'),_0x5b07b2))[_0xf752('0x4e')]('trigger:browser:url',_0x399c11);}exports['cs']=function(_0x51a381,_0x4d4d46,_0x2ae0c2,_0x2a62b5,_0x4eb2ce,_0x566bc7,_0x5505cd,_0x43b017){var _0x21c4b9={};var _0x20ade9={'user':_0x566bc7[_0xf752('0x4f')],'pass':_0x566bc7[_0xf752('0x50')]};var _0x94d5b0=_0xf752('0x51');var _0x2d3afe=_0xf752('0x52');_0x566bc7[_0xf752('0x53')]=intUtil[_0xf752('0x54')](_0x566bc7['remoteUri']);_0x566bc7['serverUrl']=intUtil['stripTrailingSlash'](_0x566bc7[_0xf752('0x55')]);var _0x165a4d=util[_0xf752('0x4c')](_0xf752('0x56'),_0x566bc7[_0xf752('0x53')]);_0x21c4b9[_0xf752('0x16')]=!_['isNil'](_0x2a62b5)?_0x2a62b5[_0xf752('0x57')]:null;_0x21c4b9['adminEmail']=_0x566bc7[_0xf752('0x57')];_0x21c4b9[_0xf752('0x20')]=_0x43b017['toLowerCase']()==='outbound'?_0x4d4d46[_0xf752('0x58')]:_0x4d4d46['calleridnum'];_0x21c4b9[_0xf752('0x59')]=_0x43b017===_0xf752('0x5a')||_0x43b017===_0xf752('0x5b')?'queue':_0xf752('0x33');var _0x56105c=util[_0xf752('0x4c')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x566bc7[_0xf752('0x55')],_0x4d4d46[_0xf752('0x5c')],md5(_0x4d4d46[_0xf752('0x5c')]));if(_0x4eb2ce&&_0x4eb2ce[_0xf752('0x5d')]){logger['info'](_0xf752('0x5e'),_0xf752('0x5f'));_0x4d4d46[_0xf752('0x60')]=_0x56105c;}else if(_0x5505cd&&_0x5505cd[_0xf752('0x61')]&&_0x5505cd['recordingFormat']!=='none'){logger[_0xf752('0x11')](_0xf752('0x62'),_0xf752('0x5f'));_0x4d4d46[_0xf752('0x60')]=_0x56105c;}else{_0x4d4d46['recordingURL']='';}return getAdminUser(_0x43b017,_0x20ade9,_0x21c4b9,_0x165a4d,_0x2d3afe,_0x94d5b0)[_0xf752('0xc')](getUser(_0x43b017,_0x20ade9,_0x165a4d,_0x2d3afe,_0x94d5b0))[_0xf752('0xc')](getEndUser(_0x43b017,_0x20ade9,_0x165a4d,_0x2d3afe,_0x94d5b0))[_0xf752('0xc')](getTicket(_0x43b017,_0x20ade9,_0x165a4d,_0x2ae0c2,_0x4d4d46,_0x2d3afe))[_0xf752('0xc')](function(_0xa41921){logger[_0xf752('0x11')](util[_0xf752('0x4c')](_0xf752('0x63'),_0xa41921[_0xf752('0x3c')]));logger[_0xf752('0x11')](util['format'](_0xf752('0x64'),_0x43b017));if(_0x43b017!==_0xf752('0x5b')){logger['info']('['+[_0x43b017[_0xf752('0x13')]()]+']',_0xf752('0x65'));emit(_0x566bc7[_0xf752('0x53')],_0x2a62b5[_0xf752('0x32')],_0xa41921[_0xf752('0x3c')]);}})[_0xf752('0x12')](function(_0xed3f5c){logger[_0xf752('0x1d')]('['+[_0x43b017['toUpperCase']()]+_0xf752('0x66'),util[_0xf752('0x67')](_0xed3f5c,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file