Built motion from commit da617fac.|2.6.6
[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 _0x55c2=['inReplyTo','messageId','html','replace','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','smtpOptions','[%s][AUTOREPLY]\x20SMTP\x20SENT','Message','create','then','stringify','error','[RPC][%s][AUTOREPLY]\x20%s','resolve','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','catch','autoreplyExecuted','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','moment','./utils','../../../../config/logger','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/whatsappInteraction','consequence','channel','isAutoreply','[%s][AUTOREPLY]\x20%s','next','isNil','created','interaction','Autoreply\x20already\x20sent','info','format','mail','getMustacheRender','body','message','from','phone','read','subject','Re:','Re:\x20','ChatWebsiteId','account','InteractionId'];(function(_0xb24a3e,_0x4a3594){var _0x4038d7=function(_0x1ea3c3){while(--_0x1ea3c3){_0xb24a3e['push'](_0xb24a3e['shift']());}};_0x4038d7(++_0x4a3594);}(_0x55c2,0x188));var _0x255c=function(_0x2c1114,_0x2a5c50){_0x2c1114=_0x2c1114-0x0;var _0x2b877c=_0x55c2[_0x2c1114];return _0x2b877c;};'use strict';var _=require('lodash');var moment=require(_0x255c('0x0'));var utils=require(_0x255c('0x1'));var logger=require(_0x255c('0x2'))('routing');var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x255c('0x3')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x255c('0x4')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x255c('0x5')),'chatInteraction':require(_0x255c('0x6')),'openchannelInteraction':require(_0x255c('0x7')),'mailInteraction':require(_0x255c('0x8')),'smsInteraction':require(_0x255c('0x9')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0x255c('0xa'))};var mailRpc=require('../../mailRpc');exports[_0x255c('0xb')]=function(_0x5df1dd,_0x5ef976,_0x22f5de,_0x3aca35){return function(_0x4bd586){try{var _0x1d9320=this[_0x255c('0xc')];if(_0x1d9320==='mail'&&_0x3aca35['body'][_0x255c('0xd')]){logger['info'](_0x255c('0xe'),_0x5df1dd,'Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)');return _0x4bd586[_0x255c('0xf')]();}if(_0x5ef976[0x0]==='1'&&(_[_0x255c('0x10')](this['interaction'][_0x255c('0x11')])||!this[_0x255c('0x12')][_0x255c('0x11')])){logger['info'](_0x255c('0xe'),_0x5df1dd,_0x255c('0x13'));return _0x4bd586[_0x255c('0xf')]();}if(_0x5ef976[0x0]==='2'&&this[_0x255c('0x12')]['autoreplyExecuted']){logger[_0x255c('0x14')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5df1dd,'One\x20Time\x20already\x20sent');return _0x4bd586[_0x255c('0xf')]();}var _0xcf32c0={'ContactId':this['contact']['id'],'sentAt':moment()[_0x255c('0x15')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':'out'};if(this[_0x255c('0xc')]===_0x255c('0x16')){_0xcf32c0['body']=utils[_0x255c('0x17')](_0x5ef976[0x2],this);}else{_0xcf32c0[_0x255c('0x18')]=utils['getMustacheRender'](_0x5ef976[0x1],this);}if(this['message']){_0xcf32c0['to']=this[_0x255c('0x19')]['from']||'';if(this[_0x255c('0xc')]===_0x255c('0x16')&&_0x5ef976[0x1]==='1'){_0xcf32c0['cc']=this[_0x255c('0x19')]['cc']||'';}_0xcf32c0[_0x255c('0x1a')]=this[_0x255c('0x19')]['to']||'';_0xcf32c0[_0x255c('0x1b')]=this[_0x255c('0x19')][_0x255c('0x1b')]||'';_0xcf32c0[_0x255c('0x1c')]=!![];if(this[_0x255c('0x19')]['subject']){_0xcf32c0[_0x255c('0x1d')]='';_0xcf32c0['subject']+=_['startsWith'](this['message'][_0x255c('0x1d')],_0x255c('0x1e'))?'':_0x255c('0x1f');_0xcf32c0[_0x255c('0x1d')]+=this['message'][_0x255c('0x1d')];}}if(this[_0x255c('0xc')]==='chat'){_0xcf32c0[_0x255c('0x20')]=this[_0x255c('0x21')]['id'];}else{_0xcf32c0[_['upperFirst'](this[_0x255c('0xc')])+'AccountId']=this[_0x255c('0x21')]['id'];}_0xcf32c0[_['upperFirst'](this['channel'])+_0x255c('0x22')]=this[_0x255c('0x12')]['id'];var _0x2047b8=this[_0x255c('0x12')];if(rpc[this[_0x255c('0xc')]+'Message']){if(this['channel']===_0x255c('0x16')){_0xcf32c0[_0x255c('0x23')]=this[_0x255c('0x19')][_0x255c('0x24')];_0xcf32c0[_0x255c('0x25')]='<div\x20id=\x22xm-mail-content\x22>'+_[_0x255c('0x26')](_0xcf32c0['body'],'<div\x20id=\x22xm-mail-content\x22','<div')+_0x255c('0x27');_0xcf32c0[_0x255c('0x28')]={'Auto-Submitted':_0x255c('0x29'),'X-Auto-Response-Suppress':_0x255c('0x2a'),'Precedence':_0x255c('0x2b')};return mailRpc[_0x255c('0x2c')](this[_0x255c('0x21')][_0x255c('0x2d')],_0xcf32c0)['then'](function(_0x2a1b64){logger[_0x255c('0x14')](_0x255c('0x2e'),_0x5df1dd);_0xcf32c0[_0x255c('0x24')]=_0x2a1b64[_0x255c('0x19')][_0x255c('0x24')];return rpc[_0x1d9320+_0x255c('0x2f')][_0x255c('0x30')](_0xcf32c0);})[_0x255c('0x31')](function(_0x3f1f4f){logger[_0x255c('0x14')](_0x255c('0xe'),_0x5df1dd,JSON[_0x255c('0x32')](_0x3f1f4f));})['catch'](function(_0x12996b){logger[_0x255c('0x33')](_0x255c('0x34'),_0x5df1dd,JSON[_0x255c('0x32')](_0x12996b));})['finally'](function(){Promise[_0x255c('0x35')]()[_0x255c('0x31')](function(){if(_0x5ef976[0x0]!=='2'||_0x2047b8['autoreplyExecuted'])return;return rpc[_0x1d9320+'Interaction']['update'](_0x2047b8['id'],{'autoreplyExecuted':!![]})[_0x255c('0x31')](function(_0x21cfb7){logger[_0x255c('0x14')](_0x255c('0x36'),_0x5df1dd,JSON[_0x255c('0x32')](_0x21cfb7));})['catch'](function(_0x587812){logger[_0x255c('0x33')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x5df1dd,JSON['stringify'](_0x587812));});})[_0x255c('0x31')](function(){_0x4bd586[_0x255c('0xf')]();});});}else{return rpc[this[_0x255c('0xc')]+_0x255c('0x2f')][_0x255c('0x30')](_0xcf32c0)[_0x255c('0x31')](function(){logger['info'](_0x255c('0xe'),_0x5df1dd,_0xcf32c0[_0x255c('0x18')]);})[_0x255c('0x37')](function(_0x19acca){logger['error'](_0x255c('0xe'),_0x5df1dd,JSON['stringify'](_0x19acca));})['finally'](function(){Promise[_0x255c('0x35')]()['then'](function(){if(_0x5ef976[0x0]!=='2'||_0x2047b8[_0x255c('0x38')])return;return rpc[_0x1d9320+_0x255c('0x39')][_0x255c('0x3a')](_0x2047b8['id'],{'autoreplyExecuted':!![]})[_0x255c('0x31')](function(_0x3a6991){logger[_0x255c('0x14')](_0x255c('0x36'),_0x5df1dd,JSON['stringify'](_0x3a6991));})[_0x255c('0x37')](function(_0x53266d){logger[_0x255c('0x33')](_0x255c('0x3b'),_0x5df1dd,JSON['stringify'](_0x53266d));});})[_0x255c('0x31')](function(){_0x4bd586[_0x255c('0xf')]();});});}}}catch(_0x491c73){logger[_0x255c('0x33')](_0x255c('0xe'),_0x5df1dd,JSON['stringify'](_0x491c73));_0x4bd586[_0x255c('0x3c')]();}};};