Built motion from commit (unavailable).|2.3.4
[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 _0xedd9=['catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','next','create','[%s][AUTOREPLY]\x20%s','stop','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../mailRpc','consequence','isNil','created','interaction','info','Autoreply\x20already\x20sent','channel','getMustacheRender','contact','YYYY-MM-DD\x20HH:mm:ss','out','message','from','phone','read','subject','startsWith','Re:','Re:\x20','ChatWebsiteId','upperFirst','InteractionId','Message','account','Smtp','service','host','port','secure','authentication','user','pass','inReplyTo','messageId','<div\x20id=\x22xm-mail-content\x22>','replace','body','<div\x20id=\x22xm-mail-content\x22','<div','</div>','sendMailMessage','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','stringify'];(function(_0x25d060,_0x418736){var _0x106892=function(_0x4aa250){while(--_0x4aa250){_0x25d060['push'](_0x25d060['shift']());}};_0x106892(++_0x418736);}(_0xedd9,0xfc));var _0x9edd=function(_0x24bff3,_0x12adbf){_0x24bff3=_0x24bff3-0x0;var _0x45a2e1=_0xedd9[_0x24bff3];return _0x45a2e1;};'use strict';var _=require('lodash');var moment=require(_0x9edd('0x0'));var utils=require(_0x9edd('0x1'));var logger=require(_0x9edd('0x2'))(_0x9edd('0x3'));var rpc={'chatMessage':require(_0x9edd('0x4')),'openchannelMessage':require(_0x9edd('0x5')),'mailMessage':require(_0x9edd('0x6')),'smsMessage':require(_0x9edd('0x7')),'faxMessage':require('../../rpc/faxMessage')};var mailRpc=require(_0x9edd('0x8'));exports[_0x9edd('0x9')]=function(_0x268f9e,_0x34c1a7){return function(_0x5319f7){try{if(_0x34c1a7[0x0]==='1'&&(_[_0x9edd('0xa')](this['interaction'][_0x9edd('0xb')])||!this[_0x9edd('0xc')][_0x9edd('0xb')])){logger[_0x9edd('0xd')]('[%s][AUTOREPLY]\x20%s',_0x268f9e,_0x9edd('0xe'));return _0x5319f7['next']();}var _0x2076fc=this[_0x9edd('0xf')];var _0x523026={'body':utils[_0x9edd('0x10')](_0x34c1a7[0x1],this),'ContactId':this[_0x9edd('0x11')]['id'],'sentAt':moment()['format'](_0x9edd('0x12')),'direction':_0x9edd('0x13')};if(this[_0x9edd('0x14')]){_0x523026['to']=this[_0x9edd('0x14')][_0x9edd('0x15')]||'';_0x523026['cc']=this[_0x9edd('0x14')]['cc']||'';_0x523026[_0x9edd('0x15')]=this[_0x9edd('0x14')]['to']||'';_0x523026['phone']=this[_0x9edd('0x14')][_0x9edd('0x16')]||'';_0x523026[_0x9edd('0x17')]=!![];if(this[_0x9edd('0x14')][_0x9edd('0x18')]){_0x523026[_0x9edd('0x18')]='';_0x523026[_0x9edd('0x18')]+=_[_0x9edd('0x19')](this['message'][_0x9edd('0x18')],_0x9edd('0x1a'))?'':_0x9edd('0x1b');_0x523026['subject']+=this[_0x9edd('0x14')][_0x9edd('0x18')];}}if(this[_0x9edd('0xf')]==='chat'){_0x523026[_0x9edd('0x1c')]=this['account']['id'];}else{_0x523026[_[_0x9edd('0x1d')](this[_0x9edd('0xf')])+'AccountId']=this['account']['id'];}_0x523026[_[_0x9edd('0x1d')](this['channel'])+_0x9edd('0x1e')]=this['interaction']['id'];if(rpc[this['channel']+_0x9edd('0x1f')]){if(this[_0x9edd('0xf')]==='mail'){var _0x5823bc={'tls':{'rejectUnauthorized':![]}};if(this[_0x9edd('0x20')][_0x9edd('0x21')][_0x9edd('0x22')]){_0x5823bc['service']=this[_0x9edd('0x20')][_0x9edd('0x21')][_0x9edd('0x22')];}else{_0x5823bc[_0x9edd('0x23')]=this[_0x9edd('0x20')]['Smtp'][_0x9edd('0x23')];_0x5823bc[_0x9edd('0x24')]=this[_0x9edd('0x20')][_0x9edd('0x21')][_0x9edd('0x24')];_0x5823bc['secure']=this['account'][_0x9edd('0x21')][_0x9edd('0x25')];}if(this[_0x9edd('0x20')][_0x9edd('0x21')][_0x9edd('0x26')]){_0x5823bc['auth']={'user':this['account'][_0x9edd('0x21')][_0x9edd('0x27')],'pass':this[_0x9edd('0x20')]['Smtp'][_0x9edd('0x28')]};}_0x523026[_0x9edd('0x29')]=this[_0x9edd('0x14')][_0x9edd('0x2a')];_0x523026['html']=_0x9edd('0x2b')+_[_0x9edd('0x2c')](_0x523026[_0x9edd('0x2d')],_0x9edd('0x2e'),_0x9edd('0x2f'))+_0x9edd('0x30');return mailRpc[_0x9edd('0x31')](_0x5823bc,_0x523026)[_0x9edd('0x32')](function(_0x19b6c1){logger[_0x9edd('0xd')](_0x9edd('0x33'),_0x268f9e);_0x523026[_0x9edd('0x2a')]=_0x19b6c1[_0x9edd('0x14')][_0x9edd('0x2a')];return rpc[_0x2076fc+_0x9edd('0x1f')]['create'](_0x523026);})[_0x9edd('0x32')](function(_0x259259){logger[_0x9edd('0xd')]('[%s][AUTOREPLY]\x20%s',_0x268f9e,JSON[_0x9edd('0x34')](_0x259259));})[_0x9edd('0x35')](function(_0xde9b13){logger[_0x9edd('0x36')](_0x9edd('0x37'),_0x268f9e,JSON[_0x9edd('0x34')](_0xde9b13));})[_0x9edd('0x38')](function(){_0x5319f7[_0x9edd('0x39')]();});}else{return rpc[this[_0x9edd('0xf')]+_0x9edd('0x1f')][_0x9edd('0x3a')](_0x523026)[_0x9edd('0x32')](function(_0x27eb7e){logger[_0x9edd('0xd')]('[%s][AUTOREPLY]\x20%s',_0x268f9e,_0x523026[_0x9edd('0x2d')]);})['catch'](function(_0x968303){logger[_0x9edd('0x36')](_0x9edd('0x3b'),_0x268f9e,JSON[_0x9edd('0x34')](_0x968303));})[_0x9edd('0x38')](function(){_0x5319f7['next']();});}}}catch(_0x6de835){logger[_0x9edd('0x36')](_0x9edd('0x3b'),_0x268f9e,JSON[_0x9edd('0x34')](_0x6de835));_0x5319f7[_0x9edd('0x3c')]();}};};