76a856e1cee14c888de4cc860271838d0b35d0ab
[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 _0x796f=['difference','createdAt','updatedAt','CompanyId','ListId','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','CmList','Contacts','ChatApplication','Applications','account','applications','list','List','orderBy','priority','asc','contact','cf-connecting-ip','first','x-forwarded-for','split','lastName','x-real-port','referer','browser','version','%s\x20%s','unknown','format','device','vendor','%s\x20%s\x20%s','threadId','ChatInteraction','externalUrl','interaction','firstName','messageId','created','autoclose','close','unmanaged','ChatMessage','UserId','User','agent','*,*,*,*','forcedOwnership','startRouting','Start','EventManager','offline','files','mapKeyOffline','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','MailAccount','spread','readFileSync','utf8','render','toPairs','offlineMessageBody','ChatOfflineMessage','mimetype','attachments','offline-chat','sequelize','Attachment','bulkCreate','MailServerOut','Smtp','forwardOffline','service','host','port','secure','authentication','auth','pass','SendMail','\x22%s\x22\x20<%s>','forwardOfflineAddress','offlineMessageSubject','openNewInteraction','MailAccountId','subjectOffline','mapValues','email','Chat','NotifyMailAccount','notifyMail','server','addInteraction','ids','getInteractions','Owner','internal','Tag','color','tag','getSnippet','interval','timezone','iftime\x20%s','indexOf','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','OFFLINE','No\x20timezone','Interval','getProactiveActions','virtual','custom','increment','Intervals','push','all','some','server/files/chat/iframe.ejs','connection','remoteAddress','alignment','backgroundColor','addApplications','transaction','findAndCountAll','getApplications','addProactiveActions','chatProactiveAction','omit','getFields','online','false','offlineForm','items','fromKey','getOfflineMessages','Contact','Attachments','addAgents','emit','userChatWebsite:save','removeAgents','isArray','userChatWebsite:remove','getAgents','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','socket.io-emitter','register','client','http','then','info','ChatWebsite,\x20%s,\x20%s','request\x20sent','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','end','undefined','limit','count','offset','set','json','apply','reject','save','get','ChatWebsites','destroy','status','name','send','index','map','ChatWebsite','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','Pause','fields','length','create','body','user','UserProfileSection','find','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','mandatoryDispositionPause','describe','addDisposition','ChatWebsiteId','Disposition','findOne','removeDispositions','addAnswer','CannedAnswer','removeAnswers','addLogo','sitepic','filename','addAvatar','file','addCustomerAvatar','systemAvatar','join','root','server/files/images/logos/default_logo.svg','getLicense','isNil','existsSync','server/files/images/logos/','download','server/files/images/avatars/default_avatar.png','agentAvatar','getCustomerAvatar','server/files/images/avatars/customer_avatar.png','customerAvatar','showCustomerAvatar','server/files/images/avatars/','getSystemAvatar','server/files/images/avatars/system_avatar.png','notify','user-agent-parser','headers','user-agent','chat','CmContact','Sequelize','ValidationError','no\x20available\x20attributes'];(function(_0x90f34f,_0x404021){var _0x4b18cf=function(_0x25112d){while(--_0x25112d){_0x90f34f['push'](_0x90f34f['shift']());}};_0x4b18cf(++_0x404021);}(_0x796f,0x98));var _0xf796=function(_0x2538c5,_0x398f64){_0x2538c5=_0x2538c5-0x0;var _0x3965d5=_0x796f[_0x2538c5];return _0x3965d5;};'use strict';var emlformat=require(_0xf796('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf796('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf796('0x2'));var moment=require(_0xf796('0x3'));var BPromise=require(_0xf796('0x4'));var Mustache=require(_0xf796('0x5'));var util=require(_0xf796('0x6'));var path=require(_0xf796('0x7'));var sox=require('sox');var csv=require(_0xf796('0x8'));var ejs=require(_0xf796('0x9'));var fs=require('fs');var fs_extra=require(_0xf796('0xa'));var _=require(_0xf796('0xb'));var squel=require(_0xf796('0xc'));var crypto=require('crypto');var jsforce=require(_0xf796('0xd'));var deskjs=require(_0xf796('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf796('0xf'));var authService=require(_0xf796('0x10'));var qs=require(_0xf796('0x11'));var as=require(_0xf796('0x12'));var hardwareService=require(_0xf796('0x13'));var logger=require(_0xf796('0x14'))(_0xf796('0x15'));var utils=require(_0xf796('0x16'));var config=require(_0xf796('0x17'));var licenseUtil=require(_0xf796('0x18'));var db=require('../../mysqldb')['db'];config[_0xf796('0x19')]=_[_0xf796('0x1a')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xf796('0x1b'))(new Redis(config['redis']));require('./chatWebsite.socket')[_0xf796('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0xf796('0x1d')][_0xf796('0x1e')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});var client9003=jayson[_0xf796('0x1d')][_0xf796('0x1e')]({'port':0x232b});var client9001=jayson[_0xf796('0x1d')]['http']({'port':0x2329});function respondWithRpcPromise(_0x49e3fc,_0xad61e6,_0x1312a2,_0x3b6a39){return new BPromise(function(_0x4a590f,_0x535f32){var _0x2a5b11=_0x3b6a39||client;return _0x2a5b11['request'](_0x49e3fc,_0x1312a2)[_0xf796('0x1f')](function(_0x447b98){logger[_0xf796('0x20')](_0xf796('0x21'),_0xad61e6,_0xf796('0x22'));logger['debug'](_0xf796('0x23'),_0xad61e6,_0xf796('0x22'),JSON[_0xf796('0x24')](_0x447b98));if(_0x447b98[_0xf796('0x25')]){if(_0x447b98[_0xf796('0x25')]['code']===0x1f4){logger['error'](_0xf796('0x21'),_0xad61e6,_0x447b98[_0xf796('0x25')][_0xf796('0x26')]);return _0x535f32(_0x447b98[_0xf796('0x25')][_0xf796('0x26')]);}logger['error'](_0xf796('0x21'),_0xad61e6,_0x447b98[_0xf796('0x25')][_0xf796('0x26')]);return _0x4a590f(_0x447b98['error'][_0xf796('0x26')]);}else{logger[_0xf796('0x20')](_0xf796('0x21'),_0xad61e6,_0xf796('0x22'));_0x4a590f(_0x447b98[_0xf796('0x27')][_0xf796('0x26')]);}})[_0xf796('0x28')](function(_0xc0b586){logger[_0xf796('0x25')](_0xf796('0x21'),_0xad61e6,_0xc0b586);_0x535f32(_0xc0b586);});});}function respondWithStatusCode(_0x3298d5,_0xa2b8b1){_0xa2b8b1=_0xa2b8b1||0xcc;return function(_0x1011cb){if(_0x1011cb){return _0x3298d5['sendStatus'](_0xa2b8b1);}return _0x3298d5['status'](_0xa2b8b1)[_0xf796('0x29')]();};}function respondWithResult(_0x42995b,_0x40792e){_0x40792e=_0x40792e||0xc8;return function(_0x26dc3c){if(_0x26dc3c){return _0x42995b['status'](_0x40792e)['json'](_0x26dc3c);}};}function respondWithFilteredResult(_0x39423e,_0x3228b4){return function(_0x3b4447){if(_0x3b4447){var _0x16c126=typeof _0x3228b4['offset']===_0xf796('0x2a')&&typeof _0x3228b4[_0xf796('0x2b')]===_0xf796('0x2a');var _0x4d1fd4=_0x3b4447[_0xf796('0x2c')];var _0x864ee9=_0x16c126?0x0:_0x3228b4['offset'];var _0x3ed80e=_0x16c126?_0x3b4447[_0xf796('0x2c')]:_0x3228b4[_0xf796('0x2d')]+_0x3228b4['limit'];var _0x3d5961;if(_0x3ed80e>=_0x4d1fd4){_0x3ed80e=_0x4d1fd4;_0x3d5961=0xc8;}else{_0x3d5961=0xce;}_0x39423e['status'](_0x3d5961);return _0x39423e[_0xf796('0x2e')]('Content-Range',_0x864ee9+'-'+_0x3ed80e+'/'+_0x4d1fd4)[_0xf796('0x2f')](_0x3b4447);}return null;};}function patchUpdates(_0x427bf7){return function(_0x43e698){try{jsonpatch[_0xf796('0x30')](_0x43e698,_0x427bf7,!![]);}catch(_0x278df7){return BPromise[_0xf796('0x31')](_0x278df7);}return _0x43e698[_0xf796('0x32')]();};}function saveUpdates(_0x5ed8a2,_0x51815c){return function(_0x110edc){if(_0x110edc){return _0x110edc['update'](_0x5ed8a2)[_0xf796('0x1f')](function(_0x48372c){return _0x48372c;});}return null;};}function removeEntity(_0x1d2362,_0x40121a){return function(_0x5bd283){if(_0x5bd283){return _0x5bd283['destroy']()[_0xf796('0x1f')](function(){var _0x39ca3f=_0x5bd283[_0xf796('0x33')]({'plain':!![]});var _0x428180=_0xf796('0x34');return db['UserProfileResource'][_0xf796('0x35')]({'where':{'type':_0x428180,'resourceId':_0x39ca3f['id']}})[_0xf796('0x1f')](function(){return _0x5bd283;});})['then'](function(){_0x1d2362[_0xf796('0x36')](0xcc)[_0xf796('0x29')]();});}};}function handleEntityNotFound(_0x4e9a10,_0x4a39fc){return function(_0x269119){if(!_0x269119){_0x4e9a10['sendStatus'](0x194);}return _0x269119;};}function handleError(_0x1dabe8,_0x4cf717){_0x4cf717=_0x4cf717||0x1f4;return function(_0x543a82){logger['error'](_0x543a82['stack']);if(_0x543a82[_0xf796('0x37')]){delete _0x543a82[_0xf796('0x37')];}_0x1dabe8[_0xf796('0x36')](_0x4cf717)[_0xf796('0x38')](_0x543a82);};}exports[_0xf796('0x39')]=function(_0x39f073,_0x2b8b67){var _0x47997a={'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x8ff137={},_0x345ceb={'count':0x0,'rows':[]};var _0x5074c3=_[_0xf796('0x3a')](db[_0xf796('0x3b')][_0xf796('0x3c')],function(_0x419ae4){return{'name':_0x419ae4[_0xf796('0x3d')],'type':_0x419ae4[_0xf796('0x3e')][_0xf796('0x3f')]};});_0x8ff137[_0xf796('0x40')]=_[_0xf796('0x3a')](_0x5074c3,'name');_0x8ff137[_0xf796('0x41')]=_[_0xf796('0x42')](_0x39f073['query']);_0x8ff137[_0xf796('0x43')]=_[_0xf796('0x44')](_0x8ff137[_0xf796('0x40')],_0x8ff137[_0xf796('0x41')]);_0x47997a['attributes']=_[_0xf796('0x44')](_0x8ff137[_0xf796('0x40')],qs['fields'](_0x39f073[_0xf796('0x41')]['fields']));_0x47997a[_0xf796('0x45')]=_0x47997a[_0xf796('0x45')]['length']?_0x47997a[_0xf796('0x45')]:_0x8ff137[_0xf796('0x40')];if(!_0x39f073['query'][_0xf796('0x46')](_0xf796('0x47'))){_0x47997a[_0xf796('0x2b')]=qs[_0xf796('0x2b')](_0x39f073[_0xf796('0x41')]['limit']);_0x47997a[_0xf796('0x2d')]=qs['offset'](_0x39f073['query'][_0xf796('0x2d')]);}_0x47997a[_0xf796('0x48')]=qs[_0xf796('0x49')](_0x39f073[_0xf796('0x41')][_0xf796('0x49')]);_0x47997a[_0xf796('0x4a')]=qs['filters'](_[_0xf796('0x4b')](_0x39f073[_0xf796('0x41')],_0x8ff137[_0xf796('0x43')]),_0x5074c3);if(_0x39f073[_0xf796('0x41')][_0xf796('0x4c')]){_0x47997a[_0xf796('0x4a')]=_[_0xf796('0x4d')](_0x47997a[_0xf796('0x4a')],{'$or':_[_0xf796('0x3a')](_0x5074c3,function(_0x313d97){if(_0x313d97[_0xf796('0x3e')]!==_0xf796('0x4e')){var _0x314180={};_0x314180[_0x313d97[_0xf796('0x37')]]={'$like':'%'+_0x39f073[_0xf796('0x41')][_0xf796('0x4c')]+'%'};return _0x314180;}})});}_0x47997a=_['merge']({},_0x47997a,_0x39f073[_0xf796('0x4f')]);var _0x5e7e4c={'where':_0x47997a[_0xf796('0x4a')]};return db['ChatWebsite'][_0xf796('0x2c')](_0x5e7e4c)['then'](function(_0x1a846f){_0x345ceb['count']=_0x1a846f;if(_0x39f073[_0xf796('0x41')][_0xf796('0x50')]){_0x47997a[_0xf796('0x51')]=[{'all':!![]}];}return db[_0xf796('0x3b')][_0xf796('0x52')](_0x47997a);})['then'](function(_0x1a6e44){_0x345ceb[_0xf796('0x53')]=_0x1a6e44;return _0x345ceb;})['then'](respondWithFilteredResult(_0x2b8b67,_0x47997a))[_0xf796('0x28')](handleError(_0x2b8b67,null));};exports[_0xf796('0x54')]=function(_0x46ec16,_0x364367){var _0x4b654c={'raw':![],'where':{'id':_0x46ec16[_0xf796('0x55')]['id']},'include':[{'model':db[_0xf796('0x56')],'as':'mandatoryDispositionPause'}]},_0x526855={};_0x526855[_0xf796('0x40')]=_[_0xf796('0x42')](db['ChatWebsite']['rawAttributes']);_0x526855[_0xf796('0x41')]=_['keys'](_0x46ec16[_0xf796('0x41')]);_0x526855[_0xf796('0x43')]=_['intersection'](_0x526855[_0xf796('0x40')],_0x526855[_0xf796('0x41')]);_0x4b654c['attributes']=_[_0xf796('0x44')](_0x526855[_0xf796('0x40')],qs[_0xf796('0x57')](_0x46ec16[_0xf796('0x41')]['fields']));_0x4b654c[_0xf796('0x45')]=_0x4b654c[_0xf796('0x45')][_0xf796('0x58')]?_0x4b654c[_0xf796('0x45')]:_0x526855[_0xf796('0x40')];if(_0x46ec16['query'][_0xf796('0x50')]){_0x4b654c[_0xf796('0x51')]=[{'all':!![]}];}_0x4b654c=_[_0xf796('0x4d')]({},_0x4b654c,_0x46ec16[_0xf796('0x4f')]);return db['ChatWebsite']['find'](_0x4b654c)[_0xf796('0x1f')](handleEntityNotFound(_0x364367,null))[_0xf796('0x1f')](respondWithResult(_0x364367,null))[_0xf796('0x28')](handleError(_0x364367,null));};exports[_0xf796('0x59')]=function(_0x3b4e81,_0x34e295){return db['ChatWebsite'][_0xf796('0x59')](_0x3b4e81[_0xf796('0x5a')],{})[_0xf796('0x1f')](function(_0x2e3702){var _0x4ef670=_0x3b4e81[_0xf796('0x5b')]['get']({'plain':!![]});if(!_0x4ef670)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x4ef670['role']===_0xf796('0x5b')){var _0x28b5b8=_0x2e3702['get']({'plain':!![]});var _0x1cb62e=_0xf796('0x34');return db[_0xf796('0x5c')][_0xf796('0x5d')]({'where':{'name':_0x1cb62e,'userProfileId':_0x4ef670[_0xf796('0x5e')]},'raw':!![]})[_0xf796('0x1f')](function(_0x172bcf){if(_0x172bcf&&_0x172bcf[_0xf796('0x5f')]===0x0){return db[_0xf796('0x60')][_0xf796('0x59')]({'name':_0x28b5b8['name'],'resourceId':_0x28b5b8['id'],'type':_0x172bcf[_0xf796('0x37')],'sectionId':_0x172bcf['id']},{})[_0xf796('0x1f')](function(){return _0x2e3702;});}else{return _0x2e3702;}})['catch'](function(_0x3f4d96){logger[_0xf796('0x25')](_0xf796('0x61'),_0x3f4d96);throw _0x3f4d96;});}return _0x2e3702;})[_0xf796('0x1f')](respondWithResult(_0x34e295,0xc9))[_0xf796('0x28')](handleError(_0x34e295,null));};exports[_0xf796('0x62')]=function(_0x2f61e0,_0x53f449){if(_0x2f61e0['body']['id']){delete _0x2f61e0[_0xf796('0x5a')]['id'];}return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x2f61e0[_0xf796('0x55')]['id']},'include':[{'model':db[_0xf796('0x56')],'as':_0xf796('0x63')}]})[_0xf796('0x1f')](handleEntityNotFound(_0x53f449,null))[_0xf796('0x1f')](saveUpdates(_0x2f61e0[_0xf796('0x5a')],null))[_0xf796('0x1f')](respondWithResult(_0x53f449,null))['catch'](handleError(_0x53f449,null));};exports[_0xf796('0x35')]=function(_0x33ae5d,_0x12518d){return db[_0xf796('0x3b')]['find']({'where':{'id':_0x33ae5d[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x12518d,null))[_0xf796('0x1f')](removeEntity(_0x12518d,null))[_0xf796('0x28')](handleError(_0x12518d,null));};exports[_0xf796('0x64')]=function(_0x36a6ae,_0x4c6519){return db[_0xf796('0x3b')][_0xf796('0x64')]()[_0xf796('0x1f')](respondWithResult(_0x4c6519,null))['catch'](handleError(_0x4c6519,null));};exports[_0xf796('0x65')]=function(_0x522999,_0x6fa191,_0x208783){if(_0x522999[_0xf796('0x5a')]['id']){delete _0x522999[_0xf796('0x5a')]['id'];}return db[_0xf796('0x3b')]['find']({'where':{'id':_0x522999['params']['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x6fa191,null))[_0xf796('0x1f')](function(_0x1f9875){if(_0x1f9875){_0x522999[_0xf796('0x5a')][_0xf796('0x66')]=_0x1f9875['id'];return db[_0xf796('0x67')][_0xf796('0x59')](_0x522999[_0xf796('0x5a')]);}})[_0xf796('0x1f')](respondWithResult(_0x6fa191,null))['catch'](handleError(_0x6fa191,null));};exports['getDispositions']=function(_0x54e73d,_0x29557c,_0x2291d5){var _0x4fc463={'raw':![],'where':{}};var _0xdc81c1={};var _0x17113f={'count':0x0,'rows':[]};return db['ChatWebsite'][_0xf796('0x68')]({'where':{'id':_0x54e73d[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x29557c,null))[_0xf796('0x1f')](function(_0x422d71){if(_0x422d71){_0xdc81c1[_0xf796('0x40')]=_[_0xf796('0x42')](db[_0xf796('0x67')]['rawAttributes']);_0xdc81c1[_0xf796('0x41')]=_[_0xf796('0x42')](_0x54e73d[_0xf796('0x41')]);_0xdc81c1['filters']=_[_0xf796('0x44')](_0xdc81c1[_0xf796('0x40')],_0xdc81c1[_0xf796('0x41')]);_0x4fc463['attributes']=_[_0xf796('0x44')](_0xdc81c1[_0xf796('0x40')],qs[_0xf796('0x57')](_0x54e73d[_0xf796('0x41')][_0xf796('0x57')]));_0x4fc463[_0xf796('0x45')]=_0x4fc463[_0xf796('0x45')][_0xf796('0x58')]?_0x4fc463[_0xf796('0x45')]:_0xdc81c1[_0xf796('0x40')];if(!_0x54e73d['query'][_0xf796('0x46')](_0xf796('0x47'))){_0x4fc463[_0xf796('0x2b')]=qs['limit'](_0x54e73d[_0xf796('0x41')][_0xf796('0x2b')]);_0x4fc463[_0xf796('0x2d')]=qs[_0xf796('0x2d')](_0x54e73d['query'][_0xf796('0x2d')]);}_0x4fc463[_0xf796('0x48')]=qs[_0xf796('0x49')](_0x54e73d[_0xf796('0x41')][_0xf796('0x49')]);_0x4fc463[_0xf796('0x4a')]=qs['filters'](_[_0xf796('0x4b')](_0x54e73d[_0xf796('0x41')],_0xdc81c1[_0xf796('0x43')]));_0x4fc463[_0xf796('0x4a')][_0xf796('0x66')]=_0x422d71['id'];if(_0x54e73d['query'][_0xf796('0x4c')]){_0x4fc463[_0xf796('0x4a')]=_[_0xf796('0x4d')](_0x4fc463[_0xf796('0x4a')],{'$or':_[_0xf796('0x3a')](_0x4fc463[_0xf796('0x45')],function(_0x1ba784){var _0x59e8af={};_0x59e8af[_0x1ba784]={'$like':'%'+_0x54e73d[_0xf796('0x41')][_0xf796('0x4c')]+'%'};return _0x59e8af;})});}_0x4fc463=_[_0xf796('0x4d')]({},_0x4fc463,_0x54e73d['options']);return db['Disposition'][_0xf796('0x2c')]({'where':_0x4fc463[_0xf796('0x4a')]})['then'](function(_0x38c7eb){_0x17113f['count']=_0x38c7eb;if(_0x54e73d[_0xf796('0x41')][_0xf796('0x50')]){_0x4fc463[_0xf796('0x51')]=[{'all':!![]}];}return db['Disposition'][_0xf796('0x52')](_0x4fc463);})[_0xf796('0x1f')](function(_0x5114d3){_0x17113f[_0xf796('0x53')]=_0x5114d3;return _0x17113f;});}})[_0xf796('0x1f')](respondWithFilteredResult(_0x29557c,_0x4fc463))['catch'](handleError(_0x29557c,null));};exports[_0xf796('0x69')]=function(_0x167315,_0x2259b4,_0x4fc63a){return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x167315['params']['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x2259b4,null))[_0xf796('0x1f')](function(_0x5bfed5){if(_0x5bfed5){return _0x5bfed5['removeDispositions'](_0x167315[_0xf796('0x41')]['ids']);}})[_0xf796('0x1f')](respondWithStatusCode(_0x2259b4,null))[_0xf796('0x28')](handleError(_0x2259b4,null));};exports[_0xf796('0x6a')]=function(_0x3f3fa2,_0x4ee6d1,_0x2659bf){if(_0x3f3fa2['body']['id']){delete _0x3f3fa2['body']['id'];}return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x3f3fa2[_0xf796('0x55')]['id']}})['then'](handleEntityNotFound(_0x4ee6d1,null))[_0xf796('0x1f')](function(_0x1669a9){if(_0x1669a9){_0x3f3fa2[_0xf796('0x5a')][_0xf796('0x66')]=_0x1669a9['id'];return db[_0xf796('0x6b')]['create'](_0x3f3fa2[_0xf796('0x5a')]);}})[_0xf796('0x1f')](respondWithResult(_0x4ee6d1,null))[_0xf796('0x28')](handleError(_0x4ee6d1,null));};exports['getAnswers']=function(_0x9d905c,_0x256382,_0x4078db){var _0x47f6b9={'raw':![],'where':{}};var _0xcc63b0={};var _0x2fa78f={'count':0x0,'rows':[]};return db[_0xf796('0x3b')]['findOne']({'where':{'id':_0x9d905c['params']['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x256382,null))[_0xf796('0x1f')](function(_0x25c79c){if(_0x25c79c){_0xcc63b0[_0xf796('0x40')]=_['keys'](db['CannedAnswer'][_0xf796('0x3c')]);_0xcc63b0[_0xf796('0x41')]=_[_0xf796('0x42')](_0x9d905c['query']);_0xcc63b0[_0xf796('0x43')]=_['intersection'](_0xcc63b0['model'],_0xcc63b0['query']);_0x47f6b9[_0xf796('0x45')]=_[_0xf796('0x44')](_0xcc63b0[_0xf796('0x40')],qs['fields'](_0x9d905c[_0xf796('0x41')][_0xf796('0x57')]));_0x47f6b9[_0xf796('0x45')]=_0x47f6b9[_0xf796('0x45')][_0xf796('0x58')]?_0x47f6b9[_0xf796('0x45')]:_0xcc63b0[_0xf796('0x40')];if(!_0x9d905c['query'][_0xf796('0x46')](_0xf796('0x47'))){_0x47f6b9[_0xf796('0x2b')]=qs[_0xf796('0x2b')](_0x9d905c['query'][_0xf796('0x2b')]);_0x47f6b9['offset']=qs[_0xf796('0x2d')](_0x9d905c[_0xf796('0x41')][_0xf796('0x2d')]);}_0x47f6b9[_0xf796('0x48')]=qs[_0xf796('0x49')](_0x9d905c[_0xf796('0x41')]['sort']);_0x47f6b9[_0xf796('0x4a')]=qs[_0xf796('0x43')](_['pick'](_0x9d905c['query'],_0xcc63b0[_0xf796('0x43')]));_0x47f6b9['where'][_0xf796('0x66')]=_0x25c79c['id'];if(_0x9d905c[_0xf796('0x41')][_0xf796('0x4c')]){_0x47f6b9[_0xf796('0x4a')]=_['merge'](_0x47f6b9['where'],{'$or':_[_0xf796('0x3a')](_0x47f6b9['attributes'],function(_0x36efae){var _0xbe693a={};_0xbe693a[_0x36efae]={'$like':'%'+_0x9d905c['query'][_0xf796('0x4c')]+'%'};return _0xbe693a;})});}_0x47f6b9=_['merge']({},_0x47f6b9,_0x9d905c[_0xf796('0x4f')]);return db[_0xf796('0x6b')][_0xf796('0x2c')]({'where':_0x47f6b9[_0xf796('0x4a')]})[_0xf796('0x1f')](function(_0x307ff4){_0x2fa78f['count']=_0x307ff4;if(_0x9d905c['query'][_0xf796('0x50')]){_0x47f6b9[_0xf796('0x51')]=[{'all':!![]}];}return db[_0xf796('0x6b')][_0xf796('0x52')](_0x47f6b9);})['then'](function(_0x1736ac){_0x2fa78f[_0xf796('0x53')]=_0x1736ac;return _0x2fa78f;});}})[_0xf796('0x1f')](respondWithFilteredResult(_0x256382,_0x47f6b9))[_0xf796('0x28')](handleError(_0x256382,null));};exports[_0xf796('0x6c')]=function(_0x7e3650,_0x203b60,_0x4472c5){return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x7e3650[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x203b60,null))[_0xf796('0x1f')](function(_0x29052a){if(_0x29052a){return _0x29052a[_0xf796('0x6c')](_0x7e3650['query']['ids']);}})[_0xf796('0x1f')](respondWithStatusCode(_0x203b60,null))[_0xf796('0x28')](handleError(_0x203b60,null));};exports[_0xf796('0x6d')]=function(_0x861962,_0x37a11b,_0x168689){_0x861962[_0xf796('0x5a')][_0xf796('0x6e')]=_0x861962['file'][_0xf796('0x6f')];return db[_0xf796('0x3b')]['find']({'where':{'id':_0x861962[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x37a11b,null))[_0xf796('0x1f')](saveUpdates(_0x861962[_0xf796('0x5a')],null))[_0xf796('0x1f')](respondWithResult(_0x37a11b,null))[_0xf796('0x28')](handleError(_0x37a11b,null));};exports[_0xf796('0x70')]=function(_0x4b8bd2,_0x2d514f,_0x46d980){_0x4b8bd2[_0xf796('0x5a')]['agentAvatar']=_0x4b8bd2[_0xf796('0x71')][_0xf796('0x6f')];return db[_0xf796('0x3b')]['find']({'where':{'id':_0x4b8bd2[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x2d514f,null))[_0xf796('0x1f')](saveUpdates(_0x4b8bd2[_0xf796('0x5a')],null))[_0xf796('0x1f')](respondWithResult(_0x2d514f,null))[_0xf796('0x28')](handleError(_0x2d514f,null));};exports[_0xf796('0x72')]=function(_0x38d147,_0x2f5273,_0x15e200){_0x38d147[_0xf796('0x5a')]['customerAvatar']=_0x38d147[_0xf796('0x71')][_0xf796('0x6f')];return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x38d147[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x2f5273,null))[_0xf796('0x1f')](saveUpdates(_0x38d147['body'],null))[_0xf796('0x1f')](respondWithResult(_0x2f5273,null))[_0xf796('0x28')](handleError(_0x2f5273,null));};exports['addSystemAvatar']=function(_0x4e3075,_0x1c02de,_0x5633af){_0x4e3075['body'][_0xf796('0x73')]=_0x4e3075[_0xf796('0x71')][_0xf796('0x6f')];return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x4e3075[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x1c02de,null))[_0xf796('0x1f')](saveUpdates(_0x4e3075[_0xf796('0x5a')],null))[_0xf796('0x1f')](respondWithResult(_0x1c02de,null))[_0xf796('0x28')](handleError(_0x1c02de,null));};exports['getLogo']=function(_0x5ce028,_0x3b5710,_0x4bb142){var _0x16dd13=path[_0xf796('0x74')](config[_0xf796('0x75')],_0xf796('0x76'));var _0x49568a={'where':{'id':_0x5ce028['params']['id']},'attributes':['id',_0xf796('0x6e')],'raw':!![]};var _0x4ecbe2=![];return require(_0xf796('0x18'))[_0xf796('0x77')]()[_0xf796('0x1f')](function(_0x35b865){if(_0x35b865){_0x4ecbe2=_0x35b865['custom'];}})[_0xf796('0x1f')](function(){return db[_0xf796('0x3b')]['find'](_0x49568a);})['then'](handleEntityNotFound(_0x3b5710,null))['then'](function(_0x9b3613){if(_0x9b3613){if(!_[_0xf796('0x78')](_0x9b3613[_0xf796('0x6e')])){if(fs[_0xf796('0x79')](path['join'](config[_0xf796('0x75')],'server/files/images/logos/',_0x9b3613[_0xf796('0x6e')]))&&_0x4ecbe2){_0x16dd13=path[_0xf796('0x74')](config[_0xf796('0x75')],_0xf796('0x7a'),_0x9b3613[_0xf796('0x6e')]);}}return _0x3b5710[_0xf796('0x7b')](_0x16dd13);}})[_0xf796('0x28')](handleError(_0x3b5710,null));};exports['getAvatar']=function(_0x322922,_0x240619,_0x5069c4){var _0x541960=path[_0xf796('0x74')](config['root'],_0xf796('0x7c'));var _0x5899bc={'where':{'id':_0x322922['params']['id']},'attributes':['id',_0xf796('0x7d')],'raw':!![]};return db[_0xf796('0x3b')][_0xf796('0x5d')](_0x5899bc)[_0xf796('0x1f')](handleEntityNotFound(_0x240619,null))[_0xf796('0x1f')](function(_0x7c7aca){if(_0x7c7aca){if(!_[_0xf796('0x78')](_0x7c7aca[_0xf796('0x7d')])){if(fs['existsSync'](path[_0xf796('0x74')](config[_0xf796('0x75')],'server/files/images/avatars/',_0x7c7aca['agentAvatar']))){_0x541960=path[_0xf796('0x74')](config[_0xf796('0x75')],'server/files/images/avatars/',_0x7c7aca[_0xf796('0x7d')]);}}return _0x240619[_0xf796('0x7b')](_0x541960);}})['catch'](handleError(_0x240619,null));};exports[_0xf796('0x7e')]=function(_0x342e41,_0x1a1bdb,_0x22e452){var _0x1c84b8=path[_0xf796('0x74')](config[_0xf796('0x75')],_0xf796('0x7f'));var _0x187cb9={'where':{'id':_0x342e41[_0xf796('0x55')]['id']},'attributes':['id','customerAvatar','showCustomerAvatar'],'raw':!![]};return db['ChatWebsite'][_0xf796('0x5d')](_0x187cb9)[_0xf796('0x1f')](handleEntityNotFound(_0x1a1bdb,null))['then'](function(_0x4cbc87){if(_0x4cbc87){if(!_[_0xf796('0x78')](_0x4cbc87[_0xf796('0x80')])){if(fs[_0xf796('0x79')](path[_0xf796('0x74')](config[_0xf796('0x75')],'server/files/images/avatars/',_0x4cbc87[_0xf796('0x80')]))&&_0x4cbc87[_0xf796('0x81')]){_0x1c84b8=path[_0xf796('0x74')](config['root'],_0xf796('0x82'),_0x4cbc87[_0xf796('0x80')]);}}return _0x1a1bdb[_0xf796('0x7b')](_0x1c84b8);}})['catch'](handleError(_0x1a1bdb,null));};exports[_0xf796('0x83')]=function(_0x10ec14,_0x4a6099,_0x18fb7a){var _0x2936e9=path['join'](config[_0xf796('0x75')],_0xf796('0x84'));var _0xa6c8ec={'where':{'id':_0x10ec14[_0xf796('0x55')]['id']},'attributes':['id',_0xf796('0x73')],'raw':!![]};return db[_0xf796('0x3b')][_0xf796('0x5d')](_0xa6c8ec)[_0xf796('0x1f')](handleEntityNotFound(_0x4a6099,null))[_0xf796('0x1f')](function(_0x4f5c3a){if(_0x4f5c3a){if(!_[_0xf796('0x78')](_0x4f5c3a[_0xf796('0x73')])){if(fs[_0xf796('0x79')](path[_0xf796('0x74')](config[_0xf796('0x75')],_0xf796('0x82'),_0x4f5c3a[_0xf796('0x73')]))){_0x2936e9=path[_0xf796('0x74')](config[_0xf796('0x75')],'server/files/images/avatars/',_0x4f5c3a[_0xf796('0x73')]);}}return _0x4a6099[_0xf796('0x7b')](_0x2936e9);}})['catch'](handleError(_0x4a6099,null));};exports[_0xf796('0x85')]=function(_0x20562a,_0x7f68c4,_0x4b6ce6){var _0x38ca57=require(_0xf796('0x86'));var _0x1a649f=new _0x38ca57();var _0x4aa8bc=_0x1a649f['setUA'](_0x20562a[_0xf796('0x87')][_0xf796('0x88')])['getResult']();var _0xf2b457={'body':_0x20562a[_0xf796('0x5a')],'channel':_0xf796('0x89')};var _0x3596fd=[];var _0x541bc1=[];var _0x5d7912={};var _0x5171e5=![];return db[_0xf796('0x8a')][_0xf796('0x64')]()[_0xf796('0x1f')](function(_0x582039){if(!_0x582039){throw new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))](_0xf796('0x8d'));}_0x3596fd=_[_0xf796('0x8e')](_['keys'](_0x582039),[_0xf796('0x8f'),_0xf796('0x90')]);_0x541bc1=_[_0xf796('0x8e')](_['keys'](_0x582039),[_0xf796('0x8f'),'updatedAt',_0xf796('0x91'),_0xf796('0x92')]);if(_0x20562a['body']['id']){delete _0x20562a[_0xf796('0x5a')]['id'];}if(_[_0xf796('0x78')](_0x20562a[_0xf796('0x5a')][_0xf796('0x93')])){throw new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))](_0xf796('0x94'));}if(_[_0xf796('0x78')](_0x20562a[_0xf796('0x5a')][_0xf796('0x5a')])||_0x20562a[_0xf796('0x5a')][_0xf796('0x5a')]===''){throw new db['Sequelize'][(_0xf796('0x8c'))](_0xf796('0x95'));}if(_[_0xf796('0x78')](_0x20562a[_0xf796('0x5a')]['mapKey'])){throw new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))](_0xf796('0x96')+_0x541bc1);}if(!_[_0xf796('0x97')](_0x541bc1,_0x20562a[_0xf796('0x5a')][_0xf796('0x98')])){throw new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x541bc1);}_0x5d7912[_0x20562a[_0xf796('0x5a')]['mapKey']]=_0x20562a['body']['from'];})[_0xf796('0x1f')](function(){return db['ChatWebsite'][_0xf796('0x5d')]({'where':{'id':_0x20562a[_0xf796('0x55')]['id']},'include':[{'model':db[_0xf796('0x99')],'as':'List','include':[{'model':db[_0xf796('0x8a')],'as':_0xf796('0x9a'),'where':_0x5d7912,'limit':0x1,'order':[['updatedAt','DESC']]}]},{'model':db[_0xf796('0x9b')],'as':_0xf796('0x9c')}]});})[_0xf796('0x1f')](handleEntityNotFound(_0x7f68c4,null))[_0xf796('0x1f')](function(_0x22589c){if(_0x22589c&&_0x22589c['List']){_0xf2b457[_0xf796('0x9d')]=_0x22589c;_0xf2b457[_0xf796('0x9e')]=_0x22589c[_0xf796('0x9c')];_0xf2b457[_0xf796('0x9f')]=_0x22589c[_0xf796('0xa0')];_0xf2b457[_0xf796('0x9e')]=_[_0xf796('0xa1')](_0xf2b457[_0xf796('0x9e')],[_0xf796('0xa2')],[_0xf796('0xa3')]);if(_0xf2b457['account'][_0xf796('0x9c')]){delete _0xf2b457[_0xf796('0x9d')][_0xf796('0x9c')];}if(_0xf2b457['account']['List']&&_0xf2b457[_0xf796('0x9d')][_0xf796('0xa0')][_0xf796('0x9a')][_0xf796('0x58')]){return _0xf2b457[_0xf796('0x9d')][_0xf796('0xa0')][_0xf796('0x9a')][0x0];}var _0x3c97e9=_[_0xf796('0x1a')](_0x20562a[_0xf796('0x5a')],{'firstName':_0x20562a[_0xf796('0x5a')]['from'],'ListId':_0x22589c[_0xf796('0x92')]});_0x3c97e9[_0x20562a[_0xf796('0x5a')][_0xf796('0x98')]]=_0x20562a['body'][_0xf796('0x93')];return db[_0xf796('0x8a')][_0xf796('0x59')](_0x3c97e9,{'fields':_0x3596fd,'raw':!![]});}})[_0xf796('0x1f')](handleEntityNotFound(_0x7f68c4,null))[_0xf796('0x1f')](function(_0x4fae14){_0xf2b457[_0xf796('0xa4')]=_0x4fae14;var _0x5a3d96=_0x20562a[_0xf796('0x5a')]['customerIp'];if(_0x20562a[_0xf796('0x87')][_0xf796('0xa5')]){_0x5a3d96=_0x20562a[_0xf796('0x87')]['cf-connecting-ip'];}else if(_0x20562a[_0xf796('0x87')]['x-forwarded-for']){_0x5a3d96=_[_0xf796('0xa6')](_0x20562a[_0xf796('0x87')][_0xf796('0xa7')][_0xf796('0xa8')](','));}if(_0x4fae14){var _0x251f51={'ContactId':_0x4fae14['id'],'ChatWebsiteId':_0x20562a[_0xf796('0x55')]['id'],'from':(_0x4fae14['firstName']||'')+'\x20'+(_0x4fae14[_0xf796('0xa9')]||''),'customerIp':_0x5a3d96,'customerPort':_0x20562a['headers']['x-real-port']?_0x20562a['headers'][_0xf796('0xaa')]:null,'referer':_0x20562a[_0xf796('0x5a')][_0xf796('0xab')],'browserName':_0x4aa8bc[_0xf796('0xac')]['name']&&_0x4aa8bc[_0xf796('0xac')][_0xf796('0xad')]?util['format'](_0xf796('0xae'),_0x4aa8bc[_0xf796('0xac')][_0xf796('0x37')],_0x4aa8bc[_0xf796('0xac')][_0xf796('0xad')]):'unknown','browserVersion':_0x4aa8bc[_0xf796('0xac')][_0xf796('0xad')]||_0xf796('0xaf'),'osName':util[_0xf796('0xb0')](_0xf796('0xae'),_0x4aa8bc['os'][_0xf796('0x37')],_0x4aa8bc['os'][_0xf796('0xad')]),'osVersion':_0x4aa8bc['os'][_0xf796('0xad')],'deviceModel':_0x4aa8bc[_0xf796('0xb1')][_0xf796('0x40')]&&_0x4aa8bc[_0xf796('0xb1')][_0xf796('0xb2')]?util[_0xf796('0xb0')](_0xf796('0xb3'),_0x4aa8bc[_0xf796('0xb1')][_0xf796('0x40')],_0x4aa8bc[_0xf796('0xb1')][_0xf796('0xb2')],_0x4aa8bc[_0xf796('0xb1')]['type']):null,'deviceVendor':_0x4aa8bc[_0xf796('0xb1')][_0xf796('0xb2')],'deviceType':_0x4aa8bc[_0xf796('0xb1')][_0xf796('0x3e')],'formData':JSON[_0xf796('0x24')](_0x20562a[_0xf796('0x5a')])};var _0x191982={'ChatWebsiteId':_0x20562a[_0xf796('0x55')]['id'],'closed':![]};if(_0x20562a[_0xf796('0x5a')][_0xf796('0xb4')]){_0x191982[_0xf796('0xb4')]=_0x20562a[_0xf796('0x5a')][_0xf796('0xb4')];return db[_0xf796('0xb5')]['find']({'where':_0x191982})['then'](function(_0x1f7d5a){if(_0x1f7d5a){return[_0x1f7d5a,![]];}_0x251f51[_0xf796('0xb4')]=_0x20562a['body'][_0xf796('0xb4')];_0x251f51[_0xf796('0xb6')]=_0x20562a['body'][_0xf796('0xb6')];return db['ChatInteraction'][_0xf796('0x59')](_0x251f51)[_0xf796('0x1f')](function(_0x295d7b){return[_0x295d7b,!![]];});});}_0x191982['ContactId']=_0x4fae14['id'];if(_0x20562a[_0xf796('0x5a')][_0xf796('0xb7')]&&_0x20562a[_0xf796('0x5a')]['interaction']['id']){_0x191982['id']=_0x20562a[_0xf796('0x5a')][_0xf796('0xb7')]['id'];return db['ChatInteraction'][_0xf796('0x5d')]({'where':_0x191982})[_0xf796('0x1f')](function(_0x2622d0){if(_0x2622d0){return[_0x2622d0,![]];}return db[_0xf796('0xb5')][_0xf796('0x59')](_0x251f51)[_0xf796('0x1f')](function(_0x241039){return[_0x241039,!![]];});});}return db['ChatInteraction'][_0xf796('0x59')](_0x251f51)['then'](function(_0x1369bc){return[_0x1369bc,!![]];});}})['spread'](function(_0x12c058,_0x3d8373){if(_0x12c058){_0x5171e5=_0x3d8373;if(!_0x3d8373){var _0x2d2d0e={'from':(_0xf2b457[_0xf796('0xa4')][_0xf796('0xb8')]||'')+'\x20'+(_0xf2b457[_0xf796('0xa4')][_0xf796('0xa9')]||'')};if(_0x20562a[_0xf796('0x5a')][_0xf796('0xb4')]&&_0x20562a[_0xf796('0x5a')][_0xf796('0xb9')]&&_0x20562a[_0xf796('0x5a')][_0xf796('0xb4')]!=_0x20562a['body'][_0xf796('0xb9')]){_0x2d2d0e[_0xf796('0xb4')]=_0x20562a['body'][_0xf796('0xb9')];}return _0x12c058[_0xf796('0x62')](_0x2d2d0e);}else{return _0x12c058;}}})[_0xf796('0x1f')](function(_0x3433c8){_0xf2b457[_0xf796('0xb7')]=_0x3433c8[_0xf796('0x33')]({'plain':!![]});_0xf2b457[_0xf796('0xb7')][_0xf796('0xba')]=_0x5171e5;if(_0xf2b457[_0xf796('0xb7')]['created']){if(_0xf2b457[_0xf796('0x9d')][_0xf796('0xbb')]){_0xf2b457[_0xf796('0x9e')]['push']({'id':0x0,'priority':_0xf2b457[_0xf796('0x9e')][_0xf796('0x58')]+0x1,'app':_0xf796('0xbc'),'appdata':_0xf796('0xbd'),'interval':'*,*,*,*'});}}return db[_0xf796('0xbe')][_0xf796('0x59')]({'body':_0x20562a['body'][_0xf796('0x5a')],'ChatWebsiteId':_0x20562a[_0xf796('0x55')]['id'],'ChatInteractionId':_0x3433c8['id'],'direction':'in','ContactId':_0xf2b457[_0xf796('0xa4')]['id'],'AttachmentId':_0x20562a[_0xf796('0x5a')]['AttachmentId']});})[_0xf796('0x1f')](function(_0x390237){_0xf2b457[_0xf796('0x26')]=_0x390237;if(_0xf2b457[_0xf796('0xb7')][_0xf796('0xbf')]){return db[_0xf796('0xc0')][_0xf796('0x5d')]({'attributes':['id',_0xf796('0x37')],'where':{'id':_0xf2b457[_0xf796('0xb7')][_0xf796('0xbf')]}})[_0xf796('0x1f')](function(_0x36ae70){if(_0x36ae70){_0xf2b457[_0xf796('0x9e')]['unshift']({'id':0x0,'priority':0x0,'app':_0xf796('0xc1'),'appdata':_0x36ae70[_0xf796('0x37')]+','+(_0xf2b457['account']['waitForTheAssignedAgent']||0xa),'interval':_0xf796('0xc2')});_0xf2b457[_0xf796('0xc3')]=!![];}return respondWithRpcPromise('Start',_0xf796('0xc4'),_0xf2b457);});}return respondWithRpcPromise(_0xf796('0xc5'),'startRouting',_0xf2b457);})[_0xf796('0x1f')](function(_0x4870f3){respondWithRpcPromise(_0xf796('0xc6'),_0xf796('0xc6'),{'event':_0xf796('0x85'),'message':_0x4870f3},client9002);return _0x4870f3;})[_0xf796('0x1f')](respondWithResult(_0x7f68c4,null))[_0xf796('0x28')](handleError(_0x7f68c4,null));};exports[_0xf796('0xc7')]=function(_0x4d5068,_0x4e6276,_0x2d2098){var _0x8b202e,_0x4ce935,_0x98877;var _0x3c3d73=[];var _0x2383fd=[];var _0x5849dc={};var _0x27e5e7=_0x4d5068[_0xf796('0xc8')]||[];var _0x2fcb30=[];var _0x3aa912;return db['CmContact']['describe']()[_0xf796('0x1f')](function(_0x4231cc){if(!_0x4231cc){throw new db['Sequelize'][(_0xf796('0x8c'))](_0xf796('0x8d'));}_0x2383fd=_[_0xf796('0x8e')](_[_0xf796('0x42')](_0x4231cc),[_0xf796('0x8f'),'updatedAt']);_0x3c3d73=_[_0xf796('0x8e')](_[_0xf796('0x42')](_0x4231cc),[_0xf796('0x8f'),_0xf796('0x90'),_0xf796('0x91'),_0xf796('0x92')]);if(_0x4d5068[_0xf796('0x5a')]['id']){delete _0x4d5068['body']['id'];}if(_[_0xf796('0x78')](_0x4d5068[_0xf796('0x5a')]['from'])){throw _0x4e6276[_0xf796('0x36')](0x1f4)['send'](new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))](_0xf796('0x94')));}if(_[_0xf796('0x78')](_0x4d5068[_0xf796('0x5a')]['body'])||_0x4d5068[_0xf796('0x5a')][_0xf796('0x5a')]===''){throw _0x4e6276[_0xf796('0x36')](0x1f4)['send'](new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))]('body\x20is\x20mandatory\x20and\x20not\x20empty'));}if(_[_0xf796('0x78')](_0x4d5068[_0xf796('0x5a')][_0xf796('0xc9')])){throw _0x4e6276[_0xf796('0x36')](0x1f4)[_0xf796('0x38')](new db[(_0xf796('0x8b'))]['ValidationError']('mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3c3d73));}if(!_[_0xf796('0x97')](_0x3c3d73,_0x4d5068[_0xf796('0x5a')]['mapKeyOffline'])){throw _0x4e6276[_0xf796('0x36')](0x1f4)[_0xf796('0x38')](new db[(_0xf796('0x8b'))][(_0xf796('0x8c'))](_0xf796('0xca')+_0x3c3d73));}_0x5849dc[_0x4d5068[_0xf796('0x5a')][_0xf796('0xc9')]]=_0x4d5068[_0xf796('0x5a')][_0xf796('0x93')];})['then'](function(){return db[_0xf796('0x3b')][_0xf796('0x5d')]({'where':{'id':_0x4d5068[_0xf796('0x55')]['id']},'include':[{'model':db[_0xf796('0x99')],'as':_0xf796('0xa0')},{'model':db[_0xf796('0xcb')],'as':'MailAccount'}]});})[_0xf796('0x1f')](handleEntityNotFound(_0x4e6276,null))[_0xf796('0x1f')](function(_0x55e68f){if(_0x55e68f&&_0x55e68f['List']){_0x4ce935=_0x55e68f;var _0x3a6eab=_[_0xf796('0x1a')](_0x4d5068[_0xf796('0x5a')],{'firstName':_0x4d5068[_0xf796('0x5a')]['from'],'phone':_0x4d5068[_0xf796('0x5a')][_0xf796('0x93')],'ListId':_0x55e68f[_0xf796('0x92')]});_0x3a6eab[_0x4d5068[_0xf796('0x5a')][_0xf796('0xc9')]]=_0x4d5068['body'][_0xf796('0x93')];return db[_0xf796('0x8a')]['findOrCreate']({'where':_0x5849dc,'defaults':_0x3a6eab});}})[_0xf796('0xcc')](function(_0x358c4c){if(_0x358c4c){_0x98877=_0x358c4c;var _0x529660=fs[_0xf796('0xcd')](path[_0xf796('0x74')](config[_0xf796('0x75')],'server/files/templates/chatOfflineMessage.ejs'),_0xf796('0xce'));var _0x2a9efc=ejs[_0xf796('0xcf')](_0x529660,{'body':_[_0xf796('0xd0')](_0x4d5068[_0xf796('0x5a')][_0xf796('0x5a')]),'bodyTitle':_0x4ce935[_0xf796('0xd1')]});return db[_0xf796('0xd2')][_0xf796('0x59')]({'body':_0x2a9efc,'ContactId':_0x358c4c['id'],'ChatWebsiteId':_0x4ce935['id']});}})[_0xf796('0x1f')](function(_0x2ac1dd){_0x3aa912=_0x2ac1dd;if(_0x27e5e7['length']){var _0x27df60=_0x27e5e7[_0xf796('0x3a')](function(_0x1de16c){return{'name':_0x1de16c['originalname'],'basename':_0x1de16c[_0xf796('0x6f')],'type':_0x1de16c[_0xf796('0xd3')],'ChatOfflineMessageId':_0x2ac1dd['id']};});_0x2fcb30=_0x27df60['map'](_0x56e3c1=>{var _0x2053b0={'filename':_0x56e3c1[_0xf796('0x37')],'path':path['join'](config['root'],'server',_0xf796('0xc8'),_0xf796('0xd4'),_0xf796('0xd5'),_0x56e3c1['basename'])};return _0x2053b0;});if(!_0x4ce935['openNewInteraction']){return db[_0xf796('0xd6')]['transaction'](function(_0x18bf5d){return db[_0xf796('0xd7')][_0xf796('0xd8')](_0x27df60,{'transaction':_0x18bf5d});});}}})['then'](function(){if(_0x3aa912){_0x8b202e=_0x3aa912;return db[_0xf796('0xcb')][_0xf796('0x68')]({'where':{'active':!![]},'include':[{'model':db[_0xf796('0xd9')],'as':_0xf796('0xda'),'raw':!![]}]});}})[_0xf796('0x1f')](function(_0x309600){if(_0x309600&&_0x309600[_0xf796('0xda')]&&_0x4ce935[_0xf796('0xdb')]&&_0x4ce935['forwardOfflineAddress']){var _0x44ba51={'tls':{'rejectUnauthorized':![]}};if(_0x309600['Smtp']['service']){_0x44ba51[_0xf796('0xdc')]=_0x309600['Smtp'][_0xf796('0xdc')];}else{_0x44ba51['host']=_0x309600[_0xf796('0xda')][_0xf796('0xdd')];_0x44ba51['port']=_0x309600[_0xf796('0xda')][_0xf796('0xde')];_0x44ba51[_0xf796('0xdf')]=_0x309600[_0xf796('0xda')]['secure'];}if(_0x309600['Smtp'][_0xf796('0xe0')]){_0x44ba51[_0xf796('0xe1')]={'user':_0x309600[_0xf796('0xda')][_0xf796('0x5b')],'pass':_0x309600[_0xf796('0xda')][_0xf796('0xe2')]};}return respondWithRpcPromise(_0xf796('0xe3'),'sendMail',{'account':_0x44ba51,'message':{'from':util[_0xf796('0xb0')](_0xf796('0xe4'),_0x309600[_0xf796('0x37')],_0x309600['email']||_0x309600[_0xf796('0xda')][_0xf796('0x5b')]),'to':_0x4ce935[_0xf796('0xe5')],'subject':_0x4ce935[_0xf796('0xe6')],'html':_0x8b202e[_0xf796('0x5a')],'attachments':_0x2fcb30}},client9003)[_0xf796('0x1f')](function(){return _0x8b202e;})[_0xf796('0x28')](function(_0x616528){console[_0xf796('0x25')](_0x616528);});}})[_0xf796('0x1f')](function(){if(_0x4ce935&&_0x4ce935[_0xf796('0xe7')]&&_0x4ce935[_0xf796('0xe8')]){var _0x2862ef=[];if(_0x27e5e7[_0xf796('0x58')]){_0x2862ef=_0x27e5e7[_0xf796('0x3a')](function(_0xbdd1ff){return{'name':_0xbdd1ff['originalname'],'basename':_0xbdd1ff[_0xf796('0x6f')],'type':_0xbdd1ff[_0xf796('0xd3')],'ChatOfflineMessageId':_0x3aa912['id']};});}var _0xb2fb98;if(!_['isNil'](_0x4ce935[_0xf796('0xe9')])){var _0x3da354=_[_0xf796('0x3a')](_0x4d5068['body'],function(_0x3712f3){return _0x3712f3;});var _0x12982c=_['toPairsIn'](_0x3da354)[0x0];var _0x317e4a=_[_0xf796('0xea')](_0x12982c,function(_0x28a28c){return _0x28a28c;});_0xb2fb98=_0x317e4a[0x1][_0x4ce935[_0xf796('0xe9')]];}var _0x4beb02={'from':_0x98877[_0xf796('0xeb')],'firstName':_0x98877[_0xf796('0xb8')],'lastName':_0x98877[_0xf796('0xa9')],'mapKey':_0xf796('0xeb'),'message':{'from':_0x98877[_0xf796('0xeb')],'to':_0x4ce935['MailAccount'][_0xf796('0xeb')],'cc':'','subject':_[_0xf796('0x78')](_0xb2fb98)?_0x4ce935[_0xf796('0xe6')]:_0xb2fb98,'messageId':'','sentAt':new Date(),'attach':_0x2862ef[_0xf796('0x58')],'attachments':_0x2862ef,'originChannel':_0xf796('0xec'),'ChatWebsiteId':_0x4ce935['id'],'ChatOfflineMessageId':_0x8b202e['id'],'originTo':_0x4ce935[_0xf796('0xcb')][_0xf796('0xeb')]},'body':_0x8b202e[_0xf796('0x5a')]};var _0x44eac6={'account':{'id':_0x4ce935[_0xf796('0xe8')]},'body':_0x4beb02,'log':'NotifyMailAccount'};return respondWithRpcPromise(_0xf796('0xed'),_0xf796('0xee'),_0x44eac6,client9001)[_0xf796('0x1f')](function(){return _0x8b202e;})[_0xf796('0x28')](function(_0x25125a){console[_0xf796('0x25')](_0x25125a);});}return;})[_0xf796('0x1f')](function(){if(_0x8b202e){return _0x8b202e;}})[_0xf796('0x1f')](respondWithResult(_0x4e6276,null))[_0xf796('0x28')](function(_0x253346){console[_0xf796('0x25')]('catch',_0x253346);for(var _0x25a4c5 of _0x27e5e7){var _0x29f6c4=path[_0xf796('0x74')](config[_0xf796('0x75')],_0xf796('0xef'),_0xf796('0xc8'),_0xf796('0xd4'),_0xf796('0xd5'),_0x25a4c5[_0xf796('0x6f')]);fs_extra['remove'](_0x29f6c4)[_0xf796('0x28')](function(_0x160593){console['error']('Could\x20not\x20remove\x20attachment\x20file',_0x29f6c4,_0x160593);});}});};exports[_0xf796('0xf0')]=function(_0x35d078,_0x31cb46,_0x357107){return db[_0xf796('0xb5')][_0xf796('0x5d')]({'where':{'id':_0x35d078[_0xf796('0x55')]['id']}})['then'](handleEntityNotFound(_0x31cb46,null))['then'](function(_0x407d6b){if(_0x407d6b){return _0x407d6b[_0xf796('0xf0')](_0x35d078[_0xf796('0x5a')][_0xf796('0xf1')],_['omit'](_0x35d078[_0xf796('0x5a')],[_0xf796('0xf1'),'id'])||{});}})['then'](respondWithResult(_0x31cb46,null))[_0xf796('0x28')](handleError(_0x31cb46,null));};exports[_0xf796('0xf2')]=function(_0x189714,_0x327b22,_0x44e988){var _0x3775b5={'raw':![],'where':{}};var _0x4e5ebc={};var _0x1317ff={'count':0x0,'rows':[]};return db[_0xf796('0x3b')]['findOne']({'where':{'id':_0x189714[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x327b22,null))[_0xf796('0x1f')](function(_0x182be8){if(_0x182be8){_0x4e5ebc[_0xf796('0x40')]=_['keys'](db[_0xf796('0xb5')]['rawAttributes']);_0x4e5ebc[_0xf796('0x41')]=_['keys'](_0x189714[_0xf796('0x41')]);_0x4e5ebc['filters']=_[_0xf796('0x44')](_0x4e5ebc[_0xf796('0x40')],_0x4e5ebc[_0xf796('0x41')]);_0x3775b5[_0xf796('0x45')]=_['intersection'](_0x4e5ebc[_0xf796('0x40')],qs[_0xf796('0x57')](_0x189714[_0xf796('0x41')]['fields']));_0x3775b5[_0xf796('0x45')]=_0x3775b5[_0xf796('0x45')][_0xf796('0x58')]?_0x3775b5[_0xf796('0x45')]:_0x4e5ebc[_0xf796('0x40')];if(!_0x189714['query'][_0xf796('0x46')]('nolimit')){_0x3775b5['limit']=qs[_0xf796('0x2b')](_0x189714[_0xf796('0x41')][_0xf796('0x2b')]);_0x3775b5[_0xf796('0x2d')]=qs[_0xf796('0x2d')](_0x189714[_0xf796('0x41')][_0xf796('0x2d')]);}_0x3775b5[_0xf796('0x48')]=qs[_0xf796('0x49')](_0x189714[_0xf796('0x41')][_0xf796('0x49')]);_0x3775b5[_0xf796('0x4a')]=qs[_0xf796('0x43')](_[_0xf796('0x4b')](_0x189714[_0xf796('0x41')],_0x4e5ebc['filters']));_0x3775b5[_0xf796('0x4a')][_0xf796('0x66')]=_0x182be8['id'];if(_0x189714[_0xf796('0x41')][_0xf796('0x4c')]){_0x3775b5['where']=_[_0xf796('0x4d')](_0x3775b5[_0xf796('0x4a')],{'$or':_[_0xf796('0x3a')](_0x3775b5[_0xf796('0x45')],function(_0x46a8ab){var _0x8ba0c8={};_0x8ba0c8[_0x46a8ab]={'$like':'%'+_0x189714[_0xf796('0x41')]['filter']+'%'};return _0x8ba0c8;})});}_0x3775b5=_[_0xf796('0x4d')]({},_0x3775b5,_0x189714['options']);return db[_0xf796('0xb5')]['count']({'where':_0x3775b5[_0xf796('0x4a')]})[_0xf796('0x1f')](function(_0xaa549f){_0x1317ff[_0xf796('0x2c')]=_0xaa549f;if(_0x189714[_0xf796('0x41')]['includeAll']){_0x3775b5[_0xf796('0x51')]=[{'model':db[_0xf796('0x8a')],'as':'Contact','required':![]},{'model':db[_0xf796('0xc0')],'as':_0xf796('0xf3'),'attributes':['name','fullname',_0xf796('0xf4')],'required':![]},{'model':db[_0xf796('0xf5')],'as':'Tags','attributes':['id',_0xf796('0x37'),_0xf796('0xf6')],'where':_0x189714[_0xf796('0x41')][_0xf796('0xf7')]?{'id':_0x189714[_0xf796('0x41')][_0xf796('0xf7')]}:undefined,'required':_0x189714[_0xf796('0x41')][_0xf796('0xf7')]?!![]:![]}];}return db[_0xf796('0xb5')][_0xf796('0x52')](_0x3775b5);})[_0xf796('0x1f')](function(_0x3034af){_0x1317ff[_0xf796('0x53')]=_0x3034af;return _0x1317ff;});}})[_0xf796('0x1f')](respondWithFilteredResult(_0x327b22,_0x3775b5))[_0xf796('0x28')](handleError(_0x327b22,null));};function iftimePromise(_0x54f061,_0x5beca0){return respondWithRpcPromise('Command',_0xf796('0xf8'),{'command':_0x5beca0['timezone']?util['format']('iftime\x20%s,%s',_0x54f061[_0xf796('0xf9')],_0x5beca0[_0xf796('0xfa')]):util[_0xf796('0xb0')](_0xf796('0xfb'),_0x54f061[_0xf796('0xf9')])},client9002)[_0xf796('0x1f')](function(_0x50981f){var _0x4dd9fe=_0x50981f&&_0x50981f[_0xf796('0xfc')](_0xf796('0xfd'))>=0x0?!![]:![];logger[_0xf796('0x20')](_0xf796('0xfe'),_0x5beca0['id'],_0x54f061['id'],_0x54f061['interval'],_0x4dd9fe?'ONLINE':_0xf796('0xff'),_0x5beca0[_0xf796('0xfa')]?_0x5beca0[_0xf796('0xfa')]:'No\x20timezone');return _0x4dd9fe;})[_0xf796('0x28')](function(_0x1ae601){logger['error']('[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)',_0x5beca0['id'],_0x54f061['id'],_0x54f061[_0xf796('0xf9')],util['inspect'](_0x1ae601,{'showHidden':![],'depth':null}),_0x5beca0[_0xf796('0xfa')]?_0x5beca0[_0xf796('0xfa')]:_0xf796('0x100'));return![];});}exports[_0xf796('0xf8')]=function(_0x1da28b,_0x575d55,_0x3917be){var _0x17cfdb=0x0;var _0x239882=0x0;var _0x2f4e27=![];var _0x32ff7c;var _0x2b5f07;return db[_0xf796('0x3b')]['find']({'where':{'id':_0x1da28b[_0xf796('0x55')]['id']},'include':[{'model':db[_0xf796('0x101')],'as':_0xf796('0x101'),'include':[{'model':db['Interval'],'as':'Intervals','attributes':['id',_0xf796('0xf9')],'raw':!![]}]}]})[_0xf796('0x1f')](handleEntityNotFound(_0x575d55,null))[_0xf796('0x1f')](function(_0x512ec9){if(_0x512ec9){_0x32ff7c=_0x512ec9;return _0x512ec9[_0xf796('0x102')]({'raw':!![]});}})[_0xf796('0x1f')](function(_0x42832c){if(_0x32ff7c){if(_0x42832c){_0x2b5f07=_0x42832c;}}return require(_0xf796('0x18'))['getLicense']();})[_0xf796('0x1f')](function(_0x544cc0){if(_0x544cc0){_0x239882=_0x544cc0[_0xf796('0x103')];_0x2f4e27=_0x544cc0[_0xf796('0x104')];}})[_0xf796('0x1f')](function(){return db[_0xf796('0xb5')][_0xf796('0x2c')]({'where':{'closed':![]}});})[_0xf796('0x1f')](function(_0x28117e){_0x17cfdb=_0x28117e;if(_0x239882&&_0x28117e>_0x239882){return db['License']['findOne']({'where':{'id':0x1}})['then'](function(_0x4e4ca0){if(_0x4e4ca0){_0x4e4ca0[_0xf796('0x105')]('chatLicenseExceeded');}});}})[_0xf796('0x1f')](function(){if(_0x32ff7c[_0xf796('0x101')]&&_0x32ff7c[_0xf796('0x101')][_0xf796('0x106')]){var _0x286862=[];for(var _0x557204=0x0;_0x557204<_0x32ff7c[_0xf796('0x101')][_0xf796('0x106')][_0xf796('0x58')];_0x557204++){var _0x14c0b6=_0x32ff7c[_0xf796('0x101')]['Intervals'][_0x557204]['get']({'plain':!![]});_0x286862[_0xf796('0x107')](iftimePromise(_0x14c0b6,_0x32ff7c));}return BPromise[_0xf796('0x108')](_0x286862)[_0xf796('0x1f')](function(_0x2c5902){return _[_0xf796('0x109')](_0x2c5902);});}else{return!![];}})[_0xf796('0x1f')](function(_0xaab052){var _0x31773f=fs[_0xf796('0xcd')](path[_0xf796('0x74')](config[_0xf796('0x75')],_0xf796('0x10a')),'utf8');var _0x5d86f4={'remote':_0x32ff7c['remote'],'query':querystring[_0xf796('0x24')](_[_0xf796('0x4d')](_0x32ff7c[_0xf796('0x33')]({'plain':!![]}),{'customerIp':_0x1da28b[_0xf796('0x87')][_0xf796('0xa7')]||_0x1da28b[_0xf796('0x87')]['x-real-ip']||_0x1da28b[_0xf796('0x10b')][_0xf796('0x10c')]||_0x1da28b['ip'],'referer':_0x1da28b[_0xf796('0x87')][_0xf796('0xab')],'openedInteractions':_0x17cfdb,'maxInteractions':_0x239882,'virtual':_0x2f4e27[_0xf796('0x103')],'online':_0xaab052,'custom':_0x2f4e27}))['replace'](/'/g,'\x5c\x27')};_0x575d55[_0xf796('0x38')](ejs[_0xf796('0xcf')](Mustache['render'](_0x31773f,_0x5d86f4),{'proactiveActions':_0x2b5f07,'alignment':_0x32ff7c[_0xf796('0x10d')],'verticalAlignment':_0x32ff7c['verticalAlignment'],'div_color':_0x32ff7c[_0xf796('0xf6')],'text_color':_0x32ff7c['textColor'],'button_color':_0x32ff7c['color_button'],'background_color':_0x32ff7c[_0xf796('0x10e')]}));})[_0xf796('0x28')](handleError(_0x575d55,null));};exports[_0xf796('0x10f')]=function(_0x148732,_0x5629ef,_0x4ede6c){return db[_0xf796('0x3b')][_0xf796('0x68')]({'where':{'id':_0x148732[_0xf796('0x55')]['id']}})['then'](handleEntityNotFound(_0x5629ef,null))[_0xf796('0x1f')](function(_0x4ba596){if(_0x4ba596){return db['sequelize'][_0xf796('0x110')](function(_0x309645){return db[_0xf796('0x9b')][_0xf796('0x35')]({'where':{'ChatWebsiteId':_0x148732[_0xf796('0x55')]['id']},'transaction':_0x309645})[_0xf796('0x1f')](function(_0xbf4293){var _0x2d1bc5=_[_0xf796('0x3a')](_0x148732[_0xf796('0x5a')],function(_0x4df144){_0x4df144[_0xf796('0x66')]=_0x148732[_0xf796('0x55')]['id'];return _0x4df144;});return db[_0xf796('0x9b')][_0xf796('0xd8')](_0x2d1bc5,{'transaction':_0x309645});});})[_0xf796('0x1f')](function(){return db['ChatApplication'][_0xf796('0x111')]({'where':{'ChatWebsiteId':_0x148732['params']['id']},'order':_0xf796('0xa2')});});}})[_0xf796('0x1f')](respondWithResult(_0x5629ef,null))[_0xf796('0x28')](handleError(_0x5629ef,null));};exports[_0xf796('0x112')]=function(_0x101442,_0x52a5dc,_0x22cf1c){var _0x4f35b4={};var _0x3d9404={};var _0x3ec838;var _0x2a99f8;return db[_0xf796('0x3b')]['findOne']({'where':{'id':_0x101442[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x52a5dc,null))[_0xf796('0x1f')](function(_0x21aff9){if(_0x21aff9){_0x3ec838=_0x21aff9;_0x3d9404[_0xf796('0x40')]=_['keys'](db[_0xf796('0x9b')][_0xf796('0x3c')]);_0x3d9404[_0xf796('0x41')]=_[_0xf796('0x42')](_0x101442[_0xf796('0x41')]);_0x3d9404[_0xf796('0x43')]=_['intersection'](_0x3d9404[_0xf796('0x40')],_0x3d9404[_0xf796('0x41')]);_0x4f35b4['attributes']=_[_0xf796('0x44')](_0x3d9404['model'],qs[_0xf796('0x57')](_0x101442[_0xf796('0x41')][_0xf796('0x57')]));_0x4f35b4[_0xf796('0x45')]=_0x4f35b4[_0xf796('0x45')]['length']?_0x4f35b4[_0xf796('0x45')]:_0x3d9404[_0xf796('0x40')];_0x4f35b4['order']=qs[_0xf796('0x49')](_0x101442[_0xf796('0x41')][_0xf796('0x49')]);_0x4f35b4['where']=qs[_0xf796('0x43')](_[_0xf796('0x4b')](_0x101442[_0xf796('0x41')],_0x3d9404['filters']));if(_0x101442['query']['filter']){_0x4f35b4[_0xf796('0x4a')]=_[_0xf796('0x4d')](_0x4f35b4[_0xf796('0x4a')],{'$or':_[_0xf796('0x3a')](_0x4f35b4['attributes'],function(_0x12a83e){var _0x3e1563={};_0x3e1563[_0x12a83e]={'$like':'%'+_0x101442['query'][_0xf796('0x4c')]+'%'};return _0x3e1563;})});}_0x4f35b4=_[_0xf796('0x4d')]({},_0x4f35b4,_0x101442[_0xf796('0x4f')]);return _0x3ec838[_0xf796('0x112')](_0x4f35b4);}})[_0xf796('0x1f')](function(_0x5b2ba2){if(_0x5b2ba2){_0x2a99f8=_0x5b2ba2['length'];if(!_0x101442[_0xf796('0x41')][_0xf796('0x46')](_0xf796('0x47'))){_0x4f35b4[_0xf796('0x2b')]=qs['limit'](_0x101442['query'][_0xf796('0x2b')]);_0x4f35b4[_0xf796('0x2d')]=qs[_0xf796('0x2d')](_0x101442[_0xf796('0x41')][_0xf796('0x2d')]);}return _0x3ec838[_0xf796('0x112')](_0x4f35b4);}})[_0xf796('0x1f')](function(_0x2ad8be){if(_0x2ad8be){return _0x2ad8be?{'count':_0x2a99f8,'rows':_0x2ad8be}:null;}})['then'](respondWithResult(_0x52a5dc,null))[_0xf796('0x28')](handleError(_0x52a5dc,null));};exports[_0xf796('0x113')]=function(_0x42e66f,_0x561aba,_0x101618){return db[_0xf796('0x114')][_0xf796('0x5d')]({'where':{'id':_0x42e66f['params']['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x561aba,null))['then'](function(_0x198c21){if(_0x198c21){return _0x198c21['addProactiveActions'](_0x42e66f[_0xf796('0x5a')][_0xf796('0xf1')],_[_0xf796('0x115')](_0x42e66f['body'],[_0xf796('0xf1'),'id'])||{});}})[_0xf796('0x1f')](respondWithResult(_0x561aba,null))['catch'](handleError(_0x561aba,null));};exports[_0xf796('0x102')]=function(_0x4789,_0x282072,_0x26ad55){var _0x225acb={};var _0x25f6e4={};var _0x4b7644;var _0x4847ed;return db[_0xf796('0x3b')][_0xf796('0x68')]({'where':{'id':_0x4789[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x282072,null))['then'](function(_0x1260af){if(_0x1260af){_0x4b7644=_0x1260af;_0x25f6e4['model']=_[_0xf796('0x42')](db['ChatProactiveAction']['rawAttributes']);_0x25f6e4['query']=_['keys'](_0x4789[_0xf796('0x41')]);_0x25f6e4[_0xf796('0x43')]=_[_0xf796('0x44')](_0x25f6e4[_0xf796('0x40')],_0x25f6e4[_0xf796('0x41')]);_0x225acb[_0xf796('0x45')]=_[_0xf796('0x44')](_0x25f6e4[_0xf796('0x40')],qs[_0xf796('0x57')](_0x4789[_0xf796('0x41')][_0xf796('0x57')]));_0x225acb[_0xf796('0x45')]=_0x225acb[_0xf796('0x45')]['length']?_0x225acb[_0xf796('0x45')]:_0x25f6e4[_0xf796('0x40')];_0x225acb['order']=qs[_0xf796('0x49')](_0x4789[_0xf796('0x41')][_0xf796('0x49')]);_0x225acb[_0xf796('0x4a')]=qs['filters'](_[_0xf796('0x4b')](_0x4789[_0xf796('0x41')],_0x25f6e4[_0xf796('0x43')]));if(_0x4789['query'][_0xf796('0x4c')]){_0x225acb['where']=_['merge'](_0x225acb[_0xf796('0x4a')],{'$or':_[_0xf796('0x3a')](_0x225acb[_0xf796('0x45')],function(_0x3e0687){var _0x25114e={};_0x25114e[_0x3e0687]={'$like':'%'+_0x4789[_0xf796('0x41')]['filter']+'%'};return _0x25114e;})});}_0x225acb=_[_0xf796('0x4d')]({},_0x225acb,_0x4789[_0xf796('0x4f')]);return _0x4b7644['getProactiveActions'](_0x225acb);}})[_0xf796('0x1f')](function(_0xf92386){if(_0xf92386){_0x4847ed=_0xf92386[_0xf796('0x58')];if(!_0x4789[_0xf796('0x41')]['hasOwnProperty'](_0xf796('0x47'))){_0x225acb[_0xf796('0x2b')]=qs['limit'](_0x4789[_0xf796('0x41')][_0xf796('0x2b')]);_0x225acb[_0xf796('0x2d')]=qs[_0xf796('0x2d')](_0x4789[_0xf796('0x41')][_0xf796('0x2d')]);}return _0x4b7644[_0xf796('0x102')](_0x225acb);}})[_0xf796('0x1f')](function(_0xf872a5){if(_0xf872a5){return _0xf872a5?{'count':_0x4847ed,'rows':_0xf872a5}:null;}})['then'](respondWithResult(_0x282072,null))['catch'](handleError(_0x282072,null));};exports[_0xf796('0x116')]=function(_0x3d6474,_0x321fa4,_0x41188b){var _0x294c0d=_0x3d6474['query'][_0xf796('0x117')]===_0xf796('0x118')?_0xf796('0x119'):'onlineForm';return db[_0xf796('0x3b')]['find']({'attributes':['id',_0x294c0d],'where':{'id':_0x3d6474[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x321fa4,null))['then'](function(_0x3fbdc9){if(_0x3fbdc9){var _0xe6c73e=_0x3fbdc9[_0x294c0d];var _0x44a78f=_0xe6c73e&&_0xe6c73e['items']?_0xe6c73e[_0xf796('0x11a')]:[];_0x321fa4[_0xf796('0x38')]({'fromKey':_['isNil'](_0xe6c73e[_0xf796('0x11b')])?undefined:_0xe6c73e['fromKey'],'count':_0x44a78f[_0xf796('0x58')],'rows':_0x44a78f});}})['catch'](handleError(_0x321fa4,null));};exports[_0xf796('0x11c')]=function(_0x543346,_0x355922,_0x563f9c){var _0x309ac0={'raw':![],'where':{}};var _0x141f81={};var _0x19e1d5={'count':0x0,'rows':[]};return db[_0xf796('0x3b')][_0xf796('0x68')]({'where':{'id':_0x543346[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x355922,null))['then'](function(_0x1db05b){if(_0x1db05b){_0x141f81['model']=_[_0xf796('0x42')](db[_0xf796('0xd2')][_0xf796('0x3c')]);_0x141f81['query']=_[_0xf796('0x42')](_0x543346['query']);_0x141f81[_0xf796('0x43')]=_['intersection'](_0x141f81[_0xf796('0x40')],_0x141f81['query']);_0x309ac0[_0xf796('0x45')]=_[_0xf796('0x44')](_0x141f81[_0xf796('0x40')],qs['fields'](_0x543346[_0xf796('0x41')]['fields']));_0x309ac0['attributes']=_0x309ac0[_0xf796('0x45')]['length']?_0x309ac0[_0xf796('0x45')]:_0x141f81[_0xf796('0x40')];if(!_0x543346[_0xf796('0x41')][_0xf796('0x46')](_0xf796('0x47'))){_0x309ac0[_0xf796('0x2b')]=qs[_0xf796('0x2b')](_0x543346[_0xf796('0x41')]['limit']);_0x309ac0['offset']=qs[_0xf796('0x2d')](_0x543346[_0xf796('0x41')][_0xf796('0x2d')]);}_0x309ac0[_0xf796('0x48')]=qs[_0xf796('0x49')](_0x543346['query'][_0xf796('0x49')]);_0x309ac0['where']=qs[_0xf796('0x43')](_[_0xf796('0x4b')](_0x543346[_0xf796('0x41')],_0x141f81[_0xf796('0x43')]));_0x309ac0[_0xf796('0x4a')][_0xf796('0x66')]=_0x1db05b['id'];if(_0x543346[_0xf796('0x41')]['filter']){_0x309ac0[_0xf796('0x4a')]=_['merge'](_0x309ac0[_0xf796('0x4a')],{'$or':_[_0xf796('0x3a')](_0x309ac0[_0xf796('0x45')],function(_0x273008){var _0x3e6c6d={};_0x3e6c6d[_0x273008]={'$like':'%'+_0x543346[_0xf796('0x41')][_0xf796('0x4c')]+'%'};return _0x3e6c6d;})});}_0x309ac0=_[_0xf796('0x4d')]({},_0x309ac0,_0x543346[_0xf796('0x4f')]);return db[_0xf796('0xd2')][_0xf796('0x2c')]({'where':_0x309ac0[_0xf796('0x4a')]})[_0xf796('0x1f')](function(_0x3f3322){_0x19e1d5[_0xf796('0x2c')]=_0x3f3322;if(_0x543346[_0xf796('0x41')]['includeAll']){_0x309ac0[_0xf796('0x51')]=[{'all':!![]}];}else{_0x309ac0[_0xf796('0x51')]=[{'model':db['CmContact'],'as':_0xf796('0x11d'),'required':![]},{'model':db[_0xf796('0xd7')],'as':_0xf796('0x11e'),'required':![]}];}return db['ChatOfflineMessage']['findAll'](_0x309ac0);})[_0xf796('0x1f')](function(_0x9daaf0){_0x19e1d5['rows']=_0x9daaf0;return _0x19e1d5;});}})['then'](respondWithFilteredResult(_0x355922,_0x309ac0))['catch'](handleError(_0x355922,null));};exports['addAgents']=function(_0x5209b4,_0x581980,_0x597586){return db['ChatWebsite'][_0xf796('0x5d')]({'where':{'id':_0x5209b4[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x581980,null))[_0xf796('0x1f')](function(_0xd346ea){if(_0xd346ea){return _0xd346ea[_0xf796('0x11f')](_0x5209b4[_0xf796('0x5a')][_0xf796('0xf1')],_[_0xf796('0x115')](_0x5209b4[_0xf796('0x5a')],[_0xf796('0xf1'),'id'])||{})['spread'](function(_0x3b7d6c){for(var _0x9d1e60=0x0;_0x9d1e60<_0x5209b4[_0xf796('0x5a')][_0xf796('0xf1')][_0xf796('0x58')];_0x9d1e60+=0x1){socket[_0xf796('0x120')](_0xf796('0x121'),{'UserId':Number(_0x5209b4[_0xf796('0x5a')][_0xf796('0xf1')][_0x9d1e60]),'ChatWebsiteId':Number(_0x5209b4[_0xf796('0x55')]['id'])});}return _0x3b7d6c;});}})[_0xf796('0x1f')](respondWithResult(_0x581980,null))[_0xf796('0x28')](handleError(_0x581980,null));};exports[_0xf796('0x122')]=function(_0x8aecef,_0x119887,_0x5960fa){return db['ChatWebsite'][_0xf796('0x5d')]({'where':{'id':_0x8aecef[_0xf796('0x55')]['id']}})['then'](handleEntityNotFound(_0x119887,null))[_0xf796('0x1f')](function(_0x27afca){if(_0x27afca){return _0x27afca[_0xf796('0x122')](_0x8aecef[_0xf796('0x41')]['ids'])[_0xf796('0x1f')](function(){if(_[_0xf796('0x123')](_0x8aecef[_0xf796('0x41')][_0xf796('0xf1')])){for(var _0x1524b4=0x0;_0x1524b4<_0x8aecef[_0xf796('0x41')][_0xf796('0xf1')][_0xf796('0x58')];_0x1524b4+=0x1){socket[_0xf796('0x120')](_0xf796('0x124'),{'UserId':Number(_0x8aecef[_0xf796('0x41')][_0xf796('0xf1')][_0x1524b4]),'ChatWebsiteId':Number(_0x8aecef['params']['id'])});}}else{socket[_0xf796('0x120')](_0xf796('0x124'),{'UserId':Number(_0x8aecef[_0xf796('0x41')][_0xf796('0xf1')]),'ChatWebsiteId':Number(_0x8aecef[_0xf796('0x55')]['id'])});}});}})[_0xf796('0x1f')](respondWithStatusCode(_0x119887,null))[_0xf796('0x28')](handleError(_0x119887,null));};exports[_0xf796('0x125')]=function(_0x5a9856,_0x3472d3,_0x219ff0){var _0x5781cc={};var _0x562099={};var _0x2462eb;var _0x38a232;return db[_0xf796('0x3b')][_0xf796('0x68')]({'where':{'id':_0x5a9856[_0xf796('0x55')]['id']}})[_0xf796('0x1f')](handleEntityNotFound(_0x3472d3,null))[_0xf796('0x1f')](function(_0x4ed21d){if(_0x4ed21d){_0x2462eb=_0x4ed21d;_0x562099[_0xf796('0x40')]=_[_0xf796('0x42')](db[_0xf796('0xc0')][_0xf796('0x3c')]);_0x562099['query']=_['keys'](_0x5a9856[_0xf796('0x41')]);_0x562099[_0xf796('0x43')]=_[_0xf796('0x44')](_0x562099[_0xf796('0x40')],_0x562099['query']);_0x5781cc[_0xf796('0x45')]=_['intersection'](_0x562099['model'],qs[_0xf796('0x57')](_0x5a9856['query']['fields']));_0x5781cc['attributes']=_0x5781cc[_0xf796('0x45')]['length']?_0x5781cc['attributes']:_0x562099[_0xf796('0x40')];_0x5781cc['order']=qs[_0xf796('0x49')](_0x5a9856[_0xf796('0x41')]['sort']);_0x5781cc[_0xf796('0x4a')]=qs[_0xf796('0x43')](_[_0xf796('0x4b')](_0x5a9856['query'],_0x562099[_0xf796('0x43')]));if(_0x5a9856[_0xf796('0x41')][_0xf796('0x4c')]){_0x5781cc['where']=_[_0xf796('0x4d')](_0x5781cc['where'],{'$or':_[_0xf796('0x3a')](_0x5781cc[_0xf796('0x45')],function(_0x3f8da0){var _0x44f2c3={};_0x44f2c3[_0x3f8da0]={'$like':'%'+_0x5a9856[_0xf796('0x41')][_0xf796('0x4c')]+'%'};return _0x44f2c3;})});}_0x5781cc=_[_0xf796('0x4d')]({},_0x5781cc,_0x5a9856[_0xf796('0x4f')]);return _0x2462eb[_0xf796('0x125')](_0x5781cc);}})['then'](function(_0x304855){if(_0x304855){_0x38a232=_0x304855[_0xf796('0x58')];if(!_0x5a9856[_0xf796('0x41')]['hasOwnProperty'](_0xf796('0x47'))){_0x5781cc[_0xf796('0x2b')]=qs[_0xf796('0x2b')](_0x5a9856['query'][_0xf796('0x2b')]);_0x5781cc[_0xf796('0x2d')]=qs[_0xf796('0x2d')](_0x5a9856[_0xf796('0x41')]['offset']);}return _0x2462eb[_0xf796('0x125')](_0x5781cc);}})[_0xf796('0x1f')](function(_0x3589eb){if(_0x3589eb){return _0x3589eb?{'count':_0x38a232,'rows':_0x3589eb}:null;}})[_0xf796('0x1f')](respondWithResult(_0x3472d3,null))[_0xf796('0x28')](handleError(_0x3472d3,null));};