Built motion from commit (unavailable).|2.5.25
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index 2db7b5d..929a5d8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2b78=['POST','format','%s/webservice.php','remoteUri','create','username','sessionName','stringify','success','resolve','result','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','error','catch','statusCode','[vTiger],\x20%s,\x20%s,\x20%s','createTicket','validateEmail','info','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','length','Agent\x20found!','email1','first_name','last_name','userId','admin','getUser','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;','then','Enduser\x20found!','firstname','lastname','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Contacts','Enduser\x20created.','getEndUser','accessKey','getchallenge','login','token','Account\x20%d\x20is\x20not\x20valid','getConnection','[HTTP]','queue','stripTrailingSlash','monitor_format','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','split','[QUEUE]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','outbound','recordingFormat','none','uniqueid','destcalleridname','Fields','[OUTBOUND]','trigger:browser:url','unmanaged','lastevent','toUpperCase','lodash','request-promise','bluebird','md5','util','ioredis','./util','vTiger','defaults','redis','localhost','socket.io-emitter','emit','forEach','type','string','idField','content','toString','variable','variableName','customVariable','name','Variable','toLowerCase','Creating\x20new\x20ticket...','merge','getString','Subjects'];(function(_0x14d68d,_0x19141f){var _0x46e9c2=function(_0x2841c4){while(--_0x2841c4){_0x14d68d['push'](_0x14d68d['shift']());}};_0x46e9c2(++_0x19141f);}(_0x2b78,0x118));var _0x82b7=function(_0xb60674,_0xa4e08a){_0xb60674=_0xb60674-0x0;var _0x2514a0=_0x2b78[_0xb60674];return _0x2514a0;};'use strict';var _=require(_0x82b7('0x0'));var rp=require(_0x82b7('0x1'));var BPromise=require(_0x82b7('0x2'));var md5=require(_0x82b7('0x3'));var util=require(_0x82b7('0x4'));var Redis=require(_0x82b7('0x5'));var intUtil=require(_0x82b7('0x6'));var config=require('../../../../config/environment');var logger=require('../../../../config/logger')(_0x82b7('0x7'));config['redis']=_[_0x82b7('0x8')](config[_0x82b7('0x9')],{'host':_0x82b7('0xa'),'port':0x18eb});var io=require(_0x82b7('0xb'))(new Redis(config['redis']));function emit(_0x5408a3,_0xa7ff98,_0x45fb41){io['to'](_0x5408a3)[_0x82b7('0xc')](_0xa7ff98,_0x45fb41);}function getCustomFields(_0xf1119,_0x3c80f6){var _0xec7387={};if(_0xf1119['length']>0x0){_[_0x82b7('0xd')](_0xf1119,function(_0x14575a){if(_0x14575a[_0x82b7('0xe')]===_0x82b7('0xf')&&_0x14575a['idField']){_0xec7387[_0x14575a[_0x82b7('0x10')]]=_0x14575a[_0x82b7('0x11')][_0x82b7('0x12')]();}else if(_0x14575a['type']===_0x82b7('0x13')&&_0x14575a[_0x82b7('0x14')]&&_0x14575a[_0x82b7('0x10')]&&_0x3c80f6[_0x14575a['variableName']]){_0xec7387[_0x14575a['idField']]=_0x3c80f6[_0x14575a[_0x82b7('0x14')]][_0x82b7('0x12')]();}else if(_0x14575a[_0x82b7('0xe')]===_0x82b7('0x15')&&_0x14575a['Variable']&&_0x14575a['Variable'][_0x82b7('0x16')]&&_0x14575a[_0x82b7('0x10')]&&_0x3c80f6[_0x14575a[_0x82b7('0x17')]['name'][_0x82b7('0x18')]()]){_0xec7387[_0x14575a[_0x82b7('0x10')]]=_0x3c80f6[_0x14575a[_0x82b7('0x17')][_0x82b7('0x16')]['toLowerCase']()][_0x82b7('0x12')]();}});}return _0xec7387;}function createTicket(_0x29b93b,_0x5d6843,_0x4049f1,_0x21138f,_0x27ce07,_0x4f9182,_0xcb4f1f){logger['info'](_0x82b7('0x19'));var _0x36cb6f=_[_0x82b7('0x1a')]({'parent_id':'','assigned_user_id':_0x5d6843['id'],'ticketpriorities':'Normal','ticketstatus':'Open','ticket_title':intUtil[_0x82b7('0x1b')](_0x21138f[_0x82b7('0x1c')],_0x27ce07,'\x20'),'description':intUtil[_0x82b7('0x1b')](_0x21138f['Descriptions'],_0x27ce07,'\x0a'),'contact_id':_0x4049f1['id']},getCustomFields(_0x4f9182,_0x27ce07));var _0x4d0bc2={'method':_0x82b7('0x1d'),'uri':util[_0x82b7('0x1e')](_0x82b7('0x1f'),_0x29b93b[_0x82b7('0x20')]),'form':{'operation':_0x82b7('0x21'),'username':_0x29b93b[_0x82b7('0x22')],'sessionName':_0xcb4f1f[_0x82b7('0x23')],'elementType':'HelpDesk','element':JSON[_0x82b7('0x24')](_0x36cb6f)},'json':!![]};return request(_0x4d0bc2)['then'](function(_0x15ce8e){if(_0x15ce8e[_0x82b7('0x25')]){return BPromise[_0x82b7('0x26')]({'id':_0x15ce8e[_0x82b7('0x27')]['id']});}else{throw new Error(util[_0x82b7('0x1e')](_0x82b7('0x28'),JSON['stringify'](_0x15ce8e[_0x82b7('0x29')])));}})[_0x82b7('0x2a')](function(_0x98c94){var _0x55ae2e=_0x98c94[_0x82b7('0x2b')]||0x1f4;logger[_0x82b7('0x29')](_0x82b7('0x2c'),_0x82b7('0x2d'),_0x55ae2e,JSON[_0x82b7('0x24')](_0x98c94));});}function getUser(_0xbb3d57,_0x5dd45d,_0x1bc927){if(intUtil[_0x82b7('0x2e')](_0x5dd45d)){logger[_0x82b7('0x2f')]('Getting\x20agent\x20with\x20email',_0x5dd45d);return request({'method':'GET','uri':util[_0x82b7('0x1e')](_0x82b7('0x1f'),_0xbb3d57[_0x82b7('0x20')]),'qs':{'operation':'query','username':_0xbb3d57[_0x82b7('0x22')],'sessionName':_0x1bc927[_0x82b7('0x23')],'query':util[_0x82b7('0x1e')](_0x82b7('0x30'),_0x5dd45d)},'json':!![]})['then'](function(_0x5fe5cb){if(_0x5fe5cb[_0x82b7('0x25')]&&_0x5fe5cb[_0x82b7('0x27')][_0x82b7('0x31')]){logger[_0x82b7('0x2f')](_0x82b7('0x32'));return BPromise[_0x82b7('0x26')]({'id':_0x5fe5cb[_0x82b7('0x27')][0x0]['id'],'email':_0x5fe5cb[_0x82b7('0x27')][0x0][_0x82b7('0x33')],'name':_0x5fe5cb['result'][0x0][_0x82b7('0x34')]+'\x20'+_0x5fe5cb[_0x82b7('0x27')][_0x82b7('0x35')]});}else{logger[_0x82b7('0x2f')]('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return BPromise[_0x82b7('0x26')]({'id':_0x1bc927[_0x82b7('0x36')],'email':_0xbb3d57[_0x82b7('0x22')],'name':_0x82b7('0x37')});}})[_0x82b7('0x2a')](function(_0xd3e38f){var _0x1a7b89=_0xd3e38f[_0x82b7('0x2b')]||0x1f4;logger[_0x82b7('0x29')](_0x82b7('0x2c'),_0x82b7('0x38'),_0x1a7b89,JSON['stringify'](_0xd3e38f));});}else{logger['info']('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return BPromise[_0x82b7('0x26')]({'id':_0x1bc927[_0x82b7('0x36')],'email':_0xbb3d57[_0x82b7('0x22')],'name':_0x82b7('0x37')})['catch'](function(_0x41069d){var _0x4e1845=_0x41069d['statusCode']||0x1f4;logger[_0x82b7('0x29')]('[vTiger],\x20%s,\x20%s,\x20%s','getUser',_0x4e1845,JSON[_0x82b7('0x24')](_0x41069d));});}}function getEndUser(_0x4c414e,_0xc2428,_0x295ec2,_0x35002d){logger[_0x82b7('0x2f')]('Searching\x20end\x20user\x20with\x20phone',_0x295ec2);return request({'method':'GET','uri':util[_0x82b7('0x1e')](_0x82b7('0x1f'),_0x4c414e['remoteUri']),'qs':{'operation':'query','username':_0x4c414e[_0x82b7('0x22')],'sessionName':_0x35002d[_0x82b7('0x23')],'query':util[_0x82b7('0x1e')](_0x82b7('0x39'),_0x295ec2,_0x295ec2,_0x295ec2,_0x295ec2,_0x295ec2)},'json':!![]})[_0x82b7('0x3a')](function(_0x201c1c){if(_0x201c1c['success']&&_0x201c1c[_0x82b7('0x27')]['length']){logger[_0x82b7('0x2f')](_0x82b7('0x3b'));return BPromise['resolve']({'id':_0x201c1c[_0x82b7('0x27')][0x0]['id'],'name':_0x201c1c['result'][0x0][_0x82b7('0x3c')]+'\x20'+_0x201c1c[_0x82b7('0x27')][0x0][_0x82b7('0x3d')],'phone':_0x295ec2});}else{logger['info'](_0x82b7('0x3e'));return request({'method':_0x82b7('0x1d'),'uri':util[_0x82b7('0x1e')](_0x82b7('0x1f'),_0x4c414e[_0x82b7('0x20')]),'form':{'operation':_0x82b7('0x21'),'sessionName':_0x35002d[_0x82b7('0x23')],'elementType':_0x82b7('0x3f'),'element':JSON[_0x82b7('0x24')]({'lastname':_0xc2428,'phone':_0x295ec2,'assigned_user_id':'\x20'})},'json':!![]})[_0x82b7('0x3a')](function(_0x14769f){logger[_0x82b7('0x2f')](_0x82b7('0x40'));return BPromise['resolve']({'id':_0x14769f['result']['id'],'name':_0x14769f[_0x82b7('0x27')]['lastname'],'phone':_0x14769f[_0x82b7('0x27')]['phone']});})[_0x82b7('0x2a')](function(_0x163ee4){var _0x3b03f3=_0x163ee4[_0x82b7('0x2b')]||0x1f4;logger[_0x82b7('0x29')](_0x82b7('0x2c'),_0x82b7('0x41'),_0x3b03f3,JSON[_0x82b7('0x24')](_0x163ee4));});}});}function getConnection(_0x168b61){var _0x2f353a=_0x168b61[_0x82b7('0x22')];var _0xf2899d=_0x168b61[_0x82b7('0x42')];return request({'method':'GET','uri':util[_0x82b7('0x1e')](_0x82b7('0x1f'),_0x168b61[_0x82b7('0x20')]),'qs':{'operation':_0x82b7('0x43'),'username':_0x2f353a},'json':!![]})[_0x82b7('0x3a')](function(_0x22a4bf){if(_0x22a4bf[_0x82b7('0x25')]){return request({'method':_0x82b7('0x1d'),'uri':util[_0x82b7('0x1e')](_0x82b7('0x1f'),_0x168b61[_0x82b7('0x20')]),'form':{'operation':_0x82b7('0x44'),'username':_0x2f353a,'accessKey':md5(_0x22a4bf[_0x82b7('0x27')][_0x82b7('0x45')]+_0xf2899d)},'json':!![]});}})[_0x82b7('0x3a')](function(_0x3f049e){if(_0x3f049e[_0x82b7('0x25')]){return BPromise[_0x82b7('0x26')](_0x3f049e[_0x82b7('0x27')]);}else{throw new Error(util[_0x82b7('0x1e')](_0x82b7('0x46'),_0x168b61['id']));}})[_0x82b7('0x2a')](function(_0x50e617){var _0x1644e1=_0x50e617[_0x82b7('0x2b')]||0x1f4;logger[_0x82b7('0x29')](_0x82b7('0x2c'),_0x82b7('0x47'),_0x1644e1,JSON['stringify'](_0x50e617));});}function request(_0x37c6ba){logger[_0x82b7('0x2f')](_0x82b7('0x48'),JSON['stringify'](_0x37c6ba));return rp(_0x37c6ba);}exports[_0x82b7('0x49')]=function(_0x9d87fb,_0x15ad8b,_0x484c3,_0x1503dd,_0x57caf5,_0x33181a){var _0x2f963f,_0x46034a,_0x522671,_0x482392;_0x33181a[_0x82b7('0x20')]=intUtil[_0x82b7('0x4a')](_0x33181a['remoteUri']);if(_0x57caf5&&_0x57caf5[_0x82b7('0x4b')]){logger[_0x82b7('0x2f')]('[QUEUE]',_0x82b7('0x4c'));_0x15ad8b[_0x82b7('0x4d')]=util[_0x82b7('0x1e')](_0x82b7('0x4e'),_0x33181a[_0x82b7('0x4f')],_0x15ad8b['uniqueid'],md5(_0x15ad8b['uniqueid']));}else{_0x15ad8b[_0x82b7('0x4d')]='';}return getConnection(_0x33181a)[_0x82b7('0x3a')](function(_0x171a4e){_0x482392=_0x171a4e;return getUser(_0x33181a,_0x1503dd[_0x82b7('0x50')],_0x482392);})[_0x82b7('0x3a')](function(_0x463bbf){_0x2f963f=_0x463bbf;logger[_0x82b7('0x2f')](_0x82b7('0x51'),_0x2f963f['id']);return getEndUser(_0x33181a,_0x15ad8b[_0x82b7('0x52')],_0x15ad8b[_0x82b7('0x53')],_0x482392);})['then'](function(_0x465078){_0x46034a=_0x465078;logger[_0x82b7('0x2f')](_0x82b7('0x54'),_0x46034a['id']);return createTicket(_0x33181a,_0x2f963f,_0x46034a,_0x484c3,_0x15ad8b,_0x484c3['Fields'],_0x482392);})['then'](function(_0x2d17d2){_0x522671=_0x2d17d2;logger[_0x82b7('0x2f')](_0x82b7('0x55'));logger[_0x82b7('0x2f')](_0x82b7('0x56'),_0x522671['id']);var _0x598f29=util['format'](_0x82b7('0x57'),_0x33181a[_0x82b7('0x20')],_[_0x82b7('0x58')](_0x522671['id'],'x')[0x1]);logger[_0x82b7('0x2f')](_0x82b7('0x59'),_0x82b7('0x5a'));emit(util['format'](_0x82b7('0x5b'),_0x1503dd[_0x82b7('0x16')]),'trigger:browser:url',{'uri':_0x598f29});})[_0x82b7('0x2a')](function(_0x44ba23){logger['error'](_0x82b7('0x59'),JSON[_0x82b7('0x24')](_0x44ba23));});};exports[_0x82b7('0x5c')]=function(_0x352d83,_0x41d23b,_0x1d745d,_0x28f89c,_0x45aca3,_0x4dd49a,_0x2ce831){var _0x4df4a2,_0x4dfb67,_0x2bd9aa,_0x4a286a;_0x4dd49a[_0x82b7('0x20')]=intUtil[_0x82b7('0x4a')](_0x4dd49a['remoteUri']);_0x4dd49a[_0x82b7('0x4f')]=intUtil[_0x82b7('0x4a')](_0x4dd49a[_0x82b7('0x4f')]);if(_0x2ce831&&_0x2ce831['recordingFormat']&&_0x2ce831[_0x82b7('0x5d')]!==_0x82b7('0x5e')){logger[_0x82b7('0x2f')]('[OUTBOUND]',_0x82b7('0x4c'));_0x41d23b['recordingURL']=util[_0x82b7('0x1e')](_0x82b7('0x4e'),_0x4dd49a['serverUrl'],_0x41d23b['uniqueid'],md5(_0x41d23b[_0x82b7('0x5f')]));}return getConnection(_0x4dd49a)['then'](function(_0x3b45de){_0x4a286a=_0x3b45de;return getUser(_0x4dd49a,_0x28f89c[_0x82b7('0x50')],_0x4a286a);})[_0x82b7('0x3a')](function(_0x1d7235){_0x4df4a2=_0x1d7235;logger[_0x82b7('0x2f')]('The\x20User\x20ID\x20is:',_0x4df4a2['id']);return getEndUser(_0x4dd49a,_0x41d23b[_0x82b7('0x60')],_0x41d23b['destcalleridnum'],_0x4a286a);})[_0x82b7('0x3a')](function(_0x553204){_0x4dfb67=_0x553204;logger[_0x82b7('0x2f')](_0x82b7('0x54'),_0x4dfb67['id']);return createTicket(_0x4dd49a,_0x4df4a2,_0x4dfb67,_0x1d745d,_0x41d23b,_0x1d745d[_0x82b7('0x61')],_0x4a286a);})[_0x82b7('0x3a')](function(_0x53f1ee){_0x2bd9aa=_0x53f1ee;logger[_0x82b7('0x2f')](_0x82b7('0x55'));logger['info'](_0x82b7('0x56'),_0x2bd9aa['id']);var _0x9d495=util[_0x82b7('0x1e')](_0x82b7('0x57'),_0x4dd49a[_0x82b7('0x20')],_[_0x82b7('0x58')](_0x2bd9aa['id'],'x')[0x1]);logger[_0x82b7('0x2f')](_0x82b7('0x62'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format'](_0x82b7('0x5b'),_0x28f89c[_0x82b7('0x16')]),_0x82b7('0x63'),{'uri':_0x9d495});})[_0x82b7('0x2a')](function(_0x4b1c10){logger[_0x82b7('0x29')](_0x82b7('0x62'),JSON[_0x82b7('0x24')](_0x4b1c10));});};exports[_0x82b7('0x64')]=function(_0x173004,_0x10b75a,_0xdf64d8,_0x160012,_0xc35068,_0x11ebb0){var _0x7618ba,_0x578471,_0x593562,_0x343bba;_0x11ebb0[_0x82b7('0x20')]=intUtil[_0x82b7('0x4a')](_0x11ebb0['remoteUri']);_0x11ebb0['serverUrl']=intUtil[_0x82b7('0x4a')](_0x11ebb0[_0x82b7('0x4f')]);if(_0xc35068&&_0xc35068[_0x82b7('0x4b')]){logger[_0x82b7('0x2f')]('['+_0x10b75a[_0x82b7('0x65')][_0x82b7('0x66')]()+']',_0x82b7('0x4c'));_0x10b75a['recordingURL']=util[_0x82b7('0x1e')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x11ebb0[_0x82b7('0x4f')],_0x10b75a[_0x82b7('0x5f')],md5(_0x10b75a[_0x82b7('0x5f')]));}else{_0x10b75a[_0x82b7('0x4d')]='';}return getConnection(_0x11ebb0)[_0x82b7('0x3a')](function(_0x82863d){_0x343bba=_0x82863d;return getUser(_0x11ebb0,'',_0x343bba);})[_0x82b7('0x3a')](function(_0x11f427){_0x7618ba=_0x11f427;logger[_0x82b7('0x2f')](_0x82b7('0x51'),_0x7618ba['id']);return getEndUser(_0x11ebb0,_0x10b75a[_0x82b7('0x52')],_0x10b75a[_0x82b7('0x53')],_0x343bba);})[_0x82b7('0x3a')](function(_0x3ed2bb){_0x578471=_0x3ed2bb;logger[_0x82b7('0x2f')](_0x82b7('0x54'),_0x578471['id']);return createTicket(_0x11ebb0,_0x7618ba,_0x578471,_0xdf64d8,_0x10b75a,_0xdf64d8[_0x82b7('0x61')],_0x343bba);})[_0x82b7('0x3a')](function(_0x20434c){_0x593562=_0x20434c;logger[_0x82b7('0x2f')]('Ticket\x20created!');logger[_0x82b7('0x2f')](_0x82b7('0x56'),_0x593562['id']);})['catch'](function(_0x5217d7){logger[_0x82b7('0x29')]('['+_0x10b75a[_0x82b7('0x65')][_0x82b7('0x66')]()+']',JSON[_0x82b7('0x24')](_0x5217d7));});};
\ No newline at end of file
+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