Built motion from commit (unavailable).|2.5.30
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index d266a05..83708a5 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 _0x130b=['The\x20Ticket\x20ID\x20is:','[OUTBOUND]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','toUpperCase','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','lastevent','bluebird','md5','util','ioredis','../../../../config/logger','vTiger','redis','defaults','localhost','socket.io-emitter','emit','length','includes','string','picklist','idField','content','toString','type','variable','variableName','customVariable','name','Variable','toLowerCase','info','merge','Open','getString','Descriptions','POST','format','%s/webservice.php','create','username','sessionName','then','success','resolve','error','[vTiger],\x20%s,\x20%s,\x20%s','Getting\x20agent\x20with\x20email','GET','remoteUri','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','result','Agent\x20found!','email1','first_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','catch','statusCode','getUser','userId','admin','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','stringify','Enduser\x20created.','phone','getEndUser','accessKey','getchallenge','token','getConnection','stripTrailingSlash','monitor_format','Recording\x20is\x20enabled!','recordingURL','serverUrl','uniqueid','email','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Fields','%s/index.php?module=HelpDesk&view=Detail&record=%s&app=SUPPORT','split','[QUEUE]','user:%s','none','The\x20User\x20ID\x20is:','destcalleridname','Ticket\x20created!'];(function(_0x4eb5b9,_0x35c185){var _0x3de2fd=function(_0x43d6c9){while(--_0x43d6c9){_0x4eb5b9['push'](_0x4eb5b9['shift']());}};_0x3de2fd(++_0x35c185);}(_0x130b,0x187));var _0xb130=function(_0x138adb,_0x193fee){_0x138adb=_0x138adb-0x0;var _0x1b27f2=_0x130b[_0x138adb];return _0x1b27f2;};'use strict';var _=require('lodash');var rp=require('request-promise');var BPromise=require(_0xb130('0x0'));var md5=require(_0xb130('0x1'));var util=require(_0xb130('0x2'));var Redis=require(_0xb130('0x3'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require(_0xb130('0x4'))(_0xb130('0x5'));config[_0xb130('0x6')]=_[_0xb130('0x7')](config['redis'],{'host':_0xb130('0x8'),'port':0x18eb});var io=require(_0xb130('0x9'))(new Redis(config[_0xb130('0x6')]));function emit(_0x527502,_0x385805,_0x5b14f9){io['to'](_0x527502)[_0xb130('0xa')](_0x385805,_0x5b14f9);}function getCustomFields(_0x222c77,_0x4e0c24){var _0x1bbd22={};if(_0x222c77[_0xb130('0xb')]>0x0){_['forEach'](_0x222c77,function(_0x4798e2){if(_[_0xb130('0xc')]([_0xb130('0xd'),_0xb130('0xe')],_0x4798e2['type'])&&_0x4798e2[_0xb130('0xf')]){_0x1bbd22[_0x4798e2[_0xb130('0xf')]]=_0x4798e2[_0xb130('0x10')][_0xb130('0x11')]();}else if(_0x4798e2[_0xb130('0x12')]===_0xb130('0x13')&&_0x4798e2[_0xb130('0x14')]&&_0x4798e2[_0xb130('0xf')]&&_0x4e0c24[_0x4798e2['variableName']]){_0x1bbd22[_0x4798e2[_0xb130('0xf')]]=_0x4e0c24[_0x4798e2['variableName']][_0xb130('0x11')]();}else if(_0x4798e2['type']===_0xb130('0x15')&&_0x4798e2['Variable']&&_0x4798e2['Variable'][_0xb130('0x16')]&&_0x4798e2['idField']&&_0x4e0c24[_0x4798e2[_0xb130('0x17')]['name'][_0xb130('0x18')]()]){_0x1bbd22[_0x4798e2[_0xb130('0xf')]]=_0x4e0c24[_0x4798e2[_0xb130('0x17')][_0xb130('0x16')][_0xb130('0x18')]()][_0xb130('0x11')]();}});}return _0x1bbd22;}function createTicket(_0x17fee7,_0x40d8fd,_0x20c11d,_0x3d8316,_0x3d2eae,_0x19661b,_0x4f3809){logger[_0xb130('0x19')]('Creating\x20new\x20ticket...');var _0x2c2595=_[_0xb130('0x1a')]({'parent_id':'','assigned_user_id':_0x40d8fd['id'],'ticketpriorities':'Normal','ticketstatus':_0xb130('0x1b'),'ticket_title':intUtil[_0xb130('0x1c')](_0x3d8316['Subjects'],_0x3d2eae,'\x20'),'description':intUtil[_0xb130('0x1c')](_0x3d8316[_0xb130('0x1d')],_0x3d2eae,'\x0a'),'contact_id':_0x20c11d['id']},getCustomFields(_0x19661b,_0x3d2eae));var _0xbbc432={'method':_0xb130('0x1e'),'uri':util[_0xb130('0x1f')](_0xb130('0x20'),_0x17fee7['remoteUri']),'form':{'operation':_0xb130('0x21'),'username':_0x17fee7[_0xb130('0x22')],'sessionName':_0x4f3809[_0xb130('0x23')],'elementType':'HelpDesk','element':JSON['stringify'](_0x2c2595)},'json':!![]};return request(_0xbbc432)[_0xb130('0x24')](function(_0x224012){if(_0x224012[_0xb130('0x25')]){return BPromise[_0xb130('0x26')]({'id':_0x224012['result']['id']});}else{throw new Error(util[_0xb130('0x1f')]('Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s',JSON['stringify'](_0x224012[_0xb130('0x27')])));}})['catch'](function(_0x20fba9){var _0x40b8b8=_0x20fba9['statusCode']||0x1f4;logger[_0xb130('0x27')](_0xb130('0x28'),'createTicket',_0x40b8b8,JSON['stringify'](_0x20fba9));});}function getUser(_0x566da7,_0x3d9bd8,_0x5c78ea){if(intUtil['validateEmail'](_0x3d9bd8)){logger['info'](_0xb130('0x29'),_0x3d9bd8);return request({'method':_0xb130('0x2a'),'uri':util[_0xb130('0x1f')]('%s/webservice.php',_0x566da7[_0xb130('0x2b')]),'qs':{'operation':'query','username':_0x566da7[_0xb130('0x22')],'sessionName':_0x5c78ea[_0xb130('0x23')],'query':util[_0xb130('0x1f')](_0xb130('0x2c'),_0x3d9bd8)},'json':!![]})[_0xb130('0x24')](function(_0x4b5771){if(_0x4b5771[_0xb130('0x25')]&&_0x4b5771[_0xb130('0x2d')][_0xb130('0xb')]){logger['info'](_0xb130('0x2e'));return BPromise[_0xb130('0x26')]({'id':_0x4b5771[_0xb130('0x2d')][0x0]['id'],'email':_0x4b5771[_0xb130('0x2d')][0x0][_0xb130('0x2f')],'name':_0x4b5771[_0xb130('0x2d')][0x0][_0xb130('0x30')]+'\x20'+_0x4b5771[_0xb130('0x2d')]['last_name']});}else{logger['info'](_0xb130('0x31'));return BPromise[_0xb130('0x26')]({'id':_0x5c78ea['userId'],'email':_0x566da7[_0xb130('0x22')],'name':'admin'});}})[_0xb130('0x32')](function(_0x13e3fb){var _0x1f770c=_0x13e3fb[_0xb130('0x33')]||0x1f4;logger['error'](_0xb130('0x28'),_0xb130('0x34'),_0x1f770c,JSON['stringify'](_0x13e3fb));});}else{logger[_0xb130('0x19')](_0xb130('0x31'));return BPromise[_0xb130('0x26')]({'id':_0x5c78ea[_0xb130('0x35')],'email':_0x566da7['username'],'name':_0xb130('0x36')})['catch'](function(_0x2e395a){var _0xffe6a8=_0x2e395a[_0xb130('0x33')]||0x1f4;logger[_0xb130('0x27')](_0xb130('0x28'),_0xb130('0x34'),_0xffe6a8,JSON['stringify'](_0x2e395a));});}}function getEndUser(_0x1235e4,_0x4c49ab,_0x5dae3c,_0x34f467){logger[_0xb130('0x19')]('Searching\x20end\x20user\x20with\x20phone',_0x5dae3c);return request({'method':'GET','uri':util[_0xb130('0x1f')]('%s/webservice.php',_0x1235e4[_0xb130('0x2b')]),'qs':{'operation':_0xb130('0x37'),'username':_0x1235e4[_0xb130('0x22')],'sessionName':_0x34f467[_0xb130('0x23')],'query':util[_0xb130('0x1f')](_0xb130('0x38'),_0x5dae3c,_0x5dae3c,_0x5dae3c,_0x5dae3c,_0x5dae3c)},'json':!![]})[_0xb130('0x24')](function(_0x2d95bb){if(_0x2d95bb[_0xb130('0x25')]&&_0x2d95bb[_0xb130('0x2d')]['length']){logger['info'](_0xb130('0x39'));return BPromise['resolve']({'id':_0x2d95bb[_0xb130('0x2d')][0x0]['id'],'name':_0x2d95bb[_0xb130('0x2d')][0x0][_0xb130('0x3a')]+'\x20'+_0x2d95bb[_0xb130('0x2d')][0x0][_0xb130('0x3b')],'phone':_0x5dae3c});}else{logger[_0xb130('0x19')](_0xb130('0x3c'));return request({'method':_0xb130('0x1e'),'uri':util[_0xb130('0x1f')](_0xb130('0x20'),_0x1235e4[_0xb130('0x2b')]),'form':{'operation':_0xb130('0x21'),'sessionName':_0x34f467[_0xb130('0x23')],'elementType':_0xb130('0x3d'),'element':JSON[_0xb130('0x3e')]({'lastname':_0x4c49ab,'phone':_0x5dae3c,'assigned_user_id':'\x20'})},'json':!![]})[_0xb130('0x24')](function(_0x202503){logger[_0xb130('0x19')](_0xb130('0x3f'));return BPromise['resolve']({'id':_0x202503[_0xb130('0x2d')]['id'],'name':_0x202503[_0xb130('0x2d')][_0xb130('0x3b')],'phone':_0x202503[_0xb130('0x2d')][_0xb130('0x40')]});})[_0xb130('0x32')](function(_0x460ad5){var _0x4442b0=_0x460ad5[_0xb130('0x33')]||0x1f4;logger['error'](_0xb130('0x28'),_0xb130('0x41'),_0x4442b0,JSON[_0xb130('0x3e')](_0x460ad5));});}});}function getConnection(_0x32e78a){var _0x1982dc=_0x32e78a[_0xb130('0x22')];var _0x55b83c=_0x32e78a[_0xb130('0x42')];return request({'method':'GET','uri':util[_0xb130('0x1f')](_0xb130('0x20'),_0x32e78a[_0xb130('0x2b')]),'qs':{'operation':_0xb130('0x43'),'username':_0x1982dc},'json':!![]})['then'](function(_0xf524){if(_0xf524[_0xb130('0x25')]){return request({'method':'POST','uri':util[_0xb130('0x1f')](_0xb130('0x20'),_0x32e78a['remoteUri']),'form':{'operation':'login','username':_0x1982dc,'accessKey':md5(_0xf524[_0xb130('0x2d')][_0xb130('0x44')]+_0x55b83c)},'json':!![]});}})['then'](function(_0x583d19){if(_0x583d19[_0xb130('0x25')]){return BPromise['resolve'](_0x583d19[_0xb130('0x2d')]);}else{throw new Error(util['format']('Account\x20%d\x20is\x20not\x20valid',_0x32e78a['id']));}})[_0xb130('0x32')](function(_0x28fb35){var _0x273739=_0x28fb35['statusCode']||0x1f4;logger[_0xb130('0x27')](_0xb130('0x28'),_0xb130('0x45'),_0x273739,JSON[_0xb130('0x3e')](_0x28fb35));});}function request(_0x178e38){logger[_0xb130('0x19')]('[HTTP]',JSON[_0xb130('0x3e')](_0x178e38));return rp(_0x178e38);}exports['queue']=function(_0x58a7f7,_0x51f91b,_0x4d49ec,_0x34641f,_0x271e40,_0x27b51d){var _0x3e11d3,_0x5a85af,_0x3da9dd,_0x308e21;_0x27b51d[_0xb130('0x2b')]=intUtil[_0xb130('0x46')](_0x27b51d['remoteUri']);if(_0x271e40&&_0x271e40[_0xb130('0x47')]){logger['info']('[QUEUE]',_0xb130('0x48'));_0x51f91b[_0xb130('0x49')]=util[_0xb130('0x1f')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x27b51d[_0xb130('0x4a')],_0x51f91b[_0xb130('0x4b')],md5(_0x51f91b[_0xb130('0x4b')]));}else{_0x51f91b[_0xb130('0x49')]='';}return getConnection(_0x27b51d)[_0xb130('0x24')](function(_0x97b4de){_0x308e21=_0x97b4de;return getUser(_0x27b51d,_0x34641f[_0xb130('0x4c')],_0x308e21);})[_0xb130('0x24')](function(_0x2cce93){_0x3e11d3=_0x2cce93;logger['info']('The\x20User\x20ID\x20is:',_0x3e11d3['id']);return getEndUser(_0x27b51d,_0x51f91b[_0xb130('0x4d')],_0x51f91b[_0xb130('0x4e')],_0x308e21);})[_0xb130('0x24')](function(_0x16cf5d){_0x5a85af=_0x16cf5d;logger[_0xb130('0x19')](_0xb130('0x4f'),_0x5a85af['id']);return createTicket(_0x27b51d,_0x3e11d3,_0x5a85af,_0x4d49ec,_0x51f91b,_0x4d49ec[_0xb130('0x50')],_0x308e21);})[_0xb130('0x24')](function(_0x22821b){_0x3da9dd=_0x22821b;logger[_0xb130('0x19')]('Ticket\x20created!');logger[_0xb130('0x19')]('The\x20Ticket\x20ID\x20is:',_0x3da9dd['id']);var _0x4a3549=util[_0xb130('0x1f')](_0xb130('0x51'),_0x27b51d[_0xb130('0x2b')],_[_0xb130('0x52')](_0x3da9dd['id'],'x')[0x1]);logger[_0xb130('0x19')](_0xb130('0x53'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xb130('0x1f')](_0xb130('0x54'),_0x34641f[_0xb130('0x16')]),'trigger:browser:url',{'uri':_0x4a3549});})[_0xb130('0x32')](function(_0x3dfa23){logger[_0xb130('0x27')](_0xb130('0x53'),JSON[_0xb130('0x3e')](_0x3dfa23));});};exports['outbound']=function(_0x4cb341,_0x5a8e39,_0x213f64,_0x1c62c9,_0x360bb6,_0x3e5528,_0x3a40d5){var _0x578815,_0x59010b,_0x18458d,_0x183f98;_0x3e5528[_0xb130('0x2b')]=intUtil['stripTrailingSlash'](_0x3e5528[_0xb130('0x2b')]);_0x3e5528[_0xb130('0x4a')]=intUtil[_0xb130('0x46')](_0x3e5528['serverUrl']);if(_0x3a40d5&&_0x3a40d5['recordingFormat']&&_0x3a40d5['recordingFormat']!==_0xb130('0x55')){logger[_0xb130('0x19')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x5a8e39[_0xb130('0x49')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x3e5528['serverUrl'],_0x5a8e39[_0xb130('0x4b')],md5(_0x5a8e39[_0xb130('0x4b')]));}return getConnection(_0x3e5528)[_0xb130('0x24')](function(_0x294865){_0x183f98=_0x294865;return getUser(_0x3e5528,_0x1c62c9['email'],_0x183f98);})[_0xb130('0x24')](function(_0x9d2f71){_0x578815=_0x9d2f71;logger[_0xb130('0x19')](_0xb130('0x56'),_0x578815['id']);return getEndUser(_0x3e5528,_0x5a8e39[_0xb130('0x57')],_0x5a8e39['destcalleridnum'],_0x183f98);})[_0xb130('0x24')](function(_0x2afea1){_0x59010b=_0x2afea1;logger[_0xb130('0x19')](_0xb130('0x4f'),_0x59010b['id']);return createTicket(_0x3e5528,_0x578815,_0x59010b,_0x213f64,_0x5a8e39,_0x213f64['Fields'],_0x183f98);})[_0xb130('0x24')](function(_0x344ad2){_0x18458d=_0x344ad2;logger[_0xb130('0x19')](_0xb130('0x58'));logger[_0xb130('0x19')](_0xb130('0x59'),_0x18458d['id']);var _0x116bf4=util[_0xb130('0x1f')](_0xb130('0x51'),_0x3e5528['remoteUri'],_[_0xb130('0x52')](_0x18458d['id'],'x')[0x1]);logger[_0xb130('0x19')](_0xb130('0x5a'),_0xb130('0x5b'));emit(util[_0xb130('0x1f')](_0xb130('0x54'),_0x1c62c9['name']),_0xb130('0x5c'),{'uri':_0x116bf4});})['catch'](function(_0x2926ed){logger[_0xb130('0x27')](_0xb130('0x5a'),JSON[_0xb130('0x3e')](_0x2926ed));});};exports['unmanaged']=function(_0x70d2d6,_0x1cfc90,_0x5897f1,_0xedbdef,_0x3e407e,_0x2300a0){var _0x31bc78,_0xe145e5,_0x1a07fa,_0x569d36;_0x2300a0[_0xb130('0x2b')]=intUtil[_0xb130('0x46')](_0x2300a0['remoteUri']);_0x2300a0[_0xb130('0x4a')]=intUtil[_0xb130('0x46')](_0x2300a0[_0xb130('0x4a')]);if(_0x3e407e&&_0x3e407e[_0xb130('0x47')]){logger['info']('['+_0x1cfc90['lastevent'][_0xb130('0x5d')]()+']',_0xb130('0x48'));_0x1cfc90[_0xb130('0x49')]=util[_0xb130('0x1f')](_0xb130('0x5e'),_0x2300a0[_0xb130('0x4a')],_0x1cfc90[_0xb130('0x4b')],md5(_0x1cfc90['uniqueid']));}else{_0x1cfc90[_0xb130('0x49')]='';}return getConnection(_0x2300a0)[_0xb130('0x24')](function(_0x410ddb){_0x569d36=_0x410ddb;return getUser(_0x2300a0,'',_0x569d36);})[_0xb130('0x24')](function(_0x8883b9){_0x31bc78=_0x8883b9;logger['info'](_0xb130('0x56'),_0x31bc78['id']);return getEndUser(_0x2300a0,_0x1cfc90[_0xb130('0x4d')],_0x1cfc90[_0xb130('0x4e')],_0x569d36);})[_0xb130('0x24')](function(_0x2d2252){_0xe145e5=_0x2d2252;logger[_0xb130('0x19')](_0xb130('0x4f'),_0xe145e5['id']);return createTicket(_0x2300a0,_0x31bc78,_0xe145e5,_0x5897f1,_0x1cfc90,_0x5897f1[_0xb130('0x50')],_0x569d36);})[_0xb130('0x24')](function(_0x4f1a51){_0x1a07fa=_0x4f1a51;logger[_0xb130('0x19')](_0xb130('0x58'));logger[_0xb130('0x19')](_0xb130('0x59'),_0x1a07fa['id']);})[_0xb130('0x32')](function(_0x355f03){logger['error']('['+_0x1cfc90[_0xb130('0x5f')]['toUpperCase']()+']',JSON['stringify'](_0x355f03));});};
\ No newline at end of file