f6ff84e38cbb61370afb38218f129c1326b8c8c9
[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 _0xcf94=['headers','auto-replied','All','auto_reply','sendMailMessage','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','resolve','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','finally','update','stop','lodash','moment','./utils','../../../../config/logger','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/whatsappInteraction','../../mailRpc','channel','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','out','getMustacheRender','message','from','mail','phone','read','subject','startsWith','Re:','chat','account','upperFirst','InteractionId','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>'];(function(_0x29548c,_0x21279f){var _0x3f6b63=function(_0xaf6c20){while(--_0xaf6c20){_0x29548c['push'](_0x29548c['shift']());}};_0x3f6b63(++_0x21279f);}(_0xcf94,0x153));var _0x4cf9=function(_0x397505,_0xbc7afa){_0x397505=_0x397505-0x0;var _0x5e525e=_0xcf94[_0x397505];return _0x5e525e;};'use strict';var _=require(_0x4cf9('0x0'));var moment=require(_0x4cf9('0x1'));var utils=require(_0x4cf9('0x2'));var logger=require(_0x4cf9('0x3'))('routing');var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x4cf9('0x4')),'smsMessage':require(_0x4cf9('0x5')),'faxMessage':require(_0x4cf9('0x6')),'whatsappMessage':require(_0x4cf9('0x7')),'chatInteraction':require(_0x4cf9('0x8')),'openchannelInteraction':require('../../rpc/openchannelInteraction'),'mailInteraction':require(_0x4cf9('0x9')),'smsInteraction':require(_0x4cf9('0xa')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0x4cf9('0xb'))};var mailRpc=require(_0x4cf9('0xc'));exports['consequence']=function(_0xde1cff,_0x1decff,_0x2902bb,_0x186b7a){return function(_0x33b25b){try{var _0x55fa32=this[_0x4cf9('0xd')];if(_0x55fa32==='mail'&&_0x186b7a[_0x4cf9('0xe')][_0x4cf9('0xf')]){logger[_0x4cf9('0x10')](_0x4cf9('0x11'),_0xde1cff,_0x4cf9('0x12'));return _0x33b25b[_0x4cf9('0x13')]();}if(_0x1decff[0x0]==='1'&&(_['isNil'](this[_0x4cf9('0x14')][_0x4cf9('0x15')])||!this[_0x4cf9('0x14')][_0x4cf9('0x15')])){logger['info'](_0x4cf9('0x11'),_0xde1cff,_0x4cf9('0x16'));return _0x33b25b[_0x4cf9('0x13')]();}if(_0x1decff[0x0]==='2'&&this[_0x4cf9('0x14')][_0x4cf9('0x17')]){logger[_0x4cf9('0x10')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0xde1cff,'One\x20Time\x20already\x20sent');return _0x33b25b[_0x4cf9('0x13')]();}var _0x1fdb57={'ContactId':this['contact']['id'],'sentAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x4cf9('0x18')};if(this['channel']==='mail'){_0x1fdb57['body']=utils[_0x4cf9('0x19')](_0x1decff[0x2],this);}else{_0x1fdb57[_0x4cf9('0xe')]=utils[_0x4cf9('0x19')](_0x1decff[0x1],this);}if(this['message']){_0x1fdb57['to']=this[_0x4cf9('0x1a')][_0x4cf9('0x1b')]||'';if(this['channel']===_0x4cf9('0x1c')&&_0x1decff[0x1]==='1'){_0x1fdb57['cc']=this[_0x4cf9('0x1a')]['cc']||'';}_0x1fdb57['from']=this['message']['to']||'';_0x1fdb57[_0x4cf9('0x1d')]=this[_0x4cf9('0x1a')][_0x4cf9('0x1d')]||'';_0x1fdb57[_0x4cf9('0x1e')]=!![];if(this[_0x4cf9('0x1a')][_0x4cf9('0x1f')]){_0x1fdb57[_0x4cf9('0x1f')]='';_0x1fdb57[_0x4cf9('0x1f')]+=_[_0x4cf9('0x20')](this['message'][_0x4cf9('0x1f')],_0x4cf9('0x21'))?'':'Re:\x20';_0x1fdb57[_0x4cf9('0x1f')]+=this[_0x4cf9('0x1a')][_0x4cf9('0x1f')];}}if(this[_0x4cf9('0xd')]===_0x4cf9('0x22')){_0x1fdb57['ChatWebsiteId']=this[_0x4cf9('0x23')]['id'];}else{_0x1fdb57[_[_0x4cf9('0x24')](this['channel'])+'AccountId']=this[_0x4cf9('0x23')]['id'];}_0x1fdb57[_[_0x4cf9('0x24')](this[_0x4cf9('0xd')])+_0x4cf9('0x25')]=this['interaction']['id'];var _0xb069f=this[_0x4cf9('0x14')];if(rpc[this[_0x4cf9('0xd')]+'Message']){if(this['channel']===_0x4cf9('0x1c')){_0x1fdb57['inReplyTo']=this[_0x4cf9('0x1a')][_0x4cf9('0x26')];_0x1fdb57[_0x4cf9('0x27')]=_0x4cf9('0x28')+_[_0x4cf9('0x29')](_0x1fdb57[_0x4cf9('0xe')],_0x4cf9('0x2a'),_0x4cf9('0x2b'))+_0x4cf9('0x2c');_0x1fdb57[_0x4cf9('0x2d')]={'Auto-Submitted':_0x4cf9('0x2e'),'X-Auto-Response-Suppress':_0x4cf9('0x2f'),'Precedence':_0x4cf9('0x30')};return mailRpc[_0x4cf9('0x31')](this[_0x4cf9('0x23')]['smtpOptions'],_0x1fdb57)[_0x4cf9('0x32')](function(_0x301388){logger[_0x4cf9('0x10')](_0x4cf9('0x33'),_0xde1cff);_0x1fdb57[_0x4cf9('0x26')]=_0x301388[_0x4cf9('0x1a')][_0x4cf9('0x26')];return rpc[_0x55fa32+_0x4cf9('0x34')][_0x4cf9('0x35')](_0x1fdb57);})[_0x4cf9('0x32')](function(_0x4cf9a5){logger['info'](_0x4cf9('0x11'),_0xde1cff,JSON[_0x4cf9('0x36')](_0x4cf9a5));})[_0x4cf9('0x37')](function(_0x60a48b){logger[_0x4cf9('0x38')](_0x4cf9('0x39'),_0xde1cff,JSON['stringify'](_0x60a48b));})['finally'](function(){Promise[_0x4cf9('0x3a')]()['then'](function(){if(_0x1decff[0x0]!=='2'||_0xb069f[_0x4cf9('0x17')])return;return rpc[_0x55fa32+'Interaction']['update'](_0xb069f['id'],{'autoreplyExecuted':!![]})['then'](function(_0x4c5c82){logger[_0x4cf9('0x10')](_0x4cf9('0x3b'),_0xde1cff,JSON[_0x4cf9('0x36')](_0x4c5c82));})[_0x4cf9('0x37')](function(_0x3c2bbc){logger[_0x4cf9('0x38')](_0x4cf9('0x3c'),_0xde1cff,JSON[_0x4cf9('0x36')](_0x3c2bbc));});})['then'](function(){_0x33b25b[_0x4cf9('0x13')]();});});}else{return rpc[this['channel']+_0x4cf9('0x34')][_0x4cf9('0x35')](_0x1fdb57)[_0x4cf9('0x32')](function(){logger[_0x4cf9('0x10')]('[%s][AUTOREPLY]\x20%s',_0xde1cff,_0x1fdb57[_0x4cf9('0xe')]);})[_0x4cf9('0x37')](function(_0x57fc2a){logger[_0x4cf9('0x38')](_0x4cf9('0x11'),_0xde1cff,JSON[_0x4cf9('0x36')](_0x57fc2a));})[_0x4cf9('0x3d')](function(){Promise[_0x4cf9('0x3a')]()[_0x4cf9('0x32')](function(){if(_0x1decff[0x0]!=='2'||_0xb069f[_0x4cf9('0x17')])return;return rpc[_0x55fa32+'Interaction'][_0x4cf9('0x3e')](_0xb069f['id'],{'autoreplyExecuted':!![]})[_0x4cf9('0x32')](function(_0x2c9cb3){logger[_0x4cf9('0x10')](_0x4cf9('0x3b'),_0xde1cff,JSON[_0x4cf9('0x36')](_0x2c9cb3));})[_0x4cf9('0x37')](function(_0x17c9b9){logger['error']('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0xde1cff,JSON[_0x4cf9('0x36')](_0x17c9b9));});})[_0x4cf9('0x32')](function(){_0x33b25b[_0x4cf9('0x13')]();});});}}}catch(_0x452475){logger[_0x4cf9('0x38')]('[%s][AUTOREPLY]\x20%s',_0xde1cff,JSON[_0x4cf9('0x36')](_0x452475));_0x33b25b[_0x4cf9('0x3f')]();}};};