Built motion from commit 97153652.|2.6.26
[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 _0x8f18=['Chat\x20Website\x20with\x20id\x20%s\x20not\x20found','account','applications','orderBy','asc','list','List','contact','headers','threadId','closed','Writing\x20on\x20closed\x20interaction','externalUrl','ContactId','interaction','ChatInteraction','messageId','created','autoclose','close','unmanaged','ChatMessage','AttachmentId','UserId','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','queueId','queue','waitForTheAssignedQueue','startRouting','EventManager','offline','files','Sequelize','ValidationError','no\x20available\x20attributes','difference','send','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKeyOffline','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','MailAccount','findOrCreate','spread','readFileSync','server/files/templates/chatOfflineMessage.ejs','utf8','render','ChatOfflineMessage','fromString','mimetype','server','attachments','offline-chat','openNewInteraction','sequelize','transaction','Attachment','MailServerOut','CloudProvider','Smtp','forwardOffline','getSmtpOptions','sendMail','\x22%s\x22\x20<%s>','originalname','subjectOffline','toPairsIn','mapValues','email','Chat','MailAccountId','NotifyMailAccount','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','User','Owner','fullname','internal','Tag','Tags','color','tag','getProactiveActions','virtual','custom','License','increment','chatLicenseExceeded','ifTime','server/files/chat/iframe.ejs','origin','testWebsiteWithWildcard','remote','x-real-ip','connection','remoteAddress','alignment','verticalAlignment','labelText','textColor','backgroundColor','IntervalId','addApplications','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','priority','finally','getApplications','chatProactiveAction','addProactiveActions','ChatProactiveAction','getFields','false','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','emit','removeAgents','isArray','userChatWebsite:remove','getAgents','path','ejs','fs-extra','lodash','querystring','ioredis','jayson/promise','../../components/parsers/qs','api','../../errors/api','APIBadRequestError','APINotFoundError','handleError','APIConflictError','url','URL','../../mysqldb','defaults','redis','socket.io-emitter','./chatWebsite.socket','register','client','http','then','request\x20sent','debug','error','code','ChatWebsite,\x20%s,\x20%s','message','info','catch','status','end','json','undefined','limit','count','offset','set','Content-Range','update','destroy','get','UserProfileResource','sendStatus','stack','name','setUA','user-agent','getResult','customerIp','cf-connecting-ip','first','x-forwarded-for','split','firstName','lastName','x-real-port','referer','browser','version','format','%s\x20%s','unknown','device','model','vendor','type','stringify','index','Pause','mandatoryDispositionPause','map','ChatWebsite','key','query','keys','filters','intersection','fields','attributes','nolimit','order','sort','where','merge','VIRTUAL','filter','includeAll','include','rows','show','params','rawAttributes','length','find','create','testWildcardValidity','body','address','\x22\x20is\x20not\x20a\x20valid\x20website\x20domain','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','ChatWebsiteId','getDispositions','findOne','Disposition','options','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','hasOwnProperty','pick','removeAnswers','sitepic','file','filename','addAvatar','agentAvatar','addCustomerAvatar','customerAvatar','addSystemAvatar','systemAvatar','getLogo','join','root','server/files/images/logos/default_logo.svg','../../config/license/util','getLicense','isNil','server/files/images/logos/','download','server/files/images/avatars/default_avatar.png','existsSync','server/files/images/avatars/','getCustomerAvatar','server/files/images/avatars/customer_avatar.png','showCustomerAvatar','server/files/images/avatars/system_avatar.png','Interval','resolve','timezone','notify','from','From\x20is\x20mandatory','mapKey','isEmpty','Body\x20is\x20mandatory','CmContact','No\x20available\x20attributes','updatedAt','createdAt','CompanyId','ListId','includes','Contacts','DESC','ChatApplication','Applications','Intervals','interval'];(function(_0xf0ec6e,_0xa183d3){var _0x8bbc27=function(_0x39822b){while(--_0x39822b){_0xf0ec6e['push'](_0xf0ec6e['shift']());}};_0x8bbc27(++_0xa183d3);}(_0x8f18,0x1bf));var _0x88f1=function(_0x396b7d,_0x2470d2){_0x396b7d=_0x396b7d-0x0;var _0x339b7e=_0x8f18[_0x396b7d];return _0x339b7e;};'use strict';var Mustache=require('mustache');var util=require('util');var path=require(_0x88f1('0x0'));var ejs=require(_0x88f1('0x1'));var fs=require('fs');var fs_extra=require(_0x88f1('0x2'));var _=require(_0x88f1('0x3'));var querystring=require(_0x88f1('0x4'));var htmlToText=require('html-to-text');var Redis=require(_0x88f1('0x5'));var jayson=require(_0x88f1('0x6'));var qs=require(_0x88f1('0x7'));var logger=require('../../config/logger')(_0x88f1('0x8'));var config=require('../../config/environment');var APIBadRequestError=require(_0x88f1('0x9'))[_0x88f1('0xa')];var APINotFoundError=require(_0x88f1('0x9'))[_0x88f1('0xb')];var APIOutOfIntervalError=require(_0x88f1('0x9'))['APIOutOfIntervalError'];var APIHandleError=require(_0x88f1('0x9'))[_0x88f1('0xc')];var APIConflictError=require('../../errors/api')[_0x88f1('0xd')];var wildcardUtils=require('./helpers/wildcard-expressions');var URL=require(_0x88f1('0xe'))[_0x88f1('0xf')];var db=require(_0x88f1('0x10'))['db'];config['redis']=_[_0x88f1('0x11')](config[_0x88f1('0x12')],{'host':'localhost','port':0x18eb});var socket=require(_0x88f1('0x13'))(new Redis(config[_0x88f1('0x12')]));require(_0x88f1('0x14'))[_0x88f1('0x15')](socket);var client=jayson[_0x88f1('0x16')][_0x88f1('0x17')]({'port':0x232c});var client9002=jayson[_0x88f1('0x16')][_0x88f1('0x17')]({'port':0x232a});var client9003=jayson[_0x88f1('0x16')]['http']({'port':0x232b});var client9001=jayson['client'][_0x88f1('0x17')]({'port':0x2329});function respondWithRpcPromise(_0x2e4844,_0x4ef270,_0x2a88fa,_0x439503){return new Promise(function(_0x30620b,_0x2585cb){var _0x2b77b1=_0x439503||client;return _0x2b77b1['request'](_0x2e4844,_0x2a88fa)[_0x88f1('0x18')](function(_0x2998e0){logger['info']('ChatWebsite,\x20%s,\x20%s',_0x4ef270,_0x88f1('0x19'));logger[_0x88f1('0x1a')]('ChatWebsite,\x20%s,\x20%s,\x20%s',_0x4ef270,_0x88f1('0x19'),JSON['stringify'](_0x2998e0));if(_0x2998e0['error']){if(_0x2998e0[_0x88f1('0x1b')][_0x88f1('0x1c')]===0x1f4){logger[_0x88f1('0x1b')](_0x88f1('0x1d'),_0x4ef270,_0x2998e0[_0x88f1('0x1b')]['message']);return _0x2585cb(_0x2998e0['error'][_0x88f1('0x1e')]);}logger[_0x88f1('0x1b')](_0x88f1('0x1d'),_0x4ef270,_0x2998e0[_0x88f1('0x1b')][_0x88f1('0x1e')]);return _0x30620b(_0x2998e0[_0x88f1('0x1b')][_0x88f1('0x1e')]);}else{logger[_0x88f1('0x1f')](_0x88f1('0x1d'),_0x4ef270,_0x88f1('0x19'));_0x30620b(_0x2998e0['result'][_0x88f1('0x1e')]);}})[_0x88f1('0x20')](function(_0xe39fa2){logger['error'](_0x88f1('0x1d'),_0x4ef270,_0xe39fa2);_0x2585cb(_0xe39fa2);});});}function respondWithStatusCode(_0x108c36,_0x29d8cf){_0x29d8cf=_0x29d8cf||0xcc;return function(_0x410053){if(_0x410053){return _0x108c36['sendStatus'](_0x29d8cf);}return _0x108c36[_0x88f1('0x21')](_0x29d8cf)[_0x88f1('0x22')]();};}function respondWithResult(_0x34c301,_0x4fef23){_0x4fef23=_0x4fef23||0xc8;return function(_0xb57853){if(_0xb57853){return _0x34c301[_0x88f1('0x21')](_0x4fef23)[_0x88f1('0x23')](_0xb57853);}};}function respondWithFilteredResult(_0x4f4588,_0x255164){return function(_0x1becc5){if(_0x1becc5){var _0x4104af=typeof _0x255164['offset']===_0x88f1('0x24')&&typeof _0x255164[_0x88f1('0x25')]===_0x88f1('0x24');var _0x48826f=_0x1becc5['count'];var _0x4a7788=_0x4104af?0x0:_0x255164['offset'];var _0x468e58=_0x4104af?_0x1becc5[_0x88f1('0x26')]:_0x255164[_0x88f1('0x27')]+_0x255164[_0x88f1('0x25')];var _0x508364;if(_0x468e58>=_0x48826f){_0x468e58=_0x48826f;_0x508364=0xc8;}else{_0x508364=0xce;}_0x4f4588[_0x88f1('0x21')](_0x508364);return _0x4f4588[_0x88f1('0x28')](_0x88f1('0x29'),_0x4a7788+'-'+_0x468e58+'/'+_0x48826f)[_0x88f1('0x23')](_0x1becc5);}return null;};}function saveUpdates(_0x201d9c){return function(_0x174095){if(_0x174095){return _0x174095[_0x88f1('0x2a')](_0x201d9c)[_0x88f1('0x18')](function(_0x50d6d3){return _0x50d6d3;});}return null;};}function removeEntity(_0x1da391){return function(_0x518fcd){if(_0x518fcd){return _0x518fcd[_0x88f1('0x2b')]()[_0x88f1('0x18')](function(){var _0x834ffb=_0x518fcd[_0x88f1('0x2c')]({'plain':!![]});var _0x12a486='ChatWebsites';return db[_0x88f1('0x2d')]['destroy']({'where':{'type':_0x12a486,'resourceId':_0x834ffb['id']}})[_0x88f1('0x18')](function(){return _0x518fcd;});})[_0x88f1('0x18')](function(){_0x1da391[_0x88f1('0x21')](0xcc)[_0x88f1('0x22')]();});}};}function handleEntityNotFound(_0x8be1ed){return function(_0x314fda){if(!_0x314fda){_0x8be1ed[_0x88f1('0x2e')](0x194);}return _0x314fda;};}function handleError(_0x37ac45,_0x415c7d){_0x415c7d=_0x415c7d||0x1f4;return function(_0x2204f0){logger[_0x88f1('0x1b')](_0x2204f0[_0x88f1('0x2f')]);if(_0x2204f0[_0x88f1('0x30')]){delete _0x2204f0[_0x88f1('0x30')];}_0x37ac45[_0x88f1('0x21')](_0x415c7d)['send'](_0x2204f0);};}function createInteractionObject(_0x333d20,_0x35f449,_0x2f9756,_0x5e7fbf){var _0x477781=require('user-agent-parser');var _0x15ec85=new _0x477781();var _0x29838a=_0x15ec85[_0x88f1('0x31')](_0x2f9756[_0x88f1('0x32')])[_0x88f1('0x33')]();var _0x437510=_0x35f449[_0x88f1('0x34')];if(_0x2f9756[_0x88f1('0x35')]){_0x437510=_0x2f9756['cf-connecting-ip'];}else if(_0x2f9756['x-forwarded-for']){_0x437510=_[_0x88f1('0x36')](_0x2f9756[_0x88f1('0x37')][_0x88f1('0x38')](','));}return{'ContactId':_0x5e7fbf['id'],'ChatWebsiteId':_0x333d20,'from':(_0x5e7fbf[_0x88f1('0x39')]||'')+'\x20'+(_0x5e7fbf[_0x88f1('0x3a')]||''),'customerIp':_0x437510,'customerPort':_0x2f9756[_0x88f1('0x3b')]?_0x2f9756[_0x88f1('0x3b')]:null,'referer':_0x35f449[_0x88f1('0x3c')],'browserName':_0x29838a['browser'][_0x88f1('0x30')]&&_0x29838a[_0x88f1('0x3d')][_0x88f1('0x3e')]?util[_0x88f1('0x3f')](_0x88f1('0x40'),_0x29838a[_0x88f1('0x3d')][_0x88f1('0x30')],_0x29838a[_0x88f1('0x3d')][_0x88f1('0x3e')]):'unknown','browserVersion':_0x29838a[_0x88f1('0x3d')]['version']||_0x88f1('0x41'),'osName':util[_0x88f1('0x3f')](_0x88f1('0x40'),_0x29838a['os'][_0x88f1('0x30')],_0x29838a['os']['version']),'osVersion':_0x29838a['os'][_0x88f1('0x3e')],'deviceModel':_0x29838a[_0x88f1('0x42')][_0x88f1('0x43')]&&_0x29838a['device'][_0x88f1('0x44')]?util['format']('%s\x20%s\x20%s',_0x29838a[_0x88f1('0x42')][_0x88f1('0x43')],_0x29838a['device'][_0x88f1('0x44')],_0x29838a[_0x88f1('0x42')][_0x88f1('0x45')]):null,'deviceVendor':_0x29838a[_0x88f1('0x42')][_0x88f1('0x44')],'deviceType':_0x29838a[_0x88f1('0x42')]['type'],'formData':JSON[_0x88f1('0x46')](_0x35f449)};}exports[_0x88f1('0x47')]=function(_0xd94f9b,_0x539816){var _0x2603fa={'include':[{'model':db[_0x88f1('0x48')],'as':_0x88f1('0x49')}]},_0x51d0c5={},_0x3919ff={'count':0x0,'rows':[]};var _0x1c6a6a=_[_0x88f1('0x4a')](db[_0x88f1('0x4b')]['rawAttributes'],function(_0x2b4c73){return{'name':_0x2b4c73['fieldName'],'type':_0x2b4c73[_0x88f1('0x45')][_0x88f1('0x4c')]};});_0x51d0c5[_0x88f1('0x43')]=_[_0x88f1('0x4a')](_0x1c6a6a,_0x88f1('0x30'));_0x51d0c5[_0x88f1('0x4d')]=_[_0x88f1('0x4e')](_0xd94f9b[_0x88f1('0x4d')]);_0x51d0c5[_0x88f1('0x4f')]=_['intersection'](_0x51d0c5[_0x88f1('0x43')],_0x51d0c5['query']);_0x2603fa['attributes']=_[_0x88f1('0x50')](_0x51d0c5[_0x88f1('0x43')],qs[_0x88f1('0x51')](_0xd94f9b[_0x88f1('0x4d')][_0x88f1('0x51')]));_0x2603fa[_0x88f1('0x52')]=_0x2603fa[_0x88f1('0x52')]['length']?_0x2603fa[_0x88f1('0x52')]:_0x51d0c5[_0x88f1('0x43')];if(!_0xd94f9b[_0x88f1('0x4d')]['hasOwnProperty'](_0x88f1('0x53'))){_0x2603fa[_0x88f1('0x25')]=qs[_0x88f1('0x25')](_0xd94f9b[_0x88f1('0x4d')]['limit']);_0x2603fa[_0x88f1('0x27')]=qs[_0x88f1('0x27')](_0xd94f9b['query'][_0x88f1('0x27')]);}_0x2603fa[_0x88f1('0x54')]=qs[_0x88f1('0x55')](_0xd94f9b[_0x88f1('0x4d')][_0x88f1('0x55')]);_0x2603fa[_0x88f1('0x56')]=qs[_0x88f1('0x4f')](_['pick'](_0xd94f9b[_0x88f1('0x4d')],_0x51d0c5[_0x88f1('0x4f')]),_0x1c6a6a);if(_0xd94f9b['query']['filter']){_0x2603fa[_0x88f1('0x56')]=_[_0x88f1('0x57')](_0x2603fa[_0x88f1('0x56')],{'$or':_['map'](_0x1c6a6a,function(_0x1ae935){if(_0x1ae935[_0x88f1('0x45')]!==_0x88f1('0x58')){var _0x424ed1={};_0x424ed1[_0x1ae935[_0x88f1('0x30')]]={'$like':'%'+_0xd94f9b[_0x88f1('0x4d')][_0x88f1('0x59')]+'%'};return _0x424ed1;}})});}_0x2603fa=_[_0x88f1('0x57')]({},_0x2603fa,_0xd94f9b['options']);var _0x4394e6={'where':_0x2603fa[_0x88f1('0x56')]};return db[_0x88f1('0x4b')][_0x88f1('0x26')](_0x4394e6)[_0x88f1('0x18')](function(_0x324c07){_0x3919ff['count']=_0x324c07;if(_0xd94f9b[_0x88f1('0x4d')][_0x88f1('0x5a')]){_0x2603fa[_0x88f1('0x5b')]=[{'all':!![]}];}return db[_0x88f1('0x4b')]['findAll'](_0x2603fa);})[_0x88f1('0x18')](function(_0x1e924b){_0x3919ff[_0x88f1('0x5c')]=_0x1e924b;return _0x3919ff;})['then'](respondWithFilteredResult(_0x539816,_0x2603fa))['catch'](handleError(_0x539816,null));};exports[_0x88f1('0x5d')]=function(_0x149854,_0x3968ab){var _0x407087={'raw':![],'where':{'id':_0x149854[_0x88f1('0x5e')]['id']},'include':[{'model':db[_0x88f1('0x48')],'as':_0x88f1('0x49')}]},_0x5810ec={};_0x5810ec[_0x88f1('0x43')]=_[_0x88f1('0x4e')](db[_0x88f1('0x4b')][_0x88f1('0x5f')]);_0x5810ec[_0x88f1('0x4d')]=_['keys'](_0x149854[_0x88f1('0x4d')]);_0x5810ec[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x5810ec['model'],_0x5810ec['query']);_0x407087[_0x88f1('0x52')]=_[_0x88f1('0x50')](_0x5810ec[_0x88f1('0x43')],qs[_0x88f1('0x51')](_0x149854['query'][_0x88f1('0x51')]));_0x407087['attributes']=_0x407087[_0x88f1('0x52')][_0x88f1('0x60')]?_0x407087['attributes']:_0x5810ec[_0x88f1('0x43')];if(_0x149854[_0x88f1('0x4d')][_0x88f1('0x5a')]){_0x407087['include']=[{'all':!![]}];}_0x407087=_[_0x88f1('0x57')]({},_0x407087,_0x149854['options']);return db[_0x88f1('0x4b')][_0x88f1('0x61')](_0x407087)[_0x88f1('0x18')](handleEntityNotFound(_0x3968ab,null))[_0x88f1('0x18')](respondWithResult(_0x3968ab,null))[_0x88f1('0x20')](handleError(_0x3968ab,null));};exports[_0x88f1('0x62')]=function(_0x3b43c8,_0x2d0266){if(!wildcardUtils[_0x88f1('0x63')](_0x3b43c8[_0x88f1('0x64')]['address'])){return handleError(_0x2d0266,null)(new APIBadRequestError('\x22'+_0x3b43c8['body'][_0x88f1('0x65')]+_0x88f1('0x66')));}return db[_0x88f1('0x4b')][_0x88f1('0x62')](_0x3b43c8[_0x88f1('0x64')],{})[_0x88f1('0x18')](function(_0x506fc9){var _0x25a516=_0x3b43c8['user'][_0x88f1('0x2c')]({'plain':!![]});if(!_0x25a516)throw new Error(_0x88f1('0x67'));if(_0x25a516[_0x88f1('0x68')]===_0x88f1('0x69')){var _0x41a608=_0x506fc9[_0x88f1('0x2c')]({'plain':!![]});var _0x58eccf='ChatWebsites';return db[_0x88f1('0x6a')][_0x88f1('0x61')]({'where':{'name':_0x58eccf,'userProfileId':_0x25a516[_0x88f1('0x6b')]},'raw':!![]})['then'](function(_0x6e38f4){if(_0x6e38f4&&_0x6e38f4['autoAssociation']===0x0){return db[_0x88f1('0x2d')][_0x88f1('0x62')]({'name':_0x41a608[_0x88f1('0x30')],'resourceId':_0x41a608['id'],'type':_0x6e38f4[_0x88f1('0x30')],'sectionId':_0x6e38f4['id']},{})[_0x88f1('0x18')](function(){return _0x506fc9;});}else{return _0x506fc9;}})[_0x88f1('0x20')](function(_0x42fe43){logger['error'](_0x88f1('0x6c'),_0x42fe43);throw _0x42fe43;});}return _0x506fc9;})[_0x88f1('0x18')](respondWithResult(_0x2d0266,0xc9))[_0x88f1('0x20')](handleError(_0x2d0266,null));};exports['update']=function(_0x3543f9,_0x57f7d9){if(!wildcardUtils[_0x88f1('0x63')](_0x3543f9[_0x88f1('0x64')]['address'])){return handleError(_0x57f7d9,null)(new APIBadRequestError('\x22'+_0x3543f9['body'][_0x88f1('0x65')]+_0x88f1('0x66')));}if(_0x3543f9[_0x88f1('0x64')]['id']){delete _0x3543f9[_0x88f1('0x64')]['id'];}return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0x3543f9[_0x88f1('0x5e')]['id']},'include':[{'model':db['Pause'],'as':_0x88f1('0x49')}]})[_0x88f1('0x18')](handleEntityNotFound(_0x57f7d9,null))[_0x88f1('0x18')](saveUpdates(_0x3543f9[_0x88f1('0x64')],null))[_0x88f1('0x18')](respondWithResult(_0x57f7d9,null))['catch'](handleError(_0x57f7d9,null));};exports[_0x88f1('0x2b')]=function(_0x368881,_0x52ceed){return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x368881[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x52ceed,null))['then'](removeEntity(_0x52ceed,null))[_0x88f1('0x20')](handleError(_0x52ceed,null));};exports[_0x88f1('0x6d')]=function(_0x490b27,_0x5a637d){return db[_0x88f1('0x4b')][_0x88f1('0x6d')]()[_0x88f1('0x18')](respondWithResult(_0x5a637d,null))[_0x88f1('0x20')](handleError(_0x5a637d,null));};exports['addDisposition']=function(_0x4a0afb,_0x2184ac){if(_0x4a0afb[_0x88f1('0x64')]['id']){delete _0x4a0afb[_0x88f1('0x64')]['id'];}return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x4a0afb[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x2184ac,null))[_0x88f1('0x18')](function(_0x3395fa){if(_0x3395fa){_0x4a0afb[_0x88f1('0x64')][_0x88f1('0x6e')]=_0x3395fa['id'];return db['Disposition']['create'](_0x4a0afb['body']);}})[_0x88f1('0x18')](respondWithResult(_0x2184ac,null))[_0x88f1('0x20')](handleError(_0x2184ac,null));};exports[_0x88f1('0x6f')]=function(_0x4afc43,_0x140495){var _0x3007b5={'raw':![],'where':{}};var _0x12420a={};var _0x171225={'count':0x0,'rows':[]};return db['ChatWebsite'][_0x88f1('0x70')]({'where':{'id':_0x4afc43[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x140495,null))[_0x88f1('0x18')](function(_0x1be68c){if(_0x1be68c){_0x12420a[_0x88f1('0x43')]=_['keys'](db[_0x88f1('0x71')][_0x88f1('0x5f')]);_0x12420a[_0x88f1('0x4d')]=_[_0x88f1('0x4e')](_0x4afc43[_0x88f1('0x4d')]);_0x12420a[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x12420a[_0x88f1('0x43')],_0x12420a[_0x88f1('0x4d')]);_0x3007b5[_0x88f1('0x52')]=_[_0x88f1('0x50')](_0x12420a['model'],qs[_0x88f1('0x51')](_0x4afc43[_0x88f1('0x4d')]['fields']));_0x3007b5[_0x88f1('0x52')]=_0x3007b5['attributes']['length']?_0x3007b5[_0x88f1('0x52')]:_0x12420a[_0x88f1('0x43')];if(!_0x4afc43[_0x88f1('0x4d')]['hasOwnProperty'](_0x88f1('0x53'))){_0x3007b5[_0x88f1('0x25')]=qs['limit'](_0x4afc43[_0x88f1('0x4d')][_0x88f1('0x25')]);_0x3007b5[_0x88f1('0x27')]=qs[_0x88f1('0x27')](_0x4afc43[_0x88f1('0x4d')][_0x88f1('0x27')]);}_0x3007b5[_0x88f1('0x54')]=qs[_0x88f1('0x55')](_0x4afc43[_0x88f1('0x4d')][_0x88f1('0x55')]);_0x3007b5['where']=qs[_0x88f1('0x4f')](_['pick'](_0x4afc43[_0x88f1('0x4d')],_0x12420a[_0x88f1('0x4f')]));_0x3007b5[_0x88f1('0x56')]['ChatWebsiteId']=_0x1be68c['id'];if(_0x4afc43['query']['filter']){_0x3007b5[_0x88f1('0x56')]=_[_0x88f1('0x57')](_0x3007b5[_0x88f1('0x56')],{'$or':_[_0x88f1('0x4a')](_0x3007b5['attributes'],function(_0xee075){var _0x4223f9={};_0x4223f9[_0xee075]={'$like':'%'+_0x4afc43[_0x88f1('0x4d')][_0x88f1('0x59')]+'%'};return _0x4223f9;})});}_0x3007b5=_[_0x88f1('0x57')]({},_0x3007b5,_0x4afc43[_0x88f1('0x72')]);return db[_0x88f1('0x71')][_0x88f1('0x26')]({'where':_0x3007b5[_0x88f1('0x56')]})['then'](function(_0x535a5e){_0x171225[_0x88f1('0x26')]=_0x535a5e;if(_0x4afc43[_0x88f1('0x4d')][_0x88f1('0x5a')]){_0x3007b5[_0x88f1('0x5b')]=[{'all':!![]}];}return db['Disposition'][_0x88f1('0x73')](_0x3007b5);})['then'](function(_0x84e180){_0x171225[_0x88f1('0x5c')]=_0x84e180;return _0x171225;});}})[_0x88f1('0x18')](respondWithFilteredResult(_0x140495,_0x3007b5))[_0x88f1('0x20')](handleError(_0x140495,null));};exports[_0x88f1('0x74')]=function(_0x1ffa9b,_0x14a855){return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0x1ffa9b[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x14a855,null))[_0x88f1('0x18')](function(_0x3c83dd){if(_0x3c83dd){return _0x3c83dd[_0x88f1('0x74')](_0x1ffa9b[_0x88f1('0x4d')][_0x88f1('0x75')]);}})[_0x88f1('0x18')](respondWithStatusCode(_0x14a855,null))[_0x88f1('0x20')](handleError(_0x14a855,null));};exports[_0x88f1('0x76')]=function(_0x384341,_0x5e62e6){if(_0x384341[_0x88f1('0x64')]['id']){delete _0x384341[_0x88f1('0x64')]['id'];}return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0x384341[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x5e62e6,null))[_0x88f1('0x18')](function(_0x3e37f4){if(_0x3e37f4){_0x384341['body'][_0x88f1('0x6e')]=_0x3e37f4['id'];return db[_0x88f1('0x77')]['create'](_0x384341[_0x88f1('0x64')]);}})[_0x88f1('0x18')](respondWithResult(_0x5e62e6,null))[_0x88f1('0x20')](handleError(_0x5e62e6,null));};exports[_0x88f1('0x78')]=function(_0x416eb5,_0x156105){var _0x4b420c={'raw':![],'where':{}};var _0x83c679={};var _0x3d21ed={'count':0x0,'rows':[]};return db[_0x88f1('0x4b')][_0x88f1('0x70')]({'where':{'id':_0x416eb5[_0x88f1('0x5e')]['id']}})['then'](handleEntityNotFound(_0x156105,null))['then'](function(_0x37fdec){if(_0x37fdec){_0x83c679[_0x88f1('0x43')]=_[_0x88f1('0x4e')](db[_0x88f1('0x77')][_0x88f1('0x5f')]);_0x83c679['query']=_[_0x88f1('0x4e')](_0x416eb5['query']);_0x83c679[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x83c679[_0x88f1('0x43')],_0x83c679[_0x88f1('0x4d')]);_0x4b420c[_0x88f1('0x52')]=_['intersection'](_0x83c679[_0x88f1('0x43')],qs[_0x88f1('0x51')](_0x416eb5[_0x88f1('0x4d')]['fields']));_0x4b420c[_0x88f1('0x52')]=_0x4b420c[_0x88f1('0x52')]['length']?_0x4b420c[_0x88f1('0x52')]:_0x83c679['model'];if(!_0x416eb5[_0x88f1('0x4d')][_0x88f1('0x79')](_0x88f1('0x53'))){_0x4b420c[_0x88f1('0x25')]=qs[_0x88f1('0x25')](_0x416eb5[_0x88f1('0x4d')][_0x88f1('0x25')]);_0x4b420c[_0x88f1('0x27')]=qs[_0x88f1('0x27')](_0x416eb5[_0x88f1('0x4d')]['offset']);}_0x4b420c[_0x88f1('0x54')]=qs['sort'](_0x416eb5[_0x88f1('0x4d')][_0x88f1('0x55')]);_0x4b420c[_0x88f1('0x56')]=qs['filters'](_[_0x88f1('0x7a')](_0x416eb5[_0x88f1('0x4d')],_0x83c679[_0x88f1('0x4f')]));_0x4b420c['where']['ChatWebsiteId']=_0x37fdec['id'];if(_0x416eb5[_0x88f1('0x4d')][_0x88f1('0x59')]){_0x4b420c[_0x88f1('0x56')]=_[_0x88f1('0x57')](_0x4b420c['where'],{'$or':_[_0x88f1('0x4a')](_0x4b420c[_0x88f1('0x52')],function(_0x541045){var _0x39b36d={};_0x39b36d[_0x541045]={'$like':'%'+_0x416eb5['query']['filter']+'%'};return _0x39b36d;})});}_0x4b420c=_['merge']({},_0x4b420c,_0x416eb5[_0x88f1('0x72')]);return db['CannedAnswer'][_0x88f1('0x26')]({'where':_0x4b420c[_0x88f1('0x56')]})[_0x88f1('0x18')](function(_0x208305){_0x3d21ed['count']=_0x208305;if(_0x416eb5[_0x88f1('0x4d')]['includeAll']){_0x4b420c[_0x88f1('0x5b')]=[{'all':!![]}];}return db[_0x88f1('0x77')][_0x88f1('0x73')](_0x4b420c);})[_0x88f1('0x18')](function(_0x59b4cb){_0x3d21ed[_0x88f1('0x5c')]=_0x59b4cb;return _0x3d21ed;});}})[_0x88f1('0x18')](respondWithFilteredResult(_0x156105,_0x4b420c))[_0x88f1('0x20')](handleError(_0x156105,null));};exports[_0x88f1('0x7b')]=function(_0xc23b5f,_0x4c0f24){return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0xc23b5f['params']['id']}})['then'](handleEntityNotFound(_0x4c0f24,null))[_0x88f1('0x18')](function(_0x833c08){if(_0x833c08){return _0x833c08[_0x88f1('0x7b')](_0xc23b5f[_0x88f1('0x4d')]['ids']);}})[_0x88f1('0x18')](respondWithStatusCode(_0x4c0f24,null))[_0x88f1('0x20')](handleError(_0x4c0f24,null));};exports['addLogo']=function(_0x152342,_0x187896){_0x152342[_0x88f1('0x64')][_0x88f1('0x7c')]=_0x152342[_0x88f1('0x7d')][_0x88f1('0x7e')];return db['ChatWebsite'][_0x88f1('0x61')]({'where':{'id':_0x152342[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x187896,null))[_0x88f1('0x18')](saveUpdates(_0x152342['body'],null))[_0x88f1('0x18')](respondWithResult(_0x187896,null))['catch'](handleError(_0x187896,null));};exports[_0x88f1('0x7f')]=function(_0x4c3e68,_0x19fedb){_0x4c3e68[_0x88f1('0x64')][_0x88f1('0x80')]=_0x4c3e68[_0x88f1('0x7d')][_0x88f1('0x7e')];return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x4c3e68['params']['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x19fedb,null))[_0x88f1('0x18')](saveUpdates(_0x4c3e68[_0x88f1('0x64')],null))['then'](respondWithResult(_0x19fedb,null))[_0x88f1('0x20')](handleError(_0x19fedb,null));};exports[_0x88f1('0x81')]=function(_0x216e40,_0x33ebfb){_0x216e40['body'][_0x88f1('0x82')]=_0x216e40[_0x88f1('0x7d')][_0x88f1('0x7e')];return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x216e40['params']['id']}})['then'](handleEntityNotFound(_0x33ebfb,null))[_0x88f1('0x18')](saveUpdates(_0x216e40[_0x88f1('0x64')],null))['then'](respondWithResult(_0x33ebfb,null))[_0x88f1('0x20')](handleError(_0x33ebfb,null));};exports[_0x88f1('0x83')]=function(_0x2d2e63,_0x11fc50){_0x2d2e63[_0x88f1('0x64')][_0x88f1('0x84')]=_0x2d2e63[_0x88f1('0x7d')][_0x88f1('0x7e')];return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x2d2e63[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x11fc50,null))['then'](saveUpdates(_0x2d2e63[_0x88f1('0x64')],null))[_0x88f1('0x18')](respondWithResult(_0x11fc50,null))[_0x88f1('0x20')](handleError(_0x11fc50,null));};exports[_0x88f1('0x85')]=function(_0xc93dc6,_0x38ce71){var _0x51fc75=path[_0x88f1('0x86')](config[_0x88f1('0x87')],_0x88f1('0x88'));var _0x37bcf9={'where':{'id':_0xc93dc6[_0x88f1('0x5e')]['id']},'attributes':['id',_0x88f1('0x7c')],'raw':!![]};var _0x1fc680=![];return require(_0x88f1('0x89'))[_0x88f1('0x8a')]()[_0x88f1('0x18')](function(_0x51bab9){if(_0x51bab9){_0x1fc680=_0x51bab9['custom'];}})[_0x88f1('0x18')](function(){return db['ChatWebsite'][_0x88f1('0x61')](_0x37bcf9);})['then'](handleEntityNotFound(_0x38ce71,null))['then'](function(_0x3ede12){if(_0x3ede12){if(!_[_0x88f1('0x8b')](_0x3ede12[_0x88f1('0x7c')])){if(fs['existsSync'](path[_0x88f1('0x86')](config['root'],_0x88f1('0x8c'),_0x3ede12[_0x88f1('0x7c')]))&&_0x1fc680){_0x51fc75=path[_0x88f1('0x86')](config['root'],_0x88f1('0x8c'),_0x3ede12[_0x88f1('0x7c')]);}}return _0x38ce71[_0x88f1('0x8d')](_0x51fc75);}})[_0x88f1('0x20')](handleError(_0x38ce71,null));};exports['getAvatar']=function(_0xf89d80,_0x88e3f9){var _0x134d80=path[_0x88f1('0x86')](config['root'],_0x88f1('0x8e'));var _0x5bc0a4={'where':{'id':_0xf89d80['params']['id']},'attributes':['id','agentAvatar'],'raw':!![]};return db[_0x88f1('0x4b')][_0x88f1('0x61')](_0x5bc0a4)['then'](handleEntityNotFound(_0x88e3f9,null))[_0x88f1('0x18')](function(_0x5c526d){if(_0x5c526d){if(!_[_0x88f1('0x8b')](_0x5c526d[_0x88f1('0x80')])){if(fs[_0x88f1('0x8f')](path[_0x88f1('0x86')](config[_0x88f1('0x87')],'server/files/images/avatars/',_0x5c526d[_0x88f1('0x80')]))){_0x134d80=path['join'](config[_0x88f1('0x87')],_0x88f1('0x90'),_0x5c526d['agentAvatar']);}}return _0x88e3f9[_0x88f1('0x8d')](_0x134d80);}})[_0x88f1('0x20')](handleError(_0x88e3f9,null));};exports[_0x88f1('0x91')]=function(_0x3bb392,_0x51dccd){var _0x3f15db=path['join'](config['root'],_0x88f1('0x92'));var _0x476df9={'where':{'id':_0x3bb392[_0x88f1('0x5e')]['id']},'attributes':['id','customerAvatar',_0x88f1('0x93')],'raw':!![]};return db[_0x88f1('0x4b')]['find'](_0x476df9)[_0x88f1('0x18')](handleEntityNotFound(_0x51dccd,null))[_0x88f1('0x18')](function(_0x52b198){if(_0x52b198){if(!_[_0x88f1('0x8b')](_0x52b198[_0x88f1('0x82')])){if(fs[_0x88f1('0x8f')](path[_0x88f1('0x86')](config[_0x88f1('0x87')],'server/files/images/avatars/',_0x52b198['customerAvatar']))&&_0x52b198[_0x88f1('0x93')]){_0x3f15db=path['join'](config['root'],_0x88f1('0x90'),_0x52b198[_0x88f1('0x82')]);}}return _0x51dccd['download'](_0x3f15db);}})['catch'](handleError(_0x51dccd,null));};exports['getSystemAvatar']=function(_0x4ef1b4,_0x56cfe3){var _0x589f3d=path['join'](config[_0x88f1('0x87')],_0x88f1('0x94'));var _0x7626e7={'where':{'id':_0x4ef1b4[_0x88f1('0x5e')]['id']},'attributes':['id','systemAvatar'],'raw':!![]};return db[_0x88f1('0x4b')][_0x88f1('0x61')](_0x7626e7)[_0x88f1('0x18')](handleEntityNotFound(_0x56cfe3,null))['then'](function(_0x17d603){if(_0x17d603){if(!_['isNil'](_0x17d603[_0x88f1('0x84')])){if(fs['existsSync'](path[_0x88f1('0x86')](config[_0x88f1('0x87')],_0x88f1('0x90'),_0x17d603[_0x88f1('0x84')]))){_0x589f3d=path[_0x88f1('0x86')](config['root'],_0x88f1('0x90'),_0x17d603[_0x88f1('0x84')]);}}return _0x56cfe3['download'](_0x589f3d);}})[_0x88f1('0x20')](handleError(_0x56cfe3,null));};function checkWebsiteInterval(_0x3bbd63){var _0x25bd6a=_0x3bbd63[_0x88f1('0x95')];if(!_0x25bd6a){return Promise[_0x88f1('0x96')](_0x3bbd63);}var _0x126951=_0x3bbd63[_0x88f1('0x97')]||undefined;return _0x25bd6a['ifTime'](_0x126951)['then'](function(_0x54e927){if(!_0x54e927){throw new APIOutOfIntervalError();}return _0x3bbd63;});}exports[_0x88f1('0x98')]=function(_0x5c623c,_0x2f050b){var _0x2c63fe={'body':_0x5c623c[_0x88f1('0x64')],'channel':'chat'};var _0x2d695b=[];var _0x2c2454=[];var _0x37a626={};var _0x11b0b1=![];if(_0x5c623c[_0x88f1('0x64')]['id']){delete _0x5c623c[_0x88f1('0x64')]['id'];}if(_[_0x88f1('0x8b')](_0x5c623c[_0x88f1('0x64')][_0x88f1('0x99')])){throw new APIBadRequestError(_0x88f1('0x9a'));}if(_[_0x88f1('0x8b')](_0x5c623c[_0x88f1('0x64')][_0x88f1('0x9b')])){throw new APIBadRequestError('MapKey\x20is\x20mandatory');}if(_[_0x88f1('0x9c')](_0x5c623c[_0x88f1('0x64')][_0x88f1('0x64')])){throw new APIBadRequestError(_0x88f1('0x9d'));}var _0x399009=_0x5c623c[_0x88f1('0x64')]['customerIp']&&_0x5c623c[_0x88f1('0x64')][_0x88f1('0x3c')];return db[_0x88f1('0x9e')][_0x88f1('0x6d')]()[_0x88f1('0x18')](function(_0x31881f){if(!_0x31881f){throw new Error(_0x88f1('0x9f'));}_0x2d695b=Object[_0x88f1('0x4e')](_0x31881f)[_0x88f1('0x59')](function(_0x1c9278){return!['createdAt',_0x88f1('0xa0')]['includes'](_0x1c9278);});_0x2c2454=Object[_0x88f1('0x4e')](_0x31881f)[_0x88f1('0x59')](function(_0x193b29){return![_0x88f1('0xa1'),_0x88f1('0xa0'),_0x88f1('0xa2'),_0x88f1('0xa3')][_0x88f1('0xa4')](_0x193b29);});if(!_[_0x88f1('0xa4')](_0x2c2454,_0x5c623c[_0x88f1('0x64')][_0x88f1('0x9b')])){throw new APIBadRequestError('Invalid\x20MapKey\x20parameter.\x20Allowed\x20values:\x20'+_0x2c2454[_0x88f1('0x86')](',\x20'));}_0x37a626[_0x5c623c[_0x88f1('0x64')][_0x88f1('0x9b')]]=_0x5c623c[_0x88f1('0x64')][_0x88f1('0x99')];})[_0x88f1('0x18')](function(){return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x5c623c['params']['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x88f1('0x9e')],'as':_0x88f1('0xa5'),'where':_0x37a626,'limit':0x1,'order':[[_0x88f1('0xa0'),_0x88f1('0xa6')]]}]},{'model':db[_0x88f1('0xa7')],'as':_0x88f1('0xa8')},{'model':db[_0x88f1('0x95')],'as':_0x88f1('0x95'),'include':[{'model':db[_0x88f1('0x95')],'as':_0x88f1('0xa9'),'attributes':['id',_0x88f1('0xaa')],'raw':!![]}]}]});})[_0x88f1('0x18')](function(_0x1fe534){if(!_0x1fe534){throw new APINotFoundError(util['format'](_0x88f1('0xab'),_0x5c623c['params']['id']));}if(_0x399009){return checkWebsiteInterval(_0x1fe534);}return _0x1fe534;})[_0x88f1('0x18')](function(_0x11d7b9){_0x2c63fe[_0x88f1('0xac')]=_0x11d7b9;_0x2c63fe[_0x88f1('0xad')]=_[_0x88f1('0xae')](_0x11d7b9[_0x88f1('0xa8')],['priority'],[_0x88f1('0xaf')]);if(_0x2c63fe[_0x88f1('0xac')][_0x88f1('0xa8')]){delete _0x2c63fe['account'][_0x88f1('0xa8')];}_0x2c63fe[_0x88f1('0xb0')]=_0x11d7b9[_0x88f1('0xb1')]||{'id':_0x11d7b9['ListId']};if(_0x2c63fe[_0x88f1('0xb0')]&&_0x2c63fe[_0x88f1('0xb0')]['Contacts'][_0x88f1('0x60')]){return _0x2c63fe[_0x88f1('0xb0')]['Contacts'][0x0];}var _0x36c2f6=_[_0x88f1('0x11')](_0x5c623c['body'],{'firstName':_0x5c623c[_0x88f1('0x64')]['from'],'ListId':_0x11d7b9['ListId']});_0x36c2f6[_0x5c623c[_0x88f1('0x64')][_0x88f1('0x9b')]]=_0x5c623c[_0x88f1('0x64')][_0x88f1('0x99')];return db[_0x88f1('0x9e')][_0x88f1('0x62')](_0x36c2f6,{'fields':_0x2d695b,'raw':!![]});})[_0x88f1('0x18')](function(_0x350c6a){_0x2c63fe[_0x88f1('0xb2')]=_0x350c6a;var _0xc425fa=createInteractionObject(_0x5c623c[_0x88f1('0x5e')]['id'],_0x5c623c['body'],_0x5c623c[_0x88f1('0xb3')],_0x350c6a);var _0x4da6a5={'ChatWebsiteId':_0x5c623c[_0x88f1('0x5e')]['id']};if(_0x5c623c[_0x88f1('0x64')][_0x88f1('0xb4')]){_0x4da6a5[_0x88f1('0xb4')]=_0x5c623c['body'][_0x88f1('0xb4')];_0x4da6a5[_0x88f1('0xb5')]=![];return db['ChatInteraction'][_0x88f1('0x61')]({'where':_0x4da6a5})[_0x88f1('0x18')](function(_0x1e1ae0){var _0x40de2f=_0x5c623c[_0x88f1('0x64')][_0x88f1('0x34')]&&_0x5c623c[_0x88f1('0x64')]['referer'];if(_0x1e1ae0){_0x11b0b1=!![];return _0x1e1ae0;}else if(!_0x40de2f&&_0x1e1ae0&&_0x1e1ae0[_0x88f1('0xb5')]){throw new APIConflictError(_0x88f1('0xb6'));}_0xc425fa[_0x88f1('0xb4')]=_0x5c623c['body'][_0x88f1('0xb4')];_0xc425fa[_0x88f1('0xb7')]=_0x5c623c[_0x88f1('0x64')]['externalUrl'];return db['ChatInteraction']['create'](_0xc425fa);});}_0x4da6a5[_0x88f1('0xb8')]=_0x350c6a['id'];if(_0x5c623c[_0x88f1('0x64')][_0x88f1('0xb9')]&&_0x5c623c[_0x88f1('0x64')]['interaction']['id']){_0x4da6a5['id']=_0x5c623c['body'][_0x88f1('0xb9')]['id'];return db[_0x88f1('0xba')][_0x88f1('0x61')]({'where':_0x4da6a5})[_0x88f1('0x18')](function(_0x3a80d6){var _0x217508=_0x5c623c[_0x88f1('0x64')]['customerIp']&&_0x5c623c['body'][_0x88f1('0x3c')];if(!_0x217508&&_0x3a80d6&&_0x3a80d6['closed']){throw new APIConflictError(_0x88f1('0xb6'));}else if(_0x3a80d6){_0x11b0b1=!![];return _0x3a80d6;}else{return db[_0x88f1('0xba')][_0x88f1('0x62')](_0xc425fa);}});}return db['ChatInteraction'][_0x88f1('0x62')](_0xc425fa);})[_0x88f1('0x18')](function(_0x5a4958){if(!_0x11b0b1){return _0x5a4958;}var _0x54cced={'from':(_0x2c63fe[_0x88f1('0xb2')][_0x88f1('0x39')]||'')+'\x20'+(_0x2c63fe['contact'][_0x88f1('0x3a')]||'')};if(_0x5c623c[_0x88f1('0x64')][_0x88f1('0xb4')]&&_0x5c623c[_0x88f1('0x64')][_0x88f1('0xbb')]&&_0x5c623c['body'][_0x88f1('0xb4')]!=_0x5c623c[_0x88f1('0x64')][_0x88f1('0xbb')]){_0x54cced['threadId']=_0x5c623c[_0x88f1('0x64')][_0x88f1('0xbb')];}return _0x5a4958[_0x88f1('0x2a')](_0x54cced);})['then'](function(_0x5d0f0f){_0x2c63fe[_0x88f1('0xb9')]=_0x5d0f0f[_0x88f1('0x2c')]({'plain':!![]});_0x2c63fe[_0x88f1('0xb9')][_0x88f1('0xbc')]=!_0x11b0b1;if(_0x2c63fe[_0x88f1('0xb9')][_0x88f1('0xbc')]){if(_0x2c63fe[_0x88f1('0xac')][_0x88f1('0xbd')]){_0x2c63fe[_0x88f1('0xad')]['push']({'id':0x0,'priority':_0x2c63fe[_0x88f1('0xad')][_0x88f1('0x60')]+0x1,'app':_0x88f1('0xbe'),'appdata':_0x88f1('0xbf'),'interval':'*,*,*,*'});}}return db[_0x88f1('0xc0')][_0x88f1('0x62')]({'body':_0x5c623c[_0x88f1('0x64')][_0x88f1('0x64')],'ChatWebsiteId':_0x5c623c[_0x88f1('0x5e')]['id'],'ChatInteractionId':_0x5d0f0f['id'],'direction':'in','ContactId':_0x2c63fe[_0x88f1('0xb2')]['id'],'AttachmentId':_0x5c623c[_0x88f1('0x64')][_0x88f1('0xc1')]});})[_0x88f1('0x18')](function(_0x4a86a8){_0x2c63fe[_0x88f1('0x1e')]=_0x4a86a8;if(!_0x2c63fe[_0x88f1('0xb9')][_0x88f1('0xc2')]){return;}return db['User'][_0x88f1('0x61')]({'attributes':['id',_0x88f1('0x30')],'where':{'id':_0x2c63fe[_0x88f1('0xb9')][_0x88f1('0xc2')]}});})[_0x88f1('0x18')](function(_0x38cc73){if(_0x38cc73){_0x2c63fe[_0x88f1('0xad')][_0x88f1('0xc3')]({'id':0x0,'priority':0x0,'app':_0x88f1('0xc4'),'appdata':_0x38cc73[_0x88f1('0x30')]+','+(_0x2c63fe[_0x88f1('0xac')][_0x88f1('0xc5')]||0xa),'interval':_0x88f1('0xc6')});_0x2c63fe[_0x88f1('0xc7')]=!![];}if(!_0x2c63fe[_0x88f1('0xb9')][_0x88f1('0xc8')]){return;}return db['ChatQueue']['find']({'attributes':['id',_0x88f1('0x30')],'where':{'id':_0x2c63fe[_0x88f1('0xb9')][_0x88f1('0xc8')]}});})[_0x88f1('0x18')](function(_0x5acdbe){if(_0x5acdbe){_0x2c63fe[_0x88f1('0xad')][_0x88f1('0xc3')]({'id':0x0,'priority':0x1,'app':_0x88f1('0xc9'),'appdata':_0x5acdbe['name']+','+(_0x2c63fe[_0x88f1('0xac')][_0x88f1('0xca')]||0x12c),'interval':'*,*,*,*'});}return respondWithRpcPromise('Start',_0x88f1('0xcb'),_0x2c63fe);})[_0x88f1('0x18')](function(_0x3a7391){respondWithRpcPromise('EventManager',_0x88f1('0xcc'),{'event':_0x88f1('0x98'),'message':_0x3a7391},client9002);return _0x3a7391;})[_0x88f1('0x18')](respondWithResult(_0x2f050b,null))['catch'](APIHandleError(_0x2f050b));};exports[_0x88f1('0xcd')]=function(_0x31a00d,_0x159afc){var _0x4a20e7,_0x4442b3,_0x3be769;var _0x92f83f=[];var _0x126ef3={};var _0x16d55f=_0x31a00d[_0x88f1('0xce')]||[];var _0x401f93=[];var _0x14c171;return db[_0x88f1('0x9e')][_0x88f1('0x6d')]()['then'](function(_0x15d214){if(!_0x15d214){throw new db[(_0x88f1('0xcf'))][(_0x88f1('0xd0'))](_0x88f1('0xd1'));}_0x92f83f=_[_0x88f1('0xd2')](_[_0x88f1('0x4e')](_0x15d214),['createdAt',_0x88f1('0xa0'),'CompanyId',_0x88f1('0xa3')]);if(_0x31a00d[_0x88f1('0x64')]['id']){delete _0x31a00d['body']['id'];}if(_[_0x88f1('0x8b')](_0x31a00d[_0x88f1('0x64')][_0x88f1('0x99')])){throw _0x159afc[_0x88f1('0x21')](0x1f4)[_0x88f1('0xd3')](new db[(_0x88f1('0xcf'))][(_0x88f1('0xd0'))](_0x88f1('0xd4')));}if(_[_0x88f1('0x8b')](_0x31a00d[_0x88f1('0x64')][_0x88f1('0x64')])||_0x31a00d[_0x88f1('0x64')]['body']===''){throw _0x159afc['status'](0x1f4)[_0x88f1('0xd3')](new db[(_0x88f1('0xcf'))][(_0x88f1('0xd0'))](_0x88f1('0xd5')));}if(_[_0x88f1('0x8b')](_0x31a00d[_0x88f1('0x64')]['mapKeyOffline'])){throw _0x159afc[_0x88f1('0x21')](0x1f4)[_0x88f1('0xd3')](new db['Sequelize'][(_0x88f1('0xd0'))](_0x88f1('0xd6')+_0x92f83f));}if(!_[_0x88f1('0xa4')](_0x92f83f,_0x31a00d[_0x88f1('0x64')][_0x88f1('0xd7')])){throw _0x159afc[_0x88f1('0x21')](0x1f4)[_0x88f1('0xd3')](new db[(_0x88f1('0xcf'))][(_0x88f1('0xd0'))](_0x88f1('0xd8')+_0x92f83f));}_0x126ef3[_0x31a00d[_0x88f1('0x64')][_0x88f1('0xd7')]]=_0x31a00d[_0x88f1('0x64')][_0x88f1('0x99')];})['then'](function(){return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0x31a00d['params']['id']},'include':[{'model':db[_0x88f1('0xd9')],'as':'List'},{'model':db[_0x88f1('0xda')],'as':_0x88f1('0xda')}]});})[_0x88f1('0x18')](handleEntityNotFound(_0x159afc,null))[_0x88f1('0x18')](function(_0x1e68c8){if(_0x1e68c8&&_0x1e68c8[_0x88f1('0xb1')]){_0x4442b3=_0x1e68c8;var _0x170707=_[_0x88f1('0x11')](_0x31a00d['body'],{'firstName':_0x31a00d['body'][_0x88f1('0x99')],'phone':_0x31a00d[_0x88f1('0x64')][_0x88f1('0x99')],'ListId':_0x1e68c8['ListId']});_0x170707[_0x31a00d[_0x88f1('0x64')][_0x88f1('0xd7')]]=_0x31a00d[_0x88f1('0x64')]['from'];return db[_0x88f1('0x9e')][_0x88f1('0xdb')]({'where':_0x126ef3,'defaults':_0x170707});}})[_0x88f1('0xdc')](function(_0x1c4d33){if(_0x1c4d33){_0x3be769=_0x1c4d33;var _0x5c8f40=fs[_0x88f1('0xdd')](path[_0x88f1('0x86')](config[_0x88f1('0x87')],_0x88f1('0xde')),_0x88f1('0xdf'));var _0x1f2160=ejs[_0x88f1('0xe0')](_0x5c8f40,{'body':_['toPairs'](_0x31a00d[_0x88f1('0x64')][_0x88f1('0x64')]),'bodyTitle':_0x4442b3['offlineMessageBody']});return db[_0x88f1('0xe1')][_0x88f1('0x62')]({'body':_0x1f2160,'plainBody':htmlToText[_0x88f1('0xe2')](_0x1f2160),'ContactId':_0x1c4d33['id'],'ChatWebsiteId':_0x4442b3['id']});}})[_0x88f1('0x18')](function(_0x13e8a0){_0x14c171=_0x13e8a0;if(_0x16d55f[_0x88f1('0x60')]){var _0x20bbdd=_0x16d55f[_0x88f1('0x4a')](function(_0x5707e7){return{'name':_0x5707e7['originalname'],'basename':_0x5707e7[_0x88f1('0x7e')],'type':_0x5707e7[_0x88f1('0xe3')],'ChatOfflineMessageId':_0x13e8a0['id']};});_0x401f93=_0x20bbdd[_0x88f1('0x4a')](_0x40a5a1=>{var _0x5c3f9e={'filename':_0x40a5a1[_0x88f1('0x30')],'path':path['join'](config[_0x88f1('0x87')],_0x88f1('0xe4'),_0x88f1('0xce'),_0x88f1('0xe5'),_0x88f1('0xe6'),_0x40a5a1['basename'])};return _0x5c3f9e;});if(!_0x4442b3[_0x88f1('0xe7')]){return db[_0x88f1('0xe8')][_0x88f1('0xe9')](function(_0x48a873){return db[_0x88f1('0xea')]['bulkCreate'](_0x20bbdd,{'transaction':_0x48a873});});}}})[_0x88f1('0x18')](function(){if(_0x14c171){_0x4a20e7=_0x14c171;return db[_0x88f1('0xda')][_0x88f1('0x70')]({'where':{'service':!![]},'include':[{'model':db[_0x88f1('0xeb')],'as':'Smtp','raw':!![],'include':[{'model':db['CloudProvider'],'as':_0x88f1('0xec'),'raw':!![]}]}]});}})['then'](function(_0x5eff5f){if(_0x5eff5f&&_0x5eff5f[_0x88f1('0xed')]&&_0x4442b3[_0x88f1('0xee')]&&_0x4442b3['forwardOfflineAddress']){var _0x1a6ceb=_0x5eff5f[_0x88f1('0xef')]();return respondWithRpcPromise('SendMail',_0x88f1('0xf0'),{'account':_0x1a6ceb,'message':{'from':util['format'](_0x88f1('0xf1'),_0x5eff5f['name'],_0x5eff5f['email']||_0x5eff5f[_0x88f1('0xed')][_0x88f1('0x69')]),'to':_0x4442b3['forwardOfflineAddress'],'subject':_0x4442b3['offlineMessageSubject'],'html':_0x4a20e7[_0x88f1('0x64')],'attachments':_0x401f93}},client9003)[_0x88f1('0x18')](function(){return _0x4a20e7;})[_0x88f1('0x20')](function(_0x22bbea){logger[_0x88f1('0x1b')](_0x22bbea);});}})[_0x88f1('0x18')](function(){if(_0x4442b3&&_0x4442b3[_0x88f1('0xe7')]&&_0x4442b3['MailAccountId']){var _0xb99085=[];if(_0x16d55f['length']){_0xb99085=_0x16d55f[_0x88f1('0x4a')](function(_0x2effa9){return{'name':_0x2effa9[_0x88f1('0xf2')],'basename':_0x2effa9[_0x88f1('0x7e')],'type':_0x2effa9[_0x88f1('0xe3')],'ChatOfflineMessageId':_0x14c171['id']};});}var _0x595b3e;if(!_[_0x88f1('0x8b')](_0x4442b3[_0x88f1('0xf3')])){var _0x11df81=_[_0x88f1('0x4a')](_0x31a00d[_0x88f1('0x64')],function(_0x33baf1){return _0x33baf1;});var _0x5ccfb0=_[_0x88f1('0xf4')](_0x11df81)[0x0];var _0x44665e=_[_0x88f1('0xf5')](_0x5ccfb0,function(_0x3d5d43){return _0x3d5d43;});_0x595b3e=_0x44665e[0x1][_0x4442b3[_0x88f1('0xf3')]];}var _0x568e09={'from':_0x3be769['email'],'firstName':_0x3be769[_0x88f1('0x39')],'lastName':_0x3be769[_0x88f1('0x3a')],'mapKey':_0x88f1('0xf6'),'message':{'from':_0x3be769[_0x88f1('0xf6')],'to':_0x4442b3[_0x88f1('0xda')][_0x88f1('0xf6')],'cc':'','subject':_[_0x88f1('0x8b')](_0x595b3e)?_0x4442b3['offlineMessageSubject']:_0x595b3e,'messageId':'','sentAt':new Date(),'attach':_0xb99085['length'],'attachments':_0xb99085,'originChannel':_0x88f1('0xf7'),'ChatWebsiteId':_0x4442b3['id'],'ChatOfflineMessageId':_0x4a20e7['id'],'originTo':_0x4442b3['MailAccount'][_0x88f1('0xf6')]},'body':_0x4a20e7[_0x88f1('0x64')]};var _0x2436b1={'account':{'id':_0x4442b3[_0x88f1('0xf8')]},'body':_0x568e09,'log':'NotifyMailAccount'};return respondWithRpcPromise(_0x88f1('0xf9'),'notifyMail',_0x2436b1,client9001)[_0x88f1('0x18')](function(){return _0x4a20e7;})['catch'](function(_0xf06bd1){logger[_0x88f1('0x1b')](_0xf06bd1);});}return;})[_0x88f1('0x18')](function(){if(_0x4a20e7){return _0x4a20e7;}})[_0x88f1('0x18')](respondWithResult(_0x159afc,null))[_0x88f1('0x20')](function(){for(var _0x4dbe94 of _0x16d55f){var _0x285f32=path[_0x88f1('0x86')](config['root'],'server',_0x88f1('0xce'),_0x88f1('0xe5'),_0x88f1('0xe6'),_0x4dbe94[_0x88f1('0x7e')]);fs_extra[_0x88f1('0xfa')](_0x285f32)[_0x88f1('0x20')](function(_0x5d0db9){logger[_0x88f1('0x1b')](_0x88f1('0xfb'),_0x285f32,_0x5d0db9);});}});};exports['addInteraction']=function(_0x3a87e4,_0x5ee78e){return db[_0x88f1('0xba')][_0x88f1('0x61')]({'where':{'id':_0x3a87e4[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x5ee78e,null))[_0x88f1('0x18')](function(_0x16744f){if(_0x16744f){return _0x16744f[_0x88f1('0xfc')](_0x3a87e4[_0x88f1('0x64')]['ids'],_[_0x88f1('0xfd')](_0x3a87e4['body'],[_0x88f1('0x75'),'id'])||{});}})[_0x88f1('0x18')](respondWithResult(_0x5ee78e,null))[_0x88f1('0x20')](handleError(_0x5ee78e,null));};exports[_0x88f1('0xfe')]=function(_0x34b907,_0xa872ca){var _0x1bd933={'raw':![],'where':{}};var _0x40ed14={};var _0x257da4={'count':0x0,'rows':[]};return db['ChatWebsite'][_0x88f1('0x70')]({'where':{'id':_0x34b907['params']['id']}})['then'](handleEntityNotFound(_0xa872ca,null))['then'](function(_0xac0fe7){if(_0xac0fe7){_0x40ed14[_0x88f1('0x43')]=_[_0x88f1('0x4e')](db[_0x88f1('0xba')][_0x88f1('0x5f')]);_0x40ed14[_0x88f1('0x4d')]=_[_0x88f1('0x4e')](_0x34b907['query']);_0x40ed14[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x40ed14['model'],_0x40ed14['query']);_0x1bd933['attributes']=_[_0x88f1('0x50')](_0x40ed14[_0x88f1('0x43')],qs['fields'](_0x34b907[_0x88f1('0x4d')]['fields']));_0x1bd933[_0x88f1('0x52')]=_0x1bd933[_0x88f1('0x52')][_0x88f1('0x60')]?_0x1bd933[_0x88f1('0x52')]:_0x40ed14['model'];if(!_0x34b907[_0x88f1('0x4d')][_0x88f1('0x79')](_0x88f1('0x53'))){_0x1bd933[_0x88f1('0x25')]=qs[_0x88f1('0x25')](_0x34b907[_0x88f1('0x4d')][_0x88f1('0x25')]);_0x1bd933[_0x88f1('0x27')]=qs[_0x88f1('0x27')](_0x34b907[_0x88f1('0x4d')][_0x88f1('0x27')]);}_0x1bd933['order']=qs[_0x88f1('0x55')](_0x34b907[_0x88f1('0x4d')][_0x88f1('0x55')]);_0x1bd933[_0x88f1('0x56')]=qs['filters'](_[_0x88f1('0x7a')](_0x34b907[_0x88f1('0x4d')],_0x40ed14[_0x88f1('0x4f')]));_0x1bd933[_0x88f1('0x56')][_0x88f1('0x6e')]=_0xac0fe7['id'];if(_0x34b907[_0x88f1('0x4d')]['filter']){_0x1bd933['where']=_[_0x88f1('0x57')](_0x1bd933[_0x88f1('0x56')],{'$or':_['map'](_0x1bd933[_0x88f1('0x52')],function(_0x39075a){var _0x2475e5={};_0x2475e5[_0x39075a]={'$like':'%'+_0x34b907['query'][_0x88f1('0x59')]+'%'};return _0x2475e5;})});}_0x1bd933=_['merge']({},_0x1bd933,_0x34b907[_0x88f1('0x72')]);return db['ChatInteraction'][_0x88f1('0x26')]({'where':_0x1bd933[_0x88f1('0x56')]})[_0x88f1('0x18')](function(_0x470bab){_0x257da4[_0x88f1('0x26')]=_0x470bab;if(_0x34b907[_0x88f1('0x4d')][_0x88f1('0x5a')]){_0x1bd933['include']=[{'model':db[_0x88f1('0x9e')],'as':_0x88f1('0xff'),'required':![]},{'model':db[_0x88f1('0x100')],'as':_0x88f1('0x101'),'attributes':[_0x88f1('0x30'),_0x88f1('0x102'),_0x88f1('0x103')],'required':![]},{'model':db[_0x88f1('0x104')],'as':_0x88f1('0x105'),'attributes':['id',_0x88f1('0x30'),_0x88f1('0x106')],'where':_0x34b907['query']['tag']?{'id':_0x34b907['query'][_0x88f1('0x107')]}:undefined,'required':_0x34b907[_0x88f1('0x4d')][_0x88f1('0x107')]?!![]:![]}];}return db[_0x88f1('0xba')][_0x88f1('0x73')](_0x1bd933);})['then'](function(_0x55f65f){_0x257da4[_0x88f1('0x5c')]=_0x55f65f;return _0x257da4;});}})[_0x88f1('0x18')](respondWithFilteredResult(_0xa872ca,_0x1bd933))[_0x88f1('0x20')](handleError(_0xa872ca,null));};exports['getSnippet']=function(_0x3413c6,_0x486082){var _0x25241b=0x0;var _0x10e9dc=0x0;var _0x325134=![];var _0x18f7b3;var _0x5163ff;return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0x3413c6[_0x88f1('0x5e')]['id']},'include':[{'model':db[_0x88f1('0x95')],'as':_0x88f1('0x95'),'include':[{'model':db[_0x88f1('0x95')],'as':_0x88f1('0xa9'),'attributes':['id','interval']}]}]})[_0x88f1('0x18')](handleEntityNotFound(_0x486082,null))[_0x88f1('0x18')](function(_0x243b2c){if(_0x243b2c){_0x18f7b3=_0x243b2c;return _0x243b2c[_0x88f1('0x108')]({'raw':!![]});}})[_0x88f1('0x18')](function(_0x3d4d4f){if(_0x18f7b3){if(_0x3d4d4f){_0x5163ff=_0x3d4d4f;}}return require('../../config/license/util')['getLicense']();})[_0x88f1('0x18')](function(_0x297967){if(_0x297967){_0x10e9dc=_0x297967[_0x88f1('0x109')];_0x325134=_0x297967[_0x88f1('0x10a')];}})[_0x88f1('0x18')](function(){return db[_0x88f1('0xba')]['count']({'where':{'closed':![]}});})['then'](function(_0x1cc900){_0x25241b=_0x1cc900;if(_0x10e9dc&&_0x1cc900>_0x10e9dc){return db[_0x88f1('0x10b')]['findOne']({'where':{'id':0x1}})['then'](function(_0x1c8638){if(_0x1c8638){_0x1c8638[_0x88f1('0x10c')](_0x88f1('0x10d'));}});}})[_0x88f1('0x18')](function(){var _0xa0bcf1=_0x18f7b3['Interval'];var _0xc61771=_0x18f7b3[_0x88f1('0x97')]||undefined;return _0xa0bcf1?_0xa0bcf1[_0x88f1('0x10e')](_0xc61771):!![];})[_0x88f1('0x18')](function(_0x65f75d){var _0x7f535e=fs[_0x88f1('0xdd')](path[_0x88f1('0x86')](config['root'],_0x88f1('0x10f')),'utf8');var _0x2c9c08='3.9.0';var _0x4832cf=![];try{const _0x15069c=new URL(_0x18f7b3[_0x88f1('0x65')]);_0x18f7b3[_0x88f1('0x65')]=_0x15069c[_0x88f1('0x110')];}catch(_0x134183){}var _0x59b40e;if(_0x3413c6[_0x88f1('0xb3')][_0x88f1('0x3c')]){_0x3413c6[_0x88f1('0xb3')][_0x88f1('0x3c')]=_0x3413c6['headers'][_0x88f1('0x3c')]['replace'](/\/$/,'');_0x59b40e=wildcardUtils[_0x88f1('0x111')](_0x18f7b3[_0x88f1('0x65')],_0x3413c6['headers'][_0x88f1('0x3c')]);}else{_0x3413c6['headers'][_0x88f1('0x3c')]=_0x18f7b3[_0x88f1('0x65')];_0x59b40e=!![];}var _0x11ea93={'chatVersion':_0x2c9c08,'chatWebsiteAddressOrigin':_0x59b40e?_0x3413c6['headers']['referer']:_0x18f7b3[_0x88f1('0x65')],'remote':_0x18f7b3[_0x88f1('0x112')],'query':querystring[_0x88f1('0x46')](_[_0x88f1('0x57')](_0x18f7b3[_0x88f1('0x2c')]({'plain':!![]}),{'customerIp':_0x3413c6[_0x88f1('0xb3')][_0x88f1('0x37')]||_0x3413c6[_0x88f1('0xb3')][_0x88f1('0x113')]||_0x3413c6[_0x88f1('0x114')][_0x88f1('0x115')]||_0x3413c6['ip'],'referer':_0x3413c6[_0x88f1('0xb3')]['referer'],'openedInteractions':_0x25241b,'maxInteractions':_0x10e9dc,'virtual':_0x325134['virtual'],'online':_0x65f75d,'custom':_0x325134,'address':_0x59b40e?_0x3413c6[_0x88f1('0xb3')][_0x88f1('0x3c')]:null}))['replace'](/'/g,'\x5c\x27')};_0x486082[_0x88f1('0xd3')](ejs['render'](Mustache['render'](_0x7f535e,_0x11ea93),{'proactiveActions':_0x5163ff,'alignment':_0x18f7b3[_0x88f1('0x116')],'verticalAlignment':_0x18f7b3[_0x88f1('0x117')],'div_color':_0x18f7b3[_0x88f1('0x106')],'labelText':_0x18f7b3[_0x88f1('0x118')],'text_color':_0x18f7b3[_0x88f1('0x119')],'text_button_color':_0x18f7b3['textButtonColor'],'button_color':_0x18f7b3['color_button'],'background_color':_0x18f7b3[_0x88f1('0x11a')],'hideWhenOffline':_0x18f7b3['hideWhenOffline'],'intervalId':_0x18f7b3[_0x88f1('0x11b')],'isDevelopment':_0x4832cf,'chatVersion':_0x2c9c08}));})['catch'](handleError(_0x486082,null));};exports[_0x88f1('0x11c')]=function(_0x276c5e,_0x596f1f){var _0x327ee2=_0x276c5e[_0x88f1('0x5e')]['id'];var _0x2465c4=_0x276c5e[_0x88f1('0x64')];var _0x415daf=0xc8;var _0x3a873c=null;return db[_0x88f1('0xe8')][_0x88f1('0xe9')]({'isolationLevel':db[_0x88f1('0xe8')][_0x88f1('0x11d')][_0x88f1('0x11e')][_0x88f1('0x11f')]},function(_0x3c0b75){return db['ChatWebsite'][_0x88f1('0x70')]({'where':{'id':_0x327ee2},'transaction':_0x3c0b75})[_0x88f1('0x18')](function(_0x2bb75a){if(_0x2bb75a){return db[_0x88f1('0xa7')]['destroy']({'where':{'ChatWebsiteId':_0x327ee2},'transaction':_0x3c0b75})['then'](function(){var _0x775ca7=_['map'](_0x2465c4,function(_0x5447e2){_0x5447e2[_0x88f1('0x6e')]=_0x327ee2;return _0x5447e2;});return db[_0x88f1('0xa7')][_0x88f1('0x120')](_0x775ca7,{'transaction':_0x3c0b75});});}else{_0x415daf=0x194;_0x3a873c=[];}});})[_0x88f1('0x18')](function(){if(_0x415daf!==0x194){return db[_0x88f1('0xa7')][_0x88f1('0x121')]({'where':{'ChatWebsiteId':_0x327ee2},'order':_0x88f1('0x122')})[_0x88f1('0x18')](function(_0x4c8b0b){_0x3a873c=_0x4c8b0b;});}})['catch'](function(_0x3afecd){_0x415daf=0x1f4;logger[_0x88f1('0x1b')](_0x3afecd[_0x88f1('0x2f')]);if(_0x3afecd['name']){delete _0x3afecd[_0x88f1('0x30')];}_0x3a873c=_0x3afecd;})[_0x88f1('0x123')](function(){if(_0x3a873c===null){_0x596f1f[_0x88f1('0x2e')](_0x415daf);}else{if(_0x415daf===0x1f4){_0x596f1f[_0x88f1('0x21')](_0x415daf)[_0x88f1('0xd3')](_0x3a873c);}else{_0x596f1f[_0x88f1('0x21')](_0x415daf)[_0x88f1('0x23')](_0x3a873c);}}});};exports['getApplications']=function(_0x4cea83,_0x1d1b61){var _0x5d9d08={};var _0x5cfbfb={};var _0x54bd4e;var _0xb72908;return db[_0x88f1('0x4b')][_0x88f1('0x70')]({'where':{'id':_0x4cea83['params']['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x1d1b61,null))[_0x88f1('0x18')](function(_0x211915){if(_0x211915){_0x54bd4e=_0x211915;_0x5cfbfb[_0x88f1('0x43')]=_['keys'](db[_0x88f1('0xa7')][_0x88f1('0x5f')]);_0x5cfbfb[_0x88f1('0x4d')]=_[_0x88f1('0x4e')](_0x4cea83['query']);_0x5cfbfb[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x5cfbfb[_0x88f1('0x43')],_0x5cfbfb['query']);_0x5d9d08[_0x88f1('0x52')]=_['intersection'](_0x5cfbfb['model'],qs[_0x88f1('0x51')](_0x4cea83[_0x88f1('0x4d')][_0x88f1('0x51')]));_0x5d9d08['attributes']=_0x5d9d08[_0x88f1('0x52')][_0x88f1('0x60')]?_0x5d9d08[_0x88f1('0x52')]:_0x5cfbfb[_0x88f1('0x43')];_0x5d9d08[_0x88f1('0x54')]=qs[_0x88f1('0x55')](_0x4cea83[_0x88f1('0x4d')][_0x88f1('0x55')]);_0x5d9d08[_0x88f1('0x56')]=qs[_0x88f1('0x4f')](_[_0x88f1('0x7a')](_0x4cea83[_0x88f1('0x4d')],_0x5cfbfb[_0x88f1('0x4f')]));if(_0x4cea83[_0x88f1('0x4d')][_0x88f1('0x59')]){_0x5d9d08[_0x88f1('0x56')]=_[_0x88f1('0x57')](_0x5d9d08[_0x88f1('0x56')],{'$or':_[_0x88f1('0x4a')](_0x5d9d08[_0x88f1('0x52')],function(_0x17a906){var _0x4f3ae1={};_0x4f3ae1[_0x17a906]={'$like':'%'+_0x4cea83[_0x88f1('0x4d')]['filter']+'%'};return _0x4f3ae1;})});}_0x5d9d08=_[_0x88f1('0x57')]({},_0x5d9d08,_0x4cea83[_0x88f1('0x72')]);return _0x54bd4e[_0x88f1('0x124')](_0x5d9d08);}})[_0x88f1('0x18')](function(_0x2817bd){if(_0x2817bd){_0xb72908=_0x2817bd[_0x88f1('0x60')];if(!_0x4cea83['query']['hasOwnProperty']('nolimit')){_0x5d9d08[_0x88f1('0x25')]=qs[_0x88f1('0x25')](_0x4cea83['query'][_0x88f1('0x25')]);_0x5d9d08['offset']=qs[_0x88f1('0x27')](_0x4cea83['query'][_0x88f1('0x27')]);}return _0x54bd4e[_0x88f1('0x124')](_0x5d9d08);}})[_0x88f1('0x18')](function(_0x2c0129){if(_0x2c0129){return _0x2c0129?{'count':_0xb72908,'rows':_0x2c0129}:null;}})[_0x88f1('0x18')](respondWithResult(_0x1d1b61,null))[_0x88f1('0x20')](handleError(_0x1d1b61,null));};exports['addProactiveActions']=function(_0x7e8650,_0x519f7f){return db[_0x88f1('0x125')]['find']({'where':{'id':_0x7e8650[_0x88f1('0x5e')]['id']}})['then'](handleEntityNotFound(_0x519f7f,null))[_0x88f1('0x18')](function(_0x5133be){if(_0x5133be){return _0x5133be[_0x88f1('0x126')](_0x7e8650[_0x88f1('0x64')]['ids'],_[_0x88f1('0xfd')](_0x7e8650[_0x88f1('0x64')],['ids','id'])||{});}})[_0x88f1('0x18')](respondWithResult(_0x519f7f,null))[_0x88f1('0x20')](handleError(_0x519f7f,null));};exports[_0x88f1('0x108')]=function(_0xc294f6,_0x2f25cc){var _0x2c885e={};var _0xd70b87={};var _0x5d68b4;var _0xf5f532;return db[_0x88f1('0x4b')][_0x88f1('0x70')]({'where':{'id':_0xc294f6[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x2f25cc,null))[_0x88f1('0x18')](function(_0x413322){if(_0x413322){_0x5d68b4=_0x413322;_0xd70b87[_0x88f1('0x43')]=_[_0x88f1('0x4e')](db[_0x88f1('0x127')][_0x88f1('0x5f')]);_0xd70b87['query']=_[_0x88f1('0x4e')](_0xc294f6[_0x88f1('0x4d')]);_0xd70b87[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0xd70b87[_0x88f1('0x43')],_0xd70b87[_0x88f1('0x4d')]);_0x2c885e[_0x88f1('0x52')]=_['intersection'](_0xd70b87[_0x88f1('0x43')],qs[_0x88f1('0x51')](_0xc294f6[_0x88f1('0x4d')][_0x88f1('0x51')]));_0x2c885e[_0x88f1('0x52')]=_0x2c885e[_0x88f1('0x52')][_0x88f1('0x60')]?_0x2c885e[_0x88f1('0x52')]:_0xd70b87[_0x88f1('0x43')];_0x2c885e[_0x88f1('0x54')]=qs[_0x88f1('0x55')](_0xc294f6['query'][_0x88f1('0x55')]);_0x2c885e[_0x88f1('0x56')]=qs[_0x88f1('0x4f')](_['pick'](_0xc294f6[_0x88f1('0x4d')],_0xd70b87[_0x88f1('0x4f')]));if(_0xc294f6[_0x88f1('0x4d')][_0x88f1('0x59')]){_0x2c885e['where']=_[_0x88f1('0x57')](_0x2c885e[_0x88f1('0x56')],{'$or':_[_0x88f1('0x4a')](_0x2c885e[_0x88f1('0x52')],function(_0x3b4e2d){var _0x56b4ac={};_0x56b4ac[_0x3b4e2d]={'$like':'%'+_0xc294f6[_0x88f1('0x4d')][_0x88f1('0x59')]+'%'};return _0x56b4ac;})});}_0x2c885e=_[_0x88f1('0x57')]({},_0x2c885e,_0xc294f6[_0x88f1('0x72')]);return _0x5d68b4[_0x88f1('0x108')](_0x2c885e);}})[_0x88f1('0x18')](function(_0x58370a){if(_0x58370a){_0xf5f532=_0x58370a[_0x88f1('0x60')];if(!_0xc294f6[_0x88f1('0x4d')]['hasOwnProperty'](_0x88f1('0x53'))){_0x2c885e[_0x88f1('0x25')]=qs['limit'](_0xc294f6[_0x88f1('0x4d')][_0x88f1('0x25')]);_0x2c885e[_0x88f1('0x27')]=qs[_0x88f1('0x27')](_0xc294f6['query'][_0x88f1('0x27')]);}return _0x5d68b4[_0x88f1('0x108')](_0x2c885e);}})[_0x88f1('0x18')](function(_0x56954f){if(_0x56954f){return _0x56954f?{'count':_0xf5f532,'rows':_0x56954f}:null;}})[_0x88f1('0x18')](respondWithResult(_0x2f25cc,null))['catch'](handleError(_0x2f25cc,null));};exports[_0x88f1('0x128')]=function(_0x2f482b,_0x2f98c9){var _0x145a72=_0x2f482b[_0x88f1('0x4d')]['online']===_0x88f1('0x129')?'offlineForm':_0x88f1('0x12a');return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'attributes':['id',_0x145a72],'where':{'id':_0x2f482b[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x2f98c9,null))[_0x88f1('0x18')](function(_0x2dc831){if(_0x2dc831){var _0xa3b891=_0x2dc831[_0x145a72];var _0x1f0085=_0xa3b891&&_0xa3b891[_0x88f1('0x12b')]?_0xa3b891[_0x88f1('0x12b')]:[];_0x2f98c9[_0x88f1('0xd3')]({'fromKey':_['isNil'](_0xa3b891[_0x88f1('0x12c')])?undefined:_0xa3b891['fromKey'],'count':_0x1f0085[_0x88f1('0x60')],'rows':_0x1f0085});}})[_0x88f1('0x20')](handleError(_0x2f98c9,null));};exports[_0x88f1('0x12d')]=function(_0x5eb043,_0xe6f462){var _0x336d44={'raw':![],'where':{}};var _0x3cad62={};var _0x4abc8d={'count':0x0,'rows':[]};return db[_0x88f1('0x4b')][_0x88f1('0x70')]({'where':{'id':_0x5eb043[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0xe6f462,null))['then'](function(_0x1600a1){if(_0x1600a1){_0x3cad62[_0x88f1('0x43')]=_['keys'](db[_0x88f1('0xe1')][_0x88f1('0x5f')]);_0x3cad62[_0x88f1('0x4d')]=_[_0x88f1('0x4e')](_0x5eb043[_0x88f1('0x4d')]);_0x3cad62[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x3cad62[_0x88f1('0x43')],_0x3cad62['query']);_0x336d44[_0x88f1('0x52')]=_[_0x88f1('0x50')](_0x3cad62[_0x88f1('0x43')],qs[_0x88f1('0x51')](_0x5eb043[_0x88f1('0x4d')]['fields']));_0x336d44['attributes']=_0x336d44[_0x88f1('0x52')]['length']?_0x336d44[_0x88f1('0x52')]:_0x3cad62['model'];if(!_0x5eb043[_0x88f1('0x4d')]['hasOwnProperty'](_0x88f1('0x53'))){_0x336d44['limit']=qs[_0x88f1('0x25')](_0x5eb043['query']['limit']);_0x336d44[_0x88f1('0x27')]=qs[_0x88f1('0x27')](_0x5eb043[_0x88f1('0x4d')]['offset']);}_0x336d44[_0x88f1('0x54')]=qs[_0x88f1('0x55')](_0x5eb043['query'][_0x88f1('0x55')]);_0x336d44[_0x88f1('0x56')]=qs[_0x88f1('0x4f')](_[_0x88f1('0x7a')](_0x5eb043['query'],_0x3cad62[_0x88f1('0x4f')]));_0x336d44[_0x88f1('0x56')][_0x88f1('0x6e')]=_0x1600a1['id'];if(_0x5eb043[_0x88f1('0x4d')][_0x88f1('0x59')]){_0x336d44[_0x88f1('0x56')]=_[_0x88f1('0x57')](_0x336d44[_0x88f1('0x56')],{'$or':_[_0x88f1('0x4a')](_0x336d44['attributes'],function(_0x33a024){var _0x4ec371={};_0x4ec371[_0x33a024]={'$like':'%'+_0x5eb043['query']['filter']+'%'};return _0x4ec371;})});}_0x336d44=_[_0x88f1('0x57')]({},_0x336d44,_0x5eb043[_0x88f1('0x72')]);return db[_0x88f1('0xe1')][_0x88f1('0x26')]({'where':_0x336d44[_0x88f1('0x56')]})['then'](function(_0x283a03){_0x4abc8d['count']=_0x283a03;if(_0x5eb043['query'][_0x88f1('0x5a')]){_0x336d44[_0x88f1('0x5b')]=[{'all':!![]}];}else{_0x336d44[_0x88f1('0x5b')]=[{'model':db[_0x88f1('0x9e')],'as':_0x88f1('0xff'),'required':![]},{'model':db['Attachment'],'as':_0x88f1('0x12e'),'required':![]}];}return db[_0x88f1('0xe1')]['findAll'](_0x336d44);})['then'](function(_0x214833){_0x4abc8d[_0x88f1('0x5c')]=_0x214833;return _0x4abc8d;});}})['then'](respondWithFilteredResult(_0xe6f462,_0x336d44))[_0x88f1('0x20')](handleError(_0xe6f462,null));};exports[_0x88f1('0x12f')]=function(_0x3a5507,_0x3abb1b){return db[_0x88f1('0x4b')][_0x88f1('0x61')]({'where':{'id':_0x3a5507[_0x88f1('0x5e')]['id']}})['then'](handleEntityNotFound(_0x3abb1b,null))[_0x88f1('0x18')](function(_0x165a57){if(_0x165a57){return _0x165a57['addAgents'](_0x3a5507[_0x88f1('0x64')][_0x88f1('0x75')],_['omit'](_0x3a5507[_0x88f1('0x64')],['ids','id'])||{})[_0x88f1('0xdc')](function(_0x3b898d){for(var _0x18ada9=0x0;_0x18ada9<_0x3a5507['body'][_0x88f1('0x75')][_0x88f1('0x60')];_0x18ada9+=0x1){socket[_0x88f1('0x130')]('userChatWebsite:save',{'UserId':Number(_0x3a5507[_0x88f1('0x64')][_0x88f1('0x75')][_0x18ada9]),'ChatWebsiteId':Number(_0x3a5507['params']['id'])});}return _0x3b898d;});}})['then'](respondWithResult(_0x3abb1b,null))['catch'](handleError(_0x3abb1b,null));};exports[_0x88f1('0x131')]=function(_0x269656,_0x4dfbaf){return db[_0x88f1('0x4b')]['find']({'where':{'id':_0x269656[_0x88f1('0x5e')]['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x4dfbaf,null))[_0x88f1('0x18')](function(_0x4d096b){if(_0x4d096b){return _0x4d096b[_0x88f1('0x131')](_0x269656[_0x88f1('0x4d')][_0x88f1('0x75')])[_0x88f1('0x18')](function(){if(_[_0x88f1('0x132')](_0x269656['query']['ids'])){for(var _0x4a5026=0x0;_0x4a5026<_0x269656[_0x88f1('0x4d')][_0x88f1('0x75')]['length'];_0x4a5026+=0x1){socket[_0x88f1('0x130')](_0x88f1('0x133'),{'UserId':Number(_0x269656['query'][_0x88f1('0x75')][_0x4a5026]),'ChatWebsiteId':Number(_0x269656[_0x88f1('0x5e')]['id'])});}}else{socket[_0x88f1('0x130')](_0x88f1('0x133'),{'UserId':Number(_0x269656[_0x88f1('0x4d')][_0x88f1('0x75')]),'ChatWebsiteId':Number(_0x269656[_0x88f1('0x5e')]['id'])});}});}})['then'](respondWithStatusCode(_0x4dfbaf,null))[_0x88f1('0x20')](handleError(_0x4dfbaf,null));};exports[_0x88f1('0x134')]=function(_0x4c8b37,_0x5032df){var _0x35fe29={};var _0x391773={};var _0x5d3e76;var _0x1fce16;return db[_0x88f1('0x4b')]['findOne']({'where':{'id':_0x4c8b37['params']['id']}})[_0x88f1('0x18')](handleEntityNotFound(_0x5032df,null))[_0x88f1('0x18')](function(_0x28c69d){if(_0x28c69d){_0x5d3e76=_0x28c69d;_0x391773[_0x88f1('0x43')]=_[_0x88f1('0x4e')](db[_0x88f1('0x100')]['rawAttributes']);_0x391773[_0x88f1('0x4d')]=_[_0x88f1('0x4e')](_0x4c8b37[_0x88f1('0x4d')]);_0x391773[_0x88f1('0x4f')]=_[_0x88f1('0x50')](_0x391773[_0x88f1('0x43')],_0x391773['query']);_0x35fe29[_0x88f1('0x52')]=_[_0x88f1('0x50')](_0x391773['model'],qs[_0x88f1('0x51')](_0x4c8b37['query']['fields']));_0x35fe29[_0x88f1('0x52')]=_0x35fe29['attributes'][_0x88f1('0x60')]?_0x35fe29['attributes']:_0x391773['model'];_0x35fe29['order']=qs['sort'](_0x4c8b37[_0x88f1('0x4d')][_0x88f1('0x55')]);_0x35fe29[_0x88f1('0x56')]=qs[_0x88f1('0x4f')](_['pick'](_0x4c8b37[_0x88f1('0x4d')],_0x391773[_0x88f1('0x4f')]));if(_0x4c8b37[_0x88f1('0x4d')][_0x88f1('0x59')]){_0x35fe29[_0x88f1('0x56')]=_[_0x88f1('0x57')](_0x35fe29[_0x88f1('0x56')],{'$or':_[_0x88f1('0x4a')](_0x35fe29[_0x88f1('0x52')],function(_0x33fbea){var _0x57d4d3={};_0x57d4d3[_0x33fbea]={'$like':'%'+_0x4c8b37[_0x88f1('0x4d')][_0x88f1('0x59')]+'%'};return _0x57d4d3;})});}_0x35fe29=_['merge']({},_0x35fe29,_0x4c8b37['options']);return _0x5d3e76['getAgents'](_0x35fe29);}})[_0x88f1('0x18')](function(_0x1aaa83){if(_0x1aaa83){_0x1fce16=_0x1aaa83[_0x88f1('0x60')];if(!_0x4c8b37['query'][_0x88f1('0x79')]('nolimit')){_0x35fe29[_0x88f1('0x25')]=qs[_0x88f1('0x25')](_0x4c8b37['query']['limit']);_0x35fe29['offset']=qs['offset'](_0x4c8b37['query']['offset']);}return _0x5d3e76[_0x88f1('0x134')](_0x35fe29);}})[_0x88f1('0x18')](function(_0xeac71c){if(_0xeac71c){return _0xeac71c?{'count':_0x1fce16,'rows':_0xeac71c}:null;}})[_0x88f1('0x18')](respondWithResult(_0x5032df,null))[_0x88f1('0x20')](handleError(_0x5032df,null));};