Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / services / ami / trigger / integration / salesforce.js
index 9873c72..04fe689 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x53f0=['moduleCreate','Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.','Company','No\x20Company','upperFirst','forEach','type','idField','content','toString','variable','variableName','customVariable','Variable','toLowerCase','name','password','securityToken','Connection','remoteUri','https://login.salesforce.com','clientId','clientSecret','login','username','Connection\x20established.','serverUrl','stripTrailingSlash','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','email','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','instanceUrl','error','[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.','stringify','recordingFormat','none','[OUTBOUND]','destcalleridnum','outbound','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','trigger:browser:url','%s/%s/e','catch','unmanaged','lastevent','toUpperCase','calleridname',']\x20Integration\x20account\x20type\x20%s.','bluebird','md5','jsforce','ioredis','./util','../../../../config/environment','../../../../config/logger','salesforce','redis','defaults','localhost','socket.io-emitter','emit','ticketType','Task','assign','getString','Subjects','Descriptions','WhoId','ContactId','sobject','isNil','validateEmail','User','find','then','length','info','resolve','Name','identity','display_name','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','user_id','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','contact_lead','Contact','execute','lead','Lead','contact','Phone','Enduser\x20with\x20phone\x20%s\x20not\x20found.','<unknown>','format','Caller\x20-\x20%s'];(function(_0x4fde08,_0x463a36){var _0x12e725=function(_0x2670c5){while(--_0x2670c5){_0x4fde08['push'](_0x4fde08['shift']());}};_0x12e725(++_0x463a36);}(_0x53f0,0x118));var _0x053f=function(_0x19950b,_0x53d0d7){_0x19950b=_0x19950b-0x0;var _0x3c6b41=_0x53f0[_0x19950b];return _0x3c6b41;};'use strict';var _=require('lodash');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x053f('0x0'));var md5=require(_0x053f('0x1'));var jsforce=require(_0x053f('0x2'));var util=require('util');var Redis=require(_0x053f('0x3'));var intUtil=require(_0x053f('0x4'));var config=require(_0x053f('0x5'));var logger=require(_0x053f('0x6'))(_0x053f('0x7'));config[_0x053f('0x8')]=_[_0x053f('0x9')](config[_0x053f('0x8')],{'host':_0x053f('0xa'),'port':0x18eb});var io=require(_0x053f('0xb'))(new Redis(config[_0x053f('0x8')]));function emit(_0x52a238,_0x5e106d,_0x21c46e){io['to'](_0x52a238)[_0x053f('0xc')](_0x5e106d,_0x21c46e);}function getTicket(_0x571620,_0x4d7c49,_0x328a61,_0xb7517f,_0x51fe6a,_0x2c0d92,_0x4087d4,_0x3c0eea){var _0x2243ae={};if(_0xb7517f[_0x053f('0xd')]===_0x053f('0xe')){_0x2243ae=Object[_0x053f('0xf')]({},{'OwnerId':_0x4d7c49['id'],'ActivityDate':moment['utc'](),'IsReminderSet':![],'IsRecurrence':![],'Subject':intUtil[_0x053f('0x10')](_0xb7517f[_0x053f('0x11')],_0x51fe6a,'\x20'),'Description':intUtil['getString'](_0xb7517f[_0x053f('0x12')],_0x51fe6a,'\x0a')},getCustomFields(_0x2c0d92,_0x51fe6a));if(_0x328a61){_0x2243ae[_0x053f('0x13')]=_0x328a61['id'];}}else if(_0xb7517f[_0x053f('0xd')]==='Case'){_0x2243ae=Object['assign']({},{'OwnerId':_0x4d7c49['id'],'Subject':intUtil['getString'](_0xb7517f[_0x053f('0x11')],_0x51fe6a,'\x20'),'Description':intUtil['getString'](_0xb7517f[_0x053f('0x12')],_0x51fe6a,'\x0a')},getCustomFields(_0x2c0d92,_0x51fe6a));if(_0x328a61){_0x2243ae[_0x053f('0x14')]=_0x328a61['id'];}}return _0x4087d4[_0x053f('0x15')](_0xb7517f[_0x053f('0xd')])['create'](_0x2243ae);}function getUser(_0x26f1b4,_0x43061f,_0xf2ad05){if(!_[_0x053f('0x16')](_0x43061f)&&intUtil[_0x053f('0x17')](_0x43061f)){var _0x52cf6d={'Email':_0x43061f};var _0x3601e2={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0xf2ad05['sobject'](_0x053f('0x18'))[_0x053f('0x19')](_0x52cf6d,_0x3601e2)['execute']()[_0x053f('0x1a')](function(_0x12ac2f){if(_0x12ac2f[_0x053f('0x1b')]){var _0x4349b6=_[_0x053f('0x19')](_0x12ac2f,function(_0x8394fe){return _0x8394fe['Email']===_0x43061f;});if(_0x4349b6){logger[_0x053f('0x1c')]('Agent\x20%s\x20found.',_0x43061f);return BPromise[_0x053f('0x1d')]({'id':_0x4349b6['Id'],'name':_0x4349b6[_0x053f('0x1e')]});}}else{logger[_0x053f('0x1c')]('Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.',_0x43061f);return _0xf2ad05[_0x053f('0x1f')]()[_0x053f('0x1a')](function(_0x106604){return BPromise[_0x053f('0x1d')]({'id':_0x106604['user_id'],'name':_0x106604[_0x053f('0x20')]});});}});}else{logger[_0x053f('0x1c')](_0x053f('0x21'),_0x43061f);return _0xf2ad05[_0x053f('0x1f')]()['then'](function(_0x4aa019){return BPromise['resolve']({'id':_0x4aa019[_0x053f('0x22')],'name':_0x4aa019['display_name']});});}}function getEndUser(_0x409408,_0x33c007,_0x496d9d,_0x17c6cc,_0x4b1e81){var _0xf43c9d={'Phone':_0x17c6cc};var _0x1ab280={'Id':!![],'Name':!![],'Phone':!![]};return BPromise['resolve']()[_0x053f('0x1a')](function(){if(_0x33c007[_0x053f('0xd')]===_0x053f('0xe')){logger[_0x053f('0x1c')](_0x053f('0x23'),_0x17c6cc,_0x33c007['moduleSearch']);switch(_0x33c007['moduleSearch']){case _0x053f('0x24'):return _0x4b1e81[_0x053f('0x15')](_0x053f('0x25'))['find'](_0xf43c9d,_0x1ab280)[_0x053f('0x26')]()[_0x053f('0x1a')](function(_0x33346c){if(_0x33346c&&_0x33346c[_0x053f('0x1b')]){return _0x33346c;}else{return _0x4b1e81[_0x053f('0x15')]('Lead')['find'](_0xf43c9d,_0x1ab280);}});case'contact':return _0x4b1e81[_0x053f('0x15')](_0x053f('0x25'))['find'](_0xf43c9d,_0x1ab280)[_0x053f('0x26')]();case _0x053f('0x27'):return _0x4b1e81[_0x053f('0x15')](_0x053f('0x28'))[_0x053f('0x19')](_0xf43c9d,_0x1ab280);default:return null;}}else if(_0x33c007['ticketType']==='Case'){logger[_0x053f('0x1c')](_0x053f('0x23'),_0x17c6cc,_0x053f('0x29'));return _0x4b1e81[_0x053f('0x15')]('Contact')[_0x053f('0x19')](_0xf43c9d,_0x1ab280)[_0x053f('0x26')]();}})['then'](function(_0x3b0aba){if(_0x3b0aba&&_0x3b0aba[_0x053f('0x1b')]){var _0x5b94d4=_[_0x053f('0x19')](_0x3b0aba,function(_0x4c8b91){return _0x4c8b91[_0x053f('0x2a')]===_0x17c6cc;});if(_0x5b94d4){return BPromise[_0x053f('0x1d')]({'id':_0x5b94d4['Id'],'name':_0x5b94d4[_0x053f('0x1e')],'phone':_0x5b94d4['Phone']});}}})[_0x053f('0x1a')](function(_0x167db5){if(_0x167db5){logger[_0x053f('0x1c')]('Enduser\x20with\x20phone\x20%s\x20found.',_0x17c6cc);return BPromise[_0x053f('0x1d')](_0x167db5);}else{logger['info'](_0x053f('0x2b'),_0x17c6cc);var _0x2f430a={'LastName':_0x496d9d!==_0x053f('0x2c')?_0x496d9d:util[_0x053f('0x2d')](_0x053f('0x2e'),_0x17c6cc),'Phone':_0x17c6cc};if(_0x33c007[_0x053f('0x2f')]){if(_0x33c007[_0x053f('0x2f')]===_0x053f('0x29')){logger['info'](_0x053f('0x30'),_0x17c6cc,_0x33c007[_0x053f('0x2f')]);}else if(_0x33c007[_0x053f('0x2f')]===_0x053f('0x27')&&_0x33c007[_0x053f('0xd')]===_0x053f('0xe')){logger[_0x053f('0x1c')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x17c6cc,_0x33c007[_0x053f('0x2f')]);_0x2f430a[_0x053f('0x31')]=_0x053f('0x32');}else{return null;}}return _0x4b1e81[_0x053f('0x15')](_[_0x053f('0x33')](_0x33c007[_0x053f('0x2f')]))['create'](_0x2f430a);}});}function getCustomFields(_0x4da7a4,_0x45137d){var _0x50e82d={};if(_0x4da7a4[_0x053f('0x1b')]>0x0){_[_0x053f('0x34')](_0x4da7a4,function(_0x2ae0c2){if(_0x2ae0c2[_0x053f('0x35')]==='string'&&_0x2ae0c2[_0x053f('0x36')]){_0x50e82d[_0x2ae0c2[_0x053f('0x36')]]=_0x2ae0c2[_0x053f('0x37')][_0x053f('0x38')]();}else if(_0x2ae0c2['type']===_0x053f('0x39')&&_0x2ae0c2[_0x053f('0x3a')]&&_0x2ae0c2['idField']){_0x45137d[_0x2ae0c2[_0x053f('0x3a')]]&&(_0x50e82d[_0x2ae0c2['idField']]=_0x45137d[_0x2ae0c2[_0x053f('0x3a')]][_0x053f('0x38')]());}else if(_0x2ae0c2[_0x053f('0x35')]===_0x053f('0x3b')&&_0x2ae0c2[_0x053f('0x3c')]&&_0x2ae0c2[_0x053f('0x3c')]['name']&&_0x2ae0c2['idField']){_0x45137d[_0x2ae0c2[_0x053f('0x3c')]['name'][_0x053f('0x3d')]()]&&(_0x50e82d[_0x2ae0c2['idField']]=_0x45137d[_0x2ae0c2['Variable'][_0x053f('0x3e')]['toLowerCase']()]['toString']());}});}return _0x50e82d;}function getConnection(_0x3fe43d){var _0x5496c1=_0x3fe43d[_0x053f('0x3f')]['concat'](_0x3fe43d[_0x053f('0x40')]);var _0x2b4423=new jsforce[(_0x053f('0x41'))]({'oauth2':{'loginUrl':_0x3fe43d[_0x053f('0x42')]||_0x053f('0x43'),'clientId':_0x3fe43d[_0x053f('0x44')],'clientSecret':_0x3fe43d[_0x053f('0x45')]}});return _0x2b4423[_0x053f('0x46')](_0x3fe43d[_0x053f('0x47')],_0x5496c1)[_0x053f('0x1a')](function(){logger[_0x053f('0x1c')](_0x053f('0x48'));return _0x2b4423;});}exports['queue']=function(_0x89f2df,_0x392e4b,_0xfa1bad,_0x3ad4d1,_0x2f15b3,_0x178509){var _0x4f874a,_0x361a3d,_0x3f2a33,_0x32e086;_0x178509[_0x053f('0x49')]=intUtil[_0x053f('0x4a')](_0x178509[_0x053f('0x49')]);_0x178509[_0x053f('0x42')]=intUtil[_0x053f('0x4a')](_0x178509[_0x053f('0x42')]);if(_0x2f15b3&&_0x2f15b3[_0x053f('0x4b')]){logger['info'](_0x053f('0x4c'),_0x053f('0x4d'));_0x392e4b[_0x053f('0x4e')]=util[_0x053f('0x2d')](_0x053f('0x4f'),_0x178509[_0x053f('0x49')],_0x392e4b[_0x053f('0x50')],md5(_0x392e4b[_0x053f('0x50')]));}else{_0x392e4b[_0x053f('0x4e')]='';}return getConnection(_0x178509)['then'](function(_0x131707){_0x32e086=_0x131707;return getUser(_0x178509,_0x3ad4d1[_0x053f('0x51')],_0x32e086);})[_0x053f('0x1a')](function(_0x2cc53c){_0x4f874a=_0x2cc53c;return getEndUser(_0x178509,_0xfa1bad,_0x392e4b['calleridname'],_0x392e4b[_0x053f('0x52')],_0x32e086);})['then'](function(_0x3b116a){_0x361a3d=_0x3b116a;return getTicket(_0x178509,_0x4f874a,_0x361a3d,_0xfa1bad,_0x392e4b,_0xfa1bad[_0x053f('0x53')],_0x32e086,'queue');})[_0x053f('0x1a')](function(_0x23d6bb){_0x3f2a33=_0x23d6bb;logger['info'](_0x053f('0x54'),_0x3f2a33['id']);logger['info'](_0x053f('0x55'),_0x3f2a33['id'],_0x3ad4d1[_0x053f('0x3e')],_0x178509['type']);switch(_0x178509['type']){case _0x053f('0x56'):emit(util[_0x053f('0x2d')](_0x053f('0x57'),_0x3ad4d1['name']),_0x053f('0x58'),{'recordId':_0x3f2a33['id']});break;case _0x053f('0x59'):emit(util['format']('user:%s',_0x3ad4d1['name']),'trigger:browser:url',{'uri':util[_0x053f('0x2d')]('%s/%s/e',_0x32e086[_0x053f('0x5a')],_0x3f2a33['id'])});break;default:logger[_0x053f('0x5b')](_0x053f('0x5c'));}})['catch'](function(_0x937617){logger[_0x053f('0x5b')](_0x053f('0x4c'),JSON[_0x053f('0x5d')](_0x937617));});};exports['outbound']=function(_0x42cc15,_0x494786,_0x9025bc,_0x545d0c,_0x42c888,_0xd3d9a2,_0x2a96dd){var _0x5f4d1d,_0x5969e1,_0x4e1667,_0x4b5289;_0xd3d9a2['serverUrl']=intUtil[_0x053f('0x4a')](_0xd3d9a2[_0x053f('0x49')]);_0xd3d9a2[_0x053f('0x42')]=intUtil['stripTrailingSlash'](_0xd3d9a2['remoteUri']);if(_0x2a96dd&&_0x2a96dd[_0x053f('0x5e')]&&_0x2a96dd[_0x053f('0x5e')]!==_0x053f('0x5f')){logger[_0x053f('0x1c')](_0x053f('0x60'),'Recording\x20is\x20enabled!');_0x494786['recordingURL']=util[_0x053f('0x2d')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0xd3d9a2[_0x053f('0x49')],_0x494786[_0x053f('0x50')],md5(_0x494786[_0x053f('0x50')]));}return getConnection(_0xd3d9a2)[_0x053f('0x1a')](function(_0x371649){_0x4b5289=_0x371649;return getUser(_0xd3d9a2,_0x545d0c[_0x053f('0x51')],_0x4b5289);})[_0x053f('0x1a')](function(_0x35ceeb){_0x5f4d1d=_0x35ceeb;return getEndUser(_0xd3d9a2,_0x9025bc,_0x494786['destcalleridname'],_0x494786[_0x053f('0x61')],_0x4b5289);})[_0x053f('0x1a')](function(_0x83ab5a){_0x5969e1=_0x83ab5a;return getTicket(_0xd3d9a2,_0x5f4d1d,_0x5969e1,_0x9025bc,_0x494786,_0x9025bc[_0x053f('0x53')],_0x4b5289,_0x053f('0x62'));})[_0x053f('0x1a')](function(_0x3ed677){_0x4e1667=_0x3ed677;logger[_0x053f('0x1c')](_0x053f('0x63'),_0x4e1667['id']);logger[_0x053f('0x1c')](_0x053f('0x64'),_0x4e1667['id'],_0x545d0c[_0x053f('0x3e')],_0xd3d9a2[_0x053f('0x35')]);switch(_0xd3d9a2['type']){case'integrationTab':emit(util[_0x053f('0x2d')]('user:%s',_0x545d0c[_0x053f('0x3e')]),'trigger:salesforce:display',{'recordId':_0x4e1667['id']});break;case'newTab':emit(util[_0x053f('0x2d')](_0x053f('0x57'),_0x545d0c[_0x053f('0x3e')]),_0x053f('0x65'),{'uri':util['format'](_0x053f('0x66'),_0x4b5289[_0x053f('0x5a')],_0x4e1667['id'])});break;default:logger[_0x053f('0x5b')]('[OUTBOUND]','Salesforce\x20account\x20type\x20not\x20recognized');}})[_0x053f('0x67')](function(_0x48c911){logger[_0x053f('0x5b')](_0x053f('0x60'),JSON['stringify'](_0x48c911));});};exports[_0x053f('0x68')]=function(_0x7c2c4,_0x1f3aec,_0xe24086,_0x5113e2,_0x3819a9,_0x9445f6){var _0x5aa9ec,_0xd0f7f3,_0x3d64c1,_0x58047e;_0x9445f6[_0x053f('0x49')]=intUtil[_0x053f('0x4a')](_0x9445f6[_0x053f('0x49')]);_0x9445f6[_0x053f('0x42')]=intUtil[_0x053f('0x4a')](_0x9445f6[_0x053f('0x42')]);if(_0x3819a9&&_0x3819a9[_0x053f('0x4b')]){logger[_0x053f('0x1c')]('['+_0x1f3aec[_0x053f('0x69')][_0x053f('0x6a')]()+']',_0x053f('0x4d'));_0x1f3aec['recordingURL']=util[_0x053f('0x2d')](_0x053f('0x4f'),_0x9445f6[_0x053f('0x49')],_0x1f3aec[_0x053f('0x50')],md5(_0x1f3aec[_0x053f('0x50')]));}else{_0x1f3aec[_0x053f('0x4e')]='';}return getConnection(_0x9445f6)[_0x053f('0x1a')](function(_0x491c0f){_0x58047e=_0x491c0f;if(!_[_0x053f('0x16')](_0x5113e2)){return getUser(_0x9445f6,_0x5113e2[_0x053f('0x3e')],_0x58047e);}else{return getUser(_0x9445f6,null,_0x58047e);}})['then'](function(_0x26a860){_0x5aa9ec=_0x26a860;return getEndUser(_0x9445f6,_0xe24086,_0x1f3aec[_0x053f('0x6b')],_0x1f3aec[_0x053f('0x52')],_0x58047e);})[_0x053f('0x1a')](function(_0x2be645){_0xd0f7f3=_0x2be645;return getTicket(_0x9445f6,_0x5aa9ec,_0xd0f7f3,_0xe24086,_0x1f3aec,_0xe24086[_0x053f('0x53')],_0x58047e);})[_0x053f('0x1a')](function(_0x40a114){_0x3d64c1=_0x40a114;logger[_0x053f('0x1c')]('['+_0x1f3aec['lastevent'][_0x053f('0x6a')]()+']\x20Ticket\x20%s\x20created.',_0x3d64c1['id']);logger[_0x053f('0x1c')]('['+_0x1f3aec['lastevent'][_0x053f('0x6a')]()+_0x053f('0x6c'),_0x9445f6[_0x053f('0x35')]);})[_0x053f('0x67')](function(_0x4191c7){logger[_0x053f('0x5b')]('['+_0x1f3aec[_0x053f('0x69')]['toUpperCase']()+']',JSON['stringify'](_0x4191c7));});};
\ No newline at end of file
+var _0x5ba6=['name','password','concat','remoteUri','https://login.salesforce.com','clientId','clientSecret','login','username','Connection\x20established.','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','uniqueid','recordingURL','email','calleridnum','[QUEUE]\x20Ticket\x20%s\x20created','integrationTab','user:%s','trigger:salesforce:display','newTab','[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.','catch','recordingFormat','[OUTBOUND]','destcalleridname','destcalleridnum','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','trigger:browser:url','%s/%s/e','instanceUrl','error','Salesforce\x20account\x20type\x20not\x20recognized','unmanaged','lastevent','toUpperCase','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','calleridname','Fields',']\x20Ticket\x20%s\x20created.','lodash','moment','bluebird','util','ioredis','redis','defaults','socket.io-emitter','emit','assign','getString','Subjects','Descriptions','ticketType','Task','ActivityDate','utc','IsReminderSet','IsRecurrence','contact','lead','WhoId','endUserType','account','Case','ContactId','AccountId','leadId','Association\x20between\x20Case\x20and\x20Lead\x20skipped','sobject','create','isNil','User','find','execute','then','length','Name','Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.','resolve','info','identity','user_id','display_name','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','moduleSearch','contact_lead','additionalSearchContact','merge','$or','Contact','additionalSearchLead','Lead','account_contact_lead','cloneDeep','additionalSearchAccount','Account','Phone','attributes','type','toLowerCase','Enduser\x20with\x20phone\x20%s\x20not\x20found','moduleCreate','<unknown>','Caller\x20-\x20%s','LastName','Company','No\x20Company','Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.','format','forEach','includes','string','idField','content','toString','variable','variableName','customVariable','Variable'];(function(_0xef8146,_0x459c34){var _0x5a6cb0=function(_0x2f84ec){while(--_0x2f84ec){_0xef8146['push'](_0xef8146['shift']());}};_0x5a6cb0(++_0x459c34);}(_0x5ba6,0x1a4));var _0x65ba=function(_0x310382,_0x501b76){_0x310382=_0x310382-0x0;var _0x354f3d=_0x5ba6[_0x310382];return _0x354f3d;};'use strict';var _=require(_0x65ba('0x0'));var rp=require('request-promise');var moment=require(_0x65ba('0x1'));var BPromise=require(_0x65ba('0x2'));var md5=require('md5');var jsforce=require('jsforce');var util=require(_0x65ba('0x3'));var Redis=require(_0x65ba('0x4'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require('../../../../config/logger')('salesforce');config[_0x65ba('0x5')]=_[_0x65ba('0x6')](config[_0x65ba('0x5')],{'host':'localhost','port':0x18eb});var io=require(_0x65ba('0x7'))(new Redis(config[_0x65ba('0x5')]));function emit(_0x1d6599,_0x239902,_0xb4f580){io['to'](_0x1d6599)[_0x65ba('0x8')](_0x239902,_0xb4f580);}function getTicket(_0x40c19d,_0x4a3968,_0x26fc48,_0x67e020,_0x3e530b,_0xc9fcf9,_0x4cdacf,_0x5cb1ba){var _0xa08cc3=Object[_0x65ba('0x9')]({},{'OwnerId':_0x4a3968['id'],'Subject':intUtil[_0x65ba('0xa')](_0x67e020[_0x65ba('0xb')],_0x3e530b,'\x20'),'Description':intUtil[_0x65ba('0xa')](_0x67e020[_0x65ba('0xc')],_0x3e530b,'\x0a')},getCustomFields(_0xc9fcf9,_0x3e530b));if(_0x26fc48){if(_0x67e020[_0x65ba('0xd')]===_0x65ba('0xe')){_0xa08cc3[_0x65ba('0xf')]=moment[_0x65ba('0x10')]();_0xa08cc3[_0x65ba('0x11')]=![];_0xa08cc3[_0x65ba('0x12')]=![];if(_0x26fc48['endUserType']===_0x65ba('0x13')||_0x26fc48['endUserType']===_0x65ba('0x14')){_0xa08cc3[_0x65ba('0x15')]=_0x26fc48['id'];}else if(_0x26fc48[_0x65ba('0x16')]===_0x65ba('0x17')){_0xa08cc3['WhatId']=_0x26fc48['id'];}}else if(_0x67e020[_0x65ba('0xd')]===_0x65ba('0x18')){if(_0x26fc48[_0x65ba('0x16')]===_0x65ba('0x13')){_0xa08cc3[_0x65ba('0x19')]=_0x26fc48['id'];}else if(_0x26fc48[_0x65ba('0x16')]==='account'){_0xa08cc3[_0x65ba('0x1a')]=_0x26fc48['id'];}else if(_0x26fc48['endUserType']===_0x65ba('0x14')&&_0x67e020[_0x65ba('0x1b')]){_0xa08cc3[_0x67e020['leadId']]=_0x26fc48['id'];}else{logger['info'](_0x65ba('0x1c'));}}}return _0x4cdacf[_0x65ba('0x1d')](_0x67e020[_0x65ba('0xd')])[_0x65ba('0x1e')](_0xa08cc3);}function getUser(_0x4c791c,_0x4f6abd,_0x20e48e){if(!_[_0x65ba('0x1f')](_0x4f6abd)&&intUtil['validateEmail'](_0x4f6abd)){var _0x2fa214={'Email':_0x4f6abd};var _0x2a7007={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x20e48e[_0x65ba('0x1d')](_0x65ba('0x20'))[_0x65ba('0x21')](_0x2fa214,_0x2a7007)[_0x65ba('0x22')]()[_0x65ba('0x23')](function(_0x55f240){if(_0x55f240[_0x65ba('0x24')]){var _0x2e0048=_[_0x65ba('0x21')](_0x55f240,function(_0x2eab8c){return _0x2eab8c['Email']===_0x4f6abd;});if(_0x2e0048){logger['info']('Agent\x20%s\x20found.',_0x4f6abd);return BPromise['resolve']({'id':_0x2e0048['Id'],'name':_0x2e0048[_0x65ba('0x25')]});}}else{logger['info'](_0x65ba('0x26'),_0x4f6abd);return _0x20e48e['identity']()['then'](function(_0x189da6){return BPromise[_0x65ba('0x27')]({'id':_0x189da6['user_id'],'name':_0x189da6['display_name']});});}});}else{logger[_0x65ba('0x28')](_0x65ba('0x26'),_0x4f6abd);return _0x20e48e[_0x65ba('0x29')]()[_0x65ba('0x23')](function(_0x518c12){return BPromise[_0x65ba('0x27')]({'id':_0x518c12[_0x65ba('0x2a')],'name':_0x518c12[_0x65ba('0x2b')]});});}}function getEndUser(_0xb9ec3b,_0x1c641a,_0x362db3,_0x1eca33,_0x335637){var _0x440610={'$or':{'Phone':_0x1eca33}};var _0x1eda0b={'Id':!![],'Name':!![],'Phone':!![]};return BPromise['resolve']()[_0x65ba('0x23')](function(){logger['info'](_0x65ba('0x2c'),_0x1eca33,_0x1c641a[_0x65ba('0x2d')]);switch(_0x1c641a['moduleSearch']){case _0x65ba('0x2e'):var _0x35a5ea=_['cloneDeep'](_0x440610);if(_0x1c641a[_0x65ba('0x2f')]){var _0x55da2a={};_0x55da2a[_0x1c641a[_0x65ba('0x2f')]]=_0x1eca33;_[_0x65ba('0x30')](_0x35a5ea[_0x65ba('0x31')],_0x55da2a);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x32'))['find'](_0x35a5ea,_0x1eda0b)[_0x65ba('0x22')]()[_0x65ba('0x23')](function(_0x8d336e){if(_0x8d336e&&_0x8d336e['length']){return _0x8d336e;}else{var _0x51cae9=_['cloneDeep'](_0x440610);if(_0x1c641a[_0x65ba('0x33')]){var _0x55a551={};_0x55a551[_0x1c641a[_0x65ba('0x33')]]=_0x1eca33;_[_0x65ba('0x30')](_0x51cae9[_0x65ba('0x31')],_0x55a551);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x34'))['find'](_0x51cae9,_0x1eda0b);}});case _0x65ba('0x35'):var _0xf846f5=_[_0x65ba('0x36')](_0x440610);if(_0x1c641a[_0x65ba('0x37')]){var _0x55da2a={};_0x55da2a[_0x1c641a['additionalSearchAccount']]=_0x1eca33;_[_0x65ba('0x30')](_0xf846f5['$or'],_0x55da2a);}return _0x335637['sobject']('Account')[_0x65ba('0x21')](_0xf846f5,_0x1eda0b)[_0x65ba('0x22')]()[_0x65ba('0x23')](function(_0x15d0ac){if(_0x15d0ac&&_0x15d0ac['length']){return _0x15d0ac;}else{var _0x51d8e3=_[_0x65ba('0x36')](_0x440610);if(_0x1c641a[_0x65ba('0x2f')]){var _0x295b17={};_0x295b17[_0x1c641a[_0x65ba('0x2f')]]=_0x1eca33;_[_0x65ba('0x30')](_0x51d8e3['$or'],_0x295b17);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x32'))[_0x65ba('0x21')](_0x51d8e3,_0x1eda0b)[_0x65ba('0x23')](function(_0x40af42){if(_0x40af42&&_0x40af42[_0x65ba('0x24')]){return _0x40af42;}else{var _0x1c5935=_['cloneDeep'](_0x440610);if(_0x1c641a[_0x65ba('0x33')]){var _0x5af25d={};_0x5af25d[_0x1c641a[_0x65ba('0x33')]]=_0x1eca33;_['merge'](_0x1c5935[_0x65ba('0x31')],_0x5af25d);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x34'))[_0x65ba('0x21')](_0x1c5935,_0x1eda0b);}});}});case _0x65ba('0x13'):var _0x35a5ea=_[_0x65ba('0x36')](_0x440610);if(_0x1c641a[_0x65ba('0x2f')]){var _0x55da2a={};_0x55da2a[_0x1c641a[_0x65ba('0x2f')]]=_0x1eca33;_[_0x65ba('0x30')](_0x35a5ea[_0x65ba('0x31')],_0x55da2a);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x32'))[_0x65ba('0x21')](_0x35a5ea,_0x1eda0b)[_0x65ba('0x22')]();case _0x65ba('0x14'):var _0x15863e=_[_0x65ba('0x36')](_0x440610);if(_0x1c641a[_0x65ba('0x33')]){var _0x55da2a={};_0x55da2a[_0x1c641a['additionalSearchLead']]=_0x1eca33;_[_0x65ba('0x30')](_0x15863e[_0x65ba('0x31')],_0x55da2a);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x34'))[_0x65ba('0x21')](_0x15863e,_0x1eda0b);case _0x65ba('0x17'):var _0xf846f5=_[_0x65ba('0x36')](_0x440610);if(_0x1c641a['additionalSearchAccount']){var _0x55da2a={};_0x55da2a[_0x1c641a['additionalSearchAccount']]=_0x1eca33;_['merge'](_0xf846f5[_0x65ba('0x31')],_0x55da2a);}return _0x335637[_0x65ba('0x1d')](_0x65ba('0x38'))['find'](_0xf846f5,_0x1eda0b);default:return null;}})[_0x65ba('0x23')](function(_0x1be641){if(_0x1be641&&_0x1be641[_0x65ba('0x24')]){var _0x3f6184=_['first'](_0x1be641);if(_0x3f6184){return BPromise[_0x65ba('0x27')]({'id':_0x3f6184['Id'],'name':_0x3f6184[_0x65ba('0x25')],'phone':_0x3f6184[_0x65ba('0x39')],'endUserType':_0x3f6184[_0x65ba('0x3a')][_0x65ba('0x3b')][_0x65ba('0x3c')]()});}}})['then'](function(_0x435bfc){if(_0x435bfc){logger[_0x65ba('0x28')]('Enduser\x20(%s)\x20with\x20phone\x20%s\x20found',_0x435bfc[_0x65ba('0x16')],_0x1eca33);return BPromise[_0x65ba('0x27')](_0x435bfc);}else{logger[_0x65ba('0x28')](_0x65ba('0x3d'),_0x1eca33);var _0xa9c4fe={'Phone':_0x1eca33};if(_0x1c641a[_0x65ba('0x3e')]){if(_0x1c641a[_0x65ba('0x3e')]===_0x65ba('0x13')){logger[_0x65ba('0x28')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x1eca33,_0x1c641a[_0x65ba('0x3e')]);_0xa9c4fe['LastName']=_0x362db3!==_0x65ba('0x3f')?_0x362db3:util['format'](_0x65ba('0x40'),_0x1eca33);}else if(_0x1c641a[_0x65ba('0x3e')]===_0x65ba('0x14')){logger[_0x65ba('0x28')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x1eca33,_0x1c641a[_0x65ba('0x3e')]);_0xa9c4fe[_0x65ba('0x41')]=_0x362db3!==_0x65ba('0x3f')?_0x362db3:util['format'](_0x65ba('0x40'),_0x1eca33);_0xa9c4fe[_0x65ba('0x42')]=_0x65ba('0x43');}else if(_0x1c641a['moduleCreate']===_0x65ba('0x17')){logger[_0x65ba('0x28')](_0x65ba('0x44'),_0x1eca33,_0x1c641a[_0x65ba('0x3e')]);_0xa9c4fe[_0x65ba('0x25')]=_0x362db3!==_0x65ba('0x3f')?_0x362db3:util[_0x65ba('0x45')]('Caller\x20-\x20%s',_0x1eca33);}else{return null;}}return _0x335637[_0x65ba('0x1d')](_['upperFirst'](_0x1c641a[_0x65ba('0x3e')]))['create'](_0xa9c4fe)[_0x65ba('0x23')](function(_0x562a27){return BPromise[_0x65ba('0x27')]({'id':_0x562a27['id'],'endUserType':_0x1c641a[_0x65ba('0x3e')]});});}});}function getCustomFields(_0x5a85d4,_0x2d1d56){var _0x216058={};if(_0x5a85d4[_0x65ba('0x24')]>0x0){_[_0x65ba('0x46')](_0x5a85d4,function(_0x1e3242){if(_[_0x65ba('0x47')]([_0x65ba('0x48'),'picklist'],_0x1e3242[_0x65ba('0x3b')])&&_0x1e3242['idField']){_0x216058[_0x1e3242[_0x65ba('0x49')]]=_0x1e3242[_0x65ba('0x4a')][_0x65ba('0x4b')]();}else if(_0x1e3242[_0x65ba('0x3b')]===_0x65ba('0x4c')&&_0x1e3242[_0x65ba('0x4d')]&&_0x1e3242[_0x65ba('0x49')]){_0x2d1d56[_0x1e3242[_0x65ba('0x4d')]]&&(_0x216058[_0x1e3242[_0x65ba('0x49')]]=_0x2d1d56[_0x1e3242[_0x65ba('0x4d')]][_0x65ba('0x4b')]());}else if(_0x1e3242['type']===_0x65ba('0x4e')&&_0x1e3242[_0x65ba('0x4f')]&&_0x1e3242[_0x65ba('0x4f')][_0x65ba('0x50')]&&_0x1e3242[_0x65ba('0x49')]){_0x2d1d56[_0x1e3242['Variable'][_0x65ba('0x50')][_0x65ba('0x3c')]()]&&(_0x216058[_0x1e3242[_0x65ba('0x49')]]=_0x2d1d56[_0x1e3242[_0x65ba('0x4f')][_0x65ba('0x50')][_0x65ba('0x3c')]()]['toString']());}});}return _0x216058;}function getConnection(_0x531ab9){var _0x5268c8=_0x531ab9[_0x65ba('0x51')][_0x65ba('0x52')](_0x531ab9['securityToken']);var _0x179ca5=new jsforce['Connection']({'oauth2':{'loginUrl':_0x531ab9[_0x65ba('0x53')]||_0x65ba('0x54'),'clientId':_0x531ab9[_0x65ba('0x55')],'clientSecret':_0x531ab9[_0x65ba('0x56')]}});return _0x179ca5[_0x65ba('0x57')](_0x531ab9[_0x65ba('0x58')],_0x5268c8)[_0x65ba('0x23')](function(){logger[_0x65ba('0x28')](_0x65ba('0x59'));return _0x179ca5;});}exports[_0x65ba('0x5a')]=function(_0x584012,_0x1b2dbf,_0x1ecf8c,_0x1e86fe,_0x505448,_0x2ea63f){var _0x44983d,_0x198e8a,_0x2ff133,_0x4a78f1;_0x2ea63f['serverUrl']=intUtil[_0x65ba('0x5b')](_0x2ea63f[_0x65ba('0x5c')]);_0x2ea63f[_0x65ba('0x53')]=intUtil[_0x65ba('0x5b')](_0x2ea63f[_0x65ba('0x53')]);if(_0x505448&&_0x505448[_0x65ba('0x5d')]){logger['info'](_0x65ba('0x5e'),_0x65ba('0x5f'));_0x1b2dbf['recordingURL']=util[_0x65ba('0x45')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2ea63f[_0x65ba('0x5c')],_0x1b2dbf['uniqueid'],md5(_0x1b2dbf[_0x65ba('0x60')]));}else{_0x1b2dbf[_0x65ba('0x61')]='';}return getConnection(_0x2ea63f)[_0x65ba('0x23')](function(_0x3f7b18){_0x4a78f1=_0x3f7b18;return getUser(_0x2ea63f,_0x1e86fe[_0x65ba('0x62')],_0x4a78f1);})[_0x65ba('0x23')](function(_0x299ace){_0x44983d=_0x299ace;return getEndUser(_0x2ea63f,_0x1ecf8c,_0x1b2dbf['calleridname'],_0x1b2dbf[_0x65ba('0x63')],_0x4a78f1);})[_0x65ba('0x23')](function(_0x39aef5){_0x198e8a=_0x39aef5;return getTicket(_0x2ea63f,_0x44983d,_0x198e8a,_0x1ecf8c,_0x1b2dbf,_0x1ecf8c['Fields'],_0x4a78f1,'queue');})[_0x65ba('0x23')](function(_0x403d29){_0x2ff133=_0x403d29;logger[_0x65ba('0x28')](_0x65ba('0x64'),_0x2ff133['id']);logger[_0x65ba('0x28')]('[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.',_0x2ff133['id'],_0x1e86fe[_0x65ba('0x50')],_0x2ea63f[_0x65ba('0x3b')]);switch(_0x2ea63f[_0x65ba('0x3b')]){case _0x65ba('0x65'):emit(util[_0x65ba('0x45')](_0x65ba('0x66'),_0x1e86fe['name']),_0x65ba('0x67'),{'recordId':_0x2ff133['id']});break;case _0x65ba('0x68'):emit(util[_0x65ba('0x45')](_0x65ba('0x66'),_0x1e86fe['name']),'trigger:browser:url',{'uri':util[_0x65ba('0x45')]('%s/%s/e',_0x4a78f1['instanceUrl'],_0x2ff133['id'])});break;default:logger['error'](_0x65ba('0x69'));}})[_0x65ba('0x6a')](function(_0x5a7f28){logger['error']('[QUEUE]',_0x5a7f28);});};exports['outbound']=function(_0xcbfa69,_0x52b8fa,_0x287c60,_0x2e99a2,_0xf20e2e,_0x329b2c,_0x3c46f3){var _0x2966cf,_0x58975b,_0xa29ecd,_0x1199c2;_0x329b2c[_0x65ba('0x5c')]=intUtil['stripTrailingSlash'](_0x329b2c['serverUrl']);_0x329b2c['remoteUri']=intUtil[_0x65ba('0x5b')](_0x329b2c['remoteUri']);if(_0x3c46f3&&_0x3c46f3[_0x65ba('0x6b')]&&_0x3c46f3['recordingFormat']!=='none'){logger[_0x65ba('0x28')](_0x65ba('0x6c'),_0x65ba('0x5f'));_0x52b8fa['recordingURL']=util[_0x65ba('0x45')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x329b2c[_0x65ba('0x5c')],_0x52b8fa[_0x65ba('0x60')],md5(_0x52b8fa['uniqueid']));}return getConnection(_0x329b2c)[_0x65ba('0x23')](function(_0x3906dd){_0x1199c2=_0x3906dd;return getUser(_0x329b2c,_0x2e99a2[_0x65ba('0x62')],_0x1199c2);})['then'](function(_0x374f05){_0x2966cf=_0x374f05;return getEndUser(_0x329b2c,_0x287c60,_0x52b8fa[_0x65ba('0x6d')],_0x52b8fa[_0x65ba('0x6e')],_0x1199c2);})[_0x65ba('0x23')](function(_0x267ef3){_0x58975b=_0x267ef3;return getTicket(_0x329b2c,_0x2966cf,_0x58975b,_0x287c60,_0x52b8fa,_0x287c60['Fields'],_0x1199c2,'outbound');})[_0x65ba('0x23')](function(_0x1b2821){_0xa29ecd=_0x1b2821;logger[_0x65ba('0x28')](_0x65ba('0x6f'),_0xa29ecd['id']);logger['info'](_0x65ba('0x70'),_0xa29ecd['id'],_0x2e99a2[_0x65ba('0x50')],_0x329b2c[_0x65ba('0x3b')]);switch(_0x329b2c['type']){case _0x65ba('0x65'):emit(util['format'](_0x65ba('0x66'),_0x2e99a2[_0x65ba('0x50')]),'trigger:salesforce:display',{'recordId':_0xa29ecd['id']});break;case _0x65ba('0x68'):emit(util[_0x65ba('0x45')](_0x65ba('0x66'),_0x2e99a2[_0x65ba('0x50')]),_0x65ba('0x71'),{'uri':util[_0x65ba('0x45')](_0x65ba('0x72'),_0x1199c2[_0x65ba('0x73')],_0xa29ecd['id'])});break;default:logger[_0x65ba('0x74')](_0x65ba('0x6c'),_0x65ba('0x75'));}})[_0x65ba('0x6a')](function(_0x50d2ae){logger[_0x65ba('0x74')](_0x65ba('0x6c'),_0x50d2ae);});};exports[_0x65ba('0x76')]=function(_0x541d08,_0x18ae9f,_0x249eda,_0x327cc8,_0x56ac46,_0x19664f){var _0xf84024,_0x3154fb,_0x58cf9c,_0x401c8c;_0x19664f['serverUrl']=intUtil[_0x65ba('0x5b')](_0x19664f['serverUrl']);_0x19664f[_0x65ba('0x53')]=intUtil[_0x65ba('0x5b')](_0x19664f[_0x65ba('0x53')]);if(_0x56ac46&&_0x56ac46[_0x65ba('0x5d')]){logger[_0x65ba('0x28')]('['+_0x18ae9f[_0x65ba('0x77')][_0x65ba('0x78')]()+']',_0x65ba('0x5f'));_0x18ae9f[_0x65ba('0x61')]=util[_0x65ba('0x45')](_0x65ba('0x79'),_0x19664f[_0x65ba('0x5c')],_0x18ae9f[_0x65ba('0x60')],md5(_0x18ae9f[_0x65ba('0x60')]));}else{_0x18ae9f[_0x65ba('0x61')]='';}return getConnection(_0x19664f)[_0x65ba('0x23')](function(_0x351ec9){_0x401c8c=_0x351ec9;if(!_[_0x65ba('0x1f')](_0x327cc8)){return getUser(_0x19664f,_0x327cc8[_0x65ba('0x50')],_0x401c8c);}else{return getUser(_0x19664f,null,_0x401c8c);}})[_0x65ba('0x23')](function(_0x38a80f){_0xf84024=_0x38a80f;return getEndUser(_0x19664f,_0x249eda,_0x18ae9f[_0x65ba('0x7a')],_0x18ae9f[_0x65ba('0x63')],_0x401c8c);})[_0x65ba('0x23')](function(_0x727fdc){_0x3154fb=_0x727fdc;return getTicket(_0x19664f,_0xf84024,_0x3154fb,_0x249eda,_0x18ae9f,_0x249eda[_0x65ba('0x7b')],_0x401c8c);})['then'](function(_0x57a40f){_0x58cf9c=_0x57a40f;logger[_0x65ba('0x28')]('['+_0x18ae9f['lastevent'][_0x65ba('0x78')]()+_0x65ba('0x7c'),_0x58cf9c['id']);logger[_0x65ba('0x28')]('['+_0x18ae9f[_0x65ba('0x77')][_0x65ba('0x78')]()+']\x20Integration\x20account\x20type\x20%s.',_0x19664f[_0x65ba('0x3b')]);})[_0x65ba('0x6a')](function(_0x58299d){logger['error']('['+_0x18ae9f['lastevent'][_0x65ba('0x78')]()+']',_0x58299d);});};
\ No newline at end of file