Built motion from commit 5293bb2a.|2.6.30
[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 _0x4d9e=['waitForTheAssignedQueue','Start','startRouting','EventManager','offline','Sequelize','ValidationError','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','render','offlineMessageBody','ChatOfflineMessage','originalname','mimetype','server','files','attachments','offline-chat','openNewInteraction','transaction','Attachment','bulkCreate','MailServerOut','Smtp','CloudProvider','forwardOffline','forwardOfflineAddress','getSmtpOptions','SendMail','sendMail','\x22%s\x22\x20<%s>','email','offlineMessageSubject','subjectOffline','toPairsIn','mapValues','Chat','NotifyMailAccount','addInteraction','omit','getInteractions','Contact','User','Owner','fullname','internal','Tag','color','tag','interval','getProactiveActions','getLicense','virtual','increment','chatLicenseExceeded','server/files/chat/iframe.ejs','utf8','origin','http://localhost:9000','remote','x-real-ip','connection','remoteAddress','replace','labelText','textColor','color_button','backgroundColor','hideWhenOffline','IntervalId','addApplications','sequelize','Transaction','READ_COMMITTED','findAndCountAll','getApplications','addProactiveActions','online','false','offlineForm','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','emit','removeAgents','isArray','userChatWebsite:remove','getAgents','mustache','ejs','lodash','html-to-text','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../errors/api','APIBadRequestError','APINotFoundError','APIOutOfIntervalError','handleError','./helpers/wildcard-expressions','url','URL','../../mysqldb','redis','defaults','http','client','info','request\x20sent','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatWebsite,\x20%s,\x20%s','message','result','catch','status','end','json','undefined','limit','count','offset','set','Content-Range','update','destroy','then','UserProfileResource','sendStatus','stack','name','send','user-agent-parser','setUA','user-agent','getResult','x-forwarded-for','first','split','firstName','lastName','x-real-port','browser','format','%s\x20%s','version','unknown','device','vendor','%s\x20%s\x20%s','type','index','Pause','mandatoryDispositionPause','map','ChatWebsite','rawAttributes','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','options','show','keys','includeAll','include','find','body','address','forEach','trim','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','testWildcardValidity','\x22\x20is\x20not\x20a\x20valid\x20wildcard\x20expression','params','describe','addDisposition','Disposition','getDispositions','findOne','ChatWebsiteId','filter','findAll','rows','removeDispositions','ids','getAnswers','CannedAnswer','removeAnswers','addLogo','sitepic','file','filename','addAvatar','addCustomerAvatar','customerAvatar','systemAvatar','getLogo','server/files/images/logos/default_logo.svg','../../config/license/util','custom','isNil','existsSync','server/files/images/logos/','join','root','server/files/images/avatars/default_avatar.png','agentAvatar','server/files/images/avatars/','download','showCustomerAvatar','getSystemAvatar','Interval','resolve','timezone','ifTime','notify','chat','from','From\x20is\x20mandatory','mapKey','MapKey\x20is\x20mandatory','Body\x20is\x20mandatory','customerIp','CmContact','createdAt','updatedAt','CompanyId','includes','Invalid\x20MapKey\x20parameter.\x20Allowed\x20values:\x20','List','Contacts','DESC','ChatApplication','Applications','Intervals','Chat\x20Website\x20with\x20id\x20%s\x20not\x20found','account','applications','orderBy','priority','asc','list','ListId','headers','threadId','closed','ChatInteraction','referer','Writing\x20on\x20closed\x20interaction','externalUrl','ContactId','interaction','contact','messageId','created','*,*,*,*','UserId','unshift','agent','waitForTheAssignedAgent','forcedOwnership','queueId','ChatQueue'];(function(_0x2e7a79,_0x30f013){var _0x29e00f=function(_0x51b9b7){while(--_0x51b9b7){_0x2e7a79['push'](_0x2e7a79['shift']());}};_0x29e00f(++_0x30f013);}(_0x4d9e,0x18c));var _0xe4d9=function(_0x3c91ab,_0x50d459){_0x3c91ab=_0x3c91ab-0x0;var _0x57d552=_0x4d9e[_0x3c91ab];return _0x57d552;};'use strict';var Mustache=require(_0xe4d9('0x0'));var util=require('util');var path=require('path');var ejs=require(_0xe4d9('0x1'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xe4d9('0x2'));var querystring=require('querystring');var htmlToText=require(_0xe4d9('0x3'));var Redis=require(_0xe4d9('0x4'));var jayson=require('jayson/promise');var qs=require(_0xe4d9('0x5'));var logger=require(_0xe4d9('0x6'))(_0xe4d9('0x7'));var config=require(_0xe4d9('0x8'));var APIBadRequestError=require(_0xe4d9('0x9'))[_0xe4d9('0xa')];var APINotFoundError=require('../../errors/api')[_0xe4d9('0xb')];var APIOutOfIntervalError=require(_0xe4d9('0x9'))[_0xe4d9('0xc')];var APIHandleError=require(_0xe4d9('0x9'))[_0xe4d9('0xd')];var APIConflictError=require(_0xe4d9('0x9'))['APIConflictError'];var wildcardUtils=require(_0xe4d9('0xe'));var URL=require(_0xe4d9('0xf'))[_0xe4d9('0x10')];var db=require(_0xe4d9('0x11'))['db'];config[_0xe4d9('0x12')]=_[_0xe4d9('0x13')](config[_0xe4d9('0x12')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./chatWebsite.socket')['register'](socket);var client=jayson['client']['http']({'port':0x232c});var client9002=jayson['client'][_0xe4d9('0x14')]({'port':0x232a});var client9003=jayson[_0xe4d9('0x15')][_0xe4d9('0x14')]({'port':0x232b});var client9001=jayson['client'][_0xe4d9('0x14')]({'port':0x2329});function respondWithRpcPromise(_0x3f6ce4,_0xe4f133,_0x4283f7,_0x58d0cf){return new Promise(function(_0x331ef3,_0x35cbc2){var _0x4687f8=_0x58d0cf||client;return _0x4687f8['request'](_0x3f6ce4,_0x4283f7)['then'](function(_0x7abb80){logger[_0xe4d9('0x16')]('ChatWebsite,\x20%s,\x20%s',_0xe4f133,_0xe4d9('0x17'));logger['debug'](_0xe4d9('0x18'),_0xe4f133,_0xe4d9('0x17'),JSON[_0xe4d9('0x19')](_0x7abb80));if(_0x7abb80[_0xe4d9('0x1a')]){if(_0x7abb80['error'][_0xe4d9('0x1b')]===0x1f4){logger[_0xe4d9('0x1a')](_0xe4d9('0x1c'),_0xe4f133,_0x7abb80[_0xe4d9('0x1a')][_0xe4d9('0x1d')]);return _0x35cbc2(_0x7abb80[_0xe4d9('0x1a')][_0xe4d9('0x1d')]);}logger[_0xe4d9('0x1a')](_0xe4d9('0x1c'),_0xe4f133,_0x7abb80['error'][_0xe4d9('0x1d')]);return _0x331ef3(_0x7abb80[_0xe4d9('0x1a')]['message']);}else{logger[_0xe4d9('0x16')]('ChatWebsite,\x20%s,\x20%s',_0xe4f133,_0xe4d9('0x17'));_0x331ef3(_0x7abb80[_0xe4d9('0x1e')]['message']);}})[_0xe4d9('0x1f')](function(_0x32e7da){logger['error'](_0xe4d9('0x1c'),_0xe4f133,_0x32e7da);_0x35cbc2(_0x32e7da);});});}function respondWithStatusCode(_0x2af9b0,_0x36444c){_0x36444c=_0x36444c||0xcc;return function(_0x5bb43b){if(_0x5bb43b){return _0x2af9b0['sendStatus'](_0x36444c);}return _0x2af9b0[_0xe4d9('0x20')](_0x36444c)[_0xe4d9('0x21')]();};}function respondWithResult(_0x52ef56,_0x5dddd2){_0x5dddd2=_0x5dddd2||0xc8;return function(_0x4954b5){if(_0x4954b5){return _0x52ef56['status'](_0x5dddd2)[_0xe4d9('0x22')](_0x4954b5);}};}function respondWithFilteredResult(_0x48d481,_0x40ffd0){return function(_0x1f3d90){if(_0x1f3d90){var _0x4192bb=typeof _0x40ffd0['offset']===_0xe4d9('0x23')&&typeof _0x40ffd0[_0xe4d9('0x24')]===_0xe4d9('0x23');var _0x45e8a3=_0x1f3d90[_0xe4d9('0x25')];var _0x1904d1=_0x4192bb?0x0:_0x40ffd0[_0xe4d9('0x26')];var _0x449cb8=_0x4192bb?_0x1f3d90[_0xe4d9('0x25')]:_0x40ffd0[_0xe4d9('0x26')]+_0x40ffd0[_0xe4d9('0x24')];var _0x29a121;if(_0x449cb8>=_0x45e8a3){_0x449cb8=_0x45e8a3;_0x29a121=0xc8;}else{_0x29a121=0xce;}_0x48d481['status'](_0x29a121);return _0x48d481[_0xe4d9('0x27')](_0xe4d9('0x28'),_0x1904d1+'-'+_0x449cb8+'/'+_0x45e8a3)[_0xe4d9('0x22')](_0x1f3d90);}return null;};}function saveUpdates(_0x3721a0){return function(_0xa444d0){if(_0xa444d0){return _0xa444d0[_0xe4d9('0x29')](_0x3721a0)['then'](function(_0x532414){return _0x532414;});}return null;};}function removeEntity(_0x4d7f17){return function(_0x270cad){if(_0x270cad){return _0x270cad[_0xe4d9('0x2a')]()[_0xe4d9('0x2b')](function(){var _0x4f8abf=_0x270cad['get']({'plain':!![]});var _0x5ad794='ChatWebsites';return db[_0xe4d9('0x2c')][_0xe4d9('0x2a')]({'where':{'type':_0x5ad794,'resourceId':_0x4f8abf['id']}})['then'](function(){return _0x270cad;});})[_0xe4d9('0x2b')](function(){_0x4d7f17[_0xe4d9('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x831143){return function(_0x20e78a){if(!_0x20e78a){_0x831143[_0xe4d9('0x2d')](0x194);}return _0x20e78a;};}function handleError(_0x4f7a6c,_0x3321f8){_0x3321f8=_0x3321f8||0x1f4;return function(_0x37a825){logger[_0xe4d9('0x1a')](_0x37a825[_0xe4d9('0x2e')]);if(_0x37a825[_0xe4d9('0x2f')]){delete _0x37a825[_0xe4d9('0x2f')];}_0x4f7a6c[_0xe4d9('0x20')](_0x3321f8)[_0xe4d9('0x30')](_0x37a825);};}function createInteractionObject(_0x234b62,_0x34f72f,_0x5601cc,_0x35b5f5){var _0x20aef6=require(_0xe4d9('0x31'));var _0x27028d=new _0x20aef6();var _0x26a721=_0x27028d[_0xe4d9('0x32')](_0x5601cc[_0xe4d9('0x33')])[_0xe4d9('0x34')]();var _0x96a350=_0x34f72f['customerIp'];if(_0x5601cc['cf-connecting-ip']){_0x96a350=_0x5601cc['cf-connecting-ip'];}else if(_0x5601cc[_0xe4d9('0x35')]){_0x96a350=_[_0xe4d9('0x36')](_0x5601cc[_0xe4d9('0x35')][_0xe4d9('0x37')](','));}return{'ContactId':_0x35b5f5['id'],'ChatWebsiteId':_0x234b62,'from':(_0x35b5f5[_0xe4d9('0x38')]||'')+'\x20'+(_0x35b5f5[_0xe4d9('0x39')]||''),'customerIp':_0x96a350,'customerPort':_0x5601cc[_0xe4d9('0x3a')]?_0x5601cc['x-real-port']:null,'referer':_0x34f72f['referer'],'browserName':_0x26a721['browser'][_0xe4d9('0x2f')]&&_0x26a721[_0xe4d9('0x3b')]['version']?util[_0xe4d9('0x3c')](_0xe4d9('0x3d'),_0x26a721[_0xe4d9('0x3b')][_0xe4d9('0x2f')],_0x26a721['browser'][_0xe4d9('0x3e')]):_0xe4d9('0x3f'),'browserVersion':_0x26a721[_0xe4d9('0x3b')][_0xe4d9('0x3e')]||_0xe4d9('0x3f'),'osName':util[_0xe4d9('0x3c')](_0xe4d9('0x3d'),_0x26a721['os'][_0xe4d9('0x2f')],_0x26a721['os'][_0xe4d9('0x3e')]),'osVersion':_0x26a721['os'][_0xe4d9('0x3e')],'deviceModel':_0x26a721[_0xe4d9('0x40')]['model']&&_0x26a721[_0xe4d9('0x40')][_0xe4d9('0x41')]?util[_0xe4d9('0x3c')](_0xe4d9('0x42'),_0x26a721[_0xe4d9('0x40')]['model'],_0x26a721[_0xe4d9('0x40')][_0xe4d9('0x41')],_0x26a721[_0xe4d9('0x40')][_0xe4d9('0x43')]):null,'deviceVendor':_0x26a721[_0xe4d9('0x40')][_0xe4d9('0x41')],'deviceType':_0x26a721[_0xe4d9('0x40')][_0xe4d9('0x43')],'formData':JSON[_0xe4d9('0x19')](_0x34f72f)};}exports[_0xe4d9('0x44')]=function(_0x5510e7,_0x246550){var _0x179117={'include':[{'model':db[_0xe4d9('0x45')],'as':_0xe4d9('0x46')}]},_0x96ead7={},_0x54bf07={'count':0x0,'rows':[]};var _0x79baad=_[_0xe4d9('0x47')](db[_0xe4d9('0x48')][_0xe4d9('0x49')],function(_0x126b6c){return{'name':_0x126b6c['fieldName'],'type':_0x126b6c[_0xe4d9('0x43')][_0xe4d9('0x4a')]};});_0x96ead7[_0xe4d9('0x4b')]=_[_0xe4d9('0x47')](_0x79baad,_0xe4d9('0x2f'));_0x96ead7[_0xe4d9('0x4c')]=_['keys'](_0x5510e7[_0xe4d9('0x4c')]);_0x96ead7[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x96ead7[_0xe4d9('0x4b')],_0x96ead7[_0xe4d9('0x4c')]);_0x179117[_0xe4d9('0x4f')]=_['intersection'](_0x96ead7[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x5510e7['query'][_0xe4d9('0x50')]));_0x179117['attributes']=_0x179117[_0xe4d9('0x4f')][_0xe4d9('0x51')]?_0x179117['attributes']:_0x96ead7[_0xe4d9('0x4b')];if(!_0x5510e7['query'][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x179117[_0xe4d9('0x24')]=qs['limit'](_0x5510e7[_0xe4d9('0x4c')][_0xe4d9('0x24')]);_0x179117['offset']=qs[_0xe4d9('0x26')](_0x5510e7[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}_0x179117[_0xe4d9('0x54')]=qs['sort'](_0x5510e7['query'][_0xe4d9('0x55')]);_0x179117[_0xe4d9('0x56')]=qs[_0xe4d9('0x4d')](_[_0xe4d9('0x57')](_0x5510e7[_0xe4d9('0x4c')],_0x96ead7[_0xe4d9('0x4d')]),_0x79baad);if(_0x5510e7['query']['filter']){_0x179117[_0xe4d9('0x56')]=_[_0xe4d9('0x58')](_0x179117[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x79baad,function(_0xfe53b8){if(_0xfe53b8[_0xe4d9('0x43')]!=='VIRTUAL'){var _0x4ac680={};_0x4ac680[_0xfe53b8[_0xe4d9('0x2f')]]={'$like':'%'+_0x5510e7[_0xe4d9('0x4c')]['filter']+'%'};return _0x4ac680;}})});}_0x179117=_[_0xe4d9('0x58')]({},_0x179117,_0x5510e7[_0xe4d9('0x59')]);var _0x281fda={'where':_0x179117['where']};return db[_0xe4d9('0x48')]['count'](_0x281fda)[_0xe4d9('0x2b')](function(_0x13b008){_0x54bf07[_0xe4d9('0x25')]=_0x13b008;if(_0x5510e7['query']['includeAll']){_0x179117['include']=[{'all':!![]}];}return db[_0xe4d9('0x48')]['findAll'](_0x179117);})[_0xe4d9('0x2b')](function(_0x4c37a6){_0x54bf07['rows']=_0x4c37a6;return _0x54bf07;})[_0xe4d9('0x2b')](respondWithFilteredResult(_0x246550,_0x179117))[_0xe4d9('0x1f')](handleError(_0x246550,null));};exports[_0xe4d9('0x5a')]=function(_0x1469b8,_0x1ef819){var _0x580bb4={'raw':![],'where':{'id':_0x1469b8['params']['id']},'include':[{'model':db['Pause'],'as':_0xe4d9('0x46')}]},_0x49a622={};_0x49a622[_0xe4d9('0x4b')]=_[_0xe4d9('0x5b')](db[_0xe4d9('0x48')][_0xe4d9('0x49')]);_0x49a622[_0xe4d9('0x4c')]=_[_0xe4d9('0x5b')](_0x1469b8['query']);_0x49a622['filters']=_[_0xe4d9('0x4e')](_0x49a622[_0xe4d9('0x4b')],_0x49a622[_0xe4d9('0x4c')]);_0x580bb4[_0xe4d9('0x4f')]=_[_0xe4d9('0x4e')](_0x49a622[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x1469b8[_0xe4d9('0x4c')][_0xe4d9('0x50')]));_0x580bb4[_0xe4d9('0x4f')]=_0x580bb4[_0xe4d9('0x4f')][_0xe4d9('0x51')]?_0x580bb4['attributes']:_0x49a622[_0xe4d9('0x4b')];if(_0x1469b8[_0xe4d9('0x4c')][_0xe4d9('0x5c')]){_0x580bb4[_0xe4d9('0x5d')]=[{'all':!![]}];}_0x580bb4=_['merge']({},_0x580bb4,_0x1469b8['options']);return db['ChatWebsite'][_0xe4d9('0x5e')](_0x580bb4)[_0xe4d9('0x2b')](handleEntityNotFound(_0x1ef819,null))[_0xe4d9('0x2b')](respondWithResult(_0x1ef819,null))[_0xe4d9('0x1f')](handleError(_0x1ef819,null));};exports['create']=function(_0x53975f,_0x383cd4){var _0xf41d89=null;_0x53975f[_0xe4d9('0x5f')][_0xe4d9('0x60')][_0xe4d9('0x37')](',')[_0xe4d9('0x61')](_0x4bb111=>{if(_0x4bb111[_0xe4d9('0x62')]()!==''&&!wildcardUtils['testWildcardValidity'](_0x4bb111[_0xe4d9('0x62')]())){_0xf41d89=new APIBadRequestError('\x22'+_0x4bb111[_0xe4d9('0x62')]()+'\x22\x20is\x20not\x20a\x20valid\x20wildcard\x20expression');}});if(_0xf41d89){return handleError(_0x383cd4,null)(_0xf41d89);}return db[_0xe4d9('0x48')][_0xe4d9('0x63')](_0x53975f['body'],{})[_0xe4d9('0x2b')](function(_0x655901){var _0x46d795=_0x53975f[_0xe4d9('0x64')][_0xe4d9('0x65')]({'plain':!![]});if(!_0x46d795)throw new Error(_0xe4d9('0x66'));if(_0x46d795['role']==='user'){var _0x3473ad=_0x655901['get']({'plain':!![]});var _0x10ef01='ChatWebsites';return db['UserProfileSection'][_0xe4d9('0x5e')]({'where':{'name':_0x10ef01,'userProfileId':_0x46d795[_0xe4d9('0x67')]},'raw':!![]})[_0xe4d9('0x2b')](function(_0x5b0471){if(_0x5b0471&&_0x5b0471[_0xe4d9('0x68')]===0x0){return db['UserProfileResource'][_0xe4d9('0x63')]({'name':_0x3473ad[_0xe4d9('0x2f')],'resourceId':_0x3473ad['id'],'type':_0x5b0471[_0xe4d9('0x2f')],'sectionId':_0x5b0471['id']},{})[_0xe4d9('0x2b')](function(){return _0x655901;});}else{return _0x655901;}})['catch'](function(_0x3b9fd3){logger[_0xe4d9('0x1a')](_0xe4d9('0x69'),_0x3b9fd3);throw _0x3b9fd3;});}return _0x655901;})[_0xe4d9('0x2b')](respondWithResult(_0x383cd4,0xc9))[_0xe4d9('0x1f')](handleError(_0x383cd4,null));};exports[_0xe4d9('0x29')]=function(_0x1fa518,_0x2ce194){var _0x29c3fe=null;_0x1fa518['body'][_0xe4d9('0x60')]['split'](',')[_0xe4d9('0x61')](_0x2847b9=>{if(_0x2847b9[_0xe4d9('0x62')]()!==''&&!wildcardUtils[_0xe4d9('0x6a')](_0x2847b9['trim']())){_0x29c3fe=new APIBadRequestError('\x22'+_0x2847b9['trim']()+_0xe4d9('0x6b'));}});if(_0x29c3fe){return handleError(_0x2ce194,null)(_0x29c3fe);}if(_0x1fa518[_0xe4d9('0x5f')]['id']){delete _0x1fa518[_0xe4d9('0x5f')]['id'];}return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x1fa518[_0xe4d9('0x6c')]['id']},'include':[{'model':db[_0xe4d9('0x45')],'as':_0xe4d9('0x46')}]})[_0xe4d9('0x2b')](handleEntityNotFound(_0x2ce194,null))['then'](saveUpdates(_0x1fa518[_0xe4d9('0x5f')],null))[_0xe4d9('0x2b')](respondWithResult(_0x2ce194,null))['catch'](handleError(_0x2ce194,null));};exports[_0xe4d9('0x2a')]=function(_0x440457,_0x1b5c79){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x440457['params']['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x1b5c79,null))[_0xe4d9('0x2b')](removeEntity(_0x1b5c79,null))[_0xe4d9('0x1f')](handleError(_0x1b5c79,null));};exports[_0xe4d9('0x6d')]=function(_0x458eea,_0x354259){return db[_0xe4d9('0x48')][_0xe4d9('0x6d')]()[_0xe4d9('0x2b')](respondWithResult(_0x354259,null))['catch'](handleError(_0x354259,null));};exports[_0xe4d9('0x6e')]=function(_0x5442b7,_0x28fb7d){if(_0x5442b7[_0xe4d9('0x5f')]['id']){delete _0x5442b7[_0xe4d9('0x5f')]['id'];}return db[_0xe4d9('0x48')]['find']({'where':{'id':_0x5442b7[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x28fb7d,null))['then'](function(_0x23bcfe){if(_0x23bcfe){_0x5442b7[_0xe4d9('0x5f')]['ChatWebsiteId']=_0x23bcfe['id'];return db[_0xe4d9('0x6f')][_0xe4d9('0x63')](_0x5442b7[_0xe4d9('0x5f')]);}})[_0xe4d9('0x2b')](respondWithResult(_0x28fb7d,null))[_0xe4d9('0x1f')](handleError(_0x28fb7d,null));};exports[_0xe4d9('0x70')]=function(_0x28b900,_0x23d38f){var _0x3e1fd4={'raw':![],'where':{}};var _0x5429fa={};var _0xdfe0af={'count':0x0,'rows':[]};return db['ChatWebsite'][_0xe4d9('0x71')]({'where':{'id':_0x28b900['params']['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x23d38f,null))[_0xe4d9('0x2b')](function(_0x1a7596){if(_0x1a7596){_0x5429fa[_0xe4d9('0x4b')]=_[_0xe4d9('0x5b')](db[_0xe4d9('0x6f')][_0xe4d9('0x49')]);_0x5429fa[_0xe4d9('0x4c')]=_['keys'](_0x28b900[_0xe4d9('0x4c')]);_0x5429fa[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x5429fa[_0xe4d9('0x4b')],_0x5429fa[_0xe4d9('0x4c')]);_0x3e1fd4[_0xe4d9('0x4f')]=_[_0xe4d9('0x4e')](_0x5429fa[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x28b900[_0xe4d9('0x4c')][_0xe4d9('0x50')]));_0x3e1fd4[_0xe4d9('0x4f')]=_0x3e1fd4[_0xe4d9('0x4f')]['length']?_0x3e1fd4[_0xe4d9('0x4f')]:_0x5429fa[_0xe4d9('0x4b')];if(!_0x28b900['query'][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x3e1fd4['limit']=qs[_0xe4d9('0x24')](_0x28b900[_0xe4d9('0x4c')][_0xe4d9('0x24')]);_0x3e1fd4[_0xe4d9('0x26')]=qs[_0xe4d9('0x26')](_0x28b900[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}_0x3e1fd4[_0xe4d9('0x54')]=qs[_0xe4d9('0x55')](_0x28b900[_0xe4d9('0x4c')][_0xe4d9('0x55')]);_0x3e1fd4[_0xe4d9('0x56')]=qs[_0xe4d9('0x4d')](_['pick'](_0x28b900['query'],_0x5429fa['filters']));_0x3e1fd4[_0xe4d9('0x56')][_0xe4d9('0x72')]=_0x1a7596['id'];if(_0x28b900['query']['filter']){_0x3e1fd4[_0xe4d9('0x56')]=_['merge'](_0x3e1fd4[_0xe4d9('0x56')],{'$or':_['map'](_0x3e1fd4[_0xe4d9('0x4f')],function(_0x133f5a){var _0x5b2782={};_0x5b2782[_0x133f5a]={'$like':'%'+_0x28b900[_0xe4d9('0x4c')][_0xe4d9('0x73')]+'%'};return _0x5b2782;})});}_0x3e1fd4=_[_0xe4d9('0x58')]({},_0x3e1fd4,_0x28b900['options']);return db[_0xe4d9('0x6f')][_0xe4d9('0x25')]({'where':_0x3e1fd4[_0xe4d9('0x56')]})[_0xe4d9('0x2b')](function(_0xaab18c){_0xdfe0af[_0xe4d9('0x25')]=_0xaab18c;if(_0x28b900[_0xe4d9('0x4c')][_0xe4d9('0x5c')]){_0x3e1fd4[_0xe4d9('0x5d')]=[{'all':!![]}];}return db[_0xe4d9('0x6f')][_0xe4d9('0x74')](_0x3e1fd4);})[_0xe4d9('0x2b')](function(_0x1936ab){_0xdfe0af[_0xe4d9('0x75')]=_0x1936ab;return _0xdfe0af;});}})[_0xe4d9('0x2b')](respondWithFilteredResult(_0x23d38f,_0x3e1fd4))[_0xe4d9('0x1f')](handleError(_0x23d38f,null));};exports[_0xe4d9('0x76')]=function(_0x35af23,_0x2c1ac4){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x35af23[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x2c1ac4,null))[_0xe4d9('0x2b')](function(_0x558f1e){if(_0x558f1e){return _0x558f1e[_0xe4d9('0x76')](_0x35af23[_0xe4d9('0x4c')][_0xe4d9('0x77')]);}})[_0xe4d9('0x2b')](respondWithStatusCode(_0x2c1ac4,null))[_0xe4d9('0x1f')](handleError(_0x2c1ac4,null));};exports['addAnswer']=function(_0x2dcdf9,_0x57adb6){if(_0x2dcdf9[_0xe4d9('0x5f')]['id']){delete _0x2dcdf9[_0xe4d9('0x5f')]['id'];}return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x2dcdf9[_0xe4d9('0x6c')]['id']}})['then'](handleEntityNotFound(_0x57adb6,null))[_0xe4d9('0x2b')](function(_0x27404d){if(_0x27404d){_0x2dcdf9[_0xe4d9('0x5f')][_0xe4d9('0x72')]=_0x27404d['id'];return db['CannedAnswer']['create'](_0x2dcdf9[_0xe4d9('0x5f')]);}})[_0xe4d9('0x2b')](respondWithResult(_0x57adb6,null))['catch'](handleError(_0x57adb6,null));};exports[_0xe4d9('0x78')]=function(_0x35a316,_0x312699){var _0x2ab4a3={'raw':![],'where':{}};var _0x40a04f={};var _0x28c84a={'count':0x0,'rows':[]};return db[_0xe4d9('0x48')][_0xe4d9('0x71')]({'where':{'id':_0x35a316[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x312699,null))[_0xe4d9('0x2b')](function(_0x52a87d){if(_0x52a87d){_0x40a04f[_0xe4d9('0x4b')]=_['keys'](db['CannedAnswer']['rawAttributes']);_0x40a04f[_0xe4d9('0x4c')]=_[_0xe4d9('0x5b')](_0x35a316[_0xe4d9('0x4c')]);_0x40a04f[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x40a04f[_0xe4d9('0x4b')],_0x40a04f[_0xe4d9('0x4c')]);_0x2ab4a3['attributes']=_[_0xe4d9('0x4e')](_0x40a04f[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x35a316[_0xe4d9('0x4c')][_0xe4d9('0x50')]));_0x2ab4a3['attributes']=_0x2ab4a3[_0xe4d9('0x4f')][_0xe4d9('0x51')]?_0x2ab4a3['attributes']:_0x40a04f[_0xe4d9('0x4b')];if(!_0x35a316[_0xe4d9('0x4c')][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x2ab4a3['limit']=qs[_0xe4d9('0x24')](_0x35a316['query'][_0xe4d9('0x24')]);_0x2ab4a3[_0xe4d9('0x26')]=qs[_0xe4d9('0x26')](_0x35a316[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}_0x2ab4a3[_0xe4d9('0x54')]=qs[_0xe4d9('0x55')](_0x35a316['query']['sort']);_0x2ab4a3[_0xe4d9('0x56')]=qs[_0xe4d9('0x4d')](_[_0xe4d9('0x57')](_0x35a316[_0xe4d9('0x4c')],_0x40a04f['filters']));_0x2ab4a3['where']['ChatWebsiteId']=_0x52a87d['id'];if(_0x35a316[_0xe4d9('0x4c')][_0xe4d9('0x73')]){_0x2ab4a3[_0xe4d9('0x56')]=_[_0xe4d9('0x58')](_0x2ab4a3[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x2ab4a3[_0xe4d9('0x4f')],function(_0x3d0dca){var _0x57a98f={};_0x57a98f[_0x3d0dca]={'$like':'%'+_0x35a316[_0xe4d9('0x4c')][_0xe4d9('0x73')]+'%'};return _0x57a98f;})});}_0x2ab4a3=_['merge']({},_0x2ab4a3,_0x35a316['options']);return db[_0xe4d9('0x79')][_0xe4d9('0x25')]({'where':_0x2ab4a3[_0xe4d9('0x56')]})[_0xe4d9('0x2b')](function(_0x5bf730){_0x28c84a[_0xe4d9('0x25')]=_0x5bf730;if(_0x35a316[_0xe4d9('0x4c')]['includeAll']){_0x2ab4a3[_0xe4d9('0x5d')]=[{'all':!![]}];}return db['CannedAnswer'][_0xe4d9('0x74')](_0x2ab4a3);})['then'](function(_0x317cec){_0x28c84a['rows']=_0x317cec;return _0x28c84a;});}})[_0xe4d9('0x2b')](respondWithFilteredResult(_0x312699,_0x2ab4a3))[_0xe4d9('0x1f')](handleError(_0x312699,null));};exports[_0xe4d9('0x7a')]=function(_0x393384,_0x255b71){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x393384[_0xe4d9('0x6c')]['id']}})['then'](handleEntityNotFound(_0x255b71,null))[_0xe4d9('0x2b')](function(_0x552a22){if(_0x552a22){return _0x552a22[_0xe4d9('0x7a')](_0x393384[_0xe4d9('0x4c')][_0xe4d9('0x77')]);}})[_0xe4d9('0x2b')](respondWithStatusCode(_0x255b71,null))[_0xe4d9('0x1f')](handleError(_0x255b71,null));};exports[_0xe4d9('0x7b')]=function(_0x543c7b,_0x308859){_0x543c7b[_0xe4d9('0x5f')][_0xe4d9('0x7c')]=_0x543c7b[_0xe4d9('0x7d')][_0xe4d9('0x7e')];return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x543c7b[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x308859,null))['then'](saveUpdates(_0x543c7b['body'],null))[_0xe4d9('0x2b')](respondWithResult(_0x308859,null))[_0xe4d9('0x1f')](handleError(_0x308859,null));};exports[_0xe4d9('0x7f')]=function(_0x280160,_0x5a5446){_0x280160[_0xe4d9('0x5f')]['agentAvatar']=_0x280160[_0xe4d9('0x7d')][_0xe4d9('0x7e')];return db['ChatWebsite']['find']({'where':{'id':_0x280160[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x5a5446,null))[_0xe4d9('0x2b')](saveUpdates(_0x280160[_0xe4d9('0x5f')],null))[_0xe4d9('0x2b')](respondWithResult(_0x5a5446,null))[_0xe4d9('0x1f')](handleError(_0x5a5446,null));};exports[_0xe4d9('0x80')]=function(_0x2af820,_0x4fdebb){_0x2af820[_0xe4d9('0x5f')][_0xe4d9('0x81')]=_0x2af820[_0xe4d9('0x7d')]['filename'];return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x2af820['params']['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x4fdebb,null))[_0xe4d9('0x2b')](saveUpdates(_0x2af820[_0xe4d9('0x5f')],null))[_0xe4d9('0x2b')](respondWithResult(_0x4fdebb,null))[_0xe4d9('0x1f')](handleError(_0x4fdebb,null));};exports['addSystemAvatar']=function(_0x3e69ba,_0x53aa65){_0x3e69ba['body'][_0xe4d9('0x82')]=_0x3e69ba[_0xe4d9('0x7d')]['filename'];return db['ChatWebsite'][_0xe4d9('0x5e')]({'where':{'id':_0x3e69ba[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x53aa65,null))[_0xe4d9('0x2b')](saveUpdates(_0x3e69ba[_0xe4d9('0x5f')],null))[_0xe4d9('0x2b')](respondWithResult(_0x53aa65,null))[_0xe4d9('0x1f')](handleError(_0x53aa65,null));};exports[_0xe4d9('0x83')]=function(_0x1794e1,_0x59dcff){var _0x175eed=path['join'](config['root'],_0xe4d9('0x84'));var _0x7e202d={'where':{'id':_0x1794e1['params']['id']},'attributes':['id','sitepic'],'raw':!![]};var _0x576fcf=![];return require(_0xe4d9('0x85'))['getLicense']()[_0xe4d9('0x2b')](function(_0x4c8cd1){if(_0x4c8cd1){_0x576fcf=_0x4c8cd1[_0xe4d9('0x86')];}})[_0xe4d9('0x2b')](function(){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')](_0x7e202d);})['then'](handleEntityNotFound(_0x59dcff,null))[_0xe4d9('0x2b')](function(_0x14b55f){if(_0x14b55f){if(!_[_0xe4d9('0x87')](_0x14b55f[_0xe4d9('0x7c')])){if(fs[_0xe4d9('0x88')](path['join'](config['root'],_0xe4d9('0x89'),_0x14b55f[_0xe4d9('0x7c')]))&&_0x576fcf){_0x175eed=path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0x89'),_0x14b55f[_0xe4d9('0x7c')]);}}return _0x59dcff['download'](_0x175eed);}})[_0xe4d9('0x1f')](handleError(_0x59dcff,null));};exports['getAvatar']=function(_0x5e6f0f,_0x1fbcad){var _0x446551=path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0x8c'));var _0x4eb401={'where':{'id':_0x5e6f0f[_0xe4d9('0x6c')]['id']},'attributes':['id','agentAvatar'],'raw':!![]};return db[_0xe4d9('0x48')][_0xe4d9('0x5e')](_0x4eb401)[_0xe4d9('0x2b')](handleEntityNotFound(_0x1fbcad,null))['then'](function(_0x392bef){if(_0x392bef){if(!_['isNil'](_0x392bef['agentAvatar'])){if(fs[_0xe4d9('0x88')](path[_0xe4d9('0x8a')](config['root'],'server/files/images/avatars/',_0x392bef[_0xe4d9('0x8d')]))){_0x446551=path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0x8e'),_0x392bef[_0xe4d9('0x8d')]);}}return _0x1fbcad[_0xe4d9('0x8f')](_0x446551);}})[_0xe4d9('0x1f')](handleError(_0x1fbcad,null));};exports['getCustomerAvatar']=function(_0x4c69ee,_0x704678){var _0x22ef03=path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],'server/files/images/avatars/customer_avatar.png');var _0x15ad99={'where':{'id':_0x4c69ee[_0xe4d9('0x6c')]['id']},'attributes':['id',_0xe4d9('0x81'),_0xe4d9('0x90')],'raw':!![]};return db[_0xe4d9('0x48')][_0xe4d9('0x5e')](_0x15ad99)[_0xe4d9('0x2b')](handleEntityNotFound(_0x704678,null))[_0xe4d9('0x2b')](function(_0x41ff9f){if(_0x41ff9f){if(!_[_0xe4d9('0x87')](_0x41ff9f['customerAvatar'])){if(fs[_0xe4d9('0x88')](path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0x8e'),_0x41ff9f[_0xe4d9('0x81')]))&&_0x41ff9f[_0xe4d9('0x90')]){_0x22ef03=path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0x8e'),_0x41ff9f['customerAvatar']);}}return _0x704678[_0xe4d9('0x8f')](_0x22ef03);}})[_0xe4d9('0x1f')](handleError(_0x704678,null));};exports[_0xe4d9('0x91')]=function(_0x4cacc0,_0x4697d0){var _0x538db5=path[_0xe4d9('0x8a')](config['root'],'server/files/images/avatars/system_avatar.png');var _0x5839c5={'where':{'id':_0x4cacc0[_0xe4d9('0x6c')]['id']},'attributes':['id','systemAvatar'],'raw':!![]};return db['ChatWebsite'][_0xe4d9('0x5e')](_0x5839c5)[_0xe4d9('0x2b')](handleEntityNotFound(_0x4697d0,null))[_0xe4d9('0x2b')](function(_0x4e0e73){if(_0x4e0e73){if(!_[_0xe4d9('0x87')](_0x4e0e73[_0xe4d9('0x82')])){if(fs[_0xe4d9('0x88')](path['join'](config[_0xe4d9('0x8b')],_0xe4d9('0x8e'),_0x4e0e73[_0xe4d9('0x82')]))){_0x538db5=path[_0xe4d9('0x8a')](config['root'],_0xe4d9('0x8e'),_0x4e0e73[_0xe4d9('0x82')]);}}return _0x4697d0['download'](_0x538db5);}})[_0xe4d9('0x1f')](handleError(_0x4697d0,null));};function checkWebsiteInterval(_0x46c5c4){var _0xed4466=_0x46c5c4[_0xe4d9('0x92')];if(!_0xed4466){return Promise[_0xe4d9('0x93')](_0x46c5c4);}var _0x3d5ad2=_0x46c5c4[_0xe4d9('0x94')]||undefined;return _0xed4466[_0xe4d9('0x95')](_0x3d5ad2)['then'](function(_0x1d1b63){if(!_0x1d1b63){throw new APIOutOfIntervalError();}return _0x46c5c4;});}exports[_0xe4d9('0x96')]=function(_0x15945a,_0x3c2a9e){var _0x7f62c6={'body':_0x15945a[_0xe4d9('0x5f')],'channel':_0xe4d9('0x97')};var _0x1dadff=[];var _0x36584b=[];var _0x388c77={};var _0x5d2e5a=![];if(_0x15945a[_0xe4d9('0x5f')]['id']){delete _0x15945a[_0xe4d9('0x5f')]['id'];}if(_['isNil'](_0x15945a['body'][_0xe4d9('0x98')])){throw new APIBadRequestError(_0xe4d9('0x99'));}if(_[_0xe4d9('0x87')](_0x15945a['body'][_0xe4d9('0x9a')])){throw new APIBadRequestError(_0xe4d9('0x9b'));}if(_['isEmpty'](_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x5f')])){throw new APIBadRequestError(_0xe4d9('0x9c'));}var _0xcfc051=_0x15945a['body'][_0xe4d9('0x9d')]&&_0x15945a['body']['referer'];return db[_0xe4d9('0x9e')][_0xe4d9('0x6d')]()['then'](function(_0x1571e8){if(!_0x1571e8){throw new Error('No\x20available\x20attributes');}_0x1dadff=Object[_0xe4d9('0x5b')](_0x1571e8)['filter'](function(_0x230c52){return![_0xe4d9('0x9f'),_0xe4d9('0xa0')]['includes'](_0x230c52);});_0x36584b=Object[_0xe4d9('0x5b')](_0x1571e8)['filter'](function(_0x248782){return![_0xe4d9('0x9f'),'updatedAt',_0xe4d9('0xa1'),'ListId'][_0xe4d9('0xa2')](_0x248782);});if(!_[_0xe4d9('0xa2')](_0x36584b,_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x9a')])){throw new APIBadRequestError(_0xe4d9('0xa3')+_0x36584b[_0xe4d9('0x8a')](',\x20'));}_0x388c77[_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x9a')]]=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x98')];})[_0xe4d9('0x2b')](function(){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x15945a[_0xe4d9('0x6c')]['id']},'include':[{'model':db['CmList'],'as':_0xe4d9('0xa4'),'include':[{'model':db[_0xe4d9('0x9e')],'as':_0xe4d9('0xa5'),'where':_0x388c77,'limit':0x1,'order':[[_0xe4d9('0xa0'),_0xe4d9('0xa6')]]}]},{'model':db[_0xe4d9('0xa7')],'as':_0xe4d9('0xa8')},{'model':db['Interval'],'as':_0xe4d9('0x92'),'include':[{'model':db[_0xe4d9('0x92')],'as':_0xe4d9('0xa9'),'attributes':['id','interval'],'raw':!![]}]}]});})[_0xe4d9('0x2b')](function(_0x1c04ed){if(!_0x1c04ed){throw new APINotFoundError(util[_0xe4d9('0x3c')](_0xe4d9('0xaa'),_0x15945a[_0xe4d9('0x6c')]['id']));}if(_0xcfc051){return checkWebsiteInterval(_0x1c04ed);}return _0x1c04ed;})[_0xe4d9('0x2b')](function(_0x2e0efe){_0x7f62c6[_0xe4d9('0xab')]=_0x2e0efe;_0x7f62c6[_0xe4d9('0xac')]=_[_0xe4d9('0xad')](_0x2e0efe[_0xe4d9('0xa8')],[_0xe4d9('0xae')],[_0xe4d9('0xaf')]);if(_0x7f62c6[_0xe4d9('0xab')][_0xe4d9('0xa8')]){delete _0x7f62c6[_0xe4d9('0xab')][_0xe4d9('0xa8')];}_0x7f62c6['list']=_0x2e0efe[_0xe4d9('0xa4')]||{'id':_0x2e0efe['ListId']};if(_0x7f62c6[_0xe4d9('0xb0')]&&_0x7f62c6['list']['Contacts'][_0xe4d9('0x51')]){return _0x7f62c6['list'][_0xe4d9('0xa5')][0x0];}var _0x1ada99=_[_0xe4d9('0x13')](_0x15945a[_0xe4d9('0x5f')],{'firstName':_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x98')],'ListId':_0x2e0efe[_0xe4d9('0xb1')]});_0x1ada99[_0x15945a['body'][_0xe4d9('0x9a')]]=_0x15945a[_0xe4d9('0x5f')]['from'];return db['CmContact']['create'](_0x1ada99,{'fields':_0x1dadff,'raw':!![]});})[_0xe4d9('0x2b')](function(_0x383dcf){_0x7f62c6['contact']=_0x383dcf;var _0x34b65=createInteractionObject(_0x15945a[_0xe4d9('0x6c')]['id'],_0x15945a[_0xe4d9('0x5f')],_0x15945a[_0xe4d9('0xb2')],_0x383dcf);var _0x398aad={'ChatWebsiteId':_0x15945a[_0xe4d9('0x6c')]['id']};if(_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xb3')]){_0x398aad['threadId']=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xb3')];_0x398aad[_0xe4d9('0xb4')]=![];return db[_0xe4d9('0xb5')][_0xe4d9('0x5e')]({'where':_0x398aad})['then'](function(_0x3b639e){var _0x1f6960=_0x15945a['body'][_0xe4d9('0x9d')]&&_0x15945a['body'][_0xe4d9('0xb6')];if(_0x3b639e){_0x5d2e5a=!![];return _0x3b639e;}else if(!_0x1f6960&&_0x3b639e&&_0x3b639e[_0xe4d9('0xb4')]){throw new APIConflictError(_0xe4d9('0xb7'));}_0x34b65[_0xe4d9('0xb3')]=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xb3')];_0x34b65[_0xe4d9('0xb8')]=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xb8')];return db[_0xe4d9('0xb5')][_0xe4d9('0x63')](_0x34b65);});}_0x398aad[_0xe4d9('0xb9')]=_0x383dcf['id'];if(_0x15945a['body'][_0xe4d9('0xba')]&&_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xba')]['id']){_0x398aad['id']=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xba')]['id'];return db[_0xe4d9('0xb5')][_0xe4d9('0x5e')]({'where':_0x398aad})[_0xe4d9('0x2b')](function(_0x3d56d6){var _0x8c2807=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x9d')]&&_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xb6')];if(!_0x8c2807&&_0x3d56d6&&_0x3d56d6['closed']){throw new APIConflictError(_0xe4d9('0xb7'));}else if(_0x3d56d6){_0x5d2e5a=!![];return _0x3d56d6;}else{return db[_0xe4d9('0xb5')][_0xe4d9('0x63')](_0x34b65);}});}return db[_0xe4d9('0xb5')][_0xe4d9('0x63')](_0x34b65);})[_0xe4d9('0x2b')](function(_0x133565){if(!_0x5d2e5a){return _0x133565;}var _0x3da039={'from':(_0x7f62c6['contact']['firstName']||'')+'\x20'+(_0x7f62c6[_0xe4d9('0xbb')]['lastName']||'')};if(_0x15945a['body'][_0xe4d9('0xb3')]&&_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xbc')]&&_0x15945a['body']['threadId']!=_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0xbc')]){_0x3da039[_0xe4d9('0xb3')]=_0x15945a['body'][_0xe4d9('0xbc')];}return _0x133565[_0xe4d9('0x29')](_0x3da039);})[_0xe4d9('0x2b')](function(_0x4e384c){_0x7f62c6[_0xe4d9('0xba')]=_0x4e384c['get']({'plain':!![]});_0x7f62c6[_0xe4d9('0xba')][_0xe4d9('0xbd')]=!_0x5d2e5a;if(_0x7f62c6[_0xe4d9('0xba')][_0xe4d9('0xbd')]){if(_0x7f62c6[_0xe4d9('0xab')]['autoclose']){_0x7f62c6[_0xe4d9('0xac')]['push']({'id':0x0,'priority':_0x7f62c6[_0xe4d9('0xac')][_0xe4d9('0x51')]+0x1,'app':'close','appdata':'unmanaged','interval':_0xe4d9('0xbe')});}}return db['ChatMessage'][_0xe4d9('0x63')]({'body':_0x15945a[_0xe4d9('0x5f')][_0xe4d9('0x5f')],'ChatWebsiteId':_0x15945a[_0xe4d9('0x6c')]['id'],'ChatInteractionId':_0x4e384c['id'],'direction':'in','ContactId':_0x7f62c6[_0xe4d9('0xbb')]['id'],'AttachmentId':_0x15945a[_0xe4d9('0x5f')]['AttachmentId']});})[_0xe4d9('0x2b')](function(_0x55da19){_0x7f62c6[_0xe4d9('0x1d')]=_0x55da19;if(!_0x7f62c6[_0xe4d9('0xba')][_0xe4d9('0xbf')]){return;}return db['User'][_0xe4d9('0x5e')]({'attributes':['id',_0xe4d9('0x2f')],'where':{'id':_0x7f62c6[_0xe4d9('0xba')]['UserId']}});})[_0xe4d9('0x2b')](function(_0x2c508a){if(_0x2c508a){_0x7f62c6[_0xe4d9('0xac')][_0xe4d9('0xc0')]({'id':0x0,'priority':0x0,'app':_0xe4d9('0xc1'),'appdata':_0x2c508a[_0xe4d9('0x2f')]+','+(_0x7f62c6[_0xe4d9('0xab')][_0xe4d9('0xc2')]||0xa),'interval':_0xe4d9('0xbe')});_0x7f62c6[_0xe4d9('0xc3')]=!![];}if(!_0x7f62c6[_0xe4d9('0xba')][_0xe4d9('0xc4')]){return;}return db[_0xe4d9('0xc5')][_0xe4d9('0x5e')]({'attributes':['id',_0xe4d9('0x2f')],'where':{'id':_0x7f62c6[_0xe4d9('0xba')][_0xe4d9('0xc4')]}});})[_0xe4d9('0x2b')](function(_0x5c623f){if(_0x5c623f){_0x7f62c6[_0xe4d9('0xac')]['unshift']({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x5c623f['name']+','+(_0x7f62c6[_0xe4d9('0xab')][_0xe4d9('0xc6')]||0x12c),'interval':_0xe4d9('0xbe')});}return respondWithRpcPromise(_0xe4d9('0xc7'),_0xe4d9('0xc8'),_0x7f62c6);})[_0xe4d9('0x2b')](function(_0x94f6a7){respondWithRpcPromise(_0xe4d9('0xc9'),_0xe4d9('0xc9'),{'event':'notify','message':_0x94f6a7},client9002);return _0x94f6a7;})['then'](respondWithResult(_0x3c2a9e,null))['catch'](APIHandleError(_0x3c2a9e));};exports[_0xe4d9('0xca')]=function(_0x4b4548,_0x3494df){var _0x4df66a,_0x17d710,_0x41c729;var _0x578769=[];var _0x50a75a={};var _0x5864db=_0x4b4548['files']||[];var _0x19e9ed=[];var _0x5e6be9;return db[_0xe4d9('0x9e')][_0xe4d9('0x6d')]()['then'](function(_0x1f325d){if(!_0x1f325d){throw new db[(_0xe4d9('0xcb'))]['ValidationError']('no\x20available\x20attributes');}_0x578769=_['difference'](_[_0xe4d9('0x5b')](_0x1f325d),[_0xe4d9('0x9f'),_0xe4d9('0xa0'),_0xe4d9('0xa1'),_0xe4d9('0xb1')]);if(_0x4b4548[_0xe4d9('0x5f')]['id']){delete _0x4b4548[_0xe4d9('0x5f')]['id'];}if(_[_0xe4d9('0x87')](_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0x98')])){throw _0x3494df['status'](0x1f4)[_0xe4d9('0x30')](new db['Sequelize'][(_0xe4d9('0xcc'))](_0xe4d9('0xcd')));}if(_[_0xe4d9('0x87')](_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0x5f')])||_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0x5f')]===''){throw _0x3494df[_0xe4d9('0x20')](0x1f4)[_0xe4d9('0x30')](new db[(_0xe4d9('0xcb'))]['ValidationError'](_0xe4d9('0xce')));}if(_[_0xe4d9('0x87')](_0x4b4548['body']['mapKeyOffline'])){throw _0x3494df['status'](0x1f4)[_0xe4d9('0x30')](new db[(_0xe4d9('0xcb'))]['ValidationError'](_0xe4d9('0xcf')+_0x578769));}if(!_[_0xe4d9('0xa2')](_0x578769,_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0xd0')])){throw _0x3494df[_0xe4d9('0x20')](0x1f4)[_0xe4d9('0x30')](new db[(_0xe4d9('0xcb'))]['ValidationError'](_0xe4d9('0xd1')+_0x578769));}_0x50a75a[_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0xd0')]]=_0x4b4548['body']['from'];})['then'](function(){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0x4b4548[_0xe4d9('0x6c')]['id']},'include':[{'model':db[_0xe4d9('0xd2')],'as':_0xe4d9('0xa4')},{'model':db[_0xe4d9('0xd3')],'as':'MailAccount'}]});})[_0xe4d9('0x2b')](handleEntityNotFound(_0x3494df,null))['then'](function(_0x2c7c2a){if(_0x2c7c2a&&_0x2c7c2a[_0xe4d9('0xa4')]){_0x17d710=_0x2c7c2a;var _0xb81039=_['defaults'](_0x4b4548[_0xe4d9('0x5f')],{'firstName':_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0x98')],'phone':_0x4b4548['body'][_0xe4d9('0x98')],'ListId':_0x2c7c2a[_0xe4d9('0xb1')]});_0xb81039[_0x4b4548['body']['mapKeyOffline']]=_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0x98')];return db[_0xe4d9('0x9e')][_0xe4d9('0xd4')]({'where':_0x50a75a,'defaults':_0xb81039});}})[_0xe4d9('0xd5')](function(_0x37c884){if(_0x37c884){_0x41c729=_0x37c884;var _0x47c661=fs[_0xe4d9('0xd6')](path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],'server/files/templates/chatOfflineMessage.ejs'),'utf8');var _0x4b3324=ejs[_0xe4d9('0xd7')](_0x47c661,{'body':_['toPairs'](_0x4b4548[_0xe4d9('0x5f')][_0xe4d9('0x5f')]),'bodyTitle':_0x17d710[_0xe4d9('0xd8')]});return db[_0xe4d9('0xd9')]['create']({'body':_0x4b3324,'plainBody':htmlToText['fromString'](_0x4b3324),'ContactId':_0x37c884['id'],'ChatWebsiteId':_0x17d710['id']});}})[_0xe4d9('0x2b')](function(_0x4410e7){_0x5e6be9=_0x4410e7;if(_0x5864db[_0xe4d9('0x51')]){var _0x5480dc=_0x5864db['map'](function(_0x1c999a){return{'name':_0x1c999a[_0xe4d9('0xda')],'basename':_0x1c999a[_0xe4d9('0x7e')],'type':_0x1c999a[_0xe4d9('0xdb')],'ChatOfflineMessageId':_0x4410e7['id']};});_0x19e9ed=_0x5480dc[_0xe4d9('0x47')](_0xbc8304=>{var _0x1355cb={'filename':_0xbc8304[_0xe4d9('0x2f')],'path':path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0xdc'),_0xe4d9('0xdd'),_0xe4d9('0xde'),_0xe4d9('0xdf'),_0xbc8304['basename'])};return _0x1355cb;});if(!_0x17d710[_0xe4d9('0xe0')]){return db['sequelize'][_0xe4d9('0xe1')](function(_0xa771fe){return db[_0xe4d9('0xe2')][_0xe4d9('0xe3')](_0x5480dc,{'transaction':_0xa771fe});});}}})[_0xe4d9('0x2b')](function(){if(_0x5e6be9){_0x4df66a=_0x5e6be9;return db[_0xe4d9('0xd3')][_0xe4d9('0x71')]({'where':{'service':!![]},'include':[{'model':db[_0xe4d9('0xe4')],'as':_0xe4d9('0xe5'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0xe4d9('0xe6'),'raw':!![]}]}]});}})['then'](function(_0x3f1f8b){if(_0x3f1f8b&&_0x3f1f8b[_0xe4d9('0xe5')]&&_0x17d710[_0xe4d9('0xe7')]&&_0x17d710[_0xe4d9('0xe8')]){var _0x4fe0ae=_0x3f1f8b[_0xe4d9('0xe9')]();return respondWithRpcPromise(_0xe4d9('0xea'),_0xe4d9('0xeb'),{'account':_0x4fe0ae,'message':{'from':util[_0xe4d9('0x3c')](_0xe4d9('0xec'),_0x3f1f8b[_0xe4d9('0x2f')],_0x3f1f8b[_0xe4d9('0xed')]||_0x3f1f8b[_0xe4d9('0xe5')][_0xe4d9('0x64')]),'to':_0x17d710[_0xe4d9('0xe8')],'subject':_0x17d710[_0xe4d9('0xee')],'html':_0x4df66a[_0xe4d9('0x5f')],'attachments':_0x19e9ed}},client9003)[_0xe4d9('0x2b')](function(){return _0x4df66a;})['catch'](function(_0x33252b){logger['error'](_0x33252b);});}})[_0xe4d9('0x2b')](function(){if(_0x17d710&&_0x17d710['openNewInteraction']&&_0x17d710['MailAccountId']){var _0x31fbc7=[];if(_0x5864db['length']){_0x31fbc7=_0x5864db[_0xe4d9('0x47')](function(_0x19b039){return{'name':_0x19b039[_0xe4d9('0xda')],'basename':_0x19b039[_0xe4d9('0x7e')],'type':_0x19b039[_0xe4d9('0xdb')],'ChatOfflineMessageId':_0x5e6be9['id']};});}var _0x16f465;if(!_[_0xe4d9('0x87')](_0x17d710[_0xe4d9('0xef')])){var _0x58e7d9=_[_0xe4d9('0x47')](_0x4b4548['body'],function(_0x3ba744){return _0x3ba744;});var _0x1b7d64=_[_0xe4d9('0xf0')](_0x58e7d9)[0x0];var _0x20b63f=_[_0xe4d9('0xf1')](_0x1b7d64,function(_0x1387ea){return _0x1387ea;});_0x16f465=_0x20b63f[0x1][_0x17d710[_0xe4d9('0xef')]];}var _0x11a94e={'from':_0x41c729[_0xe4d9('0xed')],'firstName':_0x41c729[_0xe4d9('0x38')],'lastName':_0x41c729[_0xe4d9('0x39')],'mapKey':_0xe4d9('0xed'),'message':{'from':_0x41c729[_0xe4d9('0xed')],'to':_0x17d710[_0xe4d9('0xd3')][_0xe4d9('0xed')],'cc':'','subject':_[_0xe4d9('0x87')](_0x16f465)?_0x17d710[_0xe4d9('0xee')]:_0x16f465,'messageId':'','sentAt':new Date(),'attach':_0x31fbc7[_0xe4d9('0x51')],'attachments':_0x31fbc7,'originChannel':_0xe4d9('0xf2'),'ChatWebsiteId':_0x17d710['id'],'ChatOfflineMessageId':_0x4df66a['id'],'originTo':_0x17d710['MailAccount'][_0xe4d9('0xed')]},'body':_0x4df66a[_0xe4d9('0x5f')]};var _0x510c47={'account':{'id':_0x17d710['MailAccountId']},'body':_0x11a94e,'log':_0xe4d9('0xf3')};return respondWithRpcPromise(_0xe4d9('0xf3'),'notifyMail',_0x510c47,client9001)[_0xe4d9('0x2b')](function(){return _0x4df66a;})[_0xe4d9('0x1f')](function(_0x1c3706){logger[_0xe4d9('0x1a')](_0x1c3706);});}return;})[_0xe4d9('0x2b')](function(){if(_0x4df66a){return _0x4df66a;}})[_0xe4d9('0x2b')](respondWithResult(_0x3494df,null))[_0xe4d9('0x1f')](function(){for(var _0x395f5d of _0x5864db){var _0x1c671a=path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0xdc'),_0xe4d9('0xdd'),_0xe4d9('0xde'),_0xe4d9('0xdf'),_0x395f5d['filename']);fs_extra['remove'](_0x1c671a)['catch'](function(_0x602b60){logger[_0xe4d9('0x1a')]('Could\x20not\x20remove\x20attachment\x20file',_0x1c671a,_0x602b60);});}});};exports[_0xe4d9('0xf4')]=function(_0x43791f,_0x5aaadb){return db[_0xe4d9('0xb5')]['find']({'where':{'id':_0x43791f[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x5aaadb,null))['then'](function(_0x466ed2){if(_0x466ed2){return _0x466ed2[_0xe4d9('0xf4')](_0x43791f[_0xe4d9('0x5f')][_0xe4d9('0x77')],_[_0xe4d9('0xf5')](_0x43791f['body'],[_0xe4d9('0x77'),'id'])||{});}})['then'](respondWithResult(_0x5aaadb,null))['catch'](handleError(_0x5aaadb,null));};exports[_0xe4d9('0xf6')]=function(_0x46e6f6,_0x1f00b4){var _0x3a5601={'raw':![],'where':{}};var _0x11d23e={};var _0x10108d={'count':0x0,'rows':[]};return db[_0xe4d9('0x48')]['findOne']({'where':{'id':_0x46e6f6['params']['id']}})['then'](handleEntityNotFound(_0x1f00b4,null))['then'](function(_0x41e499){if(_0x41e499){_0x11d23e['model']=_['keys'](db[_0xe4d9('0xb5')][_0xe4d9('0x49')]);_0x11d23e[_0xe4d9('0x4c')]=_['keys'](_0x46e6f6[_0xe4d9('0x4c')]);_0x11d23e[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x11d23e[_0xe4d9('0x4b')],_0x11d23e[_0xe4d9('0x4c')]);_0x3a5601[_0xe4d9('0x4f')]=_[_0xe4d9('0x4e')](_0x11d23e[_0xe4d9('0x4b')],qs['fields'](_0x46e6f6[_0xe4d9('0x4c')][_0xe4d9('0x50')]));_0x3a5601[_0xe4d9('0x4f')]=_0x3a5601[_0xe4d9('0x4f')][_0xe4d9('0x51')]?_0x3a5601[_0xe4d9('0x4f')]:_0x11d23e['model'];if(!_0x46e6f6[_0xe4d9('0x4c')][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x3a5601[_0xe4d9('0x24')]=qs[_0xe4d9('0x24')](_0x46e6f6[_0xe4d9('0x4c')][_0xe4d9('0x24')]);_0x3a5601['offset']=qs[_0xe4d9('0x26')](_0x46e6f6[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}_0x3a5601[_0xe4d9('0x54')]=qs['sort'](_0x46e6f6[_0xe4d9('0x4c')]['sort']);_0x3a5601['where']=qs[_0xe4d9('0x4d')](_[_0xe4d9('0x57')](_0x46e6f6['query'],_0x11d23e[_0xe4d9('0x4d')]));_0x3a5601[_0xe4d9('0x56')]['ChatWebsiteId']=_0x41e499['id'];if(_0x46e6f6[_0xe4d9('0x4c')][_0xe4d9('0x73')]){_0x3a5601[_0xe4d9('0x56')]=_['merge'](_0x3a5601[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x3a5601[_0xe4d9('0x4f')],function(_0x42f7c3){var _0x115b46={};_0x115b46[_0x42f7c3]={'$like':'%'+_0x46e6f6['query'][_0xe4d9('0x73')]+'%'};return _0x115b46;})});}_0x3a5601=_['merge']({},_0x3a5601,_0x46e6f6[_0xe4d9('0x59')]);return db[_0xe4d9('0xb5')][_0xe4d9('0x25')]({'where':_0x3a5601['where']})[_0xe4d9('0x2b')](function(_0x3f8b57){_0x10108d[_0xe4d9('0x25')]=_0x3f8b57;if(_0x46e6f6['query'][_0xe4d9('0x5c')]){_0x3a5601[_0xe4d9('0x5d')]=[{'model':db[_0xe4d9('0x9e')],'as':_0xe4d9('0xf7'),'required':![]},{'model':db[_0xe4d9('0xf8')],'as':_0xe4d9('0xf9'),'attributes':[_0xe4d9('0x2f'),_0xe4d9('0xfa'),_0xe4d9('0xfb')],'required':![]},{'model':db[_0xe4d9('0xfc')],'as':'Tags','attributes':['id',_0xe4d9('0x2f'),_0xe4d9('0xfd')],'where':_0x46e6f6['query'][_0xe4d9('0xfe')]?{'id':_0x46e6f6['query'][_0xe4d9('0xfe')]}:undefined,'required':_0x46e6f6[_0xe4d9('0x4c')]['tag']?!![]:![]}];}return db[_0xe4d9('0xb5')][_0xe4d9('0x74')](_0x3a5601);})['then'](function(_0x226d54){_0x10108d[_0xe4d9('0x75')]=_0x226d54;return _0x10108d;});}})[_0xe4d9('0x2b')](respondWithFilteredResult(_0x1f00b4,_0x3a5601))[_0xe4d9('0x1f')](handleError(_0x1f00b4,null));};exports['getSnippet']=function(_0x372289,_0x5d8270){var _0x40989a=0x0;var _0x490b9f=0x0;var _0x227827=![];var _0x5abfee;var _0x4b964c;return db['ChatWebsite']['find']({'where':{'id':_0x372289[_0xe4d9('0x6c')]['id']},'include':[{'model':db[_0xe4d9('0x92')],'as':_0xe4d9('0x92'),'include':[{'model':db[_0xe4d9('0x92')],'as':_0xe4d9('0xa9'),'attributes':['id',_0xe4d9('0xff')]}]}]})[_0xe4d9('0x2b')](handleEntityNotFound(_0x5d8270,null))[_0xe4d9('0x2b')](function(_0x5b1059){if(_0x5b1059){_0x5abfee=_0x5b1059;return _0x5b1059[_0xe4d9('0x100')]({'raw':!![]});}})['then'](function(_0x34161d){if(_0x5abfee){if(_0x34161d){_0x4b964c=_0x34161d;}}return require(_0xe4d9('0x85'))[_0xe4d9('0x101')]();})['then'](function(_0x298917){if(_0x298917){_0x490b9f=_0x298917[_0xe4d9('0x102')];_0x227827=_0x298917[_0xe4d9('0x86')];}})[_0xe4d9('0x2b')](function(){return db[_0xe4d9('0xb5')][_0xe4d9('0x25')]({'where':{'closed':![]}});})['then'](function(_0x43abd5){_0x40989a=_0x43abd5;if(_0x490b9f&&_0x43abd5>_0x490b9f){return db['License']['findOne']({'where':{'id':0x1}})[_0xe4d9('0x2b')](function(_0x469323){if(_0x469323){_0x469323[_0xe4d9('0x103')](_0xe4d9('0x104'));}});}})['then'](function(){var _0x29aebc=_0x5abfee[_0xe4d9('0x92')];var _0xc06a39=_0x5abfee[_0xe4d9('0x94')]||undefined;return _0x29aebc?_0x29aebc['ifTime'](_0xc06a39):!![];})[_0xe4d9('0x2b')](function(_0x12f9f0){var _0x55a7da=fs[_0xe4d9('0xd6')](path[_0xe4d9('0x8a')](config[_0xe4d9('0x8b')],_0xe4d9('0x105')),_0xe4d9('0x106'));var _0x5756b3='3.10.1';var _0x50142a=![];var _0xb9fbd1,_0x15eec4;if(_0x372289[_0xe4d9('0xb2')][_0xe4d9('0xb6')]){_0xb9fbd1=new URL(_0x372289['headers'][_0xe4d9('0xb6')])[_0xe4d9('0x107')];}else if(_0x372289[_0xe4d9('0xb2')][_0xe4d9('0x107')]){_0xb9fbd1=new URL(_0x372289[_0xe4d9('0xb2')][_0xe4d9('0x107')])[_0xe4d9('0x107')];}else{_0xb9fbd1=_0xe4d9('0x108');}_0x15eec4=typeof _0x5abfee['address'][_0xe4d9('0x37')](',')[_0xe4d9('0x5e')](function(_0x182b98){return wildcardUtils['testWebsiteWithWildcard'](_0x182b98,_0xb9fbd1);})!==_0xe4d9('0x23');var _0x56718d={'chatVersion':_0x5756b3,'chatWebsiteAddressOrigin':_0x15eec4?_0xb9fbd1:_0x5abfee[_0xe4d9('0x60')],'remote':_0x5abfee[_0xe4d9('0x109')],'query':querystring[_0xe4d9('0x19')](_[_0xe4d9('0x58')](_0x5abfee[_0xe4d9('0x65')]({'plain':!![]}),{'customerIp':_0x372289[_0xe4d9('0xb2')]['x-forwarded-for']||_0x372289['headers'][_0xe4d9('0x10a')]||_0x372289[_0xe4d9('0x10b')][_0xe4d9('0x10c')]||_0x372289['ip'],'referer':_0x372289[_0xe4d9('0xb2')]['referer'],'openedInteractions':_0x40989a,'maxInteractions':_0x490b9f,'virtual':_0x227827[_0xe4d9('0x102')],'online':_0x12f9f0,'custom':_0x227827,'address':_0x15eec4?_0xb9fbd1:null}))[_0xe4d9('0x10d')](/'/g,'\x5c\x27')};_0x5d8270[_0xe4d9('0x30')](ejs['render'](Mustache[_0xe4d9('0xd7')](_0x55a7da,_0x56718d),{'proactiveActions':_0x4b964c,'alignment':_0x5abfee['alignment'],'verticalAlignment':_0x5abfee['verticalAlignment'],'div_color':_0x5abfee[_0xe4d9('0xfd')],'labelText':_0x5abfee[_0xe4d9('0x10e')],'text_color':_0x5abfee[_0xe4d9('0x10f')],'text_button_color':_0x5abfee['textButtonColor'],'button_color':_0x5abfee[_0xe4d9('0x110')],'background_color':_0x5abfee[_0xe4d9('0x111')],'hideWhenOffline':_0x5abfee[_0xe4d9('0x112')],'intervalId':_0x5abfee[_0xe4d9('0x113')],'isDevelopment':_0x50142a,'chatVersion':_0x5756b3}));})[_0xe4d9('0x1f')](handleError(_0x5d8270,null));};exports[_0xe4d9('0x114')]=function(_0x43f24a,_0x289c07){var _0x35975a=_0x43f24a[_0xe4d9('0x6c')]['id'];var _0x19b531=_0x43f24a[_0xe4d9('0x5f')];var _0x4b9b00=0xc8;var _0x38c655=null;return db[_0xe4d9('0x115')][_0xe4d9('0xe1')]({'isolationLevel':db['sequelize'][_0xe4d9('0x116')]['ISOLATION_LEVELS'][_0xe4d9('0x117')]},function(_0x5b304f){return db['ChatWebsite'][_0xe4d9('0x71')]({'where':{'id':_0x35975a},'transaction':_0x5b304f})[_0xe4d9('0x2b')](function(_0x30946d){if(_0x30946d){return db[_0xe4d9('0xa7')]['destroy']({'where':{'ChatWebsiteId':_0x35975a},'transaction':_0x5b304f})[_0xe4d9('0x2b')](function(){var _0x3c9f65=_['map'](_0x19b531,function(_0x5c82fb){_0x5c82fb[_0xe4d9('0x72')]=_0x35975a;return _0x5c82fb;});return db[_0xe4d9('0xa7')][_0xe4d9('0xe3')](_0x3c9f65,{'transaction':_0x5b304f});});}else{_0x4b9b00=0x194;_0x38c655=[];}});})[_0xe4d9('0x2b')](function(){if(_0x4b9b00!==0x194){return db[_0xe4d9('0xa7')][_0xe4d9('0x118')]({'where':{'ChatWebsiteId':_0x35975a},'order':_0xe4d9('0xae')})['then'](function(_0x3ee853){_0x38c655=_0x3ee853;});}})[_0xe4d9('0x1f')](function(_0x1f8a9b){_0x4b9b00=0x1f4;logger[_0xe4d9('0x1a')](_0x1f8a9b[_0xe4d9('0x2e')]);if(_0x1f8a9b['name']){delete _0x1f8a9b[_0xe4d9('0x2f')];}_0x38c655=_0x1f8a9b;})['finally'](function(){if(_0x38c655===null){_0x289c07[_0xe4d9('0x2d')](_0x4b9b00);}else{if(_0x4b9b00===0x1f4){_0x289c07['status'](_0x4b9b00)[_0xe4d9('0x30')](_0x38c655);}else{_0x289c07[_0xe4d9('0x20')](_0x4b9b00)[_0xe4d9('0x22')](_0x38c655);}}});};exports[_0xe4d9('0x119')]=function(_0x1a95ce,_0x3459b7){var _0x587fdb={};var _0x39d16e={};var _0x2554be;var _0x57004e;return db[_0xe4d9('0x48')][_0xe4d9('0x71')]({'where':{'id':_0x1a95ce[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x3459b7,null))['then'](function(_0x12e1c6){if(_0x12e1c6){_0x2554be=_0x12e1c6;_0x39d16e[_0xe4d9('0x4b')]=_['keys'](db[_0xe4d9('0xa7')]['rawAttributes']);_0x39d16e['query']=_['keys'](_0x1a95ce['query']);_0x39d16e[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x39d16e['model'],_0x39d16e[_0xe4d9('0x4c')]);_0x587fdb['attributes']=_['intersection'](_0x39d16e[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x1a95ce['query'][_0xe4d9('0x50')]));_0x587fdb[_0xe4d9('0x4f')]=_0x587fdb[_0xe4d9('0x4f')][_0xe4d9('0x51')]?_0x587fdb[_0xe4d9('0x4f')]:_0x39d16e['model'];_0x587fdb[_0xe4d9('0x54')]=qs[_0xe4d9('0x55')](_0x1a95ce[_0xe4d9('0x4c')][_0xe4d9('0x55')]);_0x587fdb[_0xe4d9('0x56')]=qs[_0xe4d9('0x4d')](_['pick'](_0x1a95ce[_0xe4d9('0x4c')],_0x39d16e[_0xe4d9('0x4d')]));if(_0x1a95ce[_0xe4d9('0x4c')]['filter']){_0x587fdb[_0xe4d9('0x56')]=_[_0xe4d9('0x58')](_0x587fdb[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x587fdb[_0xe4d9('0x4f')],function(_0x74ec26){var _0x8a5b69={};_0x8a5b69[_0x74ec26]={'$like':'%'+_0x1a95ce['query'][_0xe4d9('0x73')]+'%'};return _0x8a5b69;})});}_0x587fdb=_[_0xe4d9('0x58')]({},_0x587fdb,_0x1a95ce[_0xe4d9('0x59')]);return _0x2554be[_0xe4d9('0x119')](_0x587fdb);}})[_0xe4d9('0x2b')](function(_0x24e540){if(_0x24e540){_0x57004e=_0x24e540[_0xe4d9('0x51')];if(!_0x1a95ce[_0xe4d9('0x4c')][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x587fdb[_0xe4d9('0x24')]=qs[_0xe4d9('0x24')](_0x1a95ce[_0xe4d9('0x4c')][_0xe4d9('0x24')]);_0x587fdb[_0xe4d9('0x26')]=qs[_0xe4d9('0x26')](_0x1a95ce[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}return _0x2554be['getApplications'](_0x587fdb);}})[_0xe4d9('0x2b')](function(_0x5adc06){if(_0x5adc06){return _0x5adc06?{'count':_0x57004e,'rows':_0x5adc06}:null;}})[_0xe4d9('0x2b')](respondWithResult(_0x3459b7,null))['catch'](handleError(_0x3459b7,null));};exports[_0xe4d9('0x11a')]=function(_0x4822e2,_0x336afc){return db['chatProactiveAction'][_0xe4d9('0x5e')]({'where':{'id':_0x4822e2[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x336afc,null))['then'](function(_0x3378d9){if(_0x3378d9){return _0x3378d9['addProactiveActions'](_0x4822e2[_0xe4d9('0x5f')][_0xe4d9('0x77')],_['omit'](_0x4822e2[_0xe4d9('0x5f')],[_0xe4d9('0x77'),'id'])||{});}})['then'](respondWithResult(_0x336afc,null))['catch'](handleError(_0x336afc,null));};exports['getProactiveActions']=function(_0x3186ae,_0x3dbd36){var _0x40c641={};var _0x28b529={};var _0x5dcc05;var _0x3a0339;return db[_0xe4d9('0x48')][_0xe4d9('0x71')]({'where':{'id':_0x3186ae[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x3dbd36,null))[_0xe4d9('0x2b')](function(_0x9d1543){if(_0x9d1543){_0x5dcc05=_0x9d1543;_0x28b529['model']=_['keys'](db['ChatProactiveAction'][_0xe4d9('0x49')]);_0x28b529[_0xe4d9('0x4c')]=_[_0xe4d9('0x5b')](_0x3186ae['query']);_0x28b529[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x28b529['model'],_0x28b529[_0xe4d9('0x4c')]);_0x40c641['attributes']=_[_0xe4d9('0x4e')](_0x28b529[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x3186ae[_0xe4d9('0x4c')]['fields']));_0x40c641['attributes']=_0x40c641[_0xe4d9('0x4f')][_0xe4d9('0x51')]?_0x40c641['attributes']:_0x28b529['model'];_0x40c641[_0xe4d9('0x54')]=qs['sort'](_0x3186ae['query'][_0xe4d9('0x55')]);_0x40c641['where']=qs[_0xe4d9('0x4d')](_['pick'](_0x3186ae[_0xe4d9('0x4c')],_0x28b529[_0xe4d9('0x4d')]));if(_0x3186ae[_0xe4d9('0x4c')]['filter']){_0x40c641['where']=_['merge'](_0x40c641[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x40c641[_0xe4d9('0x4f')],function(_0x17ed69){var _0x4e8ac0={};_0x4e8ac0[_0x17ed69]={'$like':'%'+_0x3186ae[_0xe4d9('0x4c')][_0xe4d9('0x73')]+'%'};return _0x4e8ac0;})});}_0x40c641=_[_0xe4d9('0x58')]({},_0x40c641,_0x3186ae['options']);return _0x5dcc05[_0xe4d9('0x100')](_0x40c641);}})[_0xe4d9('0x2b')](function(_0x59b3a5){if(_0x59b3a5){_0x3a0339=_0x59b3a5[_0xe4d9('0x51')];if(!_0x3186ae[_0xe4d9('0x4c')][_0xe4d9('0x52')]('nolimit')){_0x40c641[_0xe4d9('0x24')]=qs[_0xe4d9('0x24')](_0x3186ae['query']['limit']);_0x40c641[_0xe4d9('0x26')]=qs[_0xe4d9('0x26')](_0x3186ae[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}return _0x5dcc05['getProactiveActions'](_0x40c641);}})['then'](function(_0x11e637){if(_0x11e637){return _0x11e637?{'count':_0x3a0339,'rows':_0x11e637}:null;}})[_0xe4d9('0x2b')](respondWithResult(_0x3dbd36,null))[_0xe4d9('0x1f')](handleError(_0x3dbd36,null));};exports['getFields']=function(_0x4f327f,_0x1f84d0){var _0xcfc14c=_0x4f327f[_0xe4d9('0x4c')][_0xe4d9('0x11b')]===_0xe4d9('0x11c')?_0xe4d9('0x11d'):_0xe4d9('0x11e');return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'attributes':['id',_0xcfc14c],'where':{'id':_0x4f327f[_0xe4d9('0x6c')]['id']}})['then'](handleEntityNotFound(_0x1f84d0,null))[_0xe4d9('0x2b')](function(_0x59dd0e){if(_0x59dd0e){var _0x587483=_0x59dd0e[_0xcfc14c];var _0x165186=_0x587483&&_0x587483['items']?_0x587483[_0xe4d9('0x11f')]:[];_0x1f84d0[_0xe4d9('0x30')]({'fromKey':_[_0xe4d9('0x87')](_0x587483[_0xe4d9('0x120')])?undefined:_0x587483[_0xe4d9('0x120')],'count':_0x165186[_0xe4d9('0x51')],'rows':_0x165186});}})[_0xe4d9('0x1f')](handleError(_0x1f84d0,null));};exports[_0xe4d9('0x121')]=function(_0x30510b,_0x4c8947){var _0x266ffa={'raw':![],'where':{}};var _0x2602d8={};var _0x3e8982={'count':0x0,'rows':[]};return db[_0xe4d9('0x48')][_0xe4d9('0x71')]({'where':{'id':_0x30510b[_0xe4d9('0x6c')]['id']}})['then'](handleEntityNotFound(_0x4c8947,null))[_0xe4d9('0x2b')](function(_0x40d1a3){if(_0x40d1a3){_0x2602d8['model']=_[_0xe4d9('0x5b')](db['ChatOfflineMessage'][_0xe4d9('0x49')]);_0x2602d8[_0xe4d9('0x4c')]=_['keys'](_0x30510b[_0xe4d9('0x4c')]);_0x2602d8[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x2602d8['model'],_0x2602d8['query']);_0x266ffa[_0xe4d9('0x4f')]=_['intersection'](_0x2602d8[_0xe4d9('0x4b')],qs['fields'](_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x50')]));_0x266ffa[_0xe4d9('0x4f')]=_0x266ffa['attributes']['length']?_0x266ffa[_0xe4d9('0x4f')]:_0x2602d8['model'];if(!_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x266ffa['limit']=qs[_0xe4d9('0x24')](_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x24')]);_0x266ffa[_0xe4d9('0x26')]=qs[_0xe4d9('0x26')](_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x26')]);}_0x266ffa['order']=qs[_0xe4d9('0x55')](_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x55')]);_0x266ffa['where']=qs[_0xe4d9('0x4d')](_['pick'](_0x30510b[_0xe4d9('0x4c')],_0x2602d8['filters']));_0x266ffa[_0xe4d9('0x56')][_0xe4d9('0x72')]=_0x40d1a3['id'];if(_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x73')]){_0x266ffa['where']=_[_0xe4d9('0x58')](_0x266ffa[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x266ffa[_0xe4d9('0x4f')],function(_0x1b5e4a){var _0x4f9805={};_0x4f9805[_0x1b5e4a]={'$like':'%'+_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x73')]+'%'};return _0x4f9805;})});}_0x266ffa=_['merge']({},_0x266ffa,_0x30510b[_0xe4d9('0x59')]);return db[_0xe4d9('0xd9')][_0xe4d9('0x25')]({'where':_0x266ffa[_0xe4d9('0x56')]})[_0xe4d9('0x2b')](function(_0x4f8ef3){_0x3e8982[_0xe4d9('0x25')]=_0x4f8ef3;if(_0x30510b[_0xe4d9('0x4c')][_0xe4d9('0x5c')]){_0x266ffa['include']=[{'all':!![]}];}else{_0x266ffa['include']=[{'model':db[_0xe4d9('0x9e')],'as':_0xe4d9('0xf7'),'required':![]},{'model':db[_0xe4d9('0xe2')],'as':_0xe4d9('0x122'),'required':![]}];}return db['ChatOfflineMessage'][_0xe4d9('0x74')](_0x266ffa);})[_0xe4d9('0x2b')](function(_0x1f79e9){_0x3e8982[_0xe4d9('0x75')]=_0x1f79e9;return _0x3e8982;});}})[_0xe4d9('0x2b')](respondWithFilteredResult(_0x4c8947,_0x266ffa))[_0xe4d9('0x1f')](handleError(_0x4c8947,null));};exports[_0xe4d9('0x123')]=function(_0xecb7e8,_0x4488d0){return db[_0xe4d9('0x48')][_0xe4d9('0x5e')]({'where':{'id':_0xecb7e8['params']['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x4488d0,null))['then'](function(_0x57f07e){if(_0x57f07e){return _0x57f07e[_0xe4d9('0x123')](_0xecb7e8[_0xe4d9('0x5f')]['ids'],_[_0xe4d9('0xf5')](_0xecb7e8['body'],[_0xe4d9('0x77'),'id'])||{})[_0xe4d9('0xd5')](function(_0x23098a){for(var _0x15f432=0x0;_0x15f432<_0xecb7e8[_0xe4d9('0x5f')][_0xe4d9('0x77')]['length'];_0x15f432+=0x1){socket[_0xe4d9('0x124')]('userChatWebsite:save',{'UserId':Number(_0xecb7e8[_0xe4d9('0x5f')][_0xe4d9('0x77')][_0x15f432]),'ChatWebsiteId':Number(_0xecb7e8[_0xe4d9('0x6c')]['id'])});}return _0x23098a;});}})[_0xe4d9('0x2b')](respondWithResult(_0x4488d0,null))[_0xe4d9('0x1f')](handleError(_0x4488d0,null));};exports[_0xe4d9('0x125')]=function(_0x567d85,_0x567a86){return db['ChatWebsite']['find']({'where':{'id':_0x567d85['params']['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x567a86,null))[_0xe4d9('0x2b')](function(_0x36acb0){if(_0x36acb0){return _0x36acb0[_0xe4d9('0x125')](_0x567d85[_0xe4d9('0x4c')][_0xe4d9('0x77')])['then'](function(){if(_[_0xe4d9('0x126')](_0x567d85[_0xe4d9('0x4c')][_0xe4d9('0x77')])){for(var _0x872574=0x0;_0x872574<_0x567d85['query']['ids'][_0xe4d9('0x51')];_0x872574+=0x1){socket['emit'](_0xe4d9('0x127'),{'UserId':Number(_0x567d85[_0xe4d9('0x4c')][_0xe4d9('0x77')][_0x872574]),'ChatWebsiteId':Number(_0x567d85['params']['id'])});}}else{socket[_0xe4d9('0x124')]('userChatWebsite:remove',{'UserId':Number(_0x567d85[_0xe4d9('0x4c')]['ids']),'ChatWebsiteId':Number(_0x567d85[_0xe4d9('0x6c')]['id'])});}});}})[_0xe4d9('0x2b')](respondWithStatusCode(_0x567a86,null))['catch'](handleError(_0x567a86,null));};exports[_0xe4d9('0x128')]=function(_0x1365d8,_0x52f18a){var _0x4fcfe2={};var _0x51909d={};var _0x2a1ada;var _0x57226d;return db[_0xe4d9('0x48')][_0xe4d9('0x71')]({'where':{'id':_0x1365d8[_0xe4d9('0x6c')]['id']}})[_0xe4d9('0x2b')](handleEntityNotFound(_0x52f18a,null))['then'](function(_0x1810b6){if(_0x1810b6){_0x2a1ada=_0x1810b6;_0x51909d['model']=_[_0xe4d9('0x5b')](db[_0xe4d9('0xf8')]['rawAttributes']);_0x51909d[_0xe4d9('0x4c')]=_['keys'](_0x1365d8[_0xe4d9('0x4c')]);_0x51909d[_0xe4d9('0x4d')]=_[_0xe4d9('0x4e')](_0x51909d[_0xe4d9('0x4b')],_0x51909d[_0xe4d9('0x4c')]);_0x4fcfe2[_0xe4d9('0x4f')]=_[_0xe4d9('0x4e')](_0x51909d[_0xe4d9('0x4b')],qs[_0xe4d9('0x50')](_0x1365d8[_0xe4d9('0x4c')][_0xe4d9('0x50')]));_0x4fcfe2['attributes']=_0x4fcfe2[_0xe4d9('0x4f')]['length']?_0x4fcfe2[_0xe4d9('0x4f')]:_0x51909d[_0xe4d9('0x4b')];_0x4fcfe2[_0xe4d9('0x54')]=qs['sort'](_0x1365d8[_0xe4d9('0x4c')][_0xe4d9('0x55')]);_0x4fcfe2[_0xe4d9('0x56')]=qs[_0xe4d9('0x4d')](_[_0xe4d9('0x57')](_0x1365d8[_0xe4d9('0x4c')],_0x51909d[_0xe4d9('0x4d')]));if(_0x1365d8[_0xe4d9('0x4c')][_0xe4d9('0x73')]){_0x4fcfe2[_0xe4d9('0x56')]=_[_0xe4d9('0x58')](_0x4fcfe2[_0xe4d9('0x56')],{'$or':_[_0xe4d9('0x47')](_0x4fcfe2['attributes'],function(_0x4755b1){var _0x5663ed={};_0x5663ed[_0x4755b1]={'$like':'%'+_0x1365d8[_0xe4d9('0x4c')][_0xe4d9('0x73')]+'%'};return _0x5663ed;})});}_0x4fcfe2=_[_0xe4d9('0x58')]({},_0x4fcfe2,_0x1365d8[_0xe4d9('0x59')]);return _0x2a1ada[_0xe4d9('0x128')](_0x4fcfe2);}})[_0xe4d9('0x2b')](function(_0x18064b){if(_0x18064b){_0x57226d=_0x18064b[_0xe4d9('0x51')];if(!_0x1365d8[_0xe4d9('0x4c')][_0xe4d9('0x52')](_0xe4d9('0x53'))){_0x4fcfe2[_0xe4d9('0x24')]=qs[_0xe4d9('0x24')](_0x1365d8[_0xe4d9('0x4c')][_0xe4d9('0x24')]);_0x4fcfe2['offset']=qs['offset'](_0x1365d8['query']['offset']);}return _0x2a1ada[_0xe4d9('0x128')](_0x4fcfe2);}})[_0xe4d9('0x2b')](function(_0x5798cf){if(_0x5798cf){return _0x5798cf?{'count':_0x57226d,'rows':_0x5798cf}:null;}})[_0xe4d9('0x2b')](respondWithResult(_0x52f18a,null))[_0xe4d9('0x1f')](handleError(_0x52f18a,null));};