Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / services / routing / server / applications / autoreply.js
index 9f14cba..751cd31 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x975d=['<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','catch','stringify','finally','resolve','Interaction','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','error','stop','lodash','moment','./utils','../../../../config/logger','../../rpc/openchannelMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','isAutoreply','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','interaction','created','info','Autoreply\x20already\x20sent','autoreplyExecuted','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','getMustacheRender','body','message','from','phone','read','subject','Re:\x20','chat','ChatWebsiteId','account','AccountId','upperFirst','Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace'];(function(_0x5f2ed4,_0x38a732){var _0x1fe7e0=function(_0x2ef190){while(--_0x2ef190){_0x5f2ed4['push'](_0x5f2ed4['shift']());}};_0x1fe7e0(++_0x38a732);}(_0x975d,0xe6));var _0xd975=function(_0x3f827f,_0x5c8266){_0x3f827f=_0x3f827f-0x0;var _0x28599e=_0x975d[_0x3f827f];return _0x28599e;};'use strict';var _=require(_0xd975('0x0'));var moment=require(_0xd975('0x1'));var utils=require(_0xd975('0x2'));var logger=require(_0xd975('0x3'))('routing');var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xd975('0x4')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xd975('0x5')),'whatsappMessage':require(_0xd975('0x6')),'chatInteraction':require(_0xd975('0x7')),'openchannelInteraction':require(_0xd975('0x8')),'mailInteraction':require(_0xd975('0x9')),'smsInteraction':require(_0xd975('0xa')),'faxInteraction':require(_0xd975('0xb')),'whatsappInteraction':require(_0xd975('0xc'))};var mailRpc=require(_0xd975('0xd'));exports[_0xd975('0xe')]=function(_0x268d2c,_0x115d77,_0x4bc1cd,_0x550d4c){return function(_0x46c537){try{var _0x577003=this['channel'];if(_0x577003===_0xd975('0xf')&&_0x550d4c['body'][_0xd975('0x10')]){logger['info'](_0xd975('0x11'),_0x268d2c,_0xd975('0x12'));return _0x46c537[_0xd975('0x13')]();}if(_0x115d77[0x0]==='1'&&(_[_0xd975('0x14')](this[_0xd975('0x15')][_0xd975('0x16')])||!this[_0xd975('0x15')][_0xd975('0x16')])){logger[_0xd975('0x17')](_0xd975('0x11'),_0x268d2c,_0xd975('0x18'));return _0x46c537[_0xd975('0x13')]();}if(_0x115d77[0x0]==='2'&&this[_0xd975('0x15')][_0xd975('0x19')]){logger['info']('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x268d2c,_0xd975('0x1a'));return _0x46c537['next']();}var _0xba614a={'ContactId':this[_0xd975('0x1b')]['id'],'sentAt':moment()[_0xd975('0x1c')](_0xd975('0x1d')),'direction':'out'};if(this[_0xd975('0x1e')]===_0xd975('0xf')){_0xba614a['body']=utils[_0xd975('0x1f')](_0x115d77[0x2],this);}else{_0xba614a[_0xd975('0x20')]=utils[_0xd975('0x1f')](_0x115d77[0x1],this);}if(this[_0xd975('0x21')]){_0xba614a['to']=this['message'][_0xd975('0x22')]||'';if(this[_0xd975('0x1e')]==='mail'&&_0x115d77[0x1]==='1'){_0xba614a['cc']=this[_0xd975('0x21')]['cc']||'';}_0xba614a['from']=this['message']['to']||'';_0xba614a[_0xd975('0x23')]=this[_0xd975('0x21')][_0xd975('0x23')]||'';_0xba614a[_0xd975('0x24')]=!![];if(this['message'][_0xd975('0x25')]){_0xba614a[_0xd975('0x25')]='';_0xba614a[_0xd975('0x25')]+=_['startsWith'](this[_0xd975('0x21')]['subject'],'Re:')?'':_0xd975('0x26');_0xba614a[_0xd975('0x25')]+=this[_0xd975('0x21')][_0xd975('0x25')];}}if(this[_0xd975('0x1e')]===_0xd975('0x27')){_0xba614a[_0xd975('0x28')]=this[_0xd975('0x29')]['id'];}else{_0xba614a[_['upperFirst'](this[_0xd975('0x1e')])+_0xd975('0x2a')]=this[_0xd975('0x29')]['id'];}_0xba614a[_[_0xd975('0x2b')](this[_0xd975('0x1e')])+'InteractionId']=this[_0xd975('0x15')]['id'];var _0x4e667d=this[_0xd975('0x15')];if(rpc[this['channel']+_0xd975('0x2c')]){if(this[_0xd975('0x1e')]===_0xd975('0xf')){_0xba614a[_0xd975('0x2d')]=this[_0xd975('0x21')][_0xd975('0x2e')];_0xba614a[_0xd975('0x2f')]=_0xd975('0x30')+_[_0xd975('0x31')](_0xba614a[_0xd975('0x20')],'<div\x20id=\x22xm-mail-content\x22',_0xd975('0x32'))+_0xd975('0x33');_0xba614a[_0xd975('0x34')]={'Auto-Submitted':_0xd975('0x35'),'X-Auto-Response-Suppress':_0xd975('0x36'),'Precedence':_0xd975('0x37')};return mailRpc[_0xd975('0x38')](this[_0xd975('0x29')][_0xd975('0x39')],_0xba614a)[_0xd975('0x3a')](function(_0x2273a0){logger[_0xd975('0x17')](_0xd975('0x3b'),_0x268d2c);_0xba614a[_0xd975('0x2e')]=_0x2273a0['message'][_0xd975('0x2e')];return rpc[_0x577003+_0xd975('0x2c')][_0xd975('0x3c')](_0xba614a);})['then'](function(_0x12eb2e){logger[_0xd975('0x17')](_0xd975('0x11'),_0x268d2c,JSON['stringify'](_0x12eb2e));})[_0xd975('0x3d')](function(_0x2510a1){logger['error']('[RPC][%s][AUTOREPLY]\x20%s',_0x268d2c,JSON[_0xd975('0x3e')](_0x2510a1));})[_0xd975('0x3f')](function(){Promise[_0xd975('0x40')]()[_0xd975('0x3a')](function(){if(_0x115d77[0x0]!=='2'||_0x4e667d['autoreplyExecuted'])return;return rpc[_0x577003+_0xd975('0x41')]['update'](_0x4e667d['id'],{'autoreplyExecuted':!![]})[_0xd975('0x3a')](function(_0x49e11d){logger[_0xd975('0x17')](_0xd975('0x42'),_0x268d2c,JSON[_0xd975('0x3e')](_0x49e11d));})[_0xd975('0x3d')](function(_0x466167){logger['error'](_0xd975('0x43'),_0x268d2c,JSON[_0xd975('0x3e')](_0x466167));});})[_0xd975('0x3a')](function(){_0x46c537['next']();});});}else{return rpc[this[_0xd975('0x1e')]+_0xd975('0x2c')]['create'](_0xba614a)[_0xd975('0x3a')](function(){logger[_0xd975('0x17')](_0xd975('0x11'),_0x268d2c,_0xba614a[_0xd975('0x20')]);})[_0xd975('0x3d')](function(_0xf1c3){logger['error'](_0xd975('0x11'),_0x268d2c,JSON[_0xd975('0x3e')](_0xf1c3));})['finally'](function(){Promise[_0xd975('0x40')]()['then'](function(){if(_0x115d77[0x0]!=='2'||_0x4e667d['autoreplyExecuted'])return;return rpc[_0x577003+_0xd975('0x41')]['update'](_0x4e667d['id'],{'autoreplyExecuted':!![]})[_0xd975('0x3a')](function(_0x967c48){logger['info']('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x268d2c,JSON[_0xd975('0x3e')](_0x967c48));})['catch'](function(_0x1d4a17){logger[_0xd975('0x44')](_0xd975('0x43'),_0x268d2c,JSON[_0xd975('0x3e')](_0x1d4a17));});})[_0xd975('0x3a')](function(){_0x46c537[_0xd975('0x13')]();});});}}}catch(_0x270318){logger[_0xd975('0x44')](_0xd975('0x11'),_0x268d2c,JSON[_0xd975('0x3e')](_0x270318));_0x46c537[_0xd975('0x45')]();}};};
\ No newline at end of file
+var _0x0f0b=['interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','body','getMustacheRender','message','from','channel','phone','read','subject','startsWith','Re:','chat','ChatWebsiteId','account','AccountId','upperFirst','InteractionId','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','headers','auto-replied','All','sendMailMessage','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','moment','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','isAutoreply','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil'];(function(_0x2a6809,_0x44edde){var _0x11c371=function(_0x1a4888){while(--_0x1a4888){_0x2a6809['push'](_0x2a6809['shift']());}};_0x11c371(++_0x44edde);}(_0x0f0b,0x102));var _0xb0f0=function(_0x4feb9c,_0x19a66b){_0x4feb9c=_0x4feb9c-0x0;var _0x341ce3=_0x0f0b[_0x4feb9c];return _0x341ce3;};'use strict';var _=require('lodash');var moment=require(_0xb0f0('0x0'));var utils=require('./utils');var logger=require(_0xb0f0('0x1'))('routing');var rpc={'chatMessage':require(_0xb0f0('0x2')),'openchannelMessage':require(_0xb0f0('0x3')),'mailMessage':require(_0xb0f0('0x4')),'smsMessage':require(_0xb0f0('0x5')),'faxMessage':require(_0xb0f0('0x6')),'whatsappMessage':require(_0xb0f0('0x7')),'chatInteraction':require(_0xb0f0('0x8')),'openchannelInteraction':require(_0xb0f0('0x9')),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0xb0f0('0xa')),'faxInteraction':require(_0xb0f0('0xb')),'whatsappInteraction':require(_0xb0f0('0xc'))};var mailRpc=require(_0xb0f0('0xd'));exports[_0xb0f0('0xe')]=function(_0x5b378d,_0x1cd0ca,_0x5bef18,_0x2fa71c){return function(_0x5941ca){try{var _0x5c290f=this['channel'];if(_0x5c290f===_0xb0f0('0xf')&&_0x2fa71c['body'][_0xb0f0('0x10')]){logger[_0xb0f0('0x11')](_0xb0f0('0x12'),_0x5b378d,_0xb0f0('0x13'));return _0x5941ca[_0xb0f0('0x14')]();}if(_0x1cd0ca[0x0]==='1'&&(_[_0xb0f0('0x15')](this[_0xb0f0('0x16')][_0xb0f0('0x17')])||!this[_0xb0f0('0x16')][_0xb0f0('0x17')])){logger[_0xb0f0('0x11')]('[%s][AUTOREPLY]\x20%s',_0x5b378d,_0xb0f0('0x18'));return _0x5941ca['next']();}if(_0x1cd0ca[0x0]==='2'&&this[_0xb0f0('0x16')][_0xb0f0('0x19')]){logger[_0xb0f0('0x11')](_0xb0f0('0x1a'),_0x5b378d,_0xb0f0('0x1b'));return _0x5941ca[_0xb0f0('0x14')]();}var _0x3faae7={'ContactId':this[_0xb0f0('0x1c')]['id'],'sentAt':moment()[_0xb0f0('0x1d')](_0xb0f0('0x1e')),'direction':_0xb0f0('0x1f')};if(this['channel']===_0xb0f0('0xf')){_0x3faae7[_0xb0f0('0x20')]=utils[_0xb0f0('0x21')](_0x1cd0ca[0x2],this);}else{_0x3faae7[_0xb0f0('0x20')]=utils[_0xb0f0('0x21')](_0x1cd0ca[0x1],this);}if(this[_0xb0f0('0x22')]){_0x3faae7['to']=this[_0xb0f0('0x22')][_0xb0f0('0x23')]||'';if(this[_0xb0f0('0x24')]===_0xb0f0('0xf')&&_0x1cd0ca[0x1]==='1'){_0x3faae7['cc']=this[_0xb0f0('0x22')]['cc']||'';}_0x3faae7[_0xb0f0('0x23')]=this[_0xb0f0('0x22')]['to']||'';_0x3faae7[_0xb0f0('0x25')]=this[_0xb0f0('0x22')][_0xb0f0('0x25')]||'';_0x3faae7[_0xb0f0('0x26')]=!![];if(this['message']['subject']){_0x3faae7[_0xb0f0('0x27')]='';_0x3faae7[_0xb0f0('0x27')]+=_[_0xb0f0('0x28')](this[_0xb0f0('0x22')]['subject'],_0xb0f0('0x29'))?'':'Re:\x20';_0x3faae7[_0xb0f0('0x27')]+=this[_0xb0f0('0x22')][_0xb0f0('0x27')];}}if(this[_0xb0f0('0x24')]===_0xb0f0('0x2a')){_0x3faae7[_0xb0f0('0x2b')]=this[_0xb0f0('0x2c')]['id'];}else{_0x3faae7[_['upperFirst'](this[_0xb0f0('0x24')])+_0xb0f0('0x2d')]=this[_0xb0f0('0x2c')]['id'];}_0x3faae7[_[_0xb0f0('0x2e')](this[_0xb0f0('0x24')])+_0xb0f0('0x2f')]=this[_0xb0f0('0x16')]['id'];var _0x2add78=this['interaction'];if(rpc[this['channel']+'Message']){if(this[_0xb0f0('0x24')]===_0xb0f0('0xf')){_0x3faae7['inReplyTo']=this[_0xb0f0('0x22')][_0xb0f0('0x30')];_0x3faae7['html']=_0xb0f0('0x31')+_[_0xb0f0('0x32')](_0x3faae7[_0xb0f0('0x20')],_0xb0f0('0x33'),'<div')+'</div>';_0x3faae7[_0xb0f0('0x34')]={'Auto-Submitted':_0xb0f0('0x35'),'X-Auto-Response-Suppress':_0xb0f0('0x36'),'Precedence':'auto_reply'};return mailRpc[_0xb0f0('0x37')](this[_0xb0f0('0x2c')][_0xb0f0('0x38')],_0x3faae7)[_0xb0f0('0x39')](function(_0x234157){logger['info'](_0xb0f0('0x3a'),_0x5b378d);_0x3faae7['messageId']=_0x234157[_0xb0f0('0x22')][_0xb0f0('0x30')];return rpc[_0x5c290f+_0xb0f0('0x3b')][_0xb0f0('0x3c')](_0x3faae7);})['then'](function(_0x5ab52a){logger['info'](_0xb0f0('0x12'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x5ab52a));})[_0xb0f0('0x3e')](function(_0x41e9da){logger[_0xb0f0('0x3f')](_0xb0f0('0x40'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x41e9da));})[_0xb0f0('0x41')](function(){Promise[_0xb0f0('0x42')]()[_0xb0f0('0x39')](function(){if(_0x1cd0ca[0x0]!=='2'||_0x2add78[_0xb0f0('0x19')])return;return rpc[_0x5c290f+_0xb0f0('0x43')]['update'](_0x2add78['id'],{'autoreplyExecuted':!![]})['then'](function(_0xbac62f){logger[_0xb0f0('0x11')](_0xb0f0('0x1a'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0xbac62f));})[_0xb0f0('0x3e')](function(_0xb7df03){logger['error'](_0xb0f0('0x44'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0xb7df03));});})[_0xb0f0('0x39')](function(){_0x5941ca[_0xb0f0('0x14')]();});});}else{return rpc[this[_0xb0f0('0x24')]+'Message']['create'](_0x3faae7)[_0xb0f0('0x39')](function(){logger[_0xb0f0('0x11')]('[%s][AUTOREPLY]\x20%s',_0x5b378d,_0x3faae7[_0xb0f0('0x20')]);})[_0xb0f0('0x3e')](function(_0x4f3430){logger[_0xb0f0('0x3f')](_0xb0f0('0x12'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x4f3430));})['finally'](function(){Promise[_0xb0f0('0x42')]()['then'](function(){if(_0x1cd0ca[0x0]!=='2'||_0x2add78[_0xb0f0('0x19')])return;return rpc[_0x5c290f+_0xb0f0('0x43')]['update'](_0x2add78['id'],{'autoreplyExecuted':!![]})['then'](function(_0xe58a4f){logger[_0xb0f0('0x11')](_0xb0f0('0x1a'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0xe58a4f));})[_0xb0f0('0x3e')](function(_0x422a53){logger[_0xb0f0('0x3f')](_0xb0f0('0x44'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x422a53));});})['then'](function(){_0x5941ca[_0xb0f0('0x14')]();});});}}}catch(_0x4a31ae){logger[_0xb0f0('0x3f')](_0xb0f0('0x12'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x4a31ae));_0x5941ca[_0xb0f0('0x45')]();}};};
\ No newline at end of file