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