Built motion from commit f16df95f.|2.5.40
[motion2.git] / server / services / routing / server / applications / autoreply.js
index 8de195b..c7c70d2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x88a0=['../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','channel','mail','isAutoreply','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','phone','subject','startsWith','Re:','upperFirst','AccountId','InteractionId','Message','account','Smtp','service','port','secure','authentication','auth','user','pass','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','then','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','moment','../../../../config/logger','routing','../../rpc/chatMessage'];(function(_0x397e5f,_0x454c8f){var _0x5302b8=function(_0x1a29ef){while(--_0x1a29ef){_0x397e5f['push'](_0x397e5f['shift']());}};_0x5302b8(++_0x454c8f);}(_0x88a0,0xd7));var _0x088a=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0x88a0[_0x2dafbe];return _0x58a45a;};'use strict';var _=require('lodash');var moment=require(_0x088a('0x0'));var utils=require('./utils');var logger=require(_0x088a('0x1'))(_0x088a('0x2'));var rpc={'chatMessage':require(_0x088a('0x3')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x088a('0x4')),'smsMessage':require(_0x088a('0x5')),'faxMessage':require(_0x088a('0x6')),'whatsappMessage':require('../../rpc/whatsappMessage'),'chatInteraction':require(_0x088a('0x7')),'openchannelInteraction':require(_0x088a('0x8')),'mailInteraction':require(_0x088a('0x9')),'smsInteraction':require(_0x088a('0xa')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0x088a('0xb'))};var mailRpc=require(_0x088a('0xc'));exports[_0x088a('0xd')]=function(_0x1fb85d,_0x3a2b8a,_0x166d2e,_0x116e64){return function(_0x3d623f){try{var _0x195f8d=this[_0x088a('0xe')];if(_0x195f8d===_0x088a('0xf')&&_0x116e64['body'][_0x088a('0x10')]){logger[_0x088a('0x11')](_0x088a('0x12'),_0x1fb85d,_0x088a('0x13'));return _0x3d623f['next']();}if(_0x3a2b8a[0x0]==='1'&&(_[_0x088a('0x14')](this[_0x088a('0x15')][_0x088a('0x16')])||!this['interaction'][_0x088a('0x16')])){logger['info'](_0x088a('0x12'),_0x1fb85d,'Autoreply\x20already\x20sent');return _0x3d623f[_0x088a('0x17')]();}if(_0x3a2b8a[0x0]==='2'&&this[_0x088a('0x15')][_0x088a('0x18')]){logger[_0x088a('0x11')](_0x088a('0x19'),_0x1fb85d,'One\x20Time\x20already\x20sent');return _0x3d623f[_0x088a('0x17')]();}var _0x494a9a={'ContactId':this[_0x088a('0x1a')]['id'],'sentAt':moment()[_0x088a('0x1b')](_0x088a('0x1c')),'direction':_0x088a('0x1d')};if(this[_0x088a('0xe')]===_0x088a('0xf')){_0x494a9a[_0x088a('0x1e')]=utils['getMustacheRender'](_0x3a2b8a[0x2],this);}else{_0x494a9a[_0x088a('0x1e')]=utils[_0x088a('0x1f')](_0x3a2b8a[0x1],this);}if(this[_0x088a('0x20')]){_0x494a9a['to']=this[_0x088a('0x20')]['from']||'';if(this[_0x088a('0xe')]==='mail'&&_0x3a2b8a[0x1]==='1'){_0x494a9a['cc']=this[_0x088a('0x20')]['cc']||'';}_0x494a9a['from']=this[_0x088a('0x20')]['to']||'';_0x494a9a[_0x088a('0x21')]=this['message'][_0x088a('0x21')]||'';_0x494a9a['read']=!![];if(this['message'][_0x088a('0x22')]){_0x494a9a[_0x088a('0x22')]='';_0x494a9a['subject']+=_[_0x088a('0x23')](this[_0x088a('0x20')][_0x088a('0x22')],_0x088a('0x24'))?'':'Re:\x20';_0x494a9a['subject']+=this[_0x088a('0x20')]['subject'];}}if(this[_0x088a('0xe')]==='chat'){_0x494a9a['ChatWebsiteId']=this['account']['id'];}else{_0x494a9a[_[_0x088a('0x25')](this['channel'])+_0x088a('0x26')]=this['account']['id'];}_0x494a9a[_['upperFirst'](this[_0x088a('0xe')])+_0x088a('0x27')]=this[_0x088a('0x15')]['id'];var _0x5d362b=this[_0x088a('0x15')];if(rpc[this['channel']+_0x088a('0x28')]){if(this[_0x088a('0xe')]===_0x088a('0xf')){var _0x2ee7ce={'tls':{'rejectUnauthorized':![]}};if(this[_0x088a('0x29')][_0x088a('0x2a')]['service']){_0x2ee7ce['service']=this['account'][_0x088a('0x2a')][_0x088a('0x2b')];}else{_0x2ee7ce['host']=this[_0x088a('0x29')]['Smtp']['host'];_0x2ee7ce[_0x088a('0x2c')]=this['account'][_0x088a('0x2a')][_0x088a('0x2c')];_0x2ee7ce[_0x088a('0x2d')]=this['account'][_0x088a('0x2a')][_0x088a('0x2d')];}if(this[_0x088a('0x29')][_0x088a('0x2a')][_0x088a('0x2e')]){_0x2ee7ce[_0x088a('0x2f')]={'user':this[_0x088a('0x29')][_0x088a('0x2a')][_0x088a('0x30')],'pass':this[_0x088a('0x29')][_0x088a('0x2a')][_0x088a('0x31')]};}_0x494a9a[_0x088a('0x32')]=this['message'][_0x088a('0x33')];_0x494a9a[_0x088a('0x34')]='<div\x20id=\x22xm-mail-content\x22>'+_['replace'](_0x494a9a['body'],_0x088a('0x35'),'<div')+_0x088a('0x36');_0x494a9a[_0x088a('0x37')]={'Auto-Submitted':_0x088a('0x38'),'X-Auto-Response-Suppress':_0x088a('0x39'),'Precedence':_0x088a('0x3a')};return mailRpc[_0x088a('0x3b')](_0x2ee7ce,_0x494a9a)['then'](function(_0x56ee68){logger[_0x088a('0x11')](_0x088a('0x3c'),_0x1fb85d);_0x494a9a[_0x088a('0x33')]=_0x56ee68[_0x088a('0x20')][_0x088a('0x33')];return rpc[_0x195f8d+_0x088a('0x28')][_0x088a('0x3d')](_0x494a9a);})['then'](function(_0x258b47){logger[_0x088a('0x11')](_0x088a('0x12'),_0x1fb85d,JSON[_0x088a('0x3e')](_0x258b47));})[_0x088a('0x3f')](function(_0x2555c9){logger[_0x088a('0x40')](_0x088a('0x41'),_0x1fb85d,JSON[_0x088a('0x3e')](_0x2555c9));})[_0x088a('0x42')](function(){Promise[_0x088a('0x43')]()[_0x088a('0x44')](function(){if(_0x3a2b8a[0x0]!=='2'||_0x5d362b[_0x088a('0x18')])return;return rpc[_0x195f8d+_0x088a('0x45')][_0x088a('0x46')](_0x5d362b['id'],{'autoreplyExecuted':!![]})['then'](function(_0x2ca1e8){logger[_0x088a('0x11')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x1fb85d,JSON[_0x088a('0x3e')](_0x2ca1e8));})[_0x088a('0x3f')](function(_0x525ee6){logger[_0x088a('0x40')](_0x088a('0x47'),_0x1fb85d,JSON[_0x088a('0x3e')](_0x525ee6));});})[_0x088a('0x44')](function(){_0x3d623f[_0x088a('0x17')]();});});}else{return rpc[this[_0x088a('0xe')]+_0x088a('0x28')][_0x088a('0x3d')](_0x494a9a)[_0x088a('0x44')](function(_0x42f0a4){logger[_0x088a('0x11')](_0x088a('0x12'),_0x1fb85d,_0x494a9a[_0x088a('0x1e')]);})['catch'](function(_0x260670){logger[_0x088a('0x40')]('[%s][AUTOREPLY]\x20%s',_0x1fb85d,JSON[_0x088a('0x3e')](_0x260670));})[_0x088a('0x42')](function(){Promise[_0x088a('0x43')]()[_0x088a('0x44')](function(){if(_0x3a2b8a[0x0]!=='2'||_0x5d362b[_0x088a('0x18')])return;return rpc[_0x195f8d+'Interaction'][_0x088a('0x46')](_0x5d362b['id'],{'autoreplyExecuted':!![]})['then'](function(_0x5f10ad){logger[_0x088a('0x11')](_0x088a('0x19'),_0x1fb85d,JSON[_0x088a('0x3e')](_0x5f10ad));})[_0x088a('0x3f')](function(_0x21b425){logger[_0x088a('0x40')](_0x088a('0x47'),_0x1fb85d,JSON['stringify'](_0x21b425));});})[_0x088a('0x44')](function(){_0x3d623f[_0x088a('0x17')]();});});}}}catch(_0x24fb5f){logger[_0x088a('0x40')]('[%s][AUTOREPLY]\x20%s',_0x1fb85d,JSON[_0x088a('0x3e')](_0x24fb5f));_0x3d623f[_0x088a('0x48')]();}};};
\ No newline at end of file
+var _0xb7be=['../../rpc/faxMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/whatsappInteraction','consequence','mail','isAutoreply','info','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','interaction','created','[%s][AUTOREPLY]\x20%s','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','body','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','ChatWebsiteId','account','upperFirst','InteractionId','Smtp','service','host','port','secure','authentication','auth','user','pass','inReplyTo','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','</div>','headers','auto-replied','All','auto_reply','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','create','then','stringify','catch','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','autoreplyExecuted','Interaction','error','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','update','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage'];(function(_0x22a75f,_0xf98f1f){var _0x583584=function(_0x48a6cc){while(--_0x48a6cc){_0x22a75f['push'](_0x22a75f['shift']());}};_0x583584(++_0xf98f1f);}(_0xb7be,0xd9));var _0xeb7b=function(_0x3b0339,_0x2eaeae){_0x3b0339=_0x3b0339-0x0;var _0x20bfcd=_0xb7be[_0x3b0339];return _0x20bfcd;};'use strict';var _=require('lodash');var moment=require(_0xeb7b('0x0'));var utils=require(_0xeb7b('0x1'));var logger=require(_0xeb7b('0x2'))(_0xeb7b('0x3'));var rpc={'chatMessage':require(_0xeb7b('0x4')),'openchannelMessage':require(_0xeb7b('0x5')),'mailMessage':require(_0xeb7b('0x6')),'smsMessage':require(_0xeb7b('0x7')),'faxMessage':require(_0xeb7b('0x8')),'whatsappMessage':require('../../rpc/whatsappMessage'),'chatInteraction':require(_0xeb7b('0x9')),'openchannelInteraction':require(_0xeb7b('0xa')),'mailInteraction':require(_0xeb7b('0xb')),'smsInteraction':require('../../rpc/smsInteraction'),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xeb7b('0xc'))};var mailRpc=require('../../mailRpc');exports[_0xeb7b('0xd')]=function(_0x4ec841,_0x413d0c,_0x228780,_0x131e1a){return function(_0x2762de){try{var _0x13423f=this['channel'];if(_0x13423f===_0xeb7b('0xe')&&_0x131e1a['body'][_0xeb7b('0xf')]){logger[_0xeb7b('0x10')]('[%s][AUTOREPLY]\x20%s',_0x4ec841,_0xeb7b('0x11'));return _0x2762de[_0xeb7b('0x12')]();}if(_0x413d0c[0x0]==='1'&&(_[_0xeb7b('0x13')](this[_0xeb7b('0x14')][_0xeb7b('0x15')])||!this[_0xeb7b('0x14')]['created'])){logger['info'](_0xeb7b('0x16'),_0x4ec841,'Autoreply\x20already\x20sent');return _0x2762de[_0xeb7b('0x12')]();}if(_0x413d0c[0x0]==='2'&&this[_0xeb7b('0x14')]['autoreplyExecuted']){logger[_0xeb7b('0x10')](_0xeb7b('0x17'),_0x4ec841,_0xeb7b('0x18'));return _0x2762de[_0xeb7b('0x12')]();}var _0x51ae58={'ContactId':this['contact']['id'],'sentAt':moment()[_0xeb7b('0x19')](_0xeb7b('0x1a')),'direction':_0xeb7b('0x1b')};if(this[_0xeb7b('0x1c')]==='mail'){_0x51ae58[_0xeb7b('0x1d')]=utils[_0xeb7b('0x1e')](_0x413d0c[0x2],this);}else{_0x51ae58['body']=utils[_0xeb7b('0x1e')](_0x413d0c[0x1],this);}if(this[_0xeb7b('0x1f')]){_0x51ae58['to']=this[_0xeb7b('0x1f')][_0xeb7b('0x20')]||'';if(this[_0xeb7b('0x1c')]===_0xeb7b('0xe')&&_0x413d0c[0x1]==='1'){_0x51ae58['cc']=this[_0xeb7b('0x1f')]['cc']||'';}_0x51ae58['from']=this[_0xeb7b('0x1f')]['to']||'';_0x51ae58['phone']=this[_0xeb7b('0x1f')][_0xeb7b('0x21')]||'';_0x51ae58[_0xeb7b('0x22')]=!![];if(this[_0xeb7b('0x1f')][_0xeb7b('0x23')]){_0x51ae58[_0xeb7b('0x23')]='';_0x51ae58['subject']+=_[_0xeb7b('0x24')](this[_0xeb7b('0x1f')][_0xeb7b('0x23')],_0xeb7b('0x25'))?'':'Re:\x20';_0x51ae58[_0xeb7b('0x23')]+=this[_0xeb7b('0x1f')][_0xeb7b('0x23')];}}if(this['channel']==='chat'){_0x51ae58[_0xeb7b('0x26')]=this[_0xeb7b('0x27')]['id'];}else{_0x51ae58[_['upperFirst'](this[_0xeb7b('0x1c')])+'AccountId']=this[_0xeb7b('0x27')]['id'];}_0x51ae58[_[_0xeb7b('0x28')](this[_0xeb7b('0x1c')])+_0xeb7b('0x29')]=this[_0xeb7b('0x14')]['id'];var _0x2ac34e=this[_0xeb7b('0x14')];if(rpc[this[_0xeb7b('0x1c')]+'Message']){if(this[_0xeb7b('0x1c')]===_0xeb7b('0xe')){var _0x4d45ae={'tls':{'rejectUnauthorized':![]}};if(this['account'][_0xeb7b('0x2a')][_0xeb7b('0x2b')]){_0x4d45ae[_0xeb7b('0x2b')]=this[_0xeb7b('0x27')]['Smtp'][_0xeb7b('0x2b')];}else{_0x4d45ae['host']=this[_0xeb7b('0x27')][_0xeb7b('0x2a')][_0xeb7b('0x2c')];_0x4d45ae[_0xeb7b('0x2d')]=this['account']['Smtp'][_0xeb7b('0x2d')];_0x4d45ae[_0xeb7b('0x2e')]=this[_0xeb7b('0x27')]['Smtp']['secure'];}if(this[_0xeb7b('0x27')][_0xeb7b('0x2a')][_0xeb7b('0x2f')]){_0x4d45ae[_0xeb7b('0x30')]={'user':this[_0xeb7b('0x27')][_0xeb7b('0x2a')][_0xeb7b('0x31')],'pass':this['account'][_0xeb7b('0x2a')][_0xeb7b('0x32')]};}_0x51ae58[_0xeb7b('0x33')]=this[_0xeb7b('0x1f')][_0xeb7b('0x34')];_0x51ae58['html']=_0xeb7b('0x35')+_[_0xeb7b('0x36')](_0x51ae58[_0xeb7b('0x1d')],_0xeb7b('0x37'),'<div')+_0xeb7b('0x38');_0x51ae58[_0xeb7b('0x39')]={'Auto-Submitted':_0xeb7b('0x3a'),'X-Auto-Response-Suppress':_0xeb7b('0x3b'),'Precedence':_0xeb7b('0x3c')};return mailRpc['sendMailMessage'](_0x4d45ae,_0x51ae58)['then'](function(_0xedac67){logger[_0xeb7b('0x10')](_0xeb7b('0x3d'),_0x4ec841);_0x51ae58[_0xeb7b('0x34')]=_0xedac67[_0xeb7b('0x1f')][_0xeb7b('0x34')];return rpc[_0x13423f+_0xeb7b('0x3e')][_0xeb7b('0x3f')](_0x51ae58);})[_0xeb7b('0x40')](function(_0x40e948){logger['info'](_0xeb7b('0x16'),_0x4ec841,JSON[_0xeb7b('0x41')](_0x40e948));})[_0xeb7b('0x42')](function(_0x154391){logger['error'](_0xeb7b('0x43'),_0x4ec841,JSON[_0xeb7b('0x41')](_0x154391));})[_0xeb7b('0x44')](function(){Promise[_0xeb7b('0x45')]()[_0xeb7b('0x40')](function(){if(_0x413d0c[0x0]!=='2'||_0x2ac34e[_0xeb7b('0x46')])return;return rpc[_0x13423f+_0xeb7b('0x47')]['update'](_0x2ac34e['id'],{'autoreplyExecuted':!![]})['then'](function(_0x531ad7){logger[_0xeb7b('0x10')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x4ec841,JSON[_0xeb7b('0x41')](_0x531ad7));})[_0xeb7b('0x42')](function(_0x2a4c24){logger[_0xeb7b('0x48')](_0xeb7b('0x49'),_0x4ec841,JSON[_0xeb7b('0x41')](_0x2a4c24));});})[_0xeb7b('0x40')](function(){_0x2762de['next']();});});}else{return rpc[this[_0xeb7b('0x1c')]+'Message']['create'](_0x51ae58)[_0xeb7b('0x40')](function(_0x3e75ff){logger[_0xeb7b('0x10')](_0xeb7b('0x16'),_0x4ec841,_0x51ae58['body']);})[_0xeb7b('0x42')](function(_0x5101cf){logger[_0xeb7b('0x48')](_0xeb7b('0x16'),_0x4ec841,JSON[_0xeb7b('0x41')](_0x5101cf));})[_0xeb7b('0x44')](function(){Promise[_0xeb7b('0x45')]()[_0xeb7b('0x40')](function(){if(_0x413d0c[0x0]!=='2'||_0x2ac34e[_0xeb7b('0x46')])return;return rpc[_0x13423f+_0xeb7b('0x47')][_0xeb7b('0x4a')](_0x2ac34e['id'],{'autoreplyExecuted':!![]})[_0xeb7b('0x40')](function(_0xd01c3c){logger[_0xeb7b('0x10')](_0xeb7b('0x17'),_0x4ec841,JSON[_0xeb7b('0x41')](_0xd01c3c));})['catch'](function(_0x4442f5){logger[_0xeb7b('0x48')](_0xeb7b('0x49'),_0x4ec841,JSON[_0xeb7b('0x41')](_0x4442f5));});})[_0xeb7b('0x40')](function(){_0x2762de[_0xeb7b('0x12')]();});});}}}catch(_0x399dce){logger[_0xeb7b('0x48')]('[%s][AUTOREPLY]\x20%s',_0x4ec841,JSON[_0xeb7b('0x41')](_0x399dce));_0x2762de['stop']();}};};
\ No newline at end of file