Built motion from commit ddca4d0d.|2.5.47
[motion2.git] / server / services / routing / server / applications / autoreply.js
index b0b5b40..6e83538 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf88c=['secure','authentication','auth','user','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','auto-replied','All','sendMailMessage','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','stringify','catch','error','resolve','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','finally','stop','moment','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','next','isNil','interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','format','YYYY-MM-DD\x20HH:mm:ss','getMustacheRender','message','from','channel','phone','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','Smtp','service','host','port'];(function(_0xf97eb0,_0x1578b7){var _0xea70f4=function(_0x574c8d){while(--_0x574c8d){_0xf97eb0['push'](_0xf97eb0['shift']());}};_0xea70f4(++_0x1578b7);}(_0xf88c,0x66));var _0xcf88=function(_0x1f491a,_0x4c0839){_0x1f491a=_0x1f491a-0x0;var _0x547588=_0xf88c[_0x1f491a];return _0x547588;};'use strict';var _=require('lodash');var moment=require(_0xcf88('0x0'));var utils=require('./utils');var logger=require(_0xcf88('0x1'))(_0xcf88('0x2'));var rpc={'chatMessage':require(_0xcf88('0x3')),'openchannelMessage':require(_0xcf88('0x4')),'mailMessage':require(_0xcf88('0x5')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xcf88('0x6')),'whatsappMessage':require(_0xcf88('0x7')),'chatInteraction':require(_0xcf88('0x8')),'openchannelInteraction':require(_0xcf88('0x9')),'mailInteraction':require(_0xcf88('0xa')),'smsInteraction':require(_0xcf88('0xb')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xcf88('0xc'))};var mailRpc=require(_0xcf88('0xd'));exports[_0xcf88('0xe')]=function(_0x5be255,_0x596856,_0xf45cd0,_0xaa3992){return function(_0x21c46a){try{var _0x37134d=this['channel'];if(_0x37134d===_0xcf88('0xf')&&_0xaa3992[_0xcf88('0x10')][_0xcf88('0x11')]){logger[_0xcf88('0x12')](_0xcf88('0x13'),_0x5be255,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x21c46a[_0xcf88('0x14')]();}if(_0x596856[0x0]==='1'&&(_[_0xcf88('0x15')](this[_0xcf88('0x16')][_0xcf88('0x17')])||!this[_0xcf88('0x16')][_0xcf88('0x17')])){logger['info'](_0xcf88('0x13'),_0x5be255,_0xcf88('0x18'));return _0x21c46a[_0xcf88('0x14')]();}if(_0x596856[0x0]==='2'&&this['interaction'][_0xcf88('0x19')]){logger[_0xcf88('0x12')](_0xcf88('0x1a'),_0x5be255,_0xcf88('0x1b'));return _0x21c46a['next']();}var _0xb24a51={'ContactId':this['contact']['id'],'sentAt':moment()[_0xcf88('0x1c')](_0xcf88('0x1d')),'direction':'out'};if(this['channel']===_0xcf88('0xf')){_0xb24a51[_0xcf88('0x10')]=utils[_0xcf88('0x1e')](_0x596856[0x2],this);}else{_0xb24a51[_0xcf88('0x10')]=utils[_0xcf88('0x1e')](_0x596856[0x1],this);}if(this[_0xcf88('0x1f')]){_0xb24a51['to']=this['message'][_0xcf88('0x20')]||'';if(this[_0xcf88('0x21')]===_0xcf88('0xf')&&_0x596856[0x1]==='1'){_0xb24a51['cc']=this[_0xcf88('0x1f')]['cc']||'';}_0xb24a51[_0xcf88('0x20')]=this[_0xcf88('0x1f')]['to']||'';_0xb24a51[_0xcf88('0x22')]=this[_0xcf88('0x1f')]['phone']||'';_0xb24a51['read']=!![];if(this['message'][_0xcf88('0x23')]){_0xb24a51['subject']='';_0xb24a51[_0xcf88('0x23')]+=_[_0xcf88('0x24')](this[_0xcf88('0x1f')]['subject'],_0xcf88('0x25'))?'':_0xcf88('0x26');_0xb24a51['subject']+=this[_0xcf88('0x1f')][_0xcf88('0x23')];}}if(this[_0xcf88('0x21')]===_0xcf88('0x27')){_0xb24a51[_0xcf88('0x28')]=this[_0xcf88('0x29')]['id'];}else{_0xb24a51[_[_0xcf88('0x2a')](this[_0xcf88('0x21')])+_0xcf88('0x2b')]=this['account']['id'];}_0xb24a51[_[_0xcf88('0x2a')](this['channel'])+_0xcf88('0x2c')]=this[_0xcf88('0x16')]['id'];var _0x1fe9d0=this[_0xcf88('0x16')];if(rpc[this[_0xcf88('0x21')]+_0xcf88('0x2d')]){if(this[_0xcf88('0x21')]==='mail'){var _0x5dc93f={'tls':{'rejectUnauthorized':![]}};if(this[_0xcf88('0x29')][_0xcf88('0x2e')]['service']){_0x5dc93f[_0xcf88('0x2f')]=this[_0xcf88('0x29')][_0xcf88('0x2e')][_0xcf88('0x2f')];}else{_0x5dc93f[_0xcf88('0x30')]=this[_0xcf88('0x29')]['Smtp'][_0xcf88('0x30')];_0x5dc93f[_0xcf88('0x31')]=this[_0xcf88('0x29')][_0xcf88('0x2e')][_0xcf88('0x31')];_0x5dc93f[_0xcf88('0x32')]=this['account']['Smtp'][_0xcf88('0x32')];}if(this[_0xcf88('0x29')][_0xcf88('0x2e')][_0xcf88('0x33')]){_0x5dc93f[_0xcf88('0x34')]={'user':this[_0xcf88('0x29')]['Smtp'][_0xcf88('0x35')],'pass':this[_0xcf88('0x29')][_0xcf88('0x2e')]['pass']};}_0xb24a51['inReplyTo']=this[_0xcf88('0x1f')][_0xcf88('0x36')];_0xb24a51[_0xcf88('0x37')]=_0xcf88('0x38')+_[_0xcf88('0x39')](_0xb24a51[_0xcf88('0x10')],_0xcf88('0x3a'),_0xcf88('0x3b'))+_0xcf88('0x3c');_0xb24a51['headers']={'Auto-Submitted':_0xcf88('0x3d'),'X-Auto-Response-Suppress':_0xcf88('0x3e'),'Precedence':'auto_reply'};return mailRpc[_0xcf88('0x3f')](_0x5dc93f,_0xb24a51)[_0xcf88('0x40')](function(_0x15c0e8){logger[_0xcf88('0x12')](_0xcf88('0x41'),_0x5be255);_0xb24a51[_0xcf88('0x36')]=_0x15c0e8[_0xcf88('0x1f')][_0xcf88('0x36')];return rpc[_0x37134d+_0xcf88('0x2d')][_0xcf88('0x42')](_0xb24a51);})[_0xcf88('0x40')](function(_0x475828){logger[_0xcf88('0x12')](_0xcf88('0x13'),_0x5be255,JSON[_0xcf88('0x43')](_0x475828));})[_0xcf88('0x44')](function(_0xa9c4e7){logger[_0xcf88('0x45')]('[RPC][%s][AUTOREPLY]\x20%s',_0x5be255,JSON[_0xcf88('0x43')](_0xa9c4e7));})['finally'](function(){Promise[_0xcf88('0x46')]()[_0xcf88('0x40')](function(){if(_0x596856[0x0]!=='2'||_0x1fe9d0[_0xcf88('0x19')])return;return rpc[_0x37134d+_0xcf88('0x47')][_0xcf88('0x48')](_0x1fe9d0['id'],{'autoreplyExecuted':!![]})[_0xcf88('0x40')](function(_0xb2849b){logger['info']('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5be255,JSON[_0xcf88('0x43')](_0xb2849b));})['catch'](function(_0x1b2a31){logger[_0xcf88('0x45')](_0xcf88('0x49'),_0x5be255,JSON[_0xcf88('0x43')](_0x1b2a31));});})[_0xcf88('0x40')](function(){_0x21c46a[_0xcf88('0x14')]();});});}else{return rpc[this['channel']+'Message']['create'](_0xb24a51)[_0xcf88('0x40')](function(_0x41ddfb){logger[_0xcf88('0x12')](_0xcf88('0x13'),_0x5be255,_0xb24a51[_0xcf88('0x10')]);})[_0xcf88('0x44')](function(_0x51dff6){logger[_0xcf88('0x45')](_0xcf88('0x13'),_0x5be255,JSON['stringify'](_0x51dff6));})[_0xcf88('0x4a')](function(){Promise[_0xcf88('0x46')]()[_0xcf88('0x40')](function(){if(_0x596856[0x0]!=='2'||_0x1fe9d0[_0xcf88('0x19')])return;return rpc[_0x37134d+_0xcf88('0x47')]['update'](_0x1fe9d0['id'],{'autoreplyExecuted':!![]})[_0xcf88('0x40')](function(_0x4e5ca5){logger[_0xcf88('0x12')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5be255,JSON[_0xcf88('0x43')](_0x4e5ca5));})[_0xcf88('0x44')](function(_0x3f1e2d){logger[_0xcf88('0x45')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5be255,JSON['stringify'](_0x3f1e2d));});})['then'](function(){_0x21c46a[_0xcf88('0x14')]();});});}}}catch(_0x243c29){logger[_0xcf88('0x45')](_0xcf88('0x13'),_0x5be255,JSON[_0xcf88('0x43')](_0x243c29));_0x21c46a[_0xcf88('0x4b')]();}};};
\ No newline at end of file
+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