Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / chatWebsite / chatWebsite.controller.js
index 009a8be..1edc066 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xffb9=['offlineMessageSubject','MailAccountId','subjectOffline','toPairsIn','mapValues','Chat','NotifyMailAccount','notifyMail','server','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','getSnippet','timezone','iftime\x20%s,%s','interval','iftime\x20%s','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','OFFLINE','No\x20timezone','inspect','Interval','Intervals','getProactiveActions','virtual','custom','License','increment','chatLicenseExceeded','all','some','server/files/chat/iframe.ejs','utf8','x-forwarded-for','connection','alignment','verticalAlignment','labelText','textColor','textButtonColor','color_button','hideWhenOffline','IntervalId','addApplications','Transaction','ISOLATION_LEVELS','READ_COMMITTED','findAndCountAll','priority','finally','getApplications','addProactiveActions','ChatProactiveAction','getFields','online','false','offlineForm','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','emit','userChatWebsite:save','removeAgents','isArray','getAgents','bluebird','mustache','util','path','fs-extra','lodash','querystring','ioredis','../../config/logger','api','../../mysqldb','defaults','redis','localhost','./chatWebsite.socket','html-to-text','jayson/promise','client','http','request','then','info','ChatWebsite,\x20%s,\x20%s','request\x20sent','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','sendStatus','status','offset','undefined','count','json','update','destroy','get','ChatWebsites','end','stack','name','index','Pause','mandatoryDispositionPause','map','ChatWebsite','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','length','hasOwnProperty','nolimit','limit','sort','pick','filter','where','VIRTUAL','merge','options','findAll','rows','params','fields','includeAll','include','create','body','user','role','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','describe','addDisposition','ChatWebsiteId','Disposition','getDispositions','findOne','order','removeDispositions','ids','addAnswer','getAnswers','CannedAnswer','removeAnswers','addLogo','sitepic','filename','addAvatar','agentAvatar','file','customerAvatar','addSystemAvatar','systemAvatar','getLogo','join','server/files/images/logos/default_logo.svg','../../config/license/util','getLicense','isNil','existsSync','root','server/files/images/logos/','download','server/files/images/avatars/default_avatar.png','server/files/images/avatars/','showCustomerAvatar','getSystemAvatar','server/files/images/avatars/system_avatar.png','notify','user-agent-parser','setUA','headers','user-agent','getResult','chat','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','from','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','Contacts','ChatApplication','List','applications','Applications','list','orderBy','asc','account','contact','customerIp','cf-connecting-ip','first','firstName','lastName','x-real-port','referer','browser','version','format','%s\x20%s','vendor','%s\x20%s\x20%s','device','threadId','externalUrl','ChatInteraction','ContactId','interaction','spread','messageId','created','autoclose','push','close','AttachmentId','UserId','User','unshift','agent','*,*,*,*','Start','startRouting','EventManager','offline','files','send','mapKeyOffline','mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','MailAccount','findOrCreate','readFileSync','server/files/templates/chatOfflineMessage.ejs','render','ChatOfflineMessage','fromString','mimetype','attachments','offline-chat','openNewInteraction','sequelize','transaction','Attachment','bulkCreate','MailServerOut','Smtp','CloudProvider','forwardOffline','forwardOfflineAddress','getSmtpOptions','SendMail','\x22%s\x22\x20<%s>','email'];(function(_0x27eaa2,_0x18e330){var _0x3cf281=function(_0x1b79a4){while(--_0x1b79a4){_0x27eaa2['push'](_0x27eaa2['shift']());}};_0x3cf281(++_0x18e330);}(_0xffb9,0x178));var _0x9ffb=function(_0x2badd3,_0x498d1e){_0x2badd3=_0x2badd3-0x0;var _0x1b89cf=_0xffb9[_0x2badd3];return _0x1b89cf;};'use strict';var BPromise=require(_0x9ffb('0x0'));var Mustache=require(_0x9ffb('0x1'));var util=require(_0x9ffb('0x2'));var path=require(_0x9ffb('0x3'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x9ffb('0x4'));var _=require(_0x9ffb('0x5'));var querystring=require(_0x9ffb('0x6'));var Redis=require(_0x9ffb('0x7'));var qs=require('../../components/parsers/qs');var logger=require(_0x9ffb('0x8'))(_0x9ffb('0x9'));var config=require('../../config/environment');var db=require(_0x9ffb('0xa'))['db'];config['redis']=_[_0x9ffb('0xb')](config[_0x9ffb('0xc')],{'host':_0x9ffb('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9ffb('0xc')]));require(_0x9ffb('0xe'))['register'](socket);var htmlToText=require(_0x9ffb('0xf'));var jayson=require(_0x9ffb('0x10'));var client=jayson[_0x9ffb('0x11')]['http']({'port':0x232c});var client9002=jayson[_0x9ffb('0x11')][_0x9ffb('0x12')]({'port':0x232a});var client9003=jayson[_0x9ffb('0x11')]['http']({'port':0x232b});var client9001=jayson['client'][_0x9ffb('0x12')]({'port':0x2329});function respondWithRpcPromise(_0x22b01c,_0xe83deb,_0x1f1345,_0x77aa69){return new BPromise(function(_0xae05ad,_0x1ba4c8){var _0x4ec367=_0x77aa69||client;return _0x4ec367[_0x9ffb('0x13')](_0x22b01c,_0x1f1345)[_0x9ffb('0x14')](function(_0x3252c6){logger[_0x9ffb('0x15')](_0x9ffb('0x16'),_0xe83deb,_0x9ffb('0x17'));logger['debug'](_0x9ffb('0x18'),_0xe83deb,_0x9ffb('0x17'),JSON[_0x9ffb('0x19')](_0x3252c6));if(_0x3252c6['error']){if(_0x3252c6['error']['code']===0x1f4){logger[_0x9ffb('0x1a')]('ChatWebsite,\x20%s,\x20%s',_0xe83deb,_0x3252c6[_0x9ffb('0x1a')]['message']);return _0x1ba4c8(_0x3252c6[_0x9ffb('0x1a')][_0x9ffb('0x1b')]);}logger[_0x9ffb('0x1a')](_0x9ffb('0x16'),_0xe83deb,_0x3252c6['error'][_0x9ffb('0x1b')]);return _0xae05ad(_0x3252c6[_0x9ffb('0x1a')][_0x9ffb('0x1b')]);}else{logger[_0x9ffb('0x15')](_0x9ffb('0x16'),_0xe83deb,_0x9ffb('0x17'));_0xae05ad(_0x3252c6[_0x9ffb('0x1c')][_0x9ffb('0x1b')]);}})[_0x9ffb('0x1d')](function(_0x52e2b9){logger[_0x9ffb('0x1a')](_0x9ffb('0x16'),_0xe83deb,_0x52e2b9);_0x1ba4c8(_0x52e2b9);});});}function respondWithStatusCode(_0x5c9515,_0x1d5804){_0x1d5804=_0x1d5804||0xcc;return function(_0x4e176f){if(_0x4e176f){return _0x5c9515[_0x9ffb('0x1e')](_0x1d5804);}return _0x5c9515[_0x9ffb('0x1f')](_0x1d5804)['end']();};}function respondWithResult(_0xb6f82a,_0x4ac5c9){_0x4ac5c9=_0x4ac5c9||0xc8;return function(_0x519733){if(_0x519733){return _0xb6f82a['status'](_0x4ac5c9)['json'](_0x519733);}};}function respondWithFilteredResult(_0x475cd6,_0x4df7f9){return function(_0x356209){if(_0x356209){var _0xe337d2=typeof _0x4df7f9[_0x9ffb('0x20')]===_0x9ffb('0x21')&&typeof _0x4df7f9['limit']===_0x9ffb('0x21');var _0x1916e9=_0x356209[_0x9ffb('0x22')];var _0x474d20=_0xe337d2?0x0:_0x4df7f9[_0x9ffb('0x20')];var _0x583252=_0xe337d2?_0x356209['count']:_0x4df7f9[_0x9ffb('0x20')]+_0x4df7f9['limit'];var _0x16cc88;if(_0x583252>=_0x1916e9){_0x583252=_0x1916e9;_0x16cc88=0xc8;}else{_0x16cc88=0xce;}_0x475cd6[_0x9ffb('0x1f')](_0x16cc88);return _0x475cd6['set']('Content-Range',_0x474d20+'-'+_0x583252+'/'+_0x1916e9)[_0x9ffb('0x23')](_0x356209);}return null;};}function saveUpdates(_0x1f1622){return function(_0x2dc662){if(_0x2dc662){return _0x2dc662[_0x9ffb('0x24')](_0x1f1622)[_0x9ffb('0x14')](function(_0x160404){return _0x160404;});}return null;};}function removeEntity(_0xf8122b){return function(_0x59f6e1){if(_0x59f6e1){return _0x59f6e1[_0x9ffb('0x25')]()[_0x9ffb('0x14')](function(){var _0x3c39e6=_0x59f6e1[_0x9ffb('0x26')]({'plain':!![]});var _0x25da4a=_0x9ffb('0x27');return db['UserProfileResource'][_0x9ffb('0x25')]({'where':{'type':_0x25da4a,'resourceId':_0x3c39e6['id']}})['then'](function(){return _0x59f6e1;});})[_0x9ffb('0x14')](function(){_0xf8122b[_0x9ffb('0x1f')](0xcc)[_0x9ffb('0x28')]();});}};}function handleEntityNotFound(_0x284877){return function(_0x3d56da){if(!_0x3d56da){_0x284877[_0x9ffb('0x1e')](0x194);}return _0x3d56da;};}function handleError(_0x3313db,_0x22fc98){_0x22fc98=_0x22fc98||0x1f4;return function(_0x1691f3){logger[_0x9ffb('0x1a')](_0x1691f3[_0x9ffb('0x29')]);if(_0x1691f3['name']){delete _0x1691f3[_0x9ffb('0x2a')];}_0x3313db[_0x9ffb('0x1f')](_0x22fc98)['send'](_0x1691f3);};}exports[_0x9ffb('0x2b')]=function(_0x420ad7,_0xec84db){var _0x2a4afb={'include':[{'model':db[_0x9ffb('0x2c')],'as':_0x9ffb('0x2d')}]},_0x2c623b={},_0x3f0340={'count':0x0,'rows':[]};var _0x2a8fc1=_[_0x9ffb('0x2e')](db[_0x9ffb('0x2f')][_0x9ffb('0x30')],function(_0x507615){return{'name':_0x507615[_0x9ffb('0x31')],'type':_0x507615[_0x9ffb('0x32')][_0x9ffb('0x33')]};});_0x2c623b[_0x9ffb('0x34')]=_[_0x9ffb('0x2e')](_0x2a8fc1,_0x9ffb('0x2a'));_0x2c623b['query']=_[_0x9ffb('0x35')](_0x420ad7[_0x9ffb('0x36')]);_0x2c623b[_0x9ffb('0x37')]=_[_0x9ffb('0x38')](_0x2c623b[_0x9ffb('0x34')],_0x2c623b[_0x9ffb('0x36')]);_0x2a4afb[_0x9ffb('0x39')]=_[_0x9ffb('0x38')](_0x2c623b[_0x9ffb('0x34')],qs['fields'](_0x420ad7['query']['fields']));_0x2a4afb[_0x9ffb('0x39')]=_0x2a4afb['attributes'][_0x9ffb('0x3a')]?_0x2a4afb['attributes']:_0x2c623b[_0x9ffb('0x34')];if(!_0x420ad7[_0x9ffb('0x36')][_0x9ffb('0x3b')](_0x9ffb('0x3c'))){_0x2a4afb[_0x9ffb('0x3d')]=qs[_0x9ffb('0x3d')](_0x420ad7[_0x9ffb('0x36')][_0x9ffb('0x3d')]);_0x2a4afb[_0x9ffb('0x20')]=qs['offset'](_0x420ad7[_0x9ffb('0x36')][_0x9ffb('0x20')]);}_0x2a4afb['order']=qs[_0x9ffb('0x3e')](_0x420ad7['query']['sort']);_0x2a4afb['where']=qs['filters'](_[_0x9ffb('0x3f')](_0x420ad7['query'],_0x2c623b[_0x9ffb('0x37')]),_0x2a8fc1);if(_0x420ad7[_0x9ffb('0x36')][_0x9ffb('0x40')]){_0x2a4afb[_0x9ffb('0x41')]=_['merge'](_0x2a4afb[_0x9ffb('0x41')],{'$or':_['map'](_0x2a8fc1,function(_0x39578b){if(_0x39578b[_0x9ffb('0x32')]!==_0x9ffb('0x42')){var _0x5ac792={};_0x5ac792[_0x39578b[_0x9ffb('0x2a')]]={'$like':'%'+_0x420ad7['query'][_0x9ffb('0x40')]+'%'};return _0x5ac792;}})});}_0x2a4afb=_[_0x9ffb('0x43')]({},_0x2a4afb,_0x420ad7[_0x9ffb('0x44')]);var _0x105f34={'where':_0x2a4afb[_0x9ffb('0x41')]};return db[_0x9ffb('0x2f')][_0x9ffb('0x22')](_0x105f34)['then'](function(_0xf2e3a2){_0x3f0340[_0x9ffb('0x22')]=_0xf2e3a2;if(_0x420ad7[_0x9ffb('0x36')]['includeAll']){_0x2a4afb['include']=[{'all':!![]}];}return db[_0x9ffb('0x2f')][_0x9ffb('0x45')](_0x2a4afb);})[_0x9ffb('0x14')](function(_0x373875){_0x3f0340[_0x9ffb('0x46')]=_0x373875;return _0x3f0340;})[_0x9ffb('0x14')](respondWithFilteredResult(_0xec84db,_0x2a4afb))['catch'](handleError(_0xec84db,null));};exports['show']=function(_0x1d7a5e,_0x587b3a){var _0x5a9927={'raw':![],'where':{'id':_0x1d7a5e[_0x9ffb('0x47')]['id']},'include':[{'model':db['Pause'],'as':_0x9ffb('0x2d')}]},_0x56fb27={};_0x56fb27[_0x9ffb('0x34')]=_[_0x9ffb('0x35')](db[_0x9ffb('0x2f')][_0x9ffb('0x30')]);_0x56fb27[_0x9ffb('0x36')]=_[_0x9ffb('0x35')](_0x1d7a5e[_0x9ffb('0x36')]);_0x56fb27['filters']=_[_0x9ffb('0x38')](_0x56fb27[_0x9ffb('0x34')],_0x56fb27[_0x9ffb('0x36')]);_0x5a9927[_0x9ffb('0x39')]=_[_0x9ffb('0x38')](_0x56fb27[_0x9ffb('0x34')],qs[_0x9ffb('0x48')](_0x1d7a5e['query'][_0x9ffb('0x48')]));_0x5a9927[_0x9ffb('0x39')]=_0x5a9927[_0x9ffb('0x39')][_0x9ffb('0x3a')]?_0x5a9927[_0x9ffb('0x39')]:_0x56fb27[_0x9ffb('0x34')];if(_0x1d7a5e[_0x9ffb('0x36')][_0x9ffb('0x49')]){_0x5a9927[_0x9ffb('0x4a')]=[{'all':!![]}];}_0x5a9927=_[_0x9ffb('0x43')]({},_0x5a9927,_0x1d7a5e[_0x9ffb('0x44')]);return db[_0x9ffb('0x2f')]['find'](_0x5a9927)['then'](handleEntityNotFound(_0x587b3a,null))['then'](respondWithResult(_0x587b3a,null))[_0x9ffb('0x1d')](handleError(_0x587b3a,null));};exports['create']=function(_0x127db2,_0x9ded67){return db[_0x9ffb('0x2f')][_0x9ffb('0x4b')](_0x127db2[_0x9ffb('0x4c')],{})['then'](function(_0x72d4fa){var _0x246e6c=_0x127db2[_0x9ffb('0x4d')][_0x9ffb('0x26')]({'plain':!![]});if(!_0x246e6c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x246e6c[_0x9ffb('0x4e')]==='user'){var _0x2d4ce5=_0x72d4fa[_0x9ffb('0x26')]({'plain':!![]});var _0x3dcc81=_0x9ffb('0x27');return db['UserProfileSection']['find']({'where':{'name':_0x3dcc81,'userProfileId':_0x246e6c[_0x9ffb('0x4f')]},'raw':!![]})['then'](function(_0x59e035){if(_0x59e035&&_0x59e035[_0x9ffb('0x50')]===0x0){return db[_0x9ffb('0x51')]['create']({'name':_0x2d4ce5['name'],'resourceId':_0x2d4ce5['id'],'type':_0x59e035[_0x9ffb('0x2a')],'sectionId':_0x59e035['id']},{})[_0x9ffb('0x14')](function(){return _0x72d4fa;});}else{return _0x72d4fa;}})[_0x9ffb('0x1d')](function(_0x20d446){logger[_0x9ffb('0x1a')](_0x9ffb('0x52'),_0x20d446);throw _0x20d446;});}return _0x72d4fa;})['then'](respondWithResult(_0x9ded67,0xc9))[_0x9ffb('0x1d')](handleError(_0x9ded67,null));};exports[_0x9ffb('0x24')]=function(_0x22dafc,_0xed4bc){if(_0x22dafc[_0x9ffb('0x4c')]['id']){delete _0x22dafc[_0x9ffb('0x4c')]['id'];}return db['ChatWebsite'][_0x9ffb('0x53')]({'where':{'id':_0x22dafc[_0x9ffb('0x47')]['id']},'include':[{'model':db[_0x9ffb('0x2c')],'as':'mandatoryDispositionPause'}]})[_0x9ffb('0x14')](handleEntityNotFound(_0xed4bc,null))[_0x9ffb('0x14')](saveUpdates(_0x22dafc[_0x9ffb('0x4c')],null))[_0x9ffb('0x14')](respondWithResult(_0xed4bc,null))[_0x9ffb('0x1d')](handleError(_0xed4bc,null));};exports[_0x9ffb('0x25')]=function(_0x41f349,_0x1e3bb4){return db['ChatWebsite']['find']({'where':{'id':_0x41f349[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x1e3bb4,null))[_0x9ffb('0x14')](removeEntity(_0x1e3bb4,null))['catch'](handleError(_0x1e3bb4,null));};exports[_0x9ffb('0x54')]=function(_0x561252,_0x560be6){return db[_0x9ffb('0x2f')][_0x9ffb('0x54')]()[_0x9ffb('0x14')](respondWithResult(_0x560be6,null))[_0x9ffb('0x1d')](handleError(_0x560be6,null));};exports[_0x9ffb('0x55')]=function(_0x3beaef,_0x59ecc8){if(_0x3beaef['body']['id']){delete _0x3beaef[_0x9ffb('0x4c')]['id'];}return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0x3beaef['params']['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x59ecc8,null))[_0x9ffb('0x14')](function(_0x32e40f){if(_0x32e40f){_0x3beaef['body'][_0x9ffb('0x56')]=_0x32e40f['id'];return db[_0x9ffb('0x57')]['create'](_0x3beaef[_0x9ffb('0x4c')]);}})[_0x9ffb('0x14')](respondWithResult(_0x59ecc8,null))[_0x9ffb('0x1d')](handleError(_0x59ecc8,null));};exports[_0x9ffb('0x58')]=function(_0x5fdf52,_0x5e82c9){var _0x5449f2={'raw':![],'where':{}};var _0x36e640={};var _0x38ef37={'count':0x0,'rows':[]};return db['ChatWebsite'][_0x9ffb('0x59')]({'where':{'id':_0x5fdf52[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0x5e82c9,null))['then'](function(_0x43266b){if(_0x43266b){_0x36e640['model']=_[_0x9ffb('0x35')](db['Disposition'][_0x9ffb('0x30')]);_0x36e640[_0x9ffb('0x36')]=_[_0x9ffb('0x35')](_0x5fdf52[_0x9ffb('0x36')]);_0x36e640[_0x9ffb('0x37')]=_['intersection'](_0x36e640[_0x9ffb('0x34')],_0x36e640[_0x9ffb('0x36')]);_0x5449f2['attributes']=_[_0x9ffb('0x38')](_0x36e640[_0x9ffb('0x34')],qs[_0x9ffb('0x48')](_0x5fdf52[_0x9ffb('0x36')][_0x9ffb('0x48')]));_0x5449f2['attributes']=_0x5449f2[_0x9ffb('0x39')]['length']?_0x5449f2['attributes']:_0x36e640[_0x9ffb('0x34')];if(!_0x5fdf52[_0x9ffb('0x36')][_0x9ffb('0x3b')](_0x9ffb('0x3c'))){_0x5449f2['limit']=qs[_0x9ffb('0x3d')](_0x5fdf52[_0x9ffb('0x36')][_0x9ffb('0x3d')]);_0x5449f2[_0x9ffb('0x20')]=qs[_0x9ffb('0x20')](_0x5fdf52[_0x9ffb('0x36')][_0x9ffb('0x20')]);}_0x5449f2[_0x9ffb('0x5a')]=qs[_0x9ffb('0x3e')](_0x5fdf52[_0x9ffb('0x36')][_0x9ffb('0x3e')]);_0x5449f2[_0x9ffb('0x41')]=qs[_0x9ffb('0x37')](_['pick'](_0x5fdf52[_0x9ffb('0x36')],_0x36e640[_0x9ffb('0x37')]));_0x5449f2[_0x9ffb('0x41')][_0x9ffb('0x56')]=_0x43266b['id'];if(_0x5fdf52[_0x9ffb('0x36')]['filter']){_0x5449f2[_0x9ffb('0x41')]=_['merge'](_0x5449f2[_0x9ffb('0x41')],{'$or':_['map'](_0x5449f2['attributes'],function(_0x37ff01){var _0x1558bb={};_0x1558bb[_0x37ff01]={'$like':'%'+_0x5fdf52[_0x9ffb('0x36')]['filter']+'%'};return _0x1558bb;})});}_0x5449f2=_['merge']({},_0x5449f2,_0x5fdf52[_0x9ffb('0x44')]);return db[_0x9ffb('0x57')][_0x9ffb('0x22')]({'where':_0x5449f2[_0x9ffb('0x41')]})[_0x9ffb('0x14')](function(_0x9a6916){_0x38ef37[_0x9ffb('0x22')]=_0x9a6916;if(_0x5fdf52[_0x9ffb('0x36')]['includeAll']){_0x5449f2['include']=[{'all':!![]}];}return db[_0x9ffb('0x57')][_0x9ffb('0x45')](_0x5449f2);})[_0x9ffb('0x14')](function(_0xb39325){_0x38ef37[_0x9ffb('0x46')]=_0xb39325;return _0x38ef37;});}})[_0x9ffb('0x14')](respondWithFilteredResult(_0x5e82c9,_0x5449f2))['catch'](handleError(_0x5e82c9,null));};exports[_0x9ffb('0x5b')]=function(_0x3dd56b,_0x60db44){return db['ChatWebsite'][_0x9ffb('0x53')]({'where':{'id':_0x3dd56b[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x60db44,null))[_0x9ffb('0x14')](function(_0x55ed5f){if(_0x55ed5f){return _0x55ed5f['removeDispositions'](_0x3dd56b['query'][_0x9ffb('0x5c')]);}})[_0x9ffb('0x14')](respondWithStatusCode(_0x60db44,null))['catch'](handleError(_0x60db44,null));};exports[_0x9ffb('0x5d')]=function(_0x23b3c6,_0xbd8cbc){if(_0x23b3c6['body']['id']){delete _0x23b3c6[_0x9ffb('0x4c')]['id'];}return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0x23b3c6[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0xbd8cbc,null))[_0x9ffb('0x14')](function(_0x237f4b){if(_0x237f4b){_0x23b3c6[_0x9ffb('0x4c')][_0x9ffb('0x56')]=_0x237f4b['id'];return db['CannedAnswer'][_0x9ffb('0x4b')](_0x23b3c6[_0x9ffb('0x4c')]);}})[_0x9ffb('0x14')](respondWithResult(_0xbd8cbc,null))[_0x9ffb('0x1d')](handleError(_0xbd8cbc,null));};exports[_0x9ffb('0x5e')]=function(_0x4c6f61,_0x5377b0){var _0x5de4e1={'raw':![],'where':{}};var _0xa6c4e={};var _0x48a342={'count':0x0,'rows':[]};return db[_0x9ffb('0x2f')]['findOne']({'where':{'id':_0x4c6f61['params']['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x5377b0,null))[_0x9ffb('0x14')](function(_0x32583f){if(_0x32583f){_0xa6c4e[_0x9ffb('0x34')]=_[_0x9ffb('0x35')](db[_0x9ffb('0x5f')][_0x9ffb('0x30')]);_0xa6c4e[_0x9ffb('0x36')]=_[_0x9ffb('0x35')](_0x4c6f61[_0x9ffb('0x36')]);_0xa6c4e[_0x9ffb('0x37')]=_['intersection'](_0xa6c4e[_0x9ffb('0x34')],_0xa6c4e[_0x9ffb('0x36')]);_0x5de4e1[_0x9ffb('0x39')]=_[_0x9ffb('0x38')](_0xa6c4e['model'],qs['fields'](_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x48')]));_0x5de4e1[_0x9ffb('0x39')]=_0x5de4e1['attributes'][_0x9ffb('0x3a')]?_0x5de4e1['attributes']:_0xa6c4e[_0x9ffb('0x34')];if(!_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x3b')]('nolimit')){_0x5de4e1['limit']=qs[_0x9ffb('0x3d')](_0x4c6f61[_0x9ffb('0x36')]['limit']);_0x5de4e1['offset']=qs['offset'](_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x20')]);}_0x5de4e1[_0x9ffb('0x5a')]=qs[_0x9ffb('0x3e')](_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x3e')]);_0x5de4e1[_0x9ffb('0x41')]=qs[_0x9ffb('0x37')](_[_0x9ffb('0x3f')](_0x4c6f61[_0x9ffb('0x36')],_0xa6c4e[_0x9ffb('0x37')]));_0x5de4e1[_0x9ffb('0x41')][_0x9ffb('0x56')]=_0x32583f['id'];if(_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x40')]){_0x5de4e1[_0x9ffb('0x41')]=_[_0x9ffb('0x43')](_0x5de4e1[_0x9ffb('0x41')],{'$or':_[_0x9ffb('0x2e')](_0x5de4e1[_0x9ffb('0x39')],function(_0x299744){var _0x563f1d={};_0x563f1d[_0x299744]={'$like':'%'+_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x40')]+'%'};return _0x563f1d;})});}_0x5de4e1=_[_0x9ffb('0x43')]({},_0x5de4e1,_0x4c6f61['options']);return db[_0x9ffb('0x5f')][_0x9ffb('0x22')]({'where':_0x5de4e1[_0x9ffb('0x41')]})[_0x9ffb('0x14')](function(_0x3d8351){_0x48a342['count']=_0x3d8351;if(_0x4c6f61[_0x9ffb('0x36')][_0x9ffb('0x49')]){_0x5de4e1[_0x9ffb('0x4a')]=[{'all':!![]}];}return db[_0x9ffb('0x5f')][_0x9ffb('0x45')](_0x5de4e1);})[_0x9ffb('0x14')](function(_0x4f9b92){_0x48a342['rows']=_0x4f9b92;return _0x48a342;});}})[_0x9ffb('0x14')](respondWithFilteredResult(_0x5377b0,_0x5de4e1))[_0x9ffb('0x1d')](handleError(_0x5377b0,null));};exports[_0x9ffb('0x60')]=function(_0x2ba79b,_0x6c8d5){return db['ChatWebsite'][_0x9ffb('0x53')]({'where':{'id':_0x2ba79b['params']['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x6c8d5,null))[_0x9ffb('0x14')](function(_0x18144d){if(_0x18144d){return _0x18144d[_0x9ffb('0x60')](_0x2ba79b['query'][_0x9ffb('0x5c')]);}})[_0x9ffb('0x14')](respondWithStatusCode(_0x6c8d5,null))[_0x9ffb('0x1d')](handleError(_0x6c8d5,null));};exports[_0x9ffb('0x61')]=function(_0x3e0f30,_0x32bdfb){_0x3e0f30['body'][_0x9ffb('0x62')]=_0x3e0f30['file'][_0x9ffb('0x63')];return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0x3e0f30[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x32bdfb,null))[_0x9ffb('0x14')](saveUpdates(_0x3e0f30[_0x9ffb('0x4c')],null))['then'](respondWithResult(_0x32bdfb,null))[_0x9ffb('0x1d')](handleError(_0x32bdfb,null));};exports[_0x9ffb('0x64')]=function(_0x208001,_0x207b9e){_0x208001[_0x9ffb('0x4c')][_0x9ffb('0x65')]=_0x208001[_0x9ffb('0x66')][_0x9ffb('0x63')];return db[_0x9ffb('0x2f')]['find']({'where':{'id':_0x208001[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0x207b9e,null))[_0x9ffb('0x14')](saveUpdates(_0x208001[_0x9ffb('0x4c')],null))[_0x9ffb('0x14')](respondWithResult(_0x207b9e,null))[_0x9ffb('0x1d')](handleError(_0x207b9e,null));};exports['addCustomerAvatar']=function(_0x35b5f7,_0x3db1dd){_0x35b5f7[_0x9ffb('0x4c')][_0x9ffb('0x67')]=_0x35b5f7[_0x9ffb('0x66')][_0x9ffb('0x63')];return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0x35b5f7[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x3db1dd,null))['then'](saveUpdates(_0x35b5f7['body'],null))[_0x9ffb('0x14')](respondWithResult(_0x3db1dd,null))[_0x9ffb('0x1d')](handleError(_0x3db1dd,null));};exports[_0x9ffb('0x68')]=function(_0xbf2ef7,_0x5b7f6f){_0xbf2ef7[_0x9ffb('0x4c')][_0x9ffb('0x69')]=_0xbf2ef7['file']['filename'];return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0xbf2ef7[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x5b7f6f,null))[_0x9ffb('0x14')](saveUpdates(_0xbf2ef7[_0x9ffb('0x4c')],null))['then'](respondWithResult(_0x5b7f6f,null))[_0x9ffb('0x1d')](handleError(_0x5b7f6f,null));};exports[_0x9ffb('0x6a')]=function(_0x1d1c39,_0x20fa31){var _0x2f99a1=path[_0x9ffb('0x6b')](config['root'],_0x9ffb('0x6c'));var _0x3c3b59={'where':{'id':_0x1d1c39[_0x9ffb('0x47')]['id']},'attributes':['id',_0x9ffb('0x62')],'raw':!![]};var _0x874a31=![];return require(_0x9ffb('0x6d'))[_0x9ffb('0x6e')]()[_0x9ffb('0x14')](function(_0x162dd2){if(_0x162dd2){_0x874a31=_0x162dd2['custom'];}})[_0x9ffb('0x14')](function(){return db[_0x9ffb('0x2f')]['find'](_0x3c3b59);})[_0x9ffb('0x14')](handleEntityNotFound(_0x20fa31,null))[_0x9ffb('0x14')](function(_0x35d75c){if(_0x35d75c){if(!_[_0x9ffb('0x6f')](_0x35d75c[_0x9ffb('0x62')])){if(fs[_0x9ffb('0x70')](path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0x72'),_0x35d75c[_0x9ffb('0x62')]))&&_0x874a31){_0x2f99a1=path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0x72'),_0x35d75c[_0x9ffb('0x62')]);}}return _0x20fa31[_0x9ffb('0x73')](_0x2f99a1);}})[_0x9ffb('0x1d')](handleError(_0x20fa31,null));};exports['getAvatar']=function(_0x52fa23,_0x31317f){var _0x526c86=path[_0x9ffb('0x6b')](config['root'],_0x9ffb('0x74'));var _0x594321={'where':{'id':_0x52fa23[_0x9ffb('0x47')]['id']},'attributes':['id',_0x9ffb('0x65')],'raw':!![]};return db[_0x9ffb('0x2f')][_0x9ffb('0x53')](_0x594321)['then'](handleEntityNotFound(_0x31317f,null))[_0x9ffb('0x14')](function(_0x1de443){if(_0x1de443){if(!_['isNil'](_0x1de443[_0x9ffb('0x65')])){if(fs[_0x9ffb('0x70')](path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0x75'),_0x1de443[_0x9ffb('0x65')]))){_0x526c86=path[_0x9ffb('0x6b')](config['root'],_0x9ffb('0x75'),_0x1de443['agentAvatar']);}}return _0x31317f['download'](_0x526c86);}})[_0x9ffb('0x1d')](handleError(_0x31317f,null));};exports['getCustomerAvatar']=function(_0x7b9499,_0x56d2a3){var _0x3a0ad2=path['join'](config[_0x9ffb('0x71')],'server/files/images/avatars/customer_avatar.png');var _0x2cf175={'where':{'id':_0x7b9499[_0x9ffb('0x47')]['id']},'attributes':['id',_0x9ffb('0x67'),_0x9ffb('0x76')],'raw':!![]};return db['ChatWebsite'][_0x9ffb('0x53')](_0x2cf175)[_0x9ffb('0x14')](handleEntityNotFound(_0x56d2a3,null))[_0x9ffb('0x14')](function(_0x58437f){if(_0x58437f){if(!_[_0x9ffb('0x6f')](_0x58437f['customerAvatar'])){if(fs[_0x9ffb('0x70')](path['join'](config[_0x9ffb('0x71')],'server/files/images/avatars/',_0x58437f[_0x9ffb('0x67')]))&&_0x58437f[_0x9ffb('0x76')]){_0x3a0ad2=path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0x75'),_0x58437f[_0x9ffb('0x67')]);}}return _0x56d2a3['download'](_0x3a0ad2);}})['catch'](handleError(_0x56d2a3,null));};exports[_0x9ffb('0x77')]=function(_0x2048e9,_0xdd3d87){var _0x5aa0b8=path['join'](config[_0x9ffb('0x71')],_0x9ffb('0x78'));var _0x47688a={'where':{'id':_0x2048e9[_0x9ffb('0x47')]['id']},'attributes':['id',_0x9ffb('0x69')],'raw':!![]};return db['ChatWebsite'][_0x9ffb('0x53')](_0x47688a)[_0x9ffb('0x14')](handleEntityNotFound(_0xdd3d87,null))[_0x9ffb('0x14')](function(_0x3cc0e9){if(_0x3cc0e9){if(!_[_0x9ffb('0x6f')](_0x3cc0e9[_0x9ffb('0x69')])){if(fs['existsSync'](path[_0x9ffb('0x6b')](config['root'],_0x9ffb('0x75'),_0x3cc0e9[_0x9ffb('0x69')]))){_0x5aa0b8=path['join'](config[_0x9ffb('0x71')],_0x9ffb('0x75'),_0x3cc0e9[_0x9ffb('0x69')]);}}return _0xdd3d87[_0x9ffb('0x73')](_0x5aa0b8);}})[_0x9ffb('0x1d')](handleError(_0xdd3d87,null));};exports[_0x9ffb('0x79')]=function(_0x2f516e,_0x597987){var _0x43ef9f=require(_0x9ffb('0x7a'));var _0x3e7c6b=new _0x43ef9f();var _0x57d75b=_0x3e7c6b[_0x9ffb('0x7b')](_0x2f516e[_0x9ffb('0x7c')][_0x9ffb('0x7d')])[_0x9ffb('0x7e')]();var _0x6272a5={'body':_0x2f516e[_0x9ffb('0x4c')],'channel':_0x9ffb('0x7f')};var _0x1c7949=[];var _0x39d0bf=[];var _0xb4e7fb={};var _0x40fbeb=![];return db[_0x9ffb('0x80')]['describe']()[_0x9ffb('0x14')](function(_0x53c7eb){if(!_0x53c7eb){throw new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))](_0x9ffb('0x83'));}_0x1c7949=_[_0x9ffb('0x84')](_[_0x9ffb('0x35')](_0x53c7eb),[_0x9ffb('0x85'),_0x9ffb('0x86')]);_0x39d0bf=_['difference'](_[_0x9ffb('0x35')](_0x53c7eb),['createdAt',_0x9ffb('0x86'),_0x9ffb('0x87'),'ListId']);if(_0x2f516e[_0x9ffb('0x4c')]['id']){delete _0x2f516e[_0x9ffb('0x4c')]['id'];}if(_[_0x9ffb('0x6f')](_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x88')])){throw new db['Sequelize']['ValidationError'](_0x9ffb('0x89'));}if(_[_0x9ffb('0x6f')](_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x4c')])||_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x4c')]===''){throw new db['Sequelize'][(_0x9ffb('0x82'))](_0x9ffb('0x8a'));}if(_[_0x9ffb('0x6f')](_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x8b')])){throw new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))](_0x9ffb('0x8c')+_0x39d0bf);}if(!_[_0x9ffb('0x8d')](_0x39d0bf,_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x8b')])){throw new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))](_0x9ffb('0x8e')+_0x39d0bf);}_0xb4e7fb[_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x8b')]]=_0x2f516e[_0x9ffb('0x4c')]['from'];})['then'](function(){return db[_0x9ffb('0x2f')]['find']({'where':{'id':_0x2f516e[_0x9ffb('0x47')]['id']},'include':[{'model':db[_0x9ffb('0x8f')],'as':'List','include':[{'model':db['CmContact'],'as':_0x9ffb('0x90'),'where':_0xb4e7fb,'limit':0x1,'order':[[_0x9ffb('0x86'),'DESC']]}]},{'model':db[_0x9ffb('0x91')],'as':'Applications'}]});})[_0x9ffb('0x14')](handleEntityNotFound(_0x597987,null))[_0x9ffb('0x14')](function(_0x1ffe4b){if(_0x1ffe4b&&_0x1ffe4b[_0x9ffb('0x92')]){_0x6272a5['account']=_0x1ffe4b;_0x6272a5[_0x9ffb('0x93')]=_0x1ffe4b[_0x9ffb('0x94')];_0x6272a5[_0x9ffb('0x95')]=_0x1ffe4b[_0x9ffb('0x92')];_0x6272a5['applications']=_[_0x9ffb('0x96')](_0x6272a5['applications'],['priority'],[_0x9ffb('0x97')]);if(_0x6272a5[_0x9ffb('0x98')][_0x9ffb('0x94')]){delete _0x6272a5[_0x9ffb('0x98')]['Applications'];}if(_0x6272a5[_0x9ffb('0x98')][_0x9ffb('0x92')]&&_0x6272a5[_0x9ffb('0x98')]['List'][_0x9ffb('0x90')][_0x9ffb('0x3a')]){return _0x6272a5[_0x9ffb('0x98')][_0x9ffb('0x92')]['Contacts'][0x0];}var _0x4a8b10=_[_0x9ffb('0xb')](_0x2f516e[_0x9ffb('0x4c')],{'firstName':_0x2f516e['body'][_0x9ffb('0x88')],'ListId':_0x1ffe4b['ListId']});_0x4a8b10[_0x2f516e['body']['mapKey']]=_0x2f516e['body']['from'];return db[_0x9ffb('0x80')][_0x9ffb('0x4b')](_0x4a8b10,{'fields':_0x1c7949,'raw':!![]});}})[_0x9ffb('0x14')](handleEntityNotFound(_0x597987,null))[_0x9ffb('0x14')](function(_0x1a8d40){_0x6272a5[_0x9ffb('0x99')]=_0x1a8d40;var _0x218a5a=_0x2f516e['body'][_0x9ffb('0x9a')];if(_0x2f516e['headers'][_0x9ffb('0x9b')]){_0x218a5a=_0x2f516e[_0x9ffb('0x7c')][_0x9ffb('0x9b')];}else if(_0x2f516e[_0x9ffb('0x7c')]['x-forwarded-for']){_0x218a5a=_[_0x9ffb('0x9c')](_0x2f516e[_0x9ffb('0x7c')]['x-forwarded-for']['split'](','));}if(_0x1a8d40){var _0x570c47={'ContactId':_0x1a8d40['id'],'ChatWebsiteId':_0x2f516e['params']['id'],'from':(_0x1a8d40[_0x9ffb('0x9d')]||'')+'\x20'+(_0x1a8d40[_0x9ffb('0x9e')]||''),'customerIp':_0x218a5a,'customerPort':_0x2f516e[_0x9ffb('0x7c')][_0x9ffb('0x9f')]?_0x2f516e['headers'][_0x9ffb('0x9f')]:null,'referer':_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xa0')],'browserName':_0x57d75b[_0x9ffb('0xa1')][_0x9ffb('0x2a')]&&_0x57d75b['browser'][_0x9ffb('0xa2')]?util[_0x9ffb('0xa3')](_0x9ffb('0xa4'),_0x57d75b[_0x9ffb('0xa1')][_0x9ffb('0x2a')],_0x57d75b[_0x9ffb('0xa1')][_0x9ffb('0xa2')]):'unknown','browserVersion':_0x57d75b[_0x9ffb('0xa1')][_0x9ffb('0xa2')]||'unknown','osName':util[_0x9ffb('0xa3')](_0x9ffb('0xa4'),_0x57d75b['os'][_0x9ffb('0x2a')],_0x57d75b['os'][_0x9ffb('0xa2')]),'osVersion':_0x57d75b['os'][_0x9ffb('0xa2')],'deviceModel':_0x57d75b['device'][_0x9ffb('0x34')]&&_0x57d75b['device'][_0x9ffb('0xa5')]?util[_0x9ffb('0xa3')](_0x9ffb('0xa6'),_0x57d75b[_0x9ffb('0xa7')][_0x9ffb('0x34')],_0x57d75b[_0x9ffb('0xa7')][_0x9ffb('0xa5')],_0x57d75b['device'][_0x9ffb('0x32')]):null,'deviceVendor':_0x57d75b[_0x9ffb('0xa7')][_0x9ffb('0xa5')],'deviceType':_0x57d75b['device'][_0x9ffb('0x32')],'formData':JSON[_0x9ffb('0x19')](_0x2f516e['body'])};var _0x303963={'ChatWebsiteId':_0x2f516e[_0x9ffb('0x47')]['id'],'closed':![]};if(_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xa8')]){_0x303963[_0x9ffb('0xa8')]=_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xa8')];return db['ChatInteraction'][_0x9ffb('0x53')]({'where':_0x303963})[_0x9ffb('0x14')](function(_0x5b8d3c){if(_0x5b8d3c){return[_0x5b8d3c,![]];}_0x570c47[_0x9ffb('0xa8')]=_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xa8')];_0x570c47[_0x9ffb('0xa9')]=_0x2f516e['body'][_0x9ffb('0xa9')];return db[_0x9ffb('0xaa')]['create'](_0x570c47)[_0x9ffb('0x14')](function(_0x4a9806){return[_0x4a9806,!![]];});});}_0x303963[_0x9ffb('0xab')]=_0x1a8d40['id'];if(_0x2f516e[_0x9ffb('0x4c')]['interaction']&&_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xac')]['id']){_0x303963['id']=_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xac')]['id'];return db[_0x9ffb('0xaa')][_0x9ffb('0x53')]({'where':_0x303963})[_0x9ffb('0x14')](function(_0x3434e9){if(_0x3434e9){return[_0x3434e9,![]];}return db['ChatInteraction'][_0x9ffb('0x4b')](_0x570c47)[_0x9ffb('0x14')](function(_0xe2919a){return[_0xe2919a,!![]];});});}return db[_0x9ffb('0xaa')][_0x9ffb('0x4b')](_0x570c47)[_0x9ffb('0x14')](function(_0x4f7992){return[_0x4f7992,!![]];});}})[_0x9ffb('0xad')](function(_0x295435,_0x34a8dd){if(_0x295435){_0x40fbeb=_0x34a8dd;if(!_0x34a8dd){var _0x16c1d5={'from':(_0x6272a5[_0x9ffb('0x99')]['firstName']||'')+'\x20'+(_0x6272a5['contact'][_0x9ffb('0x9e')]||'')};if(_0x2f516e['body'][_0x9ffb('0xa8')]&&_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xae')]&&_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xa8')]!=_0x2f516e['body']['messageId']){_0x16c1d5['threadId']=_0x2f516e['body']['messageId'];}return _0x295435[_0x9ffb('0x24')](_0x16c1d5);}else{return _0x295435;}}})[_0x9ffb('0x14')](function(_0x4c3079){_0x6272a5[_0x9ffb('0xac')]=_0x4c3079['get']({'plain':!![]});_0x6272a5[_0x9ffb('0xac')][_0x9ffb('0xaf')]=_0x40fbeb;if(_0x6272a5[_0x9ffb('0xac')][_0x9ffb('0xaf')]){if(_0x6272a5[_0x9ffb('0x98')][_0x9ffb('0xb0')]){_0x6272a5['applications'][_0x9ffb('0xb1')]({'id':0x0,'priority':_0x6272a5[_0x9ffb('0x93')]['length']+0x1,'app':_0x9ffb('0xb2'),'appdata':'unmanaged','interval':'*,*,*,*'});}}return db['ChatMessage']['create']({'body':_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0x4c')],'ChatWebsiteId':_0x2f516e['params']['id'],'ChatInteractionId':_0x4c3079['id'],'direction':'in','ContactId':_0x6272a5[_0x9ffb('0x99')]['id'],'AttachmentId':_0x2f516e[_0x9ffb('0x4c')][_0x9ffb('0xb3')]});})[_0x9ffb('0x14')](function(_0x3d0734){_0x6272a5[_0x9ffb('0x1b')]=_0x3d0734;if(_0x6272a5['interaction'][_0x9ffb('0xb4')]){return db[_0x9ffb('0xb5')][_0x9ffb('0x53')]({'attributes':['id',_0x9ffb('0x2a')],'where':{'id':_0x6272a5[_0x9ffb('0xac')][_0x9ffb('0xb4')]}})[_0x9ffb('0x14')](function(_0x5505d9){if(_0x5505d9){_0x6272a5[_0x9ffb('0x93')][_0x9ffb('0xb6')]({'id':0x0,'priority':0x0,'app':_0x9ffb('0xb7'),'appdata':_0x5505d9['name']+','+(_0x6272a5[_0x9ffb('0x98')]['waitForTheAssignedAgent']||0xa),'interval':_0x9ffb('0xb8')});_0x6272a5['forcedOwnership']=!![];}return respondWithRpcPromise(_0x9ffb('0xb9'),_0x9ffb('0xba'),_0x6272a5);});}return respondWithRpcPromise(_0x9ffb('0xb9'),_0x9ffb('0xba'),_0x6272a5);})[_0x9ffb('0x14')](function(_0x387f01){respondWithRpcPromise(_0x9ffb('0xbb'),_0x9ffb('0xbb'),{'event':_0x9ffb('0x79'),'message':_0x387f01},client9002);return _0x387f01;})[_0x9ffb('0x14')](respondWithResult(_0x597987,null))[_0x9ffb('0x1d')](handleError(_0x597987,null));};exports[_0x9ffb('0xbc')]=function(_0x4db7ca,_0x671374){var _0x240c6a,_0x108926,_0x89de1;var _0x8952d4=[];var _0x27a95e={};var _0x125106=_0x4db7ca[_0x9ffb('0xbd')]||[];var _0x44bcc1=[];var _0x444052;return db['CmContact'][_0x9ffb('0x54')]()[_0x9ffb('0x14')](function(_0x180e92){if(!_0x180e92){throw new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))](_0x9ffb('0x83'));}_0x8952d4=_[_0x9ffb('0x84')](_['keys'](_0x180e92),[_0x9ffb('0x85'),_0x9ffb('0x86'),_0x9ffb('0x87'),'ListId']);if(_0x4db7ca[_0x9ffb('0x4c')]['id']){delete _0x4db7ca[_0x9ffb('0x4c')]['id'];}if(_[_0x9ffb('0x6f')](_0x4db7ca['body'][_0x9ffb('0x88')])){throw _0x671374[_0x9ffb('0x1f')](0x1f4)[_0x9ffb('0xbe')](new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))](_0x9ffb('0x89')));}if(_[_0x9ffb('0x6f')](_0x4db7ca[_0x9ffb('0x4c')][_0x9ffb('0x4c')])||_0x4db7ca[_0x9ffb('0x4c')]['body']===''){throw _0x671374[_0x9ffb('0x1f')](0x1f4)[_0x9ffb('0xbe')](new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))]('body\x20is\x20mandatory\x20and\x20not\x20empty'));}if(_[_0x9ffb('0x6f')](_0x4db7ca['body'][_0x9ffb('0xbf')])){throw _0x671374[_0x9ffb('0x1f')](0x1f4)[_0x9ffb('0xbe')](new db[(_0x9ffb('0x81'))][(_0x9ffb('0x82'))](_0x9ffb('0xc0')+_0x8952d4));}if(!_[_0x9ffb('0x8d')](_0x8952d4,_0x4db7ca['body']['mapKeyOffline'])){throw _0x671374[_0x9ffb('0x1f')](0x1f4)[_0x9ffb('0xbe')](new db[(_0x9ffb('0x81'))]['ValidationError'](_0x9ffb('0xc1')+_0x8952d4));}_0x27a95e[_0x4db7ca[_0x9ffb('0x4c')][_0x9ffb('0xbf')]]=_0x4db7ca['body'][_0x9ffb('0x88')];})[_0x9ffb('0x14')](function(){return db['ChatWebsite'][_0x9ffb('0x53')]({'where':{'id':_0x4db7ca['params']['id']},'include':[{'model':db[_0x9ffb('0x8f')],'as':'List'},{'model':db[_0x9ffb('0xc2')],'as':_0x9ffb('0xc2')}]});})[_0x9ffb('0x14')](handleEntityNotFound(_0x671374,null))[_0x9ffb('0x14')](function(_0x504fb0){if(_0x504fb0&&_0x504fb0[_0x9ffb('0x92')]){_0x108926=_0x504fb0;var _0x21b511=_[_0x9ffb('0xb')](_0x4db7ca['body'],{'firstName':_0x4db7ca['body'][_0x9ffb('0x88')],'phone':_0x4db7ca[_0x9ffb('0x4c')][_0x9ffb('0x88')],'ListId':_0x504fb0['ListId']});_0x21b511[_0x4db7ca[_0x9ffb('0x4c')][_0x9ffb('0xbf')]]=_0x4db7ca[_0x9ffb('0x4c')][_0x9ffb('0x88')];return db['CmContact'][_0x9ffb('0xc3')]({'where':_0x27a95e,'defaults':_0x21b511});}})[_0x9ffb('0xad')](function(_0x30e5c4){if(_0x30e5c4){_0x89de1=_0x30e5c4;var _0x4f1fa9=fs[_0x9ffb('0xc4')](path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0xc5')),'utf8');var _0x5b9bb0=ejs[_0x9ffb('0xc6')](_0x4f1fa9,{'body':_['toPairs'](_0x4db7ca[_0x9ffb('0x4c')][_0x9ffb('0x4c')]),'bodyTitle':_0x108926['offlineMessageBody']});return db[_0x9ffb('0xc7')][_0x9ffb('0x4b')]({'body':_0x5b9bb0,'plainBody':htmlToText[_0x9ffb('0xc8')](_0x5b9bb0),'ContactId':_0x30e5c4['id'],'ChatWebsiteId':_0x108926['id']});}})[_0x9ffb('0x14')](function(_0x1bca15){_0x444052=_0x1bca15;if(_0x125106[_0x9ffb('0x3a')]){var _0xf80c2e=_0x125106[_0x9ffb('0x2e')](function(_0x3a8e3c){return{'name':_0x3a8e3c['originalname'],'basename':_0x3a8e3c[_0x9ffb('0x63')],'type':_0x3a8e3c[_0x9ffb('0xc9')],'ChatOfflineMessageId':_0x1bca15['id']};});_0x44bcc1=_0xf80c2e[_0x9ffb('0x2e')](_0xfbb55b=>{var _0x32bc2a={'filename':_0xfbb55b[_0x9ffb('0x2a')],'path':path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],'server',_0x9ffb('0xbd'),_0x9ffb('0xca'),_0x9ffb('0xcb'),_0xfbb55b['basename'])};return _0x32bc2a;});if(!_0x108926[_0x9ffb('0xcc')]){return db[_0x9ffb('0xcd')][_0x9ffb('0xce')](function(_0x4a32e4){return db[_0x9ffb('0xcf')][_0x9ffb('0xd0')](_0xf80c2e,{'transaction':_0x4a32e4});});}}})[_0x9ffb('0x14')](function(){if(_0x444052){_0x240c6a=_0x444052;return db[_0x9ffb('0xc2')][_0x9ffb('0x59')]({'where':{'service':!![]},'include':[{'model':db[_0x9ffb('0xd1')],'as':_0x9ffb('0xd2'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0x9ffb('0xd3'),'raw':!![]}]}]});}})['then'](function(_0x4dffc6){if(_0x4dffc6&&_0x4dffc6['Smtp']&&_0x108926[_0x9ffb('0xd4')]&&_0x108926[_0x9ffb('0xd5')]){var _0x4691b3=_0x4dffc6[_0x9ffb('0xd6')]();return respondWithRpcPromise(_0x9ffb('0xd7'),'sendMail',{'account':_0x4691b3,'message':{'from':util['format'](_0x9ffb('0xd8'),_0x4dffc6[_0x9ffb('0x2a')],_0x4dffc6[_0x9ffb('0xd9')]||_0x4dffc6[_0x9ffb('0xd2')][_0x9ffb('0x4d')]),'to':_0x108926[_0x9ffb('0xd5')],'subject':_0x108926[_0x9ffb('0xda')],'html':_0x240c6a[_0x9ffb('0x4c')],'attachments':_0x44bcc1}},client9003)['then'](function(){return _0x240c6a;})[_0x9ffb('0x1d')](function(_0x65be33){logger['error'](_0x65be33);});}})[_0x9ffb('0x14')](function(){if(_0x108926&&_0x108926['openNewInteraction']&&_0x108926[_0x9ffb('0xdb')]){var _0x169abf=[];if(_0x125106[_0x9ffb('0x3a')]){_0x169abf=_0x125106['map'](function(_0x4f503c){return{'name':_0x4f503c['originalname'],'basename':_0x4f503c[_0x9ffb('0x63')],'type':_0x4f503c[_0x9ffb('0xc9')],'ChatOfflineMessageId':_0x444052['id']};});}var _0x57d9e8;if(!_[_0x9ffb('0x6f')](_0x108926[_0x9ffb('0xdc')])){var _0x2c301b=_[_0x9ffb('0x2e')](_0x4db7ca['body'],function(_0x2950dc){return _0x2950dc;});var _0x52dea7=_[_0x9ffb('0xdd')](_0x2c301b)[0x0];var _0x4f6bb2=_[_0x9ffb('0xde')](_0x52dea7,function(_0x10d69e){return _0x10d69e;});_0x57d9e8=_0x4f6bb2[0x1][_0x108926[_0x9ffb('0xdc')]];}var _0x413510={'from':_0x89de1['email'],'firstName':_0x89de1[_0x9ffb('0x9d')],'lastName':_0x89de1['lastName'],'mapKey':_0x9ffb('0xd9'),'message':{'from':_0x89de1[_0x9ffb('0xd9')],'to':_0x108926['MailAccount'][_0x9ffb('0xd9')],'cc':'','subject':_[_0x9ffb('0x6f')](_0x57d9e8)?_0x108926[_0x9ffb('0xda')]:_0x57d9e8,'messageId':'','sentAt':new Date(),'attach':_0x169abf[_0x9ffb('0x3a')],'attachments':_0x169abf,'originChannel':_0x9ffb('0xdf'),'ChatWebsiteId':_0x108926['id'],'ChatOfflineMessageId':_0x240c6a['id'],'originTo':_0x108926[_0x9ffb('0xc2')][_0x9ffb('0xd9')]},'body':_0x240c6a[_0x9ffb('0x4c')]};var _0x2f078e={'account':{'id':_0x108926['MailAccountId']},'body':_0x413510,'log':_0x9ffb('0xe0')};return respondWithRpcPromise('NotifyMailAccount',_0x9ffb('0xe1'),_0x2f078e,client9001)[_0x9ffb('0x14')](function(){return _0x240c6a;})[_0x9ffb('0x1d')](function(_0x40d51c){logger['error'](_0x40d51c);});}return;})[_0x9ffb('0x14')](function(){if(_0x240c6a){return _0x240c6a;}})['then'](respondWithResult(_0x671374,null))[_0x9ffb('0x1d')](function(_0x421248){logger['error'](_0x9ffb('0x1d'),_0x421248);for(var _0x174e9e of _0x125106){var _0x39c4e7=path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0xe2'),_0x9ffb('0xbd'),_0x9ffb('0xca'),'offline-chat',_0x174e9e[_0x9ffb('0x63')]);fs_extra[_0x9ffb('0xe3')](_0x39c4e7)[_0x9ffb('0x1d')](function(_0x359ed1){logger['error'](_0x9ffb('0xe4'),_0x39c4e7,_0x359ed1);});}});};exports[_0x9ffb('0xe5')]=function(_0x35f642,_0x2221c1){return db[_0x9ffb('0xaa')][_0x9ffb('0x53')]({'where':{'id':_0x35f642[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0x2221c1,null))[_0x9ffb('0x14')](function(_0x1882ca){if(_0x1882ca){return _0x1882ca[_0x9ffb('0xe5')](_0x35f642[_0x9ffb('0x4c')][_0x9ffb('0x5c')],_[_0x9ffb('0xe6')](_0x35f642['body'],[_0x9ffb('0x5c'),'id'])||{});}})[_0x9ffb('0x14')](respondWithResult(_0x2221c1,null))[_0x9ffb('0x1d')](handleError(_0x2221c1,null));};exports[_0x9ffb('0xe7')]=function(_0x71a7d6,_0x67cd3f){var _0x4529d1={'raw':![],'where':{}};var _0x31d9f1={};var _0x3f1dad={'count':0x0,'rows':[]};return db[_0x9ffb('0x2f')]['findOne']({'where':{'id':_0x71a7d6[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x67cd3f,null))['then'](function(_0x20f384){if(_0x20f384){_0x31d9f1[_0x9ffb('0x34')]=_[_0x9ffb('0x35')](db[_0x9ffb('0xaa')]['rawAttributes']);_0x31d9f1[_0x9ffb('0x36')]=_['keys'](_0x71a7d6[_0x9ffb('0x36')]);_0x31d9f1['filters']=_[_0x9ffb('0x38')](_0x31d9f1['model'],_0x31d9f1[_0x9ffb('0x36')]);_0x4529d1[_0x9ffb('0x39')]=_[_0x9ffb('0x38')](_0x31d9f1[_0x9ffb('0x34')],qs[_0x9ffb('0x48')](_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x48')]));_0x4529d1[_0x9ffb('0x39')]=_0x4529d1[_0x9ffb('0x39')][_0x9ffb('0x3a')]?_0x4529d1[_0x9ffb('0x39')]:_0x31d9f1[_0x9ffb('0x34')];if(!_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x3b')](_0x9ffb('0x3c'))){_0x4529d1[_0x9ffb('0x3d')]=qs[_0x9ffb('0x3d')](_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x3d')]);_0x4529d1[_0x9ffb('0x20')]=qs[_0x9ffb('0x20')](_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x20')]);}_0x4529d1[_0x9ffb('0x5a')]=qs[_0x9ffb('0x3e')](_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x3e')]);_0x4529d1['where']=qs[_0x9ffb('0x37')](_[_0x9ffb('0x3f')](_0x71a7d6[_0x9ffb('0x36')],_0x31d9f1[_0x9ffb('0x37')]));_0x4529d1['where'][_0x9ffb('0x56')]=_0x20f384['id'];if(_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x40')]){_0x4529d1['where']=_[_0x9ffb('0x43')](_0x4529d1['where'],{'$or':_[_0x9ffb('0x2e')](_0x4529d1[_0x9ffb('0x39')],function(_0x32d429){var _0x7ef8c2={};_0x7ef8c2[_0x32d429]={'$like':'%'+_0x71a7d6['query'][_0x9ffb('0x40')]+'%'};return _0x7ef8c2;})});}_0x4529d1=_['merge']({},_0x4529d1,_0x71a7d6[_0x9ffb('0x44')]);return db[_0x9ffb('0xaa')][_0x9ffb('0x22')]({'where':_0x4529d1[_0x9ffb('0x41')]})[_0x9ffb('0x14')](function(_0x4270f9){_0x3f1dad[_0x9ffb('0x22')]=_0x4270f9;if(_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0x49')]){_0x4529d1[_0x9ffb('0x4a')]=[{'model':db[_0x9ffb('0x80')],'as':_0x9ffb('0xe8'),'required':![]},{'model':db[_0x9ffb('0xb5')],'as':_0x9ffb('0xe9'),'attributes':['name',_0x9ffb('0xea'),_0x9ffb('0xeb')],'required':![]},{'model':db[_0x9ffb('0xec')],'as':_0x9ffb('0xed'),'attributes':['id','name',_0x9ffb('0xee')],'where':_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0xef')]?{'id':_0x71a7d6[_0x9ffb('0x36')][_0x9ffb('0xef')]}:undefined,'required':_0x71a7d6['query'][_0x9ffb('0xef')]?!![]:![]}];}return db[_0x9ffb('0xaa')]['findAll'](_0x4529d1);})[_0x9ffb('0x14')](function(_0x38e313){_0x3f1dad[_0x9ffb('0x46')]=_0x38e313;return _0x3f1dad;});}})[_0x9ffb('0x14')](respondWithFilteredResult(_0x67cd3f,_0x4529d1))[_0x9ffb('0x1d')](handleError(_0x67cd3f,null));};function iftimePromise(_0x4b6491,_0x11e4e0){return respondWithRpcPromise('Command',_0x9ffb('0xf0'),{'command':_0x11e4e0[_0x9ffb('0xf1')]?util[_0x9ffb('0xa3')](_0x9ffb('0xf2'),_0x4b6491[_0x9ffb('0xf3')],_0x11e4e0[_0x9ffb('0xf1')]):util[_0x9ffb('0xa3')](_0x9ffb('0xf4'),_0x4b6491[_0x9ffb('0xf3')])},client9002)[_0x9ffb('0x14')](function(_0xad472a){var _0x51bb99=_0xad472a&&_0xad472a['indexOf'](_0x9ffb('0xf5'))>=0x0?!![]:![];logger[_0x9ffb('0x15')](_0x9ffb('0xf6'),_0x11e4e0['id'],_0x4b6491['id'],_0x4b6491[_0x9ffb('0xf3')],_0x51bb99?'ONLINE':_0x9ffb('0xf7'),_0x11e4e0[_0x9ffb('0xf1')]?_0x11e4e0['timezone']:_0x9ffb('0xf8'));return _0x51bb99;})[_0x9ffb('0x1d')](function(_0xa4871d){logger[_0x9ffb('0x1a')](_0x9ffb('0xf6'),_0x11e4e0['id'],_0x4b6491['id'],_0x4b6491[_0x9ffb('0xf3')],util[_0x9ffb('0xf9')](_0xa4871d,{'showHidden':![],'depth':null}),_0x11e4e0[_0x9ffb('0xf1')]?_0x11e4e0[_0x9ffb('0xf1')]:_0x9ffb('0xf8'));return![];});}exports['getSnippet']=function(_0x58a395,_0x46a6d5){var _0x1dc1f4=0x0;var _0x2fb776=0x0;var _0x5e0907=![];var _0x18a5fc;var _0x195e2a;return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0x58a395[_0x9ffb('0x47')]['id']},'include':[{'model':db['Interval'],'as':_0x9ffb('0xfa'),'include':[{'model':db[_0x9ffb('0xfa')],'as':_0x9ffb('0xfb'),'attributes':['id',_0x9ffb('0xf3')],'raw':!![]}]}]})[_0x9ffb('0x14')](handleEntityNotFound(_0x46a6d5,null))['then'](function(_0x3184cd){if(_0x3184cd){_0x18a5fc=_0x3184cd;return _0x3184cd[_0x9ffb('0xfc')]({'raw':!![]});}})[_0x9ffb('0x14')](function(_0x410bb0){if(_0x18a5fc){if(_0x410bb0){_0x195e2a=_0x410bb0;}}return require(_0x9ffb('0x6d'))[_0x9ffb('0x6e')]();})['then'](function(_0x4761fd){if(_0x4761fd){_0x2fb776=_0x4761fd[_0x9ffb('0xfd')];_0x5e0907=_0x4761fd[_0x9ffb('0xfe')];}})[_0x9ffb('0x14')](function(){return db[_0x9ffb('0xaa')][_0x9ffb('0x22')]({'where':{'closed':![]}});})[_0x9ffb('0x14')](function(_0x35cbe4){_0x1dc1f4=_0x35cbe4;if(_0x2fb776&&_0x35cbe4>_0x2fb776){return db[_0x9ffb('0xff')][_0x9ffb('0x59')]({'where':{'id':0x1}})[_0x9ffb('0x14')](function(_0x15b7b1){if(_0x15b7b1){_0x15b7b1[_0x9ffb('0x100')](_0x9ffb('0x101'));}});}})['then'](function(){if(_0x18a5fc['Interval']&&_0x18a5fc[_0x9ffb('0xfa')][_0x9ffb('0xfb')]){var _0x562429=[];for(var _0x3fa703=0x0;_0x3fa703<_0x18a5fc[_0x9ffb('0xfa')][_0x9ffb('0xfb')][_0x9ffb('0x3a')];_0x3fa703++){var _0x5b470e=_0x18a5fc[_0x9ffb('0xfa')][_0x9ffb('0xfb')][_0x3fa703][_0x9ffb('0x26')]({'plain':!![]});_0x562429[_0x9ffb('0xb1')](iftimePromise(_0x5b470e,_0x18a5fc));}return BPromise[_0x9ffb('0x102')](_0x562429)['then'](function(_0x325149){return _[_0x9ffb('0x103')](_0x325149);});}else{return!![];}})[_0x9ffb('0x14')](function(_0x5bac3a){var _0x5d57bd=fs[_0x9ffb('0xc4')](path[_0x9ffb('0x6b')](config[_0x9ffb('0x71')],_0x9ffb('0x104')),_0x9ffb('0x105'));var _0x137bab={'remote':_0x18a5fc['remote'],'query':querystring[_0x9ffb('0x19')](_['merge'](_0x18a5fc[_0x9ffb('0x26')]({'plain':!![]}),{'customerIp':_0x58a395[_0x9ffb('0x7c')][_0x9ffb('0x106')]||_0x58a395[_0x9ffb('0x7c')]['x-real-ip']||_0x58a395[_0x9ffb('0x107')]['remoteAddress']||_0x58a395['ip'],'referer':_0x58a395[_0x9ffb('0x7c')]['referer'],'openedInteractions':_0x1dc1f4,'maxInteractions':_0x2fb776,'virtual':_0x5e0907[_0x9ffb('0xfd')],'online':_0x5bac3a,'custom':_0x5e0907}))['replace'](/'/g,'\x5c\x27')};_0x46a6d5['send'](ejs[_0x9ffb('0xc6')](Mustache[_0x9ffb('0xc6')](_0x5d57bd,_0x137bab),{'proactiveActions':_0x195e2a,'alignment':_0x18a5fc[_0x9ffb('0x108')],'verticalAlignment':_0x18a5fc[_0x9ffb('0x109')],'div_color':_0x18a5fc['color'],'labelText':_0x18a5fc[_0x9ffb('0x10a')],'text_color':_0x18a5fc[_0x9ffb('0x10b')],'text_button_color':_0x18a5fc[_0x9ffb('0x10c')],'button_color':_0x18a5fc[_0x9ffb('0x10d')],'background_color':_0x18a5fc['backgroundColor'],'hideWhenOffline':_0x18a5fc[_0x9ffb('0x10e')],'interval':_0x18a5fc[_0x9ffb('0x10f')]}));})[_0x9ffb('0x1d')](handleError(_0x46a6d5,null));};exports[_0x9ffb('0x110')]=function(_0x45fad0,_0x5cd809){var _0x3f1560=_0x45fad0[_0x9ffb('0x47')]['id'];var _0x3be7ad=_0x45fad0[_0x9ffb('0x4c')];var _0x5d00c7=0xc8;var _0x224c12=null;return db['sequelize'][_0x9ffb('0xce')]({'isolationLevel':db[_0x9ffb('0xcd')][_0x9ffb('0x111')][_0x9ffb('0x112')][_0x9ffb('0x113')]},function(_0x4a936a){return db[_0x9ffb('0x2f')][_0x9ffb('0x59')]({'where':{'id':_0x3f1560},'transaction':_0x4a936a})[_0x9ffb('0x14')](function(_0x9ef0ab){if(_0x9ef0ab){return db[_0x9ffb('0x91')][_0x9ffb('0x25')]({'where':{'ChatWebsiteId':_0x3f1560},'transaction':_0x4a936a})[_0x9ffb('0x14')](function(){var _0x2259ac=_['map'](_0x3be7ad,function(_0x2ca08d){_0x2ca08d[_0x9ffb('0x56')]=_0x3f1560;return _0x2ca08d;});return db['ChatApplication'][_0x9ffb('0xd0')](_0x2259ac,{'transaction':_0x4a936a});});}else{_0x5d00c7=0x194;_0x224c12=[];}});})[_0x9ffb('0x14')](function(){if(_0x5d00c7!==0x194){return db['ChatApplication'][_0x9ffb('0x114')]({'where':{'ChatWebsiteId':_0x3f1560},'order':_0x9ffb('0x115')})[_0x9ffb('0x14')](function(_0xf7b127){_0x224c12=_0xf7b127;});}})[_0x9ffb('0x1d')](function(_0x4f08a7){_0x5d00c7=0x1f4;logger['error'](_0x4f08a7[_0x9ffb('0x29')]);if(_0x4f08a7['name']){delete _0x4f08a7['name'];}_0x224c12=_0x4f08a7;})[_0x9ffb('0x116')](function(){if(_0x224c12===null){_0x5cd809[_0x9ffb('0x1e')](_0x5d00c7);}else{if(_0x5d00c7===0x1f4){_0x5cd809[_0x9ffb('0x1f')](_0x5d00c7)[_0x9ffb('0xbe')](_0x224c12);}else{_0x5cd809['status'](_0x5d00c7)[_0x9ffb('0x23')](_0x224c12);}}});};exports['getApplications']=function(_0x55d591,_0x5b3276){var _0x3e62cf={};var _0x295764={};var _0x2dbaa8;var _0x5369bf;return db['ChatWebsite'][_0x9ffb('0x59')]({'where':{'id':_0x55d591[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x5b3276,null))[_0x9ffb('0x14')](function(_0x4b2f30){if(_0x4b2f30){_0x2dbaa8=_0x4b2f30;_0x295764[_0x9ffb('0x34')]=_['keys'](db[_0x9ffb('0x91')][_0x9ffb('0x30')]);_0x295764[_0x9ffb('0x36')]=_[_0x9ffb('0x35')](_0x55d591[_0x9ffb('0x36')]);_0x295764[_0x9ffb('0x37')]=_[_0x9ffb('0x38')](_0x295764[_0x9ffb('0x34')],_0x295764[_0x9ffb('0x36')]);_0x3e62cf['attributes']=_[_0x9ffb('0x38')](_0x295764[_0x9ffb('0x34')],qs[_0x9ffb('0x48')](_0x55d591[_0x9ffb('0x36')][_0x9ffb('0x48')]));_0x3e62cf[_0x9ffb('0x39')]=_0x3e62cf[_0x9ffb('0x39')][_0x9ffb('0x3a')]?_0x3e62cf[_0x9ffb('0x39')]:_0x295764['model'];_0x3e62cf[_0x9ffb('0x5a')]=qs[_0x9ffb('0x3e')](_0x55d591[_0x9ffb('0x36')][_0x9ffb('0x3e')]);_0x3e62cf[_0x9ffb('0x41')]=qs[_0x9ffb('0x37')](_['pick'](_0x55d591[_0x9ffb('0x36')],_0x295764['filters']));if(_0x55d591['query']['filter']){_0x3e62cf['where']=_[_0x9ffb('0x43')](_0x3e62cf[_0x9ffb('0x41')],{'$or':_[_0x9ffb('0x2e')](_0x3e62cf[_0x9ffb('0x39')],function(_0x51e396){var _0x1b2f5b={};_0x1b2f5b[_0x51e396]={'$like':'%'+_0x55d591[_0x9ffb('0x36')][_0x9ffb('0x40')]+'%'};return _0x1b2f5b;})});}_0x3e62cf=_[_0x9ffb('0x43')]({},_0x3e62cf,_0x55d591[_0x9ffb('0x44')]);return _0x2dbaa8['getApplications'](_0x3e62cf);}})[_0x9ffb('0x14')](function(_0x5838c2){if(_0x5838c2){_0x5369bf=_0x5838c2[_0x9ffb('0x3a')];if(!_0x55d591['query'][_0x9ffb('0x3b')](_0x9ffb('0x3c'))){_0x3e62cf[_0x9ffb('0x3d')]=qs['limit'](_0x55d591['query'][_0x9ffb('0x3d')]);_0x3e62cf[_0x9ffb('0x20')]=qs[_0x9ffb('0x20')](_0x55d591[_0x9ffb('0x36')]['offset']);}return _0x2dbaa8[_0x9ffb('0x117')](_0x3e62cf);}})[_0x9ffb('0x14')](function(_0x518b96){if(_0x518b96){return _0x518b96?{'count':_0x5369bf,'rows':_0x518b96}:null;}})['then'](respondWithResult(_0x5b3276,null))[_0x9ffb('0x1d')](handleError(_0x5b3276,null));};exports[_0x9ffb('0x118')]=function(_0x48b86a,_0x5e19fe){return db['chatProactiveAction'][_0x9ffb('0x53')]({'where':{'id':_0x48b86a[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0x5e19fe,null))[_0x9ffb('0x14')](function(_0x378c36){if(_0x378c36){return _0x378c36['addProactiveActions'](_0x48b86a[_0x9ffb('0x4c')]['ids'],_[_0x9ffb('0xe6')](_0x48b86a[_0x9ffb('0x4c')],[_0x9ffb('0x5c'),'id'])||{});}})[_0x9ffb('0x14')](respondWithResult(_0x5e19fe,null))['catch'](handleError(_0x5e19fe,null));};exports[_0x9ffb('0xfc')]=function(_0x1a84e4,_0x33fc99){var _0x4b2869={};var _0x58a137={};var _0xbfdf9e;var _0x53dc2d;return db[_0x9ffb('0x2f')][_0x9ffb('0x59')]({'where':{'id':_0x1a84e4[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0x33fc99,null))[_0x9ffb('0x14')](function(_0x108456){if(_0x108456){_0xbfdf9e=_0x108456;_0x58a137[_0x9ffb('0x34')]=_[_0x9ffb('0x35')](db[_0x9ffb('0x119')][_0x9ffb('0x30')]);_0x58a137[_0x9ffb('0x36')]=_[_0x9ffb('0x35')](_0x1a84e4[_0x9ffb('0x36')]);_0x58a137[_0x9ffb('0x37')]=_[_0x9ffb('0x38')](_0x58a137[_0x9ffb('0x34')],_0x58a137[_0x9ffb('0x36')]);_0x4b2869['attributes']=_['intersection'](_0x58a137[_0x9ffb('0x34')],qs[_0x9ffb('0x48')](_0x1a84e4[_0x9ffb('0x36')][_0x9ffb('0x48')]));_0x4b2869[_0x9ffb('0x39')]=_0x4b2869[_0x9ffb('0x39')]['length']?_0x4b2869[_0x9ffb('0x39')]:_0x58a137[_0x9ffb('0x34')];_0x4b2869[_0x9ffb('0x5a')]=qs[_0x9ffb('0x3e')](_0x1a84e4[_0x9ffb('0x36')][_0x9ffb('0x3e')]);_0x4b2869[_0x9ffb('0x41')]=qs['filters'](_[_0x9ffb('0x3f')](_0x1a84e4[_0x9ffb('0x36')],_0x58a137[_0x9ffb('0x37')]));if(_0x1a84e4['query'][_0x9ffb('0x40')]){_0x4b2869[_0x9ffb('0x41')]=_[_0x9ffb('0x43')](_0x4b2869['where'],{'$or':_[_0x9ffb('0x2e')](_0x4b2869[_0x9ffb('0x39')],function(_0x286601){var _0xd6ce7b={};_0xd6ce7b[_0x286601]={'$like':'%'+_0x1a84e4[_0x9ffb('0x36')][_0x9ffb('0x40')]+'%'};return _0xd6ce7b;})});}_0x4b2869=_[_0x9ffb('0x43')]({},_0x4b2869,_0x1a84e4[_0x9ffb('0x44')]);return _0xbfdf9e[_0x9ffb('0xfc')](_0x4b2869);}})['then'](function(_0x5f6e6b){if(_0x5f6e6b){_0x53dc2d=_0x5f6e6b[_0x9ffb('0x3a')];if(!_0x1a84e4[_0x9ffb('0x36')]['hasOwnProperty'](_0x9ffb('0x3c'))){_0x4b2869[_0x9ffb('0x3d')]=qs[_0x9ffb('0x3d')](_0x1a84e4[_0x9ffb('0x36')][_0x9ffb('0x3d')]);_0x4b2869[_0x9ffb('0x20')]=qs[_0x9ffb('0x20')](_0x1a84e4[_0x9ffb('0x36')]['offset']);}return _0xbfdf9e[_0x9ffb('0xfc')](_0x4b2869);}})[_0x9ffb('0x14')](function(_0x263557){if(_0x263557){return _0x263557?{'count':_0x53dc2d,'rows':_0x263557}:null;}})[_0x9ffb('0x14')](respondWithResult(_0x33fc99,null))[_0x9ffb('0x1d')](handleError(_0x33fc99,null));};exports[_0x9ffb('0x11a')]=function(_0x1fcb6c,_0xcf5f4c){var _0x4b317a=_0x1fcb6c[_0x9ffb('0x36')][_0x9ffb('0x11b')]===_0x9ffb('0x11c')?_0x9ffb('0x11d'):_0x9ffb('0x11e');return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'attributes':['id',_0x4b317a],'where':{'id':_0x1fcb6c['params']['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0xcf5f4c,null))['then'](function(_0x2dbb93){if(_0x2dbb93){var _0x439290=_0x2dbb93[_0x4b317a];var _0x1f11cb=_0x439290&&_0x439290['items']?_0x439290[_0x9ffb('0x11f')]:[];_0xcf5f4c[_0x9ffb('0xbe')]({'fromKey':_['isNil'](_0x439290['fromKey'])?undefined:_0x439290[_0x9ffb('0x120')],'count':_0x1f11cb[_0x9ffb('0x3a')],'rows':_0x1f11cb});}})['catch'](handleError(_0xcf5f4c,null));};exports[_0x9ffb('0x121')]=function(_0x4cfa5e,_0x11c0b0){var _0x19bbe2={'raw':![],'where':{}};var _0x2c192f={};var _0x1452f4={'count':0x0,'rows':[]};return db[_0x9ffb('0x2f')][_0x9ffb('0x59')]({'where':{'id':_0x4cfa5e[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0x11c0b0,null))[_0x9ffb('0x14')](function(_0x42d9d5){if(_0x42d9d5){_0x2c192f['model']=_['keys'](db[_0x9ffb('0xc7')][_0x9ffb('0x30')]);_0x2c192f[_0x9ffb('0x36')]=_[_0x9ffb('0x35')](_0x4cfa5e[_0x9ffb('0x36')]);_0x2c192f[_0x9ffb('0x37')]=_[_0x9ffb('0x38')](_0x2c192f[_0x9ffb('0x34')],_0x2c192f[_0x9ffb('0x36')]);_0x19bbe2[_0x9ffb('0x39')]=_['intersection'](_0x2c192f[_0x9ffb('0x34')],qs[_0x9ffb('0x48')](_0x4cfa5e[_0x9ffb('0x36')]['fields']));_0x19bbe2[_0x9ffb('0x39')]=_0x19bbe2[_0x9ffb('0x39')][_0x9ffb('0x3a')]?_0x19bbe2[_0x9ffb('0x39')]:_0x2c192f[_0x9ffb('0x34')];if(!_0x4cfa5e['query'][_0x9ffb('0x3b')](_0x9ffb('0x3c'))){_0x19bbe2[_0x9ffb('0x3d')]=qs[_0x9ffb('0x3d')](_0x4cfa5e[_0x9ffb('0x36')][_0x9ffb('0x3d')]);_0x19bbe2['offset']=qs[_0x9ffb('0x20')](_0x4cfa5e[_0x9ffb('0x36')][_0x9ffb('0x20')]);}_0x19bbe2['order']=qs[_0x9ffb('0x3e')](_0x4cfa5e['query']['sort']);_0x19bbe2[_0x9ffb('0x41')]=qs['filters'](_['pick'](_0x4cfa5e[_0x9ffb('0x36')],_0x2c192f[_0x9ffb('0x37')]));_0x19bbe2[_0x9ffb('0x41')][_0x9ffb('0x56')]=_0x42d9d5['id'];if(_0x4cfa5e['query'][_0x9ffb('0x40')]){_0x19bbe2[_0x9ffb('0x41')]=_[_0x9ffb('0x43')](_0x19bbe2[_0x9ffb('0x41')],{'$or':_[_0x9ffb('0x2e')](_0x19bbe2[_0x9ffb('0x39')],function(_0x3ff829){var _0x56f19b={};_0x56f19b[_0x3ff829]={'$like':'%'+_0x4cfa5e[_0x9ffb('0x36')][_0x9ffb('0x40')]+'%'};return _0x56f19b;})});}_0x19bbe2=_[_0x9ffb('0x43')]({},_0x19bbe2,_0x4cfa5e[_0x9ffb('0x44')]);return db[_0x9ffb('0xc7')]['count']({'where':_0x19bbe2[_0x9ffb('0x41')]})[_0x9ffb('0x14')](function(_0x615bcf){_0x1452f4[_0x9ffb('0x22')]=_0x615bcf;if(_0x4cfa5e[_0x9ffb('0x36')][_0x9ffb('0x49')]){_0x19bbe2[_0x9ffb('0x4a')]=[{'all':!![]}];}else{_0x19bbe2[_0x9ffb('0x4a')]=[{'model':db[_0x9ffb('0x80')],'as':_0x9ffb('0xe8'),'required':![]},{'model':db[_0x9ffb('0xcf')],'as':_0x9ffb('0x122'),'required':![]}];}return db[_0x9ffb('0xc7')][_0x9ffb('0x45')](_0x19bbe2);})[_0x9ffb('0x14')](function(_0x366f9a){_0x1452f4[_0x9ffb('0x46')]=_0x366f9a;return _0x1452f4;});}})['then'](respondWithFilteredResult(_0x11c0b0,_0x19bbe2))[_0x9ffb('0x1d')](handleError(_0x11c0b0,null));};exports[_0x9ffb('0x123')]=function(_0x2c2bc7,_0xdcdd14){return db[_0x9ffb('0x2f')][_0x9ffb('0x53')]({'where':{'id':_0x2c2bc7[_0x9ffb('0x47')]['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0xdcdd14,null))['then'](function(_0x2245ab){if(_0x2245ab){return _0x2245ab['addAgents'](_0x2c2bc7[_0x9ffb('0x4c')][_0x9ffb('0x5c')],_[_0x9ffb('0xe6')](_0x2c2bc7[_0x9ffb('0x4c')],[_0x9ffb('0x5c'),'id'])||{})[_0x9ffb('0xad')](function(_0x865d32){for(var _0x1fc93d=0x0;_0x1fc93d<_0x2c2bc7[_0x9ffb('0x4c')][_0x9ffb('0x5c')][_0x9ffb('0x3a')];_0x1fc93d+=0x1){socket[_0x9ffb('0x124')](_0x9ffb('0x125'),{'UserId':Number(_0x2c2bc7['body'][_0x9ffb('0x5c')][_0x1fc93d]),'ChatWebsiteId':Number(_0x2c2bc7['params']['id'])});}return _0x865d32;});}})[_0x9ffb('0x14')](respondWithResult(_0xdcdd14,null))[_0x9ffb('0x1d')](handleError(_0xdcdd14,null));};exports[_0x9ffb('0x126')]=function(_0x2ccbde,_0xb688f1){return db['ChatWebsite'][_0x9ffb('0x53')]({'where':{'id':_0x2ccbde['params']['id']}})[_0x9ffb('0x14')](handleEntityNotFound(_0xb688f1,null))[_0x9ffb('0x14')](function(_0x424657){if(_0x424657){return _0x424657[_0x9ffb('0x126')](_0x2ccbde[_0x9ffb('0x36')][_0x9ffb('0x5c')])[_0x9ffb('0x14')](function(){if(_[_0x9ffb('0x127')](_0x2ccbde[_0x9ffb('0x36')][_0x9ffb('0x5c')])){for(var _0x1a6053=0x0;_0x1a6053<_0x2ccbde[_0x9ffb('0x36')][_0x9ffb('0x5c')]['length'];_0x1a6053+=0x1){socket[_0x9ffb('0x124')]('userChatWebsite:remove',{'UserId':Number(_0x2ccbde[_0x9ffb('0x36')][_0x9ffb('0x5c')][_0x1a6053]),'ChatWebsiteId':Number(_0x2ccbde[_0x9ffb('0x47')]['id'])});}}else{socket['emit']('userChatWebsite:remove',{'UserId':Number(_0x2ccbde['query'][_0x9ffb('0x5c')]),'ChatWebsiteId':Number(_0x2ccbde['params']['id'])});}});}})['then'](respondWithStatusCode(_0xb688f1,null))[_0x9ffb('0x1d')](handleError(_0xb688f1,null));};exports['getAgents']=function(_0xeba6ab,_0x5a29e5){var _0x2b7ea3={};var _0x7a7d25={};var _0x455d87;var _0x475093;return db['ChatWebsite'][_0x9ffb('0x59')]({'where':{'id':_0xeba6ab[_0x9ffb('0x47')]['id']}})['then'](handleEntityNotFound(_0x5a29e5,null))[_0x9ffb('0x14')](function(_0xbcbe65){if(_0xbcbe65){_0x455d87=_0xbcbe65;_0x7a7d25[_0x9ffb('0x34')]=_['keys'](db['User'][_0x9ffb('0x30')]);_0x7a7d25['query']=_[_0x9ffb('0x35')](_0xeba6ab[_0x9ffb('0x36')]);_0x7a7d25['filters']=_['intersection'](_0x7a7d25[_0x9ffb('0x34')],_0x7a7d25[_0x9ffb('0x36')]);_0x2b7ea3['attributes']=_[_0x9ffb('0x38')](_0x7a7d25[_0x9ffb('0x34')],qs['fields'](_0xeba6ab[_0x9ffb('0x36')]['fields']));_0x2b7ea3[_0x9ffb('0x39')]=_0x2b7ea3[_0x9ffb('0x39')][_0x9ffb('0x3a')]?_0x2b7ea3['attributes']:_0x7a7d25['model'];_0x2b7ea3[_0x9ffb('0x5a')]=qs[_0x9ffb('0x3e')](_0xeba6ab[_0x9ffb('0x36')][_0x9ffb('0x3e')]);_0x2b7ea3[_0x9ffb('0x41')]=qs['filters'](_[_0x9ffb('0x3f')](_0xeba6ab[_0x9ffb('0x36')],_0x7a7d25['filters']));if(_0xeba6ab[_0x9ffb('0x36')][_0x9ffb('0x40')]){_0x2b7ea3['where']=_['merge'](_0x2b7ea3[_0x9ffb('0x41')],{'$or':_[_0x9ffb('0x2e')](_0x2b7ea3[_0x9ffb('0x39')],function(_0x29e489){var _0x13be21={};_0x13be21[_0x29e489]={'$like':'%'+_0xeba6ab[_0x9ffb('0x36')]['filter']+'%'};return _0x13be21;})});}_0x2b7ea3=_['merge']({},_0x2b7ea3,_0xeba6ab[_0x9ffb('0x44')]);return _0x455d87[_0x9ffb('0x128')](_0x2b7ea3);}})[_0x9ffb('0x14')](function(_0x54ea48){if(_0x54ea48){_0x475093=_0x54ea48['length'];if(!_0xeba6ab[_0x9ffb('0x36')][_0x9ffb('0x3b')](_0x9ffb('0x3c'))){_0x2b7ea3[_0x9ffb('0x3d')]=qs[_0x9ffb('0x3d')](_0xeba6ab['query'][_0x9ffb('0x3d')]);_0x2b7ea3[_0x9ffb('0x20')]=qs['offset'](_0xeba6ab[_0x9ffb('0x36')][_0x9ffb('0x20')]);}return _0x455d87[_0x9ffb('0x128')](_0x2b7ea3);}})['then'](function(_0x33b2ca){if(_0x33b2ca){return _0x33b2ca?{'count':_0x475093,'rows':_0x33b2ca}:null;}})[_0x9ffb('0x14')](respondWithResult(_0x5a29e5,null))[_0x9ffb('0x1d')](handleError(_0x5a29e5,null));};
\ No newline at end of file
+var _0x34cb=['ContactId','interaction','contact','messageId','created','push','close','unmanaged','ChatMessage','AttachmentId','User','UserId','unshift','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','startRouting','Start','EventManager','offline','files','mapKeyOffline','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','MailAccount','findOrCreate','spread','readFileSync','server/files/templates/chatOfflineMessage.ejs','utf8','render','toPairs','ChatOfflineMessage','fromString','mimetype','server','attachments','offline-chat','basename','openNewInteraction','transaction','Attachment','bulkCreate','Smtp','CloudProvider','getSmtpOptions','SendMail','sendMail','\x22%s\x22\x20<%s>','email','forwardOfflineAddress','originalname','subjectOffline','toPairsIn','offlineMessageSubject','Chat','MailAccountId','NotifyMailAccount','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','Tag','Tags','color','tag','getSnippet','timezone','iftime\x20%s,%s','interval','iftime\x20%s','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','No\x20timezone','inspect','Interval','Intervals','getProactiveActions','../../config/license/util','getLicense','virtual','custom','chatLicenseExceeded','some','server/files/chat/iframe.ejs','address','origin','3.1.0','x-real-ip','connection','remoteAddress','replace','alignment','verticalAlignment','labelText','textColor','color_button','backgroundColor','hideWhenOffline','IntervalId','addApplications','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','findAndCountAll','finally','json','getApplications','addProactiveActions','ChatProactiveAction','getFields','online','false','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','emit','userChatWebsite:save','removeAgents','userChatWebsite:remove','getAgents','mustache','path','ejs','fs-extra','lodash','querystring','../../components/parsers/qs','../../config/logger','api','../../config/environment','url','redis','defaults','localhost','socket.io-emitter','./chatWebsite.socket','html-to-text','jayson/promise','client','http','request','then','ChatWebsite,\x20%s,\x20%s','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','message','info','request\x20sent','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','update','destroy','get','stack','name','send','Pause','mandatoryDispositionPause','ChatWebsite','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','map','options','includeAll','include','findAll','rows','catch','params','keys','rawAttributes','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','ChatWebsiteId','Disposition','getDispositions','findOne','order','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','addLogo','sitepic','file','filename','addAvatar','customerAvatar','addSystemAvatar','systemAvatar','getLogo','join','isNil','existsSync','root','server/files/images/logos/','download','getAvatar','server/files/images/avatars/default_avatar.png','agentAvatar','server/files/images/avatars/','server/files/images/avatars/customer_avatar.png','showCustomerAvatar','getSystemAvatar','notify','user-agent-parser','setUA','headers','user-agent','getResult','CmContact','ValidationError','no\x20available\x20attributes','difference','updatedAt','createdAt','CompanyId','ListId','from','Sequelize','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','ChatApplication','Applications','List','account','applications','list','orderBy','priority','asc','mapKey','customerIp','cf-connecting-ip','x-forwarded-for','first','split','firstName','lastName','x-real-port','referer','browser','version','format','unknown','%s\x20%s','device','vendor','%s\x20%s\x20%s','threadId','ChatInteraction','externalUrl'];(function(_0x53af79,_0x45274e){var _0x4d827b=function(_0x543d29){while(--_0x543d29){_0x53af79['push'](_0x53af79['shift']());}};_0x4d827b(++_0x45274e);}(_0x34cb,0x1aa));var _0xb34c=function(_0x3af2a5,_0x2ca3f9){_0x3af2a5=_0x3af2a5-0x0;var _0x43c05a=_0x34cb[_0x3af2a5];return _0x43c05a;};'use strict';var BPromise=require('bluebird');var Mustache=require(_0xb34c('0x0'));var util=require('util');var path=require(_0xb34c('0x1'));var ejs=require(_0xb34c('0x2'));var fs=require('fs');var fs_extra=require(_0xb34c('0x3'));var _=require(_0xb34c('0x4'));var querystring=require(_0xb34c('0x5'));var Redis=require('ioredis');var qs=require(_0xb34c('0x6'));var logger=require(_0xb34c('0x7'))(_0xb34c('0x8'));var config=require(_0xb34c('0x9'));var url=require(_0xb34c('0xa'));var db=require('../../mysqldb')['db'];config[_0xb34c('0xb')]=_[_0xb34c('0xc')](config[_0xb34c('0xb')],{'host':_0xb34c('0xd'),'port':0x18eb});var socket=require(_0xb34c('0xe'))(new Redis(config[_0xb34c('0xb')]));require(_0xb34c('0xf'))['register'](socket);var htmlToText=require(_0xb34c('0x10'));var jayson=require(_0xb34c('0x11'));var client=jayson[_0xb34c('0x12')][_0xb34c('0x13')]({'port':0x232c});var client9002=jayson['client'][_0xb34c('0x13')]({'port':0x232a});var client9003=jayson[_0xb34c('0x12')]['http']({'port':0x232b});var client9001=jayson[_0xb34c('0x12')]['http']({'port':0x2329});function respondWithRpcPromise(_0xabc229,_0x9cd9bf,_0x139bd3,_0x40b71c){return new BPromise(function(_0xc2d7c7,_0xe3c0e4){var _0x27dd76=_0x40b71c||client;return _0x27dd76[_0xb34c('0x14')](_0xabc229,_0x139bd3)[_0xb34c('0x15')](function(_0x3b3acd){logger['info'](_0xb34c('0x16'),_0x9cd9bf,'request\x20sent');logger['debug'](_0xb34c('0x17'),_0x9cd9bf,'request\x20sent',JSON[_0xb34c('0x18')](_0x3b3acd));if(_0x3b3acd[_0xb34c('0x19')]){if(_0x3b3acd['error']['code']===0x1f4){logger['error'](_0xb34c('0x16'),_0x9cd9bf,_0x3b3acd[_0xb34c('0x19')][_0xb34c('0x1a')]);return _0xe3c0e4(_0x3b3acd[_0xb34c('0x19')][_0xb34c('0x1a')]);}logger[_0xb34c('0x19')]('ChatWebsite,\x20%s,\x20%s',_0x9cd9bf,_0x3b3acd[_0xb34c('0x19')][_0xb34c('0x1a')]);return _0xc2d7c7(_0x3b3acd[_0xb34c('0x19')]['message']);}else{logger[_0xb34c('0x1b')](_0xb34c('0x16'),_0x9cd9bf,_0xb34c('0x1c'));_0xc2d7c7(_0x3b3acd['result']['message']);}})['catch'](function(_0x2631c0){logger[_0xb34c('0x19')]('ChatWebsite,\x20%s,\x20%s',_0x9cd9bf,_0x2631c0);_0xe3c0e4(_0x2631c0);});});}function respondWithStatusCode(_0x588010,_0x53c687){_0x53c687=_0x53c687||0xcc;return function(_0x262d88){if(_0x262d88){return _0x588010[_0xb34c('0x1d')](_0x53c687);}return _0x588010[_0xb34c('0x1e')](_0x53c687)[_0xb34c('0x1f')]();};}function respondWithResult(_0x488a54,_0x192bdd){_0x192bdd=_0x192bdd||0xc8;return function(_0x17d7b6){if(_0x17d7b6){return _0x488a54[_0xb34c('0x1e')](_0x192bdd)['json'](_0x17d7b6);}};}function respondWithFilteredResult(_0x152f74,_0x2f9db7){return function(_0x286cea){if(_0x286cea){var _0xa2e90d=typeof _0x2f9db7[_0xb34c('0x20')]===_0xb34c('0x21')&&typeof _0x2f9db7[_0xb34c('0x22')]===_0xb34c('0x21');var _0x59649f=_0x286cea[_0xb34c('0x23')];var _0x5c769f=_0xa2e90d?0x0:_0x2f9db7[_0xb34c('0x20')];var _0x28ddf6=_0xa2e90d?_0x286cea['count']:_0x2f9db7[_0xb34c('0x20')]+_0x2f9db7[_0xb34c('0x22')];var _0xb392f9;if(_0x28ddf6>=_0x59649f){_0x28ddf6=_0x59649f;_0xb392f9=0xc8;}else{_0xb392f9=0xce;}_0x152f74['status'](_0xb392f9);return _0x152f74[_0xb34c('0x24')](_0xb34c('0x25'),_0x5c769f+'-'+_0x28ddf6+'/'+_0x59649f)['json'](_0x286cea);}return null;};}function saveUpdates(_0xdbe791){return function(_0x2d0b58){if(_0x2d0b58){return _0x2d0b58[_0xb34c('0x26')](_0xdbe791)[_0xb34c('0x15')](function(_0x172364){return _0x172364;});}return null;};}function removeEntity(_0x351020){return function(_0x3c8f1d){if(_0x3c8f1d){return _0x3c8f1d[_0xb34c('0x27')]()[_0xb34c('0x15')](function(){var _0x435bc7=_0x3c8f1d[_0xb34c('0x28')]({'plain':!![]});var _0x51a0e2='ChatWebsites';return db['UserProfileResource'][_0xb34c('0x27')]({'where':{'type':_0x51a0e2,'resourceId':_0x435bc7['id']}})[_0xb34c('0x15')](function(){return _0x3c8f1d;});})[_0xb34c('0x15')](function(){_0x351020[_0xb34c('0x1e')](0xcc)[_0xb34c('0x1f')]();});}};}function handleEntityNotFound(_0x39d38e){return function(_0x2e9b2e){if(!_0x2e9b2e){_0x39d38e[_0xb34c('0x1d')](0x194);}return _0x2e9b2e;};}function handleError(_0x1dbd2e,_0x5b39c4){_0x5b39c4=_0x5b39c4||0x1f4;return function(_0x523c66){logger[_0xb34c('0x19')](_0x523c66[_0xb34c('0x29')]);if(_0x523c66[_0xb34c('0x2a')]){delete _0x523c66[_0xb34c('0x2a')];}_0x1dbd2e[_0xb34c('0x1e')](_0x5b39c4)[_0xb34c('0x2b')](_0x523c66);};}exports['index']=function(_0x1df379,_0x4270f7){var _0x166861={'include':[{'model':db[_0xb34c('0x2c')],'as':_0xb34c('0x2d')}]},_0x400198={},_0x266252={'count':0x0,'rows':[]};var _0x2c8327=_['map'](db[_0xb34c('0x2e')]['rawAttributes'],function(_0x304e04){return{'name':_0x304e04[_0xb34c('0x2f')],'type':_0x304e04[_0xb34c('0x30')][_0xb34c('0x31')]};});_0x400198[_0xb34c('0x32')]=_['map'](_0x2c8327,_0xb34c('0x2a'));_0x400198[_0xb34c('0x33')]=_['keys'](_0x1df379[_0xb34c('0x33')]);_0x400198[_0xb34c('0x34')]=_[_0xb34c('0x35')](_0x400198['model'],_0x400198[_0xb34c('0x33')]);_0x166861[_0xb34c('0x36')]=_[_0xb34c('0x35')](_0x400198[_0xb34c('0x32')],qs[_0xb34c('0x37')](_0x1df379['query'][_0xb34c('0x37')]));_0x166861[_0xb34c('0x36')]=_0x166861[_0xb34c('0x36')][_0xb34c('0x38')]?_0x166861[_0xb34c('0x36')]:_0x400198[_0xb34c('0x32')];if(!_0x1df379[_0xb34c('0x33')][_0xb34c('0x39')](_0xb34c('0x3a'))){_0x166861[_0xb34c('0x22')]=qs[_0xb34c('0x22')](_0x1df379[_0xb34c('0x33')][_0xb34c('0x22')]);_0x166861[_0xb34c('0x20')]=qs[_0xb34c('0x20')](_0x1df379[_0xb34c('0x33')][_0xb34c('0x20')]);}_0x166861['order']=qs[_0xb34c('0x3b')](_0x1df379[_0xb34c('0x33')][_0xb34c('0x3b')]);_0x166861[_0xb34c('0x3c')]=qs[_0xb34c('0x34')](_[_0xb34c('0x3d')](_0x1df379[_0xb34c('0x33')],_0x400198[_0xb34c('0x34')]),_0x2c8327);if(_0x1df379[_0xb34c('0x33')][_0xb34c('0x3e')]){_0x166861['where']=_[_0xb34c('0x3f')](_0x166861[_0xb34c('0x3c')],{'$or':_[_0xb34c('0x40')](_0x2c8327,function(_0x5c1895){if(_0x5c1895[_0xb34c('0x30')]!=='VIRTUAL'){var _0x400a09={};_0x400a09[_0x5c1895[_0xb34c('0x2a')]]={'$like':'%'+_0x1df379[_0xb34c('0x33')][_0xb34c('0x3e')]+'%'};return _0x400a09;}})});}_0x166861=_[_0xb34c('0x3f')]({},_0x166861,_0x1df379[_0xb34c('0x41')]);var _0x10796d={'where':_0x166861[_0xb34c('0x3c')]};return db['ChatWebsite'][_0xb34c('0x23')](_0x10796d)[_0xb34c('0x15')](function(_0x224e91){_0x266252[_0xb34c('0x23')]=_0x224e91;if(_0x1df379[_0xb34c('0x33')][_0xb34c('0x42')]){_0x166861[_0xb34c('0x43')]=[{'all':!![]}];}return db[_0xb34c('0x2e')][_0xb34c('0x44')](_0x166861);})[_0xb34c('0x15')](function(_0x3e1b68){_0x266252[_0xb34c('0x45')]=_0x3e1b68;return _0x266252;})[_0xb34c('0x15')](respondWithFilteredResult(_0x4270f7,_0x166861))[_0xb34c('0x46')](handleError(_0x4270f7,null));};exports['show']=function(_0x1827ac,_0x2c355a){var _0x165e92={'raw':![],'where':{'id':_0x1827ac[_0xb34c('0x47')]['id']},'include':[{'model':db[_0xb34c('0x2c')],'as':'mandatoryDispositionPause'}]},_0x32927b={};_0x32927b[_0xb34c('0x32')]=_[_0xb34c('0x48')](db['ChatWebsite'][_0xb34c('0x49')]);_0x32927b[_0xb34c('0x33')]=_[_0xb34c('0x48')](_0x1827ac[_0xb34c('0x33')]);_0x32927b[_0xb34c('0x34')]=_['intersection'](_0x32927b[_0xb34c('0x32')],_0x32927b[_0xb34c('0x33')]);_0x165e92['attributes']=_[_0xb34c('0x35')](_0x32927b[_0xb34c('0x32')],qs['fields'](_0x1827ac[_0xb34c('0x33')][_0xb34c('0x37')]));_0x165e92[_0xb34c('0x36')]=_0x165e92['attributes'][_0xb34c('0x38')]?_0x165e92[_0xb34c('0x36')]:_0x32927b[_0xb34c('0x32')];if(_0x1827ac[_0xb34c('0x33')][_0xb34c('0x42')]){_0x165e92['include']=[{'all':!![]}];}_0x165e92=_['merge']({},_0x165e92,_0x1827ac['options']);return db['ChatWebsite'][_0xb34c('0x4a')](_0x165e92)[_0xb34c('0x15')](handleEntityNotFound(_0x2c355a,null))[_0xb34c('0x15')](respondWithResult(_0x2c355a,null))['catch'](handleError(_0x2c355a,null));};exports[_0xb34c('0x4b')]=function(_0xc9992,_0x1e60ab){return db['ChatWebsite'][_0xb34c('0x4b')](_0xc9992[_0xb34c('0x4c')],{})['then'](function(_0x4aff8e){var _0x33f433=_0xc9992[_0xb34c('0x4d')][_0xb34c('0x28')]({'plain':!![]});if(!_0x33f433)throw new Error(_0xb34c('0x4e'));if(_0x33f433[_0xb34c('0x4f')]==='user'){var _0x2803a1=_0x4aff8e[_0xb34c('0x28')]({'plain':!![]});var _0x1a0b01='ChatWebsites';return db['UserProfileSection'][_0xb34c('0x4a')]({'where':{'name':_0x1a0b01,'userProfileId':_0x33f433[_0xb34c('0x50')]},'raw':!![]})[_0xb34c('0x15')](function(_0x5b66c1){if(_0x5b66c1&&_0x5b66c1[_0xb34c('0x51')]===0x0){return db[_0xb34c('0x52')][_0xb34c('0x4b')]({'name':_0x2803a1['name'],'resourceId':_0x2803a1['id'],'type':_0x5b66c1[_0xb34c('0x2a')],'sectionId':_0x5b66c1['id']},{})[_0xb34c('0x15')](function(){return _0x4aff8e;});}else{return _0x4aff8e;}})[_0xb34c('0x46')](function(_0x4aba45){logger[_0xb34c('0x19')](_0xb34c('0x53'),_0x4aba45);throw _0x4aba45;});}return _0x4aff8e;})[_0xb34c('0x15')](respondWithResult(_0x1e60ab,0xc9))['catch'](handleError(_0x1e60ab,null));};exports[_0xb34c('0x26')]=function(_0x346a77,_0x2fb7c1){if(_0x346a77[_0xb34c('0x4c')]['id']){delete _0x346a77[_0xb34c('0x4c')]['id'];}return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x346a77[_0xb34c('0x47')]['id']},'include':[{'model':db[_0xb34c('0x2c')],'as':_0xb34c('0x2d')}]})[_0xb34c('0x15')](handleEntityNotFound(_0x2fb7c1,null))[_0xb34c('0x15')](saveUpdates(_0x346a77[_0xb34c('0x4c')],null))['then'](respondWithResult(_0x2fb7c1,null))[_0xb34c('0x46')](handleError(_0x2fb7c1,null));};exports['destroy']=function(_0x29677f,_0x12412d){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x29677f[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x12412d,null))[_0xb34c('0x15')](removeEntity(_0x12412d,null))[_0xb34c('0x46')](handleError(_0x12412d,null));};exports[_0xb34c('0x54')]=function(_0x27df85,_0x3dea40){return db[_0xb34c('0x2e')][_0xb34c('0x54')]()[_0xb34c('0x15')](respondWithResult(_0x3dea40,null))['catch'](handleError(_0x3dea40,null));};exports[_0xb34c('0x55')]=function(_0x475b7a,_0x49b5bf){if(_0x475b7a[_0xb34c('0x4c')]['id']){delete _0x475b7a['body']['id'];}return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x475b7a[_0xb34c('0x47')]['id']}})['then'](handleEntityNotFound(_0x49b5bf,null))['then'](function(_0xc1bab5){if(_0xc1bab5){_0x475b7a['body'][_0xb34c('0x56')]=_0xc1bab5['id'];return db[_0xb34c('0x57')][_0xb34c('0x4b')](_0x475b7a[_0xb34c('0x4c')]);}})['then'](respondWithResult(_0x49b5bf,null))[_0xb34c('0x46')](handleError(_0x49b5bf,null));};exports[_0xb34c('0x58')]=function(_0x20ae6b,_0x23d7fa){var _0x5ebacd={'raw':![],'where':{}};var _0x266ebf={};var _0x2f5ef0={'count':0x0,'rows':[]};return db[_0xb34c('0x2e')][_0xb34c('0x59')]({'where':{'id':_0x20ae6b['params']['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x23d7fa,null))['then'](function(_0x234e72){if(_0x234e72){_0x266ebf[_0xb34c('0x32')]=_[_0xb34c('0x48')](db[_0xb34c('0x57')]['rawAttributes']);_0x266ebf[_0xb34c('0x33')]=_['keys'](_0x20ae6b[_0xb34c('0x33')]);_0x266ebf[_0xb34c('0x34')]=_[_0xb34c('0x35')](_0x266ebf[_0xb34c('0x32')],_0x266ebf[_0xb34c('0x33')]);_0x5ebacd[_0xb34c('0x36')]=_[_0xb34c('0x35')](_0x266ebf['model'],qs[_0xb34c('0x37')](_0x20ae6b[_0xb34c('0x33')][_0xb34c('0x37')]));_0x5ebacd['attributes']=_0x5ebacd[_0xb34c('0x36')][_0xb34c('0x38')]?_0x5ebacd['attributes']:_0x266ebf[_0xb34c('0x32')];if(!_0x20ae6b[_0xb34c('0x33')]['hasOwnProperty'](_0xb34c('0x3a'))){_0x5ebacd['limit']=qs[_0xb34c('0x22')](_0x20ae6b[_0xb34c('0x33')][_0xb34c('0x22')]);_0x5ebacd[_0xb34c('0x20')]=qs['offset'](_0x20ae6b['query'][_0xb34c('0x20')]);}_0x5ebacd[_0xb34c('0x5a')]=qs[_0xb34c('0x3b')](_0x20ae6b[_0xb34c('0x33')][_0xb34c('0x3b')]);_0x5ebacd[_0xb34c('0x3c')]=qs[_0xb34c('0x34')](_['pick'](_0x20ae6b['query'],_0x266ebf[_0xb34c('0x34')]));_0x5ebacd[_0xb34c('0x3c')][_0xb34c('0x56')]=_0x234e72['id'];if(_0x20ae6b[_0xb34c('0x33')][_0xb34c('0x3e')]){_0x5ebacd[_0xb34c('0x3c')]=_[_0xb34c('0x3f')](_0x5ebacd['where'],{'$or':_[_0xb34c('0x40')](_0x5ebacd[_0xb34c('0x36')],function(_0x318a0b){var _0x4ec3b3={};_0x4ec3b3[_0x318a0b]={'$like':'%'+_0x20ae6b['query']['filter']+'%'};return _0x4ec3b3;})});}_0x5ebacd=_[_0xb34c('0x3f')]({},_0x5ebacd,_0x20ae6b[_0xb34c('0x41')]);return db[_0xb34c('0x57')][_0xb34c('0x23')]({'where':_0x5ebacd[_0xb34c('0x3c')]})[_0xb34c('0x15')](function(_0x32df89){_0x2f5ef0[_0xb34c('0x23')]=_0x32df89;if(_0x20ae6b[_0xb34c('0x33')][_0xb34c('0x42')]){_0x5ebacd[_0xb34c('0x43')]=[{'all':!![]}];}return db['Disposition'][_0xb34c('0x44')](_0x5ebacd);})[_0xb34c('0x15')](function(_0x576ff6){_0x2f5ef0[_0xb34c('0x45')]=_0x576ff6;return _0x2f5ef0;});}})[_0xb34c('0x15')](respondWithFilteredResult(_0x23d7fa,_0x5ebacd))[_0xb34c('0x46')](handleError(_0x23d7fa,null));};exports['removeDispositions']=function(_0x1f4039,_0x666022){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x1f4039['params']['id']}})['then'](handleEntityNotFound(_0x666022,null))[_0xb34c('0x15')](function(_0x2392de){if(_0x2392de){return _0x2392de[_0xb34c('0x5b')](_0x1f4039['query'][_0xb34c('0x5c')]);}})[_0xb34c('0x15')](respondWithStatusCode(_0x666022,null))[_0xb34c('0x46')](handleError(_0x666022,null));};exports[_0xb34c('0x5d')]=function(_0x56a374,_0x4ad259){if(_0x56a374[_0xb34c('0x4c')]['id']){delete _0x56a374[_0xb34c('0x4c')]['id'];}return db['ChatWebsite'][_0xb34c('0x4a')]({'where':{'id':_0x56a374[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x4ad259,null))[_0xb34c('0x15')](function(_0x4e9119){if(_0x4e9119){_0x56a374[_0xb34c('0x4c')][_0xb34c('0x56')]=_0x4e9119['id'];return db[_0xb34c('0x5e')][_0xb34c('0x4b')](_0x56a374[_0xb34c('0x4c')]);}})['then'](respondWithResult(_0x4ad259,null))[_0xb34c('0x46')](handleError(_0x4ad259,null));};exports['getAnswers']=function(_0xebf721,_0x3fd097){var _0xea1dd4={'raw':![],'where':{}};var _0x3d12a8={};var _0x208afb={'count':0x0,'rows':[]};return db[_0xb34c('0x2e')]['findOne']({'where':{'id':_0xebf721[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x3fd097,null))[_0xb34c('0x15')](function(_0x4d6129){if(_0x4d6129){_0x3d12a8[_0xb34c('0x32')]=_['keys'](db[_0xb34c('0x5e')][_0xb34c('0x49')]);_0x3d12a8[_0xb34c('0x33')]=_[_0xb34c('0x48')](_0xebf721[_0xb34c('0x33')]);_0x3d12a8[_0xb34c('0x34')]=_['intersection'](_0x3d12a8[_0xb34c('0x32')],_0x3d12a8[_0xb34c('0x33')]);_0xea1dd4[_0xb34c('0x36')]=_[_0xb34c('0x35')](_0x3d12a8[_0xb34c('0x32')],qs[_0xb34c('0x37')](_0xebf721[_0xb34c('0x33')]['fields']));_0xea1dd4['attributes']=_0xea1dd4[_0xb34c('0x36')]['length']?_0xea1dd4[_0xb34c('0x36')]:_0x3d12a8[_0xb34c('0x32')];if(!_0xebf721['query'][_0xb34c('0x39')](_0xb34c('0x3a'))){_0xea1dd4['limit']=qs[_0xb34c('0x22')](_0xebf721['query']['limit']);_0xea1dd4[_0xb34c('0x20')]=qs[_0xb34c('0x20')](_0xebf721[_0xb34c('0x33')][_0xb34c('0x20')]);}_0xea1dd4[_0xb34c('0x5a')]=qs[_0xb34c('0x3b')](_0xebf721[_0xb34c('0x33')]['sort']);_0xea1dd4[_0xb34c('0x3c')]=qs[_0xb34c('0x34')](_['pick'](_0xebf721[_0xb34c('0x33')],_0x3d12a8[_0xb34c('0x34')]));_0xea1dd4[_0xb34c('0x3c')]['ChatWebsiteId']=_0x4d6129['id'];if(_0xebf721[_0xb34c('0x33')][_0xb34c('0x3e')]){_0xea1dd4['where']=_[_0xb34c('0x3f')](_0xea1dd4[_0xb34c('0x3c')],{'$or':_[_0xb34c('0x40')](_0xea1dd4[_0xb34c('0x36')],function(_0x10603a){var _0x1f57fe={};_0x1f57fe[_0x10603a]={'$like':'%'+_0xebf721[_0xb34c('0x33')]['filter']+'%'};return _0x1f57fe;})});}_0xea1dd4=_[_0xb34c('0x3f')]({},_0xea1dd4,_0xebf721[_0xb34c('0x41')]);return db[_0xb34c('0x5e')][_0xb34c('0x23')]({'where':_0xea1dd4[_0xb34c('0x3c')]})['then'](function(_0x2368db){_0x208afb[_0xb34c('0x23')]=_0x2368db;if(_0xebf721[_0xb34c('0x33')]['includeAll']){_0xea1dd4[_0xb34c('0x43')]=[{'all':!![]}];}return db[_0xb34c('0x5e')][_0xb34c('0x44')](_0xea1dd4);})[_0xb34c('0x15')](function(_0x11d3df){_0x208afb['rows']=_0x11d3df;return _0x208afb;});}})['then'](respondWithFilteredResult(_0x3fd097,_0xea1dd4))['catch'](handleError(_0x3fd097,null));};exports[_0xb34c('0x5f')]=function(_0x596d1d,_0x40e42b){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x596d1d['params']['id']}})['then'](handleEntityNotFound(_0x40e42b,null))[_0xb34c('0x15')](function(_0x33840a){if(_0x33840a){return _0x33840a[_0xb34c('0x5f')](_0x596d1d['query'][_0xb34c('0x5c')]);}})['then'](respondWithStatusCode(_0x40e42b,null))[_0xb34c('0x46')](handleError(_0x40e42b,null));};exports[_0xb34c('0x60')]=function(_0x34f086,_0x3d78aa){_0x34f086[_0xb34c('0x4c')][_0xb34c('0x61')]=_0x34f086[_0xb34c('0x62')][_0xb34c('0x63')];return db['ChatWebsite'][_0xb34c('0x4a')]({'where':{'id':_0x34f086[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x3d78aa,null))[_0xb34c('0x15')](saveUpdates(_0x34f086[_0xb34c('0x4c')],null))[_0xb34c('0x15')](respondWithResult(_0x3d78aa,null))[_0xb34c('0x46')](handleError(_0x3d78aa,null));};exports[_0xb34c('0x64')]=function(_0x13d3ee,_0x4d49fb){_0x13d3ee[_0xb34c('0x4c')]['agentAvatar']=_0x13d3ee[_0xb34c('0x62')]['filename'];return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x13d3ee['params']['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x4d49fb,null))['then'](saveUpdates(_0x13d3ee[_0xb34c('0x4c')],null))[_0xb34c('0x15')](respondWithResult(_0x4d49fb,null))[_0xb34c('0x46')](handleError(_0x4d49fb,null));};exports['addCustomerAvatar']=function(_0x35b21c,_0x2ae871){_0x35b21c[_0xb34c('0x4c')][_0xb34c('0x65')]=_0x35b21c[_0xb34c('0x62')][_0xb34c('0x63')];return db[_0xb34c('0x2e')]['find']({'where':{'id':_0x35b21c[_0xb34c('0x47')]['id']}})['then'](handleEntityNotFound(_0x2ae871,null))[_0xb34c('0x15')](saveUpdates(_0x35b21c[_0xb34c('0x4c')],null))[_0xb34c('0x15')](respondWithResult(_0x2ae871,null))[_0xb34c('0x46')](handleError(_0x2ae871,null));};exports[_0xb34c('0x66')]=function(_0x201b4d,_0x2afa71){_0x201b4d[_0xb34c('0x4c')][_0xb34c('0x67')]=_0x201b4d[_0xb34c('0x62')][_0xb34c('0x63')];return db['ChatWebsite'][_0xb34c('0x4a')]({'where':{'id':_0x201b4d['params']['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x2afa71,null))['then'](saveUpdates(_0x201b4d[_0xb34c('0x4c')],null))[_0xb34c('0x15')](respondWithResult(_0x2afa71,null))[_0xb34c('0x46')](handleError(_0x2afa71,null));};exports[_0xb34c('0x68')]=function(_0x34a26d,_0x31afac){var _0x20632a=path[_0xb34c('0x69')](config['root'],'server/files/images/logos/default_logo.svg');var _0x426e9d={'where':{'id':_0x34a26d[_0xb34c('0x47')]['id']},'attributes':['id',_0xb34c('0x61')],'raw':!![]};var _0xd1cf8f=![];return require('../../config/license/util')['getLicense']()['then'](function(_0x360765){if(_0x360765){_0xd1cf8f=_0x360765['custom'];}})['then'](function(){return db['ChatWebsite']['find'](_0x426e9d);})[_0xb34c('0x15')](handleEntityNotFound(_0x31afac,null))[_0xb34c('0x15')](function(_0x244015){if(_0x244015){if(!_[_0xb34c('0x6a')](_0x244015[_0xb34c('0x61')])){if(fs[_0xb34c('0x6b')](path['join'](config[_0xb34c('0x6c')],_0xb34c('0x6d'),_0x244015['sitepic']))&&_0xd1cf8f){_0x20632a=path[_0xb34c('0x69')](config[_0xb34c('0x6c')],'server/files/images/logos/',_0x244015[_0xb34c('0x61')]);}}return _0x31afac[_0xb34c('0x6e')](_0x20632a);}})[_0xb34c('0x46')](handleError(_0x31afac,null));};exports[_0xb34c('0x6f')]=function(_0x34a36b,_0x2f7035){var _0x29e095=path['join'](config[_0xb34c('0x6c')],_0xb34c('0x70'));var _0x3dc1f7={'where':{'id':_0x34a36b[_0xb34c('0x47')]['id']},'attributes':['id',_0xb34c('0x71')],'raw':!![]};return db[_0xb34c('0x2e')][_0xb34c('0x4a')](_0x3dc1f7)[_0xb34c('0x15')](handleEntityNotFound(_0x2f7035,null))['then'](function(_0x2120f8){if(_0x2120f8){if(!_['isNil'](_0x2120f8[_0xb34c('0x71')])){if(fs[_0xb34c('0x6b')](path['join'](config[_0xb34c('0x6c')],_0xb34c('0x72'),_0x2120f8[_0xb34c('0x71')]))){_0x29e095=path['join'](config['root'],_0xb34c('0x72'),_0x2120f8[_0xb34c('0x71')]);}}return _0x2f7035[_0xb34c('0x6e')](_0x29e095);}})['catch'](handleError(_0x2f7035,null));};exports['getCustomerAvatar']=function(_0xd936e1,_0x38978a){var _0x11b09b=path['join'](config[_0xb34c('0x6c')],_0xb34c('0x73'));var _0x1b7c0d={'where':{'id':_0xd936e1['params']['id']},'attributes':['id','customerAvatar',_0xb34c('0x74')],'raw':!![]};return db[_0xb34c('0x2e')][_0xb34c('0x4a')](_0x1b7c0d)[_0xb34c('0x15')](handleEntityNotFound(_0x38978a,null))[_0xb34c('0x15')](function(_0x1acee9){if(_0x1acee9){if(!_[_0xb34c('0x6a')](_0x1acee9[_0xb34c('0x65')])){if(fs[_0xb34c('0x6b')](path[_0xb34c('0x69')](config['root'],_0xb34c('0x72'),_0x1acee9[_0xb34c('0x65')]))&&_0x1acee9[_0xb34c('0x74')]){_0x11b09b=path[_0xb34c('0x69')](config[_0xb34c('0x6c')],_0xb34c('0x72'),_0x1acee9[_0xb34c('0x65')]);}}return _0x38978a[_0xb34c('0x6e')](_0x11b09b);}})[_0xb34c('0x46')](handleError(_0x38978a,null));};exports[_0xb34c('0x75')]=function(_0x78691,_0x4509f1){var _0x126e60=path[_0xb34c('0x69')](config['root'],'server/files/images/avatars/system_avatar.png');var _0x47c3f2={'where':{'id':_0x78691[_0xb34c('0x47')]['id']},'attributes':['id',_0xb34c('0x67')],'raw':!![]};return db[_0xb34c('0x2e')][_0xb34c('0x4a')](_0x47c3f2)['then'](handleEntityNotFound(_0x4509f1,null))[_0xb34c('0x15')](function(_0x31b6aa){if(_0x31b6aa){if(!_[_0xb34c('0x6a')](_0x31b6aa[_0xb34c('0x67')])){if(fs[_0xb34c('0x6b')](path[_0xb34c('0x69')](config[_0xb34c('0x6c')],'server/files/images/avatars/',_0x31b6aa[_0xb34c('0x67')]))){_0x126e60=path[_0xb34c('0x69')](config[_0xb34c('0x6c')],'server/files/images/avatars/',_0x31b6aa[_0xb34c('0x67')]);}}return _0x4509f1[_0xb34c('0x6e')](_0x126e60);}})[_0xb34c('0x46')](handleError(_0x4509f1,null));};exports[_0xb34c('0x76')]=function(_0x57f4de,_0x5e2683){var _0x39ada3=require(_0xb34c('0x77'));var _0x3a6350=new _0x39ada3();var _0x110292=_0x3a6350[_0xb34c('0x78')](_0x57f4de[_0xb34c('0x79')][_0xb34c('0x7a')])[_0xb34c('0x7b')]();var _0x178aee={'body':_0x57f4de['body'],'channel':'chat'};var _0x4075d9=[];var _0x31e9a6=[];var _0xc29103={};var _0x1da3d0=![];return db[_0xb34c('0x7c')][_0xb34c('0x54')]()[_0xb34c('0x15')](function(_0x4cf713){if(!_0x4cf713){throw new db['Sequelize'][(_0xb34c('0x7d'))](_0xb34c('0x7e'));}_0x4075d9=_[_0xb34c('0x7f')](_[_0xb34c('0x48')](_0x4cf713),['createdAt',_0xb34c('0x80')]);_0x31e9a6=_[_0xb34c('0x7f')](_[_0xb34c('0x48')](_0x4cf713),[_0xb34c('0x81'),_0xb34c('0x80'),_0xb34c('0x82'),_0xb34c('0x83')]);if(_0x57f4de['body']['id']){delete _0x57f4de[_0xb34c('0x4c')]['id'];}if(_['isNil'](_0x57f4de['body'][_0xb34c('0x84')])){throw new db[(_0xb34c('0x85'))][(_0xb34c('0x7d'))](_0xb34c('0x86'));}if(_['isNil'](_0x57f4de[_0xb34c('0x4c')][_0xb34c('0x4c')])||_0x57f4de[_0xb34c('0x4c')][_0xb34c('0x4c')]===''){throw new db['Sequelize'][(_0xb34c('0x7d'))](_0xb34c('0x87'));}if(_[_0xb34c('0x6a')](_0x57f4de['body']['mapKey'])){throw new db['Sequelize'][(_0xb34c('0x7d'))](_0xb34c('0x88')+_0x31e9a6);}if(!_[_0xb34c('0x89')](_0x31e9a6,_0x57f4de[_0xb34c('0x4c')]['mapKey'])){throw new db['Sequelize'][(_0xb34c('0x7d'))](_0xb34c('0x8a')+_0x31e9a6);}_0xc29103[_0x57f4de[_0xb34c('0x4c')]['mapKey']]=_0x57f4de[_0xb34c('0x4c')]['from'];})[_0xb34c('0x15')](function(){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x57f4de[_0xb34c('0x47')]['id']},'include':[{'model':db[_0xb34c('0x8b')],'as':'List','include':[{'model':db[_0xb34c('0x7c')],'as':_0xb34c('0x8c'),'where':_0xc29103,'limit':0x1,'order':[['updatedAt',_0xb34c('0x8d')]]}]},{'model':db[_0xb34c('0x8e')],'as':_0xb34c('0x8f')}]});})['then'](handleEntityNotFound(_0x5e2683,null))[_0xb34c('0x15')](function(_0x30b045){if(_0x30b045&&_0x30b045[_0xb34c('0x90')]){_0x178aee[_0xb34c('0x91')]=_0x30b045;_0x178aee[_0xb34c('0x92')]=_0x30b045[_0xb34c('0x8f')];_0x178aee[_0xb34c('0x93')]=_0x30b045[_0xb34c('0x90')];_0x178aee[_0xb34c('0x92')]=_[_0xb34c('0x94')](_0x178aee[_0xb34c('0x92')],[_0xb34c('0x95')],[_0xb34c('0x96')]);if(_0x178aee[_0xb34c('0x91')][_0xb34c('0x8f')]){delete _0x178aee[_0xb34c('0x91')][_0xb34c('0x8f')];}if(_0x178aee['account'][_0xb34c('0x90')]&&_0x178aee[_0xb34c('0x91')]['List'][_0xb34c('0x8c')][_0xb34c('0x38')]){return _0x178aee[_0xb34c('0x91')]['List']['Contacts'][0x0];}var _0x816cea=_['defaults'](_0x57f4de['body'],{'firstName':_0x57f4de[_0xb34c('0x4c')][_0xb34c('0x84')],'ListId':_0x30b045[_0xb34c('0x83')]});_0x816cea[_0x57f4de[_0xb34c('0x4c')][_0xb34c('0x97')]]=_0x57f4de[_0xb34c('0x4c')][_0xb34c('0x84')];return db['CmContact'][_0xb34c('0x4b')](_0x816cea,{'fields':_0x4075d9,'raw':!![]});}})[_0xb34c('0x15')](handleEntityNotFound(_0x5e2683,null))['then'](function(_0x153b2a){_0x178aee['contact']=_0x153b2a;var _0x39a680=_0x57f4de['body'][_0xb34c('0x98')];if(_0x57f4de[_0xb34c('0x79')][_0xb34c('0x99')]){_0x39a680=_0x57f4de[_0xb34c('0x79')][_0xb34c('0x99')];}else if(_0x57f4de['headers'][_0xb34c('0x9a')]){_0x39a680=_[_0xb34c('0x9b')](_0x57f4de[_0xb34c('0x79')][_0xb34c('0x9a')][_0xb34c('0x9c')](','));}if(_0x153b2a){var _0x3a69e4={'ContactId':_0x153b2a['id'],'ChatWebsiteId':_0x57f4de[_0xb34c('0x47')]['id'],'from':(_0x153b2a[_0xb34c('0x9d')]||'')+'\x20'+(_0x153b2a[_0xb34c('0x9e')]||''),'customerIp':_0x39a680,'customerPort':_0x57f4de[_0xb34c('0x79')][_0xb34c('0x9f')]?_0x57f4de['headers']['x-real-port']:null,'referer':_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xa0')],'browserName':_0x110292[_0xb34c('0xa1')]['name']&&_0x110292[_0xb34c('0xa1')][_0xb34c('0xa2')]?util[_0xb34c('0xa3')]('%s\x20%s',_0x110292['browser'][_0xb34c('0x2a')],_0x110292[_0xb34c('0xa1')]['version']):_0xb34c('0xa4'),'browserVersion':_0x110292['browser'][_0xb34c('0xa2')]||_0xb34c('0xa4'),'osName':util[_0xb34c('0xa3')](_0xb34c('0xa5'),_0x110292['os'][_0xb34c('0x2a')],_0x110292['os']['version']),'osVersion':_0x110292['os'][_0xb34c('0xa2')],'deviceModel':_0x110292[_0xb34c('0xa6')][_0xb34c('0x32')]&&_0x110292[_0xb34c('0xa6')][_0xb34c('0xa7')]?util[_0xb34c('0xa3')](_0xb34c('0xa8'),_0x110292[_0xb34c('0xa6')][_0xb34c('0x32')],_0x110292[_0xb34c('0xa6')]['vendor'],_0x110292[_0xb34c('0xa6')][_0xb34c('0x30')]):null,'deviceVendor':_0x110292['device']['vendor'],'deviceType':_0x110292[_0xb34c('0xa6')]['type'],'formData':JSON[_0xb34c('0x18')](_0x57f4de[_0xb34c('0x4c')])};var _0x264cfa={'ChatWebsiteId':_0x57f4de[_0xb34c('0x47')]['id'],'closed':![]};if(_0x57f4de['body'][_0xb34c('0xa9')]){_0x264cfa[_0xb34c('0xa9')]=_0x57f4de[_0xb34c('0x4c')]['threadId'];return db[_0xb34c('0xaa')][_0xb34c('0x4a')]({'where':_0x264cfa})[_0xb34c('0x15')](function(_0x4bfd57){if(_0x4bfd57){return[_0x4bfd57,![]];}_0x3a69e4[_0xb34c('0xa9')]=_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xa9')];_0x3a69e4[_0xb34c('0xab')]=_0x57f4de[_0xb34c('0x4c')]['externalUrl'];return db[_0xb34c('0xaa')][_0xb34c('0x4b')](_0x3a69e4)[_0xb34c('0x15')](function(_0x41d5dc){return[_0x41d5dc,!![]];});});}_0x264cfa[_0xb34c('0xac')]=_0x153b2a['id'];if(_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xad')]&&_0x57f4de[_0xb34c('0x4c')]['interaction']['id']){_0x264cfa['id']=_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xad')]['id'];return db[_0xb34c('0xaa')][_0xb34c('0x4a')]({'where':_0x264cfa})[_0xb34c('0x15')](function(_0x1035da){if(_0x1035da){return[_0x1035da,![]];}return db['ChatInteraction'][_0xb34c('0x4b')](_0x3a69e4)[_0xb34c('0x15')](function(_0x281132){return[_0x281132,!![]];});});}return db[_0xb34c('0xaa')][_0xb34c('0x4b')](_0x3a69e4)[_0xb34c('0x15')](function(_0x5b1304){return[_0x5b1304,!![]];});}})['spread'](function(_0x22e261,_0x3d82f2){if(_0x22e261){_0x1da3d0=_0x3d82f2;if(!_0x3d82f2){var _0x2bae9a={'from':(_0x178aee[_0xb34c('0xae')][_0xb34c('0x9d')]||'')+'\x20'+(_0x178aee[_0xb34c('0xae')][_0xb34c('0x9e')]||'')};if(_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xa9')]&&_0x57f4de['body'][_0xb34c('0xaf')]&&_0x57f4de['body']['threadId']!=_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xaf')]){_0x2bae9a['threadId']=_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xaf')];}return _0x22e261[_0xb34c('0x26')](_0x2bae9a);}else{return _0x22e261;}}})[_0xb34c('0x15')](function(_0x355cda){_0x178aee[_0xb34c('0xad')]=_0x355cda['get']({'plain':!![]});_0x178aee[_0xb34c('0xad')][_0xb34c('0xb0')]=_0x1da3d0;if(_0x178aee['interaction'][_0xb34c('0xb0')]){if(_0x178aee[_0xb34c('0x91')]['autoclose']){_0x178aee[_0xb34c('0x92')][_0xb34c('0xb1')]({'id':0x0,'priority':_0x178aee[_0xb34c('0x92')][_0xb34c('0x38')]+0x1,'app':_0xb34c('0xb2'),'appdata':_0xb34c('0xb3'),'interval':'*,*,*,*'});}}return db[_0xb34c('0xb4')]['create']({'body':_0x57f4de[_0xb34c('0x4c')][_0xb34c('0x4c')],'ChatWebsiteId':_0x57f4de['params']['id'],'ChatInteractionId':_0x355cda['id'],'direction':'in','ContactId':_0x178aee[_0xb34c('0xae')]['id'],'AttachmentId':_0x57f4de[_0xb34c('0x4c')][_0xb34c('0xb5')]});})[_0xb34c('0x15')](function(_0x187ace){_0x178aee[_0xb34c('0x1a')]=_0x187ace;if(_0x178aee[_0xb34c('0xad')]['UserId']){return db[_0xb34c('0xb6')][_0xb34c('0x4a')]({'attributes':['id',_0xb34c('0x2a')],'where':{'id':_0x178aee['interaction'][_0xb34c('0xb7')]}})[_0xb34c('0x15')](function(_0x1897b9){if(_0x1897b9){_0x178aee['applications'][_0xb34c('0xb8')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x1897b9[_0xb34c('0x2a')]+','+(_0x178aee['account'][_0xb34c('0xb9')]||0xa),'interval':_0xb34c('0xba')});_0x178aee[_0xb34c('0xbb')]=!![];}return respondWithRpcPromise('Start',_0xb34c('0xbc'),_0x178aee);});}return respondWithRpcPromise(_0xb34c('0xbd'),_0xb34c('0xbc'),_0x178aee);})['then'](function(_0x190213){respondWithRpcPromise(_0xb34c('0xbe'),_0xb34c('0xbe'),{'event':'notify','message':_0x190213},client9002);return _0x190213;})[_0xb34c('0x15')](respondWithResult(_0x5e2683,null))[_0xb34c('0x46')](handleError(_0x5e2683,null));};exports[_0xb34c('0xbf')]=function(_0x578261,_0x322903){var _0x5a1aa7,_0x40a17b,_0x8f6790;var _0x2c764a=[];var _0x3e13c8={};var _0x48eb8f=_0x578261[_0xb34c('0xc0')]||[];var _0x567ee2=[];var _0x20d719;return db[_0xb34c('0x7c')][_0xb34c('0x54')]()[_0xb34c('0x15')](function(_0x2f7219){if(!_0x2f7219){throw new db[(_0xb34c('0x85'))][(_0xb34c('0x7d'))](_0xb34c('0x7e'));}_0x2c764a=_['difference'](_[_0xb34c('0x48')](_0x2f7219),[_0xb34c('0x81'),_0xb34c('0x80'),_0xb34c('0x82'),_0xb34c('0x83')]);if(_0x578261[_0xb34c('0x4c')]['id']){delete _0x578261[_0xb34c('0x4c')]['id'];}if(_[_0xb34c('0x6a')](_0x578261[_0xb34c('0x4c')][_0xb34c('0x84')])){throw _0x322903[_0xb34c('0x1e')](0x1f4)[_0xb34c('0x2b')](new db[(_0xb34c('0x85'))]['ValidationError'](_0xb34c('0x86')));}if(_[_0xb34c('0x6a')](_0x578261['body'][_0xb34c('0x4c')])||_0x578261[_0xb34c('0x4c')][_0xb34c('0x4c')]===''){throw _0x322903[_0xb34c('0x1e')](0x1f4)[_0xb34c('0x2b')](new db['Sequelize'][(_0xb34c('0x7d'))](_0xb34c('0x87')));}if(_[_0xb34c('0x6a')](_0x578261[_0xb34c('0x4c')]['mapKeyOffline'])){throw _0x322903[_0xb34c('0x1e')](0x1f4)[_0xb34c('0x2b')](new db[(_0xb34c('0x85'))][(_0xb34c('0x7d'))]('mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2c764a));}if(!_[_0xb34c('0x89')](_0x2c764a,_0x578261[_0xb34c('0x4c')][_0xb34c('0xc1')])){throw _0x322903[_0xb34c('0x1e')](0x1f4)[_0xb34c('0x2b')](new db[(_0xb34c('0x85'))][(_0xb34c('0x7d'))](_0xb34c('0xc2')+_0x2c764a));}_0x3e13c8[_0x578261[_0xb34c('0x4c')][_0xb34c('0xc1')]]=_0x578261[_0xb34c('0x4c')][_0xb34c('0x84')];})[_0xb34c('0x15')](function(){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x578261['params']['id']},'include':[{'model':db[_0xb34c('0x8b')],'as':_0xb34c('0x90')},{'model':db['MailAccount'],'as':_0xb34c('0xc3')}]});})[_0xb34c('0x15')](handleEntityNotFound(_0x322903,null))[_0xb34c('0x15')](function(_0x406777){if(_0x406777&&_0x406777[_0xb34c('0x90')]){_0x40a17b=_0x406777;var _0x294340=_[_0xb34c('0xc')](_0x578261[_0xb34c('0x4c')],{'firstName':_0x578261[_0xb34c('0x4c')][_0xb34c('0x84')],'phone':_0x578261[_0xb34c('0x4c')]['from'],'ListId':_0x406777[_0xb34c('0x83')]});_0x294340[_0x578261['body'][_0xb34c('0xc1')]]=_0x578261['body'][_0xb34c('0x84')];return db[_0xb34c('0x7c')][_0xb34c('0xc4')]({'where':_0x3e13c8,'defaults':_0x294340});}})[_0xb34c('0xc5')](function(_0x4c42c9){if(_0x4c42c9){_0x8f6790=_0x4c42c9;var _0x48ea4b=fs[_0xb34c('0xc6')](path[_0xb34c('0x69')](config[_0xb34c('0x6c')],_0xb34c('0xc7')),_0xb34c('0xc8'));var _0x992bc=ejs[_0xb34c('0xc9')](_0x48ea4b,{'body':_[_0xb34c('0xca')](_0x578261[_0xb34c('0x4c')][_0xb34c('0x4c')]),'bodyTitle':_0x40a17b['offlineMessageBody']});return db[_0xb34c('0xcb')][_0xb34c('0x4b')]({'body':_0x992bc,'plainBody':htmlToText[_0xb34c('0xcc')](_0x992bc),'ContactId':_0x4c42c9['id'],'ChatWebsiteId':_0x40a17b['id']});}})[_0xb34c('0x15')](function(_0x587e95){_0x20d719=_0x587e95;if(_0x48eb8f[_0xb34c('0x38')]){var _0x2874ae=_0x48eb8f[_0xb34c('0x40')](function(_0x222b8b){return{'name':_0x222b8b['originalname'],'basename':_0x222b8b[_0xb34c('0x63')],'type':_0x222b8b[_0xb34c('0xcd')],'ChatOfflineMessageId':_0x587e95['id']};});_0x567ee2=_0x2874ae[_0xb34c('0x40')](_0x24e328=>{var _0x172c38={'filename':_0x24e328[_0xb34c('0x2a')],'path':path[_0xb34c('0x69')](config[_0xb34c('0x6c')],_0xb34c('0xce'),'files',_0xb34c('0xcf'),_0xb34c('0xd0'),_0x24e328[_0xb34c('0xd1')])};return _0x172c38;});if(!_0x40a17b[_0xb34c('0xd2')]){return db['sequelize'][_0xb34c('0xd3')](function(_0x409ba4){return db[_0xb34c('0xd4')][_0xb34c('0xd5')](_0x2874ae,{'transaction':_0x409ba4});});}}})['then'](function(){if(_0x20d719){_0x5a1aa7=_0x20d719;return db[_0xb34c('0xc3')]['findOne']({'where':{'service':!![]},'include':[{'model':db['MailServerOut'],'as':_0xb34c('0xd6'),'raw':!![],'include':[{'model':db[_0xb34c('0xd7')],'as':_0xb34c('0xd7'),'raw':!![]}]}]});}})['then'](function(_0x33c6ba){if(_0x33c6ba&&_0x33c6ba['Smtp']&&_0x40a17b['forwardOffline']&&_0x40a17b['forwardOfflineAddress']){var _0x169a79=_0x33c6ba[_0xb34c('0xd8')]();return respondWithRpcPromise(_0xb34c('0xd9'),_0xb34c('0xda'),{'account':_0x169a79,'message':{'from':util[_0xb34c('0xa3')](_0xb34c('0xdb'),_0x33c6ba['name'],_0x33c6ba[_0xb34c('0xdc')]||_0x33c6ba[_0xb34c('0xd6')]['user']),'to':_0x40a17b[_0xb34c('0xdd')],'subject':_0x40a17b['offlineMessageSubject'],'html':_0x5a1aa7['body'],'attachments':_0x567ee2}},client9003)[_0xb34c('0x15')](function(){return _0x5a1aa7;})[_0xb34c('0x46')](function(_0x1abac1){logger[_0xb34c('0x19')](_0x1abac1);});}})[_0xb34c('0x15')](function(){if(_0x40a17b&&_0x40a17b['openNewInteraction']&&_0x40a17b['MailAccountId']){var _0xb1fab1=[];if(_0x48eb8f[_0xb34c('0x38')]){_0xb1fab1=_0x48eb8f[_0xb34c('0x40')](function(_0x4f9225){return{'name':_0x4f9225[_0xb34c('0xde')],'basename':_0x4f9225[_0xb34c('0x63')],'type':_0x4f9225['mimetype'],'ChatOfflineMessageId':_0x20d719['id']};});}var _0x75d987;if(!_[_0xb34c('0x6a')](_0x40a17b[_0xb34c('0xdf')])){var _0x265397=_['map'](_0x578261[_0xb34c('0x4c')],function(_0x3f191b){return _0x3f191b;});var _0x500084=_[_0xb34c('0xe0')](_0x265397)[0x0];var _0x463d00=_['mapValues'](_0x500084,function(_0xc1f34a){return _0xc1f34a;});_0x75d987=_0x463d00[0x1][_0x40a17b[_0xb34c('0xdf')]];}var _0x1c6ab5={'from':_0x8f6790[_0xb34c('0xdc')],'firstName':_0x8f6790[_0xb34c('0x9d')],'lastName':_0x8f6790[_0xb34c('0x9e')],'mapKey':'email','message':{'from':_0x8f6790[_0xb34c('0xdc')],'to':_0x40a17b[_0xb34c('0xc3')][_0xb34c('0xdc')],'cc':'','subject':_[_0xb34c('0x6a')](_0x75d987)?_0x40a17b[_0xb34c('0xe1')]:_0x75d987,'messageId':'','sentAt':new Date(),'attach':_0xb1fab1[_0xb34c('0x38')],'attachments':_0xb1fab1,'originChannel':_0xb34c('0xe2'),'ChatWebsiteId':_0x40a17b['id'],'ChatOfflineMessageId':_0x5a1aa7['id'],'originTo':_0x40a17b[_0xb34c('0xc3')][_0xb34c('0xdc')]},'body':_0x5a1aa7['body']};var _0x17c9e0={'account':{'id':_0x40a17b[_0xb34c('0xe3')]},'body':_0x1c6ab5,'log':'NotifyMailAccount'};return respondWithRpcPromise(_0xb34c('0xe4'),'notifyMail',_0x17c9e0,client9001)[_0xb34c('0x15')](function(){return _0x5a1aa7;})[_0xb34c('0x46')](function(_0xd56af1){logger[_0xb34c('0x19')](_0xd56af1);});}return;})[_0xb34c('0x15')](function(){if(_0x5a1aa7){return _0x5a1aa7;}})[_0xb34c('0x15')](respondWithResult(_0x322903,null))[_0xb34c('0x46')](function(_0x1e2709){logger[_0xb34c('0x19')]('catch',_0x1e2709);for(var _0x1d72c7 of _0x48eb8f){var _0x22c59c=path[_0xb34c('0x69')](config[_0xb34c('0x6c')],'server',_0xb34c('0xc0'),_0xb34c('0xcf'),'offline-chat',_0x1d72c7[_0xb34c('0x63')]);fs_extra[_0xb34c('0xe5')](_0x22c59c)[_0xb34c('0x46')](function(_0x468d30){logger[_0xb34c('0x19')](_0xb34c('0xe6'),_0x22c59c,_0x468d30);});}});};exports['addInteraction']=function(_0x78cfb4,_0x12772e){return db['ChatInteraction'][_0xb34c('0x4a')]({'where':{'id':_0x78cfb4['params']['id']}})['then'](handleEntityNotFound(_0x12772e,null))[_0xb34c('0x15')](function(_0x1ffbd5){if(_0x1ffbd5){return _0x1ffbd5[_0xb34c('0xe7')](_0x78cfb4['body'][_0xb34c('0x5c')],_[_0xb34c('0xe8')](_0x78cfb4[_0xb34c('0x4c')],[_0xb34c('0x5c'),'id'])||{});}})[_0xb34c('0x15')](respondWithResult(_0x12772e,null))[_0xb34c('0x46')](handleError(_0x12772e,null));};exports[_0xb34c('0xe9')]=function(_0xed5cd,_0x585010){var _0x84bf34={'raw':![],'where':{}};var _0x434aef={};var _0x32deb9={'count':0x0,'rows':[]};return db[_0xb34c('0x2e')]['findOne']({'where':{'id':_0xed5cd[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x585010,null))[_0xb34c('0x15')](function(_0x38955d){if(_0x38955d){_0x434aef[_0xb34c('0x32')]=_['keys'](db['ChatInteraction'][_0xb34c('0x49')]);_0x434aef['query']=_[_0xb34c('0x48')](_0xed5cd[_0xb34c('0x33')]);_0x434aef[_0xb34c('0x34')]=_['intersection'](_0x434aef['model'],_0x434aef['query']);_0x84bf34[_0xb34c('0x36')]=_[_0xb34c('0x35')](_0x434aef[_0xb34c('0x32')],qs[_0xb34c('0x37')](_0xed5cd[_0xb34c('0x33')][_0xb34c('0x37')]));_0x84bf34[_0xb34c('0x36')]=_0x84bf34[_0xb34c('0x36')][_0xb34c('0x38')]?_0x84bf34[_0xb34c('0x36')]:_0x434aef['model'];if(!_0xed5cd['query'][_0xb34c('0x39')](_0xb34c('0x3a'))){_0x84bf34['limit']=qs[_0xb34c('0x22')](_0xed5cd[_0xb34c('0x33')][_0xb34c('0x22')]);_0x84bf34[_0xb34c('0x20')]=qs['offset'](_0xed5cd[_0xb34c('0x33')][_0xb34c('0x20')]);}_0x84bf34['order']=qs[_0xb34c('0x3b')](_0xed5cd[_0xb34c('0x33')][_0xb34c('0x3b')]);_0x84bf34[_0xb34c('0x3c')]=qs[_0xb34c('0x34')](_['pick'](_0xed5cd[_0xb34c('0x33')],_0x434aef[_0xb34c('0x34')]));_0x84bf34[_0xb34c('0x3c')]['ChatWebsiteId']=_0x38955d['id'];if(_0xed5cd['query']['filter']){_0x84bf34[_0xb34c('0x3c')]=_[_0xb34c('0x3f')](_0x84bf34[_0xb34c('0x3c')],{'$or':_[_0xb34c('0x40')](_0x84bf34[_0xb34c('0x36')],function(_0x54dab2){var _0x46c6b5={};_0x46c6b5[_0x54dab2]={'$like':'%'+_0xed5cd[_0xb34c('0x33')][_0xb34c('0x3e')]+'%'};return _0x46c6b5;})});}_0x84bf34=_[_0xb34c('0x3f')]({},_0x84bf34,_0xed5cd[_0xb34c('0x41')]);return db['ChatInteraction'][_0xb34c('0x23')]({'where':_0x84bf34['where']})['then'](function(_0x59b761){_0x32deb9[_0xb34c('0x23')]=_0x59b761;if(_0xed5cd[_0xb34c('0x33')][_0xb34c('0x42')]){_0x84bf34[_0xb34c('0x43')]=[{'model':db[_0xb34c('0x7c')],'as':_0xb34c('0xea'),'required':![]},{'model':db[_0xb34c('0xb6')],'as':'Owner','attributes':[_0xb34c('0x2a'),'fullname','internal'],'required':![]},{'model':db[_0xb34c('0xeb')],'as':_0xb34c('0xec'),'attributes':['id',_0xb34c('0x2a'),_0xb34c('0xed')],'where':_0xed5cd[_0xb34c('0x33')]['tag']?{'id':_0xed5cd['query'][_0xb34c('0xee')]}:undefined,'required':_0xed5cd['query'][_0xb34c('0xee')]?!![]:![]}];}return db[_0xb34c('0xaa')]['findAll'](_0x84bf34);})[_0xb34c('0x15')](function(_0x506fef){_0x32deb9[_0xb34c('0x45')]=_0x506fef;return _0x32deb9;});}})[_0xb34c('0x15')](respondWithFilteredResult(_0x585010,_0x84bf34))[_0xb34c('0x46')](handleError(_0x585010,null));};function iftimePromise(_0x403365,_0x304188){return respondWithRpcPromise('Command',_0xb34c('0xef'),{'command':_0x304188[_0xb34c('0xf0')]?util[_0xb34c('0xa3')](_0xb34c('0xf1'),_0x403365[_0xb34c('0xf2')],_0x304188[_0xb34c('0xf0')]):util[_0xb34c('0xa3')](_0xb34c('0xf3'),_0x403365[_0xb34c('0xf2')])},client9002)[_0xb34c('0x15')](function(_0x2e06e8){var _0x19ae27=_0x2e06e8&&_0x2e06e8['indexOf'](_0xb34c('0xf4'))>=0x0?!![]:![];logger[_0xb34c('0x1b')](_0xb34c('0xf5'),_0x304188['id'],_0x403365['id'],_0x403365['interval'],_0x19ae27?_0xb34c('0xf6'):'OFFLINE',_0x304188[_0xb34c('0xf0')]?_0x304188[_0xb34c('0xf0')]:_0xb34c('0xf7'));return _0x19ae27;})[_0xb34c('0x46')](function(_0x454f05){logger['error'](_0xb34c('0xf5'),_0x304188['id'],_0x403365['id'],_0x403365[_0xb34c('0xf2')],util[_0xb34c('0xf8')](_0x454f05,{'showHidden':![],'depth':null}),_0x304188[_0xb34c('0xf0')]?_0x304188[_0xb34c('0xf0')]:'No\x20timezone');return![];});}exports[_0xb34c('0xef')]=function(_0x524cf7,_0x5a6a9a){var _0x7e566=0x0;var _0x4d5c92=0x0;var _0x3e7d6f=![];var _0x1a8cae;var _0x1fff20;return db['ChatWebsite'][_0xb34c('0x4a')]({'where':{'id':_0x524cf7[_0xb34c('0x47')]['id']},'include':[{'model':db[_0xb34c('0xf9')],'as':_0xb34c('0xf9'),'include':[{'model':db[_0xb34c('0xf9')],'as':_0xb34c('0xfa'),'attributes':['id',_0xb34c('0xf2')],'raw':!![]}]}]})[_0xb34c('0x15')](handleEntityNotFound(_0x5a6a9a,null))[_0xb34c('0x15')](function(_0x5522b1){if(_0x5522b1){_0x1a8cae=_0x5522b1;return _0x5522b1[_0xb34c('0xfb')]({'raw':!![]});}})[_0xb34c('0x15')](function(_0x64ac6c){if(_0x1a8cae){if(_0x64ac6c){_0x1fff20=_0x64ac6c;}}return require(_0xb34c('0xfc'))[_0xb34c('0xfd')]();})[_0xb34c('0x15')](function(_0x4e0e47){if(_0x4e0e47){_0x4d5c92=_0x4e0e47[_0xb34c('0xfe')];_0x3e7d6f=_0x4e0e47[_0xb34c('0xff')];}})[_0xb34c('0x15')](function(){return db[_0xb34c('0xaa')][_0xb34c('0x23')]({'where':{'closed':![]}});})[_0xb34c('0x15')](function(_0x3e0ebd){_0x7e566=_0x3e0ebd;if(_0x4d5c92&&_0x3e0ebd>_0x4d5c92){return db['License'][_0xb34c('0x59')]({'where':{'id':0x1}})[_0xb34c('0x15')](function(_0x2bc916){if(_0x2bc916){_0x2bc916['increment'](_0xb34c('0x100'));}});}})[_0xb34c('0x15')](function(){if(_0x1a8cae[_0xb34c('0xf9')]&&_0x1a8cae[_0xb34c('0xf9')][_0xb34c('0xfa')]){var _0x3223a3=[];for(var _0x12930e=0x0;_0x12930e<_0x1a8cae[_0xb34c('0xf9')]['Intervals'][_0xb34c('0x38')];_0x12930e++){var _0xabb328=_0x1a8cae[_0xb34c('0xf9')]['Intervals'][_0x12930e]['get']({'plain':!![]});_0x3223a3[_0xb34c('0xb1')](iftimePromise(_0xabb328,_0x1a8cae));}return BPromise['all'](_0x3223a3)['then'](function(_0x266459){return _[_0xb34c('0x101')](_0x266459);});}else{return!![];}})[_0xb34c('0x15')](function(_0x6c9a6e){var _0x2c842c=fs[_0xb34c('0xc6')](path[_0xb34c('0x69')](config['root'],_0xb34c('0x102')),'utf8');var _0x4b5cca=new url['URL'](_0x1a8cae[_0xb34c('0x103')])[_0xb34c('0x104')];var _0x5bbe39=_0xb34c('0x105');var _0x48530f=![];var _0x5d16cf={'chatVersion':_0x5bbe39,'chatWebsiteAddressOrigin':_0x4b5cca,'remote':_0x1a8cae['remote'],'query':querystring[_0xb34c('0x18')](_['merge'](_0x1a8cae[_0xb34c('0x28')]({'plain':!![]}),{'customerIp':_0x524cf7['headers'][_0xb34c('0x9a')]||_0x524cf7[_0xb34c('0x79')][_0xb34c('0x106')]||_0x524cf7[_0xb34c('0x107')][_0xb34c('0x108')]||_0x524cf7['ip'],'referer':_0x524cf7[_0xb34c('0x79')]['referer'],'openedInteractions':_0x7e566,'maxInteractions':_0x4d5c92,'virtual':_0x3e7d6f[_0xb34c('0xfe')],'online':_0x6c9a6e,'custom':_0x3e7d6f}))[_0xb34c('0x109')](/'/g,'\x5c\x27')};_0x5a6a9a[_0xb34c('0x2b')](ejs[_0xb34c('0xc9')](Mustache[_0xb34c('0xc9')](_0x2c842c,_0x5d16cf),{'proactiveActions':_0x1fff20,'alignment':_0x1a8cae[_0xb34c('0x10a')],'verticalAlignment':_0x1a8cae[_0xb34c('0x10b')],'div_color':_0x1a8cae[_0xb34c('0xed')],'labelText':_0x1a8cae[_0xb34c('0x10c')],'text_color':_0x1a8cae[_0xb34c('0x10d')],'text_button_color':_0x1a8cae['textButtonColor'],'button_color':_0x1a8cae[_0xb34c('0x10e')],'background_color':_0x1a8cae[_0xb34c('0x10f')],'hideWhenOffline':_0x1a8cae[_0xb34c('0x110')],'intervalId':_0x1a8cae[_0xb34c('0x111')],'isDevelopment':_0x48530f,'chatVersion':_0x5bbe39}));})[_0xb34c('0x46')](handleError(_0x5a6a9a,null));};exports[_0xb34c('0x112')]=function(_0x5dc89b,_0x4c722b){var _0x578077=_0x5dc89b[_0xb34c('0x47')]['id'];var _0x57ab2a=_0x5dc89b['body'];var _0x21fa45=0xc8;var _0x9abc5a=null;return db[_0xb34c('0x113')][_0xb34c('0xd3')]({'isolationLevel':db[_0xb34c('0x113')][_0xb34c('0x114')][_0xb34c('0x115')][_0xb34c('0x116')]},function(_0x52bf86){return db[_0xb34c('0x2e')][_0xb34c('0x59')]({'where':{'id':_0x578077},'transaction':_0x52bf86})[_0xb34c('0x15')](function(_0x27e411){if(_0x27e411){return db[_0xb34c('0x8e')][_0xb34c('0x27')]({'where':{'ChatWebsiteId':_0x578077},'transaction':_0x52bf86})[_0xb34c('0x15')](function(){var _0x4ceca2=_['map'](_0x57ab2a,function(_0x156513){_0x156513[_0xb34c('0x56')]=_0x578077;return _0x156513;});return db[_0xb34c('0x8e')][_0xb34c('0xd5')](_0x4ceca2,{'transaction':_0x52bf86});});}else{_0x21fa45=0x194;_0x9abc5a=[];}});})[_0xb34c('0x15')](function(){if(_0x21fa45!==0x194){return db[_0xb34c('0x8e')][_0xb34c('0x117')]({'where':{'ChatWebsiteId':_0x578077},'order':_0xb34c('0x95')})[_0xb34c('0x15')](function(_0x16eba6){_0x9abc5a=_0x16eba6;});}})[_0xb34c('0x46')](function(_0x92a937){_0x21fa45=0x1f4;logger[_0xb34c('0x19')](_0x92a937[_0xb34c('0x29')]);if(_0x92a937[_0xb34c('0x2a')]){delete _0x92a937[_0xb34c('0x2a')];}_0x9abc5a=_0x92a937;})[_0xb34c('0x118')](function(){if(_0x9abc5a===null){_0x4c722b[_0xb34c('0x1d')](_0x21fa45);}else{if(_0x21fa45===0x1f4){_0x4c722b['status'](_0x21fa45)[_0xb34c('0x2b')](_0x9abc5a);}else{_0x4c722b[_0xb34c('0x1e')](_0x21fa45)[_0xb34c('0x119')](_0x9abc5a);}}});};exports[_0xb34c('0x11a')]=function(_0x246cc6,_0x2fbeda){var _0x53eaa4={};var _0x1e1a05={};var _0x4d66be;var _0x495bb8;return db[_0xb34c('0x2e')][_0xb34c('0x59')]({'where':{'id':_0x246cc6['params']['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x2fbeda,null))[_0xb34c('0x15')](function(_0x16d1cc){if(_0x16d1cc){_0x4d66be=_0x16d1cc;_0x1e1a05[_0xb34c('0x32')]=_[_0xb34c('0x48')](db[_0xb34c('0x8e')][_0xb34c('0x49')]);_0x1e1a05[_0xb34c('0x33')]=_['keys'](_0x246cc6[_0xb34c('0x33')]);_0x1e1a05[_0xb34c('0x34')]=_[_0xb34c('0x35')](_0x1e1a05[_0xb34c('0x32')],_0x1e1a05[_0xb34c('0x33')]);_0x53eaa4[_0xb34c('0x36')]=_[_0xb34c('0x35')](_0x1e1a05['model'],qs['fields'](_0x246cc6[_0xb34c('0x33')]['fields']));_0x53eaa4[_0xb34c('0x36')]=_0x53eaa4[_0xb34c('0x36')][_0xb34c('0x38')]?_0x53eaa4['attributes']:_0x1e1a05['model'];_0x53eaa4[_0xb34c('0x5a')]=qs[_0xb34c('0x3b')](_0x246cc6[_0xb34c('0x33')][_0xb34c('0x3b')]);_0x53eaa4[_0xb34c('0x3c')]=qs['filters'](_[_0xb34c('0x3d')](_0x246cc6[_0xb34c('0x33')],_0x1e1a05[_0xb34c('0x34')]));if(_0x246cc6['query'][_0xb34c('0x3e')]){_0x53eaa4[_0xb34c('0x3c')]=_[_0xb34c('0x3f')](_0x53eaa4[_0xb34c('0x3c')],{'$or':_[_0xb34c('0x40')](_0x53eaa4['attributes'],function(_0x20310c){var _0x23bf29={};_0x23bf29[_0x20310c]={'$like':'%'+_0x246cc6['query'][_0xb34c('0x3e')]+'%'};return _0x23bf29;})});}_0x53eaa4=_[_0xb34c('0x3f')]({},_0x53eaa4,_0x246cc6[_0xb34c('0x41')]);return _0x4d66be[_0xb34c('0x11a')](_0x53eaa4);}})['then'](function(_0xebfddb){if(_0xebfddb){_0x495bb8=_0xebfddb[_0xb34c('0x38')];if(!_0x246cc6[_0xb34c('0x33')]['hasOwnProperty']('nolimit')){_0x53eaa4[_0xb34c('0x22')]=qs['limit'](_0x246cc6[_0xb34c('0x33')][_0xb34c('0x22')]);_0x53eaa4[_0xb34c('0x20')]=qs[_0xb34c('0x20')](_0x246cc6[_0xb34c('0x33')][_0xb34c('0x20')]);}return _0x4d66be[_0xb34c('0x11a')](_0x53eaa4);}})['then'](function(_0x346c30){if(_0x346c30){return _0x346c30?{'count':_0x495bb8,'rows':_0x346c30}:null;}})[_0xb34c('0x15')](respondWithResult(_0x2fbeda,null))[_0xb34c('0x46')](handleError(_0x2fbeda,null));};exports['addProactiveActions']=function(_0x202d63,_0x28b1f1){return db['chatProactiveAction']['find']({'where':{'id':_0x202d63[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x28b1f1,null))[_0xb34c('0x15')](function(_0x488cf7){if(_0x488cf7){return _0x488cf7[_0xb34c('0x11b')](_0x202d63[_0xb34c('0x4c')][_0xb34c('0x5c')],_[_0xb34c('0xe8')](_0x202d63[_0xb34c('0x4c')],[_0xb34c('0x5c'),'id'])||{});}})[_0xb34c('0x15')](respondWithResult(_0x28b1f1,null))[_0xb34c('0x46')](handleError(_0x28b1f1,null));};exports[_0xb34c('0xfb')]=function(_0x11ca54,_0x3d034e){var _0x4ab98e={};var _0x26cbe8={};var _0xdd3751;var _0x4a5a58;return db['ChatWebsite'][_0xb34c('0x59')]({'where':{'id':_0x11ca54[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x3d034e,null))['then'](function(_0xb9debc){if(_0xb9debc){_0xdd3751=_0xb9debc;_0x26cbe8[_0xb34c('0x32')]=_[_0xb34c('0x48')](db[_0xb34c('0x11c')]['rawAttributes']);_0x26cbe8[_0xb34c('0x33')]=_[_0xb34c('0x48')](_0x11ca54[_0xb34c('0x33')]);_0x26cbe8[_0xb34c('0x34')]=_[_0xb34c('0x35')](_0x26cbe8[_0xb34c('0x32')],_0x26cbe8[_0xb34c('0x33')]);_0x4ab98e[_0xb34c('0x36')]=_[_0xb34c('0x35')](_0x26cbe8[_0xb34c('0x32')],qs[_0xb34c('0x37')](_0x11ca54[_0xb34c('0x33')]['fields']));_0x4ab98e['attributes']=_0x4ab98e[_0xb34c('0x36')]['length']?_0x4ab98e[_0xb34c('0x36')]:_0x26cbe8['model'];_0x4ab98e[_0xb34c('0x5a')]=qs[_0xb34c('0x3b')](_0x11ca54['query'][_0xb34c('0x3b')]);_0x4ab98e['where']=qs['filters'](_[_0xb34c('0x3d')](_0x11ca54['query'],_0x26cbe8['filters']));if(_0x11ca54[_0xb34c('0x33')][_0xb34c('0x3e')]){_0x4ab98e['where']=_[_0xb34c('0x3f')](_0x4ab98e['where'],{'$or':_[_0xb34c('0x40')](_0x4ab98e[_0xb34c('0x36')],function(_0x3e7649){var _0x2c677e={};_0x2c677e[_0x3e7649]={'$like':'%'+_0x11ca54[_0xb34c('0x33')][_0xb34c('0x3e')]+'%'};return _0x2c677e;})});}_0x4ab98e=_[_0xb34c('0x3f')]({},_0x4ab98e,_0x11ca54[_0xb34c('0x41')]);return _0xdd3751[_0xb34c('0xfb')](_0x4ab98e);}})[_0xb34c('0x15')](function(_0x39e92f){if(_0x39e92f){_0x4a5a58=_0x39e92f[_0xb34c('0x38')];if(!_0x11ca54[_0xb34c('0x33')][_0xb34c('0x39')]('nolimit')){_0x4ab98e['limit']=qs[_0xb34c('0x22')](_0x11ca54[_0xb34c('0x33')]['limit']);_0x4ab98e[_0xb34c('0x20')]=qs[_0xb34c('0x20')](_0x11ca54['query'][_0xb34c('0x20')]);}return _0xdd3751[_0xb34c('0xfb')](_0x4ab98e);}})['then'](function(_0x3aebd8){if(_0x3aebd8){return _0x3aebd8?{'count':_0x4a5a58,'rows':_0x3aebd8}:null;}})['then'](respondWithResult(_0x3d034e,null))[_0xb34c('0x46')](handleError(_0x3d034e,null));};exports[_0xb34c('0x11d')]=function(_0x3a4a32,_0x1ea941){var _0x3298c3=_0x3a4a32[_0xb34c('0x33')][_0xb34c('0x11e')]===_0xb34c('0x11f')?'offlineForm':_0xb34c('0x120');return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'attributes':['id',_0x3298c3],'where':{'id':_0x3a4a32[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x1ea941,null))[_0xb34c('0x15')](function(_0x1ca769){if(_0x1ca769){var _0x4ed082=_0x1ca769[_0x3298c3];var _0x18a1a4=_0x4ed082&&_0x4ed082[_0xb34c('0x121')]?_0x4ed082[_0xb34c('0x121')]:[];_0x1ea941['send']({'fromKey':_[_0xb34c('0x6a')](_0x4ed082[_0xb34c('0x122')])?undefined:_0x4ed082[_0xb34c('0x122')],'count':_0x18a1a4[_0xb34c('0x38')],'rows':_0x18a1a4});}})[_0xb34c('0x46')](handleError(_0x1ea941,null));};exports[_0xb34c('0x123')]=function(_0xaf80d0,_0x50f2eb){var _0x517f02={'raw':![],'where':{}};var _0x36969d={};var _0x5d8e54={'count':0x0,'rows':[]};return db[_0xb34c('0x2e')][_0xb34c('0x59')]({'where':{'id':_0xaf80d0[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x50f2eb,null))['then'](function(_0x41322d){if(_0x41322d){_0x36969d['model']=_[_0xb34c('0x48')](db[_0xb34c('0xcb')][_0xb34c('0x49')]);_0x36969d[_0xb34c('0x33')]=_[_0xb34c('0x48')](_0xaf80d0[_0xb34c('0x33')]);_0x36969d['filters']=_[_0xb34c('0x35')](_0x36969d[_0xb34c('0x32')],_0x36969d[_0xb34c('0x33')]);_0x517f02['attributes']=_[_0xb34c('0x35')](_0x36969d[_0xb34c('0x32')],qs['fields'](_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x37')]));_0x517f02[_0xb34c('0x36')]=_0x517f02[_0xb34c('0x36')][_0xb34c('0x38')]?_0x517f02[_0xb34c('0x36')]:_0x36969d[_0xb34c('0x32')];if(!_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x39')]('nolimit')){_0x517f02[_0xb34c('0x22')]=qs[_0xb34c('0x22')](_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x22')]);_0x517f02[_0xb34c('0x20')]=qs['offset'](_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x20')]);}_0x517f02['order']=qs['sort'](_0xaf80d0['query'][_0xb34c('0x3b')]);_0x517f02[_0xb34c('0x3c')]=qs['filters'](_[_0xb34c('0x3d')](_0xaf80d0[_0xb34c('0x33')],_0x36969d['filters']));_0x517f02[_0xb34c('0x3c')]['ChatWebsiteId']=_0x41322d['id'];if(_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x3e')]){_0x517f02[_0xb34c('0x3c')]=_[_0xb34c('0x3f')](_0x517f02[_0xb34c('0x3c')],{'$or':_['map'](_0x517f02['attributes'],function(_0x2da3a8){var _0x51b371={};_0x51b371[_0x2da3a8]={'$like':'%'+_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x3e')]+'%'};return _0x51b371;})});}_0x517f02=_[_0xb34c('0x3f')]({},_0x517f02,_0xaf80d0[_0xb34c('0x41')]);return db['ChatOfflineMessage'][_0xb34c('0x23')]({'where':_0x517f02[_0xb34c('0x3c')]})[_0xb34c('0x15')](function(_0xf6a351){_0x5d8e54[_0xb34c('0x23')]=_0xf6a351;if(_0xaf80d0[_0xb34c('0x33')][_0xb34c('0x42')]){_0x517f02[_0xb34c('0x43')]=[{'all':!![]}];}else{_0x517f02[_0xb34c('0x43')]=[{'model':db['CmContact'],'as':_0xb34c('0xea'),'required':![]},{'model':db['Attachment'],'as':_0xb34c('0x124'),'required':![]}];}return db[_0xb34c('0xcb')][_0xb34c('0x44')](_0x517f02);})[_0xb34c('0x15')](function(_0x472cd2){_0x5d8e54['rows']=_0x472cd2;return _0x5d8e54;});}})[_0xb34c('0x15')](respondWithFilteredResult(_0x50f2eb,_0x517f02))[_0xb34c('0x46')](handleError(_0x50f2eb,null));};exports[_0xb34c('0x125')]=function(_0x5b80b1,_0x4e1005){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x5b80b1[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x4e1005,null))[_0xb34c('0x15')](function(_0xf15ff){if(_0xf15ff){return _0xf15ff[_0xb34c('0x125')](_0x5b80b1[_0xb34c('0x4c')][_0xb34c('0x5c')],_[_0xb34c('0xe8')](_0x5b80b1[_0xb34c('0x4c')],[_0xb34c('0x5c'),'id'])||{})[_0xb34c('0xc5')](function(_0x97237c){for(var _0x1e8b65=0x0;_0x1e8b65<_0x5b80b1[_0xb34c('0x4c')]['ids'][_0xb34c('0x38')];_0x1e8b65+=0x1){socket[_0xb34c('0x126')](_0xb34c('0x127'),{'UserId':Number(_0x5b80b1[_0xb34c('0x4c')][_0xb34c('0x5c')][_0x1e8b65]),'ChatWebsiteId':Number(_0x5b80b1[_0xb34c('0x47')]['id'])});}return _0x97237c;});}})['then'](respondWithResult(_0x4e1005,null))['catch'](handleError(_0x4e1005,null));};exports['removeAgents']=function(_0x5e865c,_0x10ae2b){return db[_0xb34c('0x2e')][_0xb34c('0x4a')]({'where':{'id':_0x5e865c[_0xb34c('0x47')]['id']}})['then'](handleEntityNotFound(_0x10ae2b,null))[_0xb34c('0x15')](function(_0x420970){if(_0x420970){return _0x420970[_0xb34c('0x128')](_0x5e865c[_0xb34c('0x33')][_0xb34c('0x5c')])[_0xb34c('0x15')](function(){if(_['isArray'](_0x5e865c[_0xb34c('0x33')]['ids'])){for(var _0x4c90ed=0x0;_0x4c90ed<_0x5e865c['query'][_0xb34c('0x5c')][_0xb34c('0x38')];_0x4c90ed+=0x1){socket['emit'](_0xb34c('0x129'),{'UserId':Number(_0x5e865c['query'][_0xb34c('0x5c')][_0x4c90ed]),'ChatWebsiteId':Number(_0x5e865c[_0xb34c('0x47')]['id'])});}}else{socket[_0xb34c('0x126')](_0xb34c('0x129'),{'UserId':Number(_0x5e865c[_0xb34c('0x33')][_0xb34c('0x5c')]),'ChatWebsiteId':Number(_0x5e865c[_0xb34c('0x47')]['id'])});}});}})['then'](respondWithStatusCode(_0x10ae2b,null))[_0xb34c('0x46')](handleError(_0x10ae2b,null));};exports[_0xb34c('0x12a')]=function(_0x49f6dd,_0x4b12a4){var _0x2da10e={};var _0x204759={};var _0x2e0206;var _0x577d15;return db['ChatWebsite'][_0xb34c('0x59')]({'where':{'id':_0x49f6dd[_0xb34c('0x47')]['id']}})[_0xb34c('0x15')](handleEntityNotFound(_0x4b12a4,null))[_0xb34c('0x15')](function(_0x17dc43){if(_0x17dc43){_0x2e0206=_0x17dc43;_0x204759[_0xb34c('0x32')]=_[_0xb34c('0x48')](db[_0xb34c('0xb6')]['rawAttributes']);_0x204759[_0xb34c('0x33')]=_[_0xb34c('0x48')](_0x49f6dd['query']);_0x204759['filters']=_[_0xb34c('0x35')](_0x204759[_0xb34c('0x32')],_0x204759[_0xb34c('0x33')]);_0x2da10e[_0xb34c('0x36')]=_['intersection'](_0x204759[_0xb34c('0x32')],qs[_0xb34c('0x37')](_0x49f6dd['query'][_0xb34c('0x37')]));_0x2da10e[_0xb34c('0x36')]=_0x2da10e[_0xb34c('0x36')][_0xb34c('0x38')]?_0x2da10e['attributes']:_0x204759['model'];_0x2da10e[_0xb34c('0x5a')]=qs[_0xb34c('0x3b')](_0x49f6dd[_0xb34c('0x33')][_0xb34c('0x3b')]);_0x2da10e[_0xb34c('0x3c')]=qs[_0xb34c('0x34')](_[_0xb34c('0x3d')](_0x49f6dd[_0xb34c('0x33')],_0x204759[_0xb34c('0x34')]));if(_0x49f6dd['query']['filter']){_0x2da10e['where']=_[_0xb34c('0x3f')](_0x2da10e[_0xb34c('0x3c')],{'$or':_['map'](_0x2da10e[_0xb34c('0x36')],function(_0x5cd1f7){var _0x2a1b48={};_0x2a1b48[_0x5cd1f7]={'$like':'%'+_0x49f6dd[_0xb34c('0x33')][_0xb34c('0x3e')]+'%'};return _0x2a1b48;})});}_0x2da10e=_[_0xb34c('0x3f')]({},_0x2da10e,_0x49f6dd[_0xb34c('0x41')]);return _0x2e0206[_0xb34c('0x12a')](_0x2da10e);}})[_0xb34c('0x15')](function(_0x2439a6){if(_0x2439a6){_0x577d15=_0x2439a6['length'];if(!_0x49f6dd[_0xb34c('0x33')]['hasOwnProperty']('nolimit')){_0x2da10e[_0xb34c('0x22')]=qs['limit'](_0x49f6dd[_0xb34c('0x33')]['limit']);_0x2da10e[_0xb34c('0x20')]=qs[_0xb34c('0x20')](_0x49f6dd[_0xb34c('0x33')]['offset']);}return _0x2e0206[_0xb34c('0x12a')](_0x2da10e);}})[_0xb34c('0x15')](function(_0x3d326d){if(_0x3d326d){return _0x3d326d?{'count':_0x577d15,'rows':_0x3d326d}:null;}})[_0xb34c('0x15')](respondWithResult(_0x4b12a4,null))[_0xb34c('0x46')](handleError(_0x4b12a4,null));};
\ No newline at end of file