Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / services / ami / trigger / integration / servicenow.js
index 8d5e55b..defddb9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa425=['password','sysparm_limit=1','sysparm_display_value=true','remoteUri','stripTrailingSlash','serverUrl','isNil','email','destcalleridnum','calleridnum','callDirection','queue','unmanaged','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','The\x20ticket\x20ID\x20is:\x20%s','call\x20direction:\x20%s',']\x20Error\x20running\x20ServiceNow\x20integration','lodash','bluebird','request-promise','md5','ioredis','./util','../../../../config/environment','servicenow','redis','socket.io-emitter','sys_user?sysparm_query=user_name%3Dadmin','result','length','adminId','sys_id','info','toUpperCase','],\x20getAdminUser\x20crm','catch','error','message','],\x20getUser\x20input\x20crm','validateEmail','userEmail','GET','],\x20getUser\x20rp\x20obj','then','],\x20getUser\x20entity','true','userId','adminEmail',']\x20using\x20admin\x20profile','],\x20createEndUser\x20input\x20crm','POST','sys_user?','endUserNumber','System','],\x20EndUser\x20schema','endUserId','sys_user?sysparm_query=phone%3D','],\x20getEndUser\x20crm','],\x20createEndUser\x20crm','forEach','includes','string','picklist','type','nameField','customField','toString','toLowerCase','content','variable','variableName','idField','customVariable','Variable','name',']\x20getTicket\x20input\x20crm','outbound','incident','assign','getString','Subjects','Descriptions','Fields',']\x20POST\x20incident\x20entity\x20schema','ticketId','ticketNumber','number','label','?sysparm_query=name%3D','Incident','Incident\x20-\x20','push','all',']\x20arrayPromises:\x20IDs\x20in\x20table\x20label','Tags','map','%26sysparm_record_target%3Dincident','%26sysparm_record_row%3D1%26sysparm_record_rows%3D39','%255EORDERBYDESCnumber','/nav_to.do?uri=incident.do?sys_id%3D','format','user:%s','emit','username'];(function(_0x253b44,_0x4258bb){var _0x548c50=function(_0x13155a){while(--_0x13155a){_0x253b44['push'](_0x253b44['shift']());}};_0x548c50(++_0x4258bb);}(_0xa425,0x161));var _0x5a42=function(_0x34021d,_0x753aa6){_0x34021d=_0x34021d-0x0;var _0x16597b=_0xa425[_0x34021d];return _0x16597b;};'use strict';var _=require(_0x5a42('0x0'));var Promise=require(_0x5a42('0x1'));var rp=require(_0x5a42('0x2'));var util=require('util');var md5=require(_0x5a42('0x3'));var Redis=require(_0x5a42('0x4'));var intUtil=require(_0x5a42('0x5'));var config=require(_0x5a42('0x6'));var logger=require('../../../../config/logger')(_0x5a42('0x7'));config[_0x5a42('0x8')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x5a42('0x9'))(new Redis(config[_0x5a42('0x8')]));function getAdminUser(_0x2b9c4f,_0x4f3b82,_0x267f8b,_0x583302,_0x1c50d7,_0x28b81a){return new Promise(function(_0x523eba,_0x599989){var _0x45ad08={'method':'GET','uri':_0x583302+_0x5a42('0xa')+'&'+_0x1c50d7+'&'+_0x28b81a,'auth':_0x4f3b82,'json':!![]};return rp(_0x45ad08)['then'](function(_0x6ae437){if(_0x6ae437[_0x5a42('0xb')][_0x5a42('0xc')]>0x0){_0x267f8b[_0x5a42('0xd')]=_0x6ae437['result'][0x0][_0x5a42('0xe')];}logger[_0x5a42('0xf')]('['+[_0x2b9c4f[_0x5a42('0x10')]()]+_0x5a42('0x11'),_0x267f8b);_0x523eba(_0x267f8b);})[_0x5a42('0x12')](function(_0x1c8375){logger[_0x5a42('0x13')]('['+[_0x2b9c4f['toUpperCase']()]+']',_0x1c8375[_0x5a42('0x14')]);_0x599989(_0x1c8375[_0x5a42('0x14')]);});});}function getUser(_0x2f3c9a,_0x183f0c,_0x2c60d0,_0x169251,_0x36f536){return function(_0x36d947){logger['info']('['+[_0x2f3c9a[_0x5a42('0x10')]()]+_0x5a42('0x15'),_0x36d947);return new Promise(function(_0xd81c19,_0x40d9c6){if(intUtil[_0x5a42('0x16')](_0x36d947[_0x5a42('0x17')])){var _0x6d1997={'method':_0x5a42('0x18'),'uri':_0x2c60d0+'sys_user?sysparm_query=email%3D'+_0x36d947[_0x5a42('0x17')]+'&'+_0x169251+'&'+_0x36f536,'auth':_0x183f0c,'json':!![]};logger[_0x5a42('0xf')]('['+[_0x2f3c9a[_0x5a42('0x10')]()]+_0x5a42('0x19'),_0x6d1997);return rp(_0x6d1997)[_0x5a42('0x1a')](function(_0x4d68e7){logger['info']('['+[_0x2f3c9a['toUpperCase']()]+_0x5a42('0x1b'),_0x4d68e7);if(_0x4d68e7['result']['length']>0x0&&String(_0x4d68e7['result'][0x0]['active'])===_0x5a42('0x1c')){_0x36d947[_0x5a42('0x1d')]=_0x4d68e7[_0x5a42('0xb')][0x0][_0x5a42('0xe')];}else{_0x36d947[_0x5a42('0x1d')]=_0x36d947[_0x5a42('0xd')];_0x36d947[_0x5a42('0x17')]=_0x36d947[_0x5a42('0x1e')];}logger[_0x5a42('0xf')]('['+[_0x2f3c9a[_0x5a42('0x10')]()]+'],\x20getUser\x20crm',_0x36d947);_0xd81c19(_0x36d947);})[_0x5a42('0x12')](function(_0x554c97){logger['error']('['+[_0x2f3c9a[_0x5a42('0x10')]()]+']',_0x554c97['message']);_0x40d9c6(_0x554c97[_0x5a42('0x14')]);});}else{logger[_0x5a42('0xf')]('['+[_0x2f3c9a['toUpperCase']()]+_0x5a42('0x1f'));_0x36d947[_0x5a42('0x1d')]=_0x36d947['adminId'];_0x36d947[_0x5a42('0x17')]=_0x36d947[_0x5a42('0x1e')];_0xd81c19(_0x36d947);}});};}function createEndUser(_0x3405a5,_0x11f338,_0x233cbf,_0x2207c7,_0x2f9756){logger[_0x5a42('0xf')]('['+[_0x3405a5[_0x5a42('0x10')]()]+_0x5a42('0x20'),_0x233cbf);return new Promise(function(_0x26a467,_0x5c6e3c){var _0x46dd7a={'method':_0x5a42('0x21'),'uri':_0x2207c7+_0x5a42('0x22')+_0x2f9756,'body':{'user_name':_0x233cbf[_0x5a42('0x23')],'roles':'user','first_name':_0x233cbf[_0x5a42('0x23')],'active':_0x5a42('0x1c'),'date_format':_0x5a42('0x24'),'phone':_0x233cbf[_0x5a42('0x23')]},'auth':_0x11f338,'json':!![]};return rp(_0x46dd7a)[_0x5a42('0x1a')](function(_0x52b050){logger[_0x5a42('0xf')]('['+[_0x3405a5[_0x5a42('0x10')]()]+_0x5a42('0x25'),_0x52b050[_0x5a42('0xb')]);_0x233cbf[_0x5a42('0x26')]=_0x52b050[_0x5a42('0xb')][_0x5a42('0xe')];_0x26a467(_0x233cbf);})[_0x5a42('0x12')](function(_0x3ce7c2){logger[_0x5a42('0x13')]('['+[_0x3405a5[_0x5a42('0x10')]()]+']',_0x3ce7c2[_0x5a42('0x14')]);_0x5c6e3c(_0x3ce7c2['message']);});});}function getEndUser(_0x2a3cc8,_0x738bf9,_0x237d43,_0x3aae82,_0x245063){return function(_0x13a7fe){logger[_0x5a42('0xf')]('['+[_0x2a3cc8[_0x5a42('0x10')]()]+'],\x20getEndUser\x20input\x20crm',_0x13a7fe);return new Promise(function(_0x2f3033,_0x3520d0){var _0xbc9459={'method':_0x5a42('0x18'),'uri':_0x237d43+_0x5a42('0x27')+_0x13a7fe['endUserNumber']+'&'+_0x3aae82+'&'+_0x245063,'auth':_0x738bf9,'json':!![]};return rp(_0xbc9459)[_0x5a42('0x1a')](function(_0x1f3ad1){if(_0x1f3ad1[_0x5a42('0xb')]['length']>0x0){_0x13a7fe[_0x5a42('0x26')]=_0x1f3ad1[_0x5a42('0xb')][0x0][_0x5a42('0xe')];logger[_0x5a42('0xf')]('['+[_0x2a3cc8['toUpperCase']()]+_0x5a42('0x28'),_0x13a7fe);_0x2f3033(_0x13a7fe);}else{return createEndUser(_0x2a3cc8,_0x738bf9,_0x13a7fe,_0x237d43,_0x3aae82)[_0x5a42('0x1a')](function(_0x59ec4e){logger[_0x5a42('0xf')]('['+[_0x2a3cc8['toUpperCase']()]+_0x5a42('0x29'),_0x59ec4e);_0x2f3033(_0x59ec4e);});}})[_0x5a42('0x12')](function(_0x59cf1b){logger[_0x5a42('0x13')]('['+[_0x2a3cc8['toUpperCase']()]+']',_0x59cf1b[_0x5a42('0x14')]);_0x3520d0(_0x59cf1b['message']);});});};}function getCustomFields(_0x554a58,_0x1bbbaf){var _0x55922b={};if(_0x554a58[_0x5a42('0xc')]>0x0){_[_0x5a42('0x2a')](_0x554a58,function(_0x56b090){if(_[_0x5a42('0x2b')]([_0x5a42('0x2c'),_0x5a42('0x2d')],_0x56b090[_0x5a42('0x2e')])&&_0x56b090[_0x5a42('0x2f')]&&!_0x56b090[_0x5a42('0x30')]){_0x55922b[_0x56b090[_0x5a42('0x2f')]['toLowerCase']()]=_0x56b090['content'][_0x5a42('0x31')]();}else if(_[_0x5a42('0x2b')]([_0x5a42('0x2c'),_0x5a42('0x2d')],_0x56b090[_0x5a42('0x2e')])&&_0x56b090['idField']&&_0x56b090['customField']){_0x55922b[_0x56b090['idField'][_0x5a42('0x32')]()]=_0x56b090[_0x5a42('0x33')][_0x5a42('0x31')]();}else if(_0x56b090[_0x5a42('0x2e')]===_0x5a42('0x34')&&_0x56b090[_0x5a42('0x35')]&&_0x56b090[_0x5a42('0x36')]&&_0x56b090['customField']){_0x55922b[_0x56b090[_0x5a42('0x36')][_0x5a42('0x32')]()]=_0x1bbbaf[_0x56b090[_0x5a42('0x35')]][_0x5a42('0x31')]();}else if(_0x56b090[_0x5a42('0x2e')]===_0x5a42('0x37')&&_0x56b090[_0x5a42('0x38')]&&_0x56b090['Variable'][_0x5a42('0x39')]&&_0x56b090[_0x5a42('0x36')]&&_0x56b090[_0x5a42('0x30')]){_0x55922b[_0x56b090[_0x5a42('0x36')][_0x5a42('0x32')]()]=_0x1bbbaf[_0x56b090[_0x5a42('0x38')][_0x5a42('0x39')]['toLowerCase']()]['toString']();}});}return _0x55922b;}function getTicket(_0x24d74c,_0x1a5472,_0x3c48c9,_0x3a640e,_0x40d205,_0x393777){return function(_0xefd999){logger['info']('['+[_0x24d74c['toUpperCase']()]+_0x5a42('0x3a'),_0xefd999);return new Promise(function(_0x500e75,_0x591e24){var _0x8abcc3=_0x24d74c['toLowerCase']()===_0x5a42('0x3b')?_0xefd999[_0x5a42('0x1d')]:_0xefd999['endUserId'];var _0x6411d1={'method':'POST','uri':_0x3c48c9+_0x5a42('0x3c')+'?'+_0x393777,'body':Object[_0x5a42('0x3d')]({},{'active':'true','caller_id':_0x8abcc3,'assigned_to':_0xefd999[_0x5a42('0x1d')],'short_description':intUtil[_0x5a42('0x3e')](_0x3a640e[_0x5a42('0x3f')],_0x40d205,'\x20'),'description':intUtil[_0x5a42('0x3e')](_0x3a640e[_0x5a42('0x40')],_0x40d205,'\x0a')},getCustomFields(_0x3a640e[_0x5a42('0x41')],_0x40d205)),'auth':_0x1a5472,'json':!![]};return rp(_0x6411d1)[_0x5a42('0x1a')](function(_0x33eabf){logger[_0x5a42('0xf')]('['+[_0x24d74c['toUpperCase']()]+_0x5a42('0x42'),_0x33eabf[_0x5a42('0xb')]);_0xefd999[_0x5a42('0x43')]=_0x33eabf[_0x5a42('0xb')][_0x5a42('0xe')];_0xefd999[_0x5a42('0x44')]=_0x33eabf[_0x5a42('0xb')][_0x5a42('0x45')];logger[_0x5a42('0xf')]('['+[_0x24d74c[_0x5a42('0x10')]()]+']\x20getTicket\x20crm',_0xefd999);_0x500e75(_0xefd999);})[_0x5a42('0x12')](function(_0x26f2ed){logger[_0x5a42('0x13')]('['+[_0x24d74c[_0x5a42('0x10')]()]+']',_0x26f2ed[_0x5a42('0x14')]);_0x591e24(_0x26f2ed['message']);});});};}function createRemoteTag(_0x369ac9,_0x522fee,_0x347bed,_0x4ef5d9){return new Promise(function(_0x58c490,_0x23c777){var _0x515f2f={'method':_0x5a42('0x21'),'uri':_0x347bed+'label'+'?'+_0x4ef5d9,'body':{'short_description':_0x369ac9,'global':!![],'active':!![],'name':_0x369ac9},'auth':_0x522fee,'json':!![]};return rp(_0x515f2f)['then'](function(_0x4e0099){var _0x1cb2d1=_0x4e0099[_0x5a42('0xb')]['sys_id'];_0x58c490(_0x1cb2d1);});});}function getRemoteTag(_0x4f703f,_0x20a42f,_0x132161,_0x26d1b3,_0x2ce00b){return new Promise(function(_0x477527,_0xc13d62){var _0x590bcd={'method':_0x5a42('0x18'),'uri':_0x132161+_0x5a42('0x46')+_0x5a42('0x47')+_0x4f703f+'&'+_0x26d1b3,'auth':_0x20a42f,'json':!![]};return rp(_0x590bcd)[_0x5a42('0x1a')](function(_0x33e22c){if(_0x33e22c[_0x5a42('0xb')]['length']>0x0){var _0xc02866=_0x33e22c[_0x5a42('0xb')][0x0][_0x5a42('0xe')];_0x477527(_0xc02866);}else{return createRemoteTag(_0x4f703f,_0x20a42f,_0x132161,_0x26d1b3)['then'](function(_0x555a0c){_0x477527(_0x555a0c);});}});});}function assignTagToIncident(_0x298cd3,_0xda173,_0x5b8efe,_0x523c63,_0x38073c){return new Promise(function(_0x13bb5a,_0x1b67d5){var _0x57cf02={'method':_0x5a42('0x21'),'uri':_0x5b8efe+'label_entry'+'?'+_0x38073c,'body':{'label':_0x298cd3,'table':_0x5a42('0x3c'),'id_type':_0x5a42('0x48'),'table_key':_0x523c63[_0x5a42('0x43')],'title':_0x5a42('0x49')+_0x523c63[_0x5a42('0x44')],'id_display':_0x523c63['ticketNumber']},'auth':_0xda173,'json':!![]};return rp(_0x57cf02)['then'](function(_0x13b838){_0x13bb5a();})[_0x5a42('0x12')](function(){_0x13bb5a();});});}function manageTags(_0x2ea868,_0x7bb11f,_0x14e52d,_0x3fb98f,_0xd563c1,_0x201e10,_0x27bf39){return new Promise(function(_0x4866c9,_0x451cc7){var _0x1d272f=[];_0x7bb11f[_0x5a42('0x2a')](function(_0x21dc7c){_0x1d272f[_0x5a42('0x4a')](getRemoteTag(_0x21dc7c,_0x14e52d,_0x3fb98f,_0x201e10,_0x27bf39));});return Promise[_0x5a42('0x4b')](_0x1d272f)[_0x5a42('0x1a')](function(_0xda3765){if(_0xda3765['length']){logger[_0x5a42('0xf')]('['+[_0x2ea868['toUpperCase']()]+_0x5a42('0x4c'),_0xda3765);var _0x1022a0=[];_0xda3765[_0x5a42('0x2a')](function(_0x54841d){_0x1022a0[_0x5a42('0x4a')](assignTagToIncident(_0x54841d,_0x14e52d,_0x3fb98f,_0xd563c1,_0x201e10));});return Promise[_0x5a42('0x4b')](_0x1022a0)['then'](function(){_0x4866c9();})[_0x5a42('0x12')](function(){_0x4866c9();});}else{_0x4866c9();}});});}function getTags(_0x26975c,_0xeeb43,_0x4d62a5,_0x2a97ff,_0x48d8a8,_0x28f24c){return function(_0xc21ee5){return new Promise(function(_0x4234da,_0x43e175){var _0x40b51d=[];var _0x1b33a8=_0x2a97ff[_0x5a42('0x4d')];if(_0x1b33a8&&_0x1b33a8[_0x5a42('0xc')]>0x0){_0x40b51d=_[_0x5a42('0x4e')](_0x1b33a8,'name');}if(_0x40b51d[_0x5a42('0xc')]>0x0){return manageTags(_0x26975c,_0x40b51d,_0xeeb43,_0x4d62a5,_0xc21ee5,_0x48d8a8,_0x28f24c)[_0x5a42('0x1a')](function(){_0x4234da(_0xc21ee5);});}else{_0x4234da(_0xc21ee5);}});};}function emit(_0x6e5536,_0x11c583,_0x29be47){var _0x4b7d9f=_0x5a42('0x4f')+_0x5a42('0x50')+'%26sysparm_record_list%3Dactive%253Dtrue'+_0x5a42('0x51');var _0x1f11df={'uri':_0x6e5536+_0x5a42('0x52')+_0x29be47+_0x4b7d9f};io['to'](util[_0x5a42('0x53')](_0x5a42('0x54'),_0x11c583))[_0x5a42('0x55')]('trigger:browser:url',_0x1f11df);}exports['cs']=function(_0x12b9b5,_0x5effb0,_0x38544a,_0x8a048b,_0x421cd9,_0x146dc4,_0x1b4d9c,_0x50049f){var _0x179ed4={};var _0x2c79b2={'user':_0x146dc4[_0x5a42('0x56')],'pass':_0x146dc4[_0x5a42('0x57')]};var _0x4a89e5=_0x5a42('0x58');var _0x173e65=_0x5a42('0x59');_0x146dc4[_0x5a42('0x5a')]=intUtil['stripTrailingSlash'](_0x146dc4[_0x5a42('0x5a')]);_0x146dc4['serverUrl']=intUtil[_0x5a42('0x5b')](_0x146dc4[_0x5a42('0x5c')]);var _0x2665ed=util[_0x5a42('0x53')]('%s/api/now/table/',_0x146dc4[_0x5a42('0x5a')]);_0x179ed4[_0x5a42('0x17')]=!_[_0x5a42('0x5d')](_0x8a048b)?_0x8a048b['email']:null;_0x179ed4[_0x5a42('0x1e')]=_0x146dc4[_0x5a42('0x5e')];_0x179ed4[_0x5a42('0x23')]=_0x50049f[_0x5a42('0x32')]()===_0x5a42('0x3b')?_0x5effb0[_0x5a42('0x5f')]:_0x5effb0[_0x5a42('0x60')];_0x179ed4[_0x5a42('0x61')]=_0x50049f===_0x5a42('0x62')||_0x50049f===_0x5a42('0x63')?'queue':_0x5a42('0x3b');var _0x48c1b9=util[_0x5a42('0x53')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x146dc4[_0x5a42('0x5c')],_0x5effb0[_0x5a42('0x64')],md5(_0x5effb0[_0x5a42('0x64')]));if(_0x421cd9&&_0x421cd9[_0x5a42('0x65')]){logger[_0x5a42('0xf')](_0x5a42('0x66'),_0x5a42('0x67'));_0x5effb0[_0x5a42('0x68')]=_0x48c1b9;}else if(_0x1b4d9c&&_0x1b4d9c[_0x5a42('0x69')]&&_0x1b4d9c['recordingFormat']!==_0x5a42('0x6a')){logger['info']('[OUTBOUND]',_0x5a42('0x67'));_0x5effb0[_0x5a42('0x68')]=_0x48c1b9;}else{_0x5effb0[_0x5a42('0x68')]='';}return getAdminUser(_0x50049f,_0x2c79b2,_0x179ed4,_0x2665ed,_0x173e65,_0x4a89e5)[_0x5a42('0x1a')](getUser(_0x50049f,_0x2c79b2,_0x2665ed,_0x173e65,_0x4a89e5))[_0x5a42('0x1a')](getEndUser(_0x50049f,_0x2c79b2,_0x2665ed,_0x173e65,_0x4a89e5))['then'](getTicket(_0x50049f,_0x2c79b2,_0x2665ed,_0x38544a,_0x5effb0,_0x173e65))[_0x5a42('0x1a')](function(_0x329162){logger[_0x5a42('0xf')](util[_0x5a42('0x53')](_0x5a42('0x6b'),_0x329162[_0x5a42('0x43')]));logger[_0x5a42('0xf')](util[_0x5a42('0x53')](_0x5a42('0x6c'),_0x50049f));if(_0x50049f!=='unmanaged'){logger['info']('['+[_0x50049f[_0x5a42('0x10')]()]+']','Displaying\x20call\x20in\x20a\x20new\x20tab...');emit(_0x146dc4[_0x5a42('0x5a')],_0x8a048b['name'],_0x329162[_0x5a42('0x43')]);}})[_0x5a42('0x12')](function(_0x58b77e){logger[_0x5a42('0x13')]('['+[_0x50049f['toUpperCase']()]+_0x5a42('0x6d'),util['inspect'](_0x58b77e,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xb0f1=['stripTrailingSlash','serverUrl','%s/api/now/table/','outbound','destcalleridnum','callDirection','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','[OUTBOUND]','The\x20ticket\x20ID\x20is:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20ServiceNow\x20integration','inspect','bluebird','request-promise','ioredis','./util','../../../../config/environment','../../../../config/logger','servicenow','redis','localhost','GET','sys_user?sysparm_query=user_name%3Dadmin','then','result','adminId','sys_id','info','toUpperCase','catch','error','message','],\x20getUser\x20input\x20crm','sys_user?sysparm_query=email%3D','userEmail','],\x20getUser\x20rp\x20obj','length','true','userId','adminEmail','],\x20getUser\x20crm',']\x20using\x20admin\x20profile','sys_user?','endUserNumber','user','System','],\x20EndUser\x20schema','],\x20getEndUser\x20input\x20crm','sys_user?sysparm_query=phone%3D','],\x20getEndUser\x20crm','forEach','picklist','type','customField','nameField','toString','includes','idField','toLowerCase','content','Variable','name',']\x20getTicket\x20input\x20crm','endUserId','POST','incident','assign','Subjects','getString','Descriptions','Fields','ticketNumber',']\x20getTicket\x20crm','label','?sysparm_query=name%3D','label_entry','Incident','ticketId','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','/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'];(function(_0x84eba4,_0x150755){var _0x5258bb=function(_0x2e8dad){while(--_0x2e8dad){_0x84eba4['push'](_0x84eba4['shift']());}};_0x5258bb(++_0x150755);}(_0xb0f1,0x14b));var _0x1b0f=function(_0x2cfb58,_0x3d9412){_0x2cfb58=_0x2cfb58-0x0;var _0xd99951=_0xb0f1[_0x2cfb58];return _0xd99951;};'use strict';var _=require('lodash');var Promise=require(_0x1b0f('0x0'));var rp=require(_0x1b0f('0x1'));var util=require('util');var md5=require('md5');var Redis=require(_0x1b0f('0x2'));var intUtil=require(_0x1b0f('0x3'));var config=require(_0x1b0f('0x4'));var logger=require(_0x1b0f('0x5'))(_0x1b0f('0x6'));config[_0x1b0f('0x7')]=_['defaults'](config['redis'],{'host':_0x1b0f('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x1b0f('0x7')]));function getAdminUser(_0xe3a70a,_0x1705db,_0x3e31db,_0x4caa75,_0x30617c,_0x14fbaa){return new Promise(function(_0x4642b0,_0x149d35){var _0xe109e4={'method':_0x1b0f('0x9'),'uri':_0x4caa75+_0x1b0f('0xa')+'&'+_0x30617c+'&'+_0x14fbaa,'auth':_0x1705db,'json':!![]};return rp(_0xe109e4)[_0x1b0f('0xb')](function(_0x29f365){if(_0x29f365[_0x1b0f('0xc')]['length']>0x0){_0x3e31db[_0x1b0f('0xd')]=_0x29f365[_0x1b0f('0xc')][0x0][_0x1b0f('0xe')];}logger[_0x1b0f('0xf')]('['+[_0xe3a70a[_0x1b0f('0x10')]()]+'],\x20getAdminUser\x20crm',_0x3e31db);_0x4642b0(_0x3e31db);})[_0x1b0f('0x11')](function(_0x264732){logger[_0x1b0f('0x12')]('['+[_0xe3a70a[_0x1b0f('0x10')]()]+']',_0x264732[_0x1b0f('0x13')]);_0x149d35(_0x264732['message']);});});}function getUser(_0x1afce4,_0x190ed2,_0x4d1db3,_0x164c86,_0x8e9d0a){return function(_0x208061){logger['info']('['+[_0x1afce4['toUpperCase']()]+_0x1b0f('0x14'),_0x208061);return new Promise(function(_0x37106c,_0x350e9e){if(intUtil['validateEmail'](_0x208061['userEmail'])){var _0x3c52eb={'method':_0x1b0f('0x9'),'uri':_0x4d1db3+_0x1b0f('0x15')+_0x208061[_0x1b0f('0x16')]+'&'+_0x164c86+'&'+_0x8e9d0a,'auth':_0x190ed2,'json':!![]};logger[_0x1b0f('0xf')]('['+[_0x1afce4[_0x1b0f('0x10')]()]+_0x1b0f('0x17'),_0x3c52eb);return rp(_0x3c52eb)[_0x1b0f('0xb')](function(_0x49ecf1){logger[_0x1b0f('0xf')]('['+[_0x1afce4[_0x1b0f('0x10')]()]+'],\x20getUser\x20entity',_0x49ecf1);if(_0x49ecf1[_0x1b0f('0xc')][_0x1b0f('0x18')]>0x0&&String(_0x49ecf1[_0x1b0f('0xc')][0x0]['active'])===_0x1b0f('0x19')){_0x208061[_0x1b0f('0x1a')]=_0x49ecf1[_0x1b0f('0xc')][0x0]['sys_id'];}else{_0x208061['userId']=_0x208061[_0x1b0f('0xd')];_0x208061['userEmail']=_0x208061[_0x1b0f('0x1b')];}logger['info']('['+[_0x1afce4[_0x1b0f('0x10')]()]+_0x1b0f('0x1c'),_0x208061);_0x37106c(_0x208061);})[_0x1b0f('0x11')](function(_0x5cf242){logger[_0x1b0f('0x12')]('['+[_0x1afce4[_0x1b0f('0x10')]()]+']',_0x5cf242[_0x1b0f('0x13')]);_0x350e9e(_0x5cf242[_0x1b0f('0x13')]);});}else{logger[_0x1b0f('0xf')]('['+[_0x1afce4[_0x1b0f('0x10')]()]+_0x1b0f('0x1d'));_0x208061[_0x1b0f('0x1a')]=_0x208061[_0x1b0f('0xd')];_0x208061[_0x1b0f('0x16')]=_0x208061[_0x1b0f('0x1b')];_0x37106c(_0x208061);}});};}function createEndUser(_0x228d66,_0x29d4d6,_0x4578f1,_0x10debd,_0x9b6983){logger[_0x1b0f('0xf')]('['+[_0x228d66[_0x1b0f('0x10')]()]+'],\x20createEndUser\x20input\x20crm',_0x4578f1);return new Promise(function(_0x504229,_0x1b012f){var _0x50e3c7={'method':'POST','uri':_0x10debd+_0x1b0f('0x1e')+_0x9b6983,'body':{'user_name':_0x4578f1[_0x1b0f('0x1f')],'roles':_0x1b0f('0x20'),'first_name':_0x4578f1[_0x1b0f('0x1f')],'active':_0x1b0f('0x19'),'date_format':_0x1b0f('0x21'),'phone':_0x4578f1[_0x1b0f('0x1f')]},'auth':_0x29d4d6,'json':!![]};return rp(_0x50e3c7)[_0x1b0f('0xb')](function(_0x474598){logger[_0x1b0f('0xf')]('['+[_0x228d66[_0x1b0f('0x10')]()]+_0x1b0f('0x22'),_0x474598[_0x1b0f('0xc')]);_0x4578f1['endUserId']=_0x474598[_0x1b0f('0xc')][_0x1b0f('0xe')];_0x504229(_0x4578f1);})['catch'](function(_0x481ba4){logger[_0x1b0f('0x12')]('['+[_0x228d66[_0x1b0f('0x10')]()]+']',_0x481ba4[_0x1b0f('0x13')]);_0x1b012f(_0x481ba4['message']);});});}function getEndUser(_0xe2b223,_0x4fb3d0,_0x4dc693,_0x22da16,_0x32ddc6){return function(_0xb0989f){logger['info']('['+[_0xe2b223[_0x1b0f('0x10')]()]+_0x1b0f('0x23'),_0xb0989f);return new Promise(function(_0x7cf5bb,_0xd07e0a){var _0x4c6edd={'method':_0x1b0f('0x9'),'uri':_0x4dc693+_0x1b0f('0x24')+_0xb0989f['endUserNumber']+'&'+_0x22da16+'&'+_0x32ddc6,'auth':_0x4fb3d0,'json':!![]};return rp(_0x4c6edd)[_0x1b0f('0xb')](function(_0x3c069d){if(_0x3c069d[_0x1b0f('0xc')]['length']>0x0){_0xb0989f['endUserId']=_0x3c069d[_0x1b0f('0xc')][0x0]['sys_id'];logger[_0x1b0f('0xf')]('['+[_0xe2b223['toUpperCase']()]+_0x1b0f('0x25'),_0xb0989f);_0x7cf5bb(_0xb0989f);}else{return createEndUser(_0xe2b223,_0x4fb3d0,_0xb0989f,_0x4dc693,_0x22da16)['then'](function(_0x58638c){logger[_0x1b0f('0xf')]('['+[_0xe2b223[_0x1b0f('0x10')]()]+'],\x20createEndUser\x20crm',_0x58638c);_0x7cf5bb(_0x58638c);});}})[_0x1b0f('0x11')](function(_0x90795){logger[_0x1b0f('0x12')]('['+[_0xe2b223['toUpperCase']()]+']',_0x90795[_0x1b0f('0x13')]);_0xd07e0a(_0x90795[_0x1b0f('0x13')]);});});};}function getCustomFields(_0x4091da,_0x12919e){var _0x21ea21={};if(_0x4091da['length']>0x0){_[_0x1b0f('0x26')](_0x4091da,function(_0x4ca378){if(_['includes'](['string',_0x1b0f('0x27')],_0x4ca378[_0x1b0f('0x28')])&&_0x4ca378['nameField']&&!_0x4ca378[_0x1b0f('0x29')]){_0x21ea21[_0x4ca378[_0x1b0f('0x2a')]['toLowerCase']()]=_0x4ca378['content'][_0x1b0f('0x2b')]();}else if(_[_0x1b0f('0x2c')](['string',_0x1b0f('0x27')],_0x4ca378[_0x1b0f('0x28')])&&_0x4ca378[_0x1b0f('0x2d')]&&_0x4ca378[_0x1b0f('0x29')]){_0x21ea21[_0x4ca378[_0x1b0f('0x2d')][_0x1b0f('0x2e')]()]=_0x4ca378[_0x1b0f('0x2f')][_0x1b0f('0x2b')]();}else if(_0x4ca378['type']==='variable'&&_0x4ca378['variableName']&&_0x4ca378[_0x1b0f('0x2d')]&&_0x4ca378['customField']){_0x21ea21[_0x4ca378[_0x1b0f('0x2d')]['toLowerCase']()]=_0x12919e[_0x4ca378['variableName']][_0x1b0f('0x2b')]();}else if(_0x4ca378[_0x1b0f('0x28')]==='customVariable'&&_0x4ca378['Variable']&&_0x4ca378[_0x1b0f('0x30')][_0x1b0f('0x31')]&&_0x4ca378[_0x1b0f('0x2d')]&&_0x4ca378[_0x1b0f('0x29')]){_0x21ea21[_0x4ca378[_0x1b0f('0x2d')][_0x1b0f('0x2e')]()]=_0x12919e[_0x4ca378[_0x1b0f('0x30')][_0x1b0f('0x31')][_0x1b0f('0x2e')]()][_0x1b0f('0x2b')]();}});}return _0x21ea21;}function getTicket(_0x143d97,_0xf9bc23,_0x4c806b,_0x2fc7ef,_0x2ae859,_0x5421f4){return function(_0x3dc7d5){logger[_0x1b0f('0xf')]('['+[_0x143d97[_0x1b0f('0x10')]()]+_0x1b0f('0x32'),_0x3dc7d5);return new Promise(function(_0x4050e4,_0x471e8a){var _0x1f93f7=_0x143d97[_0x1b0f('0x2e')]()==='outbound'?_0x3dc7d5[_0x1b0f('0x1a')]:_0x3dc7d5[_0x1b0f('0x33')];var _0x17ec83={'method':_0x1b0f('0x34'),'uri':_0x4c806b+_0x1b0f('0x35')+'?'+_0x5421f4,'body':Object[_0x1b0f('0x36')]({},{'active':_0x1b0f('0x19'),'caller_id':_0x1f93f7,'assigned_to':_0x3dc7d5[_0x1b0f('0x1a')],'short_description':intUtil['getString'](_0x2fc7ef[_0x1b0f('0x37')],_0x2ae859,'\x20'),'description':intUtil[_0x1b0f('0x38')](_0x2fc7ef[_0x1b0f('0x39')],_0x2ae859,'\x0a')},getCustomFields(_0x2fc7ef[_0x1b0f('0x3a')],_0x2ae859)),'auth':_0xf9bc23,'json':!![]};return rp(_0x17ec83)[_0x1b0f('0xb')](function(_0x4853b2){logger[_0x1b0f('0xf')]('['+[_0x143d97[_0x1b0f('0x10')]()]+']\x20POST\x20incident\x20entity\x20schema',_0x4853b2[_0x1b0f('0xc')]);_0x3dc7d5['ticketId']=_0x4853b2[_0x1b0f('0xc')]['sys_id'];_0x3dc7d5[_0x1b0f('0x3b')]=_0x4853b2[_0x1b0f('0xc')]['number'];logger['info']('['+[_0x143d97['toUpperCase']()]+_0x1b0f('0x3c'),_0x3dc7d5);_0x4050e4(_0x3dc7d5);})[_0x1b0f('0x11')](function(_0x36dbd9){logger[_0x1b0f('0x12')]('['+[_0x143d97[_0x1b0f('0x10')]()]+']',_0x36dbd9[_0x1b0f('0x13')]);_0x471e8a(_0x36dbd9[_0x1b0f('0x13')]);});});};}function createRemoteTag(_0x27d08e,_0xcff1e5,_0x438256,_0x55de4b){return new Promise(function(_0x452d5f,_0x1876b7){var _0x5d5dc3={'method':_0x1b0f('0x34'),'uri':_0x438256+_0x1b0f('0x3d')+'?'+_0x55de4b,'body':{'short_description':_0x27d08e,'global':!![],'active':!![],'name':_0x27d08e},'auth':_0xcff1e5,'json':!![]};return rp(_0x5d5dc3)[_0x1b0f('0xb')](function(_0x1e5b46){var _0x5d20f7=_0x1e5b46[_0x1b0f('0xc')][_0x1b0f('0xe')];_0x452d5f(_0x5d20f7);});});}function getRemoteTag(_0x413be6,_0x3cedd8,_0x26995a,_0x1f540e,_0x1ece0f){return new Promise(function(_0x280fc8,_0x4b0d62){var _0x16a90b={'method':_0x1b0f('0x9'),'uri':_0x26995a+_0x1b0f('0x3d')+_0x1b0f('0x3e')+_0x413be6+'&'+_0x1f540e,'auth':_0x3cedd8,'json':!![]};return rp(_0x16a90b)[_0x1b0f('0xb')](function(_0x4de97a){if(_0x4de97a[_0x1b0f('0xc')][_0x1b0f('0x18')]>0x0){var _0x3811b8=_0x4de97a[_0x1b0f('0xc')][0x0][_0x1b0f('0xe')];_0x280fc8(_0x3811b8);}else{return createRemoteTag(_0x413be6,_0x3cedd8,_0x26995a,_0x1f540e)[_0x1b0f('0xb')](function(_0x288967){_0x280fc8(_0x288967);});}});});}function assignTagToIncident(_0x40a5e7,_0x346e2c,_0x1b52ed,_0x1853c0,_0x5cdf1b){return new Promise(function(_0x4473e2,_0x143d9a){var _0x4d60ea={'method':_0x1b0f('0x34'),'uri':_0x1b52ed+_0x1b0f('0x3f')+'?'+_0x5cdf1b,'body':{'label':_0x40a5e7,'table':_0x1b0f('0x35'),'id_type':_0x1b0f('0x40'),'table_key':_0x1853c0[_0x1b0f('0x41')],'title':_0x1b0f('0x42')+_0x1853c0['ticketNumber'],'id_display':_0x1853c0[_0x1b0f('0x3b')]},'auth':_0x346e2c,'json':!![]};return rp(_0x4d60ea)[_0x1b0f('0xb')](function(_0x539edf){_0x4473e2();})[_0x1b0f('0x11')](function(){_0x4473e2();});});}function manageTags(_0x38e89e,_0x3469b3,_0x39fe3b,_0xfaa03e,_0x1e1be4,_0x4b7b54,_0x64d19f){return new Promise(function(_0x1c9730,_0x4cac29){var _0xa20cb1=[];_0x3469b3[_0x1b0f('0x26')](function(_0x343991){_0xa20cb1[_0x1b0f('0x43')](getRemoteTag(_0x343991,_0x39fe3b,_0xfaa03e,_0x4b7b54,_0x64d19f));});return Promise[_0x1b0f('0x44')](_0xa20cb1)[_0x1b0f('0xb')](function(_0x5c309b){if(_0x5c309b[_0x1b0f('0x18')]){logger[_0x1b0f('0xf')]('['+[_0x38e89e[_0x1b0f('0x10')]()]+_0x1b0f('0x45'),_0x5c309b);var _0x2c2b86=[];_0x5c309b[_0x1b0f('0x26')](function(_0x2deeaf){_0x2c2b86['push'](assignTagToIncident(_0x2deeaf,_0x39fe3b,_0xfaa03e,_0x1e1be4,_0x4b7b54));});return Promise[_0x1b0f('0x44')](_0x2c2b86)[_0x1b0f('0xb')](function(){_0x1c9730();})[_0x1b0f('0x11')](function(){_0x1c9730();});}else{_0x1c9730();}});});}function getTags(_0x1fe0f6,_0x2cc95a,_0x572dc6,_0x2ec669,_0x4ec238,_0x27cebe){return function(_0x1a2876){return new Promise(function(_0x5a75b5,_0x23a5c5){var _0x142d03=[];var _0x154656=_0x2ec669[_0x1b0f('0x46')];if(_0x154656&&_0x154656['length']>0x0){_0x142d03=_[_0x1b0f('0x47')](_0x154656,'name');}if(_0x142d03[_0x1b0f('0x18')]>0x0){return manageTags(_0x1fe0f6,_0x142d03,_0x2cc95a,_0x572dc6,_0x1a2876,_0x4ec238,_0x27cebe)[_0x1b0f('0xb')](function(){_0x5a75b5(_0x1a2876);});}else{_0x5a75b5(_0x1a2876);}});};}function emit(_0x222857,_0x288c2e,_0x210d8d){var _0xf8bf49=_0x1b0f('0x48')+_0x1b0f('0x49')+_0x1b0f('0x4a')+'%255EORDERBYDESCnumber';var _0x4a4d6e={'uri':_0x222857+_0x1b0f('0x4b')+_0x210d8d+_0xf8bf49};io['to'](util[_0x1b0f('0x4c')](_0x1b0f('0x4d'),_0x288c2e))[_0x1b0f('0x4e')](_0x1b0f('0x4f'),_0x4a4d6e);}exports['cs']=function(_0x4c6904,_0x288791,_0xb9fa27,_0x53143c,_0x5f15f0,_0x2d66f2,_0x4f5402,_0x28a527){var _0xdcb071={};var _0x26f06b={'user':_0x2d66f2[_0x1b0f('0x50')],'pass':_0x2d66f2[_0x1b0f('0x51')]};var _0x495d01=_0x1b0f('0x52');var _0x490013=_0x1b0f('0x53');_0x2d66f2[_0x1b0f('0x54')]=intUtil[_0x1b0f('0x55')](_0x2d66f2[_0x1b0f('0x54')]);_0x2d66f2['serverUrl']=intUtil['stripTrailingSlash'](_0x2d66f2[_0x1b0f('0x56')]);var _0x2ddf66=util[_0x1b0f('0x4c')](_0x1b0f('0x57'),_0x2d66f2[_0x1b0f('0x54')]);_0xdcb071[_0x1b0f('0x16')]=!_['isNil'](_0x53143c)?_0x53143c['email']:null;_0xdcb071[_0x1b0f('0x1b')]=_0x2d66f2['email'];_0xdcb071[_0x1b0f('0x1f')]=_0x28a527[_0x1b0f('0x2e')]()===_0x1b0f('0x58')?_0x288791[_0x1b0f('0x59')]:_0x288791['calleridnum'];_0xdcb071[_0x1b0f('0x5a')]=_0x28a527===_0x1b0f('0x5b')||_0x28a527===_0x1b0f('0x5c')?_0x1b0f('0x5b'):_0x1b0f('0x58');var _0x144349=util['format'](_0x1b0f('0x5d'),_0x2d66f2[_0x1b0f('0x56')],_0x288791[_0x1b0f('0x5e')],md5(_0x288791[_0x1b0f('0x5e')]));if(_0x5f15f0&&_0x5f15f0['monitor_format']){logger['info'](_0x1b0f('0x5f'),_0x1b0f('0x60'));_0x288791[_0x1b0f('0x61')]=_0x144349;}else if(_0x4f5402&&_0x4f5402[_0x1b0f('0x62')]&&_0x4f5402['recordingFormat']!=='none'){logger[_0x1b0f('0xf')](_0x1b0f('0x63'),'Recording\x20is\x20enabled!');_0x288791[_0x1b0f('0x61')]=_0x144349;}else{_0x288791[_0x1b0f('0x61')]='';}return getAdminUser(_0x28a527,_0x26f06b,_0xdcb071,_0x2ddf66,_0x490013,_0x495d01)[_0x1b0f('0xb')](getUser(_0x28a527,_0x26f06b,_0x2ddf66,_0x490013,_0x495d01))[_0x1b0f('0xb')](getEndUser(_0x28a527,_0x26f06b,_0x2ddf66,_0x490013,_0x495d01))[_0x1b0f('0xb')](getTicket(_0x28a527,_0x26f06b,_0x2ddf66,_0xb9fa27,_0x288791,_0x490013))[_0x1b0f('0xb')](function(_0x4de014){logger[_0x1b0f('0xf')](util[_0x1b0f('0x4c')](_0x1b0f('0x64'),_0x4de014['ticketId']));logger['info'](util[_0x1b0f('0x4c')]('call\x20direction:\x20%s',_0x28a527));if(_0x28a527!=='unmanaged'){logger[_0x1b0f('0xf')]('['+[_0x28a527['toUpperCase']()]+']',_0x1b0f('0x65'));emit(_0x2d66f2[_0x1b0f('0x54')],_0x53143c['name'],_0x4de014[_0x1b0f('0x41')]);}})[_0x1b0f('0x11')](function(_0xdc9086){logger[_0x1b0f('0x12')]('['+[_0x28a527[_0x1b0f('0x10')]()]+_0x1b0f('0x66'),util[_0x1b0f('0x67')](_0xdc9086,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file