3d770ab95ad3b699a9112dc669fad0b5fb1774e8
[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 _0xf5bf=['[%s][AUTOREPLY][autoreplyExecuted]\x20%s','format','YYYY-MM-DD\x20HH:mm:ss','out','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','account','AccountId','upperFirst','InteractionId','Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','All','auto_reply','sendMailMessage','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','catch','error','[RPC][%s][AUTOREPLY]\x20%s','stringify','finally','resolve','autoreplyExecuted','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','lodash','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/whatsappInteraction','../../mailRpc','channel','mail','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','interaction','created'];(function(_0x6de07e,_0x55c0e4){var _0x352732=function(_0x39c5c7){while(--_0x39c5c7){_0x6de07e['push'](_0x6de07e['shift']());}};_0x352732(++_0x55c0e4);}(_0xf5bf,0xba));var _0xff5b=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf5bf[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xff5b('0x0'));var moment=require('moment');var utils=require(_0xff5b('0x1'));var logger=require(_0xff5b('0x2'))(_0xff5b('0x3'));var rpc={'chatMessage':require(_0xff5b('0x4')),'openchannelMessage':require(_0xff5b('0x5')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xff5b('0x6')),'whatsappMessage':require(_0xff5b('0x7')),'chatInteraction':require(_0xff5b('0x8')),'openchannelInteraction':require(_0xff5b('0x9')),'mailInteraction':require(_0xff5b('0xa')),'smsInteraction':require('../../rpc/smsInteraction'),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xff5b('0xb'))};var mailRpc=require(_0xff5b('0xc'));exports['consequence']=function(_0x306e8b,_0x20cc8a,_0x57ceb7,_0x52872f){return function(_0x457cf8){try{var _0x309c92=this[_0xff5b('0xd')];if(_0x309c92===_0xff5b('0xe')&&_0x52872f[_0xff5b('0xf')][_0xff5b('0x10')]){logger[_0xff5b('0x11')](_0xff5b('0x12'),_0x306e8b,_0xff5b('0x13'));return _0x457cf8[_0xff5b('0x14')]();}if(_0x20cc8a[0x0]==='1'&&(_[_0xff5b('0x15')](this[_0xff5b('0x16')][_0xff5b('0x17')])||!this[_0xff5b('0x16')]['created'])){logger[_0xff5b('0x11')]('[%s][AUTOREPLY]\x20%s',_0x306e8b,'Autoreply\x20already\x20sent');return _0x457cf8[_0xff5b('0x14')]();}if(_0x20cc8a[0x0]==='2'&&this[_0xff5b('0x16')]['autoreplyExecuted']){logger['info'](_0xff5b('0x18'),_0x306e8b,'One\x20Time\x20already\x20sent');return _0x457cf8['next']();}var _0x3b753e={'ContactId':this['contact']['id'],'sentAt':moment()[_0xff5b('0x19')](_0xff5b('0x1a')),'direction':_0xff5b('0x1b')};if(this[_0xff5b('0xd')]===_0xff5b('0xe')){_0x3b753e[_0xff5b('0xf')]=utils[_0xff5b('0x1c')](_0x20cc8a[0x2],this);}else{_0x3b753e['body']=utils[_0xff5b('0x1c')](_0x20cc8a[0x1],this);}if(this[_0xff5b('0x1d')]){_0x3b753e['to']=this[_0xff5b('0x1d')][_0xff5b('0x1e')]||'';if(this[_0xff5b('0xd')]===_0xff5b('0xe')&&_0x20cc8a[0x1]==='1'){_0x3b753e['cc']=this[_0xff5b('0x1d')]['cc']||'';}_0x3b753e[_0xff5b('0x1e')]=this[_0xff5b('0x1d')]['to']||'';_0x3b753e[_0xff5b('0x1f')]=this['message'][_0xff5b('0x1f')]||'';_0x3b753e[_0xff5b('0x20')]=!![];if(this[_0xff5b('0x1d')][_0xff5b('0x21')]){_0x3b753e['subject']='';_0x3b753e[_0xff5b('0x21')]+=_[_0xff5b('0x22')](this[_0xff5b('0x1d')][_0xff5b('0x21')],_0xff5b('0x23'))?'':_0xff5b('0x24');_0x3b753e[_0xff5b('0x21')]+=this[_0xff5b('0x1d')][_0xff5b('0x21')];}}if(this[_0xff5b('0xd')]===_0xff5b('0x25')){_0x3b753e[_0xff5b('0x26')]=this[_0xff5b('0x27')]['id'];}else{_0x3b753e[_['upperFirst'](this['channel'])+_0xff5b('0x28')]=this[_0xff5b('0x27')]['id'];}_0x3b753e[_[_0xff5b('0x29')](this[_0xff5b('0xd')])+_0xff5b('0x2a')]=this['interaction']['id'];var _0x10db9d=this['interaction'];if(rpc[this[_0xff5b('0xd')]+_0xff5b('0x2b')]){if(this[_0xff5b('0xd')]===_0xff5b('0xe')){_0x3b753e[_0xff5b('0x2c')]=this[_0xff5b('0x1d')][_0xff5b('0x2d')];_0x3b753e[_0xff5b('0x2e')]=_0xff5b('0x2f')+_[_0xff5b('0x30')](_0x3b753e['body'],_0xff5b('0x31'),_0xff5b('0x32'))+_0xff5b('0x33');_0x3b753e[_0xff5b('0x34')]={'Auto-Submitted':'auto-replied','X-Auto-Response-Suppress':_0xff5b('0x35'),'Precedence':_0xff5b('0x36')};return mailRpc[_0xff5b('0x37')](this[_0xff5b('0x27')]['smtpOptions'],_0x3b753e)[_0xff5b('0x38')](function(_0x2f896f){logger[_0xff5b('0x11')](_0xff5b('0x39'),_0x306e8b);_0x3b753e['messageId']=_0x2f896f[_0xff5b('0x1d')][_0xff5b('0x2d')];return rpc[_0x309c92+_0xff5b('0x2b')][_0xff5b('0x3a')](_0x3b753e);})[_0xff5b('0x38')](function(_0x4c7387){logger[_0xff5b('0x11')](_0xff5b('0x12'),_0x306e8b,JSON['stringify'](_0x4c7387));})[_0xff5b('0x3b')](function(_0x25591f){logger[_0xff5b('0x3c')](_0xff5b('0x3d'),_0x306e8b,JSON[_0xff5b('0x3e')](_0x25591f));})[_0xff5b('0x3f')](function(){Promise[_0xff5b('0x40')]()['then'](function(){if(_0x20cc8a[0x0]!=='2'||_0x10db9d[_0xff5b('0x41')])return;return rpc[_0x309c92+_0xff5b('0x42')][_0xff5b('0x43')](_0x10db9d['id'],{'autoreplyExecuted':!![]})['then'](function(_0x12cdb7){logger[_0xff5b('0x11')](_0xff5b('0x18'),_0x306e8b,JSON['stringify'](_0x12cdb7));})[_0xff5b('0x3b')](function(_0x4eb600){logger[_0xff5b('0x3c')](_0xff5b('0x44'),_0x306e8b,JSON[_0xff5b('0x3e')](_0x4eb600));});})['then'](function(){_0x457cf8[_0xff5b('0x14')]();});});}else{return rpc[this['channel']+_0xff5b('0x2b')][_0xff5b('0x3a')](_0x3b753e)[_0xff5b('0x38')](function(){logger[_0xff5b('0x11')](_0xff5b('0x12'),_0x306e8b,_0x3b753e[_0xff5b('0xf')]);})[_0xff5b('0x3b')](function(_0x26bc44){logger['error'](_0xff5b('0x12'),_0x306e8b,JSON[_0xff5b('0x3e')](_0x26bc44));})[_0xff5b('0x3f')](function(){Promise[_0xff5b('0x40')]()[_0xff5b('0x38')](function(){if(_0x20cc8a[0x0]!=='2'||_0x10db9d[_0xff5b('0x41')])return;return rpc[_0x309c92+'Interaction'][_0xff5b('0x43')](_0x10db9d['id'],{'autoreplyExecuted':!![]})[_0xff5b('0x38')](function(_0x2ed85c){logger['info'](_0xff5b('0x18'),_0x306e8b,JSON[_0xff5b('0x3e')](_0x2ed85c));})[_0xff5b('0x3b')](function(_0x3491bb){logger['error'](_0xff5b('0x44'),_0x306e8b,JSON[_0xff5b('0x3e')](_0x3491bb));});})['then'](function(){_0x457cf8[_0xff5b('0x14')]();});});}}}catch(_0x43b6f1){logger[_0xff5b('0x3c')](_0xff5b('0x12'),_0x306e8b,JSON[_0xff5b('0x3e')](_0x43b6f1));_0x457cf8[_0xff5b('0x45')]();}};};