2751c498e351d50fb6132141d9e59c9633e3fc18
[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 _0xf6c7=['findOne','nolimit','pick','ChatWebsiteId','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','hasOwnProperty','removeAnswers','addLogo','sitepic','file','filename','agentAvatar','addCustomerAvatar','addSystemAvatar','systemAvatar','root','server/files/images/logos/default_logo.svg','../../config/license/util','custom','isNil','existsSync','join','server/files/images/logos/','download','getAvatar','server/files/images/avatars/default_avatar.png','server/files/images/avatars/','getCustomerAvatar','server/files/images/avatars/customer_avatar.png','customerAvatar','showCustomerAvatar','getSystemAvatar','server/files/images/avatars/system_avatar.png','notify','user-agent-parser','setUA','headers','user-agent','chat','CmContact','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','from','ValidationError','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','Contacts','DESC','ChatApplication','Applications','account','applications','list','orderBy','priority','asc','defaults','contact','customerIp','cf-connecting-ip','x-forwarded-for','first','split','lastName','x-real-port','referer','browser','version','format','%s\x20%s','unknown','device','vendor','%s\x20%s\x20%s','threadId','ChatInteraction','externalUrl','ContactId','interaction','spread','firstName','messageId','created','autoclose','push','close','unmanaged','*,*,*,*','ChatMessage','AttachmentId','UserId','agent','forcedOwnership','Start','startRouting','EventManager','offline','files','mapKeyOffline','mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','MailAccount','findOrCreate','readFileSync','utf8','offlineMessageBody','ChatOfflineMessage','originalname','mimetype','server','offline-chat','basename','openNewInteraction','sequelize','transaction','Attachment','bulkCreate','MailServerOut','Smtp','CloudProvider','forwardOffline','forwardOfflineAddress','SendMail','\x22%s\x22\x20<%s>','email','MailAccountId','subjectOffline','toPairsIn','offlineMessageSubject','Chat','NotifyMailAccount','notifyMail','attachments','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Owner','fullname','internal','Tag','Tags','color','tag','getSnippet','interval','timezone','iftime\x20%s','indexOf','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','OFFLINE','No\x20timezone','inspect','Interval','Intervals','getProactiveActions','getLicense','virtual','License','all','some','server/files/chat/iframe.ejs','remote','stringify','x-real-ip','connection','replace','render','alignment','verticalAlignment','labelText','textColor','textButtonColor','color_button','backgroundColor','hideWhenOffline','IntervalId','addApplications','Transaction','ISOLATION_LEVELS','READ_COMMITTED','findAndCountAll','finally','getApplications','addProactiveActions','chatProactiveAction','getFields','false','offlineForm','onlineForm','items','fromKey','getOfflineMessages','Contact','Attachments','addAgents','emit','userChatWebsite:save','removeAgents','isArray','userChatWebsite:remove','User','getAgents','bluebird','mustache','util','path','ejs','fs-extra','querystring','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./chatWebsite.socket','html-to-text','http','client','request','then','info','ChatWebsite,\x20%s,\x20%s','request\x20sent','debug','error','code','message','catch','sendStatus','end','json','undefined','limit','count','offset','status','get','ChatWebsites','UserProfileResource','destroy','stack','name','send','index','Pause','mandatoryDispositionPause','ChatWebsite','rawAttributes','fieldName','type','model','map','query','keys','intersection','attributes','fields','length','order','sort','where','filters','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','show','params','find','create','body','user','role','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','Disposition','getDispositions'];(function(_0x38aa39,_0x563f65){var _0x1ff3a5=function(_0x49213c){while(--_0x49213c){_0x38aa39['push'](_0x38aa39['shift']());}};_0x1ff3a5(++_0x563f65);}(_0xf6c7,0xdc));var _0x7f6c=function(_0x50f1ab,_0x42b0a8){_0x50f1ab=_0x50f1ab-0x0;var _0x4077b5=_0xf6c7[_0x50f1ab];return _0x4077b5;};'use strict';var BPromise=require(_0x7f6c('0x0'));var Mustache=require(_0x7f6c('0x1'));var util=require(_0x7f6c('0x2'));var path=require(_0x7f6c('0x3'));var ejs=require(_0x7f6c('0x4'));var fs=require('fs');var fs_extra=require(_0x7f6c('0x5'));var _=require('lodash');var querystring=require(_0x7f6c('0x6'));var Redis=require(_0x7f6c('0x7'));var qs=require(_0x7f6c('0x8'));var logger=require(_0x7f6c('0x9'))(_0x7f6c('0xa'));var config=require(_0x7f6c('0xb'));var db=require(_0x7f6c('0xc'))['db'];config[_0x7f6c('0xd')]=_['defaults'](config[_0x7f6c('0xd')],{'host':_0x7f6c('0xe'),'port':0x18eb});var socket=require(_0x7f6c('0xf'))(new Redis(config[_0x7f6c('0xd')]));require(_0x7f6c('0x10'))['register'](socket);var htmlToText=require(_0x7f6c('0x11'));var jayson=require('jayson/promise');var client=jayson['client'][_0x7f6c('0x12')]({'port':0x232c});var client9002=jayson[_0x7f6c('0x13')][_0x7f6c('0x12')]({'port':0x232a});var client9003=jayson[_0x7f6c('0x13')][_0x7f6c('0x12')]({'port':0x232b});var client9001=jayson[_0x7f6c('0x13')]['http']({'port':0x2329});function respondWithRpcPromise(_0x4dc1c6,_0x547dd6,_0x4363f4,_0x1d4002){return new BPromise(function(_0x145636,_0x126393){var _0x3026d7=_0x1d4002||client;return _0x3026d7[_0x7f6c('0x14')](_0x4dc1c6,_0x4363f4)[_0x7f6c('0x15')](function(_0x277f12){logger[_0x7f6c('0x16')](_0x7f6c('0x17'),_0x547dd6,_0x7f6c('0x18'));logger[_0x7f6c('0x19')]('ChatWebsite,\x20%s,\x20%s,\x20%s',_0x547dd6,'request\x20sent',JSON['stringify'](_0x277f12));if(_0x277f12[_0x7f6c('0x1a')]){if(_0x277f12[_0x7f6c('0x1a')][_0x7f6c('0x1b')]===0x1f4){logger['error'](_0x7f6c('0x17'),_0x547dd6,_0x277f12['error'][_0x7f6c('0x1c')]);return _0x126393(_0x277f12[_0x7f6c('0x1a')][_0x7f6c('0x1c')]);}logger[_0x7f6c('0x1a')]('ChatWebsite,\x20%s,\x20%s',_0x547dd6,_0x277f12['error']['message']);return _0x145636(_0x277f12[_0x7f6c('0x1a')][_0x7f6c('0x1c')]);}else{logger[_0x7f6c('0x16')](_0x7f6c('0x17'),_0x547dd6,_0x7f6c('0x18'));_0x145636(_0x277f12['result']['message']);}})[_0x7f6c('0x1d')](function(_0x8d329d){logger[_0x7f6c('0x1a')](_0x7f6c('0x17'),_0x547dd6,_0x8d329d);_0x126393(_0x8d329d);});});}function respondWithStatusCode(_0x4848e8,_0x21d655){_0x21d655=_0x21d655||0xcc;return function(_0x3642ef){if(_0x3642ef){return _0x4848e8[_0x7f6c('0x1e')](_0x21d655);}return _0x4848e8['status'](_0x21d655)[_0x7f6c('0x1f')]();};}function respondWithResult(_0x2d28c5,_0x18db92){_0x18db92=_0x18db92||0xc8;return function(_0x4d4626){if(_0x4d4626){return _0x2d28c5['status'](_0x18db92)[_0x7f6c('0x20')](_0x4d4626);}};}function respondWithFilteredResult(_0x144517,_0x597cf8){return function(_0x4a45aa){if(_0x4a45aa){var _0x4c1c86=typeof _0x597cf8['offset']===_0x7f6c('0x21')&&typeof _0x597cf8[_0x7f6c('0x22')]===_0x7f6c('0x21');var _0x1b60c5=_0x4a45aa[_0x7f6c('0x23')];var _0x13a4aa=_0x4c1c86?0x0:_0x597cf8['offset'];var _0x151e16=_0x4c1c86?_0x4a45aa[_0x7f6c('0x23')]:_0x597cf8[_0x7f6c('0x24')]+_0x597cf8[_0x7f6c('0x22')];var _0x1f4acb;if(_0x151e16>=_0x1b60c5){_0x151e16=_0x1b60c5;_0x1f4acb=0xc8;}else{_0x1f4acb=0xce;}_0x144517[_0x7f6c('0x25')](_0x1f4acb);return _0x144517['set']('Content-Range',_0x13a4aa+'-'+_0x151e16+'/'+_0x1b60c5)[_0x7f6c('0x20')](_0x4a45aa);}return null;};}function saveUpdates(_0x449dfb){return function(_0x237726){if(_0x237726){return _0x237726['update'](_0x449dfb)['then'](function(_0x3f5a31){return _0x3f5a31;});}return null;};}function removeEntity(_0x38a50b){return function(_0xbd9dd){if(_0xbd9dd){return _0xbd9dd['destroy']()['then'](function(){var _0x30dccc=_0xbd9dd[_0x7f6c('0x26')]({'plain':!![]});var _0x2c4038=_0x7f6c('0x27');return db[_0x7f6c('0x28')][_0x7f6c('0x29')]({'where':{'type':_0x2c4038,'resourceId':_0x30dccc['id']}})[_0x7f6c('0x15')](function(){return _0xbd9dd;});})[_0x7f6c('0x15')](function(){_0x38a50b[_0x7f6c('0x25')](0xcc)[_0x7f6c('0x1f')]();});}};}function handleEntityNotFound(_0x3fae03){return function(_0xdac7a7){if(!_0xdac7a7){_0x3fae03['sendStatus'](0x194);}return _0xdac7a7;};}function handleError(_0x2d0d2e,_0x3d6ea1){_0x3d6ea1=_0x3d6ea1||0x1f4;return function(_0xc57c1e){logger[_0x7f6c('0x1a')](_0xc57c1e[_0x7f6c('0x2a')]);if(_0xc57c1e[_0x7f6c('0x2b')]){delete _0xc57c1e[_0x7f6c('0x2b')];}_0x2d0d2e[_0x7f6c('0x25')](_0x3d6ea1)[_0x7f6c('0x2c')](_0xc57c1e);};}exports[_0x7f6c('0x2d')]=function(_0x464e6f,_0x3c6401){var _0x14ba8c={'include':[{'model':db[_0x7f6c('0x2e')],'as':_0x7f6c('0x2f')}]},_0xac1f32={},_0xc36920={'count':0x0,'rows':[]};var _0x36acb6=_['map'](db[_0x7f6c('0x30')][_0x7f6c('0x31')],function(_0x4762bf){return{'name':_0x4762bf[_0x7f6c('0x32')],'type':_0x4762bf[_0x7f6c('0x33')]['key']};});_0xac1f32[_0x7f6c('0x34')]=_[_0x7f6c('0x35')](_0x36acb6,'name');_0xac1f32[_0x7f6c('0x36')]=_[_0x7f6c('0x37')](_0x464e6f[_0x7f6c('0x36')]);_0xac1f32['filters']=_[_0x7f6c('0x38')](_0xac1f32[_0x7f6c('0x34')],_0xac1f32[_0x7f6c('0x36')]);_0x14ba8c[_0x7f6c('0x39')]=_[_0x7f6c('0x38')](_0xac1f32['model'],qs[_0x7f6c('0x3a')](_0x464e6f[_0x7f6c('0x36')][_0x7f6c('0x3a')]));_0x14ba8c[_0x7f6c('0x39')]=_0x14ba8c[_0x7f6c('0x39')][_0x7f6c('0x3b')]?_0x14ba8c[_0x7f6c('0x39')]:_0xac1f32['model'];if(!_0x464e6f[_0x7f6c('0x36')]['hasOwnProperty']('nolimit')){_0x14ba8c[_0x7f6c('0x22')]=qs[_0x7f6c('0x22')](_0x464e6f[_0x7f6c('0x36')][_0x7f6c('0x22')]);_0x14ba8c[_0x7f6c('0x24')]=qs[_0x7f6c('0x24')](_0x464e6f[_0x7f6c('0x36')][_0x7f6c('0x24')]);}_0x14ba8c[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0x464e6f[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0x14ba8c[_0x7f6c('0x3e')]=qs[_0x7f6c('0x3f')](_['pick'](_0x464e6f['query'],_0xac1f32[_0x7f6c('0x3f')]),_0x36acb6);if(_0x464e6f['query'][_0x7f6c('0x40')]){_0x14ba8c[_0x7f6c('0x3e')]=_['merge'](_0x14ba8c[_0x7f6c('0x3e')],{'$or':_[_0x7f6c('0x35')](_0x36acb6,function(_0x5ef68b){if(_0x5ef68b[_0x7f6c('0x33')]!==_0x7f6c('0x41')){var _0x52b267={};_0x52b267[_0x5ef68b[_0x7f6c('0x2b')]]={'$like':'%'+_0x464e6f[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x52b267;}})});}_0x14ba8c=_[_0x7f6c('0x42')]({},_0x14ba8c,_0x464e6f[_0x7f6c('0x43')]);var _0x17f40e={'where':_0x14ba8c[_0x7f6c('0x3e')]};return db['ChatWebsite']['count'](_0x17f40e)[_0x7f6c('0x15')](function(_0x3f0b10){_0xc36920[_0x7f6c('0x23')]=_0x3f0b10;if(_0x464e6f[_0x7f6c('0x36')][_0x7f6c('0x44')]){_0x14ba8c[_0x7f6c('0x45')]=[{'all':!![]}];}return db[_0x7f6c('0x30')][_0x7f6c('0x46')](_0x14ba8c);})[_0x7f6c('0x15')](function(_0x22439d){_0xc36920[_0x7f6c('0x47')]=_0x22439d;return _0xc36920;})[_0x7f6c('0x15')](respondWithFilteredResult(_0x3c6401,_0x14ba8c))[_0x7f6c('0x1d')](handleError(_0x3c6401,null));};exports[_0x7f6c('0x48')]=function(_0x55900f,_0x298116){var _0xc74b8c={'raw':![],'where':{'id':_0x55900f[_0x7f6c('0x49')]['id']},'include':[{'model':db[_0x7f6c('0x2e')],'as':_0x7f6c('0x2f')}]},_0x34dbae={};_0x34dbae['model']=_[_0x7f6c('0x37')](db['ChatWebsite'][_0x7f6c('0x31')]);_0x34dbae['query']=_[_0x7f6c('0x37')](_0x55900f[_0x7f6c('0x36')]);_0x34dbae[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x34dbae[_0x7f6c('0x34')],_0x34dbae[_0x7f6c('0x36')]);_0xc74b8c['attributes']=_['intersection'](_0x34dbae['model'],qs[_0x7f6c('0x3a')](_0x55900f['query']['fields']));_0xc74b8c['attributes']=_0xc74b8c[_0x7f6c('0x39')][_0x7f6c('0x3b')]?_0xc74b8c['attributes']:_0x34dbae[_0x7f6c('0x34')];if(_0x55900f[_0x7f6c('0x36')][_0x7f6c('0x44')]){_0xc74b8c[_0x7f6c('0x45')]=[{'all':!![]}];}_0xc74b8c=_['merge']({},_0xc74b8c,_0x55900f['options']);return db[_0x7f6c('0x30')][_0x7f6c('0x4a')](_0xc74b8c)[_0x7f6c('0x15')](handleEntityNotFound(_0x298116,null))[_0x7f6c('0x15')](respondWithResult(_0x298116,null))[_0x7f6c('0x1d')](handleError(_0x298116,null));};exports[_0x7f6c('0x4b')]=function(_0x97d2b7,_0x5dd06a){return db[_0x7f6c('0x30')]['create'](_0x97d2b7[_0x7f6c('0x4c')],{})['then'](function(_0x247348){var _0x11076d=_0x97d2b7[_0x7f6c('0x4d')][_0x7f6c('0x26')]({'plain':!![]});if(!_0x11076d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x11076d[_0x7f6c('0x4e')]===_0x7f6c('0x4d')){var _0x2abe2f=_0x247348['get']({'plain':!![]});var _0x13d043='ChatWebsites';return db['UserProfileSection'][_0x7f6c('0x4a')]({'where':{'name':_0x13d043,'userProfileId':_0x11076d[_0x7f6c('0x4f')]},'raw':!![]})[_0x7f6c('0x15')](function(_0x3bb1e2){if(_0x3bb1e2&&_0x3bb1e2['autoAssociation']===0x0){return db[_0x7f6c('0x28')][_0x7f6c('0x4b')]({'name':_0x2abe2f['name'],'resourceId':_0x2abe2f['id'],'type':_0x3bb1e2[_0x7f6c('0x2b')],'sectionId':_0x3bb1e2['id']},{})['then'](function(){return _0x247348;});}else{return _0x247348;}})[_0x7f6c('0x1d')](function(_0x434977){logger['error'](_0x7f6c('0x50'),_0x434977);throw _0x434977;});}return _0x247348;})[_0x7f6c('0x15')](respondWithResult(_0x5dd06a,0xc9))['catch'](handleError(_0x5dd06a,null));};exports['update']=function(_0x3e2bf9,_0x391540){if(_0x3e2bf9['body']['id']){delete _0x3e2bf9['body']['id'];}return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x3e2bf9[_0x7f6c('0x49')]['id']},'include':[{'model':db[_0x7f6c('0x2e')],'as':_0x7f6c('0x2f')}]})[_0x7f6c('0x15')](handleEntityNotFound(_0x391540,null))[_0x7f6c('0x15')](saveUpdates(_0x3e2bf9[_0x7f6c('0x4c')],null))[_0x7f6c('0x15')](respondWithResult(_0x391540,null))[_0x7f6c('0x1d')](handleError(_0x391540,null));};exports[_0x7f6c('0x29')]=function(_0x2ba8fb,_0x49bfc8){return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x2ba8fb['params']['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x49bfc8,null))[_0x7f6c('0x15')](removeEntity(_0x49bfc8,null))[_0x7f6c('0x1d')](handleError(_0x49bfc8,null));};exports[_0x7f6c('0x51')]=function(_0x2151ec,_0x23b418){return db[_0x7f6c('0x30')]['describe']()[_0x7f6c('0x15')](respondWithResult(_0x23b418,null))['catch'](handleError(_0x23b418,null));};exports[_0x7f6c('0x52')]=function(_0x3f939f,_0x19d00f){if(_0x3f939f[_0x7f6c('0x4c')]['id']){delete _0x3f939f[_0x7f6c('0x4c')]['id'];}return db['ChatWebsite'][_0x7f6c('0x4a')]({'where':{'id':_0x3f939f[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x19d00f,null))['then'](function(_0x4a2294){if(_0x4a2294){_0x3f939f[_0x7f6c('0x4c')]['ChatWebsiteId']=_0x4a2294['id'];return db[_0x7f6c('0x53')][_0x7f6c('0x4b')](_0x3f939f[_0x7f6c('0x4c')]);}})[_0x7f6c('0x15')](respondWithResult(_0x19d00f,null))[_0x7f6c('0x1d')](handleError(_0x19d00f,null));};exports[_0x7f6c('0x54')]=function(_0x2dd7b6,_0x1d6823){var _0x5224ae={'raw':![],'where':{}};var _0x11548e={};var _0x357e1c={'count':0x0,'rows':[]};return db[_0x7f6c('0x30')][_0x7f6c('0x55')]({'where':{'id':_0x2dd7b6[_0x7f6c('0x49')]['id']}})['then'](handleEntityNotFound(_0x1d6823,null))['then'](function(_0x1f717c){if(_0x1f717c){_0x11548e['model']=_[_0x7f6c('0x37')](db['Disposition'][_0x7f6c('0x31')]);_0x11548e[_0x7f6c('0x36')]=_[_0x7f6c('0x37')](_0x2dd7b6['query']);_0x11548e[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x11548e[_0x7f6c('0x34')],_0x11548e[_0x7f6c('0x36')]);_0x5224ae[_0x7f6c('0x39')]=_['intersection'](_0x11548e['model'],qs[_0x7f6c('0x3a')](_0x2dd7b6[_0x7f6c('0x36')][_0x7f6c('0x3a')]));_0x5224ae['attributes']=_0x5224ae[_0x7f6c('0x39')][_0x7f6c('0x3b')]?_0x5224ae[_0x7f6c('0x39')]:_0x11548e[_0x7f6c('0x34')];if(!_0x2dd7b6[_0x7f6c('0x36')]['hasOwnProperty'](_0x7f6c('0x56'))){_0x5224ae[_0x7f6c('0x22')]=qs['limit'](_0x2dd7b6[_0x7f6c('0x36')][_0x7f6c('0x22')]);_0x5224ae[_0x7f6c('0x24')]=qs['offset'](_0x2dd7b6[_0x7f6c('0x36')][_0x7f6c('0x24')]);}_0x5224ae[_0x7f6c('0x3c')]=qs['sort'](_0x2dd7b6['query'][_0x7f6c('0x3d')]);_0x5224ae[_0x7f6c('0x3e')]=qs[_0x7f6c('0x3f')](_[_0x7f6c('0x57')](_0x2dd7b6[_0x7f6c('0x36')],_0x11548e[_0x7f6c('0x3f')]));_0x5224ae[_0x7f6c('0x3e')][_0x7f6c('0x58')]=_0x1f717c['id'];if(_0x2dd7b6[_0x7f6c('0x36')][_0x7f6c('0x40')]){_0x5224ae[_0x7f6c('0x3e')]=_[_0x7f6c('0x42')](_0x5224ae[_0x7f6c('0x3e')],{'$or':_[_0x7f6c('0x35')](_0x5224ae['attributes'],function(_0x574f85){var _0x335870={};_0x335870[_0x574f85]={'$like':'%'+_0x2dd7b6[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x335870;})});}_0x5224ae=_['merge']({},_0x5224ae,_0x2dd7b6[_0x7f6c('0x43')]);return db[_0x7f6c('0x53')][_0x7f6c('0x23')]({'where':_0x5224ae[_0x7f6c('0x3e')]})[_0x7f6c('0x15')](function(_0x5c6f2d){_0x357e1c[_0x7f6c('0x23')]=_0x5c6f2d;if(_0x2dd7b6['query'][_0x7f6c('0x44')]){_0x5224ae[_0x7f6c('0x45')]=[{'all':!![]}];}return db[_0x7f6c('0x53')][_0x7f6c('0x46')](_0x5224ae);})[_0x7f6c('0x15')](function(_0x12f3b2){_0x357e1c[_0x7f6c('0x47')]=_0x12f3b2;return _0x357e1c;});}})[_0x7f6c('0x15')](respondWithFilteredResult(_0x1d6823,_0x5224ae))['catch'](handleError(_0x1d6823,null));};exports[_0x7f6c('0x59')]=function(_0x3dff91,_0x1665ef){return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x3dff91[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x1665ef,null))[_0x7f6c('0x15')](function(_0x3c31e1){if(_0x3c31e1){return _0x3c31e1[_0x7f6c('0x59')](_0x3dff91[_0x7f6c('0x36')][_0x7f6c('0x5a')]);}})[_0x7f6c('0x15')](respondWithStatusCode(_0x1665ef,null))[_0x7f6c('0x1d')](handleError(_0x1665ef,null));};exports[_0x7f6c('0x5b')]=function(_0x58baa9,_0xf8ceb4){if(_0x58baa9[_0x7f6c('0x4c')]['id']){delete _0x58baa9['body']['id'];}return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x58baa9[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0xf8ceb4,null))[_0x7f6c('0x15')](function(_0x375043){if(_0x375043){_0x58baa9[_0x7f6c('0x4c')][_0x7f6c('0x58')]=_0x375043['id'];return db[_0x7f6c('0x5c')][_0x7f6c('0x4b')](_0x58baa9[_0x7f6c('0x4c')]);}})['then'](respondWithResult(_0xf8ceb4,null))['catch'](handleError(_0xf8ceb4,null));};exports[_0x7f6c('0x5d')]=function(_0x3327d9,_0x193cb7){var _0x3f0bd1={'raw':![],'where':{}};var _0x3bf9ae={};var _0xec9240={'count':0x0,'rows':[]};return db[_0x7f6c('0x30')][_0x7f6c('0x55')]({'where':{'id':_0x3327d9[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x193cb7,null))[_0x7f6c('0x15')](function(_0x162f7a){if(_0x162f7a){_0x3bf9ae[_0x7f6c('0x34')]=_['keys'](db['CannedAnswer'][_0x7f6c('0x31')]);_0x3bf9ae[_0x7f6c('0x36')]=_['keys'](_0x3327d9['query']);_0x3bf9ae[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x3bf9ae[_0x7f6c('0x34')],_0x3bf9ae[_0x7f6c('0x36')]);_0x3f0bd1['attributes']=_[_0x7f6c('0x38')](_0x3bf9ae[_0x7f6c('0x34')],qs[_0x7f6c('0x3a')](_0x3327d9['query'][_0x7f6c('0x3a')]));_0x3f0bd1[_0x7f6c('0x39')]=_0x3f0bd1['attributes'][_0x7f6c('0x3b')]?_0x3f0bd1[_0x7f6c('0x39')]:_0x3bf9ae[_0x7f6c('0x34')];if(!_0x3327d9['query'][_0x7f6c('0x5e')](_0x7f6c('0x56'))){_0x3f0bd1[_0x7f6c('0x22')]=qs[_0x7f6c('0x22')](_0x3327d9[_0x7f6c('0x36')]['limit']);_0x3f0bd1[_0x7f6c('0x24')]=qs[_0x7f6c('0x24')](_0x3327d9[_0x7f6c('0x36')][_0x7f6c('0x24')]);}_0x3f0bd1[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0x3327d9[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0x3f0bd1[_0x7f6c('0x3e')]=qs[_0x7f6c('0x3f')](_[_0x7f6c('0x57')](_0x3327d9[_0x7f6c('0x36')],_0x3bf9ae[_0x7f6c('0x3f')]));_0x3f0bd1[_0x7f6c('0x3e')][_0x7f6c('0x58')]=_0x162f7a['id'];if(_0x3327d9[_0x7f6c('0x36')][_0x7f6c('0x40')]){_0x3f0bd1[_0x7f6c('0x3e')]=_[_0x7f6c('0x42')](_0x3f0bd1['where'],{'$or':_[_0x7f6c('0x35')](_0x3f0bd1[_0x7f6c('0x39')],function(_0x4cd624){var _0x3780f2={};_0x3780f2[_0x4cd624]={'$like':'%'+_0x3327d9[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x3780f2;})});}_0x3f0bd1=_[_0x7f6c('0x42')]({},_0x3f0bd1,_0x3327d9['options']);return db[_0x7f6c('0x5c')][_0x7f6c('0x23')]({'where':_0x3f0bd1[_0x7f6c('0x3e')]})[_0x7f6c('0x15')](function(_0x32b2b7){_0xec9240[_0x7f6c('0x23')]=_0x32b2b7;if(_0x3327d9['query'][_0x7f6c('0x44')]){_0x3f0bd1[_0x7f6c('0x45')]=[{'all':!![]}];}return db[_0x7f6c('0x5c')][_0x7f6c('0x46')](_0x3f0bd1);})['then'](function(_0x3c1a9b){_0xec9240[_0x7f6c('0x47')]=_0x3c1a9b;return _0xec9240;});}})['then'](respondWithFilteredResult(_0x193cb7,_0x3f0bd1))[_0x7f6c('0x1d')](handleError(_0x193cb7,null));};exports[_0x7f6c('0x5f')]=function(_0x5e7408,_0x1cf777){return db[_0x7f6c('0x30')]['find']({'where':{'id':_0x5e7408[_0x7f6c('0x49')]['id']}})['then'](handleEntityNotFound(_0x1cf777,null))[_0x7f6c('0x15')](function(_0x139947){if(_0x139947){return _0x139947['removeAnswers'](_0x5e7408['query'][_0x7f6c('0x5a')]);}})[_0x7f6c('0x15')](respondWithStatusCode(_0x1cf777,null))['catch'](handleError(_0x1cf777,null));};exports[_0x7f6c('0x60')]=function(_0x22d936,_0x15daed){_0x22d936['body'][_0x7f6c('0x61')]=_0x22d936[_0x7f6c('0x62')][_0x7f6c('0x63')];return db[_0x7f6c('0x30')]['find']({'where':{'id':_0x22d936[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x15daed,null))[_0x7f6c('0x15')](saveUpdates(_0x22d936[_0x7f6c('0x4c')],null))[_0x7f6c('0x15')](respondWithResult(_0x15daed,null))[_0x7f6c('0x1d')](handleError(_0x15daed,null));};exports['addAvatar']=function(_0x3f2daa,_0x47cf2f){_0x3f2daa['body'][_0x7f6c('0x64')]=_0x3f2daa[_0x7f6c('0x62')]['filename'];return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x3f2daa[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x47cf2f,null))[_0x7f6c('0x15')](saveUpdates(_0x3f2daa[_0x7f6c('0x4c')],null))[_0x7f6c('0x15')](respondWithResult(_0x47cf2f,null))[_0x7f6c('0x1d')](handleError(_0x47cf2f,null));};exports[_0x7f6c('0x65')]=function(_0x404e63,_0x4d0dcc){_0x404e63[_0x7f6c('0x4c')]['customerAvatar']=_0x404e63[_0x7f6c('0x62')]['filename'];return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x404e63['params']['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x4d0dcc,null))[_0x7f6c('0x15')](saveUpdates(_0x404e63['body'],null))[_0x7f6c('0x15')](respondWithResult(_0x4d0dcc,null))['catch'](handleError(_0x4d0dcc,null));};exports[_0x7f6c('0x66')]=function(_0x9ff0d5,_0x550c05){_0x9ff0d5[_0x7f6c('0x4c')][_0x7f6c('0x67')]=_0x9ff0d5[_0x7f6c('0x62')][_0x7f6c('0x63')];return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x9ff0d5[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x550c05,null))[_0x7f6c('0x15')](saveUpdates(_0x9ff0d5[_0x7f6c('0x4c')],null))[_0x7f6c('0x15')](respondWithResult(_0x550c05,null))[_0x7f6c('0x1d')](handleError(_0x550c05,null));};exports['getLogo']=function(_0x546987,_0x1ebe6a){var _0x29e7ad=path['join'](config[_0x7f6c('0x68')],_0x7f6c('0x69'));var _0x33f588={'where':{'id':_0x546987[_0x7f6c('0x49')]['id']},'attributes':['id','sitepic'],'raw':!![]};var _0x47a520=![];return require(_0x7f6c('0x6a'))['getLicense']()[_0x7f6c('0x15')](function(_0x402453){if(_0x402453){_0x47a520=_0x402453[_0x7f6c('0x6b')];}})[_0x7f6c('0x15')](function(){return db[_0x7f6c('0x30')]['find'](_0x33f588);})[_0x7f6c('0x15')](handleEntityNotFound(_0x1ebe6a,null))['then'](function(_0x33a4f1){if(_0x33a4f1){if(!_[_0x7f6c('0x6c')](_0x33a4f1[_0x7f6c('0x61')])){if(fs[_0x7f6c('0x6d')](path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0x6f'),_0x33a4f1[_0x7f6c('0x61')]))&&_0x47a520){_0x29e7ad=path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],'server/files/images/logos/',_0x33a4f1[_0x7f6c('0x61')]);}}return _0x1ebe6a[_0x7f6c('0x70')](_0x29e7ad);}})[_0x7f6c('0x1d')](handleError(_0x1ebe6a,null));};exports[_0x7f6c('0x71')]=function(_0x329522,_0xa82d9){var _0x5f24dd=path['join'](config[_0x7f6c('0x68')],_0x7f6c('0x72'));var _0x2f6c85={'where':{'id':_0x329522[_0x7f6c('0x49')]['id']},'attributes':['id','agentAvatar'],'raw':!![]};return db[_0x7f6c('0x30')][_0x7f6c('0x4a')](_0x2f6c85)[_0x7f6c('0x15')](handleEntityNotFound(_0xa82d9,null))[_0x7f6c('0x15')](function(_0x323317){if(_0x323317){if(!_['isNil'](_0x323317[_0x7f6c('0x64')])){if(fs['existsSync'](path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0x73'),_0x323317[_0x7f6c('0x64')]))){_0x5f24dd=path['join'](config[_0x7f6c('0x68')],_0x7f6c('0x73'),_0x323317[_0x7f6c('0x64')]);}}return _0xa82d9[_0x7f6c('0x70')](_0x5f24dd);}})[_0x7f6c('0x1d')](handleError(_0xa82d9,null));};exports[_0x7f6c('0x74')]=function(_0x2d9e39,_0x715fbf){var _0x110e5f=path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0x75'));var _0x46bc58={'where':{'id':_0x2d9e39[_0x7f6c('0x49')]['id']},'attributes':['id',_0x7f6c('0x76'),'showCustomerAvatar'],'raw':!![]};return db[_0x7f6c('0x30')][_0x7f6c('0x4a')](_0x46bc58)[_0x7f6c('0x15')](handleEntityNotFound(_0x715fbf,null))[_0x7f6c('0x15')](function(_0x432f7c){if(_0x432f7c){if(!_[_0x7f6c('0x6c')](_0x432f7c[_0x7f6c('0x76')])){if(fs['existsSync'](path[_0x7f6c('0x6e')](config['root'],_0x7f6c('0x73'),_0x432f7c['customerAvatar']))&&_0x432f7c[_0x7f6c('0x77')]){_0x110e5f=path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0x73'),_0x432f7c[_0x7f6c('0x76')]);}}return _0x715fbf[_0x7f6c('0x70')](_0x110e5f);}})[_0x7f6c('0x1d')](handleError(_0x715fbf,null));};exports[_0x7f6c('0x78')]=function(_0xe6bdca,_0x3e14d0){var _0x5d9aa6=path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0x79'));var _0x3ec89c={'where':{'id':_0xe6bdca['params']['id']},'attributes':['id',_0x7f6c('0x67')],'raw':!![]};return db[_0x7f6c('0x30')]['find'](_0x3ec89c)[_0x7f6c('0x15')](handleEntityNotFound(_0x3e14d0,null))[_0x7f6c('0x15')](function(_0x158297){if(_0x158297){if(!_[_0x7f6c('0x6c')](_0x158297[_0x7f6c('0x67')])){if(fs[_0x7f6c('0x6d')](path[_0x7f6c('0x6e')](config['root'],_0x7f6c('0x73'),_0x158297[_0x7f6c('0x67')]))){_0x5d9aa6=path['join'](config[_0x7f6c('0x68')],_0x7f6c('0x73'),_0x158297['systemAvatar']);}}return _0x3e14d0[_0x7f6c('0x70')](_0x5d9aa6);}})[_0x7f6c('0x1d')](handleError(_0x3e14d0,null));};exports[_0x7f6c('0x7a')]=function(_0x455249,_0x558867){var _0x1a3bda=require(_0x7f6c('0x7b'));var _0x4a5adf=new _0x1a3bda();var _0x4b2932=_0x4a5adf[_0x7f6c('0x7c')](_0x455249[_0x7f6c('0x7d')][_0x7f6c('0x7e')])['getResult']();var _0x41a4a2={'body':_0x455249[_0x7f6c('0x4c')],'channel':_0x7f6c('0x7f')};var _0xe95b22=[];var _0x274bd8=[];var _0xddf38a={};var _0x5e67a8=![];return db[_0x7f6c('0x80')]['describe']()['then'](function(_0xf63900){if(!_0xf63900){throw new db[(_0x7f6c('0x81'))]['ValidationError'](_0x7f6c('0x82'));}_0xe95b22=_[_0x7f6c('0x83')](_['keys'](_0xf63900),[_0x7f6c('0x84'),'updatedAt']);_0x274bd8=_[_0x7f6c('0x83')](_['keys'](_0xf63900),[_0x7f6c('0x84'),_0x7f6c('0x85'),_0x7f6c('0x86'),'ListId']);if(_0x455249[_0x7f6c('0x4c')]['id']){delete _0x455249[_0x7f6c('0x4c')]['id'];}if(_[_0x7f6c('0x6c')](_0x455249[_0x7f6c('0x4c')][_0x7f6c('0x87')])){throw new db[(_0x7f6c('0x81'))][(_0x7f6c('0x88'))](_0x7f6c('0x89'));}if(_[_0x7f6c('0x6c')](_0x455249['body']['body'])||_0x455249[_0x7f6c('0x4c')][_0x7f6c('0x4c')]===''){throw new db['Sequelize']['ValidationError'](_0x7f6c('0x8a'));}if(_['isNil'](_0x455249[_0x7f6c('0x4c')]['mapKey'])){throw new db[(_0x7f6c('0x81'))][(_0x7f6c('0x88'))](_0x7f6c('0x8b')+_0x274bd8);}if(!_[_0x7f6c('0x8c')](_0x274bd8,_0x455249['body'][_0x7f6c('0x8d')])){throw new db[(_0x7f6c('0x81'))][(_0x7f6c('0x88'))](_0x7f6c('0x8e')+_0x274bd8);}_0xddf38a[_0x455249[_0x7f6c('0x4c')]['mapKey']]=_0x455249[_0x7f6c('0x4c')][_0x7f6c('0x87')];})[_0x7f6c('0x15')](function(){return db['ChatWebsite'][_0x7f6c('0x4a')]({'where':{'id':_0x455249['params']['id']},'include':[{'model':db['CmList'],'as':_0x7f6c('0x8f'),'include':[{'model':db[_0x7f6c('0x80')],'as':_0x7f6c('0x90'),'where':_0xddf38a,'limit':0x1,'order':[[_0x7f6c('0x85'),_0x7f6c('0x91')]]}]},{'model':db[_0x7f6c('0x92')],'as':_0x7f6c('0x93')}]});})[_0x7f6c('0x15')](handleEntityNotFound(_0x558867,null))[_0x7f6c('0x15')](function(_0x49f3a9){if(_0x49f3a9&&_0x49f3a9[_0x7f6c('0x8f')]){_0x41a4a2[_0x7f6c('0x94')]=_0x49f3a9;_0x41a4a2[_0x7f6c('0x95')]=_0x49f3a9[_0x7f6c('0x93')];_0x41a4a2[_0x7f6c('0x96')]=_0x49f3a9[_0x7f6c('0x8f')];_0x41a4a2[_0x7f6c('0x95')]=_[_0x7f6c('0x97')](_0x41a4a2[_0x7f6c('0x95')],[_0x7f6c('0x98')],[_0x7f6c('0x99')]);if(_0x41a4a2[_0x7f6c('0x94')][_0x7f6c('0x93')]){delete _0x41a4a2[_0x7f6c('0x94')][_0x7f6c('0x93')];}if(_0x41a4a2[_0x7f6c('0x94')][_0x7f6c('0x8f')]&&_0x41a4a2[_0x7f6c('0x94')]['List'][_0x7f6c('0x90')][_0x7f6c('0x3b')]){return _0x41a4a2['account']['List'][_0x7f6c('0x90')][0x0];}var _0xbc6aed=_[_0x7f6c('0x9a')](_0x455249[_0x7f6c('0x4c')],{'firstName':_0x455249['body'][_0x7f6c('0x87')],'ListId':_0x49f3a9['ListId']});_0xbc6aed[_0x455249[_0x7f6c('0x4c')][_0x7f6c('0x8d')]]=_0x455249['body'][_0x7f6c('0x87')];return db[_0x7f6c('0x80')]['create'](_0xbc6aed,{'fields':_0xe95b22,'raw':!![]});}})[_0x7f6c('0x15')](handleEntityNotFound(_0x558867,null))['then'](function(_0x46163a){_0x41a4a2[_0x7f6c('0x9b')]=_0x46163a;var _0x281f49=_0x455249['body'][_0x7f6c('0x9c')];if(_0x455249[_0x7f6c('0x7d')][_0x7f6c('0x9d')]){_0x281f49=_0x455249[_0x7f6c('0x7d')][_0x7f6c('0x9d')];}else if(_0x455249['headers'][_0x7f6c('0x9e')]){_0x281f49=_[_0x7f6c('0x9f')](_0x455249[_0x7f6c('0x7d')][_0x7f6c('0x9e')][_0x7f6c('0xa0')](','));}if(_0x46163a){var _0x41011a={'ContactId':_0x46163a['id'],'ChatWebsiteId':_0x455249[_0x7f6c('0x49')]['id'],'from':(_0x46163a['firstName']||'')+'\x20'+(_0x46163a[_0x7f6c('0xa1')]||''),'customerIp':_0x281f49,'customerPort':_0x455249['headers'][_0x7f6c('0xa2')]?_0x455249['headers'][_0x7f6c('0xa2')]:null,'referer':_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xa3')],'browserName':_0x4b2932[_0x7f6c('0xa4')]['name']&&_0x4b2932[_0x7f6c('0xa4')][_0x7f6c('0xa5')]?util[_0x7f6c('0xa6')](_0x7f6c('0xa7'),_0x4b2932[_0x7f6c('0xa4')][_0x7f6c('0x2b')],_0x4b2932[_0x7f6c('0xa4')][_0x7f6c('0xa5')]):_0x7f6c('0xa8'),'browserVersion':_0x4b2932[_0x7f6c('0xa4')][_0x7f6c('0xa5')]||'unknown','osName':util[_0x7f6c('0xa6')](_0x7f6c('0xa7'),_0x4b2932['os'][_0x7f6c('0x2b')],_0x4b2932['os'][_0x7f6c('0xa5')]),'osVersion':_0x4b2932['os'][_0x7f6c('0xa5')],'deviceModel':_0x4b2932[_0x7f6c('0xa9')][_0x7f6c('0x34')]&&_0x4b2932[_0x7f6c('0xa9')][_0x7f6c('0xaa')]?util[_0x7f6c('0xa6')](_0x7f6c('0xab'),_0x4b2932[_0x7f6c('0xa9')]['model'],_0x4b2932['device']['vendor'],_0x4b2932[_0x7f6c('0xa9')]['type']):null,'deviceVendor':_0x4b2932[_0x7f6c('0xa9')]['vendor'],'deviceType':_0x4b2932[_0x7f6c('0xa9')][_0x7f6c('0x33')],'formData':JSON['stringify'](_0x455249['body'])};var _0x39ae2e={'ChatWebsiteId':_0x455249['params']['id'],'closed':![]};if(_0x455249['body'][_0x7f6c('0xac')]){_0x39ae2e['threadId']=_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xac')];return db[_0x7f6c('0xad')][_0x7f6c('0x4a')]({'where':_0x39ae2e})[_0x7f6c('0x15')](function(_0x5048df){if(_0x5048df){return[_0x5048df,![]];}_0x41011a[_0x7f6c('0xac')]=_0x455249['body'][_0x7f6c('0xac')];_0x41011a['externalUrl']=_0x455249['body'][_0x7f6c('0xae')];return db[_0x7f6c('0xad')][_0x7f6c('0x4b')](_0x41011a)['then'](function(_0x12673b){return[_0x12673b,!![]];});});}_0x39ae2e[_0x7f6c('0xaf')]=_0x46163a['id'];if(_0x455249[_0x7f6c('0x4c')]['interaction']&&_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xb0')]['id']){_0x39ae2e['id']=_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xb0')]['id'];return db['ChatInteraction'][_0x7f6c('0x4a')]({'where':_0x39ae2e})[_0x7f6c('0x15')](function(_0x14ba0b){if(_0x14ba0b){return[_0x14ba0b,![]];}return db['ChatInteraction'][_0x7f6c('0x4b')](_0x41011a)['then'](function(_0x1e160b){return[_0x1e160b,!![]];});});}return db[_0x7f6c('0xad')][_0x7f6c('0x4b')](_0x41011a)['then'](function(_0xdf4e3f){return[_0xdf4e3f,!![]];});}})[_0x7f6c('0xb1')](function(_0x3cadb9,_0x2cbe8e){if(_0x3cadb9){_0x5e67a8=_0x2cbe8e;if(!_0x2cbe8e){var _0x1497cf={'from':(_0x41a4a2[_0x7f6c('0x9b')][_0x7f6c('0xb2')]||'')+'\x20'+(_0x41a4a2['contact'][_0x7f6c('0xa1')]||'')};if(_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xac')]&&_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xb3')]&&_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xac')]!=_0x455249[_0x7f6c('0x4c')]['messageId']){_0x1497cf[_0x7f6c('0xac')]=_0x455249['body']['messageId'];}return _0x3cadb9['update'](_0x1497cf);}else{return _0x3cadb9;}}})['then'](function(_0x57acbc){_0x41a4a2[_0x7f6c('0xb0')]=_0x57acbc['get']({'plain':!![]});_0x41a4a2[_0x7f6c('0xb0')][_0x7f6c('0xb4')]=_0x5e67a8;if(_0x41a4a2[_0x7f6c('0xb0')][_0x7f6c('0xb4')]){if(_0x41a4a2[_0x7f6c('0x94')][_0x7f6c('0xb5')]){_0x41a4a2[_0x7f6c('0x95')][_0x7f6c('0xb6')]({'id':0x0,'priority':_0x41a4a2[_0x7f6c('0x95')]['length']+0x1,'app':_0x7f6c('0xb7'),'appdata':_0x7f6c('0xb8'),'interval':_0x7f6c('0xb9')});}}return db[_0x7f6c('0xba')][_0x7f6c('0x4b')]({'body':_0x455249[_0x7f6c('0x4c')][_0x7f6c('0x4c')],'ChatWebsiteId':_0x455249[_0x7f6c('0x49')]['id'],'ChatInteractionId':_0x57acbc['id'],'direction':'in','ContactId':_0x41a4a2[_0x7f6c('0x9b')]['id'],'AttachmentId':_0x455249[_0x7f6c('0x4c')][_0x7f6c('0xbb')]});})[_0x7f6c('0x15')](function(_0x4cb697){_0x41a4a2['message']=_0x4cb697;if(_0x41a4a2['interaction'][_0x7f6c('0xbc')]){return db['User'][_0x7f6c('0x4a')]({'attributes':['id',_0x7f6c('0x2b')],'where':{'id':_0x41a4a2[_0x7f6c('0xb0')][_0x7f6c('0xbc')]}})[_0x7f6c('0x15')](function(_0x5e53e4){if(_0x5e53e4){_0x41a4a2[_0x7f6c('0x95')]['unshift']({'id':0x0,'priority':0x0,'app':_0x7f6c('0xbd'),'appdata':_0x5e53e4[_0x7f6c('0x2b')]+','+(_0x41a4a2[_0x7f6c('0x94')]['waitForTheAssignedAgent']||0xa),'interval':_0x7f6c('0xb9')});_0x41a4a2[_0x7f6c('0xbe')]=!![];}return respondWithRpcPromise(_0x7f6c('0xbf'),'startRouting',_0x41a4a2);});}return respondWithRpcPromise('Start',_0x7f6c('0xc0'),_0x41a4a2);})[_0x7f6c('0x15')](function(_0x1f2c7d){respondWithRpcPromise(_0x7f6c('0xc1'),_0x7f6c('0xc1'),{'event':_0x7f6c('0x7a'),'message':_0x1f2c7d},client9002);return _0x1f2c7d;})['then'](respondWithResult(_0x558867,null))[_0x7f6c('0x1d')](handleError(_0x558867,null));};exports[_0x7f6c('0xc2')]=function(_0x14c157,_0x5c7dc1){var _0x1a1303,_0x3bb6f3,_0x376991;var _0xaa074f=[];var _0x14fed3={};var _0xf4822c=_0x14c157[_0x7f6c('0xc3')]||[];var _0x5eb4e0=[];var _0x1ca35b;return db[_0x7f6c('0x80')]['describe']()[_0x7f6c('0x15')](function(_0x3ee694){if(!_0x3ee694){throw new db[(_0x7f6c('0x81'))][(_0x7f6c('0x88'))](_0x7f6c('0x82'));}_0xaa074f=_['difference'](_['keys'](_0x3ee694),[_0x7f6c('0x84'),_0x7f6c('0x85'),_0x7f6c('0x86'),'ListId']);if(_0x14c157[_0x7f6c('0x4c')]['id']){delete _0x14c157[_0x7f6c('0x4c')]['id'];}if(_[_0x7f6c('0x6c')](_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0x87')])){throw _0x5c7dc1[_0x7f6c('0x25')](0x1f4)[_0x7f6c('0x2c')](new db[(_0x7f6c('0x81'))][(_0x7f6c('0x88'))]('from\x20is\x20mandatory'));}if(_[_0x7f6c('0x6c')](_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0x4c')])||_0x14c157[_0x7f6c('0x4c')]['body']===''){throw _0x5c7dc1['status'](0x1f4)[_0x7f6c('0x2c')](new db[(_0x7f6c('0x81'))]['ValidationError'](_0x7f6c('0x8a')));}if(_[_0x7f6c('0x6c')](_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0xc4')])){throw _0x5c7dc1[_0x7f6c('0x25')](0x1f4)[_0x7f6c('0x2c')](new db[(_0x7f6c('0x81'))][(_0x7f6c('0x88'))](_0x7f6c('0xc5')+_0xaa074f));}if(!_[_0x7f6c('0x8c')](_0xaa074f,_0x14c157['body'][_0x7f6c('0xc4')])){throw _0x5c7dc1[_0x7f6c('0x25')](0x1f4)[_0x7f6c('0x2c')](new db['Sequelize'][(_0x7f6c('0x88'))](_0x7f6c('0xc6')+_0xaa074f));}_0x14fed3[_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0xc4')]]=_0x14c157['body'][_0x7f6c('0x87')];})[_0x7f6c('0x15')](function(){return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x14c157[_0x7f6c('0x49')]['id']},'include':[{'model':db[_0x7f6c('0xc7')],'as':_0x7f6c('0x8f')},{'model':db[_0x7f6c('0xc8')],'as':_0x7f6c('0xc8')}]});})[_0x7f6c('0x15')](handleEntityNotFound(_0x5c7dc1,null))[_0x7f6c('0x15')](function(_0x32d1a5){if(_0x32d1a5&&_0x32d1a5[_0x7f6c('0x8f')]){_0x3bb6f3=_0x32d1a5;var _0x1119fd=_[_0x7f6c('0x9a')](_0x14c157[_0x7f6c('0x4c')],{'firstName':_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0x87')],'phone':_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0x87')],'ListId':_0x32d1a5['ListId']});_0x1119fd[_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0xc4')]]=_0x14c157[_0x7f6c('0x4c')][_0x7f6c('0x87')];return db[_0x7f6c('0x80')][_0x7f6c('0xc9')]({'where':_0x14fed3,'defaults':_0x1119fd});}})['spread'](function(_0x408ae3){if(_0x408ae3){_0x376991=_0x408ae3;var _0x464e83=fs[_0x7f6c('0xca')](path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],'server/files/templates/chatOfflineMessage.ejs'),_0x7f6c('0xcb'));var _0x12a9b3=ejs['render'](_0x464e83,{'body':_['toPairs'](_0x14c157[_0x7f6c('0x4c')]['body']),'bodyTitle':_0x3bb6f3[_0x7f6c('0xcc')]});return db[_0x7f6c('0xcd')][_0x7f6c('0x4b')]({'body':_0x12a9b3,'plainBody':htmlToText['fromString'](_0x12a9b3),'ContactId':_0x408ae3['id'],'ChatWebsiteId':_0x3bb6f3['id']});}})[_0x7f6c('0x15')](function(_0x51a7ba){_0x1ca35b=_0x51a7ba;if(_0xf4822c['length']){var _0x5ab923=_0xf4822c[_0x7f6c('0x35')](function(_0x455373){return{'name':_0x455373[_0x7f6c('0xce')],'basename':_0x455373[_0x7f6c('0x63')],'type':_0x455373[_0x7f6c('0xcf')],'ChatOfflineMessageId':_0x51a7ba['id']};});_0x5eb4e0=_0x5ab923[_0x7f6c('0x35')](_0x5f408e=>{var _0x2f1ddf={'filename':_0x5f408e[_0x7f6c('0x2b')],'path':path['join'](config[_0x7f6c('0x68')],_0x7f6c('0xd0'),_0x7f6c('0xc3'),'attachments',_0x7f6c('0xd1'),_0x5f408e[_0x7f6c('0xd2')])};return _0x2f1ddf;});if(!_0x3bb6f3[_0x7f6c('0xd3')]){return db[_0x7f6c('0xd4')][_0x7f6c('0xd5')](function(_0x2f3ced){return db[_0x7f6c('0xd6')][_0x7f6c('0xd7')](_0x5ab923,{'transaction':_0x2f3ced});});}}})['then'](function(){if(_0x1ca35b){_0x1a1303=_0x1ca35b;return db['MailAccount']['findOne']({'where':{'service':!![]},'include':[{'model':db[_0x7f6c('0xd8')],'as':_0x7f6c('0xd9'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0x7f6c('0xda'),'raw':!![]}]}]});}})[_0x7f6c('0x15')](function(_0x1bc07e){if(_0x1bc07e&&_0x1bc07e[_0x7f6c('0xd9')]&&_0x3bb6f3[_0x7f6c('0xdb')]&&_0x3bb6f3[_0x7f6c('0xdc')]){var _0x4fbf5a=_0x1bc07e['getSmtpOptions']();return respondWithRpcPromise(_0x7f6c('0xdd'),'sendMail',{'account':_0x4fbf5a,'message':{'from':util[_0x7f6c('0xa6')](_0x7f6c('0xde'),_0x1bc07e[_0x7f6c('0x2b')],_0x1bc07e[_0x7f6c('0xdf')]||_0x1bc07e[_0x7f6c('0xd9')][_0x7f6c('0x4d')]),'to':_0x3bb6f3[_0x7f6c('0xdc')],'subject':_0x3bb6f3['offlineMessageSubject'],'html':_0x1a1303[_0x7f6c('0x4c')],'attachments':_0x5eb4e0}},client9003)['then'](function(){return _0x1a1303;})[_0x7f6c('0x1d')](function(_0x157a51){logger['error'](_0x157a51);});}})['then'](function(){if(_0x3bb6f3&&_0x3bb6f3['openNewInteraction']&&_0x3bb6f3[_0x7f6c('0xe0')]){var _0x1553fa=[];if(_0xf4822c['length']){_0x1553fa=_0xf4822c['map'](function(_0x58a3aa){return{'name':_0x58a3aa[_0x7f6c('0xce')],'basename':_0x58a3aa[_0x7f6c('0x63')],'type':_0x58a3aa[_0x7f6c('0xcf')],'ChatOfflineMessageId':_0x1ca35b['id']};});}var _0x74745a;if(!_[_0x7f6c('0x6c')](_0x3bb6f3[_0x7f6c('0xe1')])){var _0x2787ff=_[_0x7f6c('0x35')](_0x14c157[_0x7f6c('0x4c')],function(_0xc64fa9){return _0xc64fa9;});var _0x4f0826=_[_0x7f6c('0xe2')](_0x2787ff)[0x0];var _0x4283a7=_['mapValues'](_0x4f0826,function(_0x2867a8){return _0x2867a8;});_0x74745a=_0x4283a7[0x1][_0x3bb6f3['subjectOffline']];}var _0x3552eb={'from':_0x376991['email'],'firstName':_0x376991[_0x7f6c('0xb2')],'lastName':_0x376991[_0x7f6c('0xa1')],'mapKey':'email','message':{'from':_0x376991[_0x7f6c('0xdf')],'to':_0x3bb6f3[_0x7f6c('0xc8')]['email'],'cc':'','subject':_['isNil'](_0x74745a)?_0x3bb6f3[_0x7f6c('0xe3')]:_0x74745a,'messageId':'','sentAt':new Date(),'attach':_0x1553fa['length'],'attachments':_0x1553fa,'originChannel':_0x7f6c('0xe4'),'ChatWebsiteId':_0x3bb6f3['id'],'ChatOfflineMessageId':_0x1a1303['id'],'originTo':_0x3bb6f3['MailAccount'][_0x7f6c('0xdf')]},'body':_0x1a1303[_0x7f6c('0x4c')]};var _0x2b90a5={'account':{'id':_0x3bb6f3[_0x7f6c('0xe0')]},'body':_0x3552eb,'log':'NotifyMailAccount'};return respondWithRpcPromise(_0x7f6c('0xe5'),_0x7f6c('0xe6'),_0x2b90a5,client9001)[_0x7f6c('0x15')](function(){return _0x1a1303;})[_0x7f6c('0x1d')](function(_0x2e17d1){logger[_0x7f6c('0x1a')](_0x2e17d1);});}return;})['then'](function(){if(_0x1a1303){return _0x1a1303;}})['then'](respondWithResult(_0x5c7dc1,null))[_0x7f6c('0x1d')](function(_0x470bbe){logger[_0x7f6c('0x1a')]('catch',_0x470bbe);for(var _0x519750 of _0xf4822c){var _0x31bdf7=path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0xd0'),_0x7f6c('0xc3'),_0x7f6c('0xe7'),_0x7f6c('0xd1'),_0x519750[_0x7f6c('0x63')]);fs_extra[_0x7f6c('0xe8')](_0x31bdf7)['catch'](function(_0x229d2a){logger[_0x7f6c('0x1a')](_0x7f6c('0xe9'),_0x31bdf7,_0x229d2a);});}});};exports[_0x7f6c('0xea')]=function(_0x43c3f3,_0x44d776){return db[_0x7f6c('0xad')][_0x7f6c('0x4a')]({'where':{'id':_0x43c3f3[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x44d776,null))[_0x7f6c('0x15')](function(_0x1de04f){if(_0x1de04f){return _0x1de04f['addInteraction'](_0x43c3f3[_0x7f6c('0x4c')][_0x7f6c('0x5a')],_[_0x7f6c('0xeb')](_0x43c3f3[_0x7f6c('0x4c')],[_0x7f6c('0x5a'),'id'])||{});}})[_0x7f6c('0x15')](respondWithResult(_0x44d776,null))[_0x7f6c('0x1d')](handleError(_0x44d776,null));};exports[_0x7f6c('0xec')]=function(_0x339511,_0x5450c5){var _0x212ac3={'raw':![],'where':{}};var _0x1f3de6={};var _0x2ee966={'count':0x0,'rows':[]};return db['ChatWebsite'][_0x7f6c('0x55')]({'where':{'id':_0x339511[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x5450c5,null))[_0x7f6c('0x15')](function(_0x158fe9){if(_0x158fe9){_0x1f3de6[_0x7f6c('0x34')]=_[_0x7f6c('0x37')](db[_0x7f6c('0xad')][_0x7f6c('0x31')]);_0x1f3de6[_0x7f6c('0x36')]=_[_0x7f6c('0x37')](_0x339511[_0x7f6c('0x36')]);_0x1f3de6[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x1f3de6['model'],_0x1f3de6['query']);_0x212ac3[_0x7f6c('0x39')]=_[_0x7f6c('0x38')](_0x1f3de6[_0x7f6c('0x34')],qs[_0x7f6c('0x3a')](_0x339511[_0x7f6c('0x36')][_0x7f6c('0x3a')]));_0x212ac3[_0x7f6c('0x39')]=_0x212ac3[_0x7f6c('0x39')][_0x7f6c('0x3b')]?_0x212ac3[_0x7f6c('0x39')]:_0x1f3de6[_0x7f6c('0x34')];if(!_0x339511[_0x7f6c('0x36')]['hasOwnProperty'](_0x7f6c('0x56'))){_0x212ac3[_0x7f6c('0x22')]=qs[_0x7f6c('0x22')](_0x339511['query'][_0x7f6c('0x22')]);_0x212ac3['offset']=qs[_0x7f6c('0x24')](_0x339511[_0x7f6c('0x36')]['offset']);}_0x212ac3[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0x339511[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0x212ac3[_0x7f6c('0x3e')]=qs['filters'](_[_0x7f6c('0x57')](_0x339511[_0x7f6c('0x36')],_0x1f3de6['filters']));_0x212ac3[_0x7f6c('0x3e')]['ChatWebsiteId']=_0x158fe9['id'];if(_0x339511[_0x7f6c('0x36')]['filter']){_0x212ac3['where']=_['merge'](_0x212ac3['where'],{'$or':_[_0x7f6c('0x35')](_0x212ac3[_0x7f6c('0x39')],function(_0x5a2927){var _0x2147ae={};_0x2147ae[_0x5a2927]={'$like':'%'+_0x339511[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x2147ae;})});}_0x212ac3=_[_0x7f6c('0x42')]({},_0x212ac3,_0x339511[_0x7f6c('0x43')]);return db[_0x7f6c('0xad')]['count']({'where':_0x212ac3[_0x7f6c('0x3e')]})[_0x7f6c('0x15')](function(_0x1a1014){_0x2ee966[_0x7f6c('0x23')]=_0x1a1014;if(_0x339511['query'][_0x7f6c('0x44')]){_0x212ac3[_0x7f6c('0x45')]=[{'model':db[_0x7f6c('0x80')],'as':'Contact','required':![]},{'model':db['User'],'as':_0x7f6c('0xed'),'attributes':[_0x7f6c('0x2b'),_0x7f6c('0xee'),_0x7f6c('0xef')],'required':![]},{'model':db[_0x7f6c('0xf0')],'as':_0x7f6c('0xf1'),'attributes':['id',_0x7f6c('0x2b'),_0x7f6c('0xf2')],'where':_0x339511[_0x7f6c('0x36')][_0x7f6c('0xf3')]?{'id':_0x339511[_0x7f6c('0x36')][_0x7f6c('0xf3')]}:undefined,'required':_0x339511[_0x7f6c('0x36')][_0x7f6c('0xf3')]?!![]:![]}];}return db['ChatInteraction'][_0x7f6c('0x46')](_0x212ac3);})[_0x7f6c('0x15')](function(_0x636f){_0x2ee966[_0x7f6c('0x47')]=_0x636f;return _0x2ee966;});}})[_0x7f6c('0x15')](respondWithFilteredResult(_0x5450c5,_0x212ac3))[_0x7f6c('0x1d')](handleError(_0x5450c5,null));};function iftimePromise(_0x232941,_0x2f9b58){return respondWithRpcPromise('Command',_0x7f6c('0xf4'),{'command':_0x2f9b58['timezone']?util[_0x7f6c('0xa6')]('iftime\x20%s,%s',_0x232941[_0x7f6c('0xf5')],_0x2f9b58[_0x7f6c('0xf6')]):util['format'](_0x7f6c('0xf7'),_0x232941['interval'])},client9002)[_0x7f6c('0x15')](function(_0x4aa582){var _0xc61917=_0x4aa582&&_0x4aa582[_0x7f6c('0xf8')](_0x7f6c('0xf9'))>=0x0?!![]:![];logger['info'](_0x7f6c('0xfa'),_0x2f9b58['id'],_0x232941['id'],_0x232941[_0x7f6c('0xf5')],_0xc61917?_0x7f6c('0xfb'):_0x7f6c('0xfc'),_0x2f9b58['timezone']?_0x2f9b58['timezone']:_0x7f6c('0xfd'));return _0xc61917;})[_0x7f6c('0x1d')](function(_0x706d37){logger[_0x7f6c('0x1a')](_0x7f6c('0xfa'),_0x2f9b58['id'],_0x232941['id'],_0x232941['interval'],util[_0x7f6c('0xfe')](_0x706d37,{'showHidden':![],'depth':null}),_0x2f9b58[_0x7f6c('0xf6')]?_0x2f9b58['timezone']:_0x7f6c('0xfd'));return![];});}exports[_0x7f6c('0xf4')]=function(_0x20960a,_0x5da4a2){var _0xb79c4e=0x0;var _0x1351c5=0x0;var _0x5447e7=![];var _0x4b2e95;var _0x463718;return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x20960a[_0x7f6c('0x49')]['id']},'include':[{'model':db[_0x7f6c('0xff')],'as':_0x7f6c('0xff'),'include':[{'model':db['Interval'],'as':_0x7f6c('0x100'),'attributes':['id',_0x7f6c('0xf5')],'raw':!![]}]}]})[_0x7f6c('0x15')](handleEntityNotFound(_0x5da4a2,null))[_0x7f6c('0x15')](function(_0x5c5b68){if(_0x5c5b68){_0x4b2e95=_0x5c5b68;return _0x5c5b68[_0x7f6c('0x101')]({'raw':!![]});}})[_0x7f6c('0x15')](function(_0x47fb49){if(_0x4b2e95){if(_0x47fb49){_0x463718=_0x47fb49;}}return require(_0x7f6c('0x6a'))[_0x7f6c('0x102')]();})['then'](function(_0x18dbb8){if(_0x18dbb8){_0x1351c5=_0x18dbb8[_0x7f6c('0x103')];_0x5447e7=_0x18dbb8[_0x7f6c('0x6b')];}})[_0x7f6c('0x15')](function(){return db[_0x7f6c('0xad')][_0x7f6c('0x23')]({'where':{'closed':![]}});})[_0x7f6c('0x15')](function(_0x5b0267){_0xb79c4e=_0x5b0267;if(_0x1351c5&&_0x5b0267>_0x1351c5){return db[_0x7f6c('0x104')][_0x7f6c('0x55')]({'where':{'id':0x1}})[_0x7f6c('0x15')](function(_0x552cad){if(_0x552cad){_0x552cad['increment']('chatLicenseExceeded');}});}})[_0x7f6c('0x15')](function(){if(_0x4b2e95['Interval']&&_0x4b2e95[_0x7f6c('0xff')]['Intervals']){var _0x7f0012=[];for(var _0x556db0=0x0;_0x556db0<_0x4b2e95['Interval'][_0x7f6c('0x100')][_0x7f6c('0x3b')];_0x556db0++){var _0x1dc463=_0x4b2e95[_0x7f6c('0xff')]['Intervals'][_0x556db0][_0x7f6c('0x26')]({'plain':!![]});_0x7f0012['push'](iftimePromise(_0x1dc463,_0x4b2e95));}return BPromise[_0x7f6c('0x105')](_0x7f0012)[_0x7f6c('0x15')](function(_0x29bb0f){return _[_0x7f6c('0x106')](_0x29bb0f);});}else{return!![];}})['then'](function(_0x2335c3){var _0x4aaf4e=fs[_0x7f6c('0xca')](path[_0x7f6c('0x6e')](config[_0x7f6c('0x68')],_0x7f6c('0x107')),'utf8');var _0x58710e={'remote':_0x4b2e95[_0x7f6c('0x108')],'query':querystring[_0x7f6c('0x109')](_[_0x7f6c('0x42')](_0x4b2e95[_0x7f6c('0x26')]({'plain':!![]}),{'customerIp':_0x20960a['headers'][_0x7f6c('0x9e')]||_0x20960a[_0x7f6c('0x7d')][_0x7f6c('0x10a')]||_0x20960a[_0x7f6c('0x10b')]['remoteAddress']||_0x20960a['ip'],'referer':_0x20960a[_0x7f6c('0x7d')][_0x7f6c('0xa3')],'openedInteractions':_0xb79c4e,'maxInteractions':_0x1351c5,'virtual':_0x5447e7[_0x7f6c('0x103')],'online':_0x2335c3,'custom':_0x5447e7}))[_0x7f6c('0x10c')](/'/g,'\x5c\x27')};_0x5da4a2[_0x7f6c('0x2c')](ejs['render'](Mustache[_0x7f6c('0x10d')](_0x4aaf4e,_0x58710e),{'proactiveActions':_0x463718,'alignment':_0x4b2e95[_0x7f6c('0x10e')],'verticalAlignment':_0x4b2e95[_0x7f6c('0x10f')],'div_color':_0x4b2e95[_0x7f6c('0xf2')],'labelText':_0x4b2e95[_0x7f6c('0x110')],'text_color':_0x4b2e95[_0x7f6c('0x111')],'text_button_color':_0x4b2e95[_0x7f6c('0x112')],'button_color':_0x4b2e95[_0x7f6c('0x113')],'background_color':_0x4b2e95[_0x7f6c('0x114')],'hideWhenOffline':_0x4b2e95[_0x7f6c('0x115')],'interval':_0x4b2e95[_0x7f6c('0x116')]}));})[_0x7f6c('0x1d')](handleError(_0x5da4a2,null));};exports[_0x7f6c('0x117')]=function(_0x3772fa,_0x2970b5){var _0x1d919d=_0x3772fa[_0x7f6c('0x49')]['id'];var _0xb04713=_0x3772fa[_0x7f6c('0x4c')];var _0x2cdc55=0xc8;var _0x4597d0=null;return db[_0x7f6c('0xd4')][_0x7f6c('0xd5')]({'isolationLevel':db[_0x7f6c('0xd4')][_0x7f6c('0x118')][_0x7f6c('0x119')][_0x7f6c('0x11a')]},function(_0x38ee11){return db['ChatWebsite']['findOne']({'where':{'id':_0x1d919d},'transaction':_0x38ee11})[_0x7f6c('0x15')](function(_0x3fef7f){if(_0x3fef7f){return db[_0x7f6c('0x92')][_0x7f6c('0x29')]({'where':{'ChatWebsiteId':_0x1d919d},'transaction':_0x38ee11})[_0x7f6c('0x15')](function(){var _0x3d2460=_[_0x7f6c('0x35')](_0xb04713,function(_0x14b619){_0x14b619[_0x7f6c('0x58')]=_0x1d919d;return _0x14b619;});return db[_0x7f6c('0x92')]['bulkCreate'](_0x3d2460,{'transaction':_0x38ee11});});}else{_0x2cdc55=0x194;_0x4597d0=[];}});})[_0x7f6c('0x15')](function(){if(_0x2cdc55!==0x194){return db[_0x7f6c('0x92')][_0x7f6c('0x11b')]({'where':{'ChatWebsiteId':_0x1d919d},'order':_0x7f6c('0x98')})[_0x7f6c('0x15')](function(_0x19d3c1){_0x4597d0=_0x19d3c1;});}})[_0x7f6c('0x1d')](function(_0x169e0a){_0x2cdc55=0x1f4;logger[_0x7f6c('0x1a')](_0x169e0a[_0x7f6c('0x2a')]);if(_0x169e0a[_0x7f6c('0x2b')]){delete _0x169e0a[_0x7f6c('0x2b')];}_0x4597d0=_0x169e0a;})[_0x7f6c('0x11c')](function(){if(_0x4597d0===null){_0x2970b5[_0x7f6c('0x1e')](_0x2cdc55);}else{if(_0x2cdc55===0x1f4){_0x2970b5['status'](_0x2cdc55)['send'](_0x4597d0);}else{_0x2970b5[_0x7f6c('0x25')](_0x2cdc55)['json'](_0x4597d0);}}});};exports[_0x7f6c('0x11d')]=function(_0x1357a3,_0x339e7d){var _0xd16753={};var _0x35a38f={};var _0x42b6e2;var _0x2b8084;return db[_0x7f6c('0x30')][_0x7f6c('0x55')]({'where':{'id':_0x1357a3['params']['id']}})['then'](handleEntityNotFound(_0x339e7d,null))[_0x7f6c('0x15')](function(_0x1b3502){if(_0x1b3502){_0x42b6e2=_0x1b3502;_0x35a38f[_0x7f6c('0x34')]=_[_0x7f6c('0x37')](db[_0x7f6c('0x92')][_0x7f6c('0x31')]);_0x35a38f['query']=_[_0x7f6c('0x37')](_0x1357a3[_0x7f6c('0x36')]);_0x35a38f[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x35a38f[_0x7f6c('0x34')],_0x35a38f[_0x7f6c('0x36')]);_0xd16753['attributes']=_['intersection'](_0x35a38f[_0x7f6c('0x34')],qs[_0x7f6c('0x3a')](_0x1357a3[_0x7f6c('0x36')][_0x7f6c('0x3a')]));_0xd16753[_0x7f6c('0x39')]=_0xd16753[_0x7f6c('0x39')]['length']?_0xd16753[_0x7f6c('0x39')]:_0x35a38f[_0x7f6c('0x34')];_0xd16753[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0x1357a3[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0xd16753['where']=qs[_0x7f6c('0x3f')](_[_0x7f6c('0x57')](_0x1357a3[_0x7f6c('0x36')],_0x35a38f[_0x7f6c('0x3f')]));if(_0x1357a3[_0x7f6c('0x36')]['filter']){_0xd16753[_0x7f6c('0x3e')]=_[_0x7f6c('0x42')](_0xd16753['where'],{'$or':_[_0x7f6c('0x35')](_0xd16753[_0x7f6c('0x39')],function(_0x211b3c){var _0x52f552={};_0x52f552[_0x211b3c]={'$like':'%'+_0x1357a3[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x52f552;})});}_0xd16753=_[_0x7f6c('0x42')]({},_0xd16753,_0x1357a3[_0x7f6c('0x43')]);return _0x42b6e2[_0x7f6c('0x11d')](_0xd16753);}})[_0x7f6c('0x15')](function(_0x4bc1a7){if(_0x4bc1a7){_0x2b8084=_0x4bc1a7[_0x7f6c('0x3b')];if(!_0x1357a3[_0x7f6c('0x36')][_0x7f6c('0x5e')](_0x7f6c('0x56'))){_0xd16753['limit']=qs[_0x7f6c('0x22')](_0x1357a3[_0x7f6c('0x36')]['limit']);_0xd16753[_0x7f6c('0x24')]=qs['offset'](_0x1357a3['query'][_0x7f6c('0x24')]);}return _0x42b6e2[_0x7f6c('0x11d')](_0xd16753);}})[_0x7f6c('0x15')](function(_0x4b0e3c){if(_0x4b0e3c){return _0x4b0e3c?{'count':_0x2b8084,'rows':_0x4b0e3c}:null;}})[_0x7f6c('0x15')](respondWithResult(_0x339e7d,null))[_0x7f6c('0x1d')](handleError(_0x339e7d,null));};exports[_0x7f6c('0x11e')]=function(_0x52e92,_0x490429){return db[_0x7f6c('0x11f')]['find']({'where':{'id':_0x52e92[_0x7f6c('0x49')]['id']}})['then'](handleEntityNotFound(_0x490429,null))[_0x7f6c('0x15')](function(_0x4fa7ff){if(_0x4fa7ff){return _0x4fa7ff[_0x7f6c('0x11e')](_0x52e92['body']['ids'],_[_0x7f6c('0xeb')](_0x52e92[_0x7f6c('0x4c')],['ids','id'])||{});}})[_0x7f6c('0x15')](respondWithResult(_0x490429,null))[_0x7f6c('0x1d')](handleError(_0x490429,null));};exports[_0x7f6c('0x101')]=function(_0x4dd14f,_0x11c919){var _0x488743={};var _0x1054b6={};var _0xd61220;var _0x5c7eef;return db[_0x7f6c('0x30')]['findOne']({'where':{'id':_0x4dd14f['params']['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x11c919,null))['then'](function(_0x40ddbf){if(_0x40ddbf){_0xd61220=_0x40ddbf;_0x1054b6[_0x7f6c('0x34')]=_[_0x7f6c('0x37')](db['ChatProactiveAction'][_0x7f6c('0x31')]);_0x1054b6[_0x7f6c('0x36')]=_[_0x7f6c('0x37')](_0x4dd14f[_0x7f6c('0x36')]);_0x1054b6[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x1054b6[_0x7f6c('0x34')],_0x1054b6[_0x7f6c('0x36')]);_0x488743['attributes']=_['intersection'](_0x1054b6[_0x7f6c('0x34')],qs[_0x7f6c('0x3a')](_0x4dd14f['query'][_0x7f6c('0x3a')]));_0x488743['attributes']=_0x488743[_0x7f6c('0x39')][_0x7f6c('0x3b')]?_0x488743[_0x7f6c('0x39')]:_0x1054b6[_0x7f6c('0x34')];_0x488743[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0x4dd14f[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0x488743['where']=qs['filters'](_[_0x7f6c('0x57')](_0x4dd14f[_0x7f6c('0x36')],_0x1054b6[_0x7f6c('0x3f')]));if(_0x4dd14f['query'][_0x7f6c('0x40')]){_0x488743[_0x7f6c('0x3e')]=_[_0x7f6c('0x42')](_0x488743[_0x7f6c('0x3e')],{'$or':_[_0x7f6c('0x35')](_0x488743[_0x7f6c('0x39')],function(_0x3deae6){var _0x57eb92={};_0x57eb92[_0x3deae6]={'$like':'%'+_0x4dd14f[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x57eb92;})});}_0x488743=_[_0x7f6c('0x42')]({},_0x488743,_0x4dd14f['options']);return _0xd61220[_0x7f6c('0x101')](_0x488743);}})[_0x7f6c('0x15')](function(_0x3bc279){if(_0x3bc279){_0x5c7eef=_0x3bc279[_0x7f6c('0x3b')];if(!_0x4dd14f[_0x7f6c('0x36')]['hasOwnProperty'](_0x7f6c('0x56'))){_0x488743[_0x7f6c('0x22')]=qs[_0x7f6c('0x22')](_0x4dd14f[_0x7f6c('0x36')][_0x7f6c('0x22')]);_0x488743[_0x7f6c('0x24')]=qs['offset'](_0x4dd14f[_0x7f6c('0x36')][_0x7f6c('0x24')]);}return _0xd61220[_0x7f6c('0x101')](_0x488743);}})[_0x7f6c('0x15')](function(_0x41ea8d){if(_0x41ea8d){return _0x41ea8d?{'count':_0x5c7eef,'rows':_0x41ea8d}:null;}})[_0x7f6c('0x15')](respondWithResult(_0x11c919,null))[_0x7f6c('0x1d')](handleError(_0x11c919,null));};exports[_0x7f6c('0x120')]=function(_0x52f2fd,_0x1c5971){var _0x25f1af=_0x52f2fd['query']['online']===_0x7f6c('0x121')?_0x7f6c('0x122'):_0x7f6c('0x123');return db['ChatWebsite'][_0x7f6c('0x4a')]({'attributes':['id',_0x25f1af],'where':{'id':_0x52f2fd['params']['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x1c5971,null))[_0x7f6c('0x15')](function(_0x9a9775){if(_0x9a9775){var _0x4c33da=_0x9a9775[_0x25f1af];var _0x1ccb01=_0x4c33da&&_0x4c33da['items']?_0x4c33da[_0x7f6c('0x124')]:[];_0x1c5971[_0x7f6c('0x2c')]({'fromKey':_['isNil'](_0x4c33da[_0x7f6c('0x125')])?undefined:_0x4c33da[_0x7f6c('0x125')],'count':_0x1ccb01['length'],'rows':_0x1ccb01});}})[_0x7f6c('0x1d')](handleError(_0x1c5971,null));};exports[_0x7f6c('0x126')]=function(_0xe01a08,_0xdf1ca8){var _0x167acb={'raw':![],'where':{}};var _0x3618ac={};var _0x58c7d5={'count':0x0,'rows':[]};return db[_0x7f6c('0x30')][_0x7f6c('0x55')]({'where':{'id':_0xe01a08[_0x7f6c('0x49')]['id']}})['then'](handleEntityNotFound(_0xdf1ca8,null))['then'](function(_0x2c1d0c){if(_0x2c1d0c){_0x3618ac[_0x7f6c('0x34')]=_[_0x7f6c('0x37')](db[_0x7f6c('0xcd')][_0x7f6c('0x31')]);_0x3618ac['query']=_[_0x7f6c('0x37')](_0xe01a08[_0x7f6c('0x36')]);_0x3618ac[_0x7f6c('0x3f')]=_[_0x7f6c('0x38')](_0x3618ac[_0x7f6c('0x34')],_0x3618ac[_0x7f6c('0x36')]);_0x167acb[_0x7f6c('0x39')]=_[_0x7f6c('0x38')](_0x3618ac['model'],qs[_0x7f6c('0x3a')](_0xe01a08['query'][_0x7f6c('0x3a')]));_0x167acb[_0x7f6c('0x39')]=_0x167acb['attributes'][_0x7f6c('0x3b')]?_0x167acb[_0x7f6c('0x39')]:_0x3618ac['model'];if(!_0xe01a08[_0x7f6c('0x36')][_0x7f6c('0x5e')]('nolimit')){_0x167acb['limit']=qs[_0x7f6c('0x22')](_0xe01a08[_0x7f6c('0x36')][_0x7f6c('0x22')]);_0x167acb[_0x7f6c('0x24')]=qs[_0x7f6c('0x24')](_0xe01a08[_0x7f6c('0x36')]['offset']);}_0x167acb[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0xe01a08[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0x167acb[_0x7f6c('0x3e')]=qs[_0x7f6c('0x3f')](_[_0x7f6c('0x57')](_0xe01a08['query'],_0x3618ac[_0x7f6c('0x3f')]));_0x167acb['where'][_0x7f6c('0x58')]=_0x2c1d0c['id'];if(_0xe01a08[_0x7f6c('0x36')][_0x7f6c('0x40')]){_0x167acb['where']=_[_0x7f6c('0x42')](_0x167acb[_0x7f6c('0x3e')],{'$or':_['map'](_0x167acb[_0x7f6c('0x39')],function(_0x1ee957){var _0x34146d={};_0x34146d[_0x1ee957]={'$like':'%'+_0xe01a08[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x34146d;})});}_0x167acb=_['merge']({},_0x167acb,_0xe01a08[_0x7f6c('0x43')]);return db['ChatOfflineMessage'][_0x7f6c('0x23')]({'where':_0x167acb[_0x7f6c('0x3e')]})[_0x7f6c('0x15')](function(_0xbaffb8){_0x58c7d5[_0x7f6c('0x23')]=_0xbaffb8;if(_0xe01a08['query'][_0x7f6c('0x44')]){_0x167acb[_0x7f6c('0x45')]=[{'all':!![]}];}else{_0x167acb['include']=[{'model':db[_0x7f6c('0x80')],'as':_0x7f6c('0x127'),'required':![]},{'model':db[_0x7f6c('0xd6')],'as':_0x7f6c('0x128'),'required':![]}];}return db[_0x7f6c('0xcd')][_0x7f6c('0x46')](_0x167acb);})[_0x7f6c('0x15')](function(_0x5757e3){_0x58c7d5[_0x7f6c('0x47')]=_0x5757e3;return _0x58c7d5;});}})[_0x7f6c('0x15')](respondWithFilteredResult(_0xdf1ca8,_0x167acb))[_0x7f6c('0x1d')](handleError(_0xdf1ca8,null));};exports[_0x7f6c('0x129')]=function(_0xcb978,_0xce3ce0){return db['ChatWebsite'][_0x7f6c('0x4a')]({'where':{'id':_0xcb978['params']['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0xce3ce0,null))[_0x7f6c('0x15')](function(_0x12baa1){if(_0x12baa1){return _0x12baa1[_0x7f6c('0x129')](_0xcb978[_0x7f6c('0x4c')][_0x7f6c('0x5a')],_[_0x7f6c('0xeb')](_0xcb978[_0x7f6c('0x4c')],[_0x7f6c('0x5a'),'id'])||{})[_0x7f6c('0xb1')](function(_0x1e4742){for(var _0x524d84=0x0;_0x524d84<_0xcb978[_0x7f6c('0x4c')][_0x7f6c('0x5a')]['length'];_0x524d84+=0x1){socket[_0x7f6c('0x12a')](_0x7f6c('0x12b'),{'UserId':Number(_0xcb978[_0x7f6c('0x4c')][_0x7f6c('0x5a')][_0x524d84]),'ChatWebsiteId':Number(_0xcb978['params']['id'])});}return _0x1e4742;});}})[_0x7f6c('0x15')](respondWithResult(_0xce3ce0,null))[_0x7f6c('0x1d')](handleError(_0xce3ce0,null));};exports[_0x7f6c('0x12c')]=function(_0x3b383f,_0x5452af){return db[_0x7f6c('0x30')][_0x7f6c('0x4a')]({'where':{'id':_0x3b383f[_0x7f6c('0x49')]['id']}})[_0x7f6c('0x15')](handleEntityNotFound(_0x5452af,null))[_0x7f6c('0x15')](function(_0x4c2e07){if(_0x4c2e07){return _0x4c2e07[_0x7f6c('0x12c')](_0x3b383f[_0x7f6c('0x36')][_0x7f6c('0x5a')])[_0x7f6c('0x15')](function(){if(_[_0x7f6c('0x12d')](_0x3b383f[_0x7f6c('0x36')][_0x7f6c('0x5a')])){for(var _0x3366fe=0x0;_0x3366fe<_0x3b383f['query'][_0x7f6c('0x5a')][_0x7f6c('0x3b')];_0x3366fe+=0x1){socket['emit']('userChatWebsite:remove',{'UserId':Number(_0x3b383f['query'][_0x7f6c('0x5a')][_0x3366fe]),'ChatWebsiteId':Number(_0x3b383f[_0x7f6c('0x49')]['id'])});}}else{socket[_0x7f6c('0x12a')](_0x7f6c('0x12e'),{'UserId':Number(_0x3b383f[_0x7f6c('0x36')][_0x7f6c('0x5a')]),'ChatWebsiteId':Number(_0x3b383f[_0x7f6c('0x49')]['id'])});}});}})[_0x7f6c('0x15')](respondWithStatusCode(_0x5452af,null))['catch'](handleError(_0x5452af,null));};exports['getAgents']=function(_0x5c4c43,_0x523008){var _0x2d30f7={};var _0x785949={};var _0xbb8888;var _0x37b905;return db[_0x7f6c('0x30')][_0x7f6c('0x55')]({'where':{'id':_0x5c4c43[_0x7f6c('0x49')]['id']}})['then'](handleEntityNotFound(_0x523008,null))[_0x7f6c('0x15')](function(_0x190bc2){if(_0x190bc2){_0xbb8888=_0x190bc2;_0x785949[_0x7f6c('0x34')]=_[_0x7f6c('0x37')](db[_0x7f6c('0x12f')][_0x7f6c('0x31')]);_0x785949[_0x7f6c('0x36')]=_[_0x7f6c('0x37')](_0x5c4c43[_0x7f6c('0x36')]);_0x785949['filters']=_[_0x7f6c('0x38')](_0x785949[_0x7f6c('0x34')],_0x785949[_0x7f6c('0x36')]);_0x2d30f7[_0x7f6c('0x39')]=_[_0x7f6c('0x38')](_0x785949[_0x7f6c('0x34')],qs[_0x7f6c('0x3a')](_0x5c4c43['query'][_0x7f6c('0x3a')]));_0x2d30f7[_0x7f6c('0x39')]=_0x2d30f7['attributes'][_0x7f6c('0x3b')]?_0x2d30f7['attributes']:_0x785949[_0x7f6c('0x34')];_0x2d30f7[_0x7f6c('0x3c')]=qs[_0x7f6c('0x3d')](_0x5c4c43[_0x7f6c('0x36')][_0x7f6c('0x3d')]);_0x2d30f7[_0x7f6c('0x3e')]=qs[_0x7f6c('0x3f')](_['pick'](_0x5c4c43[_0x7f6c('0x36')],_0x785949[_0x7f6c('0x3f')]));if(_0x5c4c43[_0x7f6c('0x36')][_0x7f6c('0x40')]){_0x2d30f7[_0x7f6c('0x3e')]=_[_0x7f6c('0x42')](_0x2d30f7[_0x7f6c('0x3e')],{'$or':_[_0x7f6c('0x35')](_0x2d30f7[_0x7f6c('0x39')],function(_0x5adb5d){var _0x5b89e3={};_0x5b89e3[_0x5adb5d]={'$like':'%'+_0x5c4c43[_0x7f6c('0x36')][_0x7f6c('0x40')]+'%'};return _0x5b89e3;})});}_0x2d30f7=_[_0x7f6c('0x42')]({},_0x2d30f7,_0x5c4c43['options']);return _0xbb8888[_0x7f6c('0x130')](_0x2d30f7);}})['then'](function(_0x332851){if(_0x332851){_0x37b905=_0x332851[_0x7f6c('0x3b')];if(!_0x5c4c43[_0x7f6c('0x36')][_0x7f6c('0x5e')](_0x7f6c('0x56'))){_0x2d30f7[_0x7f6c('0x22')]=qs[_0x7f6c('0x22')](_0x5c4c43['query'][_0x7f6c('0x22')]);_0x2d30f7[_0x7f6c('0x24')]=qs['offset'](_0x5c4c43[_0x7f6c('0x36')][_0x7f6c('0x24')]);}return _0xbb8888['getAgents'](_0x2d30f7);}})[_0x7f6c('0x15')](function(_0x64a95f){if(_0x64a95f){return _0x64a95f?{'count':_0x37b905,'rows':_0x64a95f}:null;}})['then'](respondWithResult(_0x523008,null))[_0x7f6c('0x1d')](handleError(_0x523008,null));};