Built motion from commit (unavailable).|2.5.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 _0x71f9=['Re:','Re:\x20','chat','account','InteractionId','Message','mail','Smtp','service','port','secure','authentication','auth','user','inReplyTo','messageId','html','<div\x20id=\x22xm-mail-content\x22>','replace','<div','</div>','sendMailMessage','then','[%s][AUTOREPLY]\x20SMTP\x20SENT','create','stringify','catch','error','finally','body','stop','moment','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../mailRpc','consequence','isNil','interaction','created','info','[%s][AUTOREPLY]\x20%s','next','channel','getMustacheRender','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','message','from','phone','read','subject'];(function(_0x4404ff,_0x13d7a9){var _0x5e7b19=function(_0x13847a){while(--_0x13847a){_0x4404ff['push'](_0x4404ff['shift']());}};_0x5e7b19(++_0x13d7a9);}(_0x71f9,0x8f));var _0x971f=function(_0x321874,_0x3e8383){_0x321874=_0x321874-0x0;var _0xd4acf7=_0x71f9[_0x321874];return _0xd4acf7;};'use strict';var _=require('lodash');var moment=require(_0x971f('0x0'));var utils=require('./utils');var logger=require('../../../../config/logger')(_0x971f('0x1'));var rpc={'chatMessage':require(_0x971f('0x2')),'openchannelMessage':require(_0x971f('0x3')),'mailMessage':require(_0x971f('0x4')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0x971f('0x5')),'whatsappMessage':require('../../rpc/whatsappMessage')};var mailRpc=require(_0x971f('0x6'));exports[_0x971f('0x7')]=function(_0x3ff9b9,_0xd3b9df){return function(_0x4b0d4f){try{if(_0xd3b9df[0x0]==='1'&&(_[_0x971f('0x8')](this[_0x971f('0x9')][_0x971f('0xa')])||!this[_0x971f('0x9')][_0x971f('0xa')])){logger[_0x971f('0xb')](_0x971f('0xc'),_0x3ff9b9,'Autoreply\x20already\x20sent');return _0x4b0d4f[_0x971f('0xd')]();}var _0x905089=this[_0x971f('0xe')];var _0x9aff16={'body':utils[_0x971f('0xf')](_0xd3b9df[0x1],this),'ContactId':this[_0x971f('0x10')]['id'],'sentAt':moment()[_0x971f('0x11')](_0x971f('0x12')),'direction':_0x971f('0x13')};if(this[_0x971f('0x14')]){_0x9aff16['to']=this['message'][_0x971f('0x15')]||'';_0x9aff16['cc']=this[_0x971f('0x14')]['cc']||'';_0x9aff16[_0x971f('0x15')]=this['message']['to']||'';_0x9aff16['phone']=this[_0x971f('0x14')][_0x971f('0x16')]||'';_0x9aff16[_0x971f('0x17')]=!![];if(this[_0x971f('0x14')][_0x971f('0x18')]){_0x9aff16[_0x971f('0x18')]='';_0x9aff16[_0x971f('0x18')]+=_['startsWith'](this[_0x971f('0x14')][_0x971f('0x18')],_0x971f('0x19'))?'':_0x971f('0x1a');_0x9aff16[_0x971f('0x18')]+=this[_0x971f('0x14')][_0x971f('0x18')];}}if(this[_0x971f('0xe')]===_0x971f('0x1b')){_0x9aff16['ChatWebsiteId']=this[_0x971f('0x1c')]['id'];}else{_0x9aff16[_['upperFirst'](this['channel'])+'AccountId']=this[_0x971f('0x1c')]['id'];}_0x9aff16[_['upperFirst'](this[_0x971f('0xe')])+_0x971f('0x1d')]=this['interaction']['id'];if(rpc[this['channel']+_0x971f('0x1e')]){if(this['channel']===_0x971f('0x1f')){var _0x4e1f34={'tls':{'rejectUnauthorized':![]}};if(this[_0x971f('0x1c')][_0x971f('0x20')][_0x971f('0x21')]){_0x4e1f34[_0x971f('0x21')]=this[_0x971f('0x1c')]['Smtp'][_0x971f('0x21')];}else{_0x4e1f34['host']=this['account'][_0x971f('0x20')]['host'];_0x4e1f34[_0x971f('0x22')]=this[_0x971f('0x1c')][_0x971f('0x20')][_0x971f('0x22')];_0x4e1f34[_0x971f('0x23')]=this['account']['Smtp'][_0x971f('0x23')];}if(this[_0x971f('0x1c')]['Smtp'][_0x971f('0x24')]){_0x4e1f34[_0x971f('0x25')]={'user':this['account'][_0x971f('0x20')][_0x971f('0x26')],'pass':this[_0x971f('0x1c')][_0x971f('0x20')]['pass']};}_0x9aff16[_0x971f('0x27')]=this[_0x971f('0x14')][_0x971f('0x28')];_0x9aff16[_0x971f('0x29')]=_0x971f('0x2a')+_[_0x971f('0x2b')](_0x9aff16['body'],'<div\x20id=\x22xm-mail-content\x22',_0x971f('0x2c'))+_0x971f('0x2d');return mailRpc[_0x971f('0x2e')](_0x4e1f34,_0x9aff16)[_0x971f('0x2f')](function(_0x249d19){logger[_0x971f('0xb')](_0x971f('0x30'),_0x3ff9b9);_0x9aff16[_0x971f('0x28')]=_0x249d19[_0x971f('0x14')]['messageId'];return rpc[_0x905089+_0x971f('0x1e')][_0x971f('0x31')](_0x9aff16);})[_0x971f('0x2f')](function(_0x4745d3){logger[_0x971f('0xb')](_0x971f('0xc'),_0x3ff9b9,JSON[_0x971f('0x32')](_0x4745d3));})[_0x971f('0x33')](function(_0x262bcb){logger[_0x971f('0x34')]('[RPC][%s][AUTOREPLY]\x20%s',_0x3ff9b9,JSON[_0x971f('0x32')](_0x262bcb));})[_0x971f('0x35')](function(){_0x4b0d4f[_0x971f('0xd')]();});}else{return rpc[this['channel']+_0x971f('0x1e')][_0x971f('0x31')](_0x9aff16)[_0x971f('0x2f')](function(_0x5c5480){logger[_0x971f('0xb')](_0x971f('0xc'),_0x3ff9b9,_0x9aff16[_0x971f('0x36')]);})['catch'](function(_0x2dd7b3){logger[_0x971f('0x34')](_0x971f('0xc'),_0x3ff9b9,JSON[_0x971f('0x32')](_0x2dd7b3));})[_0x971f('0x35')](function(){_0x4b0d4f['next']();});}}}catch(_0x309e0c){logger[_0x971f('0x34')](_0x971f('0xc'),_0x3ff9b9,JSON[_0x971f('0x32')](_0x309e0c));_0x4b0d4f[_0x971f('0x37')]();}};};