Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / services / routing / server / applications / autoreply.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x7eaf=['../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','isAutoreply','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','info','Autoreply\x20already\x20sent','interaction','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','body','getMustacheRender','message','from','phone','read','startsWith','subject','Re:','Re:\x20','ChatWebsiteId','account','channel','upperFirst','InteractionId','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','</div>','All','auto_reply','sendMailMessage','smtpOptions','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','create','then','stringify','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','catch','stop','lodash','./utils'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x7eaf,0x122));var _0xf7ea=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x7eaf[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xf7ea('0x0'));var moment=require('moment');var utils=require(_0xf7ea('0x1'));var logger=require(_0xf7ea('0x2'))(_0xf7ea('0x3'));var rpc={'chatMessage':require(_0xf7ea('0x4')),'openchannelMessage':require(_0xf7ea('0x5')),'mailMessage':require(_0xf7ea('0x6')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xf7ea('0x7')),'whatsappMessage':require(_0xf7ea('0x8')),'chatInteraction':require(_0xf7ea('0x9')),'openchannelInteraction':require(_0xf7ea('0xa')),'mailInteraction':require(_0xf7ea('0xb')),'smsInteraction':require(_0xf7ea('0xc')),'faxInteraction':require(_0xf7ea('0xd')),'whatsappInteraction':require(_0xf7ea('0xe'))};var mailRpc=require(_0xf7ea('0xf'));exports[_0xf7ea('0x10')]=function(_0x1e50f5,_0x23e685,_0x4ba748,_0x1782f0){return function(_0x458cb8){try{var _0x186725=this['channel'];if(_0x186725===_0xf7ea('0x11')&&_0x1782f0['body'][_0xf7ea('0x12')]){logger['info'](_0xf7ea('0x13'),_0x1e50f5,_0xf7ea('0x14'));return _0x458cb8[_0xf7ea('0x15')]();}if(_0x23e685[0x0]==='1'&&(_[_0xf7ea('0x16')](this['interaction']['created'])||!this['interaction']['created'])){logger[_0xf7ea('0x17')]('[%s][AUTOREPLY]\x20%s',_0x1e50f5,_0xf7ea('0x18'));return _0x458cb8[_0xf7ea('0x15')]();}if(_0x23e685[0x0]==='2'&&this[_0xf7ea('0x19')][_0xf7ea('0x1a')]){logger[_0xf7ea('0x17')](_0xf7ea('0x1b'),_0x1e50f5,_0xf7ea('0x1c'));return _0x458cb8[_0xf7ea('0x15')]();}var _0x2778a1={'ContactId':this[_0xf7ea('0x1d')]['id'],'sentAt':moment()[_0xf7ea('0x1e')](_0xf7ea('0x1f')),'direction':_0xf7ea('0x20')};if(this['channel']===_0xf7ea('0x11')){_0x2778a1[_0xf7ea('0x21')]=utils[_0xf7ea('0x22')](_0x23e685[0x2],this);}else{_0x2778a1[_0xf7ea('0x21')]=utils['getMustacheRender'](_0x23e685[0x1],this);}if(this['message']){_0x2778a1['to']=this[_0xf7ea('0x23')][_0xf7ea('0x24')]||'';if(this['channel']===_0xf7ea('0x11')&&_0x23e685[0x1]==='1'){_0x2778a1['cc']=this['message']['cc']||'';}_0x2778a1[_0xf7ea('0x24')]=this[_0xf7ea('0x23')]['to']||'';_0x2778a1[_0xf7ea('0x25')]=this[_0xf7ea('0x23')][_0xf7ea('0x25')]||'';_0x2778a1[_0xf7ea('0x26')]=!![];if(this['message']['subject']){_0x2778a1['subject']='';_0x2778a1['subject']+=_[_0xf7ea('0x27')](this[_0xf7ea('0x23')][_0xf7ea('0x28')],_0xf7ea('0x29'))?'':_0xf7ea('0x2a');_0x2778a1[_0xf7ea('0x28')]+=this[_0xf7ea('0x23')][_0xf7ea('0x28')];}}if(this['channel']==='chat'){_0x2778a1[_0xf7ea('0x2b')]=this[_0xf7ea('0x2c')]['id'];}else{_0x2778a1[_['upperFirst'](this[_0xf7ea('0x2d')])+'AccountId']=this[_0xf7ea('0x2c')]['id'];}_0x2778a1[_[_0xf7ea('0x2e')](this[_0xf7ea('0x2d')])+_0xf7ea('0x2f')]=this[_0xf7ea('0x19')]['id'];var _0x18e54a=this[_0xf7ea('0x19')];if(rpc[this[_0xf7ea('0x2d')]+'Message']){if(this['channel']===_0xf7ea('0x11')){_0x2778a1[_0xf7ea('0x30')]=this[_0xf7ea('0x23')][_0xf7ea('0x31')];_0x2778a1[_0xf7ea('0x32')]=_0xf7ea('0x33')+_[_0xf7ea('0x34')](_0x2778a1[_0xf7ea('0x21')],_0xf7ea('0x35'),'<div')+_0xf7ea('0x36');_0x2778a1['headers']={'Auto-Submitted':'auto-replied','X-Auto-Response-Suppress':_0xf7ea('0x37'),'Precedence':_0xf7ea('0x38')};return mailRpc[_0xf7ea('0x39')](this[_0xf7ea('0x2c')][_0xf7ea('0x3a')],_0x2778a1)['then'](function(_0x28db25){logger[_0xf7ea('0x17')](_0xf7ea('0x3b'),_0x1e50f5);_0x2778a1[_0xf7ea('0x31')]=_0x28db25[_0xf7ea('0x23')][_0xf7ea('0x31')];return rpc[_0x186725+_0xf7ea('0x3c')][_0xf7ea('0x3d')](_0x2778a1);})[_0xf7ea('0x3e')](function(_0x230077){logger['info'](_0xf7ea('0x13'),_0x1e50f5,JSON[_0xf7ea('0x3f')](_0x230077));})['catch'](function(_0xba088d){logger[_0xf7ea('0x40')](_0xf7ea('0x41'),_0x1e50f5,JSON['stringify'](_0xba088d));})[_0xf7ea('0x42')](function(){Promise[_0xf7ea('0x43')]()[_0xf7ea('0x3e')](function(){if(_0x23e685[0x0]!=='2'||_0x18e54a[_0xf7ea('0x1a')])return;return rpc[_0x186725+_0xf7ea('0x44')][_0xf7ea('0x45')](_0x18e54a['id'],{'autoreplyExecuted':!![]})[_0xf7ea('0x3e')](function(_0x4b9a74){logger[_0xf7ea('0x17')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x1e50f5,JSON[_0xf7ea('0x3f')](_0x4b9a74));})['catch'](function(_0x91c113){logger[_0xf7ea('0x40')](_0xf7ea('0x46'),_0x1e50f5,JSON[_0xf7ea('0x3f')](_0x91c113));});})[_0xf7ea('0x3e')](function(){_0x458cb8[_0xf7ea('0x15')]();});});}else{return rpc[this[_0xf7ea('0x2d')]+_0xf7ea('0x3c')]['create'](_0x2778a1)['then'](function(){logger[_0xf7ea('0x17')](_0xf7ea('0x13'),_0x1e50f5,_0x2778a1[_0xf7ea('0x21')]);})[_0xf7ea('0x47')](function(_0x1dec40){logger[_0xf7ea('0x40')]('[%s][AUTOREPLY]\x20%s',_0x1e50f5,JSON[_0xf7ea('0x3f')](_0x1dec40));})[_0xf7ea('0x42')](function(){Promise['resolve']()[_0xf7ea('0x3e')](function(){if(_0x23e685[0x0]!=='2'||_0x18e54a[_0xf7ea('0x1a')])return;return rpc[_0x186725+_0xf7ea('0x44')][_0xf7ea('0x45')](_0x18e54a['id'],{'autoreplyExecuted':!![]})[_0xf7ea('0x3e')](function(_0x1fefcc){logger[_0xf7ea('0x17')](_0xf7ea('0x1b'),_0x1e50f5,JSON[_0xf7ea('0x3f')](_0x1fefcc));})[_0xf7ea('0x47')](function(_0xa98da6){logger['error']('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x1e50f5,JSON['stringify'](_0xa98da6));});})[_0xf7ea('0x3e')](function(){_0x458cb8[_0xf7ea('0x15')]();});});}}}catch(_0x468c50){logger[_0xf7ea('0x40')](_0xf7ea('0x13'),_0x1e50f5,JSON['stringify'](_0x468c50));_0x458cb8[_0xf7ea('0x48')]();}};};