Built motion from commit 87cd5f02.|2.5.48
[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 _0xebee=['interaction','created','Autoreply\x20already\x20sent','autoreplyExecuted','[%s][AUTOREPLY][autoreplyExecuted]\x20%s','contact','format','out','getMustacheRender','from','message','phone','read','subject','startsWith','Re:','Re:\x20','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','Message','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','<div','</div>','headers','All','auto_reply','sendMailMessage','smtpOptions','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','catch','[RPC][%s][AUTOREPLY]\x20%s','finally','resolve','Interaction','update','stringify','error','[RPC][%s][AUTOREPLY][autoreplyExecuted]\x20%s','create','stop','moment','./utils','../../../../config/logger','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../rpc/chatInteraction','../../rpc/openchannelInteraction','../../rpc/smsInteraction','../../rpc/faxInteraction','../../mailRpc','consequence','channel','mail','body','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20not\x20executed\x20(message\x20is\x20autoreply)','next','isNil'];(function(_0x2c4d17,_0x4f08e1){var _0x1f09cb=function(_0x4bf653){while(--_0x4bf653){_0x2c4d17['push'](_0x2c4d17['shift']());}};_0x1f09cb(++_0x4f08e1);}(_0xebee,0xb9));var _0xeebe=function(_0x25e9cd,_0x3e0260){_0x25e9cd=_0x25e9cd-0x0;var _0x35e363=_0xebee[_0x25e9cd];return _0x35e363;};'use strict';var _=require('lodash');var moment=require(_0xeebe('0x0'));var utils=require(_0xeebe('0x1'));var logger=require(_0xeebe('0x2'))('routing');var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xeebe('0x3')),'mailMessage':require(_0xeebe('0x4')),'smsMessage':require(_0xeebe('0x5')),'faxMessage':require(_0xeebe('0x6')),'whatsappMessage':require(_0xeebe('0x7')),'chatInteraction':require(_0xeebe('0x8')),'openchannelInteraction':require(_0xeebe('0x9')),'mailInteraction':require('../../rpc/mailInteraction'),'smsInteraction':require(_0xeebe('0xa')),'faxInteraction':require(_0xeebe('0xb')),'whatsappInteraction':require('../../rpc/whatsappInteraction')};var mailRpc=require(_0xeebe('0xc'));exports[_0xeebe('0xd')]=function(_0x1c35dd,_0x2df39f,_0x1036a7,_0x453223){return function(_0x22e95d){try{var _0x4a8033=this[_0xeebe('0xe')];if(_0x4a8033===_0xeebe('0xf')&&_0x453223[_0xeebe('0x10')]['isAutoreply']){logger[_0xeebe('0x11')](_0xeebe('0x12'),_0x1c35dd,_0xeebe('0x13'));return _0x22e95d[_0xeebe('0x14')]();}if(_0x2df39f[0x0]==='1'&&(_[_0xeebe('0x15')](this[_0xeebe('0x16')][_0xeebe('0x17')])||!this[_0xeebe('0x16')]['created'])){logger[_0xeebe('0x11')](_0xeebe('0x12'),_0x1c35dd,_0xeebe('0x18'));return _0x22e95d['next']();}if(_0x2df39f[0x0]==='2'&&this[_0xeebe('0x16')][_0xeebe('0x19')]){logger[_0xeebe('0x11')](_0xeebe('0x1a'),_0x1c35dd,'One\x20Time\x20already\x20sent');return _0x22e95d[_0xeebe('0x14')]();}var _0x53d8f6={'ContactId':this[_0xeebe('0x1b')]['id'],'sentAt':moment()[_0xeebe('0x1c')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0xeebe('0x1d')};if(this[_0xeebe('0xe')]==='mail'){_0x53d8f6['body']=utils[_0xeebe('0x1e')](_0x2df39f[0x2],this);}else{_0x53d8f6['body']=utils[_0xeebe('0x1e')](_0x2df39f[0x1],this);}if(this['message']){_0x53d8f6['to']=this['message'][_0xeebe('0x1f')]||'';if(this[_0xeebe('0xe')]==='mail'&&_0x2df39f[0x1]==='1'){_0x53d8f6['cc']=this[_0xeebe('0x20')]['cc']||'';}_0x53d8f6['from']=this[_0xeebe('0x20')]['to']||'';_0x53d8f6[_0xeebe('0x21')]=this['message'][_0xeebe('0x21')]||'';_0x53d8f6[_0xeebe('0x22')]=!![];if(this[_0xeebe('0x20')]['subject']){_0x53d8f6['subject']='';_0x53d8f6[_0xeebe('0x23')]+=_[_0xeebe('0x24')](this[_0xeebe('0x20')][_0xeebe('0x23')],_0xeebe('0x25'))?'':_0xeebe('0x26');_0x53d8f6[_0xeebe('0x23')]+=this['message']['subject'];}}if(this['channel']==='chat'){_0x53d8f6[_0xeebe('0x27')]=this['account']['id'];}else{_0x53d8f6[_[_0xeebe('0x28')](this[_0xeebe('0xe')])+_0xeebe('0x29')]=this[_0xeebe('0x2a')]['id'];}_0x53d8f6[_['upperFirst'](this[_0xeebe('0xe')])+_0xeebe('0x2b')]=this[_0xeebe('0x16')]['id'];var _0x4b2cbf=this['interaction'];if(rpc[this[_0xeebe('0xe')]+_0xeebe('0x2c')]){if(this[_0xeebe('0xe')]===_0xeebe('0xf')){_0x53d8f6[_0xeebe('0x2d')]=this[_0xeebe('0x20')][_0xeebe('0x2e')];_0x53d8f6[_0xeebe('0x2f')]=_0xeebe('0x30')+_['replace'](_0x53d8f6['body'],'<div\x20id=\x22xm-mail-content\x22',_0xeebe('0x31'))+_0xeebe('0x32');_0x53d8f6[_0xeebe('0x33')]={'Auto-Submitted':'auto-replied','X-Auto-Response-Suppress':_0xeebe('0x34'),'Precedence':_0xeebe('0x35')};return mailRpc[_0xeebe('0x36')](this[_0xeebe('0x2a')][_0xeebe('0x37')],_0x53d8f6)[_0xeebe('0x38')](function(_0x55c5b2){logger[_0xeebe('0x11')](_0xeebe('0x39'),_0x1c35dd);_0x53d8f6[_0xeebe('0x2e')]=_0x55c5b2[_0xeebe('0x20')][_0xeebe('0x2e')];return rpc[_0x4a8033+_0xeebe('0x2c')]['create'](_0x53d8f6);})[_0xeebe('0x38')](function(_0x365523){logger['info'](_0xeebe('0x12'),_0x1c35dd,JSON['stringify'](_0x365523));})[_0xeebe('0x3a')](function(_0x10b725){logger['error'](_0xeebe('0x3b'),_0x1c35dd,JSON['stringify'](_0x10b725));})[_0xeebe('0x3c')](function(){Promise[_0xeebe('0x3d')]()[_0xeebe('0x38')](function(){if(_0x2df39f[0x0]!=='2'||_0x4b2cbf[_0xeebe('0x19')])return;return rpc[_0x4a8033+_0xeebe('0x3e')][_0xeebe('0x3f')](_0x4b2cbf['id'],{'autoreplyExecuted':!![]})[_0xeebe('0x38')](function(_0x11e246){logger[_0xeebe('0x11')](_0xeebe('0x1a'),_0x1c35dd,JSON[_0xeebe('0x40')](_0x11e246));})[_0xeebe('0x3a')](function(_0x321f53){logger[_0xeebe('0x41')](_0xeebe('0x42'),_0x1c35dd,JSON['stringify'](_0x321f53));});})[_0xeebe('0x38')](function(){_0x22e95d[_0xeebe('0x14')]();});});}else{return rpc[this[_0xeebe('0xe')]+_0xeebe('0x2c')][_0xeebe('0x43')](_0x53d8f6)['then'](function(){logger[_0xeebe('0x11')](_0xeebe('0x12'),_0x1c35dd,_0x53d8f6[_0xeebe('0x10')]);})['catch'](function(_0x52a9b8){logger['error'](_0xeebe('0x12'),_0x1c35dd,JSON[_0xeebe('0x40')](_0x52a9b8));})[_0xeebe('0x3c')](function(){Promise[_0xeebe('0x3d')]()['then'](function(){if(_0x2df39f[0x0]!=='2'||_0x4b2cbf['autoreplyExecuted'])return;return rpc[_0x4a8033+'Interaction']['update'](_0x4b2cbf['id'],{'autoreplyExecuted':!![]})['then'](function(_0x1ef8d8){logger['info']('[%s][AUTOREPLY][autoreplyExecuted]\x20%s',_0x1c35dd,JSON[_0xeebe('0x40')](_0x1ef8d8));})[_0xeebe('0x3a')](function(_0x556eb7){logger['error'](_0xeebe('0x42'),_0x1c35dd,JSON[_0xeebe('0x40')](_0x556eb7));});})[_0xeebe('0x38')](function(){_0x22e95d[_0xeebe('0x14')]();});});}}}catch(_0x13b29a){logger[_0xeebe('0x41')](_0xeebe('0x12'),_0x1c35dd,JSON['stringify'](_0x13b29a));_0x22e95d[_0xeebe('0x44')]();}};};