Built motion from commit ddca4d0d.|2.5.47
[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 _0x2c34=['../../rpc/faxMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','mail','body','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','created','interaction','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','One\x20Time\x20already\x20sent','contact','format','getMustacheRender','message','channel','phone','read','subject','Re:','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','Smtp','service','host','port','secure','authentication','auth','user','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','then','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','update','stop','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage'];(function(_0x1dc034,_0x186f35){var _0x5d120e=function(_0xc7c9d1){while(--_0xc7c9d1){_0x1dc034['push'](_0x1dc034['shift']());}};_0x5d120e(++_0x186f35);}(_0x2c34,0x8f));var _0x42c3=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0x2c34[_0x57b54c];return _0x59cc19;};'use strict';var _=require('lodash');var moment=require(_0x42c3('0x0'));var utils=require(_0x42c3('0x1'));var logger=require(_0x42c3('0x2'))(_0x42c3('0x3'));var rpc={'chatMessage':require(_0x42c3('0x4')),'openchannelMessage':require(_0x42c3('0x5')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x42c3('0x6')),'faxMessage':require(_0x42c3('0x7')),'whatsappMessage':require('../../rpc/whatsappMessage'),'chatInteraction':require(_0x42c3('0x8')),'openchannelInteraction':require(_0x42c3('0x9')),'mailInteraction':require(_0x42c3('0xa')),'smsInteraction':require(_0x42c3('0xb')),'faxInteraction':require(_0x42c3('0xc')),'whatsappInteraction':require(_0x42c3('0xd'))};var mailRpc=require(_0x42c3('0xe'));exports[_0x42c3('0xf')]=function(_0x4fcbec,_0x4bfefe,_0x4b9393,_0x2d05a5){return function(_0xe3eb45){try{var _0x33329f=this['channel'];if(_0x33329f===_0x42c3('0x10')&&_0x2d05a5[_0x42c3('0x11')]['isAutoreply']){logger[_0x42c3('0x12')](_0x42c3('0x13'),_0x4fcbec,_0x42c3('0x14'));return _0xe3eb45[_0x42c3('0x15')]();}if(_0x4bfefe[0x0]==='1'&&(_[_0x42c3('0x16')](this['interaction'][_0x42c3('0x17')])||!this[_0x42c3('0x18')][_0x42c3('0x17')])){logger['info'](_0x42c3('0x13'),_0x4fcbec,_0x42c3('0x19'));return _0xe3eb45[_0x42c3('0x15')]();}if(_0x4bfefe[0x0]==='2'&&this[_0x42c3('0x18')][_0x42c3('0x1a')]){logger[_0x42c3('0x12')](_0x42c3('0x1b'),_0x4fcbec,_0x42c3('0x1c'));return _0xe3eb45[_0x42c3('0x15')]();}var _0x5df314={'ContactId':this[_0x42c3('0x1d')]['id'],'sentAt':moment()[_0x42c3('0x1e')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':'out'};if(this['channel']===_0x42c3('0x10')){_0x5df314['body']=utils[_0x42c3('0x1f')](_0x4bfefe[0x2],this);}else{_0x5df314['body']=utils['getMustacheRender'](_0x4bfefe[0x1],this);}if(this[_0x42c3('0x20')]){_0x5df314['to']=this['message']['from']||'';if(this[_0x42c3('0x21')]===_0x42c3('0x10')&&_0x4bfefe[0x1]==='1'){_0x5df314['cc']=this[_0x42c3('0x20')]['cc']||'';}_0x5df314['from']=this[_0x42c3('0x20')]['to']||'';_0x5df314[_0x42c3('0x22')]=this[_0x42c3('0x20')][_0x42c3('0x22')]||'';_0x5df314[_0x42c3('0x23')]=!![];if(this[_0x42c3('0x20')][_0x42c3('0x24')]){_0x5df314[_0x42c3('0x24')]='';_0x5df314['subject']+=_['startsWith'](this[_0x42c3('0x20')][_0x42c3('0x24')],_0x42c3('0x25'))?'':'Re:\x20';_0x5df314[_0x42c3('0x24')]+=this[_0x42c3('0x20')][_0x42c3('0x24')];}}if(this[_0x42c3('0x21')]==='chat'){_0x5df314[_0x42c3('0x26')]=this[_0x42c3('0x27')]['id'];}else{_0x5df314[_[_0x42c3('0x28')](this[_0x42c3('0x21')])+_0x42c3('0x29')]=this[_0x42c3('0x27')]['id'];}_0x5df314[_[_0x42c3('0x28')](this['channel'])+_0x42c3('0x2a')]=this[_0x42c3('0x18')]['id'];var _0x2064a2=this['interaction'];if(rpc[this[_0x42c3('0x21')]+_0x42c3('0x2b')]){if(this[_0x42c3('0x21')]===_0x42c3('0x10')){var _0x553e95={'tls':{'rejectUnauthorized':![]}};if(this['account'][_0x42c3('0x2c')][_0x42c3('0x2d')]){_0x553e95[_0x42c3('0x2d')]=this[_0x42c3('0x27')][_0x42c3('0x2c')][_0x42c3('0x2d')];}else{_0x553e95[_0x42c3('0x2e')]=this[_0x42c3('0x27')][_0x42c3('0x2c')]['host'];_0x553e95[_0x42c3('0x2f')]=this[_0x42c3('0x27')][_0x42c3('0x2c')][_0x42c3('0x2f')];_0x553e95['secure']=this['account']['Smtp'][_0x42c3('0x30')];}if(this[_0x42c3('0x27')][_0x42c3('0x2c')][_0x42c3('0x31')]){_0x553e95[_0x42c3('0x32')]={'user':this['account'][_0x42c3('0x2c')][_0x42c3('0x33')],'pass':this[_0x42c3('0x27')][_0x42c3('0x2c')]['pass']};}_0x5df314['inReplyTo']=this['message'][_0x42c3('0x34')];_0x5df314['html']=_0x42c3('0x35')+_[_0x42c3('0x36')](_0x5df314[_0x42c3('0x11')],_0x42c3('0x37'),_0x42c3('0x38'))+_0x42c3('0x39');_0x5df314[_0x42c3('0x3a')]={'Auto-Submitted':_0x42c3('0x3b'),'X-Auto-Response-Suppress':_0x42c3('0x3c'),'Precedence':_0x42c3('0x3d')};return mailRpc[_0x42c3('0x3e')](_0x553e95,_0x5df314)[_0x42c3('0x3f')](function(_0x4420d8){logger[_0x42c3('0x12')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x4fcbec);_0x5df314['messageId']=_0x4420d8[_0x42c3('0x20')][_0x42c3('0x34')];return rpc[_0x33329f+'Message'][_0x42c3('0x40')](_0x5df314);})['then'](function(_0x5972c2){logger['info']('[%s][AUTOREPLY]\x20%s',_0x4fcbec,JSON[_0x42c3('0x41')](_0x5972c2));})[_0x42c3('0x42')](function(_0x524615){logger[_0x42c3('0x43')](_0x42c3('0x44'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x524615));})[_0x42c3('0x45')](function(){Promise[_0x42c3('0x46')]()[_0x42c3('0x3f')](function(){if(_0x4bfefe[0x0]!=='2'||_0x2064a2['autoreplyExecuted'])return;return rpc[_0x33329f+_0x42c3('0x47')]['update'](_0x2064a2['id'],{'autoreplyExecuted':!![]})['then'](function(_0x581883){logger[_0x42c3('0x12')](_0x42c3('0x1b'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x581883));})[_0x42c3('0x42')](function(_0x48ba6f){logger[_0x42c3('0x43')](_0x42c3('0x48'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x48ba6f));});})[_0x42c3('0x3f')](function(){_0xe3eb45['next']();});});}else{return rpc[this['channel']+'Message']['create'](_0x5df314)['then'](function(_0x5c6147){logger[_0x42c3('0x12')](_0x42c3('0x13'),_0x4fcbec,_0x5df314[_0x42c3('0x11')]);})[_0x42c3('0x42')](function(_0x4c988d){logger[_0x42c3('0x43')](_0x42c3('0x13'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x4c988d));})['finally'](function(){Promise[_0x42c3('0x46')]()['then'](function(){if(_0x4bfefe[0x0]!=='2'||_0x2064a2['autoreplyExecuted'])return;return rpc[_0x33329f+_0x42c3('0x47')][_0x42c3('0x49')](_0x2064a2['id'],{'autoreplyExecuted':!![]})['then'](function(_0x2603b7){logger[_0x42c3('0x12')](_0x42c3('0x1b'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x2603b7));})[_0x42c3('0x42')](function(_0x265b87){logger[_0x42c3('0x43')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x4fcbec,JSON[_0x42c3('0x41')](_0x265b87));});})[_0x42c3('0x3f')](function(){_0xe3eb45[_0x42c3('0x15')]();});});}}}catch(_0x2ba449){logger['error'](_0x42c3('0x13'),_0x4fcbec,JSON[_0x42c3('0x41')](_0x2ba449));_0xe3eb45[_0x42c3('0x4a')]();}};};