Built motion from commit (unavailable).|2.5.1
[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 _0xf470=['isNil','interaction','created','info','[%s][AUTOREPLY]\x20%s','Autoreply\x20already\x20sent','next','channel','contact','YYYY-MM-DD\x20HH:mm:ss','out','mail','body','getMustacheRender','message','from','phone','read','subject','startsWith','Re:','Re:\x20','chat','ChatWebsiteId','account','upperFirst','Message','Smtp','service','host','port','secure','authentication','auth','pass','inReplyTo','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div\x20id=\x22xm-mail-content\x22','<div','</div>','headers','auto-replied','All','[%s][AUTOREPLY]\x20SMTP\x20SENT','messageId','create','stringify','catch','error','[RPC][%s][AUTOREPLY]\x20%s','finally','then','stop','lodash','moment','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','../../mailRpc','consequence'];(function(_0x329d13,_0x1aff27){var _0x33efd9=function(_0x265b7d){while(--_0x265b7d){_0x329d13['push'](_0x329d13['shift']());}};_0x33efd9(++_0x1aff27);}(_0xf470,0xfd));var _0x0f47=function(_0x160c73,_0x2ee678){_0x160c73=_0x160c73-0x0;var _0xd9302=_0xf470[_0x160c73];return _0xd9302;};'use strict';var _=require(_0x0f47('0x0'));var moment=require(_0x0f47('0x1'));var utils=require(_0x0f47('0x2'));var logger=require(_0x0f47('0x3'))(_0x0f47('0x4'));var rpc={'chatMessage':require(_0x0f47('0x5')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x0f47('0x6')),'smsMessage':require(_0x0f47('0x7')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x0f47('0x8'))};var mailRpc=require(_0x0f47('0x9'));exports[_0x0f47('0xa')]=function(_0x428c24,_0x42c33a){return function(_0x3c1886){try{if(_0x42c33a[0x0]==='1'&&(_[_0x0f47('0xb')](this[_0x0f47('0xc')][_0x0f47('0xd')])||!this[_0x0f47('0xc')][_0x0f47('0xd')])){logger[_0x0f47('0xe')](_0x0f47('0xf'),_0x428c24,_0x0f47('0x10'));return _0x3c1886[_0x0f47('0x11')]();}var _0x2196d2=this[_0x0f47('0x12')];var _0x423b4a={'ContactId':this[_0x0f47('0x13')]['id'],'sentAt':moment()['format'](_0x0f47('0x14')),'direction':_0x0f47('0x15')};if(this[_0x0f47('0x12')]===_0x0f47('0x16')){_0x423b4a[_0x0f47('0x17')]=utils['getMustacheRender'](_0x42c33a[0x2],this);}else{_0x423b4a['body']=utils[_0x0f47('0x18')](_0x42c33a[0x1],this);}if(this[_0x0f47('0x19')]){_0x423b4a['to']=this[_0x0f47('0x19')][_0x0f47('0x1a')]||'';if(this[_0x0f47('0x12')]==='mail'&&_0x42c33a[0x1]==='1'){_0x423b4a['cc']=this[_0x0f47('0x19')]['cc']||'';}_0x423b4a['from']=this['message']['to']||'';_0x423b4a[_0x0f47('0x1b')]=this[_0x0f47('0x19')][_0x0f47('0x1b')]||'';_0x423b4a[_0x0f47('0x1c')]=!![];if(this[_0x0f47('0x19')][_0x0f47('0x1d')]){_0x423b4a[_0x0f47('0x1d')]='';_0x423b4a['subject']+=_[_0x0f47('0x1e')](this[_0x0f47('0x19')]['subject'],_0x0f47('0x1f'))?'':_0x0f47('0x20');_0x423b4a[_0x0f47('0x1d')]+=this[_0x0f47('0x19')][_0x0f47('0x1d')];}}if(this[_0x0f47('0x12')]===_0x0f47('0x21')){_0x423b4a[_0x0f47('0x22')]=this[_0x0f47('0x23')]['id'];}else{_0x423b4a[_[_0x0f47('0x24')](this[_0x0f47('0x12')])+'AccountId']=this['account']['id'];}_0x423b4a[_['upperFirst'](this[_0x0f47('0x12')])+'InteractionId']=this['interaction']['id'];if(rpc[this[_0x0f47('0x12')]+_0x0f47('0x25')]){if(this[_0x0f47('0x12')]===_0x0f47('0x16')){var _0x28edc5={'tls':{'rejectUnauthorized':![]}};if(this[_0x0f47('0x23')][_0x0f47('0x26')]['service']){_0x28edc5['service']=this[_0x0f47('0x23')][_0x0f47('0x26')][_0x0f47('0x27')];}else{_0x28edc5['host']=this[_0x0f47('0x23')][_0x0f47('0x26')][_0x0f47('0x28')];_0x28edc5[_0x0f47('0x29')]=this['account'][_0x0f47('0x26')][_0x0f47('0x29')];_0x28edc5[_0x0f47('0x2a')]=this[_0x0f47('0x23')][_0x0f47('0x26')][_0x0f47('0x2a')];}if(this[_0x0f47('0x23')][_0x0f47('0x26')][_0x0f47('0x2b')]){_0x28edc5[_0x0f47('0x2c')]={'user':this[_0x0f47('0x23')][_0x0f47('0x26')]['user'],'pass':this[_0x0f47('0x23')][_0x0f47('0x26')][_0x0f47('0x2d')]};}_0x423b4a[_0x0f47('0x2e')]=this[_0x0f47('0x19')]['messageId'];_0x423b4a[_0x0f47('0x2f')]=_0x0f47('0x30')+_[_0x0f47('0x31')](_0x423b4a['body'],_0x0f47('0x32'),_0x0f47('0x33'))+_0x0f47('0x34');_0x423b4a[_0x0f47('0x35')]={'Auto-Submitted':_0x0f47('0x36'),'X-Auto-Response-Suppress':_0x0f47('0x37'),'Precedence':'auto_reply'};return mailRpc['sendMailMessage'](_0x28edc5,_0x423b4a)['then'](function(_0x29d2e9){logger['info'](_0x0f47('0x38'),_0x428c24);_0x423b4a['messageId']=_0x29d2e9[_0x0f47('0x19')][_0x0f47('0x39')];return rpc[_0x2196d2+_0x0f47('0x25')][_0x0f47('0x3a')](_0x423b4a);})['then'](function(_0x38470b){logger[_0x0f47('0xe')](_0x0f47('0xf'),_0x428c24,JSON[_0x0f47('0x3b')](_0x38470b));})[_0x0f47('0x3c')](function(_0x4d7d38){logger[_0x0f47('0x3d')](_0x0f47('0x3e'),_0x428c24,JSON[_0x0f47('0x3b')](_0x4d7d38));})[_0x0f47('0x3f')](function(){_0x3c1886[_0x0f47('0x11')]();});}else{return rpc[this['channel']+'Message']['create'](_0x423b4a)[_0x0f47('0x40')](function(_0x813d0d){logger[_0x0f47('0xe')]('[%s][AUTOREPLY]\x20%s',_0x428c24,_0x423b4a[_0x0f47('0x17')]);})[_0x0f47('0x3c')](function(_0x4814fe){logger['error']('[%s][AUTOREPLY]\x20%s',_0x428c24,JSON[_0x0f47('0x3b')](_0x4814fe));})['finally'](function(){_0x3c1886[_0x0f47('0x11')]();});}}}catch(_0x332e55){logger['error'](_0x0f47('0xf'),_0x428c24,JSON[_0x0f47('0x3b')](_0x332e55));_0x3c1886[_0x0f47('0x41')]();}};};