5c83eb130d858151aaf7f2a818fcde6ec32b1303
[motion2.git] / server / api / chatWebsite / chatWebsite.controller.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 _0x3f40=['applications','list','orderBy','priority','asc','customerIp','cf-connecting-ip','x-forwarded-for','split','firstName','x-real-port','referer','browser','version','format','%s\x20%s','unknown','device','vendor','%s\x20%s\x20%s','threadId','ChatInteraction','ContactId','spread','lastName','messageId','created','autoclose','push','close','unmanaged','ChatMessage','AttachmentId','UserId','User','unshift','agent','forcedOwnership','Start','startRouting','EventManager','offline','createdAt','CompanyId','mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKeyOffline','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','MailAccount','findOrCreate','server/files/templates/chatOfflineMessage.ejs','utf8','toPairs','offlineMessageBody','ChatOfflineMessage','server','files','attachments','offline-chat','basename','openNewInteraction','sequelize','transaction','bulkCreate','forwardOfflineAddress','Smtp','service','host','port','secure','authentication','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','offlineMessageSubject','subjectOffline','toPairsIn','mapValues','Chat','MailAccountId','NotifyMailAccount','notifyMail','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Owner','fullname','internal','Tag','Tags','color','tag','Command','iftime\x20%s,%s','interval','timezone','iftime\x20%s','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','No\x20timezone','inspect','getSnippet','Interval','Intervals','virtual','custom','chatLicenseExceeded','all','some','readFileSync','server/files/chat/iframe.js','remote','replace','verticalAlignment','textColor','color_button','backgroundColor','findAndCountAll','getApplications','addProactiveActions','chatProactiveAction','getProactiveActions','ChatProactiveAction','online','false','items','fromKey','getOfflineMessages','Attachment','addAgents','userChatWebsite:save','removeAgents','isArray','emit','userChatWebsite:remove','getAgents','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../mysqldb','redis','defaults','localhost','./chatWebsite.socket','register','client','http','request','then','info','ChatWebsite,\x20%s,\x20%s','ChatWebsite,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','sendStatus','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','destroy','get','ChatWebsites','UserProfileResource','end','stack','name','send','render','merge','body','contact','interaction','account','index','Pause','mandatoryDispositionPause','ChatWebsite','rawAttributes','fieldName','map','query','keys','filters','intersection','model','fields','attributes','length','nolimit','order','sort','pick','where','type','filter','options','includeAll','include','findAll','catch','show','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','autoAssociation','params','describe','addDisposition','ChatWebsiteId','Disposition','hasOwnProperty','rows','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','findOne','removeAnswers','sitepic','file','filename','addAvatar','agentAvatar','addCustomerAvatar','customerAvatar','addSystemAvatar','getLogo','join','root','../../config/license/util','getLicense','isNil','existsSync','server/files/images/logos/','download','getAvatar','server/files/images/avatars/default_avatar.png','server/files/images/avatars/','getCustomerAvatar','server/files/images/avatars/customer_avatar.png','showCustomerAvatar','getSystemAvatar','server/files/images/avatars/system_avatar.png','systemAvatar','notify','user-agent-parser','setUA','headers','user-agent','chat','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','updatedAt','ListId','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','List','Contacts','DESC','ChatApplication','Applications'];(function(_0x20d54d,_0x1adc8e){var _0x516e8b=function(_0x2754e1){while(--_0x2754e1){_0x20d54d['push'](_0x20d54d['shift']());}};_0x516e8b(++_0x1adc8e);}(_0x3f40,0x1bb));var _0x03f4=function(_0x183c48,_0x406657){_0x183c48=_0x183c48-0x0;var _0x45dce8=_0x3f40[_0x183c48];return _0x45dce8;};'use strict';var emlformat=require(_0x03f4('0x0'));var rimraf=require(_0x03f4('0x1'));var zipdir=require(_0x03f4('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x03f4('0x3'));var moment=require(_0x03f4('0x4'));var BPromise=require(_0x03f4('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x03f4('0x6'));var sox=require(_0x03f4('0x7'));var csv=require('to-csv');var ejs=require(_0x03f4('0x8'));var fs=require('fs');var fs_extra=require(_0x03f4('0x9'));var _=require(_0x03f4('0xa'));var squel=require(_0x03f4('0xb'));var crypto=require(_0x03f4('0xc'));var jsforce=require(_0x03f4('0xd'));var deskjs=require(_0x03f4('0xe'));var toCsv=require(_0x03f4('0xf'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x03f4('0x10'));var qs=require(_0x03f4('0x11'));var as=require(_0x03f4('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x03f4('0x13'));var utils=require('../../config/utils');var config=require(_0x03f4('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x03f4('0x15'))['db'];config[_0x03f4('0x16')]=_[_0x03f4('0x17')](config[_0x03f4('0x16')],{'host':_0x03f4('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x03f4('0x16')]));require(_0x03f4('0x19'))[_0x03f4('0x1a')](socket);var jayson=require('jayson/promise');var client=jayson[_0x03f4('0x1b')][_0x03f4('0x1c')]({'port':0x232c});var client9002=jayson[_0x03f4('0x1b')]['http']({'port':0x232a});var client9003=jayson[_0x03f4('0x1b')][_0x03f4('0x1c')]({'port':0x232b});var client9001=jayson[_0x03f4('0x1b')][_0x03f4('0x1c')]({'port':0x2329});function respondWithRpcPromise(_0x5a50f1,_0x367d34,_0x3c2b8d,_0x130258){return new BPromise(function(_0x4c183d,_0x27f437){var _0xd1827e=_0x130258||client;return _0xd1827e[_0x03f4('0x1d')](_0x5a50f1,_0x3c2b8d)[_0x03f4('0x1e')](function(_0x1d4f17){logger[_0x03f4('0x1f')](_0x03f4('0x20'),_0x367d34,'request\x20sent');logger['debug'](_0x03f4('0x21'),_0x367d34,_0x03f4('0x22'),JSON[_0x03f4('0x23')](_0x1d4f17));if(_0x1d4f17[_0x03f4('0x24')]){if(_0x1d4f17[_0x03f4('0x24')][_0x03f4('0x25')]===0x1f4){logger[_0x03f4('0x24')](_0x03f4('0x20'),_0x367d34,_0x1d4f17['error'][_0x03f4('0x26')]);return _0x27f437(_0x1d4f17['error'][_0x03f4('0x26')]);}logger['error'](_0x03f4('0x20'),_0x367d34,_0x1d4f17[_0x03f4('0x24')][_0x03f4('0x26')]);return _0x4c183d(_0x1d4f17[_0x03f4('0x24')][_0x03f4('0x26')]);}else{logger[_0x03f4('0x1f')](_0x03f4('0x20'),_0x367d34,_0x03f4('0x22'));_0x4c183d(_0x1d4f17['result'][_0x03f4('0x26')]);}})['catch'](function(_0x158329){logger['error'](_0x03f4('0x20'),_0x367d34,_0x158329);_0x27f437(_0x158329);});});}function respondWithStatusCode(_0x18f6ef,_0x13f842){_0x13f842=_0x13f842||0xcc;return function(_0x5853c0){if(_0x5853c0){return _0x18f6ef[_0x03f4('0x27')](_0x13f842);}return _0x18f6ef[_0x03f4('0x28')](_0x13f842)['end']();};}function respondWithResult(_0x194758,_0x5a5c29){_0x5a5c29=_0x5a5c29||0xc8;return function(_0x1ea018){if(_0x1ea018){return _0x194758[_0x03f4('0x28')](_0x5a5c29)[_0x03f4('0x29')](_0x1ea018);}};}function respondWithFilteredResult(_0x1b347c,_0x481e56){return function(_0x527f9d){if(_0x527f9d){var _0x528cd4=typeof _0x481e56['offset']===_0x03f4('0x2a')&&typeof _0x481e56[_0x03f4('0x2b')]===_0x03f4('0x2a');var _0x3b9745=_0x527f9d['count'];var _0x59a3cd=_0x528cd4?0x0:_0x481e56['offset'];var _0x5976c1=_0x528cd4?_0x527f9d[_0x03f4('0x2c')]:_0x481e56[_0x03f4('0x2d')]+_0x481e56[_0x03f4('0x2b')];var _0x4f0d50;if(_0x5976c1>=_0x3b9745){_0x5976c1=_0x3b9745;_0x4f0d50=0xc8;}else{_0x4f0d50=0xce;}_0x1b347c[_0x03f4('0x28')](_0x4f0d50);return _0x1b347c[_0x03f4('0x2e')](_0x03f4('0x2f'),_0x59a3cd+'-'+_0x5976c1+'/'+_0x3b9745)['json'](_0x527f9d);}return null;};}function patchUpdates(_0x357739){return function(_0x59234f){try{jsonpatch[_0x03f4('0x30')](_0x59234f,_0x357739,!![]);}catch(_0x45c790){return BPromise[_0x03f4('0x31')](_0x45c790);}return _0x59234f[_0x03f4('0x32')]();};}function saveUpdates(_0x4a5dbd,_0xa3043e){return function(_0x1850b8){if(_0x1850b8){return _0x1850b8[_0x03f4('0x33')](_0x4a5dbd)['then'](function(_0x479137){return _0x479137;});}return null;};}function removeEntity(_0x41a035,_0x5083e1){return function(_0x135194){if(_0x135194){return _0x135194[_0x03f4('0x34')]()[_0x03f4('0x1e')](function(){var _0x1178cf=_0x135194[_0x03f4('0x35')]({'plain':!![]});var _0x56aa1a=_0x03f4('0x36');return db[_0x03f4('0x37')][_0x03f4('0x34')]({'where':{'type':_0x56aa1a,'resourceId':_0x1178cf['id']}})[_0x03f4('0x1e')](function(){return _0x135194;});})[_0x03f4('0x1e')](function(){_0x41a035[_0x03f4('0x28')](0xcc)[_0x03f4('0x38')]();});}};}function handleEntityNotFound(_0x5e32ff,_0x1fbd10){return function(_0xde1d23){if(!_0xde1d23){_0x5e32ff[_0x03f4('0x27')](0x194);}return _0xde1d23;};}function handleError(_0x1967fc,_0xb9bf0b){_0xb9bf0b=_0xb9bf0b||0x1f4;return function(_0x39027c){logger[_0x03f4('0x24')](_0x39027c[_0x03f4('0x39')]);if(_0x39027c['name']){delete _0x39027c[_0x03f4('0x3a')];}_0x1967fc[_0x03f4('0x28')](_0xb9bf0b)[_0x03f4('0x3b')](_0x39027c);};}function getMustacheRender(_0x3fdfe6,_0x1ed72b){return Mustache[_0x03f4('0x3c')](_0x3fdfe6,_[_0x03f4('0x3d')](_0x1ed72b[_0x03f4('0x3e')],{'contact':_0x1ed72b[_0x03f4('0x3f')],'message':_0x1ed72b[_0x03f4('0x26')],'agent':_0x1ed72b['agent'],'interaction':_0x1ed72b[_0x03f4('0x40')],'account':_0x1ed72b[_0x03f4('0x41')]}))||'';}exports[_0x03f4('0x42')]=function(_0x36a7bb,_0x570325){var _0x2d8230={'include':[{'model':db[_0x03f4('0x43')],'as':_0x03f4('0x44')}]},_0x52eee9={},_0x23740b={'count':0x0,'rows':[]};var _0x115741=_['map'](db[_0x03f4('0x45')][_0x03f4('0x46')],function(_0x4fb76b){return{'name':_0x4fb76b[_0x03f4('0x47')],'type':_0x4fb76b['type']['key']};});_0x52eee9['model']=_[_0x03f4('0x48')](_0x115741,_0x03f4('0x3a'));_0x52eee9[_0x03f4('0x49')]=_[_0x03f4('0x4a')](_0x36a7bb[_0x03f4('0x49')]);_0x52eee9[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x52eee9[_0x03f4('0x4d')],_0x52eee9[_0x03f4('0x49')]);_0x2d8230['attributes']=_[_0x03f4('0x4c')](_0x52eee9[_0x03f4('0x4d')],qs[_0x03f4('0x4e')](_0x36a7bb['query'][_0x03f4('0x4e')]));_0x2d8230[_0x03f4('0x4f')]=_0x2d8230[_0x03f4('0x4f')][_0x03f4('0x50')]?_0x2d8230[_0x03f4('0x4f')]:_0x52eee9[_0x03f4('0x4d')];if(!_0x36a7bb[_0x03f4('0x49')]['hasOwnProperty'](_0x03f4('0x51'))){_0x2d8230['limit']=qs[_0x03f4('0x2b')](_0x36a7bb['query'][_0x03f4('0x2b')]);_0x2d8230[_0x03f4('0x2d')]=qs[_0x03f4('0x2d')](_0x36a7bb[_0x03f4('0x49')][_0x03f4('0x2d')]);}_0x2d8230[_0x03f4('0x52')]=qs[_0x03f4('0x53')](_0x36a7bb[_0x03f4('0x49')][_0x03f4('0x53')]);_0x2d8230['where']=qs[_0x03f4('0x4b')](_[_0x03f4('0x54')](_0x36a7bb[_0x03f4('0x49')],_0x52eee9['filters']),_0x115741);if(_0x36a7bb[_0x03f4('0x49')]['filter']){_0x2d8230['where']=_[_0x03f4('0x3d')](_0x2d8230[_0x03f4('0x55')],{'$or':_[_0x03f4('0x48')](_0x115741,function(_0x45c132){if(_0x45c132[_0x03f4('0x56')]!=='VIRTUAL'){var _0x290819={};_0x290819[_0x45c132['name']]={'$like':'%'+_0x36a7bb['query'][_0x03f4('0x57')]+'%'};return _0x290819;}})});}_0x2d8230=_[_0x03f4('0x3d')]({},_0x2d8230,_0x36a7bb[_0x03f4('0x58')]);var _0x4e03e0={'where':_0x2d8230['where']};return db['ChatWebsite'][_0x03f4('0x2c')](_0x4e03e0)[_0x03f4('0x1e')](function(_0x5841d6){_0x23740b[_0x03f4('0x2c')]=_0x5841d6;if(_0x36a7bb['query'][_0x03f4('0x59')]){_0x2d8230[_0x03f4('0x5a')]=[{'all':!![]}];}return db['ChatWebsite'][_0x03f4('0x5b')](_0x2d8230);})[_0x03f4('0x1e')](function(_0x2dd2a1){_0x23740b['rows']=_0x2dd2a1;return _0x23740b;})[_0x03f4('0x1e')](respondWithFilteredResult(_0x570325,_0x2d8230))[_0x03f4('0x5c')](handleError(_0x570325,null));};exports[_0x03f4('0x5d')]=function(_0xe4a2cc,_0x5955c4){var _0x5434f2={'raw':![],'where':{'id':_0xe4a2cc['params']['id']},'include':[{'model':db['Pause'],'as':_0x03f4('0x44')}]},_0x4a463b={};_0x4a463b[_0x03f4('0x4d')]=_['keys'](db[_0x03f4('0x45')][_0x03f4('0x46')]);_0x4a463b[_0x03f4('0x49')]=_['keys'](_0xe4a2cc[_0x03f4('0x49')]);_0x4a463b[_0x03f4('0x4b')]=_['intersection'](_0x4a463b[_0x03f4('0x4d')],_0x4a463b[_0x03f4('0x49')]);_0x5434f2[_0x03f4('0x4f')]=_[_0x03f4('0x4c')](_0x4a463b[_0x03f4('0x4d')],qs[_0x03f4('0x4e')](_0xe4a2cc[_0x03f4('0x49')][_0x03f4('0x4e')]));_0x5434f2[_0x03f4('0x4f')]=_0x5434f2[_0x03f4('0x4f')]['length']?_0x5434f2[_0x03f4('0x4f')]:_0x4a463b[_0x03f4('0x4d')];if(_0xe4a2cc[_0x03f4('0x49')][_0x03f4('0x59')]){_0x5434f2[_0x03f4('0x5a')]=[{'all':!![]}];}_0x5434f2=_[_0x03f4('0x3d')]({},_0x5434f2,_0xe4a2cc['options']);return db['ChatWebsite'][_0x03f4('0x5e')](_0x5434f2)['then'](handleEntityNotFound(_0x5955c4,null))[_0x03f4('0x1e')](respondWithResult(_0x5955c4,null))[_0x03f4('0x5c')](handleError(_0x5955c4,null));};exports[_0x03f4('0x5f')]=function(_0x262ee8,_0x671354){return db[_0x03f4('0x45')][_0x03f4('0x5f')](_0x262ee8[_0x03f4('0x3e')],{})[_0x03f4('0x1e')](function(_0x1e705b){var _0x3612f2=_0x262ee8[_0x03f4('0x60')][_0x03f4('0x35')]({'plain':!![]});if(!_0x3612f2)throw new Error(_0x03f4('0x61'));if(_0x3612f2['role']==='user'){var _0x305946=_0x1e705b[_0x03f4('0x35')]({'plain':!![]});var _0x32dfd5='ChatWebsites';return db[_0x03f4('0x62')][_0x03f4('0x5e')]({'where':{'name':_0x32dfd5,'userProfileId':_0x3612f2['userProfileId']},'raw':!![]})[_0x03f4('0x1e')](function(_0x89667a){if(_0x89667a&&_0x89667a[_0x03f4('0x63')]===0x0){return db[_0x03f4('0x37')]['create']({'name':_0x305946[_0x03f4('0x3a')],'resourceId':_0x305946['id'],'type':_0x89667a[_0x03f4('0x3a')],'sectionId':_0x89667a['id']},{})[_0x03f4('0x1e')](function(){return _0x1e705b;});}else{return _0x1e705b;}})[_0x03f4('0x5c')](function(_0x50cda6){logger[_0x03f4('0x24')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x50cda6);throw _0x50cda6;});}return _0x1e705b;})[_0x03f4('0x1e')](respondWithResult(_0x671354,0xc9))[_0x03f4('0x5c')](handleError(_0x671354,null));};exports[_0x03f4('0x33')]=function(_0x511c0f,_0x1070de){if(_0x511c0f[_0x03f4('0x3e')]['id']){delete _0x511c0f[_0x03f4('0x3e')]['id'];}return db['ChatWebsite'][_0x03f4('0x5e')]({'where':{'id':_0x511c0f[_0x03f4('0x64')]['id']},'include':[{'model':db['Pause'],'as':_0x03f4('0x44')}]})[_0x03f4('0x1e')](handleEntityNotFound(_0x1070de,null))[_0x03f4('0x1e')](saveUpdates(_0x511c0f['body'],null))[_0x03f4('0x1e')](respondWithResult(_0x1070de,null))[_0x03f4('0x5c')](handleError(_0x1070de,null));};exports[_0x03f4('0x34')]=function(_0x11bbae,_0x250359){return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'where':{'id':_0x11bbae[_0x03f4('0x64')]['id']}})['then'](handleEntityNotFound(_0x250359,null))['then'](removeEntity(_0x250359,null))[_0x03f4('0x5c')](handleError(_0x250359,null));};exports['describe']=function(_0x27538b,_0x495235){return db[_0x03f4('0x45')][_0x03f4('0x65')]()[_0x03f4('0x1e')](respondWithResult(_0x495235,null))[_0x03f4('0x5c')](handleError(_0x495235,null));};exports[_0x03f4('0x66')]=function(_0x2ffdbe,_0x4196e3,_0x38dde2){if(_0x2ffdbe[_0x03f4('0x3e')]['id']){delete _0x2ffdbe['body']['id'];}return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'where':{'id':_0x2ffdbe[_0x03f4('0x64')]['id']}})['then'](handleEntityNotFound(_0x4196e3,null))['then'](function(_0x33d063){if(_0x33d063){_0x2ffdbe[_0x03f4('0x3e')][_0x03f4('0x67')]=_0x33d063['id'];return db[_0x03f4('0x68')][_0x03f4('0x5f')](_0x2ffdbe[_0x03f4('0x3e')]);}})[_0x03f4('0x1e')](respondWithResult(_0x4196e3,null))[_0x03f4('0x5c')](handleError(_0x4196e3,null));};exports['getDispositions']=function(_0x110571,_0x4e848c,_0x4fa801){var _0x5d3e1d={'raw':![],'where':{}};var _0x15d388={};var _0x56c398={'count':0x0,'rows':[]};return db[_0x03f4('0x45')]['findOne']({'where':{'id':_0x110571[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x4e848c,null))[_0x03f4('0x1e')](function(_0x4d6c90){if(_0x4d6c90){_0x15d388['model']=_['keys'](db[_0x03f4('0x68')]['rawAttributes']);_0x15d388[_0x03f4('0x49')]=_[_0x03f4('0x4a')](_0x110571[_0x03f4('0x49')]);_0x15d388[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x15d388[_0x03f4('0x4d')],_0x15d388[_0x03f4('0x49')]);_0x5d3e1d['attributes']=_['intersection'](_0x15d388[_0x03f4('0x4d')],qs[_0x03f4('0x4e')](_0x110571[_0x03f4('0x49')]['fields']));_0x5d3e1d[_0x03f4('0x4f')]=_0x5d3e1d['attributes']['length']?_0x5d3e1d[_0x03f4('0x4f')]:_0x15d388[_0x03f4('0x4d')];if(!_0x110571[_0x03f4('0x49')][_0x03f4('0x69')](_0x03f4('0x51'))){_0x5d3e1d[_0x03f4('0x2b')]=qs['limit'](_0x110571[_0x03f4('0x49')]['limit']);_0x5d3e1d['offset']=qs['offset'](_0x110571[_0x03f4('0x49')][_0x03f4('0x2d')]);}_0x5d3e1d[_0x03f4('0x52')]=qs[_0x03f4('0x53')](_0x110571[_0x03f4('0x49')]['sort']);_0x5d3e1d[_0x03f4('0x55')]=qs[_0x03f4('0x4b')](_['pick'](_0x110571['query'],_0x15d388[_0x03f4('0x4b')]));_0x5d3e1d[_0x03f4('0x55')][_0x03f4('0x67')]=_0x4d6c90['id'];if(_0x110571['query'][_0x03f4('0x57')]){_0x5d3e1d['where']=_[_0x03f4('0x3d')](_0x5d3e1d[_0x03f4('0x55')],{'$or':_[_0x03f4('0x48')](_0x5d3e1d['attributes'],function(_0x99fe47){var _0x5bf66b={};_0x5bf66b[_0x99fe47]={'$like':'%'+_0x110571[_0x03f4('0x49')]['filter']+'%'};return _0x5bf66b;})});}_0x5d3e1d=_[_0x03f4('0x3d')]({},_0x5d3e1d,_0x110571[_0x03f4('0x58')]);return db[_0x03f4('0x68')][_0x03f4('0x2c')]({'where':_0x5d3e1d['where']})[_0x03f4('0x1e')](function(_0x113853){_0x56c398[_0x03f4('0x2c')]=_0x113853;if(_0x110571['query'][_0x03f4('0x59')]){_0x5d3e1d[_0x03f4('0x5a')]=[{'all':!![]}];}return db[_0x03f4('0x68')]['findAll'](_0x5d3e1d);})[_0x03f4('0x1e')](function(_0x2e8ee2){_0x56c398[_0x03f4('0x6a')]=_0x2e8ee2;return _0x56c398;});}})[_0x03f4('0x1e')](respondWithFilteredResult(_0x4e848c,_0x5d3e1d))[_0x03f4('0x5c')](handleError(_0x4e848c,null));};exports[_0x03f4('0x6b')]=function(_0x1f3fdf,_0x178449,_0x287e35){return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'where':{'id':_0x1f3fdf[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x178449,null))[_0x03f4('0x1e')](function(_0x2b5885){if(_0x2b5885){return _0x2b5885[_0x03f4('0x6b')](_0x1f3fdf['query'][_0x03f4('0x6c')]);}})['then'](respondWithStatusCode(_0x178449,null))['catch'](handleError(_0x178449,null));};exports[_0x03f4('0x6d')]=function(_0xcb51d1,_0xb78a54,_0x4b4b8c){if(_0xcb51d1[_0x03f4('0x3e')]['id']){delete _0xcb51d1[_0x03f4('0x3e')]['id'];}return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'where':{'id':_0xcb51d1['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0xb78a54,null))[_0x03f4('0x1e')](function(_0x57dce6){if(_0x57dce6){_0xcb51d1[_0x03f4('0x3e')]['ChatWebsiteId']=_0x57dce6['id'];return db[_0x03f4('0x6e')][_0x03f4('0x5f')](_0xcb51d1[_0x03f4('0x3e')]);}})[_0x03f4('0x1e')](respondWithResult(_0xb78a54,null))[_0x03f4('0x5c')](handleError(_0xb78a54,null));};exports[_0x03f4('0x6f')]=function(_0x4b04f2,_0x339858,_0x4b10e9){var _0x3773f8={'raw':![],'where':{}};var _0x45ee1c={};var _0x4720d8={'count':0x0,'rows':[]};return db[_0x03f4('0x45')][_0x03f4('0x70')]({'where':{'id':_0x4b04f2['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x339858,null))[_0x03f4('0x1e')](function(_0xd4cb1c){if(_0xd4cb1c){_0x45ee1c['model']=_[_0x03f4('0x4a')](db[_0x03f4('0x6e')][_0x03f4('0x46')]);_0x45ee1c[_0x03f4('0x49')]=_[_0x03f4('0x4a')](_0x4b04f2[_0x03f4('0x49')]);_0x45ee1c[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x45ee1c['model'],_0x45ee1c['query']);_0x3773f8[_0x03f4('0x4f')]=_['intersection'](_0x45ee1c[_0x03f4('0x4d')],qs[_0x03f4('0x4e')](_0x4b04f2[_0x03f4('0x49')]['fields']));_0x3773f8[_0x03f4('0x4f')]=_0x3773f8[_0x03f4('0x4f')][_0x03f4('0x50')]?_0x3773f8[_0x03f4('0x4f')]:_0x45ee1c[_0x03f4('0x4d')];if(!_0x4b04f2[_0x03f4('0x49')][_0x03f4('0x69')](_0x03f4('0x51'))){_0x3773f8[_0x03f4('0x2b')]=qs['limit'](_0x4b04f2['query'][_0x03f4('0x2b')]);_0x3773f8[_0x03f4('0x2d')]=qs[_0x03f4('0x2d')](_0x4b04f2[_0x03f4('0x49')][_0x03f4('0x2d')]);}_0x3773f8[_0x03f4('0x52')]=qs[_0x03f4('0x53')](_0x4b04f2['query'][_0x03f4('0x53')]);_0x3773f8[_0x03f4('0x55')]=qs[_0x03f4('0x4b')](_['pick'](_0x4b04f2['query'],_0x45ee1c[_0x03f4('0x4b')]));_0x3773f8['where'][_0x03f4('0x67')]=_0xd4cb1c['id'];if(_0x4b04f2['query']['filter']){_0x3773f8[_0x03f4('0x55')]=_[_0x03f4('0x3d')](_0x3773f8['where'],{'$or':_['map'](_0x3773f8[_0x03f4('0x4f')],function(_0x5e14e7){var _0x1ac1c4={};_0x1ac1c4[_0x5e14e7]={'$like':'%'+_0x4b04f2['query'][_0x03f4('0x57')]+'%'};return _0x1ac1c4;})});}_0x3773f8=_['merge']({},_0x3773f8,_0x4b04f2['options']);return db['CannedAnswer']['count']({'where':_0x3773f8[_0x03f4('0x55')]})[_0x03f4('0x1e')](function(_0x1d78ea){_0x4720d8[_0x03f4('0x2c')]=_0x1d78ea;if(_0x4b04f2[_0x03f4('0x49')]['includeAll']){_0x3773f8[_0x03f4('0x5a')]=[{'all':!![]}];}return db[_0x03f4('0x6e')][_0x03f4('0x5b')](_0x3773f8);})[_0x03f4('0x1e')](function(_0x5a291d){_0x4720d8[_0x03f4('0x6a')]=_0x5a291d;return _0x4720d8;});}})['then'](respondWithFilteredResult(_0x339858,_0x3773f8))[_0x03f4('0x5c')](handleError(_0x339858,null));};exports[_0x03f4('0x71')]=function(_0x9a974f,_0x3ced47,_0x1dc581){return db['ChatWebsite'][_0x03f4('0x5e')]({'where':{'id':_0x9a974f[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x3ced47,null))[_0x03f4('0x1e')](function(_0x3bb4f1){if(_0x3bb4f1){return _0x3bb4f1[_0x03f4('0x71')](_0x9a974f[_0x03f4('0x49')][_0x03f4('0x6c')]);}})['then'](respondWithStatusCode(_0x3ced47,null))['catch'](handleError(_0x3ced47,null));};exports['addLogo']=function(_0x350fbb,_0x861226,_0x153264){_0x350fbb[_0x03f4('0x3e')][_0x03f4('0x72')]=_0x350fbb[_0x03f4('0x73')][_0x03f4('0x74')];return db['ChatWebsite'][_0x03f4('0x5e')]({'where':{'id':_0x350fbb['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x861226,null))['then'](saveUpdates(_0x350fbb[_0x03f4('0x3e')],null))[_0x03f4('0x1e')](respondWithResult(_0x861226,null))[_0x03f4('0x5c')](handleError(_0x861226,null));};exports[_0x03f4('0x75')]=function(_0x1a4b3c,_0x270867,_0x56cc79){_0x1a4b3c['body'][_0x03f4('0x76')]=_0x1a4b3c['file'][_0x03f4('0x74')];return db['ChatWebsite'][_0x03f4('0x5e')]({'where':{'id':_0x1a4b3c[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x270867,null))['then'](saveUpdates(_0x1a4b3c[_0x03f4('0x3e')],null))[_0x03f4('0x1e')](respondWithResult(_0x270867,null))[_0x03f4('0x5c')](handleError(_0x270867,null));};exports[_0x03f4('0x77')]=function(_0x3f23b4,_0x4f7ce4,_0x2067f1){_0x3f23b4[_0x03f4('0x3e')][_0x03f4('0x78')]=_0x3f23b4[_0x03f4('0x73')]['filename'];return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'where':{'id':_0x3f23b4['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x4f7ce4,null))[_0x03f4('0x1e')](saveUpdates(_0x3f23b4[_0x03f4('0x3e')],null))[_0x03f4('0x1e')](respondWithResult(_0x4f7ce4,null))['catch'](handleError(_0x4f7ce4,null));};exports[_0x03f4('0x79')]=function(_0x4847c3,_0x257d2c,_0x22aae8){_0x4847c3[_0x03f4('0x3e')]['systemAvatar']=_0x4847c3[_0x03f4('0x73')]['filename'];return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'where':{'id':_0x4847c3['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x257d2c,null))[_0x03f4('0x1e')](saveUpdates(_0x4847c3[_0x03f4('0x3e')],null))[_0x03f4('0x1e')](respondWithResult(_0x257d2c,null))[_0x03f4('0x5c')](handleError(_0x257d2c,null));};exports[_0x03f4('0x7a')]=function(_0x9ba660,_0x3add8a,_0x3d36dd){var _0x41b5d6=path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],'server/files/images/logos/default_logo.svg');var _0x4198bd={'where':{'id':_0x9ba660[_0x03f4('0x64')]['id']},'attributes':['id',_0x03f4('0x72')],'raw':!![]};var _0x2d63fd=![];return require(_0x03f4('0x7d'))[_0x03f4('0x7e')]()[_0x03f4('0x1e')](function(_0x656efe){if(_0x656efe){_0x2d63fd=_0x656efe['custom'];}})['then'](function(){return db[_0x03f4('0x45')][_0x03f4('0x5e')](_0x4198bd);})['then'](handleEntityNotFound(_0x3add8a,null))[_0x03f4('0x1e')](function(_0xd0b93d){if(_0xd0b93d){if(!_[_0x03f4('0x7f')](_0xd0b93d[_0x03f4('0x72')])){if(fs[_0x03f4('0x80')](path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0x81'),_0xd0b93d[_0x03f4('0x72')]))&&_0x2d63fd){_0x41b5d6=path[_0x03f4('0x7b')](config['root'],'server/files/images/logos/',_0xd0b93d[_0x03f4('0x72')]);}}return _0x3add8a[_0x03f4('0x82')](_0x41b5d6);}})[_0x03f4('0x5c')](handleError(_0x3add8a,null));};exports[_0x03f4('0x83')]=function(_0xea2207,_0x12af53,_0x3966db){var _0x3fc9d4=path['join'](config[_0x03f4('0x7c')],_0x03f4('0x84'));var _0x3377f1={'where':{'id':_0xea2207[_0x03f4('0x64')]['id']},'attributes':['id',_0x03f4('0x76')],'raw':!![]};return db[_0x03f4('0x45')][_0x03f4('0x5e')](_0x3377f1)[_0x03f4('0x1e')](handleEntityNotFound(_0x12af53,null))[_0x03f4('0x1e')](function(_0x3a2161){if(_0x3a2161){if(!_[_0x03f4('0x7f')](_0x3a2161[_0x03f4('0x76')])){if(fs['existsSync'](path['join'](config['root'],_0x03f4('0x85'),_0x3a2161[_0x03f4('0x76')]))){_0x3fc9d4=path[_0x03f4('0x7b')](config['root'],'server/files/images/avatars/',_0x3a2161['agentAvatar']);}}return _0x12af53[_0x03f4('0x82')](_0x3fc9d4);}})['catch'](handleError(_0x12af53,null));};exports[_0x03f4('0x86')]=function(_0x5942ff,_0x3b7ab9,_0x3736f1){var _0x4225f7=path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0x87'));var _0x211fa3={'where':{'id':_0x5942ff[_0x03f4('0x64')]['id']},'attributes':['id',_0x03f4('0x78'),_0x03f4('0x88')],'raw':!![]};return db[_0x03f4('0x45')]['find'](_0x211fa3)[_0x03f4('0x1e')](handleEntityNotFound(_0x3b7ab9,null))[_0x03f4('0x1e')](function(_0x304800){if(_0x304800){if(!_[_0x03f4('0x7f')](_0x304800[_0x03f4('0x78')])){if(fs[_0x03f4('0x80')](path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0x85'),_0x304800[_0x03f4('0x78')]))&&_0x304800['showCustomerAvatar']){_0x4225f7=path['join'](config[_0x03f4('0x7c')],_0x03f4('0x85'),_0x304800[_0x03f4('0x78')]);}}return _0x3b7ab9[_0x03f4('0x82')](_0x4225f7);}})[_0x03f4('0x5c')](handleError(_0x3b7ab9,null));};exports[_0x03f4('0x89')]=function(_0xcbf157,_0x225c34,_0x231438){var _0xf91bf6=path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0x8a'));var _0x3cf212={'where':{'id':_0xcbf157[_0x03f4('0x64')]['id']},'attributes':['id',_0x03f4('0x8b')],'raw':!![]};return db['ChatWebsite'][_0x03f4('0x5e')](_0x3cf212)[_0x03f4('0x1e')](handleEntityNotFound(_0x225c34,null))[_0x03f4('0x1e')](function(_0x2d8ece){if(_0x2d8ece){if(!_[_0x03f4('0x7f')](_0x2d8ece[_0x03f4('0x8b')])){if(fs['existsSync'](path['join'](config[_0x03f4('0x7c')],_0x03f4('0x85'),_0x2d8ece[_0x03f4('0x8b')]))){_0xf91bf6=path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0x85'),_0x2d8ece[_0x03f4('0x8b')]);}}return _0x225c34[_0x03f4('0x82')](_0xf91bf6);}})['catch'](handleError(_0x225c34,null));};exports[_0x03f4('0x8c')]=function(_0x639336,_0x5a019e,_0x5d1461){var _0x561170=require(_0x03f4('0x8d'));var _0x248fc7=new _0x561170();var _0x595ccc=_0x248fc7[_0x03f4('0x8e')](_0x639336[_0x03f4('0x8f')][_0x03f4('0x90')])['getResult']();var _0x3bf50f={'body':_0x639336[_0x03f4('0x3e')],'channel':_0x03f4('0x91')};var _0xe59123=[];var _0x3b7ada=[];var _0x183740={};var _0x324fe0=![];return db[_0x03f4('0x92')][_0x03f4('0x65')]()['then'](function(_0x3770bc){if(!_0x3770bc){throw new db[(_0x03f4('0x93'))][(_0x03f4('0x94'))](_0x03f4('0x95'));}_0xe59123=_[_0x03f4('0x96')](_[_0x03f4('0x4a')](_0x3770bc),['createdAt','updatedAt']);_0x3b7ada=_['difference'](_[_0x03f4('0x4a')](_0x3770bc),['createdAt',_0x03f4('0x97'),'CompanyId',_0x03f4('0x98')]);if(_0x639336[_0x03f4('0x3e')]['id']){delete _0x639336[_0x03f4('0x3e')]['id'];}if(_['isNil'](_0x639336[_0x03f4('0x3e')][_0x03f4('0x99')])){throw new db['Sequelize'][(_0x03f4('0x94'))](_0x03f4('0x9a'));}if(_['isNil'](_0x639336[_0x03f4('0x3e')][_0x03f4('0x3e')])||_0x639336[_0x03f4('0x3e')][_0x03f4('0x3e')]===''){throw new db['Sequelize'][(_0x03f4('0x94'))](_0x03f4('0x9b'));}if(_[_0x03f4('0x7f')](_0x639336[_0x03f4('0x3e')][_0x03f4('0x9c')])){throw new db[(_0x03f4('0x93'))][(_0x03f4('0x94'))](_0x03f4('0x9d')+_0x3b7ada);}if(!_[_0x03f4('0x9e')](_0x3b7ada,_0x639336['body'][_0x03f4('0x9c')])){throw new db[(_0x03f4('0x93'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3b7ada);}_0x183740[_0x639336[_0x03f4('0x3e')]['mapKey']]=_0x639336['body'][_0x03f4('0x99')];})[_0x03f4('0x1e')](function(){return db[_0x03f4('0x45')]['find']({'where':{'id':_0x639336[_0x03f4('0x64')]['id']},'include':[{'model':db[_0x03f4('0x9f')],'as':_0x03f4('0xa0'),'include':[{'model':db[_0x03f4('0x92')],'as':_0x03f4('0xa1'),'where':_0x183740,'limit':0x1,'order':[[_0x03f4('0x97'),_0x03f4('0xa2')]]}]},{'model':db[_0x03f4('0xa3')],'as':_0x03f4('0xa4')}]});})[_0x03f4('0x1e')](handleEntityNotFound(_0x5a019e,null))['then'](function(_0x4b2524){if(_0x4b2524&&_0x4b2524['List']){_0x3bf50f[_0x03f4('0x41')]=_0x4b2524;_0x3bf50f[_0x03f4('0xa5')]=_0x4b2524[_0x03f4('0xa4')];_0x3bf50f[_0x03f4('0xa6')]=_0x4b2524[_0x03f4('0xa0')];_0x3bf50f[_0x03f4('0xa5')]=_[_0x03f4('0xa7')](_0x3bf50f['applications'],[_0x03f4('0xa8')],[_0x03f4('0xa9')]);if(_0x3bf50f['account'][_0x03f4('0xa4')]){delete _0x3bf50f[_0x03f4('0x41')][_0x03f4('0xa4')];}if(_0x3bf50f[_0x03f4('0x41')][_0x03f4('0xa0')]&&_0x3bf50f[_0x03f4('0x41')][_0x03f4('0xa0')][_0x03f4('0xa1')]['length']){return _0x3bf50f['account']['List']['Contacts'][0x0];}var _0x2f9181=_[_0x03f4('0x17')](_0x639336['body'],{'firstName':_0x639336[_0x03f4('0x3e')][_0x03f4('0x99')],'ListId':_0x4b2524[_0x03f4('0x98')]});_0x2f9181[_0x639336[_0x03f4('0x3e')][_0x03f4('0x9c')]]=_0x639336['body'][_0x03f4('0x99')];return db[_0x03f4('0x92')][_0x03f4('0x5f')](_0x2f9181,{'fields':_0xe59123,'raw':!![]});}})[_0x03f4('0x1e')](handleEntityNotFound(_0x5a019e,null))[_0x03f4('0x1e')](function(_0x141b85){_0x3bf50f[_0x03f4('0x3f')]=_0x141b85;var _0x2fda67=_0x639336[_0x03f4('0x3e')][_0x03f4('0xaa')];if(_0x639336['headers'][_0x03f4('0xab')]){_0x2fda67=_0x639336[_0x03f4('0x8f')][_0x03f4('0xab')];}else if(_0x639336[_0x03f4('0x8f')][_0x03f4('0xac')]){_0x2fda67=_['first'](_0x639336[_0x03f4('0x8f')]['x-forwarded-for'][_0x03f4('0xad')](','));}if(_0x141b85){var _0x52c23f={'ContactId':_0x141b85['id'],'ChatWebsiteId':_0x639336[_0x03f4('0x64')]['id'],'from':(_0x141b85[_0x03f4('0xae')]||'')+'\x20'+(_0x141b85['lastName']||''),'customerIp':_0x2fda67,'customerPort':_0x639336[_0x03f4('0x8f')][_0x03f4('0xaf')]?_0x639336[_0x03f4('0x8f')][_0x03f4('0xaf')]:null,'referer':_0x639336[_0x03f4('0x3e')][_0x03f4('0xb0')],'browserName':_0x595ccc[_0x03f4('0xb1')][_0x03f4('0x3a')]&&_0x595ccc[_0x03f4('0xb1')][_0x03f4('0xb2')]?util[_0x03f4('0xb3')](_0x03f4('0xb4'),_0x595ccc[_0x03f4('0xb1')][_0x03f4('0x3a')],_0x595ccc[_0x03f4('0xb1')][_0x03f4('0xb2')]):_0x03f4('0xb5'),'browserVersion':_0x595ccc['browser'][_0x03f4('0xb2')]||_0x03f4('0xb5'),'osName':util[_0x03f4('0xb3')](_0x03f4('0xb4'),_0x595ccc['os'][_0x03f4('0x3a')],_0x595ccc['os'][_0x03f4('0xb2')]),'osVersion':_0x595ccc['os'][_0x03f4('0xb2')],'deviceModel':_0x595ccc[_0x03f4('0xb6')][_0x03f4('0x4d')]&&_0x595ccc[_0x03f4('0xb6')][_0x03f4('0xb7')]?util[_0x03f4('0xb3')](_0x03f4('0xb8'),_0x595ccc[_0x03f4('0xb6')][_0x03f4('0x4d')],_0x595ccc[_0x03f4('0xb6')][_0x03f4('0xb7')],_0x595ccc[_0x03f4('0xb6')][_0x03f4('0x56')]):null,'deviceVendor':_0x595ccc[_0x03f4('0xb6')][_0x03f4('0xb7')],'deviceType':_0x595ccc[_0x03f4('0xb6')][_0x03f4('0x56')],'formData':JSON['stringify'](_0x639336[_0x03f4('0x3e')])};var _0x127d62={'ChatWebsiteId':_0x639336['params']['id'],'closed':![]};if(_0x639336['body']['threadId']){_0x127d62['threadId']=_0x639336[_0x03f4('0x3e')][_0x03f4('0xb9')];return db[_0x03f4('0xba')][_0x03f4('0x5e')]({'where':_0x127d62})['then'](function(_0x1751b4){if(_0x1751b4){return[_0x1751b4,![]];}_0x52c23f[_0x03f4('0xb9')]=_0x639336['body'][_0x03f4('0xb9')];_0x52c23f['externalUrl']=_0x639336[_0x03f4('0x3e')]['externalUrl'];return db['ChatInteraction']['create'](_0x52c23f)[_0x03f4('0x1e')](function(_0x2932c4){return[_0x2932c4,!![]];});});}_0x127d62[_0x03f4('0xbb')]=_0x141b85['id'];if(_0x639336[_0x03f4('0x3e')]['interaction']&&_0x639336[_0x03f4('0x3e')][_0x03f4('0x40')]['id']){_0x127d62['id']=_0x639336[_0x03f4('0x3e')][_0x03f4('0x40')]['id'];return db[_0x03f4('0xba')][_0x03f4('0x5e')]({'where':_0x127d62})[_0x03f4('0x1e')](function(_0x2028b8){if(_0x2028b8){return[_0x2028b8,![]];}return db[_0x03f4('0xba')]['create'](_0x52c23f)[_0x03f4('0x1e')](function(_0x5e6703){return[_0x5e6703,!![]];});});}return db['ChatInteraction'][_0x03f4('0x5f')](_0x52c23f)['then'](function(_0x2a69e3){return[_0x2a69e3,!![]];});}})[_0x03f4('0xbc')](function(_0xfb3a0f,_0x49817d){if(_0xfb3a0f){_0x324fe0=_0x49817d;if(!_0x49817d){var _0x5e752b={'from':(_0x3bf50f[_0x03f4('0x3f')]['firstName']||'')+'\x20'+(_0x3bf50f['contact'][_0x03f4('0xbd')]||'')};if(_0x639336['body'][_0x03f4('0xb9')]&&_0x639336[_0x03f4('0x3e')][_0x03f4('0xbe')]&&_0x639336[_0x03f4('0x3e')]['threadId']!=_0x639336[_0x03f4('0x3e')]['messageId']){_0x5e752b[_0x03f4('0xb9')]=_0x639336['body'][_0x03f4('0xbe')];}return _0xfb3a0f['update'](_0x5e752b);}else{return _0xfb3a0f;}}})[_0x03f4('0x1e')](function(_0x165e51){_0x3bf50f[_0x03f4('0x40')]=_0x165e51['get']({'plain':!![]});_0x3bf50f[_0x03f4('0x40')][_0x03f4('0xbf')]=_0x324fe0;if(_0x3bf50f[_0x03f4('0x40')][_0x03f4('0xbf')]){if(_0x3bf50f[_0x03f4('0x41')][_0x03f4('0xc0')]){_0x3bf50f[_0x03f4('0xa5')][_0x03f4('0xc1')]({'id':0x0,'priority':_0x3bf50f[_0x03f4('0xa5')]['length']+0x1,'app':_0x03f4('0xc2'),'appdata':_0x03f4('0xc3'),'interval':'*,*,*,*'});}}return db[_0x03f4('0xc4')][_0x03f4('0x5f')]({'body':_0x639336[_0x03f4('0x3e')]['body'],'ChatWebsiteId':_0x639336[_0x03f4('0x64')]['id'],'ChatInteractionId':_0x165e51['id'],'direction':'in','ContactId':_0x3bf50f[_0x03f4('0x3f')]['id'],'AttachmentId':_0x639336[_0x03f4('0x3e')][_0x03f4('0xc5')]});})['then'](function(_0x5e135c){_0x3bf50f[_0x03f4('0x26')]=_0x5e135c;if(_0x3bf50f[_0x03f4('0x40')][_0x03f4('0xc6')]){return db[_0x03f4('0xc7')][_0x03f4('0x5e')]({'attributes':['id',_0x03f4('0x3a')],'where':{'id':_0x3bf50f['interaction'][_0x03f4('0xc6')]}})['then'](function(_0x2c1504){if(_0x2c1504){_0x3bf50f['applications'][_0x03f4('0xc8')]({'id':0x0,'priority':0x0,'app':_0x03f4('0xc9'),'appdata':_0x2c1504['name']+','+(_0x3bf50f['account']['waitForTheAssignedAgent']||0xa),'interval':'*,*,*,*'});_0x3bf50f[_0x03f4('0xca')]=!![];}return respondWithRpcPromise(_0x03f4('0xcb'),_0x03f4('0xcc'),_0x3bf50f);});}return respondWithRpcPromise(_0x03f4('0xcb'),'startRouting',_0x3bf50f);})[_0x03f4('0x1e')](function(_0x1234da){respondWithRpcPromise(_0x03f4('0xcd'),'EventManager',{'event':_0x03f4('0x8c'),'message':_0x1234da},client9002);return _0x1234da;})['then'](respondWithResult(_0x5a019e,null))[_0x03f4('0x5c')](handleError(_0x5a019e,null));};exports[_0x03f4('0xce')]=function(_0x2fb01e,_0x1cabb4,_0x455828){var _0x19f62e,_0x55517d,_0x4e01ae;var _0x4de400=[];var _0x3c3648=[];var _0xd96f25={};var _0x2b1935=_0x2fb01e['files']||[];var _0x2956ed=[];var _0xd32b80;return db[_0x03f4('0x92')][_0x03f4('0x65')]()[_0x03f4('0x1e')](function(_0x2bd15b){if(!_0x2bd15b){throw new db[(_0x03f4('0x93'))][(_0x03f4('0x94'))](_0x03f4('0x95'));}_0x3c3648=_[_0x03f4('0x96')](_[_0x03f4('0x4a')](_0x2bd15b),[_0x03f4('0xcf'),_0x03f4('0x97')]);_0x4de400=_['difference'](_['keys'](_0x2bd15b),[_0x03f4('0xcf'),_0x03f4('0x97'),_0x03f4('0xd0'),_0x03f4('0x98')]);if(_0x2fb01e[_0x03f4('0x3e')]['id']){delete _0x2fb01e[_0x03f4('0x3e')]['id'];}if(_[_0x03f4('0x7f')](_0x2fb01e['body'][_0x03f4('0x99')])){throw _0x1cabb4[_0x03f4('0x28')](0x1f4)[_0x03f4('0x3b')](new db['Sequelize'][(_0x03f4('0x94'))]('from\x20is\x20mandatory'));}if(_[_0x03f4('0x7f')](_0x2fb01e[_0x03f4('0x3e')][_0x03f4('0x3e')])||_0x2fb01e[_0x03f4('0x3e')][_0x03f4('0x3e')]===''){throw _0x1cabb4['status'](0x1f4)[_0x03f4('0x3b')](new db[(_0x03f4('0x93'))]['ValidationError'](_0x03f4('0x9b')));}if(_[_0x03f4('0x7f')](_0x2fb01e[_0x03f4('0x3e')]['mapKeyOffline'])){throw _0x1cabb4[_0x03f4('0x28')](0x1f4)['send'](new db[(_0x03f4('0x93'))][(_0x03f4('0x94'))](_0x03f4('0xd1')+_0x4de400));}if(!_['includes'](_0x4de400,_0x2fb01e[_0x03f4('0x3e')][_0x03f4('0xd2')])){throw _0x1cabb4[_0x03f4('0x28')](0x1f4)[_0x03f4('0x3b')](new db[(_0x03f4('0x93'))][(_0x03f4('0x94'))](_0x03f4('0xd3')+_0x4de400));}_0xd96f25[_0x2fb01e[_0x03f4('0x3e')]['mapKeyOffline']]=_0x2fb01e['body'][_0x03f4('0x99')];})[_0x03f4('0x1e')](function(){return db['ChatWebsite'][_0x03f4('0x5e')]({'where':{'id':_0x2fb01e[_0x03f4('0x64')]['id']},'include':[{'model':db[_0x03f4('0x9f')],'as':_0x03f4('0xa0')},{'model':db[_0x03f4('0xd4')],'as':_0x03f4('0xd4')}]});})[_0x03f4('0x1e')](handleEntityNotFound(_0x1cabb4,null))[_0x03f4('0x1e')](function(_0x5c8781){if(_0x5c8781&&_0x5c8781[_0x03f4('0xa0')]){_0x55517d=_0x5c8781;var _0x34821a=_['defaults'](_0x2fb01e[_0x03f4('0x3e')],{'firstName':_0x2fb01e[_0x03f4('0x3e')]['from'],'phone':_0x2fb01e[_0x03f4('0x3e')][_0x03f4('0x99')],'ListId':_0x5c8781['ListId']});_0x34821a[_0x2fb01e[_0x03f4('0x3e')][_0x03f4('0xd2')]]=_0x2fb01e[_0x03f4('0x3e')]['from'];return db[_0x03f4('0x92')][_0x03f4('0xd5')]({'where':_0xd96f25,'defaults':_0x34821a});}})['spread'](function(_0x45251e){if(_0x45251e){_0x4e01ae=_0x45251e;var _0x9262c4=fs['readFileSync'](path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0xd6')),_0x03f4('0xd7'));var _0x4fa94a=ejs['render'](_0x9262c4,{'body':_[_0x03f4('0xd8')](_0x2fb01e[_0x03f4('0x3e')][_0x03f4('0x3e')]),'bodyTitle':_0x55517d[_0x03f4('0xd9')]});return db[_0x03f4('0xda')][_0x03f4('0x5f')]({'body':_0x4fa94a,'ContactId':_0x45251e['id'],'ChatWebsiteId':_0x55517d['id']});}})[_0x03f4('0x1e')](function(_0x10c92e){_0xd32b80=_0x10c92e;if(_0x2b1935[_0x03f4('0x50')]){var _0xeb24d=_0x2b1935[_0x03f4('0x48')](function(_0x43379e){return{'name':_0x43379e['originalname'],'basename':_0x43379e['filename'],'type':_0x43379e['mimetype'],'ChatOfflineMessageId':_0x10c92e['id']};});_0x2956ed=_0xeb24d[_0x03f4('0x48')](_0x40799b=>{var _0x3fbcf4={'filename':_0x40799b[_0x03f4('0x3a')],'path':path['join'](config['root'],_0x03f4('0xdb'),_0x03f4('0xdc'),_0x03f4('0xdd'),_0x03f4('0xde'),_0x40799b[_0x03f4('0xdf')])};return _0x3fbcf4;});if(!_0x55517d[_0x03f4('0xe0')]){return db[_0x03f4('0xe1')][_0x03f4('0xe2')](function(_0x1b9d16){return db['Attachment'][_0x03f4('0xe3')](_0xeb24d,{'transaction':_0x1b9d16});});}}})[_0x03f4('0x1e')](function(){if(_0xd32b80){_0x19f62e=_0xd32b80;return db['MailAccount'][_0x03f4('0x70')]({'where':{'active':!![]},'include':[{'model':db['MailServerOut'],'as':'Smtp','raw':!![]}]});}})['then'](function(_0x50b274){if(_0x50b274&&_0x50b274['Smtp']&&_0x55517d['forwardOffline']&&_0x55517d[_0x03f4('0xe4')]){var _0x540a14={'tls':{'rejectUnauthorized':![]}};if(_0x50b274[_0x03f4('0xe5')][_0x03f4('0xe6')]){_0x540a14[_0x03f4('0xe6')]=_0x50b274[_0x03f4('0xe5')]['service'];}else{_0x540a14[_0x03f4('0xe7')]=_0x50b274[_0x03f4('0xe5')][_0x03f4('0xe7')];_0x540a14[_0x03f4('0xe8')]=_0x50b274[_0x03f4('0xe5')][_0x03f4('0xe8')];_0x540a14[_0x03f4('0xe9')]=_0x50b274['Smtp']['secure'];}if(_0x50b274['Smtp'][_0x03f4('0xea')]){_0x540a14['auth']={'user':_0x50b274['Smtp'][_0x03f4('0x60')],'pass':_0x50b274[_0x03f4('0xe5')][_0x03f4('0xeb')]};}return respondWithRpcPromise(_0x03f4('0xec'),_0x03f4('0xed'),{'account':_0x540a14,'message':{'from':util['format'](_0x03f4('0xee'),_0x50b274[_0x03f4('0x3a')],_0x50b274[_0x03f4('0xef')]||_0x50b274[_0x03f4('0xe5')][_0x03f4('0x60')]),'to':_0x55517d[_0x03f4('0xe4')],'subject':_0x55517d[_0x03f4('0xf0')],'html':_0x19f62e[_0x03f4('0x3e')],'attachments':_0x2956ed}},client9003)[_0x03f4('0x1e')](function(){return _0x19f62e;})[_0x03f4('0x5c')](function(_0x2f8b95){console['error'](_0x2f8b95);});}})[_0x03f4('0x1e')](function(){if(_0x55517d&&_0x55517d[_0x03f4('0xe0')]&&_0x55517d['MailAccountId']){var _0x422f3e=[];if(_0x2b1935[_0x03f4('0x50')]){_0x422f3e=_0x2b1935[_0x03f4('0x48')](function(_0xe1a8c6){return{'name':_0xe1a8c6['originalname'],'basename':_0xe1a8c6[_0x03f4('0x74')],'type':_0xe1a8c6['mimetype'],'ChatOfflineMessageId':_0xd32b80['id']};});}var _0x350632;if(!_[_0x03f4('0x7f')](_0x55517d[_0x03f4('0xf1')])){var _0x207c57=_['map'](_0x2fb01e['body'],function(_0x3d026b){return _0x3d026b;});var _0x51afa0=_[_0x03f4('0xf2')](_0x207c57)[0x0];var _0x3d32fb=_[_0x03f4('0xf3')](_0x51afa0,function(_0x13b3a1){return _0x13b3a1;});_0x350632=_0x3d32fb[0x1][_0x55517d['subjectOffline']];}var _0x40254f={'from':_0x4e01ae[_0x03f4('0xef')],'firstName':_0x4e01ae[_0x03f4('0xae')],'lastName':_0x4e01ae['lastName'],'mapKey':_0x03f4('0xef'),'message':{'from':_0x4e01ae['email'],'to':_0x55517d['MailAccount']['email'],'cc':'','subject':_[_0x03f4('0x7f')](_0x350632)?_0x55517d['offlineMessageSubject']:_0x350632,'messageId':'','sentAt':new Date(),'attach':_0x422f3e['length'],'attachments':_0x422f3e,'originChannel':_0x03f4('0xf4'),'ChatWebsiteId':_0x55517d['id'],'ChatOfflineMessageId':_0x19f62e['id'],'originTo':_0x55517d[_0x03f4('0xd4')][_0x03f4('0xef')]},'body':_0x19f62e[_0x03f4('0x3e')]};var _0x3b8544={'account':{'id':_0x55517d[_0x03f4('0xf5')]},'body':_0x40254f,'log':_0x03f4('0xf6')};return respondWithRpcPromise(_0x03f4('0xf6'),_0x03f4('0xf7'),_0x3b8544,client9001)[_0x03f4('0x1e')](function(){return _0x19f62e;})[_0x03f4('0x5c')](function(_0x4b96ee){console['error'](_0x4b96ee);});}return;})[_0x03f4('0x1e')](function(){if(_0x19f62e){return _0x19f62e;}})[_0x03f4('0x1e')](respondWithResult(_0x1cabb4,null))[_0x03f4('0x5c')](function(_0x13b4b8){console[_0x03f4('0x24')](_0x03f4('0x5c'),_0x13b4b8);for(var _0x4d7576 of _0x2b1935){var _0x3ba128=path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0xdb'),_0x03f4('0xdc'),_0x03f4('0xdd'),_0x03f4('0xde'),_0x4d7576[_0x03f4('0x74')]);fs_extra[_0x03f4('0xf8')](_0x3ba128)[_0x03f4('0x5c')](function(_0x18d092){console[_0x03f4('0x24')](_0x03f4('0xf9'),_0x3ba128,_0x18d092);});}});};exports[_0x03f4('0xfa')]=function(_0x52487c,_0x5eedfd,_0x2543cb){return db[_0x03f4('0xba')][_0x03f4('0x5e')]({'where':{'id':_0x52487c[_0x03f4('0x64')]['id']}})['then'](handleEntityNotFound(_0x5eedfd,null))['then'](function(_0x4759c4){if(_0x4759c4){return _0x4759c4[_0x03f4('0xfa')](_0x52487c[_0x03f4('0x3e')][_0x03f4('0x6c')],_[_0x03f4('0xfb')](_0x52487c[_0x03f4('0x3e')],[_0x03f4('0x6c'),'id'])||{});}})[_0x03f4('0x1e')](respondWithResult(_0x5eedfd,null))[_0x03f4('0x5c')](handleError(_0x5eedfd,null));};exports[_0x03f4('0xfc')]=function(_0x1538d1,_0x86c6a8,_0x54ab24){var _0x3288ac={'raw':![],'where':{}};var _0x5f156b={};var _0x2edcb5={'count':0x0,'rows':[]};return db[_0x03f4('0x45')]['findOne']({'where':{'id':_0x1538d1[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x86c6a8,null))[_0x03f4('0x1e')](function(_0x12322a){if(_0x12322a){_0x5f156b['model']=_[_0x03f4('0x4a')](db[_0x03f4('0xba')][_0x03f4('0x46')]);_0x5f156b['query']=_[_0x03f4('0x4a')](_0x1538d1[_0x03f4('0x49')]);_0x5f156b[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x5f156b[_0x03f4('0x4d')],_0x5f156b[_0x03f4('0x49')]);_0x3288ac[_0x03f4('0x4f')]=_[_0x03f4('0x4c')](_0x5f156b[_0x03f4('0x4d')],qs[_0x03f4('0x4e')](_0x1538d1['query'][_0x03f4('0x4e')]));_0x3288ac[_0x03f4('0x4f')]=_0x3288ac['attributes'][_0x03f4('0x50')]?_0x3288ac[_0x03f4('0x4f')]:_0x5f156b[_0x03f4('0x4d')];if(!_0x1538d1['query'][_0x03f4('0x69')](_0x03f4('0x51'))){_0x3288ac['limit']=qs['limit'](_0x1538d1['query']['limit']);_0x3288ac[_0x03f4('0x2d')]=qs[_0x03f4('0x2d')](_0x1538d1[_0x03f4('0x49')][_0x03f4('0x2d')]);}_0x3288ac[_0x03f4('0x52')]=qs[_0x03f4('0x53')](_0x1538d1['query'][_0x03f4('0x53')]);_0x3288ac[_0x03f4('0x55')]=qs[_0x03f4('0x4b')](_[_0x03f4('0x54')](_0x1538d1[_0x03f4('0x49')],_0x5f156b[_0x03f4('0x4b')]));_0x3288ac['where'][_0x03f4('0x67')]=_0x12322a['id'];if(_0x1538d1['query']['filter']){_0x3288ac['where']=_['merge'](_0x3288ac[_0x03f4('0x55')],{'$or':_[_0x03f4('0x48')](_0x3288ac[_0x03f4('0x4f')],function(_0x5608c6){var _0x35517b={};_0x35517b[_0x5608c6]={'$like':'%'+_0x1538d1['query']['filter']+'%'};return _0x35517b;})});}_0x3288ac=_[_0x03f4('0x3d')]({},_0x3288ac,_0x1538d1[_0x03f4('0x58')]);return db[_0x03f4('0xba')][_0x03f4('0x2c')]({'where':_0x3288ac[_0x03f4('0x55')]})[_0x03f4('0x1e')](function(_0x35f036){_0x2edcb5['count']=_0x35f036;if(_0x1538d1[_0x03f4('0x49')]['includeAll']){_0x3288ac[_0x03f4('0x5a')]=[{'model':db[_0x03f4('0x92')],'as':'Contact','required':![]},{'model':db['User'],'as':_0x03f4('0xfd'),'attributes':[_0x03f4('0x3a'),_0x03f4('0xfe'),_0x03f4('0xff')],'required':![]},{'model':db[_0x03f4('0x100')],'as':_0x03f4('0x101'),'attributes':['id','name',_0x03f4('0x102')],'where':_0x1538d1[_0x03f4('0x49')]['tag']?{'id':_0x1538d1[_0x03f4('0x49')][_0x03f4('0x103')]}:undefined,'required':_0x1538d1[_0x03f4('0x49')]['tag']?!![]:![]}];}return db[_0x03f4('0xba')]['findAll'](_0x3288ac);})[_0x03f4('0x1e')](function(_0x485f85){_0x2edcb5['rows']=_0x485f85;return _0x2edcb5;});}})[_0x03f4('0x1e')](respondWithFilteredResult(_0x86c6a8,_0x3288ac))[_0x03f4('0x5c')](handleError(_0x86c6a8,null));};function iftimePromise(_0x42aace,_0x2c20dc){return respondWithRpcPromise(_0x03f4('0x104'),'getSnippet',{'command':_0x2c20dc['timezone']?util[_0x03f4('0xb3')](_0x03f4('0x105'),_0x42aace[_0x03f4('0x106')],_0x2c20dc[_0x03f4('0x107')]):util[_0x03f4('0xb3')](_0x03f4('0x108'),_0x42aace[_0x03f4('0x106')])},client9002)[_0x03f4('0x1e')](function(_0x294c9e){var _0x21bba0=_0x294c9e&&_0x294c9e['indexOf'](_0x03f4('0x109'))>=0x0?!![]:![];logger[_0x03f4('0x1f')](_0x03f4('0x10a'),_0x2c20dc['id'],_0x42aace['id'],_0x42aace[_0x03f4('0x106')],_0x21bba0?'ONLINE':'OFFLINE',_0x2c20dc[_0x03f4('0x107')]?_0x2c20dc[_0x03f4('0x107')]:_0x03f4('0x10b'));return _0x21bba0;})[_0x03f4('0x5c')](function(_0x3df8d5){logger[_0x03f4('0x24')](_0x03f4('0x10a'),_0x2c20dc['id'],_0x42aace['id'],_0x42aace[_0x03f4('0x106')],util[_0x03f4('0x10c')](_0x3df8d5,{'showHidden':![],'depth':null}),_0x2c20dc[_0x03f4('0x107')]?_0x2c20dc['timezone']:_0x03f4('0x10b'));return![];});}exports[_0x03f4('0x10d')]=function(_0x2f9949,_0x111f5f,_0x2b8cea){var _0x2e0aa8=0x0;var _0x23d370=0x0;var _0x30ff0e=![];var _0x44451b;var _0x104cf2;return db[_0x03f4('0x45')]['find']({'where':{'id':_0x2f9949['params']['id']},'include':[{'model':db['Interval'],'as':'Interval','include':[{'model':db[_0x03f4('0x10e')],'as':_0x03f4('0x10f'),'attributes':['id',_0x03f4('0x106')],'raw':!![]}]}]})['then'](handleEntityNotFound(_0x111f5f,null))[_0x03f4('0x1e')](function(_0x1f7aa7){if(_0x1f7aa7){_0x44451b=_0x1f7aa7;return _0x1f7aa7['getProactiveActions']({'raw':!![]});}})[_0x03f4('0x1e')](function(_0x437212){if(_0x44451b){if(_0x437212){_0x104cf2=_0x437212;}}return require('../../config/license/util')['getLicense']();})[_0x03f4('0x1e')](function(_0x2fa960){if(_0x2fa960){_0x23d370=_0x2fa960[_0x03f4('0x110')];_0x30ff0e=_0x2fa960[_0x03f4('0x111')];}})[_0x03f4('0x1e')](function(){return db[_0x03f4('0xba')][_0x03f4('0x2c')]({'where':{'closed':![]}});})[_0x03f4('0x1e')](function(_0xbf88ef){_0x2e0aa8=_0xbf88ef;if(_0x23d370&&_0xbf88ef>_0x23d370){return db['License'][_0x03f4('0x70')]({'where':{'id':0x1}})[_0x03f4('0x1e')](function(_0x2d3100){if(_0x2d3100){_0x2d3100['increment'](_0x03f4('0x112'));}});}})[_0x03f4('0x1e')](function(){if(_0x44451b['Interval']&&_0x44451b['Interval']['Intervals']){var _0xd78f2b=[];for(var _0x4b5eb5=0x0;_0x4b5eb5<_0x44451b[_0x03f4('0x10e')]['Intervals'][_0x03f4('0x50')];_0x4b5eb5++){var _0x34428b=_0x44451b[_0x03f4('0x10e')][_0x03f4('0x10f')][_0x4b5eb5][_0x03f4('0x35')]({'plain':!![]});_0xd78f2b[_0x03f4('0xc1')](iftimePromise(_0x34428b,_0x44451b));}return BPromise[_0x03f4('0x113')](_0xd78f2b)[_0x03f4('0x1e')](function(_0x377073){return _[_0x03f4('0x114')](_0x377073);});}else{return!![];}})[_0x03f4('0x1e')](function(_0x456aa2){var _0x409135=fs[_0x03f4('0x115')](path[_0x03f4('0x7b')](config[_0x03f4('0x7c')],_0x03f4('0x116')),_0x03f4('0xd7'));var _0x4a902e={'remote':_0x44451b[_0x03f4('0x117')],'query':querystring[_0x03f4('0x23')](_[_0x03f4('0x3d')](_0x44451b[_0x03f4('0x35')]({'plain':!![]}),{'customerIp':_0x2f9949[_0x03f4('0x8f')][_0x03f4('0xac')]||_0x2f9949['headers']['x-real-ip']||_0x2f9949['connection']['remoteAddress']||_0x2f9949['ip'],'referer':_0x2f9949[_0x03f4('0x8f')][_0x03f4('0xb0')],'openedInteractions':_0x2e0aa8,'maxInteractions':_0x23d370,'virtual':_0x30ff0e[_0x03f4('0x110')],'online':_0x456aa2,'custom':_0x30ff0e}))[_0x03f4('0x118')](/'/g,'\x5c\x27')};_0x111f5f[_0x03f4('0x3b')](ejs['render'](Mustache[_0x03f4('0x3c')](_0x409135,_0x4a902e),{'proactiveActions':_0x104cf2,'alignment':_0x44451b['alignment'],'verticalAlignment':_0x44451b[_0x03f4('0x119')],'div_color':_0x44451b[_0x03f4('0x102')],'text_color':_0x44451b[_0x03f4('0x11a')],'button_color':_0x44451b[_0x03f4('0x11b')],'background_color':_0x44451b[_0x03f4('0x11c')]}));})['catch'](handleError(_0x111f5f,null));};exports['addApplications']=function(_0x47a1b9,_0x4d62e8,_0x115440){return db['ChatWebsite'][_0x03f4('0x70')]({'where':{'id':_0x47a1b9[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x4d62e8,null))['then'](function(_0x3e5e42){if(_0x3e5e42){return db[_0x03f4('0xe1')]['transaction'](function(_0x23c287){return db['ChatApplication'][_0x03f4('0x34')]({'where':{'ChatWebsiteId':_0x47a1b9['params']['id']},'transaction':_0x23c287})[_0x03f4('0x1e')](function(_0x5f1e12){var _0x5cdd12=_[_0x03f4('0x48')](_0x47a1b9['body'],function(_0x1f68a4){_0x1f68a4['ChatWebsiteId']=_0x47a1b9['params']['id'];return _0x1f68a4;});return db[_0x03f4('0xa3')][_0x03f4('0xe3')](_0x5cdd12,{'transaction':_0x23c287});});})['then'](function(){return db['ChatApplication'][_0x03f4('0x11d')]({'where':{'ChatWebsiteId':_0x47a1b9[_0x03f4('0x64')]['id']},'order':_0x03f4('0xa8')});});}})[_0x03f4('0x1e')](respondWithResult(_0x4d62e8,null))[_0x03f4('0x5c')](handleError(_0x4d62e8,null));};exports[_0x03f4('0x11e')]=function(_0x616bc9,_0x158eed,_0x5f4544){var _0x4c4f1b={};var _0x57ecd2={};var _0x3721e8;var _0x16d902;return db['ChatWebsite']['findOne']({'where':{'id':_0x616bc9['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x158eed,null))[_0x03f4('0x1e')](function(_0x2e18fb){if(_0x2e18fb){_0x3721e8=_0x2e18fb;_0x57ecd2[_0x03f4('0x4d')]=_[_0x03f4('0x4a')](db[_0x03f4('0xa3')][_0x03f4('0x46')]);_0x57ecd2[_0x03f4('0x49')]=_[_0x03f4('0x4a')](_0x616bc9[_0x03f4('0x49')]);_0x57ecd2[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x57ecd2['model'],_0x57ecd2[_0x03f4('0x49')]);_0x4c4f1b[_0x03f4('0x4f')]=_[_0x03f4('0x4c')](_0x57ecd2['model'],qs['fields'](_0x616bc9[_0x03f4('0x49')]['fields']));_0x4c4f1b['attributes']=_0x4c4f1b[_0x03f4('0x4f')][_0x03f4('0x50')]?_0x4c4f1b[_0x03f4('0x4f')]:_0x57ecd2['model'];_0x4c4f1b['order']=qs[_0x03f4('0x53')](_0x616bc9[_0x03f4('0x49')][_0x03f4('0x53')]);_0x4c4f1b[_0x03f4('0x55')]=qs['filters'](_[_0x03f4('0x54')](_0x616bc9[_0x03f4('0x49')],_0x57ecd2['filters']));if(_0x616bc9[_0x03f4('0x49')]['filter']){_0x4c4f1b[_0x03f4('0x55')]=_[_0x03f4('0x3d')](_0x4c4f1b[_0x03f4('0x55')],{'$or':_[_0x03f4('0x48')](_0x4c4f1b[_0x03f4('0x4f')],function(_0x2a4403){var _0x1b95f6={};_0x1b95f6[_0x2a4403]={'$like':'%'+_0x616bc9[_0x03f4('0x49')]['filter']+'%'};return _0x1b95f6;})});}_0x4c4f1b=_[_0x03f4('0x3d')]({},_0x4c4f1b,_0x616bc9[_0x03f4('0x58')]);return _0x3721e8[_0x03f4('0x11e')](_0x4c4f1b);}})[_0x03f4('0x1e')](function(_0x47b382){if(_0x47b382){_0x16d902=_0x47b382[_0x03f4('0x50')];if(!_0x616bc9[_0x03f4('0x49')][_0x03f4('0x69')](_0x03f4('0x51'))){_0x4c4f1b['limit']=qs['limit'](_0x616bc9[_0x03f4('0x49')]['limit']);_0x4c4f1b['offset']=qs[_0x03f4('0x2d')](_0x616bc9[_0x03f4('0x49')]['offset']);}return _0x3721e8['getApplications'](_0x4c4f1b);}})[_0x03f4('0x1e')](function(_0x400180){if(_0x400180){return _0x400180?{'count':_0x16d902,'rows':_0x400180}:null;}})[_0x03f4('0x1e')](respondWithResult(_0x158eed,null))['catch'](handleError(_0x158eed,null));};exports[_0x03f4('0x11f')]=function(_0x11bc83,_0x5ecdcd,_0x4e75f6){return db[_0x03f4('0x120')]['find']({'where':{'id':_0x11bc83['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x5ecdcd,null))[_0x03f4('0x1e')](function(_0x1d974d){if(_0x1d974d){return _0x1d974d[_0x03f4('0x11f')](_0x11bc83[_0x03f4('0x3e')][_0x03f4('0x6c')],_['omit'](_0x11bc83[_0x03f4('0x3e')],['ids','id'])||{});}})[_0x03f4('0x1e')](respondWithResult(_0x5ecdcd,null))[_0x03f4('0x5c')](handleError(_0x5ecdcd,null));};exports[_0x03f4('0x121')]=function(_0x458119,_0x24b538,_0x18b29b){var _0x41caf1={};var _0x3a1b15={};var _0x11c69b;var _0x6b2bf;return db[_0x03f4('0x45')][_0x03f4('0x70')]({'where':{'id':_0x458119[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x24b538,null))[_0x03f4('0x1e')](function(_0x4ea726){if(_0x4ea726){_0x11c69b=_0x4ea726;_0x3a1b15['model']=_['keys'](db[_0x03f4('0x122')][_0x03f4('0x46')]);_0x3a1b15[_0x03f4('0x49')]=_[_0x03f4('0x4a')](_0x458119[_0x03f4('0x49')]);_0x3a1b15['filters']=_[_0x03f4('0x4c')](_0x3a1b15['model'],_0x3a1b15[_0x03f4('0x49')]);_0x41caf1[_0x03f4('0x4f')]=_[_0x03f4('0x4c')](_0x3a1b15[_0x03f4('0x4d')],qs['fields'](_0x458119[_0x03f4('0x49')][_0x03f4('0x4e')]));_0x41caf1[_0x03f4('0x4f')]=_0x41caf1['attributes']['length']?_0x41caf1[_0x03f4('0x4f')]:_0x3a1b15['model'];_0x41caf1[_0x03f4('0x52')]=qs[_0x03f4('0x53')](_0x458119[_0x03f4('0x49')][_0x03f4('0x53')]);_0x41caf1[_0x03f4('0x55')]=qs[_0x03f4('0x4b')](_['pick'](_0x458119[_0x03f4('0x49')],_0x3a1b15[_0x03f4('0x4b')]));if(_0x458119[_0x03f4('0x49')][_0x03f4('0x57')]){_0x41caf1[_0x03f4('0x55')]=_[_0x03f4('0x3d')](_0x41caf1[_0x03f4('0x55')],{'$or':_['map'](_0x41caf1[_0x03f4('0x4f')],function(_0xeb9ebd){var _0x1b545a={};_0x1b545a[_0xeb9ebd]={'$like':'%'+_0x458119[_0x03f4('0x49')][_0x03f4('0x57')]+'%'};return _0x1b545a;})});}_0x41caf1=_[_0x03f4('0x3d')]({},_0x41caf1,_0x458119[_0x03f4('0x58')]);return _0x11c69b[_0x03f4('0x121')](_0x41caf1);}})[_0x03f4('0x1e')](function(_0x37c1e8){if(_0x37c1e8){_0x6b2bf=_0x37c1e8['length'];if(!_0x458119[_0x03f4('0x49')][_0x03f4('0x69')](_0x03f4('0x51'))){_0x41caf1[_0x03f4('0x2b')]=qs[_0x03f4('0x2b')](_0x458119[_0x03f4('0x49')][_0x03f4('0x2b')]);_0x41caf1[_0x03f4('0x2d')]=qs[_0x03f4('0x2d')](_0x458119[_0x03f4('0x49')][_0x03f4('0x2d')]);}return _0x11c69b['getProactiveActions'](_0x41caf1);}})[_0x03f4('0x1e')](function(_0x5c021b){if(_0x5c021b){return _0x5c021b?{'count':_0x6b2bf,'rows':_0x5c021b}:null;}})[_0x03f4('0x1e')](respondWithResult(_0x24b538,null))[_0x03f4('0x5c')](handleError(_0x24b538,null));};exports['getFields']=function(_0x39633e,_0x3afd11,_0x3211cd){var _0x545dd3=_0x39633e[_0x03f4('0x49')][_0x03f4('0x123')]===_0x03f4('0x124')?'offlineForm':'onlineForm';return db[_0x03f4('0x45')][_0x03f4('0x5e')]({'attributes':['id',_0x545dd3],'where':{'id':_0x39633e['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x3afd11,null))[_0x03f4('0x1e')](function(_0x7381d2){if(_0x7381d2){var _0x265cba=_0x7381d2[_0x545dd3];var _0x5172bb=_0x265cba&&_0x265cba[_0x03f4('0x125')]?_0x265cba[_0x03f4('0x125')]:[];_0x3afd11['send']({'fromKey':_['isNil'](_0x265cba['fromKey'])?undefined:_0x265cba[_0x03f4('0x126')],'count':_0x5172bb['length'],'rows':_0x5172bb});}})[_0x03f4('0x5c')](handleError(_0x3afd11,null));};exports[_0x03f4('0x127')]=function(_0x2c1153,_0x448d56,_0x34531e){var _0x3cfd56={'raw':![],'where':{}};var _0x4e2d39={};var _0x1f4b35={'count':0x0,'rows':[]};return db[_0x03f4('0x45')][_0x03f4('0x70')]({'where':{'id':_0x2c1153[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x448d56,null))[_0x03f4('0x1e')](function(_0x4ee1c7){if(_0x4ee1c7){_0x4e2d39[_0x03f4('0x4d')]=_['keys'](db[_0x03f4('0xda')][_0x03f4('0x46')]);_0x4e2d39['query']=_[_0x03f4('0x4a')](_0x2c1153[_0x03f4('0x49')]);_0x4e2d39[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x4e2d39[_0x03f4('0x4d')],_0x4e2d39[_0x03f4('0x49')]);_0x3cfd56[_0x03f4('0x4f')]=_['intersection'](_0x4e2d39['model'],qs[_0x03f4('0x4e')](_0x2c1153[_0x03f4('0x49')]['fields']));_0x3cfd56[_0x03f4('0x4f')]=_0x3cfd56['attributes']['length']?_0x3cfd56['attributes']:_0x4e2d39[_0x03f4('0x4d')];if(!_0x2c1153['query'][_0x03f4('0x69')](_0x03f4('0x51'))){_0x3cfd56[_0x03f4('0x2b')]=qs[_0x03f4('0x2b')](_0x2c1153['query'][_0x03f4('0x2b')]);_0x3cfd56[_0x03f4('0x2d')]=qs[_0x03f4('0x2d')](_0x2c1153[_0x03f4('0x49')][_0x03f4('0x2d')]);}_0x3cfd56[_0x03f4('0x52')]=qs[_0x03f4('0x53')](_0x2c1153[_0x03f4('0x49')][_0x03f4('0x53')]);_0x3cfd56['where']=qs[_0x03f4('0x4b')](_[_0x03f4('0x54')](_0x2c1153[_0x03f4('0x49')],_0x4e2d39[_0x03f4('0x4b')]));_0x3cfd56[_0x03f4('0x55')][_0x03f4('0x67')]=_0x4ee1c7['id'];if(_0x2c1153[_0x03f4('0x49')][_0x03f4('0x57')]){_0x3cfd56[_0x03f4('0x55')]=_[_0x03f4('0x3d')](_0x3cfd56[_0x03f4('0x55')],{'$or':_[_0x03f4('0x48')](_0x3cfd56['attributes'],function(_0x2b465d){var _0x3b9e69={};_0x3b9e69[_0x2b465d]={'$like':'%'+_0x2c1153[_0x03f4('0x49')][_0x03f4('0x57')]+'%'};return _0x3b9e69;})});}_0x3cfd56=_['merge']({},_0x3cfd56,_0x2c1153[_0x03f4('0x58')]);return db['ChatOfflineMessage']['count']({'where':_0x3cfd56[_0x03f4('0x55')]})[_0x03f4('0x1e')](function(_0x4186bc){_0x1f4b35['count']=_0x4186bc;if(_0x2c1153[_0x03f4('0x49')][_0x03f4('0x59')]){_0x3cfd56[_0x03f4('0x5a')]=[{'all':!![]}];}else{_0x3cfd56[_0x03f4('0x5a')]=[{'model':db[_0x03f4('0x92')],'as':'Contact','required':![]},{'model':db[_0x03f4('0x128')],'as':'Attachments','required':![]}];}return db['ChatOfflineMessage']['findAll'](_0x3cfd56);})[_0x03f4('0x1e')](function(_0x1bf109){_0x1f4b35[_0x03f4('0x6a')]=_0x1bf109;return _0x1f4b35;});}})[_0x03f4('0x1e')](respondWithFilteredResult(_0x448d56,_0x3cfd56))[_0x03f4('0x5c')](handleError(_0x448d56,null));};exports[_0x03f4('0x129')]=function(_0x76c722,_0x4dae7f,_0x29b23a){return db[_0x03f4('0x45')]['find']({'where':{'id':_0x76c722['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x4dae7f,null))[_0x03f4('0x1e')](function(_0x2e4819){if(_0x2e4819){return _0x2e4819[_0x03f4('0x129')](_0x76c722[_0x03f4('0x3e')][_0x03f4('0x6c')],_[_0x03f4('0xfb')](_0x76c722[_0x03f4('0x3e')],['ids','id'])||{})[_0x03f4('0xbc')](function(_0x15d586){for(var _0x2e87e2=0x0;_0x2e87e2<_0x76c722[_0x03f4('0x3e')][_0x03f4('0x6c')]['length'];_0x2e87e2+=0x1){socket['emit'](_0x03f4('0x12a'),{'UserId':_0x76c722[_0x03f4('0x3e')][_0x03f4('0x6c')][_0x2e87e2],'ChatWebsiteId':_0x76c722[_0x03f4('0x64')]['id']});}return _0x15d586;});}})[_0x03f4('0x1e')](respondWithResult(_0x4dae7f,null))[_0x03f4('0x5c')](handleError(_0x4dae7f,null));};exports[_0x03f4('0x12b')]=function(_0x3f8882,_0x2ac22e,_0xfd01fd){return db[_0x03f4('0x45')]['find']({'where':{'id':_0x3f8882[_0x03f4('0x64')]['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x2ac22e,null))[_0x03f4('0x1e')](function(_0x1d8a40){if(_0x1d8a40){return _0x1d8a40[_0x03f4('0x12b')](_0x3f8882['query'][_0x03f4('0x6c')])[_0x03f4('0x1e')](function(){if(_[_0x03f4('0x12c')](_0x3f8882[_0x03f4('0x49')][_0x03f4('0x6c')])){for(var _0x29c76e=0x0;_0x29c76e<_0x3f8882['query']['ids']['length'];_0x29c76e+=0x1){socket[_0x03f4('0x12d')](_0x03f4('0x12e'),{'UserId':Number(_0x3f8882[_0x03f4('0x49')][_0x03f4('0x6c')][_0x29c76e]),'ChatWebsiteId':Number(_0x3f8882[_0x03f4('0x64')]['id'])});}}else{socket[_0x03f4('0x12d')](_0x03f4('0x12e'),{'UserId':Number(_0x3f8882[_0x03f4('0x49')][_0x03f4('0x6c')]),'ChatWebsiteId':Number(_0x3f8882[_0x03f4('0x64')]['id'])});}});}})[_0x03f4('0x1e')](respondWithStatusCode(_0x2ac22e,null))[_0x03f4('0x5c')](handleError(_0x2ac22e,null));};exports[_0x03f4('0x12f')]=function(_0x132026,_0x3cf7f8,_0xc67977){var _0x47c63b={};var _0x3b418f={};var _0x19c61f;var _0x562541;return db[_0x03f4('0x45')]['findOne']({'where':{'id':_0x132026['params']['id']}})[_0x03f4('0x1e')](handleEntityNotFound(_0x3cf7f8,null))['then'](function(_0x26741e){if(_0x26741e){_0x19c61f=_0x26741e;_0x3b418f[_0x03f4('0x4d')]=_['keys'](db['User'][_0x03f4('0x46')]);_0x3b418f[_0x03f4('0x49')]=_[_0x03f4('0x4a')](_0x132026[_0x03f4('0x49')]);_0x3b418f[_0x03f4('0x4b')]=_[_0x03f4('0x4c')](_0x3b418f['model'],_0x3b418f[_0x03f4('0x49')]);_0x47c63b['attributes']=_[_0x03f4('0x4c')](_0x3b418f['model'],qs[_0x03f4('0x4e')](_0x132026[_0x03f4('0x49')]['fields']));_0x47c63b[_0x03f4('0x4f')]=_0x47c63b[_0x03f4('0x4f')][_0x03f4('0x50')]?_0x47c63b[_0x03f4('0x4f')]:_0x3b418f[_0x03f4('0x4d')];_0x47c63b['order']=qs['sort'](_0x132026['query']['sort']);_0x47c63b[_0x03f4('0x55')]=qs[_0x03f4('0x4b')](_[_0x03f4('0x54')](_0x132026[_0x03f4('0x49')],_0x3b418f[_0x03f4('0x4b')]));if(_0x132026[_0x03f4('0x49')][_0x03f4('0x57')]){_0x47c63b[_0x03f4('0x55')]=_[_0x03f4('0x3d')](_0x47c63b['where'],{'$or':_[_0x03f4('0x48')](_0x47c63b[_0x03f4('0x4f')],function(_0x1b4eef){var _0x5b6c49={};_0x5b6c49[_0x1b4eef]={'$like':'%'+_0x132026[_0x03f4('0x49')]['filter']+'%'};return _0x5b6c49;})});}_0x47c63b=_[_0x03f4('0x3d')]({},_0x47c63b,_0x132026[_0x03f4('0x58')]);return _0x19c61f[_0x03f4('0x12f')](_0x47c63b);}})[_0x03f4('0x1e')](function(_0x948c31){if(_0x948c31){_0x562541=_0x948c31[_0x03f4('0x50')];if(!_0x132026['query'][_0x03f4('0x69')](_0x03f4('0x51'))){_0x47c63b['limit']=qs[_0x03f4('0x2b')](_0x132026[_0x03f4('0x49')][_0x03f4('0x2b')]);_0x47c63b[_0x03f4('0x2d')]=qs['offset'](_0x132026['query'][_0x03f4('0x2d')]);}return _0x19c61f[_0x03f4('0x12f')](_0x47c63b);}})['then'](function(_0x836e7b){if(_0x836e7b){return _0x836e7b?{'count':_0x562541,'rows':_0x836e7b}:null;}})[_0x03f4('0x1e')](respondWithResult(_0x3cf7f8,null))['catch'](handleError(_0x3cf7f8,null));};