Built motion from commit c116dc8b.|2.6.30
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 88a98ea..927f594 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7ffa=['recordingURL','recordingFormat','none','[OUTBOUND]','The\x20ticket\x20ID\x20is:\x20%s','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','lodash','util','md5','ioredis','../../../../config/environment','../../../../config/logger','servicenow','redis','defaults','localhost','socket.io-emitter','GET','sys_user?sysparm_query=user_name%3Dadmin','result','sys_id','info','],\x20getAdminUser\x20crm','catch','error','toUpperCase','message','sys_user?sysparm_query=email%3D','then','],\x20getUser\x20entity','length','active','true','userId','userEmail',']\x20using\x20admin\x20profile','adminId','adminEmail','],\x20createEndUser\x20input\x20crm','POST','endUserNumber','user','System','],\x20EndUser\x20schema','],\x20getEndUser\x20input\x20crm','endUserId','],\x20getEndUser\x20crm','forEach','includes','picklist','type','customField','nameField','toLowerCase','content','string','idField','variable','variableName','Variable','name','toString',']\x20getTicket\x20input\x20crm','incident','assign','getString','Subjects','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketId','ticketNumber','number',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','Incident\x20-\x20','push','all',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','Tags','map','%26sysparm_record_target%3Dincident','%26sysparm_record_row%3D1%26sysparm_record_rows%3D39','%26sysparm_record_list%3Dactive%253Dtrue','%255EORDERBYDESCnumber','/nav_to.do?uri=incident.do?sys_id%3D','format','user:%s','emit','trigger:browser:url','username','password','sysparm_limit=1','sysparm_display_value=true','remoteUri','serverUrl','stripTrailingSlash','%s/api/now/table/','email','outbound','destcalleridnum','calleridnum','callDirection','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','Recording\x20is\x20enabled!'];(function(_0x397e5f,_0x454c8f){var _0x5302b8=function(_0x1a29ef){while(--_0x1a29ef){_0x397e5f['push'](_0x397e5f['shift']());}};_0x5302b8(++_0x454c8f);}(_0x7ffa,0x155));var _0xa7ff=function(_0x1a4023,_0xa7961){_0x1a4023=_0x1a4023-0x0;var _0x3cc2cf=_0x7ffa[_0x1a4023];return _0x3cc2cf;};'use strict';var _=require(_0xa7ff('0x0'));var Promise=require('bluebird');var rp=require('request-promise');var util=require(_0xa7ff('0x1'));var md5=require(_0xa7ff('0x2'));var Redis=require(_0xa7ff('0x3'));var intUtil=require('./util');var config=require(_0xa7ff('0x4'));var logger=require(_0xa7ff('0x5'))(_0xa7ff('0x6'));config[_0xa7ff('0x7')]=_[_0xa7ff('0x8')](config['redis'],{'host':_0xa7ff('0x9'),'port':0x18eb});var io=require(_0xa7ff('0xa'))(new Redis(config[_0xa7ff('0x7')]));function getAdminUser(_0x81cdc4,_0x3d6b15,_0x3f67c2,_0x1ccaf4,_0x2117b2,_0x4c9dc1){return new Promise(function(_0x34eb07,_0x4af756){var _0x5817d8={'method':_0xa7ff('0xb'),'uri':_0x1ccaf4+_0xa7ff('0xc')+'&'+_0x2117b2+'&'+_0x4c9dc1,'auth':_0x3d6b15,'json':!![]};return rp(_0x5817d8)['then'](function(_0x142e88){if(_0x142e88[_0xa7ff('0xd')]['length']>0x0){_0x3f67c2['adminId']=_0x142e88[_0xa7ff('0xd')][0x0][_0xa7ff('0xe')];}logger[_0xa7ff('0xf')]('['+[_0x81cdc4['toUpperCase']()]+_0xa7ff('0x10'),_0x3f67c2);_0x34eb07(_0x3f67c2);})[_0xa7ff('0x11')](function(_0x2ca6a0){logger[_0xa7ff('0x12')]('['+[_0x81cdc4[_0xa7ff('0x13')]()]+']',_0x2ca6a0[_0xa7ff('0x14')]);_0x4af756(_0x2ca6a0[_0xa7ff('0x14')]);});});}function getUser(_0x2c4be9,_0x4d0d08,_0x5ea520,_0x19d1a5,_0x5e6b3b){return function(_0x335eff){logger[_0xa7ff('0xf')]('['+[_0x2c4be9['toUpperCase']()]+'],\x20getUser\x20input\x20crm',_0x335eff);return new Promise(function(_0x1f7c24,_0x4b904a){if(intUtil['validateEmail'](_0x335eff['userEmail'])){var _0x2bee4a={'method':_0xa7ff('0xb'),'uri':_0x5ea520+_0xa7ff('0x15')+_0x335eff['userEmail']+'&'+_0x19d1a5+'&'+_0x5e6b3b,'auth':_0x4d0d08,'json':!![]};logger[_0xa7ff('0xf')]('['+[_0x2c4be9[_0xa7ff('0x13')]()]+'],\x20getUser\x20rp\x20obj',_0x2bee4a);return rp(_0x2bee4a)[_0xa7ff('0x16')](function(_0x2e6a90){logger[_0xa7ff('0xf')]('['+[_0x2c4be9[_0xa7ff('0x13')]()]+_0xa7ff('0x17'),_0x2e6a90);if(_0x2e6a90[_0xa7ff('0xd')][_0xa7ff('0x18')]>0x0&&String(_0x2e6a90[_0xa7ff('0xd')][0x0][_0xa7ff('0x19')])===_0xa7ff('0x1a')){_0x335eff['userId']=_0x2e6a90[_0xa7ff('0xd')][0x0][_0xa7ff('0xe')];}else{_0x335eff[_0xa7ff('0x1b')]=_0x335eff['adminId'];_0x335eff[_0xa7ff('0x1c')]=_0x335eff['adminEmail'];}logger[_0xa7ff('0xf')]('['+[_0x2c4be9[_0xa7ff('0x13')]()]+'],\x20getUser\x20crm',_0x335eff);_0x1f7c24(_0x335eff);})['catch'](function(_0x2857b2){logger[_0xa7ff('0x12')]('['+[_0x2c4be9[_0xa7ff('0x13')]()]+']',_0x2857b2[_0xa7ff('0x14')]);_0x4b904a(_0x2857b2[_0xa7ff('0x14')]);});}else{logger['info']('['+[_0x2c4be9['toUpperCase']()]+_0xa7ff('0x1d'));_0x335eff[_0xa7ff('0x1b')]=_0x335eff[_0xa7ff('0x1e')];_0x335eff['userEmail']=_0x335eff[_0xa7ff('0x1f')];_0x1f7c24(_0x335eff);}});};}function createEndUser(_0x5742a9,_0x58b4f3,_0x164d21,_0x5972b1,_0x4e9a05){logger[_0xa7ff('0xf')]('['+[_0x5742a9['toUpperCase']()]+_0xa7ff('0x20'),_0x164d21);return new Promise(function(_0x390f76,_0x1fc32){var _0x12ac6b={'method':_0xa7ff('0x21'),'uri':_0x5972b1+'sys_user?'+_0x4e9a05,'body':{'user_name':_0x164d21[_0xa7ff('0x22')],'roles':_0xa7ff('0x23'),'first_name':_0x164d21[_0xa7ff('0x22')],'active':_0xa7ff('0x1a'),'date_format':_0xa7ff('0x24'),'phone':_0x164d21[_0xa7ff('0x22')]},'auth':_0x58b4f3,'json':!![]};return rp(_0x12ac6b)[_0xa7ff('0x16')](function(_0x488520){logger[_0xa7ff('0xf')]('['+[_0x5742a9[_0xa7ff('0x13')]()]+_0xa7ff('0x25'),_0x488520[_0xa7ff('0xd')]);_0x164d21['endUserId']=_0x488520[_0xa7ff('0xd')][_0xa7ff('0xe')];_0x390f76(_0x164d21);})['catch'](function(_0x4dbfb1){logger[_0xa7ff('0x12')]('['+[_0x5742a9[_0xa7ff('0x13')]()]+']',_0x4dbfb1[_0xa7ff('0x14')]);_0x1fc32(_0x4dbfb1[_0xa7ff('0x14')]);});});}function getEndUser(_0x2dfcdb,_0x5df8a4,_0x5daae8,_0x3e1ecc,_0x2de348){return function(_0x56da43){logger[_0xa7ff('0xf')]('['+[_0x2dfcdb[_0xa7ff('0x13')]()]+_0xa7ff('0x26'),_0x56da43);return new Promise(function(_0x29ce0a,_0x29dcd4){var _0x4e40a0={'method':'GET','uri':_0x5daae8+'sys_user?sysparm_query=phone%3D'+_0x56da43[_0xa7ff('0x22')]+'&'+_0x3e1ecc+'&'+_0x2de348,'auth':_0x5df8a4,'json':!![]};return rp(_0x4e40a0)['then'](function(_0x147b6b){if(_0x147b6b['result']['length']>0x0){_0x56da43[_0xa7ff('0x27')]=_0x147b6b[_0xa7ff('0xd')][0x0]['sys_id'];logger[_0xa7ff('0xf')]('['+[_0x2dfcdb[_0xa7ff('0x13')]()]+_0xa7ff('0x28'),_0x56da43);_0x29ce0a(_0x56da43);}else{return createEndUser(_0x2dfcdb,_0x5df8a4,_0x56da43,_0x5daae8,_0x3e1ecc)['then'](function(_0x18d603){logger[_0xa7ff('0xf')]('['+[_0x2dfcdb['toUpperCase']()]+'],\x20createEndUser\x20crm',_0x18d603);_0x29ce0a(_0x18d603);});}})[_0xa7ff('0x11')](function(_0x439e31){logger['error']('['+[_0x2dfcdb[_0xa7ff('0x13')]()]+']',_0x439e31[_0xa7ff('0x14')]);_0x29dcd4(_0x439e31[_0xa7ff('0x14')]);});});};}function getCustomFields(_0x433070,_0x157800){var _0x7fdef9={};if(_0x433070[_0xa7ff('0x18')]>0x0){_[_0xa7ff('0x29')](_0x433070,function(_0xc7197a){if(_[_0xa7ff('0x2a')](['string',_0xa7ff('0x2b')],_0xc7197a[_0xa7ff('0x2c')])&&_0xc7197a['nameField']&&!_0xc7197a[_0xa7ff('0x2d')]){_0x7fdef9[_0xc7197a[_0xa7ff('0x2e')][_0xa7ff('0x2f')]()]=_0xc7197a[_0xa7ff('0x30')]['toString']();}else if(_['includes']([_0xa7ff('0x31'),_0xa7ff('0x2b')],_0xc7197a['type'])&&_0xc7197a[_0xa7ff('0x32')]&&_0xc7197a[_0xa7ff('0x2d')]){_0x7fdef9[_0xc7197a[_0xa7ff('0x32')][_0xa7ff('0x2f')]()]=_0xc7197a[_0xa7ff('0x30')]['toString']();}else if(_0xc7197a[_0xa7ff('0x2c')]===_0xa7ff('0x33')&&_0xc7197a[_0xa7ff('0x34')]&&_0xc7197a['idField']&&_0xc7197a[_0xa7ff('0x2d')]){_0x7fdef9[_0xc7197a[_0xa7ff('0x32')][_0xa7ff('0x2f')]()]=_0x157800[_0xc7197a[_0xa7ff('0x34')]]['toString']();}else if(_0xc7197a['type']==='customVariable'&&_0xc7197a[_0xa7ff('0x35')]&&_0xc7197a[_0xa7ff('0x35')][_0xa7ff('0x36')]&&_0xc7197a[_0xa7ff('0x32')]&&_0xc7197a['customField']){_0x7fdef9[_0xc7197a[_0xa7ff('0x32')]['toLowerCase']()]=_0x157800[_0xc7197a['Variable'][_0xa7ff('0x36')][_0xa7ff('0x2f')]()][_0xa7ff('0x37')]();}});}return _0x7fdef9;}function getTicket(_0x30975f,_0x3fe8a6,_0xc7c476,_0x14d155,_0x359932,_0x21e0d9){return function(_0x285519){logger[_0xa7ff('0xf')]('['+[_0x30975f[_0xa7ff('0x13')]()]+_0xa7ff('0x38'),_0x285519);return new Promise(function(_0x576b3e,_0x5afe43){var _0xd49004=_0x30975f[_0xa7ff('0x2f')]()==='outbound'?_0x285519['userId']:_0x285519[_0xa7ff('0x27')];var _0xcf3738={'method':'POST','uri':_0xc7c476+_0xa7ff('0x39')+'?'+_0x21e0d9,'body':Object[_0xa7ff('0x3a')]({},{'active':_0xa7ff('0x1a'),'caller_id':_0xd49004,'assigned_to':_0x285519['userId'],'short_description':intUtil[_0xa7ff('0x3b')](_0x14d155[_0xa7ff('0x3c')],_0x359932,'\x20'),'description':intUtil[_0xa7ff('0x3b')](_0x14d155['Descriptions'],_0x359932,'\x0a')},getCustomFields(_0x14d155[_0xa7ff('0x3d')],_0x359932)),'auth':_0x3fe8a6,'json':!![]};return rp(_0xcf3738)['then'](function(_0x563a25){logger[_0xa7ff('0xf')]('['+[_0x30975f['toUpperCase']()]+_0xa7ff('0x3e'),_0x563a25['result']);_0x285519[_0xa7ff('0x3f')]=_0x563a25['result'][_0xa7ff('0xe')];_0x285519[_0xa7ff('0x40')]=_0x563a25[_0xa7ff('0xd')][_0xa7ff('0x41')];logger[_0xa7ff('0xf')]('['+[_0x30975f['toUpperCase']()]+_0xa7ff('0x42'),_0x285519);_0x576b3e(_0x285519);})[_0xa7ff('0x11')](function(_0x51812b){logger[_0xa7ff('0x12')]('['+[_0x30975f[_0xa7ff('0x13')]()]+']',_0x51812b[_0xa7ff('0x14')]);_0x5afe43(_0x51812b[_0xa7ff('0x14')]);});});};}function createRemoteTag(_0x313637,_0x553649,_0x115cbc,_0x349451){return new Promise(function(_0x4051a2,_0x4767f6){var _0x3e302c={'method':_0xa7ff('0x21'),'uri':_0x115cbc+_0xa7ff('0x43')+'?'+_0x349451,'body':{'short_description':_0x313637,'global':!![],'active':!![],'name':_0x313637},'auth':_0x553649,'json':!![]};return rp(_0x3e302c)[_0xa7ff('0x16')](function(_0x555648){var _0x29bf7e=_0x555648[_0xa7ff('0xd')][_0xa7ff('0xe')];_0x4051a2(_0x29bf7e);});});}function getRemoteTag(_0x296ecc,_0x1cd4bc,_0x14cf54,_0x2f982d,_0x3a463d){return new Promise(function(_0x1a735d,_0x1d9fc3){var _0x2c9e67={'method':_0xa7ff('0xb'),'uri':_0x14cf54+'label'+_0xa7ff('0x44')+_0x296ecc+'&'+_0x2f982d,'auth':_0x1cd4bc,'json':!![]};return rp(_0x2c9e67)[_0xa7ff('0x16')](function(_0x22a8a6){if(_0x22a8a6[_0xa7ff('0xd')]['length']>0x0){var _0x54006c=_0x22a8a6[_0xa7ff('0xd')][0x0]['sys_id'];_0x1a735d(_0x54006c);}else{return createRemoteTag(_0x296ecc,_0x1cd4bc,_0x14cf54,_0x2f982d)[_0xa7ff('0x16')](function(_0x3c444f){_0x1a735d(_0x3c444f);});}});});}function assignTagToIncident(_0x53a08d,_0x134cce,_0x3d9b23,_0x332476,_0x8fde72){return new Promise(function(_0x4d3961,_0x4b9ed0){var _0x277c9d={'method':'POST','uri':_0x3d9b23+'label_entry'+'?'+_0x8fde72,'body':{'label':_0x53a08d,'table':_0xa7ff('0x39'),'id_type':'Incident','table_key':_0x332476['ticketId'],'title':_0xa7ff('0x45')+_0x332476[_0xa7ff('0x40')],'id_display':_0x332476[_0xa7ff('0x40')]},'auth':_0x134cce,'json':!![]};return rp(_0x277c9d)[_0xa7ff('0x16')](function(_0x1695bb){_0x4d3961();})['catch'](function(){_0x4d3961();});});}function manageTags(_0x3c0d11,_0x50a4e1,_0x53fdd3,_0x3edb81,_0xd5e501,_0x5daa60,_0x325e27){return new Promise(function(_0x43ba4f,_0x31f53b){var _0x1acb91=[];_0x50a4e1[_0xa7ff('0x29')](function(_0x5eec8f){_0x1acb91[_0xa7ff('0x46')](getRemoteTag(_0x5eec8f,_0x53fdd3,_0x3edb81,_0x5daa60,_0x325e27));});return Promise[_0xa7ff('0x47')](_0x1acb91)[_0xa7ff('0x16')](function(_0x5e0806){if(_0x5e0806[_0xa7ff('0x18')]){logger[_0xa7ff('0xf')]('['+[_0x3c0d11[_0xa7ff('0x13')]()]+_0xa7ff('0x48'),_0x5e0806);var _0xc02c8a=[];_0x5e0806[_0xa7ff('0x29')](function(_0x382769){_0xc02c8a['push'](assignTagToIncident(_0x382769,_0x53fdd3,_0x3edb81,_0xd5e501,_0x5daa60));});return Promise[_0xa7ff('0x47')](_0xc02c8a)['then'](function(){_0x43ba4f();})[_0xa7ff('0x11')](function(){_0x43ba4f();});}else{_0x43ba4f();}});});}function getTags(_0x45c043,_0x46b5c6,_0x37363f,_0x280acb,_0x5bd800,_0x4bce38){return function(_0x4c10fd){return new Promise(function(_0x3d4284,_0x1ab95e){var _0xf3f4af=[];var _0x31cfde=_0x280acb[_0xa7ff('0x49')];if(_0x31cfde&&_0x31cfde[_0xa7ff('0x18')]>0x0){_0xf3f4af=_[_0xa7ff('0x4a')](_0x31cfde,'name');}if(_0xf3f4af[_0xa7ff('0x18')]>0x0){return manageTags(_0x45c043,_0xf3f4af,_0x46b5c6,_0x37363f,_0x4c10fd,_0x5bd800,_0x4bce38)[_0xa7ff('0x16')](function(){_0x3d4284(_0x4c10fd);});}else{_0x3d4284(_0x4c10fd);}});};}function emit(_0x400426,_0x4e9c2a,_0x6cec29){var _0x43084c=_0xa7ff('0x4b')+_0xa7ff('0x4c')+_0xa7ff('0x4d')+_0xa7ff('0x4e');var _0x50337a={'uri':_0x400426+_0xa7ff('0x4f')+_0x6cec29+_0x43084c};io['to'](util[_0xa7ff('0x50')](_0xa7ff('0x51'),_0x4e9c2a))[_0xa7ff('0x52')](_0xa7ff('0x53'),_0x50337a);}exports['cs']=function(_0x3c10b7,_0x2c7ec1,_0x15c498,_0x53c02b,_0x2d7a0e,_0x35ba9d,_0x5b6b21,_0x6eab1b){var _0x4d8058={};var _0x1fd3c5={'user':_0x35ba9d[_0xa7ff('0x54')],'pass':_0x35ba9d[_0xa7ff('0x55')]};var _0x4e594d=_0xa7ff('0x56');var _0x1c60fa=_0xa7ff('0x57');_0x35ba9d[_0xa7ff('0x58')]=intUtil['stripTrailingSlash'](_0x35ba9d[_0xa7ff('0x58')]);_0x35ba9d[_0xa7ff('0x59')]=intUtil[_0xa7ff('0x5a')](_0x35ba9d['serverUrl']);var _0x17ca75=util['format'](_0xa7ff('0x5b'),_0x35ba9d[_0xa7ff('0x58')]);_0x4d8058['userEmail']=!_['isNil'](_0x53c02b)?_0x53c02b[_0xa7ff('0x5c')]:null;_0x4d8058['adminEmail']=_0x35ba9d['email'];_0x4d8058[_0xa7ff('0x22')]=_0x6eab1b[_0xa7ff('0x2f')]()===_0xa7ff('0x5d')?_0x2c7ec1[_0xa7ff('0x5e')]:_0x2c7ec1[_0xa7ff('0x5f')];_0x4d8058[_0xa7ff('0x60')]=_0x6eab1b===_0xa7ff('0x61')||_0x6eab1b===_0xa7ff('0x62')?'queue':'outbound';var _0x238a84=util[_0xa7ff('0x50')](_0xa7ff('0x63'),_0x35ba9d['serverUrl'],_0x2c7ec1[_0xa7ff('0x64')],md5(_0x2c7ec1[_0xa7ff('0x64')]));if(_0x2d7a0e&&_0x2d7a0e[_0xa7ff('0x65')]){logger[_0xa7ff('0xf')]('[QUEUE]',_0xa7ff('0x66'));_0x2c7ec1[_0xa7ff('0x67')]=_0x238a84;}else if(_0x5b6b21&&_0x5b6b21[_0xa7ff('0x68')]&&_0x5b6b21['recordingFormat']!==_0xa7ff('0x69')){logger[_0xa7ff('0xf')](_0xa7ff('0x6a'),'Recording\x20is\x20enabled!');_0x2c7ec1['recordingURL']=_0x238a84;}else{_0x2c7ec1[_0xa7ff('0x67')]='';}return getAdminUser(_0x6eab1b,_0x1fd3c5,_0x4d8058,_0x17ca75,_0x1c60fa,_0x4e594d)[_0xa7ff('0x16')](getUser(_0x6eab1b,_0x1fd3c5,_0x17ca75,_0x1c60fa,_0x4e594d))[_0xa7ff('0x16')](getEndUser(_0x6eab1b,_0x1fd3c5,_0x17ca75,_0x1c60fa,_0x4e594d))['then'](getTicket(_0x6eab1b,_0x1fd3c5,_0x17ca75,_0x15c498,_0x2c7ec1,_0x1c60fa))[_0xa7ff('0x16')](function(_0x203fee){logger[_0xa7ff('0xf')](util['format'](_0xa7ff('0x6b'),_0x203fee['ticketId']));logger[_0xa7ff('0xf')](util[_0xa7ff('0x50')](_0xa7ff('0x6c'),_0x6eab1b));if(_0x6eab1b!==_0xa7ff('0x62')){logger[_0xa7ff('0xf')]('['+[_0x6eab1b[_0xa7ff('0x13')]()]+']',_0xa7ff('0x6d'));emit(_0x35ba9d[_0xa7ff('0x58')],_0x53c02b[_0xa7ff('0x36')],_0x203fee[_0xa7ff('0x3f')]);}})['catch'](function(_0x59294b){logger[_0xa7ff('0x12')]('['+[_0x6eab1b[_0xa7ff('0x13')]()]+_0xa7ff('0x6e'),util['inspect'](_0x59294b,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xec40=['adminEmail','destcalleridnum','calleridnum','callDirection','queue','unmanaged','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingFormat','none','recordingURL','The\x20ticket\x20ID\x20is:\x20%s','call\x20direction:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','lodash','util','md5','../../../../config/environment','../../../../config/logger','servicenow','redis','defaults','socket.io-emitter','GET','then','result','length','adminId','sys_id','error','toUpperCase','message','],\x20getUser\x20input\x20crm','userEmail','info','],\x20getUser\x20rp\x20obj','active','true','userId','],\x20getUser\x20crm','catch',']\x20using\x20admin\x20profile','POST','sys_user?','endUserNumber','user','System','],\x20EndUser\x20schema','],\x20getEndUser\x20input\x20crm','sys_user?sysparm_query=phone%3D','endUserId','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','includes','picklist','nameField','customField','toLowerCase','content','toString','string','type','idField','variable','variableName','Variable','name',']\x20getTicket\x20input\x20crm','outbound','incident','assign','Subjects','getString','Descriptions','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketNumber','number','label','?sysparm_query=name%3D','label_entry','ticketId','Incident\x20-\x20','push','all',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','Tags','map','%26sysparm_record_list%3Dactive%253Dtrue','%255EORDERBYDESCnumber','/nav_to.do?uri=incident.do?sys_id%3D','user:%s','emit','trigger:browser:url','username','remoteUri','stripTrailingSlash','format','%s/api/now/table/','isNil','email'];(function(_0x77d286,_0x1ddc6d){var _0x5446a5=function(_0x45e2cf){while(--_0x45e2cf){_0x77d286['push'](_0x77d286['shift']());}};_0x5446a5(++_0x1ddc6d);}(_0xec40,0x7a));var _0x0ec4=function(_0x278f93,_0x5d74c6){_0x278f93=_0x278f93-0x0;var _0x47d224=_0xec40[_0x278f93];return _0x47d224;};'use strict';var _=require(_0x0ec4('0x0'));var Promise=require('bluebird');var rp=require('request-promise');var util=require(_0x0ec4('0x1'));var md5=require(_0x0ec4('0x2'));var Redis=require('ioredis');var intUtil=require('./util');var config=require(_0x0ec4('0x3'));var logger=require(_0x0ec4('0x4'))(_0x0ec4('0x5'));config[_0x0ec4('0x6')]=_[_0x0ec4('0x7')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x0ec4('0x8'))(new Redis(config[_0x0ec4('0x6')]));function getAdminUser(_0x5e793f,_0x3755b4,_0x13ffea,_0x2dce5f,_0x106920,_0x39bda4){return new Promise(function(_0x1ea9cf,_0x5f5957){var _0x8a15c9={'method':_0x0ec4('0x9'),'uri':_0x2dce5f+'sys_user?sysparm_query=user_name%3Dadmin'+'&'+_0x106920+'&'+_0x39bda4,'auth':_0x3755b4,'json':!![]};return rp(_0x8a15c9)[_0x0ec4('0xa')](function(_0x2f63ef){if(_0x2f63ef[_0x0ec4('0xb')][_0x0ec4('0xc')]>0x0){_0x13ffea[_0x0ec4('0xd')]=_0x2f63ef[_0x0ec4('0xb')][0x0][_0x0ec4('0xe')];}logger['info']('['+[_0x5e793f['toUpperCase']()]+'],\x20getAdminUser\x20crm',_0x13ffea);_0x1ea9cf(_0x13ffea);})['catch'](function(_0x76cfc1){logger[_0x0ec4('0xf')]('['+[_0x5e793f[_0x0ec4('0x10')]()]+']',_0x76cfc1[_0x0ec4('0x11')]);_0x5f5957(_0x76cfc1[_0x0ec4('0x11')]);});});}function getUser(_0x5a4176,_0x42a9aa,_0x33dfb2,_0x5e73a0,_0x50a2d6){return function(_0x85ff70){logger['info']('['+[_0x5a4176['toUpperCase']()]+_0x0ec4('0x12'),_0x85ff70);return new Promise(function(_0x39edaf,_0x7f4146){if(intUtil['validateEmail'](_0x85ff70[_0x0ec4('0x13')])){var _0x54f8e1={'method':'GET','uri':_0x33dfb2+'sys_user?sysparm_query=email%3D'+_0x85ff70[_0x0ec4('0x13')]+'&'+_0x5e73a0+'&'+_0x50a2d6,'auth':_0x42a9aa,'json':!![]};logger[_0x0ec4('0x14')]('['+[_0x5a4176[_0x0ec4('0x10')]()]+_0x0ec4('0x15'),_0x54f8e1);return rp(_0x54f8e1)['then'](function(_0x6ccc43){logger[_0x0ec4('0x14')]('['+[_0x5a4176[_0x0ec4('0x10')]()]+'],\x20getUser\x20entity',_0x6ccc43);if(_0x6ccc43[_0x0ec4('0xb')][_0x0ec4('0xc')]>0x0&&String(_0x6ccc43[_0x0ec4('0xb')][0x0][_0x0ec4('0x16')])===_0x0ec4('0x17')){_0x85ff70[_0x0ec4('0x18')]=_0x6ccc43[_0x0ec4('0xb')][0x0]['sys_id'];}else{_0x85ff70['userId']=_0x85ff70[_0x0ec4('0xd')];_0x85ff70[_0x0ec4('0x13')]=_0x85ff70['adminEmail'];}logger[_0x0ec4('0x14')]('['+[_0x5a4176[_0x0ec4('0x10')]()]+_0x0ec4('0x19'),_0x85ff70);_0x39edaf(_0x85ff70);})[_0x0ec4('0x1a')](function(_0xc0124d){logger[_0x0ec4('0xf')]('['+[_0x5a4176[_0x0ec4('0x10')]()]+']',_0xc0124d[_0x0ec4('0x11')]);_0x7f4146(_0xc0124d['message']);});}else{logger[_0x0ec4('0x14')]('['+[_0x5a4176[_0x0ec4('0x10')]()]+_0x0ec4('0x1b'));_0x85ff70[_0x0ec4('0x18')]=_0x85ff70['adminId'];_0x85ff70['userEmail']=_0x85ff70['adminEmail'];_0x39edaf(_0x85ff70);}});};}function createEndUser(_0x3b1bd6,_0x530c47,_0x3897cc,_0x427a16,_0x8be4c5){logger[_0x0ec4('0x14')]('['+[_0x3b1bd6[_0x0ec4('0x10')]()]+'],\x20createEndUser\x20input\x20crm',_0x3897cc);return new Promise(function(_0x37ddce,_0x33c203){var _0x44e2c2={'method':_0x0ec4('0x1c'),'uri':_0x427a16+_0x0ec4('0x1d')+_0x8be4c5,'body':{'user_name':_0x3897cc[_0x0ec4('0x1e')],'roles':_0x0ec4('0x1f'),'first_name':_0x3897cc[_0x0ec4('0x1e')],'active':_0x0ec4('0x17'),'date_format':_0x0ec4('0x20'),'phone':_0x3897cc['endUserNumber']},'auth':_0x530c47,'json':!![]};return rp(_0x44e2c2)['then'](function(_0x18907c){logger['info']('['+[_0x3b1bd6[_0x0ec4('0x10')]()]+_0x0ec4('0x21'),_0x18907c[_0x0ec4('0xb')]);_0x3897cc['endUserId']=_0x18907c[_0x0ec4('0xb')][_0x0ec4('0xe')];_0x37ddce(_0x3897cc);})[_0x0ec4('0x1a')](function(_0x445492){logger[_0x0ec4('0xf')]('['+[_0x3b1bd6[_0x0ec4('0x10')]()]+']',_0x445492['message']);_0x33c203(_0x445492[_0x0ec4('0x11')]);});});}function getEndUser(_0x2ccb16,_0x561048,_0x4656a5,_0x1eeb14,_0x2b3cd9){return function(_0x1e3799){logger[_0x0ec4('0x14')]('['+[_0x2ccb16[_0x0ec4('0x10')]()]+_0x0ec4('0x22'),_0x1e3799);return new Promise(function(_0x39c4f9,_0x32e073){var _0x2e66be={'method':_0x0ec4('0x9'),'uri':_0x4656a5+_0x0ec4('0x23')+_0x1e3799[_0x0ec4('0x1e')]+'&'+_0x1eeb14+'&'+_0x2b3cd9,'auth':_0x561048,'json':!![]};return rp(_0x2e66be)['then'](function(_0x1e57f4){if(_0x1e57f4[_0x0ec4('0xb')][_0x0ec4('0xc')]>0x0){_0x1e3799[_0x0ec4('0x24')]=_0x1e57f4[_0x0ec4('0xb')][0x0][_0x0ec4('0xe')];logger[_0x0ec4('0x14')]('['+[_0x2ccb16[_0x0ec4('0x10')]()]+_0x0ec4('0x25'),_0x1e3799);_0x39c4f9(_0x1e3799);}else{return createEndUser(_0x2ccb16,_0x561048,_0x1e3799,_0x4656a5,_0x1eeb14)[_0x0ec4('0xa')](function(_0x780af5){logger[_0x0ec4('0x14')]('['+[_0x2ccb16[_0x0ec4('0x10')]()]+_0x0ec4('0x26'),_0x780af5);_0x39c4f9(_0x780af5);});}})['catch'](function(_0xca9816){logger[_0x0ec4('0xf')]('['+[_0x2ccb16['toUpperCase']()]+']',_0xca9816['message']);_0x32e073(_0xca9816[_0x0ec4('0x11')]);});});};}function getCustomFields(_0x38b38d,_0x2d1745){var _0x2beab2={};if(_0x38b38d[_0x0ec4('0xc')]>0x0){_[_0x0ec4('0x27')](_0x38b38d,function(_0x47abb3){if(_[_0x0ec4('0x28')](['string',_0x0ec4('0x29')],_0x47abb3['type'])&&_0x47abb3[_0x0ec4('0x2a')]&&!_0x47abb3[_0x0ec4('0x2b')]){_0x2beab2[_0x47abb3[_0x0ec4('0x2a')][_0x0ec4('0x2c')]()]=_0x47abb3[_0x0ec4('0x2d')][_0x0ec4('0x2e')]();}else if(_['includes']([_0x0ec4('0x2f'),_0x0ec4('0x29')],_0x47abb3[_0x0ec4('0x30')])&&_0x47abb3[_0x0ec4('0x31')]&&_0x47abb3[_0x0ec4('0x2b')]){_0x2beab2[_0x47abb3[_0x0ec4('0x31')]['toLowerCase']()]=_0x47abb3['content'][_0x0ec4('0x2e')]();}else if(_0x47abb3[_0x0ec4('0x30')]===_0x0ec4('0x32')&&_0x47abb3[_0x0ec4('0x33')]&&_0x47abb3[_0x0ec4('0x31')]&&_0x47abb3['customField']){_0x2beab2[_0x47abb3[_0x0ec4('0x31')][_0x0ec4('0x2c')]()]=_0x2d1745[_0x47abb3[_0x0ec4('0x33')]][_0x0ec4('0x2e')]();}else if(_0x47abb3['type']==='customVariable'&&_0x47abb3[_0x0ec4('0x34')]&&_0x47abb3[_0x0ec4('0x34')][_0x0ec4('0x35')]&&_0x47abb3[_0x0ec4('0x31')]&&_0x47abb3['customField']){_0x2beab2[_0x47abb3[_0x0ec4('0x31')][_0x0ec4('0x2c')]()]=_0x2d1745[_0x47abb3['Variable'][_0x0ec4('0x35')][_0x0ec4('0x2c')]()][_0x0ec4('0x2e')]();}});}return _0x2beab2;}function getTicket(_0x4dcd35,_0x1ab22f,_0x380e7c,_0x5a159d,_0x2472d8,_0x5ee004){return function(_0x399189){logger[_0x0ec4('0x14')]('['+[_0x4dcd35['toUpperCase']()]+_0x0ec4('0x36'),_0x399189);return new Promise(function(_0x2f628c,_0x5d82dc){var _0x7e578e=_0x4dcd35[_0x0ec4('0x2c')]()===_0x0ec4('0x37')?_0x399189[_0x0ec4('0x18')]:_0x399189[_0x0ec4('0x24')];var _0x2efbdb={'method':_0x0ec4('0x1c'),'uri':_0x380e7c+_0x0ec4('0x38')+'?'+_0x5ee004,'body':Object[_0x0ec4('0x39')]({},{'active':_0x0ec4('0x17'),'caller_id':_0x7e578e,'assigned_to':_0x399189[_0x0ec4('0x18')],'short_description':intUtil['getString'](_0x5a159d[_0x0ec4('0x3a')],_0x2472d8,'\x20'),'description':intUtil[_0x0ec4('0x3b')](_0x5a159d[_0x0ec4('0x3c')],_0x2472d8,'\x0a')},getCustomFields(_0x5a159d[_0x0ec4('0x3d')],_0x2472d8)),'auth':_0x1ab22f,'json':!![]};return rp(_0x2efbdb)[_0x0ec4('0xa')](function(_0x247b57){logger[_0x0ec4('0x14')]('['+[_0x4dcd35[_0x0ec4('0x10')]()]+_0x0ec4('0x3e'),_0x247b57[_0x0ec4('0xb')]);_0x399189['ticketId']=_0x247b57['result'][_0x0ec4('0xe')];_0x399189[_0x0ec4('0x3f')]=_0x247b57[_0x0ec4('0xb')][_0x0ec4('0x40')];logger['info']('['+[_0x4dcd35[_0x0ec4('0x10')]()]+']\x20getTicket\x20crm',_0x399189);_0x2f628c(_0x399189);})[_0x0ec4('0x1a')](function(_0x47a4cf){logger[_0x0ec4('0xf')]('['+[_0x4dcd35[_0x0ec4('0x10')]()]+']',_0x47a4cf[_0x0ec4('0x11')]);_0x5d82dc(_0x47a4cf[_0x0ec4('0x11')]);});});};}function createRemoteTag(_0xbc6526,_0x24e4f8,_0x14e807,_0x51aaf4){return new Promise(function(_0x286243,_0x3129d2){var _0x5c7ef4={'method':_0x0ec4('0x1c'),'uri':_0x14e807+'label'+'?'+_0x51aaf4,'body':{'short_description':_0xbc6526,'global':!![],'active':!![],'name':_0xbc6526},'auth':_0x24e4f8,'json':!![]};return rp(_0x5c7ef4)[_0x0ec4('0xa')](function(_0x1ae990){var _0x5b87e2=_0x1ae990[_0x0ec4('0xb')][_0x0ec4('0xe')];_0x286243(_0x5b87e2);});});}function getRemoteTag(_0x19eaf3,_0x2fdcc9,_0x49e4a9,_0x178f1b,_0x2c833c){return new Promise(function(_0x53a21e,_0x105187){var _0xe9e401={'method':'GET','uri':_0x49e4a9+_0x0ec4('0x41')+_0x0ec4('0x42')+_0x19eaf3+'&'+_0x178f1b,'auth':_0x2fdcc9,'json':!![]};return rp(_0xe9e401)[_0x0ec4('0xa')](function(_0x1df864){if(_0x1df864[_0x0ec4('0xb')][_0x0ec4('0xc')]>0x0){var _0x184543=_0x1df864['result'][0x0][_0x0ec4('0xe')];_0x53a21e(_0x184543);}else{return createRemoteTag(_0x19eaf3,_0x2fdcc9,_0x49e4a9,_0x178f1b)[_0x0ec4('0xa')](function(_0x104135){_0x53a21e(_0x104135);});}});});}function assignTagToIncident(_0x58d9ff,_0xbd5583,_0x4dba24,_0x3347b4,_0x13989e){return new Promise(function(_0x2ac281,_0x490ebd){var _0x2834fb={'method':_0x0ec4('0x1c'),'uri':_0x4dba24+_0x0ec4('0x43')+'?'+_0x13989e,'body':{'label':_0x58d9ff,'table':_0x0ec4('0x38'),'id_type':'Incident','table_key':_0x3347b4[_0x0ec4('0x44')],'title':_0x0ec4('0x45')+_0x3347b4[_0x0ec4('0x3f')],'id_display':_0x3347b4['ticketNumber']},'auth':_0xbd5583,'json':!![]};return rp(_0x2834fb)['then'](function(_0x30eeb2){_0x2ac281();})[_0x0ec4('0x1a')](function(){_0x2ac281();});});}function manageTags(_0x597116,_0x4e6836,_0x4e0ad8,_0x5d9080,_0x35aed9,_0x45dafa,_0x334ec0){return new Promise(function(_0x1117e4,_0x46b30e){var _0x3cc210=[];_0x4e6836[_0x0ec4('0x27')](function(_0x5b4cb3){_0x3cc210[_0x0ec4('0x46')](getRemoteTag(_0x5b4cb3,_0x4e0ad8,_0x5d9080,_0x45dafa,_0x334ec0));});return Promise[_0x0ec4('0x47')](_0x3cc210)[_0x0ec4('0xa')](function(_0x1f7881){if(_0x1f7881[_0x0ec4('0xc')]){logger[_0x0ec4('0x14')]('['+[_0x597116[_0x0ec4('0x10')]()]+_0x0ec4('0x48'),_0x1f7881);var _0x3be732=[];_0x1f7881[_0x0ec4('0x27')](function(_0x313c95){_0x3be732['push'](assignTagToIncident(_0x313c95,_0x4e0ad8,_0x5d9080,_0x35aed9,_0x45dafa));});return Promise[_0x0ec4('0x47')](_0x3be732)[_0x0ec4('0xa')](function(){_0x1117e4();})['catch'](function(){_0x1117e4();});}else{_0x1117e4();}});});}function getTags(_0x5f3b68,_0x249b42,_0x7f8b67,_0x148814,_0x5d3f41,_0x5b9cce){return function(_0xfa8687){return new Promise(function(_0x436b13,_0x338561){var _0x8b9b91=[];var _0x4a5b92=_0x148814[_0x0ec4('0x49')];if(_0x4a5b92&&_0x4a5b92[_0x0ec4('0xc')]>0x0){_0x8b9b91=_[_0x0ec4('0x4a')](_0x4a5b92,_0x0ec4('0x35'));}if(_0x8b9b91[_0x0ec4('0xc')]>0x0){return manageTags(_0x5f3b68,_0x8b9b91,_0x249b42,_0x7f8b67,_0xfa8687,_0x5d3f41,_0x5b9cce)['then'](function(){_0x436b13(_0xfa8687);});}else{_0x436b13(_0xfa8687);}});};}function emit(_0x45cd82,_0x148c29,_0x10196b){var _0x2711a0='%26sysparm_record_target%3Dincident'+'%26sysparm_record_row%3D1%26sysparm_record_rows%3D39'+_0x0ec4('0x4b')+_0x0ec4('0x4c');var _0x3571a2={'uri':_0x45cd82+_0x0ec4('0x4d')+_0x10196b+_0x2711a0};io['to'](util['format'](_0x0ec4('0x4e'),_0x148c29))[_0x0ec4('0x4f')](_0x0ec4('0x50'),_0x3571a2);}exports['cs']=function(_0x18d5ff,_0x20ca90,_0x4cd1f9,_0x319b63,_0x2484d7,_0xc89cf8,_0x2618ae,_0x2c70e5){var _0x503dc1={};var _0x4f87ab={'user':_0xc89cf8[_0x0ec4('0x51')],'pass':_0xc89cf8['password']};var _0x18e293='sysparm_limit=1';var _0x5a0823='sysparm_display_value=true';_0xc89cf8[_0x0ec4('0x52')]=intUtil[_0x0ec4('0x53')](_0xc89cf8[_0x0ec4('0x52')]);_0xc89cf8['serverUrl']=intUtil['stripTrailingSlash'](_0xc89cf8['serverUrl']);var _0x4ee30a=util[_0x0ec4('0x54')](_0x0ec4('0x55'),_0xc89cf8[_0x0ec4('0x52')]);_0x503dc1[_0x0ec4('0x13')]=!_[_0x0ec4('0x56')](_0x319b63)?_0x319b63[_0x0ec4('0x57')]:null;_0x503dc1[_0x0ec4('0x58')]=_0xc89cf8['email'];_0x503dc1[_0x0ec4('0x1e')]=_0x2c70e5[_0x0ec4('0x2c')]()===_0x0ec4('0x37')?_0x20ca90[_0x0ec4('0x59')]:_0x20ca90[_0x0ec4('0x5a')];_0x503dc1[_0x0ec4('0x5b')]=_0x2c70e5===_0x0ec4('0x5c')||_0x2c70e5===_0x0ec4('0x5d')?_0x0ec4('0x5c'):_0x0ec4('0x37');var _0x597bf0=util[_0x0ec4('0x54')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0xc89cf8['serverUrl'],_0x20ca90[_0x0ec4('0x5e')],md5(_0x20ca90[_0x0ec4('0x5e')]));if(_0x2484d7&&_0x2484d7[_0x0ec4('0x5f')]){logger['info'](_0x0ec4('0x60'),_0x0ec4('0x61'));_0x20ca90['recordingURL']=_0x597bf0;}else if(_0x2618ae&&_0x2618ae[_0x0ec4('0x62')]&&_0x2618ae[_0x0ec4('0x62')]!==_0x0ec4('0x63')){logger[_0x0ec4('0x14')]('[OUTBOUND]',_0x0ec4('0x61'));_0x20ca90[_0x0ec4('0x64')]=_0x597bf0;}else{_0x20ca90[_0x0ec4('0x64')]='';}return getAdminUser(_0x2c70e5,_0x4f87ab,_0x503dc1,_0x4ee30a,_0x5a0823,_0x18e293)['then'](getUser(_0x2c70e5,_0x4f87ab,_0x4ee30a,_0x5a0823,_0x18e293))[_0x0ec4('0xa')](getEndUser(_0x2c70e5,_0x4f87ab,_0x4ee30a,_0x5a0823,_0x18e293))[_0x0ec4('0xa')](getTicket(_0x2c70e5,_0x4f87ab,_0x4ee30a,_0x4cd1f9,_0x20ca90,_0x5a0823))[_0x0ec4('0xa')](function(_0x32438e){logger[_0x0ec4('0x14')](util['format'](_0x0ec4('0x65'),_0x32438e['ticketId']));logger[_0x0ec4('0x14')](util['format'](_0x0ec4('0x66'),_0x2c70e5));if(_0x2c70e5!==_0x0ec4('0x5d')){logger[_0x0ec4('0x14')]('['+[_0x2c70e5[_0x0ec4('0x10')]()]+']',_0x0ec4('0x67'));emit(_0xc89cf8[_0x0ec4('0x52')],_0x319b63['name'],_0x32438e[_0x0ec4('0x44')]);}})[_0x0ec4('0x1a')](function(_0x3dd537){logger[_0x0ec4('0xf')]('['+[_0x2c70e5['toUpperCase']()]+_0x0ec4('0x68'),util['inspect'](_0x3dd537,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file