51bc62b91807c0aa2931a4c819ce28488d1c1274
[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 _0x97c8=['[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','lodash','moment','./utils','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc','consequence','channel','mail','isAutoreply','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil','interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','body','getMustacheRender','from','message','phone','read','subject','startsWith','Re:','chat','ChatWebsiteId','account','upperFirst','AccountId','Message','inReplyTo','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','headers','auto-replied','All','auto_reply','sendMailMessage','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','error','[RPC][%s][AUTOREPLY]\x20%s','stringify','finally','resolve','Interaction','update','catch'];(function(_0x3f6ac0,_0xd62588){var _0x3c8c03=function(_0xaabf3a){while(--_0xaabf3a){_0x3f6ac0['push'](_0x3f6ac0['shift']());}};_0x3c8c03(++_0xd62588);}(_0x97c8,0xd3));var _0x897c=function(_0x1d2bbb,_0x202267){_0x1d2bbb=_0x1d2bbb-0x0;var _0x38082b=_0x97c8[_0x1d2bbb];return _0x38082b;};'use strict';var _=require(_0x897c('0x0'));var moment=require(_0x897c('0x1'));var utils=require(_0x897c('0x2'));var logger=require('../../../../config/logger')(_0x897c('0x3'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x897c('0x4')),'mailMessage':require(_0x897c('0x5')),'smsMessage':require(_0x897c('0x6')),'faxMessage':require(_0x897c('0x7')),'whatsappMessage':require(_0x897c('0x8')),'chatInteraction':require(_0x897c('0x9')),'openchannelInteraction':require('../../rpc/openchannelInteraction'),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0x897c('0xa')),'faxInteraction':require(_0x897c('0xb')),'whatsappInteraction':require(_0x897c('0xc'))};var mailRpc=require(_0x897c('0xd'));exports[_0x897c('0xe')]=function(_0x4da05a,_0x4d8447,_0xb5b16c,_0x198602){return function(_0x4d605f){try{var _0x6f8d82=this[_0x897c('0xf')];if(_0x6f8d82===_0x897c('0x10')&&_0x198602['body'][_0x897c('0x11')]){logger[_0x897c('0x12')](_0x897c('0x13'),_0x4da05a,_0x897c('0x14'));return _0x4d605f[_0x897c('0x15')]();}if(_0x4d8447[0x0]==='1'&&(_[_0x897c('0x16')](this[_0x897c('0x17')][_0x897c('0x18')])||!this[_0x897c('0x17')][_0x897c('0x18')])){logger[_0x897c('0x12')](_0x897c('0x13'),_0x4da05a,_0x897c('0x19'));return _0x4d605f[_0x897c('0x15')]();}if(_0x4d8447[0x0]==='2'&&this['interaction'][_0x897c('0x1a')]){logger[_0x897c('0x12')](_0x897c('0x1b'),_0x4da05a,'One\x20Time\x20already\x20sent');return _0x4d605f[_0x897c('0x15')]();}var _0x1d07f2={'ContactId':this[_0x897c('0x1c')]['id'],'sentAt':moment()[_0x897c('0x1d')](_0x897c('0x1e')),'direction':_0x897c('0x1f')};if(this[_0x897c('0xf')]===_0x897c('0x10')){_0x1d07f2[_0x897c('0x20')]=utils['getMustacheRender'](_0x4d8447[0x2],this);}else{_0x1d07f2['body']=utils[_0x897c('0x21')](_0x4d8447[0x1],this);}if(this['message']){_0x1d07f2['to']=this['message'][_0x897c('0x22')]||'';if(this['channel']==='mail'&&_0x4d8447[0x1]==='1'){_0x1d07f2['cc']=this[_0x897c('0x23')]['cc']||'';}_0x1d07f2[_0x897c('0x22')]=this[_0x897c('0x23')]['to']||'';_0x1d07f2[_0x897c('0x24')]=this[_0x897c('0x23')][_0x897c('0x24')]||'';_0x1d07f2[_0x897c('0x25')]=!![];if(this[_0x897c('0x23')][_0x897c('0x26')]){_0x1d07f2[_0x897c('0x26')]='';_0x1d07f2[_0x897c('0x26')]+=_[_0x897c('0x27')](this[_0x897c('0x23')][_0x897c('0x26')],_0x897c('0x28'))?'':'Re:\x20';_0x1d07f2['subject']+=this[_0x897c('0x23')][_0x897c('0x26')];}}if(this[_0x897c('0xf')]===_0x897c('0x29')){_0x1d07f2[_0x897c('0x2a')]=this[_0x897c('0x2b')]['id'];}else{_0x1d07f2[_[_0x897c('0x2c')](this[_0x897c('0xf')])+_0x897c('0x2d')]=this[_0x897c('0x2b')]['id'];}_0x1d07f2[_[_0x897c('0x2c')](this[_0x897c('0xf')])+'InteractionId']=this[_0x897c('0x17')]['id'];var _0x584001=this[_0x897c('0x17')];if(rpc[this['channel']+_0x897c('0x2e')]){if(this[_0x897c('0xf')]==='mail'){_0x1d07f2[_0x897c('0x2f')]=this[_0x897c('0x23')][_0x897c('0x30')];_0x1d07f2['html']=_0x897c('0x31')+_[_0x897c('0x32')](_0x1d07f2[_0x897c('0x20')],_0x897c('0x33'),_0x897c('0x34'))+'</div>';_0x1d07f2[_0x897c('0x35')]={'Auto-Submitted':_0x897c('0x36'),'X-Auto-Response-Suppress':_0x897c('0x37'),'Precedence':_0x897c('0x38')};return mailRpc[_0x897c('0x39')](this[_0x897c('0x2b')][_0x897c('0x3a')],_0x1d07f2)[_0x897c('0x3b')](function(_0xfc329d){logger[_0x897c('0x12')](_0x897c('0x3c'),_0x4da05a);_0x1d07f2['messageId']=_0xfc329d['message'][_0x897c('0x30')];return rpc[_0x6f8d82+_0x897c('0x2e')]['create'](_0x1d07f2);})[_0x897c('0x3b')](function(_0x1e07c8){logger[_0x897c('0x12')](_0x897c('0x13'),_0x4da05a,JSON['stringify'](_0x1e07c8));})['catch'](function(_0x2c5d99){logger[_0x897c('0x3d')](_0x897c('0x3e'),_0x4da05a,JSON[_0x897c('0x3f')](_0x2c5d99));})[_0x897c('0x40')](function(){Promise[_0x897c('0x41')]()[_0x897c('0x3b')](function(){if(_0x4d8447[0x0]!=='2'||_0x584001[_0x897c('0x1a')])return;return rpc[_0x6f8d82+_0x897c('0x42')][_0x897c('0x43')](_0x584001['id'],{'autoreplyExecuted':!![]})[_0x897c('0x3b')](function(_0x27c47f){logger[_0x897c('0x12')](_0x897c('0x1b'),_0x4da05a,JSON[_0x897c('0x3f')](_0x27c47f));})[_0x897c('0x44')](function(_0x460660){logger[_0x897c('0x3d')](_0x897c('0x45'),_0x4da05a,JSON[_0x897c('0x3f')](_0x460660));});})['then'](function(){_0x4d605f[_0x897c('0x15')]();});});}else{return rpc[this[_0x897c('0xf')]+_0x897c('0x2e')]['create'](_0x1d07f2)[_0x897c('0x3b')](function(){logger[_0x897c('0x12')]('[%s][AUTOREPLY]\x20%s',_0x4da05a,_0x1d07f2[_0x897c('0x20')]);})[_0x897c('0x44')](function(_0x1ba3e9){logger[_0x897c('0x3d')](_0x897c('0x13'),_0x4da05a,JSON[_0x897c('0x3f')](_0x1ba3e9));})[_0x897c('0x40')](function(){Promise[_0x897c('0x41')]()[_0x897c('0x3b')](function(){if(_0x4d8447[0x0]!=='2'||_0x584001[_0x897c('0x1a')])return;return rpc[_0x6f8d82+_0x897c('0x42')][_0x897c('0x43')](_0x584001['id'],{'autoreplyExecuted':!![]})[_0x897c('0x3b')](function(_0x2e645b){logger[_0x897c('0x12')](_0x897c('0x1b'),_0x4da05a,JSON['stringify'](_0x2e645b));})[_0x897c('0x44')](function(_0x2988da){logger[_0x897c('0x3d')]('[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x4da05a,JSON['stringify'](_0x2988da));});})['then'](function(){_0x4d605f[_0x897c('0x15')]();});});}}}catch(_0x402fb9){logger[_0x897c('0x3d')](_0x897c('0x13'),_0x4da05a,JSON['stringify'](_0x402fb9));_0x4d605f['stop']();}};};