Built motion from commit (unavailable).|2.4.21
[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 _0x5b83=['format','%s\x20%s','unknown','device','vendor','%s\x20%s\x20%s','stringify','threadId','externalUrl','ChatInteraction','ContactId','interaction','spread','messageId','created','push','unmanaged','*,*,*,*','AttachmentId','User','UserId','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','offline','no\x20available\x20attributes','send','mapKeyOffline','mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','findOrCreate','readFileSync','server/files/templates/chatOfflineMessage.ejs','utf8','render','toPairs','offlineMessageBody','ChatOfflineMessage','MailAccount','Smtp','service','port','secure','SendMail','sendMail','forwardOfflineAddress','offlineMessageSubject','addInteraction','omit','getInteractions','Owner','fullname','Tag','Tags','color','tag','Command','getSnippet','timezone','iftime\x20%s','interval','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','inspect','No\x20timezone','Interval','getProactiveActions','License','increment','chatLicenseExceeded','Intervals','remote','x-real-ip','connection','remoteAddress','virtual','replace','verticalAlignment','textColor','sequelize','transaction','bulkCreate','findAndCountAll','getApplications','addProactiveActions','chatProactiveAction','ChatProactiveAction','getFields','false','offlineForm','onlineForm','items','getOfflineMessages','Contact','addAgents','emit','userChatWebsite:save','removeAgents','isArray','userChatWebsite:remove','getAgents','eml-format','zip-dir','fast-json-patch','request-promise','mustache','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../mysqldb','redis','defaults','socket.io-emitter','./chatWebsite.socket','register','jayson/promise','client','http','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','debug','request\x20sent','error','code','ChatWebsite,\x20%s,\x20%s','message','info','result','catch','sendStatus','status','json','count','offset','limit','set','apply','reject','update','destroy','UserProfileResource','name','index','Pause','mandatoryDispositionPause','map','ChatWebsite','rawAttributes','fieldName','type','query','keys','filters','model','attributes','intersection','fields','length','nolimit','order','sort','pick','filter','merge','options','where','includeAll','findAll','rows','show','params','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','ChatWebsites','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','ChatWebsiteId','Disposition','getDispositions','findOne','hasOwnProperty','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addLogo','file','filename','addAvatar','addCustomerAvatar','customerAvatar','systemAvatar','getLogo','join','root','server/files/images/logos/default_logo.png','../../config/license/util','getLicense','custom','isNil','sitepic','existsSync','server/files/images/logos/','getAvatar','agentAvatar','server/files/images/avatars/','download','showCustomerAvatar','getSystemAvatar','setUA','headers','user-agent','getResult','chat','ValidationError','createdAt','updatedAt','difference','CompanyId','ListId','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','CmContact','Contacts','DESC','ChatApplication','account','Applications','list','applications','orderBy','priority','asc','contact','customerIp','cf-connecting-ip','x-forwarded-for','first','split','firstName','lastName','x-real-port','referer','browser','version'];(function(_0x47764b,_0x3bf238){var _0x10d86e=function(_0x51a5a1){while(--_0x51a5a1){_0x47764b['push'](_0x47764b['shift']());}};_0x10d86e(++_0x3bf238);}(_0x5b83,0x17f));var _0x35b8=function(_0x4453a9,_0x20efe2){_0x4453a9=_0x4453a9-0x0;var _0x5a300a=_0x5b83[_0x4453a9];return _0x5a300a;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x35b8('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x35b8('0x1'));var jsonpatch=require(_0x35b8('0x2'));var rp=require(_0x35b8('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x35b8('0x4'));var util=require('util');var path=require(_0x35b8('0x5'));var sox=require('sox');var csv=require(_0x35b8('0x6'));var ejs=require(_0x35b8('0x7'));var fs=require('fs');var _=require(_0x35b8('0x8'));var squel=require('squel');var crypto=require(_0x35b8('0x9'));var jsforce=require(_0x35b8('0xa'));var deskjs=require(_0x35b8('0xb'));var toCsv=require(_0x35b8('0x6'));var querystring=require(_0x35b8('0xc'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x35b8('0xd'));var qs=require(_0x35b8('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x35b8('0xf'));var logger=require(_0x35b8('0x10'))(_0x35b8('0x11'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x35b8('0x12'))['db'];config[_0x35b8('0x13')]=_[_0x35b8('0x14')](config[_0x35b8('0x13')],{'host':'localhost','port':0x18eb});var socket=require(_0x35b8('0x15'))(new Redis(config['redis']));require(_0x35b8('0x16'))[_0x35b8('0x17')](socket);var jayson=require(_0x35b8('0x18'));var client=jayson[_0x35b8('0x19')][_0x35b8('0x1a')]({'port':0x232c});var client9002=jayson[_0x35b8('0x19')][_0x35b8('0x1a')]({'port':0x232a});var client9003=jayson[_0x35b8('0x19')][_0x35b8('0x1a')]({'port':0x232b});function checkPasswordPattern(_0xc1a6dd,_0x5a1c40,_0x2b2c50){if(_0x2b2c50){var _0x58f7a2=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x58f7a2['test'](_0x5a1c40)){return _0xc1a6dd;}else{throw new db[(_0x35b8('0x1b'))]['ValidationError'](_0x35b8('0x1c'));}}else{return _0xc1a6dd;}}function respondWithRpcPromise(_0x312f8c,_0x3800bd,_0x44fe62,_0x1a835d){return new BPromise(function(_0x27214a,_0x5378e4){var _0x2839d1=_0x1a835d||client;return _0x2839d1[_0x35b8('0x1d')](_0x312f8c,_0x44fe62)[_0x35b8('0x1e')](function(_0xec5be6){logger['info']('ChatWebsite,\x20%s,\x20%s',_0x3800bd,'request\x20sent');logger[_0x35b8('0x1f')]('ChatWebsite,\x20%s,\x20%s,\x20%s',_0x3800bd,_0x35b8('0x20'),JSON['stringify'](_0xec5be6));if(_0xec5be6[_0x35b8('0x21')]){if(_0xec5be6[_0x35b8('0x21')][_0x35b8('0x22')]===0x1f4){logger[_0x35b8('0x21')](_0x35b8('0x23'),_0x3800bd,_0xec5be6[_0x35b8('0x21')][_0x35b8('0x24')]);return _0x5378e4(_0xec5be6[_0x35b8('0x21')]['message']);}logger['error'](_0x35b8('0x23'),_0x3800bd,_0xec5be6[_0x35b8('0x21')][_0x35b8('0x24')]);return _0x27214a(_0xec5be6[_0x35b8('0x21')][_0x35b8('0x24')]);}else{logger[_0x35b8('0x25')](_0x35b8('0x23'),_0x3800bd,'request\x20sent');_0x27214a(_0xec5be6[_0x35b8('0x26')][_0x35b8('0x24')]);}})[_0x35b8('0x27')](function(_0x813b73){logger[_0x35b8('0x21')](_0x35b8('0x23'),_0x3800bd,_0x813b73);_0x5378e4(_0x813b73);});});}function respondWithStatusCode(_0x297b19,_0x368355){_0x368355=_0x368355||0xcc;return function(_0x745f02){if(_0x745f02){return _0x297b19[_0x35b8('0x28')](_0x368355);}return _0x297b19['status'](_0x368355)['end']();};}function respondWithResult(_0x51fdd4,_0x434adc){_0x434adc=_0x434adc||0xc8;return function(_0x4cd3b2){if(_0x4cd3b2){return _0x51fdd4[_0x35b8('0x29')](_0x434adc)[_0x35b8('0x2a')](_0x4cd3b2);}};}function respondWithFilteredResult(_0xbdeab7,_0x2b55c2){return function(_0x5b74f7){if(_0x5b74f7){var _0x272cd9=_0x5b74f7[_0x35b8('0x2b')],_0x375dd7=_0x2b55c2['offset'],_0x4931fb=_0x2b55c2[_0x35b8('0x2c')]+_0x2b55c2[_0x35b8('0x2d')],_0x4011d3;if(_0x4931fb>=_0x272cd9){_0x4931fb=_0x272cd9;_0x4011d3=0xc8;}else{_0x4011d3=0xce;}_0xbdeab7[_0x35b8('0x29')](_0x4011d3);return _0xbdeab7[_0x35b8('0x2e')]('Content-Range',_0x375dd7+'-'+_0x4931fb+'/'+_0x272cd9)[_0x35b8('0x2a')](_0x5b74f7);}return null;};}function patchUpdates(_0x12c27b){return function(_0x34012e){try{jsonpatch[_0x35b8('0x2f')](_0x34012e,_0x12c27b,!![]);}catch(_0x2e76a9){return BPromise[_0x35b8('0x30')](_0x2e76a9);}return _0x34012e['save']();};}function saveUpdates(_0x54bcc3,_0x1ea8fc){return function(_0x408b8d){if(_0x408b8d){return _0x408b8d[_0x35b8('0x31')](_0x54bcc3)[_0x35b8('0x1e')](function(_0x28c23c){return _0x28c23c;});}return null;};}function removeEntity(_0xfd262e,_0x48dd5d){return function(_0x1fba61){if(_0x1fba61){return _0x1fba61[_0x35b8('0x32')]()[_0x35b8('0x1e')](function(){var _0x324f52=_0x1fba61['get']({'plain':!![]});var _0x3c055c='ChatWebsites';return db[_0x35b8('0x33')][_0x35b8('0x32')]({'where':{'type':_0x3c055c,'resourceId':_0x324f52['id']}})[_0x35b8('0x1e')](function(){return _0x1fba61;});})['then'](function(){_0xfd262e[_0x35b8('0x29')](0xcc)['end']();});}};}function handleEntityNotFound(_0x10968e,_0x49af9b){return function(_0x3c2aca){if(!_0x3c2aca){_0x10968e[_0x35b8('0x28')](0x194);}return _0x3c2aca;};}function handleError(_0x38c6d5,_0x523944){_0x523944=_0x523944||0x1f4;return function(_0x2dede1){logger['error'](_0x2dede1['stack']);if(_0x2dede1[_0x35b8('0x34')]){delete _0x2dede1[_0x35b8('0x34')];}_0x38c6d5[_0x35b8('0x29')](_0x523944)['send'](_0x2dede1);};}exports[_0x35b8('0x35')]=function(_0x10898d,_0x4fd1d4){var _0x2527b4={'include':[{'model':db[_0x35b8('0x36')],'as':_0x35b8('0x37')}]},_0x4f1248={},_0xa0f06c={'count':0x0,'rows':[]};var _0x33e0ca=_[_0x35b8('0x38')](db[_0x35b8('0x39')][_0x35b8('0x3a')],function(_0x22a1c5){return{'name':_0x22a1c5[_0x35b8('0x3b')],'type':_0x22a1c5[_0x35b8('0x3c')]['key']};});_0x4f1248['model']=_[_0x35b8('0x38')](_0x33e0ca,'name');_0x4f1248[_0x35b8('0x3d')]=_[_0x35b8('0x3e')](_0x10898d[_0x35b8('0x3d')]);_0x4f1248[_0x35b8('0x3f')]=_['intersection'](_0x4f1248[_0x35b8('0x40')],_0x4f1248[_0x35b8('0x3d')]);_0x2527b4[_0x35b8('0x41')]=_[_0x35b8('0x42')](_0x4f1248[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0x10898d[_0x35b8('0x3d')][_0x35b8('0x43')]));_0x2527b4[_0x35b8('0x41')]=_0x2527b4[_0x35b8('0x41')][_0x35b8('0x44')]?_0x2527b4['attributes']:_0x4f1248['model'];if(!_0x10898d[_0x35b8('0x3d')]['hasOwnProperty'](_0x35b8('0x45'))){_0x2527b4['limit']=qs[_0x35b8('0x2d')](_0x10898d[_0x35b8('0x3d')][_0x35b8('0x2d')]);_0x2527b4[_0x35b8('0x2c')]=qs[_0x35b8('0x2c')](_0x10898d[_0x35b8('0x3d')][_0x35b8('0x2c')]);}_0x2527b4[_0x35b8('0x46')]=qs[_0x35b8('0x47')](_0x10898d[_0x35b8('0x3d')][_0x35b8('0x47')]);_0x2527b4['where']=qs[_0x35b8('0x3f')](_[_0x35b8('0x48')](_0x10898d[_0x35b8('0x3d')],_0x4f1248[_0x35b8('0x3f')]));if(_0x10898d[_0x35b8('0x3d')]['filter']){_0x2527b4['where']=_['merge'](_0x2527b4['where'],{'$or':_['map'](_0x33e0ca,function(_0xee87ff){if(_0xee87ff[_0x35b8('0x3c')]!=='VIRTUAL'){var _0x430fa3={};_0x430fa3[_0xee87ff[_0x35b8('0x34')]]={'$like':'%'+_0x10898d[_0x35b8('0x3d')][_0x35b8('0x49')]+'%'};return _0x430fa3;}})});}_0x2527b4=_[_0x35b8('0x4a')]({},_0x2527b4,_0x10898d[_0x35b8('0x4b')]);var _0x52e64a={'where':_0x2527b4[_0x35b8('0x4c')]};return db['ChatWebsite'][_0x35b8('0x2b')](_0x52e64a)['then'](function(_0x29cca1){_0xa0f06c[_0x35b8('0x2b')]=_0x29cca1;if(_0x10898d[_0x35b8('0x3d')][_0x35b8('0x4d')]){_0x2527b4['include']=[{'all':!![]}];}return db['ChatWebsite'][_0x35b8('0x4e')](_0x2527b4);})[_0x35b8('0x1e')](function(_0x47f461){_0xa0f06c[_0x35b8('0x4f')]=_0x47f461;return _0xa0f06c;})[_0x35b8('0x1e')](respondWithFilteredResult(_0x4fd1d4,_0x2527b4))[_0x35b8('0x27')](handleError(_0x4fd1d4,null));};exports[_0x35b8('0x50')]=function(_0x5e1091,_0x17387b){var _0x4ea29b={'raw':![],'where':{'id':_0x5e1091[_0x35b8('0x51')]['id']},'include':[{'model':db[_0x35b8('0x36')],'as':_0x35b8('0x37')}]},_0x2e4ab2={};_0x2e4ab2[_0x35b8('0x40')]=_[_0x35b8('0x3e')](db[_0x35b8('0x39')][_0x35b8('0x3a')]);_0x2e4ab2['query']=_[_0x35b8('0x3e')](_0x5e1091[_0x35b8('0x3d')]);_0x2e4ab2[_0x35b8('0x3f')]=_[_0x35b8('0x42')](_0x2e4ab2['model'],_0x2e4ab2['query']);_0x4ea29b[_0x35b8('0x41')]=_['intersection'](_0x2e4ab2[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0x5e1091[_0x35b8('0x3d')][_0x35b8('0x43')]));_0x4ea29b[_0x35b8('0x41')]=_0x4ea29b[_0x35b8('0x41')]['length']?_0x4ea29b[_0x35b8('0x41')]:_0x2e4ab2['model'];if(_0x5e1091[_0x35b8('0x3d')][_0x35b8('0x4d')]){_0x4ea29b[_0x35b8('0x52')]=[{'all':!![]}];}_0x4ea29b=_['merge']({},_0x4ea29b,_0x5e1091[_0x35b8('0x4b')]);return db[_0x35b8('0x39')][_0x35b8('0x53')](_0x4ea29b)['then'](handleEntityNotFound(_0x17387b,null))[_0x35b8('0x1e')](respondWithResult(_0x17387b,null))[_0x35b8('0x27')](handleError(_0x17387b,null));};exports['create']=function(_0x5d110,_0x10562f){return db['ChatWebsite'][_0x35b8('0x54')](_0x5d110[_0x35b8('0x55')],{})[_0x35b8('0x1e')](function(_0xd1ff17){var _0x9e5c90=_0x5d110[_0x35b8('0x56')]['get']({'plain':!![]});if(!_0x9e5c90)throw new Error(_0x35b8('0x57'));if(_0x9e5c90[_0x35b8('0x58')]===_0x35b8('0x56')){var _0x502fb5=_0xd1ff17[_0x35b8('0x59')]({'plain':!![]});var _0x45cb74=_0x35b8('0x5a');return db[_0x35b8('0x5b')][_0x35b8('0x53')]({'where':{'name':_0x45cb74,'userProfileId':_0x9e5c90[_0x35b8('0x5c')]},'raw':!![]})[_0x35b8('0x1e')](function(_0x38c285){if(_0x38c285&&_0x38c285[_0x35b8('0x5d')]===0x0){return db[_0x35b8('0x33')][_0x35b8('0x54')]({'name':_0x502fb5[_0x35b8('0x34')],'resourceId':_0x502fb5['id'],'type':_0x38c285[_0x35b8('0x34')],'sectionId':_0x38c285['id']},{})[_0x35b8('0x1e')](function(){return _0xd1ff17;});}else{return _0xd1ff17;}})['catch'](function(_0x203573){logger[_0x35b8('0x21')](_0x35b8('0x5e'),_0x203573);throw _0x203573;});}return _0xd1ff17;})[_0x35b8('0x1e')](respondWithResult(_0x10562f,0xc9))[_0x35b8('0x27')](handleError(_0x10562f,null));};exports[_0x35b8('0x31')]=function(_0x237ba2,_0x186e73){if(_0x237ba2['body']['id']){delete _0x237ba2[_0x35b8('0x55')]['id'];}return db[_0x35b8('0x39')]['find']({'where':{'id':_0x237ba2[_0x35b8('0x51')]['id']},'include':[{'model':db[_0x35b8('0x36')],'as':_0x35b8('0x37')}]})[_0x35b8('0x1e')](handleEntityNotFound(_0x186e73,null))[_0x35b8('0x1e')](saveUpdates(_0x237ba2[_0x35b8('0x55')],null))[_0x35b8('0x1e')](respondWithResult(_0x186e73,null))[_0x35b8('0x27')](handleError(_0x186e73,null));};exports[_0x35b8('0x32')]=function(_0x39e6e3,_0x1bc2e6){return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x39e6e3[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x1bc2e6,null))['then'](removeEntity(_0x1bc2e6,null))[_0x35b8('0x27')](handleError(_0x1bc2e6,null));};exports[_0x35b8('0x5f')]=function(_0x889dd2,_0x380763){return db['ChatWebsite'][_0x35b8('0x5f')]()[_0x35b8('0x1e')](respondWithResult(_0x380763,null))[_0x35b8('0x27')](handleError(_0x380763,null));};exports['addDisposition']=function(_0x40bf83,_0x2cc253,_0x295589){if(_0x40bf83[_0x35b8('0x55')]['id']){delete _0x40bf83['body']['id'];}return db[_0x35b8('0x39')]['find']({'where':{'id':_0x40bf83[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x2cc253,null))['then'](function(_0x4140dc){if(_0x4140dc){_0x40bf83[_0x35b8('0x55')][_0x35b8('0x60')]=_0x4140dc['id'];return db[_0x35b8('0x61')][_0x35b8('0x54')](_0x40bf83[_0x35b8('0x55')]);}})[_0x35b8('0x1e')](respondWithResult(_0x2cc253,null))['catch'](handleError(_0x2cc253,null));};exports[_0x35b8('0x62')]=function(_0x17cdf7,_0x59ec95,_0xebbe89){var _0x51e5d1={'raw':![],'where':{}};var _0x108f4c={};var _0x520e3e={'count':0x0,'rows':[]};return db[_0x35b8('0x39')][_0x35b8('0x63')]({'where':{'id':_0x17cdf7[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x59ec95,null))[_0x35b8('0x1e')](function(_0x36a3ae){if(_0x36a3ae){_0x108f4c[_0x35b8('0x40')]=_[_0x35b8('0x3e')](db['Disposition'][_0x35b8('0x3a')]);_0x108f4c['query']=_[_0x35b8('0x3e')](_0x17cdf7[_0x35b8('0x3d')]);_0x108f4c[_0x35b8('0x3f')]=_['intersection'](_0x108f4c[_0x35b8('0x40')],_0x108f4c[_0x35b8('0x3d')]);_0x51e5d1[_0x35b8('0x41')]=_['intersection'](_0x108f4c[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0x17cdf7[_0x35b8('0x3d')][_0x35b8('0x43')]));_0x51e5d1[_0x35b8('0x41')]=_0x51e5d1['attributes'][_0x35b8('0x44')]?_0x51e5d1['attributes']:_0x108f4c['model'];if(!_0x17cdf7[_0x35b8('0x3d')][_0x35b8('0x64')](_0x35b8('0x45'))){_0x51e5d1[_0x35b8('0x2d')]=qs[_0x35b8('0x2d')](_0x17cdf7[_0x35b8('0x3d')][_0x35b8('0x2d')]);_0x51e5d1[_0x35b8('0x2c')]=qs[_0x35b8('0x2c')](_0x17cdf7[_0x35b8('0x3d')][_0x35b8('0x2c')]);}_0x51e5d1[_0x35b8('0x46')]=qs['sort'](_0x17cdf7[_0x35b8('0x3d')]['sort']);_0x51e5d1['where']=qs[_0x35b8('0x3f')](_[_0x35b8('0x48')](_0x17cdf7['query'],_0x108f4c['filters']));_0x51e5d1[_0x35b8('0x4c')]['ChatWebsiteId']=_0x36a3ae['id'];if(_0x17cdf7[_0x35b8('0x3d')]['filter']){_0x51e5d1[_0x35b8('0x4c')]=_[_0x35b8('0x4a')](_0x51e5d1[_0x35b8('0x4c')],{'$or':_[_0x35b8('0x38')](_0x51e5d1[_0x35b8('0x41')],function(_0x44c20f){var _0x89bb12={};_0x89bb12[_0x44c20f]={'$like':'%'+_0x17cdf7[_0x35b8('0x3d')]['filter']+'%'};return _0x89bb12;})});}_0x51e5d1=_['merge']({},_0x51e5d1,_0x17cdf7[_0x35b8('0x4b')]);return db[_0x35b8('0x61')][_0x35b8('0x2b')]({'where':_0x51e5d1['where']})[_0x35b8('0x1e')](function(_0x448375){_0x520e3e[_0x35b8('0x2b')]=_0x448375;if(_0x17cdf7[_0x35b8('0x3d')]['includeAll']){_0x51e5d1[_0x35b8('0x52')]=[{'all':!![]}];}return db[_0x35b8('0x61')]['findAll'](_0x51e5d1);})[_0x35b8('0x1e')](function(_0xbecda0){_0x520e3e[_0x35b8('0x4f')]=_0xbecda0;return _0x520e3e;});}})[_0x35b8('0x1e')](respondWithFilteredResult(_0x59ec95,_0x51e5d1))[_0x35b8('0x27')](handleError(_0x59ec95,null));};exports[_0x35b8('0x65')]=function(_0x22d10f,_0xea9598,_0x56ce80){return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x22d10f['params']['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0xea9598,null))['then'](function(_0xe4e805){if(_0xe4e805){return _0xe4e805[_0x35b8('0x65')](_0x22d10f[_0x35b8('0x3d')][_0x35b8('0x66')]);}})['then'](respondWithStatusCode(_0xea9598,null))[_0x35b8('0x27')](handleError(_0xea9598,null));};exports[_0x35b8('0x67')]=function(_0x415332,_0x118ed3,_0x431589){if(_0x415332[_0x35b8('0x55')]['id']){delete _0x415332[_0x35b8('0x55')]['id'];}return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x415332[_0x35b8('0x51')]['id']}})['then'](handleEntityNotFound(_0x118ed3,null))[_0x35b8('0x1e')](function(_0x3c1c2b){if(_0x3c1c2b){_0x415332[_0x35b8('0x55')]['ChatWebsiteId']=_0x3c1c2b['id'];return db[_0x35b8('0x68')]['create'](_0x415332[_0x35b8('0x55')]);}})['then'](respondWithResult(_0x118ed3,null))[_0x35b8('0x27')](handleError(_0x118ed3,null));};exports[_0x35b8('0x69')]=function(_0x44aaf8,_0x22de5c,_0x2b2208){var _0x516aef={'raw':![],'where':{}};var _0x237581={};var _0x48f078={'count':0x0,'rows':[]};return db[_0x35b8('0x39')]['findOne']({'where':{'id':_0x44aaf8[_0x35b8('0x51')]['id']}})['then'](handleEntityNotFound(_0x22de5c,null))[_0x35b8('0x1e')](function(_0x164be4){if(_0x164be4){_0x237581[_0x35b8('0x40')]=_[_0x35b8('0x3e')](db['CannedAnswer']['rawAttributes']);_0x237581[_0x35b8('0x3d')]=_[_0x35b8('0x3e')](_0x44aaf8[_0x35b8('0x3d')]);_0x237581[_0x35b8('0x3f')]=_['intersection'](_0x237581[_0x35b8('0x40')],_0x237581[_0x35b8('0x3d')]);_0x516aef[_0x35b8('0x41')]=_[_0x35b8('0x42')](_0x237581[_0x35b8('0x40')],qs['fields'](_0x44aaf8[_0x35b8('0x3d')][_0x35b8('0x43')]));_0x516aef['attributes']=_0x516aef[_0x35b8('0x41')][_0x35b8('0x44')]?_0x516aef['attributes']:_0x237581['model'];if(!_0x44aaf8[_0x35b8('0x3d')][_0x35b8('0x64')](_0x35b8('0x45'))){_0x516aef[_0x35b8('0x2d')]=qs[_0x35b8('0x2d')](_0x44aaf8[_0x35b8('0x3d')][_0x35b8('0x2d')]);_0x516aef[_0x35b8('0x2c')]=qs[_0x35b8('0x2c')](_0x44aaf8['query'][_0x35b8('0x2c')]);}_0x516aef[_0x35b8('0x46')]=qs['sort'](_0x44aaf8['query'][_0x35b8('0x47')]);_0x516aef['where']=qs['filters'](_[_0x35b8('0x48')](_0x44aaf8[_0x35b8('0x3d')],_0x237581[_0x35b8('0x3f')]));_0x516aef[_0x35b8('0x4c')][_0x35b8('0x60')]=_0x164be4['id'];if(_0x44aaf8['query'][_0x35b8('0x49')]){_0x516aef[_0x35b8('0x4c')]=_[_0x35b8('0x4a')](_0x516aef[_0x35b8('0x4c')],{'$or':_['map'](_0x516aef['attributes'],function(_0x55df0c){var _0x2a830c={};_0x2a830c[_0x55df0c]={'$like':'%'+_0x44aaf8[_0x35b8('0x3d')][_0x35b8('0x49')]+'%'};return _0x2a830c;})});}_0x516aef=_[_0x35b8('0x4a')]({},_0x516aef,_0x44aaf8[_0x35b8('0x4b')]);return db[_0x35b8('0x68')][_0x35b8('0x2b')]({'where':_0x516aef[_0x35b8('0x4c')]})['then'](function(_0x1bd0f0){_0x48f078[_0x35b8('0x2b')]=_0x1bd0f0;if(_0x44aaf8[_0x35b8('0x3d')]['includeAll']){_0x516aef[_0x35b8('0x52')]=[{'all':!![]}];}return db['CannedAnswer'][_0x35b8('0x4e')](_0x516aef);})[_0x35b8('0x1e')](function(_0x4e0486){_0x48f078['rows']=_0x4e0486;return _0x48f078;});}})[_0x35b8('0x1e')](respondWithFilteredResult(_0x22de5c,_0x516aef))[_0x35b8('0x27')](handleError(_0x22de5c,null));};exports[_0x35b8('0x6a')]=function(_0x580a27,_0xe007a4,_0x443e38){return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x580a27[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0xe007a4,null))['then'](function(_0x396cef){if(_0x396cef){return _0x396cef[_0x35b8('0x6a')](_0x580a27[_0x35b8('0x3d')][_0x35b8('0x66')]);}})[_0x35b8('0x1e')](respondWithStatusCode(_0xe007a4,null))[_0x35b8('0x27')](handleError(_0xe007a4,null));};exports[_0x35b8('0x6b')]=function(_0x25d608,_0x3ebca7,_0x2193be){_0x25d608['body']['sitepic']=_0x25d608[_0x35b8('0x6c')][_0x35b8('0x6d')];return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x25d608[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x3ebca7,null))[_0x35b8('0x1e')](saveUpdates(_0x25d608[_0x35b8('0x55')],null))[_0x35b8('0x1e')](respondWithResult(_0x3ebca7,null))[_0x35b8('0x27')](handleError(_0x3ebca7,null));};exports[_0x35b8('0x6e')]=function(_0x5dae87,_0x3a500b,_0x44ee2b){_0x5dae87[_0x35b8('0x55')]['agentAvatar']=_0x5dae87['file'][_0x35b8('0x6d')];return db['ChatWebsite'][_0x35b8('0x53')]({'where':{'id':_0x5dae87['params']['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x3a500b,null))[_0x35b8('0x1e')](saveUpdates(_0x5dae87[_0x35b8('0x55')],null))[_0x35b8('0x1e')](respondWithResult(_0x3a500b,null))[_0x35b8('0x27')](handleError(_0x3a500b,null));};exports[_0x35b8('0x6f')]=function(_0x4e5a39,_0x482ffb,_0x237b61){_0x4e5a39['body'][_0x35b8('0x70')]=_0x4e5a39[_0x35b8('0x6c')][_0x35b8('0x6d')];return db[_0x35b8('0x39')]['find']({'where':{'id':_0x4e5a39[_0x35b8('0x51')]['id']}})['then'](handleEntityNotFound(_0x482ffb,null))[_0x35b8('0x1e')](saveUpdates(_0x4e5a39[_0x35b8('0x55')],null))[_0x35b8('0x1e')](respondWithResult(_0x482ffb,null))[_0x35b8('0x27')](handleError(_0x482ffb,null));};exports['addSystemAvatar']=function(_0x29249f,_0x35e527,_0x5859b2){_0x29249f[_0x35b8('0x55')][_0x35b8('0x71')]=_0x29249f[_0x35b8('0x6c')]['filename'];return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x29249f[_0x35b8('0x51')]['id']}})['then'](handleEntityNotFound(_0x35e527,null))[_0x35b8('0x1e')](saveUpdates(_0x29249f['body'],null))[_0x35b8('0x1e')](respondWithResult(_0x35e527,null))[_0x35b8('0x27')](handleError(_0x35e527,null));};exports[_0x35b8('0x72')]=function(_0x30f746,_0x4af4b8,_0x7b8d83){var _0x120803=path[_0x35b8('0x73')](config[_0x35b8('0x74')],_0x35b8('0x75'));var _0x30c8a3={'where':{'id':_0x30f746[_0x35b8('0x51')]['id']},'attributes':['id','sitepic'],'raw':!![]};var _0x208fce=![];return require(_0x35b8('0x76'))[_0x35b8('0x77')]()['then'](function(_0x2edb47){if(_0x2edb47){_0x208fce=_0x2edb47[_0x35b8('0x78')];}})['then'](function(){return db[_0x35b8('0x39')][_0x35b8('0x53')](_0x30c8a3);})[_0x35b8('0x1e')](handleEntityNotFound(_0x4af4b8,null))[_0x35b8('0x1e')](function(_0xd0f696){if(_0xd0f696){if(!_[_0x35b8('0x79')](_0xd0f696[_0x35b8('0x7a')])){if(fs[_0x35b8('0x7b')](path[_0x35b8('0x73')](config[_0x35b8('0x74')],_0x35b8('0x7c'),_0xd0f696[_0x35b8('0x7a')]))&&_0x208fce){_0x120803=path[_0x35b8('0x73')](config[_0x35b8('0x74')],_0x35b8('0x7c'),_0xd0f696[_0x35b8('0x7a')]);}}return _0x4af4b8['download'](_0x120803);}})['catch'](handleError(_0x4af4b8,null));};exports[_0x35b8('0x7d')]=function(_0x38ab62,_0x617b92,_0x4df7ad){var _0x37198f=path['join'](config[_0x35b8('0x74')],'server/files/images/avatars/default_avatar.png');var _0x329934={'where':{'id':_0x38ab62[_0x35b8('0x51')]['id']},'attributes':['id',_0x35b8('0x7e')],'raw':!![]};return db[_0x35b8('0x39')][_0x35b8('0x53')](_0x329934)[_0x35b8('0x1e')](handleEntityNotFound(_0x617b92,null))[_0x35b8('0x1e')](function(_0x121431){if(_0x121431){if(!_[_0x35b8('0x79')](_0x121431['agentAvatar'])){if(fs['existsSync'](path[_0x35b8('0x73')](config['root'],'server/files/images/avatars/',_0x121431[_0x35b8('0x7e')]))){_0x37198f=path['join'](config['root'],_0x35b8('0x7f'),_0x121431[_0x35b8('0x7e')]);}}return _0x617b92[_0x35b8('0x80')](_0x37198f);}})[_0x35b8('0x27')](handleError(_0x617b92,null));};exports['getCustomerAvatar']=function(_0x17b547,_0x7dba23,_0x7bf0be){var _0x2d80f7=path[_0x35b8('0x73')](config['root'],'server/files/images/avatars/customer_avatar.png');var _0x5477f5={'where':{'id':_0x17b547[_0x35b8('0x51')]['id']},'attributes':['id','customerAvatar',_0x35b8('0x81')],'raw':!![]};return db[_0x35b8('0x39')]['find'](_0x5477f5)[_0x35b8('0x1e')](handleEntityNotFound(_0x7dba23,null))[_0x35b8('0x1e')](function(_0x567f10){if(_0x567f10){if(!_[_0x35b8('0x79')](_0x567f10[_0x35b8('0x70')])){if(fs[_0x35b8('0x7b')](path[_0x35b8('0x73')](config['root'],_0x35b8('0x7f'),_0x567f10[_0x35b8('0x70')]))&&_0x567f10[_0x35b8('0x81')]){_0x2d80f7=path[_0x35b8('0x73')](config['root'],_0x35b8('0x7f'),_0x567f10[_0x35b8('0x70')]);}}return _0x7dba23[_0x35b8('0x80')](_0x2d80f7);}})[_0x35b8('0x27')](handleError(_0x7dba23,null));};exports[_0x35b8('0x82')]=function(_0x3d67a4,_0x4f35c8,_0x4028a6){var _0x38f3ee=path[_0x35b8('0x73')](config[_0x35b8('0x74')],'server/files/images/avatars/system_avatar.png');var _0x487434={'where':{'id':_0x3d67a4['params']['id']},'attributes':['id',_0x35b8('0x71')],'raw':!![]};return db[_0x35b8('0x39')][_0x35b8('0x53')](_0x487434)['then'](handleEntityNotFound(_0x4f35c8,null))[_0x35b8('0x1e')](function(_0x14e3c0){if(_0x14e3c0){if(!_[_0x35b8('0x79')](_0x14e3c0[_0x35b8('0x71')])){if(fs[_0x35b8('0x7b')](path['join'](config[_0x35b8('0x74')],'server/files/images/avatars/',_0x14e3c0[_0x35b8('0x71')]))){_0x38f3ee=path[_0x35b8('0x73')](config[_0x35b8('0x74')],_0x35b8('0x7f'),_0x14e3c0['systemAvatar']);}}return _0x4f35c8[_0x35b8('0x80')](_0x38f3ee);}})[_0x35b8('0x27')](handleError(_0x4f35c8,null));};exports['notify']=function(_0x179c85,_0x55c3f9,_0x104d12){var _0x38df93=require('user-agent-parser');var _0x494797=new _0x38df93();var _0x4699f2=_0x494797[_0x35b8('0x83')](_0x179c85[_0x35b8('0x84')][_0x35b8('0x85')])[_0x35b8('0x86')]();var _0x2fa7eb={'body':_0x179c85[_0x35b8('0x55')],'channel':_0x35b8('0x87')};var _0xec38e=[];var _0x5578e3=[];var _0x315958={};var _0x9324f7=![];return db['CmContact']['describe']()['then'](function(_0xf4a892){if(!_0xf4a892){throw new db[(_0x35b8('0x1b'))][(_0x35b8('0x88'))]('no\x20available\x20attributes');}_0xec38e=_['difference'](_['keys'](_0xf4a892),[_0x35b8('0x89'),_0x35b8('0x8a')]);_0x5578e3=_[_0x35b8('0x8b')](_[_0x35b8('0x3e')](_0xf4a892),[_0x35b8('0x89'),_0x35b8('0x8a'),_0x35b8('0x8c'),_0x35b8('0x8d')]);if(_0x179c85[_0x35b8('0x55')]['id']){delete _0x179c85[_0x35b8('0x55')]['id'];}if(_[_0x35b8('0x79')](_0x179c85[_0x35b8('0x55')][_0x35b8('0x8e')])){throw new db[(_0x35b8('0x1b'))]['ValidationError'](_0x35b8('0x8f'));}if(_[_0x35b8('0x79')](_0x179c85['body']['body'])||_0x179c85[_0x35b8('0x55')][_0x35b8('0x55')]===''){throw new db[(_0x35b8('0x1b'))]['ValidationError'](_0x35b8('0x90'));}if(_[_0x35b8('0x79')](_0x179c85[_0x35b8('0x55')][_0x35b8('0x91')])){throw new db[(_0x35b8('0x1b'))][(_0x35b8('0x88'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5578e3);}if(!_[_0x35b8('0x92')](_0x5578e3,_0x179c85[_0x35b8('0x55')][_0x35b8('0x91')])){throw new db[(_0x35b8('0x1b'))][(_0x35b8('0x88'))](_0x35b8('0x93')+_0x5578e3);}_0x315958[_0x179c85[_0x35b8('0x55')][_0x35b8('0x91')]]=_0x179c85[_0x35b8('0x55')][_0x35b8('0x8e')];})[_0x35b8('0x1e')](function(){return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x179c85['params']['id']},'include':[{'model':db[_0x35b8('0x94')],'as':_0x35b8('0x95'),'include':[{'model':db[_0x35b8('0x96')],'as':_0x35b8('0x97'),'where':_0x315958,'limit':0x1,'order':[[_0x35b8('0x8a'),_0x35b8('0x98')]]}]},{'model':db[_0x35b8('0x99')],'as':'Applications'}]});})[_0x35b8('0x1e')](handleEntityNotFound(_0x55c3f9,null))[_0x35b8('0x1e')](function(_0x4ecc39){if(_0x4ecc39&&_0x4ecc39['List']){_0x2fa7eb[_0x35b8('0x9a')]=_0x4ecc39;_0x2fa7eb['applications']=_0x4ecc39[_0x35b8('0x9b')];_0x2fa7eb[_0x35b8('0x9c')]=_0x4ecc39['List'];_0x2fa7eb[_0x35b8('0x9d')]=_[_0x35b8('0x9e')](_0x2fa7eb[_0x35b8('0x9d')],[_0x35b8('0x9f')],[_0x35b8('0xa0')]);if(_0x2fa7eb[_0x35b8('0x9a')]['Applications']){delete _0x2fa7eb['account'][_0x35b8('0x9b')];}if(_0x2fa7eb[_0x35b8('0x9a')][_0x35b8('0x95')]&&_0x2fa7eb[_0x35b8('0x9a')][_0x35b8('0x95')][_0x35b8('0x97')]['length']){return _0x2fa7eb[_0x35b8('0x9a')]['List'][_0x35b8('0x97')][0x0];}var _0x4445f4=_[_0x35b8('0x14')](_0x179c85[_0x35b8('0x55')],{'firstName':_0x179c85['body']['from'],'ListId':_0x4ecc39['ListId']});_0x4445f4[_0x179c85['body']['mapKey']]=_0x179c85[_0x35b8('0x55')][_0x35b8('0x8e')];return db[_0x35b8('0x96')][_0x35b8('0x54')](_0x4445f4,{'fields':_0xec38e,'raw':!![]});}})[_0x35b8('0x1e')](handleEntityNotFound(_0x55c3f9,null))['then'](function(_0x59b376){_0x2fa7eb[_0x35b8('0xa1')]=_0x59b376;var _0x436d13=_0x179c85['body'][_0x35b8('0xa2')];if(_0x179c85['headers']['cf-connecting-ip']){_0x436d13=_0x179c85['headers'][_0x35b8('0xa3')];}else if(_0x179c85[_0x35b8('0x84')][_0x35b8('0xa4')]){_0x436d13=_[_0x35b8('0xa5')](_0x179c85[_0x35b8('0x84')][_0x35b8('0xa4')][_0x35b8('0xa6')](','));}if(_0x59b376){var _0x88c66c={'ContactId':_0x59b376['id'],'ChatWebsiteId':_0x179c85[_0x35b8('0x51')]['id'],'from':(_0x59b376[_0x35b8('0xa7')]||'')+'\x20'+(_0x59b376[_0x35b8('0xa8')]||''),'customerIp':_0x436d13,'customerPort':_0x179c85[_0x35b8('0x84')][_0x35b8('0xa9')]?_0x179c85[_0x35b8('0x84')][_0x35b8('0xa9')]:null,'referer':_0x179c85[_0x35b8('0x55')][_0x35b8('0xaa')],'browserName':_0x4699f2[_0x35b8('0xab')][_0x35b8('0x34')]&&_0x4699f2[_0x35b8('0xab')][_0x35b8('0xac')]?util[_0x35b8('0xad')](_0x35b8('0xae'),_0x4699f2[_0x35b8('0xab')][_0x35b8('0x34')],_0x4699f2[_0x35b8('0xab')][_0x35b8('0xac')]):'unknown','browserVersion':_0x4699f2[_0x35b8('0xab')][_0x35b8('0xac')]||_0x35b8('0xaf'),'osName':util[_0x35b8('0xad')](_0x35b8('0xae'),_0x4699f2['os'][_0x35b8('0x34')],_0x4699f2['os'][_0x35b8('0xac')]),'osVersion':_0x4699f2['os'][_0x35b8('0xac')],'deviceModel':_0x4699f2[_0x35b8('0xb0')][_0x35b8('0x40')]&&_0x4699f2['device'][_0x35b8('0xb1')]?util['format'](_0x35b8('0xb2'),_0x4699f2[_0x35b8('0xb0')][_0x35b8('0x40')],_0x4699f2[_0x35b8('0xb0')][_0x35b8('0xb1')],_0x4699f2[_0x35b8('0xb0')][_0x35b8('0x3c')]):null,'deviceVendor':_0x4699f2[_0x35b8('0xb0')]['vendor'],'deviceType':_0x4699f2['device']['type'],'formData':JSON[_0x35b8('0xb3')](_0x179c85[_0x35b8('0x55')])};var _0xd97611={'ChatWebsiteId':_0x179c85[_0x35b8('0x51')]['id'],'closed':![]};if(_0x179c85[_0x35b8('0x55')][_0x35b8('0xb4')]){_0xd97611[_0x35b8('0xb4')]=_0x179c85['body'][_0x35b8('0xb4')];return db['ChatInteraction'][_0x35b8('0x53')]({'where':_0xd97611})[_0x35b8('0x1e')](function(_0x2b489a){if(_0x2b489a){return[_0x2b489a,![]];}_0x88c66c['threadId']=_0x179c85[_0x35b8('0x55')][_0x35b8('0xb4')];_0x88c66c[_0x35b8('0xb5')]=_0x179c85[_0x35b8('0x55')][_0x35b8('0xb5')];return db[_0x35b8('0xb6')][_0x35b8('0x54')](_0x88c66c)[_0x35b8('0x1e')](function(_0x415b55){return[_0x415b55,!![]];});});}_0xd97611[_0x35b8('0xb7')]=_0x59b376['id'];if(_0x179c85[_0x35b8('0x55')][_0x35b8('0xb8')]&&_0x179c85[_0x35b8('0x55')][_0x35b8('0xb8')]['id']){_0xd97611['id']=_0x179c85['body']['interaction']['id'];return db['ChatInteraction'][_0x35b8('0x53')]({'where':_0xd97611})[_0x35b8('0x1e')](function(_0x55f237){if(_0x55f237){return[_0x55f237,![]];}return db['ChatInteraction'][_0x35b8('0x54')](_0x88c66c)[_0x35b8('0x1e')](function(_0x1b9e95){return[_0x1b9e95,!![]];});});}return db[_0x35b8('0xb6')]['create'](_0x88c66c)[_0x35b8('0x1e')](function(_0x499f25){return[_0x499f25,!![]];});}})[_0x35b8('0xb9')](function(_0x2d7d7c,_0x64b69f){if(_0x2d7d7c){_0x9324f7=_0x64b69f;if(!_0x64b69f){var _0x3e0895={'from':(_0x2fa7eb['contact']['firstName']||'')+'\x20'+(_0x2fa7eb[_0x35b8('0xa1')][_0x35b8('0xa8')]||'')};if(_0x179c85['body'][_0x35b8('0xb4')]&&_0x179c85[_0x35b8('0x55')][_0x35b8('0xba')]&&_0x179c85[_0x35b8('0x55')][_0x35b8('0xb4')]!=_0x179c85[_0x35b8('0x55')][_0x35b8('0xba')]){_0x3e0895['threadId']=_0x179c85['body'][_0x35b8('0xba')];}return _0x2d7d7c[_0x35b8('0x31')](_0x3e0895);}else{return _0x2d7d7c;}}})[_0x35b8('0x1e')](function(_0x151f13){_0x2fa7eb['interaction']=_0x151f13[_0x35b8('0x59')]({'plain':!![]});_0x2fa7eb[_0x35b8('0xb8')][_0x35b8('0xbb')]=_0x9324f7;if(_0x2fa7eb[_0x35b8('0xb8')][_0x35b8('0xbb')]){if(_0x2fa7eb[_0x35b8('0x9a')]['autoclose']){_0x2fa7eb['applications'][_0x35b8('0xbc')]({'id':0x0,'priority':_0x2fa7eb['applications'][_0x35b8('0x44')]+0x1,'app':'close','appdata':_0x35b8('0xbd'),'interval':_0x35b8('0xbe')});}}return db['ChatMessage'][_0x35b8('0x54')]({'body':_0x179c85[_0x35b8('0x55')][_0x35b8('0x55')],'ChatWebsiteId':_0x179c85[_0x35b8('0x51')]['id'],'ChatInteractionId':_0x151f13['id'],'direction':'in','ContactId':_0x2fa7eb[_0x35b8('0xa1')]['id'],'AttachmentId':_0x179c85[_0x35b8('0x55')][_0x35b8('0xbf')]});})[_0x35b8('0x1e')](function(_0x21c852){_0x2fa7eb[_0x35b8('0x24')]=_0x21c852;if(_0x2fa7eb[_0x35b8('0xb8')]['UserId']){return db[_0x35b8('0xc0')][_0x35b8('0x53')]({'attributes':['id',_0x35b8('0x34')],'where':{'id':_0x2fa7eb[_0x35b8('0xb8')][_0x35b8('0xc1')]}})[_0x35b8('0x1e')](function(_0x337007){if(_0x337007){_0x2fa7eb[_0x35b8('0x9d')][_0x35b8('0xc2')]({'id':0x0,'priority':0x0,'app':_0x35b8('0xc3'),'appdata':_0x337007['name']+','+(_0x2fa7eb[_0x35b8('0x9a')][_0x35b8('0xc4')]||0xa),'interval':_0x35b8('0xbe')});_0x2fa7eb[_0x35b8('0xc5')]=!![];}return respondWithRpcPromise('Start','startRouting',_0x2fa7eb);});}return respondWithRpcPromise(_0x35b8('0xc6'),_0x35b8('0xc7'),_0x2fa7eb);})[_0x35b8('0x1e')](function(_0x513a08){respondWithRpcPromise('EventManager',_0x35b8('0xc8'),{'event':'notify','message':_0x513a08},client9002);return _0x513a08;})[_0x35b8('0x1e')](respondWithResult(_0x55c3f9,null))['catch'](handleError(_0x55c3f9,null));};exports[_0x35b8('0xc9')]=function(_0x2a7c46,_0x249a84,_0x5e66fa){var _0x50b2d6,_0x240249,_0x43fb02;var _0x4ddc5a=[];var _0x2addb7=[];var _0x297352={};return db[_0x35b8('0x96')][_0x35b8('0x5f')]()[_0x35b8('0x1e')](function(_0x272b6a){if(!_0x272b6a){throw new db[(_0x35b8('0x1b'))]['ValidationError'](_0x35b8('0xca'));}_0x2addb7=_['difference'](_[_0x35b8('0x3e')](_0x272b6a),[_0x35b8('0x89'),_0x35b8('0x8a')]);_0x4ddc5a=_[_0x35b8('0x8b')](_['keys'](_0x272b6a),['createdAt',_0x35b8('0x8a'),_0x35b8('0x8c'),_0x35b8('0x8d')]);if(_0x2a7c46[_0x35b8('0x55')]['id']){delete _0x2a7c46[_0x35b8('0x55')]['id'];}if(_['isNil'](_0x2a7c46[_0x35b8('0x55')][_0x35b8('0x8e')])){throw _0x249a84[_0x35b8('0x29')](0x1f4)[_0x35b8('0xcb')](new db[(_0x35b8('0x1b'))]['ValidationError'](_0x35b8('0x8f')));}if(_[_0x35b8('0x79')](_0x2a7c46['body'][_0x35b8('0x55')])||_0x2a7c46[_0x35b8('0x55')][_0x35b8('0x55')]===''){throw _0x249a84['status'](0x1f4)['send'](new db['Sequelize'][(_0x35b8('0x88'))](_0x35b8('0x90')));}if(_[_0x35b8('0x79')](_0x2a7c46['body'][_0x35b8('0xcc')])){throw _0x249a84[_0x35b8('0x29')](0x1f4)[_0x35b8('0xcb')](new db[(_0x35b8('0x1b'))]['ValidationError'](_0x35b8('0xcd')+_0x4ddc5a));}if(!_['includes'](_0x4ddc5a,_0x2a7c46[_0x35b8('0x55')][_0x35b8('0xcc')])){throw _0x249a84[_0x35b8('0x29')](0x1f4)['send'](new db[(_0x35b8('0x1b'))][(_0x35b8('0x88'))]('mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4ddc5a));}_0x297352[_0x2a7c46[_0x35b8('0x55')]['mapKeyOffline']]=_0x2a7c46[_0x35b8('0x55')]['from'];})[_0x35b8('0x1e')](function(){return db['ChatWebsite']['find']({'where':{'id':_0x2a7c46[_0x35b8('0x51')]['id']},'include':[{'model':db['CmList'],'as':_0x35b8('0x95')}]});})[_0x35b8('0x1e')](handleEntityNotFound(_0x249a84,null))['then'](function(_0x240a4a){if(_0x240a4a&&_0x240a4a['List']){_0x240249=_0x240a4a;var _0x738c97=_[_0x35b8('0x14')](_0x2a7c46['body'],{'firstName':_0x2a7c46[_0x35b8('0x55')][_0x35b8('0x8e')],'phone':_0x2a7c46['body'][_0x35b8('0x8e')],'ListId':_0x240a4a['ListId']});_0x738c97[_0x2a7c46['body']['mapKeyOffline']]=_0x2a7c46[_0x35b8('0x55')][_0x35b8('0x8e')];return db[_0x35b8('0x96')][_0x35b8('0xce')]({'where':_0x297352,'defaults':_0x738c97});}})[_0x35b8('0xb9')](function(_0x4a64d7){if(_0x4a64d7){_0x43fb02=_0x4a64d7;var _0x5a1616=fs[_0x35b8('0xcf')](path[_0x35b8('0x73')](config['root'],_0x35b8('0xd0')),_0x35b8('0xd1'));var _0xaae38e=ejs[_0x35b8('0xd2')](_0x5a1616,{'body':_[_0x35b8('0xd3')](_0x2a7c46[_0x35b8('0x55')]['body']),'bodyTitle':_0x240249[_0x35b8('0xd4')]});return db[_0x35b8('0xd5')][_0x35b8('0x54')]({'body':_0xaae38e,'ContactId':_0x4a64d7['id'],'ChatWebsiteId':_0x240249['id']});}})[_0x35b8('0x1e')](function(_0x4b45c3){if(_0x4b45c3){_0x50b2d6=_0x4b45c3;return db[_0x35b8('0xd6')][_0x35b8('0x63')]({'where':{'service':!![]},'include':[{'model':db['MailServerOut'],'as':'Smtp','raw':!![]}]});}})['then'](function(_0x5cdfe8){if(_0x5cdfe8&&_0x5cdfe8[_0x35b8('0xd7')]&&_0x240249['forwardOfflineAddress']){var _0x559d2f={'tls':{'rejectUnauthorized':![]}};if(_0x5cdfe8[_0x35b8('0xd7')]['service']){_0x559d2f[_0x35b8('0xd8')]=_0x5cdfe8[_0x35b8('0xd7')]['service'];}else{_0x559d2f['host']=_0x5cdfe8[_0x35b8('0xd7')]['host'];_0x559d2f['port']=_0x5cdfe8['Smtp'][_0x35b8('0xd9')];_0x559d2f[_0x35b8('0xda')]=_0x5cdfe8[_0x35b8('0xd7')][_0x35b8('0xda')];}if(_0x5cdfe8['Smtp']['authentication']){_0x559d2f['auth']={'user':_0x5cdfe8[_0x35b8('0xd7')]['user'],'pass':_0x5cdfe8[_0x35b8('0xd7')]['pass']};}return respondWithRpcPromise(_0x35b8('0xdb'),_0x35b8('0xdc'),{'account':_0x559d2f,'message':{'from':util[_0x35b8('0xad')]('\x22%s\x22\x20<%s>',_0x5cdfe8[_0x35b8('0x34')],_0x5cdfe8['email']||_0x5cdfe8[_0x35b8('0xd7')][_0x35b8('0x56')]),'to':_0x240249[_0x35b8('0xdd')],'subject':_0x240249[_0x35b8('0xde')],'text':_0x50b2d6['body']}},client9003)[_0x35b8('0x1e')](function(){return _0x50b2d6;})[_0x35b8('0x27')](function(_0x1b8875){console[_0x35b8('0x21')](_0x1b8875);});}})[_0x35b8('0x1e')](function(){if(_0x50b2d6){return _0x50b2d6;}})[_0x35b8('0x1e')](respondWithResult(_0x249a84,null))[_0x35b8('0x27')](handleError(_0x249a84,null));};exports['addInteraction']=function(_0x11d1b1,_0x22376b,_0x3f5851){return db[_0x35b8('0xb6')][_0x35b8('0x53')]({'where':{'id':_0x11d1b1[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x22376b,null))[_0x35b8('0x1e')](function(_0x53436e){if(_0x53436e){return _0x53436e[_0x35b8('0xdf')](_0x11d1b1[_0x35b8('0x55')][_0x35b8('0x66')],_[_0x35b8('0xe0')](_0x11d1b1[_0x35b8('0x55')],[_0x35b8('0x66'),'id'])||{});}})[_0x35b8('0x1e')](respondWithResult(_0x22376b,null))[_0x35b8('0x27')](handleError(_0x22376b,null));};exports[_0x35b8('0xe1')]=function(_0xcfcb2a,_0x206d4f,_0x49cbca){var _0x456f90={'raw':![],'where':{}};var _0x3c562e={};var _0xd85c73={'count':0x0,'rows':[]};return db['ChatWebsite']['findOne']({'where':{'id':_0xcfcb2a[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x206d4f,null))[_0x35b8('0x1e')](function(_0x3132ae){if(_0x3132ae){_0x3c562e['model']=_[_0x35b8('0x3e')](db['ChatInteraction']['rawAttributes']);_0x3c562e[_0x35b8('0x3d')]=_[_0x35b8('0x3e')](_0xcfcb2a[_0x35b8('0x3d')]);_0x3c562e['filters']=_[_0x35b8('0x42')](_0x3c562e['model'],_0x3c562e[_0x35b8('0x3d')]);_0x456f90[_0x35b8('0x41')]=_[_0x35b8('0x42')](_0x3c562e[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0xcfcb2a['query'][_0x35b8('0x43')]));_0x456f90['attributes']=_0x456f90[_0x35b8('0x41')][_0x35b8('0x44')]?_0x456f90[_0x35b8('0x41')]:_0x3c562e[_0x35b8('0x40')];if(!_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0x64')]('nolimit')){_0x456f90['limit']=qs[_0x35b8('0x2d')](_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0x2d')]);_0x456f90[_0x35b8('0x2c')]=qs['offset'](_0xcfcb2a['query']['offset']);}_0x456f90['order']=qs[_0x35b8('0x47')](_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0x47')]);_0x456f90[_0x35b8('0x4c')]=qs[_0x35b8('0x3f')](_[_0x35b8('0x48')](_0xcfcb2a[_0x35b8('0x3d')],_0x3c562e[_0x35b8('0x3f')]));_0x456f90[_0x35b8('0x4c')]['ChatWebsiteId']=_0x3132ae['id'];if(_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0x49')]){_0x456f90[_0x35b8('0x4c')]=_[_0x35b8('0x4a')](_0x456f90[_0x35b8('0x4c')],{'$or':_[_0x35b8('0x38')](_0x456f90[_0x35b8('0x41')],function(_0x209e12){var _0x1852c5={};_0x1852c5[_0x209e12]={'$like':'%'+_0xcfcb2a[_0x35b8('0x3d')]['filter']+'%'};return _0x1852c5;})});}_0x456f90=_[_0x35b8('0x4a')]({},_0x456f90,_0xcfcb2a[_0x35b8('0x4b')]);return db['ChatInteraction'][_0x35b8('0x2b')]({'where':_0x456f90['where']})['then'](function(_0x270d1e){_0xd85c73[_0x35b8('0x2b')]=_0x270d1e;if(_0xcfcb2a['query'][_0x35b8('0x4d')]){_0x456f90['include']=[{'model':db['CmContact'],'as':'Contact','required':![]},{'model':db['User'],'as':_0x35b8('0xe2'),'attributes':['name',_0x35b8('0xe3'),'internal'],'required':![]},{'model':db[_0x35b8('0xe4')],'as':_0x35b8('0xe5'),'attributes':['id',_0x35b8('0x34'),_0x35b8('0xe6')],'where':_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0xe7')]?{'id':_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0xe7')]}:undefined,'required':_0xcfcb2a[_0x35b8('0x3d')][_0x35b8('0xe7')]?!![]:![]}];}return db['ChatInteraction'][_0x35b8('0x4e')](_0x456f90);})[_0x35b8('0x1e')](function(_0x3388ce){_0xd85c73['rows']=_0x3388ce;return _0xd85c73;});}})[_0x35b8('0x1e')](respondWithFilteredResult(_0x206d4f,_0x456f90))[_0x35b8('0x27')](handleError(_0x206d4f,null));};function iftimePromise(_0x20d32c,_0x454d30){return respondWithRpcPromise(_0x35b8('0xe8'),_0x35b8('0xe9'),{'command':_0x454d30[_0x35b8('0xea')]?util['format']('iftime\x20%s,%s',_0x20d32c['interval'],_0x454d30['timezone']):util[_0x35b8('0xad')](_0x35b8('0xeb'),_0x20d32c[_0x35b8('0xec')])},client9002)['then'](function(_0x3e1b86){var _0x387bf9=_0x3e1b86&&_0x3e1b86['indexOf'](_0x35b8('0xed'))>=0x0?!![]:![];logger['info'](_0x35b8('0xee'),_0x454d30['id'],_0x20d32c['id'],_0x20d32c[_0x35b8('0xec')],_0x387bf9?_0x35b8('0xef'):'OFFLINE',_0x454d30[_0x35b8('0xea')]?_0x454d30['timezone']:'No\x20timezone');return _0x387bf9;})[_0x35b8('0x27')](function(_0x10eb5c){logger[_0x35b8('0x21')](_0x35b8('0xee'),_0x454d30['id'],_0x20d32c['id'],_0x20d32c[_0x35b8('0xec')],util[_0x35b8('0xf0')](_0x10eb5c,{'showHidden':![],'depth':null}),_0x454d30[_0x35b8('0xea')]?_0x454d30[_0x35b8('0xea')]:_0x35b8('0xf1'));return![];});}exports[_0x35b8('0xe9')]=function(_0x244176,_0x3ff59d,_0x15aaa2){var _0x4cae92=0x0;var _0x3930b8=0x0;var _0x54c09d=![];var _0x18dd94;var _0x584091;return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x244176[_0x35b8('0x51')]['id']},'include':[{'model':db[_0x35b8('0xf2')],'as':_0x35b8('0xf2'),'include':[{'model':db[_0x35b8('0xf2')],'as':'Intervals','attributes':['id',_0x35b8('0xec')],'raw':!![]}]}]})[_0x35b8('0x1e')](handleEntityNotFound(_0x3ff59d,null))['then'](function(_0x37922c){if(_0x37922c){_0x18dd94=_0x37922c;return _0x37922c[_0x35b8('0xf3')]({'raw':!![]});}})[_0x35b8('0x1e')](function(_0x1f6b8c){if(_0x18dd94){if(_0x1f6b8c){_0x584091=_0x1f6b8c;}}return require('../../config/license/util')[_0x35b8('0x77')]();})[_0x35b8('0x1e')](function(_0x36415c){if(_0x36415c){_0x3930b8=_0x36415c['virtual'];_0x54c09d=_0x36415c['custom'];}})[_0x35b8('0x1e')](function(){return db['ChatInteraction'][_0x35b8('0x2b')]({'where':{'closed':![]}});})[_0x35b8('0x1e')](function(_0x112660){_0x4cae92=_0x112660;if(_0x3930b8&&_0x112660>_0x3930b8){return db[_0x35b8('0xf4')]['findOne']({'where':{'id':0x1}})[_0x35b8('0x1e')](function(_0x2b9a3b){if(_0x2b9a3b){_0x2b9a3b[_0x35b8('0xf5')](_0x35b8('0xf6'));}});}})['then'](function(){if(_0x18dd94[_0x35b8('0xf2')]&&_0x18dd94[_0x35b8('0xf2')]['Intervals']){var _0x3a6aef=[];for(var _0x49823c=0x0;_0x49823c<_0x18dd94[_0x35b8('0xf2')][_0x35b8('0xf7')]['length'];_0x49823c++){var _0x5c5887=_0x18dd94[_0x35b8('0xf2')]['Intervals'][_0x49823c][_0x35b8('0x59')]({'plain':!![]});_0x3a6aef[_0x35b8('0xbc')](iftimePromise(_0x5c5887,_0x18dd94));}return BPromise['all'](_0x3a6aef)[_0x35b8('0x1e')](function(_0x5a2613){return _['some'](_0x5a2613);});}else{return!![];}})[_0x35b8('0x1e')](function(_0x1b8ea9){var _0x173320=fs['readFileSync'](path[_0x35b8('0x73')](config['root'],'server/files/chat/iframe.js'),_0x35b8('0xd1'));var _0x1028ae={'remote':_0x18dd94[_0x35b8('0xf8')],'query':querystring[_0x35b8('0xb3')](_[_0x35b8('0x4a')](_0x18dd94[_0x35b8('0x59')]({'plain':!![]}),{'customerIp':_0x244176[_0x35b8('0x84')][_0x35b8('0xa4')]||_0x244176[_0x35b8('0x84')][_0x35b8('0xf9')]||_0x244176[_0x35b8('0xfa')][_0x35b8('0xfb')]||_0x244176['ip'],'referer':_0x244176[_0x35b8('0x84')][_0x35b8('0xaa')],'openedInteractions':_0x4cae92,'maxInteractions':_0x3930b8,'virtual':_0x54c09d[_0x35b8('0xfc')],'online':_0x1b8ea9,'custom':_0x54c09d}))[_0x35b8('0xfd')](/'/g,'\x5c\x27')};_0x3ff59d[_0x35b8('0xcb')](ejs[_0x35b8('0xd2')](Mustache[_0x35b8('0xd2')](_0x173320,_0x1028ae),{'proactiveActions':_0x584091,'alignment':_0x18dd94['alignment'],'verticalAlignment':_0x18dd94[_0x35b8('0xfe')],'div_color':_0x18dd94[_0x35b8('0xe6')],'text_color':_0x18dd94[_0x35b8('0xff')]}));})[_0x35b8('0x27')](handleError(_0x3ff59d,null));};exports['addApplications']=function(_0x970fc8,_0x10f22d,_0x97e11e){return db[_0x35b8('0x39')][_0x35b8('0x63')]({'where':{'id':_0x970fc8[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x10f22d,null))[_0x35b8('0x1e')](function(_0x1d00d2){if(_0x1d00d2){return db[_0x35b8('0x100')][_0x35b8('0x101')](function(_0x18cde4){return db['ChatApplication'][_0x35b8('0x32')]({'where':{'ChatWebsiteId':_0x970fc8[_0x35b8('0x51')]['id']},'transaction':_0x18cde4})['then'](function(_0x2b1129){var _0x51cb39=_[_0x35b8('0x38')](_0x970fc8[_0x35b8('0x55')],function(_0x179b96){_0x179b96[_0x35b8('0x60')]=_0x970fc8['params']['id'];return _0x179b96;});return db[_0x35b8('0x99')][_0x35b8('0x102')](_0x51cb39,{'transaction':_0x18cde4});});})[_0x35b8('0x1e')](function(){return db[_0x35b8('0x99')][_0x35b8('0x103')]({'where':{'ChatWebsiteId':_0x970fc8['params']['id']},'order':_0x35b8('0x9f')});});}})[_0x35b8('0x1e')](respondWithResult(_0x10f22d,null))[_0x35b8('0x27')](handleError(_0x10f22d,null));};exports[_0x35b8('0x104')]=function(_0x496a81,_0xfcc7dd,_0xb07baf){var _0x3f4814={};var _0x38c48d={};var _0x5b7ad2;var _0x54a525;return db[_0x35b8('0x39')][_0x35b8('0x63')]({'where':{'id':_0x496a81['params']['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0xfcc7dd,null))[_0x35b8('0x1e')](function(_0x22ee5d){if(_0x22ee5d){_0x5b7ad2=_0x22ee5d;_0x38c48d['model']=_[_0x35b8('0x3e')](db['ChatApplication'][_0x35b8('0x3a')]);_0x38c48d['query']=_['keys'](_0x496a81[_0x35b8('0x3d')]);_0x38c48d[_0x35b8('0x3f')]=_[_0x35b8('0x42')](_0x38c48d[_0x35b8('0x40')],_0x38c48d[_0x35b8('0x3d')]);_0x3f4814[_0x35b8('0x41')]=_['intersection'](_0x38c48d[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0x496a81[_0x35b8('0x3d')][_0x35b8('0x43')]));_0x3f4814[_0x35b8('0x41')]=_0x3f4814['attributes']['length']?_0x3f4814['attributes']:_0x38c48d[_0x35b8('0x40')];_0x3f4814['order']=qs[_0x35b8('0x47')](_0x496a81[_0x35b8('0x3d')][_0x35b8('0x47')]);_0x3f4814[_0x35b8('0x4c')]=qs[_0x35b8('0x3f')](_['pick'](_0x496a81[_0x35b8('0x3d')],_0x38c48d[_0x35b8('0x3f')]));if(_0x496a81[_0x35b8('0x3d')][_0x35b8('0x49')]){_0x3f4814[_0x35b8('0x4c')]=_[_0x35b8('0x4a')](_0x3f4814[_0x35b8('0x4c')],{'$or':_['map'](_0x3f4814['attributes'],function(_0x383bd2){var _0x4f846d={};_0x4f846d[_0x383bd2]={'$like':'%'+_0x496a81['query']['filter']+'%'};return _0x4f846d;})});}_0x3f4814=_['merge']({},_0x3f4814,_0x496a81['options']);return _0x5b7ad2[_0x35b8('0x104')](_0x3f4814);}})[_0x35b8('0x1e')](function(_0x24a5ca){if(_0x24a5ca){_0x54a525=_0x24a5ca[_0x35b8('0x44')];if(!_0x496a81[_0x35b8('0x3d')][_0x35b8('0x64')](_0x35b8('0x45'))){_0x3f4814[_0x35b8('0x2d')]=qs[_0x35b8('0x2d')](_0x496a81['query'][_0x35b8('0x2d')]);_0x3f4814[_0x35b8('0x2c')]=qs[_0x35b8('0x2c')](_0x496a81[_0x35b8('0x3d')][_0x35b8('0x2c')]);}return _0x5b7ad2[_0x35b8('0x104')](_0x3f4814);}})[_0x35b8('0x1e')](function(_0x5281d3){if(_0x5281d3){return _0x5281d3?{'count':_0x54a525,'rows':_0x5281d3}:null;}})[_0x35b8('0x1e')](respondWithResult(_0xfcc7dd,null))[_0x35b8('0x27')](handleError(_0xfcc7dd,null));};exports[_0x35b8('0x105')]=function(_0x2eccfe,_0x4861a3,_0x114330){return db[_0x35b8('0x106')][_0x35b8('0x53')]({'where':{'id':_0x2eccfe[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x4861a3,null))[_0x35b8('0x1e')](function(_0x3149c8){if(_0x3149c8){return _0x3149c8[_0x35b8('0x105')](_0x2eccfe[_0x35b8('0x55')][_0x35b8('0x66')],_['omit'](_0x2eccfe[_0x35b8('0x55')],[_0x35b8('0x66'),'id'])||{});}})[_0x35b8('0x1e')](respondWithResult(_0x4861a3,null))[_0x35b8('0x27')](handleError(_0x4861a3,null));};exports[_0x35b8('0xf3')]=function(_0x2ff8e9,_0x8f6727,_0x14c9e8){var _0x12f250={};var _0x4326ec={};var _0x4fecb6;var _0x3e20cf;return db[_0x35b8('0x39')][_0x35b8('0x63')]({'where':{'id':_0x2ff8e9[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x8f6727,null))[_0x35b8('0x1e')](function(_0x566cd6){if(_0x566cd6){_0x4fecb6=_0x566cd6;_0x4326ec[_0x35b8('0x40')]=_[_0x35b8('0x3e')](db[_0x35b8('0x107')][_0x35b8('0x3a')]);_0x4326ec[_0x35b8('0x3d')]=_['keys'](_0x2ff8e9[_0x35b8('0x3d')]);_0x4326ec[_0x35b8('0x3f')]=_[_0x35b8('0x42')](_0x4326ec[_0x35b8('0x40')],_0x4326ec[_0x35b8('0x3d')]);_0x12f250['attributes']=_[_0x35b8('0x42')](_0x4326ec[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0x2ff8e9[_0x35b8('0x3d')]['fields']));_0x12f250[_0x35b8('0x41')]=_0x12f250[_0x35b8('0x41')][_0x35b8('0x44')]?_0x12f250[_0x35b8('0x41')]:_0x4326ec[_0x35b8('0x40')];_0x12f250[_0x35b8('0x46')]=qs['sort'](_0x2ff8e9[_0x35b8('0x3d')][_0x35b8('0x47')]);_0x12f250[_0x35b8('0x4c')]=qs[_0x35b8('0x3f')](_[_0x35b8('0x48')](_0x2ff8e9['query'],_0x4326ec[_0x35b8('0x3f')]));if(_0x2ff8e9[_0x35b8('0x3d')]['filter']){_0x12f250[_0x35b8('0x4c')]=_['merge'](_0x12f250['where'],{'$or':_['map'](_0x12f250[_0x35b8('0x41')],function(_0xc9f14c){var _0x52c6ca={};_0x52c6ca[_0xc9f14c]={'$like':'%'+_0x2ff8e9['query']['filter']+'%'};return _0x52c6ca;})});}_0x12f250=_[_0x35b8('0x4a')]({},_0x12f250,_0x2ff8e9[_0x35b8('0x4b')]);return _0x4fecb6['getProactiveActions'](_0x12f250);}})[_0x35b8('0x1e')](function(_0x442af5){if(_0x442af5){_0x3e20cf=_0x442af5[_0x35b8('0x44')];if(!_0x2ff8e9[_0x35b8('0x3d')][_0x35b8('0x64')]('nolimit')){_0x12f250['limit']=qs[_0x35b8('0x2d')](_0x2ff8e9[_0x35b8('0x3d')][_0x35b8('0x2d')]);_0x12f250['offset']=qs[_0x35b8('0x2c')](_0x2ff8e9['query'][_0x35b8('0x2c')]);}return _0x4fecb6['getProactiveActions'](_0x12f250);}})[_0x35b8('0x1e')](function(_0x8c802){if(_0x8c802){return _0x8c802?{'count':_0x3e20cf,'rows':_0x8c802}:null;}})[_0x35b8('0x1e')](respondWithResult(_0x8f6727,null))[_0x35b8('0x27')](handleError(_0x8f6727,null));};exports[_0x35b8('0x108')]=function(_0xaddc11,_0x2afd3d,_0x1495b2){var _0x4e1915=_0xaddc11[_0x35b8('0x3d')]['online']===_0x35b8('0x109')?_0x35b8('0x10a'):_0x35b8('0x10b');return db['ChatWebsite'][_0x35b8('0x53')]({'attributes':['id',_0x4e1915],'where':{'id':_0xaddc11[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x2afd3d,null))[_0x35b8('0x1e')](function(_0x1a838e){if(_0x1a838e){var _0x572c4a=_0x1a838e[_0x4e1915];var _0x310939=_0x572c4a&&_0x572c4a[_0x35b8('0x10c')]?_0x572c4a[_0x35b8('0x10c')]:[];_0x2afd3d[_0x35b8('0xcb')]({'fromKey':_['isNil'](_0x572c4a['fromKey'])?undefined:_0x572c4a['fromKey'],'count':_0x310939['length'],'rows':_0x310939});}})[_0x35b8('0x27')](handleError(_0x2afd3d,null));};exports[_0x35b8('0x10d')]=function(_0x192182,_0xc5b419,_0x551940){var _0x1437fa={'raw':![],'where':{}};var _0x3df354={};var _0x208b75={'count':0x0,'rows':[]};return db[_0x35b8('0x39')]['findOne']({'where':{'id':_0x192182[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0xc5b419,null))['then'](function(_0x9f22e3){if(_0x9f22e3){_0x3df354[_0x35b8('0x40')]=_['keys'](db[_0x35b8('0xd5')]['rawAttributes']);_0x3df354[_0x35b8('0x3d')]=_['keys'](_0x192182[_0x35b8('0x3d')]);_0x3df354[_0x35b8('0x3f')]=_[_0x35b8('0x42')](_0x3df354[_0x35b8('0x40')],_0x3df354[_0x35b8('0x3d')]);_0x1437fa[_0x35b8('0x41')]=_[_0x35b8('0x42')](_0x3df354[_0x35b8('0x40')],qs['fields'](_0x192182[_0x35b8('0x3d')]['fields']));_0x1437fa[_0x35b8('0x41')]=_0x1437fa[_0x35b8('0x41')][_0x35b8('0x44')]?_0x1437fa[_0x35b8('0x41')]:_0x3df354[_0x35b8('0x40')];if(!_0x192182[_0x35b8('0x3d')]['hasOwnProperty'](_0x35b8('0x45'))){_0x1437fa[_0x35b8('0x2d')]=qs[_0x35b8('0x2d')](_0x192182[_0x35b8('0x3d')]['limit']);_0x1437fa[_0x35b8('0x2c')]=qs[_0x35b8('0x2c')](_0x192182[_0x35b8('0x3d')]['offset']);}_0x1437fa[_0x35b8('0x46')]=qs['sort'](_0x192182[_0x35b8('0x3d')][_0x35b8('0x47')]);_0x1437fa[_0x35b8('0x4c')]=qs[_0x35b8('0x3f')](_[_0x35b8('0x48')](_0x192182[_0x35b8('0x3d')],_0x3df354[_0x35b8('0x3f')]));_0x1437fa[_0x35b8('0x4c')][_0x35b8('0x60')]=_0x9f22e3['id'];if(_0x192182[_0x35b8('0x3d')][_0x35b8('0x49')]){_0x1437fa[_0x35b8('0x4c')]=_[_0x35b8('0x4a')](_0x1437fa[_0x35b8('0x4c')],{'$or':_[_0x35b8('0x38')](_0x1437fa[_0x35b8('0x41')],function(_0x2a19ed){var _0x347a52={};_0x347a52[_0x2a19ed]={'$like':'%'+_0x192182[_0x35b8('0x3d')][_0x35b8('0x49')]+'%'};return _0x347a52;})});}_0x1437fa=_[_0x35b8('0x4a')]({},_0x1437fa,_0x192182[_0x35b8('0x4b')]);return db['ChatOfflineMessage'][_0x35b8('0x2b')]({'where':_0x1437fa[_0x35b8('0x4c')]})[_0x35b8('0x1e')](function(_0x3d4357){_0x208b75[_0x35b8('0x2b')]=_0x3d4357;if(_0x192182[_0x35b8('0x3d')]['includeAll']){_0x1437fa[_0x35b8('0x52')]=[{'all':!![]}];}else{_0x1437fa['include']=[{'model':db[_0x35b8('0x96')],'as':_0x35b8('0x10e'),'required':![]}];}return db['ChatOfflineMessage'][_0x35b8('0x4e')](_0x1437fa);})[_0x35b8('0x1e')](function(_0x52a953){_0x208b75[_0x35b8('0x4f')]=_0x52a953;return _0x208b75;});}})[_0x35b8('0x1e')](respondWithFilteredResult(_0xc5b419,_0x1437fa))['catch'](handleError(_0xc5b419,null));};exports['addAgents']=function(_0x36a1d3,_0x472dc3,_0x4c4e1e){return db['ChatWebsite']['find']({'where':{'id':_0x36a1d3[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x472dc3,null))['then'](function(_0x410256){if(_0x410256){return _0x410256[_0x35b8('0x10f')](_0x36a1d3[_0x35b8('0x55')]['ids'],_[_0x35b8('0xe0')](_0x36a1d3['body'],[_0x35b8('0x66'),'id'])||{})[_0x35b8('0xb9')](function(_0x2dcf1f){for(var _0x2bd4a1=0x0;_0x2bd4a1<_0x36a1d3[_0x35b8('0x55')][_0x35b8('0x66')][_0x35b8('0x44')];_0x2bd4a1+=0x1){socket[_0x35b8('0x110')](_0x35b8('0x111'),{'UserId':_0x36a1d3[_0x35b8('0x55')][_0x35b8('0x66')][_0x2bd4a1],'ChatWebsiteId':_0x36a1d3[_0x35b8('0x51')]['id']});}return _0x2dcf1f;});}})[_0x35b8('0x1e')](respondWithResult(_0x472dc3,null))[_0x35b8('0x27')](handleError(_0x472dc3,null));};exports[_0x35b8('0x112')]=function(_0x2c1132,_0x379788,_0x175835){return db[_0x35b8('0x39')][_0x35b8('0x53')]({'where':{'id':_0x2c1132[_0x35b8('0x51')]['id']}})[_0x35b8('0x1e')](handleEntityNotFound(_0x379788,null))[_0x35b8('0x1e')](function(_0x1aae97){if(_0x1aae97){return _0x1aae97['removeAgents'](_0x2c1132[_0x35b8('0x3d')][_0x35b8('0x66')])[_0x35b8('0x1e')](function(){if(_[_0x35b8('0x113')](_0x2c1132[_0x35b8('0x3d')]['ids'])){for(var _0x21e37a=0x0;_0x21e37a<_0x2c1132[_0x35b8('0x3d')]['ids'][_0x35b8('0x44')];_0x21e37a+=0x1){socket[_0x35b8('0x110')](_0x35b8('0x114'),{'UserId':Number(_0x2c1132[_0x35b8('0x3d')][_0x35b8('0x66')][_0x21e37a]),'ChatWebsiteId':Number(_0x2c1132[_0x35b8('0x51')]['id'])});}}else{socket[_0x35b8('0x110')](_0x35b8('0x114'),{'UserId':Number(_0x2c1132[_0x35b8('0x3d')][_0x35b8('0x66')]),'ChatWebsiteId':Number(_0x2c1132[_0x35b8('0x51')]['id'])});}});}})[_0x35b8('0x1e')](respondWithStatusCode(_0x379788,null))[_0x35b8('0x27')](handleError(_0x379788,null));};exports[_0x35b8('0x115')]=function(_0x28b6f3,_0x31ebbc,_0x522c4a){var _0x471482={};var _0x21e921={};var _0x33fc78;var _0x349d08;return db[_0x35b8('0x39')][_0x35b8('0x63')]({'where':{'id':_0x28b6f3[_0x35b8('0x51')]['id']}})['then'](handleEntityNotFound(_0x31ebbc,null))[_0x35b8('0x1e')](function(_0xb9b6c2){if(_0xb9b6c2){_0x33fc78=_0xb9b6c2;_0x21e921[_0x35b8('0x40')]=_[_0x35b8('0x3e')](db['User'][_0x35b8('0x3a')]);_0x21e921[_0x35b8('0x3d')]=_[_0x35b8('0x3e')](_0x28b6f3[_0x35b8('0x3d')]);_0x21e921[_0x35b8('0x3f')]=_[_0x35b8('0x42')](_0x21e921['model'],_0x21e921['query']);_0x471482[_0x35b8('0x41')]=_[_0x35b8('0x42')](_0x21e921[_0x35b8('0x40')],qs[_0x35b8('0x43')](_0x28b6f3[_0x35b8('0x3d')][_0x35b8('0x43')]));_0x471482[_0x35b8('0x41')]=_0x471482[_0x35b8('0x41')][_0x35b8('0x44')]?_0x471482[_0x35b8('0x41')]:_0x21e921['model'];_0x471482[_0x35b8('0x46')]=qs[_0x35b8('0x47')](_0x28b6f3[_0x35b8('0x3d')]['sort']);_0x471482[_0x35b8('0x4c')]=qs[_0x35b8('0x3f')](_[_0x35b8('0x48')](_0x28b6f3[_0x35b8('0x3d')],_0x21e921['filters']));if(_0x28b6f3[_0x35b8('0x3d')][_0x35b8('0x49')]){_0x471482['where']=_[_0x35b8('0x4a')](_0x471482[_0x35b8('0x4c')],{'$or':_[_0x35b8('0x38')](_0x471482[_0x35b8('0x41')],function(_0x4cb215){var _0x5e41b0={};_0x5e41b0[_0x4cb215]={'$like':'%'+_0x28b6f3['query'][_0x35b8('0x49')]+'%'};return _0x5e41b0;})});}_0x471482=_[_0x35b8('0x4a')]({},_0x471482,_0x28b6f3[_0x35b8('0x4b')]);return _0x33fc78['getAgents'](_0x471482);}})[_0x35b8('0x1e')](function(_0x341eac){if(_0x341eac){_0x349d08=_0x341eac[_0x35b8('0x44')];if(!_0x28b6f3[_0x35b8('0x3d')][_0x35b8('0x64')]('nolimit')){_0x471482[_0x35b8('0x2d')]=qs[_0x35b8('0x2d')](_0x28b6f3[_0x35b8('0x3d')][_0x35b8('0x2d')]);_0x471482[_0x35b8('0x2c')]=qs['offset'](_0x28b6f3[_0x35b8('0x3d')][_0x35b8('0x2c')]);}return _0x33fc78['getAgents'](_0x471482);}})[_0x35b8('0x1e')](function(_0x388ba2){if(_0x388ba2){return _0x388ba2?{'count':_0x349d08,'rows':_0x388ba2}:null;}})['then'](respondWithResult(_0x31ebbc,null))[_0x35b8('0x27')](handleError(_0x31ebbc,null));};