527ff0731ce6580955a18ac765ff94aa3e458ad1
[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 _0xc091=['consequence','channel','mail','body','isAutoreply','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','isNil','interaction','created','next','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','contact','YYYY-MM-DD\x20HH:mm:ss','out','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','autoreplyExecuted','Interaction','update','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/mailInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../rpc/whatsappInteraction','../../mailRpc'];(function(_0x3df871,_0xda2e11){var _0x570f7b=function(_0xfaac78){while(--_0xfaac78){_0x3df871['push'](_0x3df871['shift']());}};_0x570f7b(++_0xda2e11);}(_0xc091,0x114));var _0x1c09=function(_0x4fd262,_0xc20b0d){_0x4fd262=_0x4fd262-0x0;var _0x276aad=_0xc091[_0x4fd262];return _0x276aad;};'use strict';var _=require(_0x1c09('0x0'));var moment=require(_0x1c09('0x1'));var utils=require(_0x1c09('0x2'));var logger=require(_0x1c09('0x3'))(_0x1c09('0x4'));var rpc={'chatMessage':require(_0x1c09('0x5')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x1c09('0x6')),'smsMessage':require(_0x1c09('0x7')),'faxMessage':require(_0x1c09('0x8')),'whatsappMessage':require(_0x1c09('0x9')),'chatInteraction':require(_0x1c09('0xa')),'openchannelInteraction':require('../../rpc/openchannelInteraction'),'mailInteraction':require(_0x1c09('0xb')),'smsInteraction':require(_0x1c09('0xc')),'faxInteraction':require(_0x1c09('0xd')),'whatsappInteraction':require(_0x1c09('0xe'))};var mailRpc=require(_0x1c09('0xf'));exports[_0x1c09('0x10')]=function(_0x49cc45,_0x2a6479,_0x16e649,_0x44fa11){return function(_0x411852){try{var _0x64dd0d=this[_0x1c09('0x11')];if(_0x64dd0d===_0x1c09('0x12')&&_0x44fa11[_0x1c09('0x13')][_0x1c09('0x14')]){logger[_0x1c09('0x15')](_0x1c09('0x16'),_0x49cc45,_0x1c09('0x17'));return _0x411852['next']();}if(_0x2a6479[0x0]==='1'&&(_[_0x1c09('0x18')](this[_0x1c09('0x19')][_0x1c09('0x1a')])||!this[_0x1c09('0x19')][_0x1c09('0x1a')])){logger[_0x1c09('0x15')](_0x1c09('0x16'),_0x49cc45,'Autoreply\x20already\x20sent');return _0x411852[_0x1c09('0x1b')]();}if(_0x2a6479[0x0]==='2'&&this['interaction']['autoreplyExecuted']){logger[_0x1c09('0x15')](_0x1c09('0x1c'),_0x49cc45,'One\x20Time\x20already\x20sent');return _0x411852[_0x1c09('0x1b')]();}var _0x4de2a4={'ContactId':this[_0x1c09('0x1d')]['id'],'sentAt':moment()['format'](_0x1c09('0x1e')),'direction':_0x1c09('0x1f')};if(this[_0x1c09('0x11')]===_0x1c09('0x12')){_0x4de2a4[_0x1c09('0x13')]=utils[_0x1c09('0x20')](_0x2a6479[0x2],this);}else{_0x4de2a4[_0x1c09('0x13')]=utils[_0x1c09('0x20')](_0x2a6479[0x1],this);}if(this[_0x1c09('0x21')]){_0x4de2a4['to']=this['message']['from']||'';if(this['channel']===_0x1c09('0x12')&&_0x2a6479[0x1]==='1'){_0x4de2a4['cc']=this[_0x1c09('0x21')]['cc']||'';}_0x4de2a4[_0x1c09('0x22')]=this[_0x1c09('0x21')]['to']||'';_0x4de2a4[_0x1c09('0x23')]=this[_0x1c09('0x21')][_0x1c09('0x23')]||'';_0x4de2a4[_0x1c09('0x24')]=!![];if(this[_0x1c09('0x21')][_0x1c09('0x25')]){_0x4de2a4[_0x1c09('0x25')]='';_0x4de2a4[_0x1c09('0x25')]+=_[_0x1c09('0x26')](this[_0x1c09('0x21')]['subject'],_0x1c09('0x27'))?'':'Re:\x20';_0x4de2a4['subject']+=this[_0x1c09('0x21')][_0x1c09('0x25')];}}if(this[_0x1c09('0x11')]==='chat'){_0x4de2a4[_0x1c09('0x28')]=this['account']['id'];}else{_0x4de2a4[_[_0x1c09('0x29')](this['channel'])+_0x1c09('0x2a')]=this[_0x1c09('0x2b')]['id'];}_0x4de2a4[_['upperFirst'](this[_0x1c09('0x11')])+_0x1c09('0x2c')]=this['interaction']['id'];var _0x41dd3=this[_0x1c09('0x19')];if(rpc[this['channel']+_0x1c09('0x2d')]){if(this[_0x1c09('0x11')]==='mail'){_0x4de2a4[_0x1c09('0x2e')]=this['message'][_0x1c09('0x2f')];_0x4de2a4[_0x1c09('0x30')]=_0x1c09('0x31')+_[_0x1c09('0x32')](_0x4de2a4[_0x1c09('0x13')],_0x1c09('0x33'),_0x1c09('0x34'))+_0x1c09('0x35');_0x4de2a4[_0x1c09('0x36')]={'Auto-Submitted':_0x1c09('0x37'),'X-Auto-Response-Suppress':_0x1c09('0x38'),'Precedence':_0x1c09('0x39')};return mailRpc[_0x1c09('0x3a')](this['account'][_0x1c09('0x3b')],_0x4de2a4)[_0x1c09('0x3c')](function(_0x21d6bb){logger[_0x1c09('0x15')](_0x1c09('0x3d'),_0x49cc45);_0x4de2a4[_0x1c09('0x2f')]=_0x21d6bb[_0x1c09('0x21')][_0x1c09('0x2f')];return rpc[_0x64dd0d+_0x1c09('0x2d')][_0x1c09('0x3e')](_0x4de2a4);})[_0x1c09('0x3c')](function(_0x845d57){logger[_0x1c09('0x15')](_0x1c09('0x16'),_0x49cc45,JSON[_0x1c09('0x3f')](_0x845d57));})[_0x1c09('0x40')](function(_0x1720b7){logger[_0x1c09('0x41')](_0x1c09('0x42'),_0x49cc45,JSON[_0x1c09('0x3f')](_0x1720b7));})[_0x1c09('0x43')](function(){Promise[_0x1c09('0x44')]()[_0x1c09('0x3c')](function(){if(_0x2a6479[0x0]!=='2'||_0x41dd3[_0x1c09('0x45')])return;return rpc[_0x64dd0d+_0x1c09('0x46')][_0x1c09('0x47')](_0x41dd3['id'],{'autoreplyExecuted':!![]})[_0x1c09('0x3c')](function(_0xe01fd8){logger[_0x1c09('0x15')](_0x1c09('0x1c'),_0x49cc45,JSON[_0x1c09('0x3f')](_0xe01fd8));})[_0x1c09('0x40')](function(_0xc3e406){logger[_0x1c09('0x41')](_0x1c09('0x48'),_0x49cc45,JSON['stringify'](_0xc3e406));});})[_0x1c09('0x3c')](function(){_0x411852[_0x1c09('0x1b')]();});});}else{return rpc[this[_0x1c09('0x11')]+'Message'][_0x1c09('0x3e')](_0x4de2a4)['then'](function(){logger[_0x1c09('0x15')]('[%s][AUTOREPLY]\x20%s',_0x49cc45,_0x4de2a4[_0x1c09('0x13')]);})[_0x1c09('0x40')](function(_0x25de79){logger[_0x1c09('0x41')](_0x1c09('0x16'),_0x49cc45,JSON[_0x1c09('0x3f')](_0x25de79));})['finally'](function(){Promise[_0x1c09('0x44')]()[_0x1c09('0x3c')](function(){if(_0x2a6479[0x0]!=='2'||_0x41dd3['autoreplyExecuted'])return;return rpc[_0x64dd0d+_0x1c09('0x46')][_0x1c09('0x47')](_0x41dd3['id'],{'autoreplyExecuted':!![]})['then'](function(_0x6b7109){logger[_0x1c09('0x15')]('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x49cc45,JSON[_0x1c09('0x3f')](_0x6b7109));})[_0x1c09('0x40')](function(_0x2d1c97){logger[_0x1c09('0x41')](_0x1c09('0x48'),_0x49cc45,JSON['stringify'](_0x2d1c97));});})[_0x1c09('0x3c')](function(){_0x411852['next']();});});}}}catch(_0x6cd7c0){logger[_0x1c09('0x41')](_0x1c09('0x16'),_0x49cc45,JSON[_0x1c09('0x3f')](_0x6cd7c0));_0x411852['stop']();}};};