Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index ca4a9e8..983813f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x92a8=['md5','util','ioredis','./util','../../../../config/environment','../../../../config/logger','socket.io-emitter','redis','forEach','type','string','idField','content','toString','variable','variableName','customVariable','Variable','name','toLowerCase','info','Creating\x20new\x20ticket...','Normal','Open','Subjects','getString','Descriptions','POST','format','%s/webservice.php','sessionName','HelpDesk','stringify','then','resolve','result','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','error','catch','[vTiger],\x20%s,\x20%s,\x20%s','createTicket','validateEmail','Getting\x20agent\x20with\x20email','remoteUri','query','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','success','Agent\x20found!','email1','first_name','last_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','statusCode','getUser','username','Searching\x20end\x20user\x20with\x20phone','GET','SELECT\x20id,\x20firstname,\x20lastname,\x20email,\x20phone,\x20mobile,\x20homephone,\x20otherphone,\x20assistantphone\x20FROM\x20Contacts\x20WHERE\x20phone\x20=\x20\x27%s\x27\x20OR\x20mobile\x20=\x27%s\x27\x20OR\x20homephone\x20=\x27%s\x27\x20OR\x20otherphone\x20=\x27%s\x27\x20OR\x20assistantphone\x20=\x27%s\x27;','length','lastname','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','create','Contacts','Enduser\x20created.','phone','getEndUser','accessKey','getchallenge','token','getConnection','queue','stripTrailingSlash','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','email','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','split','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','[QUEUE]','outbound','recordingFormat','none','[OUTBOUND]','uniqueid','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','Fields','Ticket\x20created!','monitor_format','lastevent','toUpperCase','lodash','request-promise'];(function(_0x195577,_0x5de53a){var _0x13c367=function(_0x583022){while(--_0x583022){_0x195577['push'](_0x195577['shift']());}};_0x13c367(++_0x5de53a);}(_0x92a8,0x12a));var _0x892a=function(_0x4bfcbe,_0x4630f5){_0x4bfcbe=_0x4bfcbe-0x0;var _0x5b65e6=_0x92a8[_0x4bfcbe];return _0x5b65e6;};'use strict';var _=require(_0x892a('0x0'));var rp=require(_0x892a('0x1'));var BPromise=require('bluebird');var md5=require(_0x892a('0x2'));var util=require(_0x892a('0x3'));var Redis=require(_0x892a('0x4'));var intUtil=require(_0x892a('0x5'));var config=require(_0x892a('0x6'));var logger=require(_0x892a('0x7'))('vTiger');config['redis']=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x892a('0x8'))(new Redis(config[_0x892a('0x9')]));function emit(_0x10feae,_0x12a21,_0x581963){io['to'](_0x10feae)['emit'](_0x12a21,_0x581963);}function getCustomFields(_0x20367f,_0x132eff){var _0x1e1bdc={};if(_0x20367f['length']>0x0){_[_0x892a('0xa')](_0x20367f,function(_0x262fd1){if(_0x262fd1[_0x892a('0xb')]===_0x892a('0xc')&&_0x262fd1[_0x892a('0xd')]){_0x1e1bdc[_0x262fd1[_0x892a('0xd')]]=_0x262fd1[_0x892a('0xe')][_0x892a('0xf')]();}else if(_0x262fd1[_0x892a('0xb')]===_0x892a('0x10')&&_0x262fd1['variableName']&&_0x262fd1[_0x892a('0xd')]&&_0x132eff[_0x262fd1[_0x892a('0x11')]]){_0x1e1bdc[_0x262fd1[_0x892a('0xd')]]=_0x132eff[_0x262fd1['variableName']]['toString']();}else if(_0x262fd1[_0x892a('0xb')]===_0x892a('0x12')&&_0x262fd1[_0x892a('0x13')]&&_0x262fd1[_0x892a('0x13')][_0x892a('0x14')]&&_0x262fd1['idField']&&_0x132eff[_0x262fd1[_0x892a('0x13')]['name'][_0x892a('0x15')]()]){_0x1e1bdc[_0x262fd1['idField']]=_0x132eff[_0x262fd1['Variable']['name']['toLowerCase']()][_0x892a('0xf')]();}});}return _0x1e1bdc;}function createTicket(_0x3b36e7,_0x58d8bf,_0x31de31,_0x35e510,_0x1a1086,_0xee8687,_0x5d27cb){logger[_0x892a('0x16')](_0x892a('0x17'));var _0x49fcbc=_['merge']({'parent_id':'','assigned_user_id':_0x58d8bf['id'],'ticketpriorities':_0x892a('0x18'),'ticketstatus':_0x892a('0x19'),'ticket_title':intUtil['getString'](_0x35e510[_0x892a('0x1a')],_0x1a1086,'\x20'),'description':intUtil[_0x892a('0x1b')](_0x35e510[_0x892a('0x1c')],_0x1a1086,'\x0a'),'contact_id':_0x31de31['id']},getCustomFields(_0xee8687,_0x1a1086));var _0x4df166={'method':_0x892a('0x1d'),'uri':util[_0x892a('0x1e')](_0x892a('0x1f'),_0x3b36e7['remoteUri']),'form':{'operation':'create','username':_0x3b36e7['username'],'sessionName':_0x5d27cb[_0x892a('0x20')],'elementType':_0x892a('0x21'),'element':JSON[_0x892a('0x22')](_0x49fcbc)},'json':!![]};return request(_0x4df166)[_0x892a('0x23')](function(_0x2e422e){if(_0x2e422e['success']){return BPromise[_0x892a('0x24')]({'id':_0x2e422e[_0x892a('0x25')]['id']});}else{throw new Error(util[_0x892a('0x1e')](_0x892a('0x26'),JSON['stringify'](_0x2e422e[_0x892a('0x27')])));}})[_0x892a('0x28')](function(_0x32778d){var _0x4205af=_0x32778d['statusCode']||0x1f4;logger['error'](_0x892a('0x29'),_0x892a('0x2a'),_0x4205af,JSON[_0x892a('0x22')](_0x32778d));});}function getUser(_0x23df3a,_0x4e77af,_0xc766c1){if(intUtil[_0x892a('0x2b')](_0x4e77af)){logger[_0x892a('0x16')](_0x892a('0x2c'),_0x4e77af);return request({'method':'GET','uri':util[_0x892a('0x1e')]('%s/webservice.php',_0x23df3a[_0x892a('0x2d')]),'qs':{'operation':_0x892a('0x2e'),'username':_0x23df3a['username'],'sessionName':_0xc766c1[_0x892a('0x20')],'query':util['format'](_0x892a('0x2f'),_0x4e77af)},'json':!![]})['then'](function(_0x3e4460){if(_0x3e4460[_0x892a('0x30')]&&_0x3e4460['result']['length']){logger[_0x892a('0x16')](_0x892a('0x31'));return BPromise[_0x892a('0x24')]({'id':_0x3e4460[_0x892a('0x25')][0x0]['id'],'email':_0x3e4460[_0x892a('0x25')][0x0][_0x892a('0x32')],'name':_0x3e4460[_0x892a('0x25')][0x0][_0x892a('0x33')]+'\x20'+_0x3e4460[_0x892a('0x25')][_0x892a('0x34')]});}else{logger[_0x892a('0x16')](_0x892a('0x35'));return BPromise[_0x892a('0x24')]({'id':_0xc766c1['userId'],'email':_0x23df3a['username'],'name':'admin'});}})['catch'](function(_0x3a3ad4){var _0x1b7adf=_0x3a3ad4[_0x892a('0x36')]||0x1f4;logger[_0x892a('0x27')](_0x892a('0x29'),_0x892a('0x37'),_0x1b7adf,JSON[_0x892a('0x22')](_0x3a3ad4));});}else{logger[_0x892a('0x16')](_0x892a('0x35'));return BPromise[_0x892a('0x24')]({'id':_0xc766c1['userId'],'email':_0x23df3a[_0x892a('0x38')],'name':'admin'})[_0x892a('0x28')](function(_0x18f56e){var _0x276d9d=_0x18f56e[_0x892a('0x36')]||0x1f4;logger[_0x892a('0x27')](_0x892a('0x29'),_0x892a('0x37'),_0x276d9d,JSON[_0x892a('0x22')](_0x18f56e));});}}function getEndUser(_0x35ec69,_0x5c9976,_0x3d529f,_0x45c04e){logger[_0x892a('0x16')](_0x892a('0x39'),_0x3d529f);return request({'method':_0x892a('0x3a'),'uri':util['format'](_0x892a('0x1f'),_0x35ec69['remoteUri']),'qs':{'operation':_0x892a('0x2e'),'username':_0x35ec69[_0x892a('0x38')],'sessionName':_0x45c04e['sessionName'],'query':util['format'](_0x892a('0x3b'),_0x3d529f,_0x3d529f,_0x3d529f,_0x3d529f,_0x3d529f)},'json':!![]})[_0x892a('0x23')](function(_0xe400de){if(_0xe400de[_0x892a('0x30')]&&_0xe400de[_0x892a('0x25')][_0x892a('0x3c')]){logger[_0x892a('0x16')]('Enduser\x20found!');return BPromise[_0x892a('0x24')]({'id':_0xe400de[_0x892a('0x25')][0x0]['id'],'name':_0xe400de[_0x892a('0x25')][0x0]['firstname']+'\x20'+_0xe400de['result'][0x0][_0x892a('0x3d')],'phone':_0x3d529f});}else{logger[_0x892a('0x16')](_0x892a('0x3e'));return request({'method':_0x892a('0x1d'),'uri':util[_0x892a('0x1e')](_0x892a('0x1f'),_0x35ec69[_0x892a('0x2d')]),'form':{'operation':_0x892a('0x3f'),'sessionName':_0x45c04e[_0x892a('0x20')],'elementType':_0x892a('0x40'),'element':JSON[_0x892a('0x22')]({'lastname':_0x5c9976,'phone':_0x3d529f,'assigned_user_id':'\x20'})},'json':!![]})[_0x892a('0x23')](function(_0x2912c7){logger[_0x892a('0x16')](_0x892a('0x41'));return BPromise[_0x892a('0x24')]({'id':_0x2912c7[_0x892a('0x25')]['id'],'name':_0x2912c7[_0x892a('0x25')][_0x892a('0x3d')],'phone':_0x2912c7[_0x892a('0x25')][_0x892a('0x42')]});})[_0x892a('0x28')](function(_0x173091){var _0x5a54de=_0x173091[_0x892a('0x36')]||0x1f4;logger[_0x892a('0x27')]('[vTiger],\x20%s,\x20%s,\x20%s',_0x892a('0x43'),_0x5a54de,JSON['stringify'](_0x173091));});}});}function getConnection(_0x8c1913){var _0x2a6fa1=_0x8c1913[_0x892a('0x38')];var _0x5a55a7=_0x8c1913[_0x892a('0x44')];return request({'method':_0x892a('0x3a'),'uri':util[_0x892a('0x1e')](_0x892a('0x1f'),_0x8c1913[_0x892a('0x2d')]),'qs':{'operation':_0x892a('0x45'),'username':_0x2a6fa1},'json':!![]})[_0x892a('0x23')](function(_0x1ffc20){if(_0x1ffc20[_0x892a('0x30')]){return request({'method':'POST','uri':util['format']('%s/webservice.php',_0x8c1913['remoteUri']),'form':{'operation':'login','username':_0x2a6fa1,'accessKey':md5(_0x1ffc20[_0x892a('0x25')][_0x892a('0x46')]+_0x5a55a7)},'json':!![]});}})[_0x892a('0x23')](function(_0x2b2c5f){if(_0x2b2c5f[_0x892a('0x30')]){return BPromise[_0x892a('0x24')](_0x2b2c5f[_0x892a('0x25')]);}else{throw new Error(util[_0x892a('0x1e')]('Account\x20%d\x20is\x20not\x20valid',_0x8c1913['id']));}})[_0x892a('0x28')](function(_0x410260){var _0x59bb0e=_0x410260[_0x892a('0x36')]||0x1f4;logger['error'](_0x892a('0x29'),_0x892a('0x47'),_0x59bb0e,JSON[_0x892a('0x22')](_0x410260));});}function request(_0x44e26c){logger['info']('[HTTP]',JSON['stringify'](_0x44e26c));return rp(_0x44e26c);}exports[_0x892a('0x48')]=function(_0x37164d,_0x2f8277,_0x28554c,_0x511508,_0x97efc1,_0x51b9f4){var _0x2d54e5,_0xc7d879,_0x428ebf,_0x37a4df;_0x51b9f4['remoteUri']=intUtil[_0x892a('0x49')](_0x51b9f4['remoteUri']);if(_0x97efc1&&_0x97efc1['monitor_format']){logger[_0x892a('0x16')]('[QUEUE]','Recording\x20is\x20enabled!');_0x2f8277[_0x892a('0x4a')]=util[_0x892a('0x1e')](_0x892a('0x4b'),_0x51b9f4[_0x892a('0x4c')],_0x2f8277['uniqueid'],md5(_0x2f8277['uniqueid']));}else{_0x2f8277[_0x892a('0x4a')]='';}return getConnection(_0x51b9f4)[_0x892a('0x23')](function(_0x260676){_0x37a4df=_0x260676;return getUser(_0x51b9f4,_0x511508[_0x892a('0x4d')],_0x37a4df);})[_0x892a('0x23')](function(_0x19da40){_0x2d54e5=_0x19da40;logger['info']('The\x20User\x20ID\x20is:',_0x2d54e5['id']);return getEndUser(_0x51b9f4,_0x2f8277['calleridname'],_0x2f8277[_0x892a('0x4e')],_0x37a4df);})['then'](function(_0x51db11){_0xc7d879=_0x51db11;logger[_0x892a('0x16')](_0x892a('0x4f'),_0xc7d879['id']);return createTicket(_0x51b9f4,_0x2d54e5,_0xc7d879,_0x28554c,_0x2f8277,_0x28554c['Fields'],_0x37a4df);})[_0x892a('0x23')](function(_0x2f1557){_0x428ebf=_0x2f1557;logger[_0x892a('0x16')]('Ticket\x20created!');logger[_0x892a('0x16')](_0x892a('0x50'),_0x428ebf['id']);var _0x3b5ec5=util[_0x892a('0x1e')](_0x892a('0x51'),_0x51b9f4[_0x892a('0x2d')],_[_0x892a('0x52')](_0x428ebf['id'],'x')[0x1]);logger[_0x892a('0x16')]('[QUEUE]',_0x892a('0x53'));emit(util[_0x892a('0x1e')](_0x892a('0x54'),_0x511508[_0x892a('0x14')]),_0x892a('0x55'),{'uri':_0x3b5ec5});})[_0x892a('0x28')](function(_0x4b1087){logger['error'](_0x892a('0x56'),JSON[_0x892a('0x22')](_0x4b1087));});};exports[_0x892a('0x57')]=function(_0x1f360a,_0x5b2cb0,_0x2a7c3b,_0x3f664d,_0x64a17f,_0x557881,_0x3ff5f0){var _0x4907d5,_0x40e242,_0x5b3bf1,_0x5aa82f;_0x557881['remoteUri']=intUtil[_0x892a('0x49')](_0x557881[_0x892a('0x2d')]);_0x557881[_0x892a('0x4c')]=intUtil['stripTrailingSlash'](_0x557881['serverUrl']);if(_0x3ff5f0&&_0x3ff5f0[_0x892a('0x58')]&&_0x3ff5f0['recordingFormat']!==_0x892a('0x59')){logger[_0x892a('0x16')](_0x892a('0x5a'),'Recording\x20is\x20enabled!');_0x5b2cb0[_0x892a('0x4a')]=util[_0x892a('0x1e')](_0x892a('0x4b'),_0x557881[_0x892a('0x4c')],_0x5b2cb0['uniqueid'],md5(_0x5b2cb0[_0x892a('0x5b')]));}return getConnection(_0x557881)[_0x892a('0x23')](function(_0x4d1812){_0x5aa82f=_0x4d1812;return getUser(_0x557881,_0x3f664d['email'],_0x5aa82f);})[_0x892a('0x23')](function(_0xb87657){_0x4907d5=_0xb87657;logger[_0x892a('0x16')](_0x892a('0x5c'),_0x4907d5['id']);return getEndUser(_0x557881,_0x5b2cb0[_0x892a('0x5d')],_0x5b2cb0[_0x892a('0x5e')],_0x5aa82f);})['then'](function(_0x335ec7){_0x40e242=_0x335ec7;logger[_0x892a('0x16')]('The\x20Enduser\x20ID\x20is:',_0x40e242['id']);return createTicket(_0x557881,_0x4907d5,_0x40e242,_0x2a7c3b,_0x5b2cb0,_0x2a7c3b[_0x892a('0x5f')],_0x5aa82f);})['then'](function(_0x374748){_0x5b3bf1=_0x374748;logger[_0x892a('0x16')](_0x892a('0x60'));logger[_0x892a('0x16')]('The\x20Ticket\x20ID\x20is:',_0x5b3bf1['id']);var _0x1c207f=util[_0x892a('0x1e')](_0x892a('0x51'),_0x557881[_0x892a('0x2d')],_[_0x892a('0x52')](_0x5b3bf1['id'],'x')[0x1]);logger[_0x892a('0x16')](_0x892a('0x5a'),_0x892a('0x53'));emit(util[_0x892a('0x1e')](_0x892a('0x54'),_0x3f664d[_0x892a('0x14')]),_0x892a('0x55'),{'uri':_0x1c207f});})[_0x892a('0x28')](function(_0x25fe36){logger[_0x892a('0x27')](_0x892a('0x5a'),JSON[_0x892a('0x22')](_0x25fe36));});};exports['unmanaged']=function(_0x58d75b,_0xf13492,_0x4f8917,_0x3e70f6,_0x4325d7,_0x2571ef){var _0x97fecc,_0x29f711,_0x232215,_0x4891b5;_0x2571ef['remoteUri']=intUtil['stripTrailingSlash'](_0x2571ef[_0x892a('0x2d')]);_0x2571ef[_0x892a('0x4c')]=intUtil[_0x892a('0x49')](_0x2571ef[_0x892a('0x4c')]);if(_0x4325d7&&_0x4325d7[_0x892a('0x61')]){logger[_0x892a('0x16')]('['+_0xf13492[_0x892a('0x62')][_0x892a('0x63')]()+']','Recording\x20is\x20enabled!');_0xf13492[_0x892a('0x4a')]=util[_0x892a('0x1e')](_0x892a('0x4b'),_0x2571ef['serverUrl'],_0xf13492[_0x892a('0x5b')],md5(_0xf13492[_0x892a('0x5b')]));}else{_0xf13492['recordingURL']='';}return getConnection(_0x2571ef)['then'](function(_0x14bd6f){_0x4891b5=_0x14bd6f;return getUser(_0x2571ef,'',_0x4891b5);})[_0x892a('0x23')](function(_0x54483e){_0x97fecc=_0x54483e;logger[_0x892a('0x16')]('The\x20User\x20ID\x20is:',_0x97fecc['id']);return getEndUser(_0x2571ef,_0xf13492['calleridname'],_0xf13492[_0x892a('0x4e')],_0x4891b5);})[_0x892a('0x23')](function(_0xbe7b8){_0x29f711=_0xbe7b8;logger[_0x892a('0x16')](_0x892a('0x4f'),_0x29f711['id']);return createTicket(_0x2571ef,_0x97fecc,_0x29f711,_0x4f8917,_0xf13492,_0x4f8917[_0x892a('0x5f')],_0x4891b5);})[_0x892a('0x23')](function(_0xccc100){_0x232215=_0xccc100;logger[_0x892a('0x16')](_0x892a('0x60'));logger[_0x892a('0x16')]('The\x20Ticket\x20ID\x20is:',_0x232215['id']);})['catch'](function(_0x59cef3){logger['error']('['+_0xf13492['lastevent'][_0x892a('0x63')]()+']',JSON[_0x892a('0x22')](_0x59cef3));});};
\ No newline at end of file
+var _0x9c44=['stringify','validateEmail','Getting\x20agent\x20with\x20email','GET','%s/webservice.php','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','success','length','Agent\x20found!','email1','first_name','last_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userId','getUser','admin','Searching\x20end\x20user\x20with\x20phone','SELECT\x20id,\x20firstname,\x20lastname,\x20email,\x20phone,\x20mobile,\x20homephone,\x20otherphone,\x20assistantphone\x20FROM\x20Contacts\x20WHERE\x20phone\x20=\x20\x27%s\x27\x20OR\x20mobile\x20=\x27%s\x27\x20OR\x20homephone\x20=\x27%s\x27\x20OR\x20otherphone\x20=\x27%s\x27\x20OR\x20assistantphone\x20=\x27%s\x27;','Enduser\x20found!','firstname','lastname','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Contacts','Enduser\x20created.','phone','getEndUser','accessKey','login','Account\x20%d\x20is\x20not\x20valid','getConnection','[HTTP]','queue','stripTrailingSlash','[QUEUE]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','uniqueid','recordingURL','email','The\x20User\x20ID\x20is:','calleridname','The\x20Enduser\x20ID\x20is:','Fields','The\x20Ticket\x20ID\x20is:','split','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!','destcalleridname','destcalleridnum','Ticket\x20created!','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','trigger:browser:url','unmanaged','monitor_format','toUpperCase','calleridnum','lastevent','bluebird','md5','util','ioredis','./util','../../../../config/environment','redis','localhost','socket.io-emitter','emit','forEach','string','picklist','idField','content','type','variable','variableName','toString','customVariable','Variable','name','toLowerCase','info','Creating\x20new\x20ticket...','merge','Normal','Open','getString','Subjects','POST','remoteUri','create','username','sessionName','then','resolve','result','format','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','catch','statusCode','error','[vTiger],\x20%s,\x20%s,\x20%s'];(function(_0x12ba0c,_0x15d6e9){var _0x402cbe=function(_0x235661){while(--_0x235661){_0x12ba0c['push'](_0x12ba0c['shift']());}};_0x402cbe(++_0x15d6e9);}(_0x9c44,0x178));var _0x49c4=function(_0x422905,_0x3bce3a){_0x422905=_0x422905-0x0;var _0x33dc6c=_0x9c44[_0x422905];return _0x33dc6c;};'use strict';var _=require('lodash');var rp=require('request-promise');var BPromise=require(_0x49c4('0x0'));var md5=require(_0x49c4('0x1'));var util=require(_0x49c4('0x2'));var Redis=require(_0x49c4('0x3'));var intUtil=require(_0x49c4('0x4'));var config=require(_0x49c4('0x5'));var logger=require('../../../../config/logger')('vTiger');config[_0x49c4('0x6')]=_['defaults'](config[_0x49c4('0x6')],{'host':_0x49c4('0x7'),'port':0x18eb});var io=require(_0x49c4('0x8'))(new Redis(config[_0x49c4('0x6')]));function emit(_0x436234,_0x511d53,_0x11c586){io['to'](_0x436234)[_0x49c4('0x9')](_0x511d53,_0x11c586);}function getCustomFields(_0x1d13fb,_0x4487ca){var _0x4c7d3a={};if(_0x1d13fb['length']>0x0){_[_0x49c4('0xa')](_0x1d13fb,function(_0x313e73){if(_['includes']([_0x49c4('0xb'),_0x49c4('0xc')],_0x313e73['type'])&&_0x313e73['idField']){_0x4c7d3a[_0x313e73[_0x49c4('0xd')]]=_0x313e73[_0x49c4('0xe')]['toString']();}else if(_0x313e73[_0x49c4('0xf')]===_0x49c4('0x10')&&_0x313e73['variableName']&&_0x313e73[_0x49c4('0xd')]&&_0x4487ca[_0x313e73[_0x49c4('0x11')]]){_0x4c7d3a[_0x313e73[_0x49c4('0xd')]]=_0x4487ca[_0x313e73[_0x49c4('0x11')]][_0x49c4('0x12')]();}else if(_0x313e73[_0x49c4('0xf')]===_0x49c4('0x13')&&_0x313e73[_0x49c4('0x14')]&&_0x313e73['Variable'][_0x49c4('0x15')]&&_0x313e73[_0x49c4('0xd')]&&_0x4487ca[_0x313e73[_0x49c4('0x14')][_0x49c4('0x15')][_0x49c4('0x16')]()]){_0x4c7d3a[_0x313e73['idField']]=_0x4487ca[_0x313e73[_0x49c4('0x14')][_0x49c4('0x15')]['toLowerCase']()]['toString']();}});}return _0x4c7d3a;}function createTicket(_0x3c782d,_0x2f82d5,_0x3addb2,_0x59f29b,_0x24856d,_0x50b151,_0x2cbd50){logger[_0x49c4('0x17')](_0x49c4('0x18'));var _0x291526=_[_0x49c4('0x19')]({'parent_id':'','assigned_user_id':_0x2f82d5['id'],'ticketpriorities':_0x49c4('0x1a'),'ticketstatus':_0x49c4('0x1b'),'ticket_title':intUtil[_0x49c4('0x1c')](_0x59f29b[_0x49c4('0x1d')],_0x24856d,'\x20'),'description':intUtil['getString'](_0x59f29b['Descriptions'],_0x24856d,'\x0a'),'contact_id':_0x3addb2['id']},getCustomFields(_0x50b151,_0x24856d));var _0x57f502={'method':_0x49c4('0x1e'),'uri':util['format']('%s/webservice.php',_0x3c782d[_0x49c4('0x1f')]),'form':{'operation':_0x49c4('0x20'),'username':_0x3c782d[_0x49c4('0x21')],'sessionName':_0x2cbd50[_0x49c4('0x22')],'elementType':'HelpDesk','element':JSON['stringify'](_0x291526)},'json':!![]};return request(_0x57f502)[_0x49c4('0x23')](function(_0x9cb797){if(_0x9cb797['success']){return BPromise[_0x49c4('0x24')]({'id':_0x9cb797[_0x49c4('0x25')]['id']});}else{throw new Error(util[_0x49c4('0x26')](_0x49c4('0x27'),JSON['stringify'](_0x9cb797['error'])));}})[_0x49c4('0x28')](function(_0x53c199){var _0x3800b7=_0x53c199[_0x49c4('0x29')]||0x1f4;logger[_0x49c4('0x2a')](_0x49c4('0x2b'),'createTicket',_0x3800b7,JSON[_0x49c4('0x2c')](_0x53c199));});}function getUser(_0x2b2793,_0x46e04d,_0x4f28a2){if(intUtil[_0x49c4('0x2d')](_0x46e04d)){logger[_0x49c4('0x17')](_0x49c4('0x2e'),_0x46e04d);return request({'method':_0x49c4('0x2f'),'uri':util[_0x49c4('0x26')](_0x49c4('0x30'),_0x2b2793[_0x49c4('0x1f')]),'qs':{'operation':'query','username':_0x2b2793['username'],'sessionName':_0x4f28a2['sessionName'],'query':util[_0x49c4('0x26')](_0x49c4('0x31'),_0x46e04d)},'json':!![]})[_0x49c4('0x23')](function(_0x27e467){if(_0x27e467[_0x49c4('0x32')]&&_0x27e467['result'][_0x49c4('0x33')]){logger[_0x49c4('0x17')](_0x49c4('0x34'));return BPromise[_0x49c4('0x24')]({'id':_0x27e467['result'][0x0]['id'],'email':_0x27e467['result'][0x0][_0x49c4('0x35')],'name':_0x27e467[_0x49c4('0x25')][0x0][_0x49c4('0x36')]+'\x20'+_0x27e467[_0x49c4('0x25')][_0x49c4('0x37')]});}else{logger['info'](_0x49c4('0x38'));return BPromise[_0x49c4('0x24')]({'id':_0x4f28a2[_0x49c4('0x39')],'email':_0x2b2793['username'],'name':'admin'});}})[_0x49c4('0x28')](function(_0x1991e9){var _0x3bec0a=_0x1991e9[_0x49c4('0x29')]||0x1f4;logger[_0x49c4('0x2a')](_0x49c4('0x2b'),_0x49c4('0x3a'),_0x3bec0a,JSON[_0x49c4('0x2c')](_0x1991e9));});}else{logger[_0x49c4('0x17')]('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return BPromise[_0x49c4('0x24')]({'id':_0x4f28a2['userId'],'email':_0x2b2793[_0x49c4('0x21')],'name':_0x49c4('0x3b')})[_0x49c4('0x28')](function(_0x1c2830){var _0x4ed4f8=_0x1c2830[_0x49c4('0x29')]||0x1f4;logger[_0x49c4('0x2a')](_0x49c4('0x2b'),'getUser',_0x4ed4f8,JSON[_0x49c4('0x2c')](_0x1c2830));});}}function getEndUser(_0x21d8c7,_0x178987,_0x5e5366,_0x1ba7a0){logger[_0x49c4('0x17')](_0x49c4('0x3c'),_0x5e5366);return request({'method':_0x49c4('0x2f'),'uri':util[_0x49c4('0x26')](_0x49c4('0x30'),_0x21d8c7[_0x49c4('0x1f')]),'qs':{'operation':'query','username':_0x21d8c7[_0x49c4('0x21')],'sessionName':_0x1ba7a0[_0x49c4('0x22')],'query':util[_0x49c4('0x26')](_0x49c4('0x3d'),_0x5e5366,_0x5e5366,_0x5e5366,_0x5e5366,_0x5e5366)},'json':!![]})[_0x49c4('0x23')](function(_0x29dd5d){if(_0x29dd5d[_0x49c4('0x32')]&&_0x29dd5d[_0x49c4('0x25')][_0x49c4('0x33')]){logger[_0x49c4('0x17')](_0x49c4('0x3e'));return BPromise[_0x49c4('0x24')]({'id':_0x29dd5d[_0x49c4('0x25')][0x0]['id'],'name':_0x29dd5d['result'][0x0][_0x49c4('0x3f')]+'\x20'+_0x29dd5d['result'][0x0][_0x49c4('0x40')],'phone':_0x5e5366});}else{logger[_0x49c4('0x17')](_0x49c4('0x41'));return request({'method':_0x49c4('0x1e'),'uri':util[_0x49c4('0x26')](_0x49c4('0x30'),_0x21d8c7['remoteUri']),'form':{'operation':'create','sessionName':_0x1ba7a0[_0x49c4('0x22')],'elementType':_0x49c4('0x42'),'element':JSON[_0x49c4('0x2c')]({'lastname':_0x178987,'phone':_0x5e5366,'assigned_user_id':'\x20'})},'json':!![]})[_0x49c4('0x23')](function(_0x490823){logger[_0x49c4('0x17')](_0x49c4('0x43'));return BPromise[_0x49c4('0x24')]({'id':_0x490823[_0x49c4('0x25')]['id'],'name':_0x490823[_0x49c4('0x25')][_0x49c4('0x40')],'phone':_0x490823[_0x49c4('0x25')][_0x49c4('0x44')]});})[_0x49c4('0x28')](function(_0x5640d3){var _0x2ad771=_0x5640d3['statusCode']||0x1f4;logger[_0x49c4('0x2a')](_0x49c4('0x2b'),_0x49c4('0x45'),_0x2ad771,JSON[_0x49c4('0x2c')](_0x5640d3));});}});}function getConnection(_0x2d93d8){var _0x5b296d=_0x2d93d8[_0x49c4('0x21')];var _0x15b674=_0x2d93d8[_0x49c4('0x46')];return request({'method':_0x49c4('0x2f'),'uri':util[_0x49c4('0x26')](_0x49c4('0x30'),_0x2d93d8[_0x49c4('0x1f')]),'qs':{'operation':'getchallenge','username':_0x5b296d},'json':!![]})[_0x49c4('0x23')](function(_0x5cfff9){if(_0x5cfff9[_0x49c4('0x32')]){return request({'method':_0x49c4('0x1e'),'uri':util[_0x49c4('0x26')](_0x49c4('0x30'),_0x2d93d8[_0x49c4('0x1f')]),'form':{'operation':_0x49c4('0x47'),'username':_0x5b296d,'accessKey':md5(_0x5cfff9[_0x49c4('0x25')]['token']+_0x15b674)},'json':!![]});}})[_0x49c4('0x23')](function(_0x3feaf0){if(_0x3feaf0['success']){return BPromise[_0x49c4('0x24')](_0x3feaf0[_0x49c4('0x25')]);}else{throw new Error(util[_0x49c4('0x26')](_0x49c4('0x48'),_0x2d93d8['id']));}})['catch'](function(_0x5d8bf0){var _0x144fd2=_0x5d8bf0['statusCode']||0x1f4;logger[_0x49c4('0x2a')](_0x49c4('0x2b'),_0x49c4('0x49'),_0x144fd2,JSON[_0x49c4('0x2c')](_0x5d8bf0));});}function request(_0x240c20){logger[_0x49c4('0x17')](_0x49c4('0x4a'),JSON['stringify'](_0x240c20));return rp(_0x240c20);}exports[_0x49c4('0x4b')]=function(_0x1550ce,_0x3936d3,_0x3d944c,_0x17ef75,_0x2644c0,_0x156748){var _0x25d174,_0x1e0b4f,_0x1856be,_0x5b822f;_0x156748['remoteUri']=intUtil[_0x49c4('0x4c')](_0x156748[_0x49c4('0x1f')]);if(_0x2644c0&&_0x2644c0['monitor_format']){logger['info'](_0x49c4('0x4d'),'Recording\x20is\x20enabled!');_0x3936d3['recordingURL']=util[_0x49c4('0x26')](_0x49c4('0x4e'),_0x156748[_0x49c4('0x4f')],_0x3936d3[_0x49c4('0x50')],md5(_0x3936d3[_0x49c4('0x50')]));}else{_0x3936d3[_0x49c4('0x51')]='';}return getConnection(_0x156748)[_0x49c4('0x23')](function(_0x50798e){_0x5b822f=_0x50798e;return getUser(_0x156748,_0x17ef75[_0x49c4('0x52')],_0x5b822f);})[_0x49c4('0x23')](function(_0x207572){_0x25d174=_0x207572;logger[_0x49c4('0x17')](_0x49c4('0x53'),_0x25d174['id']);return getEndUser(_0x156748,_0x3936d3[_0x49c4('0x54')],_0x3936d3['calleridnum'],_0x5b822f);})['then'](function(_0x1ef0c1){_0x1e0b4f=_0x1ef0c1;logger[_0x49c4('0x17')](_0x49c4('0x55'),_0x1e0b4f['id']);return createTicket(_0x156748,_0x25d174,_0x1e0b4f,_0x3d944c,_0x3936d3,_0x3d944c[_0x49c4('0x56')],_0x5b822f);})[_0x49c4('0x23')](function(_0x6b2592){_0x1856be=_0x6b2592;logger[_0x49c4('0x17')]('Ticket\x20created!');logger[_0x49c4('0x17')](_0x49c4('0x57'),_0x1856be['id']);var _0x4ba4eb=util[_0x49c4('0x26')]('%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT',_0x156748[_0x49c4('0x1f')],_[_0x49c4('0x58')](_0x1856be['id'],'x')[0x1]);logger[_0x49c4('0x17')](_0x49c4('0x4d'),_0x49c4('0x59'));emit(util[_0x49c4('0x26')](_0x49c4('0x5a'),_0x17ef75[_0x49c4('0x15')]),'trigger:browser:url',{'uri':_0x4ba4eb});})[_0x49c4('0x28')](function(_0x27b9c2){logger['error'](_0x49c4('0x4d'),JSON[_0x49c4('0x2c')](_0x27b9c2));});};exports['outbound']=function(_0x39c455,_0x42e0e6,_0x4f50bf,_0x4dc54d,_0x589484,_0x513879,_0xc43386){var _0x54947d,_0xb20a5d,_0x32f344,_0x515240;_0x513879[_0x49c4('0x1f')]=intUtil[_0x49c4('0x4c')](_0x513879['remoteUri']);_0x513879[_0x49c4('0x4f')]=intUtil[_0x49c4('0x4c')](_0x513879[_0x49c4('0x4f')]);if(_0xc43386&&_0xc43386[_0x49c4('0x5b')]&&_0xc43386['recordingFormat']!==_0x49c4('0x5c')){logger[_0x49c4('0x17')](_0x49c4('0x5d'),_0x49c4('0x5e'));_0x42e0e6['recordingURL']=util[_0x49c4('0x26')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x513879['serverUrl'],_0x42e0e6['uniqueid'],md5(_0x42e0e6['uniqueid']));}return getConnection(_0x513879)[_0x49c4('0x23')](function(_0x32eaef){_0x515240=_0x32eaef;return getUser(_0x513879,_0x4dc54d[_0x49c4('0x52')],_0x515240);})[_0x49c4('0x23')](function(_0x5b056e){_0x54947d=_0x5b056e;logger['info'](_0x49c4('0x53'),_0x54947d['id']);return getEndUser(_0x513879,_0x42e0e6[_0x49c4('0x5f')],_0x42e0e6[_0x49c4('0x60')],_0x515240);})[_0x49c4('0x23')](function(_0x102c15){_0xb20a5d=_0x102c15;logger[_0x49c4('0x17')](_0x49c4('0x55'),_0xb20a5d['id']);return createTicket(_0x513879,_0x54947d,_0xb20a5d,_0x4f50bf,_0x42e0e6,_0x4f50bf[_0x49c4('0x56')],_0x515240);})['then'](function(_0x2276db){_0x32f344=_0x2276db;logger['info'](_0x49c4('0x61'));logger[_0x49c4('0x17')](_0x49c4('0x57'),_0x32f344['id']);var _0x1ea1b4=util[_0x49c4('0x26')](_0x49c4('0x62'),_0x513879[_0x49c4('0x1f')],_[_0x49c4('0x58')](_0x32f344['id'],'x')[0x1]);logger[_0x49c4('0x17')](_0x49c4('0x5d'),_0x49c4('0x59'));emit(util[_0x49c4('0x26')](_0x49c4('0x5a'),_0x4dc54d[_0x49c4('0x15')]),_0x49c4('0x63'),{'uri':_0x1ea1b4});})[_0x49c4('0x28')](function(_0x371e49){logger[_0x49c4('0x2a')]('[OUTBOUND]',JSON['stringify'](_0x371e49));});};exports[_0x49c4('0x64')]=function(_0x16b3e8,_0x4af680,_0x1a15f3,_0x38ad50,_0x2939fd,_0x16e7b1){var _0x4d6aaa,_0x5a14a5,_0x4a85d4,_0x2e90d8;_0x16e7b1[_0x49c4('0x1f')]=intUtil[_0x49c4('0x4c')](_0x16e7b1[_0x49c4('0x1f')]);_0x16e7b1[_0x49c4('0x4f')]=intUtil[_0x49c4('0x4c')](_0x16e7b1[_0x49c4('0x4f')]);if(_0x2939fd&&_0x2939fd[_0x49c4('0x65')]){logger[_0x49c4('0x17')]('['+_0x4af680['lastevent'][_0x49c4('0x66')]()+']',_0x49c4('0x5e'));_0x4af680[_0x49c4('0x51')]=util['format'](_0x49c4('0x4e'),_0x16e7b1[_0x49c4('0x4f')],_0x4af680[_0x49c4('0x50')],md5(_0x4af680[_0x49c4('0x50')]));}else{_0x4af680[_0x49c4('0x51')]='';}return getConnection(_0x16e7b1)[_0x49c4('0x23')](function(_0x35fa39){_0x2e90d8=_0x35fa39;return getUser(_0x16e7b1,'',_0x2e90d8);})[_0x49c4('0x23')](function(_0x4ba198){_0x4d6aaa=_0x4ba198;logger[_0x49c4('0x17')](_0x49c4('0x53'),_0x4d6aaa['id']);return getEndUser(_0x16e7b1,_0x4af680[_0x49c4('0x54')],_0x4af680[_0x49c4('0x67')],_0x2e90d8);})[_0x49c4('0x23')](function(_0x4a204d){_0x5a14a5=_0x4a204d;logger['info'](_0x49c4('0x55'),_0x5a14a5['id']);return createTicket(_0x16e7b1,_0x4d6aaa,_0x5a14a5,_0x1a15f3,_0x4af680,_0x1a15f3['Fields'],_0x2e90d8);})[_0x49c4('0x23')](function(_0x558880){_0x4a85d4=_0x558880;logger[_0x49c4('0x17')](_0x49c4('0x61'));logger[_0x49c4('0x17')](_0x49c4('0x57'),_0x4a85d4['id']);})['catch'](function(_0x123060){logger[_0x49c4('0x2a')]('['+_0x4af680[_0x49c4('0x68')][_0x49c4('0x66')]()+']',JSON[_0x49c4('0x2c')](_0x123060));});};
\ No newline at end of file