Built motion from commit (unavailable).|2.5.22
[motion2.git] / server / services / ami / trigger / integration / salesforce.js
index 9873c72..f85db2b 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 _0x7c5f=['request-promise','moment','bluebird','md5','util','ioredis','./util','../../../../config/environment','salesforce','defaults','redis','localhost','socket.io-emitter','Task','assign','utc','getString','WhoId','ticketType','Case','Subjects','ContactId','sobject','create','isNil','validateEmail','find','execute','length','Email','info','Agent\x20%s\x20found.','resolve','Name','identity','then','user_id','display_name','Searching\x20enduser\x20with\x20phone\x20%s.\x20Serching\x20method\x20used\x20%s.','moduleSearch','contact_lead','Contact','Lead','lead','contact','Phone','Enduser\x20with\x20phone\x20%s\x20found.','<unknown>','format','Caller\x20-\x20%s','moduleCreate','Company','No\x20Company','forEach','type','string','idField','content','toString','variable','variableName','customVariable','Variable','name','toLowerCase','password','concat','securityToken','remoteUri','https://login.salesforce.com','clientId','clientSecret','serverUrl','stripTrailingSlash','[QUEUE]','recordingURL','email','calleridname','Fields','queue','user:%s','newTab','trigger:browser:url','%s/%s/e','error','stringify','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','destcalleridnum','[OUTBOUND]\x20Ticket\x20%s\x20created.','[OUTBOUND]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.','integrationTab','trigger:salesforce:display','instanceUrl','catch','unmanaged','monitor_format','lastevent','toUpperCase','calleridnum',']\x20Ticket\x20%s\x20created.',']\x20Integration\x20account\x20type\x20%s.'];(function(_0x24061a,_0x1c9f4d){var _0x82054e=function(_0x2ec346){while(--_0x2ec346){_0x24061a['push'](_0x24061a['shift']());}};_0x82054e(++_0x1c9f4d);}(_0x7c5f,0x6a));var _0xf7c5=function(_0x372b49,_0x108788){_0x372b49=_0x372b49-0x0;var _0x4f1d48=_0x7c5f[_0x372b49];return _0x4f1d48;};'use strict';var _=require('lodash');var rp=require(_0xf7c5('0x0'));var moment=require(_0xf7c5('0x1'));var BPromise=require(_0xf7c5('0x2'));var md5=require(_0xf7c5('0x3'));var jsforce=require('jsforce');var util=require(_0xf7c5('0x4'));var Redis=require(_0xf7c5('0x5'));var intUtil=require(_0xf7c5('0x6'));var config=require(_0xf7c5('0x7'));var logger=require('../../../../config/logger')(_0xf7c5('0x8'));config['redis']=_[_0xf7c5('0x9')](config[_0xf7c5('0xa')],{'host':_0xf7c5('0xb'),'port':0x18eb});var io=require(_0xf7c5('0xc'))(new Redis(config[_0xf7c5('0xa')]));function emit(_0x390be0,_0xf9625f,_0x14e746){io['to'](_0x390be0)['emit'](_0xf9625f,_0x14e746);}function getTicket(_0x55cce2,_0x3f7ba9,_0x1d1f4d,_0x2aa29a,_0xba9263,_0x364104,_0x1770cb,_0x3c879b){var _0x4235d0={};if(_0x2aa29a['ticketType']===_0xf7c5('0xd')){_0x4235d0=Object[_0xf7c5('0xe')]({},{'OwnerId':_0x3f7ba9['id'],'ActivityDate':moment[_0xf7c5('0xf')](),'IsReminderSet':![],'IsRecurrence':![],'Subject':intUtil[_0xf7c5('0x10')](_0x2aa29a['Subjects'],_0xba9263,'\x20'),'Description':intUtil['getString'](_0x2aa29a['Descriptions'],_0xba9263,'\x0a')},getCustomFields(_0x364104,_0xba9263));if(_0x1d1f4d){_0x4235d0[_0xf7c5('0x11')]=_0x1d1f4d['id'];}}else if(_0x2aa29a[_0xf7c5('0x12')]===_0xf7c5('0x13')){_0x4235d0=Object['assign']({},{'OwnerId':_0x3f7ba9['id'],'Subject':intUtil[_0xf7c5('0x10')](_0x2aa29a[_0xf7c5('0x14')],_0xba9263,'\x20'),'Description':intUtil[_0xf7c5('0x10')](_0x2aa29a['Descriptions'],_0xba9263,'\x0a')},getCustomFields(_0x364104,_0xba9263));if(_0x1d1f4d){_0x4235d0[_0xf7c5('0x15')]=_0x1d1f4d['id'];}}return _0x1770cb[_0xf7c5('0x16')](_0x2aa29a[_0xf7c5('0x12')])[_0xf7c5('0x17')](_0x4235d0);}function getUser(_0x56c40d,_0x197a28,_0x38f3c3){if(!_[_0xf7c5('0x18')](_0x197a28)&&intUtil[_0xf7c5('0x19')](_0x197a28)){var _0x4a9d9a={'Email':_0x197a28};var _0x3ece8d={'Id':!![],'Username':!![],'Name':!![],'Email':!![]};return _0x38f3c3[_0xf7c5('0x16')]('User')[_0xf7c5('0x1a')](_0x4a9d9a,_0x3ece8d)[_0xf7c5('0x1b')]()['then'](function(_0x26e87a){if(_0x26e87a[_0xf7c5('0x1c')]){var _0x4b0b4a=_[_0xf7c5('0x1a')](_0x26e87a,function(_0x259d60){return _0x259d60[_0xf7c5('0x1d')]===_0x197a28;});if(_0x4b0b4a){logger[_0xf7c5('0x1e')](_0xf7c5('0x1f'),_0x197a28);return BPromise[_0xf7c5('0x20')]({'id':_0x4b0b4a['Id'],'name':_0x4b0b4a[_0xf7c5('0x21')]});}}else{logger['info']('Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.',_0x197a28);return _0x38f3c3[_0xf7c5('0x22')]()[_0xf7c5('0x23')](function(_0x2df090){return BPromise['resolve']({'id':_0x2df090[_0xf7c5('0x24')],'name':_0x2df090['display_name']});});}});}else{logger[_0xf7c5('0x1e')]('Agent\x20%s\x20not\x20found.\x20Switch\x20to\x20the\x20admin\x20account.',_0x197a28);return _0x38f3c3[_0xf7c5('0x22')]()[_0xf7c5('0x23')](function(_0x37692a){return BPromise[_0xf7c5('0x20')]({'id':_0x37692a[_0xf7c5('0x24')],'name':_0x37692a[_0xf7c5('0x25')]});});}}function getEndUser(_0xae3fd7,_0x12bf00,_0x1e0540,_0x8622c4,_0x174f9c){var _0x40209c={'Phone':_0x8622c4};var _0x37f5b1={'Id':!![],'Name':!![],'Phone':!![]};return BPromise[_0xf7c5('0x20')]()[_0xf7c5('0x23')](function(){if(_0x12bf00['ticketType']===_0xf7c5('0xd')){logger[_0xf7c5('0x1e')](_0xf7c5('0x26'),_0x8622c4,_0x12bf00[_0xf7c5('0x27')]);switch(_0x12bf00['moduleSearch']){case _0xf7c5('0x28'):return _0x174f9c[_0xf7c5('0x16')](_0xf7c5('0x29'))[_0xf7c5('0x1a')](_0x40209c,_0x37f5b1)[_0xf7c5('0x1b')]()['then'](function(_0x2e2eab){if(_0x2e2eab&&_0x2e2eab[_0xf7c5('0x1c')]){return _0x2e2eab;}else{return _0x174f9c[_0xf7c5('0x16')](_0xf7c5('0x2a'))['find'](_0x40209c,_0x37f5b1);}});case'contact':return _0x174f9c['sobject'](_0xf7c5('0x29'))[_0xf7c5('0x1a')](_0x40209c,_0x37f5b1)['execute']();case _0xf7c5('0x2b'):return _0x174f9c['sobject'](_0xf7c5('0x2a'))[_0xf7c5('0x1a')](_0x40209c,_0x37f5b1);default:return null;}}else if(_0x12bf00[_0xf7c5('0x12')]===_0xf7c5('0x13')){logger[_0xf7c5('0x1e')](_0xf7c5('0x26'),_0x8622c4,_0xf7c5('0x2c'));return _0x174f9c[_0xf7c5('0x16')](_0xf7c5('0x29'))[_0xf7c5('0x1a')](_0x40209c,_0x37f5b1)[_0xf7c5('0x1b')]();}})[_0xf7c5('0x23')](function(_0x36a294){if(_0x36a294&&_0x36a294[_0xf7c5('0x1c')]){var _0x3a1bb2=_[_0xf7c5('0x1a')](_0x36a294,function(_0x10026d){return _0x10026d[_0xf7c5('0x2d')]===_0x8622c4;});if(_0x3a1bb2){return BPromise[_0xf7c5('0x20')]({'id':_0x3a1bb2['Id'],'name':_0x3a1bb2['Name'],'phone':_0x3a1bb2[_0xf7c5('0x2d')]});}}})[_0xf7c5('0x23')](function(_0x4c9cc3){if(_0x4c9cc3){logger['info'](_0xf7c5('0x2e'),_0x8622c4);return BPromise[_0xf7c5('0x20')](_0x4c9cc3);}else{logger['info']('Enduser\x20with\x20phone\x20%s\x20not\x20found.',_0x8622c4);var _0x4cfc0b={'LastName':_0x1e0540!==_0xf7c5('0x2f')?_0x1e0540:util[_0xf7c5('0x30')](_0xf7c5('0x31'),_0x8622c4),'Phone':_0x8622c4};if(_0x12bf00[_0xf7c5('0x32')]){if(_0x12bf00[_0xf7c5('0x32')]===_0xf7c5('0x2c')){logger[_0xf7c5('0x1e')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x8622c4,_0x12bf00['moduleCreate']);}else if(_0x12bf00[_0xf7c5('0x32')]===_0xf7c5('0x2b')&&_0x12bf00['ticketType']==='Task'){logger[_0xf7c5('0x1e')]('Enduser\x20with\x20phone\x20%s.\x20Creating\x20method\x20used\x20%s.',_0x8622c4,_0x12bf00[_0xf7c5('0x32')]);_0x4cfc0b[_0xf7c5('0x33')]=_0xf7c5('0x34');}else{return null;}}return _0x174f9c[_0xf7c5('0x16')](_['upperFirst'](_0x12bf00['moduleCreate']))['create'](_0x4cfc0b);}});}function getCustomFields(_0x4104bf,_0x18d0f3){var _0x544917={};if(_0x4104bf[_0xf7c5('0x1c')]>0x0){_[_0xf7c5('0x35')](_0x4104bf,function(_0x5b96be){if(_0x5b96be[_0xf7c5('0x36')]===_0xf7c5('0x37')&&_0x5b96be[_0xf7c5('0x38')]){_0x544917[_0x5b96be[_0xf7c5('0x38')]]=_0x5b96be[_0xf7c5('0x39')][_0xf7c5('0x3a')]();}else if(_0x5b96be[_0xf7c5('0x36')]===_0xf7c5('0x3b')&&_0x5b96be[_0xf7c5('0x3c')]&&_0x5b96be[_0xf7c5('0x38')]){_0x18d0f3[_0x5b96be[_0xf7c5('0x3c')]]&&(_0x544917[_0x5b96be[_0xf7c5('0x38')]]=_0x18d0f3[_0x5b96be['variableName']][_0xf7c5('0x3a')]());}else if(_0x5b96be[_0xf7c5('0x36')]===_0xf7c5('0x3d')&&_0x5b96be[_0xf7c5('0x3e')]&&_0x5b96be[_0xf7c5('0x3e')][_0xf7c5('0x3f')]&&_0x5b96be[_0xf7c5('0x38')]){_0x18d0f3[_0x5b96be[_0xf7c5('0x3e')]['name']['toLowerCase']()]&&(_0x544917[_0x5b96be[_0xf7c5('0x38')]]=_0x18d0f3[_0x5b96be[_0xf7c5('0x3e')][_0xf7c5('0x3f')][_0xf7c5('0x40')]()][_0xf7c5('0x3a')]());}});}return _0x544917;}function getConnection(_0x4f711d){var _0x1b1357=_0x4f711d[_0xf7c5('0x41')][_0xf7c5('0x42')](_0x4f711d[_0xf7c5('0x43')]);var _0x2ec5f9=new jsforce['Connection']({'oauth2':{'loginUrl':_0x4f711d[_0xf7c5('0x44')]||_0xf7c5('0x45'),'clientId':_0x4f711d[_0xf7c5('0x46')],'clientSecret':_0x4f711d[_0xf7c5('0x47')]}});return _0x2ec5f9['login'](_0x4f711d['username'],_0x1b1357)[_0xf7c5('0x23')](function(){logger[_0xf7c5('0x1e')]('Connection\x20established.');return _0x2ec5f9;});}exports['queue']=function(_0x33c2e8,_0x2082c6,_0x1c54a1,_0x6991b8,_0x4c87db,_0x39716c){var _0x1688c5,_0x5c823f,_0x47194b,_0x256f8f;_0x39716c[_0xf7c5('0x48')]=intUtil[_0xf7c5('0x49')](_0x39716c[_0xf7c5('0x48')]);_0x39716c[_0xf7c5('0x44')]=intUtil[_0xf7c5('0x49')](_0x39716c['remoteUri']);if(_0x4c87db&&_0x4c87db['monitor_format']){logger[_0xf7c5('0x1e')](_0xf7c5('0x4a'),'Recording\x20is\x20enabled!');_0x2082c6[_0xf7c5('0x4b')]=util[_0xf7c5('0x30')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x39716c['serverUrl'],_0x2082c6['uniqueid'],md5(_0x2082c6['uniqueid']));}else{_0x2082c6[_0xf7c5('0x4b')]='';}return getConnection(_0x39716c)[_0xf7c5('0x23')](function(_0xd1c800){_0x256f8f=_0xd1c800;return getUser(_0x39716c,_0x6991b8[_0xf7c5('0x4c')],_0x256f8f);})[_0xf7c5('0x23')](function(_0x6fd7a9){_0x1688c5=_0x6fd7a9;return getEndUser(_0x39716c,_0x1c54a1,_0x2082c6[_0xf7c5('0x4d')],_0x2082c6['calleridnum'],_0x256f8f);})['then'](function(_0x2d8b8e){_0x5c823f=_0x2d8b8e;return getTicket(_0x39716c,_0x1688c5,_0x5c823f,_0x1c54a1,_0x2082c6,_0x1c54a1[_0xf7c5('0x4e')],_0x256f8f,_0xf7c5('0x4f'));})[_0xf7c5('0x23')](function(_0x3f9f21){_0x47194b=_0x3f9f21;logger[_0xf7c5('0x1e')]('[QUEUE]\x20Ticket\x20%s\x20created',_0x47194b['id']);logger[_0xf7c5('0x1e')]('[QUEUE]\x20Displaying\x20ticket\x20%s\x20to\x20agent\x20%s.\x20Integration\x20account\x20type\x20%s.',_0x47194b['id'],_0x6991b8[_0xf7c5('0x3f')],_0x39716c[_0xf7c5('0x36')]);switch(_0x39716c[_0xf7c5('0x36')]){case'integrationTab':emit(util[_0xf7c5('0x30')](_0xf7c5('0x50'),_0x6991b8[_0xf7c5('0x3f')]),'trigger:salesforce:display',{'recordId':_0x47194b['id']});break;case _0xf7c5('0x51'):emit(util['format']('user:%s',_0x6991b8['name']),_0xf7c5('0x52'),{'uri':util[_0xf7c5('0x30')](_0xf7c5('0x53'),_0x256f8f['instanceUrl'],_0x47194b['id'])});break;default:logger[_0xf7c5('0x54')]('[QUEUE]\x20Salesforce\x20account\x20type\x20not\x20recognized.');}})['catch'](function(_0x2b1a05){logger[_0xf7c5('0x54')](_0xf7c5('0x4a'),JSON[_0xf7c5('0x55')](_0x2b1a05));});};exports['outbound']=function(_0x3bbcb,_0x5358ff,_0x2bb98b,_0x53fb15,_0x7ad271,_0x302378,_0x29187c){var _0x90dd78,_0x5d5a7f,_0x3cb5c2,_0x22f1a9;_0x302378['serverUrl']=intUtil[_0xf7c5('0x49')](_0x302378['serverUrl']);_0x302378['remoteUri']=intUtil[_0xf7c5('0x49')](_0x302378['remoteUri']);if(_0x29187c&&_0x29187c[_0xf7c5('0x56')]&&_0x29187c[_0xf7c5('0x56')]!==_0xf7c5('0x57')){logger[_0xf7c5('0x1e')](_0xf7c5('0x58'),_0xf7c5('0x59'));_0x5358ff['recordingURL']=util['format'](_0xf7c5('0x5a'),_0x302378['serverUrl'],_0x5358ff[_0xf7c5('0x5b')],md5(_0x5358ff[_0xf7c5('0x5b')]));}return getConnection(_0x302378)[_0xf7c5('0x23')](function(_0x5e149b){_0x22f1a9=_0x5e149b;return getUser(_0x302378,_0x53fb15[_0xf7c5('0x4c')],_0x22f1a9);})[_0xf7c5('0x23')](function(_0x3bed0d){_0x90dd78=_0x3bed0d;return getEndUser(_0x302378,_0x2bb98b,_0x5358ff['destcalleridname'],_0x5358ff[_0xf7c5('0x5c')],_0x22f1a9);})[_0xf7c5('0x23')](function(_0x50c92f){_0x5d5a7f=_0x50c92f;return getTicket(_0x302378,_0x90dd78,_0x5d5a7f,_0x2bb98b,_0x5358ff,_0x2bb98b[_0xf7c5('0x4e')],_0x22f1a9,'outbound');})['then'](function(_0x595af0){_0x3cb5c2=_0x595af0;logger[_0xf7c5('0x1e')](_0xf7c5('0x5d'),_0x3cb5c2['id']);logger[_0xf7c5('0x1e')](_0xf7c5('0x5e'),_0x3cb5c2['id'],_0x53fb15[_0xf7c5('0x3f')],_0x302378['type']);switch(_0x302378[_0xf7c5('0x36')]){case _0xf7c5('0x5f'):emit(util[_0xf7c5('0x30')](_0xf7c5('0x50'),_0x53fb15[_0xf7c5('0x3f')]),_0xf7c5('0x60'),{'recordId':_0x3cb5c2['id']});break;case _0xf7c5('0x51'):emit(util[_0xf7c5('0x30')]('user:%s',_0x53fb15[_0xf7c5('0x3f')]),_0xf7c5('0x52'),{'uri':util[_0xf7c5('0x30')]('%s/%s/e',_0x22f1a9[_0xf7c5('0x61')],_0x3cb5c2['id'])});break;default:logger[_0xf7c5('0x54')](_0xf7c5('0x58'),'Salesforce\x20account\x20type\x20not\x20recognized');}})[_0xf7c5('0x62')](function(_0x2c6246){logger[_0xf7c5('0x54')](_0xf7c5('0x58'),JSON[_0xf7c5('0x55')](_0x2c6246));});};exports[_0xf7c5('0x63')]=function(_0x83b817,_0x45fb78,_0x5c2a7c,_0x23d482,_0x3c0879,_0x778fe){var _0x2ed06e,_0x504496,_0x14e23b,_0x1a8b85;_0x778fe[_0xf7c5('0x48')]=intUtil[_0xf7c5('0x49')](_0x778fe[_0xf7c5('0x48')]);_0x778fe['remoteUri']=intUtil[_0xf7c5('0x49')](_0x778fe[_0xf7c5('0x44')]);if(_0x3c0879&&_0x3c0879[_0xf7c5('0x64')]){logger[_0xf7c5('0x1e')]('['+_0x45fb78[_0xf7c5('0x65')][_0xf7c5('0x66')]()+']',_0xf7c5('0x59'));_0x45fb78[_0xf7c5('0x4b')]=util['format'](_0xf7c5('0x5a'),_0x778fe[_0xf7c5('0x48')],_0x45fb78[_0xf7c5('0x5b')],md5(_0x45fb78['uniqueid']));}else{_0x45fb78['recordingURL']='';}return getConnection(_0x778fe)[_0xf7c5('0x23')](function(_0x3ba5fc){_0x1a8b85=_0x3ba5fc;if(!_['isNil'](_0x23d482)){return getUser(_0x778fe,_0x23d482[_0xf7c5('0x3f')],_0x1a8b85);}else{return getUser(_0x778fe,null,_0x1a8b85);}})['then'](function(_0x27d904){_0x2ed06e=_0x27d904;return getEndUser(_0x778fe,_0x5c2a7c,_0x45fb78['calleridname'],_0x45fb78[_0xf7c5('0x67')],_0x1a8b85);})[_0xf7c5('0x23')](function(_0x1e045b){_0x504496=_0x1e045b;return getTicket(_0x778fe,_0x2ed06e,_0x504496,_0x5c2a7c,_0x45fb78,_0x5c2a7c[_0xf7c5('0x4e')],_0x1a8b85);})['then'](function(_0x3bd168){_0x14e23b=_0x3bd168;logger['info']('['+_0x45fb78[_0xf7c5('0x65')][_0xf7c5('0x66')]()+_0xf7c5('0x68'),_0x14e23b['id']);logger['info']('['+_0x45fb78[_0xf7c5('0x65')][_0xf7c5('0x66')]()+_0xf7c5('0x69'),_0x778fe[_0xf7c5('0x36')]);})[_0xf7c5('0x62')](function(_0x2156db){logger['error']('['+_0x45fb78[_0xf7c5('0x65')][_0xf7c5('0x66')]()+']',JSON['stringify'](_0x2156db));});};
\ No newline at end of file