Built motion from commit 753c950e.|2.5.42
[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 _0x5f66=['Start','startRouting','EventManager','offline','files','send','from\x20is\x20mandatory','mapKeyOffline','mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','MailAccount','findOrCreate','readFileSync','server/files/templates/chatOfflineMessage.ejs','utf8','render','toPairs','offlineMessageBody','ChatOfflineMessage','fromString','originalname','mimetype','server','basename','openNewInteraction','sequelize','transaction','Attachment','bulkCreate','findOne','MailServerOut','Smtp','forwardOfflineAddress','service','host','secure','authentication','auth','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','offlineMessageSubject','toPairsIn','mapValues','subjectOffline','Chat','MailAccountId','NotifyMailAccount','notifyMail','attachments','offline-chat','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','Owner','fullname','internal','Tags','tag','Command','getSnippet','timezone','iftime\x20%s,%s','interval','indexOf','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','OFFLINE','No\x20timezone','inspect','Interval','Intervals','getProactiveActions','../../config/license/util','virtual','custom','License','increment','chatLicenseExceeded','all','some','x-real-ip','connection','remoteAddress','replace','alignment','color','labelText','textColor','color_button','backgroundColor','addApplications','Transaction','READ_COMMITTED','priority','getApplications','addProactiveActions','ChatProactiveAction','getFields','false','offlineForm','items','fromKey','Attachments','addAgents','emit','userChatWebsite:save','removeAgents','isArray','userChatWebsite:remove','getAgents','mustache','path','ejs','fs-extra','lodash','querystring','../../components/parsers/qs','api','../../config/environment','defaults','redis','localhost','socket.io-emitter','./chatWebsite.socket','jayson/promise','client','http','request','then','info','ChatWebsite,\x20%s,\x20%s','request\x20sent','ChatWebsite,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','sendStatus','status','limit','undefined','count','offset','set','Content-Range','json','update','destroy','get','ChatWebsites','UserProfileResource','end','stack','name','index','mandatoryDispositionPause','map','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','ChatWebsite','include','rows','show','params','Pause','keys','rawAttributes','includeAll','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','ChatWebsiteId','Disposition','getDispositions','removeDispositions','addAnswer','getAnswers','CannedAnswer','findAll','removeAnswers','ids','sitepic','file','filename','addAvatar','agentAvatar','addCustomerAvatar','addSystemAvatar','systemAvatar','getLogo','join','root','server/files/images/logos/default_logo.svg','getLicense','isNil','server/files/images/logos/','download','getAvatar','server/files/images/avatars/default_avatar.png','existsSync','server/files/images/avatars/','customerAvatar','showCustomerAvatar','getSystemAvatar','server/files/images/avatars/system_avatar.png','notify','user-agent-parser','setUA','headers','getResult','chat','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','from','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','ChatApplication','Applications','List','account','applications','list','asc','contact','customerIp','cf-connecting-ip','x-forwarded-for','split','firstName','lastName','x-real-port','referer','browser','version','format','%s\x20%s','unknown','device','vendor','%s\x20%s\x20%s','stringify','ChatInteraction','threadId','externalUrl','ContactId','interaction','spread','messageId','created','autoclose','unmanaged','*,*,*,*','AttachmentId','User','unshift','agent','forcedOwnership'];(function(_0x158a61,_0x4e93a3){var _0x534c81=function(_0x42781d){while(--_0x42781d){_0x158a61['push'](_0x158a61['shift']());}};_0x534c81(++_0x4e93a3);}(_0x5f66,0x1a0));var _0x65f6=function(_0x21a9d9,_0x4d5ac8){_0x21a9d9=_0x21a9d9-0x0;var _0x46adce=_0x5f66[_0x21a9d9];return _0x46adce;};'use strict';var BPromise=require('bluebird');var Mustache=require(_0x65f6('0x0'));var util=require('util');var path=require(_0x65f6('0x1'));var ejs=require(_0x65f6('0x2'));var fs=require('fs');var fs_extra=require(_0x65f6('0x3'));var _=require(_0x65f6('0x4'));var querystring=require(_0x65f6('0x5'));var Redis=require('ioredis');var qs=require(_0x65f6('0x6'));var logger=require('../../config/logger')(_0x65f6('0x7'));var config=require(_0x65f6('0x8'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x65f6('0x9')](config[_0x65f6('0xa')],{'host':_0x65f6('0xb'),'port':0x18eb});var socket=require(_0x65f6('0xc'))(new Redis(config[_0x65f6('0xa')]));require(_0x65f6('0xd'))['register'](socket);var htmlToText=require('html-to-text');var jayson=require(_0x65f6('0xe'));var client=jayson[_0x65f6('0xf')][_0x65f6('0x10')]({'port':0x232c});var client9002=jayson[_0x65f6('0xf')]['http']({'port':0x232a});var client9003=jayson[_0x65f6('0xf')]['http']({'port':0x232b});var client9001=jayson['client'][_0x65f6('0x10')]({'port':0x2329});function respondWithRpcPromise(_0x576875,_0x419819,_0x4862a5,_0x2f964a){return new BPromise(function(_0x186a6a,_0x2c4ee5){var _0x217570=_0x2f964a||client;return _0x217570[_0x65f6('0x11')](_0x576875,_0x4862a5)[_0x65f6('0x12')](function(_0x44144b){logger[_0x65f6('0x13')](_0x65f6('0x14'),_0x419819,_0x65f6('0x15'));logger['debug'](_0x65f6('0x16'),_0x419819,'request\x20sent',JSON['stringify'](_0x44144b));if(_0x44144b[_0x65f6('0x17')]){if(_0x44144b[_0x65f6('0x17')][_0x65f6('0x18')]===0x1f4){logger[_0x65f6('0x17')](_0x65f6('0x14'),_0x419819,_0x44144b[_0x65f6('0x17')][_0x65f6('0x19')]);return _0x2c4ee5(_0x44144b[_0x65f6('0x17')]['message']);}logger['error'](_0x65f6('0x14'),_0x419819,_0x44144b['error']['message']);return _0x186a6a(_0x44144b['error'][_0x65f6('0x19')]);}else{logger[_0x65f6('0x13')]('ChatWebsite,\x20%s,\x20%s',_0x419819,_0x65f6('0x15'));_0x186a6a(_0x44144b[_0x65f6('0x1a')][_0x65f6('0x19')]);}})[_0x65f6('0x1b')](function(_0x219ab2){logger[_0x65f6('0x17')]('ChatWebsite,\x20%s,\x20%s',_0x419819,_0x219ab2);_0x2c4ee5(_0x219ab2);});});}function respondWithStatusCode(_0x197a49,_0x4bb39e){_0x4bb39e=_0x4bb39e||0xcc;return function(_0x5b9e2a){if(_0x5b9e2a){return _0x197a49[_0x65f6('0x1c')](_0x4bb39e);}return _0x197a49[_0x65f6('0x1d')](_0x4bb39e)['end']();};}function respondWithResult(_0x1eeaaa,_0x471a33){_0x471a33=_0x471a33||0xc8;return function(_0x2317ce){if(_0x2317ce){return _0x1eeaaa[_0x65f6('0x1d')](_0x471a33)['json'](_0x2317ce);}};}function respondWithFilteredResult(_0x9d7bb0,_0x59ea32){return function(_0x20a161){if(_0x20a161){var _0x5963e0=typeof _0x59ea32['offset']==='undefined'&&typeof _0x59ea32[_0x65f6('0x1e')]===_0x65f6('0x1f');var _0x4b2292=_0x20a161[_0x65f6('0x20')];var _0x28f710=_0x5963e0?0x0:_0x59ea32['offset'];var _0x325cb4=_0x5963e0?_0x20a161[_0x65f6('0x20')]:_0x59ea32[_0x65f6('0x21')]+_0x59ea32['limit'];var _0x4ac04b;if(_0x325cb4>=_0x4b2292){_0x325cb4=_0x4b2292;_0x4ac04b=0xc8;}else{_0x4ac04b=0xce;}_0x9d7bb0['status'](_0x4ac04b);return _0x9d7bb0[_0x65f6('0x22')](_0x65f6('0x23'),_0x28f710+'-'+_0x325cb4+'/'+_0x4b2292)[_0x65f6('0x24')](_0x20a161);}return null;};}function saveUpdates(_0x408ccc){return function(_0x518cac){if(_0x518cac){return _0x518cac[_0x65f6('0x25')](_0x408ccc)[_0x65f6('0x12')](function(_0x4ace4c){return _0x4ace4c;});}return null;};}function removeEntity(_0x4ea23d){return function(_0x154cbd){if(_0x154cbd){return _0x154cbd[_0x65f6('0x26')]()['then'](function(){var _0x4e50c0=_0x154cbd[_0x65f6('0x27')]({'plain':!![]});var _0x1ce43c=_0x65f6('0x28');return db[_0x65f6('0x29')][_0x65f6('0x26')]({'where':{'type':_0x1ce43c,'resourceId':_0x4e50c0['id']}})[_0x65f6('0x12')](function(){return _0x154cbd;});})['then'](function(){_0x4ea23d[_0x65f6('0x1d')](0xcc)[_0x65f6('0x2a')]();});}};}function handleEntityNotFound(_0x46f03c){return function(_0x4bc037){if(!_0x4bc037){_0x46f03c[_0x65f6('0x1c')](0x194);}return _0x4bc037;};}function handleError(_0x2a7aa8,_0xbaed3c){_0xbaed3c=_0xbaed3c||0x1f4;return function(_0x45510a){logger[_0x65f6('0x17')](_0x45510a[_0x65f6('0x2b')]);if(_0x45510a['name']){delete _0x45510a[_0x65f6('0x2c')];}_0x2a7aa8[_0x65f6('0x1d')](_0xbaed3c)['send'](_0x45510a);};}exports[_0x65f6('0x2d')]=function(_0x5a740a,_0x2b403b){var _0x50494b={'include':[{'model':db['Pause'],'as':_0x65f6('0x2e')}]},_0x2b9fb6={},_0x24f7fd={'count':0x0,'rows':[]};var _0x13e41a=_[_0x65f6('0x2f')](db['ChatWebsite']['rawAttributes'],function(_0x30109d){return{'name':_0x30109d['fieldName'],'type':_0x30109d[_0x65f6('0x30')]['key']};});_0x2b9fb6[_0x65f6('0x31')]=_[_0x65f6('0x2f')](_0x13e41a,'name');_0x2b9fb6[_0x65f6('0x32')]=_['keys'](_0x5a740a['query']);_0x2b9fb6[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x2b9fb6[_0x65f6('0x31')],_0x2b9fb6[_0x65f6('0x32')]);_0x50494b[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x2b9fb6[_0x65f6('0x31')],qs[_0x65f6('0x36')](_0x5a740a['query'][_0x65f6('0x36')]));_0x50494b['attributes']=_0x50494b[_0x65f6('0x35')][_0x65f6('0x37')]?_0x50494b[_0x65f6('0x35')]:_0x2b9fb6[_0x65f6('0x31')];if(!_0x5a740a['query'][_0x65f6('0x38')](_0x65f6('0x39'))){_0x50494b[_0x65f6('0x1e')]=qs[_0x65f6('0x1e')](_0x5a740a[_0x65f6('0x32')][_0x65f6('0x1e')]);_0x50494b[_0x65f6('0x21')]=qs[_0x65f6('0x21')](_0x5a740a[_0x65f6('0x32')]['offset']);}_0x50494b[_0x65f6('0x3a')]=qs[_0x65f6('0x3b')](_0x5a740a[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x50494b[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x5a740a[_0x65f6('0x32')],_0x2b9fb6[_0x65f6('0x33')]),_0x13e41a);if(_0x5a740a[_0x65f6('0x32')][_0x65f6('0x3e')]){_0x50494b[_0x65f6('0x3c')]=_[_0x65f6('0x3f')](_0x50494b[_0x65f6('0x3c')],{'$or':_[_0x65f6('0x2f')](_0x13e41a,function(_0x2cb38d){if(_0x2cb38d['type']!==_0x65f6('0x40')){var _0x37cd36={};_0x37cd36[_0x2cb38d[_0x65f6('0x2c')]]={'$like':'%'+_0x5a740a[_0x65f6('0x32')]['filter']+'%'};return _0x37cd36;}})});}_0x50494b=_[_0x65f6('0x3f')]({},_0x50494b,_0x5a740a[_0x65f6('0x41')]);var _0x2b01eb={'where':_0x50494b['where']};return db[_0x65f6('0x42')][_0x65f6('0x20')](_0x2b01eb)[_0x65f6('0x12')](function(_0x2179e5){_0x24f7fd['count']=_0x2179e5;if(_0x5a740a[_0x65f6('0x32')]['includeAll']){_0x50494b[_0x65f6('0x43')]=[{'all':!![]}];}return db[_0x65f6('0x42')]['findAll'](_0x50494b);})[_0x65f6('0x12')](function(_0x5085db){_0x24f7fd[_0x65f6('0x44')]=_0x5085db;return _0x24f7fd;})[_0x65f6('0x12')](respondWithFilteredResult(_0x2b403b,_0x50494b))[_0x65f6('0x1b')](handleError(_0x2b403b,null));};exports[_0x65f6('0x45')]=function(_0x3ec18f,_0x3837b2){var _0x4d30c5={'raw':![],'where':{'id':_0x3ec18f[_0x65f6('0x46')]['id']},'include':[{'model':db[_0x65f6('0x47')],'as':_0x65f6('0x2e')}]},_0x51bf6c={};_0x51bf6c[_0x65f6('0x31')]=_[_0x65f6('0x48')](db[_0x65f6('0x42')][_0x65f6('0x49')]);_0x51bf6c[_0x65f6('0x32')]=_[_0x65f6('0x48')](_0x3ec18f['query']);_0x51bf6c[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x51bf6c[_0x65f6('0x31')],_0x51bf6c['query']);_0x4d30c5[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x51bf6c['model'],qs[_0x65f6('0x36')](_0x3ec18f[_0x65f6('0x32')]['fields']));_0x4d30c5[_0x65f6('0x35')]=_0x4d30c5['attributes'][_0x65f6('0x37')]?_0x4d30c5[_0x65f6('0x35')]:_0x51bf6c[_0x65f6('0x31')];if(_0x3ec18f['query'][_0x65f6('0x4a')]){_0x4d30c5[_0x65f6('0x43')]=[{'all':!![]}];}_0x4d30c5=_['merge']({},_0x4d30c5,_0x3ec18f[_0x65f6('0x41')]);return db[_0x65f6('0x42')]['find'](_0x4d30c5)[_0x65f6('0x12')](handleEntityNotFound(_0x3837b2,null))[_0x65f6('0x12')](respondWithResult(_0x3837b2,null))[_0x65f6('0x1b')](handleError(_0x3837b2,null));};exports[_0x65f6('0x4b')]=function(_0x234fa7,_0x2350ca){return db[_0x65f6('0x42')][_0x65f6('0x4b')](_0x234fa7['body'],{})['then'](function(_0x5ca62e){var _0x19f40c=_0x234fa7[_0x65f6('0x4c')][_0x65f6('0x27')]({'plain':!![]});if(!_0x19f40c)throw new Error(_0x65f6('0x4d'));if(_0x19f40c['role']===_0x65f6('0x4c')){var _0x2032b9=_0x5ca62e[_0x65f6('0x27')]({'plain':!![]});var _0x50f63a=_0x65f6('0x28');return db[_0x65f6('0x4e')][_0x65f6('0x4f')]({'where':{'name':_0x50f63a,'userProfileId':_0x19f40c['userProfileId']},'raw':!![]})['then'](function(_0x1d337d){if(_0x1d337d&&_0x1d337d[_0x65f6('0x50')]===0x0){return db[_0x65f6('0x29')][_0x65f6('0x4b')]({'name':_0x2032b9[_0x65f6('0x2c')],'resourceId':_0x2032b9['id'],'type':_0x1d337d[_0x65f6('0x2c')],'sectionId':_0x1d337d['id']},{})[_0x65f6('0x12')](function(){return _0x5ca62e;});}else{return _0x5ca62e;}})[_0x65f6('0x1b')](function(_0x2d8b5b){logger[_0x65f6('0x17')](_0x65f6('0x51'),_0x2d8b5b);throw _0x2d8b5b;});}return _0x5ca62e;})[_0x65f6('0x12')](respondWithResult(_0x2350ca,0xc9))[_0x65f6('0x1b')](handleError(_0x2350ca,null));};exports[_0x65f6('0x25')]=function(_0x5ba9c6,_0x47610a){if(_0x5ba9c6[_0x65f6('0x52')]['id']){delete _0x5ba9c6[_0x65f6('0x52')]['id'];}return db['ChatWebsite'][_0x65f6('0x4f')]({'where':{'id':_0x5ba9c6[_0x65f6('0x46')]['id']},'include':[{'model':db[_0x65f6('0x47')],'as':_0x65f6('0x2e')}]})['then'](handleEntityNotFound(_0x47610a,null))[_0x65f6('0x12')](saveUpdates(_0x5ba9c6[_0x65f6('0x52')],null))[_0x65f6('0x12')](respondWithResult(_0x47610a,null))[_0x65f6('0x1b')](handleError(_0x47610a,null));};exports['destroy']=function(_0x2923ff,_0x2fc20f){return db['ChatWebsite'][_0x65f6('0x4f')]({'where':{'id':_0x2923ff[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x2fc20f,null))['then'](removeEntity(_0x2fc20f,null))[_0x65f6('0x1b')](handleError(_0x2fc20f,null));};exports[_0x65f6('0x53')]=function(_0x3974ef,_0x3c23e3){return db[_0x65f6('0x42')][_0x65f6('0x53')]()['then'](respondWithResult(_0x3c23e3,null))['catch'](handleError(_0x3c23e3,null));};exports['addDisposition']=function(_0x336a7d,_0x367d95){if(_0x336a7d[_0x65f6('0x52')]['id']){delete _0x336a7d[_0x65f6('0x52')]['id'];}return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0x336a7d['params']['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x367d95,null))[_0x65f6('0x12')](function(_0x54b569){if(_0x54b569){_0x336a7d[_0x65f6('0x52')][_0x65f6('0x54')]=_0x54b569['id'];return db[_0x65f6('0x55')]['create'](_0x336a7d[_0x65f6('0x52')]);}})[_0x65f6('0x12')](respondWithResult(_0x367d95,null))['catch'](handleError(_0x367d95,null));};exports[_0x65f6('0x56')]=function(_0x3edc6b,_0x1301f5){var _0x417b44={'raw':![],'where':{}};var _0x3d55f7={};var _0x2226bf={'count':0x0,'rows':[]};return db[_0x65f6('0x42')]['findOne']({'where':{'id':_0x3edc6b['params']['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x1301f5,null))[_0x65f6('0x12')](function(_0x4a9524){if(_0x4a9524){_0x3d55f7[_0x65f6('0x31')]=_['keys'](db[_0x65f6('0x55')]['rawAttributes']);_0x3d55f7[_0x65f6('0x32')]=_[_0x65f6('0x48')](_0x3edc6b[_0x65f6('0x32')]);_0x3d55f7[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x3d55f7[_0x65f6('0x31')],_0x3d55f7[_0x65f6('0x32')]);_0x417b44[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x3d55f7['model'],qs['fields'](_0x3edc6b[_0x65f6('0x32')][_0x65f6('0x36')]));_0x417b44[_0x65f6('0x35')]=_0x417b44['attributes']['length']?_0x417b44[_0x65f6('0x35')]:_0x3d55f7[_0x65f6('0x31')];if(!_0x3edc6b[_0x65f6('0x32')][_0x65f6('0x38')](_0x65f6('0x39'))){_0x417b44[_0x65f6('0x1e')]=qs['limit'](_0x3edc6b['query'][_0x65f6('0x1e')]);_0x417b44[_0x65f6('0x21')]=qs['offset'](_0x3edc6b[_0x65f6('0x32')]['offset']);}_0x417b44[_0x65f6('0x3a')]=qs[_0x65f6('0x3b')](_0x3edc6b[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x417b44['where']=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x3edc6b[_0x65f6('0x32')],_0x3d55f7['filters']));_0x417b44['where'][_0x65f6('0x54')]=_0x4a9524['id'];if(_0x3edc6b['query'][_0x65f6('0x3e')]){_0x417b44[_0x65f6('0x3c')]=_[_0x65f6('0x3f')](_0x417b44[_0x65f6('0x3c')],{'$or':_['map'](_0x417b44['attributes'],function(_0x56f7f1){var _0x2e29b4={};_0x2e29b4[_0x56f7f1]={'$like':'%'+_0x3edc6b[_0x65f6('0x32')][_0x65f6('0x3e')]+'%'};return _0x2e29b4;})});}_0x417b44=_['merge']({},_0x417b44,_0x3edc6b[_0x65f6('0x41')]);return db[_0x65f6('0x55')][_0x65f6('0x20')]({'where':_0x417b44['where']})[_0x65f6('0x12')](function(_0x15809e){_0x2226bf['count']=_0x15809e;if(_0x3edc6b[_0x65f6('0x32')][_0x65f6('0x4a')]){_0x417b44['include']=[{'all':!![]}];}return db[_0x65f6('0x55')]['findAll'](_0x417b44);})[_0x65f6('0x12')](function(_0x55ea91){_0x2226bf[_0x65f6('0x44')]=_0x55ea91;return _0x2226bf;});}})[_0x65f6('0x12')](respondWithFilteredResult(_0x1301f5,_0x417b44))['catch'](handleError(_0x1301f5,null));};exports[_0x65f6('0x57')]=function(_0x442e25,_0x2a700b){return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0x442e25[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x2a700b,null))[_0x65f6('0x12')](function(_0x31dba0){if(_0x31dba0){return _0x31dba0[_0x65f6('0x57')](_0x442e25[_0x65f6('0x32')]['ids']);}})[_0x65f6('0x12')](respondWithStatusCode(_0x2a700b,null))[_0x65f6('0x1b')](handleError(_0x2a700b,null));};exports[_0x65f6('0x58')]=function(_0x219e42,_0x5694f9){if(_0x219e42[_0x65f6('0x52')]['id']){delete _0x219e42[_0x65f6('0x52')]['id'];}return db['ChatWebsite'][_0x65f6('0x4f')]({'where':{'id':_0x219e42['params']['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x5694f9,null))['then'](function(_0x31f6c1){if(_0x31f6c1){_0x219e42[_0x65f6('0x52')]['ChatWebsiteId']=_0x31f6c1['id'];return db['CannedAnswer'][_0x65f6('0x4b')](_0x219e42[_0x65f6('0x52')]);}})['then'](respondWithResult(_0x5694f9,null))[_0x65f6('0x1b')](handleError(_0x5694f9,null));};exports[_0x65f6('0x59')]=function(_0x73d359,_0x4edba0){var _0x1348ec={'raw':![],'where':{}};var _0x246510={};var _0x5889dc={'count':0x0,'rows':[]};return db[_0x65f6('0x42')]['findOne']({'where':{'id':_0x73d359[_0x65f6('0x46')]['id']}})['then'](handleEntityNotFound(_0x4edba0,null))['then'](function(_0x20687f){if(_0x20687f){_0x246510[_0x65f6('0x31')]=_[_0x65f6('0x48')](db[_0x65f6('0x5a')][_0x65f6('0x49')]);_0x246510[_0x65f6('0x32')]=_[_0x65f6('0x48')](_0x73d359[_0x65f6('0x32')]);_0x246510['filters']=_['intersection'](_0x246510[_0x65f6('0x31')],_0x246510['query']);_0x1348ec[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x246510[_0x65f6('0x31')],qs[_0x65f6('0x36')](_0x73d359[_0x65f6('0x32')]['fields']));_0x1348ec[_0x65f6('0x35')]=_0x1348ec[_0x65f6('0x35')][_0x65f6('0x37')]?_0x1348ec['attributes']:_0x246510[_0x65f6('0x31')];if(!_0x73d359[_0x65f6('0x32')][_0x65f6('0x38')](_0x65f6('0x39'))){_0x1348ec[_0x65f6('0x1e')]=qs[_0x65f6('0x1e')](_0x73d359['query']['limit']);_0x1348ec[_0x65f6('0x21')]=qs[_0x65f6('0x21')](_0x73d359[_0x65f6('0x32')][_0x65f6('0x21')]);}_0x1348ec['order']=qs['sort'](_0x73d359[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x1348ec[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x73d359[_0x65f6('0x32')],_0x246510['filters']));_0x1348ec['where']['ChatWebsiteId']=_0x20687f['id'];if(_0x73d359[_0x65f6('0x32')][_0x65f6('0x3e')]){_0x1348ec[_0x65f6('0x3c')]=_[_0x65f6('0x3f')](_0x1348ec['where'],{'$or':_['map'](_0x1348ec[_0x65f6('0x35')],function(_0x27e44b){var _0x56077a={};_0x56077a[_0x27e44b]={'$like':'%'+_0x73d359[_0x65f6('0x32')]['filter']+'%'};return _0x56077a;})});}_0x1348ec=_[_0x65f6('0x3f')]({},_0x1348ec,_0x73d359['options']);return db[_0x65f6('0x5a')][_0x65f6('0x20')]({'where':_0x1348ec['where']})[_0x65f6('0x12')](function(_0x330e18){_0x5889dc[_0x65f6('0x20')]=_0x330e18;if(_0x73d359[_0x65f6('0x32')][_0x65f6('0x4a')]){_0x1348ec[_0x65f6('0x43')]=[{'all':!![]}];}return db['CannedAnswer'][_0x65f6('0x5b')](_0x1348ec);})['then'](function(_0x24495c){_0x5889dc['rows']=_0x24495c;return _0x5889dc;});}})[_0x65f6('0x12')](respondWithFilteredResult(_0x4edba0,_0x1348ec))[_0x65f6('0x1b')](handleError(_0x4edba0,null));};exports[_0x65f6('0x5c')]=function(_0x41e59a,_0x535558){return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0x41e59a[_0x65f6('0x46')]['id']}})['then'](handleEntityNotFound(_0x535558,null))['then'](function(_0xccd888){if(_0xccd888){return _0xccd888[_0x65f6('0x5c')](_0x41e59a['query'][_0x65f6('0x5d')]);}})[_0x65f6('0x12')](respondWithStatusCode(_0x535558,null))[_0x65f6('0x1b')](handleError(_0x535558,null));};exports['addLogo']=function(_0x2c8938,_0xf1e6a1){_0x2c8938['body'][_0x65f6('0x5e')]=_0x2c8938[_0x65f6('0x5f')][_0x65f6('0x60')];return db['ChatWebsite'][_0x65f6('0x4f')]({'where':{'id':_0x2c8938[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0xf1e6a1,null))['then'](saveUpdates(_0x2c8938[_0x65f6('0x52')],null))['then'](respondWithResult(_0xf1e6a1,null))[_0x65f6('0x1b')](handleError(_0xf1e6a1,null));};exports[_0x65f6('0x61')]=function(_0x31ec61,_0x22be6e){_0x31ec61[_0x65f6('0x52')][_0x65f6('0x62')]=_0x31ec61['file'][_0x65f6('0x60')];return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0x31ec61[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x22be6e,null))['then'](saveUpdates(_0x31ec61['body'],null))['then'](respondWithResult(_0x22be6e,null))[_0x65f6('0x1b')](handleError(_0x22be6e,null));};exports[_0x65f6('0x63')]=function(_0xcfc47a,_0x59b715){_0xcfc47a[_0x65f6('0x52')]['customerAvatar']=_0xcfc47a['file'][_0x65f6('0x60')];return db[_0x65f6('0x42')]['find']({'where':{'id':_0xcfc47a[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x59b715,null))[_0x65f6('0x12')](saveUpdates(_0xcfc47a[_0x65f6('0x52')],null))[_0x65f6('0x12')](respondWithResult(_0x59b715,null))[_0x65f6('0x1b')](handleError(_0x59b715,null));};exports[_0x65f6('0x64')]=function(_0x3291ac,_0x477f29){_0x3291ac[_0x65f6('0x52')][_0x65f6('0x65')]=_0x3291ac[_0x65f6('0x5f')]['filename'];return db[_0x65f6('0x42')]['find']({'where':{'id':_0x3291ac['params']['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x477f29,null))[_0x65f6('0x12')](saveUpdates(_0x3291ac[_0x65f6('0x52')],null))[_0x65f6('0x12')](respondWithResult(_0x477f29,null))['catch'](handleError(_0x477f29,null));};exports[_0x65f6('0x66')]=function(_0x565b63,_0x490512){var _0x416ed4=path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x69'));var _0xd893ef={'where':{'id':_0x565b63[_0x65f6('0x46')]['id']},'attributes':['id','sitepic'],'raw':!![]};var _0x5c8131=![];return require('../../config/license/util')[_0x65f6('0x6a')]()[_0x65f6('0x12')](function(_0x365044){if(_0x365044){_0x5c8131=_0x365044['custom'];}})[_0x65f6('0x12')](function(){return db['ChatWebsite']['find'](_0xd893ef);})[_0x65f6('0x12')](handleEntityNotFound(_0x490512,null))[_0x65f6('0x12')](function(_0x2dbed5){if(_0x2dbed5){if(!_[_0x65f6('0x6b')](_0x2dbed5[_0x65f6('0x5e')])){if(fs['existsSync'](path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x6c'),_0x2dbed5[_0x65f6('0x5e')]))&&_0x5c8131){_0x416ed4=path['join'](config[_0x65f6('0x68')],_0x65f6('0x6c'),_0x2dbed5[_0x65f6('0x5e')]);}}return _0x490512[_0x65f6('0x6d')](_0x416ed4);}})[_0x65f6('0x1b')](handleError(_0x490512,null));};exports[_0x65f6('0x6e')]=function(_0x2f9814,_0x8aab06){var _0x558410=path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x6f'));var _0x8adb47={'where':{'id':_0x2f9814[_0x65f6('0x46')]['id']},'attributes':['id',_0x65f6('0x62')],'raw':!![]};return db['ChatWebsite'][_0x65f6('0x4f')](_0x8adb47)[_0x65f6('0x12')](handleEntityNotFound(_0x8aab06,null))['then'](function(_0x34f1e6){if(_0x34f1e6){if(!_['isNil'](_0x34f1e6[_0x65f6('0x62')])){if(fs[_0x65f6('0x70')](path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x71'),_0x34f1e6['agentAvatar']))){_0x558410=path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x71'),_0x34f1e6[_0x65f6('0x62')]);}}return _0x8aab06[_0x65f6('0x6d')](_0x558410);}})['catch'](handleError(_0x8aab06,null));};exports['getCustomerAvatar']=function(_0x38006c,_0x22a9e7){var _0x2993ee=path[_0x65f6('0x67')](config['root'],'server/files/images/avatars/customer_avatar.png');var _0x534004={'where':{'id':_0x38006c[_0x65f6('0x46')]['id']},'attributes':['id',_0x65f6('0x72'),_0x65f6('0x73')],'raw':!![]};return db['ChatWebsite'][_0x65f6('0x4f')](_0x534004)[_0x65f6('0x12')](handleEntityNotFound(_0x22a9e7,null))[_0x65f6('0x12')](function(_0x18c6a8){if(_0x18c6a8){if(!_[_0x65f6('0x6b')](_0x18c6a8['customerAvatar'])){if(fs[_0x65f6('0x70')](path[_0x65f6('0x67')](config['root'],'server/files/images/avatars/',_0x18c6a8[_0x65f6('0x72')]))&&_0x18c6a8[_0x65f6('0x73')]){_0x2993ee=path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x71'),_0x18c6a8['customerAvatar']);}}return _0x22a9e7[_0x65f6('0x6d')](_0x2993ee);}})['catch'](handleError(_0x22a9e7,null));};exports[_0x65f6('0x74')]=function(_0x5d181a,_0x38fcc9){var _0x5cec52=path[_0x65f6('0x67')](config['root'],_0x65f6('0x75'));var _0x3b9aed={'where':{'id':_0x5d181a['params']['id']},'attributes':['id','systemAvatar'],'raw':!![]};return db[_0x65f6('0x42')][_0x65f6('0x4f')](_0x3b9aed)[_0x65f6('0x12')](handleEntityNotFound(_0x38fcc9,null))[_0x65f6('0x12')](function(_0x861892){if(_0x861892){if(!_[_0x65f6('0x6b')](_0x861892[_0x65f6('0x65')])){if(fs[_0x65f6('0x70')](path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x71'),_0x861892[_0x65f6('0x65')]))){_0x5cec52=path[_0x65f6('0x67')](config[_0x65f6('0x68')],_0x65f6('0x71'),_0x861892[_0x65f6('0x65')]);}}return _0x38fcc9[_0x65f6('0x6d')](_0x5cec52);}})['catch'](handleError(_0x38fcc9,null));};exports[_0x65f6('0x76')]=function(_0x91d7bf,_0x11bdf3){var _0x16e246=require(_0x65f6('0x77'));var _0x1dbf36=new _0x16e246();var _0x849936=_0x1dbf36[_0x65f6('0x78')](_0x91d7bf[_0x65f6('0x79')]['user-agent'])[_0x65f6('0x7a')]();var _0x585e99={'body':_0x91d7bf[_0x65f6('0x52')],'channel':_0x65f6('0x7b')};var _0x5c2f2c=[];var _0x38db52=[];var _0x39dedf={};var _0x5c7462=![];return db[_0x65f6('0x7c')][_0x65f6('0x53')]()[_0x65f6('0x12')](function(_0x207831){if(!_0x207831){throw new db[(_0x65f6('0x7d'))][(_0x65f6('0x7e'))]('no\x20available\x20attributes');}_0x5c2f2c=_[_0x65f6('0x7f')](_[_0x65f6('0x48')](_0x207831),[_0x65f6('0x80'),_0x65f6('0x81')]);_0x38db52=_['difference'](_['keys'](_0x207831),['createdAt',_0x65f6('0x81'),_0x65f6('0x82'),_0x65f6('0x83')]);if(_0x91d7bf[_0x65f6('0x52')]['id']){delete _0x91d7bf[_0x65f6('0x52')]['id'];}if(_['isNil'](_0x91d7bf['body'][_0x65f6('0x84')])){throw new db[(_0x65f6('0x7d'))][(_0x65f6('0x7e'))]('from\x20is\x20mandatory');}if(_['isNil'](_0x91d7bf[_0x65f6('0x52')]['body'])||_0x91d7bf[_0x65f6('0x52')][_0x65f6('0x52')]===''){throw new db[(_0x65f6('0x7d'))][(_0x65f6('0x7e'))](_0x65f6('0x85'));}if(_[_0x65f6('0x6b')](_0x91d7bf[_0x65f6('0x52')][_0x65f6('0x86')])){throw new db[(_0x65f6('0x7d'))]['ValidationError'](_0x65f6('0x87')+_0x38db52);}if(!_[_0x65f6('0x88')](_0x38db52,_0x91d7bf['body'][_0x65f6('0x86')])){throw new db['Sequelize'][(_0x65f6('0x7e'))](_0x65f6('0x89')+_0x38db52);}_0x39dedf[_0x91d7bf[_0x65f6('0x52')]['mapKey']]=_0x91d7bf[_0x65f6('0x52')]['from'];})['then'](function(){return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0x91d7bf['params']['id']},'include':[{'model':db[_0x65f6('0x8a')],'as':'List','include':[{'model':db[_0x65f6('0x7c')],'as':_0x65f6('0x8b'),'where':_0x39dedf,'limit':0x1,'order':[[_0x65f6('0x81'),_0x65f6('0x8c')]]}]},{'model':db[_0x65f6('0x8d')],'as':_0x65f6('0x8e')}]});})[_0x65f6('0x12')](handleEntityNotFound(_0x11bdf3,null))[_0x65f6('0x12')](function(_0x5ed6ff){if(_0x5ed6ff&&_0x5ed6ff[_0x65f6('0x8f')]){_0x585e99[_0x65f6('0x90')]=_0x5ed6ff;_0x585e99[_0x65f6('0x91')]=_0x5ed6ff[_0x65f6('0x8e')];_0x585e99[_0x65f6('0x92')]=_0x5ed6ff['List'];_0x585e99[_0x65f6('0x91')]=_['orderBy'](_0x585e99[_0x65f6('0x91')],['priority'],[_0x65f6('0x93')]);if(_0x585e99[_0x65f6('0x90')][_0x65f6('0x8e')]){delete _0x585e99[_0x65f6('0x90')][_0x65f6('0x8e')];}if(_0x585e99[_0x65f6('0x90')][_0x65f6('0x8f')]&&_0x585e99[_0x65f6('0x90')][_0x65f6('0x8f')][_0x65f6('0x8b')][_0x65f6('0x37')]){return _0x585e99[_0x65f6('0x90')][_0x65f6('0x8f')][_0x65f6('0x8b')][0x0];}var _0x37fa08=_[_0x65f6('0x9')](_0x91d7bf[_0x65f6('0x52')],{'firstName':_0x91d7bf['body'][_0x65f6('0x84')],'ListId':_0x5ed6ff['ListId']});_0x37fa08[_0x91d7bf[_0x65f6('0x52')][_0x65f6('0x86')]]=_0x91d7bf[_0x65f6('0x52')][_0x65f6('0x84')];return db[_0x65f6('0x7c')][_0x65f6('0x4b')](_0x37fa08,{'fields':_0x5c2f2c,'raw':!![]});}})['then'](handleEntityNotFound(_0x11bdf3,null))[_0x65f6('0x12')](function(_0x1ac0bd){_0x585e99[_0x65f6('0x94')]=_0x1ac0bd;var _0x359734=_0x91d7bf[_0x65f6('0x52')][_0x65f6('0x95')];if(_0x91d7bf[_0x65f6('0x79')][_0x65f6('0x96')]){_0x359734=_0x91d7bf[_0x65f6('0x79')][_0x65f6('0x96')];}else if(_0x91d7bf[_0x65f6('0x79')]['x-forwarded-for']){_0x359734=_['first'](_0x91d7bf[_0x65f6('0x79')][_0x65f6('0x97')][_0x65f6('0x98')](','));}if(_0x1ac0bd){var _0x179fed={'ContactId':_0x1ac0bd['id'],'ChatWebsiteId':_0x91d7bf[_0x65f6('0x46')]['id'],'from':(_0x1ac0bd[_0x65f6('0x99')]||'')+'\x20'+(_0x1ac0bd[_0x65f6('0x9a')]||''),'customerIp':_0x359734,'customerPort':_0x91d7bf['headers'][_0x65f6('0x9b')]?_0x91d7bf[_0x65f6('0x79')][_0x65f6('0x9b')]:null,'referer':_0x91d7bf[_0x65f6('0x52')][_0x65f6('0x9c')],'browserName':_0x849936[_0x65f6('0x9d')][_0x65f6('0x2c')]&&_0x849936[_0x65f6('0x9d')][_0x65f6('0x9e')]?util[_0x65f6('0x9f')](_0x65f6('0xa0'),_0x849936[_0x65f6('0x9d')][_0x65f6('0x2c')],_0x849936['browser']['version']):'unknown','browserVersion':_0x849936[_0x65f6('0x9d')][_0x65f6('0x9e')]||_0x65f6('0xa1'),'osName':util['format'](_0x65f6('0xa0'),_0x849936['os'][_0x65f6('0x2c')],_0x849936['os'][_0x65f6('0x9e')]),'osVersion':_0x849936['os']['version'],'deviceModel':_0x849936[_0x65f6('0xa2')][_0x65f6('0x31')]&&_0x849936['device'][_0x65f6('0xa3')]?util[_0x65f6('0x9f')](_0x65f6('0xa4'),_0x849936['device'][_0x65f6('0x31')],_0x849936[_0x65f6('0xa2')][_0x65f6('0xa3')],_0x849936[_0x65f6('0xa2')][_0x65f6('0x30')]):null,'deviceVendor':_0x849936[_0x65f6('0xa2')][_0x65f6('0xa3')],'deviceType':_0x849936[_0x65f6('0xa2')][_0x65f6('0x30')],'formData':JSON[_0x65f6('0xa5')](_0x91d7bf['body'])};var _0x43c89e={'ChatWebsiteId':_0x91d7bf[_0x65f6('0x46')]['id'],'closed':![]};if(_0x91d7bf[_0x65f6('0x52')]['threadId']){_0x43c89e['threadId']=_0x91d7bf[_0x65f6('0x52')]['threadId'];return db[_0x65f6('0xa6')][_0x65f6('0x4f')]({'where':_0x43c89e})[_0x65f6('0x12')](function(_0xbf4abe){if(_0xbf4abe){return[_0xbf4abe,![]];}_0x179fed[_0x65f6('0xa7')]=_0x91d7bf['body'][_0x65f6('0xa7')];_0x179fed[_0x65f6('0xa8')]=_0x91d7bf[_0x65f6('0x52')][_0x65f6('0xa8')];return db['ChatInteraction'][_0x65f6('0x4b')](_0x179fed)[_0x65f6('0x12')](function(_0x11d3fb){return[_0x11d3fb,!![]];});});}_0x43c89e[_0x65f6('0xa9')]=_0x1ac0bd['id'];if(_0x91d7bf[_0x65f6('0x52')][_0x65f6('0xaa')]&&_0x91d7bf[_0x65f6('0x52')][_0x65f6('0xaa')]['id']){_0x43c89e['id']=_0x91d7bf[_0x65f6('0x52')][_0x65f6('0xaa')]['id'];return db[_0x65f6('0xa6')][_0x65f6('0x4f')]({'where':_0x43c89e})[_0x65f6('0x12')](function(_0x31e87d){if(_0x31e87d){return[_0x31e87d,![]];}return db[_0x65f6('0xa6')]['create'](_0x179fed)[_0x65f6('0x12')](function(_0x1cca16){return[_0x1cca16,!![]];});});}return db['ChatInteraction']['create'](_0x179fed)[_0x65f6('0x12')](function(_0x7c1efc){return[_0x7c1efc,!![]];});}})[_0x65f6('0xab')](function(_0x2bcdec,_0x21b9ba){if(_0x2bcdec){_0x5c7462=_0x21b9ba;if(!_0x21b9ba){var _0x33e01f={'from':(_0x585e99[_0x65f6('0x94')]['firstName']||'')+'\x20'+(_0x585e99[_0x65f6('0x94')]['lastName']||'')};if(_0x91d7bf['body'][_0x65f6('0xa7')]&&_0x91d7bf[_0x65f6('0x52')][_0x65f6('0xac')]&&_0x91d7bf[_0x65f6('0x52')]['threadId']!=_0x91d7bf['body'][_0x65f6('0xac')]){_0x33e01f[_0x65f6('0xa7')]=_0x91d7bf['body']['messageId'];}return _0x2bcdec['update'](_0x33e01f);}else{return _0x2bcdec;}}})[_0x65f6('0x12')](function(_0x42dc3a){_0x585e99[_0x65f6('0xaa')]=_0x42dc3a[_0x65f6('0x27')]({'plain':!![]});_0x585e99[_0x65f6('0xaa')]['created']=_0x5c7462;if(_0x585e99['interaction'][_0x65f6('0xad')]){if(_0x585e99[_0x65f6('0x90')][_0x65f6('0xae')]){_0x585e99['applications']['push']({'id':0x0,'priority':_0x585e99[_0x65f6('0x91')][_0x65f6('0x37')]+0x1,'app':'close','appdata':_0x65f6('0xaf'),'interval':_0x65f6('0xb0')});}}return db['ChatMessage'][_0x65f6('0x4b')]({'body':_0x91d7bf['body'][_0x65f6('0x52')],'ChatWebsiteId':_0x91d7bf[_0x65f6('0x46')]['id'],'ChatInteractionId':_0x42dc3a['id'],'direction':'in','ContactId':_0x585e99[_0x65f6('0x94')]['id'],'AttachmentId':_0x91d7bf[_0x65f6('0x52')][_0x65f6('0xb1')]});})[_0x65f6('0x12')](function(_0x5ca33e){_0x585e99[_0x65f6('0x19')]=_0x5ca33e;if(_0x585e99[_0x65f6('0xaa')]['UserId']){return db[_0x65f6('0xb2')][_0x65f6('0x4f')]({'attributes':['id',_0x65f6('0x2c')],'where':{'id':_0x585e99['interaction']['UserId']}})[_0x65f6('0x12')](function(_0x2229ae){if(_0x2229ae){_0x585e99[_0x65f6('0x91')][_0x65f6('0xb3')]({'id':0x0,'priority':0x0,'app':_0x65f6('0xb4'),'appdata':_0x2229ae[_0x65f6('0x2c')]+','+(_0x585e99['account']['waitForTheAssignedAgent']||0xa),'interval':_0x65f6('0xb0')});_0x585e99[_0x65f6('0xb5')]=!![];}return respondWithRpcPromise(_0x65f6('0xb6'),_0x65f6('0xb7'),_0x585e99);});}return respondWithRpcPromise(_0x65f6('0xb6'),_0x65f6('0xb7'),_0x585e99);})[_0x65f6('0x12')](function(_0x4146df){respondWithRpcPromise(_0x65f6('0xb8'),_0x65f6('0xb8'),{'event':_0x65f6('0x76'),'message':_0x4146df},client9002);return _0x4146df;})[_0x65f6('0x12')](respondWithResult(_0x11bdf3,null))['catch'](handleError(_0x11bdf3,null));};exports[_0x65f6('0xb9')]=function(_0x3d2328,_0x21a8c9){var _0x101050,_0x3be8bc,_0x385d13;var _0xd00f2f=[];var _0x868a4f={};var _0x2820b3=_0x3d2328[_0x65f6('0xba')]||[];var _0x591fcd=[];var _0x4dfda4;return db[_0x65f6('0x7c')][_0x65f6('0x53')]()['then'](function(_0x1db7e4){if(!_0x1db7e4){throw new db[(_0x65f6('0x7d'))][(_0x65f6('0x7e'))]('no\x20available\x20attributes');}_0xd00f2f=_['difference'](_[_0x65f6('0x48')](_0x1db7e4),[_0x65f6('0x80'),_0x65f6('0x81'),_0x65f6('0x82'),_0x65f6('0x83')]);if(_0x3d2328[_0x65f6('0x52')]['id']){delete _0x3d2328[_0x65f6('0x52')]['id'];}if(_[_0x65f6('0x6b')](_0x3d2328[_0x65f6('0x52')][_0x65f6('0x84')])){throw _0x21a8c9[_0x65f6('0x1d')](0x1f4)[_0x65f6('0xbb')](new db[(_0x65f6('0x7d'))][(_0x65f6('0x7e'))](_0x65f6('0xbc')));}if(_[_0x65f6('0x6b')](_0x3d2328[_0x65f6('0x52')][_0x65f6('0x52')])||_0x3d2328['body'][_0x65f6('0x52')]===''){throw _0x21a8c9[_0x65f6('0x1d')](0x1f4)[_0x65f6('0xbb')](new db[(_0x65f6('0x7d'))]['ValidationError'](_0x65f6('0x85')));}if(_['isNil'](_0x3d2328[_0x65f6('0x52')][_0x65f6('0xbd')])){throw _0x21a8c9[_0x65f6('0x1d')](0x1f4)[_0x65f6('0xbb')](new db[(_0x65f6('0x7d'))]['ValidationError'](_0x65f6('0xbe')+_0xd00f2f));}if(!_['includes'](_0xd00f2f,_0x3d2328['body']['mapKeyOffline'])){throw _0x21a8c9[_0x65f6('0x1d')](0x1f4)['send'](new db[(_0x65f6('0x7d'))][(_0x65f6('0x7e'))](_0x65f6('0xbf')+_0xd00f2f));}_0x868a4f[_0x3d2328[_0x65f6('0x52')][_0x65f6('0xbd')]]=_0x3d2328[_0x65f6('0x52')][_0x65f6('0x84')];})[_0x65f6('0x12')](function(){return db['ChatWebsite']['find']({'where':{'id':_0x3d2328[_0x65f6('0x46')]['id']},'include':[{'model':db[_0x65f6('0x8a')],'as':'List'},{'model':db[_0x65f6('0xc0')],'as':'MailAccount'}]});})['then'](handleEntityNotFound(_0x21a8c9,null))[_0x65f6('0x12')](function(_0x74f19d){if(_0x74f19d&&_0x74f19d[_0x65f6('0x8f')]){_0x3be8bc=_0x74f19d;var _0x1050c7=_[_0x65f6('0x9')](_0x3d2328['body'],{'firstName':_0x3d2328[_0x65f6('0x52')]['from'],'phone':_0x3d2328[_0x65f6('0x52')]['from'],'ListId':_0x74f19d['ListId']});_0x1050c7[_0x3d2328[_0x65f6('0x52')][_0x65f6('0xbd')]]=_0x3d2328[_0x65f6('0x52')][_0x65f6('0x84')];return db[_0x65f6('0x7c')][_0x65f6('0xc1')]({'where':_0x868a4f,'defaults':_0x1050c7});}})[_0x65f6('0xab')](function(_0x2ff0f5){if(_0x2ff0f5){_0x385d13=_0x2ff0f5;var _0x504520=fs[_0x65f6('0xc2')](path['join'](config[_0x65f6('0x68')],_0x65f6('0xc3')),_0x65f6('0xc4'));var _0x588b38=ejs[_0x65f6('0xc5')](_0x504520,{'body':_[_0x65f6('0xc6')](_0x3d2328['body'][_0x65f6('0x52')]),'bodyTitle':_0x3be8bc[_0x65f6('0xc7')]});return db[_0x65f6('0xc8')][_0x65f6('0x4b')]({'body':_0x588b38,'plainBody':htmlToText[_0x65f6('0xc9')](_0x588b38),'ContactId':_0x2ff0f5['id'],'ChatWebsiteId':_0x3be8bc['id']});}})['then'](function(_0x428a19){_0x4dfda4=_0x428a19;if(_0x2820b3[_0x65f6('0x37')]){var _0x410442=_0x2820b3['map'](function(_0x4c1149){return{'name':_0x4c1149[_0x65f6('0xca')],'basename':_0x4c1149[_0x65f6('0x60')],'type':_0x4c1149[_0x65f6('0xcb')],'ChatOfflineMessageId':_0x428a19['id']};});_0x591fcd=_0x410442[_0x65f6('0x2f')](_0x3d1df9=>{var _0x5b4033={'filename':_0x3d1df9['name'],'path':path['join'](config[_0x65f6('0x68')],_0x65f6('0xcc'),'files','attachments','offline-chat',_0x3d1df9[_0x65f6('0xcd')])};return _0x5b4033;});if(!_0x3be8bc[_0x65f6('0xce')]){return db[_0x65f6('0xcf')][_0x65f6('0xd0')](function(_0x1be461){return db[_0x65f6('0xd1')][_0x65f6('0xd2')](_0x410442,{'transaction':_0x1be461});});}}})[_0x65f6('0x12')](function(){if(_0x4dfda4){_0x101050=_0x4dfda4;return db[_0x65f6('0xc0')][_0x65f6('0xd3')]({'where':{'active':!![]},'include':[{'model':db[_0x65f6('0xd4')],'as':_0x65f6('0xd5'),'raw':!![]}]});}})[_0x65f6('0x12')](function(_0x62136d){if(_0x62136d&&_0x62136d[_0x65f6('0xd5')]&&_0x3be8bc['forwardOffline']&&_0x3be8bc[_0x65f6('0xd6')]){var _0x1979c2={'tls':{'rejectUnauthorized':![]}};if(_0x62136d[_0x65f6('0xd5')][_0x65f6('0xd7')]){_0x1979c2[_0x65f6('0xd7')]=_0x62136d[_0x65f6('0xd5')]['service'];}else{_0x1979c2[_0x65f6('0xd8')]=_0x62136d[_0x65f6('0xd5')]['host'];_0x1979c2['port']=_0x62136d[_0x65f6('0xd5')]['port'];_0x1979c2['secure']=_0x62136d[_0x65f6('0xd5')][_0x65f6('0xd9')];}if(_0x62136d['Smtp'][_0x65f6('0xda')]){_0x1979c2[_0x65f6('0xdb')]={'user':_0x62136d['Smtp'][_0x65f6('0x4c')],'pass':_0x62136d[_0x65f6('0xd5')][_0x65f6('0xdc')]};}return respondWithRpcPromise(_0x65f6('0xdd'),_0x65f6('0xde'),{'account':_0x1979c2,'message':{'from':util[_0x65f6('0x9f')](_0x65f6('0xdf'),_0x62136d[_0x65f6('0x2c')],_0x62136d[_0x65f6('0xe0')]||_0x62136d['Smtp'][_0x65f6('0x4c')]),'to':_0x3be8bc[_0x65f6('0xd6')],'subject':_0x3be8bc[_0x65f6('0xe1')],'html':_0x101050[_0x65f6('0x52')],'attachments':_0x591fcd}},client9003)[_0x65f6('0x12')](function(){return _0x101050;})[_0x65f6('0x1b')](function(_0x4e4726){console[_0x65f6('0x17')](_0x4e4726);});}})['then'](function(){if(_0x3be8bc&&_0x3be8bc['openNewInteraction']&&_0x3be8bc['MailAccountId']){var _0x3f770a=[];if(_0x2820b3['length']){_0x3f770a=_0x2820b3[_0x65f6('0x2f')](function(_0x408f37){return{'name':_0x408f37[_0x65f6('0xca')],'basename':_0x408f37[_0x65f6('0x60')],'type':_0x408f37[_0x65f6('0xcb')],'ChatOfflineMessageId':_0x4dfda4['id']};});}var _0x355476;if(!_[_0x65f6('0x6b')](_0x3be8bc['subjectOffline'])){var _0x5db63d=_[_0x65f6('0x2f')](_0x3d2328[_0x65f6('0x52')],function(_0x11edd6){return _0x11edd6;});var _0x4bb32e=_[_0x65f6('0xe2')](_0x5db63d)[0x0];var _0x5d8c8e=_[_0x65f6('0xe3')](_0x4bb32e,function(_0x2b1dfc){return _0x2b1dfc;});_0x355476=_0x5d8c8e[0x1][_0x3be8bc[_0x65f6('0xe4')]];}var _0x4b920a={'from':_0x385d13[_0x65f6('0xe0')],'firstName':_0x385d13[_0x65f6('0x99')],'lastName':_0x385d13[_0x65f6('0x9a')],'mapKey':_0x65f6('0xe0'),'message':{'from':_0x385d13['email'],'to':_0x3be8bc['MailAccount'][_0x65f6('0xe0')],'cc':'','subject':_['isNil'](_0x355476)?_0x3be8bc[_0x65f6('0xe1')]:_0x355476,'messageId':'','sentAt':new Date(),'attach':_0x3f770a['length'],'attachments':_0x3f770a,'originChannel':_0x65f6('0xe5'),'ChatWebsiteId':_0x3be8bc['id'],'ChatOfflineMessageId':_0x101050['id'],'originTo':_0x3be8bc[_0x65f6('0xc0')][_0x65f6('0xe0')]},'body':_0x101050['body']};var _0x3225b6={'account':{'id':_0x3be8bc[_0x65f6('0xe6')]},'body':_0x4b920a,'log':_0x65f6('0xe7')};return respondWithRpcPromise(_0x65f6('0xe7'),_0x65f6('0xe8'),_0x3225b6,client9001)[_0x65f6('0x12')](function(){return _0x101050;})[_0x65f6('0x1b')](function(_0x4e40d4){console[_0x65f6('0x17')](_0x4e40d4);});}return;})[_0x65f6('0x12')](function(){if(_0x101050){return _0x101050;}})[_0x65f6('0x12')](respondWithResult(_0x21a8c9,null))[_0x65f6('0x1b')](function(_0x72ac02){console[_0x65f6('0x17')](_0x65f6('0x1b'),_0x72ac02);for(var _0xe52598 of _0x2820b3){var _0x1790e4=path['join'](config[_0x65f6('0x68')],'server',_0x65f6('0xba'),_0x65f6('0xe9'),_0x65f6('0xea'),_0xe52598[_0x65f6('0x60')]);fs_extra[_0x65f6('0xeb')](_0x1790e4)[_0x65f6('0x1b')](function(_0x4684ab){console[_0x65f6('0x17')](_0x65f6('0xec'),_0x1790e4,_0x4684ab);});}});};exports[_0x65f6('0xed')]=function(_0x148993,_0x38e6ff){return db[_0x65f6('0xa6')][_0x65f6('0x4f')]({'where':{'id':_0x148993[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x38e6ff,null))[_0x65f6('0x12')](function(_0x560dbb){if(_0x560dbb){return _0x560dbb[_0x65f6('0xed')](_0x148993[_0x65f6('0x52')]['ids'],_[_0x65f6('0xee')](_0x148993[_0x65f6('0x52')],[_0x65f6('0x5d'),'id'])||{});}})[_0x65f6('0x12')](respondWithResult(_0x38e6ff,null))[_0x65f6('0x1b')](handleError(_0x38e6ff,null));};exports[_0x65f6('0xef')]=function(_0x4adb7a,_0x492c89){var _0x409127={'raw':![],'where':{}};var _0x2c0165={};var _0xd11998={'count':0x0,'rows':[]};return db['ChatWebsite'][_0x65f6('0xd3')]({'where':{'id':_0x4adb7a['params']['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x492c89,null))[_0x65f6('0x12')](function(_0x1c8b2e){if(_0x1c8b2e){_0x2c0165[_0x65f6('0x31')]=_['keys'](db[_0x65f6('0xa6')]['rawAttributes']);_0x2c0165[_0x65f6('0x32')]=_[_0x65f6('0x48')](_0x4adb7a[_0x65f6('0x32')]);_0x2c0165['filters']=_[_0x65f6('0x34')](_0x2c0165['model'],_0x2c0165['query']);_0x409127[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x2c0165[_0x65f6('0x31')],qs[_0x65f6('0x36')](_0x4adb7a[_0x65f6('0x32')][_0x65f6('0x36')]));_0x409127[_0x65f6('0x35')]=_0x409127[_0x65f6('0x35')][_0x65f6('0x37')]?_0x409127[_0x65f6('0x35')]:_0x2c0165[_0x65f6('0x31')];if(!_0x4adb7a['query'][_0x65f6('0x38')]('nolimit')){_0x409127[_0x65f6('0x1e')]=qs[_0x65f6('0x1e')](_0x4adb7a['query'][_0x65f6('0x1e')]);_0x409127[_0x65f6('0x21')]=qs['offset'](_0x4adb7a['query'][_0x65f6('0x21')]);}_0x409127['order']=qs['sort'](_0x4adb7a[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x409127[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x4adb7a[_0x65f6('0x32')],_0x2c0165[_0x65f6('0x33')]));_0x409127[_0x65f6('0x3c')][_0x65f6('0x54')]=_0x1c8b2e['id'];if(_0x4adb7a['query'][_0x65f6('0x3e')]){_0x409127[_0x65f6('0x3c')]=_['merge'](_0x409127[_0x65f6('0x3c')],{'$or':_[_0x65f6('0x2f')](_0x409127[_0x65f6('0x35')],function(_0xcf934){var _0x73732f={};_0x73732f[_0xcf934]={'$like':'%'+_0x4adb7a[_0x65f6('0x32')]['filter']+'%'};return _0x73732f;})});}_0x409127=_['merge']({},_0x409127,_0x4adb7a[_0x65f6('0x41')]);return db[_0x65f6('0xa6')][_0x65f6('0x20')]({'where':_0x409127[_0x65f6('0x3c')]})[_0x65f6('0x12')](function(_0x4cee07){_0xd11998[_0x65f6('0x20')]=_0x4cee07;if(_0x4adb7a[_0x65f6('0x32')][_0x65f6('0x4a')]){_0x409127[_0x65f6('0x43')]=[{'model':db[_0x65f6('0x7c')],'as':_0x65f6('0xf0'),'required':![]},{'model':db[_0x65f6('0xb2')],'as':_0x65f6('0xf1'),'attributes':[_0x65f6('0x2c'),_0x65f6('0xf2'),_0x65f6('0xf3')],'required':![]},{'model':db['Tag'],'as':_0x65f6('0xf4'),'attributes':['id',_0x65f6('0x2c'),'color'],'where':_0x4adb7a['query'][_0x65f6('0xf5')]?{'id':_0x4adb7a[_0x65f6('0x32')][_0x65f6('0xf5')]}:undefined,'required':_0x4adb7a['query'][_0x65f6('0xf5')]?!![]:![]}];}return db[_0x65f6('0xa6')][_0x65f6('0x5b')](_0x409127);})[_0x65f6('0x12')](function(_0xf29979){_0xd11998[_0x65f6('0x44')]=_0xf29979;return _0xd11998;});}})[_0x65f6('0x12')](respondWithFilteredResult(_0x492c89,_0x409127))['catch'](handleError(_0x492c89,null));};function iftimePromise(_0xacdf06,_0x58f7a8){return respondWithRpcPromise(_0x65f6('0xf6'),_0x65f6('0xf7'),{'command':_0x58f7a8[_0x65f6('0xf8')]?util[_0x65f6('0x9f')](_0x65f6('0xf9'),_0xacdf06[_0x65f6('0xfa')],_0x58f7a8['timezone']):util[_0x65f6('0x9f')]('iftime\x20%s',_0xacdf06[_0x65f6('0xfa')])},client9002)['then'](function(_0x32829e){var _0x5258a4=_0x32829e&&_0x32829e[_0x65f6('0xfb')](_0x65f6('0xfc'))>=0x0?!![]:![];logger[_0x65f6('0x13')](_0x65f6('0xfd'),_0x58f7a8['id'],_0xacdf06['id'],_0xacdf06['interval'],_0x5258a4?_0x65f6('0xfe'):_0x65f6('0xff'),_0x58f7a8[_0x65f6('0xf8')]?_0x58f7a8[_0x65f6('0xf8')]:_0x65f6('0x100'));return _0x5258a4;})[_0x65f6('0x1b')](function(_0xd06566){logger[_0x65f6('0x17')]('[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)',_0x58f7a8['id'],_0xacdf06['id'],_0xacdf06['interval'],util[_0x65f6('0x101')](_0xd06566,{'showHidden':![],'depth':null}),_0x58f7a8[_0x65f6('0xf8')]?_0x58f7a8[_0x65f6('0xf8')]:_0x65f6('0x100'));return![];});}exports['getSnippet']=function(_0x1a25ae,_0x1e1498){var _0x4c63f9=0x0;var _0x13f4a5=0x0;var _0x4315c1=![];var _0x141d13;var _0x575f14;return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0x1a25ae['params']['id']},'include':[{'model':db['Interval'],'as':'Interval','include':[{'model':db[_0x65f6('0x102')],'as':_0x65f6('0x103'),'attributes':['id',_0x65f6('0xfa')],'raw':!![]}]}]})[_0x65f6('0x12')](handleEntityNotFound(_0x1e1498,null))[_0x65f6('0x12')](function(_0x39bea9){if(_0x39bea9){_0x141d13=_0x39bea9;return _0x39bea9[_0x65f6('0x104')]({'raw':!![]});}})[_0x65f6('0x12')](function(_0x270944){if(_0x141d13){if(_0x270944){_0x575f14=_0x270944;}}return require(_0x65f6('0x105'))[_0x65f6('0x6a')]();})[_0x65f6('0x12')](function(_0x2a0aab){if(_0x2a0aab){_0x13f4a5=_0x2a0aab[_0x65f6('0x106')];_0x4315c1=_0x2a0aab[_0x65f6('0x107')];}})[_0x65f6('0x12')](function(){return db[_0x65f6('0xa6')][_0x65f6('0x20')]({'where':{'closed':![]}});})['then'](function(_0x4345af){_0x4c63f9=_0x4345af;if(_0x13f4a5&&_0x4345af>_0x13f4a5){return db[_0x65f6('0x108')]['findOne']({'where':{'id':0x1}})['then'](function(_0x23709a){if(_0x23709a){_0x23709a[_0x65f6('0x109')](_0x65f6('0x10a'));}});}})[_0x65f6('0x12')](function(){if(_0x141d13['Interval']&&_0x141d13['Interval'][_0x65f6('0x103')]){var _0x5dc205=[];for(var _0xd2313b=0x0;_0xd2313b<_0x141d13[_0x65f6('0x102')]['Intervals']['length'];_0xd2313b++){var _0x408e74=_0x141d13[_0x65f6('0x102')][_0x65f6('0x103')][_0xd2313b][_0x65f6('0x27')]({'plain':!![]});_0x5dc205['push'](iftimePromise(_0x408e74,_0x141d13));}return BPromise[_0x65f6('0x10b')](_0x5dc205)['then'](function(_0x34542c){return _[_0x65f6('0x10c')](_0x34542c);});}else{return!![];}})[_0x65f6('0x12')](function(_0x2ab4ac){var _0x4bc08e=fs[_0x65f6('0xc2')](path['join'](config[_0x65f6('0x68')],'server/files/chat/iframe.ejs'),'utf8');var _0x38de54={'remote':_0x141d13['remote'],'query':querystring[_0x65f6('0xa5')](_[_0x65f6('0x3f')](_0x141d13[_0x65f6('0x27')]({'plain':!![]}),{'customerIp':_0x1a25ae[_0x65f6('0x79')][_0x65f6('0x97')]||_0x1a25ae[_0x65f6('0x79')][_0x65f6('0x10d')]||_0x1a25ae[_0x65f6('0x10e')][_0x65f6('0x10f')]||_0x1a25ae['ip'],'referer':_0x1a25ae['headers'][_0x65f6('0x9c')],'openedInteractions':_0x4c63f9,'maxInteractions':_0x13f4a5,'virtual':_0x4315c1[_0x65f6('0x106')],'online':_0x2ab4ac,'custom':_0x4315c1}))[_0x65f6('0x110')](/'/g,'\x5c\x27')};_0x1e1498[_0x65f6('0xbb')](ejs['render'](Mustache[_0x65f6('0xc5')](_0x4bc08e,_0x38de54),{'proactiveActions':_0x575f14,'alignment':_0x141d13[_0x65f6('0x111')],'verticalAlignment':_0x141d13['verticalAlignment'],'div_color':_0x141d13[_0x65f6('0x112')],'labelText':_0x141d13[_0x65f6('0x113')],'text_color':_0x141d13[_0x65f6('0x114')],'button_color':_0x141d13[_0x65f6('0x115')],'background_color':_0x141d13[_0x65f6('0x116')]}));})[_0x65f6('0x1b')](handleError(_0x1e1498,null));};exports[_0x65f6('0x117')]=function(_0x112db7,_0x313634){var _0x1779de=_0x112db7[_0x65f6('0x46')]['id'];var _0x4b1ec2=_0x112db7[_0x65f6('0x52')];var _0x533902=0xc8;var _0x3bee71=null;return db['sequelize'][_0x65f6('0xd0')]({'isolationLevel':db[_0x65f6('0xcf')][_0x65f6('0x118')]['ISOLATION_LEVELS'][_0x65f6('0x119')]},function(_0x34ec6b){return db['ChatWebsite'][_0x65f6('0xd3')]({'where':{'id':_0x1779de},'transaction':_0x34ec6b})[_0x65f6('0x12')](function(_0xff9e69){if(_0xff9e69){return db['ChatApplication']['destroy']({'where':{'ChatWebsiteId':_0x1779de},'transaction':_0x34ec6b})['then'](function(){var _0x4eec1f=_[_0x65f6('0x2f')](_0x4b1ec2,function(_0x14417a){_0x14417a[_0x65f6('0x54')]=_0x1779de;return _0x14417a;});return db[_0x65f6('0x8d')][_0x65f6('0xd2')](_0x4eec1f,{'transaction':_0x34ec6b});});}else{_0x533902=0x194;_0x3bee71=[];}});})[_0x65f6('0x12')](function(){if(_0x533902!==0x194){return db[_0x65f6('0x8d')]['findAndCountAll']({'where':{'ChatWebsiteId':_0x1779de},'order':_0x65f6('0x11a')})[_0x65f6('0x12')](function(_0x212333){_0x3bee71=_0x212333;});}})[_0x65f6('0x1b')](function(_0x4dbf35){_0x533902=0x1f4;logger[_0x65f6('0x17')](_0x4dbf35['stack']);if(_0x4dbf35[_0x65f6('0x2c')]){delete _0x4dbf35[_0x65f6('0x2c')];}_0x3bee71=_0x4dbf35;})['finally'](function(){if(_0x3bee71===null){_0x313634['sendStatus'](_0x533902);}else{if(_0x533902===0x1f4){_0x313634[_0x65f6('0x1d')](_0x533902)[_0x65f6('0xbb')](_0x3bee71);}else{_0x313634['status'](_0x533902)['json'](_0x3bee71);}}});};exports[_0x65f6('0x11b')]=function(_0x41ee46,_0xa54e78){var _0x31a57d={};var _0x3177f6={};var _0x142593;var _0x2d8fcc;return db[_0x65f6('0x42')][_0x65f6('0xd3')]({'where':{'id':_0x41ee46[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0xa54e78,null))[_0x65f6('0x12')](function(_0x1556ab){if(_0x1556ab){_0x142593=_0x1556ab;_0x3177f6[_0x65f6('0x31')]=_[_0x65f6('0x48')](db[_0x65f6('0x8d')]['rawAttributes']);_0x3177f6['query']=_[_0x65f6('0x48')](_0x41ee46[_0x65f6('0x32')]);_0x3177f6[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x3177f6[_0x65f6('0x31')],_0x3177f6[_0x65f6('0x32')]);_0x31a57d[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x3177f6[_0x65f6('0x31')],qs[_0x65f6('0x36')](_0x41ee46['query'][_0x65f6('0x36')]));_0x31a57d['attributes']=_0x31a57d['attributes'][_0x65f6('0x37')]?_0x31a57d[_0x65f6('0x35')]:_0x3177f6[_0x65f6('0x31')];_0x31a57d[_0x65f6('0x3a')]=qs['sort'](_0x41ee46[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x31a57d[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x41ee46[_0x65f6('0x32')],_0x3177f6[_0x65f6('0x33')]));if(_0x41ee46[_0x65f6('0x32')][_0x65f6('0x3e')]){_0x31a57d[_0x65f6('0x3c')]=_['merge'](_0x31a57d['where'],{'$or':_[_0x65f6('0x2f')](_0x31a57d[_0x65f6('0x35')],function(_0x457fa8){var _0x15f247={};_0x15f247[_0x457fa8]={'$like':'%'+_0x41ee46[_0x65f6('0x32')][_0x65f6('0x3e')]+'%'};return _0x15f247;})});}_0x31a57d=_[_0x65f6('0x3f')]({},_0x31a57d,_0x41ee46[_0x65f6('0x41')]);return _0x142593['getApplications'](_0x31a57d);}})['then'](function(_0x1ebe7e){if(_0x1ebe7e){_0x2d8fcc=_0x1ebe7e[_0x65f6('0x37')];if(!_0x41ee46['query'][_0x65f6('0x38')](_0x65f6('0x39'))){_0x31a57d[_0x65f6('0x1e')]=qs[_0x65f6('0x1e')](_0x41ee46[_0x65f6('0x32')][_0x65f6('0x1e')]);_0x31a57d['offset']=qs[_0x65f6('0x21')](_0x41ee46[_0x65f6('0x32')]['offset']);}return _0x142593['getApplications'](_0x31a57d);}})[_0x65f6('0x12')](function(_0x3743eb){if(_0x3743eb){return _0x3743eb?{'count':_0x2d8fcc,'rows':_0x3743eb}:null;}})[_0x65f6('0x12')](respondWithResult(_0xa54e78,null))[_0x65f6('0x1b')](handleError(_0xa54e78,null));};exports[_0x65f6('0x11c')]=function(_0x3dd349,_0x4c7b0a){return db['chatProactiveAction'][_0x65f6('0x4f')]({'where':{'id':_0x3dd349[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x4c7b0a,null))['then'](function(_0x25684b){if(_0x25684b){return _0x25684b[_0x65f6('0x11c')](_0x3dd349[_0x65f6('0x52')]['ids'],_[_0x65f6('0xee')](_0x3dd349[_0x65f6('0x52')],[_0x65f6('0x5d'),'id'])||{});}})['then'](respondWithResult(_0x4c7b0a,null))[_0x65f6('0x1b')](handleError(_0x4c7b0a,null));};exports[_0x65f6('0x104')]=function(_0x1ad645,_0x3b062b){var _0x2c1a02={};var _0x15bdd2={};var _0x20fbe4;var _0x4316bc;return db[_0x65f6('0x42')][_0x65f6('0xd3')]({'where':{'id':_0x1ad645['params']['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x3b062b,null))['then'](function(_0x2086ce){if(_0x2086ce){_0x20fbe4=_0x2086ce;_0x15bdd2['model']=_['keys'](db[_0x65f6('0x11d')][_0x65f6('0x49')]);_0x15bdd2['query']=_[_0x65f6('0x48')](_0x1ad645[_0x65f6('0x32')]);_0x15bdd2[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x15bdd2[_0x65f6('0x31')],_0x15bdd2['query']);_0x2c1a02['attributes']=_['intersection'](_0x15bdd2[_0x65f6('0x31')],qs['fields'](_0x1ad645[_0x65f6('0x32')][_0x65f6('0x36')]));_0x2c1a02[_0x65f6('0x35')]=_0x2c1a02[_0x65f6('0x35')][_0x65f6('0x37')]?_0x2c1a02[_0x65f6('0x35')]:_0x15bdd2[_0x65f6('0x31')];_0x2c1a02['order']=qs['sort'](_0x1ad645['query'][_0x65f6('0x3b')]);_0x2c1a02[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x1ad645['query'],_0x15bdd2[_0x65f6('0x33')]));if(_0x1ad645['query']['filter']){_0x2c1a02[_0x65f6('0x3c')]=_[_0x65f6('0x3f')](_0x2c1a02['where'],{'$or':_[_0x65f6('0x2f')](_0x2c1a02[_0x65f6('0x35')],function(_0xb4e1c5){var _0x390553={};_0x390553[_0xb4e1c5]={'$like':'%'+_0x1ad645['query']['filter']+'%'};return _0x390553;})});}_0x2c1a02=_[_0x65f6('0x3f')]({},_0x2c1a02,_0x1ad645[_0x65f6('0x41')]);return _0x20fbe4['getProactiveActions'](_0x2c1a02);}})[_0x65f6('0x12')](function(_0x13ecb8){if(_0x13ecb8){_0x4316bc=_0x13ecb8[_0x65f6('0x37')];if(!_0x1ad645[_0x65f6('0x32')][_0x65f6('0x38')](_0x65f6('0x39'))){_0x2c1a02[_0x65f6('0x1e')]=qs[_0x65f6('0x1e')](_0x1ad645[_0x65f6('0x32')]['limit']);_0x2c1a02[_0x65f6('0x21')]=qs[_0x65f6('0x21')](_0x1ad645[_0x65f6('0x32')][_0x65f6('0x21')]);}return _0x20fbe4['getProactiveActions'](_0x2c1a02);}})['then'](function(_0x2c6cca){if(_0x2c6cca){return _0x2c6cca?{'count':_0x4316bc,'rows':_0x2c6cca}:null;}})['then'](respondWithResult(_0x3b062b,null))[_0x65f6('0x1b')](handleError(_0x3b062b,null));};exports[_0x65f6('0x11e')]=function(_0x3d46d4,_0xf51395){var _0x5b3abc=_0x3d46d4[_0x65f6('0x32')]['online']===_0x65f6('0x11f')?_0x65f6('0x120'):'onlineForm';return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'attributes':['id',_0x5b3abc],'where':{'id':_0x3d46d4[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0xf51395,null))[_0x65f6('0x12')](function(_0x9c768){if(_0x9c768){var _0x5b2cc1=_0x9c768[_0x5b3abc];var _0x62830b=_0x5b2cc1&&_0x5b2cc1['items']?_0x5b2cc1[_0x65f6('0x121')]:[];_0xf51395['send']({'fromKey':_[_0x65f6('0x6b')](_0x5b2cc1[_0x65f6('0x122')])?undefined:_0x5b2cc1['fromKey'],'count':_0x62830b[_0x65f6('0x37')],'rows':_0x62830b});}})[_0x65f6('0x1b')](handleError(_0xf51395,null));};exports['getOfflineMessages']=function(_0x42ad46,_0x4dd517){var _0x2dcf79={'raw':![],'where':{}};var _0x333da7={};var _0x10c466={'count':0x0,'rows':[]};return db[_0x65f6('0x42')][_0x65f6('0xd3')]({'where':{'id':_0x42ad46[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x4dd517,null))[_0x65f6('0x12')](function(_0x1c9d56){if(_0x1c9d56){_0x333da7[_0x65f6('0x31')]=_[_0x65f6('0x48')](db[_0x65f6('0xc8')][_0x65f6('0x49')]);_0x333da7[_0x65f6('0x32')]=_[_0x65f6('0x48')](_0x42ad46[_0x65f6('0x32')]);_0x333da7['filters']=_[_0x65f6('0x34')](_0x333da7[_0x65f6('0x31')],_0x333da7['query']);_0x2dcf79[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0x333da7[_0x65f6('0x31')],qs[_0x65f6('0x36')](_0x42ad46[_0x65f6('0x32')][_0x65f6('0x36')]));_0x2dcf79[_0x65f6('0x35')]=_0x2dcf79[_0x65f6('0x35')][_0x65f6('0x37')]?_0x2dcf79[_0x65f6('0x35')]:_0x333da7['model'];if(!_0x42ad46['query'][_0x65f6('0x38')](_0x65f6('0x39'))){_0x2dcf79['limit']=qs[_0x65f6('0x1e')](_0x42ad46[_0x65f6('0x32')][_0x65f6('0x1e')]);_0x2dcf79[_0x65f6('0x21')]=qs[_0x65f6('0x21')](_0x42ad46['query']['offset']);}_0x2dcf79['order']=qs[_0x65f6('0x3b')](_0x42ad46[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x2dcf79[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_['pick'](_0x42ad46[_0x65f6('0x32')],_0x333da7['filters']));_0x2dcf79[_0x65f6('0x3c')][_0x65f6('0x54')]=_0x1c9d56['id'];if(_0x42ad46[_0x65f6('0x32')]['filter']){_0x2dcf79[_0x65f6('0x3c')]=_['merge'](_0x2dcf79[_0x65f6('0x3c')],{'$or':_[_0x65f6('0x2f')](_0x2dcf79['attributes'],function(_0x230125){var _0xe75255={};_0xe75255[_0x230125]={'$like':'%'+_0x42ad46['query'][_0x65f6('0x3e')]+'%'};return _0xe75255;})});}_0x2dcf79=_[_0x65f6('0x3f')]({},_0x2dcf79,_0x42ad46[_0x65f6('0x41')]);return db[_0x65f6('0xc8')][_0x65f6('0x20')]({'where':_0x2dcf79['where']})[_0x65f6('0x12')](function(_0x4416b4){_0x10c466['count']=_0x4416b4;if(_0x42ad46[_0x65f6('0x32')][_0x65f6('0x4a')]){_0x2dcf79['include']=[{'all':!![]}];}else{_0x2dcf79['include']=[{'model':db[_0x65f6('0x7c')],'as':'Contact','required':![]},{'model':db[_0x65f6('0xd1')],'as':_0x65f6('0x123'),'required':![]}];}return db[_0x65f6('0xc8')][_0x65f6('0x5b')](_0x2dcf79);})[_0x65f6('0x12')](function(_0x2e36c8){_0x10c466[_0x65f6('0x44')]=_0x2e36c8;return _0x10c466;});}})[_0x65f6('0x12')](respondWithFilteredResult(_0x4dd517,_0x2dcf79))[_0x65f6('0x1b')](handleError(_0x4dd517,null));};exports[_0x65f6('0x124')]=function(_0x52556c,_0x4665ec){return db['ChatWebsite'][_0x65f6('0x4f')]({'where':{'id':_0x52556c[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x4665ec,null))[_0x65f6('0x12')](function(_0x57c109){if(_0x57c109){return _0x57c109['addAgents'](_0x52556c[_0x65f6('0x52')][_0x65f6('0x5d')],_[_0x65f6('0xee')](_0x52556c[_0x65f6('0x52')],[_0x65f6('0x5d'),'id'])||{})[_0x65f6('0xab')](function(_0x5052d0){for(var _0x5dcfb7=0x0;_0x5dcfb7<_0x52556c[_0x65f6('0x52')]['ids'][_0x65f6('0x37')];_0x5dcfb7+=0x1){socket[_0x65f6('0x125')](_0x65f6('0x126'),{'UserId':Number(_0x52556c[_0x65f6('0x52')][_0x65f6('0x5d')][_0x5dcfb7]),'ChatWebsiteId':Number(_0x52556c['params']['id'])});}return _0x5052d0;});}})[_0x65f6('0x12')](respondWithResult(_0x4665ec,null))['catch'](handleError(_0x4665ec,null));};exports[_0x65f6('0x127')]=function(_0xab6058,_0x57d25c){return db[_0x65f6('0x42')][_0x65f6('0x4f')]({'where':{'id':_0xab6058[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x57d25c,null))['then'](function(_0x402a5e){if(_0x402a5e){return _0x402a5e[_0x65f6('0x127')](_0xab6058[_0x65f6('0x32')]['ids'])[_0x65f6('0x12')](function(){if(_[_0x65f6('0x128')](_0xab6058[_0x65f6('0x32')][_0x65f6('0x5d')])){for(var _0x146686=0x0;_0x146686<_0xab6058[_0x65f6('0x32')][_0x65f6('0x5d')][_0x65f6('0x37')];_0x146686+=0x1){socket[_0x65f6('0x125')]('userChatWebsite:remove',{'UserId':Number(_0xab6058[_0x65f6('0x32')][_0x65f6('0x5d')][_0x146686]),'ChatWebsiteId':Number(_0xab6058[_0x65f6('0x46')]['id'])});}}else{socket[_0x65f6('0x125')](_0x65f6('0x129'),{'UserId':Number(_0xab6058[_0x65f6('0x32')][_0x65f6('0x5d')]),'ChatWebsiteId':Number(_0xab6058[_0x65f6('0x46')]['id'])});}});}})[_0x65f6('0x12')](respondWithStatusCode(_0x57d25c,null))[_0x65f6('0x1b')](handleError(_0x57d25c,null));};exports[_0x65f6('0x12a')]=function(_0x9d31a8,_0x56a917){var _0x5bc949={};var _0xcecebe={};var _0xbf5cba;var _0xfbd390;return db[_0x65f6('0x42')]['findOne']({'where':{'id':_0x9d31a8[_0x65f6('0x46')]['id']}})[_0x65f6('0x12')](handleEntityNotFound(_0x56a917,null))[_0x65f6('0x12')](function(_0x5bba5b){if(_0x5bba5b){_0xbf5cba=_0x5bba5b;_0xcecebe[_0x65f6('0x31')]=_[_0x65f6('0x48')](db[_0x65f6('0xb2')][_0x65f6('0x49')]);_0xcecebe[_0x65f6('0x32')]=_['keys'](_0x9d31a8['query']);_0xcecebe['filters']=_[_0x65f6('0x34')](_0xcecebe[_0x65f6('0x31')],_0xcecebe[_0x65f6('0x32')]);_0x5bc949[_0x65f6('0x35')]=_[_0x65f6('0x34')](_0xcecebe[_0x65f6('0x31')],qs[_0x65f6('0x36')](_0x9d31a8[_0x65f6('0x32')][_0x65f6('0x36')]));_0x5bc949['attributes']=_0x5bc949[_0x65f6('0x35')][_0x65f6('0x37')]?_0x5bc949['attributes']:_0xcecebe['model'];_0x5bc949[_0x65f6('0x3a')]=qs['sort'](_0x9d31a8[_0x65f6('0x32')][_0x65f6('0x3b')]);_0x5bc949[_0x65f6('0x3c')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3d')](_0x9d31a8[_0x65f6('0x32')],_0xcecebe[_0x65f6('0x33')]));if(_0x9d31a8[_0x65f6('0x32')][_0x65f6('0x3e')]){_0x5bc949[_0x65f6('0x3c')]=_[_0x65f6('0x3f')](_0x5bc949[_0x65f6('0x3c')],{'$or':_[_0x65f6('0x2f')](_0x5bc949[_0x65f6('0x35')],function(_0x4e5800){var _0x35934d={};_0x35934d[_0x4e5800]={'$like':'%'+_0x9d31a8[_0x65f6('0x32')][_0x65f6('0x3e')]+'%'};return _0x35934d;})});}_0x5bc949=_[_0x65f6('0x3f')]({},_0x5bc949,_0x9d31a8[_0x65f6('0x41')]);return _0xbf5cba[_0x65f6('0x12a')](_0x5bc949);}})['then'](function(_0x309659){if(_0x309659){_0xfbd390=_0x309659['length'];if(!_0x9d31a8[_0x65f6('0x32')][_0x65f6('0x38')](_0x65f6('0x39'))){_0x5bc949[_0x65f6('0x1e')]=qs[_0x65f6('0x1e')](_0x9d31a8[_0x65f6('0x32')]['limit']);_0x5bc949[_0x65f6('0x21')]=qs[_0x65f6('0x21')](_0x9d31a8[_0x65f6('0x32')]['offset']);}return _0xbf5cba[_0x65f6('0x12a')](_0x5bc949);}})[_0x65f6('0x12')](function(_0x227065){if(_0x227065){return _0x227065?{'count':_0xfbd390,'rows':_0x227065}:null;}})['then'](respondWithResult(_0x56a917,null))[_0x65f6('0x1b')](handleError(_0x56a917,null));};