Built motion from commit e38a297d.|2.6.18
[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 _0x533c=['../../rpc/smsInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','channel','mail','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','interaction','created','Autoreply\x20already\x20sent','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','next','format','YYYY-MM-DD\x20HH:mm:ss','body','getMustacheRender','message','from','phone','read','subject','startsWith','Re:\x20','ChatWebsiteId','account','upperFirst','AccountId','Message','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','auto-replied','All','auto_reply','smtpOptions','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','stringify','error','[RPC][%s][AUTOREPLY]\x20%s','finally','then','autoreplyExecuted','update','catch','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','resolve','Interaction','stop','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/whatsappMessage','../../rpc/openchannelInteraction'];(function(_0x273c39,_0x1052e6){var _0x46d6b5=function(_0x44f1fb){while(--_0x44f1fb){_0x273c39['push'](_0x273c39['shift']());}};_0x46d6b5(++_0x1052e6);}(_0x533c,0xb9));var _0xc533=function(_0x214721,_0x450da9){_0x214721=_0x214721-0x0;var _0x155b81=_0x533c[_0x214721];return _0x155b81;};'use strict';var _=require(_0xc533('0x0'));var moment=require(_0xc533('0x1'));var utils=require(_0xc533('0x2'));var logger=require(_0xc533('0x3'))(_0xc533('0x4'));var rpc={'chatMessage':require(_0xc533('0x5')),'openchannelMessage':require(_0xc533('0x6')),'mailMessage':require(_0xc533('0x7')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0xc533('0x8')),'chatInteraction':require('../../rpc/chatInteraction'),'openchannelInteraction':require(_0xc533('0x9')),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0xc533('0xa')),'faxInteraction':require('../../rpc/faxInteraction'),'whatsappInteraction':require(_0xc533('0xb'))};var mailRpc=require(_0xc533('0xc'));exports[_0xc533('0xd')]=function(_0x1903fe,_0x5c8a1f,_0x4ab113,_0x104fe6){return function(_0x58b345){try{var _0x5858b0=this[_0xc533('0xe')];if(_0x5858b0===_0xc533('0xf')&&_0x104fe6['body']['isAutoreply']){logger[_0xc533('0x10')](_0xc533('0x11'),_0x1903fe,_0xc533('0x12'));return _0x58b345['next']();}if(_0x5c8a1f[0x0]==='1'&&(_[_0xc533('0x13')](this[_0xc533('0x14')][_0xc533('0x15')])||!this[_0xc533('0x14')][_0xc533('0x15')])){logger[_0xc533('0x10')](_0xc533('0x11'),_0x1903fe,_0xc533('0x16'));return _0x58b345['next']();}if(_0x5c8a1f[0x0]==='2'&&this[_0xc533('0x14')]['autoreplyExecuted']){logger[_0xc533('0x10')](_0xc533('0x17'),_0x1903fe,'One\x20Time\x20already\x20sent');return _0x58b345[_0xc533('0x18')]();}var _0xd30727={'ContactId':this['contact']['id'],'sentAt':moment()[_0xc533('0x19')](_0xc533('0x1a')),'direction':'out'};if(this['channel']===_0xc533('0xf')){_0xd30727[_0xc533('0x1b')]=utils[_0xc533('0x1c')](_0x5c8a1f[0x2],this);}else{_0xd30727[_0xc533('0x1b')]=utils[_0xc533('0x1c')](_0x5c8a1f[0x1],this);}if(this[_0xc533('0x1d')]){_0xd30727['to']=this['message'][_0xc533('0x1e')]||'';if(this['channel']===_0xc533('0xf')&&_0x5c8a1f[0x1]==='1'){_0xd30727['cc']=this[_0xc533('0x1d')]['cc']||'';}_0xd30727['from']=this[_0xc533('0x1d')]['to']||'';_0xd30727[_0xc533('0x1f')]=this['message'][_0xc533('0x1f')]||'';_0xd30727[_0xc533('0x20')]=!![];if(this[_0xc533('0x1d')]['subject']){_0xd30727[_0xc533('0x21')]='';_0xd30727[_0xc533('0x21')]+=_[_0xc533('0x22')](this[_0xc533('0x1d')][_0xc533('0x21')],'Re:')?'':_0xc533('0x23');_0xd30727[_0xc533('0x21')]+=this[_0xc533('0x1d')][_0xc533('0x21')];}}if(this['channel']==='chat'){_0xd30727[_0xc533('0x24')]=this[_0xc533('0x25')]['id'];}else{_0xd30727[_[_0xc533('0x26')](this[_0xc533('0xe')])+_0xc533('0x27')]=this['account']['id'];}_0xd30727[_[_0xc533('0x26')](this['channel'])+'InteractionId']=this[_0xc533('0x14')]['id'];var _0x3bd6e4=this[_0xc533('0x14')];if(rpc[this[_0xc533('0xe')]+_0xc533('0x28')]){if(this[_0xc533('0xe')]==='mail'){_0xd30727['inReplyTo']=this[_0xc533('0x1d')][_0xc533('0x29')];_0xd30727[_0xc533('0x2a')]=_0xc533('0x2b')+_[_0xc533('0x2c')](_0xd30727['body'],_0xc533('0x2d'),_0xc533('0x2e'))+'</div>';_0xd30727['headers']={'Auto-Submitted':_0xc533('0x2f'),'X-Auto-Response-Suppress':_0xc533('0x30'),'Precedence':_0xc533('0x31')};return mailRpc['sendMailMessage'](this[_0xc533('0x25')][_0xc533('0x32')],_0xd30727)['then'](function(_0x528116){logger[_0xc533('0x10')](_0xc533('0x33'),_0x1903fe);_0xd30727['messageId']=_0x528116[_0xc533('0x1d')][_0xc533('0x29')];return rpc[_0x5858b0+_0xc533('0x28')][_0xc533('0x34')](_0xd30727);})['then'](function(_0x467d7e){logger['info'](_0xc533('0x11'),_0x1903fe,JSON[_0xc533('0x35')](_0x467d7e));})['catch'](function(_0x2a6762){logger[_0xc533('0x36')](_0xc533('0x37'),_0x1903fe,JSON['stringify'](_0x2a6762));})[_0xc533('0x38')](function(){Promise['resolve']()[_0xc533('0x39')](function(){if(_0x5c8a1f[0x0]!=='2'||_0x3bd6e4[_0xc533('0x3a')])return;return rpc[_0x5858b0+'Interaction'][_0xc533('0x3b')](_0x3bd6e4['id'],{'autoreplyExecuted':!![]})[_0xc533('0x39')](function(_0x378991){logger['info'](_0xc533('0x17'),_0x1903fe,JSON[_0xc533('0x35')](_0x378991));})[_0xc533('0x3c')](function(_0xa8df34){logger[_0xc533('0x36')](_0xc533('0x3d'),_0x1903fe,JSON[_0xc533('0x35')](_0xa8df34));});})[_0xc533('0x39')](function(){_0x58b345[_0xc533('0x18')]();});});}else{return rpc[this[_0xc533('0xe')]+'Message'][_0xc533('0x34')](_0xd30727)[_0xc533('0x39')](function(){logger[_0xc533('0x10')](_0xc533('0x11'),_0x1903fe,_0xd30727[_0xc533('0x1b')]);})[_0xc533('0x3c')](function(_0x26d150){logger[_0xc533('0x36')](_0xc533('0x11'),_0x1903fe,JSON['stringify'](_0x26d150));})['finally'](function(){Promise[_0xc533('0x3e')]()[_0xc533('0x39')](function(){if(_0x5c8a1f[0x0]!=='2'||_0x3bd6e4[_0xc533('0x3a')])return;return rpc[_0x5858b0+_0xc533('0x3f')]['update'](_0x3bd6e4['id'],{'autoreplyExecuted':!![]})['then'](function(_0x230b44){logger[_0xc533('0x10')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x1903fe,JSON[_0xc533('0x35')](_0x230b44));})['catch'](function(_0x241024){logger[_0xc533('0x36')](_0xc533('0x3d'),_0x1903fe,JSON[_0xc533('0x35')](_0x241024));});})['then'](function(){_0x58b345[_0xc533('0x18')]();});});}}}catch(_0x16fc55){logger[_0xc533('0x36')](_0xc533('0x11'),_0x1903fe,JSON['stringify'](_0x16fc55));_0x58b345[_0xc533('0x40')]();}};};