2fe42e66da85537ae856e1c214b5813b7be7514a
[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 _0x6d5e=['orderBy','priority','asc','defaults','customerIp','cf-connecting-ip','headers','x-forwarded-for','first','split','firstName','lastName','x-real-port','browser','format','%s\x20%s','version','unknown','device','vendor','%s\x20%s\x20%s','threadId','ChatInteraction','ContactId','spread','contact','messageId','interaction','created','autoclose','close','unmanaged','*,*,*,*','ChatMessage','AttachmentId','UserId','unshift','agent','waitForTheAssignedAgent','forcedOwnership','startRouting','Start','EventManager','offline','files','mapKeyOffline','MailAccount','findOrCreate','readFileSync','server/files/templates/chatOfflineMessage.ejs','utf8','render','toPairs','offlineMessageBody','ChatOfflineMessage','originalname','mimetype','server','attachments','offline-chat','basename','openNewInteraction','Attachment','bulkCreate','Smtp','forwardOffline','service','host','secure','authentication','auth','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','forwardOfflineAddress','offlineMessageSubject','subjectOffline','toPairsIn','mapValues','NotifyMailAccount','notifyMail','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','User','Owner','internal','Tag','Tags','tag','Command','getSnippet','timezone','iftime\x20%s,%s','interval','iftime\x20%s','indexOf','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','OFFLINE','No\x20timezone','inspect','Interval','Intervals','getProactiveActions','custom','License','increment','chatLicenseExceeded','push','all','remote','x-real-ip','remoteAddress','referer','virtual','replace','verticalAlignment','color','textColor','color_button','backgroundColor','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','findAndCountAll','getApplications','addProactiveActions','ChatProactiveAction','getFields','online','offlineForm','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','userChatWebsite:save','removeAgents','emit','userChatWebsite:remove','getAgents','bluebird','mustache','util','ejs','fs-extra','querystring','ioredis','../../config/logger','../../mysqldb','redis','localhost','socket.io-emitter','./chatWebsite.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','message','ChatWebsite,\x20%s,\x20%s','catch','status','end','json','undefined','limit','count','offset','set','Content-Range','update','destroy','get','ChatWebsites','UserProfileResource','sendStatus','stack','name','send','index','Pause','mandatoryDispositionPause','map','ChatWebsite','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','sort','where','pick','filter','merge','options','include','rows','show','params','length','includeAll','find','create','body','user','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','ChatWebsiteId','Disposition','getDispositions','findOne','nolimit','order','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addLogo','sitepic','filename','addAvatar','file','addCustomerAvatar','customerAvatar','addSystemAvatar','getLogo','root','server/files/images/logos/default_logo.svg','../../config/license/util','getLicense','isNil','existsSync','server/files/images/logos/','join','download','getAvatar','server/files/images/avatars/default_avatar.png','agentAvatar','server/files/images/avatars/','showCustomerAvatar','getSystemAvatar','server/files/images/avatars/system_avatar.png','systemAvatar','notify','setUA','user-agent','getResult','chat','CmContact','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','from','Sequelize','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','ChatApplication','Applications','account','applications','list'];(function(_0x5049e1,_0x4ac87a){var _0x37f162=function(_0x2e06cb){while(--_0x2e06cb){_0x5049e1['push'](_0x5049e1['shift']());}};_0x37f162(++_0x4ac87a);}(_0x6d5e,0x1c6));var _0xe6d5=function(_0x1df8cb,_0x53a66c){_0x1df8cb=_0x1df8cb-0x0;var _0x259a5a=_0x6d5e[_0x1df8cb];return _0x259a5a;};'use strict';var BPromise=require(_0xe6d5('0x0'));var Mustache=require(_0xe6d5('0x1'));var util=require(_0xe6d5('0x2'));var path=require('path');var ejs=require(_0xe6d5('0x3'));var fs=require('fs');var fs_extra=require(_0xe6d5('0x4'));var _=require('lodash');var querystring=require(_0xe6d5('0x5'));var Redis=require(_0xe6d5('0x6'));var qs=require('../../components/parsers/qs');var logger=require(_0xe6d5('0x7'))('api');var config=require('../../config/environment');var db=require(_0xe6d5('0x8'))['db'];config[_0xe6d5('0x9')]=_['defaults'](config['redis'],{'host':_0xe6d5('0xa'),'port':0x18eb});var socket=require(_0xe6d5('0xb'))(new Redis(config[_0xe6d5('0x9')]));require(_0xe6d5('0xc'))[_0xe6d5('0xd')](socket);var jayson=require(_0xe6d5('0xe'));var client=jayson[_0xe6d5('0xf')][_0xe6d5('0x10')]({'port':0x232c});var client9002=jayson[_0xe6d5('0xf')][_0xe6d5('0x10')]({'port':0x232a});var client9003=jayson['client'][_0xe6d5('0x10')]({'port':0x232b});var client9001=jayson[_0xe6d5('0xf')]['http']({'port':0x2329});function respondWithRpcPromise(_0x2990c1,_0x3ad387,_0x35c540,_0x12a715){return new BPromise(function(_0xbb2244,_0x597ca8){var _0x2aa3fa=_0x12a715||client;return _0x2aa3fa[_0xe6d5('0x11')](_0x2990c1,_0x35c540)[_0xe6d5('0x12')](function(_0x2608c6){logger[_0xe6d5('0x13')]('ChatWebsite,\x20%s,\x20%s',_0x3ad387,_0xe6d5('0x14'));logger[_0xe6d5('0x15')](_0xe6d5('0x16'),_0x3ad387,_0xe6d5('0x14'),JSON[_0xe6d5('0x17')](_0x2608c6));if(_0x2608c6[_0xe6d5('0x18')]){if(_0x2608c6[_0xe6d5('0x18')]['code']===0x1f4){logger[_0xe6d5('0x18')]('ChatWebsite,\x20%s,\x20%s',_0x3ad387,_0x2608c6[_0xe6d5('0x18')][_0xe6d5('0x19')]);return _0x597ca8(_0x2608c6[_0xe6d5('0x18')][_0xe6d5('0x19')]);}logger[_0xe6d5('0x18')](_0xe6d5('0x1a'),_0x3ad387,_0x2608c6[_0xe6d5('0x18')]['message']);return _0xbb2244(_0x2608c6['error']['message']);}else{logger[_0xe6d5('0x13')]('ChatWebsite,\x20%s,\x20%s',_0x3ad387,_0xe6d5('0x14'));_0xbb2244(_0x2608c6['result'][_0xe6d5('0x19')]);}})[_0xe6d5('0x1b')](function(_0x56fc13){logger[_0xe6d5('0x18')](_0xe6d5('0x1a'),_0x3ad387,_0x56fc13);_0x597ca8(_0x56fc13);});});}function respondWithStatusCode(_0x1dc1f9,_0x5994c8){_0x5994c8=_0x5994c8||0xcc;return function(_0x39bfe5){if(_0x39bfe5){return _0x1dc1f9['sendStatus'](_0x5994c8);}return _0x1dc1f9[_0xe6d5('0x1c')](_0x5994c8)[_0xe6d5('0x1d')]();};}function respondWithResult(_0x20b724,_0x252b20){_0x252b20=_0x252b20||0xc8;return function(_0x55ee29){if(_0x55ee29){return _0x20b724[_0xe6d5('0x1c')](_0x252b20)[_0xe6d5('0x1e')](_0x55ee29);}};}function respondWithFilteredResult(_0x4cfee6,_0x4d43eb){return function(_0x22fe3c){if(_0x22fe3c){var _0x5a47d9=typeof _0x4d43eb['offset']===_0xe6d5('0x1f')&&typeof _0x4d43eb[_0xe6d5('0x20')]===_0xe6d5('0x1f');var _0x2dd993=_0x22fe3c[_0xe6d5('0x21')];var _0x959852=_0x5a47d9?0x0:_0x4d43eb[_0xe6d5('0x22')];var _0x1a2545=_0x5a47d9?_0x22fe3c[_0xe6d5('0x21')]:_0x4d43eb[_0xe6d5('0x22')]+_0x4d43eb['limit'];var _0x492059;if(_0x1a2545>=_0x2dd993){_0x1a2545=_0x2dd993;_0x492059=0xc8;}else{_0x492059=0xce;}_0x4cfee6[_0xe6d5('0x1c')](_0x492059);return _0x4cfee6[_0xe6d5('0x23')](_0xe6d5('0x24'),_0x959852+'-'+_0x1a2545+'/'+_0x2dd993)[_0xe6d5('0x1e')](_0x22fe3c);}return null;};}function saveUpdates(_0x3cbb06){return function(_0x420c95){if(_0x420c95){return _0x420c95[_0xe6d5('0x25')](_0x3cbb06)['then'](function(_0x233a7e){return _0x233a7e;});}return null;};}function removeEntity(_0x9e90d2){return function(_0x3f400b){if(_0x3f400b){return _0x3f400b[_0xe6d5('0x26')]()[_0xe6d5('0x12')](function(){var _0x2bbd64=_0x3f400b[_0xe6d5('0x27')]({'plain':!![]});var _0x2ca1f5=_0xe6d5('0x28');return db[_0xe6d5('0x29')][_0xe6d5('0x26')]({'where':{'type':_0x2ca1f5,'resourceId':_0x2bbd64['id']}})['then'](function(){return _0x3f400b;});})['then'](function(){_0x9e90d2[_0xe6d5('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x54eb06){return function(_0x5492f3){if(!_0x5492f3){_0x54eb06[_0xe6d5('0x2a')](0x194);}return _0x5492f3;};}function handleError(_0x56dc77,_0xf39a96){_0xf39a96=_0xf39a96||0x1f4;return function(_0x1385a4){logger['error'](_0x1385a4[_0xe6d5('0x2b')]);if(_0x1385a4[_0xe6d5('0x2c')]){delete _0x1385a4[_0xe6d5('0x2c')];}_0x56dc77[_0xe6d5('0x1c')](_0xf39a96)[_0xe6d5('0x2d')](_0x1385a4);};}exports[_0xe6d5('0x2e')]=function(_0x13b049,_0x3bd880){var _0x428db9={'include':[{'model':db[_0xe6d5('0x2f')],'as':_0xe6d5('0x30')}]},_0x46bfeb={},_0x4b5a45={'count':0x0,'rows':[]};var _0x165781=_[_0xe6d5('0x31')](db[_0xe6d5('0x32')][_0xe6d5('0x33')],function(_0x29222c){return{'name':_0x29222c[_0xe6d5('0x34')],'type':_0x29222c[_0xe6d5('0x35')][_0xe6d5('0x36')]};});_0x46bfeb[_0xe6d5('0x37')]=_[_0xe6d5('0x31')](_0x165781,'name');_0x46bfeb[_0xe6d5('0x38')]=_[_0xe6d5('0x39')](_0x13b049[_0xe6d5('0x38')]);_0x46bfeb[_0xe6d5('0x3a')]=_[_0xe6d5('0x3b')](_0x46bfeb[_0xe6d5('0x37')],_0x46bfeb[_0xe6d5('0x38')]);_0x428db9[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x46bfeb[_0xe6d5('0x37')],qs[_0xe6d5('0x3d')](_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x3d')]));_0x428db9[_0xe6d5('0x3c')]=_0x428db9[_0xe6d5('0x3c')]['length']?_0x428db9[_0xe6d5('0x3c')]:_0x46bfeb['model'];if(!_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x3e')]('nolimit')){_0x428db9[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x20')]);_0x428db9['offset']=qs[_0xe6d5('0x22')](_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x22')]);}_0x428db9['order']=qs[_0xe6d5('0x3f')](_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x3f')]);_0x428db9[_0xe6d5('0x40')]=qs['filters'](_[_0xe6d5('0x41')](_0x13b049[_0xe6d5('0x38')],_0x46bfeb[_0xe6d5('0x3a')]),_0x165781);if(_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x42')]){_0x428db9[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0x428db9[_0xe6d5('0x40')],{'$or':_[_0xe6d5('0x31')](_0x165781,function(_0x18cdd9){if(_0x18cdd9[_0xe6d5('0x35')]!=='VIRTUAL'){var _0x263ed6={};_0x263ed6[_0x18cdd9[_0xe6d5('0x2c')]]={'$like':'%'+_0x13b049[_0xe6d5('0x38')][_0xe6d5('0x42')]+'%'};return _0x263ed6;}})});}_0x428db9=_['merge']({},_0x428db9,_0x13b049[_0xe6d5('0x44')]);var _0x484a79={'where':_0x428db9[_0xe6d5('0x40')]};return db[_0xe6d5('0x32')][_0xe6d5('0x21')](_0x484a79)[_0xe6d5('0x12')](function(_0x5eb3a6){_0x4b5a45['count']=_0x5eb3a6;if(_0x13b049['query']['includeAll']){_0x428db9[_0xe6d5('0x45')]=[{'all':!![]}];}return db[_0xe6d5('0x32')]['findAll'](_0x428db9);})[_0xe6d5('0x12')](function(_0x467827){_0x4b5a45[_0xe6d5('0x46')]=_0x467827;return _0x4b5a45;})[_0xe6d5('0x12')](respondWithFilteredResult(_0x3bd880,_0x428db9))[_0xe6d5('0x1b')](handleError(_0x3bd880,null));};exports[_0xe6d5('0x47')]=function(_0x3c09af,_0x5d0fbc){var _0x45e066={'raw':![],'where':{'id':_0x3c09af[_0xe6d5('0x48')]['id']},'include':[{'model':db[_0xe6d5('0x2f')],'as':_0xe6d5('0x30')}]},_0x2bb27d={};_0x2bb27d[_0xe6d5('0x37')]=_[_0xe6d5('0x39')](db[_0xe6d5('0x32')][_0xe6d5('0x33')]);_0x2bb27d[_0xe6d5('0x38')]=_[_0xe6d5('0x39')](_0x3c09af[_0xe6d5('0x38')]);_0x2bb27d[_0xe6d5('0x3a')]=_[_0xe6d5('0x3b')](_0x2bb27d[_0xe6d5('0x37')],_0x2bb27d[_0xe6d5('0x38')]);_0x45e066[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x2bb27d['model'],qs[_0xe6d5('0x3d')](_0x3c09af['query'][_0xe6d5('0x3d')]));_0x45e066['attributes']=_0x45e066[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x45e066['attributes']:_0x2bb27d[_0xe6d5('0x37')];if(_0x3c09af[_0xe6d5('0x38')][_0xe6d5('0x4a')]){_0x45e066[_0xe6d5('0x45')]=[{'all':!![]}];}_0x45e066=_[_0xe6d5('0x43')]({},_0x45e066,_0x3c09af[_0xe6d5('0x44')]);return db['ChatWebsite'][_0xe6d5('0x4b')](_0x45e066)['then'](handleEntityNotFound(_0x5d0fbc,null))[_0xe6d5('0x12')](respondWithResult(_0x5d0fbc,null))[_0xe6d5('0x1b')](handleError(_0x5d0fbc,null));};exports[_0xe6d5('0x4c')]=function(_0x54a916,_0x2af27e){return db[_0xe6d5('0x32')][_0xe6d5('0x4c')](_0x54a916[_0xe6d5('0x4d')],{})['then'](function(_0x4394f0){var _0x27939b=_0x54a916[_0xe6d5('0x4e')][_0xe6d5('0x27')]({'plain':!![]});if(!_0x27939b)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x27939b['role']===_0xe6d5('0x4e')){var _0x4e4391=_0x4394f0[_0xe6d5('0x27')]({'plain':!![]});var _0x28a6cb=_0xe6d5('0x28');return db['UserProfileSection']['find']({'where':{'name':_0x28a6cb,'userProfileId':_0x27939b[_0xe6d5('0x4f')]},'raw':!![]})[_0xe6d5('0x12')](function(_0x23aaba){if(_0x23aaba&&_0x23aaba['autoAssociation']===0x0){return db[_0xe6d5('0x29')][_0xe6d5('0x4c')]({'name':_0x4e4391[_0xe6d5('0x2c')],'resourceId':_0x4e4391['id'],'type':_0x23aaba[_0xe6d5('0x2c')],'sectionId':_0x23aaba['id']},{})[_0xe6d5('0x12')](function(){return _0x4394f0;});}else{return _0x4394f0;}})[_0xe6d5('0x1b')](function(_0xd9052a){logger['error'](_0xe6d5('0x50'),_0xd9052a);throw _0xd9052a;});}return _0x4394f0;})[_0xe6d5('0x12')](respondWithResult(_0x2af27e,0xc9))[_0xe6d5('0x1b')](handleError(_0x2af27e,null));};exports[_0xe6d5('0x25')]=function(_0x2fe88c,_0x1746e3){if(_0x2fe88c[_0xe6d5('0x4d')]['id']){delete _0x2fe88c[_0xe6d5('0x4d')]['id'];}return db[_0xe6d5('0x32')]['find']({'where':{'id':_0x2fe88c[_0xe6d5('0x48')]['id']},'include':[{'model':db[_0xe6d5('0x2f')],'as':_0xe6d5('0x30')}]})[_0xe6d5('0x12')](handleEntityNotFound(_0x1746e3,null))['then'](saveUpdates(_0x2fe88c[_0xe6d5('0x4d')],null))[_0xe6d5('0x12')](respondWithResult(_0x1746e3,null))[_0xe6d5('0x1b')](handleError(_0x1746e3,null));};exports['destroy']=function(_0x3f8dd6,_0x775e8c){return db[_0xe6d5('0x32')][_0xe6d5('0x4b')]({'where':{'id':_0x3f8dd6[_0xe6d5('0x48')]['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x775e8c,null))[_0xe6d5('0x12')](removeEntity(_0x775e8c,null))[_0xe6d5('0x1b')](handleError(_0x775e8c,null));};exports[_0xe6d5('0x51')]=function(_0x229549,_0x2f5934){return db[_0xe6d5('0x32')][_0xe6d5('0x51')]()[_0xe6d5('0x12')](respondWithResult(_0x2f5934,null))['catch'](handleError(_0x2f5934,null));};exports[_0xe6d5('0x52')]=function(_0x4ea32f,_0xc3d5){if(_0x4ea32f[_0xe6d5('0x4d')]['id']){delete _0x4ea32f[_0xe6d5('0x4d')]['id'];}return db['ChatWebsite'][_0xe6d5('0x4b')]({'where':{'id':_0x4ea32f[_0xe6d5('0x48')]['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0xc3d5,null))['then'](function(_0x3dcb7c){if(_0x3dcb7c){_0x4ea32f[_0xe6d5('0x4d')][_0xe6d5('0x53')]=_0x3dcb7c['id'];return db[_0xe6d5('0x54')]['create'](_0x4ea32f['body']);}})[_0xe6d5('0x12')](respondWithResult(_0xc3d5,null))[_0xe6d5('0x1b')](handleError(_0xc3d5,null));};exports[_0xe6d5('0x55')]=function(_0x114e59,_0x41a446){var _0x397cde={'raw':![],'where':{}};var _0x542d41={};var _0x350429={'count':0x0,'rows':[]};return db[_0xe6d5('0x32')][_0xe6d5('0x56')]({'where':{'id':_0x114e59['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x41a446,null))['then'](function(_0x187d41){if(_0x187d41){_0x542d41[_0xe6d5('0x37')]=_[_0xe6d5('0x39')](db['Disposition'][_0xe6d5('0x33')]);_0x542d41['query']=_[_0xe6d5('0x39')](_0x114e59[_0xe6d5('0x38')]);_0x542d41[_0xe6d5('0x3a')]=_['intersection'](_0x542d41['model'],_0x542d41[_0xe6d5('0x38')]);_0x397cde[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x542d41[_0xe6d5('0x37')],qs[_0xe6d5('0x3d')](_0x114e59[_0xe6d5('0x38')]['fields']));_0x397cde[_0xe6d5('0x3c')]=_0x397cde[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x397cde['attributes']:_0x542d41['model'];if(!_0x114e59[_0xe6d5('0x38')]['hasOwnProperty'](_0xe6d5('0x57'))){_0x397cde[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x114e59[_0xe6d5('0x38')][_0xe6d5('0x20')]);_0x397cde[_0xe6d5('0x22')]=qs[_0xe6d5('0x22')](_0x114e59['query'][_0xe6d5('0x22')]);}_0x397cde[_0xe6d5('0x58')]=qs['sort'](_0x114e59[_0xe6d5('0x38')][_0xe6d5('0x3f')]);_0x397cde[_0xe6d5('0x40')]=qs[_0xe6d5('0x3a')](_[_0xe6d5('0x41')](_0x114e59[_0xe6d5('0x38')],_0x542d41[_0xe6d5('0x3a')]));_0x397cde[_0xe6d5('0x40')][_0xe6d5('0x53')]=_0x187d41['id'];if(_0x114e59[_0xe6d5('0x38')][_0xe6d5('0x42')]){_0x397cde[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0x397cde['where'],{'$or':_[_0xe6d5('0x31')](_0x397cde['attributes'],function(_0x537e99){var _0x5760c7={};_0x5760c7[_0x537e99]={'$like':'%'+_0x114e59[_0xe6d5('0x38')]['filter']+'%'};return _0x5760c7;})});}_0x397cde=_[_0xe6d5('0x43')]({},_0x397cde,_0x114e59[_0xe6d5('0x44')]);return db[_0xe6d5('0x54')][_0xe6d5('0x21')]({'where':_0x397cde[_0xe6d5('0x40')]})['then'](function(_0x374875){_0x350429[_0xe6d5('0x21')]=_0x374875;if(_0x114e59[_0xe6d5('0x38')][_0xe6d5('0x4a')]){_0x397cde[_0xe6d5('0x45')]=[{'all':!![]}];}return db[_0xe6d5('0x54')][_0xe6d5('0x59')](_0x397cde);})[_0xe6d5('0x12')](function(_0x5b1a59){_0x350429['rows']=_0x5b1a59;return _0x350429;});}})['then'](respondWithFilteredResult(_0x41a446,_0x397cde))['catch'](handleError(_0x41a446,null));};exports[_0xe6d5('0x5a')]=function(_0x279350,_0x245f66){return db[_0xe6d5('0x32')][_0xe6d5('0x4b')]({'where':{'id':_0x279350[_0xe6d5('0x48')]['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x245f66,null))[_0xe6d5('0x12')](function(_0x2231f4){if(_0x2231f4){return _0x2231f4[_0xe6d5('0x5a')](_0x279350['query'][_0xe6d5('0x5b')]);}})[_0xe6d5('0x12')](respondWithStatusCode(_0x245f66,null))[_0xe6d5('0x1b')](handleError(_0x245f66,null));};exports[_0xe6d5('0x5c')]=function(_0x425afc,_0x19ed45){if(_0x425afc[_0xe6d5('0x4d')]['id']){delete _0x425afc['body']['id'];}return db[_0xe6d5('0x32')][_0xe6d5('0x4b')]({'where':{'id':_0x425afc[_0xe6d5('0x48')]['id']}})['then'](handleEntityNotFound(_0x19ed45,null))[_0xe6d5('0x12')](function(_0x1cac47){if(_0x1cac47){_0x425afc[_0xe6d5('0x4d')][_0xe6d5('0x53')]=_0x1cac47['id'];return db[_0xe6d5('0x5d')][_0xe6d5('0x4c')](_0x425afc[_0xe6d5('0x4d')]);}})['then'](respondWithResult(_0x19ed45,null))[_0xe6d5('0x1b')](handleError(_0x19ed45,null));};exports[_0xe6d5('0x5e')]=function(_0x24f883,_0x1f880b){var _0x172f7d={'raw':![],'where':{}};var _0x544ae5={};var _0x52cb25={'count':0x0,'rows':[]};return db['ChatWebsite']['findOne']({'where':{'id':_0x24f883['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x1f880b,null))[_0xe6d5('0x12')](function(_0x5b5982){if(_0x5b5982){_0x544ae5[_0xe6d5('0x37')]=_[_0xe6d5('0x39')](db[_0xe6d5('0x5d')][_0xe6d5('0x33')]);_0x544ae5[_0xe6d5('0x38')]=_[_0xe6d5('0x39')](_0x24f883[_0xe6d5('0x38')]);_0x544ae5['filters']=_['intersection'](_0x544ae5['model'],_0x544ae5[_0xe6d5('0x38')]);_0x172f7d[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x544ae5['model'],qs[_0xe6d5('0x3d')](_0x24f883['query']['fields']));_0x172f7d[_0xe6d5('0x3c')]=_0x172f7d[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x172f7d[_0xe6d5('0x3c')]:_0x544ae5[_0xe6d5('0x37')];if(!_0x24f883[_0xe6d5('0x38')][_0xe6d5('0x3e')](_0xe6d5('0x57'))){_0x172f7d[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x24f883['query']['limit']);_0x172f7d[_0xe6d5('0x22')]=qs['offset'](_0x24f883['query'][_0xe6d5('0x22')]);}_0x172f7d[_0xe6d5('0x58')]=qs['sort'](_0x24f883[_0xe6d5('0x38')][_0xe6d5('0x3f')]);_0x172f7d[_0xe6d5('0x40')]=qs[_0xe6d5('0x3a')](_[_0xe6d5('0x41')](_0x24f883['query'],_0x544ae5[_0xe6d5('0x3a')]));_0x172f7d[_0xe6d5('0x40')][_0xe6d5('0x53')]=_0x5b5982['id'];if(_0x24f883['query'][_0xe6d5('0x42')]){_0x172f7d[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0x172f7d[_0xe6d5('0x40')],{'$or':_[_0xe6d5('0x31')](_0x172f7d[_0xe6d5('0x3c')],function(_0x3136b2){var _0xcdd2d8={};_0xcdd2d8[_0x3136b2]={'$like':'%'+_0x24f883[_0xe6d5('0x38')]['filter']+'%'};return _0xcdd2d8;})});}_0x172f7d=_[_0xe6d5('0x43')]({},_0x172f7d,_0x24f883[_0xe6d5('0x44')]);return db[_0xe6d5('0x5d')][_0xe6d5('0x21')]({'where':_0x172f7d[_0xe6d5('0x40')]})[_0xe6d5('0x12')](function(_0x50bf10){_0x52cb25[_0xe6d5('0x21')]=_0x50bf10;if(_0x24f883['query'][_0xe6d5('0x4a')]){_0x172f7d[_0xe6d5('0x45')]=[{'all':!![]}];}return db[_0xe6d5('0x5d')][_0xe6d5('0x59')](_0x172f7d);})['then'](function(_0x312c41){_0x52cb25['rows']=_0x312c41;return _0x52cb25;});}})[_0xe6d5('0x12')](respondWithFilteredResult(_0x1f880b,_0x172f7d))[_0xe6d5('0x1b')](handleError(_0x1f880b,null));};exports[_0xe6d5('0x5f')]=function(_0x441dfa,_0xc93e60){return db[_0xe6d5('0x32')]['find']({'where':{'id':_0x441dfa['params']['id']}})['then'](handleEntityNotFound(_0xc93e60,null))[_0xe6d5('0x12')](function(_0x17b6fc){if(_0x17b6fc){return _0x17b6fc[_0xe6d5('0x5f')](_0x441dfa['query'][_0xe6d5('0x5b')]);}})[_0xe6d5('0x12')](respondWithStatusCode(_0xc93e60,null))[_0xe6d5('0x1b')](handleError(_0xc93e60,null));};exports[_0xe6d5('0x60')]=function(_0x163194,_0x247137){_0x163194[_0xe6d5('0x4d')][_0xe6d5('0x61')]=_0x163194['file'][_0xe6d5('0x62')];return db['ChatWebsite'][_0xe6d5('0x4b')]({'where':{'id':_0x163194[_0xe6d5('0x48')]['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x247137,null))[_0xe6d5('0x12')](saveUpdates(_0x163194[_0xe6d5('0x4d')],null))['then'](respondWithResult(_0x247137,null))[_0xe6d5('0x1b')](handleError(_0x247137,null));};exports[_0xe6d5('0x63')]=function(_0x1cb9a6,_0x2a9cdf){_0x1cb9a6['body']['agentAvatar']=_0x1cb9a6[_0xe6d5('0x64')][_0xe6d5('0x62')];return db[_0xe6d5('0x32')][_0xe6d5('0x4b')]({'where':{'id':_0x1cb9a6['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x2a9cdf,null))['then'](saveUpdates(_0x1cb9a6['body'],null))[_0xe6d5('0x12')](respondWithResult(_0x2a9cdf,null))['catch'](handleError(_0x2a9cdf,null));};exports[_0xe6d5('0x65')]=function(_0x1322df,_0x89959e){_0x1322df[_0xe6d5('0x4d')][_0xe6d5('0x66')]=_0x1322df[_0xe6d5('0x64')][_0xe6d5('0x62')];return db['ChatWebsite'][_0xe6d5('0x4b')]({'where':{'id':_0x1322df[_0xe6d5('0x48')]['id']}})['then'](handleEntityNotFound(_0x89959e,null))[_0xe6d5('0x12')](saveUpdates(_0x1322df[_0xe6d5('0x4d')],null))[_0xe6d5('0x12')](respondWithResult(_0x89959e,null))[_0xe6d5('0x1b')](handleError(_0x89959e,null));};exports[_0xe6d5('0x67')]=function(_0x3563b4,_0x44db10){_0x3563b4[_0xe6d5('0x4d')]['systemAvatar']=_0x3563b4['file'][_0xe6d5('0x62')];return db[_0xe6d5('0x32')]['find']({'where':{'id':_0x3563b4[_0xe6d5('0x48')]['id']}})['then'](handleEntityNotFound(_0x44db10,null))['then'](saveUpdates(_0x3563b4[_0xe6d5('0x4d')],null))[_0xe6d5('0x12')](respondWithResult(_0x44db10,null))[_0xe6d5('0x1b')](handleError(_0x44db10,null));};exports[_0xe6d5('0x68')]=function(_0xb3fd24,_0x4e5a47){var _0x32fc7a=path['join'](config[_0xe6d5('0x69')],_0xe6d5('0x6a'));var _0x3bee53={'where':{'id':_0xb3fd24['params']['id']},'attributes':['id','sitepic'],'raw':!![]};var _0x5a9cf6=![];return require(_0xe6d5('0x6b'))[_0xe6d5('0x6c')]()[_0xe6d5('0x12')](function(_0x30f7ea){if(_0x30f7ea){_0x5a9cf6=_0x30f7ea['custom'];}})['then'](function(){return db[_0xe6d5('0x32')][_0xe6d5('0x4b')](_0x3bee53);})[_0xe6d5('0x12')](handleEntityNotFound(_0x4e5a47,null))[_0xe6d5('0x12')](function(_0x5d1ef2){if(_0x5d1ef2){if(!_[_0xe6d5('0x6d')](_0x5d1ef2['sitepic'])){if(fs[_0xe6d5('0x6e')](path['join'](config[_0xe6d5('0x69')],_0xe6d5('0x6f'),_0x5d1ef2[_0xe6d5('0x61')]))&&_0x5a9cf6){_0x32fc7a=path[_0xe6d5('0x70')](config[_0xe6d5('0x69')],_0xe6d5('0x6f'),_0x5d1ef2[_0xe6d5('0x61')]);}}return _0x4e5a47[_0xe6d5('0x71')](_0x32fc7a);}})['catch'](handleError(_0x4e5a47,null));};exports[_0xe6d5('0x72')]=function(_0x91575c,_0x21de5e){var _0x25cb74=path[_0xe6d5('0x70')](config[_0xe6d5('0x69')],_0xe6d5('0x73'));var _0x542622={'where':{'id':_0x91575c['params']['id']},'attributes':['id',_0xe6d5('0x74')],'raw':!![]};return db[_0xe6d5('0x32')][_0xe6d5('0x4b')](_0x542622)['then'](handleEntityNotFound(_0x21de5e,null))[_0xe6d5('0x12')](function(_0x19b838){if(_0x19b838){if(!_['isNil'](_0x19b838[_0xe6d5('0x74')])){if(fs[_0xe6d5('0x6e')](path['join'](config[_0xe6d5('0x69')],'server/files/images/avatars/',_0x19b838[_0xe6d5('0x74')]))){_0x25cb74=path[_0xe6d5('0x70')](config[_0xe6d5('0x69')],'server/files/images/avatars/',_0x19b838[_0xe6d5('0x74')]);}}return _0x21de5e[_0xe6d5('0x71')](_0x25cb74);}})[_0xe6d5('0x1b')](handleError(_0x21de5e,null));};exports['getCustomerAvatar']=function(_0x68ce9a,_0x482759){var _0xb8c059=path['join'](config['root'],'server/files/images/avatars/customer_avatar.png');var _0x5ac945={'where':{'id':_0x68ce9a[_0xe6d5('0x48')]['id']},'attributes':['id',_0xe6d5('0x66'),'showCustomerAvatar'],'raw':!![]};return db[_0xe6d5('0x32')]['find'](_0x5ac945)['then'](handleEntityNotFound(_0x482759,null))[_0xe6d5('0x12')](function(_0x50f161){if(_0x50f161){if(!_[_0xe6d5('0x6d')](_0x50f161[_0xe6d5('0x66')])){if(fs['existsSync'](path[_0xe6d5('0x70')](config['root'],_0xe6d5('0x75'),_0x50f161[_0xe6d5('0x66')]))&&_0x50f161[_0xe6d5('0x76')]){_0xb8c059=path[_0xe6d5('0x70')](config[_0xe6d5('0x69')],'server/files/images/avatars/',_0x50f161[_0xe6d5('0x66')]);}}return _0x482759[_0xe6d5('0x71')](_0xb8c059);}})[_0xe6d5('0x1b')](handleError(_0x482759,null));};exports[_0xe6d5('0x77')]=function(_0x2d0e81,_0x1de4c8){var _0x1fd736=path[_0xe6d5('0x70')](config['root'],_0xe6d5('0x78'));var _0x5c4589={'where':{'id':_0x2d0e81[_0xe6d5('0x48')]['id']},'attributes':['id','systemAvatar'],'raw':!![]};return db[_0xe6d5('0x32')][_0xe6d5('0x4b')](_0x5c4589)[_0xe6d5('0x12')](handleEntityNotFound(_0x1de4c8,null))['then'](function(_0x159d06){if(_0x159d06){if(!_['isNil'](_0x159d06[_0xe6d5('0x79')])){if(fs['existsSync'](path['join'](config[_0xe6d5('0x69')],_0xe6d5('0x75'),_0x159d06['systemAvatar']))){_0x1fd736=path['join'](config['root'],_0xe6d5('0x75'),_0x159d06[_0xe6d5('0x79')]);}}return _0x1de4c8[_0xe6d5('0x71')](_0x1fd736);}})['catch'](handleError(_0x1de4c8,null));};exports[_0xe6d5('0x7a')]=function(_0xa459e8,_0x11ed51){var _0x24c259=require('user-agent-parser');var _0xc907f1=new _0x24c259();var _0x1baac1=_0xc907f1[_0xe6d5('0x7b')](_0xa459e8['headers'][_0xe6d5('0x7c')])[_0xe6d5('0x7d')]();var _0x142e0b={'body':_0xa459e8[_0xe6d5('0x4d')],'channel':_0xe6d5('0x7e')};var _0x239e6b=[];var _0x2b98d9=[];var _0x51ba37={};var _0x344051=![];return db[_0xe6d5('0x7f')][_0xe6d5('0x51')]()[_0xe6d5('0x12')](function(_0x46b661){if(!_0x46b661){throw new db['Sequelize'][(_0xe6d5('0x80'))](_0xe6d5('0x81'));}_0x239e6b=_[_0xe6d5('0x82')](_[_0xe6d5('0x39')](_0x46b661),[_0xe6d5('0x83'),'updatedAt']);_0x2b98d9=_['difference'](_[_0xe6d5('0x39')](_0x46b661),[_0xe6d5('0x83'),_0xe6d5('0x84'),_0xe6d5('0x85'),_0xe6d5('0x86')]);if(_0xa459e8[_0xe6d5('0x4d')]['id']){delete _0xa459e8['body']['id'];}if(_[_0xe6d5('0x6d')](_0xa459e8['body'][_0xe6d5('0x87')])){throw new db[(_0xe6d5('0x88'))][(_0xe6d5('0x80'))](_0xe6d5('0x89'));}if(_[_0xe6d5('0x6d')](_0xa459e8[_0xe6d5('0x4d')]['body'])||_0xa459e8['body'][_0xe6d5('0x4d')]===''){throw new db[(_0xe6d5('0x88'))]['ValidationError'](_0xe6d5('0x8a'));}if(_['isNil'](_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x8b')])){throw new db['Sequelize'][(_0xe6d5('0x80'))](_0xe6d5('0x8c')+_0x2b98d9);}if(!_[_0xe6d5('0x8d')](_0x2b98d9,_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x8b')])){throw new db['Sequelize'][(_0xe6d5('0x80'))](_0xe6d5('0x8e')+_0x2b98d9);}_0x51ba37[_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x8b')]]=_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x87')];})[_0xe6d5('0x12')](function(){return db[_0xe6d5('0x32')]['find']({'where':{'id':_0xa459e8['params']['id']},'include':[{'model':db[_0xe6d5('0x8f')],'as':_0xe6d5('0x90'),'include':[{'model':db[_0xe6d5('0x7f')],'as':_0xe6d5('0x91'),'where':_0x51ba37,'limit':0x1,'order':[['updatedAt',_0xe6d5('0x92')]]}]},{'model':db[_0xe6d5('0x93')],'as':_0xe6d5('0x94')}]});})['then'](handleEntityNotFound(_0x11ed51,null))[_0xe6d5('0x12')](function(_0x2370d0){if(_0x2370d0&&_0x2370d0[_0xe6d5('0x90')]){_0x142e0b[_0xe6d5('0x95')]=_0x2370d0;_0x142e0b[_0xe6d5('0x96')]=_0x2370d0[_0xe6d5('0x94')];_0x142e0b[_0xe6d5('0x97')]=_0x2370d0[_0xe6d5('0x90')];_0x142e0b[_0xe6d5('0x96')]=_[_0xe6d5('0x98')](_0x142e0b[_0xe6d5('0x96')],[_0xe6d5('0x99')],[_0xe6d5('0x9a')]);if(_0x142e0b['account'][_0xe6d5('0x94')]){delete _0x142e0b['account'][_0xe6d5('0x94')];}if(_0x142e0b[_0xe6d5('0x95')][_0xe6d5('0x90')]&&_0x142e0b[_0xe6d5('0x95')][_0xe6d5('0x90')][_0xe6d5('0x91')][_0xe6d5('0x49')]){return _0x142e0b[_0xe6d5('0x95')][_0xe6d5('0x90')][_0xe6d5('0x91')][0x0];}var _0x2ed970=_[_0xe6d5('0x9b')](_0xa459e8[_0xe6d5('0x4d')],{'firstName':_0xa459e8[_0xe6d5('0x4d')]['from'],'ListId':_0x2370d0[_0xe6d5('0x86')]});_0x2ed970[_0xa459e8['body'][_0xe6d5('0x8b')]]=_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x87')];return db[_0xe6d5('0x7f')][_0xe6d5('0x4c')](_0x2ed970,{'fields':_0x239e6b,'raw':!![]});}})['then'](handleEntityNotFound(_0x11ed51,null))[_0xe6d5('0x12')](function(_0x5225ce){_0x142e0b['contact']=_0x5225ce;var _0x4695d9=_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x9c')];if(_0xa459e8['headers']['cf-connecting-ip']){_0x4695d9=_0xa459e8['headers'][_0xe6d5('0x9d')];}else if(_0xa459e8[_0xe6d5('0x9e')][_0xe6d5('0x9f')]){_0x4695d9=_[_0xe6d5('0xa0')](_0xa459e8['headers'][_0xe6d5('0x9f')][_0xe6d5('0xa1')](','));}if(_0x5225ce){var _0x1343ba={'ContactId':_0x5225ce['id'],'ChatWebsiteId':_0xa459e8[_0xe6d5('0x48')]['id'],'from':(_0x5225ce[_0xe6d5('0xa2')]||'')+'\x20'+(_0x5225ce[_0xe6d5('0xa3')]||''),'customerIp':_0x4695d9,'customerPort':_0xa459e8[_0xe6d5('0x9e')][_0xe6d5('0xa4')]?_0xa459e8['headers'][_0xe6d5('0xa4')]:null,'referer':_0xa459e8[_0xe6d5('0x4d')]['referer'],'browserName':_0x1baac1[_0xe6d5('0xa5')][_0xe6d5('0x2c')]&&_0x1baac1[_0xe6d5('0xa5')]['version']?util[_0xe6d5('0xa6')](_0xe6d5('0xa7'),_0x1baac1[_0xe6d5('0xa5')]['name'],_0x1baac1[_0xe6d5('0xa5')]['version']):'unknown','browserVersion':_0x1baac1['browser'][_0xe6d5('0xa8')]||_0xe6d5('0xa9'),'osName':util[_0xe6d5('0xa6')](_0xe6d5('0xa7'),_0x1baac1['os'][_0xe6d5('0x2c')],_0x1baac1['os'][_0xe6d5('0xa8')]),'osVersion':_0x1baac1['os'][_0xe6d5('0xa8')],'deviceModel':_0x1baac1[_0xe6d5('0xaa')][_0xe6d5('0x37')]&&_0x1baac1[_0xe6d5('0xaa')][_0xe6d5('0xab')]?util[_0xe6d5('0xa6')](_0xe6d5('0xac'),_0x1baac1['device'][_0xe6d5('0x37')],_0x1baac1[_0xe6d5('0xaa')][_0xe6d5('0xab')],_0x1baac1[_0xe6d5('0xaa')][_0xe6d5('0x35')]):null,'deviceVendor':_0x1baac1[_0xe6d5('0xaa')][_0xe6d5('0xab')],'deviceType':_0x1baac1[_0xe6d5('0xaa')][_0xe6d5('0x35')],'formData':JSON[_0xe6d5('0x17')](_0xa459e8[_0xe6d5('0x4d')])};var _0x5ab6a2={'ChatWebsiteId':_0xa459e8['params']['id'],'closed':![]};if(_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xad')]){_0x5ab6a2['threadId']=_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xad')];return db[_0xe6d5('0xae')][_0xe6d5('0x4b')]({'where':_0x5ab6a2})[_0xe6d5('0x12')](function(_0xc8320f){if(_0xc8320f){return[_0xc8320f,![]];}_0x1343ba[_0xe6d5('0xad')]=_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xad')];_0x1343ba['externalUrl']=_0xa459e8[_0xe6d5('0x4d')]['externalUrl'];return db[_0xe6d5('0xae')][_0xe6d5('0x4c')](_0x1343ba)['then'](function(_0x3af1b1){return[_0x3af1b1,!![]];});});}_0x5ab6a2[_0xe6d5('0xaf')]=_0x5225ce['id'];if(_0xa459e8[_0xe6d5('0x4d')]['interaction']&&_0xa459e8['body']['interaction']['id']){_0x5ab6a2['id']=_0xa459e8['body']['interaction']['id'];return db[_0xe6d5('0xae')][_0xe6d5('0x4b')]({'where':_0x5ab6a2})['then'](function(_0x3585b5){if(_0x3585b5){return[_0x3585b5,![]];}return db['ChatInteraction']['create'](_0x1343ba)[_0xe6d5('0x12')](function(_0x40edab){return[_0x40edab,!![]];});});}return db['ChatInteraction'][_0xe6d5('0x4c')](_0x1343ba)[_0xe6d5('0x12')](function(_0x3c6248){return[_0x3c6248,!![]];});}})[_0xe6d5('0xb0')](function(_0x3eaa1d,_0x207f02){if(_0x3eaa1d){_0x344051=_0x207f02;if(!_0x207f02){var _0x2c2808={'from':(_0x142e0b[_0xe6d5('0xb1')][_0xe6d5('0xa2')]||'')+'\x20'+(_0x142e0b[_0xe6d5('0xb1')]['lastName']||'')};if(_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xad')]&&_0xa459e8['body'][_0xe6d5('0xb2')]&&_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xad')]!=_0xa459e8['body']['messageId']){_0x2c2808[_0xe6d5('0xad')]=_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xb2')];}return _0x3eaa1d[_0xe6d5('0x25')](_0x2c2808);}else{return _0x3eaa1d;}}})[_0xe6d5('0x12')](function(_0x389229){_0x142e0b[_0xe6d5('0xb3')]=_0x389229[_0xe6d5('0x27')]({'plain':!![]});_0x142e0b[_0xe6d5('0xb3')][_0xe6d5('0xb4')]=_0x344051;if(_0x142e0b['interaction'][_0xe6d5('0xb4')]){if(_0x142e0b['account'][_0xe6d5('0xb5')]){_0x142e0b[_0xe6d5('0x96')]['push']({'id':0x0,'priority':_0x142e0b['applications'][_0xe6d5('0x49')]+0x1,'app':_0xe6d5('0xb6'),'appdata':_0xe6d5('0xb7'),'interval':_0xe6d5('0xb8')});}}return db[_0xe6d5('0xb9')][_0xe6d5('0x4c')]({'body':_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0x4d')],'ChatWebsiteId':_0xa459e8['params']['id'],'ChatInteractionId':_0x389229['id'],'direction':'in','ContactId':_0x142e0b[_0xe6d5('0xb1')]['id'],'AttachmentId':_0xa459e8[_0xe6d5('0x4d')][_0xe6d5('0xba')]});})['then'](function(_0x2f28c8){_0x142e0b[_0xe6d5('0x19')]=_0x2f28c8;if(_0x142e0b[_0xe6d5('0xb3')]['UserId']){return db['User'][_0xe6d5('0x4b')]({'attributes':['id',_0xe6d5('0x2c')],'where':{'id':_0x142e0b[_0xe6d5('0xb3')][_0xe6d5('0xbb')]}})[_0xe6d5('0x12')](function(_0xda9ce){if(_0xda9ce){_0x142e0b[_0xe6d5('0x96')][_0xe6d5('0xbc')]({'id':0x0,'priority':0x0,'app':_0xe6d5('0xbd'),'appdata':_0xda9ce['name']+','+(_0x142e0b[_0xe6d5('0x95')][_0xe6d5('0xbe')]||0xa),'interval':'*,*,*,*'});_0x142e0b[_0xe6d5('0xbf')]=!![];}return respondWithRpcPromise('Start',_0xe6d5('0xc0'),_0x142e0b);});}return respondWithRpcPromise(_0xe6d5('0xc1'),_0xe6d5('0xc0'),_0x142e0b);})[_0xe6d5('0x12')](function(_0x3119a2){respondWithRpcPromise(_0xe6d5('0xc2'),_0xe6d5('0xc2'),{'event':_0xe6d5('0x7a'),'message':_0x3119a2},client9002);return _0x3119a2;})[_0xe6d5('0x12')](respondWithResult(_0x11ed51,null))[_0xe6d5('0x1b')](handleError(_0x11ed51,null));};exports[_0xe6d5('0xc3')]=function(_0x382273,_0x44b2ac){var _0x2afa44,_0x5a0731,_0x3afa7f;var _0x5bbb4c=[];var _0x559317={};var _0x3ec330=_0x382273[_0xe6d5('0xc4')]||[];var _0x53346d=[];var _0x59f592;return db[_0xe6d5('0x7f')][_0xe6d5('0x51')]()['then'](function(_0x21bfb6){if(!_0x21bfb6){throw new db[(_0xe6d5('0x88'))][(_0xe6d5('0x80'))](_0xe6d5('0x81'));}_0x5bbb4c=_[_0xe6d5('0x82')](_[_0xe6d5('0x39')](_0x21bfb6),[_0xe6d5('0x83'),'updatedAt','CompanyId',_0xe6d5('0x86')]);if(_0x382273[_0xe6d5('0x4d')]['id']){delete _0x382273[_0xe6d5('0x4d')]['id'];}if(_['isNil'](_0x382273[_0xe6d5('0x4d')]['from'])){throw _0x44b2ac[_0xe6d5('0x1c')](0x1f4)[_0xe6d5('0x2d')](new db[(_0xe6d5('0x88'))][(_0xe6d5('0x80'))]('from\x20is\x20mandatory'));}if(_[_0xe6d5('0x6d')](_0x382273[_0xe6d5('0x4d')]['body'])||_0x382273[_0xe6d5('0x4d')][_0xe6d5('0x4d')]===''){throw _0x44b2ac[_0xe6d5('0x1c')](0x1f4)[_0xe6d5('0x2d')](new db[(_0xe6d5('0x88'))]['ValidationError'](_0xe6d5('0x8a')));}if(_[_0xe6d5('0x6d')](_0x382273[_0xe6d5('0x4d')][_0xe6d5('0xc5')])){throw _0x44b2ac[_0xe6d5('0x1c')](0x1f4)['send'](new db[(_0xe6d5('0x88'))]['ValidationError']('mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5bbb4c));}if(!_['includes'](_0x5bbb4c,_0x382273[_0xe6d5('0x4d')]['mapKeyOffline'])){throw _0x44b2ac[_0xe6d5('0x1c')](0x1f4)[_0xe6d5('0x2d')](new db['Sequelize'][(_0xe6d5('0x80'))]('mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5bbb4c));}_0x559317[_0x382273['body']['mapKeyOffline']]=_0x382273[_0xe6d5('0x4d')][_0xe6d5('0x87')];})[_0xe6d5('0x12')](function(){return db['ChatWebsite'][_0xe6d5('0x4b')]({'where':{'id':_0x382273[_0xe6d5('0x48')]['id']},'include':[{'model':db[_0xe6d5('0x8f')],'as':'List'},{'model':db[_0xe6d5('0xc6')],'as':_0xe6d5('0xc6')}]});})[_0xe6d5('0x12')](handleEntityNotFound(_0x44b2ac,null))[_0xe6d5('0x12')](function(_0x5a81dc){if(_0x5a81dc&&_0x5a81dc['List']){_0x5a0731=_0x5a81dc;var _0x1222d7=_[_0xe6d5('0x9b')](_0x382273[_0xe6d5('0x4d')],{'firstName':_0x382273[_0xe6d5('0x4d')][_0xe6d5('0x87')],'phone':_0x382273['body'][_0xe6d5('0x87')],'ListId':_0x5a81dc[_0xe6d5('0x86')]});_0x1222d7[_0x382273['body'][_0xe6d5('0xc5')]]=_0x382273[_0xe6d5('0x4d')][_0xe6d5('0x87')];return db[_0xe6d5('0x7f')][_0xe6d5('0xc7')]({'where':_0x559317,'defaults':_0x1222d7});}})['spread'](function(_0x57efa2){if(_0x57efa2){_0x3afa7f=_0x57efa2;var _0x242cec=fs[_0xe6d5('0xc8')](path[_0xe6d5('0x70')](config[_0xe6d5('0x69')],_0xe6d5('0xc9')),_0xe6d5('0xca'));var _0x3700d4=ejs[_0xe6d5('0xcb')](_0x242cec,{'body':_[_0xe6d5('0xcc')](_0x382273['body'][_0xe6d5('0x4d')]),'bodyTitle':_0x5a0731[_0xe6d5('0xcd')]});return db[_0xe6d5('0xce')][_0xe6d5('0x4c')]({'body':_0x3700d4,'ContactId':_0x57efa2['id'],'ChatWebsiteId':_0x5a0731['id']});}})[_0xe6d5('0x12')](function(_0x4e975e){_0x59f592=_0x4e975e;if(_0x3ec330['length']){var _0x435de7=_0x3ec330[_0xe6d5('0x31')](function(_0x194221){return{'name':_0x194221[_0xe6d5('0xcf')],'basename':_0x194221['filename'],'type':_0x194221[_0xe6d5('0xd0')],'ChatOfflineMessageId':_0x4e975e['id']};});_0x53346d=_0x435de7[_0xe6d5('0x31')](_0x52a2a9=>{var _0x2862ed={'filename':_0x52a2a9[_0xe6d5('0x2c')],'path':path[_0xe6d5('0x70')](config[_0xe6d5('0x69')],_0xe6d5('0xd1'),_0xe6d5('0xc4'),_0xe6d5('0xd2'),_0xe6d5('0xd3'),_0x52a2a9[_0xe6d5('0xd4')])};return _0x2862ed;});if(!_0x5a0731[_0xe6d5('0xd5')]){return db['sequelize']['transaction'](function(_0x119ac8){return db[_0xe6d5('0xd6')][_0xe6d5('0xd7')](_0x435de7,{'transaction':_0x119ac8});});}}})[_0xe6d5('0x12')](function(){if(_0x59f592){_0x2afa44=_0x59f592;return db[_0xe6d5('0xc6')][_0xe6d5('0x56')]({'where':{'active':!![]},'include':[{'model':db['MailServerOut'],'as':_0xe6d5('0xd8'),'raw':!![]}]});}})[_0xe6d5('0x12')](function(_0xc9bd67){if(_0xc9bd67&&_0xc9bd67[_0xe6d5('0xd8')]&&_0x5a0731[_0xe6d5('0xd9')]&&_0x5a0731['forwardOfflineAddress']){var _0x268687={'tls':{'rejectUnauthorized':![]}};if(_0xc9bd67['Smtp']['service']){_0x268687[_0xe6d5('0xda')]=_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0xda')];}else{_0x268687[_0xe6d5('0xdb')]=_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0xdb')];_0x268687['port']=_0xc9bd67[_0xe6d5('0xd8')]['port'];_0x268687[_0xe6d5('0xdc')]=_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0xdc')];}if(_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0xdd')]){_0x268687[_0xe6d5('0xde')]={'user':_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0x4e')],'pass':_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0xdf')]};}return respondWithRpcPromise(_0xe6d5('0xe0'),_0xe6d5('0xe1'),{'account':_0x268687,'message':{'from':util[_0xe6d5('0xa6')](_0xe6d5('0xe2'),_0xc9bd67['name'],_0xc9bd67[_0xe6d5('0xe3')]||_0xc9bd67[_0xe6d5('0xd8')][_0xe6d5('0x4e')]),'to':_0x5a0731[_0xe6d5('0xe4')],'subject':_0x5a0731[_0xe6d5('0xe5')],'html':_0x2afa44[_0xe6d5('0x4d')],'attachments':_0x53346d}},client9003)[_0xe6d5('0x12')](function(){return _0x2afa44;})[_0xe6d5('0x1b')](function(_0x1ef33e){console[_0xe6d5('0x18')](_0x1ef33e);});}})[_0xe6d5('0x12')](function(){if(_0x5a0731&&_0x5a0731[_0xe6d5('0xd5')]&&_0x5a0731['MailAccountId']){var _0x189cb7=[];if(_0x3ec330[_0xe6d5('0x49')]){_0x189cb7=_0x3ec330[_0xe6d5('0x31')](function(_0x4c3487){return{'name':_0x4c3487[_0xe6d5('0xcf')],'basename':_0x4c3487[_0xe6d5('0x62')],'type':_0x4c3487[_0xe6d5('0xd0')],'ChatOfflineMessageId':_0x59f592['id']};});}var _0x2f010f;if(!_[_0xe6d5('0x6d')](_0x5a0731[_0xe6d5('0xe6')])){var _0x1bcfa3=_['map'](_0x382273[_0xe6d5('0x4d')],function(_0x1bfa28){return _0x1bfa28;});var _0x52c7ca=_[_0xe6d5('0xe7')](_0x1bcfa3)[0x0];var _0x508b14=_[_0xe6d5('0xe8')](_0x52c7ca,function(_0x5cf3e4){return _0x5cf3e4;});_0x2f010f=_0x508b14[0x1][_0x5a0731[_0xe6d5('0xe6')]];}var _0x28249a={'from':_0x3afa7f[_0xe6d5('0xe3')],'firstName':_0x3afa7f['firstName'],'lastName':_0x3afa7f['lastName'],'mapKey':'email','message':{'from':_0x3afa7f[_0xe6d5('0xe3')],'to':_0x5a0731[_0xe6d5('0xc6')]['email'],'cc':'','subject':_[_0xe6d5('0x6d')](_0x2f010f)?_0x5a0731[_0xe6d5('0xe5')]:_0x2f010f,'messageId':'','sentAt':new Date(),'attach':_0x189cb7['length'],'attachments':_0x189cb7,'originChannel':'Chat','ChatWebsiteId':_0x5a0731['id'],'ChatOfflineMessageId':_0x2afa44['id'],'originTo':_0x5a0731[_0xe6d5('0xc6')][_0xe6d5('0xe3')]},'body':_0x2afa44[_0xe6d5('0x4d')]};var _0x3df306={'account':{'id':_0x5a0731['MailAccountId']},'body':_0x28249a,'log':_0xe6d5('0xe9')};return respondWithRpcPromise(_0xe6d5('0xe9'),_0xe6d5('0xea'),_0x3df306,client9001)[_0xe6d5('0x12')](function(){return _0x2afa44;})[_0xe6d5('0x1b')](function(_0x360de2){console[_0xe6d5('0x18')](_0x360de2);});}return;})[_0xe6d5('0x12')](function(){if(_0x2afa44){return _0x2afa44;}})[_0xe6d5('0x12')](respondWithResult(_0x44b2ac,null))[_0xe6d5('0x1b')](function(_0x3fa56a){console['error'](_0xe6d5('0x1b'),_0x3fa56a);for(var _0x163ea2 of _0x3ec330){var _0x46a7e2=path['join'](config['root'],'server',_0xe6d5('0xc4'),_0xe6d5('0xd2'),_0xe6d5('0xd3'),_0x163ea2['filename']);fs_extra[_0xe6d5('0xeb')](_0x46a7e2)[_0xe6d5('0x1b')](function(_0x412658){console[_0xe6d5('0x18')](_0xe6d5('0xec'),_0x46a7e2,_0x412658);});}});};exports[_0xe6d5('0xed')]=function(_0x287821,_0x1059d8){return db[_0xe6d5('0xae')][_0xe6d5('0x4b')]({'where':{'id':_0x287821['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x1059d8,null))['then'](function(_0xf576c8){if(_0xf576c8){return _0xf576c8['addInteraction'](_0x287821[_0xe6d5('0x4d')][_0xe6d5('0x5b')],_[_0xe6d5('0xee')](_0x287821['body'],[_0xe6d5('0x5b'),'id'])||{});}})[_0xe6d5('0x12')](respondWithResult(_0x1059d8,null))[_0xe6d5('0x1b')](handleError(_0x1059d8,null));};exports[_0xe6d5('0xef')]=function(_0x4e37f0,_0x4a71a2){var _0xa93669={'raw':![],'where':{}};var _0x167930={};var _0x48e6d1={'count':0x0,'rows':[]};return db['ChatWebsite']['findOne']({'where':{'id':_0x4e37f0['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x4a71a2,null))[_0xe6d5('0x12')](function(_0x5cb442){if(_0x5cb442){_0x167930['model']=_['keys'](db[_0xe6d5('0xae')][_0xe6d5('0x33')]);_0x167930['query']=_['keys'](_0x4e37f0[_0xe6d5('0x38')]);_0x167930[_0xe6d5('0x3a')]=_[_0xe6d5('0x3b')](_0x167930[_0xe6d5('0x37')],_0x167930[_0xe6d5('0x38')]);_0xa93669[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x167930['model'],qs[_0xe6d5('0x3d')](_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0x3d')]));_0xa93669[_0xe6d5('0x3c')]=_0xa93669[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0xa93669['attributes']:_0x167930[_0xe6d5('0x37')];if(!_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0x3e')](_0xe6d5('0x57'))){_0xa93669[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0x20')]);_0xa93669['offset']=qs['offset'](_0x4e37f0[_0xe6d5('0x38')]['offset']);}_0xa93669[_0xe6d5('0x58')]=qs[_0xe6d5('0x3f')](_0x4e37f0[_0xe6d5('0x38')]['sort']);_0xa93669['where']=qs['filters'](_[_0xe6d5('0x41')](_0x4e37f0[_0xe6d5('0x38')],_0x167930[_0xe6d5('0x3a')]));_0xa93669[_0xe6d5('0x40')][_0xe6d5('0x53')]=_0x5cb442['id'];if(_0x4e37f0[_0xe6d5('0x38')]['filter']){_0xa93669[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0xa93669[_0xe6d5('0x40')],{'$or':_[_0xe6d5('0x31')](_0xa93669[_0xe6d5('0x3c')],function(_0x5a90a2){var _0x467de9={};_0x467de9[_0x5a90a2]={'$like':'%'+_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0x42')]+'%'};return _0x467de9;})});}_0xa93669=_[_0xe6d5('0x43')]({},_0xa93669,_0x4e37f0[_0xe6d5('0x44')]);return db[_0xe6d5('0xae')]['count']({'where':_0xa93669[_0xe6d5('0x40')]})[_0xe6d5('0x12')](function(_0xabcac7){_0x48e6d1['count']=_0xabcac7;if(_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0x4a')]){_0xa93669['include']=[{'model':db[_0xe6d5('0x7f')],'as':_0xe6d5('0xf0'),'required':![]},{'model':db[_0xe6d5('0xf1')],'as':_0xe6d5('0xf2'),'attributes':[_0xe6d5('0x2c'),'fullname',_0xe6d5('0xf3')],'required':![]},{'model':db[_0xe6d5('0xf4')],'as':_0xe6d5('0xf5'),'attributes':['id',_0xe6d5('0x2c'),'color'],'where':_0x4e37f0['query']['tag']?{'id':_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0xf6')]}:undefined,'required':_0x4e37f0[_0xe6d5('0x38')][_0xe6d5('0xf6')]?!![]:![]}];}return db[_0xe6d5('0xae')][_0xe6d5('0x59')](_0xa93669);})[_0xe6d5('0x12')](function(_0x36337d){_0x48e6d1['rows']=_0x36337d;return _0x48e6d1;});}})[_0xe6d5('0x12')](respondWithFilteredResult(_0x4a71a2,_0xa93669))[_0xe6d5('0x1b')](handleError(_0x4a71a2,null));};function iftimePromise(_0x2a501d,_0x48142a){return respondWithRpcPromise(_0xe6d5('0xf7'),_0xe6d5('0xf8'),{'command':_0x48142a[_0xe6d5('0xf9')]?util['format'](_0xe6d5('0xfa'),_0x2a501d[_0xe6d5('0xfb')],_0x48142a[_0xe6d5('0xf9')]):util[_0xe6d5('0xa6')](_0xe6d5('0xfc'),_0x2a501d[_0xe6d5('0xfb')])},client9002)['then'](function(_0x5dd782){var _0x42d4bc=_0x5dd782&&_0x5dd782[_0xe6d5('0xfd')](_0xe6d5('0xfe'))>=0x0?!![]:![];logger['info'](_0xe6d5('0xff'),_0x48142a['id'],_0x2a501d['id'],_0x2a501d[_0xe6d5('0xfb')],_0x42d4bc?_0xe6d5('0x100'):_0xe6d5('0x101'),_0x48142a['timezone']?_0x48142a[_0xe6d5('0xf9')]:_0xe6d5('0x102'));return _0x42d4bc;})[_0xe6d5('0x1b')](function(_0x4bff2c){logger[_0xe6d5('0x18')](_0xe6d5('0xff'),_0x48142a['id'],_0x2a501d['id'],_0x2a501d[_0xe6d5('0xfb')],util[_0xe6d5('0x103')](_0x4bff2c,{'showHidden':![],'depth':null}),_0x48142a[_0xe6d5('0xf9')]?_0x48142a[_0xe6d5('0xf9')]:_0xe6d5('0x102'));return![];});}exports['getSnippet']=function(_0xc134a6,_0xcaac11){var _0x4e6549=0x0;var _0x353942=0x0;var _0x7d2d79=![];var _0x41b535;var _0x53b53a;return db['ChatWebsite'][_0xe6d5('0x4b')]({'where':{'id':_0xc134a6[_0xe6d5('0x48')]['id']},'include':[{'model':db[_0xe6d5('0x104')],'as':_0xe6d5('0x104'),'include':[{'model':db[_0xe6d5('0x104')],'as':_0xe6d5('0x105'),'attributes':['id',_0xe6d5('0xfb')],'raw':!![]}]}]})[_0xe6d5('0x12')](handleEntityNotFound(_0xcaac11,null))[_0xe6d5('0x12')](function(_0xce13d2){if(_0xce13d2){_0x41b535=_0xce13d2;return _0xce13d2[_0xe6d5('0x106')]({'raw':!![]});}})[_0xe6d5('0x12')](function(_0x1c55e4){if(_0x41b535){if(_0x1c55e4){_0x53b53a=_0x1c55e4;}}return require('../../config/license/util')[_0xe6d5('0x6c')]();})['then'](function(_0x2774d7){if(_0x2774d7){_0x353942=_0x2774d7['virtual'];_0x7d2d79=_0x2774d7[_0xe6d5('0x107')];}})[_0xe6d5('0x12')](function(){return db[_0xe6d5('0xae')][_0xe6d5('0x21')]({'where':{'closed':![]}});})['then'](function(_0x1b9376){_0x4e6549=_0x1b9376;if(_0x353942&&_0x1b9376>_0x353942){return db[_0xe6d5('0x108')][_0xe6d5('0x56')]({'where':{'id':0x1}})[_0xe6d5('0x12')](function(_0x48556a){if(_0x48556a){_0x48556a[_0xe6d5('0x109')](_0xe6d5('0x10a'));}});}})[_0xe6d5('0x12')](function(){if(_0x41b535[_0xe6d5('0x104')]&&_0x41b535['Interval'][_0xe6d5('0x105')]){var _0x925f22=[];for(var _0xca2705=0x0;_0xca2705<_0x41b535['Interval']['Intervals']['length'];_0xca2705++){var _0x20e2a1=_0x41b535[_0xe6d5('0x104')][_0xe6d5('0x105')][_0xca2705]['get']({'plain':!![]});_0x925f22[_0xe6d5('0x10b')](iftimePromise(_0x20e2a1,_0x41b535));}return BPromise[_0xe6d5('0x10c')](_0x925f22)['then'](function(_0x83faf){return _['some'](_0x83faf);});}else{return!![];}})[_0xe6d5('0x12')](function(_0x1cf712){var _0x4b426f=fs[_0xe6d5('0xc8')](path['join'](config[_0xe6d5('0x69')],'server/files/chat/iframe.ejs'),_0xe6d5('0xca'));var _0x48cb34={'remote':_0x41b535[_0xe6d5('0x10d')],'query':querystring[_0xe6d5('0x17')](_[_0xe6d5('0x43')](_0x41b535[_0xe6d5('0x27')]({'plain':!![]}),{'customerIp':_0xc134a6[_0xe6d5('0x9e')][_0xe6d5('0x9f')]||_0xc134a6[_0xe6d5('0x9e')][_0xe6d5('0x10e')]||_0xc134a6['connection'][_0xe6d5('0x10f')]||_0xc134a6['ip'],'referer':_0xc134a6['headers'][_0xe6d5('0x110')],'openedInteractions':_0x4e6549,'maxInteractions':_0x353942,'virtual':_0x7d2d79[_0xe6d5('0x111')],'online':_0x1cf712,'custom':_0x7d2d79}))[_0xe6d5('0x112')](/'/g,'\x5c\x27')};_0xcaac11[_0xe6d5('0x2d')](ejs[_0xe6d5('0xcb')](Mustache[_0xe6d5('0xcb')](_0x4b426f,_0x48cb34),{'proactiveActions':_0x53b53a,'alignment':_0x41b535['alignment'],'verticalAlignment':_0x41b535[_0xe6d5('0x113')],'div_color':_0x41b535[_0xe6d5('0x114')],'text_color':_0x41b535[_0xe6d5('0x115')],'button_color':_0x41b535[_0xe6d5('0x116')],'background_color':_0x41b535[_0xe6d5('0x117')]}));})[_0xe6d5('0x1b')](handleError(_0xcaac11,null));};exports['addApplications']=function(_0x314d26,_0x112e36){var _0x3e5a2c=_0x314d26['params']['id'];var _0x1181dd=_0x314d26[_0xe6d5('0x4d')];var _0x37a533=0xc8;var _0x2df312=null;return db[_0xe6d5('0x118')][_0xe6d5('0x119')]({'isolationLevel':db[_0xe6d5('0x118')][_0xe6d5('0x11a')][_0xe6d5('0x11b')][_0xe6d5('0x11c')]},function(_0x4d5071){return db[_0xe6d5('0x32')][_0xe6d5('0x56')]({'where':{'id':_0x3e5a2c},'transaction':_0x4d5071})[_0xe6d5('0x12')](function(_0x641d0e){if(_0x641d0e){return db['ChatApplication']['destroy']({'where':{'ChatWebsiteId':_0x3e5a2c},'transaction':_0x4d5071})[_0xe6d5('0x12')](function(){var _0x523010=_[_0xe6d5('0x31')](_0x1181dd,function(_0x4c061e){_0x4c061e['ChatWebsiteId']=_0x3e5a2c;return _0x4c061e;});return db[_0xe6d5('0x93')][_0xe6d5('0xd7')](_0x523010,{'transaction':_0x4d5071});});}else{_0x37a533=0x194;_0x2df312=[];}});})[_0xe6d5('0x12')](function(){if(_0x37a533!==0x194){return db[_0xe6d5('0x93')][_0xe6d5('0x11d')]({'where':{'ChatWebsiteId':_0x3e5a2c},'order':_0xe6d5('0x99')})[_0xe6d5('0x12')](function(_0x10c334){_0x2df312=_0x10c334;});}})[_0xe6d5('0x1b')](function(_0x40b12b){_0x37a533=0x1f4;logger[_0xe6d5('0x18')](_0x40b12b[_0xe6d5('0x2b')]);if(_0x40b12b[_0xe6d5('0x2c')]){delete _0x40b12b[_0xe6d5('0x2c')];}_0x2df312=_0x40b12b;})['finally'](function(){if(_0x2df312===null){_0x112e36[_0xe6d5('0x2a')](_0x37a533);}else{if(_0x37a533===0x1f4){_0x112e36['status'](_0x37a533)[_0xe6d5('0x2d')](_0x2df312);}else{_0x112e36['status'](_0x37a533)[_0xe6d5('0x1e')](_0x2df312);}}});};exports['getApplications']=function(_0x532576,_0x2aeecc){var _0x9d6f43={};var _0x3c00b4={};var _0x37a0c6;var _0x110112;return db['ChatWebsite']['findOne']({'where':{'id':_0x532576['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x2aeecc,null))[_0xe6d5('0x12')](function(_0x5bdcfb){if(_0x5bdcfb){_0x37a0c6=_0x5bdcfb;_0x3c00b4['model']=_[_0xe6d5('0x39')](db['ChatApplication'][_0xe6d5('0x33')]);_0x3c00b4[_0xe6d5('0x38')]=_[_0xe6d5('0x39')](_0x532576['query']);_0x3c00b4['filters']=_[_0xe6d5('0x3b')](_0x3c00b4[_0xe6d5('0x37')],_0x3c00b4[_0xe6d5('0x38')]);_0x9d6f43['attributes']=_[_0xe6d5('0x3b')](_0x3c00b4[_0xe6d5('0x37')],qs['fields'](_0x532576[_0xe6d5('0x38')]['fields']));_0x9d6f43[_0xe6d5('0x3c')]=_0x9d6f43[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x9d6f43['attributes']:_0x3c00b4[_0xe6d5('0x37')];_0x9d6f43[_0xe6d5('0x58')]=qs[_0xe6d5('0x3f')](_0x532576[_0xe6d5('0x38')]['sort']);_0x9d6f43['where']=qs['filters'](_[_0xe6d5('0x41')](_0x532576[_0xe6d5('0x38')],_0x3c00b4[_0xe6d5('0x3a')]));if(_0x532576[_0xe6d5('0x38')][_0xe6d5('0x42')]){_0x9d6f43['where']=_[_0xe6d5('0x43')](_0x9d6f43[_0xe6d5('0x40')],{'$or':_[_0xe6d5('0x31')](_0x9d6f43[_0xe6d5('0x3c')],function(_0x35e75c){var _0x40008f={};_0x40008f[_0x35e75c]={'$like':'%'+_0x532576['query'][_0xe6d5('0x42')]+'%'};return _0x40008f;})});}_0x9d6f43=_[_0xe6d5('0x43')]({},_0x9d6f43,_0x532576['options']);return _0x37a0c6[_0xe6d5('0x11e')](_0x9d6f43);}})['then'](function(_0x5de5c3){if(_0x5de5c3){_0x110112=_0x5de5c3[_0xe6d5('0x49')];if(!_0x532576['query'][_0xe6d5('0x3e')]('nolimit')){_0x9d6f43[_0xe6d5('0x20')]=qs['limit'](_0x532576[_0xe6d5('0x38')][_0xe6d5('0x20')]);_0x9d6f43[_0xe6d5('0x22')]=qs['offset'](_0x532576['query'][_0xe6d5('0x22')]);}return _0x37a0c6[_0xe6d5('0x11e')](_0x9d6f43);}})['then'](function(_0x220ba4){if(_0x220ba4){return _0x220ba4?{'count':_0x110112,'rows':_0x220ba4}:null;}})[_0xe6d5('0x12')](respondWithResult(_0x2aeecc,null))[_0xe6d5('0x1b')](handleError(_0x2aeecc,null));};exports[_0xe6d5('0x11f')]=function(_0x1dc1b9,_0x33f79b){return db['chatProactiveAction'][_0xe6d5('0x4b')]({'where':{'id':_0x1dc1b9['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x33f79b,null))[_0xe6d5('0x12')](function(_0x5aae74){if(_0x5aae74){return _0x5aae74[_0xe6d5('0x11f')](_0x1dc1b9[_0xe6d5('0x4d')][_0xe6d5('0x5b')],_[_0xe6d5('0xee')](_0x1dc1b9[_0xe6d5('0x4d')],['ids','id'])||{});}})['then'](respondWithResult(_0x33f79b,null))[_0xe6d5('0x1b')](handleError(_0x33f79b,null));};exports[_0xe6d5('0x106')]=function(_0x51e8e0,_0x347941){var _0x44742c={};var _0x565d91={};var _0x1bbb12;var _0x1fb768;return db[_0xe6d5('0x32')][_0xe6d5('0x56')]({'where':{'id':_0x51e8e0[_0xe6d5('0x48')]['id']}})['then'](handleEntityNotFound(_0x347941,null))[_0xe6d5('0x12')](function(_0x16a757){if(_0x16a757){_0x1bbb12=_0x16a757;_0x565d91[_0xe6d5('0x37')]=_[_0xe6d5('0x39')](db[_0xe6d5('0x120')][_0xe6d5('0x33')]);_0x565d91[_0xe6d5('0x38')]=_[_0xe6d5('0x39')](_0x51e8e0[_0xe6d5('0x38')]);_0x565d91[_0xe6d5('0x3a')]=_[_0xe6d5('0x3b')](_0x565d91['model'],_0x565d91[_0xe6d5('0x38')]);_0x44742c[_0xe6d5('0x3c')]=_['intersection'](_0x565d91[_0xe6d5('0x37')],qs[_0xe6d5('0x3d')](_0x51e8e0[_0xe6d5('0x38')][_0xe6d5('0x3d')]));_0x44742c[_0xe6d5('0x3c')]=_0x44742c[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x44742c[_0xe6d5('0x3c')]:_0x565d91['model'];_0x44742c['order']=qs[_0xe6d5('0x3f')](_0x51e8e0[_0xe6d5('0x38')][_0xe6d5('0x3f')]);_0x44742c[_0xe6d5('0x40')]=qs[_0xe6d5('0x3a')](_[_0xe6d5('0x41')](_0x51e8e0[_0xe6d5('0x38')],_0x565d91[_0xe6d5('0x3a')]));if(_0x51e8e0[_0xe6d5('0x38')][_0xe6d5('0x42')]){_0x44742c[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0x44742c[_0xe6d5('0x40')],{'$or':_[_0xe6d5('0x31')](_0x44742c['attributes'],function(_0x5eb7d2){var _0x1cd8d9={};_0x1cd8d9[_0x5eb7d2]={'$like':'%'+_0x51e8e0[_0xe6d5('0x38')]['filter']+'%'};return _0x1cd8d9;})});}_0x44742c=_[_0xe6d5('0x43')]({},_0x44742c,_0x51e8e0[_0xe6d5('0x44')]);return _0x1bbb12[_0xe6d5('0x106')](_0x44742c);}})[_0xe6d5('0x12')](function(_0x2caac6){if(_0x2caac6){_0x1fb768=_0x2caac6['length'];if(!_0x51e8e0[_0xe6d5('0x38')]['hasOwnProperty'](_0xe6d5('0x57'))){_0x44742c[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x51e8e0['query'][_0xe6d5('0x20')]);_0x44742c['offset']=qs[_0xe6d5('0x22')](_0x51e8e0[_0xe6d5('0x38')][_0xe6d5('0x22')]);}return _0x1bbb12['getProactiveActions'](_0x44742c);}})[_0xe6d5('0x12')](function(_0x457986){if(_0x457986){return _0x457986?{'count':_0x1fb768,'rows':_0x457986}:null;}})['then'](respondWithResult(_0x347941,null))[_0xe6d5('0x1b')](handleError(_0x347941,null));};exports[_0xe6d5('0x121')]=function(_0x3dac80,_0x3e047b){var _0x4af1b7=_0x3dac80[_0xe6d5('0x38')][_0xe6d5('0x122')]==='false'?_0xe6d5('0x123'):_0xe6d5('0x124');return db[_0xe6d5('0x32')][_0xe6d5('0x4b')]({'attributes':['id',_0x4af1b7],'where':{'id':_0x3dac80['params']['id']}})['then'](handleEntityNotFound(_0x3e047b,null))[_0xe6d5('0x12')](function(_0x2d4387){if(_0x2d4387){var _0x4eef56=_0x2d4387[_0x4af1b7];var _0x2f01bd=_0x4eef56&&_0x4eef56[_0xe6d5('0x125')]?_0x4eef56[_0xe6d5('0x125')]:[];_0x3e047b[_0xe6d5('0x2d')]({'fromKey':_[_0xe6d5('0x6d')](_0x4eef56[_0xe6d5('0x126')])?undefined:_0x4eef56[_0xe6d5('0x126')],'count':_0x2f01bd[_0xe6d5('0x49')],'rows':_0x2f01bd});}})['catch'](handleError(_0x3e047b,null));};exports[_0xe6d5('0x127')]=function(_0x542886,_0x52a4f2){var _0x5032d5={'raw':![],'where':{}};var _0x4cf54b={};var _0x37f332={'count':0x0,'rows':[]};return db['ChatWebsite'][_0xe6d5('0x56')]({'where':{'id':_0x542886['params']['id']}})['then'](handleEntityNotFound(_0x52a4f2,null))[_0xe6d5('0x12')](function(_0x3de61e){if(_0x3de61e){_0x4cf54b[_0xe6d5('0x37')]=_[_0xe6d5('0x39')](db['ChatOfflineMessage'][_0xe6d5('0x33')]);_0x4cf54b['query']=_['keys'](_0x542886[_0xe6d5('0x38')]);_0x4cf54b['filters']=_[_0xe6d5('0x3b')](_0x4cf54b[_0xe6d5('0x37')],_0x4cf54b[_0xe6d5('0x38')]);_0x5032d5[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x4cf54b[_0xe6d5('0x37')],qs[_0xe6d5('0x3d')](_0x542886['query']['fields']));_0x5032d5[_0xe6d5('0x3c')]=_0x5032d5[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x5032d5['attributes']:_0x4cf54b['model'];if(!_0x542886[_0xe6d5('0x38')][_0xe6d5('0x3e')](_0xe6d5('0x57'))){_0x5032d5[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x542886[_0xe6d5('0x38')][_0xe6d5('0x20')]);_0x5032d5['offset']=qs[_0xe6d5('0x22')](_0x542886[_0xe6d5('0x38')]['offset']);}_0x5032d5['order']=qs[_0xe6d5('0x3f')](_0x542886[_0xe6d5('0x38')][_0xe6d5('0x3f')]);_0x5032d5[_0xe6d5('0x40')]=qs['filters'](_['pick'](_0x542886[_0xe6d5('0x38')],_0x4cf54b[_0xe6d5('0x3a')]));_0x5032d5[_0xe6d5('0x40')][_0xe6d5('0x53')]=_0x3de61e['id'];if(_0x542886['query']['filter']){_0x5032d5[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0x5032d5[_0xe6d5('0x40')],{'$or':_['map'](_0x5032d5[_0xe6d5('0x3c')],function(_0x4f1884){var _0x5d85b3={};_0x5d85b3[_0x4f1884]={'$like':'%'+_0x542886[_0xe6d5('0x38')][_0xe6d5('0x42')]+'%'};return _0x5d85b3;})});}_0x5032d5=_['merge']({},_0x5032d5,_0x542886[_0xe6d5('0x44')]);return db['ChatOfflineMessage'][_0xe6d5('0x21')]({'where':_0x5032d5[_0xe6d5('0x40')]})['then'](function(_0x59a39e){_0x37f332[_0xe6d5('0x21')]=_0x59a39e;if(_0x542886[_0xe6d5('0x38')][_0xe6d5('0x4a')]){_0x5032d5[_0xe6d5('0x45')]=[{'all':!![]}];}else{_0x5032d5[_0xe6d5('0x45')]=[{'model':db[_0xe6d5('0x7f')],'as':_0xe6d5('0xf0'),'required':![]},{'model':db['Attachment'],'as':_0xe6d5('0x128'),'required':![]}];}return db[_0xe6d5('0xce')]['findAll'](_0x5032d5);})[_0xe6d5('0x12')](function(_0x557c2b){_0x37f332[_0xe6d5('0x46')]=_0x557c2b;return _0x37f332;});}})[_0xe6d5('0x12')](respondWithFilteredResult(_0x52a4f2,_0x5032d5))['catch'](handleError(_0x52a4f2,null));};exports[_0xe6d5('0x129')]=function(_0x3cc878,_0x443401){return db[_0xe6d5('0x32')][_0xe6d5('0x4b')]({'where':{'id':_0x3cc878['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x443401,null))['then'](function(_0x30e12a){if(_0x30e12a){return _0x30e12a[_0xe6d5('0x129')](_0x3cc878[_0xe6d5('0x4d')][_0xe6d5('0x5b')],_[_0xe6d5('0xee')](_0x3cc878[_0xe6d5('0x4d')],['ids','id'])||{})[_0xe6d5('0xb0')](function(_0x5176f5){for(var _0x4a471e=0x0;_0x4a471e<_0x3cc878['body'][_0xe6d5('0x5b')]['length'];_0x4a471e+=0x1){socket['emit'](_0xe6d5('0x12a'),{'UserId':Number(_0x3cc878[_0xe6d5('0x4d')]['ids'][_0x4a471e]),'ChatWebsiteId':Number(_0x3cc878['params']['id'])});}return _0x5176f5;});}})[_0xe6d5('0x12')](respondWithResult(_0x443401,null))[_0xe6d5('0x1b')](handleError(_0x443401,null));};exports[_0xe6d5('0x12b')]=function(_0x2380be,_0x3017ad){return db['ChatWebsite'][_0xe6d5('0x4b')]({'where':{'id':_0x2380be[_0xe6d5('0x48')]['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x3017ad,null))[_0xe6d5('0x12')](function(_0x1d56c9){if(_0x1d56c9){return _0x1d56c9['removeAgents'](_0x2380be[_0xe6d5('0x38')]['ids'])['then'](function(){if(_['isArray'](_0x2380be[_0xe6d5('0x38')][_0xe6d5('0x5b')])){for(var _0x2344a4=0x0;_0x2344a4<_0x2380be[_0xe6d5('0x38')][_0xe6d5('0x5b')][_0xe6d5('0x49')];_0x2344a4+=0x1){socket[_0xe6d5('0x12c')](_0xe6d5('0x12d'),{'UserId':Number(_0x2380be[_0xe6d5('0x38')]['ids'][_0x2344a4]),'ChatWebsiteId':Number(_0x2380be[_0xe6d5('0x48')]['id'])});}}else{socket[_0xe6d5('0x12c')](_0xe6d5('0x12d'),{'UserId':Number(_0x2380be['query'][_0xe6d5('0x5b')]),'ChatWebsiteId':Number(_0x2380be['params']['id'])});}});}})['then'](respondWithStatusCode(_0x3017ad,null))[_0xe6d5('0x1b')](handleError(_0x3017ad,null));};exports['getAgents']=function(_0x142614,_0x364f6c){var _0x49cf06={};var _0x585ea5={};var _0x5558ff;var _0x2fe752;return db['ChatWebsite'][_0xe6d5('0x56')]({'where':{'id':_0x142614['params']['id']}})[_0xe6d5('0x12')](handleEntityNotFound(_0x364f6c,null))['then'](function(_0x577e55){if(_0x577e55){_0x5558ff=_0x577e55;_0x585ea5[_0xe6d5('0x37')]=_[_0xe6d5('0x39')](db['User'][_0xe6d5('0x33')]);_0x585ea5[_0xe6d5('0x38')]=_['keys'](_0x142614[_0xe6d5('0x38')]);_0x585ea5[_0xe6d5('0x3a')]=_[_0xe6d5('0x3b')](_0x585ea5['model'],_0x585ea5[_0xe6d5('0x38')]);_0x49cf06[_0xe6d5('0x3c')]=_[_0xe6d5('0x3b')](_0x585ea5[_0xe6d5('0x37')],qs[_0xe6d5('0x3d')](_0x142614[_0xe6d5('0x38')][_0xe6d5('0x3d')]));_0x49cf06[_0xe6d5('0x3c')]=_0x49cf06[_0xe6d5('0x3c')][_0xe6d5('0x49')]?_0x49cf06['attributes']:_0x585ea5[_0xe6d5('0x37')];_0x49cf06['order']=qs[_0xe6d5('0x3f')](_0x142614[_0xe6d5('0x38')][_0xe6d5('0x3f')]);_0x49cf06[_0xe6d5('0x40')]=qs[_0xe6d5('0x3a')](_[_0xe6d5('0x41')](_0x142614['query'],_0x585ea5['filters']));if(_0x142614[_0xe6d5('0x38')][_0xe6d5('0x42')]){_0x49cf06[_0xe6d5('0x40')]=_[_0xe6d5('0x43')](_0x49cf06[_0xe6d5('0x40')],{'$or':_['map'](_0x49cf06[_0xe6d5('0x3c')],function(_0x38fb0a){var _0x355d03={};_0x355d03[_0x38fb0a]={'$like':'%'+_0x142614[_0xe6d5('0x38')][_0xe6d5('0x42')]+'%'};return _0x355d03;})});}_0x49cf06=_['merge']({},_0x49cf06,_0x142614[_0xe6d5('0x44')]);return _0x5558ff[_0xe6d5('0x12e')](_0x49cf06);}})[_0xe6d5('0x12')](function(_0x4d9e8e){if(_0x4d9e8e){_0x2fe752=_0x4d9e8e['length'];if(!_0x142614[_0xe6d5('0x38')][_0xe6d5('0x3e')](_0xe6d5('0x57'))){_0x49cf06[_0xe6d5('0x20')]=qs[_0xe6d5('0x20')](_0x142614[_0xe6d5('0x38')][_0xe6d5('0x20')]);_0x49cf06['offset']=qs[_0xe6d5('0x22')](_0x142614[_0xe6d5('0x38')][_0xe6d5('0x22')]);}return _0x5558ff[_0xe6d5('0x12e')](_0x49cf06);}})[_0xe6d5('0x12')](function(_0x22de41){if(_0x22de41){return _0x22de41?{'count':_0x2fe752,'rows':_0x22de41}:null;}})[_0xe6d5('0x12')](respondWithResult(_0x364f6c,null))[_0xe6d5('0x1b')](handleError(_0x364f6c,null));};