Built motion from commit 9e1399f3.|2.5.37
[motion2.git] / server / services / ami / trigger / integration / salesforce.js
index aceba09..39a3885 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf3c0=['password','concat','remoteUri','https://login.salesforce.com','clientId','clientSecret','login','username','Connection\x20established.','queue','stripTrailingSlash','serverUrl','monitor_format','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','email','calleridname','calleridnum','Fields','[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','trigger:browser:url','instanceUrl','error','[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.','catch','[QUEUE]','stringify','outbound','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!','destcalleridname','destcalleridnum','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','%s/%s/e','Salesforce\x20account\x20type\x20not\x20recognized','lastevent','toUpperCase','isNil','lodash','request-promise','bluebird','md5','jsforce','ioredis','../../../../config/logger','localhost','socket.io-emitter','redis','ticketType','Task','utc','getString','Subjects','Descriptions','WhoId','Case','sobject','create','User','find','execute','then','Email','info','Agent\x20%s\x20found.','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','identity','resolve','user_id','display_name','moduleSearch','Contact','length','contact','lead','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','Name','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.','No\x20Company','upperFirst','forEach','type','idField','content','toString','variable','variableName','Variable','name','toLowerCase'];(function(_0x32dca3,_0x4c3191){var _0x5b9883=function(_0x240859){while(--_0x240859){_0x32dca3['push'](_0x32dca3['shift']());}};_0x5b9883(++_0x4c3191);}(_0xf3c0,0x99));var _0x0f3c=function(_0x4b3b2e,_0xe793ed){_0x4b3b2e=_0x4b3b2e-0x0;var _0x57b7cc=_0xf3c0[_0x4b3b2e];return _0x57b7cc;};'use strict';var _=require(_0x0f3c('0x0'));var rp=require(_0x0f3c('0x1'));var moment=require('moment');var BPromise=require(_0x0f3c('0x2'));var md5=require(_0x0f3c('0x3'));var jsforce=require(_0x0f3c('0x4'));var util=require('util');var Redis=require(_0x0f3c('0x5'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require(_0x0f3c('0x6'))('salesforce');config['redis']=_['defaults'](config['redis'],{'host':_0x0f3c('0x7'),'port':0x18eb});var io=require(_0x0f3c('0x8'))(new Redis(config[_0x0f3c('0x9')]));function emit(_0x5a4d58,_0x49dead,_0x299e53){io['to'](_0x5a4d58)['emit'](_0x49dead,_0x299e53);}function getTicket(_0x4b8089,_0xa06abd,_0x5952da,_0x43da0b,_0x466609,_0x20736d,_0x31c255,_0x3cf9d1){var _0x190e96={};if(_0x43da0b[_0x0f3c('0xa')]===_0x0f3c('0xb')){_0x190e96=Object['assign']({},{'OwnerId':_0xa06abd['id'],'ActivityDate':moment[_0x0f3c('0xc')](),'IsReminderSet':![],'IsRecurrence':![],'Subject':intUtil[_0x0f3c('0xd')](_0x43da0b[_0x0f3c('0xe')],_0x466609,'\x20'),'Description':intUtil[_0x0f3c('0xd')](_0x43da0b[_0x0f3c('0xf')],_0x466609,'\x0a')},getCustomFields(_0x20736d,_0x466609));if(_0x5952da){_0x190e96[_0x0f3c('0x10')]=_0x5952da['id'];}}else if(_0x43da0b['ticketType']===_0x0f3c('0x11')){_0x190e96=Object['assign']({},{'OwnerId':_0xa06abd['id'],'Subject':intUtil[_0x0f3c('0xd')](_0x43da0b['Subjects'],_0x466609,'\x20'),'Description':intUtil['getString'](_0x43da0b[_0x0f3c('0xf')],_0x466609,'\x0a')},getCustomFields(_0x20736d,_0x466609));if(_0x5952da){_0x190e96['ContactId']=_0x5952da['id'];}}return _0x31c255[_0x0f3c('0x12')](_0x43da0b[_0x0f3c('0xa')])[_0x0f3c('0x13')](_0x190e96);}function getUser(_0x2b037e,_0x5b92b4,_0x2f7d3c){if(!_['isNil'](_0x5b92b4)&&intUtil['validateEmail'](_0x5b92b4)){var _0x57c115={'Email':_0x5b92b4};var _0x43fad4={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x2f7d3c[_0x0f3c('0x12')](_0x0f3c('0x14'))[_0x0f3c('0x15')](_0x57c115,_0x43fad4)[_0x0f3c('0x16')]()[_0x0f3c('0x17')](function(_0x2bb934){if(_0x2bb934['length']){var _0xb1742b=_[_0x0f3c('0x15')](_0x2bb934,function(_0x27e8c7){return _0x27e8c7[_0x0f3c('0x18')]===_0x5b92b4;});if(_0xb1742b){logger[_0x0f3c('0x19')](_0x0f3c('0x1a'),_0x5b92b4);return BPromise['resolve']({'id':_0xb1742b['Id'],'name':_0xb1742b['Name']});}}else{logger['info'](_0x0f3c('0x1b'),_0x5b92b4);return _0x2f7d3c[_0x0f3c('0x1c')]()[_0x0f3c('0x17')](function(_0xae1f29){return BPromise[_0x0f3c('0x1d')]({'id':_0xae1f29[_0x0f3c('0x1e')],'name':_0xae1f29[_0x0f3c('0x1f')]});});}});}else{logger['info'](_0x0f3c('0x1b'),_0x5b92b4);return _0x2f7d3c[_0x0f3c('0x1c')]()['then'](function(_0x210728){return BPromise[_0x0f3c('0x1d')]({'id':_0x210728[_0x0f3c('0x1e')],'name':_0x210728['display_name']});});}}function getEndUser(_0x423fc8,_0x53d763,_0x51b307,_0x4d7802,_0x5a01df){var _0x2f078f={'Phone':_0x4d7802};var _0x478dae={'Id':!![],'Name':!![],'Phone':!![]};return BPromise['resolve']()[_0x0f3c('0x17')](function(){if(_0x53d763[_0x0f3c('0xa')]==='Task'){logger['info']('Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.',_0x4d7802,_0x53d763[_0x0f3c('0x20')]);switch(_0x53d763[_0x0f3c('0x20')]){case'contact_lead':return _0x5a01df[_0x0f3c('0x12')](_0x0f3c('0x21'))[_0x0f3c('0x15')](_0x2f078f,_0x478dae)['execute']()[_0x0f3c('0x17')](function(_0x27380d){if(_0x27380d&&_0x27380d[_0x0f3c('0x22')]){return _0x27380d;}else{return _0x5a01df[_0x0f3c('0x12')]('Lead')[_0x0f3c('0x15')](_0x2f078f,_0x478dae);}});case _0x0f3c('0x23'):return _0x5a01df[_0x0f3c('0x12')](_0x0f3c('0x21'))[_0x0f3c('0x15')](_0x2f078f,_0x478dae)[_0x0f3c('0x16')]();case _0x0f3c('0x24'):return _0x5a01df[_0x0f3c('0x12')]('Lead')[_0x0f3c('0x15')](_0x2f078f,_0x478dae);default:return null;}}else if(_0x53d763[_0x0f3c('0xa')]==='Case'){logger[_0x0f3c('0x19')](_0x0f3c('0x25'),_0x4d7802,_0x0f3c('0x23'));return _0x5a01df['sobject'](_0x0f3c('0x21'))[_0x0f3c('0x15')](_0x2f078f,_0x478dae)[_0x0f3c('0x16')]();}})['then'](function(_0x16f92f){if(_0x16f92f&&_0x16f92f[_0x0f3c('0x22')]){var _0x171556=_[_0x0f3c('0x15')](_0x16f92f,function(_0x40a861){return _0x40a861['Phone']===_0x4d7802;});if(_0x171556){return BPromise[_0x0f3c('0x1d')]({'id':_0x171556['Id'],'name':_0x171556[_0x0f3c('0x26')],'phone':_0x171556[_0x0f3c('0x27')]});}}})[_0x0f3c('0x17')](function(_0x653884){if(_0x653884){logger[_0x0f3c('0x19')](_0x0f3c('0x28'),_0x4d7802);return BPromise[_0x0f3c('0x1d')](_0x653884);}else{logger[_0x0f3c('0x19')](_0x0f3c('0x29'),_0x4d7802);var _0x23dd96={'LastName':_0x51b307!==_0x0f3c('0x2a')?_0x51b307:util[_0x0f3c('0x2b')](_0x0f3c('0x2c'),_0x4d7802),'Phone':_0x4d7802};if(_0x53d763[_0x0f3c('0x2d')]){if(_0x53d763[_0x0f3c('0x2d')]===_0x0f3c('0x23')){logger[_0x0f3c('0x19')](_0x0f3c('0x2e'),_0x4d7802,_0x53d763[_0x0f3c('0x2d')]);}else if(_0x53d763[_0x0f3c('0x2d')]===_0x0f3c('0x24')&&_0x53d763[_0x0f3c('0xa')]===_0x0f3c('0xb')){logger[_0x0f3c('0x19')](_0x0f3c('0x2e'),_0x4d7802,_0x53d763[_0x0f3c('0x2d')]);_0x23dd96['Company']=_0x0f3c('0x2f');}else{return null;}}return _0x5a01df['sobject'](_[_0x0f3c('0x30')](_0x53d763[_0x0f3c('0x2d')]))[_0x0f3c('0x13')](_0x23dd96);}});}function getCustomFields(_0x4cbfa9,_0xf5a312){var _0x1971f8={};if(_0x4cbfa9[_0x0f3c('0x22')]>0x0){_[_0x0f3c('0x31')](_0x4cbfa9,function(_0x1e8d84){if(_0x1e8d84[_0x0f3c('0x32')]==='string'&&_0x1e8d84[_0x0f3c('0x33')]){_0x1971f8[_0x1e8d84['idField']]=_0x1e8d84[_0x0f3c('0x34')][_0x0f3c('0x35')]();}else if(_0x1e8d84[_0x0f3c('0x32')]===_0x0f3c('0x36')&&_0x1e8d84[_0x0f3c('0x37')]&&_0x1e8d84[_0x0f3c('0x33')]){_0xf5a312[_0x1e8d84[_0x0f3c('0x37')]]&&(_0x1971f8[_0x1e8d84['idField']]=_0xf5a312[_0x1e8d84[_0x0f3c('0x37')]][_0x0f3c('0x35')]());}else if(_0x1e8d84[_0x0f3c('0x32')]==='customVariable'&&_0x1e8d84['Variable']&&_0x1e8d84[_0x0f3c('0x38')][_0x0f3c('0x39')]&&_0x1e8d84[_0x0f3c('0x33')]){_0xf5a312[_0x1e8d84[_0x0f3c('0x38')]['name']['toLowerCase']()]&&(_0x1971f8[_0x1e8d84[_0x0f3c('0x33')]]=_0xf5a312[_0x1e8d84[_0x0f3c('0x38')][_0x0f3c('0x39')][_0x0f3c('0x3a')]()][_0x0f3c('0x35')]());}});}return _0x1971f8;}function getConnection(_0x312fcb){var _0x1ae876=_0x312fcb[_0x0f3c('0x3b')][_0x0f3c('0x3c')](_0x312fcb['securityToken']);var _0x31d242=new jsforce['Connection']({'oauth2':{'loginUrl':_0x312fcb[_0x0f3c('0x3d')]||_0x0f3c('0x3e'),'clientId':_0x312fcb[_0x0f3c('0x3f')],'clientSecret':_0x312fcb[_0x0f3c('0x40')]}});return _0x31d242[_0x0f3c('0x41')](_0x312fcb[_0x0f3c('0x42')],_0x1ae876)[_0x0f3c('0x17')](function(){logger[_0x0f3c('0x19')](_0x0f3c('0x43'));return _0x31d242;});}exports[_0x0f3c('0x44')]=function(_0x280e5f,_0x3825c6,_0x295d84,_0x2fc9f2,_0x2ff562,_0x32892a){var _0x5d47a7,_0x4b4a1c,_0x3ce769,_0x6226d3;_0x32892a['serverUrl']=intUtil[_0x0f3c('0x45')](_0x32892a[_0x0f3c('0x46')]);_0x32892a[_0x0f3c('0x3d')]=intUtil['stripTrailingSlash'](_0x32892a[_0x0f3c('0x3d')]);if(_0x2ff562&&_0x2ff562[_0x0f3c('0x47')]){logger[_0x0f3c('0x19')]('[QUEUE]','Recording\x20is\x20enabled!');_0x3825c6[_0x0f3c('0x48')]=util[_0x0f3c('0x2b')](_0x0f3c('0x49'),_0x32892a[_0x0f3c('0x46')],_0x3825c6['uniqueid'],md5(_0x3825c6[_0x0f3c('0x4a')]));}else{_0x3825c6['recordingURL']='';}return getConnection(_0x32892a)['then'](function(_0x86cf55){_0x6226d3=_0x86cf55;return getUser(_0x32892a,_0x2fc9f2[_0x0f3c('0x4b')],_0x6226d3);})[_0x0f3c('0x17')](function(_0x48df57){_0x5d47a7=_0x48df57;return getEndUser(_0x32892a,_0x295d84,_0x3825c6[_0x0f3c('0x4c')],_0x3825c6[_0x0f3c('0x4d')],_0x6226d3);})[_0x0f3c('0x17')](function(_0x188fb4){_0x4b4a1c=_0x188fb4;return getTicket(_0x32892a,_0x5d47a7,_0x4b4a1c,_0x295d84,_0x3825c6,_0x295d84[_0x0f3c('0x4e')],_0x6226d3,_0x0f3c('0x44'));})[_0x0f3c('0x17')](function(_0x1e501c){_0x3ce769=_0x1e501c;logger[_0x0f3c('0x19')](_0x0f3c('0x4f'),_0x3ce769['id']);logger['info'](_0x0f3c('0x50'),_0x3ce769['id'],_0x2fc9f2['name'],_0x32892a[_0x0f3c('0x32')]);switch(_0x32892a[_0x0f3c('0x32')]){case _0x0f3c('0x51'):emit(util[_0x0f3c('0x2b')](_0x0f3c('0x52'),_0x2fc9f2[_0x0f3c('0x39')]),_0x0f3c('0x53'),{'recordId':_0x3ce769['id']});break;case _0x0f3c('0x54'):emit(util[_0x0f3c('0x2b')](_0x0f3c('0x52'),_0x2fc9f2['name']),_0x0f3c('0x55'),{'uri':util[_0x0f3c('0x2b')]('%s/%s/e',_0x6226d3[_0x0f3c('0x56')],_0x3ce769['id'])});break;default:logger[_0x0f3c('0x57')](_0x0f3c('0x58'));}})[_0x0f3c('0x59')](function(_0x585781){logger['error'](_0x0f3c('0x5a'),JSON[_0x0f3c('0x5b')](_0x585781));});};exports[_0x0f3c('0x5c')]=function(_0x202f9c,_0x3f4a0d,_0x2dac53,_0x23a2a7,_0x1b6a95,_0x1e81c9,_0x5f4b4b){var _0x40c8ba,_0x24109a,_0xe798f9,_0x2a8e86;_0x1e81c9['serverUrl']=intUtil[_0x0f3c('0x45')](_0x1e81c9['serverUrl']);_0x1e81c9[_0x0f3c('0x3d')]=intUtil[_0x0f3c('0x45')](_0x1e81c9[_0x0f3c('0x3d')]);if(_0x5f4b4b&&_0x5f4b4b['recordingFormat']&&_0x5f4b4b[_0x0f3c('0x5d')]!==_0x0f3c('0x5e')){logger[_0x0f3c('0x19')](_0x0f3c('0x5f'),_0x0f3c('0x60'));_0x3f4a0d['recordingURL']=util[_0x0f3c('0x2b')](_0x0f3c('0x49'),_0x1e81c9[_0x0f3c('0x46')],_0x3f4a0d[_0x0f3c('0x4a')],md5(_0x3f4a0d[_0x0f3c('0x4a')]));}return getConnection(_0x1e81c9)[_0x0f3c('0x17')](function(_0x25bb5d){_0x2a8e86=_0x25bb5d;return getUser(_0x1e81c9,_0x23a2a7[_0x0f3c('0x4b')],_0x2a8e86);})[_0x0f3c('0x17')](function(_0x33a6fe){_0x40c8ba=_0x33a6fe;return getEndUser(_0x1e81c9,_0x2dac53,_0x3f4a0d[_0x0f3c('0x61')],_0x3f4a0d[_0x0f3c('0x62')],_0x2a8e86);})[_0x0f3c('0x17')](function(_0x364fc7){_0x24109a=_0x364fc7;return getTicket(_0x1e81c9,_0x40c8ba,_0x24109a,_0x2dac53,_0x3f4a0d,_0x2dac53[_0x0f3c('0x4e')],_0x2a8e86,_0x0f3c('0x5c'));})[_0x0f3c('0x17')](function(_0x25d73e){_0xe798f9=_0x25d73e;logger[_0x0f3c('0x19')](_0x0f3c('0x63'),_0xe798f9['id']);logger[_0x0f3c('0x19')](_0x0f3c('0x64'),_0xe798f9['id'],_0x23a2a7[_0x0f3c('0x39')],_0x1e81c9[_0x0f3c('0x32')]);switch(_0x1e81c9[_0x0f3c('0x32')]){case _0x0f3c('0x51'):emit(util['format'](_0x0f3c('0x52'),_0x23a2a7['name']),_0x0f3c('0x53'),{'recordId':_0xe798f9['id']});break;case'newTab':emit(util[_0x0f3c('0x2b')]('user:%s',_0x23a2a7[_0x0f3c('0x39')]),'trigger:browser:url',{'uri':util[_0x0f3c('0x2b')](_0x0f3c('0x65'),_0x2a8e86[_0x0f3c('0x56')],_0xe798f9['id'])});break;default:logger['error'](_0x0f3c('0x5f'),_0x0f3c('0x66'));}})[_0x0f3c('0x59')](function(_0x213471){logger[_0x0f3c('0x57')](_0x0f3c('0x5f'),JSON['stringify'](_0x213471));});};exports['unmanaged']=function(_0x365494,_0x149769,_0x47744b,_0x492cc2,_0x3bb72f,_0x16d7f9){var _0x19f0dd,_0x2c318e,_0x45e753,_0x441f6a;_0x16d7f9[_0x0f3c('0x46')]=intUtil[_0x0f3c('0x45')](_0x16d7f9[_0x0f3c('0x46')]);_0x16d7f9[_0x0f3c('0x3d')]=intUtil[_0x0f3c('0x45')](_0x16d7f9[_0x0f3c('0x3d')]);if(_0x3bb72f&&_0x3bb72f[_0x0f3c('0x47')]){logger[_0x0f3c('0x19')]('['+_0x149769[_0x0f3c('0x67')][_0x0f3c('0x68')]()+']',_0x0f3c('0x60'));_0x149769['recordingURL']=util[_0x0f3c('0x2b')](_0x0f3c('0x49'),_0x16d7f9['serverUrl'],_0x149769[_0x0f3c('0x4a')],md5(_0x149769[_0x0f3c('0x4a')]));}else{_0x149769[_0x0f3c('0x48')]='';}return getConnection(_0x16d7f9)[_0x0f3c('0x17')](function(_0x367460){_0x441f6a=_0x367460;if(!_[_0x0f3c('0x69')](_0x492cc2)){return getUser(_0x16d7f9,_0x492cc2[_0x0f3c('0x39')],_0x441f6a);}else{return getUser(_0x16d7f9,null,_0x441f6a);}})[_0x0f3c('0x17')](function(_0x245914){_0x19f0dd=_0x245914;return getEndUser(_0x16d7f9,_0x47744b,_0x149769[_0x0f3c('0x4c')],_0x149769[_0x0f3c('0x4d')],_0x441f6a);})['then'](function(_0x29524f){_0x2c318e=_0x29524f;return getTicket(_0x16d7f9,_0x19f0dd,_0x2c318e,_0x47744b,_0x149769,_0x47744b[_0x0f3c('0x4e')],_0x441f6a);})[_0x0f3c('0x17')](function(_0x118fda){_0x45e753=_0x118fda;logger[_0x0f3c('0x19')]('['+_0x149769[_0x0f3c('0x67')][_0x0f3c('0x68')]()+']\x20Ticket\x20%s\x20created.',_0x45e753['id']);logger[_0x0f3c('0x19')]('['+_0x149769['lastevent'][_0x0f3c('0x68')]()+']\x20Integration\x20account\x20type\x20%s.',_0x16d7f9[_0x0f3c('0x32')]);})[_0x0f3c('0x59')](function(_0x2c1f26){logger[_0x0f3c('0x57')]('['+_0x149769[_0x0f3c('0x67')][_0x0f3c('0x68')]()+']',JSON[_0x0f3c('0x5b')](_0x2c1f26));});};
\ No newline at end of file
+var _0xf06c=['customVariable','Variable','name','toLowerCase','password','concat','securityToken','Connection','remoteUri','https://login.salesforce.com','clientSecret','login','username','Connection\x20established.','queue','serverUrl','stripTrailingSlash','monitor_format','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','calleridname','[QUEUE]\x20Ticket\x20%s\x20created','integrationTab','user:%s','trigger:salesforce:display','newTab','trigger:browser:url','%s/%s/e','[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.','catch','error','none','[OUTBOUND]','email','destcalleridname','Fields','outbound','[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','toUpperCase',']\x20Ticket\x20%s\x20created.','lastevent','lodash','request-promise','moment','md5','jsforce','util','ioredis','./util','../../../../config/environment','socket.io-emitter','assign','getString','Subjects','Descriptions','ticketType','utc','IsReminderSet','IsRecurrence','endUserType','WhoId','account','ContactId','AccountId','lead','leadId','sobject','create','isNil','validateEmail','User','then','length','Email','info','Agent\x20%s\x20found.','resolve','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','identity','user_id','display_name','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','moduleSearch','contact_lead','additionalSearchContact','merge','find','execute','cloneDeep','additionalSearchLead','Lead','account_contact_lead','additionalSearchAccount','Account','$or','Contact','contact','first','Name','Phone','Enduser\x20(%s)\x20with\x20phone\x20%s\x20found','LastName','<unknown>','format','Caller\x20-\x20%s','moduleCreate','No\x20Company','upperFirst','forEach','string','type','idField','content','toString','variable','variableName'];(function(_0x1d1779,_0x284147){var _0x2377e9=function(_0x299f6f){while(--_0x299f6f){_0x1d1779['push'](_0x1d1779['shift']());}};_0x2377e9(++_0x284147);}(_0xf06c,0x199));var _0xcf06=function(_0x33583d,_0x45b9ac){_0x33583d=_0x33583d-0x0;var _0x448ba1=_0xf06c[_0x33583d];return _0x448ba1;};'use strict';var _=require(_0xcf06('0x0'));var rp=require(_0xcf06('0x1'));var moment=require(_0xcf06('0x2'));var BPromise=require('bluebird');var md5=require(_0xcf06('0x3'));var jsforce=require(_0xcf06('0x4'));var util=require(_0xcf06('0x5'));var Redis=require(_0xcf06('0x6'));var intUtil=require(_0xcf06('0x7'));var config=require(_0xcf06('0x8'));var logger=require('../../../../config/logger')('salesforce');config['redis']=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0xcf06('0x9'))(new Redis(config['redis']));function emit(_0xfb4a8d,_0x547fb5,_0x5e71db){io['to'](_0xfb4a8d)['emit'](_0x547fb5,_0x5e71db);}function getTicket(_0x34e5cb,_0x4ed681,_0x29fc87,_0x53876a,_0x4b980e,_0x4e9bad,_0x199147,_0x77b878){var _0x5e66bd=Object[_0xcf06('0xa')]({},{'OwnerId':_0x4ed681['id'],'Subject':intUtil[_0xcf06('0xb')](_0x53876a[_0xcf06('0xc')],_0x4b980e,'\x20'),'Description':intUtil[_0xcf06('0xb')](_0x53876a[_0xcf06('0xd')],_0x4b980e,'\x0a')},getCustomFields(_0x4e9bad,_0x4b980e));if(_0x29fc87){if(_0x53876a[_0xcf06('0xe')]==='Task'){_0x5e66bd['ActivityDate']=moment[_0xcf06('0xf')]();_0x5e66bd[_0xcf06('0x10')]=![];_0x5e66bd[_0xcf06('0x11')]=![];if(_0x29fc87['endUserType']==='contact'||_0x29fc87[_0xcf06('0x12')]==='lead'){_0x5e66bd[_0xcf06('0x13')]=_0x29fc87['id'];}else if(_0x29fc87[_0xcf06('0x12')]===_0xcf06('0x14')){_0x5e66bd['WhatId']=_0x29fc87['id'];}}else if(_0x53876a['ticketType']==='Case'){if(_0x29fc87[_0xcf06('0x12')]==='contact'){_0x5e66bd[_0xcf06('0x15')]=_0x29fc87['id'];}else if(_0x29fc87[_0xcf06('0x12')]===_0xcf06('0x14')){_0x5e66bd[_0xcf06('0x16')]=_0x29fc87['id'];}else if(_0x29fc87[_0xcf06('0x12')]===_0xcf06('0x17')&&_0x53876a[_0xcf06('0x18')]){_0x5e66bd[_0x53876a['leadId']]=_0x29fc87['id'];}else{logger['info']('Association\x20between\x20Case\x20and\x20Lead\x20skipped');}}}return _0x199147[_0xcf06('0x19')](_0x53876a[_0xcf06('0xe')])[_0xcf06('0x1a')](_0x5e66bd);}function getUser(_0x5eef00,_0x4db172,_0x46c1b9){if(!_[_0xcf06('0x1b')](_0x4db172)&&intUtil[_0xcf06('0x1c')](_0x4db172)){var _0x5d2719={'Email':_0x4db172};var _0x1abfab={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x46c1b9[_0xcf06('0x19')](_0xcf06('0x1d'))['find'](_0x5d2719,_0x1abfab)['execute']()[_0xcf06('0x1e')](function(_0x1b7d0f){if(_0x1b7d0f[_0xcf06('0x1f')]){var _0xff6542=_['find'](_0x1b7d0f,function(_0x589db1){return _0x589db1[_0xcf06('0x20')]===_0x4db172;});if(_0xff6542){logger[_0xcf06('0x21')](_0xcf06('0x22'),_0x4db172);return BPromise[_0xcf06('0x23')]({'id':_0xff6542['Id'],'name':_0xff6542['Name']});}}else{logger[_0xcf06('0x21')](_0xcf06('0x24'),_0x4db172);return _0x46c1b9[_0xcf06('0x25')]()[_0xcf06('0x1e')](function(_0x58fcbd){return BPromise[_0xcf06('0x23')]({'id':_0x58fcbd[_0xcf06('0x26')],'name':_0x58fcbd[_0xcf06('0x27')]});});}});}else{logger[_0xcf06('0x21')](_0xcf06('0x24'),_0x4db172);return _0x46c1b9['identity']()['then'](function(_0x58f4b6){return BPromise[_0xcf06('0x23')]({'id':_0x58f4b6[_0xcf06('0x26')],'name':_0x58f4b6['display_name']});});}}function getEndUser(_0x4c4426,_0x56c54c,_0x20f862,_0xbf85ed,_0x35d460){var _0x1f3104={'$or':{'Phone':_0xbf85ed}};var _0x1ac9bb={'Id':!![],'Name':!![],'Phone':!![]};return BPromise['resolve']()[_0xcf06('0x1e')](function(){logger['info'](_0xcf06('0x28'),_0xbf85ed,_0x56c54c[_0xcf06('0x29')]);switch(_0x56c54c[_0xcf06('0x29')]){case _0xcf06('0x2a'):var _0x334f6e=_['cloneDeep'](_0x1f3104);if(_0x56c54c[_0xcf06('0x2b')]){var _0x129a8e={};_0x129a8e[_0x56c54c[_0xcf06('0x2b')]]=_0xbf85ed;_[_0xcf06('0x2c')](_0x334f6e['$or'],_0x129a8e);}return _0x35d460[_0xcf06('0x19')]('Contact')[_0xcf06('0x2d')](_0x334f6e,_0x1ac9bb)[_0xcf06('0x2e')]()['then'](function(_0x3dc1f0){if(_0x3dc1f0&&_0x3dc1f0[_0xcf06('0x1f')]){return _0x3dc1f0;}else{var _0x56a35c=_[_0xcf06('0x2f')](_0x1f3104);if(_0x56c54c[_0xcf06('0x30')]){var _0x4348bd={};_0x4348bd[_0x56c54c[_0xcf06('0x30')]]=_0xbf85ed;_[_0xcf06('0x2c')](_0x56a35c['$or'],_0x4348bd);}return _0x35d460[_0xcf06('0x19')](_0xcf06('0x31'))[_0xcf06('0x2d')](_0x56a35c,_0x1ac9bb);}});case _0xcf06('0x32'):var _0x182911=_[_0xcf06('0x2f')](_0x1f3104);if(_0x56c54c[_0xcf06('0x33')]){var _0x129a8e={};_0x129a8e[_0x56c54c[_0xcf06('0x33')]]=_0xbf85ed;_[_0xcf06('0x2c')](_0x182911['$or'],_0x129a8e);}return _0x35d460[_0xcf06('0x19')](_0xcf06('0x34'))[_0xcf06('0x2d')](_0x182911,_0x1ac9bb)[_0xcf06('0x2e')]()[_0xcf06('0x1e')](function(_0x203d6a){if(_0x203d6a&&_0x203d6a[_0xcf06('0x1f')]){return _0x203d6a;}else{var _0x2fcac9=_['cloneDeep'](_0x1f3104);if(_0x56c54c[_0xcf06('0x2b')]){var _0x1a64e0={};_0x1a64e0[_0x56c54c['additionalSearchContact']]=_0xbf85ed;_['merge'](_0x2fcac9[_0xcf06('0x35')],_0x1a64e0);}return _0x35d460[_0xcf06('0x19')](_0xcf06('0x36'))[_0xcf06('0x2d')](_0x2fcac9,_0x1ac9bb)[_0xcf06('0x1e')](function(_0x4bea57){if(_0x4bea57&&_0x4bea57[_0xcf06('0x1f')]){return _0x4bea57;}else{var _0x2f3658=_[_0xcf06('0x2f')](_0x1f3104);if(_0x56c54c[_0xcf06('0x30')]){var _0x4c1b76={};_0x4c1b76[_0x56c54c['additionalSearchLead']]=_0xbf85ed;_[_0xcf06('0x2c')](_0x2f3658['$or'],_0x4c1b76);}return _0x35d460[_0xcf06('0x19')](_0xcf06('0x31'))[_0xcf06('0x2d')](_0x2f3658,_0x1ac9bb);}});}});case _0xcf06('0x37'):var _0x334f6e=_['cloneDeep'](_0x1f3104);if(_0x56c54c[_0xcf06('0x2b')]){var _0x129a8e={};_0x129a8e[_0x56c54c[_0xcf06('0x2b')]]=_0xbf85ed;_[_0xcf06('0x2c')](_0x334f6e[_0xcf06('0x35')],_0x129a8e);}return _0x35d460['sobject'](_0xcf06('0x36'))[_0xcf06('0x2d')](_0x334f6e,_0x1ac9bb)[_0xcf06('0x2e')]();case _0xcf06('0x17'):var _0x576eae=_['cloneDeep'](_0x1f3104);if(_0x56c54c[_0xcf06('0x30')]){var _0x129a8e={};_0x129a8e[_0x56c54c['additionalSearchLead']]=_0xbf85ed;_[_0xcf06('0x2c')](_0x576eae[_0xcf06('0x35')],_0x129a8e);}return _0x35d460[_0xcf06('0x19')](_0xcf06('0x31'))[_0xcf06('0x2d')](_0x576eae,_0x1ac9bb);case _0xcf06('0x14'):var _0x182911=_[_0xcf06('0x2f')](_0x1f3104);if(_0x56c54c[_0xcf06('0x33')]){var _0x129a8e={};_0x129a8e[_0x56c54c[_0xcf06('0x33')]]=_0xbf85ed;_[_0xcf06('0x2c')](_0x182911[_0xcf06('0x35')],_0x129a8e);}return _0x35d460[_0xcf06('0x19')]('Account')[_0xcf06('0x2d')](_0x182911,_0x1ac9bb);default:return null;}})[_0xcf06('0x1e')](function(_0x50a877){if(_0x50a877&&_0x50a877[_0xcf06('0x1f')]){var _0x370579=_[_0xcf06('0x38')](_0x50a877);if(_0x370579){return BPromise[_0xcf06('0x23')]({'id':_0x370579['Id'],'name':_0x370579[_0xcf06('0x39')],'phone':_0x370579[_0xcf06('0x3a')],'endUserType':_0x370579['attributes']['type']['toLowerCase']()});}}})[_0xcf06('0x1e')](function(_0x330527){if(_0x330527){logger[_0xcf06('0x21')](_0xcf06('0x3b'),_0x330527[_0xcf06('0x12')],_0xbf85ed);return BPromise[_0xcf06('0x23')](_0x330527);}else{logger[_0xcf06('0x21')]('Enduser\x20with\x20phone\x20%s\x20not\x20found',_0xbf85ed);var _0x392381={'Phone':_0xbf85ed};if(_0x56c54c['moduleCreate']){if(_0x56c54c['moduleCreate']===_0xcf06('0x37')){logger[_0xcf06('0x21')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0xbf85ed,_0x56c54c['moduleCreate']);_0x392381[_0xcf06('0x3c')]=_0x20f862!==_0xcf06('0x3d')?_0x20f862:util[_0xcf06('0x3e')](_0xcf06('0x3f'),_0xbf85ed);}else if(_0x56c54c[_0xcf06('0x40')]===_0xcf06('0x17')){logger[_0xcf06('0x21')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0xbf85ed,_0x56c54c['moduleCreate']);_0x392381[_0xcf06('0x3c')]=_0x20f862!==_0xcf06('0x3d')?_0x20f862:util['format']('Caller\x20-\x20%s',_0xbf85ed);_0x392381['Company']=_0xcf06('0x41');}else if(_0x56c54c['moduleCreate']===_0xcf06('0x14')){logger['info']('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0xbf85ed,_0x56c54c[_0xcf06('0x40')]);_0x392381['Name']=_0x20f862!==_0xcf06('0x3d')?_0x20f862:util[_0xcf06('0x3e')](_0xcf06('0x3f'),_0xbf85ed);}else{return null;}}return _0x35d460[_0xcf06('0x19')](_[_0xcf06('0x42')](_0x56c54c[_0xcf06('0x40')]))[_0xcf06('0x1a')](_0x392381)[_0xcf06('0x1e')](function(_0x56788a){return BPromise['resolve']({'id':_0x56788a['id'],'endUserType':_0x56c54c[_0xcf06('0x40')]});});}});}function getCustomFields(_0x405e72,_0x2ac8a3){var _0x130c83={};if(_0x405e72['length']>0x0){_[_0xcf06('0x43')](_0x405e72,function(_0xb8410b){if(_['includes']([_0xcf06('0x44'),'picklist'],_0xb8410b[_0xcf06('0x45')])&&_0xb8410b[_0xcf06('0x46')]){_0x130c83[_0xb8410b[_0xcf06('0x46')]]=_0xb8410b[_0xcf06('0x47')][_0xcf06('0x48')]();}else if(_0xb8410b[_0xcf06('0x45')]===_0xcf06('0x49')&&_0xb8410b[_0xcf06('0x4a')]&&_0xb8410b['idField']){_0x2ac8a3[_0xb8410b[_0xcf06('0x4a')]]&&(_0x130c83[_0xb8410b[_0xcf06('0x46')]]=_0x2ac8a3[_0xb8410b['variableName']][_0xcf06('0x48')]());}else if(_0xb8410b[_0xcf06('0x45')]===_0xcf06('0x4b')&&_0xb8410b[_0xcf06('0x4c')]&&_0xb8410b['Variable'][_0xcf06('0x4d')]&&_0xb8410b['idField']){_0x2ac8a3[_0xb8410b['Variable'][_0xcf06('0x4d')][_0xcf06('0x4e')]()]&&(_0x130c83[_0xb8410b[_0xcf06('0x46')]]=_0x2ac8a3[_0xb8410b[_0xcf06('0x4c')][_0xcf06('0x4d')][_0xcf06('0x4e')]()][_0xcf06('0x48')]());}});}return _0x130c83;}function getConnection(_0x3b86b6){var _0x4efe9e=_0x3b86b6[_0xcf06('0x4f')][_0xcf06('0x50')](_0x3b86b6[_0xcf06('0x51')]);var _0x528c98=new jsforce[(_0xcf06('0x52'))]({'oauth2':{'loginUrl':_0x3b86b6[_0xcf06('0x53')]||_0xcf06('0x54'),'clientId':_0x3b86b6['clientId'],'clientSecret':_0x3b86b6[_0xcf06('0x55')]}});return _0x528c98[_0xcf06('0x56')](_0x3b86b6[_0xcf06('0x57')],_0x4efe9e)['then'](function(){logger[_0xcf06('0x21')](_0xcf06('0x58'));return _0x528c98;});}exports[_0xcf06('0x59')]=function(_0x5f2e2b,_0x1d41cb,_0x5a3d20,_0x4ab892,_0x177ab1,_0x1e4dd9){var _0x5cc0ec,_0x36f482,_0x590c2e,_0x164be2;_0x1e4dd9[_0xcf06('0x5a')]=intUtil[_0xcf06('0x5b')](_0x1e4dd9[_0xcf06('0x5a')]);_0x1e4dd9[_0xcf06('0x53')]=intUtil[_0xcf06('0x5b')](_0x1e4dd9[_0xcf06('0x53')]);if(_0x177ab1&&_0x177ab1[_0xcf06('0x5c')]){logger['info']('[QUEUE]',_0xcf06('0x5d'));_0x1d41cb[_0xcf06('0x5e')]=util['format'](_0xcf06('0x5f'),_0x1e4dd9['serverUrl'],_0x1d41cb[_0xcf06('0x60')],md5(_0x1d41cb['uniqueid']));}else{_0x1d41cb[_0xcf06('0x5e')]='';}return getConnection(_0x1e4dd9)[_0xcf06('0x1e')](function(_0x2a7321){_0x164be2=_0x2a7321;return getUser(_0x1e4dd9,_0x4ab892['email'],_0x164be2);})[_0xcf06('0x1e')](function(_0xeb1ebd){_0x5cc0ec=_0xeb1ebd;return getEndUser(_0x1e4dd9,_0x5a3d20,_0x1d41cb[_0xcf06('0x61')],_0x1d41cb['calleridnum'],_0x164be2);})[_0xcf06('0x1e')](function(_0x1a8f29){_0x36f482=_0x1a8f29;return getTicket(_0x1e4dd9,_0x5cc0ec,_0x36f482,_0x5a3d20,_0x1d41cb,_0x5a3d20['Fields'],_0x164be2,_0xcf06('0x59'));})['then'](function(_0x11fa8d){_0x590c2e=_0x11fa8d;logger[_0xcf06('0x21')](_0xcf06('0x62'),_0x590c2e['id']);logger[_0xcf06('0x21')]('[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.',_0x590c2e['id'],_0x4ab892['name'],_0x1e4dd9[_0xcf06('0x45')]);switch(_0x1e4dd9[_0xcf06('0x45')]){case _0xcf06('0x63'):emit(util[_0xcf06('0x3e')](_0xcf06('0x64'),_0x4ab892[_0xcf06('0x4d')]),_0xcf06('0x65'),{'recordId':_0x590c2e['id']});break;case _0xcf06('0x66'):emit(util['format'](_0xcf06('0x64'),_0x4ab892['name']),_0xcf06('0x67'),{'uri':util[_0xcf06('0x3e')](_0xcf06('0x68'),_0x164be2['instanceUrl'],_0x590c2e['id'])});break;default:logger['error'](_0xcf06('0x69'));}})[_0xcf06('0x6a')](function(_0x3982df){logger[_0xcf06('0x6b')]('[QUEUE]',_0x3982df);});};exports['outbound']=function(_0x4151ae,_0x464fcd,_0xb9315d,_0x3828eb,_0x5107bc,_0x187631,_0x47bc80){var _0x357b7e,_0x379540,_0x2944d7,_0x2048ed;_0x187631[_0xcf06('0x5a')]=intUtil[_0xcf06('0x5b')](_0x187631[_0xcf06('0x5a')]);_0x187631[_0xcf06('0x53')]=intUtil[_0xcf06('0x5b')](_0x187631['remoteUri']);if(_0x47bc80&&_0x47bc80['recordingFormat']&&_0x47bc80['recordingFormat']!==_0xcf06('0x6c')){logger[_0xcf06('0x21')](_0xcf06('0x6d'),_0xcf06('0x5d'));_0x464fcd['recordingURL']=util['format'](_0xcf06('0x5f'),_0x187631[_0xcf06('0x5a')],_0x464fcd[_0xcf06('0x60')],md5(_0x464fcd[_0xcf06('0x60')]));}return getConnection(_0x187631)['then'](function(_0x14ac20){_0x2048ed=_0x14ac20;return getUser(_0x187631,_0x3828eb[_0xcf06('0x6e')],_0x2048ed);})[_0xcf06('0x1e')](function(_0x2ee97a){_0x357b7e=_0x2ee97a;return getEndUser(_0x187631,_0xb9315d,_0x464fcd[_0xcf06('0x6f')],_0x464fcd['destcalleridnum'],_0x2048ed);})['then'](function(_0x46bbae){_0x379540=_0x46bbae;return getTicket(_0x187631,_0x357b7e,_0x379540,_0xb9315d,_0x464fcd,_0xb9315d[_0xcf06('0x70')],_0x2048ed,_0xcf06('0x71'));})['then'](function(_0x21ec16){_0x2944d7=_0x21ec16;logger[_0xcf06('0x21')](_0xcf06('0x72'),_0x2944d7['id']);logger[_0xcf06('0x21')](_0xcf06('0x73'),_0x2944d7['id'],_0x3828eb['name'],_0x187631[_0xcf06('0x45')]);switch(_0x187631[_0xcf06('0x45')]){case'integrationTab':emit(util[_0xcf06('0x3e')](_0xcf06('0x64'),_0x3828eb['name']),_0xcf06('0x65'),{'recordId':_0x2944d7['id']});break;case _0xcf06('0x66'):emit(util[_0xcf06('0x3e')](_0xcf06('0x64'),_0x3828eb[_0xcf06('0x4d')]),_0xcf06('0x67'),{'uri':util[_0xcf06('0x3e')](_0xcf06('0x68'),_0x2048ed['instanceUrl'],_0x2944d7['id'])});break;default:logger[_0xcf06('0x6b')](_0xcf06('0x6d'),_0xcf06('0x74'));}})[_0xcf06('0x6a')](function(_0x8e0c49){logger[_0xcf06('0x6b')](_0xcf06('0x6d'),_0x8e0c49);});};exports[_0xcf06('0x75')]=function(_0x10d8d3,_0x4fc494,_0x10f640,_0x33d0f0,_0x32378d,_0x39d94f){var _0xade49f,_0xc4144b,_0x5650dd,_0x351e63;_0x39d94f[_0xcf06('0x5a')]=intUtil[_0xcf06('0x5b')](_0x39d94f['serverUrl']);_0x39d94f[_0xcf06('0x53')]=intUtil[_0xcf06('0x5b')](_0x39d94f['remoteUri']);if(_0x32378d&&_0x32378d['monitor_format']){logger['info']('['+_0x4fc494['lastevent'][_0xcf06('0x76')]()+']',_0xcf06('0x5d'));_0x4fc494[_0xcf06('0x5e')]=util[_0xcf06('0x3e')](_0xcf06('0x5f'),_0x39d94f[_0xcf06('0x5a')],_0x4fc494['uniqueid'],md5(_0x4fc494[_0xcf06('0x60')]));}else{_0x4fc494[_0xcf06('0x5e')]='';}return getConnection(_0x39d94f)[_0xcf06('0x1e')](function(_0x43584f){_0x351e63=_0x43584f;if(!_[_0xcf06('0x1b')](_0x33d0f0)){return getUser(_0x39d94f,_0x33d0f0[_0xcf06('0x4d')],_0x351e63);}else{return getUser(_0x39d94f,null,_0x351e63);}})[_0xcf06('0x1e')](function(_0x50b122){_0xade49f=_0x50b122;return getEndUser(_0x39d94f,_0x10f640,_0x4fc494['calleridname'],_0x4fc494['calleridnum'],_0x351e63);})['then'](function(_0x22f444){_0xc4144b=_0x22f444;return getTicket(_0x39d94f,_0xade49f,_0xc4144b,_0x10f640,_0x4fc494,_0x10f640['Fields'],_0x351e63);})[_0xcf06('0x1e')](function(_0x3a2300){_0x5650dd=_0x3a2300;logger[_0xcf06('0x21')]('['+_0x4fc494['lastevent']['toUpperCase']()+_0xcf06('0x77'),_0x5650dd['id']);logger[_0xcf06('0x21')]('['+_0x4fc494[_0xcf06('0x78')][_0xcf06('0x76')]()+']\x20Integration\x20account\x20type\x20%s.',_0x39d94f['type']);})[_0xcf06('0x6a')](function(_0x5638aa){logger[_0xcf06('0x6b')]('['+_0x4fc494[_0xcf06('0x78')]['toUpperCase']()+']',_0x5638aa);});};
\ No newline at end of file