Built motion from commit ff78e754.|2.6.29
[motion2.git] / server / services / routing / server / applications / autoreply.js
index 12bb0a2..f151ca2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfea2=['messageId','html','<div\x20id=\x22xm-mail-content\x22>','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','smtpOptions','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','then','stringify','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','catch','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','Interaction','update','stop','lodash','../../../../config/logger','routing','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','consequence','channel','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','next','isNil','interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','out','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','account','upperFirst','mail','inReplyTo'];(function(_0x2c7487,_0x1f59c6){var _0x27a602=function(_0x3a5626){while(--_0x3a5626){_0x2c7487['push'](_0x2c7487['shift']());}};_0x27a602(++_0x1f59c6);}(_0xfea2,0x15e));var _0x2fea=function(_0x5be869,_0x9b30d2){_0x5be869=_0x5be869-0x0;var _0x514548=_0xfea2[_0x5be869];return _0x514548;};'use strict';var _=require(_0x2fea('0x0'));var moment=require('moment');var utils=require('./utils');var logger=require(_0x2fea('0x1'))(_0x2fea('0x2'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x2fea('0x3')),'faxMessage':require(_0x2fea('0x4')),'whatsappMessage':require('../../rpc/whatsappMessage'),'chatInteraction':require(_0x2fea('0x5')),'openchannelInteraction':require(_0x2fea('0x6')),'mailInteraction':require(_0x2fea('0x7')),'smsInteraction':require(_0x2fea('0x8')),'faxInteraction':require(_0x2fea('0x9')),'whatsappInteraction':require(_0x2fea('0xa'))};var mailRpc=require('../../mailRpc');exports[_0x2fea('0xb')]=function(_0x2d2199,_0x4a5f4b,_0x5c90a8,_0x25b8b8){return function(_0x187802){try{var _0x1721cd=this[_0x2fea('0xc')];if(_0x1721cd==='mail'&&_0x25b8b8[_0x2fea('0xd')][_0x2fea('0xe')]){logger[_0x2fea('0xf')](_0x2fea('0x10'),_0x2d2199,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x187802[_0x2fea('0x11')]();}if(_0x4a5f4b[0x0]==='1'&&(_[_0x2fea('0x12')](this[_0x2fea('0x13')][_0x2fea('0x14')])||!this[_0x2fea('0x13')][_0x2fea('0x14')])){logger['info']('[%s][AUTOREPLY]\x20%s',_0x2d2199,_0x2fea('0x15'));return _0x187802['next']();}if(_0x4a5f4b[0x0]==='2'&&this[_0x2fea('0x13')][_0x2fea('0x16')]){logger['info'](_0x2fea('0x17'),_0x2d2199,'One\x20Time\x20already\x20sent');return _0x187802[_0x2fea('0x11')]();}var _0x494ac5={'ContactId':this['contact']['id'],'sentAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x2fea('0x18')};if(this[_0x2fea('0xc')]==='mail'){_0x494ac5[_0x2fea('0xd')]=utils[_0x2fea('0x19')](_0x4a5f4b[0x2],this);}else{_0x494ac5[_0x2fea('0xd')]=utils['getMustacheRender'](_0x4a5f4b[0x1],this);}if(this[_0x2fea('0x1a')]){_0x494ac5['to']=this[_0x2fea('0x1a')][_0x2fea('0x1b')]||'';if(this[_0x2fea('0xc')]==='mail'&&_0x4a5f4b[0x1]==='1'){_0x494ac5['cc']=this[_0x2fea('0x1a')]['cc']||'';}_0x494ac5[_0x2fea('0x1b')]=this[_0x2fea('0x1a')]['to']||'';_0x494ac5['phone']=this[_0x2fea('0x1a')][_0x2fea('0x1c')]||'';_0x494ac5[_0x2fea('0x1d')]=!![];if(this[_0x2fea('0x1a')][_0x2fea('0x1e')]){_0x494ac5['subject']='';_0x494ac5[_0x2fea('0x1e')]+=_[_0x2fea('0x1f')](this[_0x2fea('0x1a')][_0x2fea('0x1e')],_0x2fea('0x20'))?'':_0x2fea('0x21');_0x494ac5[_0x2fea('0x1e')]+=this[_0x2fea('0x1a')][_0x2fea('0x1e')];}}if(this[_0x2fea('0xc')]===_0x2fea('0x22')){_0x494ac5[_0x2fea('0x23')]=this[_0x2fea('0x24')]['id'];}else{_0x494ac5[_[_0x2fea('0x25')](this[_0x2fea('0xc')])+'AccountId']=this[_0x2fea('0x24')]['id'];}_0x494ac5[_[_0x2fea('0x25')](this[_0x2fea('0xc')])+'InteractionId']=this[_0x2fea('0x13')]['id'];var _0x4f5700=this[_0x2fea('0x13')];if(rpc[this[_0x2fea('0xc')]+'Message']){if(this[_0x2fea('0xc')]===_0x2fea('0x26')){_0x494ac5[_0x2fea('0x27')]=this[_0x2fea('0x1a')][_0x2fea('0x28')];_0x494ac5[_0x2fea('0x29')]=_0x2fea('0x2a')+_['replace'](_0x494ac5[_0x2fea('0xd')],_0x2fea('0x2b'),_0x2fea('0x2c'))+_0x2fea('0x2d');_0x494ac5[_0x2fea('0x2e')]={'Auto-Submitted':_0x2fea('0x2f'),'X-Auto-Response-Suppress':_0x2fea('0x30'),'Precedence':_0x2fea('0x31')};return mailRpc[_0x2fea('0x32')](this[_0x2fea('0x24')][_0x2fea('0x33')],_0x494ac5)['then'](function(_0x10e8b9){logger[_0x2fea('0xf')](_0x2fea('0x34'),_0x2d2199);_0x494ac5['messageId']=_0x10e8b9[_0x2fea('0x1a')][_0x2fea('0x28')];return rpc[_0x1721cd+_0x2fea('0x35')]['create'](_0x494ac5);})[_0x2fea('0x36')](function(_0x517389){logger['info'](_0x2fea('0x10'),_0x2d2199,JSON[_0x2fea('0x37')](_0x517389));})['catch'](function(_0x1b6bfb){logger[_0x2fea('0x38')](_0x2fea('0x39'),_0x2d2199,JSON[_0x2fea('0x37')](_0x1b6bfb));})[_0x2fea('0x3a')](function(){Promise[_0x2fea('0x3b')]()[_0x2fea('0x36')](function(){if(_0x4a5f4b[0x0]!=='2'||_0x4f5700[_0x2fea('0x16')])return;return rpc[_0x1721cd+'Interaction']['update'](_0x4f5700['id'],{'autoreplyExecuted':!![]})[_0x2fea('0x36')](function(_0x26d312){logger[_0x2fea('0xf')](_0x2fea('0x17'),_0x2d2199,JSON[_0x2fea('0x37')](_0x26d312));})[_0x2fea('0x3c')](function(_0xe4ec0f){logger[_0x2fea('0x38')](_0x2fea('0x3d'),_0x2d2199,JSON['stringify'](_0xe4ec0f));});})[_0x2fea('0x36')](function(){_0x187802[_0x2fea('0x11')]();});});}else{return rpc[this[_0x2fea('0xc')]+_0x2fea('0x35')]['create'](_0x494ac5)['then'](function(){logger['info'](_0x2fea('0x10'),_0x2d2199,_0x494ac5[_0x2fea('0xd')]);})['catch'](function(_0x5c8f5c){logger[_0x2fea('0x38')](_0x2fea('0x10'),_0x2d2199,JSON[_0x2fea('0x37')](_0x5c8f5c));})[_0x2fea('0x3a')](function(){Promise[_0x2fea('0x3b')]()['then'](function(){if(_0x4a5f4b[0x0]!=='2'||_0x4f5700[_0x2fea('0x16')])return;return rpc[_0x1721cd+_0x2fea('0x3e')][_0x2fea('0x3f')](_0x4f5700['id'],{'autoreplyExecuted':!![]})[_0x2fea('0x36')](function(_0x513eac){logger['info'](_0x2fea('0x17'),_0x2d2199,JSON[_0x2fea('0x37')](_0x513eac));})[_0x2fea('0x3c')](function(_0x22616b){logger[_0x2fea('0x38')](_0x2fea('0x3d'),_0x2d2199,JSON[_0x2fea('0x37')](_0x22616b));});})[_0x2fea('0x36')](function(){_0x187802[_0x2fea('0x11')]();});});}}}catch(_0x2d4558){logger[_0x2fea('0x38')]('[%s][AUTOREPLY]\x20%s',_0x2d2199,JSON['stringify'](_0x2d4558));_0x187802[_0x2fea('0x40')]();}};};
\ No newline at end of file
+var _0xb4fb=['inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','</div>','auto-replied','auto_reply','sendMailMessage','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','then','stringify','[RPC][%s][AUTOREPLY]\x20%s','update','error','catch','finally','resolve','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','moment','../../../../config/logger','routing','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','channel','mail','body','isAutoreply','[%s][AUTOREPLY]\x20%s','next','isNil','interaction','created','info','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat','account','AccountId','upperFirst','InteractionId','Message'];(function(_0x375e04,_0x27dad6){var _0x250b96=function(_0xd6d106){while(--_0xd6d106){_0x375e04['push'](_0x375e04['shift']());}};_0x250b96(++_0x27dad6);}(_0xb4fb,0x9c));var _0xbb4f=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xb4fb[_0x20a584];return _0x4b41a8;};'use strict';var _=require('lodash');var moment=require(_0xbb4f('0x0'));var utils=require('./utils');var logger=require(_0xbb4f('0x1'))(_0xbb4f('0x2'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0xbb4f('0x3')),'smsMessage':require(_0xbb4f('0x4')),'faxMessage':require(_0xbb4f('0x5')),'whatsappMessage':require(_0xbb4f('0x6')),'chatInteraction':require('../../rpc/chatInteraction'),'openchannelInteraction':require(_0xbb4f('0x7')),'mailInteraction':require(_0xbb4f('0x8')),'smsInteraction':require(_0xbb4f('0x9')),'faxInteraction':require(_0xbb4f('0xa')),'whatsappInteraction':require(_0xbb4f('0xb'))};var mailRpc=require(_0xbb4f('0xc'));exports['consequence']=function(_0x2d17f9,_0x1cc47b,_0x14fc3c,_0x257e02){return function(_0x2c990c){try{var _0x2c291f=this[_0xbb4f('0xd')];if(_0x2c291f===_0xbb4f('0xe')&&_0x257e02[_0xbb4f('0xf')][_0xbb4f('0x10')]){logger['info'](_0xbb4f('0x11'),_0x2d17f9,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x2c990c[_0xbb4f('0x12')]();}if(_0x1cc47b[0x0]==='1'&&(_[_0xbb4f('0x13')](this[_0xbb4f('0x14')][_0xbb4f('0x15')])||!this[_0xbb4f('0x14')][_0xbb4f('0x15')])){logger[_0xbb4f('0x16')](_0xbb4f('0x11'),_0x2d17f9,_0xbb4f('0x17'));return _0x2c990c['next']();}if(_0x1cc47b[0x0]==='2'&&this[_0xbb4f('0x14')][_0xbb4f('0x18')]){logger['info'](_0xbb4f('0x19'),_0x2d17f9,_0xbb4f('0x1a'));return _0x2c990c['next']();}var _0x588fd4={'ContactId':this[_0xbb4f('0x1b')]['id'],'sentAt':moment()[_0xbb4f('0x1c')](_0xbb4f('0x1d')),'direction':'out'};if(this[_0xbb4f('0xd')]==='mail'){_0x588fd4[_0xbb4f('0xf')]=utils[_0xbb4f('0x1e')](_0x1cc47b[0x2],this);}else{_0x588fd4[_0xbb4f('0xf')]=utils[_0xbb4f('0x1e')](_0x1cc47b[0x1],this);}if(this['message']){_0x588fd4['to']=this[_0xbb4f('0x1f')]['from']||'';if(this['channel']===_0xbb4f('0xe')&&_0x1cc47b[0x1]==='1'){_0x588fd4['cc']=this[_0xbb4f('0x1f')]['cc']||'';}_0x588fd4[_0xbb4f('0x20')]=this[_0xbb4f('0x1f')]['to']||'';_0x588fd4[_0xbb4f('0x21')]=this['message']['phone']||'';_0x588fd4[_0xbb4f('0x22')]=!![];if(this['message'][_0xbb4f('0x23')]){_0x588fd4['subject']='';_0x588fd4[_0xbb4f('0x23')]+=_[_0xbb4f('0x24')](this[_0xbb4f('0x1f')][_0xbb4f('0x23')],_0xbb4f('0x25'))?'':_0xbb4f('0x26');_0x588fd4['subject']+=this[_0xbb4f('0x1f')]['subject'];}}if(this[_0xbb4f('0xd')]===_0xbb4f('0x27')){_0x588fd4['ChatWebsiteId']=this[_0xbb4f('0x28')]['id'];}else{_0x588fd4[_['upperFirst'](this[_0xbb4f('0xd')])+_0xbb4f('0x29')]=this['account']['id'];}_0x588fd4[_[_0xbb4f('0x2a')](this['channel'])+_0xbb4f('0x2b')]=this['interaction']['id'];var _0x50e487=this[_0xbb4f('0x14')];if(rpc[this[_0xbb4f('0xd')]+_0xbb4f('0x2c')]){if(this[_0xbb4f('0xd')]===_0xbb4f('0xe')){_0x588fd4[_0xbb4f('0x2d')]=this[_0xbb4f('0x1f')][_0xbb4f('0x2e')];_0x588fd4[_0xbb4f('0x2f')]=_0xbb4f('0x30')+_[_0xbb4f('0x31')](_0x588fd4[_0xbb4f('0xf')],'<div\x20id=\x22xm-mail-content\x22','<div')+_0xbb4f('0x32');_0x588fd4['headers']={'Auto-Submitted':_0xbb4f('0x33'),'X-Auto-Response-Suppress':'All','Precedence':_0xbb4f('0x34')};return mailRpc[_0xbb4f('0x35')](this[_0xbb4f('0x28')]['smtpOptions'],_0x588fd4)['then'](function(_0x18ea61){logger[_0xbb4f('0x16')](_0xbb4f('0x36'),_0x2d17f9);_0x588fd4[_0xbb4f('0x2e')]=_0x18ea61[_0xbb4f('0x1f')][_0xbb4f('0x2e')];return rpc[_0x2c291f+_0xbb4f('0x2c')][_0xbb4f('0x37')](_0x588fd4);})[_0xbb4f('0x38')](function(_0x470f18){logger['info']('[%s][AUTOREPLY]\x20%s',_0x2d17f9,JSON[_0xbb4f('0x39')](_0x470f18));})['catch'](function(_0x1c3644){logger['error'](_0xbb4f('0x3a'),_0x2d17f9,JSON['stringify'](_0x1c3644));})['finally'](function(){Promise['resolve']()[_0xbb4f('0x38')](function(){if(_0x1cc47b[0x0]!=='2'||_0x50e487['autoreplyExecuted'])return;return rpc[_0x2c291f+'Interaction'][_0xbb4f('0x3b')](_0x50e487['id'],{'autoreplyExecuted':!![]})['then'](function(_0x59ec33){logger[_0xbb4f('0x16')](_0xbb4f('0x19'),_0x2d17f9,JSON[_0xbb4f('0x39')](_0x59ec33));})['catch'](function(_0x3d9d73){logger[_0xbb4f('0x3c')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x2d17f9,JSON[_0xbb4f('0x39')](_0x3d9d73));});})[_0xbb4f('0x38')](function(){_0x2c990c[_0xbb4f('0x12')]();});});}else{return rpc[this[_0xbb4f('0xd')]+_0xbb4f('0x2c')][_0xbb4f('0x37')](_0x588fd4)[_0xbb4f('0x38')](function(){logger[_0xbb4f('0x16')](_0xbb4f('0x11'),_0x2d17f9,_0x588fd4['body']);})[_0xbb4f('0x3d')](function(_0x1e2a51){logger['error']('[%s][AUTOREPLY]\x20%s',_0x2d17f9,JSON[_0xbb4f('0x39')](_0x1e2a51));})[_0xbb4f('0x3e')](function(){Promise[_0xbb4f('0x3f')]()[_0xbb4f('0x38')](function(){if(_0x1cc47b[0x0]!=='2'||_0x50e487[_0xbb4f('0x18')])return;return rpc[_0x2c291f+_0xbb4f('0x40')][_0xbb4f('0x3b')](_0x50e487['id'],{'autoreplyExecuted':!![]})[_0xbb4f('0x38')](function(_0x172e42){logger['info'](_0xbb4f('0x19'),_0x2d17f9,JSON[_0xbb4f('0x39')](_0x172e42));})[_0xbb4f('0x3d')](function(_0x22aaaf){logger[_0xbb4f('0x3c')](_0xbb4f('0x41'),_0x2d17f9,JSON['stringify'](_0x22aaaf));});})['then'](function(){_0x2c990c[_0xbb4f('0x12')]();});});}}}catch(_0x5f2019){logger[_0xbb4f('0x3c')]('[%s][AUTOREPLY]\x20%s',_0x2d17f9,JSON[_0xbb4f('0x39')](_0x5f2019));_0x2c990c[_0xbb4f('0x42')]();}};};
\ No newline at end of file