Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / services / routing / server / applications / autoreply.js
index 6e83538..21641eb 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2c34=['../../rpc/faxMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','body','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','created','interaction','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','getMustacheRender','message','channel','phone','read','subject','Re:','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','Smtp','service','host','port','secure','authentication','auth','user','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','then','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','update','stop','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage'];(function(_0x1dc034,_0x186f35){var _0x5d120e=function(_0xc7c9d1){while(--_0xc7c9d1){_0x1dc034['push'](_0x1dc034['shift']());}};_0x5d120e(++_0x186f35);}(_0x2c34,0x8f));var _0x42c3=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0x2c34[_0x57b54c];return _0x59cc19;};'use strict';var _=require('lodash');var moment=require(_0x42c3('0x0'));var utils=require(_0x42c3('0x1'));var logger=require(_0x42c3('0x2'))(_0x42c3('0x3'));var rpc={'chatMessage':require(_0x42c3('0x4')),'openchannelMessage':require(_0x42c3('0x5')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x42c3('0x6')),'faxMessage':require(_0x42c3('0x7')),'whatsappMessage':require('../../rpc/whatsappMessage'),'chatInteraction':require(_0x42c3('0x8')),'openchannelInteraction':require(_0x42c3('0x9')),'mailInteraction':require(_0x42c3('0xa')),'smsInteraction':require(_0x42c3('0xb')),'faxInteraction':require(_0x42c3('0xc')),'whatsappInteraction':require(_0x42c3('0xd'))};var mailRpc=require(_0x42c3('0xe'));exports[_0x42c3('0xf')]=function(_0x4fcbec,_0x4bfefe,_0x4b9393,_0x2d05a5){return function(_0xe3eb45){try{var _0x33329f=this['channel'];if(_0x33329f===_0x42c3('0x10')&&_0x2d05a5[_0x42c3('0x11')]['isAutoreply']){logger[_0x42c3('0x12')](_0x42c3('0x13'),_0x4fcbec,_0x42c3('0x14'));return _0xe3eb45[_0x42c3('0x15')]();}if(_0x4bfefe[0x0]==='1'&&(_[_0x42c3('0x16')](this['interaction'][_0x42c3('0x17')])||!this[_0x42c3('0x18')][_0x42c3('0x17')])){logger['info'](_0x42c3('0x13'),_0x4fcbec,_0x42c3('0x19'));return _0xe3eb45[_0x42c3('0x15')]();}if(_0x4bfefe[0x0]==='2'&&this[_0x42c3('0x18')][_0x42c3('0x1a')]){logger[_0x42c3('0x12')](_0x42c3('0x1b'),_0x4fcbec,_0x42c3('0x1c'));return _0xe3eb45[_0x42c3('0x15')]();}var _0x5df314={'ContactId':this[_0x42c3('0x1d')]['id'],'sentAt':moment()[_0x42c3('0x1e')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':'out'};if(this['channel']===_0x42c3('0x10')){_0x5df314['body']=utils[_0x42c3('0x1f')](_0x4bfefe[0x2],this);}else{_0x5df314['body']=utils['getMustacheRender'](_0x4bfefe[0x1],this);}if(this[_0x42c3('0x20')]){_0x5df314['to']=this['message']['from']||'';if(this[_0x42c3('0x21')]===_0x42c3('0x10')&&_0x4bfefe[0x1]==='1'){_0x5df314['cc']=this[_0x42c3('0x20')]['cc']||'';}_0x5df314['from']=this[_0x42c3('0x20')]['to']||'';_0x5df314[_0x42c3('0x22')]=this[_0x42c3('0x20')][_0x42c3('0x22')]||'';_0x5df314[_0x42c3('0x23')]=!![];if(this[_0x42c3('0x20')][_0x42c3('0x24')]){_0x5df314[_0x42c3('0x24')]='';_0x5df314['subject']+=_['startsWith'](this[_0x42c3('0x20')][_0x42c3('0x24')],_0x42c3('0x25'))?'':'Re:\x20';_0x5df314[_0x42c3('0x24')]+=this[_0x42c3('0x20')][_0x42c3('0x24')];}}if(this[_0x42c3('0x21')]==='chat'){_0x5df314[_0x42c3('0x26')]=this[_0x42c3('0x27')]['id'];}else{_0x5df314[_[_0x42c3('0x28')](this[_0x42c3('0x21')])+_0x42c3('0x29')]=this[_0x42c3('0x27')]['id'];}_0x5df314[_[_0x42c3('0x28')](this['channel'])+_0x42c3('0x2a')]=this[_0x42c3('0x18')]['id'];var _0x2064a2=this['interaction'];if(rpc[this[_0x42c3('0x21')]+_0x42c3('0x2b')]){if(this[_0x42c3('0x21')]===_0x42c3('0x10')){var _0x553e95={'tls':{'rejectUnauthorized':![]}};if(this['account'][_0x42c3('0x2c')][_0x42c3('0x2d')]){_0x553e95[_0x42c3('0x2d')]=this[_0x42c3('0x27')][_0x42c3('0x2c')][_0x42c3('0x2d')];}else{_0x553e95[_0x42c3('0x2e')]=this[_0x42c3('0x27')][_0x42c3('0x2c')]['host'];_0x553e95[_0x42c3('0x2f')]=this[_0x42c3('0x27')][_0x42c3('0x2c')][_0x42c3('0x2f')];_0x553e95['secure']=this['account']['Smtp'][_0x42c3('0x30')];}if(this[_0x42c3('0x27')][_0x42c3('0x2c')][_0x42c3('0x31')]){_0x553e95[_0x42c3('0x32')]={'user':this['account'][_0x42c3('0x2c')][_0x42c3('0x33')],'pass':this[_0x42c3('0x27')][_0x42c3('0x2c')]['pass']};}_0x5df314['inReplyTo']=this['message'][_0x42c3('0x34')];_0x5df314['html']=_0x42c3('0x35')+_[_0x42c3('0x36')](_0x5df314[_0x42c3('0x11')],_0x42c3('0x37'),_0x42c3('0x38'))+_0x42c3('0x39');_0x5df314[_0x42c3('0x3a')]={'Auto-Submitted':_0x42c3('0x3b'),'X-Auto-Response-Suppress':_0x42c3('0x3c'),'Precedence':_0x42c3('0x3d')};return mailRpc[_0x42c3('0x3e')](_0x553e95,_0x5df314)[_0x42c3('0x3f')](function(_0x4420d8){logger[_0x42c3('0x12')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x4fcbec);_0x5df314['messageId']=_0x4420d8[_0x42c3('0x20')][_0x42c3('0x34')];return rpc[_0x33329f+'Message'][_0x42c3('0x40')](_0x5df314);})['then'](function(_0x5972c2){logger['info']('[%s][AUTOREPLY]\x20%s',_0x4fcbec,JSON[_0x42c3('0x41')](_0x5972c2));})[_0x42c3('0x42')](function(_0x524615){logger[_0x42c3('0x43')](_0x42c3('0x44'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x524615));})[_0x42c3('0x45')](function(){Promise[_0x42c3('0x46')]()[_0x42c3('0x3f')](function(){if(_0x4bfefe[0x0]!=='2'||_0x2064a2['autoreplyExecuted'])return;return rpc[_0x33329f+_0x42c3('0x47')]['update'](_0x2064a2['id'],{'autoreplyExecuted':!![]})['then'](function(_0x581883){logger[_0x42c3('0x12')](_0x42c3('0x1b'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x581883));})[_0x42c3('0x42')](function(_0x48ba6f){logger[_0x42c3('0x43')](_0x42c3('0x48'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x48ba6f));});})[_0x42c3('0x3f')](function(){_0xe3eb45['next']();});});}else{return rpc[this['channel']+'Message']['create'](_0x5df314)['then'](function(_0x5c6147){logger[_0x42c3('0x12')](_0x42c3('0x13'),_0x4fcbec,_0x5df314[_0x42c3('0x11')]);})[_0x42c3('0x42')](function(_0x4c988d){logger[_0x42c3('0x43')](_0x42c3('0x13'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x4c988d));})['finally'](function(){Promise[_0x42c3('0x46')]()['then'](function(){if(_0x4bfefe[0x0]!=='2'||_0x2064a2['autoreplyExecuted'])return;return rpc[_0x33329f+_0x42c3('0x47')][_0x42c3('0x49')](_0x2064a2['id'],{'autoreplyExecuted':!![]})['then'](function(_0x2603b7){logger[_0x42c3('0x12')](_0x42c3('0x1b'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x2603b7));})[_0x42c3('0x42')](function(_0x265b87){logger[_0x42c3('0x43')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x4fcbec,JSON[_0x42c3('0x41')](_0x265b87));});})[_0x42c3('0x3f')](function(){_0xe3eb45[_0x42c3('0x15')]();});});}}}catch(_0x2ba449){logger['error'](_0x42c3('0x13'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x2ba449));_0xe3eb45[_0x42c3('0x4a')]();}};};
\ No newline at end of file
+var _0xdca4=['consequence','mail','body','isAutoreply','info','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','interaction','created','[%s][AUTOREPLY]\x20%s','Autoreply\x20already\x20sent','next','autoreplyExecuted','contact','YYYY-MM-DD\x20HH:mm:ss','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','channel','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','<div\x20id=\x22xm-mail-content\x22>','replace','<div','</div>','auto-replied','All','auto_reply','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','messageId','create','catch','error','[RPC][%s][AUTOREPLY]\x20%s','stringify','resolve','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','finally','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','lodash','moment','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/whatsappInteraction','../../mailRpc'];(function(_0x3635ce,_0x33a6f9){var _0x97ecd0=function(_0x123d98){while(--_0x123d98){_0x3635ce['push'](_0x3635ce['shift']());}};_0x97ecd0(++_0x33a6f9);}(_0xdca4,0x19a));var _0x4dca=function(_0x239a9f,_0x4a97b6){_0x239a9f=_0x239a9f-0x0;var _0x360549=_0xdca4[_0x239a9f];return _0x360549;};'use strict';var _=require(_0x4dca('0x0'));var moment=require(_0x4dca('0x1'));var utils=require(_0x4dca('0x2'));var logger=require('../../../../config/logger')(_0x4dca('0x3'));var rpc={'chatMessage':require(_0x4dca('0x4')),'openchannelMessage':require(_0x4dca('0x5')),'mailMessage':require(_0x4dca('0x6')),'smsMessage':require(_0x4dca('0x7')),'faxMessage':require(_0x4dca('0x8')),'whatsappMessage':require(_0x4dca('0x9')),'chatInteraction':require(_0x4dca('0xa')),'openchannelInteraction':require(_0x4dca('0xb')),'mailInteraction':require(_0x4dca('0xc')),'smsInteraction':require(_0x4dca('0xd')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0x4dca('0xe'))};var mailRpc=require(_0x4dca('0xf'));exports[_0x4dca('0x10')]=function(_0x18da1b,_0x2ab1ad,_0x5545a0,_0x397241){return function(_0xf1a354){try{var _0xbc6917=this['channel'];if(_0xbc6917===_0x4dca('0x11')&&_0x397241[_0x4dca('0x12')][_0x4dca('0x13')]){logger[_0x4dca('0x14')]('[%s][AUTOREPLY]\x20%s',_0x18da1b,_0x4dca('0x15'));return _0xf1a354['next']();}if(_0x2ab1ad[0x0]==='1'&&(_[_0x4dca('0x16')](this[_0x4dca('0x17')][_0x4dca('0x18')])||!this[_0x4dca('0x17')][_0x4dca('0x18')])){logger[_0x4dca('0x14')](_0x4dca('0x19'),_0x18da1b,_0x4dca('0x1a'));return _0xf1a354[_0x4dca('0x1b')]();}if(_0x2ab1ad[0x0]==='2'&&this[_0x4dca('0x17')][_0x4dca('0x1c')]){logger[_0x4dca('0x14')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x18da1b,'One\x20Time\x20already\x20sent');return _0xf1a354['next']();}var _0x42f231={'ContactId':this[_0x4dca('0x1d')]['id'],'sentAt':moment()['format'](_0x4dca('0x1e')),'direction':'out'};if(this['channel']===_0x4dca('0x11')){_0x42f231[_0x4dca('0x12')]=utils[_0x4dca('0x1f')](_0x2ab1ad[0x2],this);}else{_0x42f231[_0x4dca('0x12')]=utils[_0x4dca('0x1f')](_0x2ab1ad[0x1],this);}if(this['message']){_0x42f231['to']=this[_0x4dca('0x20')][_0x4dca('0x21')]||'';if(this['channel']==='mail'&&_0x2ab1ad[0x1]==='1'){_0x42f231['cc']=this['message']['cc']||'';}_0x42f231['from']=this[_0x4dca('0x20')]['to']||'';_0x42f231[_0x4dca('0x22')]=this[_0x4dca('0x20')][_0x4dca('0x22')]||'';_0x42f231[_0x4dca('0x23')]=!![];if(this[_0x4dca('0x20')]['subject']){_0x42f231[_0x4dca('0x24')]='';_0x42f231[_0x4dca('0x24')]+=_[_0x4dca('0x25')](this['message'][_0x4dca('0x24')],_0x4dca('0x26'))?'':_0x4dca('0x27');_0x42f231[_0x4dca('0x24')]+=this['message'][_0x4dca('0x24')];}}if(this[_0x4dca('0x28')]===_0x4dca('0x29')){_0x42f231[_0x4dca('0x2a')]=this[_0x4dca('0x2b')]['id'];}else{_0x42f231[_[_0x4dca('0x2c')](this[_0x4dca('0x28')])+_0x4dca('0x2d')]=this['account']['id'];}_0x42f231[_[_0x4dca('0x2c')](this[_0x4dca('0x28')])+_0x4dca('0x2e')]=this[_0x4dca('0x17')]['id'];var _0x372a38=this['interaction'];if(rpc[this[_0x4dca('0x28')]+_0x4dca('0x2f')]){if(this[_0x4dca('0x28')]===_0x4dca('0x11')){_0x42f231['inReplyTo']=this[_0x4dca('0x20')]['messageId'];_0x42f231['html']=_0x4dca('0x30')+_[_0x4dca('0x31')](_0x42f231[_0x4dca('0x12')],'<div\x20id=\x22xm-mail-content\x22',_0x4dca('0x32'))+_0x4dca('0x33');_0x42f231['headers']={'Auto-Submitted':_0x4dca('0x34'),'X-Auto-Response-Suppress':_0x4dca('0x35'),'Precedence':_0x4dca('0x36')};return mailRpc['sendMailMessage'](this[_0x4dca('0x2b')][_0x4dca('0x37')],_0x42f231)[_0x4dca('0x38')](function(_0x1f3857){logger[_0x4dca('0x14')](_0x4dca('0x39'),_0x18da1b);_0x42f231[_0x4dca('0x3a')]=_0x1f3857[_0x4dca('0x20')]['messageId'];return rpc[_0xbc6917+_0x4dca('0x2f')][_0x4dca('0x3b')](_0x42f231);})['then'](function(_0x573af1){logger[_0x4dca('0x14')](_0x4dca('0x19'),_0x18da1b,JSON['stringify'](_0x573af1));})[_0x4dca('0x3c')](function(_0x1462f0){logger[_0x4dca('0x3d')](_0x4dca('0x3e'),_0x18da1b,JSON[_0x4dca('0x3f')](_0x1462f0));})['finally'](function(){Promise[_0x4dca('0x40')]()[_0x4dca('0x38')](function(){if(_0x2ab1ad[0x0]!=='2'||_0x372a38[_0x4dca('0x1c')])return;return rpc[_0xbc6917+_0x4dca('0x41')][_0x4dca('0x42')](_0x372a38['id'],{'autoreplyExecuted':!![]})[_0x4dca('0x38')](function(_0x5639dc){logger[_0x4dca('0x14')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x18da1b,JSON[_0x4dca('0x3f')](_0x5639dc));})['catch'](function(_0x5563fb){logger['error'](_0x4dca('0x43'),_0x18da1b,JSON[_0x4dca('0x3f')](_0x5563fb));});})[_0x4dca('0x38')](function(){_0xf1a354[_0x4dca('0x1b')]();});});}else{return rpc[this[_0x4dca('0x28')]+_0x4dca('0x2f')][_0x4dca('0x3b')](_0x42f231)[_0x4dca('0x38')](function(){logger[_0x4dca('0x14')](_0x4dca('0x19'),_0x18da1b,_0x42f231[_0x4dca('0x12')]);})[_0x4dca('0x3c')](function(_0xa8952e){logger[_0x4dca('0x3d')]('[%s][AUTOREPLY]\x20%s',_0x18da1b,JSON[_0x4dca('0x3f')](_0xa8952e));})[_0x4dca('0x44')](function(){Promise[_0x4dca('0x40')]()[_0x4dca('0x38')](function(){if(_0x2ab1ad[0x0]!=='2'||_0x372a38[_0x4dca('0x1c')])return;return rpc[_0xbc6917+_0x4dca('0x41')][_0x4dca('0x42')](_0x372a38['id'],{'autoreplyExecuted':!![]})[_0x4dca('0x38')](function(_0x1a5bec){logger[_0x4dca('0x14')](_0x4dca('0x45'),_0x18da1b,JSON[_0x4dca('0x3f')](_0x1a5bec));})['catch'](function(_0x108474){logger[_0x4dca('0x3d')](_0x4dca('0x43'),_0x18da1b,JSON[_0x4dca('0x3f')](_0x108474));});})['then'](function(){_0xf1a354[_0x4dca('0x1b')]();});});}}}catch(_0x598b52){logger[_0x4dca('0x3d')]('[%s][AUTOREPLY]\x20%s',_0x18da1b,JSON[_0x4dca('0x3f')](_0x598b52));_0xf1a354[_0x4dca('0x46')]();}};};
\ No newline at end of file