Built motion from commit (unavailable).|2.5.21
[motion2.git] / server / services / ami / trigger / integration / salesforce.js
index 8172960..ea81791 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4ff0=['first','Name','Phone','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.','LastName','<unknown>','format','Caller\x20-\x20%s','upperFirst','create','forEach','string','picklist','idField','toString','type','variable','variableName','customVariable','Variable','name','toLowerCase','password','securityToken','Connection','clientId','clientSecret','username','Connection\x20established.','queue','serverUrl','stripTrailingSlash','remoteUri','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','email','calleridname','calleridnum','Fields','[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','integrationTab','user:%s','trigger:salesforce:display','trigger:browser:url','%s/%s/e','instanceUrl','error','outbound','recordingFormat','none','[OUTBOUND]','destcalleridname','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','newTab','Salesforce\x20account\x20type\x20not\x20recognized','catch','unmanaged','lastevent','toUpperCase','isNil',']\x20Integration\x20account\x20type\x20%s.','lodash','request-promise','bluebird','md5','jsforce','util','ioredis','./util','../../../../config/environment','../../../../config/logger','salesforce','redis','defaults','localhost','assign','getString','Task','IsRecurrence','endUserType','lead','WhoId','WhatId','ticketType','contact','ContactId','account','AccountId','leadId','info','Association\x20between\x20Case\x20and\x20Lead\x20skipped','sobject','validateEmail','User','find','then','Email','Agent\x20%s\x20found.','resolve','identity','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','additionalSearchContact','merge','$or','Contact','execute','cloneDeep','additionalSearchLead','Lead','account_contact_lead','additionalSearchAccount','Account','length'];(function(_0x47e93d,_0x26bbdd){var _0xe86c46=function(_0x10e072){while(--_0x10e072){_0x47e93d['push'](_0x47e93d['shift']());}};_0xe86c46(++_0x26bbdd);}(_0x4ff0,0xc3));var _0x04ff=function(_0x4b36ad,_0x4d923f){_0x4b36ad=_0x4b36ad-0x0;var _0x1d81af=_0x4ff0[_0x4b36ad];return _0x1d81af;};'use strict';var _=require(_0x04ff('0x0'));var rp=require(_0x04ff('0x1'));var moment=require('moment');var BPromise=require(_0x04ff('0x2'));var md5=require(_0x04ff('0x3'));var jsforce=require(_0x04ff('0x4'));var util=require(_0x04ff('0x5'));var Redis=require(_0x04ff('0x6'));var intUtil=require(_0x04ff('0x7'));var config=require(_0x04ff('0x8'));var logger=require(_0x04ff('0x9'))(_0x04ff('0xa'));config[_0x04ff('0xb')]=_[_0x04ff('0xc')](config[_0x04ff('0xb')],{'host':_0x04ff('0xd'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x04ff('0xb')]));function emit(_0x40f4df,_0x365aab,_0x5b4864){io['to'](_0x40f4df)['emit'](_0x365aab,_0x5b4864);}function getTicket(_0x4d2b33,_0x9d2c6e,_0x440957,_0x2f2de2,_0xce0263,_0x34a954,_0x5b3f1b,_0x30e31d){var _0x4ec281=Object[_0x04ff('0xe')]({},{'OwnerId':_0x9d2c6e['id'],'Subject':intUtil[_0x04ff('0xf')](_0x2f2de2['Subjects'],_0xce0263,'\x20'),'Description':intUtil['getString'](_0x2f2de2['Descriptions'],_0xce0263,'\x0a')},getCustomFields(_0x34a954,_0xce0263));if(_0x440957){if(_0x2f2de2['ticketType']===_0x04ff('0x10')){_0x4ec281['ActivityDate']=moment['utc']();_0x4ec281['IsReminderSet']=![];_0x4ec281[_0x04ff('0x11')]=![];if(_0x440957['endUserType']==='contact'||_0x440957[_0x04ff('0x12')]===_0x04ff('0x13')){_0x4ec281[_0x04ff('0x14')]=_0x440957['id'];}else if(_0x440957[_0x04ff('0x12')]==='account'){_0x4ec281[_0x04ff('0x15')]=_0x440957['id'];}}else if(_0x2f2de2[_0x04ff('0x16')]==='Case'){if(_0x440957['endUserType']===_0x04ff('0x17')){_0x4ec281[_0x04ff('0x18')]=_0x440957['id'];}else if(_0x440957[_0x04ff('0x12')]===_0x04ff('0x19')){_0x4ec281[_0x04ff('0x1a')]=_0x440957['id'];}else if(_0x440957[_0x04ff('0x12')]===_0x04ff('0x13')&&_0x2f2de2[_0x04ff('0x1b')]){_0x4ec281[_0x2f2de2[_0x04ff('0x1b')]]=_0x440957['id'];}else{logger[_0x04ff('0x1c')](_0x04ff('0x1d'));}}}return _0x5b3f1b[_0x04ff('0x1e')](_0x2f2de2[_0x04ff('0x16')])['create'](_0x4ec281);}function getUser(_0x26615e,_0xafb39b,_0x3bf93a){if(!_['isNil'](_0xafb39b)&&intUtil[_0x04ff('0x1f')](_0xafb39b)){var _0x47ed7a={'Email':_0xafb39b};var _0x11124e={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x3bf93a[_0x04ff('0x1e')](_0x04ff('0x20'))[_0x04ff('0x21')](_0x47ed7a,_0x11124e)['execute']()[_0x04ff('0x22')](function(_0x30727d){if(_0x30727d['length']){var _0xa4de57=_[_0x04ff('0x21')](_0x30727d,function(_0x5a5ca8){return _0x5a5ca8[_0x04ff('0x23')]===_0xafb39b;});if(_0xa4de57){logger[_0x04ff('0x1c')](_0x04ff('0x24'),_0xafb39b);return BPromise[_0x04ff('0x25')]({'id':_0xa4de57['Id'],'name':_0xa4de57['Name']});}}else{logger[_0x04ff('0x1c')]('Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.',_0xafb39b);return _0x3bf93a[_0x04ff('0x26')]()['then'](function(_0x139917){return BPromise[_0x04ff('0x25')]({'id':_0x139917[_0x04ff('0x27')],'name':_0x139917[_0x04ff('0x28')]});});}});}else{logger[_0x04ff('0x1c')](_0x04ff('0x29'),_0xafb39b);return _0x3bf93a['identity']()['then'](function(_0xb982af){return BPromise[_0x04ff('0x25')]({'id':_0xb982af[_0x04ff('0x27')],'name':_0xb982af['display_name']});});}}function getEndUser(_0x12eefe,_0x283aec,_0x1a82e5,_0x40c2e6,_0x4d2ecd){var _0x1512b0={'$or':{'Phone':_0x40c2e6}};var _0x28714b={'Id':!![],'Name':!![],'Phone':!![]};return BPromise[_0x04ff('0x25')]()[_0x04ff('0x22')](function(){logger[_0x04ff('0x1c')](_0x04ff('0x2a'),_0x40c2e6,_0x283aec[_0x04ff('0x2b')]);switch(_0x283aec['moduleSearch']){case _0x04ff('0x2c'):var _0x4a6eb8=_['cloneDeep'](_0x1512b0);if(_0x283aec[_0x04ff('0x2d')]){var _0x48c80e={};_0x48c80e[_0x283aec[_0x04ff('0x2d')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0x4a6eb8[_0x04ff('0x2f')],_0x48c80e);}return _0x4d2ecd[_0x04ff('0x1e')](_0x04ff('0x30'))[_0x04ff('0x21')](_0x4a6eb8,_0x28714b)[_0x04ff('0x31')]()['then'](function(_0x6aa4de){if(_0x6aa4de&&_0x6aa4de['length']){return _0x6aa4de;}else{var _0x55bc49=_[_0x04ff('0x32')](_0x1512b0);if(_0x283aec[_0x04ff('0x33')]){var _0x4b8c3d={};_0x4b8c3d[_0x283aec[_0x04ff('0x33')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0x55bc49[_0x04ff('0x2f')],_0x4b8c3d);}return _0x4d2ecd[_0x04ff('0x1e')](_0x04ff('0x34'))[_0x04ff('0x21')](_0x55bc49,_0x28714b);}});case _0x04ff('0x35'):var _0x1a7d67=_[_0x04ff('0x32')](_0x1512b0);if(_0x283aec[_0x04ff('0x36')]){var _0x48c80e={};_0x48c80e[_0x283aec['additionalSearchAccount']]=_0x40c2e6;_[_0x04ff('0x2e')](_0x1a7d67[_0x04ff('0x2f')],_0x48c80e);}return _0x4d2ecd[_0x04ff('0x1e')](_0x04ff('0x37'))[_0x04ff('0x21')](_0x1a7d67,_0x28714b)[_0x04ff('0x31')]()[_0x04ff('0x22')](function(_0x16982e){if(_0x16982e&&_0x16982e[_0x04ff('0x38')]){return _0x16982e;}else{var _0xf43cef=_[_0x04ff('0x32')](_0x1512b0);if(_0x283aec[_0x04ff('0x2d')]){var _0x1c5cd9={};_0x1c5cd9[_0x283aec[_0x04ff('0x2d')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0xf43cef[_0x04ff('0x2f')],_0x1c5cd9);}return _0x4d2ecd[_0x04ff('0x1e')](_0x04ff('0x30'))[_0x04ff('0x21')](_0xf43cef,_0x28714b)[_0x04ff('0x22')](function(_0xfec73f){if(_0xfec73f&&_0xfec73f['length']){return _0xfec73f;}else{var _0xfa611=_[_0x04ff('0x32')](_0x1512b0);if(_0x283aec[_0x04ff('0x33')]){var _0x3143a0={};_0x3143a0[_0x283aec[_0x04ff('0x33')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0xfa611[_0x04ff('0x2f')],_0x3143a0);}return _0x4d2ecd['sobject'](_0x04ff('0x34'))['find'](_0xfa611,_0x28714b);}});}});case _0x04ff('0x17'):var _0x4a6eb8=_[_0x04ff('0x32')](_0x1512b0);if(_0x283aec[_0x04ff('0x2d')]){var _0x48c80e={};_0x48c80e[_0x283aec[_0x04ff('0x2d')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0x4a6eb8['$or'],_0x48c80e);}return _0x4d2ecd[_0x04ff('0x1e')]('Contact')[_0x04ff('0x21')](_0x4a6eb8,_0x28714b)[_0x04ff('0x31')]();case _0x04ff('0x13'):var _0x4389a8=_[_0x04ff('0x32')](_0x1512b0);if(_0x283aec[_0x04ff('0x33')]){var _0x48c80e={};_0x48c80e[_0x283aec[_0x04ff('0x33')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0x4389a8[_0x04ff('0x2f')],_0x48c80e);}return _0x4d2ecd['sobject'](_0x04ff('0x34'))[_0x04ff('0x21')](_0x4389a8,_0x28714b);case'account':var _0x1a7d67=_['cloneDeep'](_0x1512b0);if(_0x283aec[_0x04ff('0x36')]){var _0x48c80e={};_0x48c80e[_0x283aec[_0x04ff('0x36')]]=_0x40c2e6;_[_0x04ff('0x2e')](_0x1a7d67['$or'],_0x48c80e);}return _0x4d2ecd[_0x04ff('0x1e')](_0x04ff('0x37'))[_0x04ff('0x21')](_0x1a7d67,_0x28714b);default:return null;}})[_0x04ff('0x22')](function(_0x6db5aa){if(_0x6db5aa&&_0x6db5aa['length']){var _0x5bf70d=_[_0x04ff('0x39')](_0x6db5aa);if(_0x5bf70d){return BPromise[_0x04ff('0x25')]({'id':_0x5bf70d['Id'],'name':_0x5bf70d[_0x04ff('0x3a')],'phone':_0x5bf70d[_0x04ff('0x3b')],'endUserType':_0x5bf70d['attributes']['type']['toLowerCase']()});}}})[_0x04ff('0x22')](function(_0x50409c){if(_0x50409c){logger[_0x04ff('0x1c')](_0x04ff('0x3c'),_0x50409c[_0x04ff('0x12')],_0x40c2e6);return BPromise[_0x04ff('0x25')](_0x50409c);}else{logger['info'](_0x04ff('0x3d'),_0x40c2e6);var _0x29acc7={'Phone':_0x40c2e6};if(_0x283aec[_0x04ff('0x3e')]){if(_0x283aec[_0x04ff('0x3e')]===_0x04ff('0x17')){logger[_0x04ff('0x1c')](_0x04ff('0x3f'),_0x40c2e6,_0x283aec[_0x04ff('0x3e')]);_0x29acc7[_0x04ff('0x40')]=_0x1a82e5!==_0x04ff('0x41')?_0x1a82e5:util[_0x04ff('0x42')]('Caller\x20-\x20%s',_0x40c2e6);}else if(_0x283aec['moduleCreate']===_0x04ff('0x13')){logger[_0x04ff('0x1c')](_0x04ff('0x3f'),_0x40c2e6,_0x283aec['moduleCreate']);_0x29acc7[_0x04ff('0x40')]=_0x1a82e5!=='<unknown>'?_0x1a82e5:util[_0x04ff('0x42')](_0x04ff('0x43'),_0x40c2e6);_0x29acc7['Company']='No\x20Company';}else if(_0x283aec[_0x04ff('0x3e')]===_0x04ff('0x19')){logger['info'](_0x04ff('0x3f'),_0x40c2e6,_0x283aec[_0x04ff('0x3e')]);_0x29acc7[_0x04ff('0x3a')]=_0x1a82e5!==_0x04ff('0x41')?_0x1a82e5:util[_0x04ff('0x42')]('Caller\x20-\x20%s',_0x40c2e6);}else{return null;}}return _0x4d2ecd[_0x04ff('0x1e')](_[_0x04ff('0x44')](_0x283aec[_0x04ff('0x3e')]))[_0x04ff('0x45')](_0x29acc7)['then'](function(_0xf8e9b1){return BPromise[_0x04ff('0x25')]({'id':_0xf8e9b1['id'],'endUserType':_0x283aec[_0x04ff('0x3e')]});});}});}function getCustomFields(_0x12ce94,_0x4a163d){var _0x58fd91={};if(_0x12ce94[_0x04ff('0x38')]>0x0){_[_0x04ff('0x46')](_0x12ce94,function(_0x381e0a){if(_['includes']([_0x04ff('0x47'),_0x04ff('0x48')],_0x381e0a['type'])&&_0x381e0a[_0x04ff('0x49')]){_0x58fd91[_0x381e0a[_0x04ff('0x49')]]=_0x381e0a['content'][_0x04ff('0x4a')]();}else if(_0x381e0a[_0x04ff('0x4b')]===_0x04ff('0x4c')&&_0x381e0a[_0x04ff('0x4d')]&&_0x381e0a[_0x04ff('0x49')]){_0x4a163d[_0x381e0a['variableName']]&&(_0x58fd91[_0x381e0a[_0x04ff('0x49')]]=_0x4a163d[_0x381e0a[_0x04ff('0x4d')]][_0x04ff('0x4a')]());}else if(_0x381e0a[_0x04ff('0x4b')]===_0x04ff('0x4e')&&_0x381e0a[_0x04ff('0x4f')]&&_0x381e0a['Variable'][_0x04ff('0x50')]&&_0x381e0a[_0x04ff('0x49')]){_0x4a163d[_0x381e0a['Variable'][_0x04ff('0x50')][_0x04ff('0x51')]()]&&(_0x58fd91[_0x381e0a[_0x04ff('0x49')]]=_0x4a163d[_0x381e0a['Variable'][_0x04ff('0x50')][_0x04ff('0x51')]()][_0x04ff('0x4a')]());}});}return _0x58fd91;}function getConnection(_0x471862){var _0xafb91c=_0x471862[_0x04ff('0x52')]['concat'](_0x471862[_0x04ff('0x53')]);var _0x29fc0e=new jsforce[(_0x04ff('0x54'))]({'oauth2':{'loginUrl':_0x471862['remoteUri']||'https://login.salesforce.com','clientId':_0x471862[_0x04ff('0x55')],'clientSecret':_0x471862[_0x04ff('0x56')]}});return _0x29fc0e['login'](_0x471862[_0x04ff('0x57')],_0xafb91c)[_0x04ff('0x22')](function(){logger['info'](_0x04ff('0x58'));return _0x29fc0e;});}exports[_0x04ff('0x59')]=function(_0x5d35df,_0x2cd169,_0x16c02e,_0x3b4872,_0x41d678,_0x2f4f07){var _0x5cc73f,_0x570652,_0x4d4ed5,_0x1ba7b2;_0x2f4f07[_0x04ff('0x5a')]=intUtil[_0x04ff('0x5b')](_0x2f4f07[_0x04ff('0x5a')]);_0x2f4f07[_0x04ff('0x5c')]=intUtil[_0x04ff('0x5b')](_0x2f4f07[_0x04ff('0x5c')]);if(_0x41d678&&_0x41d678[_0x04ff('0x5d')]){logger[_0x04ff('0x1c')](_0x04ff('0x5e'),_0x04ff('0x5f'));_0x2cd169[_0x04ff('0x60')]=util['format'](_0x04ff('0x61'),_0x2f4f07[_0x04ff('0x5a')],_0x2cd169[_0x04ff('0x62')],md5(_0x2cd169[_0x04ff('0x62')]));}else{_0x2cd169[_0x04ff('0x60')]='';}return getConnection(_0x2f4f07)[_0x04ff('0x22')](function(_0x2fdb9f){_0x1ba7b2=_0x2fdb9f;return getUser(_0x2f4f07,_0x3b4872[_0x04ff('0x63')],_0x1ba7b2);})['then'](function(_0x49b393){_0x5cc73f=_0x49b393;return getEndUser(_0x2f4f07,_0x16c02e,_0x2cd169[_0x04ff('0x64')],_0x2cd169[_0x04ff('0x65')],_0x1ba7b2);})[_0x04ff('0x22')](function(_0x19b41e){_0x570652=_0x19b41e;return getTicket(_0x2f4f07,_0x5cc73f,_0x570652,_0x16c02e,_0x2cd169,_0x16c02e[_0x04ff('0x66')],_0x1ba7b2,'queue');})[_0x04ff('0x22')](function(_0x54770d){_0x4d4ed5=_0x54770d;logger['info']('[QUEUE]\x20Ticket\x20%s\x20created',_0x4d4ed5['id']);logger[_0x04ff('0x1c')](_0x04ff('0x67'),_0x4d4ed5['id'],_0x3b4872[_0x04ff('0x50')],_0x2f4f07[_0x04ff('0x4b')]);switch(_0x2f4f07[_0x04ff('0x4b')]){case _0x04ff('0x68'):emit(util['format'](_0x04ff('0x69'),_0x3b4872[_0x04ff('0x50')]),_0x04ff('0x6a'),{'recordId':_0x4d4ed5['id']});break;case'newTab':emit(util[_0x04ff('0x42')](_0x04ff('0x69'),_0x3b4872[_0x04ff('0x50')]),_0x04ff('0x6b'),{'uri':util[_0x04ff('0x42')](_0x04ff('0x6c'),_0x1ba7b2[_0x04ff('0x6d')],_0x4d4ed5['id'])});break;default:logger['error']('[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.');}})['catch'](function(_0x279d2a){logger[_0x04ff('0x6e')](_0x04ff('0x5e'),_0x279d2a);});};exports[_0x04ff('0x6f')]=function(_0x99ec06,_0x4bc697,_0x2bcca6,_0x424b66,_0x4b4de9,_0x91ff6d,_0x4c0a2d){var _0xb81382,_0x1415e3,_0x5a54c9,_0x51a391;_0x91ff6d[_0x04ff('0x5a')]=intUtil['stripTrailingSlash'](_0x91ff6d[_0x04ff('0x5a')]);_0x91ff6d['remoteUri']=intUtil[_0x04ff('0x5b')](_0x91ff6d['remoteUri']);if(_0x4c0a2d&&_0x4c0a2d[_0x04ff('0x70')]&&_0x4c0a2d['recordingFormat']!==_0x04ff('0x71')){logger[_0x04ff('0x1c')](_0x04ff('0x72'),_0x04ff('0x5f'));_0x4bc697[_0x04ff('0x60')]=util[_0x04ff('0x42')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x91ff6d['serverUrl'],_0x4bc697['uniqueid'],md5(_0x4bc697[_0x04ff('0x62')]));}return getConnection(_0x91ff6d)[_0x04ff('0x22')](function(_0x11f2f1){_0x51a391=_0x11f2f1;return getUser(_0x91ff6d,_0x424b66[_0x04ff('0x63')],_0x51a391);})[_0x04ff('0x22')](function(_0xe9e524){_0xb81382=_0xe9e524;return getEndUser(_0x91ff6d,_0x2bcca6,_0x4bc697[_0x04ff('0x73')],_0x4bc697['destcalleridnum'],_0x51a391);})[_0x04ff('0x22')](function(_0x4281ce){_0x1415e3=_0x4281ce;return getTicket(_0x91ff6d,_0xb81382,_0x1415e3,_0x2bcca6,_0x4bc697,_0x2bcca6[_0x04ff('0x66')],_0x51a391,_0x04ff('0x6f'));})[_0x04ff('0x22')](function(_0x16f0fc){_0x5a54c9=_0x16f0fc;logger[_0x04ff('0x1c')](_0x04ff('0x74'),_0x5a54c9['id']);logger[_0x04ff('0x1c')](_0x04ff('0x75'),_0x5a54c9['id'],_0x424b66[_0x04ff('0x50')],_0x91ff6d[_0x04ff('0x4b')]);switch(_0x91ff6d['type']){case _0x04ff('0x68'):emit(util['format'](_0x04ff('0x69'),_0x424b66['name']),'trigger:salesforce:display',{'recordId':_0x5a54c9['id']});break;case _0x04ff('0x76'):emit(util[_0x04ff('0x42')]('user:%s',_0x424b66[_0x04ff('0x50')]),'trigger:browser:url',{'uri':util[_0x04ff('0x42')](_0x04ff('0x6c'),_0x51a391[_0x04ff('0x6d')],_0x5a54c9['id'])});break;default:logger['error'](_0x04ff('0x72'),_0x04ff('0x77'));}})[_0x04ff('0x78')](function(_0x11d799){logger[_0x04ff('0x6e')]('[OUTBOUND]',_0x11d799);});};exports[_0x04ff('0x79')]=function(_0x2aaf6e,_0x5d2acd,_0x1f6209,_0x8f4b2c,_0x4f3704,_0x3e488e){var _0x44cf8c,_0x1d34be,_0x3cc8e1,_0x357a21;_0x3e488e[_0x04ff('0x5a')]=intUtil[_0x04ff('0x5b')](_0x3e488e[_0x04ff('0x5a')]);_0x3e488e[_0x04ff('0x5c')]=intUtil[_0x04ff('0x5b')](_0x3e488e[_0x04ff('0x5c')]);if(_0x4f3704&&_0x4f3704['monitor_format']){logger[_0x04ff('0x1c')]('['+_0x5d2acd[_0x04ff('0x7a')][_0x04ff('0x7b')]()+']','Recording\x20is\x20enabled!');_0x5d2acd[_0x04ff('0x60')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x3e488e[_0x04ff('0x5a')],_0x5d2acd['uniqueid'],md5(_0x5d2acd[_0x04ff('0x62')]));}else{_0x5d2acd[_0x04ff('0x60')]='';}return getConnection(_0x3e488e)[_0x04ff('0x22')](function(_0x1c3166){_0x357a21=_0x1c3166;if(!_[_0x04ff('0x7c')](_0x8f4b2c)){return getUser(_0x3e488e,_0x8f4b2c[_0x04ff('0x50')],_0x357a21);}else{return getUser(_0x3e488e,null,_0x357a21);}})[_0x04ff('0x22')](function(_0x38e133){_0x44cf8c=_0x38e133;return getEndUser(_0x3e488e,_0x1f6209,_0x5d2acd['calleridname'],_0x5d2acd[_0x04ff('0x65')],_0x357a21);})[_0x04ff('0x22')](function(_0x37a4c2){_0x1d34be=_0x37a4c2;return getTicket(_0x3e488e,_0x44cf8c,_0x1d34be,_0x1f6209,_0x5d2acd,_0x1f6209[_0x04ff('0x66')],_0x357a21);})[_0x04ff('0x22')](function(_0x3a4bed){_0x3cc8e1=_0x3a4bed;logger['info']('['+_0x5d2acd['lastevent'][_0x04ff('0x7b')]()+']\x20Ticket\x20%s\x20created.',_0x3cc8e1['id']);logger['info']('['+_0x5d2acd[_0x04ff('0x7a')]['toUpperCase']()+_0x04ff('0x7d'),_0x3e488e[_0x04ff('0x4b')]);})[_0x04ff('0x78')](function(_0x399d81){logger['error']('['+_0x5d2acd[_0x04ff('0x7a')][_0x04ff('0x7b')]()+']',_0x399d81);});};
\ No newline at end of file
+var _0xf569=['unmanaged','lastevent','toUpperCase',']\x20Integration\x20account\x20type\x20%s.','lodash','request-promise','moment','bluebird','md5','ioredis','./util','../../../../config/environment','../../../../config/logger','salesforce','redis','defaults','socket.io-emitter','emit','ticketType','Task','assign','utc','getString','Descriptions','WhoId','create','isNil','validateEmail','sobject','User','length','find','info','Agent\x20%s\x20found.','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','identity','resolve','user_id','display_name','then','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','moduleSearch','Contact','execute','contact','Lead','Case','Phone','Name','<unknown>','format','Caller\x20-\x20%s','Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.','moduleCreate','lead','Company','No\x20Company','forEach','string','idField','type','variable','variableName','customVariable','Variable','name','toLowerCase','toString','password','concat','Connection','remoteUri','https://login.salesforce.com','clientSecret','username','Connection\x20established.','serverUrl','stripTrailingSlash','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','calleridname','calleridnum','Fields','[QUEUE]\x20Ticket\x20%s\x20created','[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','integrationTab','newTab','trigger:browser:url','%s/%s/e','instanceUrl','catch','error','stringify','outbound','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum','[OUTBOUND]\x20Ticket\x20%s\x20created.','user:%s','Salesforce\x20account\x20type\x20not\x20recognized'];(function(_0x7888bd,_0x53f6f3){var _0x25e3c0=function(_0x59c177){while(--_0x59c177){_0x7888bd['push'](_0x7888bd['shift']());}};_0x25e3c0(++_0x53f6f3);}(_0xf569,0x6d));var _0x9f56=function(_0x2b9b7f,_0x4d47df){_0x2b9b7f=_0x2b9b7f-0x0;var _0x4ed19a=_0xf569[_0x2b9b7f];return _0x4ed19a;};'use strict';var _=require(_0x9f56('0x0'));var rp=require(_0x9f56('0x1'));var moment=require(_0x9f56('0x2'));var BPromise=require(_0x9f56('0x3'));var md5=require(_0x9f56('0x4'));var jsforce=require('jsforce');var util=require('util');var Redis=require(_0x9f56('0x5'));var intUtil=require(_0x9f56('0x6'));var config=require(_0x9f56('0x7'));var logger=require(_0x9f56('0x8'))(_0x9f56('0x9'));config[_0x9f56('0xa')]=_[_0x9f56('0xb')](config[_0x9f56('0xa')],{'host':'localhost','port':0x18eb});var io=require(_0x9f56('0xc'))(new Redis(config[_0x9f56('0xa')]));function emit(_0x1da049,_0x29ff3e,_0x32f375){io['to'](_0x1da049)[_0x9f56('0xd')](_0x29ff3e,_0x32f375);}function getTicket(_0x267295,_0x4b2737,_0x1c1ae4,_0x47dcb6,_0xd13f5c,_0x40ff45,_0x119241,_0x45fd13){var _0x136b1b={};if(_0x47dcb6[_0x9f56('0xe')]===_0x9f56('0xf')){_0x136b1b=Object[_0x9f56('0x10')]({},{'OwnerId':_0x4b2737['id'],'ActivityDate':moment[_0x9f56('0x11')](),'IsReminderSet':![],'IsRecurrence':![],'Subject':intUtil[_0x9f56('0x12')](_0x47dcb6['Subjects'],_0xd13f5c,'\x20'),'Description':intUtil['getString'](_0x47dcb6[_0x9f56('0x13')],_0xd13f5c,'\x0a')},getCustomFields(_0x40ff45,_0xd13f5c));if(_0x1c1ae4){_0x136b1b[_0x9f56('0x14')]=_0x1c1ae4['id'];}}else if(_0x47dcb6[_0x9f56('0xe')]==='Case'){_0x136b1b=Object[_0x9f56('0x10')]({},{'OwnerId':_0x4b2737['id'],'Subject':intUtil[_0x9f56('0x12')](_0x47dcb6['Subjects'],_0xd13f5c,'\x20'),'Description':intUtil[_0x9f56('0x12')](_0x47dcb6[_0x9f56('0x13')],_0xd13f5c,'\x0a')},getCustomFields(_0x40ff45,_0xd13f5c));if(_0x1c1ae4){_0x136b1b['ContactId']=_0x1c1ae4['id'];}}return _0x119241['sobject'](_0x47dcb6[_0x9f56('0xe')])[_0x9f56('0x15')](_0x136b1b);}function getUser(_0xf973d9,_0x4e9778,_0x5105e3){if(!_[_0x9f56('0x16')](_0x4e9778)&&intUtil[_0x9f56('0x17')](_0x4e9778)){var _0x492174={'Email':_0x4e9778};var _0x596002={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x5105e3[_0x9f56('0x18')](_0x9f56('0x19'))['find'](_0x492174,_0x596002)['execute']()['then'](function(_0x2ece56){if(_0x2ece56[_0x9f56('0x1a')]){var _0x3b0d3f=_[_0x9f56('0x1b')](_0x2ece56,function(_0x4ac478){return _0x4ac478['Email']===_0x4e9778;});if(_0x3b0d3f){logger[_0x9f56('0x1c')](_0x9f56('0x1d'),_0x4e9778);return BPromise['resolve']({'id':_0x3b0d3f['Id'],'name':_0x3b0d3f['Name']});}}else{logger['info'](_0x9f56('0x1e'),_0x4e9778);return _0x5105e3[_0x9f56('0x1f')]()['then'](function(_0x9cbd50){return BPromise[_0x9f56('0x20')]({'id':_0x9cbd50[_0x9f56('0x21')],'name':_0x9cbd50[_0x9f56('0x22')]});});}});}else{logger[_0x9f56('0x1c')](_0x9f56('0x1e'),_0x4e9778);return _0x5105e3[_0x9f56('0x1f')]()['then'](function(_0x52af97){return BPromise[_0x9f56('0x20')]({'id':_0x52af97['user_id'],'name':_0x52af97[_0x9f56('0x22')]});});}}function getEndUser(_0x1f18db,_0x42e4a4,_0x235474,_0x43925c,_0x476db4){var _0x4de52e={'Phone':_0x43925c};var _0x202b12={'Id':!![],'Name':!![],'Phone':!![]};return BPromise[_0x9f56('0x20')]()[_0x9f56('0x23')](function(){if(_0x42e4a4['ticketType']===_0x9f56('0xf')){logger[_0x9f56('0x1c')](_0x9f56('0x24'),_0x43925c,_0x42e4a4[_0x9f56('0x25')]);switch(_0x42e4a4[_0x9f56('0x25')]){case'contact_lead':return _0x476db4[_0x9f56('0x18')](_0x9f56('0x26'))['find'](_0x4de52e,_0x202b12)[_0x9f56('0x27')]()[_0x9f56('0x23')](function(_0xa54579){if(_0xa54579&&_0xa54579[_0x9f56('0x1a')]){return _0xa54579;}else{return _0x476db4[_0x9f56('0x18')]('Lead')[_0x9f56('0x1b')](_0x4de52e,_0x202b12);}});case _0x9f56('0x28'):return _0x476db4[_0x9f56('0x18')](_0x9f56('0x26'))['find'](_0x4de52e,_0x202b12)[_0x9f56('0x27')]();case'lead':return _0x476db4[_0x9f56('0x18')](_0x9f56('0x29'))[_0x9f56('0x1b')](_0x4de52e,_0x202b12);default:return null;}}else if(_0x42e4a4[_0x9f56('0xe')]===_0x9f56('0x2a')){logger['info']('Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.',_0x43925c,_0x9f56('0x28'));return _0x476db4[_0x9f56('0x18')](_0x9f56('0x26'))['find'](_0x4de52e,_0x202b12)[_0x9f56('0x27')]();}})[_0x9f56('0x23')](function(_0x5f0172){if(_0x5f0172&&_0x5f0172[_0x9f56('0x1a')]){var _0x3ca997=_[_0x9f56('0x1b')](_0x5f0172,function(_0x393cbf){return _0x393cbf[_0x9f56('0x2b')]===_0x43925c;});if(_0x3ca997){return BPromise['resolve']({'id':_0x3ca997['Id'],'name':_0x3ca997[_0x9f56('0x2c')],'phone':_0x3ca997['Phone']});}}})[_0x9f56('0x23')](function(_0x5c4bc4){if(_0x5c4bc4){logger[_0x9f56('0x1c')]('Enduser\x20with\x20phone\x20%s\x20found.',_0x43925c);return BPromise[_0x9f56('0x20')](_0x5c4bc4);}else{logger['info']('Enduser\x20with\x20phone\x20%s\x20not\x20found.',_0x43925c);var _0x3bf743={'LastName':_0x235474!==_0x9f56('0x2d')?_0x235474:util[_0x9f56('0x2e')](_0x9f56('0x2f'),_0x43925c),'Phone':_0x43925c};if(_0x42e4a4['moduleCreate']){if(_0x42e4a4['moduleCreate']==='contact'){logger[_0x9f56('0x1c')](_0x9f56('0x30'),_0x43925c,_0x42e4a4['moduleCreate']);}else if(_0x42e4a4[_0x9f56('0x31')]===_0x9f56('0x32')&&_0x42e4a4[_0x9f56('0xe')]===_0x9f56('0xf')){logger[_0x9f56('0x1c')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x43925c,_0x42e4a4[_0x9f56('0x31')]);_0x3bf743[_0x9f56('0x33')]=_0x9f56('0x34');}else{return null;}}return _0x476db4['sobject'](_['upperFirst'](_0x42e4a4[_0x9f56('0x31')]))[_0x9f56('0x15')](_0x3bf743);}});}function getCustomFields(_0x355cde,_0x3b0bd8){var _0x4c88be={};if(_0x355cde[_0x9f56('0x1a')]>0x0){_[_0x9f56('0x35')](_0x355cde,function(_0x18e572){if(_0x18e572['type']===_0x9f56('0x36')&&_0x18e572[_0x9f56('0x37')]){_0x4c88be[_0x18e572[_0x9f56('0x37')]]=_0x18e572['content']['toString']();}else if(_0x18e572[_0x9f56('0x38')]===_0x9f56('0x39')&&_0x18e572[_0x9f56('0x3a')]&&_0x18e572[_0x9f56('0x37')]){_0x3b0bd8[_0x18e572[_0x9f56('0x3a')]]&&(_0x4c88be[_0x18e572[_0x9f56('0x37')]]=_0x3b0bd8[_0x18e572[_0x9f56('0x3a')]]['toString']());}else if(_0x18e572[_0x9f56('0x38')]===_0x9f56('0x3b')&&_0x18e572['Variable']&&_0x18e572[_0x9f56('0x3c')][_0x9f56('0x3d')]&&_0x18e572[_0x9f56('0x37')]){_0x3b0bd8[_0x18e572['Variable'][_0x9f56('0x3d')][_0x9f56('0x3e')]()]&&(_0x4c88be[_0x18e572[_0x9f56('0x37')]]=_0x3b0bd8[_0x18e572[_0x9f56('0x3c')]['name'][_0x9f56('0x3e')]()][_0x9f56('0x3f')]());}});}return _0x4c88be;}function getConnection(_0x3a20c5){var _0x4de274=_0x3a20c5[_0x9f56('0x40')][_0x9f56('0x41')](_0x3a20c5['securityToken']);var _0x3e1fe0=new jsforce[(_0x9f56('0x42'))]({'oauth2':{'loginUrl':_0x3a20c5[_0x9f56('0x43')]||_0x9f56('0x44'),'clientId':_0x3a20c5['clientId'],'clientSecret':_0x3a20c5[_0x9f56('0x45')]}});return _0x3e1fe0['login'](_0x3a20c5[_0x9f56('0x46')],_0x4de274)[_0x9f56('0x23')](function(){logger[_0x9f56('0x1c')](_0x9f56('0x47'));return _0x3e1fe0;});}exports['queue']=function(_0x1f3d2b,_0x307ed1,_0x14a2c5,_0x5b384b,_0x55dde4,_0x244d51){var _0x3ae426,_0x4f1b4e,_0x2d109e,_0x40404a;_0x244d51[_0x9f56('0x48')]=intUtil[_0x9f56('0x49')](_0x244d51['serverUrl']);_0x244d51['remoteUri']=intUtil['stripTrailingSlash'](_0x244d51[_0x9f56('0x43')]);if(_0x55dde4&&_0x55dde4['monitor_format']){logger['info'](_0x9f56('0x4a'),_0x9f56('0x4b'));_0x307ed1[_0x9f56('0x4c')]=util[_0x9f56('0x2e')](_0x9f56('0x4d'),_0x244d51[_0x9f56('0x48')],_0x307ed1['uniqueid'],md5(_0x307ed1[_0x9f56('0x4e')]));}else{_0x307ed1[_0x9f56('0x4c')]='';}return getConnection(_0x244d51)[_0x9f56('0x23')](function(_0xf2fe09){_0x40404a=_0xf2fe09;return getUser(_0x244d51,_0x5b384b['email'],_0x40404a);})['then'](function(_0x333123){_0x3ae426=_0x333123;return getEndUser(_0x244d51,_0x14a2c5,_0x307ed1[_0x9f56('0x4f')],_0x307ed1[_0x9f56('0x50')],_0x40404a);})['then'](function(_0x3ba3b5){_0x4f1b4e=_0x3ba3b5;return getTicket(_0x244d51,_0x3ae426,_0x4f1b4e,_0x14a2c5,_0x307ed1,_0x14a2c5[_0x9f56('0x51')],_0x40404a,'queue');})[_0x9f56('0x23')](function(_0x538c6a){_0x2d109e=_0x538c6a;logger[_0x9f56('0x1c')](_0x9f56('0x52'),_0x2d109e['id']);logger['info'](_0x9f56('0x53'),_0x2d109e['id'],_0x5b384b[_0x9f56('0x3d')],_0x244d51['type']);switch(_0x244d51[_0x9f56('0x38')]){case _0x9f56('0x54'):emit(util[_0x9f56('0x2e')]('user:%s',_0x5b384b['name']),'trigger:salesforce:display',{'recordId':_0x2d109e['id']});break;case _0x9f56('0x55'):emit(util[_0x9f56('0x2e')]('user:%s',_0x5b384b['name']),_0x9f56('0x56'),{'uri':util['format'](_0x9f56('0x57'),_0x40404a[_0x9f56('0x58')],_0x2d109e['id'])});break;default:logger['error']('[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.');}})[_0x9f56('0x59')](function(_0xccb675){logger[_0x9f56('0x5a')](_0x9f56('0x4a'),JSON[_0x9f56('0x5b')](_0xccb675));});};exports[_0x9f56('0x5c')]=function(_0x5817d6,_0x39f6e5,_0x4a39f6,_0x131857,_0x703335,_0x4b9ab9,_0x5e39f1){var _0x5d63d9,_0x231387,_0x20f030,_0x1f5cec;_0x4b9ab9[_0x9f56('0x48')]=intUtil[_0x9f56('0x49')](_0x4b9ab9[_0x9f56('0x48')]);_0x4b9ab9['remoteUri']=intUtil[_0x9f56('0x49')](_0x4b9ab9[_0x9f56('0x43')]);if(_0x5e39f1&&_0x5e39f1['recordingFormat']&&_0x5e39f1[_0x9f56('0x5d')]!==_0x9f56('0x5e')){logger[_0x9f56('0x1c')](_0x9f56('0x5f'),_0x9f56('0x4b'));_0x39f6e5['recordingURL']=util[_0x9f56('0x2e')](_0x9f56('0x4d'),_0x4b9ab9['serverUrl'],_0x39f6e5[_0x9f56('0x4e')],md5(_0x39f6e5['uniqueid']));}return getConnection(_0x4b9ab9)['then'](function(_0x3d3969){_0x1f5cec=_0x3d3969;return getUser(_0x4b9ab9,_0x131857['email'],_0x1f5cec);})[_0x9f56('0x23')](function(_0x5e6452){_0x5d63d9=_0x5e6452;return getEndUser(_0x4b9ab9,_0x4a39f6,_0x39f6e5[_0x9f56('0x60')],_0x39f6e5[_0x9f56('0x61')],_0x1f5cec);})['then'](function(_0xa36489){_0x231387=_0xa36489;return getTicket(_0x4b9ab9,_0x5d63d9,_0x231387,_0x4a39f6,_0x39f6e5,_0x4a39f6[_0x9f56('0x51')],_0x1f5cec,'outbound');})[_0x9f56('0x23')](function(_0x4f6d63){_0x20f030=_0x4f6d63;logger['info'](_0x9f56('0x62'),_0x20f030['id']);logger['info']('[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.',_0x20f030['id'],_0x131857[_0x9f56('0x3d')],_0x4b9ab9[_0x9f56('0x38')]);switch(_0x4b9ab9['type']){case _0x9f56('0x54'):emit(util['format']('user:%s',_0x131857['name']),'trigger:salesforce:display',{'recordId':_0x20f030['id']});break;case _0x9f56('0x55'):emit(util[_0x9f56('0x2e')](_0x9f56('0x63'),_0x131857[_0x9f56('0x3d')]),_0x9f56('0x56'),{'uri':util[_0x9f56('0x2e')](_0x9f56('0x57'),_0x1f5cec['instanceUrl'],_0x20f030['id'])});break;default:logger[_0x9f56('0x5a')](_0x9f56('0x5f'),_0x9f56('0x64'));}})[_0x9f56('0x59')](function(_0x236438){logger[_0x9f56('0x5a')](_0x9f56('0x5f'),JSON[_0x9f56('0x5b')](_0x236438));});};exports[_0x9f56('0x65')]=function(_0x10ca1d,_0x218a22,_0x5acb0c,_0x157dcd,_0x1b7d7f,_0x22f54e){var _0x127812,_0x1ed436,_0x160dcc,_0x39857d;_0x22f54e[_0x9f56('0x48')]=intUtil['stripTrailingSlash'](_0x22f54e[_0x9f56('0x48')]);_0x22f54e['remoteUri']=intUtil[_0x9f56('0x49')](_0x22f54e[_0x9f56('0x43')]);if(_0x1b7d7f&&_0x1b7d7f['monitor_format']){logger[_0x9f56('0x1c')]('['+_0x218a22[_0x9f56('0x66')][_0x9f56('0x67')]()+']','Recording\x20is\x20enabled!');_0x218a22['recordingURL']=util[_0x9f56('0x2e')](_0x9f56('0x4d'),_0x22f54e[_0x9f56('0x48')],_0x218a22[_0x9f56('0x4e')],md5(_0x218a22[_0x9f56('0x4e')]));}else{_0x218a22[_0x9f56('0x4c')]='';}return getConnection(_0x22f54e)[_0x9f56('0x23')](function(_0x2ed536){_0x39857d=_0x2ed536;if(!_[_0x9f56('0x16')](_0x157dcd)){return getUser(_0x22f54e,_0x157dcd[_0x9f56('0x3d')],_0x39857d);}else{return getUser(_0x22f54e,null,_0x39857d);}})[_0x9f56('0x23')](function(_0x25267e){_0x127812=_0x25267e;return getEndUser(_0x22f54e,_0x5acb0c,_0x218a22[_0x9f56('0x4f')],_0x218a22['calleridnum'],_0x39857d);})['then'](function(_0x5012fb){_0x1ed436=_0x5012fb;return getTicket(_0x22f54e,_0x127812,_0x1ed436,_0x5acb0c,_0x218a22,_0x5acb0c[_0x9f56('0x51')],_0x39857d);})[_0x9f56('0x23')](function(_0x104196){_0x160dcc=_0x104196;logger['info']('['+_0x218a22[_0x9f56('0x66')]['toUpperCase']()+']\x20Ticket\x20%s\x20created.',_0x160dcc['id']);logger['info']('['+_0x218a22['lastevent'][_0x9f56('0x67')]()+_0x9f56('0x68'),_0x22f54e['type']);})[_0x9f56('0x59')](function(_0x437b2e){logger[_0x9f56('0x5a')]('['+_0x218a22[_0x9f56('0x66')][_0x9f56('0x67')]()+']',JSON[_0x9f56('0x5b')](_0x437b2e));});};
\ No newline at end of file