Built motion from commit f67b3b02.|2.6.31
[motion2.git] / server / services / routing / server / applications / autoreply.js
index 349da6e..6086461 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9f90=['Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','headers','auto-replied','All','auto_reply','smtpOptions','[%s][AUTOREPLY]\x20SMTP\x20SENT','stringify','catch','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','update','then','error','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/whatsappInteraction','../../mailRpc','channel','mail','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','next','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','out','getMustacheRender','message','from','phone','read','subject','Re:\x20','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','interaction'];(function(_0x3735de,_0x31dbd8){var _0x35b62e=function(_0x367552){while(--_0x367552){_0x3735de['push'](_0x3735de['shift']());}};_0x35b62e(++_0x31dbd8);}(_0x9f90,0x167));var _0x09f9=function(_0x46bba8,_0x4f4deb){_0x46bba8=_0x46bba8-0x0;var _0x260270=_0x9f90[_0x46bba8];return _0x260270;};'use strict';var _=require(_0x09f9('0x0'));var moment=require(_0x09f9('0x1'));var utils=require(_0x09f9('0x2'));var logger=require(_0x09f9('0x3'))(_0x09f9('0x4'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x09f9('0x5')),'mailMessage':require(_0x09f9('0x6')),'smsMessage':require(_0x09f9('0x7')),'faxMessage':require(_0x09f9('0x8')),'whatsappMessage':require(_0x09f9('0x9')),'chatInteraction':require('../../rpc/chatInteraction'),'openchannelInteraction':require(_0x09f9('0xa')),'mailInteraction':require(_0x09f9('0xb')),'smsInteraction':require(_0x09f9('0xc')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0x09f9('0xd'))};var mailRpc=require(_0x09f9('0xe'));exports['consequence']=function(_0x9539bc,_0x2aafee,_0x505bc4,_0xf5b8ac){return function(_0x15200b){try{var _0x383ec2=this[_0x09f9('0xf')];if(_0x383ec2===_0x09f9('0x10')&&_0xf5b8ac[_0x09f9('0x11')][_0x09f9('0x12')]){logger[_0x09f9('0x13')](_0x09f9('0x14'),_0x9539bc,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x15200b[_0x09f9('0x15')]();}if(_0x2aafee[0x0]==='1'&&(_['isNil'](this['interaction'][_0x09f9('0x16')])||!this['interaction'][_0x09f9('0x16')])){logger[_0x09f9('0x13')](_0x09f9('0x14'),_0x9539bc,_0x09f9('0x17'));return _0x15200b[_0x09f9('0x15')]();}if(_0x2aafee[0x0]==='2'&&this['interaction'][_0x09f9('0x18')]){logger[_0x09f9('0x13')](_0x09f9('0x19'),_0x9539bc,_0x09f9('0x1a'));return _0x15200b[_0x09f9('0x15')]();}var _0x1c4101={'ContactId':this[_0x09f9('0x1b')]['id'],'sentAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x09f9('0x1c')};if(this[_0x09f9('0xf')]===_0x09f9('0x10')){_0x1c4101[_0x09f9('0x11')]=utils[_0x09f9('0x1d')](_0x2aafee[0x2],this);}else{_0x1c4101[_0x09f9('0x11')]=utils[_0x09f9('0x1d')](_0x2aafee[0x1],this);}if(this[_0x09f9('0x1e')]){_0x1c4101['to']=this[_0x09f9('0x1e')]['from']||'';if(this[_0x09f9('0xf')]==='mail'&&_0x2aafee[0x1]==='1'){_0x1c4101['cc']=this['message']['cc']||'';}_0x1c4101[_0x09f9('0x1f')]=this[_0x09f9('0x1e')]['to']||'';_0x1c4101[_0x09f9('0x20')]=this[_0x09f9('0x1e')][_0x09f9('0x20')]||'';_0x1c4101[_0x09f9('0x21')]=!![];if(this[_0x09f9('0x1e')][_0x09f9('0x22')]){_0x1c4101[_0x09f9('0x22')]='';_0x1c4101[_0x09f9('0x22')]+=_['startsWith'](this[_0x09f9('0x1e')][_0x09f9('0x22')],'Re:')?'':_0x09f9('0x23');_0x1c4101[_0x09f9('0x22')]+=this[_0x09f9('0x1e')][_0x09f9('0x22')];}}if(this[_0x09f9('0xf')]===_0x09f9('0x24')){_0x1c4101[_0x09f9('0x25')]=this[_0x09f9('0x26')]['id'];}else{_0x1c4101[_[_0x09f9('0x27')](this[_0x09f9('0xf')])+_0x09f9('0x28')]=this[_0x09f9('0x26')]['id'];}_0x1c4101[_[_0x09f9('0x27')](this[_0x09f9('0xf')])+_0x09f9('0x29')]=this['interaction']['id'];var _0x3ff6d1=this[_0x09f9('0x2a')];if(rpc[this[_0x09f9('0xf')]+_0x09f9('0x2b')]){if(this[_0x09f9('0xf')]===_0x09f9('0x10')){_0x1c4101[_0x09f9('0x2c')]=this[_0x09f9('0x1e')][_0x09f9('0x2d')];_0x1c4101[_0x09f9('0x2e')]=_0x09f9('0x2f')+_[_0x09f9('0x30')](_0x1c4101['body'],_0x09f9('0x31'),_0x09f9('0x32'))+'</div>';_0x1c4101[_0x09f9('0x33')]={'Auto-Submitted':_0x09f9('0x34'),'X-Auto-Response-Suppress':_0x09f9('0x35'),'Precedence':_0x09f9('0x36')};return mailRpc['sendMailMessage'](this[_0x09f9('0x26')][_0x09f9('0x37')],_0x1c4101)['then'](function(_0x554406){logger[_0x09f9('0x13')](_0x09f9('0x38'),_0x9539bc);_0x1c4101[_0x09f9('0x2d')]=_0x554406['message']['messageId'];return rpc[_0x383ec2+'Message']['create'](_0x1c4101);})['then'](function(_0x512f52){logger['info']('[%s][AUTOREPLY]\x20%s',_0x9539bc,JSON[_0x09f9('0x39')](_0x512f52));})[_0x09f9('0x3a')](function(_0x598a32){logger['error'](_0x09f9('0x3b'),_0x9539bc,JSON[_0x09f9('0x39')](_0x598a32));})[_0x09f9('0x3c')](function(){Promise[_0x09f9('0x3d')]()['then'](function(){if(_0x2aafee[0x0]!=='2'||_0x3ff6d1[_0x09f9('0x18')])return;return rpc[_0x383ec2+'Interaction'][_0x09f9('0x3e')](_0x3ff6d1['id'],{'autoreplyExecuted':!![]})[_0x09f9('0x3f')](function(_0x5b9eda){logger[_0x09f9('0x13')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x9539bc,JSON['stringify'](_0x5b9eda));})[_0x09f9('0x3a')](function(_0x356728){logger[_0x09f9('0x40')](_0x09f9('0x41'),_0x9539bc,JSON['stringify'](_0x356728));});})[_0x09f9('0x3f')](function(){_0x15200b['next']();});});}else{return rpc[this[_0x09f9('0xf')]+'Message']['create'](_0x1c4101)['then'](function(){logger[_0x09f9('0x13')](_0x09f9('0x14'),_0x9539bc,_0x1c4101[_0x09f9('0x11')]);})[_0x09f9('0x3a')](function(_0x518096){logger['error']('[%s][AUTOREPLY]\x20%s',_0x9539bc,JSON['stringify'](_0x518096));})[_0x09f9('0x3c')](function(){Promise[_0x09f9('0x3d')]()['then'](function(){if(_0x2aafee[0x0]!=='2'||_0x3ff6d1['autoreplyExecuted'])return;return rpc[_0x383ec2+'Interaction']['update'](_0x3ff6d1['id'],{'autoreplyExecuted':!![]})['then'](function(_0x570d82){logger[_0x09f9('0x13')](_0x09f9('0x19'),_0x9539bc,JSON['stringify'](_0x570d82));})[_0x09f9('0x3a')](function(_0x2314dc){logger[_0x09f9('0x40')](_0x09f9('0x41'),_0x9539bc,JSON[_0x09f9('0x39')](_0x2314dc));});})[_0x09f9('0x3f')](function(){_0x15200b[_0x09f9('0x15')]();});});}}}catch(_0x4e8ca4){logger['error'](_0x09f9('0x14'),_0x9539bc,JSON['stringify'](_0x4e8ca4));_0x15200b[_0x09f9('0x42')]();}};};
\ No newline at end of file
+var _0x2628=['getMustacheRender','message','from','phone','read','subject','Re:','Re:\x20','chat','ChatWebsiteId','account','upperFirst','AccountId','Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','auto-replied','All','smtpOptions','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','stringify','error','[RPC][%s][AUTOREPLY]\x20%s','resolve','then','Interaction','update','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','catch','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','finally','stop','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','consequence','channel','mail','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','next','isNil','interaction','created','autoreplyExecuted','contact','format','YYYY-MM-DD\x20HH:mm:ss','out'];(function(_0x43722e,_0x2e4c37){var _0x4c6e18=function(_0x45cc4f){while(--_0x45cc4f){_0x43722e['push'](_0x43722e['shift']());}};_0x4c6e18(++_0x2e4c37);}(_0x2628,0x1be));var _0x8262=function(_0x465e90,_0x82f15){_0x465e90=_0x465e90-0x0;var _0x51a1db=_0x2628[_0x465e90];return _0x51a1db;};'use strict';var _=require('lodash');var moment=require(_0x8262('0x0'));var utils=require(_0x8262('0x1'));var logger=require(_0x8262('0x2'))(_0x8262('0x3'));var rpc={'chatMessage':require(_0x8262('0x4')),'openchannelMessage':require(_0x8262('0x5')),'mailMessage':require(_0x8262('0x6')),'smsMessage':require(_0x8262('0x7')),'faxMessage':require(_0x8262('0x8')),'whatsappMessage':require(_0x8262('0x9')),'chatInteraction':require(_0x8262('0xa')),'openchannelInteraction':require(_0x8262('0xb')),'mailInteraction':require(_0x8262('0xc')),'smsInteraction':require(_0x8262('0xd')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require('../../rpc/whatsappInteraction')};var mailRpc=require('../../mailRpc');exports[_0x8262('0xe')]=function(_0x5186fb,_0x43d082,_0x517723,_0x29aebe){return function(_0x1f60b2){try{var _0x756f7e=this[_0x8262('0xf')];if(_0x756f7e===_0x8262('0x10')&&_0x29aebe[_0x8262('0x11')][_0x8262('0x12')]){logger[_0x8262('0x13')](_0x8262('0x14'),_0x5186fb,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x1f60b2[_0x8262('0x15')]();}if(_0x43d082[0x0]==='1'&&(_[_0x8262('0x16')](this[_0x8262('0x17')][_0x8262('0x18')])||!this[_0x8262('0x17')][_0x8262('0x18')])){logger[_0x8262('0x13')](_0x8262('0x14'),_0x5186fb,'Autoreply\x20already\x20sent');return _0x1f60b2['next']();}if(_0x43d082[0x0]==='2'&&this[_0x8262('0x17')][_0x8262('0x19')]){logger[_0x8262('0x13')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5186fb,'One\x20Time\x20already\x20sent');return _0x1f60b2[_0x8262('0x15')]();}var _0x45d171={'ContactId':this[_0x8262('0x1a')]['id'],'sentAt':moment()[_0x8262('0x1b')](_0x8262('0x1c')),'direction':_0x8262('0x1d')};if(this[_0x8262('0xf')]==='mail'){_0x45d171[_0x8262('0x11')]=utils['getMustacheRender'](_0x43d082[0x2],this);}else{_0x45d171['body']=utils[_0x8262('0x1e')](_0x43d082[0x1],this);}if(this[_0x8262('0x1f')]){_0x45d171['to']=this['message']['from']||'';if(this[_0x8262('0xf')]===_0x8262('0x10')&&_0x43d082[0x1]==='1'){_0x45d171['cc']=this[_0x8262('0x1f')]['cc']||'';}_0x45d171[_0x8262('0x20')]=this['message']['to']||'';_0x45d171[_0x8262('0x21')]=this['message'][_0x8262('0x21')]||'';_0x45d171[_0x8262('0x22')]=!![];if(this[_0x8262('0x1f')]['subject']){_0x45d171[_0x8262('0x23')]='';_0x45d171['subject']+=_['startsWith'](this[_0x8262('0x1f')][_0x8262('0x23')],_0x8262('0x24'))?'':_0x8262('0x25');_0x45d171['subject']+=this['message'][_0x8262('0x23')];}}if(this[_0x8262('0xf')]===_0x8262('0x26')){_0x45d171[_0x8262('0x27')]=this[_0x8262('0x28')]['id'];}else{_0x45d171[_[_0x8262('0x29')](this['channel'])+_0x8262('0x2a')]=this[_0x8262('0x28')]['id'];}_0x45d171[_[_0x8262('0x29')](this[_0x8262('0xf')])+'InteractionId']=this[_0x8262('0x17')]['id'];var _0x2e3237=this[_0x8262('0x17')];if(rpc[this[_0x8262('0xf')]+_0x8262('0x2b')]){if(this['channel']==='mail'){_0x45d171[_0x8262('0x2c')]=this[_0x8262('0x1f')][_0x8262('0x2d')];_0x45d171[_0x8262('0x2e')]=_0x8262('0x2f')+_[_0x8262('0x30')](_0x45d171[_0x8262('0x11')],_0x8262('0x31'),_0x8262('0x32'))+'</div>';_0x45d171['headers']={'Auto-Submitted':_0x8262('0x33'),'X-Auto-Response-Suppress':_0x8262('0x34'),'Precedence':'auto_reply'};return mailRpc['sendMailMessage'](this[_0x8262('0x28')][_0x8262('0x35')],_0x45d171)['then'](function(_0x1d5c48){logger[_0x8262('0x13')](_0x8262('0x36'),_0x5186fb);_0x45d171[_0x8262('0x2d')]=_0x1d5c48[_0x8262('0x1f')][_0x8262('0x2d')];return rpc[_0x756f7e+_0x8262('0x2b')][_0x8262('0x37')](_0x45d171);})['then'](function(_0x2a1966){logger[_0x8262('0x13')](_0x8262('0x14'),_0x5186fb,JSON[_0x8262('0x38')](_0x2a1966));})['catch'](function(_0x3fae59){logger[_0x8262('0x39')](_0x8262('0x3a'),_0x5186fb,JSON[_0x8262('0x38')](_0x3fae59));})['finally'](function(){Promise[_0x8262('0x3b')]()[_0x8262('0x3c')](function(){if(_0x43d082[0x0]!=='2'||_0x2e3237[_0x8262('0x19')])return;return rpc[_0x756f7e+_0x8262('0x3d')][_0x8262('0x3e')](_0x2e3237['id'],{'autoreplyExecuted':!![]})[_0x8262('0x3c')](function(_0x46acc5){logger['info'](_0x8262('0x3f'),_0x5186fb,JSON[_0x8262('0x38')](_0x46acc5));})[_0x8262('0x40')](function(_0x14be6b){logger[_0x8262('0x39')](_0x8262('0x41'),_0x5186fb,JSON[_0x8262('0x38')](_0x14be6b));});})[_0x8262('0x3c')](function(){_0x1f60b2[_0x8262('0x15')]();});});}else{return rpc[this[_0x8262('0xf')]+_0x8262('0x2b')]['create'](_0x45d171)['then'](function(){logger[_0x8262('0x13')](_0x8262('0x14'),_0x5186fb,_0x45d171['body']);})[_0x8262('0x40')](function(_0x1f9d9b){logger['error'](_0x8262('0x14'),_0x5186fb,JSON['stringify'](_0x1f9d9b));})[_0x8262('0x42')](function(){Promise['resolve']()[_0x8262('0x3c')](function(){if(_0x43d082[0x0]!=='2'||_0x2e3237[_0x8262('0x19')])return;return rpc[_0x756f7e+_0x8262('0x3d')]['update'](_0x2e3237['id'],{'autoreplyExecuted':!![]})[_0x8262('0x3c')](function(_0x217fdb){logger[_0x8262('0x13')](_0x8262('0x3f'),_0x5186fb,JSON[_0x8262('0x38')](_0x217fdb));})['catch'](function(_0x554a19){logger[_0x8262('0x39')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5186fb,JSON['stringify'](_0x554a19));});})[_0x8262('0x3c')](function(){_0x1f60b2[_0x8262('0x15')]();});});}}}catch(_0x189274){logger[_0x8262('0x39')]('[%s][AUTOREPLY]\x20%s',_0x5186fb,JSON[_0x8262('0x38')](_0x189274));_0x1f60b2[_0x8262('0x43')]();}};};
\ No newline at end of file