Built motion from commit (unavailable).|2.5.17
[motion2.git] / server / services / ami / trigger / integration / vtiger.js
index 0b9e046..d266a05 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2144=['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','recordingFormat','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','destcalleridname','destcalleridnum','Ticket\x20created!','[OUTBOUND]','unmanaged','lastevent','toUpperCase','lodash','request-promise','md5','ioredis','./util','../../../../config/environment','vTiger','defaults','redis','emit','length','forEach','type','string','idField','content','toString','variableName','Variable','name','toLowerCase','Creating\x20new\x20ticket...','Normal','Open','getString','Subjects','Descriptions','POST','format','remoteUri','username','sessionName','HelpDesk','stringify','success','resolve','result','Ticket\x20could\x20not\x20be\x20created\x20due\x20to:\x20%s','catch','statusCode','error','validateEmail','info','Getting\x20agent\x20with\x20email','GET','%s/webservice.php','query','SELECT\x20first_name,\x20last_name,\x20email1\x20FROM\x20Users\x20WHERE\x20email1=\x27%s\x27;','email1','first_name','last_name','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userId','admin','[vTiger],\x20%s,\x20%s,\x20%s','getUser','Searching\x20end\x20user\x20with\x20phone','then','Enduser\x20found!','firstname','lastname','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','create','Contacts','Enduser\x20created.','getEndUser','login','token','getConnection','[HTTP]','stripTrailingSlash','monitor_format','[QUEUE]','recordingURL','serverUrl','uniqueid','email','The\x20User\x20ID\x20is:','calleridname'];(function(_0x2d3c54,_0x541000){var _0x2e1079=function(_0x400dc3){while(--_0x400dc3){_0x2d3c54['push'](_0x2d3c54['shift']());}};_0x2e1079(++_0x541000);}(_0x2144,0x73));var _0x4214=function(_0x2cd1fb,_0x291f55){_0x2cd1fb=_0x2cd1fb-0x0;var _0x48fd2b=_0x2144[_0x2cd1fb];return _0x48fd2b;};'use strict';var _=require(_0x4214('0x0'));var rp=require(_0x4214('0x1'));var BPromise=require('bluebird');var md5=require(_0x4214('0x2'));var util=require('util');var Redis=require(_0x4214('0x3'));var intUtil=require(_0x4214('0x4'));var config=require(_0x4214('0x5'));var logger=require('../../../../config/logger')(_0x4214('0x6'));config['redis']=_[_0x4214('0x7')](config[_0x4214('0x8')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x4214('0x8')]));function emit(_0x38e484,_0x1167a4,_0x13d3cd){io['to'](_0x38e484)[_0x4214('0x9')](_0x1167a4,_0x13d3cd);}function getCustomFields(_0x40b3c4,_0x5b31d0){var _0x511276={};if(_0x40b3c4[_0x4214('0xa')]>0x0){_[_0x4214('0xb')](_0x40b3c4,function(_0x55ecb9){if(_0x55ecb9[_0x4214('0xc')]===_0x4214('0xd')&&_0x55ecb9[_0x4214('0xe')]){_0x511276[_0x55ecb9[_0x4214('0xe')]]=_0x55ecb9[_0x4214('0xf')][_0x4214('0x10')]();}else if(_0x55ecb9[_0x4214('0xc')]==='variable'&&_0x55ecb9[_0x4214('0x11')]&&_0x55ecb9['idField']&&_0x5b31d0[_0x55ecb9[_0x4214('0x11')]]){_0x511276[_0x55ecb9['idField']]=_0x5b31d0[_0x55ecb9[_0x4214('0x11')]][_0x4214('0x10')]();}else if(_0x55ecb9[_0x4214('0xc')]==='customVariable'&&_0x55ecb9['Variable']&&_0x55ecb9[_0x4214('0x12')][_0x4214('0x13')]&&_0x55ecb9[_0x4214('0xe')]&&_0x5b31d0[_0x55ecb9['Variable']['name'][_0x4214('0x14')]()]){_0x511276[_0x55ecb9[_0x4214('0xe')]]=_0x5b31d0[_0x55ecb9['Variable'][_0x4214('0x13')]['toLowerCase']()][_0x4214('0x10')]();}});}return _0x511276;}function createTicket(_0x52b5b2,_0x4d3e0b,_0x23cf6d,_0x114b50,_0x4bceda,_0x250b64,_0x32485b){logger['info'](_0x4214('0x15'));var _0x296440=_['merge']({'parent_id':'','assigned_user_id':_0x4d3e0b['id'],'ticketpriorities':_0x4214('0x16'),'ticketstatus':_0x4214('0x17'),'ticket_title':intUtil[_0x4214('0x18')](_0x114b50[_0x4214('0x19')],_0x4bceda,'\x20'),'description':intUtil[_0x4214('0x18')](_0x114b50[_0x4214('0x1a')],_0x4bceda,'\x0a'),'contact_id':_0x23cf6d['id']},getCustomFields(_0x250b64,_0x4bceda));var _0x424365={'method':_0x4214('0x1b'),'uri':util[_0x4214('0x1c')]('%s/webservice.php',_0x52b5b2[_0x4214('0x1d')]),'form':{'operation':'create','username':_0x52b5b2[_0x4214('0x1e')],'sessionName':_0x32485b[_0x4214('0x1f')],'elementType':_0x4214('0x20'),'element':JSON[_0x4214('0x21')](_0x296440)},'json':!![]};return request(_0x424365)['then'](function(_0x474190){if(_0x474190[_0x4214('0x22')]){return BPromise[_0x4214('0x23')]({'id':_0x474190[_0x4214('0x24')]['id']});}else{throw new Error(util['format'](_0x4214('0x25'),JSON[_0x4214('0x21')](_0x474190['error'])));}})[_0x4214('0x26')](function(_0x31938e){var _0x3a4f95=_0x31938e[_0x4214('0x27')]||0x1f4;logger[_0x4214('0x28')]('[vTiger],\x20%s,\x20%s,\x20%s','createTicket',_0x3a4f95,JSON['stringify'](_0x31938e));});}function getUser(_0x5c874a,_0x38768e,_0x472da9){if(intUtil[_0x4214('0x29')](_0x38768e)){logger[_0x4214('0x2a')](_0x4214('0x2b'),_0x38768e);return request({'method':_0x4214('0x2c'),'uri':util['format'](_0x4214('0x2d'),_0x5c874a['remoteUri']),'qs':{'operation':_0x4214('0x2e'),'username':_0x5c874a[_0x4214('0x1e')],'sessionName':_0x472da9[_0x4214('0x1f')],'query':util[_0x4214('0x1c')](_0x4214('0x2f'),_0x38768e)},'json':!![]})['then'](function(_0x37bf33){if(_0x37bf33[_0x4214('0x22')]&&_0x37bf33['result']['length']){logger[_0x4214('0x2a')]('Agent\x20found!');return BPromise[_0x4214('0x23')]({'id':_0x37bf33[_0x4214('0x24')][0x0]['id'],'email':_0x37bf33['result'][0x0][_0x4214('0x30')],'name':_0x37bf33[_0x4214('0x24')][0x0][_0x4214('0x31')]+'\x20'+_0x37bf33['result'][_0x4214('0x32')]});}else{logger[_0x4214('0x2a')](_0x4214('0x33'));return BPromise[_0x4214('0x23')]({'id':_0x472da9[_0x4214('0x34')],'email':_0x5c874a[_0x4214('0x1e')],'name':_0x4214('0x35')});}})[_0x4214('0x26')](function(_0x2d9698){var _0x44188b=_0x2d9698['statusCode']||0x1f4;logger['error'](_0x4214('0x36'),_0x4214('0x37'),_0x44188b,JSON[_0x4214('0x21')](_0x2d9698));});}else{logger[_0x4214('0x2a')](_0x4214('0x33'));return BPromise[_0x4214('0x23')]({'id':_0x472da9[_0x4214('0x34')],'email':_0x5c874a[_0x4214('0x1e')],'name':_0x4214('0x35')})[_0x4214('0x26')](function(_0x1fddbd){var _0xd5e0b1=_0x1fddbd[_0x4214('0x27')]||0x1f4;logger[_0x4214('0x28')](_0x4214('0x36'),_0x4214('0x37'),_0xd5e0b1,JSON[_0x4214('0x21')](_0x1fddbd));});}}function getEndUser(_0x3a96c6,_0x5a1079,_0x1fa753,_0x326af2){logger['info'](_0x4214('0x38'),_0x1fa753);return request({'method':_0x4214('0x2c'),'uri':util[_0x4214('0x1c')](_0x4214('0x2d'),_0x3a96c6['remoteUri']),'qs':{'operation':_0x4214('0x2e'),'username':_0x3a96c6[_0x4214('0x1e')],'sessionName':_0x326af2[_0x4214('0x1f')],'query':util[_0x4214('0x1c')]('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;',_0x1fa753,_0x1fa753,_0x1fa753,_0x1fa753,_0x1fa753)},'json':!![]})[_0x4214('0x39')](function(_0x5755c0){if(_0x5755c0[_0x4214('0x22')]&&_0x5755c0[_0x4214('0x24')]['length']){logger[_0x4214('0x2a')](_0x4214('0x3a'));return BPromise[_0x4214('0x23')]({'id':_0x5755c0['result'][0x0]['id'],'name':_0x5755c0[_0x4214('0x24')][0x0][_0x4214('0x3b')]+'\x20'+_0x5755c0[_0x4214('0x24')][0x0][_0x4214('0x3c')],'phone':_0x1fa753});}else{logger[_0x4214('0x2a')](_0x4214('0x3d'));return request({'method':_0x4214('0x1b'),'uri':util[_0x4214('0x1c')](_0x4214('0x2d'),_0x3a96c6[_0x4214('0x1d')]),'form':{'operation':_0x4214('0x3e'),'sessionName':_0x326af2[_0x4214('0x1f')],'elementType':_0x4214('0x3f'),'element':JSON[_0x4214('0x21')]({'lastname':_0x5a1079,'phone':_0x1fa753,'assigned_user_id':'\x20'})},'json':!![]})[_0x4214('0x39')](function(_0x12a817){logger['info'](_0x4214('0x40'));return BPromise[_0x4214('0x23')]({'id':_0x12a817[_0x4214('0x24')]['id'],'name':_0x12a817[_0x4214('0x24')][_0x4214('0x3c')],'phone':_0x12a817['result']['phone']});})[_0x4214('0x26')](function(_0x5905f8){var _0x159fc6=_0x5905f8['statusCode']||0x1f4;logger['error'](_0x4214('0x36'),_0x4214('0x41'),_0x159fc6,JSON[_0x4214('0x21')](_0x5905f8));});}});}function getConnection(_0x573d2c){var _0x59d00f=_0x573d2c[_0x4214('0x1e')];var _0x18bdcf=_0x573d2c['accessKey'];return request({'method':_0x4214('0x2c'),'uri':util['format']('%s/webservice.php',_0x573d2c['remoteUri']),'qs':{'operation':'getchallenge','username':_0x59d00f},'json':!![]})[_0x4214('0x39')](function(_0x5d0e80){if(_0x5d0e80[_0x4214('0x22')]){return request({'method':_0x4214('0x1b'),'uri':util[_0x4214('0x1c')]('%s/webservice.php',_0x573d2c[_0x4214('0x1d')]),'form':{'operation':_0x4214('0x42'),'username':_0x59d00f,'accessKey':md5(_0x5d0e80['result'][_0x4214('0x43')]+_0x18bdcf)},'json':!![]});}})[_0x4214('0x39')](function(_0x2a055b){if(_0x2a055b[_0x4214('0x22')]){return BPromise[_0x4214('0x23')](_0x2a055b[_0x4214('0x24')]);}else{throw new Error(util[_0x4214('0x1c')]('Account\x20%d\x20is\x20not\x20valid',_0x573d2c['id']));}})[_0x4214('0x26')](function(_0x228558){var _0x88ac44=_0x228558['statusCode']||0x1f4;logger[_0x4214('0x28')]('[vTiger],\x20%s,\x20%s,\x20%s',_0x4214('0x44'),_0x88ac44,JSON[_0x4214('0x21')](_0x228558));});}function request(_0x6301bf){logger['info'](_0x4214('0x45'),JSON[_0x4214('0x21')](_0x6301bf));return rp(_0x6301bf);}exports['queue']=function(_0x13e2e0,_0x4a32ac,_0x15b4d6,_0x146acf,_0x597dba,_0x510176){var _0x5751cc,_0xabe237,_0x277776,_0x321615;_0x510176[_0x4214('0x1d')]=intUtil[_0x4214('0x46')](_0x510176[_0x4214('0x1d')]);if(_0x597dba&&_0x597dba[_0x4214('0x47')]){logger[_0x4214('0x2a')](_0x4214('0x48'),'Recording\x20is\x20enabled!');_0x4a32ac[_0x4214('0x49')]=util[_0x4214('0x1c')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x510176[_0x4214('0x4a')],_0x4a32ac[_0x4214('0x4b')],md5(_0x4a32ac[_0x4214('0x4b')]));}else{_0x4a32ac[_0x4214('0x49')]='';}return getConnection(_0x510176)['then'](function(_0x26fcee){_0x321615=_0x26fcee;return getUser(_0x510176,_0x146acf[_0x4214('0x4c')],_0x321615);})[_0x4214('0x39')](function(_0x59bafb){_0x5751cc=_0x59bafb;logger[_0x4214('0x2a')](_0x4214('0x4d'),_0x5751cc['id']);return getEndUser(_0x510176,_0x4a32ac[_0x4214('0x4e')],_0x4a32ac[_0x4214('0x4f')],_0x321615);})[_0x4214('0x39')](function(_0x255c6d){_0xabe237=_0x255c6d;logger['info'](_0x4214('0x50'),_0xabe237['id']);return createTicket(_0x510176,_0x5751cc,_0xabe237,_0x15b4d6,_0x4a32ac,_0x15b4d6[_0x4214('0x51')],_0x321615);})[_0x4214('0x39')](function(_0x245ce8){_0x277776=_0x245ce8;logger['info']('Ticket\x20created!');logger[_0x4214('0x2a')](_0x4214('0x52'),_0x277776['id']);var _0x1d91b6=util[_0x4214('0x1c')](_0x4214('0x53'),_0x510176[_0x4214('0x1d')],_[_0x4214('0x54')](_0x277776['id'],'x')[0x1]);logger[_0x4214('0x2a')](_0x4214('0x48'),_0x4214('0x55'));emit(util[_0x4214('0x1c')](_0x4214('0x56'),_0x146acf[_0x4214('0x13')]),_0x4214('0x57'),{'uri':_0x1d91b6});})['catch'](function(_0x3ecafa){logger[_0x4214('0x28')](_0x4214('0x48'),JSON[_0x4214('0x21')](_0x3ecafa));});};exports['outbound']=function(_0x2dec8d,_0x2dd9bd,_0x5e3245,_0x14ca4c,_0x43ab01,_0xcd4a23,_0x409d49){var _0x28b41b,_0x29f63c,_0x4927fa,_0x5c4f8a;_0xcd4a23[_0x4214('0x1d')]=intUtil[_0x4214('0x46')](_0xcd4a23['remoteUri']);_0xcd4a23[_0x4214('0x4a')]=intUtil[_0x4214('0x46')](_0xcd4a23['serverUrl']);if(_0x409d49&&_0x409d49[_0x4214('0x58')]&&_0x409d49[_0x4214('0x58')]!=='none'){logger[_0x4214('0x2a')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x2dd9bd[_0x4214('0x49')]=util[_0x4214('0x1c')](_0x4214('0x59'),_0xcd4a23[_0x4214('0x4a')],_0x2dd9bd[_0x4214('0x4b')],md5(_0x2dd9bd[_0x4214('0x4b')]));}return getConnection(_0xcd4a23)['then'](function(_0x57363d){_0x5c4f8a=_0x57363d;return getUser(_0xcd4a23,_0x14ca4c[_0x4214('0x4c')],_0x5c4f8a);})['then'](function(_0x5ed88e){_0x28b41b=_0x5ed88e;logger[_0x4214('0x2a')]('The\x20User\x20ID\x20is:',_0x28b41b['id']);return getEndUser(_0xcd4a23,_0x2dd9bd[_0x4214('0x5a')],_0x2dd9bd[_0x4214('0x5b')],_0x5c4f8a);})[_0x4214('0x39')](function(_0x2b8c98){_0x29f63c=_0x2b8c98;logger[_0x4214('0x2a')](_0x4214('0x50'),_0x29f63c['id']);return createTicket(_0xcd4a23,_0x28b41b,_0x29f63c,_0x5e3245,_0x2dd9bd,_0x5e3245[_0x4214('0x51')],_0x5c4f8a);})[_0x4214('0x39')](function(_0x28c1db){_0x4927fa=_0x28c1db;logger[_0x4214('0x2a')](_0x4214('0x5c'));logger['info'](_0x4214('0x52'),_0x4927fa['id']);var _0x53612f=util[_0x4214('0x1c')](_0x4214('0x53'),_0xcd4a23[_0x4214('0x1d')],_[_0x4214('0x54')](_0x4927fa['id'],'x')[0x1]);logger[_0x4214('0x2a')]('[OUTBOUND]',_0x4214('0x55'));emit(util['format'](_0x4214('0x56'),_0x14ca4c[_0x4214('0x13')]),_0x4214('0x57'),{'uri':_0x53612f});})['catch'](function(_0x5a5a05){logger[_0x4214('0x28')](_0x4214('0x5d'),JSON[_0x4214('0x21')](_0x5a5a05));});};exports[_0x4214('0x5e')]=function(_0x19f1ac,_0x3af9f0,_0x582228,_0x5056f9,_0x6b0d33,_0x564bee){var _0x13a66f,_0x17e433,_0x1f1417,_0x733d1e;_0x564bee['remoteUri']=intUtil[_0x4214('0x46')](_0x564bee[_0x4214('0x1d')]);_0x564bee['serverUrl']=intUtil[_0x4214('0x46')](_0x564bee[_0x4214('0x4a')]);if(_0x6b0d33&&_0x6b0d33['monitor_format']){logger[_0x4214('0x2a')]('['+_0x3af9f0[_0x4214('0x5f')]['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x3af9f0['recordingURL']=util[_0x4214('0x1c')](_0x4214('0x59'),_0x564bee[_0x4214('0x4a')],_0x3af9f0[_0x4214('0x4b')],md5(_0x3af9f0['uniqueid']));}else{_0x3af9f0[_0x4214('0x49')]='';}return getConnection(_0x564bee)[_0x4214('0x39')](function(_0x2f3c8d){_0x733d1e=_0x2f3c8d;return getUser(_0x564bee,'',_0x733d1e);})[_0x4214('0x39')](function(_0x51e43e){_0x13a66f=_0x51e43e;logger[_0x4214('0x2a')](_0x4214('0x4d'),_0x13a66f['id']);return getEndUser(_0x564bee,_0x3af9f0['calleridname'],_0x3af9f0[_0x4214('0x4f')],_0x733d1e);})['then'](function(_0x138f73){_0x17e433=_0x138f73;logger[_0x4214('0x2a')](_0x4214('0x50'),_0x17e433['id']);return createTicket(_0x564bee,_0x13a66f,_0x17e433,_0x582228,_0x3af9f0,_0x582228[_0x4214('0x51')],_0x733d1e);})[_0x4214('0x39')](function(_0x1024b2){_0x1f1417=_0x1024b2;logger['info'](_0x4214('0x5c'));logger[_0x4214('0x2a')](_0x4214('0x52'),_0x1f1417['id']);})[_0x4214('0x26')](function(_0x2e5a2f){logger['error']('['+_0x3af9f0[_0x4214('0x5f')][_0x4214('0x60')]()+']',JSON[_0x4214('0x21')](_0x2e5a2f));});};
\ No newline at end of file
+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