Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / services / routing / server / applications / autoreply.js
index 4fea601..687c4a4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xeddc=['isAutoreply','info','[%s][AUTOREPLY]\x20%s','next','isNil','interaction','created','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','out','getMustacheRender','message','from','phone','read','subject','startsWith','chat','account','upperFirst','AccountId','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','sendMailMessage','then','Message','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','autoreplyExecuted','update','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','lodash','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','channel','mail','body'];(function(_0x2f8257,_0x4644e9){var _0x908e5c=function(_0x12dc26){while(--_0x12dc26){_0x2f8257['push'](_0x2f8257['shift']());}};_0x908e5c(++_0x4644e9);}(_0xeddc,0x169));var _0xcedd=function(_0x3d1b74,_0x1a3f65){_0x3d1b74=_0x3d1b74-0x0;var _0x4f1fcb=_0xeddc[_0x3d1b74];return _0x4f1fcb;};'use strict';var _=require(_0xcedd('0x0'));var moment=require('moment');var utils=require(_0xcedd('0x1'));var logger=require('../../../../config/logger')(_0xcedd('0x2'));var rpc={'chatMessage':require(_0xcedd('0x3')),'openchannelMessage':require(_0xcedd('0x4')),'mailMessage':require(_0xcedd('0x5')),'smsMessage':require(_0xcedd('0x6')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0xcedd('0x7')),'chatInteraction':require(_0xcedd('0x8')),'openchannelInteraction':require(_0xcedd('0x9')),'mailInteraction':require(_0xcedd('0xa')),'smsInteraction':require('../../rpc/smsInteraction'),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xcedd('0xb'))};var mailRpc=require(_0xcedd('0xc'));exports[_0xcedd('0xd')]=function(_0x2e5c7c,_0xf4f8a3,_0x5c5397,_0x431d95){return function(_0x20771a){try{var _0x35ca3d=this[_0xcedd('0xe')];if(_0x35ca3d===_0xcedd('0xf')&&_0x431d95[_0xcedd('0x10')][_0xcedd('0x11')]){logger[_0xcedd('0x12')](_0xcedd('0x13'),_0x2e5c7c,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x20771a[_0xcedd('0x14')]();}if(_0xf4f8a3[0x0]==='1'&&(_[_0xcedd('0x15')](this['interaction']['created'])||!this[_0xcedd('0x16')][_0xcedd('0x17')])){logger[_0xcedd('0x12')]('[%s][AUTOREPLY]\x20%s',_0x2e5c7c,'Autoreply\x20already\x20sent');return _0x20771a[_0xcedd('0x14')]();}if(_0xf4f8a3[0x0]==='2'&&this['interaction']['autoreplyExecuted']){logger['info'](_0xcedd('0x18'),_0x2e5c7c,_0xcedd('0x19'));return _0x20771a[_0xcedd('0x14')]();}var _0x6e3fd2={'ContactId':this[_0xcedd('0x1a')]['id'],'sentAt':moment()[_0xcedd('0x1b')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0xcedd('0x1c')};if(this[_0xcedd('0xe')]==='mail'){_0x6e3fd2[_0xcedd('0x10')]=utils[_0xcedd('0x1d')](_0xf4f8a3[0x2],this);}else{_0x6e3fd2[_0xcedd('0x10')]=utils[_0xcedd('0x1d')](_0xf4f8a3[0x1],this);}if(this[_0xcedd('0x1e')]){_0x6e3fd2['to']=this['message'][_0xcedd('0x1f')]||'';if(this[_0xcedd('0xe')]===_0xcedd('0xf')&&_0xf4f8a3[0x1]==='1'){_0x6e3fd2['cc']=this[_0xcedd('0x1e')]['cc']||'';}_0x6e3fd2[_0xcedd('0x1f')]=this[_0xcedd('0x1e')]['to']||'';_0x6e3fd2[_0xcedd('0x20')]=this[_0xcedd('0x1e')]['phone']||'';_0x6e3fd2[_0xcedd('0x21')]=!![];if(this[_0xcedd('0x1e')]['subject']){_0x6e3fd2[_0xcedd('0x22')]='';_0x6e3fd2[_0xcedd('0x22')]+=_[_0xcedd('0x23')](this[_0xcedd('0x1e')][_0xcedd('0x22')],'Re:')?'':'Re:\x20';_0x6e3fd2[_0xcedd('0x22')]+=this[_0xcedd('0x1e')][_0xcedd('0x22')];}}if(this[_0xcedd('0xe')]===_0xcedd('0x24')){_0x6e3fd2['ChatWebsiteId']=this[_0xcedd('0x25')]['id'];}else{_0x6e3fd2[_[_0xcedd('0x26')](this[_0xcedd('0xe')])+_0xcedd('0x27')]=this[_0xcedd('0x25')]['id'];}_0x6e3fd2[_['upperFirst'](this[_0xcedd('0xe')])+'InteractionId']=this[_0xcedd('0x16')]['id'];var _0x588294=this[_0xcedd('0x16')];if(rpc[this[_0xcedd('0xe')]+'Message']){if(this[_0xcedd('0xe')]===_0xcedd('0xf')){_0x6e3fd2[_0xcedd('0x28')]=this[_0xcedd('0x1e')][_0xcedd('0x29')];_0x6e3fd2[_0xcedd('0x2a')]=_0xcedd('0x2b')+_[_0xcedd('0x2c')](_0x6e3fd2[_0xcedd('0x10')],_0xcedd('0x2d'),_0xcedd('0x2e'))+_0xcedd('0x2f');_0x6e3fd2['headers']={'Auto-Submitted':'auto-replied','X-Auto-Response-Suppress':'All','Precedence':'auto_reply'};return mailRpc[_0xcedd('0x30')](this[_0xcedd('0x25')]['smtpOptions'],_0x6e3fd2)[_0xcedd('0x31')](function(_0x2e4df9){logger[_0xcedd('0x12')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x2e5c7c);_0x6e3fd2['messageId']=_0x2e4df9[_0xcedd('0x1e')][_0xcedd('0x29')];return rpc[_0x35ca3d+_0xcedd('0x32')][_0xcedd('0x33')](_0x6e3fd2);})[_0xcedd('0x31')](function(_0x48a354){logger[_0xcedd('0x12')](_0xcedd('0x13'),_0x2e5c7c,JSON[_0xcedd('0x34')](_0x48a354));})[_0xcedd('0x35')](function(_0x2e4b40){logger[_0xcedd('0x36')](_0xcedd('0x37'),_0x2e5c7c,JSON[_0xcedd('0x34')](_0x2e4b40));})[_0xcedd('0x38')](function(){Promise[_0xcedd('0x39')]()[_0xcedd('0x31')](function(){if(_0xf4f8a3[0x0]!=='2'||_0x588294[_0xcedd('0x3a')])return;return rpc[_0x35ca3d+'Interaction'][_0xcedd('0x3b')](_0x588294['id'],{'autoreplyExecuted':!![]})['then'](function(_0x3c13a8){logger[_0xcedd('0x12')](_0xcedd('0x18'),_0x2e5c7c,JSON[_0xcedd('0x34')](_0x3c13a8));})['catch'](function(_0x318f0f){logger[_0xcedd('0x36')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x2e5c7c,JSON[_0xcedd('0x34')](_0x318f0f));});})[_0xcedd('0x31')](function(){_0x20771a['next']();});});}else{return rpc[this[_0xcedd('0xe')]+_0xcedd('0x32')]['create'](_0x6e3fd2)[_0xcedd('0x31')](function(){logger['info']('[%s][AUTOREPLY]\x20%s',_0x2e5c7c,_0x6e3fd2[_0xcedd('0x10')]);})['catch'](function(_0x44ba74){logger[_0xcedd('0x36')](_0xcedd('0x13'),_0x2e5c7c,JSON[_0xcedd('0x34')](_0x44ba74));})[_0xcedd('0x38')](function(){Promise[_0xcedd('0x39')]()['then'](function(){if(_0xf4f8a3[0x0]!=='2'||_0x588294[_0xcedd('0x3a')])return;return rpc[_0x35ca3d+_0xcedd('0x3c')][_0xcedd('0x3b')](_0x588294['id'],{'autoreplyExecuted':!![]})['then'](function(_0xd145be){logger['info'](_0xcedd('0x18'),_0x2e5c7c,JSON[_0xcedd('0x34')](_0xd145be));})[_0xcedd('0x35')](function(_0x156a0c){logger[_0xcedd('0x36')](_0xcedd('0x3d'),_0x2e5c7c,JSON['stringify'](_0x156a0c));});})[_0xcedd('0x31')](function(){_0x20771a[_0xcedd('0x14')]();});});}}}catch(_0x5e0afa){logger[_0xcedd('0x36')](_0xcedd('0x13'),_0x2e5c7c,JSON[_0xcedd('0x34')](_0x5e0afa));_0x20771a[_0xcedd('0x3e')]();}};};
\ No newline at end of file
+var _0x8ccc=['<div\x20id=\x22xm-mail-content\x22>','<div','</div>','headers','auto-replied','auto_reply','sendMailMessage','smtpOptions','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','then','autoreplyExecuted','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','./utils','routing','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','channel','mail','body','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','interaction','created','Autoreply\x20already\x20sent','next','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','upperFirst','account','InteractionId','Message','inReplyTo','messageId','html'];(function(_0x335a61,_0x21b879){var _0x48a02b=function(_0x2978a8){while(--_0x2978a8){_0x335a61['push'](_0x335a61['shift']());}};_0x48a02b(++_0x21b879);}(_0x8ccc,0x159));var _0xc8cc=function(_0x372e7c,_0x186d77){_0x372e7c=_0x372e7c-0x0;var _0x1b09ae=_0x8ccc[_0x372e7c];return _0x1b09ae;};'use strict';var _=require('lodash');var moment=require('moment');var utils=require(_0xc8cc('0x0'));var logger=require('../../../../config/logger')(_0xc8cc('0x1'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xc8cc('0x2')),'whatsappMessage':require(_0xc8cc('0x3')),'chatInteraction':require(_0xc8cc('0x4')),'openchannelInteraction':require(_0xc8cc('0x5')),'mailInteraction':require(_0xc8cc('0x6')),'smsInteraction':require('../../rpc/smsInteraction'),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xc8cc('0x7'))};var mailRpc=require(_0xc8cc('0x8'));exports[_0xc8cc('0x9')]=function(_0x3f4ef6,_0x1bd5c5,_0x264605,_0x860819){return function(_0x3d38ea){try{var _0x351d41=this[_0xc8cc('0xa')];if(_0x351d41===_0xc8cc('0xb')&&_0x860819[_0xc8cc('0xc')]['isAutoreply']){logger[_0xc8cc('0xd')](_0xc8cc('0xe'),_0x3f4ef6,_0xc8cc('0xf'));return _0x3d38ea['next']();}if(_0x1bd5c5[0x0]==='1'&&(_[_0xc8cc('0x10')](this[_0xc8cc('0x11')][_0xc8cc('0x12')])||!this[_0xc8cc('0x11')][_0xc8cc('0x12')])){logger[_0xc8cc('0xd')](_0xc8cc('0xe'),_0x3f4ef6,_0xc8cc('0x13'));return _0x3d38ea[_0xc8cc('0x14')]();}if(_0x1bd5c5[0x0]==='2'&&this[_0xc8cc('0x11')]['autoreplyExecuted']){logger[_0xc8cc('0xd')](_0xc8cc('0x15'),_0x3f4ef6,_0xc8cc('0x16'));return _0x3d38ea['next']();}var _0x5bcc64={'ContactId':this[_0xc8cc('0x17')]['id'],'sentAt':moment()[_0xc8cc('0x18')](_0xc8cc('0x19')),'direction':_0xc8cc('0x1a')};if(this[_0xc8cc('0xa')]===_0xc8cc('0xb')){_0x5bcc64[_0xc8cc('0xc')]=utils[_0xc8cc('0x1b')](_0x1bd5c5[0x2],this);}else{_0x5bcc64[_0xc8cc('0xc')]=utils[_0xc8cc('0x1b')](_0x1bd5c5[0x1],this);}if(this[_0xc8cc('0x1c')]){_0x5bcc64['to']=this[_0xc8cc('0x1c')]['from']||'';if(this['channel']==='mail'&&_0x1bd5c5[0x1]==='1'){_0x5bcc64['cc']=this[_0xc8cc('0x1c')]['cc']||'';}_0x5bcc64[_0xc8cc('0x1d')]=this[_0xc8cc('0x1c')]['to']||'';_0x5bcc64[_0xc8cc('0x1e')]=this['message'][_0xc8cc('0x1e')]||'';_0x5bcc64[_0xc8cc('0x1f')]=!![];if(this['message'][_0xc8cc('0x20')]){_0x5bcc64[_0xc8cc('0x20')]='';_0x5bcc64[_0xc8cc('0x20')]+=_[_0xc8cc('0x21')](this[_0xc8cc('0x1c')]['subject'],_0xc8cc('0x22'))?'':_0xc8cc('0x23');_0x5bcc64[_0xc8cc('0x20')]+=this[_0xc8cc('0x1c')][_0xc8cc('0x20')];}}if(this[_0xc8cc('0xa')]===_0xc8cc('0x24')){_0x5bcc64[_0xc8cc('0x25')]=this['account']['id'];}else{_0x5bcc64[_[_0xc8cc('0x26')](this[_0xc8cc('0xa')])+'AccountId']=this[_0xc8cc('0x27')]['id'];}_0x5bcc64[_['upperFirst'](this[_0xc8cc('0xa')])+_0xc8cc('0x28')]=this[_0xc8cc('0x11')]['id'];var _0x426013=this[_0xc8cc('0x11')];if(rpc[this['channel']+_0xc8cc('0x29')]){if(this[_0xc8cc('0xa')]===_0xc8cc('0xb')){_0x5bcc64[_0xc8cc('0x2a')]=this[_0xc8cc('0x1c')][_0xc8cc('0x2b')];_0x5bcc64[_0xc8cc('0x2c')]=_0xc8cc('0x2d')+_['replace'](_0x5bcc64[_0xc8cc('0xc')],'<div\x20id=\x22xm-mail-content\x22',_0xc8cc('0x2e'))+_0xc8cc('0x2f');_0x5bcc64[_0xc8cc('0x30')]={'Auto-Submitted':_0xc8cc('0x31'),'X-Auto-Response-Suppress':'All','Precedence':_0xc8cc('0x32')};return mailRpc[_0xc8cc('0x33')](this['account'][_0xc8cc('0x34')],_0x5bcc64)['then'](function(_0x1edc2c){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x3f4ef6);_0x5bcc64[_0xc8cc('0x2b')]=_0x1edc2c[_0xc8cc('0x1c')]['messageId'];return rpc[_0x351d41+_0xc8cc('0x29')][_0xc8cc('0x35')](_0x5bcc64);})['then'](function(_0x122610){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY]\x20%s',_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x122610));})[_0xc8cc('0x37')](function(_0x5206e6){logger[_0xc8cc('0x38')](_0xc8cc('0x39'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x5206e6));})[_0xc8cc('0x3a')](function(){Promise[_0xc8cc('0x3b')]()[_0xc8cc('0x3c')](function(){if(_0x1bd5c5[0x0]!=='2'||_0x426013[_0xc8cc('0x3d')])return;return rpc[_0x351d41+'Interaction'][_0xc8cc('0x3e')](_0x426013['id'],{'autoreplyExecuted':!![]})[_0xc8cc('0x3c')](function(_0x2ffef2){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x3f4ef6,JSON['stringify'](_0x2ffef2));})[_0xc8cc('0x37')](function(_0x1aadd5){logger[_0xc8cc('0x38')](_0xc8cc('0x3f'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x1aadd5));});})['then'](function(){_0x3d38ea[_0xc8cc('0x14')]();});});}else{return rpc[this[_0xc8cc('0xa')]+_0xc8cc('0x29')][_0xc8cc('0x35')](_0x5bcc64)[_0xc8cc('0x3c')](function(){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY]\x20%s',_0x3f4ef6,_0x5bcc64[_0xc8cc('0xc')]);})['catch'](function(_0x211c4c){logger[_0xc8cc('0x38')](_0xc8cc('0xe'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x211c4c));})[_0xc8cc('0x3a')](function(){Promise[_0xc8cc('0x3b')]()[_0xc8cc('0x3c')](function(){if(_0x1bd5c5[0x0]!=='2'||_0x426013['autoreplyExecuted'])return;return rpc[_0x351d41+'Interaction'][_0xc8cc('0x3e')](_0x426013['id'],{'autoreplyExecuted':!![]})['then'](function(_0x44ee7e){logger['info'](_0xc8cc('0x15'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x44ee7e));})[_0xc8cc('0x37')](function(_0xb9e11d){logger[_0xc8cc('0x38')](_0xc8cc('0x3f'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0xb9e11d));});})['then'](function(){_0x3d38ea[_0xc8cc('0x14')]();});});}}}catch(_0x1dc1de){logger[_0xc8cc('0x38')](_0xc8cc('0xe'),_0x3f4ef6,JSON['stringify'](_0x1dc1de));_0x3d38ea[_0xc8cc('0x40')]();}};};
\ No newline at end of file