Built motion from commit 3e059bc2.|2.5.32
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index 929a5d8..0cf3a12 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0c99=['username','sessionName','HelpDesk','then','success','stringify','error','catch','statusCode','[vTiger],\x20%s,\x20%s,\x20%s','createTicket','validateEmail','GET','remoteUri','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','result','Agent\x20found!','resolve','email1','first_name','last_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userId','admin','getUser','Searching\x20end\x20user\x20with\x20phone','query','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;','firstname','lastname','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Enduser\x20created.','getEndUser','getchallenge','Account\x20%d\x20is\x20not\x20valid','getConnection','[HTTP]','queue','monitor_format','[QUEUE]','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','uniqueid','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','outbound','stripTrailingSlash','none','[OUTBOUND]','Recording\x20is\x20enabled!','destcalleridname','destcalleridnum','Fields','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','split','unmanaged','toUpperCase','lastevent','lodash','request-promise','md5','util','ioredis','./util','../../../../config/logger','redis','defaults','localhost','socket.io-emitter','emit','length','includes','string','picklist','type','idField','content','toString','variable','variableName','customVariable','Variable','toLowerCase','name','info','Creating\x20new\x20ticket...','merge','Normal','Open','Subjects','getString','Descriptions','POST','format','%s/webservice.php','create'];(function(_0x2b355f,_0x4b5758){var _0x3ae502=function(_0x3c3bc9){while(--_0x3c3bc9){_0x2b355f['push'](_0x2b355f['shift']());}};_0x3ae502(++_0x4b5758);}(_0x0c99,0xac));var _0x90c9=function(_0x5c2e3e,_0x26ecd3){_0x5c2e3e=_0x5c2e3e-0x0;var _0x53f64a=_0x0c99[_0x5c2e3e];return _0x53f64a;};'use strict';var _=require(_0x90c9('0x0'));var rp=require(_0x90c9('0x1'));var BPromise=require('bluebird');var md5=require(_0x90c9('0x2'));var util=require(_0x90c9('0x3'));var Redis=require(_0x90c9('0x4'));var intUtil=require(_0x90c9('0x5'));var config=require('../../../../config/environment');var logger=require(_0x90c9('0x6'))('vTiger');config[_0x90c9('0x7')]=_[_0x90c9('0x8')](config['redis'],{'host':_0x90c9('0x9'),'port':0x18eb});var io=require(_0x90c9('0xa'))(new Redis(config[_0x90c9('0x7')]));function emit(_0x240566,_0x3012b0,_0x5e14ae){io['to'](_0x240566)[_0x90c9('0xb')](_0x3012b0,_0x5e14ae);}function getCustomFields(_0xcedb4d,_0x48b6b8){var _0x3347f4={};if(_0xcedb4d[_0x90c9('0xc')]>0x0){_['forEach'](_0xcedb4d,function(_0x3610c9){if(_[_0x90c9('0xd')]([_0x90c9('0xe'),_0x90c9('0xf')],_0x3610c9[_0x90c9('0x10')])&&_0x3610c9[_0x90c9('0x11')]){_0x3347f4[_0x3610c9[_0x90c9('0x11')]]=_0x3610c9[_0x90c9('0x12')][_0x90c9('0x13')]();}else if(_0x3610c9[_0x90c9('0x10')]===_0x90c9('0x14')&&_0x3610c9[_0x90c9('0x15')]&&_0x3610c9[_0x90c9('0x11')]&&_0x48b6b8[_0x3610c9[_0x90c9('0x15')]]){_0x3347f4[_0x3610c9[_0x90c9('0x11')]]=_0x48b6b8[_0x3610c9['variableName']][_0x90c9('0x13')]();}else if(_0x3610c9[_0x90c9('0x10')]===_0x90c9('0x16')&&_0x3610c9[_0x90c9('0x17')]&&_0x3610c9['Variable']['name']&&_0x3610c9['idField']&&_0x48b6b8[_0x3610c9[_0x90c9('0x17')]['name'][_0x90c9('0x18')]()]){_0x3347f4[_0x3610c9[_0x90c9('0x11')]]=_0x48b6b8[_0x3610c9[_0x90c9('0x17')][_0x90c9('0x19')][_0x90c9('0x18')]()]['toString']();}});}return _0x3347f4;}function createTicket(_0x3c47ee,_0x3e6c0c,_0x204e18,_0x4a5829,_0x576d74,_0x1df2c2,_0x51b2b4){logger[_0x90c9('0x1a')](_0x90c9('0x1b'));var _0x4ac474=_[_0x90c9('0x1c')]({'parent_id':'','assigned_user_id':_0x3e6c0c['id'],'ticketpriorities':_0x90c9('0x1d'),'ticketstatus':_0x90c9('0x1e'),'ticket_title':intUtil['getString'](_0x4a5829[_0x90c9('0x1f')],_0x576d74,'\x20'),'description':intUtil[_0x90c9('0x20')](_0x4a5829[_0x90c9('0x21')],_0x576d74,'\x0a'),'contact_id':_0x204e18['id']},getCustomFields(_0x1df2c2,_0x576d74));var _0x90dcf9={'method':_0x90c9('0x22'),'uri':util[_0x90c9('0x23')](_0x90c9('0x24'),_0x3c47ee['remoteUri']),'form':{'operation':_0x90c9('0x25'),'username':_0x3c47ee[_0x90c9('0x26')],'sessionName':_0x51b2b4[_0x90c9('0x27')],'elementType':_0x90c9('0x28'),'element':JSON['stringify'](_0x4ac474)},'json':!![]};return request(_0x90dcf9)[_0x90c9('0x29')](function(_0x402d50){if(_0x402d50[_0x90c9('0x2a')]){return BPromise['resolve']({'id':_0x402d50['result']['id']});}else{throw new Error(util[_0x90c9('0x23')]('Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s',JSON[_0x90c9('0x2b')](_0x402d50[_0x90c9('0x2c')])));}})[_0x90c9('0x2d')](function(_0x205348){var _0x154721=_0x205348[_0x90c9('0x2e')]||0x1f4;logger[_0x90c9('0x2c')](_0x90c9('0x2f'),_0x90c9('0x30'),_0x154721,JSON[_0x90c9('0x2b')](_0x205348));});}function getUser(_0x4995a3,_0x53dbee,_0x5a71bb){if(intUtil[_0x90c9('0x31')](_0x53dbee)){logger['info']('Getting\x20agent\x20with\x20email',_0x53dbee);return request({'method':_0x90c9('0x32'),'uri':util[_0x90c9('0x23')](_0x90c9('0x24'),_0x4995a3[_0x90c9('0x33')]),'qs':{'operation':'query','username':_0x4995a3[_0x90c9('0x26')],'sessionName':_0x5a71bb[_0x90c9('0x27')],'query':util[_0x90c9('0x23')](_0x90c9('0x34'),_0x53dbee)},'json':!![]})[_0x90c9('0x29')](function(_0x37f08f){if(_0x37f08f['success']&&_0x37f08f[_0x90c9('0x35')][_0x90c9('0xc')]){logger['info'](_0x90c9('0x36'));return BPromise[_0x90c9('0x37')]({'id':_0x37f08f[_0x90c9('0x35')][0x0]['id'],'email':_0x37f08f[_0x90c9('0x35')][0x0][_0x90c9('0x38')],'name':_0x37f08f[_0x90c9('0x35')][0x0][_0x90c9('0x39')]+'\x20'+_0x37f08f[_0x90c9('0x35')][_0x90c9('0x3a')]});}else{logger[_0x90c9('0x1a')](_0x90c9('0x3b'));return BPromise[_0x90c9('0x37')]({'id':_0x5a71bb[_0x90c9('0x3c')],'email':_0x4995a3[_0x90c9('0x26')],'name':'admin'});}})[_0x90c9('0x2d')](function(_0x1aaee5){var _0x56a53d=_0x1aaee5[_0x90c9('0x2e')]||0x1f4;logger[_0x90c9('0x2c')]('[vTiger],\x20%s,\x20%s,\x20%s','getUser',_0x56a53d,JSON[_0x90c9('0x2b')](_0x1aaee5));});}else{logger['info'](_0x90c9('0x3b'));return BPromise['resolve']({'id':_0x5a71bb[_0x90c9('0x3c')],'email':_0x4995a3[_0x90c9('0x26')],'name':_0x90c9('0x3d')})[_0x90c9('0x2d')](function(_0x1a3de3){var _0x22ae52=_0x1a3de3[_0x90c9('0x2e')]||0x1f4;logger[_0x90c9('0x2c')](_0x90c9('0x2f'),_0x90c9('0x3e'),_0x22ae52,JSON[_0x90c9('0x2b')](_0x1a3de3));});}}function getEndUser(_0x41b7bf,_0x41aff3,_0x34cc31,_0x51787e){logger[_0x90c9('0x1a')](_0x90c9('0x3f'),_0x34cc31);return request({'method':_0x90c9('0x32'),'uri':util[_0x90c9('0x23')](_0x90c9('0x24'),_0x41b7bf[_0x90c9('0x33')]),'qs':{'operation':_0x90c9('0x40'),'username':_0x41b7bf['username'],'sessionName':_0x51787e[_0x90c9('0x27')],'query':util['format'](_0x90c9('0x41'),_0x34cc31,_0x34cc31,_0x34cc31,_0x34cc31,_0x34cc31)},'json':!![]})[_0x90c9('0x29')](function(_0x1a01bf){if(_0x1a01bf['success']&&_0x1a01bf[_0x90c9('0x35')][_0x90c9('0xc')]){logger['info']('Enduser\x20found!');return BPromise[_0x90c9('0x37')]({'id':_0x1a01bf[_0x90c9('0x35')][0x0]['id'],'name':_0x1a01bf[_0x90c9('0x35')][0x0][_0x90c9('0x42')]+'\x20'+_0x1a01bf[_0x90c9('0x35')][0x0][_0x90c9('0x43')],'phone':_0x34cc31});}else{logger['info'](_0x90c9('0x44'));return request({'method':_0x90c9('0x22'),'uri':util[_0x90c9('0x23')](_0x90c9('0x24'),_0x41b7bf[_0x90c9('0x33')]),'form':{'operation':'create','sessionName':_0x51787e[_0x90c9('0x27')],'elementType':'Contacts','element':JSON[_0x90c9('0x2b')]({'lastname':_0x41aff3,'phone':_0x34cc31,'assigned_user_id':'\x20'})},'json':!![]})[_0x90c9('0x29')](function(_0x467230){logger['info'](_0x90c9('0x45'));return BPromise[_0x90c9('0x37')]({'id':_0x467230[_0x90c9('0x35')]['id'],'name':_0x467230[_0x90c9('0x35')][_0x90c9('0x43')],'phone':_0x467230[_0x90c9('0x35')]['phone']});})[_0x90c9('0x2d')](function(_0x2a057d){var _0x969b15=_0x2a057d[_0x90c9('0x2e')]||0x1f4;logger[_0x90c9('0x2c')](_0x90c9('0x2f'),_0x90c9('0x46'),_0x969b15,JSON['stringify'](_0x2a057d));});}});}function getConnection(_0x492ba3){var _0x1cfbcc=_0x492ba3[_0x90c9('0x26')];var _0x485a77=_0x492ba3['accessKey'];return request({'method':_0x90c9('0x32'),'uri':util['format'](_0x90c9('0x24'),_0x492ba3['remoteUri']),'qs':{'operation':_0x90c9('0x47'),'username':_0x1cfbcc},'json':!![]})[_0x90c9('0x29')](function(_0x30d7fc){if(_0x30d7fc[_0x90c9('0x2a')]){return request({'method':'POST','uri':util[_0x90c9('0x23')](_0x90c9('0x24'),_0x492ba3['remoteUri']),'form':{'operation':'login','username':_0x1cfbcc,'accessKey':md5(_0x30d7fc[_0x90c9('0x35')]['token']+_0x485a77)},'json':!![]});}})[_0x90c9('0x29')](function(_0x3bf3aa){if(_0x3bf3aa[_0x90c9('0x2a')]){return BPromise['resolve'](_0x3bf3aa[_0x90c9('0x35')]);}else{throw new Error(util[_0x90c9('0x23')](_0x90c9('0x48'),_0x492ba3['id']));}})[_0x90c9('0x2d')](function(_0x573277){var _0x3b334d=_0x573277[_0x90c9('0x2e')]||0x1f4;logger[_0x90c9('0x2c')](_0x90c9('0x2f'),_0x90c9('0x49'),_0x3b334d,JSON[_0x90c9('0x2b')](_0x573277));});}function request(_0x46d5a4){logger['info'](_0x90c9('0x4a'),JSON['stringify'](_0x46d5a4));return rp(_0x46d5a4);}exports[_0x90c9('0x4b')]=function(_0x305009,_0xb68629,_0x37efb8,_0x18994f,_0x1fae30,_0x2b1973){var _0x855c55,_0x8df133,_0x5c044c,_0x573b06;_0x2b1973[_0x90c9('0x33')]=intUtil['stripTrailingSlash'](_0x2b1973[_0x90c9('0x33')]);if(_0x1fae30&&_0x1fae30[_0x90c9('0x4c')]){logger[_0x90c9('0x1a')](_0x90c9('0x4d'),'Recording\x20is\x20enabled!');_0xb68629[_0x90c9('0x4e')]=util[_0x90c9('0x23')](_0x90c9('0x4f'),_0x2b1973[_0x90c9('0x50')],_0xb68629[_0x90c9('0x51')],md5(_0xb68629[_0x90c9('0x51')]));}else{_0xb68629[_0x90c9('0x4e')]='';}return getConnection(_0x2b1973)[_0x90c9('0x29')](function(_0x436e47){_0x573b06=_0x436e47;return getUser(_0x2b1973,_0x18994f[_0x90c9('0x52')],_0x573b06);})[_0x90c9('0x29')](function(_0x3805be){_0x855c55=_0x3805be;logger[_0x90c9('0x1a')](_0x90c9('0x53'),_0x855c55['id']);return getEndUser(_0x2b1973,_0xb68629[_0x90c9('0x54')],_0xb68629[_0x90c9('0x55')],_0x573b06);})[_0x90c9('0x29')](function(_0x17ce9d){_0x8df133=_0x17ce9d;logger[_0x90c9('0x1a')](_0x90c9('0x56'),_0x8df133['id']);return createTicket(_0x2b1973,_0x855c55,_0x8df133,_0x37efb8,_0xb68629,_0x37efb8['Fields'],_0x573b06);})[_0x90c9('0x29')](function(_0xa70a3b){_0x5c044c=_0xa70a3b;logger[_0x90c9('0x1a')](_0x90c9('0x57'));logger[_0x90c9('0x1a')](_0x90c9('0x58'),_0x5c044c['id']);var _0x165088=util[_0x90c9('0x23')]('%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT',_0x2b1973[_0x90c9('0x33')],_['split'](_0x5c044c['id'],'x')[0x1]);logger['info']('[QUEUE]',_0x90c9('0x59'));emit(util[_0x90c9('0x23')](_0x90c9('0x5a'),_0x18994f[_0x90c9('0x19')]),_0x90c9('0x5b'),{'uri':_0x165088});})[_0x90c9('0x2d')](function(_0x535d1b){logger[_0x90c9('0x2c')](_0x90c9('0x4d'),JSON['stringify'](_0x535d1b));});};exports[_0x90c9('0x5c')]=function(_0x33cf61,_0x120c80,_0x3df4aa,_0x2065a4,_0x25ab91,_0x555275,_0x25dceb){var _0x445e12,_0x442dea,_0x322540,_0x3912bf;_0x555275[_0x90c9('0x33')]=intUtil[_0x90c9('0x5d')](_0x555275[_0x90c9('0x33')]);_0x555275[_0x90c9('0x50')]=intUtil['stripTrailingSlash'](_0x555275[_0x90c9('0x50')]);if(_0x25dceb&&_0x25dceb['recordingFormat']&&_0x25dceb['recordingFormat']!==_0x90c9('0x5e')){logger['info'](_0x90c9('0x5f'),_0x90c9('0x60'));_0x120c80[_0x90c9('0x4e')]=util[_0x90c9('0x23')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x555275[_0x90c9('0x50')],_0x120c80['uniqueid'],md5(_0x120c80[_0x90c9('0x51')]));}return getConnection(_0x555275)['then'](function(_0x4bd474){_0x3912bf=_0x4bd474;return getUser(_0x555275,_0x2065a4[_0x90c9('0x52')],_0x3912bf);})['then'](function(_0x2b5528){_0x445e12=_0x2b5528;logger[_0x90c9('0x1a')](_0x90c9('0x53'),_0x445e12['id']);return getEndUser(_0x555275,_0x120c80[_0x90c9('0x61')],_0x120c80[_0x90c9('0x62')],_0x3912bf);})[_0x90c9('0x29')](function(_0x51ac10){_0x442dea=_0x51ac10;logger[_0x90c9('0x1a')](_0x90c9('0x56'),_0x442dea['id']);return createTicket(_0x555275,_0x445e12,_0x442dea,_0x3df4aa,_0x120c80,_0x3df4aa[_0x90c9('0x63')],_0x3912bf);})['then'](function(_0x53cc2b){_0x322540=_0x53cc2b;logger['info'](_0x90c9('0x57'));logger[_0x90c9('0x1a')](_0x90c9('0x58'),_0x322540['id']);var _0x943a87=util['format'](_0x90c9('0x64'),_0x555275[_0x90c9('0x33')],_[_0x90c9('0x65')](_0x322540['id'],'x')[0x1]);logger[_0x90c9('0x1a')](_0x90c9('0x5f'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x90c9('0x23')](_0x90c9('0x5a'),_0x2065a4[_0x90c9('0x19')]),_0x90c9('0x5b'),{'uri':_0x943a87});})['catch'](function(_0x374b1e){logger[_0x90c9('0x2c')](_0x90c9('0x5f'),JSON['stringify'](_0x374b1e));});};exports[_0x90c9('0x66')]=function(_0x424281,_0x5ca4ef,_0x4eaf98,_0xa78f77,_0x3c5618,_0x192ffb){var _0x2cf9bb,_0x5f4122,_0xfc6580,_0x4034fb;_0x192ffb[_0x90c9('0x33')]=intUtil[_0x90c9('0x5d')](_0x192ffb[_0x90c9('0x33')]);_0x192ffb[_0x90c9('0x50')]=intUtil['stripTrailingSlash'](_0x192ffb[_0x90c9('0x50')]);if(_0x3c5618&&_0x3c5618['monitor_format']){logger[_0x90c9('0x1a')]('['+_0x5ca4ef['lastevent'][_0x90c9('0x67')]()+']',_0x90c9('0x60'));_0x5ca4ef[_0x90c9('0x4e')]=util[_0x90c9('0x23')](_0x90c9('0x4f'),_0x192ffb[_0x90c9('0x50')],_0x5ca4ef[_0x90c9('0x51')],md5(_0x5ca4ef[_0x90c9('0x51')]));}else{_0x5ca4ef[_0x90c9('0x4e')]='';}return getConnection(_0x192ffb)['then'](function(_0x20ecac){_0x4034fb=_0x20ecac;return getUser(_0x192ffb,'',_0x4034fb);})['then'](function(_0x56948f){_0x2cf9bb=_0x56948f;logger[_0x90c9('0x1a')](_0x90c9('0x53'),_0x2cf9bb['id']);return getEndUser(_0x192ffb,_0x5ca4ef[_0x90c9('0x54')],_0x5ca4ef[_0x90c9('0x55')],_0x4034fb);})['then'](function(_0xd93f81){_0x5f4122=_0xd93f81;logger[_0x90c9('0x1a')](_0x90c9('0x56'),_0x5f4122['id']);return createTicket(_0x192ffb,_0x2cf9bb,_0x5f4122,_0x4eaf98,_0x5ca4ef,_0x4eaf98[_0x90c9('0x63')],_0x4034fb);})[_0x90c9('0x29')](function(_0x53e6e8){_0xfc6580=_0x53e6e8;logger[_0x90c9('0x1a')](_0x90c9('0x57'));logger[_0x90c9('0x1a')]('The\x20Ticket\x20ID\x20is:',_0xfc6580['id']);})[_0x90c9('0x2d')](function(_0x3e3c40){logger[_0x90c9('0x2c')]('['+_0x5ca4ef[_0x90c9('0x68')][_0x90c9('0x67')]()+']',JSON[_0x90c9('0x2b')](_0x3e3c40));});};
\ No newline at end of file
+var _0xa9e0=['variable','variableName','customVariable','Variable','name','toLowerCase','info','Creating\x20new\x20ticket...','Normal','Open','Subjects','POST','format','%s/webservice.php','create','username','sessionName','HelpDesk','stringify','then','result','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','catch','error','[vTiger],\x20%s,\x20%s,\x20%s','createTicket','validateEmail','Getting\x20agent\x20with\x20email','GET','query','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','success','resolve','email1','last_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userId','admin','statusCode','getUser','Searching\x20end\x20user\x20with\x20phone','remoteUri','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','getchallenge','login','token','Account\x20%d\x20is\x20not\x20valid','[HTTP]','queue','stripTrailingSlash','[QUEUE]','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','uniqueid','The\x20User\x20ID\x20is:','calleridnum','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','outbound','recordingFormat','none','[OUTBOUND]','destcalleridname','The\x20Enduser\x20ID\x20is:','Fields','split','trigger:browser:url','unmanaged','monitor_format','toUpperCase','calleridname','lastevent','lodash','request-promise','bluebird','ioredis','../../../../config/environment','../../../../config/logger','vTiger','redis','defaults','localhost','socket.io-emitter','length','forEach','includes','idField','content','toString','type'];(function(_0x1d1779,_0x284147){var _0x2377e9=function(_0x299f6f){while(--_0x299f6f){_0x1d1779['push'](_0x1d1779['shift']());}};_0x2377e9(++_0x284147);}(_0xa9e0,0x123));var _0x0a9e=function(_0xf0bcac,_0x531755){_0xf0bcac=_0xf0bcac-0x0;var _0x4e4c65=_0xa9e0[_0xf0bcac];return _0x4e4c65;};'use strict';var _=require(_0x0a9e('0x0'));var rp=require(_0x0a9e('0x1'));var BPromise=require(_0x0a9e('0x2'));var md5=require('md5');var util=require('util');var Redis=require(_0x0a9e('0x3'));var intUtil=require('./util');var config=require(_0x0a9e('0x4'));var logger=require(_0x0a9e('0x5'))(_0x0a9e('0x6'));config[_0x0a9e('0x7')]=_[_0x0a9e('0x8')](config['redis'],{'host':_0x0a9e('0x9'),'port':0x18eb});var io=require(_0x0a9e('0xa'))(new Redis(config[_0x0a9e('0x7')]));function emit(_0x5f41ea,_0x503809,_0xe42b77){io['to'](_0x5f41ea)['emit'](_0x503809,_0xe42b77);}function getCustomFields(_0x52cace,_0x39753a){var _0xf81284={};if(_0x52cace[_0x0a9e('0xb')]>0x0){_[_0x0a9e('0xc')](_0x52cace,function(_0xfeb75b){if(_[_0x0a9e('0xd')](['string','picklist'],_0xfeb75b['type'])&&_0xfeb75b['idField']){_0xf81284[_0xfeb75b[_0x0a9e('0xe')]]=_0xfeb75b[_0x0a9e('0xf')][_0x0a9e('0x10')]();}else if(_0xfeb75b[_0x0a9e('0x11')]===_0x0a9e('0x12')&&_0xfeb75b[_0x0a9e('0x13')]&&_0xfeb75b['idField']&&_0x39753a[_0xfeb75b[_0x0a9e('0x13')]]){_0xf81284[_0xfeb75b[_0x0a9e('0xe')]]=_0x39753a[_0xfeb75b[_0x0a9e('0x13')]][_0x0a9e('0x10')]();}else if(_0xfeb75b[_0x0a9e('0x11')]===_0x0a9e('0x14')&&_0xfeb75b['Variable']&&_0xfeb75b[_0x0a9e('0x15')]['name']&&_0xfeb75b[_0x0a9e('0xe')]&&_0x39753a[_0xfeb75b['Variable'][_0x0a9e('0x16')][_0x0a9e('0x17')]()]){_0xf81284[_0xfeb75b['idField']]=_0x39753a[_0xfeb75b[_0x0a9e('0x15')]['name'][_0x0a9e('0x17')]()][_0x0a9e('0x10')]();}});}return _0xf81284;}function createTicket(_0x106033,_0x205fd6,_0x31b1ca,_0x2eb11f,_0x530eb7,_0x20559e,_0x1314ae){logger[_0x0a9e('0x18')](_0x0a9e('0x19'));var _0x105080=_['merge']({'parent_id':'','assigned_user_id':_0x205fd6['id'],'ticketpriorities':_0x0a9e('0x1a'),'ticketstatus':_0x0a9e('0x1b'),'ticket_title':intUtil['getString'](_0x2eb11f[_0x0a9e('0x1c')],_0x530eb7,'\x20'),'description':intUtil['getString'](_0x2eb11f['Descriptions'],_0x530eb7,'\x0a'),'contact_id':_0x31b1ca['id']},getCustomFields(_0x20559e,_0x530eb7));var _0x3a02e1={'method':_0x0a9e('0x1d'),'uri':util[_0x0a9e('0x1e')](_0x0a9e('0x1f'),_0x106033['remoteUri']),'form':{'operation':_0x0a9e('0x20'),'username':_0x106033[_0x0a9e('0x21')],'sessionName':_0x1314ae[_0x0a9e('0x22')],'elementType':_0x0a9e('0x23'),'element':JSON[_0x0a9e('0x24')](_0x105080)},'json':!![]};return request(_0x3a02e1)[_0x0a9e('0x25')](function(_0x16b1ca){if(_0x16b1ca['success']){return BPromise['resolve']({'id':_0x16b1ca[_0x0a9e('0x26')]['id']});}else{throw new Error(util[_0x0a9e('0x1e')](_0x0a9e('0x27'),JSON[_0x0a9e('0x24')](_0x16b1ca['error'])));}})[_0x0a9e('0x28')](function(_0x479bc4){var _0x45a1e7=_0x479bc4['statusCode']||0x1f4;logger[_0x0a9e('0x29')](_0x0a9e('0x2a'),_0x0a9e('0x2b'),_0x45a1e7,JSON[_0x0a9e('0x24')](_0x479bc4));});}function getUser(_0x140511,_0x1538a4,_0x11c3b6){if(intUtil[_0x0a9e('0x2c')](_0x1538a4)){logger['info'](_0x0a9e('0x2d'),_0x1538a4);return request({'method':_0x0a9e('0x2e'),'uri':util[_0x0a9e('0x1e')](_0x0a9e('0x1f'),_0x140511['remoteUri']),'qs':{'operation':_0x0a9e('0x2f'),'username':_0x140511[_0x0a9e('0x21')],'sessionName':_0x11c3b6[_0x0a9e('0x22')],'query':util[_0x0a9e('0x1e')](_0x0a9e('0x30'),_0x1538a4)},'json':!![]})[_0x0a9e('0x25')](function(_0x296f41){if(_0x296f41[_0x0a9e('0x31')]&&_0x296f41[_0x0a9e('0x26')]['length']){logger[_0x0a9e('0x18')]('Agent\x20found!');return BPromise[_0x0a9e('0x32')]({'id':_0x296f41[_0x0a9e('0x26')][0x0]['id'],'email':_0x296f41[_0x0a9e('0x26')][0x0][_0x0a9e('0x33')],'name':_0x296f41[_0x0a9e('0x26')][0x0]['first_name']+'\x20'+_0x296f41[_0x0a9e('0x26')][_0x0a9e('0x34')]});}else{logger[_0x0a9e('0x18')](_0x0a9e('0x35'));return BPromise[_0x0a9e('0x32')]({'id':_0x11c3b6[_0x0a9e('0x36')],'email':_0x140511[_0x0a9e('0x21')],'name':_0x0a9e('0x37')});}})['catch'](function(_0x44295a){var _0x5e7238=_0x44295a[_0x0a9e('0x38')]||0x1f4;logger[_0x0a9e('0x29')](_0x0a9e('0x2a'),_0x0a9e('0x39'),_0x5e7238,JSON['stringify'](_0x44295a));});}else{logger[_0x0a9e('0x18')](_0x0a9e('0x35'));return BPromise[_0x0a9e('0x32')]({'id':_0x11c3b6[_0x0a9e('0x36')],'email':_0x140511['username'],'name':'admin'})[_0x0a9e('0x28')](function(_0x5640eb){var _0x24936a=_0x5640eb[_0x0a9e('0x38')]||0x1f4;logger[_0x0a9e('0x29')](_0x0a9e('0x2a'),'getUser',_0x24936a,JSON[_0x0a9e('0x24')](_0x5640eb));});}}function getEndUser(_0x3bfce8,_0x3cae,_0x533942,_0x1dbf74){logger[_0x0a9e('0x18')](_0x0a9e('0x3a'),_0x533942);return request({'method':'GET','uri':util['format'](_0x0a9e('0x1f'),_0x3bfce8[_0x0a9e('0x3b')]),'qs':{'operation':'query','username':_0x3bfce8[_0x0a9e('0x21')],'sessionName':_0x1dbf74[_0x0a9e('0x22')],'query':util[_0x0a9e('0x1e')](_0x0a9e('0x3c'),_0x533942,_0x533942,_0x533942,_0x533942,_0x533942)},'json':!![]})['then'](function(_0x5a594b){if(_0x5a594b[_0x0a9e('0x31')]&&_0x5a594b[_0x0a9e('0x26')]['length']){logger[_0x0a9e('0x18')](_0x0a9e('0x3d'));return BPromise[_0x0a9e('0x32')]({'id':_0x5a594b['result'][0x0]['id'],'name':_0x5a594b[_0x0a9e('0x26')][0x0][_0x0a9e('0x3e')]+'\x20'+_0x5a594b[_0x0a9e('0x26')][0x0][_0x0a9e('0x3f')],'phone':_0x533942});}else{logger[_0x0a9e('0x18')](_0x0a9e('0x40'));return request({'method':_0x0a9e('0x1d'),'uri':util[_0x0a9e('0x1e')](_0x0a9e('0x1f'),_0x3bfce8[_0x0a9e('0x3b')]),'form':{'operation':_0x0a9e('0x20'),'sessionName':_0x1dbf74[_0x0a9e('0x22')],'elementType':_0x0a9e('0x41'),'element':JSON[_0x0a9e('0x24')]({'lastname':_0x3cae,'phone':_0x533942,'assigned_user_id':'\x20'})},'json':!![]})[_0x0a9e('0x25')](function(_0x4d04c8){logger['info'](_0x0a9e('0x42'));return BPromise[_0x0a9e('0x32')]({'id':_0x4d04c8[_0x0a9e('0x26')]['id'],'name':_0x4d04c8[_0x0a9e('0x26')][_0x0a9e('0x3f')],'phone':_0x4d04c8[_0x0a9e('0x26')][_0x0a9e('0x43')]});})[_0x0a9e('0x28')](function(_0x432fcc){var _0x25c6e6=_0x432fcc[_0x0a9e('0x38')]||0x1f4;logger[_0x0a9e('0x29')]('[vTiger],\x20%s,\x20%s,\x20%s',_0x0a9e('0x44'),_0x25c6e6,JSON[_0x0a9e('0x24')](_0x432fcc));});}});}function getConnection(_0xdd268f){var _0xfbd5ad=_0xdd268f[_0x0a9e('0x21')];var _0xbe9d19=_0xdd268f[_0x0a9e('0x45')];return request({'method':_0x0a9e('0x2e'),'uri':util['format'](_0x0a9e('0x1f'),_0xdd268f['remoteUri']),'qs':{'operation':_0x0a9e('0x46'),'username':_0xfbd5ad},'json':!![]})[_0x0a9e('0x25')](function(_0x8d6dd1){if(_0x8d6dd1['success']){return request({'method':_0x0a9e('0x1d'),'uri':util[_0x0a9e('0x1e')](_0x0a9e('0x1f'),_0xdd268f[_0x0a9e('0x3b')]),'form':{'operation':_0x0a9e('0x47'),'username':_0xfbd5ad,'accessKey':md5(_0x8d6dd1[_0x0a9e('0x26')][_0x0a9e('0x48')]+_0xbe9d19)},'json':!![]});}})['then'](function(_0x13f44d){if(_0x13f44d[_0x0a9e('0x31')]){return BPromise[_0x0a9e('0x32')](_0x13f44d[_0x0a9e('0x26')]);}else{throw new Error(util[_0x0a9e('0x1e')](_0x0a9e('0x49'),_0xdd268f['id']));}})[_0x0a9e('0x28')](function(_0x19383e){var _0x34febd=_0x19383e['statusCode']||0x1f4;logger[_0x0a9e('0x29')](_0x0a9e('0x2a'),'getConnection',_0x34febd,JSON['stringify'](_0x19383e));});}function request(_0x5ddf84){logger[_0x0a9e('0x18')](_0x0a9e('0x4a'),JSON[_0x0a9e('0x24')](_0x5ddf84));return rp(_0x5ddf84);}exports[_0x0a9e('0x4b')]=function(_0x61bb17,_0x30decb,_0x2e5165,_0x375c18,_0x5d38ae,_0x4b1b9f){var _0x53975a,_0x39d77d,_0x204173,_0x14d602;_0x4b1b9f['remoteUri']=intUtil[_0x0a9e('0x4c')](_0x4b1b9f[_0x0a9e('0x3b')]);if(_0x5d38ae&&_0x5d38ae['monitor_format']){logger['info'](_0x0a9e('0x4d'),'Recording\x20is\x20enabled!');_0x30decb[_0x0a9e('0x4e')]=util['format'](_0x0a9e('0x4f'),_0x4b1b9f[_0x0a9e('0x50')],_0x30decb[_0x0a9e('0x51')],md5(_0x30decb['uniqueid']));}else{_0x30decb[_0x0a9e('0x4e')]='';}return getConnection(_0x4b1b9f)[_0x0a9e('0x25')](function(_0x508b47){_0x14d602=_0x508b47;return getUser(_0x4b1b9f,_0x375c18['email'],_0x14d602);})[_0x0a9e('0x25')](function(_0x3aedd0){_0x53975a=_0x3aedd0;logger['info'](_0x0a9e('0x52'),_0x53975a['id']);return getEndUser(_0x4b1b9f,_0x30decb['calleridname'],_0x30decb[_0x0a9e('0x53')],_0x14d602);})['then'](function(_0xe22ccc){_0x39d77d=_0xe22ccc;logger['info']('The\x20Enduser\x20ID\x20is:',_0x39d77d['id']);return createTicket(_0x4b1b9f,_0x53975a,_0x39d77d,_0x2e5165,_0x30decb,_0x2e5165['Fields'],_0x14d602);})[_0x0a9e('0x25')](function(_0x47de4c){_0x204173=_0x47de4c;logger[_0x0a9e('0x18')](_0x0a9e('0x54'));logger[_0x0a9e('0x18')](_0x0a9e('0x55'),_0x204173['id']);var _0x232830=util[_0x0a9e('0x1e')](_0x0a9e('0x56'),_0x4b1b9f[_0x0a9e('0x3b')],_['split'](_0x204173['id'],'x')[0x1]);logger[_0x0a9e('0x18')](_0x0a9e('0x4d'),_0x0a9e('0x57'));emit(util[_0x0a9e('0x1e')](_0x0a9e('0x58'),_0x375c18[_0x0a9e('0x16')]),'trigger:browser:url',{'uri':_0x232830});})[_0x0a9e('0x28')](function(_0x26bc80){logger['error'](_0x0a9e('0x4d'),JSON['stringify'](_0x26bc80));});};exports[_0x0a9e('0x59')]=function(_0x5ba1f9,_0x4b3c1a,_0x5674ee,_0x273cb5,_0x49d231,_0x2244d6,_0x1fc70e){var _0x261adb,_0x7be420,_0x1cca9f,_0x26d7db;_0x2244d6['remoteUri']=intUtil[_0x0a9e('0x4c')](_0x2244d6['remoteUri']);_0x2244d6[_0x0a9e('0x50')]=intUtil[_0x0a9e('0x4c')](_0x2244d6[_0x0a9e('0x50')]);if(_0x1fc70e&&_0x1fc70e['recordingFormat']&&_0x1fc70e[_0x0a9e('0x5a')]!==_0x0a9e('0x5b')){logger[_0x0a9e('0x18')](_0x0a9e('0x5c'),'Recording\x20is\x20enabled!');_0x4b3c1a[_0x0a9e('0x4e')]=util[_0x0a9e('0x1e')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2244d6[_0x0a9e('0x50')],_0x4b3c1a[_0x0a9e('0x51')],md5(_0x4b3c1a[_0x0a9e('0x51')]));}return getConnection(_0x2244d6)[_0x0a9e('0x25')](function(_0x401837){_0x26d7db=_0x401837;return getUser(_0x2244d6,_0x273cb5['email'],_0x26d7db);})[_0x0a9e('0x25')](function(_0x2937e0){_0x261adb=_0x2937e0;logger[_0x0a9e('0x18')]('The\x20User\x20ID\x20is:',_0x261adb['id']);return getEndUser(_0x2244d6,_0x4b3c1a[_0x0a9e('0x5d')],_0x4b3c1a['destcalleridnum'],_0x26d7db);})['then'](function(_0x242745){_0x7be420=_0x242745;logger[_0x0a9e('0x18')](_0x0a9e('0x5e'),_0x7be420['id']);return createTicket(_0x2244d6,_0x261adb,_0x7be420,_0x5674ee,_0x4b3c1a,_0x5674ee[_0x0a9e('0x5f')],_0x26d7db);})[_0x0a9e('0x25')](function(_0xc8c264){_0x1cca9f=_0xc8c264;logger[_0x0a9e('0x18')](_0x0a9e('0x54'));logger[_0x0a9e('0x18')](_0x0a9e('0x55'),_0x1cca9f['id']);var _0x2e89b7=util[_0x0a9e('0x1e')](_0x0a9e('0x56'),_0x2244d6[_0x0a9e('0x3b')],_[_0x0a9e('0x60')](_0x1cca9f['id'],'x')[0x1]);logger[_0x0a9e('0x18')](_0x0a9e('0x5c'),_0x0a9e('0x57'));emit(util['format'](_0x0a9e('0x58'),_0x273cb5[_0x0a9e('0x16')]),_0x0a9e('0x61'),{'uri':_0x2e89b7});})['catch'](function(_0x1148a1){logger[_0x0a9e('0x29')]('[OUTBOUND]',JSON[_0x0a9e('0x24')](_0x1148a1));});};exports[_0x0a9e('0x62')]=function(_0x3ef315,_0x427946,_0x13b5c0,_0x4a43a8,_0x50cdce,_0x4a2438){var _0x40fb85,_0x18bf5d,_0x1104ad,_0x23a7d3;_0x4a2438[_0x0a9e('0x3b')]=intUtil[_0x0a9e('0x4c')](_0x4a2438[_0x0a9e('0x3b')]);_0x4a2438[_0x0a9e('0x50')]=intUtil['stripTrailingSlash'](_0x4a2438[_0x0a9e('0x50')]);if(_0x50cdce&&_0x50cdce[_0x0a9e('0x63')]){logger[_0x0a9e('0x18')]('['+_0x427946['lastevent'][_0x0a9e('0x64')]()+']','Recording\x20is\x20enabled!');_0x427946[_0x0a9e('0x4e')]=util[_0x0a9e('0x1e')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x4a2438[_0x0a9e('0x50')],_0x427946[_0x0a9e('0x51')],md5(_0x427946[_0x0a9e('0x51')]));}else{_0x427946[_0x0a9e('0x4e')]='';}return getConnection(_0x4a2438)['then'](function(_0x1d442c){_0x23a7d3=_0x1d442c;return getUser(_0x4a2438,'',_0x23a7d3);})[_0x0a9e('0x25')](function(_0x371533){_0x40fb85=_0x371533;logger[_0x0a9e('0x18')]('The\x20User\x20ID\x20is:',_0x40fb85['id']);return getEndUser(_0x4a2438,_0x427946[_0x0a9e('0x65')],_0x427946[_0x0a9e('0x53')],_0x23a7d3);})[_0x0a9e('0x25')](function(_0x361b21){_0x18bf5d=_0x361b21;logger['info'](_0x0a9e('0x5e'),_0x18bf5d['id']);return createTicket(_0x4a2438,_0x40fb85,_0x18bf5d,_0x13b5c0,_0x427946,_0x13b5c0[_0x0a9e('0x5f')],_0x23a7d3);})[_0x0a9e('0x25')](function(_0xf410e5){_0x1104ad=_0xf410e5;logger[_0x0a9e('0x18')](_0x0a9e('0x54'));logger[_0x0a9e('0x18')](_0x0a9e('0x55'),_0x1104ad['id']);})[_0x0a9e('0x28')](function(_0x336dc3){logger[_0x0a9e('0x29')]('['+_0x427946[_0x0a9e('0x66')][_0x0a9e('0x64')]()+']',JSON[_0x0a9e('0x24')](_0x336dc3));});};
\ No newline at end of file