Built motion from commit (unavailable).|2.5.18
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index d266a05..8ecd52d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf558=['SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','result','first_name','last_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userId','[vTiger],\x20%s,\x20%s,\x20%s','getUser','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!','lastname','Contacts','phone','accessKey','getchallenge','login','token','Account\x20%d\x20is\x20not\x20valid','getConnection','[HTTP]','stripTrailingSlash','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','recordingURL','email','The\x20User\x20ID\x20is:','calleridnum','The\x20Enduser\x20ID\x20is:','Fields','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','outbound','recordingFormat','none','uniqueid','destcalleridname','destcalleridnum','Ticket\x20created!','unmanaged','lastevent','toUpperCase','calleridname','lodash','bluebird','md5','util','ioredis','./util','vTiger','redis','defaults','localhost','socket.io-emitter','emit','length','forEach','type','string','content','toString','variable','variableName','idField','customVariable','Variable','toLowerCase','name','Creating\x20new\x20ticket...','Normal','Open','Subjects','Descriptions','POST','format','%s/webservice.php','remoteUri','create','username','sessionName','HelpDesk','stringify','then','success','resolve','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','error','catch','statusCode','createTicket','info','Getting\x20agent\x20with\x20email','GET','query'];(function(_0x265b89,_0x3b9dde){var _0x3d972c=function(_0x4277f1){while(--_0x4277f1){_0x265b89['push'](_0x265b89['shift']());}};_0x3d972c(++_0x3b9dde);}(_0xf558,0x1c6));var _0x8f55=function(_0x13d5a3,_0x4fe4ec){_0x13d5a3=_0x13d5a3-0x0;var _0xf5e40d=_0xf558[_0x13d5a3];return _0xf5e40d;};'use strict';var _=require(_0x8f55('0x0'));var rp=require('request-promise');var BPromise=require(_0x8f55('0x1'));var md5=require(_0x8f55('0x2'));var util=require(_0x8f55('0x3'));var Redis=require(_0x8f55('0x4'));var intUtil=require(_0x8f55('0x5'));var config=require('../../../../config/environment');var logger=require('../../../../config/logger')(_0x8f55('0x6'));config[_0x8f55('0x7')]=_[_0x8f55('0x8')](config[_0x8f55('0x7')],{'host':_0x8f55('0x9'),'port':0x18eb});var io=require(_0x8f55('0xa'))(new Redis(config[_0x8f55('0x7')]));function emit(_0x50542a,_0x1f8952,_0x34df75){io['to'](_0x50542a)[_0x8f55('0xb')](_0x1f8952,_0x34df75);}function getCustomFields(_0x2210f6,_0x460ac4){var _0x30c13c={};if(_0x2210f6[_0x8f55('0xc')]>0x0){_[_0x8f55('0xd')](_0x2210f6,function(_0x206a77){if(_0x206a77[_0x8f55('0xe')]===_0x8f55('0xf')&&_0x206a77['idField']){_0x30c13c[_0x206a77['idField']]=_0x206a77[_0x8f55('0x10')][_0x8f55('0x11')]();}else if(_0x206a77[_0x8f55('0xe')]===_0x8f55('0x12')&&_0x206a77[_0x8f55('0x13')]&&_0x206a77[_0x8f55('0x14')]&&_0x460ac4[_0x206a77[_0x8f55('0x13')]]){_0x30c13c[_0x206a77[_0x8f55('0x14')]]=_0x460ac4[_0x206a77[_0x8f55('0x13')]][_0x8f55('0x11')]();}else if(_0x206a77[_0x8f55('0xe')]===_0x8f55('0x15')&&_0x206a77[_0x8f55('0x16')]&&_0x206a77['Variable']['name']&&_0x206a77[_0x8f55('0x14')]&&_0x460ac4[_0x206a77['Variable']['name'][_0x8f55('0x17')]()]){_0x30c13c[_0x206a77[_0x8f55('0x14')]]=_0x460ac4[_0x206a77['Variable'][_0x8f55('0x18')][_0x8f55('0x17')]()][_0x8f55('0x11')]();}});}return _0x30c13c;}function createTicket(_0x4c6b0,_0x18196b,_0x4909f8,_0x13e61a,_0xbd1559,_0x901183,_0x404087){logger['info'](_0x8f55('0x19'));var _0x2a1560=_['merge']({'parent_id':'','assigned_user_id':_0x18196b['id'],'ticketpriorities':_0x8f55('0x1a'),'ticketstatus':_0x8f55('0x1b'),'ticket_title':intUtil['getString'](_0x13e61a[_0x8f55('0x1c')],_0xbd1559,'\x20'),'description':intUtil['getString'](_0x13e61a[_0x8f55('0x1d')],_0xbd1559,'\x0a'),'contact_id':_0x4909f8['id']},getCustomFields(_0x901183,_0xbd1559));var _0x55782e={'method':_0x8f55('0x1e'),'uri':util[_0x8f55('0x1f')](_0x8f55('0x20'),_0x4c6b0[_0x8f55('0x21')]),'form':{'operation':_0x8f55('0x22'),'username':_0x4c6b0[_0x8f55('0x23')],'sessionName':_0x404087[_0x8f55('0x24')],'elementType':_0x8f55('0x25'),'element':JSON[_0x8f55('0x26')](_0x2a1560)},'json':!![]};return request(_0x55782e)[_0x8f55('0x27')](function(_0x322caa){if(_0x322caa[_0x8f55('0x28')]){return BPromise[_0x8f55('0x29')]({'id':_0x322caa['result']['id']});}else{throw new Error(util['format'](_0x8f55('0x2a'),JSON[_0x8f55('0x26')](_0x322caa[_0x8f55('0x2b')])));}})[_0x8f55('0x2c')](function(_0x207396){var _0x472760=_0x207396[_0x8f55('0x2d')]||0x1f4;logger[_0x8f55('0x2b')]('[vTiger],\x20%s,\x20%s,\x20%s',_0x8f55('0x2e'),_0x472760,JSON[_0x8f55('0x26')](_0x207396));});}function getUser(_0x345507,_0x286032,_0x5b4c90){if(intUtil['validateEmail'](_0x286032)){logger[_0x8f55('0x2f')](_0x8f55('0x30'),_0x286032);return request({'method':_0x8f55('0x31'),'uri':util['format'](_0x8f55('0x20'),_0x345507[_0x8f55('0x21')]),'qs':{'operation':_0x8f55('0x32'),'username':_0x345507[_0x8f55('0x23')],'sessionName':_0x5b4c90[_0x8f55('0x24')],'query':util[_0x8f55('0x1f')](_0x8f55('0x33'),_0x286032)},'json':!![]})['then'](function(_0x3e73a4){if(_0x3e73a4[_0x8f55('0x28')]&&_0x3e73a4['result'][_0x8f55('0xc')]){logger['info']('Agent\x20found!');return BPromise['resolve']({'id':_0x3e73a4['result'][0x0]['id'],'email':_0x3e73a4[_0x8f55('0x34')][0x0]['email1'],'name':_0x3e73a4[_0x8f55('0x34')][0x0][_0x8f55('0x35')]+'\x20'+_0x3e73a4['result'][_0x8f55('0x36')]});}else{logger[_0x8f55('0x2f')](_0x8f55('0x37'));return BPromise[_0x8f55('0x29')]({'id':_0x5b4c90[_0x8f55('0x38')],'email':_0x345507['username'],'name':'admin'});}})['catch'](function(_0xc2c205){var _0x4ceec2=_0xc2c205[_0x8f55('0x2d')]||0x1f4;logger[_0x8f55('0x2b')](_0x8f55('0x39'),'getUser',_0x4ceec2,JSON[_0x8f55('0x26')](_0xc2c205));});}else{logger['info'](_0x8f55('0x37'));return BPromise[_0x8f55('0x29')]({'id':_0x5b4c90['userId'],'email':_0x345507[_0x8f55('0x23')],'name':'admin'})[_0x8f55('0x2c')](function(_0x34fc44){var _0x3c3414=_0x34fc44['statusCode']||0x1f4;logger[_0x8f55('0x2b')](_0x8f55('0x39'),_0x8f55('0x3a'),_0x3c3414,JSON[_0x8f55('0x26')](_0x34fc44));});}}function getEndUser(_0x4104d6,_0xadb18f,_0x56aba6,_0x28984c){logger[_0x8f55('0x2f')](_0x8f55('0x3b'),_0x56aba6);return request({'method':_0x8f55('0x31'),'uri':util['format'](_0x8f55('0x20'),_0x4104d6['remoteUri']),'qs':{'operation':_0x8f55('0x32'),'username':_0x4104d6[_0x8f55('0x23')],'sessionName':_0x28984c[_0x8f55('0x24')],'query':util['format'](_0x8f55('0x3c'),_0x56aba6,_0x56aba6,_0x56aba6,_0x56aba6,_0x56aba6)},'json':!![]})[_0x8f55('0x27')](function(_0x2c5688){if(_0x2c5688[_0x8f55('0x28')]&&_0x2c5688[_0x8f55('0x34')][_0x8f55('0xc')]){logger['info'](_0x8f55('0x3d'));return BPromise[_0x8f55('0x29')]({'id':_0x2c5688[_0x8f55('0x34')][0x0]['id'],'name':_0x2c5688[_0x8f55('0x34')][0x0]['firstname']+'\x20'+_0x2c5688[_0x8f55('0x34')][0x0][_0x8f55('0x3e')],'phone':_0x56aba6});}else{logger[_0x8f55('0x2f')]('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'method':_0x8f55('0x1e'),'uri':util[_0x8f55('0x1f')](_0x8f55('0x20'),_0x4104d6[_0x8f55('0x21')]),'form':{'operation':_0x8f55('0x22'),'sessionName':_0x28984c['sessionName'],'elementType':_0x8f55('0x3f'),'element':JSON[_0x8f55('0x26')]({'lastname':_0xadb18f,'phone':_0x56aba6,'assigned_user_id':'\x20'})},'json':!![]})[_0x8f55('0x27')](function(_0x348850){logger[_0x8f55('0x2f')]('Enduser\x20created.');return BPromise[_0x8f55('0x29')]({'id':_0x348850[_0x8f55('0x34')]['id'],'name':_0x348850[_0x8f55('0x34')][_0x8f55('0x3e')],'phone':_0x348850[_0x8f55('0x34')][_0x8f55('0x40')]});})[_0x8f55('0x2c')](function(_0x59d52f){var _0x2d5a3e=_0x59d52f[_0x8f55('0x2d')]||0x1f4;logger[_0x8f55('0x2b')](_0x8f55('0x39'),'getEndUser',_0x2d5a3e,JSON['stringify'](_0x59d52f));});}});}function getConnection(_0x2fd565){var _0x4dc559=_0x2fd565[_0x8f55('0x23')];var _0x2cee97=_0x2fd565[_0x8f55('0x41')];return request({'method':_0x8f55('0x31'),'uri':util[_0x8f55('0x1f')](_0x8f55('0x20'),_0x2fd565[_0x8f55('0x21')]),'qs':{'operation':_0x8f55('0x42'),'username':_0x4dc559},'json':!![]})[_0x8f55('0x27')](function(_0xf635a6){if(_0xf635a6['success']){return request({'method':'POST','uri':util[_0x8f55('0x1f')]('%s/webservice.php',_0x2fd565[_0x8f55('0x21')]),'form':{'operation':_0x8f55('0x43'),'username':_0x4dc559,'accessKey':md5(_0xf635a6[_0x8f55('0x34')][_0x8f55('0x44')]+_0x2cee97)},'json':!![]});}})[_0x8f55('0x27')](function(_0x4bf4ca){if(_0x4bf4ca['success']){return BPromise[_0x8f55('0x29')](_0x4bf4ca['result']);}else{throw new Error(util[_0x8f55('0x1f')](_0x8f55('0x45'),_0x2fd565['id']));}})[_0x8f55('0x2c')](function(_0x1f6983){var _0x4f0236=_0x1f6983[_0x8f55('0x2d')]||0x1f4;logger[_0x8f55('0x2b')]('[vTiger],\x20%s,\x20%s,\x20%s',_0x8f55('0x46'),_0x4f0236,JSON[_0x8f55('0x26')](_0x1f6983));});}function request(_0x39aa0b){logger['info'](_0x8f55('0x47'),JSON[_0x8f55('0x26')](_0x39aa0b));return rp(_0x39aa0b);}exports['queue']=function(_0x30401e,_0x4da779,_0x57356b,_0x56b870,_0x17f05d,_0x481349){var _0x43362d,_0x5884e9,_0x45247f,_0x4c4674;_0x481349[_0x8f55('0x21')]=intUtil[_0x8f55('0x48')](_0x481349[_0x8f55('0x21')]);if(_0x17f05d&&_0x17f05d[_0x8f55('0x49')]){logger[_0x8f55('0x2f')](_0x8f55('0x4a'),_0x8f55('0x4b'));_0x4da779['recordingURL']=util[_0x8f55('0x1f')](_0x8f55('0x4c'),_0x481349[_0x8f55('0x4d')],_0x4da779['uniqueid'],md5(_0x4da779['uniqueid']));}else{_0x4da779[_0x8f55('0x4e')]='';}return getConnection(_0x481349)[_0x8f55('0x27')](function(_0x26024b){_0x4c4674=_0x26024b;return getUser(_0x481349,_0x56b870[_0x8f55('0x4f')],_0x4c4674);})[_0x8f55('0x27')](function(_0x534f1a){_0x43362d=_0x534f1a;logger[_0x8f55('0x2f')](_0x8f55('0x50'),_0x43362d['id']);return getEndUser(_0x481349,_0x4da779['calleridname'],_0x4da779[_0x8f55('0x51')],_0x4c4674);})['then'](function(_0x14ee3){_0x5884e9=_0x14ee3;logger['info'](_0x8f55('0x52'),_0x5884e9['id']);return createTicket(_0x481349,_0x43362d,_0x5884e9,_0x57356b,_0x4da779,_0x57356b[_0x8f55('0x53')],_0x4c4674);})[_0x8f55('0x27')](function(_0x1d9d9e){_0x45247f=_0x1d9d9e;logger[_0x8f55('0x2f')]('Ticket\x20created!');logger[_0x8f55('0x2f')](_0x8f55('0x54'),_0x45247f['id']);var _0x2c716e=util['format'](_0x8f55('0x55'),_0x481349[_0x8f55('0x21')],_[_0x8f55('0x56')](_0x45247f['id'],'x')[0x1]);logger['info'](_0x8f55('0x4a'),_0x8f55('0x57'));emit(util[_0x8f55('0x1f')](_0x8f55('0x58'),_0x56b870['name']),_0x8f55('0x59'),{'uri':_0x2c716e});})[_0x8f55('0x2c')](function(_0x3e884c){logger[_0x8f55('0x2b')](_0x8f55('0x4a'),JSON[_0x8f55('0x26')](_0x3e884c));});};exports[_0x8f55('0x5a')]=function(_0x1911d5,_0x2f5589,_0x1df98d,_0x1e8343,_0xf6acf5,_0x410502,_0x1f0211){var _0x12ae8c,_0x3deb9a,_0x43fc99,_0xd97124;_0x410502[_0x8f55('0x21')]=intUtil[_0x8f55('0x48')](_0x410502[_0x8f55('0x21')]);_0x410502[_0x8f55('0x4d')]=intUtil[_0x8f55('0x48')](_0x410502[_0x8f55('0x4d')]);if(_0x1f0211&&_0x1f0211[_0x8f55('0x5b')]&&_0x1f0211[_0x8f55('0x5b')]!==_0x8f55('0x5c')){logger[_0x8f55('0x2f')]('[OUTBOUND]',_0x8f55('0x4b'));_0x2f5589['recordingURL']=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x410502[_0x8f55('0x4d')],_0x2f5589[_0x8f55('0x5d')],md5(_0x2f5589[_0x8f55('0x5d')]));}return getConnection(_0x410502)[_0x8f55('0x27')](function(_0x50ddf0){_0xd97124=_0x50ddf0;return getUser(_0x410502,_0x1e8343[_0x8f55('0x4f')],_0xd97124);})['then'](function(_0x3025f0){_0x12ae8c=_0x3025f0;logger['info'](_0x8f55('0x50'),_0x12ae8c['id']);return getEndUser(_0x410502,_0x2f5589[_0x8f55('0x5e')],_0x2f5589[_0x8f55('0x5f')],_0xd97124);})[_0x8f55('0x27')](function(_0x3e2b1){_0x3deb9a=_0x3e2b1;logger[_0x8f55('0x2f')]('The\x20Enduser\x20ID\x20is:',_0x3deb9a['id']);return createTicket(_0x410502,_0x12ae8c,_0x3deb9a,_0x1df98d,_0x2f5589,_0x1df98d[_0x8f55('0x53')],_0xd97124);})[_0x8f55('0x27')](function(_0x5d62bd){_0x43fc99=_0x5d62bd;logger[_0x8f55('0x2f')](_0x8f55('0x60'));logger['info'](_0x8f55('0x54'),_0x43fc99['id']);var _0x30aa29=util[_0x8f55('0x1f')](_0x8f55('0x55'),_0x410502[_0x8f55('0x21')],_['split'](_0x43fc99['id'],'x')[0x1]);logger['info']('[OUTBOUND]',_0x8f55('0x57'));emit(util['format']('user:%s',_0x1e8343[_0x8f55('0x18')]),_0x8f55('0x59'),{'uri':_0x30aa29});})[_0x8f55('0x2c')](function(_0x108388){logger['error']('[OUTBOUND]',JSON[_0x8f55('0x26')](_0x108388));});};exports[_0x8f55('0x61')]=function(_0x53129c,_0x115839,_0x554ef8,_0x307e8d,_0x577783,_0x3b3aa2){var _0x51a648,_0x245beb,_0x26f49e,_0x8e1b8c;_0x3b3aa2[_0x8f55('0x21')]=intUtil[_0x8f55('0x48')](_0x3b3aa2[_0x8f55('0x21')]);_0x3b3aa2[_0x8f55('0x4d')]=intUtil[_0x8f55('0x48')](_0x3b3aa2['serverUrl']);if(_0x577783&&_0x577783[_0x8f55('0x49')]){logger[_0x8f55('0x2f')]('['+_0x115839[_0x8f55('0x62')][_0x8f55('0x63')]()+']',_0x8f55('0x4b'));_0x115839[_0x8f55('0x4e')]=util[_0x8f55('0x1f')](_0x8f55('0x4c'),_0x3b3aa2['serverUrl'],_0x115839[_0x8f55('0x5d')],md5(_0x115839[_0x8f55('0x5d')]));}else{_0x115839['recordingURL']='';}return getConnection(_0x3b3aa2)['then'](function(_0x5443cb){_0x8e1b8c=_0x5443cb;return getUser(_0x3b3aa2,'',_0x8e1b8c);})[_0x8f55('0x27')](function(_0xdaf66d){_0x51a648=_0xdaf66d;logger[_0x8f55('0x2f')]('The\x20User\x20ID\x20is:',_0x51a648['id']);return getEndUser(_0x3b3aa2,_0x115839[_0x8f55('0x64')],_0x115839[_0x8f55('0x51')],_0x8e1b8c);})['then'](function(_0x4c1a7f){_0x245beb=_0x4c1a7f;logger[_0x8f55('0x2f')](_0x8f55('0x52'),_0x245beb['id']);return createTicket(_0x3b3aa2,_0x51a648,_0x245beb,_0x554ef8,_0x115839,_0x554ef8[_0x8f55('0x53')],_0x8e1b8c);})[_0x8f55('0x27')](function(_0x25515e){_0x26f49e=_0x25515e;logger[_0x8f55('0x2f')]('Ticket\x20created!');logger['info'](_0x8f55('0x54'),_0x26f49e['id']);})[_0x8f55('0x2c')](function(_0x2e77be){logger['error']('['+_0x115839[_0x8f55('0x62')][_0x8f55('0x63')]()+']',JSON[_0x8f55('0x26')](_0x2e77be));});};
\ No newline at end of file
+var _0xab03=['Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','uniqueid','email','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Fields','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','outbound','stripTrailingSlash','recordingFormat','[OUTBOUND]','destcalleridname','destcalleridnum','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','unmanaged','monitor_format','toUpperCase','The\x20User\x20ID\x20is:','lastevent','request-promise','bluebird','md5','util','ioredis','./util','../../../../config/environment','redis','localhost','socket.io-emitter','length','forEach','type','string','idField','variable','variableName','customVariable','Variable','name','toLowerCase','toString','info','Creating\x20new\x20ticket...','Open','Subjects','getString','%s/webservice.php','remoteUri','create','username','HelpDesk','stringify','then','success','resolve','result','format','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','error','catch','statusCode','[vTiger],\x20%s,\x20%s,\x20%s','createTicket','Getting\x20agent\x20with\x20email','GET','sessionName','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','Agent\x20found!','first_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;','Enduser\x20found!','firstname','lastname','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Contacts','phone','getEndUser','accessKey','getchallenge','POST','login','token','Account\x20%d\x20is\x20not\x20valid','getConnection','[HTTP]','queue','[QUEUE]'];(function(_0x1e7b16,_0x4607a1){var _0x37fadc=function(_0x1fc9ce){while(--_0x1fc9ce){_0x1e7b16['push'](_0x1e7b16['shift']());}};_0x37fadc(++_0x4607a1);}(_0xab03,0xe2));var _0x3ab0=function(_0x3655d2,_0x4eb122){_0x3655d2=_0x3655d2-0x0;var _0x2ed319=_0xab03[_0x3655d2];return _0x2ed319;};'use strict';var _=require('lodash');var rp=require(_0x3ab0('0x0'));var BPromise=require(_0x3ab0('0x1'));var md5=require(_0x3ab0('0x2'));var util=require(_0x3ab0('0x3'));var Redis=require(_0x3ab0('0x4'));var intUtil=require(_0x3ab0('0x5'));var config=require(_0x3ab0('0x6'));var logger=require('../../../../config/logger')('vTiger');config[_0x3ab0('0x7')]=_['defaults'](config[_0x3ab0('0x7')],{'host':_0x3ab0('0x8'),'port':0x18eb});var io=require(_0x3ab0('0x9'))(new Redis(config['redis']));function emit(_0x25e394,_0x253e59,_0x3b6db8){io['to'](_0x25e394)['emit'](_0x253e59,_0x3b6db8);}function getCustomFields(_0x26c555,_0x504974){var _0x1180ef={};if(_0x26c555[_0x3ab0('0xa')]>0x0){_[_0x3ab0('0xb')](_0x26c555,function(_0x117e1f){if(_0x117e1f[_0x3ab0('0xc')]===_0x3ab0('0xd')&&_0x117e1f[_0x3ab0('0xe')]){_0x1180ef[_0x117e1f[_0x3ab0('0xe')]]=_0x117e1f['content']['toString']();}else if(_0x117e1f[_0x3ab0('0xc')]===_0x3ab0('0xf')&&_0x117e1f[_0x3ab0('0x10')]&&_0x117e1f[_0x3ab0('0xe')]&&_0x504974[_0x117e1f[_0x3ab0('0x10')]]){_0x1180ef[_0x117e1f[_0x3ab0('0xe')]]=_0x504974[_0x117e1f[_0x3ab0('0x10')]]['toString']();}else if(_0x117e1f[_0x3ab0('0xc')]===_0x3ab0('0x11')&&_0x117e1f[_0x3ab0('0x12')]&&_0x117e1f[_0x3ab0('0x12')][_0x3ab0('0x13')]&&_0x117e1f[_0x3ab0('0xe')]&&_0x504974[_0x117e1f['Variable']['name'][_0x3ab0('0x14')]()]){_0x1180ef[_0x117e1f[_0x3ab0('0xe')]]=_0x504974[_0x117e1f['Variable'][_0x3ab0('0x13')]['toLowerCase']()][_0x3ab0('0x15')]();}});}return _0x1180ef;}function createTicket(_0x541868,_0x212166,_0x2a8e03,_0x95af77,_0x350336,_0x2085ed,_0x2c383a){logger[_0x3ab0('0x16')](_0x3ab0('0x17'));var _0x40d416=_['merge']({'parent_id':'','assigned_user_id':_0x212166['id'],'ticketpriorities':'Normal','ticketstatus':_0x3ab0('0x18'),'ticket_title':intUtil['getString'](_0x95af77[_0x3ab0('0x19')],_0x350336,'\x20'),'description':intUtil[_0x3ab0('0x1a')](_0x95af77['Descriptions'],_0x350336,'\x0a'),'contact_id':_0x2a8e03['id']},getCustomFields(_0x2085ed,_0x350336));var _0x14fd63={'method':'POST','uri':util['format'](_0x3ab0('0x1b'),_0x541868[_0x3ab0('0x1c')]),'form':{'operation':_0x3ab0('0x1d'),'username':_0x541868[_0x3ab0('0x1e')],'sessionName':_0x2c383a['sessionName'],'elementType':_0x3ab0('0x1f'),'element':JSON[_0x3ab0('0x20')](_0x40d416)},'json':!![]};return request(_0x14fd63)[_0x3ab0('0x21')](function(_0x265f0f){if(_0x265f0f[_0x3ab0('0x22')]){return BPromise[_0x3ab0('0x23')]({'id':_0x265f0f[_0x3ab0('0x24')]['id']});}else{throw new Error(util[_0x3ab0('0x25')](_0x3ab0('0x26'),JSON[_0x3ab0('0x20')](_0x265f0f[_0x3ab0('0x27')])));}})[_0x3ab0('0x28')](function(_0x53f4d0){var _0x305879=_0x53f4d0[_0x3ab0('0x29')]||0x1f4;logger[_0x3ab0('0x27')](_0x3ab0('0x2a'),_0x3ab0('0x2b'),_0x305879,JSON['stringify'](_0x53f4d0));});}function getUser(_0x1ee8cc,_0x162b5e,_0x5a4ed8){if(intUtil['validateEmail'](_0x162b5e)){logger[_0x3ab0('0x16')](_0x3ab0('0x2c'),_0x162b5e);return request({'method':_0x3ab0('0x2d'),'uri':util[_0x3ab0('0x25')](_0x3ab0('0x1b'),_0x1ee8cc[_0x3ab0('0x1c')]),'qs':{'operation':'query','username':_0x1ee8cc[_0x3ab0('0x1e')],'sessionName':_0x5a4ed8[_0x3ab0('0x2e')],'query':util['format'](_0x3ab0('0x2f'),_0x162b5e)},'json':!![]})['then'](function(_0x1d0503){if(_0x1d0503[_0x3ab0('0x22')]&&_0x1d0503['result']['length']){logger[_0x3ab0('0x16')](_0x3ab0('0x30'));return BPromise[_0x3ab0('0x23')]({'id':_0x1d0503[_0x3ab0('0x24')][0x0]['id'],'email':_0x1d0503[_0x3ab0('0x24')][0x0]['email1'],'name':_0x1d0503[_0x3ab0('0x24')][0x0][_0x3ab0('0x31')]+'\x20'+_0x1d0503[_0x3ab0('0x24')]['last_name']});}else{logger[_0x3ab0('0x16')](_0x3ab0('0x32'));return BPromise['resolve']({'id':_0x5a4ed8[_0x3ab0('0x33')],'email':_0x1ee8cc[_0x3ab0('0x1e')],'name':_0x3ab0('0x34')});}})['catch'](function(_0x307a13){var _0x329d03=_0x307a13['statusCode']||0x1f4;logger[_0x3ab0('0x27')](_0x3ab0('0x2a'),'getUser',_0x329d03,JSON[_0x3ab0('0x20')](_0x307a13));});}else{logger[_0x3ab0('0x16')](_0x3ab0('0x32'));return BPromise['resolve']({'id':_0x5a4ed8[_0x3ab0('0x33')],'email':_0x1ee8cc['username'],'name':'admin'})[_0x3ab0('0x28')](function(_0x3912b3){var _0x3d9069=_0x3912b3[_0x3ab0('0x29')]||0x1f4;logger[_0x3ab0('0x27')](_0x3ab0('0x2a'),_0x3ab0('0x35'),_0x3d9069,JSON[_0x3ab0('0x20')](_0x3912b3));});}}function getEndUser(_0x59b48b,_0x37408f,_0x3794d0,_0x242691){logger[_0x3ab0('0x16')](_0x3ab0('0x36'),_0x3794d0);return request({'method':_0x3ab0('0x2d'),'uri':util['format'](_0x3ab0('0x1b'),_0x59b48b[_0x3ab0('0x1c')]),'qs':{'operation':_0x3ab0('0x37'),'username':_0x59b48b[_0x3ab0('0x1e')],'sessionName':_0x242691['sessionName'],'query':util[_0x3ab0('0x25')](_0x3ab0('0x38'),_0x3794d0,_0x3794d0,_0x3794d0,_0x3794d0,_0x3794d0)},'json':!![]})[_0x3ab0('0x21')](function(_0x422838){if(_0x422838[_0x3ab0('0x22')]&&_0x422838[_0x3ab0('0x24')][_0x3ab0('0xa')]){logger[_0x3ab0('0x16')](_0x3ab0('0x39'));return BPromise[_0x3ab0('0x23')]({'id':_0x422838[_0x3ab0('0x24')][0x0]['id'],'name':_0x422838[_0x3ab0('0x24')][0x0][_0x3ab0('0x3a')]+'\x20'+_0x422838[_0x3ab0('0x24')][0x0][_0x3ab0('0x3b')],'phone':_0x3794d0});}else{logger[_0x3ab0('0x16')](_0x3ab0('0x3c'));return request({'method':'POST','uri':util['format'](_0x3ab0('0x1b'),_0x59b48b[_0x3ab0('0x1c')]),'form':{'operation':_0x3ab0('0x1d'),'sessionName':_0x242691['sessionName'],'elementType':_0x3ab0('0x3d'),'element':JSON[_0x3ab0('0x20')]({'lastname':_0x37408f,'phone':_0x3794d0,'assigned_user_id':'\x20'})},'json':!![]})['then'](function(_0x591551){logger['info']('Enduser\x20created.');return BPromise[_0x3ab0('0x23')]({'id':_0x591551[_0x3ab0('0x24')]['id'],'name':_0x591551[_0x3ab0('0x24')][_0x3ab0('0x3b')],'phone':_0x591551[_0x3ab0('0x24')][_0x3ab0('0x3e')]});})[_0x3ab0('0x28')](function(_0x3ec01e){var _0x39816b=_0x3ec01e[_0x3ab0('0x29')]||0x1f4;logger[_0x3ab0('0x27')](_0x3ab0('0x2a'),_0x3ab0('0x3f'),_0x39816b,JSON[_0x3ab0('0x20')](_0x3ec01e));});}});}function getConnection(_0x1878b4){var _0x4967b8=_0x1878b4[_0x3ab0('0x1e')];var _0x2703b0=_0x1878b4[_0x3ab0('0x40')];return request({'method':'GET','uri':util['format']('%s/webservice.php',_0x1878b4[_0x3ab0('0x1c')]),'qs':{'operation':_0x3ab0('0x41'),'username':_0x4967b8},'json':!![]})[_0x3ab0('0x21')](function(_0x24b221){if(_0x24b221[_0x3ab0('0x22')]){return request({'method':_0x3ab0('0x42'),'uri':util['format'](_0x3ab0('0x1b'),_0x1878b4['remoteUri']),'form':{'operation':_0x3ab0('0x43'),'username':_0x4967b8,'accessKey':md5(_0x24b221[_0x3ab0('0x24')][_0x3ab0('0x44')]+_0x2703b0)},'json':!![]});}})[_0x3ab0('0x21')](function(_0x5e0ca5){if(_0x5e0ca5[_0x3ab0('0x22')]){return BPromise['resolve'](_0x5e0ca5[_0x3ab0('0x24')]);}else{throw new Error(util['format'](_0x3ab0('0x45'),_0x1878b4['id']));}})['catch'](function(_0x18dccc){var _0x75a94c=_0x18dccc[_0x3ab0('0x29')]||0x1f4;logger[_0x3ab0('0x27')]('[vTiger],\x20%s,\x20%s,\x20%s',_0x3ab0('0x46'),_0x75a94c,JSON[_0x3ab0('0x20')](_0x18dccc));});}function request(_0x33c982){logger[_0x3ab0('0x16')](_0x3ab0('0x47'),JSON[_0x3ab0('0x20')](_0x33c982));return rp(_0x33c982);}exports[_0x3ab0('0x48')]=function(_0x45362c,_0x3c9585,_0x4ba5c4,_0x5725b7,_0x3247d9,_0x50e676){var _0x417825,_0x44b151,_0xc91974,_0x29f2da;_0x50e676[_0x3ab0('0x1c')]=intUtil['stripTrailingSlash'](_0x50e676['remoteUri']);if(_0x3247d9&&_0x3247d9['monitor_format']){logger[_0x3ab0('0x16')](_0x3ab0('0x49'),_0x3ab0('0x4a'));_0x3c9585[_0x3ab0('0x4b')]=util[_0x3ab0('0x25')](_0x3ab0('0x4c'),_0x50e676[_0x3ab0('0x4d')],_0x3c9585['uniqueid'],md5(_0x3c9585[_0x3ab0('0x4e')]));}else{_0x3c9585[_0x3ab0('0x4b')]='';}return getConnection(_0x50e676)[_0x3ab0('0x21')](function(_0x518a6a){_0x29f2da=_0x518a6a;return getUser(_0x50e676,_0x5725b7[_0x3ab0('0x4f')],_0x29f2da);})[_0x3ab0('0x21')](function(_0x3cca38){_0x417825=_0x3cca38;logger[_0x3ab0('0x16')]('The\x20User\x20ID\x20is:',_0x417825['id']);return getEndUser(_0x50e676,_0x3c9585[_0x3ab0('0x50')],_0x3c9585[_0x3ab0('0x51')],_0x29f2da);})['then'](function(_0x4acce0){_0x44b151=_0x4acce0;logger['info'](_0x3ab0('0x52'),_0x44b151['id']);return createTicket(_0x50e676,_0x417825,_0x44b151,_0x4ba5c4,_0x3c9585,_0x4ba5c4[_0x3ab0('0x53')],_0x29f2da);})['then'](function(_0x5683f8){_0xc91974=_0x5683f8;logger[_0x3ab0('0x16')]('Ticket\x20created!');logger[_0x3ab0('0x16')]('The\x20Ticket\x20ID\x20is:',_0xc91974['id']);var _0x5c7d73=util['format'](_0x3ab0('0x54'),_0x50e676[_0x3ab0('0x1c')],_['split'](_0xc91974['id'],'x')[0x1]);logger[_0x3ab0('0x16')]('[QUEUE]',_0x3ab0('0x55'));emit(util['format'](_0x3ab0('0x56'),_0x5725b7[_0x3ab0('0x13')]),'trigger:browser:url',{'uri':_0x5c7d73});})['catch'](function(_0x8bec52){logger[_0x3ab0('0x27')](_0x3ab0('0x49'),JSON[_0x3ab0('0x20')](_0x8bec52));});};exports[_0x3ab0('0x57')]=function(_0x854eb4,_0x5ca2a1,_0x5ce112,_0x2dd8e7,_0xcd55f,_0xdbf072,_0xcb50a7){var _0x479314,_0x2b6d91,_0x4092a0,_0x5567eb;_0xdbf072[_0x3ab0('0x1c')]=intUtil[_0x3ab0('0x58')](_0xdbf072[_0x3ab0('0x1c')]);_0xdbf072[_0x3ab0('0x4d')]=intUtil[_0x3ab0('0x58')](_0xdbf072[_0x3ab0('0x4d')]);if(_0xcb50a7&&_0xcb50a7[_0x3ab0('0x59')]&&_0xcb50a7['recordingFormat']!=='none'){logger[_0x3ab0('0x16')](_0x3ab0('0x5a'),'Recording\x20is\x20enabled!');_0x5ca2a1[_0x3ab0('0x4b')]=util[_0x3ab0('0x25')](_0x3ab0('0x4c'),_0xdbf072[_0x3ab0('0x4d')],_0x5ca2a1[_0x3ab0('0x4e')],md5(_0x5ca2a1[_0x3ab0('0x4e')]));}return getConnection(_0xdbf072)[_0x3ab0('0x21')](function(_0xcf923c){_0x5567eb=_0xcf923c;return getUser(_0xdbf072,_0x2dd8e7[_0x3ab0('0x4f')],_0x5567eb);})[_0x3ab0('0x21')](function(_0x370d19){_0x479314=_0x370d19;logger[_0x3ab0('0x16')]('The\x20User\x20ID\x20is:',_0x479314['id']);return getEndUser(_0xdbf072,_0x5ca2a1[_0x3ab0('0x5b')],_0x5ca2a1[_0x3ab0('0x5c')],_0x5567eb);})[_0x3ab0('0x21')](function(_0x36f738){_0x2b6d91=_0x36f738;logger['info']('The\x20Enduser\x20ID\x20is:',_0x2b6d91['id']);return createTicket(_0xdbf072,_0x479314,_0x2b6d91,_0x5ce112,_0x5ca2a1,_0x5ce112[_0x3ab0('0x53')],_0x5567eb);})[_0x3ab0('0x21')](function(_0x2d13a3){_0x4092a0=_0x2d13a3;logger[_0x3ab0('0x16')](_0x3ab0('0x5d'));logger[_0x3ab0('0x16')](_0x3ab0('0x5e'),_0x4092a0['id']);var _0x12456b=util[_0x3ab0('0x25')]('%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT',_0xdbf072[_0x3ab0('0x1c')],_['split'](_0x4092a0['id'],'x')[0x1]);logger[_0x3ab0('0x16')](_0x3ab0('0x5a'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x3ab0('0x25')](_0x3ab0('0x56'),_0x2dd8e7[_0x3ab0('0x13')]),'trigger:browser:url',{'uri':_0x12456b});})[_0x3ab0('0x28')](function(_0x5890d9){logger[_0x3ab0('0x27')](_0x3ab0('0x5a'),JSON['stringify'](_0x5890d9));});};exports[_0x3ab0('0x5f')]=function(_0x1fad24,_0x4fccd6,_0x325f98,_0x543a62,_0x33d47c,_0x71a7b6){var _0x94b434,_0x444243,_0x7f03ac,_0x1adc4c;_0x71a7b6[_0x3ab0('0x1c')]=intUtil[_0x3ab0('0x58')](_0x71a7b6[_0x3ab0('0x1c')]);_0x71a7b6['serverUrl']=intUtil[_0x3ab0('0x58')](_0x71a7b6['serverUrl']);if(_0x33d47c&&_0x33d47c[_0x3ab0('0x60')]){logger[_0x3ab0('0x16')]('['+_0x4fccd6['lastevent'][_0x3ab0('0x61')]()+']',_0x3ab0('0x4a'));_0x4fccd6[_0x3ab0('0x4b')]=util[_0x3ab0('0x25')](_0x3ab0('0x4c'),_0x71a7b6[_0x3ab0('0x4d')],_0x4fccd6['uniqueid'],md5(_0x4fccd6[_0x3ab0('0x4e')]));}else{_0x4fccd6[_0x3ab0('0x4b')]='';}return getConnection(_0x71a7b6)['then'](function(_0x1b48b6){_0x1adc4c=_0x1b48b6;return getUser(_0x71a7b6,'',_0x1adc4c);})['then'](function(_0x548bb6){_0x94b434=_0x548bb6;logger[_0x3ab0('0x16')](_0x3ab0('0x62'),_0x94b434['id']);return getEndUser(_0x71a7b6,_0x4fccd6[_0x3ab0('0x50')],_0x4fccd6[_0x3ab0('0x51')],_0x1adc4c);})['then'](function(_0x56404f){_0x444243=_0x56404f;logger[_0x3ab0('0x16')](_0x3ab0('0x52'),_0x444243['id']);return createTicket(_0x71a7b6,_0x94b434,_0x444243,_0x325f98,_0x4fccd6,_0x325f98['Fields'],_0x1adc4c);})[_0x3ab0('0x21')](function(_0x5e5bc5){_0x7f03ac=_0x5e5bc5;logger[_0x3ab0('0x16')]('Ticket\x20created!');logger[_0x3ab0('0x16')](_0x3ab0('0x5e'),_0x7f03ac['id']);})[_0x3ab0('0x28')](function(_0x49d317){logger[_0x3ab0('0x27')]('['+_0x4fccd6[_0x3ab0('0x63')]['toUpperCase']()+']',JSON[_0x3ab0('0x20')](_0x49d317));});};
\ No newline at end of file