Built motion from commit 775e2a94.|2.6.3
[motion2.git] / server / services / ami / trigger / integration / salesforce.js
index d9b0dcd..5f35422 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2f22=['recordingFormat','none','[OUTBOUND]','destcalleridname','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','Salesforce\x20account\x20type\x20not\x20recognized','unmanaged','lastevent','toUpperCase','calleridnum',']\x20Ticket\x20%s\x20created.','lodash','request-promise','moment','md5','jsforce','ioredis','./util','../../../../config/environment','../../../../config/logger','salesforce','redis','defaults','localhost','socket.io-emitter','emit','ticketType','Task','assign','utc','getString','Subjects','WhoId','Case','Descriptions','ContactId','sobject','create','isNil','validateEmail','find','execute','length','Email','info','Agent\x20%s\x20found.','Name','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','identity','then','display_name','resolve','user_id','moduleSearch','contact_lead','Contact','Lead','contact','lead','Phone','Enduser\x20with\x20phone\x20%s\x20found.','Enduser\x20with\x20phone\x20%s\x20not\x20found.','<unknown>','format','Caller\x20-\x20%s','moduleCreate','Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.','upperFirst','forEach','type','string','idField','content','toString','customVariable','Variable','name','toLowerCase','password','Connection','remoteUri','https://login.salesforce.com','clientId','clientSecret','username','Connection\x20established.','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','calleridname','Fields','[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','integrationTab','user:%s','trigger:salesforce:display','newTab','trigger:browser:url','%s/%s/e','instanceUrl','error','catch','stringify','outbound'];(function(_0x275621,_0x524302){var _0x2ad056=function(_0x1e962f){while(--_0x1e962f){_0x275621['push'](_0x275621['shift']());}};_0x2ad056(++_0x524302);}(_0x2f22,0x156));var _0x22f2=function(_0x3ab51d,_0x2fa01d){_0x3ab51d=_0x3ab51d-0x0;var _0x29a04e=_0x2f22[_0x3ab51d];return _0x29a04e;};'use strict';var _=require(_0x22f2('0x0'));var rp=require(_0x22f2('0x1'));var moment=require(_0x22f2('0x2'));var BPromise=require('bluebird');var md5=require(_0x22f2('0x3'));var jsforce=require(_0x22f2('0x4'));var util=require('util');var Redis=require(_0x22f2('0x5'));var intUtil=require(_0x22f2('0x6'));var config=require(_0x22f2('0x7'));var logger=require(_0x22f2('0x8'))(_0x22f2('0x9'));config[_0x22f2('0xa')]=_[_0x22f2('0xb')](config['redis'],{'host':_0x22f2('0xc'),'port':0x18eb});var io=require(_0x22f2('0xd'))(new Redis(config[_0x22f2('0xa')]));function emit(_0x19b85c,_0x574d13,_0x1a3e52){io['to'](_0x19b85c)[_0x22f2('0xe')](_0x574d13,_0x1a3e52);}function getTicket(_0x56e4f4,_0x406448,_0x1f67aa,_0x114ef1,_0x1ccb55,_0x302b40,_0x468ce1,_0x2857cf){var _0x26b249={};if(_0x114ef1[_0x22f2('0xf')]===_0x22f2('0x10')){_0x26b249=Object[_0x22f2('0x11')]({},{'OwnerId':_0x406448['id'],'ActivityDate':moment[_0x22f2('0x12')](),'IsReminderSet':![],'IsRecurrence':![],'Subject':intUtil[_0x22f2('0x13')](_0x114ef1[_0x22f2('0x14')],_0x1ccb55,'\x20'),'Description':intUtil[_0x22f2('0x13')](_0x114ef1['Descriptions'],_0x1ccb55,'\x0a')},getCustomFields(_0x302b40,_0x1ccb55));if(_0x1f67aa){_0x26b249[_0x22f2('0x15')]=_0x1f67aa['id'];}}else if(_0x114ef1[_0x22f2('0xf')]===_0x22f2('0x16')){_0x26b249=Object[_0x22f2('0x11')]({},{'OwnerId':_0x406448['id'],'Subject':intUtil[_0x22f2('0x13')](_0x114ef1['Subjects'],_0x1ccb55,'\x20'),'Description':intUtil['getString'](_0x114ef1[_0x22f2('0x17')],_0x1ccb55,'\x0a')},getCustomFields(_0x302b40,_0x1ccb55));if(_0x1f67aa){_0x26b249[_0x22f2('0x18')]=_0x1f67aa['id'];}}return _0x468ce1[_0x22f2('0x19')](_0x114ef1['ticketType'])[_0x22f2('0x1a')](_0x26b249);}function getUser(_0x488baf,_0x121914,_0x3bd647){if(!_[_0x22f2('0x1b')](_0x121914)&&intUtil[_0x22f2('0x1c')](_0x121914)){var _0x18c874={'Email':_0x121914};var _0x1aa78d={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x3bd647['sobject']('User')[_0x22f2('0x1d')](_0x18c874,_0x1aa78d)[_0x22f2('0x1e')]()['then'](function(_0x17ebd7){if(_0x17ebd7[_0x22f2('0x1f')]){var _0x35ab89=_[_0x22f2('0x1d')](_0x17ebd7,function(_0x382fa7){return _0x382fa7[_0x22f2('0x20')]===_0x121914;});if(_0x35ab89){logger[_0x22f2('0x21')](_0x22f2('0x22'),_0x121914);return BPromise['resolve']({'id':_0x35ab89['Id'],'name':_0x35ab89[_0x22f2('0x23')]});}}else{logger[_0x22f2('0x21')](_0x22f2('0x24'),_0x121914);return _0x3bd647[_0x22f2('0x25')]()[_0x22f2('0x26')](function(_0x49c4e5){return BPromise['resolve']({'id':_0x49c4e5['user_id'],'name':_0x49c4e5[_0x22f2('0x27')]});});}});}else{logger[_0x22f2('0x21')](_0x22f2('0x24'),_0x121914);return _0x3bd647[_0x22f2('0x25')]()[_0x22f2('0x26')](function(_0x4f540c){return BPromise[_0x22f2('0x28')]({'id':_0x4f540c[_0x22f2('0x29')],'name':_0x4f540c['display_name']});});}}function getEndUser(_0x41eb3d,_0x5a3a33,_0xb43c6c,_0x544bc8,_0x5747fa){var _0x5a448b={'Phone':_0x544bc8};var _0x4673d0={'Id':!![],'Name':!![],'Phone':!![]};return BPromise[_0x22f2('0x28')]()[_0x22f2('0x26')](function(){if(_0x5a3a33[_0x22f2('0xf')]===_0x22f2('0x10')){logger['info']('Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.',_0x544bc8,_0x5a3a33[_0x22f2('0x2a')]);switch(_0x5a3a33[_0x22f2('0x2a')]){case _0x22f2('0x2b'):return _0x5747fa[_0x22f2('0x19')](_0x22f2('0x2c'))[_0x22f2('0x1d')](_0x5a448b,_0x4673d0)[_0x22f2('0x1e')]()['then'](function(_0xd5db46){if(_0xd5db46&&_0xd5db46[_0x22f2('0x1f')]){return _0xd5db46;}else{return _0x5747fa[_0x22f2('0x19')](_0x22f2('0x2d'))[_0x22f2('0x1d')](_0x5a448b,_0x4673d0);}});case _0x22f2('0x2e'):return _0x5747fa[_0x22f2('0x19')]('Contact')[_0x22f2('0x1d')](_0x5a448b,_0x4673d0)[_0x22f2('0x1e')]();case _0x22f2('0x2f'):return _0x5747fa[_0x22f2('0x19')](_0x22f2('0x2d'))[_0x22f2('0x1d')](_0x5a448b,_0x4673d0);default:return null;}}else if(_0x5a3a33[_0x22f2('0xf')]==='Case'){logger[_0x22f2('0x21')]('Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.',_0x544bc8,'contact');return _0x5747fa[_0x22f2('0x19')](_0x22f2('0x2c'))[_0x22f2('0x1d')](_0x5a448b,_0x4673d0)[_0x22f2('0x1e')]();}})[_0x22f2('0x26')](function(_0x3997da){if(_0x3997da&&_0x3997da[_0x22f2('0x1f')]){var _0x43bdcb=_[_0x22f2('0x1d')](_0x3997da,function(_0x274e02){return _0x274e02[_0x22f2('0x30')]===_0x544bc8;});if(_0x43bdcb){return BPromise[_0x22f2('0x28')]({'id':_0x43bdcb['Id'],'name':_0x43bdcb[_0x22f2('0x23')],'phone':_0x43bdcb['Phone']});}}})[_0x22f2('0x26')](function(_0x336024){if(_0x336024){logger[_0x22f2('0x21')](_0x22f2('0x31'),_0x544bc8);return BPromise[_0x22f2('0x28')](_0x336024);}else{logger[_0x22f2('0x21')](_0x22f2('0x32'),_0x544bc8);var _0x390927={'LastName':_0xb43c6c!==_0x22f2('0x33')?_0xb43c6c:util[_0x22f2('0x34')](_0x22f2('0x35'),_0x544bc8),'Phone':_0x544bc8};if(_0x5a3a33['moduleCreate']){if(_0x5a3a33[_0x22f2('0x36')]==='contact'){logger[_0x22f2('0x21')](_0x22f2('0x37'),_0x544bc8,_0x5a3a33[_0x22f2('0x36')]);}else if(_0x5a3a33[_0x22f2('0x36')]===_0x22f2('0x2f')&&_0x5a3a33[_0x22f2('0xf')]===_0x22f2('0x10')){logger[_0x22f2('0x21')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x544bc8,_0x5a3a33['moduleCreate']);_0x390927['Company']='No\x20Company';}else{return null;}}return _0x5747fa[_0x22f2('0x19')](_[_0x22f2('0x38')](_0x5a3a33[_0x22f2('0x36')]))[_0x22f2('0x1a')](_0x390927);}});}function getCustomFields(_0xee71a1,_0x223473){var _0x4e4365={};if(_0xee71a1[_0x22f2('0x1f')]>0x0){_[_0x22f2('0x39')](_0xee71a1,function(_0x52f394){if(_0x52f394[_0x22f2('0x3a')]===_0x22f2('0x3b')&&_0x52f394['idField']){_0x4e4365[_0x52f394[_0x22f2('0x3c')]]=_0x52f394[_0x22f2('0x3d')][_0x22f2('0x3e')]();}else if(_0x52f394[_0x22f2('0x3a')]==='variable'&&_0x52f394['variableName']&&_0x52f394[_0x22f2('0x3c')]){_0x223473[_0x52f394['variableName']]&&(_0x4e4365[_0x52f394[_0x22f2('0x3c')]]=_0x223473[_0x52f394['variableName']]['toString']());}else if(_0x52f394[_0x22f2('0x3a')]===_0x22f2('0x3f')&&_0x52f394[_0x22f2('0x40')]&&_0x52f394[_0x22f2('0x40')]['name']&&_0x52f394['idField']){_0x223473[_0x52f394['Variable'][_0x22f2('0x41')][_0x22f2('0x42')]()]&&(_0x4e4365[_0x52f394[_0x22f2('0x3c')]]=_0x223473[_0x52f394[_0x22f2('0x40')]['name'][_0x22f2('0x42')]()][_0x22f2('0x3e')]());}});}return _0x4e4365;}function getConnection(_0x3d4480){var _0x345781=_0x3d4480[_0x22f2('0x43')]['concat'](_0x3d4480['securityToken']);var _0x4ece5d=new jsforce[(_0x22f2('0x44'))]({'oauth2':{'loginUrl':_0x3d4480[_0x22f2('0x45')]||_0x22f2('0x46'),'clientId':_0x3d4480[_0x22f2('0x47')],'clientSecret':_0x3d4480[_0x22f2('0x48')]}});return _0x4ece5d['login'](_0x3d4480[_0x22f2('0x49')],_0x345781)[_0x22f2('0x26')](function(){logger[_0x22f2('0x21')](_0x22f2('0x4a'));return _0x4ece5d;});}exports[_0x22f2('0x4b')]=function(_0x4ce96b,_0x2ea50c,_0x12079a,_0x1be9a9,_0x3e53bf,_0x3a2d7f){var _0x566bbf,_0x5a1311,_0x1e0d2b,_0x4625e9;_0x3a2d7f['serverUrl']=intUtil[_0x22f2('0x4c')](_0x3a2d7f[_0x22f2('0x4d')]);_0x3a2d7f[_0x22f2('0x45')]=intUtil['stripTrailingSlash'](_0x3a2d7f[_0x22f2('0x45')]);if(_0x3e53bf&&_0x3e53bf[_0x22f2('0x4e')]){logger[_0x22f2('0x21')](_0x22f2('0x4f'),_0x22f2('0x50'));_0x2ea50c[_0x22f2('0x51')]=util[_0x22f2('0x34')](_0x22f2('0x52'),_0x3a2d7f[_0x22f2('0x4d')],_0x2ea50c[_0x22f2('0x53')],md5(_0x2ea50c[_0x22f2('0x53')]));}else{_0x2ea50c[_0x22f2('0x51')]='';}return getConnection(_0x3a2d7f)['then'](function(_0x122b03){_0x4625e9=_0x122b03;return getUser(_0x3a2d7f,_0x1be9a9['email'],_0x4625e9);})[_0x22f2('0x26')](function(_0x3e9aa0){_0x566bbf=_0x3e9aa0;return getEndUser(_0x3a2d7f,_0x12079a,_0x2ea50c[_0x22f2('0x54')],_0x2ea50c['calleridnum'],_0x4625e9);})[_0x22f2('0x26')](function(_0x282f95){_0x5a1311=_0x282f95;return getTicket(_0x3a2d7f,_0x566bbf,_0x5a1311,_0x12079a,_0x2ea50c,_0x12079a[_0x22f2('0x55')],_0x4625e9,_0x22f2('0x4b'));})[_0x22f2('0x26')](function(_0x294c7f){_0x1e0d2b=_0x294c7f;logger[_0x22f2('0x21')]('[QUEUE]\x20Ticket\x20%s\x20created',_0x1e0d2b['id']);logger[_0x22f2('0x21')](_0x22f2('0x56'),_0x1e0d2b['id'],_0x1be9a9['name'],_0x3a2d7f[_0x22f2('0x3a')]);switch(_0x3a2d7f['type']){case _0x22f2('0x57'):emit(util[_0x22f2('0x34')](_0x22f2('0x58'),_0x1be9a9[_0x22f2('0x41')]),_0x22f2('0x59'),{'recordId':_0x1e0d2b['id']});break;case _0x22f2('0x5a'):emit(util[_0x22f2('0x34')]('user:%s',_0x1be9a9[_0x22f2('0x41')]),_0x22f2('0x5b'),{'uri':util[_0x22f2('0x34')](_0x22f2('0x5c'),_0x4625e9[_0x22f2('0x5d')],_0x1e0d2b['id'])});break;default:logger[_0x22f2('0x5e')]('[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.');}})[_0x22f2('0x5f')](function(_0x504438){logger[_0x22f2('0x5e')](_0x22f2('0x4f'),JSON[_0x22f2('0x60')](_0x504438));});};exports[_0x22f2('0x61')]=function(_0x433030,_0x5bab10,_0x1efd67,_0x41a8e4,_0x4a2a2c,_0x3b87e5,_0x18a20a){var _0x25e0b9,_0x451fb0,_0x3e6ca3,_0x158192;_0x3b87e5[_0x22f2('0x4d')]=intUtil[_0x22f2('0x4c')](_0x3b87e5[_0x22f2('0x4d')]);_0x3b87e5['remoteUri']=intUtil[_0x22f2('0x4c')](_0x3b87e5['remoteUri']);if(_0x18a20a&&_0x18a20a[_0x22f2('0x62')]&&_0x18a20a[_0x22f2('0x62')]!==_0x22f2('0x63')){logger[_0x22f2('0x21')](_0x22f2('0x64'),'Recording\x20is\x20enabled!');_0x5bab10[_0x22f2('0x51')]=util[_0x22f2('0x34')](_0x22f2('0x52'),_0x3b87e5[_0x22f2('0x4d')],_0x5bab10[_0x22f2('0x53')],md5(_0x5bab10[_0x22f2('0x53')]));}return getConnection(_0x3b87e5)[_0x22f2('0x26')](function(_0x24573a){_0x158192=_0x24573a;return getUser(_0x3b87e5,_0x41a8e4['email'],_0x158192);})[_0x22f2('0x26')](function(_0x930e36){_0x25e0b9=_0x930e36;return getEndUser(_0x3b87e5,_0x1efd67,_0x5bab10[_0x22f2('0x65')],_0x5bab10['destcalleridnum'],_0x158192);})[_0x22f2('0x26')](function(_0x5ca762){_0x451fb0=_0x5ca762;return getTicket(_0x3b87e5,_0x25e0b9,_0x451fb0,_0x1efd67,_0x5bab10,_0x1efd67['Fields'],_0x158192,_0x22f2('0x61'));})[_0x22f2('0x26')](function(_0x91247f){_0x3e6ca3=_0x91247f;logger[_0x22f2('0x21')](_0x22f2('0x66'),_0x3e6ca3['id']);logger[_0x22f2('0x21')](_0x22f2('0x67'),_0x3e6ca3['id'],_0x41a8e4[_0x22f2('0x41')],_0x3b87e5['type']);switch(_0x3b87e5[_0x22f2('0x3a')]){case'integrationTab':emit(util[_0x22f2('0x34')](_0x22f2('0x58'),_0x41a8e4[_0x22f2('0x41')]),_0x22f2('0x59'),{'recordId':_0x3e6ca3['id']});break;case _0x22f2('0x5a'):emit(util[_0x22f2('0x34')]('user:%s',_0x41a8e4[_0x22f2('0x41')]),_0x22f2('0x5b'),{'uri':util[_0x22f2('0x34')]('%s/%s/e',_0x158192[_0x22f2('0x5d')],_0x3e6ca3['id'])});break;default:logger[_0x22f2('0x5e')](_0x22f2('0x64'),_0x22f2('0x68'));}})[_0x22f2('0x5f')](function(_0x104c94){logger[_0x22f2('0x5e')](_0x22f2('0x64'),JSON[_0x22f2('0x60')](_0x104c94));});};exports[_0x22f2('0x69')]=function(_0x24b692,_0x5985b7,_0x1d2e2c,_0x4e9647,_0x34d282,_0x4fdad2){var _0x5dae76,_0x37ce8e,_0x316854,_0x16a75;_0x4fdad2['serverUrl']=intUtil[_0x22f2('0x4c')](_0x4fdad2['serverUrl']);_0x4fdad2[_0x22f2('0x45')]=intUtil[_0x22f2('0x4c')](_0x4fdad2[_0x22f2('0x45')]);if(_0x34d282&&_0x34d282[_0x22f2('0x4e')]){logger[_0x22f2('0x21')]('['+_0x5985b7[_0x22f2('0x6a')][_0x22f2('0x6b')]()+']',_0x22f2('0x50'));_0x5985b7[_0x22f2('0x51')]=util['format'](_0x22f2('0x52'),_0x4fdad2[_0x22f2('0x4d')],_0x5985b7[_0x22f2('0x53')],md5(_0x5985b7[_0x22f2('0x53')]));}else{_0x5985b7[_0x22f2('0x51')]='';}return getConnection(_0x4fdad2)[_0x22f2('0x26')](function(_0x5eb824){_0x16a75=_0x5eb824;if(!_['isNil'](_0x4e9647)){return getUser(_0x4fdad2,_0x4e9647[_0x22f2('0x41')],_0x16a75);}else{return getUser(_0x4fdad2,null,_0x16a75);}})[_0x22f2('0x26')](function(_0x1d45b4){_0x5dae76=_0x1d45b4;return getEndUser(_0x4fdad2,_0x1d2e2c,_0x5985b7[_0x22f2('0x54')],_0x5985b7[_0x22f2('0x6c')],_0x16a75);})[_0x22f2('0x26')](function(_0x345488){_0x37ce8e=_0x345488;return getTicket(_0x4fdad2,_0x5dae76,_0x37ce8e,_0x1d2e2c,_0x5985b7,_0x1d2e2c[_0x22f2('0x55')],_0x16a75);})[_0x22f2('0x26')](function(_0x400ac6){_0x316854=_0x400ac6;logger[_0x22f2('0x21')]('['+_0x5985b7[_0x22f2('0x6a')][_0x22f2('0x6b')]()+_0x22f2('0x6d'),_0x316854['id']);logger[_0x22f2('0x21')]('['+_0x5985b7['lastevent'][_0x22f2('0x6b')]()+']\x20Integration\x20account\x20type\x20%s.',_0x4fdad2[_0x22f2('0x3a')]);})['catch'](function(_0x4f9d08){logger[_0x22f2('0x5e')]('['+_0x5985b7['lastevent']['toUpperCase']()+']',JSON[_0x22f2('0x60')](_0x4f9d08));});};
\ No newline at end of file
+var _0xcbc7=['redis','defaults','socket.io-emitter','emit','getString','Subjects','Descriptions','Task','ActivityDate','IsReminderSet','IsRecurrence','endUserType','contact','lead','WhoId','account','WhatId','ticketType','Case','ContactId','AccountId','leadId','info','Association\x20between\x20Case\x20and\x20Lead\x20skipped','sobject','create','isNil','validateEmail','find','execute','Email','Agent\x20%s\x20found.','resolve','identity','then','user_id','display_name','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','moduleSearch','contact_lead','cloneDeep','additionalSearchContact','merge','$or','Contact','length','additionalSearchLead','Lead','account_contact_lead','additionalSearchAccount','Account','first','Phone','attributes','toLowerCase','Enduser\x20(%s)\x20with\x20phone\x20%s\x20found','Enduser\x20with\x20phone\x20%s\x20not\x20found','moduleCreate','Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.','<unknown>','format','Caller\x20-\x20%s','LastName','No\x20Company','upperFirst','includes','string','type','idField','toString','variableName','customVariable','name','Variable','securityToken','remoteUri','https://login.salesforce.com','clientId','username','queue','serverUrl','stripTrailingSlash','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','calleridname','calleridnum','[QUEUE]\x20Ticket\x20%s\x20created','[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','integrationTab','user:%s','trigger:salesforce:display','newTab','instanceUrl','error','[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.','catch','recordingFormat','none','destcalleridnum','Fields','outbound','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','trigger:browser:url','[OUTBOUND]','Salesforce\x20account\x20type\x20not\x20recognized','unmanaged','lastevent','toUpperCase',']\x20Integration\x20account\x20type\x20%s.','lodash','request-promise','moment','bluebird','md5','jsforce','util','ioredis','../../../../config/environment','../../../../config/logger','salesforce'];(function(_0x2bfd4f,_0x1bbf2c){var _0x341849=function(_0x4c246e){while(--_0x4c246e){_0x2bfd4f['push'](_0x2bfd4f['shift']());}};_0x341849(++_0x1bbf2c);}(_0xcbc7,0xf1));var _0x7cbc=function(_0x293023,_0x4ac622){_0x293023=_0x293023-0x0;var _0x49751d=_0xcbc7[_0x293023];return _0x49751d;};'use strict';var _=require(_0x7cbc('0x0'));var rp=require(_0x7cbc('0x1'));var moment=require(_0x7cbc('0x2'));var BPromise=require(_0x7cbc('0x3'));var md5=require(_0x7cbc('0x4'));var jsforce=require(_0x7cbc('0x5'));var util=require(_0x7cbc('0x6'));var Redis=require(_0x7cbc('0x7'));var intUtil=require('./util');var config=require(_0x7cbc('0x8'));var logger=require(_0x7cbc('0x9'))(_0x7cbc('0xa'));config[_0x7cbc('0xb')]=_[_0x7cbc('0xc')](config[_0x7cbc('0xb')],{'host':'localhost','port':0x18eb});var io=require(_0x7cbc('0xd'))(new Redis(config[_0x7cbc('0xb')]));function emit(_0x410873,_0x55f27e,_0x262a26){io['to'](_0x410873)[_0x7cbc('0xe')](_0x55f27e,_0x262a26);}function getTicket(_0xbf7549,_0x1112d5,_0x3a0198,_0x436384,_0x216fb2,_0x10e541,_0x39ebdb,_0x122031){var _0x204fff=Object['assign']({},{'OwnerId':_0x1112d5['id'],'Subject':intUtil[_0x7cbc('0xf')](_0x436384[_0x7cbc('0x10')],_0x216fb2,'\x20'),'Description':intUtil['getString'](_0x436384[_0x7cbc('0x11')],_0x216fb2,'\x0a')},getCustomFields(_0x10e541,_0x216fb2));if(_0x3a0198){if(_0x436384['ticketType']===_0x7cbc('0x12')){_0x204fff[_0x7cbc('0x13')]=moment['utc']();_0x204fff[_0x7cbc('0x14')]=![];_0x204fff[_0x7cbc('0x15')]=![];if(_0x3a0198[_0x7cbc('0x16')]===_0x7cbc('0x17')||_0x3a0198['endUserType']===_0x7cbc('0x18')){_0x204fff[_0x7cbc('0x19')]=_0x3a0198['id'];}else if(_0x3a0198[_0x7cbc('0x16')]===_0x7cbc('0x1a')){_0x204fff[_0x7cbc('0x1b')]=_0x3a0198['id'];}}else if(_0x436384[_0x7cbc('0x1c')]===_0x7cbc('0x1d')){if(_0x3a0198[_0x7cbc('0x16')]==='contact'){_0x204fff[_0x7cbc('0x1e')]=_0x3a0198['id'];}else if(_0x3a0198[_0x7cbc('0x16')]===_0x7cbc('0x1a')){_0x204fff[_0x7cbc('0x1f')]=_0x3a0198['id'];}else if(_0x3a0198[_0x7cbc('0x16')]===_0x7cbc('0x18')&&_0x436384[_0x7cbc('0x20')]){_0x204fff[_0x436384[_0x7cbc('0x20')]]=_0x3a0198['id'];}else{logger[_0x7cbc('0x21')](_0x7cbc('0x22'));}}}return _0x39ebdb[_0x7cbc('0x23')](_0x436384[_0x7cbc('0x1c')])[_0x7cbc('0x24')](_0x204fff);}function getUser(_0x78f2f5,_0x53cf39,_0xb99859){if(!_[_0x7cbc('0x25')](_0x53cf39)&&intUtil[_0x7cbc('0x26')](_0x53cf39)){var _0x1e010f={'Email':_0x53cf39};var _0x122ce6={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0xb99859[_0x7cbc('0x23')]('User')[_0x7cbc('0x27')](_0x1e010f,_0x122ce6)[_0x7cbc('0x28')]()['then'](function(_0x50a85a){if(_0x50a85a['length']){var _0x4d2b98=_[_0x7cbc('0x27')](_0x50a85a,function(_0x57b467){return _0x57b467[_0x7cbc('0x29')]===_0x53cf39;});if(_0x4d2b98){logger[_0x7cbc('0x21')](_0x7cbc('0x2a'),_0x53cf39);return BPromise[_0x7cbc('0x2b')]({'id':_0x4d2b98['Id'],'name':_0x4d2b98['Name']});}}else{logger['info']('Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.',_0x53cf39);return _0xb99859[_0x7cbc('0x2c')]()[_0x7cbc('0x2d')](function(_0x320183){return BPromise[_0x7cbc('0x2b')]({'id':_0x320183[_0x7cbc('0x2e')],'name':_0x320183[_0x7cbc('0x2f')]});});}});}else{logger[_0x7cbc('0x21')](_0x7cbc('0x30'),_0x53cf39);return _0xb99859[_0x7cbc('0x2c')]()[_0x7cbc('0x2d')](function(_0x39e99d){return BPromise['resolve']({'id':_0x39e99d[_0x7cbc('0x2e')],'name':_0x39e99d[_0x7cbc('0x2f')]});});}}function getEndUser(_0x4c8230,_0x3c1653,_0x11b54c,_0x38b868,_0x386975){var _0x57dfb3={'$or':{'Phone':_0x38b868}};var _0x4a2ced={'Id':!![],'Name':!![],'Phone':!![]};return BPromise[_0x7cbc('0x2b')]()['then'](function(){logger['info'](_0x7cbc('0x31'),_0x38b868,_0x3c1653[_0x7cbc('0x32')]);switch(_0x3c1653[_0x7cbc('0x32')]){case _0x7cbc('0x33'):var _0x54febe=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653['additionalSearchContact']){var _0x57f39e={};_0x57f39e[_0x3c1653[_0x7cbc('0x35')]]=_0x38b868;_[_0x7cbc('0x36')](_0x54febe[_0x7cbc('0x37')],_0x57f39e);}return _0x386975[_0x7cbc('0x23')](_0x7cbc('0x38'))['find'](_0x54febe,_0x4a2ced)[_0x7cbc('0x28')]()[_0x7cbc('0x2d')](function(_0x261208){if(_0x261208&&_0x261208[_0x7cbc('0x39')]){return _0x261208;}else{var _0x1c43cb=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653[_0x7cbc('0x3a')]){var _0x5dbd7f={};_0x5dbd7f[_0x3c1653[_0x7cbc('0x3a')]]=_0x38b868;_[_0x7cbc('0x36')](_0x1c43cb[_0x7cbc('0x37')],_0x5dbd7f);}return _0x386975[_0x7cbc('0x23')](_0x7cbc('0x3b'))[_0x7cbc('0x27')](_0x1c43cb,_0x4a2ced);}});case _0x7cbc('0x3c'):var _0x31f9f4=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653['additionalSearchAccount']){var _0x57f39e={};_0x57f39e[_0x3c1653[_0x7cbc('0x3d')]]=_0x38b868;_[_0x7cbc('0x36')](_0x31f9f4[_0x7cbc('0x37')],_0x57f39e);}return _0x386975[_0x7cbc('0x23')](_0x7cbc('0x3e'))['find'](_0x31f9f4,_0x4a2ced)[_0x7cbc('0x28')]()['then'](function(_0x35aa6b){if(_0x35aa6b&&_0x35aa6b['length']){return _0x35aa6b;}else{var _0x2d3d95=_['cloneDeep'](_0x57dfb3);if(_0x3c1653['additionalSearchContact']){var _0x27942f={};_0x27942f[_0x3c1653[_0x7cbc('0x35')]]=_0x38b868;_['merge'](_0x2d3d95[_0x7cbc('0x37')],_0x27942f);}return _0x386975[_0x7cbc('0x23')](_0x7cbc('0x38'))[_0x7cbc('0x27')](_0x2d3d95,_0x4a2ced)[_0x7cbc('0x2d')](function(_0x4f2cf0){if(_0x4f2cf0&&_0x4f2cf0[_0x7cbc('0x39')]){return _0x4f2cf0;}else{var _0x332dac=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653[_0x7cbc('0x3a')]){var _0x940aa4={};_0x940aa4[_0x3c1653[_0x7cbc('0x3a')]]=_0x38b868;_[_0x7cbc('0x36')](_0x332dac[_0x7cbc('0x37')],_0x940aa4);}return _0x386975[_0x7cbc('0x23')]('Lead')[_0x7cbc('0x27')](_0x332dac,_0x4a2ced);}});}});case _0x7cbc('0x17'):var _0x54febe=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653['additionalSearchContact']){var _0x57f39e={};_0x57f39e[_0x3c1653[_0x7cbc('0x35')]]=_0x38b868;_[_0x7cbc('0x36')](_0x54febe[_0x7cbc('0x37')],_0x57f39e);}return _0x386975[_0x7cbc('0x23')](_0x7cbc('0x38'))[_0x7cbc('0x27')](_0x54febe,_0x4a2ced)[_0x7cbc('0x28')]();case'lead':var _0x4d7a28=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653[_0x7cbc('0x3a')]){var _0x57f39e={};_0x57f39e[_0x3c1653[_0x7cbc('0x3a')]]=_0x38b868;_[_0x7cbc('0x36')](_0x4d7a28[_0x7cbc('0x37')],_0x57f39e);}return _0x386975[_0x7cbc('0x23')](_0x7cbc('0x3b'))['find'](_0x4d7a28,_0x4a2ced);case _0x7cbc('0x1a'):var _0x31f9f4=_[_0x7cbc('0x34')](_0x57dfb3);if(_0x3c1653[_0x7cbc('0x3d')]){var _0x57f39e={};_0x57f39e[_0x3c1653[_0x7cbc('0x3d')]]=_0x38b868;_[_0x7cbc('0x36')](_0x31f9f4[_0x7cbc('0x37')],_0x57f39e);}return _0x386975[_0x7cbc('0x23')]('Account')[_0x7cbc('0x27')](_0x31f9f4,_0x4a2ced);default:return null;}})[_0x7cbc('0x2d')](function(_0x3ceda4){if(_0x3ceda4&&_0x3ceda4['length']){var _0x47f47e=_[_0x7cbc('0x3f')](_0x3ceda4);if(_0x47f47e){return BPromise[_0x7cbc('0x2b')]({'id':_0x47f47e['Id'],'name':_0x47f47e['Name'],'phone':_0x47f47e[_0x7cbc('0x40')],'endUserType':_0x47f47e[_0x7cbc('0x41')]['type'][_0x7cbc('0x42')]()});}}})['then'](function(_0x58dec5){if(_0x58dec5){logger[_0x7cbc('0x21')](_0x7cbc('0x43'),_0x58dec5[_0x7cbc('0x16')],_0x38b868);return BPromise[_0x7cbc('0x2b')](_0x58dec5);}else{logger['info'](_0x7cbc('0x44'),_0x38b868);var _0x1f154d={'Phone':_0x38b868};if(_0x3c1653[_0x7cbc('0x45')]){if(_0x3c1653['moduleCreate']===_0x7cbc('0x17')){logger[_0x7cbc('0x21')](_0x7cbc('0x46'),_0x38b868,_0x3c1653[_0x7cbc('0x45')]);_0x1f154d['LastName']=_0x11b54c!==_0x7cbc('0x47')?_0x11b54c:util[_0x7cbc('0x48')](_0x7cbc('0x49'),_0x38b868);}else if(_0x3c1653[_0x7cbc('0x45')]===_0x7cbc('0x18')){logger['info']('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x38b868,_0x3c1653['moduleCreate']);_0x1f154d[_0x7cbc('0x4a')]=_0x11b54c!==_0x7cbc('0x47')?_0x11b54c:util[_0x7cbc('0x48')](_0x7cbc('0x49'),_0x38b868);_0x1f154d['Company']=_0x7cbc('0x4b');}else if(_0x3c1653[_0x7cbc('0x45')]===_0x7cbc('0x1a')){logger['info'](_0x7cbc('0x46'),_0x38b868,_0x3c1653[_0x7cbc('0x45')]);_0x1f154d['Name']=_0x11b54c!==_0x7cbc('0x47')?_0x11b54c:util[_0x7cbc('0x48')](_0x7cbc('0x49'),_0x38b868);}else{return null;}}return _0x386975[_0x7cbc('0x23')](_[_0x7cbc('0x4c')](_0x3c1653['moduleCreate']))[_0x7cbc('0x24')](_0x1f154d)[_0x7cbc('0x2d')](function(_0x3fa959){return BPromise[_0x7cbc('0x2b')]({'id':_0x3fa959['id'],'endUserType':_0x3c1653[_0x7cbc('0x45')]});});}});}function getCustomFields(_0x57ac12,_0x13efd4){var _0x331466={};if(_0x57ac12[_0x7cbc('0x39')]>0x0){_['forEach'](_0x57ac12,function(_0x409d50){if(_[_0x7cbc('0x4d')]([_0x7cbc('0x4e'),'picklist'],_0x409d50[_0x7cbc('0x4f')])&&_0x409d50[_0x7cbc('0x50')]){_0x331466[_0x409d50[_0x7cbc('0x50')]]=_0x409d50['content'][_0x7cbc('0x51')]();}else if(_0x409d50[_0x7cbc('0x4f')]==='variable'&&_0x409d50['variableName']&&_0x409d50['idField']){_0x13efd4[_0x409d50['variableName']]&&(_0x331466[_0x409d50[_0x7cbc('0x50')]]=_0x13efd4[_0x409d50[_0x7cbc('0x52')]]['toString']());}else if(_0x409d50['type']===_0x7cbc('0x53')&&_0x409d50['Variable']&&_0x409d50['Variable'][_0x7cbc('0x54')]&&_0x409d50[_0x7cbc('0x50')]){_0x13efd4[_0x409d50[_0x7cbc('0x55')][_0x7cbc('0x54')][_0x7cbc('0x42')]()]&&(_0x331466[_0x409d50[_0x7cbc('0x50')]]=_0x13efd4[_0x409d50[_0x7cbc('0x55')][_0x7cbc('0x54')][_0x7cbc('0x42')]()]['toString']());}});}return _0x331466;}function getConnection(_0x108077){var _0x11973a=_0x108077['password']['concat'](_0x108077[_0x7cbc('0x56')]);var _0x109bfb=new jsforce['Connection']({'oauth2':{'loginUrl':_0x108077[_0x7cbc('0x57')]||_0x7cbc('0x58'),'clientId':_0x108077[_0x7cbc('0x59')],'clientSecret':_0x108077['clientSecret']}});return _0x109bfb['login'](_0x108077[_0x7cbc('0x5a')],_0x11973a)[_0x7cbc('0x2d')](function(){logger['info']('Connection\x20established.');return _0x109bfb;});}exports[_0x7cbc('0x5b')]=function(_0x413769,_0x5712da,_0x5b6d7b,_0x3fbb21,_0x50e802,_0x304adc){var _0x11806d,_0x15b893,_0x485b1d,_0x5c6144;_0x304adc[_0x7cbc('0x5c')]=intUtil['stripTrailingSlash'](_0x304adc[_0x7cbc('0x5c')]);_0x304adc[_0x7cbc('0x57')]=intUtil[_0x7cbc('0x5d')](_0x304adc[_0x7cbc('0x57')]);if(_0x50e802&&_0x50e802[_0x7cbc('0x5e')]){logger[_0x7cbc('0x21')](_0x7cbc('0x5f'),_0x7cbc('0x60'));_0x5712da[_0x7cbc('0x61')]=util[_0x7cbc('0x48')](_0x7cbc('0x62'),_0x304adc[_0x7cbc('0x5c')],_0x5712da[_0x7cbc('0x63')],md5(_0x5712da['uniqueid']));}else{_0x5712da[_0x7cbc('0x61')]='';}return getConnection(_0x304adc)[_0x7cbc('0x2d')](function(_0x11cef1){_0x5c6144=_0x11cef1;return getUser(_0x304adc,_0x3fbb21['email'],_0x5c6144);})[_0x7cbc('0x2d')](function(_0x42d18f){_0x11806d=_0x42d18f;return getEndUser(_0x304adc,_0x5b6d7b,_0x5712da[_0x7cbc('0x64')],_0x5712da[_0x7cbc('0x65')],_0x5c6144);})[_0x7cbc('0x2d')](function(_0x1dc62f){_0x15b893=_0x1dc62f;return getTicket(_0x304adc,_0x11806d,_0x15b893,_0x5b6d7b,_0x5712da,_0x5b6d7b['Fields'],_0x5c6144,_0x7cbc('0x5b'));})[_0x7cbc('0x2d')](function(_0x500669){_0x485b1d=_0x500669;logger[_0x7cbc('0x21')](_0x7cbc('0x66'),_0x485b1d['id']);logger[_0x7cbc('0x21')](_0x7cbc('0x67'),_0x485b1d['id'],_0x3fbb21[_0x7cbc('0x54')],_0x304adc[_0x7cbc('0x4f')]);switch(_0x304adc[_0x7cbc('0x4f')]){case _0x7cbc('0x68'):emit(util[_0x7cbc('0x48')](_0x7cbc('0x69'),_0x3fbb21[_0x7cbc('0x54')]),_0x7cbc('0x6a'),{'recordId':_0x485b1d['id']});break;case _0x7cbc('0x6b'):emit(util[_0x7cbc('0x48')](_0x7cbc('0x69'),_0x3fbb21[_0x7cbc('0x54')]),'trigger:browser:url',{'uri':util[_0x7cbc('0x48')]('%s/%s/e',_0x5c6144[_0x7cbc('0x6c')],_0x485b1d['id'])});break;default:logger[_0x7cbc('0x6d')](_0x7cbc('0x6e'));}})[_0x7cbc('0x6f')](function(_0x3d2fce){logger[_0x7cbc('0x6d')](_0x7cbc('0x5f'),_0x3d2fce);});};exports['outbound']=function(_0x4da098,_0x541630,_0xecea25,_0x3ebec9,_0x3f9f14,_0x552b20,_0x1f6311){var _0x24d51b,_0xfb75de,_0x3cd2b7,_0x30d104;_0x552b20[_0x7cbc('0x5c')]=intUtil[_0x7cbc('0x5d')](_0x552b20[_0x7cbc('0x5c')]);_0x552b20[_0x7cbc('0x57')]=intUtil[_0x7cbc('0x5d')](_0x552b20[_0x7cbc('0x57')]);if(_0x1f6311&&_0x1f6311[_0x7cbc('0x70')]&&_0x1f6311[_0x7cbc('0x70')]!==_0x7cbc('0x71')){logger['info']('[OUTBOUND]',_0x7cbc('0x60'));_0x541630[_0x7cbc('0x61')]=util[_0x7cbc('0x48')](_0x7cbc('0x62'),_0x552b20['serverUrl'],_0x541630[_0x7cbc('0x63')],md5(_0x541630[_0x7cbc('0x63')]));}return getConnection(_0x552b20)[_0x7cbc('0x2d')](function(_0x21678f){_0x30d104=_0x21678f;return getUser(_0x552b20,_0x3ebec9['email'],_0x30d104);})[_0x7cbc('0x2d')](function(_0x68218c){_0x24d51b=_0x68218c;return getEndUser(_0x552b20,_0xecea25,_0x541630['destcalleridname'],_0x541630[_0x7cbc('0x72')],_0x30d104);})['then'](function(_0x349e82){_0xfb75de=_0x349e82;return getTicket(_0x552b20,_0x24d51b,_0xfb75de,_0xecea25,_0x541630,_0xecea25[_0x7cbc('0x73')],_0x30d104,_0x7cbc('0x74'));})[_0x7cbc('0x2d')](function(_0x5ebd97){_0x3cd2b7=_0x5ebd97;logger[_0x7cbc('0x21')](_0x7cbc('0x75'),_0x3cd2b7['id']);logger[_0x7cbc('0x21')](_0x7cbc('0x76'),_0x3cd2b7['id'],_0x3ebec9['name'],_0x552b20[_0x7cbc('0x4f')]);switch(_0x552b20[_0x7cbc('0x4f')]){case _0x7cbc('0x68'):emit(util[_0x7cbc('0x48')]('user:%s',_0x3ebec9[_0x7cbc('0x54')]),_0x7cbc('0x6a'),{'recordId':_0x3cd2b7['id']});break;case _0x7cbc('0x6b'):emit(util['format']('user:%s',_0x3ebec9[_0x7cbc('0x54')]),_0x7cbc('0x77'),{'uri':util[_0x7cbc('0x48')]('%s/%s/e',_0x30d104[_0x7cbc('0x6c')],_0x3cd2b7['id'])});break;default:logger[_0x7cbc('0x6d')](_0x7cbc('0x78'),_0x7cbc('0x79'));}})[_0x7cbc('0x6f')](function(_0x5e9ebb){logger[_0x7cbc('0x6d')](_0x7cbc('0x78'),_0x5e9ebb);});};exports[_0x7cbc('0x7a')]=function(_0x5cfe36,_0x4a8ec2,_0x57345f,_0x5c6dca,_0x2924b2,_0x485bcb){var _0xe518cd,_0x31558d,_0x46194f,_0x29ba35;_0x485bcb['serverUrl']=intUtil[_0x7cbc('0x5d')](_0x485bcb[_0x7cbc('0x5c')]);_0x485bcb['remoteUri']=intUtil[_0x7cbc('0x5d')](_0x485bcb[_0x7cbc('0x57')]);if(_0x2924b2&&_0x2924b2[_0x7cbc('0x5e')]){logger['info']('['+_0x4a8ec2[_0x7cbc('0x7b')][_0x7cbc('0x7c')]()+']',_0x7cbc('0x60'));_0x4a8ec2[_0x7cbc('0x61')]=util[_0x7cbc('0x48')](_0x7cbc('0x62'),_0x485bcb[_0x7cbc('0x5c')],_0x4a8ec2[_0x7cbc('0x63')],md5(_0x4a8ec2[_0x7cbc('0x63')]));}else{_0x4a8ec2[_0x7cbc('0x61')]='';}return getConnection(_0x485bcb)['then'](function(_0x253872){_0x29ba35=_0x253872;if(!_['isNil'](_0x5c6dca)){return getUser(_0x485bcb,_0x5c6dca[_0x7cbc('0x54')],_0x29ba35);}else{return getUser(_0x485bcb,null,_0x29ba35);}})[_0x7cbc('0x2d')](function(_0x4d402d){_0xe518cd=_0x4d402d;return getEndUser(_0x485bcb,_0x57345f,_0x4a8ec2[_0x7cbc('0x64')],_0x4a8ec2[_0x7cbc('0x65')],_0x29ba35);})[_0x7cbc('0x2d')](function(_0x2ba7e7){_0x31558d=_0x2ba7e7;return getTicket(_0x485bcb,_0xe518cd,_0x31558d,_0x57345f,_0x4a8ec2,_0x57345f[_0x7cbc('0x73')],_0x29ba35);})[_0x7cbc('0x2d')](function(_0x474431){_0x46194f=_0x474431;logger[_0x7cbc('0x21')]('['+_0x4a8ec2[_0x7cbc('0x7b')]['toUpperCase']()+']\x20Ticket\x20%s\x20created.',_0x46194f['id']);logger[_0x7cbc('0x21')]('['+_0x4a8ec2[_0x7cbc('0x7b')]['toUpperCase']()+_0x7cbc('0x7d'),_0x485bcb['type']);})[_0x7cbc('0x6f')](function(_0x518ad8){logger[_0x7cbc('0x6d')]('['+_0x4a8ec2['lastevent'][_0x7cbc('0x7c')]()+']',_0x518ad8);});};
\ No newline at end of file