Built motion from commit 00bf23f6.|2.6.16
[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 _0xa28e=['chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','messageId','html','<div\x20id=\x22xm-mail-content\x22>','<div\x20id=\x22xm-mail-content\x22','<div','</div>','auto-replied','All','sendMailMessage','then','create','stringify','catch','[RPC][%s][AUTOREPLY]\x20%s','finally','Interaction','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','error','resolve','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','stop','lodash','moment','./utils','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../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','interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','One\x20Time\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','getMustacheRender','message','from','phone','read','subject','startsWith','Re:'];(function(_0xe20333,_0x2bce45){var _0x5ef2ad=function(_0xcc07de){while(--_0xcc07de){_0xe20333['push'](_0xe20333['shift']());}};_0x5ef2ad(++_0x2bce45);}(_0xa28e,0x12c));var _0xea28=function(_0x503055,_0x304102){_0x503055=_0x503055-0x0;var _0x30fb63=_0xa28e[_0x503055];return _0x30fb63;};'use strict';var _=require(_0xea28('0x0'));var moment=require(_0xea28('0x1'));var utils=require(_0xea28('0x2'));var logger=require(_0xea28('0x3'))('routing');var rpc={'chatMessage':require(_0xea28('0x4')),'openchannelMessage':require(_0xea28('0x5')),'mailMessage':require(_0xea28('0x6')),'smsMessage':require(_0xea28('0x7')),'faxMessage':require(_0xea28('0x8')),'whatsappMessage':require(_0xea28('0x9')),'chatInteraction':require(_0xea28('0xa')),'openchannelInteraction':require('../../rpc/openchannelInteraction'),'mailInteraction':require(_0xea28('0xb')),'smsInteraction':require(_0xea28('0xc')),'faxInteraction':require(_0xea28('0xd')),'whatsappInteraction':require(_0xea28('0xe'))};var mailRpc=require(_0xea28('0xf'));exports[_0xea28('0x10')]=function(_0x4730f3,_0x2b6356,_0x49500b,_0x360ba4){return function(_0x4e6902){try{var _0x521c64=this['channel'];if(_0x521c64===_0xea28('0x11')&&_0x360ba4[_0xea28('0x12')]['isAutoreply']){logger[_0xea28('0x13')](_0xea28('0x14'),_0x4730f3,_0xea28('0x15'));return _0x4e6902[_0xea28('0x16')]();}if(_0x2b6356[0x0]==='1'&&(_['isNil'](this[_0xea28('0x17')]['created'])||!this[_0xea28('0x17')][_0xea28('0x18')])){logger[_0xea28('0x13')](_0xea28('0x14'),_0x4730f3,_0xea28('0x19'));return _0x4e6902[_0xea28('0x16')]();}if(_0x2b6356[0x0]==='2'&&this['interaction'][_0xea28('0x1a')]){logger['info']('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x4730f3,_0xea28('0x1b'));return _0x4e6902['next']();}var _0x20af1a={'ContactId':this[_0xea28('0x1c')]['id'],'sentAt':moment()[_0xea28('0x1d')](_0xea28('0x1e')),'direction':'out'};if(this[_0xea28('0x1f')]==='mail'){_0x20af1a[_0xea28('0x12')]=utils[_0xea28('0x20')](_0x2b6356[0x2],this);}else{_0x20af1a[_0xea28('0x12')]=utils[_0xea28('0x20')](_0x2b6356[0x1],this);}if(this[_0xea28('0x21')]){_0x20af1a['to']=this[_0xea28('0x21')][_0xea28('0x22')]||'';if(this[_0xea28('0x1f')]===_0xea28('0x11')&&_0x2b6356[0x1]==='1'){_0x20af1a['cc']=this[_0xea28('0x21')]['cc']||'';}_0x20af1a[_0xea28('0x22')]=this[_0xea28('0x21')]['to']||'';_0x20af1a[_0xea28('0x23')]=this['message']['phone']||'';_0x20af1a[_0xea28('0x24')]=!![];if(this[_0xea28('0x21')]['subject']){_0x20af1a[_0xea28('0x25')]='';_0x20af1a[_0xea28('0x25')]+=_[_0xea28('0x26')](this[_0xea28('0x21')][_0xea28('0x25')],_0xea28('0x27'))?'':'Re:\x20';_0x20af1a[_0xea28('0x25')]+=this[_0xea28('0x21')][_0xea28('0x25')];}}if(this['channel']===_0xea28('0x28')){_0x20af1a[_0xea28('0x29')]=this[_0xea28('0x2a')]['id'];}else{_0x20af1a[_[_0xea28('0x2b')](this[_0xea28('0x1f')])+_0xea28('0x2c')]=this['account']['id'];}_0x20af1a[_[_0xea28('0x2b')](this[_0xea28('0x1f')])+_0xea28('0x2d')]=this[_0xea28('0x17')]['id'];var _0x3222b7=this[_0xea28('0x17')];if(rpc[this[_0xea28('0x1f')]+_0xea28('0x2e')]){if(this['channel']==='mail'){_0x20af1a['inReplyTo']=this[_0xea28('0x21')][_0xea28('0x2f')];_0x20af1a[_0xea28('0x30')]=_0xea28('0x31')+_['replace'](_0x20af1a[_0xea28('0x12')],_0xea28('0x32'),_0xea28('0x33'))+_0xea28('0x34');_0x20af1a['headers']={'Auto-Submitted':_0xea28('0x35'),'X-Auto-Response-Suppress':_0xea28('0x36'),'Precedence':'auto_reply'};return mailRpc[_0xea28('0x37')](this[_0xea28('0x2a')]['smtpOptions'],_0x20af1a)[_0xea28('0x38')](function(_0x2f4072){logger[_0xea28('0x13')]('[%s][AUTOREPLY]\x20SMTP\x20SENT',_0x4730f3);_0x20af1a['messageId']=_0x2f4072[_0xea28('0x21')][_0xea28('0x2f')];return rpc[_0x521c64+_0xea28('0x2e')][_0xea28('0x39')](_0x20af1a);})[_0xea28('0x38')](function(_0x44b56e){logger['info'](_0xea28('0x14'),_0x4730f3,JSON[_0xea28('0x3a')](_0x44b56e));})[_0xea28('0x3b')](function(_0x4a605a){logger['error'](_0xea28('0x3c'),_0x4730f3,JSON['stringify'](_0x4a605a));})[_0xea28('0x3d')](function(){Promise['resolve']()[_0xea28('0x38')](function(){if(_0x2b6356[0x0]!=='2'||_0x3222b7['autoreplyExecuted'])return;return rpc[_0x521c64+_0xea28('0x3e')]['update'](_0x3222b7['id'],{'autoreplyExecuted':!![]})[_0xea28('0x38')](function(_0x280b91){logger[_0xea28('0x13')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x4730f3,JSON[_0xea28('0x3a')](_0x280b91));})[_0xea28('0x3b')](function(_0x23f600){logger['error'](_0xea28('0x3f'),_0x4730f3,JSON['stringify'](_0x23f600));});})[_0xea28('0x38')](function(){_0x4e6902[_0xea28('0x16')]();});});}else{return rpc[this[_0xea28('0x1f')]+_0xea28('0x2e')][_0xea28('0x39')](_0x20af1a)[_0xea28('0x38')](function(){logger[_0xea28('0x13')](_0xea28('0x14'),_0x4730f3,_0x20af1a[_0xea28('0x12')]);})[_0xea28('0x3b')](function(_0x1c3aad){logger[_0xea28('0x40')](_0xea28('0x14'),_0x4730f3,JSON[_0xea28('0x3a')](_0x1c3aad));})[_0xea28('0x3d')](function(){Promise[_0xea28('0x41')]()[_0xea28('0x38')](function(){if(_0x2b6356[0x0]!=='2'||_0x3222b7[_0xea28('0x1a')])return;return rpc[_0x521c64+_0xea28('0x3e')]['update'](_0x3222b7['id'],{'autoreplyExecuted':!![]})[_0xea28('0x38')](function(_0x2474a1){logger[_0xea28('0x13')](_0xea28('0x42'),_0x4730f3,JSON[_0xea28('0x3a')](_0x2474a1));})[_0xea28('0x3b')](function(_0x5edbd7){logger[_0xea28('0x40')](_0xea28('0x3f'),_0x4730f3,JSON[_0xea28('0x3a')](_0x5edbd7));});})[_0xea28('0x38')](function(){_0x4e6902[_0xea28('0x16')]();});});}}}catch(_0x4fd7f6){logger[_0xea28('0x40')](_0xea28('0x14'),_0x4730f3,JSON[_0xea28('0x3a')](_0x4fd7f6));_0x4e6902[_0xea28('0x43')]();}};};