751cd31b1404dc39941af84f93736ea9e213562a
[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 _0x0f0b=['interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','body','getMustacheRender','message','from','channel','phone','read','subject','startsWith','Re:','chat','ChatWebsiteId','account','AccountId','upperFirst','InteractionId','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','headers','auto-replied','All','sendMailMessage','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','moment','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','isAutoreply','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil'];(function(_0x2a6809,_0x44edde){var _0x11c371=function(_0x1a4888){while(--_0x1a4888){_0x2a6809['push'](_0x2a6809['shift']());}};_0x11c371(++_0x44edde);}(_0x0f0b,0x102));var _0xb0f0=function(_0x4feb9c,_0x19a66b){_0x4feb9c=_0x4feb9c-0x0;var _0x341ce3=_0x0f0b[_0x4feb9c];return _0x341ce3;};'use strict';var _=require('lodash');var moment=require(_0xb0f0('0x0'));var utils=require('./utils');var logger=require(_0xb0f0('0x1'))('routing');var rpc={'chatMessage':require(_0xb0f0('0x2')),'openchannelMessage':require(_0xb0f0('0x3')),'mailMessage':require(_0xb0f0('0x4')),'smsMessage':require(_0xb0f0('0x5')),'faxMessage':require(_0xb0f0('0x6')),'whatsappMessage':require(_0xb0f0('0x7')),'chatInteraction':require(_0xb0f0('0x8')),'openchannelInteraction':require(_0xb0f0('0x9')),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0xb0f0('0xa')),'faxInteraction':require(_0xb0f0('0xb')),'whatsappInteraction':require(_0xb0f0('0xc'))};var mailRpc=require(_0xb0f0('0xd'));exports[_0xb0f0('0xe')]=function(_0x5b378d,_0x1cd0ca,_0x5bef18,_0x2fa71c){return function(_0x5941ca){try{var _0x5c290f=this['channel'];if(_0x5c290f===_0xb0f0('0xf')&&_0x2fa71c['body'][_0xb0f0('0x10')]){logger[_0xb0f0('0x11')](_0xb0f0('0x12'),_0x5b378d,_0xb0f0('0x13'));return _0x5941ca[_0xb0f0('0x14')]();}if(_0x1cd0ca[0x0]==='1'&&(_[_0xb0f0('0x15')](this[_0xb0f0('0x16')][_0xb0f0('0x17')])||!this[_0xb0f0('0x16')][_0xb0f0('0x17')])){logger[_0xb0f0('0x11')]('[%s][AUTOREPLY]\x20%s',_0x5b378d,_0xb0f0('0x18'));return _0x5941ca['next']();}if(_0x1cd0ca[0x0]==='2'&&this[_0xb0f0('0x16')][_0xb0f0('0x19')]){logger[_0xb0f0('0x11')](_0xb0f0('0x1a'),_0x5b378d,_0xb0f0('0x1b'));return _0x5941ca[_0xb0f0('0x14')]();}var _0x3faae7={'ContactId':this[_0xb0f0('0x1c')]['id'],'sentAt':moment()[_0xb0f0('0x1d')](_0xb0f0('0x1e')),'direction':_0xb0f0('0x1f')};if(this['channel']===_0xb0f0('0xf')){_0x3faae7[_0xb0f0('0x20')]=utils[_0xb0f0('0x21')](_0x1cd0ca[0x2],this);}else{_0x3faae7[_0xb0f0('0x20')]=utils[_0xb0f0('0x21')](_0x1cd0ca[0x1],this);}if(this[_0xb0f0('0x22')]){_0x3faae7['to']=this[_0xb0f0('0x22')][_0xb0f0('0x23')]||'';if(this[_0xb0f0('0x24')]===_0xb0f0('0xf')&&_0x1cd0ca[0x1]==='1'){_0x3faae7['cc']=this[_0xb0f0('0x22')]['cc']||'';}_0x3faae7[_0xb0f0('0x23')]=this[_0xb0f0('0x22')]['to']||'';_0x3faae7[_0xb0f0('0x25')]=this[_0xb0f0('0x22')][_0xb0f0('0x25')]||'';_0x3faae7[_0xb0f0('0x26')]=!![];if(this['message']['subject']){_0x3faae7[_0xb0f0('0x27')]='';_0x3faae7[_0xb0f0('0x27')]+=_[_0xb0f0('0x28')](this[_0xb0f0('0x22')]['subject'],_0xb0f0('0x29'))?'':'Re:\x20';_0x3faae7[_0xb0f0('0x27')]+=this[_0xb0f0('0x22')][_0xb0f0('0x27')];}}if(this[_0xb0f0('0x24')]===_0xb0f0('0x2a')){_0x3faae7[_0xb0f0('0x2b')]=this[_0xb0f0('0x2c')]['id'];}else{_0x3faae7[_['upperFirst'](this[_0xb0f0('0x24')])+_0xb0f0('0x2d')]=this[_0xb0f0('0x2c')]['id'];}_0x3faae7[_[_0xb0f0('0x2e')](this[_0xb0f0('0x24')])+_0xb0f0('0x2f')]=this[_0xb0f0('0x16')]['id'];var _0x2add78=this['interaction'];if(rpc[this['channel']+'Message']){if(this[_0xb0f0('0x24')]===_0xb0f0('0xf')){_0x3faae7['inReplyTo']=this[_0xb0f0('0x22')][_0xb0f0('0x30')];_0x3faae7['html']=_0xb0f0('0x31')+_[_0xb0f0('0x32')](_0x3faae7[_0xb0f0('0x20')],_0xb0f0('0x33'),'<div')+'</div>';_0x3faae7[_0xb0f0('0x34')]={'Auto-Submitted':_0xb0f0('0x35'),'X-Auto-Response-Suppress':_0xb0f0('0x36'),'Precedence':'auto_reply'};return mailRpc[_0xb0f0('0x37')](this[_0xb0f0('0x2c')][_0xb0f0('0x38')],_0x3faae7)[_0xb0f0('0x39')](function(_0x234157){logger['info'](_0xb0f0('0x3a'),_0x5b378d);_0x3faae7['messageId']=_0x234157[_0xb0f0('0x22')][_0xb0f0('0x30')];return rpc[_0x5c290f+_0xb0f0('0x3b')][_0xb0f0('0x3c')](_0x3faae7);})['then'](function(_0x5ab52a){logger['info'](_0xb0f0('0x12'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x5ab52a));})[_0xb0f0('0x3e')](function(_0x41e9da){logger[_0xb0f0('0x3f')](_0xb0f0('0x40'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x41e9da));})[_0xb0f0('0x41')](function(){Promise[_0xb0f0('0x42')]()[_0xb0f0('0x39')](function(){if(_0x1cd0ca[0x0]!=='2'||_0x2add78[_0xb0f0('0x19')])return;return rpc[_0x5c290f+_0xb0f0('0x43')]['update'](_0x2add78['id'],{'autoreplyExecuted':!![]})['then'](function(_0xbac62f){logger[_0xb0f0('0x11')](_0xb0f0('0x1a'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0xbac62f));})[_0xb0f0('0x3e')](function(_0xb7df03){logger['error'](_0xb0f0('0x44'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0xb7df03));});})[_0xb0f0('0x39')](function(){_0x5941ca[_0xb0f0('0x14')]();});});}else{return rpc[this[_0xb0f0('0x24')]+'Message']['create'](_0x3faae7)[_0xb0f0('0x39')](function(){logger[_0xb0f0('0x11')]('[%s][AUTOREPLY]\x20%s',_0x5b378d,_0x3faae7[_0xb0f0('0x20')]);})[_0xb0f0('0x3e')](function(_0x4f3430){logger[_0xb0f0('0x3f')](_0xb0f0('0x12'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x4f3430));})['finally'](function(){Promise[_0xb0f0('0x42')]()['then'](function(){if(_0x1cd0ca[0x0]!=='2'||_0x2add78[_0xb0f0('0x19')])return;return rpc[_0x5c290f+_0xb0f0('0x43')]['update'](_0x2add78['id'],{'autoreplyExecuted':!![]})['then'](function(_0xe58a4f){logger[_0xb0f0('0x11')](_0xb0f0('0x1a'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0xe58a4f));})[_0xb0f0('0x3e')](function(_0x422a53){logger[_0xb0f0('0x3f')](_0xb0f0('0x44'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x422a53));});})['then'](function(){_0x5941ca[_0xb0f0('0x14')]();});});}}}catch(_0x4a31ae){logger[_0xb0f0('0x3f')](_0xb0f0('0x12'),_0x5b378d,JSON[_0xb0f0('0x3d')](_0x4a31ae));_0x5941ca[_0xb0f0('0x45')]();}};};