Built motion from commit e6806ed6.|2.6.0
[motion2.git] / server / api / chatWebsite / chatWebsite.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _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));};