2f823b0d44ffe77eae39fbc1b48c826957b59ba6
[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 _0xd9f4=['isNil','interaction','created','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20already\x20sent','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','mail','body','getMustacheRender','from','message','phone','read','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','Message','Smtp','service','host','port','secure','auth','pass','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','auto-replied','All','auto_reply','sendMailMessage','[%s][AUTOREPLY]\x20SMTP\x20SENT','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','then','next','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','../../mailRpc','consequence'];(function(_0x30e3c1,_0x1a36e3){var _0x1b3456=function(_0x53b2cd){while(--_0x53b2cd){_0x30e3c1['push'](_0x30e3c1['shift']());}};_0x1b3456(++_0x1a36e3);}(_0xd9f4,0x7b));var _0x4d9f=function(_0xbe200f,_0x4b50eb){_0xbe200f=_0xbe200f-0x0;var _0x192597=_0xd9f4[_0xbe200f];return _0x192597;};'use strict';var _=require(_0x4d9f('0x0'));var moment=require(_0x4d9f('0x1'));var utils=require(_0x4d9f('0x2'));var logger=require(_0x4d9f('0x3'))(_0x4d9f('0x4'));var rpc={'chatMessage':require(_0x4d9f('0x5')),'openchannelMessage':require(_0x4d9f('0x6')),'mailMessage':require(_0x4d9f('0x7')),'smsMessage':require(_0x4d9f('0x8')),'faxMessage':require(_0x4d9f('0x9')),'whatsappMessage':require(_0x4d9f('0xa'))};var mailRpc=require(_0x4d9f('0xb'));exports[_0x4d9f('0xc')]=function(_0x16a023,_0x8b2b40){return function(_0x1a8f08){try{if(_0x8b2b40[0x0]==='1'&&(_[_0x4d9f('0xd')](this[_0x4d9f('0xe')][_0x4d9f('0xf')])||!this[_0x4d9f('0xe')]['created'])){logger[_0x4d9f('0x10')](_0x4d9f('0x11'),_0x16a023,_0x4d9f('0x12'));return _0x1a8f08['next']();}var _0xb1659c=this['channel'];var _0x1193cb={'ContactId':this[_0x4d9f('0x13')]['id'],'sentAt':moment()[_0x4d9f('0x14')](_0x4d9f('0x15')),'direction':'out'};if(this[_0x4d9f('0x16')]===_0x4d9f('0x17')){_0x1193cb[_0x4d9f('0x18')]=utils[_0x4d9f('0x19')](_0x8b2b40[0x2],this);}else{_0x1193cb[_0x4d9f('0x18')]=utils[_0x4d9f('0x19')](_0x8b2b40[0x1],this);}if(this['message']){_0x1193cb['to']=this['message'][_0x4d9f('0x1a')]||'';if(this[_0x4d9f('0x16')]==='mail'&&_0x8b2b40[0x1]==='1'){_0x1193cb['cc']=this['message']['cc']||'';}_0x1193cb[_0x4d9f('0x1a')]=this[_0x4d9f('0x1b')]['to']||'';_0x1193cb[_0x4d9f('0x1c')]=this[_0x4d9f('0x1b')][_0x4d9f('0x1c')]||'';_0x1193cb[_0x4d9f('0x1d')]=!![];if(this[_0x4d9f('0x1b')][_0x4d9f('0x1e')]){_0x1193cb['subject']='';_0x1193cb[_0x4d9f('0x1e')]+=_[_0x4d9f('0x1f')](this[_0x4d9f('0x1b')][_0x4d9f('0x1e')],_0x4d9f('0x20'))?'':_0x4d9f('0x21');_0x1193cb[_0x4d9f('0x1e')]+=this[_0x4d9f('0x1b')]['subject'];}}if(this[_0x4d9f('0x16')]===_0x4d9f('0x22')){_0x1193cb[_0x4d9f('0x23')]=this[_0x4d9f('0x24')]['id'];}else{_0x1193cb[_[_0x4d9f('0x25')](this[_0x4d9f('0x16')])+_0x4d9f('0x26')]=this[_0x4d9f('0x24')]['id'];}_0x1193cb[_[_0x4d9f('0x25')](this[_0x4d9f('0x16')])+_0x4d9f('0x27')]=this[_0x4d9f('0xe')]['id'];if(rpc[this[_0x4d9f('0x16')]+_0x4d9f('0x28')]){if(this[_0x4d9f('0x16')]===_0x4d9f('0x17')){var _0x410ace={'tls':{'rejectUnauthorized':![]}};if(this[_0x4d9f('0x24')][_0x4d9f('0x29')]['service']){_0x410ace[_0x4d9f('0x2a')]=this['account'][_0x4d9f('0x29')][_0x4d9f('0x2a')];}else{_0x410ace[_0x4d9f('0x2b')]=this['account'][_0x4d9f('0x29')]['host'];_0x410ace[_0x4d9f('0x2c')]=this[_0x4d9f('0x24')][_0x4d9f('0x29')][_0x4d9f('0x2c')];_0x410ace[_0x4d9f('0x2d')]=this[_0x4d9f('0x24')]['Smtp']['secure'];}if(this[_0x4d9f('0x24')][_0x4d9f('0x29')]['authentication']){_0x410ace[_0x4d9f('0x2e')]={'user':this[_0x4d9f('0x24')][_0x4d9f('0x29')]['user'],'pass':this[_0x4d9f('0x24')][_0x4d9f('0x29')][_0x4d9f('0x2f')]};}_0x1193cb[_0x4d9f('0x30')]=this['message'][_0x4d9f('0x31')];_0x1193cb[_0x4d9f('0x32')]=_0x4d9f('0x33')+_['replace'](_0x1193cb['body'],_0x4d9f('0x34'),_0x4d9f('0x35'))+_0x4d9f('0x36');_0x1193cb[_0x4d9f('0x37')]={'Auto-Submitted':_0x4d9f('0x38'),'X-Auto-Response-Suppress':_0x4d9f('0x39'),'Precedence':_0x4d9f('0x3a')};return mailRpc[_0x4d9f('0x3b')](_0x410ace,_0x1193cb)['then'](function(_0x2e2379){logger[_0x4d9f('0x10')](_0x4d9f('0x3c'),_0x16a023);_0x1193cb[_0x4d9f('0x31')]=_0x2e2379[_0x4d9f('0x1b')]['messageId'];return rpc[_0xb1659c+_0x4d9f('0x28')]['create'](_0x1193cb);})['then'](function(_0x23f96d){logger[_0x4d9f('0x10')]('[%s][AUTOREPLY]\x20%s',_0x16a023,JSON[_0x4d9f('0x3d')](_0x23f96d));})[_0x4d9f('0x3e')](function(_0x2093eb){logger[_0x4d9f('0x3f')](_0x4d9f('0x40'),_0x16a023,JSON['stringify'](_0x2093eb));})[_0x4d9f('0x41')](function(){_0x1a8f08['next']();});}else{return rpc[this[_0x4d9f('0x16')]+'Message']['create'](_0x1193cb)[_0x4d9f('0x42')](function(_0x1d3ac6){logger[_0x4d9f('0x10')](_0x4d9f('0x11'),_0x16a023,_0x1193cb[_0x4d9f('0x18')]);})[_0x4d9f('0x3e')](function(_0x26a961){logger['error']('[%s][AUTOREPLY]\x20%s',_0x16a023,JSON[_0x4d9f('0x3d')](_0x26a961));})[_0x4d9f('0x41')](function(){_0x1a8f08[_0x4d9f('0x43')]();});}}}catch(_0x4f3129){logger[_0x4d9f('0x3f')](_0x4d9f('0x11'),_0x16a023,JSON[_0x4d9f('0x3d')](_0x4f3129));_0x1a8f08['stop']();}};};