Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index d266a05..e71d91f 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 _0xd8b0=['info','Creating\x20new\x20ticket...','merge','Normal','Subjects','POST','format','%s/webservice.php','remoteUri','create','username','sessionName','HelpDesk','stringify','success','result','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','error','statusCode','[vTiger],\x20%s,\x20%s,\x20%s','validateEmail','Getting\x20agent\x20with\x20email','then','Agent\x20found!','resolve','email1','first_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','admin','catch','userId','getUser','Searching\x20end\x20user\x20with\x20phone','GET','query','Enduser\x20found!','firstname','Enduser\x20created.','lastname','phone','accessKey','getchallenge','login','token','getConnection','stripTrailingSlash','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','recordingURL','email','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Fields','Ticket\x20created!','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','split','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','outbound','recordingFormat','none','[OUTBOUND]','uniqueid','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','The\x20Ticket\x20ID\x20is:','user:%s','lastevent','toUpperCase','lodash','request-promise','ioredis','./util','../../../../config/environment','../../../../config/logger','vTiger','redis','localhost','socket.io-emitter','emit','length','forEach','includes','picklist','idField','content','toString','type','variable','variableName','customVariable','Variable','name','toLowerCase'];(function(_0x44a3b0,_0x352810){var _0x39e6f6=function(_0x248002){while(--_0x248002){_0x44a3b0['push'](_0x44a3b0['shift']());}};_0x39e6f6(++_0x352810);}(_0xd8b0,0xad));var _0x0d8b=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xd8b0[_0x20a584];return _0x4b41a8;};'use strict';var _=require(_0x0d8b('0x0'));var rp=require(_0x0d8b('0x1'));var BPromise=require('bluebird');var md5=require('md5');var util=require('util');var Redis=require(_0x0d8b('0x2'));var intUtil=require(_0x0d8b('0x3'));var config=require(_0x0d8b('0x4'));var logger=require(_0x0d8b('0x5'))(_0x0d8b('0x6'));config['redis']=_['defaults'](config[_0x0d8b('0x7')],{'host':_0x0d8b('0x8'),'port':0x18eb});var io=require(_0x0d8b('0x9'))(new Redis(config['redis']));function emit(_0x413284,_0x284169,_0x58e4e2){io['to'](_0x413284)[_0x0d8b('0xa')](_0x284169,_0x58e4e2);}function getCustomFields(_0x348e65,_0x3b027f){var _0x1f4800={};if(_0x348e65[_0x0d8b('0xb')]>0x0){_[_0x0d8b('0xc')](_0x348e65,function(_0x2c5e9e){if(_[_0x0d8b('0xd')](['string',_0x0d8b('0xe')],_0x2c5e9e['type'])&&_0x2c5e9e[_0x0d8b('0xf')]){_0x1f4800[_0x2c5e9e[_0x0d8b('0xf')]]=_0x2c5e9e[_0x0d8b('0x10')][_0x0d8b('0x11')]();}else if(_0x2c5e9e[_0x0d8b('0x12')]===_0x0d8b('0x13')&&_0x2c5e9e[_0x0d8b('0x14')]&&_0x2c5e9e[_0x0d8b('0xf')]&&_0x3b027f[_0x2c5e9e[_0x0d8b('0x14')]]){_0x1f4800[_0x2c5e9e[_0x0d8b('0xf')]]=_0x3b027f[_0x2c5e9e[_0x0d8b('0x14')]][_0x0d8b('0x11')]();}else if(_0x2c5e9e[_0x0d8b('0x12')]===_0x0d8b('0x15')&&_0x2c5e9e['Variable']&&_0x2c5e9e[_0x0d8b('0x16')][_0x0d8b('0x17')]&&_0x2c5e9e[_0x0d8b('0xf')]&&_0x3b027f[_0x2c5e9e[_0x0d8b('0x16')][_0x0d8b('0x17')]['toLowerCase']()]){_0x1f4800[_0x2c5e9e[_0x0d8b('0xf')]]=_0x3b027f[_0x2c5e9e[_0x0d8b('0x16')][_0x0d8b('0x17')][_0x0d8b('0x18')]()][_0x0d8b('0x11')]();}});}return _0x1f4800;}function createTicket(_0x18dd2d,_0x264b39,_0xa3612a,_0x4a15bf,_0x27512e,_0x23d58f,_0x196c0a){logger[_0x0d8b('0x19')](_0x0d8b('0x1a'));var _0x5b709c=_[_0x0d8b('0x1b')]({'parent_id':'','assigned_user_id':_0x264b39['id'],'ticketpriorities':_0x0d8b('0x1c'),'ticketstatus':'Open','ticket_title':intUtil['getString'](_0x4a15bf[_0x0d8b('0x1d')],_0x27512e,'\x20'),'description':intUtil['getString'](_0x4a15bf['Descriptions'],_0x27512e,'\x0a'),'contact_id':_0xa3612a['id']},getCustomFields(_0x23d58f,_0x27512e));var _0x5527d8={'method':_0x0d8b('0x1e'),'uri':util[_0x0d8b('0x1f')](_0x0d8b('0x20'),_0x18dd2d[_0x0d8b('0x21')]),'form':{'operation':_0x0d8b('0x22'),'username':_0x18dd2d[_0x0d8b('0x23')],'sessionName':_0x196c0a[_0x0d8b('0x24')],'elementType':_0x0d8b('0x25'),'element':JSON[_0x0d8b('0x26')](_0x5b709c)},'json':!![]};return request(_0x5527d8)['then'](function(_0xe8bbee){if(_0xe8bbee[_0x0d8b('0x27')]){return BPromise['resolve']({'id':_0xe8bbee[_0x0d8b('0x28')]['id']});}else{throw new Error(util['format'](_0x0d8b('0x29'),JSON[_0x0d8b('0x26')](_0xe8bbee[_0x0d8b('0x2a')])));}})['catch'](function(_0x59a905){var _0x28f639=_0x59a905[_0x0d8b('0x2b')]||0x1f4;logger['error'](_0x0d8b('0x2c'),'createTicket',_0x28f639,JSON[_0x0d8b('0x26')](_0x59a905));});}function getUser(_0x4b59e5,_0x97050a,_0x48f24f){if(intUtil[_0x0d8b('0x2d')](_0x97050a)){logger['info'](_0x0d8b('0x2e'),_0x97050a);return request({'method':'GET','uri':util[_0x0d8b('0x1f')](_0x0d8b('0x20'),_0x4b59e5[_0x0d8b('0x21')]),'qs':{'operation':'query','username':_0x4b59e5['username'],'sessionName':_0x48f24f['sessionName'],'query':util[_0x0d8b('0x1f')]('SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;',_0x97050a)},'json':!![]})[_0x0d8b('0x2f')](function(_0x54f6f3){if(_0x54f6f3['success']&&_0x54f6f3[_0x0d8b('0x28')][_0x0d8b('0xb')]){logger[_0x0d8b('0x19')](_0x0d8b('0x30'));return BPromise[_0x0d8b('0x31')]({'id':_0x54f6f3[_0x0d8b('0x28')][0x0]['id'],'email':_0x54f6f3[_0x0d8b('0x28')][0x0][_0x0d8b('0x32')],'name':_0x54f6f3['result'][0x0][_0x0d8b('0x33')]+'\x20'+_0x54f6f3[_0x0d8b('0x28')]['last_name']});}else{logger[_0x0d8b('0x19')](_0x0d8b('0x34'));return BPromise[_0x0d8b('0x31')]({'id':_0x48f24f['userId'],'email':_0x4b59e5[_0x0d8b('0x23')],'name':_0x0d8b('0x35')});}})[_0x0d8b('0x36')](function(_0x31ceba){var _0x933e01=_0x31ceba['statusCode']||0x1f4;logger[_0x0d8b('0x2a')](_0x0d8b('0x2c'),'getUser',_0x933e01,JSON[_0x0d8b('0x26')](_0x31ceba));});}else{logger[_0x0d8b('0x19')](_0x0d8b('0x34'));return BPromise[_0x0d8b('0x31')]({'id':_0x48f24f[_0x0d8b('0x37')],'email':_0x4b59e5['username'],'name':'admin'})[_0x0d8b('0x36')](function(_0x5c2c04){var _0x531c55=_0x5c2c04[_0x0d8b('0x2b')]||0x1f4;logger[_0x0d8b('0x2a')](_0x0d8b('0x2c'),_0x0d8b('0x38'),_0x531c55,JSON[_0x0d8b('0x26')](_0x5c2c04));});}}function getEndUser(_0x24c789,_0x579324,_0x6e5bab,_0x6a02ad){logger[_0x0d8b('0x19')](_0x0d8b('0x39'),_0x6e5bab);return request({'method':_0x0d8b('0x3a'),'uri':util[_0x0d8b('0x1f')](_0x0d8b('0x20'),_0x24c789['remoteUri']),'qs':{'operation':_0x0d8b('0x3b'),'username':_0x24c789[_0x0d8b('0x23')],'sessionName':_0x6a02ad[_0x0d8b('0x24')],'query':util[_0x0d8b('0x1f')]('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;',_0x6e5bab,_0x6e5bab,_0x6e5bab,_0x6e5bab,_0x6e5bab)},'json':!![]})[_0x0d8b('0x2f')](function(_0x4b4bde){if(_0x4b4bde[_0x0d8b('0x27')]&&_0x4b4bde[_0x0d8b('0x28')][_0x0d8b('0xb')]){logger[_0x0d8b('0x19')](_0x0d8b('0x3c'));return BPromise[_0x0d8b('0x31')]({'id':_0x4b4bde[_0x0d8b('0x28')][0x0]['id'],'name':_0x4b4bde[_0x0d8b('0x28')][0x0][_0x0d8b('0x3d')]+'\x20'+_0x4b4bde[_0x0d8b('0x28')][0x0]['lastname'],'phone':_0x6e5bab});}else{logger['info']('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'method':'POST','uri':util['format'](_0x0d8b('0x20'),_0x24c789[_0x0d8b('0x21')]),'form':{'operation':_0x0d8b('0x22'),'sessionName':_0x6a02ad['sessionName'],'elementType':'Contacts','element':JSON[_0x0d8b('0x26')]({'lastname':_0x579324,'phone':_0x6e5bab,'assigned_user_id':'\x20'})},'json':!![]})[_0x0d8b('0x2f')](function(_0x344278){logger['info'](_0x0d8b('0x3e'));return BPromise[_0x0d8b('0x31')]({'id':_0x344278['result']['id'],'name':_0x344278['result'][_0x0d8b('0x3f')],'phone':_0x344278['result'][_0x0d8b('0x40')]});})['catch'](function(_0x53f643){var _0x30ccee=_0x53f643[_0x0d8b('0x2b')]||0x1f4;logger['error']('[vTiger],\x20%s,\x20%s,\x20%s','getEndUser',_0x30ccee,JSON['stringify'](_0x53f643));});}});}function getConnection(_0x374d40){var _0x1e0498=_0x374d40[_0x0d8b('0x23')];var _0x490eda=_0x374d40[_0x0d8b('0x41')];return request({'method':_0x0d8b('0x3a'),'uri':util[_0x0d8b('0x1f')](_0x0d8b('0x20'),_0x374d40[_0x0d8b('0x21')]),'qs':{'operation':_0x0d8b('0x42'),'username':_0x1e0498},'json':!![]})[_0x0d8b('0x2f')](function(_0x1d5067){if(_0x1d5067[_0x0d8b('0x27')]){return request({'method':_0x0d8b('0x1e'),'uri':util[_0x0d8b('0x1f')](_0x0d8b('0x20'),_0x374d40[_0x0d8b('0x21')]),'form':{'operation':_0x0d8b('0x43'),'username':_0x1e0498,'accessKey':md5(_0x1d5067[_0x0d8b('0x28')][_0x0d8b('0x44')]+_0x490eda)},'json':!![]});}})[_0x0d8b('0x2f')](function(_0x1e162c){if(_0x1e162c[_0x0d8b('0x27')]){return BPromise['resolve'](_0x1e162c[_0x0d8b('0x28')]);}else{throw new Error(util['format']('Account\x20%d\x20is\x20not\x20valid',_0x374d40['id']));}})[_0x0d8b('0x36')](function(_0x113fb7){var _0x3f943a=_0x113fb7[_0x0d8b('0x2b')]||0x1f4;logger['error'](_0x0d8b('0x2c'),_0x0d8b('0x45'),_0x3f943a,JSON[_0x0d8b('0x26')](_0x113fb7));});}function request(_0x241587){logger[_0x0d8b('0x19')]('[HTTP]',JSON['stringify'](_0x241587));return rp(_0x241587);}exports['queue']=function(_0x573f4f,_0x368ede,_0xf22c3c,_0x5e3bb4,_0x4950a8,_0x44c5c1){var _0x3d3cb6,_0x5c5bd7,_0x5ef6c3,_0x900906;_0x44c5c1[_0x0d8b('0x21')]=intUtil[_0x0d8b('0x46')](_0x44c5c1[_0x0d8b('0x21')]);if(_0x4950a8&&_0x4950a8[_0x0d8b('0x47')]){logger['info'](_0x0d8b('0x48'),_0x0d8b('0x49'));_0x368ede['recordingURL']=util['format'](_0x0d8b('0x4a'),_0x44c5c1[_0x0d8b('0x4b')],_0x368ede['uniqueid'],md5(_0x368ede['uniqueid']));}else{_0x368ede[_0x0d8b('0x4c')]='';}return getConnection(_0x44c5c1)[_0x0d8b('0x2f')](function(_0x377027){_0x900906=_0x377027;return getUser(_0x44c5c1,_0x5e3bb4[_0x0d8b('0x4d')],_0x900906);})['then'](function(_0x356b3d){_0x3d3cb6=_0x356b3d;logger['info']('The\x20User\x20ID\x20is:',_0x3d3cb6['id']);return getEndUser(_0x44c5c1,_0x368ede[_0x0d8b('0x4e')],_0x368ede[_0x0d8b('0x4f')],_0x900906);})['then'](function(_0x4a8f33){_0x5c5bd7=_0x4a8f33;logger[_0x0d8b('0x19')](_0x0d8b('0x50'),_0x5c5bd7['id']);return createTicket(_0x44c5c1,_0x3d3cb6,_0x5c5bd7,_0xf22c3c,_0x368ede,_0xf22c3c[_0x0d8b('0x51')],_0x900906);})[_0x0d8b('0x2f')](function(_0x3afc3a){_0x5ef6c3=_0x3afc3a;logger[_0x0d8b('0x19')](_0x0d8b('0x52'));logger[_0x0d8b('0x19')]('The\x20Ticket\x20ID\x20is:',_0x5ef6c3['id']);var _0x24a859=util[_0x0d8b('0x1f')](_0x0d8b('0x53'),_0x44c5c1[_0x0d8b('0x21')],_[_0x0d8b('0x54')](_0x5ef6c3['id'],'x')[0x1]);logger[_0x0d8b('0x19')](_0x0d8b('0x48'),_0x0d8b('0x55'));emit(util[_0x0d8b('0x1f')]('user:%s',_0x5e3bb4[_0x0d8b('0x17')]),_0x0d8b('0x56'),{'uri':_0x24a859});})[_0x0d8b('0x36')](function(_0x23de9e){logger[_0x0d8b('0x2a')]('[QUEUE]',JSON[_0x0d8b('0x26')](_0x23de9e));});};exports[_0x0d8b('0x57')]=function(_0x181d49,_0x17a87f,_0x1d6cd4,_0x59ada2,_0x4d0e7c,_0x3b1166,_0x291b83){var _0x3e4a41,_0xbbb520,_0x5a70bd,_0x199122;_0x3b1166[_0x0d8b('0x21')]=intUtil[_0x0d8b('0x46')](_0x3b1166['remoteUri']);_0x3b1166[_0x0d8b('0x4b')]=intUtil['stripTrailingSlash'](_0x3b1166[_0x0d8b('0x4b')]);if(_0x291b83&&_0x291b83[_0x0d8b('0x58')]&&_0x291b83[_0x0d8b('0x58')]!==_0x0d8b('0x59')){logger[_0x0d8b('0x19')](_0x0d8b('0x5a'),'Recording\x20is\x20enabled!');_0x17a87f[_0x0d8b('0x4c')]=util['format'](_0x0d8b('0x4a'),_0x3b1166[_0x0d8b('0x4b')],_0x17a87f[_0x0d8b('0x5b')],md5(_0x17a87f[_0x0d8b('0x5b')]));}return getConnection(_0x3b1166)['then'](function(_0x19e097){_0x199122=_0x19e097;return getUser(_0x3b1166,_0x59ada2[_0x0d8b('0x4d')],_0x199122);})[_0x0d8b('0x2f')](function(_0x2332fc){_0x3e4a41=_0x2332fc;logger[_0x0d8b('0x19')](_0x0d8b('0x5c'),_0x3e4a41['id']);return getEndUser(_0x3b1166,_0x17a87f[_0x0d8b('0x5d')],_0x17a87f[_0x0d8b('0x5e')],_0x199122);})[_0x0d8b('0x2f')](function(_0x34affb){_0xbbb520=_0x34affb;logger['info']('The\x20Enduser\x20ID\x20is:',_0xbbb520['id']);return createTicket(_0x3b1166,_0x3e4a41,_0xbbb520,_0x1d6cd4,_0x17a87f,_0x1d6cd4[_0x0d8b('0x51')],_0x199122);})[_0x0d8b('0x2f')](function(_0x53e399){_0x5a70bd=_0x53e399;logger[_0x0d8b('0x19')]('Ticket\x20created!');logger['info'](_0x0d8b('0x5f'),_0x5a70bd['id']);var _0x1c4e96=util['format']('%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT',_0x3b1166[_0x0d8b('0x21')],_[_0x0d8b('0x54')](_0x5a70bd['id'],'x')[0x1]);logger[_0x0d8b('0x19')](_0x0d8b('0x5a'),_0x0d8b('0x55'));emit(util[_0x0d8b('0x1f')](_0x0d8b('0x60'),_0x59ada2['name']),_0x0d8b('0x56'),{'uri':_0x1c4e96});})['catch'](function(_0x1a203e){logger[_0x0d8b('0x2a')](_0x0d8b('0x5a'),JSON[_0x0d8b('0x26')](_0x1a203e));});};exports['unmanaged']=function(_0x3fe47d,_0x4a1c4a,_0x3a356b,_0x2c6c5f,_0x1c5fe2,_0x2ebea3){var _0xc5c35f,_0x2b44e5,_0x3e927c,_0x91aa89;_0x2ebea3[_0x0d8b('0x21')]=intUtil[_0x0d8b('0x46')](_0x2ebea3['remoteUri']);_0x2ebea3[_0x0d8b('0x4b')]=intUtil['stripTrailingSlash'](_0x2ebea3[_0x0d8b('0x4b')]);if(_0x1c5fe2&&_0x1c5fe2[_0x0d8b('0x47')]){logger['info']('['+_0x4a1c4a[_0x0d8b('0x61')]['toUpperCase']()+']',_0x0d8b('0x49'));_0x4a1c4a[_0x0d8b('0x4c')]=util[_0x0d8b('0x1f')](_0x0d8b('0x4a'),_0x2ebea3[_0x0d8b('0x4b')],_0x4a1c4a[_0x0d8b('0x5b')],md5(_0x4a1c4a[_0x0d8b('0x5b')]));}else{_0x4a1c4a[_0x0d8b('0x4c')]='';}return getConnection(_0x2ebea3)['then'](function(_0x10eca6){_0x91aa89=_0x10eca6;return getUser(_0x2ebea3,'',_0x91aa89);})[_0x0d8b('0x2f')](function(_0x5b2916){_0xc5c35f=_0x5b2916;logger[_0x0d8b('0x19')](_0x0d8b('0x5c'),_0xc5c35f['id']);return getEndUser(_0x2ebea3,_0x4a1c4a[_0x0d8b('0x4e')],_0x4a1c4a[_0x0d8b('0x4f')],_0x91aa89);})[_0x0d8b('0x2f')](function(_0x9e44b4){_0x2b44e5=_0x9e44b4;logger[_0x0d8b('0x19')](_0x0d8b('0x50'),_0x2b44e5['id']);return createTicket(_0x2ebea3,_0xc5c35f,_0x2b44e5,_0x3a356b,_0x4a1c4a,_0x3a356b[_0x0d8b('0x51')],_0x91aa89);})[_0x0d8b('0x2f')](function(_0xe35028){_0x3e927c=_0xe35028;logger[_0x0d8b('0x19')]('Ticket\x20created!');logger[_0x0d8b('0x19')](_0x0d8b('0x5f'),_0x3e927c['id']);})[_0x0d8b('0x36')](function(_0x58525c){logger['error']('['+_0x4a1c4a[_0x0d8b('0x61')][_0x0d8b('0x62')]()+']',JSON[_0x0d8b('0x26')](_0x58525c));});};
\ No newline at end of file