Built motion from commit 43538d75.|2.5.35
[motion2.git] / server / services / routing / server / applications / autoreply.js
index f4eff94..ff7f2fd 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x97d8=['host','port','secure','authentication','auth','user','pass','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22','auto-replied','auto_reply','then','create','catch','error','[RPC][%s][AUTOREPLY]\x20%s','stringify','resolve','Interaction','update','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','finally','stop','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/whatsappMessage','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','consequence','mail','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','isNil','interaction','created','next','autoreplyExecuted','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','getMustacheRender','message','from','channel','phone','read','subject','startsWith','Re:\x20','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','Smtp','service'];(function(_0x3d4b29,_0x12ad14){var _0x324a3a=function(_0x267496){while(--_0x267496){_0x3d4b29['push'](_0x3d4b29['shift']());}};_0x324a3a(++_0x12ad14);}(_0x97d8,0x13e));var _0x897d=function(_0x4350c2,_0x112f3c){_0x4350c2=_0x4350c2-0x0;var _0x8b6406=_0x97d8[_0x4350c2];return _0x8b6406;};'use strict';var _=require(_0x897d('0x0'));var moment=require(_0x897d('0x1'));var utils=require(_0x897d('0x2'));var logger=require(_0x897d('0x3'))(_0x897d('0x4'));var rpc={'chatMessage':require(_0x897d('0x5')),'openchannelMessage':require(_0x897d('0x6')),'mailMessage':require(_0x897d('0x7')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x897d('0x8')),'chatInteraction':require('../../rpc/chatInteraction'),'openchannelInteraction':require(_0x897d('0x9')),'mailInteraction':require(_0x897d('0xa')),'smsInteraction':require(_0x897d('0xb')),'faxInteraction':require(_0x897d('0xc')),'whatsappInteraction':require(_0x897d('0xd'))};var mailRpc=require('../../mailRpc');exports[_0x897d('0xe')]=function(_0x3bf46b,_0x2db2e4,_0x141f47,_0x2126e1){return function(_0x4db103){try{var _0x2ba6a3=this['channel'];if(_0x2ba6a3===_0x897d('0xf')&&_0x2126e1[_0x897d('0x10')][_0x897d('0x11')]){logger[_0x897d('0x12')](_0x897d('0x13'),_0x3bf46b,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x4db103['next']();}if(_0x2db2e4[0x0]==='1'&&(_[_0x897d('0x14')](this[_0x897d('0x15')][_0x897d('0x16')])||!this['interaction']['created'])){logger[_0x897d('0x12')](_0x897d('0x13'),_0x3bf46b,'Autoreply\x20already\x20sent');return _0x4db103[_0x897d('0x17')]();}if(_0x2db2e4[0x0]==='2'&&this[_0x897d('0x15')][_0x897d('0x18')]){logger[_0x897d('0x12')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x3bf46b,_0x897d('0x19'));return _0x4db103[_0x897d('0x17')]();}var _0x4375d3={'ContactId':this[_0x897d('0x1a')]['id'],'sentAt':moment()[_0x897d('0x1b')](_0x897d('0x1c')),'direction':'out'};if(this['channel']===_0x897d('0xf')){_0x4375d3['body']=utils[_0x897d('0x1d')](_0x2db2e4[0x2],this);}else{_0x4375d3['body']=utils[_0x897d('0x1d')](_0x2db2e4[0x1],this);}if(this[_0x897d('0x1e')]){_0x4375d3['to']=this[_0x897d('0x1e')][_0x897d('0x1f')]||'';if(this[_0x897d('0x20')]===_0x897d('0xf')&&_0x2db2e4[0x1]==='1'){_0x4375d3['cc']=this[_0x897d('0x1e')]['cc']||'';}_0x4375d3[_0x897d('0x1f')]=this[_0x897d('0x1e')]['to']||'';_0x4375d3['phone']=this['message'][_0x897d('0x21')]||'';_0x4375d3[_0x897d('0x22')]=!![];if(this['message']['subject']){_0x4375d3[_0x897d('0x23')]='';_0x4375d3[_0x897d('0x23')]+=_[_0x897d('0x24')](this[_0x897d('0x1e')][_0x897d('0x23')],'Re:')?'':_0x897d('0x25');_0x4375d3[_0x897d('0x23')]+=this[_0x897d('0x1e')][_0x897d('0x23')];}}if(this['channel']===_0x897d('0x26')){_0x4375d3[_0x897d('0x27')]=this[_0x897d('0x28')]['id'];}else{_0x4375d3[_[_0x897d('0x29')](this[_0x897d('0x20')])+_0x897d('0x2a')]=this[_0x897d('0x28')]['id'];}_0x4375d3[_[_0x897d('0x29')](this[_0x897d('0x20')])+_0x897d('0x2b')]=this['interaction']['id'];var _0x23deb5=this[_0x897d('0x15')];if(rpc[this[_0x897d('0x20')]+_0x897d('0x2c')]){if(this[_0x897d('0x20')]==='mail'){var _0x1f9ffd={'tls':{'rejectUnauthorized':![]}};if(this['account'][_0x897d('0x2d')]['service']){_0x1f9ffd['service']=this[_0x897d('0x28')][_0x897d('0x2d')][_0x897d('0x2e')];}else{_0x1f9ffd[_0x897d('0x2f')]=this[_0x897d('0x28')][_0x897d('0x2d')][_0x897d('0x2f')];_0x1f9ffd['port']=this[_0x897d('0x28')][_0x897d('0x2d')][_0x897d('0x30')];_0x1f9ffd[_0x897d('0x31')]=this[_0x897d('0x28')][_0x897d('0x2d')][_0x897d('0x31')];}if(this['account']['Smtp'][_0x897d('0x32')]){_0x1f9ffd[_0x897d('0x33')]={'user':this[_0x897d('0x28')][_0x897d('0x2d')][_0x897d('0x34')],'pass':this[_0x897d('0x28')][_0x897d('0x2d')][_0x897d('0x35')]};}_0x4375d3[_0x897d('0x36')]=this[_0x897d('0x1e')][_0x897d('0x37')];_0x4375d3[_0x897d('0x38')]='<div\x20id=\x22xm-mail-content\x22>'+_['replace'](_0x4375d3[_0x897d('0x10')],_0x897d('0x39'),'<div')+'</div>';_0x4375d3['headers']={'Auto-Submitted':_0x897d('0x3a'),'X-Auto-Response-Suppress':'All','Precedence':_0x897d('0x3b')};return mailRpc['sendMailMessage'](_0x1f9ffd,_0x4375d3)[_0x897d('0x3c')](function(_0x5b866c){logger[_0x897d('0x12')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x3bf46b);_0x4375d3[_0x897d('0x37')]=_0x5b866c[_0x897d('0x1e')][_0x897d('0x37')];return rpc[_0x2ba6a3+_0x897d('0x2c')][_0x897d('0x3d')](_0x4375d3);})['then'](function(_0x4550cb){logger[_0x897d('0x12')](_0x897d('0x13'),_0x3bf46b,JSON['stringify'](_0x4550cb));})[_0x897d('0x3e')](function(_0x1fec3d){logger[_0x897d('0x3f')](_0x897d('0x40'),_0x3bf46b,JSON[_0x897d('0x41')](_0x1fec3d));})['finally'](function(){Promise[_0x897d('0x42')]()[_0x897d('0x3c')](function(){if(_0x2db2e4[0x0]!=='2'||_0x23deb5['autoreplyExecuted'])return;return rpc[_0x2ba6a3+_0x897d('0x43')][_0x897d('0x44')](_0x23deb5['id'],{'autoreplyExecuted':!![]})['then'](function(_0x366aaf){logger['info'](_0x897d('0x45'),_0x3bf46b,JSON[_0x897d('0x41')](_0x366aaf));})['catch'](function(_0xe9f1ac){logger['error'](_0x897d('0x46'),_0x3bf46b,JSON[_0x897d('0x41')](_0xe9f1ac));});})[_0x897d('0x3c')](function(){_0x4db103[_0x897d('0x17')]();});});}else{return rpc[this[_0x897d('0x20')]+_0x897d('0x2c')][_0x897d('0x3d')](_0x4375d3)[_0x897d('0x3c')](function(_0x5a7428){logger[_0x897d('0x12')](_0x897d('0x13'),_0x3bf46b,_0x4375d3[_0x897d('0x10')]);})[_0x897d('0x3e')](function(_0x3628a0){logger['error'](_0x897d('0x13'),_0x3bf46b,JSON['stringify'](_0x3628a0));})[_0x897d('0x47')](function(){Promise[_0x897d('0x42')]()[_0x897d('0x3c')](function(){if(_0x2db2e4[0x0]!=='2'||_0x23deb5['autoreplyExecuted'])return;return rpc[_0x2ba6a3+'Interaction'][_0x897d('0x44')](_0x23deb5['id'],{'autoreplyExecuted':!![]})['then'](function(_0x2d3027){logger[_0x897d('0x12')](_0x897d('0x45'),_0x3bf46b,JSON[_0x897d('0x41')](_0x2d3027));})['catch'](function(_0x2b97de){logger['error']('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x3bf46b,JSON['stringify'](_0x2b97de));});})[_0x897d('0x3c')](function(){_0x4db103[_0x897d('0x17')]();});});}}}catch(_0x3f3638){logger[_0x897d('0x3f')](_0x897d('0x13'),_0x3bf46b,JSON['stringify'](_0x3f3638));_0x4db103[_0x897d('0x48')]();}};};
\ No newline at end of file
+var _0xdd7e=['<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','then','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','resolve','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','finally','update','stop','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../mailRpc','channel','mail','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','interaction','created','next','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','body','getMustacheRender','message','from','phone','read','subject','startsWith','Re:\x20','chat','ChatWebsiteId','account','upperFirst','AccountId','Message','Smtp','service','host','port','secure','authentication','auth','user','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22'];(function(_0x29e801,_0x251732){var _0x35b9e6=function(_0x2f5cfa){while(--_0x2f5cfa){_0x29e801['push'](_0x29e801['shift']());}};_0x35b9e6(++_0x251732);}(_0xdd7e,0xfe));var _0xedd7=function(_0x5c3d42,_0xf2a84c){_0x5c3d42=_0x5c3d42-0x0;var _0xd478b3=_0xdd7e[_0x5c3d42];return _0xd478b3;};'use strict';var _=require(_0xedd7('0x0'));var moment=require(_0xedd7('0x1'));var utils=require(_0xedd7('0x2'));var logger=require(_0xedd7('0x3'))(_0xedd7('0x4'));var rpc={'chatMessage':require(_0xedd7('0x5')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0xedd7('0x6')),'smsMessage':require(_0xedd7('0x7')),'faxMessage':require(_0xedd7('0x8')),'whatsappMessage':require(_0xedd7('0x9')),'chatInteraction':require(_0xedd7('0xa')),'openchannelInteraction':require('../../rpc/openchannelInteraction'),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0xedd7('0xb')),'faxInteraction':require(_0xedd7('0xc')),'whatsappInteraction':require('../../rpc/whatsappInteraction')};var mailRpc=require(_0xedd7('0xd'));exports['consequence']=function(_0x569e2b,_0x37276c,_0x4c261e,_0x3c3c5e){return function(_0x4c8c62){try{var _0x3f0809=this[_0xedd7('0xe')];if(_0x3f0809===_0xedd7('0xf')&&_0x3c3c5e['body']['isAutoreply']){logger[_0xedd7('0x10')](_0xedd7('0x11'),_0x569e2b,_0xedd7('0x12'));return _0x4c8c62['next']();}if(_0x37276c[0x0]==='1'&&(_[_0xedd7('0x13')](this[_0xedd7('0x14')][_0xedd7('0x15')])||!this[_0xedd7('0x14')][_0xedd7('0x15')])){logger[_0xedd7('0x10')](_0xedd7('0x11'),_0x569e2b,'Autoreply\x20already\x20sent');return _0x4c8c62[_0xedd7('0x16')]();}if(_0x37276c[0x0]==='2'&&this[_0xedd7('0x14')][_0xedd7('0x17')]){logger['info'](_0xedd7('0x18'),_0x569e2b,'One\x20Time\x20already\x20sent');return _0x4c8c62[_0xedd7('0x16')]();}var _0x13a14d={'ContactId':this[_0xedd7('0x19')]['id'],'sentAt':moment()[_0xedd7('0x1a')](_0xedd7('0x1b')),'direction':_0xedd7('0x1c')};if(this[_0xedd7('0xe')]===_0xedd7('0xf')){_0x13a14d[_0xedd7('0x1d')]=utils['getMustacheRender'](_0x37276c[0x2],this);}else{_0x13a14d[_0xedd7('0x1d')]=utils[_0xedd7('0x1e')](_0x37276c[0x1],this);}if(this[_0xedd7('0x1f')]){_0x13a14d['to']=this['message'][_0xedd7('0x20')]||'';if(this[_0xedd7('0xe')]===_0xedd7('0xf')&&_0x37276c[0x1]==='1'){_0x13a14d['cc']=this[_0xedd7('0x1f')]['cc']||'';}_0x13a14d[_0xedd7('0x20')]=this[_0xedd7('0x1f')]['to']||'';_0x13a14d[_0xedd7('0x21')]=this[_0xedd7('0x1f')][_0xedd7('0x21')]||'';_0x13a14d[_0xedd7('0x22')]=!![];if(this[_0xedd7('0x1f')][_0xedd7('0x23')]){_0x13a14d[_0xedd7('0x23')]='';_0x13a14d[_0xedd7('0x23')]+=_[_0xedd7('0x24')](this[_0xedd7('0x1f')][_0xedd7('0x23')],'Re:')?'':_0xedd7('0x25');_0x13a14d[_0xedd7('0x23')]+=this[_0xedd7('0x1f')]['subject'];}}if(this['channel']===_0xedd7('0x26')){_0x13a14d[_0xedd7('0x27')]=this[_0xedd7('0x28')]['id'];}else{_0x13a14d[_[_0xedd7('0x29')](this[_0xedd7('0xe')])+_0xedd7('0x2a')]=this['account']['id'];}_0x13a14d[_[_0xedd7('0x29')](this[_0xedd7('0xe')])+'InteractionId']=this['interaction']['id'];var _0x118e3d=this['interaction'];if(rpc[this['channel']+_0xedd7('0x2b')]){if(this[_0xedd7('0xe')]===_0xedd7('0xf')){var _0x56a4be={'tls':{'rejectUnauthorized':![]}};if(this[_0xedd7('0x28')][_0xedd7('0x2c')][_0xedd7('0x2d')]){_0x56a4be[_0xedd7('0x2d')]=this['account']['Smtp'][_0xedd7('0x2d')];}else{_0x56a4be[_0xedd7('0x2e')]=this[_0xedd7('0x28')]['Smtp']['host'];_0x56a4be[_0xedd7('0x2f')]=this['account'][_0xedd7('0x2c')]['port'];_0x56a4be[_0xedd7('0x30')]=this[_0xedd7('0x28')][_0xedd7('0x2c')][_0xedd7('0x30')];}if(this[_0xedd7('0x28')][_0xedd7('0x2c')][_0xedd7('0x31')]){_0x56a4be[_0xedd7('0x32')]={'user':this[_0xedd7('0x28')][_0xedd7('0x2c')][_0xedd7('0x33')],'pass':this[_0xedd7('0x28')]['Smtp']['pass']};}_0x13a14d[_0xedd7('0x34')]=this[_0xedd7('0x1f')][_0xedd7('0x35')];_0x13a14d[_0xedd7('0x36')]=_0xedd7('0x37')+_[_0xedd7('0x38')](_0x13a14d[_0xedd7('0x1d')],_0xedd7('0x39'),_0xedd7('0x3a'))+_0xedd7('0x3b');_0x13a14d[_0xedd7('0x3c')]={'Auto-Submitted':_0xedd7('0x3d'),'X-Auto-Response-Suppress':_0xedd7('0x3e'),'Precedence':_0xedd7('0x3f')};return mailRpc[_0xedd7('0x40')](_0x56a4be,_0x13a14d)['then'](function(_0x5cd7a3){logger[_0xedd7('0x10')](_0xedd7('0x41'),_0x569e2b);_0x13a14d['messageId']=_0x5cd7a3[_0xedd7('0x1f')][_0xedd7('0x35')];return rpc[_0x3f0809+_0xedd7('0x2b')][_0xedd7('0x42')](_0x13a14d);})[_0xedd7('0x43')](function(_0x1896e5){logger['info'](_0xedd7('0x11'),_0x569e2b,JSON[_0xedd7('0x44')](_0x1896e5));})[_0xedd7('0x45')](function(_0x94a71f){logger[_0xedd7('0x46')](_0xedd7('0x47'),_0x569e2b,JSON[_0xedd7('0x44')](_0x94a71f));})['finally'](function(){Promise[_0xedd7('0x48')]()[_0xedd7('0x43')](function(){if(_0x37276c[0x0]!=='2'||_0x118e3d[_0xedd7('0x17')])return;return rpc[_0x3f0809+_0xedd7('0x49')]['update'](_0x118e3d['id'],{'autoreplyExecuted':!![]})[_0xedd7('0x43')](function(_0x814e2d){logger[_0xedd7('0x10')](_0xedd7('0x18'),_0x569e2b,JSON[_0xedd7('0x44')](_0x814e2d));})[_0xedd7('0x45')](function(_0x42f9fe){logger['error'](_0xedd7('0x4a'),_0x569e2b,JSON[_0xedd7('0x44')](_0x42f9fe));});})[_0xedd7('0x43')](function(){_0x4c8c62[_0xedd7('0x16')]();});});}else{return rpc[this[_0xedd7('0xe')]+'Message'][_0xedd7('0x42')](_0x13a14d)[_0xedd7('0x43')](function(_0x41a9d9){logger[_0xedd7('0x10')]('[%s][AUTOREPLY]\x20%s',_0x569e2b,_0x13a14d['body']);})[_0xedd7('0x45')](function(_0x716515){logger['error'](_0xedd7('0x11'),_0x569e2b,JSON[_0xedd7('0x44')](_0x716515));})[_0xedd7('0x4b')](function(){Promise[_0xedd7('0x48')]()['then'](function(){if(_0x37276c[0x0]!=='2'||_0x118e3d['autoreplyExecuted'])return;return rpc[_0x3f0809+'Interaction'][_0xedd7('0x4c')](_0x118e3d['id'],{'autoreplyExecuted':!![]})[_0xedd7('0x43')](function(_0xa42f5a){logger['info'](_0xedd7('0x18'),_0x569e2b,JSON[_0xedd7('0x44')](_0xa42f5a));})[_0xedd7('0x45')](function(_0x581def){logger[_0xedd7('0x46')](_0xedd7('0x4a'),_0x569e2b,JSON[_0xedd7('0x44')](_0x581def));});})[_0xedd7('0x43')](function(){_0x4c8c62[_0xedd7('0x16')]();});});}}}catch(_0x22bab8){logger[_0xedd7('0x46')]('[%s][AUTOREPLY]\x20%s',_0x569e2b,JSON['stringify'](_0x22bab8));_0x4c8c62[_0xedd7('0x4d')]();}};};
\ No newline at end of file