Built motion from commit f7863d46.|2.5.41
[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 _0xf7c3=['[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','OFFLINE','No\x20timezone','inspect','Interval','virtual','custom','License','increment','Intervals','all','some','x-real-ip','connection','remoteAddress','replace','alignment','verticalAlignment','labelText','textColor','color_button','backgroundColor','addApplications','Transaction','ISOLATION_LEVELS','READ_COMMITTED','findAndCountAll','finally','getApplications','addProactiveActions','chatProactiveAction','getProactiveActions','ChatProactiveAction','online','false','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','userChatWebsite:save','removeAgents','emit','userChatWebsite:remove','getAgents','bluebird','mustache','util','path','fs-extra','querystring','ioredis','../../components/parsers/qs','api','../../config/environment','redis','socket.io-emitter','./chatWebsite.socket','jayson/promise','client','http','info','ChatWebsite,\x20%s,\x20%s','request\x20sent','debug','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','end','status','json','offset','undefined','limit','set','Content-Range','update','then','destroy','get','UserProfileResource','sendStatus','stack','send','Pause','map','ChatWebsite','rawAttributes','fieldName','type','keys','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','name','options','count','includeAll','params','include','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','ChatWebsites','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','mandatoryDispositionPause','describe','addDisposition','Disposition','getDispositions','findOne','ChatWebsiteId','findAll','CannedAnswer','getAnswers','rows','removeAnswers','ids','addLogo','sitepic','file','filename','agentAvatar','addCustomerAvatar','customerAvatar','addSystemAvatar','systemAvatar','getLogo','join','server/files/images/logos/default_logo.svg','../../config/license/util','getLicense','isNil','existsSync','root','server/files/images/logos/','server/files/images/avatars/default_avatar.png','server/files/images/avatars/','download','getCustomerAvatar','showCustomerAvatar','getSystemAvatar','setUA','user-agent','getResult','chat','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','Sequelize','from\x20is\x20mandatory','mapKey','from','CmList','List','CmContact','Contacts','ChatApplication','Applications','account','applications','list','priority','asc','defaults','contact','customerIp','headers','cf-connecting-ip','first','x-forwarded-for','split','lastName','x-real-port','referer','browser','%s\x20%s','version','unknown','format','device','vendor','%s\x20%s\x20%s','threadId','externalUrl','ChatInteraction','ContactId','interaction','spread','firstName','messageId','created','autoclose','push','unmanaged','ChatMessage','AttachmentId','UserId','User','unshift','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','notify','offline','files','CompanyId','mapKeyOffline','includes','MailAccount','findOrCreate','readFileSync','utf8','render','toPairs','offlineMessageBody','ChatOfflineMessage','originalname','mimetype','attachments','basename','openNewInteraction','sequelize','transaction','bulkCreate','Smtp','forwardOffline','forwardOfflineAddress','service','host','port','secure','authentication','SendMail','sendMail','\x22%s\x22\x20<%s>','email','MailAccountId','toPairsIn','mapValues','subjectOffline','offlineMessageSubject','NotifyMailAccount','notifyMail','server','offline-chat','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','Owner','internal','Tags','color','tag','Command','getSnippet','timezone','interval','iftime\x20%s','indexOf','true'];(function(_0x24d2f0,_0x453d58){var _0x31fb21=function(_0x2f03f9){while(--_0x2f03f9){_0x24d2f0['push'](_0x24d2f0['shift']());}};_0x31fb21(++_0x453d58);}(_0xf7c3,0x154));var _0x3f7c=function(_0x14d04b,_0xa8059){_0x14d04b=_0x14d04b-0x0;var _0xef65f8=_0xf7c3[_0x14d04b];return _0xef65f8;};'use strict';var BPromise=require(_0x3f7c('0x0'));var Mustache=require(_0x3f7c('0x1'));var util=require(_0x3f7c('0x2'));var path=require(_0x3f7c('0x3'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3f7c('0x4'));var _=require('lodash');var querystring=require(_0x3f7c('0x5'));var Redis=require(_0x3f7c('0x6'));var qs=require(_0x3f7c('0x7'));var logger=require('../../config/logger')(_0x3f7c('0x8'));var config=require(_0x3f7c('0x9'));var db=require('../../mysqldb')['db'];config[_0x3f7c('0xa')]=_['defaults'](config[_0x3f7c('0xa')],{'host':'localhost','port':0x18eb});var socket=require(_0x3f7c('0xb'))(new Redis(config[_0x3f7c('0xa')]));require(_0x3f7c('0xc'))['register'](socket);var jayson=require(_0x3f7c('0xd'));var client=jayson[_0x3f7c('0xe')][_0x3f7c('0xf')]({'port':0x232c});var client9002=jayson[_0x3f7c('0xe')]['http']({'port':0x232a});var client9003=jayson['client'][_0x3f7c('0xf')]({'port':0x232b});var client9001=jayson[_0x3f7c('0xe')]['http']({'port':0x2329});function respondWithRpcPromise(_0x174e31,_0x1de8d4,_0x376518,_0x3fe5b1){return new BPromise(function(_0x4a61ef,_0x1c0f0c){var _0x23434a=_0x3fe5b1||client;return _0x23434a['request'](_0x174e31,_0x376518)['then'](function(_0x4f255f){logger[_0x3f7c('0x10')](_0x3f7c('0x11'),_0x1de8d4,_0x3f7c('0x12'));logger[_0x3f7c('0x13')](_0x3f7c('0x14'),_0x1de8d4,'request\x20sent',JSON[_0x3f7c('0x15')](_0x4f255f));if(_0x4f255f[_0x3f7c('0x16')]){if(_0x4f255f['error']['code']===0x1f4){logger[_0x3f7c('0x16')](_0x3f7c('0x11'),_0x1de8d4,_0x4f255f['error'][_0x3f7c('0x17')]);return _0x1c0f0c(_0x4f255f[_0x3f7c('0x16')][_0x3f7c('0x17')]);}logger['error'](_0x3f7c('0x11'),_0x1de8d4,_0x4f255f[_0x3f7c('0x16')][_0x3f7c('0x17')]);return _0x4a61ef(_0x4f255f['error'][_0x3f7c('0x17')]);}else{logger[_0x3f7c('0x10')]('ChatWebsite,\x20%s,\x20%s',_0x1de8d4,_0x3f7c('0x12'));_0x4a61ef(_0x4f255f[_0x3f7c('0x18')][_0x3f7c('0x17')]);}})[_0x3f7c('0x19')](function(_0x3720f4){logger[_0x3f7c('0x16')](_0x3f7c('0x11'),_0x1de8d4,_0x3720f4);_0x1c0f0c(_0x3720f4);});});}function respondWithStatusCode(_0x3bdcf2,_0x23b133){_0x23b133=_0x23b133||0xcc;return function(_0x377f50){if(_0x377f50){return _0x3bdcf2['sendStatus'](_0x23b133);}return _0x3bdcf2['status'](_0x23b133)[_0x3f7c('0x1a')]();};}function respondWithResult(_0x1067a5,_0x2dcb02){_0x2dcb02=_0x2dcb02||0xc8;return function(_0x3e6bc3){if(_0x3e6bc3){return _0x1067a5[_0x3f7c('0x1b')](_0x2dcb02)[_0x3f7c('0x1c')](_0x3e6bc3);}};}function respondWithFilteredResult(_0x31f964,_0x472007){return function(_0x235212){if(_0x235212){var _0x3b6e4e=typeof _0x472007[_0x3f7c('0x1d')]===_0x3f7c('0x1e')&&typeof _0x472007[_0x3f7c('0x1f')]===_0x3f7c('0x1e');var _0xc21d4a=_0x235212['count'];var _0x39fac1=_0x3b6e4e?0x0:_0x472007[_0x3f7c('0x1d')];var _0x3fef2a=_0x3b6e4e?_0x235212['count']:_0x472007[_0x3f7c('0x1d')]+_0x472007[_0x3f7c('0x1f')];var _0x43aee5;if(_0x3fef2a>=_0xc21d4a){_0x3fef2a=_0xc21d4a;_0x43aee5=0xc8;}else{_0x43aee5=0xce;}_0x31f964[_0x3f7c('0x1b')](_0x43aee5);return _0x31f964[_0x3f7c('0x20')](_0x3f7c('0x21'),_0x39fac1+'-'+_0x3fef2a+'/'+_0xc21d4a)[_0x3f7c('0x1c')](_0x235212);}return null;};}function saveUpdates(_0x296301){return function(_0x16c879){if(_0x16c879){return _0x16c879[_0x3f7c('0x22')](_0x296301)[_0x3f7c('0x23')](function(_0x22ab78){return _0x22ab78;});}return null;};}function removeEntity(_0xb2810f){return function(_0x50863c){if(_0x50863c){return _0x50863c[_0x3f7c('0x24')]()[_0x3f7c('0x23')](function(){var _0x4132da=_0x50863c[_0x3f7c('0x25')]({'plain':!![]});var _0x5292d3='ChatWebsites';return db[_0x3f7c('0x26')]['destroy']({'where':{'type':_0x5292d3,'resourceId':_0x4132da['id']}})[_0x3f7c('0x23')](function(){return _0x50863c;});})[_0x3f7c('0x23')](function(){_0xb2810f[_0x3f7c('0x1b')](0xcc)[_0x3f7c('0x1a')]();});}};}function handleEntityNotFound(_0x2ead0b){return function(_0x42ecdb){if(!_0x42ecdb){_0x2ead0b[_0x3f7c('0x27')](0x194);}return _0x42ecdb;};}function handleError(_0x300112,_0x31e9e3){_0x31e9e3=_0x31e9e3||0x1f4;return function(_0x31488e){logger['error'](_0x31488e[_0x3f7c('0x28')]);if(_0x31488e['name']){delete _0x31488e['name'];}_0x300112[_0x3f7c('0x1b')](_0x31e9e3)[_0x3f7c('0x29')](_0x31488e);};}exports['index']=function(_0x58c266,_0x2a306f){var _0x433ff7={'include':[{'model':db[_0x3f7c('0x2a')],'as':'mandatoryDispositionPause'}]},_0x70df6={},_0x19bc56={'count':0x0,'rows':[]};var _0x177e1f=_[_0x3f7c('0x2b')](db[_0x3f7c('0x2c')][_0x3f7c('0x2d')],function(_0x284b7a){return{'name':_0x284b7a[_0x3f7c('0x2e')],'type':_0x284b7a[_0x3f7c('0x2f')]['key']};});_0x70df6['model']=_[_0x3f7c('0x2b')](_0x177e1f,'name');_0x70df6['query']=_[_0x3f7c('0x30')](_0x58c266[_0x3f7c('0x31')]);_0x70df6['filters']=_[_0x3f7c('0x32')](_0x70df6[_0x3f7c('0x33')],_0x70df6[_0x3f7c('0x31')]);_0x433ff7[_0x3f7c('0x34')]=_['intersection'](_0x70df6[_0x3f7c('0x33')],qs['fields'](_0x58c266[_0x3f7c('0x31')][_0x3f7c('0x35')]));_0x433ff7['attributes']=_0x433ff7[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x433ff7[_0x3f7c('0x34')]:_0x70df6[_0x3f7c('0x33')];if(!_0x58c266[_0x3f7c('0x31')][_0x3f7c('0x37')](_0x3f7c('0x38'))){_0x433ff7[_0x3f7c('0x1f')]=qs[_0x3f7c('0x1f')](_0x58c266[_0x3f7c('0x31')][_0x3f7c('0x1f')]);_0x433ff7['offset']=qs[_0x3f7c('0x1d')](_0x58c266[_0x3f7c('0x31')]['offset']);}_0x433ff7[_0x3f7c('0x39')]=qs[_0x3f7c('0x3a')](_0x58c266[_0x3f7c('0x31')]['sort']);_0x433ff7[_0x3f7c('0x3b')]=qs[_0x3f7c('0x3c')](_[_0x3f7c('0x3d')](_0x58c266['query'],_0x70df6[_0x3f7c('0x3c')]),_0x177e1f);if(_0x58c266[_0x3f7c('0x31')][_0x3f7c('0x3e')]){_0x433ff7[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x433ff7[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x177e1f,function(_0x2c52fd){if(_0x2c52fd[_0x3f7c('0x2f')]!=='VIRTUAL'){var _0x20e268={};_0x20e268[_0x2c52fd[_0x3f7c('0x40')]]={'$like':'%'+_0x58c266[_0x3f7c('0x31')]['filter']+'%'};return _0x20e268;}})});}_0x433ff7=_['merge']({},_0x433ff7,_0x58c266[_0x3f7c('0x41')]);var _0x22f39c={'where':_0x433ff7[_0x3f7c('0x3b')]};return db[_0x3f7c('0x2c')][_0x3f7c('0x42')](_0x22f39c)[_0x3f7c('0x23')](function(_0x4a47a4){_0x19bc56[_0x3f7c('0x42')]=_0x4a47a4;if(_0x58c266[_0x3f7c('0x31')][_0x3f7c('0x43')]){_0x433ff7['include']=[{'all':!![]}];}return db['ChatWebsite']['findAll'](_0x433ff7);})[_0x3f7c('0x23')](function(_0x4d7e13){_0x19bc56['rows']=_0x4d7e13;return _0x19bc56;})['then'](respondWithFilteredResult(_0x2a306f,_0x433ff7))[_0x3f7c('0x19')](handleError(_0x2a306f,null));};exports['show']=function(_0x2d530a,_0x3d020c){var _0x2bb919={'raw':![],'where':{'id':_0x2d530a[_0x3f7c('0x44')]['id']},'include':[{'model':db[_0x3f7c('0x2a')],'as':'mandatoryDispositionPause'}]},_0x3d10b4={};_0x3d10b4[_0x3f7c('0x33')]=_[_0x3f7c('0x30')](db[_0x3f7c('0x2c')][_0x3f7c('0x2d')]);_0x3d10b4['query']=_[_0x3f7c('0x30')](_0x2d530a[_0x3f7c('0x31')]);_0x3d10b4['filters']=_[_0x3f7c('0x32')](_0x3d10b4[_0x3f7c('0x33')],_0x3d10b4[_0x3f7c('0x31')]);_0x2bb919['attributes']=_[_0x3f7c('0x32')](_0x3d10b4[_0x3f7c('0x33')],qs[_0x3f7c('0x35')](_0x2d530a[_0x3f7c('0x31')]['fields']));_0x2bb919[_0x3f7c('0x34')]=_0x2bb919[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x2bb919['attributes']:_0x3d10b4[_0x3f7c('0x33')];if(_0x2d530a[_0x3f7c('0x31')][_0x3f7c('0x43')]){_0x2bb919[_0x3f7c('0x45')]=[{'all':!![]}];}_0x2bb919=_[_0x3f7c('0x3f')]({},_0x2bb919,_0x2d530a[_0x3f7c('0x41')]);return db['ChatWebsite']['find'](_0x2bb919)[_0x3f7c('0x23')](handleEntityNotFound(_0x3d020c,null))[_0x3f7c('0x23')](respondWithResult(_0x3d020c,null))[_0x3f7c('0x19')](handleError(_0x3d020c,null));};exports[_0x3f7c('0x46')]=function(_0x48aed5,_0x4b704b){return db[_0x3f7c('0x2c')][_0x3f7c('0x46')](_0x48aed5['body'],{})['then'](function(_0x4a47aa){var _0x302560=_0x48aed5['user'][_0x3f7c('0x25')]({'plain':!![]});if(!_0x302560)throw new Error(_0x3f7c('0x47'));if(_0x302560[_0x3f7c('0x48')]===_0x3f7c('0x49')){var _0x264cf6=_0x4a47aa[_0x3f7c('0x25')]({'plain':!![]});var _0x2c4259=_0x3f7c('0x4a');return db[_0x3f7c('0x4b')][_0x3f7c('0x4c')]({'where':{'name':_0x2c4259,'userProfileId':_0x302560[_0x3f7c('0x4d')]},'raw':!![]})['then'](function(_0xa81a36){if(_0xa81a36&&_0xa81a36[_0x3f7c('0x4e')]===0x0){return db[_0x3f7c('0x26')][_0x3f7c('0x46')]({'name':_0x264cf6['name'],'resourceId':_0x264cf6['id'],'type':_0xa81a36['name'],'sectionId':_0xa81a36['id']},{})['then'](function(){return _0x4a47aa;});}else{return _0x4a47aa;}})['catch'](function(_0x2e49c1){logger[_0x3f7c('0x16')](_0x3f7c('0x4f'),_0x2e49c1);throw _0x2e49c1;});}return _0x4a47aa;})[_0x3f7c('0x23')](respondWithResult(_0x4b704b,0xc9))[_0x3f7c('0x19')](handleError(_0x4b704b,null));};exports[_0x3f7c('0x22')]=function(_0x41d924,_0x246230){if(_0x41d924[_0x3f7c('0x50')]['id']){delete _0x41d924[_0x3f7c('0x50')]['id'];}return db['ChatWebsite'][_0x3f7c('0x4c')]({'where':{'id':_0x41d924[_0x3f7c('0x44')]['id']},'include':[{'model':db[_0x3f7c('0x2a')],'as':_0x3f7c('0x51')}]})[_0x3f7c('0x23')](handleEntityNotFound(_0x246230,null))['then'](saveUpdates(_0x41d924[_0x3f7c('0x50')],null))[_0x3f7c('0x23')](respondWithResult(_0x246230,null))[_0x3f7c('0x19')](handleError(_0x246230,null));};exports[_0x3f7c('0x24')]=function(_0x4020e1,_0x33faee){return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x4020e1[_0x3f7c('0x44')]['id']}})['then'](handleEntityNotFound(_0x33faee,null))[_0x3f7c('0x23')](removeEntity(_0x33faee,null))[_0x3f7c('0x19')](handleError(_0x33faee,null));};exports[_0x3f7c('0x52')]=function(_0x37327d,_0x2b887b){return db[_0x3f7c('0x2c')][_0x3f7c('0x52')]()['then'](respondWithResult(_0x2b887b,null))[_0x3f7c('0x19')](handleError(_0x2b887b,null));};exports[_0x3f7c('0x53')]=function(_0x18d736,_0x102869){if(_0x18d736[_0x3f7c('0x50')]['id']){delete _0x18d736[_0x3f7c('0x50')]['id'];}return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x18d736[_0x3f7c('0x44')]['id']}})['then'](handleEntityNotFound(_0x102869,null))['then'](function(_0x2845b3){if(_0x2845b3){_0x18d736['body']['ChatWebsiteId']=_0x2845b3['id'];return db[_0x3f7c('0x54')]['create'](_0x18d736[_0x3f7c('0x50')]);}})[_0x3f7c('0x23')](respondWithResult(_0x102869,null))[_0x3f7c('0x19')](handleError(_0x102869,null));};exports[_0x3f7c('0x55')]=function(_0x125715,_0x4e82b1){var _0x143641={'raw':![],'where':{}};var _0x409498={};var _0x7a90cf={'count':0x0,'rows':[]};return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0x125715[_0x3f7c('0x44')]['id']}})['then'](handleEntityNotFound(_0x4e82b1,null))[_0x3f7c('0x23')](function(_0x23e336){if(_0x23e336){_0x409498[_0x3f7c('0x33')]=_['keys'](db['Disposition'][_0x3f7c('0x2d')]);_0x409498['query']=_[_0x3f7c('0x30')](_0x125715[_0x3f7c('0x31')]);_0x409498[_0x3f7c('0x3c')]=_[_0x3f7c('0x32')](_0x409498[_0x3f7c('0x33')],_0x409498[_0x3f7c('0x31')]);_0x143641[_0x3f7c('0x34')]=_[_0x3f7c('0x32')](_0x409498[_0x3f7c('0x33')],qs[_0x3f7c('0x35')](_0x125715['query'][_0x3f7c('0x35')]));_0x143641[_0x3f7c('0x34')]=_0x143641[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x143641[_0x3f7c('0x34')]:_0x409498[_0x3f7c('0x33')];if(!_0x125715[_0x3f7c('0x31')][_0x3f7c('0x37')]('nolimit')){_0x143641['limit']=qs['limit'](_0x125715['query'][_0x3f7c('0x1f')]);_0x143641[_0x3f7c('0x1d')]=qs['offset'](_0x125715[_0x3f7c('0x31')]['offset']);}_0x143641['order']=qs[_0x3f7c('0x3a')](_0x125715[_0x3f7c('0x31')][_0x3f7c('0x3a')]);_0x143641['where']=qs[_0x3f7c('0x3c')](_[_0x3f7c('0x3d')](_0x125715[_0x3f7c('0x31')],_0x409498[_0x3f7c('0x3c')]));_0x143641[_0x3f7c('0x3b')][_0x3f7c('0x57')]=_0x23e336['id'];if(_0x125715[_0x3f7c('0x31')]['filter']){_0x143641[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x143641['where'],{'$or':_[_0x3f7c('0x2b')](_0x143641['attributes'],function(_0x5c980f){var _0x3e5b11={};_0x3e5b11[_0x5c980f]={'$like':'%'+_0x125715['query'][_0x3f7c('0x3e')]+'%'};return _0x3e5b11;})});}_0x143641=_[_0x3f7c('0x3f')]({},_0x143641,_0x125715[_0x3f7c('0x41')]);return db['Disposition']['count']({'where':_0x143641[_0x3f7c('0x3b')]})[_0x3f7c('0x23')](function(_0x13c2eb){_0x7a90cf[_0x3f7c('0x42')]=_0x13c2eb;if(_0x125715['query'][_0x3f7c('0x43')]){_0x143641[_0x3f7c('0x45')]=[{'all':!![]}];}return db[_0x3f7c('0x54')][_0x3f7c('0x58')](_0x143641);})[_0x3f7c('0x23')](function(_0x4045ff){_0x7a90cf['rows']=_0x4045ff;return _0x7a90cf;});}})[_0x3f7c('0x23')](respondWithFilteredResult(_0x4e82b1,_0x143641))[_0x3f7c('0x19')](handleError(_0x4e82b1,null));};exports['removeDispositions']=function(_0x1cb553,_0x202ec1){return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x1cb553[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x202ec1,null))['then'](function(_0x497196){if(_0x497196){return _0x497196['removeDispositions'](_0x1cb553[_0x3f7c('0x31')]['ids']);}})[_0x3f7c('0x23')](respondWithStatusCode(_0x202ec1,null))[_0x3f7c('0x19')](handleError(_0x202ec1,null));};exports['addAnswer']=function(_0x4c540e,_0x3fd232){if(_0x4c540e[_0x3f7c('0x50')]['id']){delete _0x4c540e[_0x3f7c('0x50')]['id'];}return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x4c540e[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x3fd232,null))[_0x3f7c('0x23')](function(_0x5b93f9){if(_0x5b93f9){_0x4c540e[_0x3f7c('0x50')][_0x3f7c('0x57')]=_0x5b93f9['id'];return db[_0x3f7c('0x59')][_0x3f7c('0x46')](_0x4c540e[_0x3f7c('0x50')]);}})['then'](respondWithResult(_0x3fd232,null))[_0x3f7c('0x19')](handleError(_0x3fd232,null));};exports[_0x3f7c('0x5a')]=function(_0x430918,_0x46d414){var _0x512c28={'raw':![],'where':{}};var _0x5329fd={};var _0x3e3909={'count':0x0,'rows':[]};return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0x430918[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x46d414,null))['then'](function(_0x280346){if(_0x280346){_0x5329fd[_0x3f7c('0x33')]=_[_0x3f7c('0x30')](db[_0x3f7c('0x59')][_0x3f7c('0x2d')]);_0x5329fd[_0x3f7c('0x31')]=_[_0x3f7c('0x30')](_0x430918['query']);_0x5329fd['filters']=_[_0x3f7c('0x32')](_0x5329fd[_0x3f7c('0x33')],_0x5329fd[_0x3f7c('0x31')]);_0x512c28['attributes']=_['intersection'](_0x5329fd[_0x3f7c('0x33')],qs[_0x3f7c('0x35')](_0x430918['query']['fields']));_0x512c28[_0x3f7c('0x34')]=_0x512c28[_0x3f7c('0x34')]['length']?_0x512c28[_0x3f7c('0x34')]:_0x5329fd[_0x3f7c('0x33')];if(!_0x430918['query'][_0x3f7c('0x37')](_0x3f7c('0x38'))){_0x512c28[_0x3f7c('0x1f')]=qs['limit'](_0x430918[_0x3f7c('0x31')]['limit']);_0x512c28[_0x3f7c('0x1d')]=qs[_0x3f7c('0x1d')](_0x430918['query'][_0x3f7c('0x1d')]);}_0x512c28['order']=qs[_0x3f7c('0x3a')](_0x430918['query'][_0x3f7c('0x3a')]);_0x512c28['where']=qs[_0x3f7c('0x3c')](_['pick'](_0x430918[_0x3f7c('0x31')],_0x5329fd['filters']));_0x512c28[_0x3f7c('0x3b')][_0x3f7c('0x57')]=_0x280346['id'];if(_0x430918[_0x3f7c('0x31')][_0x3f7c('0x3e')]){_0x512c28[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x512c28[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x512c28[_0x3f7c('0x34')],function(_0xff51e9){var _0x1b56ea={};_0x1b56ea[_0xff51e9]={'$like':'%'+_0x430918['query'][_0x3f7c('0x3e')]+'%'};return _0x1b56ea;})});}_0x512c28=_[_0x3f7c('0x3f')]({},_0x512c28,_0x430918[_0x3f7c('0x41')]);return db['CannedAnswer'][_0x3f7c('0x42')]({'where':_0x512c28['where']})[_0x3f7c('0x23')](function(_0x4ac8b1){_0x3e3909[_0x3f7c('0x42')]=_0x4ac8b1;if(_0x430918[_0x3f7c('0x31')][_0x3f7c('0x43')]){_0x512c28[_0x3f7c('0x45')]=[{'all':!![]}];}return db[_0x3f7c('0x59')][_0x3f7c('0x58')](_0x512c28);})[_0x3f7c('0x23')](function(_0x1e186d){_0x3e3909[_0x3f7c('0x5b')]=_0x1e186d;return _0x3e3909;});}})[_0x3f7c('0x23')](respondWithFilteredResult(_0x46d414,_0x512c28))[_0x3f7c('0x19')](handleError(_0x46d414,null));};exports[_0x3f7c('0x5c')]=function(_0x1f1b58,_0xe74ece){return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x1f1b58[_0x3f7c('0x44')]['id']}})['then'](handleEntityNotFound(_0xe74ece,null))['then'](function(_0x57692a){if(_0x57692a){return _0x57692a[_0x3f7c('0x5c')](_0x1f1b58[_0x3f7c('0x31')][_0x3f7c('0x5d')]);}})[_0x3f7c('0x23')](respondWithStatusCode(_0xe74ece,null))['catch'](handleError(_0xe74ece,null));};exports[_0x3f7c('0x5e')]=function(_0x49c3ac,_0x3dcb7d){_0x49c3ac[_0x3f7c('0x50')][_0x3f7c('0x5f')]=_0x49c3ac[_0x3f7c('0x60')][_0x3f7c('0x61')];return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x49c3ac[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x3dcb7d,null))[_0x3f7c('0x23')](saveUpdates(_0x49c3ac['body'],null))[_0x3f7c('0x23')](respondWithResult(_0x3dcb7d,null))[_0x3f7c('0x19')](handleError(_0x3dcb7d,null));};exports['addAvatar']=function(_0x677d9f,_0x3419e0){_0x677d9f[_0x3f7c('0x50')][_0x3f7c('0x62')]=_0x677d9f[_0x3f7c('0x60')][_0x3f7c('0x61')];return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x677d9f[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x3419e0,null))[_0x3f7c('0x23')](saveUpdates(_0x677d9f['body'],null))[_0x3f7c('0x23')](respondWithResult(_0x3419e0,null))[_0x3f7c('0x19')](handleError(_0x3419e0,null));};exports[_0x3f7c('0x63')]=function(_0x209e66,_0x47b727){_0x209e66['body'][_0x3f7c('0x64')]=_0x209e66[_0x3f7c('0x60')]['filename'];return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x209e66['params']['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x47b727,null))[_0x3f7c('0x23')](saveUpdates(_0x209e66[_0x3f7c('0x50')],null))['then'](respondWithResult(_0x47b727,null))[_0x3f7c('0x19')](handleError(_0x47b727,null));};exports[_0x3f7c('0x65')]=function(_0x132269,_0x2f6a01){_0x132269[_0x3f7c('0x50')][_0x3f7c('0x66')]=_0x132269[_0x3f7c('0x60')][_0x3f7c('0x61')];return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x132269[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x2f6a01,null))[_0x3f7c('0x23')](saveUpdates(_0x132269[_0x3f7c('0x50')],null))[_0x3f7c('0x23')](respondWithResult(_0x2f6a01,null))[_0x3f7c('0x19')](handleError(_0x2f6a01,null));};exports[_0x3f7c('0x67')]=function(_0x1c56dc,_0x28fa4c){var _0x3eaa99=path[_0x3f7c('0x68')](config['root'],_0x3f7c('0x69'));var _0x1bf089={'where':{'id':_0x1c56dc['params']['id']},'attributes':['id',_0x3f7c('0x5f')],'raw':!![]};var _0x482bb9=![];return require(_0x3f7c('0x6a'))[_0x3f7c('0x6b')]()[_0x3f7c('0x23')](function(_0x56d69c){if(_0x56d69c){_0x482bb9=_0x56d69c['custom'];}})[_0x3f7c('0x23')](function(){return db[_0x3f7c('0x2c')]['find'](_0x1bf089);})[_0x3f7c('0x23')](handleEntityNotFound(_0x28fa4c,null))[_0x3f7c('0x23')](function(_0x8cc8cf){if(_0x8cc8cf){if(!_[_0x3f7c('0x6c')](_0x8cc8cf[_0x3f7c('0x5f')])){if(fs[_0x3f7c('0x6d')](path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0x6f'),_0x8cc8cf[_0x3f7c('0x5f')]))&&_0x482bb9){_0x3eaa99=path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0x6f'),_0x8cc8cf[_0x3f7c('0x5f')]);}}return _0x28fa4c['download'](_0x3eaa99);}})[_0x3f7c('0x19')](handleError(_0x28fa4c,null));};exports['getAvatar']=function(_0x40d9e9,_0x11e4ba){var _0x4cf37a=path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0x70'));var _0x3cffee={'where':{'id':_0x40d9e9[_0x3f7c('0x44')]['id']},'attributes':['id',_0x3f7c('0x62')],'raw':!![]};return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')](_0x3cffee)[_0x3f7c('0x23')](handleEntityNotFound(_0x11e4ba,null))[_0x3f7c('0x23')](function(_0x3ffb8b){if(_0x3ffb8b){if(!_[_0x3f7c('0x6c')](_0x3ffb8b['agentAvatar'])){if(fs[_0x3f7c('0x6d')](path[_0x3f7c('0x68')](config['root'],_0x3f7c('0x71'),_0x3ffb8b[_0x3f7c('0x62')]))){_0x4cf37a=path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0x71'),_0x3ffb8b[_0x3f7c('0x62')]);}}return _0x11e4ba[_0x3f7c('0x72')](_0x4cf37a);}})['catch'](handleError(_0x11e4ba,null));};exports[_0x3f7c('0x73')]=function(_0x3e9f48,_0x4f336e){var _0x405f7=path['join'](config['root'],'server/files/images/avatars/customer_avatar.png');var _0x4ecd28={'where':{'id':_0x3e9f48[_0x3f7c('0x44')]['id']},'attributes':['id',_0x3f7c('0x64'),_0x3f7c('0x74')],'raw':!![]};return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')](_0x4ecd28)[_0x3f7c('0x23')](handleEntityNotFound(_0x4f336e,null))[_0x3f7c('0x23')](function(_0x2c4aca){if(_0x2c4aca){if(!_[_0x3f7c('0x6c')](_0x2c4aca[_0x3f7c('0x64')])){if(fs[_0x3f7c('0x6d')](path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0x71'),_0x2c4aca[_0x3f7c('0x64')]))&&_0x2c4aca[_0x3f7c('0x74')]){_0x405f7=path['join'](config['root'],'server/files/images/avatars/',_0x2c4aca[_0x3f7c('0x64')]);}}return _0x4f336e[_0x3f7c('0x72')](_0x405f7);}})[_0x3f7c('0x19')](handleError(_0x4f336e,null));};exports[_0x3f7c('0x75')]=function(_0x479181,_0x50f9ce){var _0x47d862=path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],'server/files/images/avatars/system_avatar.png');var _0x5c0ec0={'where':{'id':_0x479181['params']['id']},'attributes':['id',_0x3f7c('0x66')],'raw':!![]};return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')](_0x5c0ec0)[_0x3f7c('0x23')](handleEntityNotFound(_0x50f9ce,null))['then'](function(_0x3614f9){if(_0x3614f9){if(!_[_0x3f7c('0x6c')](_0x3614f9[_0x3f7c('0x66')])){if(fs[_0x3f7c('0x6d')](path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],'server/files/images/avatars/',_0x3614f9[_0x3f7c('0x66')]))){_0x47d862=path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0x71'),_0x3614f9['systemAvatar']);}}return _0x50f9ce[_0x3f7c('0x72')](_0x47d862);}})[_0x3f7c('0x19')](handleError(_0x50f9ce,null));};exports['notify']=function(_0x465acc,_0x480c65){var _0x486167=require('user-agent-parser');var _0x3332db=new _0x486167();var _0x368c66=_0x3332db[_0x3f7c('0x76')](_0x465acc['headers'][_0x3f7c('0x77')])[_0x3f7c('0x78')]();var _0x513026={'body':_0x465acc[_0x3f7c('0x50')],'channel':_0x3f7c('0x79')};var _0xb0ea50=[];var _0x5c4021=[];var _0x13f84e={};var _0x12bb5b=![];return db['CmContact'][_0x3f7c('0x52')]()['then'](function(_0x27cc43){if(!_0x27cc43){throw new db['Sequelize'][(_0x3f7c('0x7a'))](_0x3f7c('0x7b'));}_0xb0ea50=_[_0x3f7c('0x7c')](_['keys'](_0x27cc43),[_0x3f7c('0x7d'),_0x3f7c('0x7e')]);_0x5c4021=_['difference'](_['keys'](_0x27cc43),['createdAt',_0x3f7c('0x7e'),'CompanyId',_0x3f7c('0x7f')]);if(_0x465acc[_0x3f7c('0x50')]['id']){delete _0x465acc['body']['id'];}if(_[_0x3f7c('0x6c')](_0x465acc[_0x3f7c('0x50')]['from'])){throw new db[(_0x3f7c('0x80'))][(_0x3f7c('0x7a'))](_0x3f7c('0x81'));}if(_[_0x3f7c('0x6c')](_0x465acc['body']['body'])||_0x465acc['body'][_0x3f7c('0x50')]===''){throw new db['Sequelize'][(_0x3f7c('0x7a'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x3f7c('0x6c')](_0x465acc[_0x3f7c('0x50')][_0x3f7c('0x82')])){throw new db[(_0x3f7c('0x80'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5c4021);}if(!_['includes'](_0x5c4021,_0x465acc[_0x3f7c('0x50')][_0x3f7c('0x82')])){throw new db[(_0x3f7c('0x80'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5c4021);}_0x13f84e[_0x465acc[_0x3f7c('0x50')][_0x3f7c('0x82')]]=_0x465acc[_0x3f7c('0x50')][_0x3f7c('0x83')];})[_0x3f7c('0x23')](function(){return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x465acc[_0x3f7c('0x44')]['id']},'include':[{'model':db[_0x3f7c('0x84')],'as':_0x3f7c('0x85'),'include':[{'model':db[_0x3f7c('0x86')],'as':_0x3f7c('0x87'),'where':_0x13f84e,'limit':0x1,'order':[[_0x3f7c('0x7e'),'DESC']]}]},{'model':db[_0x3f7c('0x88')],'as':_0x3f7c('0x89')}]});})[_0x3f7c('0x23')](handleEntityNotFound(_0x480c65,null))[_0x3f7c('0x23')](function(_0x5780c4){if(_0x5780c4&&_0x5780c4[_0x3f7c('0x85')]){_0x513026[_0x3f7c('0x8a')]=_0x5780c4;_0x513026[_0x3f7c('0x8b')]=_0x5780c4[_0x3f7c('0x89')];_0x513026[_0x3f7c('0x8c')]=_0x5780c4['List'];_0x513026[_0x3f7c('0x8b')]=_['orderBy'](_0x513026['applications'],[_0x3f7c('0x8d')],[_0x3f7c('0x8e')]);if(_0x513026[_0x3f7c('0x8a')][_0x3f7c('0x89')]){delete _0x513026[_0x3f7c('0x8a')]['Applications'];}if(_0x513026[_0x3f7c('0x8a')][_0x3f7c('0x85')]&&_0x513026[_0x3f7c('0x8a')]['List'][_0x3f7c('0x87')][_0x3f7c('0x36')]){return _0x513026[_0x3f7c('0x8a')]['List'][_0x3f7c('0x87')][0x0];}var _0x18d6a1=_[_0x3f7c('0x8f')](_0x465acc['body'],{'firstName':_0x465acc[_0x3f7c('0x50')][_0x3f7c('0x83')],'ListId':_0x5780c4[_0x3f7c('0x7f')]});_0x18d6a1[_0x465acc['body'][_0x3f7c('0x82')]]=_0x465acc['body'][_0x3f7c('0x83')];return db[_0x3f7c('0x86')][_0x3f7c('0x46')](_0x18d6a1,{'fields':_0xb0ea50,'raw':!![]});}})[_0x3f7c('0x23')](handleEntityNotFound(_0x480c65,null))[_0x3f7c('0x23')](function(_0x17b16c){_0x513026[_0x3f7c('0x90')]=_0x17b16c;var _0x3724aa=_0x465acc['body'][_0x3f7c('0x91')];if(_0x465acc[_0x3f7c('0x92')][_0x3f7c('0x93')]){_0x3724aa=_0x465acc[_0x3f7c('0x92')]['cf-connecting-ip'];}else if(_0x465acc[_0x3f7c('0x92')]['x-forwarded-for']){_0x3724aa=_[_0x3f7c('0x94')](_0x465acc[_0x3f7c('0x92')][_0x3f7c('0x95')][_0x3f7c('0x96')](','));}if(_0x17b16c){var _0x2e3728={'ContactId':_0x17b16c['id'],'ChatWebsiteId':_0x465acc[_0x3f7c('0x44')]['id'],'from':(_0x17b16c['firstName']||'')+'\x20'+(_0x17b16c[_0x3f7c('0x97')]||''),'customerIp':_0x3724aa,'customerPort':_0x465acc[_0x3f7c('0x92')][_0x3f7c('0x98')]?_0x465acc[_0x3f7c('0x92')][_0x3f7c('0x98')]:null,'referer':_0x465acc['body'][_0x3f7c('0x99')],'browserName':_0x368c66[_0x3f7c('0x9a')][_0x3f7c('0x40')]&&_0x368c66[_0x3f7c('0x9a')]['version']?util['format'](_0x3f7c('0x9b'),_0x368c66['browser'][_0x3f7c('0x40')],_0x368c66[_0x3f7c('0x9a')][_0x3f7c('0x9c')]):'unknown','browserVersion':_0x368c66[_0x3f7c('0x9a')][_0x3f7c('0x9c')]||_0x3f7c('0x9d'),'osName':util[_0x3f7c('0x9e')](_0x3f7c('0x9b'),_0x368c66['os'][_0x3f7c('0x40')],_0x368c66['os']['version']),'osVersion':_0x368c66['os']['version'],'deviceModel':_0x368c66[_0x3f7c('0x9f')][_0x3f7c('0x33')]&&_0x368c66[_0x3f7c('0x9f')][_0x3f7c('0xa0')]?util['format'](_0x3f7c('0xa1'),_0x368c66[_0x3f7c('0x9f')]['model'],_0x368c66['device'][_0x3f7c('0xa0')],_0x368c66['device'][_0x3f7c('0x2f')]):null,'deviceVendor':_0x368c66['device'][_0x3f7c('0xa0')],'deviceType':_0x368c66[_0x3f7c('0x9f')][_0x3f7c('0x2f')],'formData':JSON[_0x3f7c('0x15')](_0x465acc['body'])};var _0x362985={'ChatWebsiteId':_0x465acc[_0x3f7c('0x44')]['id'],'closed':![]};if(_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa2')]){_0x362985[_0x3f7c('0xa2')]=_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa2')];return db['ChatInteraction'][_0x3f7c('0x4c')]({'where':_0x362985})[_0x3f7c('0x23')](function(_0x42fe6e){if(_0x42fe6e){return[_0x42fe6e,![]];}_0x2e3728[_0x3f7c('0xa2')]=_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa2')];_0x2e3728[_0x3f7c('0xa3')]=_0x465acc[_0x3f7c('0x50')]['externalUrl'];return db[_0x3f7c('0xa4')]['create'](_0x2e3728)[_0x3f7c('0x23')](function(_0x58ed24){return[_0x58ed24,!![]];});});}_0x362985[_0x3f7c('0xa5')]=_0x17b16c['id'];if(_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa6')]&&_0x465acc['body'][_0x3f7c('0xa6')]['id']){_0x362985['id']=_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa6')]['id'];return db[_0x3f7c('0xa4')][_0x3f7c('0x4c')]({'where':_0x362985})[_0x3f7c('0x23')](function(_0x463222){if(_0x463222){return[_0x463222,![]];}return db[_0x3f7c('0xa4')][_0x3f7c('0x46')](_0x2e3728)[_0x3f7c('0x23')](function(_0x354a31){return[_0x354a31,!![]];});});}return db[_0x3f7c('0xa4')][_0x3f7c('0x46')](_0x2e3728)[_0x3f7c('0x23')](function(_0x47dfd5){return[_0x47dfd5,!![]];});}})[_0x3f7c('0xa7')](function(_0x575388,_0x58ed9c){if(_0x575388){_0x12bb5b=_0x58ed9c;if(!_0x58ed9c){var _0x19f718={'from':(_0x513026[_0x3f7c('0x90')][_0x3f7c('0xa8')]||'')+'\x20'+(_0x513026[_0x3f7c('0x90')][_0x3f7c('0x97')]||'')};if(_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa2')]&&_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa9')]&&_0x465acc['body']['threadId']!=_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa9')]){_0x19f718[_0x3f7c('0xa2')]=_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xa9')];}return _0x575388['update'](_0x19f718);}else{return _0x575388;}}})[_0x3f7c('0x23')](function(_0x11c278){_0x513026['interaction']=_0x11c278['get']({'plain':!![]});_0x513026[_0x3f7c('0xa6')][_0x3f7c('0xaa')]=_0x12bb5b;if(_0x513026['interaction'][_0x3f7c('0xaa')]){if(_0x513026[_0x3f7c('0x8a')][_0x3f7c('0xab')]){_0x513026['applications'][_0x3f7c('0xac')]({'id':0x0,'priority':_0x513026[_0x3f7c('0x8b')][_0x3f7c('0x36')]+0x1,'app':'close','appdata':_0x3f7c('0xad'),'interval':'*,*,*,*'});}}return db[_0x3f7c('0xae')][_0x3f7c('0x46')]({'body':_0x465acc[_0x3f7c('0x50')][_0x3f7c('0x50')],'ChatWebsiteId':_0x465acc[_0x3f7c('0x44')]['id'],'ChatInteractionId':_0x11c278['id'],'direction':'in','ContactId':_0x513026[_0x3f7c('0x90')]['id'],'AttachmentId':_0x465acc[_0x3f7c('0x50')][_0x3f7c('0xaf')]});})[_0x3f7c('0x23')](function(_0x56619f){_0x513026[_0x3f7c('0x17')]=_0x56619f;if(_0x513026[_0x3f7c('0xa6')][_0x3f7c('0xb0')]){return db[_0x3f7c('0xb1')]['find']({'attributes':['id',_0x3f7c('0x40')],'where':{'id':_0x513026[_0x3f7c('0xa6')][_0x3f7c('0xb0')]}})[_0x3f7c('0x23')](function(_0x506862){if(_0x506862){_0x513026[_0x3f7c('0x8b')][_0x3f7c('0xb2')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x506862[_0x3f7c('0x40')]+','+(_0x513026[_0x3f7c('0x8a')][_0x3f7c('0xb3')]||0xa),'interval':_0x3f7c('0xb4')});_0x513026[_0x3f7c('0xb5')]=!![];}return respondWithRpcPromise(_0x3f7c('0xb6'),_0x3f7c('0xb7'),_0x513026);});}return respondWithRpcPromise(_0x3f7c('0xb6'),_0x3f7c('0xb7'),_0x513026);})[_0x3f7c('0x23')](function(_0x1e8490){respondWithRpcPromise(_0x3f7c('0xb8'),'EventManager',{'event':_0x3f7c('0xb9'),'message':_0x1e8490},client9002);return _0x1e8490;})[_0x3f7c('0x23')](respondWithResult(_0x480c65,null))[_0x3f7c('0x19')](handleError(_0x480c65,null));};exports[_0x3f7c('0xba')]=function(_0x19b42b,_0x788d19){var _0x1ce954,_0x4dbc6b,_0x25efd4;var _0x49c27a=[];var _0x589333={};var _0x39c5e7=_0x19b42b[_0x3f7c('0xbb')]||[];var _0x583131=[];var _0x1bcceb;return db[_0x3f7c('0x86')]['describe']()['then'](function(_0x43354b){if(!_0x43354b){throw new db['Sequelize']['ValidationError'](_0x3f7c('0x7b'));}_0x49c27a=_[_0x3f7c('0x7c')](_['keys'](_0x43354b),[_0x3f7c('0x7d'),'updatedAt',_0x3f7c('0xbc'),_0x3f7c('0x7f')]);if(_0x19b42b[_0x3f7c('0x50')]['id']){delete _0x19b42b['body']['id'];}if(_[_0x3f7c('0x6c')](_0x19b42b['body']['from'])){throw _0x788d19[_0x3f7c('0x1b')](0x1f4)[_0x3f7c('0x29')](new db[(_0x3f7c('0x80'))][(_0x3f7c('0x7a'))](_0x3f7c('0x81')));}if(_[_0x3f7c('0x6c')](_0x19b42b[_0x3f7c('0x50')]['body'])||_0x19b42b[_0x3f7c('0x50')][_0x3f7c('0x50')]===''){throw _0x788d19[_0x3f7c('0x1b')](0x1f4)[_0x3f7c('0x29')](new db[(_0x3f7c('0x80'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty'));}if(_['isNil'](_0x19b42b[_0x3f7c('0x50')][_0x3f7c('0xbd')])){throw _0x788d19['status'](0x1f4)['send'](new db[(_0x3f7c('0x80'))][(_0x3f7c('0x7a'))]('mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x49c27a));}if(!_[_0x3f7c('0xbe')](_0x49c27a,_0x19b42b[_0x3f7c('0x50')][_0x3f7c('0xbd')])){throw _0x788d19[_0x3f7c('0x1b')](0x1f4)[_0x3f7c('0x29')](new db[(_0x3f7c('0x80'))][(_0x3f7c('0x7a'))]('mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x49c27a));}_0x589333[_0x19b42b['body'][_0x3f7c('0xbd')]]=_0x19b42b[_0x3f7c('0x50')][_0x3f7c('0x83')];})[_0x3f7c('0x23')](function(){return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x19b42b[_0x3f7c('0x44')]['id']},'include':[{'model':db[_0x3f7c('0x84')],'as':'List'},{'model':db[_0x3f7c('0xbf')],'as':_0x3f7c('0xbf')}]});})['then'](handleEntityNotFound(_0x788d19,null))['then'](function(_0xc040d5){if(_0xc040d5&&_0xc040d5['List']){_0x4dbc6b=_0xc040d5;var _0x46889e=_['defaults'](_0x19b42b['body'],{'firstName':_0x19b42b['body'][_0x3f7c('0x83')],'phone':_0x19b42b[_0x3f7c('0x50')][_0x3f7c('0x83')],'ListId':_0xc040d5[_0x3f7c('0x7f')]});_0x46889e[_0x19b42b[_0x3f7c('0x50')]['mapKeyOffline']]=_0x19b42b[_0x3f7c('0x50')]['from'];return db[_0x3f7c('0x86')][_0x3f7c('0xc0')]({'where':_0x589333,'defaults':_0x46889e});}})[_0x3f7c('0xa7')](function(_0x1b9c36){if(_0x1b9c36){_0x25efd4=_0x1b9c36;var _0x29afcf=fs[_0x3f7c('0xc1')](path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],'server/files/templates/chatOfflineMessage.ejs'),_0x3f7c('0xc2'));var _0x16f0cc=ejs[_0x3f7c('0xc3')](_0x29afcf,{'body':_[_0x3f7c('0xc4')](_0x19b42b[_0x3f7c('0x50')][_0x3f7c('0x50')]),'bodyTitle':_0x4dbc6b[_0x3f7c('0xc5')]});return db[_0x3f7c('0xc6')]['create']({'body':_0x16f0cc,'ContactId':_0x1b9c36['id'],'ChatWebsiteId':_0x4dbc6b['id']});}})[_0x3f7c('0x23')](function(_0x26c6c5){_0x1bcceb=_0x26c6c5;if(_0x39c5e7[_0x3f7c('0x36')]){var _0x432531=_0x39c5e7[_0x3f7c('0x2b')](function(_0x39cdc9){return{'name':_0x39cdc9[_0x3f7c('0xc7')],'basename':_0x39cdc9[_0x3f7c('0x61')],'type':_0x39cdc9[_0x3f7c('0xc8')],'ChatOfflineMessageId':_0x26c6c5['id']};});_0x583131=_0x432531[_0x3f7c('0x2b')](_0x5edf35=>{var _0x4f35a5={'filename':_0x5edf35[_0x3f7c('0x40')],'path':path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],'server','files',_0x3f7c('0xc9'),'offline-chat',_0x5edf35[_0x3f7c('0xca')])};return _0x4f35a5;});if(!_0x4dbc6b[_0x3f7c('0xcb')]){return db[_0x3f7c('0xcc')][_0x3f7c('0xcd')](function(_0x3a255f){return db['Attachment'][_0x3f7c('0xce')](_0x432531,{'transaction':_0x3a255f});});}}})[_0x3f7c('0x23')](function(){if(_0x1bcceb){_0x1ce954=_0x1bcceb;return db['MailAccount'][_0x3f7c('0x56')]({'where':{'active':!![]},'include':[{'model':db['MailServerOut'],'as':'Smtp','raw':!![]}]});}})[_0x3f7c('0x23')](function(_0x5af3b1){if(_0x5af3b1&&_0x5af3b1[_0x3f7c('0xcf')]&&_0x4dbc6b[_0x3f7c('0xd0')]&&_0x4dbc6b[_0x3f7c('0xd1')]){var _0xee4287={'tls':{'rejectUnauthorized':![]}};if(_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0xd2')]){_0xee4287[_0x3f7c('0xd2')]=_0x5af3b1['Smtp'][_0x3f7c('0xd2')];}else{_0xee4287[_0x3f7c('0xd3')]=_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0xd3')];_0xee4287[_0x3f7c('0xd4')]=_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0xd4')];_0xee4287['secure']=_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0xd5')];}if(_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0xd6')]){_0xee4287['auth']={'user':_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0x49')],'pass':_0x5af3b1['Smtp']['pass']};}return respondWithRpcPromise(_0x3f7c('0xd7'),_0x3f7c('0xd8'),{'account':_0xee4287,'message':{'from':util['format'](_0x3f7c('0xd9'),_0x5af3b1['name'],_0x5af3b1[_0x3f7c('0xda')]||_0x5af3b1[_0x3f7c('0xcf')][_0x3f7c('0x49')]),'to':_0x4dbc6b[_0x3f7c('0xd1')],'subject':_0x4dbc6b['offlineMessageSubject'],'html':_0x1ce954[_0x3f7c('0x50')],'attachments':_0x583131}},client9003)['then'](function(){return _0x1ce954;})[_0x3f7c('0x19')](function(_0x2f0994){console['error'](_0x2f0994);});}})['then'](function(){if(_0x4dbc6b&&_0x4dbc6b[_0x3f7c('0xcb')]&&_0x4dbc6b[_0x3f7c('0xdb')]){var _0x4ddfb2=[];if(_0x39c5e7['length']){_0x4ddfb2=_0x39c5e7[_0x3f7c('0x2b')](function(_0x57b985){return{'name':_0x57b985[_0x3f7c('0xc7')],'basename':_0x57b985[_0x3f7c('0x61')],'type':_0x57b985[_0x3f7c('0xc8')],'ChatOfflineMessageId':_0x1bcceb['id']};});}var _0x4b97bc;if(!_['isNil'](_0x4dbc6b['subjectOffline'])){var _0x5453e4=_[_0x3f7c('0x2b')](_0x19b42b[_0x3f7c('0x50')],function(_0x27f689){return _0x27f689;});var _0x11006f=_[_0x3f7c('0xdc')](_0x5453e4)[0x0];var _0x46b611=_[_0x3f7c('0xdd')](_0x11006f,function(_0x1f076a){return _0x1f076a;});_0x4b97bc=_0x46b611[0x1][_0x4dbc6b[_0x3f7c('0xde')]];}var _0x10d03e={'from':_0x25efd4['email'],'firstName':_0x25efd4['firstName'],'lastName':_0x25efd4[_0x3f7c('0x97')],'mapKey':_0x3f7c('0xda'),'message':{'from':_0x25efd4[_0x3f7c('0xda')],'to':_0x4dbc6b[_0x3f7c('0xbf')]['email'],'cc':'','subject':_[_0x3f7c('0x6c')](_0x4b97bc)?_0x4dbc6b[_0x3f7c('0xdf')]:_0x4b97bc,'messageId':'','sentAt':new Date(),'attach':_0x4ddfb2[_0x3f7c('0x36')],'attachments':_0x4ddfb2,'originChannel':'Chat','ChatWebsiteId':_0x4dbc6b['id'],'ChatOfflineMessageId':_0x1ce954['id'],'originTo':_0x4dbc6b[_0x3f7c('0xbf')][_0x3f7c('0xda')]},'body':_0x1ce954['body']};var _0x534f06={'account':{'id':_0x4dbc6b[_0x3f7c('0xdb')]},'body':_0x10d03e,'log':_0x3f7c('0xe0')};return respondWithRpcPromise(_0x3f7c('0xe0'),_0x3f7c('0xe1'),_0x534f06,client9001)['then'](function(){return _0x1ce954;})[_0x3f7c('0x19')](function(_0x15c416){console[_0x3f7c('0x16')](_0x15c416);});}return;})[_0x3f7c('0x23')](function(){if(_0x1ce954){return _0x1ce954;}})[_0x3f7c('0x23')](respondWithResult(_0x788d19,null))['catch'](function(_0x27f2ab){console['error'](_0x3f7c('0x19'),_0x27f2ab);for(var _0x122790 of _0x39c5e7){var _0x53c994=path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],_0x3f7c('0xe2'),'files',_0x3f7c('0xc9'),_0x3f7c('0xe3'),_0x122790[_0x3f7c('0x61')]);fs_extra[_0x3f7c('0xe4')](_0x53c994)[_0x3f7c('0x19')](function(_0x5e0c53){console[_0x3f7c('0x16')](_0x3f7c('0xe5'),_0x53c994,_0x5e0c53);});}});};exports[_0x3f7c('0xe6')]=function(_0x14c667,_0x55fd94){return db[_0x3f7c('0xa4')][_0x3f7c('0x4c')]({'where':{'id':_0x14c667[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x55fd94,null))['then'](function(_0x574ebc){if(_0x574ebc){return _0x574ebc[_0x3f7c('0xe6')](_0x14c667[_0x3f7c('0x50')][_0x3f7c('0x5d')],_[_0x3f7c('0xe7')](_0x14c667[_0x3f7c('0x50')],['ids','id'])||{});}})[_0x3f7c('0x23')](respondWithResult(_0x55fd94,null))[_0x3f7c('0x19')](handleError(_0x55fd94,null));};exports[_0x3f7c('0xe8')]=function(_0x19242c,_0x5ecf0c){var _0x41607d={'raw':![],'where':{}};var _0x3fe5b6={};var _0x5e8eb4={'count':0x0,'rows':[]};return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0x19242c[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x5ecf0c,null))[_0x3f7c('0x23')](function(_0x1bdb1f){if(_0x1bdb1f){_0x3fe5b6[_0x3f7c('0x33')]=_[_0x3f7c('0x30')](db[_0x3f7c('0xa4')][_0x3f7c('0x2d')]);_0x3fe5b6['query']=_[_0x3f7c('0x30')](_0x19242c[_0x3f7c('0x31')]);_0x3fe5b6[_0x3f7c('0x3c')]=_[_0x3f7c('0x32')](_0x3fe5b6[_0x3f7c('0x33')],_0x3fe5b6[_0x3f7c('0x31')]);_0x41607d[_0x3f7c('0x34')]=_['intersection'](_0x3fe5b6[_0x3f7c('0x33')],qs[_0x3f7c('0x35')](_0x19242c[_0x3f7c('0x31')][_0x3f7c('0x35')]));_0x41607d[_0x3f7c('0x34')]=_0x41607d[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x41607d[_0x3f7c('0x34')]:_0x3fe5b6[_0x3f7c('0x33')];if(!_0x19242c[_0x3f7c('0x31')]['hasOwnProperty']('nolimit')){_0x41607d[_0x3f7c('0x1f')]=qs[_0x3f7c('0x1f')](_0x19242c[_0x3f7c('0x31')][_0x3f7c('0x1f')]);_0x41607d['offset']=qs[_0x3f7c('0x1d')](_0x19242c[_0x3f7c('0x31')]['offset']);}_0x41607d['order']=qs[_0x3f7c('0x3a')](_0x19242c['query'][_0x3f7c('0x3a')]);_0x41607d[_0x3f7c('0x3b')]=qs[_0x3f7c('0x3c')](_[_0x3f7c('0x3d')](_0x19242c[_0x3f7c('0x31')],_0x3fe5b6[_0x3f7c('0x3c')]));_0x41607d[_0x3f7c('0x3b')][_0x3f7c('0x57')]=_0x1bdb1f['id'];if(_0x19242c[_0x3f7c('0x31')][_0x3f7c('0x3e')]){_0x41607d[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x41607d[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x41607d[_0x3f7c('0x34')],function(_0x35e591){var _0x42aa45={};_0x42aa45[_0x35e591]={'$like':'%'+_0x19242c['query'][_0x3f7c('0x3e')]+'%'};return _0x42aa45;})});}_0x41607d=_[_0x3f7c('0x3f')]({},_0x41607d,_0x19242c['options']);return db[_0x3f7c('0xa4')][_0x3f7c('0x42')]({'where':_0x41607d[_0x3f7c('0x3b')]})['then'](function(_0xcf7527){_0x5e8eb4['count']=_0xcf7527;if(_0x19242c[_0x3f7c('0x31')][_0x3f7c('0x43')]){_0x41607d['include']=[{'model':db['CmContact'],'as':_0x3f7c('0xe9'),'required':![]},{'model':db[_0x3f7c('0xb1')],'as':_0x3f7c('0xea'),'attributes':[_0x3f7c('0x40'),'fullname',_0x3f7c('0xeb')],'required':![]},{'model':db['Tag'],'as':_0x3f7c('0xec'),'attributes':['id',_0x3f7c('0x40'),_0x3f7c('0xed')],'where':_0x19242c[_0x3f7c('0x31')][_0x3f7c('0xee')]?{'id':_0x19242c[_0x3f7c('0x31')][_0x3f7c('0xee')]}:undefined,'required':_0x19242c[_0x3f7c('0x31')][_0x3f7c('0xee')]?!![]:![]}];}return db[_0x3f7c('0xa4')][_0x3f7c('0x58')](_0x41607d);})[_0x3f7c('0x23')](function(_0x24a20c){_0x5e8eb4['rows']=_0x24a20c;return _0x5e8eb4;});}})[_0x3f7c('0x23')](respondWithFilteredResult(_0x5ecf0c,_0x41607d))['catch'](handleError(_0x5ecf0c,null));};function iftimePromise(_0x1fabc9,_0x1b5ed2){return respondWithRpcPromise(_0x3f7c('0xef'),_0x3f7c('0xf0'),{'command':_0x1b5ed2[_0x3f7c('0xf1')]?util['format']('iftime\x20%s,%s',_0x1fabc9[_0x3f7c('0xf2')],_0x1b5ed2['timezone']):util[_0x3f7c('0x9e')](_0x3f7c('0xf3'),_0x1fabc9[_0x3f7c('0xf2')])},client9002)['then'](function(_0x48096a){var _0x263bff=_0x48096a&&_0x48096a[_0x3f7c('0xf4')](_0x3f7c('0xf5'))>=0x0?!![]:![];logger[_0x3f7c('0x10')](_0x3f7c('0xf6'),_0x1b5ed2['id'],_0x1fabc9['id'],_0x1fabc9[_0x3f7c('0xf2')],_0x263bff?_0x3f7c('0xf7'):_0x3f7c('0xf8'),_0x1b5ed2[_0x3f7c('0xf1')]?_0x1b5ed2[_0x3f7c('0xf1')]:_0x3f7c('0xf9'));return _0x263bff;})['catch'](function(_0x116ce6){logger[_0x3f7c('0x16')](_0x3f7c('0xf6'),_0x1b5ed2['id'],_0x1fabc9['id'],_0x1fabc9[_0x3f7c('0xf2')],util[_0x3f7c('0xfa')](_0x116ce6,{'showHidden':![],'depth':null}),_0x1b5ed2['timezone']?_0x1b5ed2[_0x3f7c('0xf1')]:_0x3f7c('0xf9'));return![];});}exports['getSnippet']=function(_0x13ffa3,_0x48792f){var _0x30b351=0x0;var _0x4c66c4=0x0;var _0x14755f=![];var _0x2370da;var _0x271b9b;return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x13ffa3[_0x3f7c('0x44')]['id']},'include':[{'model':db[_0x3f7c('0xfb')],'as':'Interval','include':[{'model':db['Interval'],'as':'Intervals','attributes':['id',_0x3f7c('0xf2')],'raw':!![]}]}]})[_0x3f7c('0x23')](handleEntityNotFound(_0x48792f,null))[_0x3f7c('0x23')](function(_0x198e74){if(_0x198e74){_0x2370da=_0x198e74;return _0x198e74['getProactiveActions']({'raw':!![]});}})[_0x3f7c('0x23')](function(_0x405def){if(_0x2370da){if(_0x405def){_0x271b9b=_0x405def;}}return require(_0x3f7c('0x6a'))[_0x3f7c('0x6b')]();})['then'](function(_0x146bf2){if(_0x146bf2){_0x4c66c4=_0x146bf2[_0x3f7c('0xfc')];_0x14755f=_0x146bf2[_0x3f7c('0xfd')];}})[_0x3f7c('0x23')](function(){return db['ChatInteraction'][_0x3f7c('0x42')]({'where':{'closed':![]}});})[_0x3f7c('0x23')](function(_0x8364f1){_0x30b351=_0x8364f1;if(_0x4c66c4&&_0x8364f1>_0x4c66c4){return db[_0x3f7c('0xfe')]['findOne']({'where':{'id':0x1}})['then'](function(_0x112bf8){if(_0x112bf8){_0x112bf8[_0x3f7c('0xff')]('chatLicenseExceeded');}});}})[_0x3f7c('0x23')](function(){if(_0x2370da[_0x3f7c('0xfb')]&&_0x2370da['Interval']['Intervals']){var _0x1c42a8=[];for(var _0x2f97a2=0x0;_0x2f97a2<_0x2370da['Interval'][_0x3f7c('0x100')]['length'];_0x2f97a2++){var _0x386aa4=_0x2370da[_0x3f7c('0xfb')][_0x3f7c('0x100')][_0x2f97a2][_0x3f7c('0x25')]({'plain':!![]});_0x1c42a8[_0x3f7c('0xac')](iftimePromise(_0x386aa4,_0x2370da));}return BPromise[_0x3f7c('0x101')](_0x1c42a8)[_0x3f7c('0x23')](function(_0x5be83b){return _[_0x3f7c('0x102')](_0x5be83b);});}else{return!![];}})[_0x3f7c('0x23')](function(_0x28ebc8){var _0x15af4a=fs['readFileSync'](path[_0x3f7c('0x68')](config[_0x3f7c('0x6e')],'server/files/chat/iframe.ejs'),_0x3f7c('0xc2'));var _0x5ec165={'remote':_0x2370da['remote'],'query':querystring[_0x3f7c('0x15')](_['merge'](_0x2370da['get']({'plain':!![]}),{'customerIp':_0x13ffa3[_0x3f7c('0x92')][_0x3f7c('0x95')]||_0x13ffa3['headers'][_0x3f7c('0x103')]||_0x13ffa3[_0x3f7c('0x104')][_0x3f7c('0x105')]||_0x13ffa3['ip'],'referer':_0x13ffa3[_0x3f7c('0x92')]['referer'],'openedInteractions':_0x30b351,'maxInteractions':_0x4c66c4,'virtual':_0x14755f[_0x3f7c('0xfc')],'online':_0x28ebc8,'custom':_0x14755f}))[_0x3f7c('0x106')](/'/g,'\x5c\x27')};_0x48792f[_0x3f7c('0x29')](ejs[_0x3f7c('0xc3')](Mustache[_0x3f7c('0xc3')](_0x15af4a,_0x5ec165),{'proactiveActions':_0x271b9b,'alignment':_0x2370da[_0x3f7c('0x107')],'verticalAlignment':_0x2370da[_0x3f7c('0x108')],'div_color':_0x2370da[_0x3f7c('0xed')],'labelText':_0x2370da[_0x3f7c('0x109')],'text_color':_0x2370da[_0x3f7c('0x10a')],'button_color':_0x2370da[_0x3f7c('0x10b')],'background_color':_0x2370da[_0x3f7c('0x10c')]}));})[_0x3f7c('0x19')](handleError(_0x48792f,null));};exports[_0x3f7c('0x10d')]=function(_0x4bdacb,_0x4eb70e){var _0x262583=_0x4bdacb['params']['id'];var _0x4aa523=_0x4bdacb[_0x3f7c('0x50')];var _0x28ab71=0xc8;var _0x444c79=null;return db['sequelize'][_0x3f7c('0xcd')]({'isolationLevel':db[_0x3f7c('0xcc')][_0x3f7c('0x10e')][_0x3f7c('0x10f')][_0x3f7c('0x110')]},function(_0x23b157){return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0x262583},'transaction':_0x23b157})[_0x3f7c('0x23')](function(_0x273dbe){if(_0x273dbe){return db['ChatApplication']['destroy']({'where':{'ChatWebsiteId':_0x262583},'transaction':_0x23b157})[_0x3f7c('0x23')](function(){var _0x5dbfef=_[_0x3f7c('0x2b')](_0x4aa523,function(_0x5dcde0){_0x5dcde0[_0x3f7c('0x57')]=_0x262583;return _0x5dcde0;});return db['ChatApplication']['bulkCreate'](_0x5dbfef,{'transaction':_0x23b157});});}else{_0x28ab71=0x194;_0x444c79=[];}});})['then'](function(){if(_0x28ab71!==0x194){return db['ChatApplication'][_0x3f7c('0x111')]({'where':{'ChatWebsiteId':_0x262583},'order':_0x3f7c('0x8d')})['then'](function(_0x1672e5){_0x444c79=_0x1672e5;});}})[_0x3f7c('0x19')](function(_0x1b0e45){_0x28ab71=0x1f4;logger[_0x3f7c('0x16')](_0x1b0e45[_0x3f7c('0x28')]);if(_0x1b0e45['name']){delete _0x1b0e45[_0x3f7c('0x40')];}_0x444c79=_0x1b0e45;})[_0x3f7c('0x112')](function(){if(_0x444c79===null){_0x4eb70e[_0x3f7c('0x27')](_0x28ab71);}else{if(_0x28ab71===0x1f4){_0x4eb70e[_0x3f7c('0x1b')](_0x28ab71)[_0x3f7c('0x29')](_0x444c79);}else{_0x4eb70e[_0x3f7c('0x1b')](_0x28ab71)[_0x3f7c('0x1c')](_0x444c79);}}});};exports[_0x3f7c('0x113')]=function(_0x516194,_0x48b7a6){var _0x165b3c={};var _0x402aaf={};var _0x17e84a;var _0x3ea96b;return db['ChatWebsite'][_0x3f7c('0x56')]({'where':{'id':_0x516194[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x48b7a6,null))[_0x3f7c('0x23')](function(_0x4b0b10){if(_0x4b0b10){_0x17e84a=_0x4b0b10;_0x402aaf['model']=_[_0x3f7c('0x30')](db['ChatApplication'][_0x3f7c('0x2d')]);_0x402aaf[_0x3f7c('0x31')]=_['keys'](_0x516194[_0x3f7c('0x31')]);_0x402aaf[_0x3f7c('0x3c')]=_[_0x3f7c('0x32')](_0x402aaf[_0x3f7c('0x33')],_0x402aaf[_0x3f7c('0x31')]);_0x165b3c[_0x3f7c('0x34')]=_[_0x3f7c('0x32')](_0x402aaf[_0x3f7c('0x33')],qs['fields'](_0x516194[_0x3f7c('0x31')][_0x3f7c('0x35')]));_0x165b3c[_0x3f7c('0x34')]=_0x165b3c[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x165b3c[_0x3f7c('0x34')]:_0x402aaf['model'];_0x165b3c[_0x3f7c('0x39')]=qs['sort'](_0x516194[_0x3f7c('0x31')]['sort']);_0x165b3c['where']=qs[_0x3f7c('0x3c')](_[_0x3f7c('0x3d')](_0x516194[_0x3f7c('0x31')],_0x402aaf[_0x3f7c('0x3c')]));if(_0x516194[_0x3f7c('0x31')][_0x3f7c('0x3e')]){_0x165b3c[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x165b3c[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x165b3c[_0x3f7c('0x34')],function(_0x1712fc){var _0x3580e9={};_0x3580e9[_0x1712fc]={'$like':'%'+_0x516194[_0x3f7c('0x31')][_0x3f7c('0x3e')]+'%'};return _0x3580e9;})});}_0x165b3c=_['merge']({},_0x165b3c,_0x516194[_0x3f7c('0x41')]);return _0x17e84a['getApplications'](_0x165b3c);}})[_0x3f7c('0x23')](function(_0x4a893b){if(_0x4a893b){_0x3ea96b=_0x4a893b[_0x3f7c('0x36')];if(!_0x516194[_0x3f7c('0x31')][_0x3f7c('0x37')]('nolimit')){_0x165b3c[_0x3f7c('0x1f')]=qs[_0x3f7c('0x1f')](_0x516194[_0x3f7c('0x31')][_0x3f7c('0x1f')]);_0x165b3c[_0x3f7c('0x1d')]=qs[_0x3f7c('0x1d')](_0x516194['query'][_0x3f7c('0x1d')]);}return _0x17e84a[_0x3f7c('0x113')](_0x165b3c);}})[_0x3f7c('0x23')](function(_0x105dab){if(_0x105dab){return _0x105dab?{'count':_0x3ea96b,'rows':_0x105dab}:null;}})[_0x3f7c('0x23')](respondWithResult(_0x48b7a6,null))[_0x3f7c('0x19')](handleError(_0x48b7a6,null));};exports[_0x3f7c('0x114')]=function(_0x3d592d,_0x14d6b9){return db[_0x3f7c('0x115')][_0x3f7c('0x4c')]({'where':{'id':_0x3d592d['params']['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x14d6b9,null))[_0x3f7c('0x23')](function(_0x3750f0){if(_0x3750f0){return _0x3750f0['addProactiveActions'](_0x3d592d['body']['ids'],_[_0x3f7c('0xe7')](_0x3d592d['body'],[_0x3f7c('0x5d'),'id'])||{});}})[_0x3f7c('0x23')](respondWithResult(_0x14d6b9,null))['catch'](handleError(_0x14d6b9,null));};exports[_0x3f7c('0x116')]=function(_0x55e4e6,_0x1060ef){var _0x4b6371={};var _0x1795e9={};var _0x3dcfa1;var _0x360bee;return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0x55e4e6[_0x3f7c('0x44')]['id']}})['then'](handleEntityNotFound(_0x1060ef,null))[_0x3f7c('0x23')](function(_0x3b4cb2){if(_0x3b4cb2){_0x3dcfa1=_0x3b4cb2;_0x1795e9['model']=_['keys'](db[_0x3f7c('0x117')][_0x3f7c('0x2d')]);_0x1795e9['query']=_['keys'](_0x55e4e6[_0x3f7c('0x31')]);_0x1795e9[_0x3f7c('0x3c')]=_[_0x3f7c('0x32')](_0x1795e9[_0x3f7c('0x33')],_0x1795e9[_0x3f7c('0x31')]);_0x4b6371[_0x3f7c('0x34')]=_[_0x3f7c('0x32')](_0x1795e9[_0x3f7c('0x33')],qs[_0x3f7c('0x35')](_0x55e4e6[_0x3f7c('0x31')]['fields']));_0x4b6371['attributes']=_0x4b6371[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x4b6371[_0x3f7c('0x34')]:_0x1795e9['model'];_0x4b6371[_0x3f7c('0x39')]=qs[_0x3f7c('0x3a')](_0x55e4e6['query'][_0x3f7c('0x3a')]);_0x4b6371[_0x3f7c('0x3b')]=qs[_0x3f7c('0x3c')](_[_0x3f7c('0x3d')](_0x55e4e6['query'],_0x1795e9[_0x3f7c('0x3c')]));if(_0x55e4e6[_0x3f7c('0x31')][_0x3f7c('0x3e')]){_0x4b6371[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x4b6371[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x4b6371[_0x3f7c('0x34')],function(_0x33f8b1){var _0x5c2779={};_0x5c2779[_0x33f8b1]={'$like':'%'+_0x55e4e6[_0x3f7c('0x31')]['filter']+'%'};return _0x5c2779;})});}_0x4b6371=_[_0x3f7c('0x3f')]({},_0x4b6371,_0x55e4e6['options']);return _0x3dcfa1[_0x3f7c('0x116')](_0x4b6371);}})[_0x3f7c('0x23')](function(_0x5533e3){if(_0x5533e3){_0x360bee=_0x5533e3[_0x3f7c('0x36')];if(!_0x55e4e6[_0x3f7c('0x31')][_0x3f7c('0x37')](_0x3f7c('0x38'))){_0x4b6371[_0x3f7c('0x1f')]=qs['limit'](_0x55e4e6['query']['limit']);_0x4b6371[_0x3f7c('0x1d')]=qs[_0x3f7c('0x1d')](_0x55e4e6['query']['offset']);}return _0x3dcfa1[_0x3f7c('0x116')](_0x4b6371);}})[_0x3f7c('0x23')](function(_0x30bd97){if(_0x30bd97){return _0x30bd97?{'count':_0x360bee,'rows':_0x30bd97}:null;}})[_0x3f7c('0x23')](respondWithResult(_0x1060ef,null))[_0x3f7c('0x19')](handleError(_0x1060ef,null));};exports['getFields']=function(_0x5a4646,_0x36338d){var _0x2ff0f3=_0x5a4646[_0x3f7c('0x31')][_0x3f7c('0x118')]===_0x3f7c('0x119')?'offlineForm':_0x3f7c('0x11a');return db[_0x3f7c('0x2c')]['find']({'attributes':['id',_0x2ff0f3],'where':{'id':_0x5a4646[_0x3f7c('0x44')]['id']}})['then'](handleEntityNotFound(_0x36338d,null))[_0x3f7c('0x23')](function(_0x29d3bc){if(_0x29d3bc){var _0x2c5ca6=_0x29d3bc[_0x2ff0f3];var _0x56b5de=_0x2c5ca6&&_0x2c5ca6[_0x3f7c('0x11b')]?_0x2c5ca6[_0x3f7c('0x11b')]:[];_0x36338d[_0x3f7c('0x29')]({'fromKey':_['isNil'](_0x2c5ca6[_0x3f7c('0x11c')])?undefined:_0x2c5ca6[_0x3f7c('0x11c')],'count':_0x56b5de['length'],'rows':_0x56b5de});}})[_0x3f7c('0x19')](handleError(_0x36338d,null));};exports[_0x3f7c('0x11d')]=function(_0xd08aee,_0x3e9eb1){var _0x360d91={'raw':![],'where':{}};var _0x37c489={};var _0x4e81a5={'count':0x0,'rows':[]};return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0xd08aee['params']['id']}})['then'](handleEntityNotFound(_0x3e9eb1,null))[_0x3f7c('0x23')](function(_0x347578){if(_0x347578){_0x37c489[_0x3f7c('0x33')]=_[_0x3f7c('0x30')](db[_0x3f7c('0xc6')]['rawAttributes']);_0x37c489['query']=_[_0x3f7c('0x30')](_0xd08aee[_0x3f7c('0x31')]);_0x37c489[_0x3f7c('0x3c')]=_[_0x3f7c('0x32')](_0x37c489[_0x3f7c('0x33')],_0x37c489[_0x3f7c('0x31')]);_0x360d91[_0x3f7c('0x34')]=_[_0x3f7c('0x32')](_0x37c489[_0x3f7c('0x33')],qs[_0x3f7c('0x35')](_0xd08aee['query'][_0x3f7c('0x35')]));_0x360d91['attributes']=_0x360d91[_0x3f7c('0x34')][_0x3f7c('0x36')]?_0x360d91[_0x3f7c('0x34')]:_0x37c489[_0x3f7c('0x33')];if(!_0xd08aee[_0x3f7c('0x31')][_0x3f7c('0x37')](_0x3f7c('0x38'))){_0x360d91[_0x3f7c('0x1f')]=qs['limit'](_0xd08aee[_0x3f7c('0x31')][_0x3f7c('0x1f')]);_0x360d91[_0x3f7c('0x1d')]=qs[_0x3f7c('0x1d')](_0xd08aee['query'][_0x3f7c('0x1d')]);}_0x360d91[_0x3f7c('0x39')]=qs[_0x3f7c('0x3a')](_0xd08aee[_0x3f7c('0x31')][_0x3f7c('0x3a')]);_0x360d91[_0x3f7c('0x3b')]=qs[_0x3f7c('0x3c')](_[_0x3f7c('0x3d')](_0xd08aee['query'],_0x37c489[_0x3f7c('0x3c')]));_0x360d91['where'][_0x3f7c('0x57')]=_0x347578['id'];if(_0xd08aee['query'][_0x3f7c('0x3e')]){_0x360d91['where']=_['merge'](_0x360d91[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x360d91['attributes'],function(_0xcdc009){var _0x403afa={};_0x403afa[_0xcdc009]={'$like':'%'+_0xd08aee[_0x3f7c('0x31')][_0x3f7c('0x3e')]+'%'};return _0x403afa;})});}_0x360d91=_[_0x3f7c('0x3f')]({},_0x360d91,_0xd08aee[_0x3f7c('0x41')]);return db['ChatOfflineMessage'][_0x3f7c('0x42')]({'where':_0x360d91[_0x3f7c('0x3b')]})[_0x3f7c('0x23')](function(_0xf196fe){_0x4e81a5['count']=_0xf196fe;if(_0xd08aee[_0x3f7c('0x31')][_0x3f7c('0x43')]){_0x360d91[_0x3f7c('0x45')]=[{'all':!![]}];}else{_0x360d91['include']=[{'model':db[_0x3f7c('0x86')],'as':'Contact','required':![]},{'model':db['Attachment'],'as':_0x3f7c('0x11e'),'required':![]}];}return db[_0x3f7c('0xc6')]['findAll'](_0x360d91);})[_0x3f7c('0x23')](function(_0x79bd1a){_0x4e81a5[_0x3f7c('0x5b')]=_0x79bd1a;return _0x4e81a5;});}})['then'](respondWithFilteredResult(_0x3e9eb1,_0x360d91))[_0x3f7c('0x19')](handleError(_0x3e9eb1,null));};exports[_0x3f7c('0x11f')]=function(_0x39c27a,_0x31cefb){return db[_0x3f7c('0x2c')][_0x3f7c('0x4c')]({'where':{'id':_0x39c27a[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x31cefb,null))[_0x3f7c('0x23')](function(_0x2650b1){if(_0x2650b1){return _0x2650b1[_0x3f7c('0x11f')](_0x39c27a[_0x3f7c('0x50')][_0x3f7c('0x5d')],_[_0x3f7c('0xe7')](_0x39c27a[_0x3f7c('0x50')],[_0x3f7c('0x5d'),'id'])||{})['spread'](function(_0x78bef2){for(var _0x4d9af9=0x0;_0x4d9af9<_0x39c27a[_0x3f7c('0x50')][_0x3f7c('0x5d')][_0x3f7c('0x36')];_0x4d9af9+=0x1){socket['emit'](_0x3f7c('0x120'),{'UserId':Number(_0x39c27a[_0x3f7c('0x50')]['ids'][_0x4d9af9]),'ChatWebsiteId':Number(_0x39c27a['params']['id'])});}return _0x78bef2;});}})['then'](respondWithResult(_0x31cefb,null))[_0x3f7c('0x19')](handleError(_0x31cefb,null));};exports[_0x3f7c('0x121')]=function(_0x157c00,_0x5c6e92){return db[_0x3f7c('0x2c')]['find']({'where':{'id':_0x157c00[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x5c6e92,null))[_0x3f7c('0x23')](function(_0x3487de){if(_0x3487de){return _0x3487de[_0x3f7c('0x121')](_0x157c00['query'][_0x3f7c('0x5d')])['then'](function(){if(_['isArray'](_0x157c00[_0x3f7c('0x31')][_0x3f7c('0x5d')])){for(var _0x55f736=0x0;_0x55f736<_0x157c00[_0x3f7c('0x31')]['ids']['length'];_0x55f736+=0x1){socket[_0x3f7c('0x122')](_0x3f7c('0x123'),{'UserId':Number(_0x157c00[_0x3f7c('0x31')]['ids'][_0x55f736]),'ChatWebsiteId':Number(_0x157c00[_0x3f7c('0x44')]['id'])});}}else{socket[_0x3f7c('0x122')]('userChatWebsite:remove',{'UserId':Number(_0x157c00[_0x3f7c('0x31')][_0x3f7c('0x5d')]),'ChatWebsiteId':Number(_0x157c00[_0x3f7c('0x44')]['id'])});}});}})[_0x3f7c('0x23')](respondWithStatusCode(_0x5c6e92,null))[_0x3f7c('0x19')](handleError(_0x5c6e92,null));};exports[_0x3f7c('0x124')]=function(_0x5b468e,_0x2f3d1f){var _0x1123ba={};var _0x237628={};var _0x349983;var _0x369063;return db[_0x3f7c('0x2c')][_0x3f7c('0x56')]({'where':{'id':_0x5b468e[_0x3f7c('0x44')]['id']}})[_0x3f7c('0x23')](handleEntityNotFound(_0x2f3d1f,null))[_0x3f7c('0x23')](function(_0x3847b4){if(_0x3847b4){_0x349983=_0x3847b4;_0x237628[_0x3f7c('0x33')]=_[_0x3f7c('0x30')](db['User'][_0x3f7c('0x2d')]);_0x237628[_0x3f7c('0x31')]=_[_0x3f7c('0x30')](_0x5b468e[_0x3f7c('0x31')]);_0x237628[_0x3f7c('0x3c')]=_[_0x3f7c('0x32')](_0x237628[_0x3f7c('0x33')],_0x237628['query']);_0x1123ba[_0x3f7c('0x34')]=_[_0x3f7c('0x32')](_0x237628[_0x3f7c('0x33')],qs['fields'](_0x5b468e[_0x3f7c('0x31')][_0x3f7c('0x35')]));_0x1123ba[_0x3f7c('0x34')]=_0x1123ba[_0x3f7c('0x34')]['length']?_0x1123ba[_0x3f7c('0x34')]:_0x237628[_0x3f7c('0x33')];_0x1123ba[_0x3f7c('0x39')]=qs['sort'](_0x5b468e[_0x3f7c('0x31')][_0x3f7c('0x3a')]);_0x1123ba['where']=qs[_0x3f7c('0x3c')](_['pick'](_0x5b468e[_0x3f7c('0x31')],_0x237628['filters']));if(_0x5b468e['query'][_0x3f7c('0x3e')]){_0x1123ba[_0x3f7c('0x3b')]=_[_0x3f7c('0x3f')](_0x1123ba[_0x3f7c('0x3b')],{'$or':_[_0x3f7c('0x2b')](_0x1123ba[_0x3f7c('0x34')],function(_0x58a76e){var _0x4359ae={};_0x4359ae[_0x58a76e]={'$like':'%'+_0x5b468e[_0x3f7c('0x31')][_0x3f7c('0x3e')]+'%'};return _0x4359ae;})});}_0x1123ba=_['merge']({},_0x1123ba,_0x5b468e[_0x3f7c('0x41')]);return _0x349983[_0x3f7c('0x124')](_0x1123ba);}})[_0x3f7c('0x23')](function(_0xd7d2ee){if(_0xd7d2ee){_0x369063=_0xd7d2ee['length'];if(!_0x5b468e[_0x3f7c('0x31')]['hasOwnProperty'](_0x3f7c('0x38'))){_0x1123ba[_0x3f7c('0x1f')]=qs['limit'](_0x5b468e[_0x3f7c('0x31')][_0x3f7c('0x1f')]);_0x1123ba[_0x3f7c('0x1d')]=qs['offset'](_0x5b468e['query'][_0x3f7c('0x1d')]);}return _0x349983[_0x3f7c('0x124')](_0x1123ba);}})[_0x3f7c('0x23')](function(_0x397f13){if(_0x397f13){return _0x397f13?{'count':_0x369063,'rows':_0x397f13}:null;}})['then'](respondWithResult(_0x2f3d1f,null))[_0x3f7c('0x19')](handleError(_0x2f3d1f,null));};