687c4a445115c83c8f78393cc6469a66faa7a3be
[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 _0x8ccc=['<div\x20id=\x22xm-mail-content\x22>','<div','</div>','headers','auto-replied','auto_reply','sendMailMessage','smtpOptions','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','then','autoreplyExecuted','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','./utils','routing','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','channel','mail','body','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','interaction','created','Autoreply\x20already\x20sent','next','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','upperFirst','account','InteractionId','Message','inReplyTo','messageId','html'];(function(_0x335a61,_0x21b879){var _0x48a02b=function(_0x2978a8){while(--_0x2978a8){_0x335a61['push'](_0x335a61['shift']());}};_0x48a02b(++_0x21b879);}(_0x8ccc,0x159));var _0xc8cc=function(_0x372e7c,_0x186d77){_0x372e7c=_0x372e7c-0x0;var _0x1b09ae=_0x8ccc[_0x372e7c];return _0x1b09ae;};'use strict';var _=require('lodash');var moment=require('moment');var utils=require(_0xc8cc('0x0'));var logger=require('../../../../config/logger')(_0xc8cc('0x1'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xc8cc('0x2')),'whatsappMessage':require(_0xc8cc('0x3')),'chatInteraction':require(_0xc8cc('0x4')),'openchannelInteraction':require(_0xc8cc('0x5')),'mailInteraction':require(_0xc8cc('0x6')),'smsInteraction':require('../../rpc/smsInteraction'),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xc8cc('0x7'))};var mailRpc=require(_0xc8cc('0x8'));exports[_0xc8cc('0x9')]=function(_0x3f4ef6,_0x1bd5c5,_0x264605,_0x860819){return function(_0x3d38ea){try{var _0x351d41=this[_0xc8cc('0xa')];if(_0x351d41===_0xc8cc('0xb')&&_0x860819[_0xc8cc('0xc')]['isAutoreply']){logger[_0xc8cc('0xd')](_0xc8cc('0xe'),_0x3f4ef6,_0xc8cc('0xf'));return _0x3d38ea['next']();}if(_0x1bd5c5[0x0]==='1'&&(_[_0xc8cc('0x10')](this[_0xc8cc('0x11')][_0xc8cc('0x12')])||!this[_0xc8cc('0x11')][_0xc8cc('0x12')])){logger[_0xc8cc('0xd')](_0xc8cc('0xe'),_0x3f4ef6,_0xc8cc('0x13'));return _0x3d38ea[_0xc8cc('0x14')]();}if(_0x1bd5c5[0x0]==='2'&&this[_0xc8cc('0x11')]['autoreplyExecuted']){logger[_0xc8cc('0xd')](_0xc8cc('0x15'),_0x3f4ef6,_0xc8cc('0x16'));return _0x3d38ea['next']();}var _0x5bcc64={'ContactId':this[_0xc8cc('0x17')]['id'],'sentAt':moment()[_0xc8cc('0x18')](_0xc8cc('0x19')),'direction':_0xc8cc('0x1a')};if(this[_0xc8cc('0xa')]===_0xc8cc('0xb')){_0x5bcc64[_0xc8cc('0xc')]=utils[_0xc8cc('0x1b')](_0x1bd5c5[0x2],this);}else{_0x5bcc64[_0xc8cc('0xc')]=utils[_0xc8cc('0x1b')](_0x1bd5c5[0x1],this);}if(this[_0xc8cc('0x1c')]){_0x5bcc64['to']=this[_0xc8cc('0x1c')]['from']||'';if(this['channel']==='mail'&&_0x1bd5c5[0x1]==='1'){_0x5bcc64['cc']=this[_0xc8cc('0x1c')]['cc']||'';}_0x5bcc64[_0xc8cc('0x1d')]=this[_0xc8cc('0x1c')]['to']||'';_0x5bcc64[_0xc8cc('0x1e')]=this['message'][_0xc8cc('0x1e')]||'';_0x5bcc64[_0xc8cc('0x1f')]=!![];if(this['message'][_0xc8cc('0x20')]){_0x5bcc64[_0xc8cc('0x20')]='';_0x5bcc64[_0xc8cc('0x20')]+=_[_0xc8cc('0x21')](this[_0xc8cc('0x1c')]['subject'],_0xc8cc('0x22'))?'':_0xc8cc('0x23');_0x5bcc64[_0xc8cc('0x20')]+=this[_0xc8cc('0x1c')][_0xc8cc('0x20')];}}if(this[_0xc8cc('0xa')]===_0xc8cc('0x24')){_0x5bcc64[_0xc8cc('0x25')]=this['account']['id'];}else{_0x5bcc64[_[_0xc8cc('0x26')](this[_0xc8cc('0xa')])+'AccountId']=this[_0xc8cc('0x27')]['id'];}_0x5bcc64[_['upperFirst'](this[_0xc8cc('0xa')])+_0xc8cc('0x28')]=this[_0xc8cc('0x11')]['id'];var _0x426013=this[_0xc8cc('0x11')];if(rpc[this['channel']+_0xc8cc('0x29')]){if(this[_0xc8cc('0xa')]===_0xc8cc('0xb')){_0x5bcc64[_0xc8cc('0x2a')]=this[_0xc8cc('0x1c')][_0xc8cc('0x2b')];_0x5bcc64[_0xc8cc('0x2c')]=_0xc8cc('0x2d')+_['replace'](_0x5bcc64[_0xc8cc('0xc')],'<div\x20id=\x22xm-mail-content\x22',_0xc8cc('0x2e'))+_0xc8cc('0x2f');_0x5bcc64[_0xc8cc('0x30')]={'Auto-Submitted':_0xc8cc('0x31'),'X-Auto-Response-Suppress':'All','Precedence':_0xc8cc('0x32')};return mailRpc[_0xc8cc('0x33')](this['account'][_0xc8cc('0x34')],_0x5bcc64)['then'](function(_0x1edc2c){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x3f4ef6);_0x5bcc64[_0xc8cc('0x2b')]=_0x1edc2c[_0xc8cc('0x1c')]['messageId'];return rpc[_0x351d41+_0xc8cc('0x29')][_0xc8cc('0x35')](_0x5bcc64);})['then'](function(_0x122610){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY]\x20%s',_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x122610));})[_0xc8cc('0x37')](function(_0x5206e6){logger[_0xc8cc('0x38')](_0xc8cc('0x39'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x5206e6));})[_0xc8cc('0x3a')](function(){Promise[_0xc8cc('0x3b')]()[_0xc8cc('0x3c')](function(){if(_0x1bd5c5[0x0]!=='2'||_0x426013[_0xc8cc('0x3d')])return;return rpc[_0x351d41+'Interaction'][_0xc8cc('0x3e')](_0x426013['id'],{'autoreplyExecuted':!![]})[_0xc8cc('0x3c')](function(_0x2ffef2){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x3f4ef6,JSON['stringify'](_0x2ffef2));})[_0xc8cc('0x37')](function(_0x1aadd5){logger[_0xc8cc('0x38')](_0xc8cc('0x3f'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x1aadd5));});})['then'](function(){_0x3d38ea[_0xc8cc('0x14')]();});});}else{return rpc[this[_0xc8cc('0xa')]+_0xc8cc('0x29')][_0xc8cc('0x35')](_0x5bcc64)[_0xc8cc('0x3c')](function(){logger[_0xc8cc('0xd')]('[%s][AUTOREPLY]\x20%s',_0x3f4ef6,_0x5bcc64[_0xc8cc('0xc')]);})['catch'](function(_0x211c4c){logger[_0xc8cc('0x38')](_0xc8cc('0xe'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x211c4c));})[_0xc8cc('0x3a')](function(){Promise[_0xc8cc('0x3b')]()[_0xc8cc('0x3c')](function(){if(_0x1bd5c5[0x0]!=='2'||_0x426013['autoreplyExecuted'])return;return rpc[_0x351d41+'Interaction'][_0xc8cc('0x3e')](_0x426013['id'],{'autoreplyExecuted':!![]})['then'](function(_0x44ee7e){logger['info'](_0xc8cc('0x15'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0x44ee7e));})[_0xc8cc('0x37')](function(_0xb9e11d){logger[_0xc8cc('0x38')](_0xc8cc('0x3f'),_0x3f4ef6,JSON[_0xc8cc('0x36')](_0xb9e11d));});})['then'](function(){_0x3d38ea[_0xc8cc('0x14')]();});});}}}catch(_0x1dc1de){logger[_0xc8cc('0x38')](_0xc8cc('0xe'),_0x3f4ef6,JSON['stringify'](_0x1dc1de));_0x3d38ea[_0xc8cc('0x40')]();}};};