07b15460ecfd457e08389979b3fa698af816b317
[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 _0x9c73=['ChatWebsiteId','account','upperFirst','InteractionId','Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','All','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','stringify','catch','[RPC][%s][AUTOREPLY]\x20%s','resolve','Interaction','error','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','create','finally','update','stop','lodash','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','channel','mail','body','isAutoreply','info','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','created','interaction','[%s][AUTOREPLY]\x20%s','Autoreply\x20already\x20sent','next','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','out','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat'];(function(_0xd4e47c,_0x2428b8){var _0x935fc7=function(_0x18b2c5){while(--_0x18b2c5){_0xd4e47c['push'](_0xd4e47c['shift']());}};_0x935fc7(++_0x2428b8);}(_0x9c73,0x180));var _0x39c7=function(_0x5a3b37,_0x4fd839){_0x5a3b37=_0x5a3b37-0x0;var _0x334733=_0x9c73[_0x5a3b37];return _0x334733;};'use strict';var _=require(_0x39c7('0x0'));var moment=require('moment');var utils=require(_0x39c7('0x1'));var logger=require('../../../../config/logger')(_0x39c7('0x2'));var rpc={'chatMessage':require(_0x39c7('0x3')),'openchannelMessage':require(_0x39c7('0x4')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x39c7('0x5')),'faxMessage':require(_0x39c7('0x6')),'whatsappMessage':require(_0x39c7('0x7')),'chatInteraction':require(_0x39c7('0x8')),'openchannelInteraction':require(_0x39c7('0x9')),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0x39c7('0xa')),'faxInteraction':require(_0x39c7('0xb')),'whatsappInteraction':require(_0x39c7('0xc'))};var mailRpc=require(_0x39c7('0xd'));exports['consequence']=function(_0x42e30c,_0x158f71,_0x25ddc2,_0x817bcb){return function(_0x37e018){try{var _0x161dac=this[_0x39c7('0xe')];if(_0x161dac===_0x39c7('0xf')&&_0x817bcb[_0x39c7('0x10')][_0x39c7('0x11')]){logger[_0x39c7('0x12')]('[%s][AUTOREPLY]\x20%s',_0x42e30c,_0x39c7('0x13'));return _0x37e018['next']();}if(_0x158f71[0x0]==='1'&&(_[_0x39c7('0x14')](this['interaction'][_0x39c7('0x15')])||!this[_0x39c7('0x16')][_0x39c7('0x15')])){logger[_0x39c7('0x12')](_0x39c7('0x17'),_0x42e30c,_0x39c7('0x18'));return _0x37e018[_0x39c7('0x19')]();}if(_0x158f71[0x0]==='2'&&this[_0x39c7('0x16')][_0x39c7('0x1a')]){logger['info'](_0x39c7('0x1b'),_0x42e30c,_0x39c7('0x1c'));return _0x37e018[_0x39c7('0x19')]();}var _0x81c7a5={'ContactId':this[_0x39c7('0x1d')]['id'],'sentAt':moment()[_0x39c7('0x1e')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x39c7('0x1f')};if(this[_0x39c7('0xe')]==='mail'){_0x81c7a5[_0x39c7('0x10')]=utils[_0x39c7('0x20')](_0x158f71[0x2],this);}else{_0x81c7a5[_0x39c7('0x10')]=utils[_0x39c7('0x20')](_0x158f71[0x1],this);}if(this[_0x39c7('0x21')]){_0x81c7a5['to']=this[_0x39c7('0x21')][_0x39c7('0x22')]||'';if(this[_0x39c7('0xe')]==='mail'&&_0x158f71[0x1]==='1'){_0x81c7a5['cc']=this[_0x39c7('0x21')]['cc']||'';}_0x81c7a5['from']=this['message']['to']||'';_0x81c7a5[_0x39c7('0x23')]=this[_0x39c7('0x21')][_0x39c7('0x23')]||'';_0x81c7a5[_0x39c7('0x24')]=!![];if(this[_0x39c7('0x21')][_0x39c7('0x25')]){_0x81c7a5[_0x39c7('0x25')]='';_0x81c7a5[_0x39c7('0x25')]+=_[_0x39c7('0x26')](this['message'][_0x39c7('0x25')],_0x39c7('0x27'))?'':_0x39c7('0x28');_0x81c7a5['subject']+=this[_0x39c7('0x21')]['subject'];}}if(this[_0x39c7('0xe')]===_0x39c7('0x29')){_0x81c7a5[_0x39c7('0x2a')]=this[_0x39c7('0x2b')]['id'];}else{_0x81c7a5[_[_0x39c7('0x2c')](this['channel'])+'AccountId']=this[_0x39c7('0x2b')]['id'];}_0x81c7a5[_[_0x39c7('0x2c')](this[_0x39c7('0xe')])+_0x39c7('0x2d')]=this[_0x39c7('0x16')]['id'];var _0x191e78=this[_0x39c7('0x16')];if(rpc[this[_0x39c7('0xe')]+_0x39c7('0x2e')]){if(this[_0x39c7('0xe')]===_0x39c7('0xf')){_0x81c7a5[_0x39c7('0x2f')]=this[_0x39c7('0x21')][_0x39c7('0x30')];_0x81c7a5[_0x39c7('0x31')]=_0x39c7('0x32')+_[_0x39c7('0x33')](_0x81c7a5[_0x39c7('0x10')],_0x39c7('0x34'),_0x39c7('0x35'))+_0x39c7('0x36');_0x81c7a5[_0x39c7('0x37')]={'Auto-Submitted':'auto-replied','X-Auto-Response-Suppress':_0x39c7('0x38'),'Precedence':'auto_reply'};return mailRpc['sendMailMessage'](this[_0x39c7('0x2b')][_0x39c7('0x39')],_0x81c7a5)[_0x39c7('0x3a')](function(_0x4e3b5a){logger['info'](_0x39c7('0x3b'),_0x42e30c);_0x81c7a5[_0x39c7('0x30')]=_0x4e3b5a['message'][_0x39c7('0x30')];return rpc[_0x161dac+_0x39c7('0x2e')]['create'](_0x81c7a5);})['then'](function(_0x40bd7d){logger[_0x39c7('0x12')](_0x39c7('0x17'),_0x42e30c,JSON[_0x39c7('0x3c')](_0x40bd7d));})[_0x39c7('0x3d')](function(_0x56397f){logger['error'](_0x39c7('0x3e'),_0x42e30c,JSON[_0x39c7('0x3c')](_0x56397f));})['finally'](function(){Promise[_0x39c7('0x3f')]()[_0x39c7('0x3a')](function(){if(_0x158f71[0x0]!=='2'||_0x191e78['autoreplyExecuted'])return;return rpc[_0x161dac+_0x39c7('0x40')]['update'](_0x191e78['id'],{'autoreplyExecuted':!![]})[_0x39c7('0x3a')](function(_0x1b9da3){logger['info'](_0x39c7('0x1b'),_0x42e30c,JSON['stringify'](_0x1b9da3));})[_0x39c7('0x3d')](function(_0x50953e){logger[_0x39c7('0x41')](_0x39c7('0x42'),_0x42e30c,JSON[_0x39c7('0x3c')](_0x50953e));});})['then'](function(){_0x37e018[_0x39c7('0x19')]();});});}else{return rpc[this['channel']+_0x39c7('0x2e')][_0x39c7('0x43')](_0x81c7a5)[_0x39c7('0x3a')](function(){logger['info'](_0x39c7('0x17'),_0x42e30c,_0x81c7a5[_0x39c7('0x10')]);})['catch'](function(_0xadf516){logger['error'](_0x39c7('0x17'),_0x42e30c,JSON[_0x39c7('0x3c')](_0xadf516));})[_0x39c7('0x44')](function(){Promise[_0x39c7('0x3f')]()[_0x39c7('0x3a')](function(){if(_0x158f71[0x0]!=='2'||_0x191e78[_0x39c7('0x1a')])return;return rpc[_0x161dac+_0x39c7('0x40')][_0x39c7('0x45')](_0x191e78['id'],{'autoreplyExecuted':!![]})['then'](function(_0x39fd8f){logger['info'](_0x39c7('0x1b'),_0x42e30c,JSON[_0x39c7('0x3c')](_0x39fd8f));})[_0x39c7('0x3d')](function(_0x6b47b1){logger[_0x39c7('0x41')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x42e30c,JSON[_0x39c7('0x3c')](_0x6b47b1));});})[_0x39c7('0x3a')](function(){_0x37e018[_0x39c7('0x19')]();});});}}}catch(_0x477a21){logger['error'](_0x39c7('0x17'),_0x42e30c,JSON['stringify'](_0x477a21));_0x37e018[_0x39c7('0x46')]();}};};