Built motion from commit a61a4a20.|2.5.46
[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 _0xf961=['orderBy','priority','asc','Applications','headers','cf-connecting-ip','x-forwarded-for','x-real-port','referer','browser','format','%s\x20%s','version','device','vendor','%s\x20%s\x20%s','threadId','ChatInteraction','externalUrl','ContactId','interaction','contact','firstName','messageId','created','autoclose','push','close','unmanaged','*,*,*,*','ChatMessage','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','startRouting','Start','EventManager','offline','ValidationError','from\x20is\x20mandatory','mapKeyOffline','includes','mapKeyOffline\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','MailAccount','spread','readFileSync','server/files/templates/chatOfflineMessage.ejs','utf8','toPairs','offlineMessageBody','ChatOfflineMessage','fromString','originalname','mimetype','server','files','attachments','offline-chat','basename','openNewInteraction','transaction','Attachment','MailServerOut','Smtp','forwardOffline','forwardOfflineAddress','service','host','port','secure','auth','user','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','offlineMessageSubject','MailAccountId','subjectOffline','toPairsIn','mapValues','lastName','NotifyMailAccount','remove','Could\x20not\x20remove\x20attachment\x20file','addInteraction','omit','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','timezone','iftime\x20%s,%s','interval','iftime\x20%s','true','[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)','ONLINE','inspect','No\x20timezone','getSnippet','Interval','Intervals','getProactiveActions','virtual','custom','increment','all','remote','x-real-ip','connection','replace','render','verticalAlignment','labelText','textColor','color_button','backgroundColor','hideWhenOffline','IntervalId','sequelize','Transaction','ISOLATION_LEVELS','bulkCreate','findAndCountAll','finally','getApplications','addProactiveActions','chatProactiveAction','ChatProactiveAction','getFields','online','false','offlineForm','onlineForm','items','fromKey','getOfflineMessages','Attachments','addAgents','userChatWebsite:save','removeAgents','emit','userChatWebsite:remove','getAgents','bluebird','mustache','util','path','fs-extra','lodash','querystring','../../components/parsers/qs','../../config/logger','api','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./chatWebsite.socket','jayson/promise','http','client','request','info','ChatWebsite,\x20%s,\x20%s','request\x20sent','ChatWebsite,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','update','then','get','ChatWebsites','UserProfileResource','destroy','stack','name','send','index','Pause','mandatoryDispositionPause','map','ChatWebsite','rawAttributes','fieldName','type','key','model','query','filters','attributes','fields','length','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','intersection','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','ChatWebsiteId','Disposition','getDispositions','findOne','hasOwnProperty','removeDispositions','ids','CannedAnswer','removeAnswers','addLogo','sitepic','file','addAvatar','agentAvatar','filename','addCustomerAvatar','addSystemAvatar','getLogo','root','server/files/images/logos/default_logo.svg','../../config/license/util','getLicense','isNil','existsSync','join','server/files/images/logos/','download','server/files/images/avatars/default_avatar.png','server/files/images/avatars/','getCustomerAvatar','server/files/images/avatars/customer_avatar.png','customerAvatar','showCustomerAvatar','getSystemAvatar','systemAvatar','notify','setUA','user-agent','getResult','chat','CmContact','no\x20available\x20attributes','createdAt','updatedAt','difference','CompanyId','ListId','from','Sequelize','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','Contacts','DESC','ChatApplication','List','account','applications','list'];(function(_0x2ed08e,_0x31e039){var _0x5d98cb=function(_0x345294){while(--_0x345294){_0x2ed08e['push'](_0x2ed08e['shift']());}};_0x5d98cb(++_0x31e039);}(_0xf961,0x1cf));var _0x1f96=function(_0x3ab9ee,_0x4a74b8){_0x3ab9ee=_0x3ab9ee-0x0;var _0x82ee88=_0xf961[_0x3ab9ee];return _0x82ee88;};'use strict';var BPromise=require(_0x1f96('0x0'));var Mustache=require(_0x1f96('0x1'));var util=require(_0x1f96('0x2'));var path=require(_0x1f96('0x3'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1f96('0x4'));var _=require(_0x1f96('0x5'));var querystring=require(_0x1f96('0x6'));var Redis=require('ioredis');var qs=require(_0x1f96('0x7'));var logger=require(_0x1f96('0x8'))(_0x1f96('0x9'));var config=require('../../config/environment');var db=require(_0x1f96('0xa'))['db'];config['redis']=_[_0x1f96('0xb')](config[_0x1f96('0xc')],{'host':_0x1f96('0xd'),'port':0x18eb});var socket=require(_0x1f96('0xe'))(new Redis(config[_0x1f96('0xc')]));require(_0x1f96('0xf'))['register'](socket);var htmlToText=require('html-to-text');var jayson=require(_0x1f96('0x10'));var client=jayson['client'][_0x1f96('0x11')]({'port':0x232c});var client9002=jayson[_0x1f96('0x12')][_0x1f96('0x11')]({'port':0x232a});var client9003=jayson[_0x1f96('0x12')]['http']({'port':0x232b});var client9001=jayson[_0x1f96('0x12')][_0x1f96('0x11')]({'port':0x2329});function respondWithRpcPromise(_0x3c045f,_0x4dafee,_0x7a4391,_0x13c5d3){return new BPromise(function(_0x4669b3,_0xe69e8c){var _0x3d3c3c=_0x13c5d3||client;return _0x3d3c3c[_0x1f96('0x13')](_0x3c045f,_0x7a4391)['then'](function(_0x11d22d){logger[_0x1f96('0x14')](_0x1f96('0x15'),_0x4dafee,_0x1f96('0x16'));logger['debug'](_0x1f96('0x17'),_0x4dafee,_0x1f96('0x16'),JSON[_0x1f96('0x18')](_0x11d22d));if(_0x11d22d[_0x1f96('0x19')]){if(_0x11d22d[_0x1f96('0x19')][_0x1f96('0x1a')]===0x1f4){logger[_0x1f96('0x19')](_0x1f96('0x15'),_0x4dafee,_0x11d22d['error'][_0x1f96('0x1b')]);return _0xe69e8c(_0x11d22d[_0x1f96('0x19')]['message']);}logger[_0x1f96('0x19')](_0x1f96('0x15'),_0x4dafee,_0x11d22d[_0x1f96('0x19')][_0x1f96('0x1b')]);return _0x4669b3(_0x11d22d[_0x1f96('0x19')][_0x1f96('0x1b')]);}else{logger['info'](_0x1f96('0x15'),_0x4dafee,'request\x20sent');_0x4669b3(_0x11d22d[_0x1f96('0x1c')][_0x1f96('0x1b')]);}})[_0x1f96('0x1d')](function(_0x3ec6a2){logger['error'](_0x1f96('0x15'),_0x4dafee,_0x3ec6a2);_0xe69e8c(_0x3ec6a2);});});}function respondWithStatusCode(_0x28c9cb,_0x51d0b3){_0x51d0b3=_0x51d0b3||0xcc;return function(_0x4e965a){if(_0x4e965a){return _0x28c9cb[_0x1f96('0x1e')](_0x51d0b3);}return _0x28c9cb[_0x1f96('0x1f')](_0x51d0b3)[_0x1f96('0x20')]();};}function respondWithResult(_0x573808,_0x151bc8){_0x151bc8=_0x151bc8||0xc8;return function(_0x30fdcd){if(_0x30fdcd){return _0x573808[_0x1f96('0x1f')](_0x151bc8)[_0x1f96('0x21')](_0x30fdcd);}};}function respondWithFilteredResult(_0x322b03,_0x1ffa96){return function(_0x987bd9){if(_0x987bd9){var _0x4057f6=typeof _0x1ffa96['offset']==='undefined'&&typeof _0x1ffa96['limit']==='undefined';var _0x50d182=_0x987bd9[_0x1f96('0x22')];var _0x42e247=_0x4057f6?0x0:_0x1ffa96[_0x1f96('0x23')];var _0x94e25e=_0x4057f6?_0x987bd9['count']:_0x1ffa96[_0x1f96('0x23')]+_0x1ffa96[_0x1f96('0x24')];var _0x29e1d2;if(_0x94e25e>=_0x50d182){_0x94e25e=_0x50d182;_0x29e1d2=0xc8;}else{_0x29e1d2=0xce;}_0x322b03['status'](_0x29e1d2);return _0x322b03[_0x1f96('0x25')](_0x1f96('0x26'),_0x42e247+'-'+_0x94e25e+'/'+_0x50d182)['json'](_0x987bd9);}return null;};}function saveUpdates(_0x5ddb20){return function(_0x2f0429){if(_0x2f0429){return _0x2f0429[_0x1f96('0x27')](_0x5ddb20)[_0x1f96('0x28')](function(_0x1f182a){return _0x1f182a;});}return null;};}function removeEntity(_0x7930af){return function(_0x393e08){if(_0x393e08){return _0x393e08['destroy']()[_0x1f96('0x28')](function(){var _0x504120=_0x393e08[_0x1f96('0x29')]({'plain':!![]});var _0x25f639=_0x1f96('0x2a');return db[_0x1f96('0x2b')][_0x1f96('0x2c')]({'where':{'type':_0x25f639,'resourceId':_0x504120['id']}})['then'](function(){return _0x393e08;});})[_0x1f96('0x28')](function(){_0x7930af[_0x1f96('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x17810e){return function(_0x2e18ad){if(!_0x2e18ad){_0x17810e[_0x1f96('0x1e')](0x194);}return _0x2e18ad;};}function handleError(_0x168dd6,_0x59b719){_0x59b719=_0x59b719||0x1f4;return function(_0x17792a){logger[_0x1f96('0x19')](_0x17792a[_0x1f96('0x2d')]);if(_0x17792a['name']){delete _0x17792a[_0x1f96('0x2e')];}_0x168dd6[_0x1f96('0x1f')](_0x59b719)[_0x1f96('0x2f')](_0x17792a);};}exports[_0x1f96('0x30')]=function(_0x3e6b99,_0xf0c804){var _0x35015d={'include':[{'model':db[_0x1f96('0x31')],'as':_0x1f96('0x32')}]},_0x1cc45a={},_0x5bba8f={'count':0x0,'rows':[]};var _0x58f961=_[_0x1f96('0x33')](db[_0x1f96('0x34')][_0x1f96('0x35')],function(_0x6f5a73){return{'name':_0x6f5a73[_0x1f96('0x36')],'type':_0x6f5a73[_0x1f96('0x37')][_0x1f96('0x38')]};});_0x1cc45a[_0x1f96('0x39')]=_[_0x1f96('0x33')](_0x58f961,_0x1f96('0x2e'));_0x1cc45a[_0x1f96('0x3a')]=_['keys'](_0x3e6b99[_0x1f96('0x3a')]);_0x1cc45a[_0x1f96('0x3b')]=_['intersection'](_0x1cc45a['model'],_0x1cc45a[_0x1f96('0x3a')]);_0x35015d[_0x1f96('0x3c')]=_['intersection'](_0x1cc45a['model'],qs[_0x1f96('0x3d')](_0x3e6b99[_0x1f96('0x3a')][_0x1f96('0x3d')]));_0x35015d[_0x1f96('0x3c')]=_0x35015d[_0x1f96('0x3c')][_0x1f96('0x3e')]?_0x35015d['attributes']:_0x1cc45a[_0x1f96('0x39')];if(!_0x3e6b99['query']['hasOwnProperty'](_0x1f96('0x3f'))){_0x35015d[_0x1f96('0x24')]=qs[_0x1f96('0x24')](_0x3e6b99[_0x1f96('0x3a')][_0x1f96('0x24')]);_0x35015d['offset']=qs[_0x1f96('0x23')](_0x3e6b99[_0x1f96('0x3a')]['offset']);}_0x35015d[_0x1f96('0x40')]=qs[_0x1f96('0x41')](_0x3e6b99[_0x1f96('0x3a')][_0x1f96('0x41')]);_0x35015d['where']=qs[_0x1f96('0x3b')](_[_0x1f96('0x42')](_0x3e6b99[_0x1f96('0x3a')],_0x1cc45a['filters']),_0x58f961);if(_0x3e6b99['query'][_0x1f96('0x43')]){_0x35015d[_0x1f96('0x44')]=_[_0x1f96('0x45')](_0x35015d[_0x1f96('0x44')],{'$or':_[_0x1f96('0x33')](_0x58f961,function(_0x4ec221){if(_0x4ec221[_0x1f96('0x37')]!==_0x1f96('0x46')){var _0x3061b2={};_0x3061b2[_0x4ec221[_0x1f96('0x2e')]]={'$like':'%'+_0x3e6b99[_0x1f96('0x3a')]['filter']+'%'};return _0x3061b2;}})});}_0x35015d=_[_0x1f96('0x45')]({},_0x35015d,_0x3e6b99[_0x1f96('0x47')]);var _0x2bf388={'where':_0x35015d[_0x1f96('0x44')]};return db[_0x1f96('0x34')][_0x1f96('0x22')](_0x2bf388)[_0x1f96('0x28')](function(_0x3f2926){_0x5bba8f[_0x1f96('0x22')]=_0x3f2926;if(_0x3e6b99['query'][_0x1f96('0x48')]){_0x35015d[_0x1f96('0x49')]=[{'all':!![]}];}return db[_0x1f96('0x34')][_0x1f96('0x4a')](_0x35015d);})[_0x1f96('0x28')](function(_0x12b56b){_0x5bba8f[_0x1f96('0x4b')]=_0x12b56b;return _0x5bba8f;})[_0x1f96('0x28')](respondWithFilteredResult(_0xf0c804,_0x35015d))[_0x1f96('0x1d')](handleError(_0xf0c804,null));};exports[_0x1f96('0x4c')]=function(_0x153746,_0x4f01d3){var _0x3683c9={'raw':![],'where':{'id':_0x153746[_0x1f96('0x4d')]['id']},'include':[{'model':db[_0x1f96('0x31')],'as':_0x1f96('0x32')}]},_0x4d2778={};_0x4d2778[_0x1f96('0x39')]=_[_0x1f96('0x4e')](db['ChatWebsite'][_0x1f96('0x35')]);_0x4d2778[_0x1f96('0x3a')]=_[_0x1f96('0x4e')](_0x153746[_0x1f96('0x3a')]);_0x4d2778[_0x1f96('0x3b')]=_[_0x1f96('0x4f')](_0x4d2778['model'],_0x4d2778[_0x1f96('0x3a')]);_0x3683c9[_0x1f96('0x3c')]=_[_0x1f96('0x4f')](_0x4d2778['model'],qs['fields'](_0x153746[_0x1f96('0x3a')][_0x1f96('0x3d')]));_0x3683c9['attributes']=_0x3683c9[_0x1f96('0x3c')]['length']?_0x3683c9[_0x1f96('0x3c')]:_0x4d2778[_0x1f96('0x39')];if(_0x153746['query'][_0x1f96('0x48')]){_0x3683c9['include']=[{'all':!![]}];}_0x3683c9=_[_0x1f96('0x45')]({},_0x3683c9,_0x153746['options']);return db[_0x1f96('0x34')]['find'](_0x3683c9)['then'](handleEntityNotFound(_0x4f01d3,null))[_0x1f96('0x28')](respondWithResult(_0x4f01d3,null))['catch'](handleError(_0x4f01d3,null));};exports[_0x1f96('0x50')]=function(_0x36f791,_0x142d4a){return db['ChatWebsite'][_0x1f96('0x50')](_0x36f791[_0x1f96('0x51')],{})[_0x1f96('0x28')](function(_0x48fa45){var _0x365141=_0x36f791['user'][_0x1f96('0x29')]({'plain':!![]});if(!_0x365141)throw new Error(_0x1f96('0x52'));if(_0x365141[_0x1f96('0x53')]==='user'){var _0x57b42c=_0x48fa45['get']({'plain':!![]});var _0x497fa4='ChatWebsites';return db[_0x1f96('0x54')][_0x1f96('0x55')]({'where':{'name':_0x497fa4,'userProfileId':_0x365141[_0x1f96('0x56')]},'raw':!![]})[_0x1f96('0x28')](function(_0x53ce01){if(_0x53ce01&&_0x53ce01[_0x1f96('0x57')]===0x0){return db['UserProfileResource'][_0x1f96('0x50')]({'name':_0x57b42c[_0x1f96('0x2e')],'resourceId':_0x57b42c['id'],'type':_0x53ce01[_0x1f96('0x2e')],'sectionId':_0x53ce01['id']},{})[_0x1f96('0x28')](function(){return _0x48fa45;});}else{return _0x48fa45;}})[_0x1f96('0x1d')](function(_0x2d8a71){logger['error'](_0x1f96('0x58'),_0x2d8a71);throw _0x2d8a71;});}return _0x48fa45;})[_0x1f96('0x28')](respondWithResult(_0x142d4a,0xc9))[_0x1f96('0x1d')](handleError(_0x142d4a,null));};exports[_0x1f96('0x27')]=function(_0x237f14,_0x3e1e75){if(_0x237f14[_0x1f96('0x51')]['id']){delete _0x237f14[_0x1f96('0x51')]['id'];}return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x237f14[_0x1f96('0x4d')]['id']},'include':[{'model':db[_0x1f96('0x31')],'as':_0x1f96('0x32')}]})[_0x1f96('0x28')](handleEntityNotFound(_0x3e1e75,null))[_0x1f96('0x28')](saveUpdates(_0x237f14[_0x1f96('0x51')],null))[_0x1f96('0x28')](respondWithResult(_0x3e1e75,null))[_0x1f96('0x1d')](handleError(_0x3e1e75,null));};exports[_0x1f96('0x2c')]=function(_0x3d1058,_0x521161){return db[_0x1f96('0x34')]['find']({'where':{'id':_0x3d1058['params']['id']}})['then'](handleEntityNotFound(_0x521161,null))['then'](removeEntity(_0x521161,null))['catch'](handleError(_0x521161,null));};exports[_0x1f96('0x59')]=function(_0x1e3801,_0x38eba7){return db[_0x1f96('0x34')]['describe']()[_0x1f96('0x28')](respondWithResult(_0x38eba7,null))[_0x1f96('0x1d')](handleError(_0x38eba7,null));};exports[_0x1f96('0x5a')]=function(_0x4e61a2,_0x168d5f){if(_0x4e61a2[_0x1f96('0x51')]['id']){delete _0x4e61a2[_0x1f96('0x51')]['id'];}return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x4e61a2['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x168d5f,null))['then'](function(_0x22b611){if(_0x22b611){_0x4e61a2['body'][_0x1f96('0x5b')]=_0x22b611['id'];return db[_0x1f96('0x5c')]['create'](_0x4e61a2[_0x1f96('0x51')]);}})[_0x1f96('0x28')](respondWithResult(_0x168d5f,null))[_0x1f96('0x1d')](handleError(_0x168d5f,null));};exports[_0x1f96('0x5d')]=function(_0x31bf77,_0x15c324){var _0x1c5960={'raw':![],'where':{}};var _0xa95597={};var _0x2618c7={'count':0x0,'rows':[]};return db[_0x1f96('0x34')][_0x1f96('0x5e')]({'where':{'id':_0x31bf77[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x15c324,null))[_0x1f96('0x28')](function(_0x4c5998){if(_0x4c5998){_0xa95597[_0x1f96('0x39')]=_[_0x1f96('0x4e')](db[_0x1f96('0x5c')][_0x1f96('0x35')]);_0xa95597[_0x1f96('0x3a')]=_[_0x1f96('0x4e')](_0x31bf77[_0x1f96('0x3a')]);_0xa95597[_0x1f96('0x3b')]=_[_0x1f96('0x4f')](_0xa95597[_0x1f96('0x39')],_0xa95597[_0x1f96('0x3a')]);_0x1c5960['attributes']=_['intersection'](_0xa95597[_0x1f96('0x39')],qs[_0x1f96('0x3d')](_0x31bf77[_0x1f96('0x3a')][_0x1f96('0x3d')]));_0x1c5960['attributes']=_0x1c5960[_0x1f96('0x3c')]['length']?_0x1c5960[_0x1f96('0x3c')]:_0xa95597[_0x1f96('0x39')];if(!_0x31bf77['query'][_0x1f96('0x5f')]('nolimit')){_0x1c5960[_0x1f96('0x24')]=qs[_0x1f96('0x24')](_0x31bf77[_0x1f96('0x3a')][_0x1f96('0x24')]);_0x1c5960[_0x1f96('0x23')]=qs[_0x1f96('0x23')](_0x31bf77[_0x1f96('0x3a')][_0x1f96('0x23')]);}_0x1c5960[_0x1f96('0x40')]=qs[_0x1f96('0x41')](_0x31bf77['query'][_0x1f96('0x41')]);_0x1c5960[_0x1f96('0x44')]=qs[_0x1f96('0x3b')](_[_0x1f96('0x42')](_0x31bf77['query'],_0xa95597[_0x1f96('0x3b')]));_0x1c5960[_0x1f96('0x44')][_0x1f96('0x5b')]=_0x4c5998['id'];if(_0x31bf77[_0x1f96('0x3a')][_0x1f96('0x43')]){_0x1c5960[_0x1f96('0x44')]=_['merge'](_0x1c5960[_0x1f96('0x44')],{'$or':_[_0x1f96('0x33')](_0x1c5960[_0x1f96('0x3c')],function(_0x33c5de){var _0x3cd4de={};_0x3cd4de[_0x33c5de]={'$like':'%'+_0x31bf77['query']['filter']+'%'};return _0x3cd4de;})});}_0x1c5960=_[_0x1f96('0x45')]({},_0x1c5960,_0x31bf77['options']);return db[_0x1f96('0x5c')]['count']({'where':_0x1c5960[_0x1f96('0x44')]})[_0x1f96('0x28')](function(_0x5c8893){_0x2618c7[_0x1f96('0x22')]=_0x5c8893;if(_0x31bf77['query']['includeAll']){_0x1c5960[_0x1f96('0x49')]=[{'all':!![]}];}return db[_0x1f96('0x5c')][_0x1f96('0x4a')](_0x1c5960);})[_0x1f96('0x28')](function(_0x388c82){_0x2618c7[_0x1f96('0x4b')]=_0x388c82;return _0x2618c7;});}})[_0x1f96('0x28')](respondWithFilteredResult(_0x15c324,_0x1c5960))['catch'](handleError(_0x15c324,null));};exports[_0x1f96('0x60')]=function(_0x2d19d0,_0x1d646c){return db[_0x1f96('0x34')]['find']({'where':{'id':_0x2d19d0['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x1d646c,null))['then'](function(_0x3d72fe){if(_0x3d72fe){return _0x3d72fe['removeDispositions'](_0x2d19d0['query'][_0x1f96('0x61')]);}})[_0x1f96('0x28')](respondWithStatusCode(_0x1d646c,null))['catch'](handleError(_0x1d646c,null));};exports['addAnswer']=function(_0x1331fd,_0x236014){if(_0x1331fd[_0x1f96('0x51')]['id']){delete _0x1331fd['body']['id'];}return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x1331fd['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x236014,null))['then'](function(_0x26de56){if(_0x26de56){_0x1331fd['body'][_0x1f96('0x5b')]=_0x26de56['id'];return db['CannedAnswer']['create'](_0x1331fd[_0x1f96('0x51')]);}})['then'](respondWithResult(_0x236014,null))[_0x1f96('0x1d')](handleError(_0x236014,null));};exports['getAnswers']=function(_0x5d0709,_0x3f69dd){var _0xfd7098={'raw':![],'where':{}};var _0x468beb={};var _0x1257c7={'count':0x0,'rows':[]};return db[_0x1f96('0x34')][_0x1f96('0x5e')]({'where':{'id':_0x5d0709[_0x1f96('0x4d')]['id']}})['then'](handleEntityNotFound(_0x3f69dd,null))[_0x1f96('0x28')](function(_0x21e517){if(_0x21e517){_0x468beb['model']=_[_0x1f96('0x4e')](db[_0x1f96('0x62')][_0x1f96('0x35')]);_0x468beb[_0x1f96('0x3a')]=_[_0x1f96('0x4e')](_0x5d0709[_0x1f96('0x3a')]);_0x468beb[_0x1f96('0x3b')]=_[_0x1f96('0x4f')](_0x468beb[_0x1f96('0x39')],_0x468beb[_0x1f96('0x3a')]);_0xfd7098[_0x1f96('0x3c')]=_[_0x1f96('0x4f')](_0x468beb['model'],qs['fields'](_0x5d0709[_0x1f96('0x3a')][_0x1f96('0x3d')]));_0xfd7098[_0x1f96('0x3c')]=_0xfd7098[_0x1f96('0x3c')][_0x1f96('0x3e')]?_0xfd7098[_0x1f96('0x3c')]:_0x468beb[_0x1f96('0x39')];if(!_0x5d0709[_0x1f96('0x3a')][_0x1f96('0x5f')]('nolimit')){_0xfd7098[_0x1f96('0x24')]=qs[_0x1f96('0x24')](_0x5d0709[_0x1f96('0x3a')][_0x1f96('0x24')]);_0xfd7098[_0x1f96('0x23')]=qs[_0x1f96('0x23')](_0x5d0709[_0x1f96('0x3a')]['offset']);}_0xfd7098[_0x1f96('0x40')]=qs[_0x1f96('0x41')](_0x5d0709['query'][_0x1f96('0x41')]);_0xfd7098[_0x1f96('0x44')]=qs[_0x1f96('0x3b')](_[_0x1f96('0x42')](_0x5d0709[_0x1f96('0x3a')],_0x468beb[_0x1f96('0x3b')]));_0xfd7098['where']['ChatWebsiteId']=_0x21e517['id'];if(_0x5d0709[_0x1f96('0x3a')][_0x1f96('0x43')]){_0xfd7098[_0x1f96('0x44')]=_['merge'](_0xfd7098[_0x1f96('0x44')],{'$or':_[_0x1f96('0x33')](_0xfd7098[_0x1f96('0x3c')],function(_0x36ecd3){var _0x44197d={};_0x44197d[_0x36ecd3]={'$like':'%'+_0x5d0709['query']['filter']+'%'};return _0x44197d;})});}_0xfd7098=_['merge']({},_0xfd7098,_0x5d0709[_0x1f96('0x47')]);return db[_0x1f96('0x62')]['count']({'where':_0xfd7098[_0x1f96('0x44')]})[_0x1f96('0x28')](function(_0x4b4ea2){_0x1257c7[_0x1f96('0x22')]=_0x4b4ea2;if(_0x5d0709[_0x1f96('0x3a')][_0x1f96('0x48')]){_0xfd7098[_0x1f96('0x49')]=[{'all':!![]}];}return db[_0x1f96('0x62')][_0x1f96('0x4a')](_0xfd7098);})[_0x1f96('0x28')](function(_0xdcff2f){_0x1257c7[_0x1f96('0x4b')]=_0xdcff2f;return _0x1257c7;});}})['then'](respondWithFilteredResult(_0x3f69dd,_0xfd7098))[_0x1f96('0x1d')](handleError(_0x3f69dd,null));};exports[_0x1f96('0x63')]=function(_0x1a820a,_0x4c8bb7){return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x1a820a[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x4c8bb7,null))[_0x1f96('0x28')](function(_0x417c02){if(_0x417c02){return _0x417c02['removeAnswers'](_0x1a820a[_0x1f96('0x3a')][_0x1f96('0x61')]);}})['then'](respondWithStatusCode(_0x4c8bb7,null))[_0x1f96('0x1d')](handleError(_0x4c8bb7,null));};exports[_0x1f96('0x64')]=function(_0x58126b,_0x413f08){_0x58126b[_0x1f96('0x51')][_0x1f96('0x65')]=_0x58126b[_0x1f96('0x66')]['filename'];return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x58126b[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x413f08,null))[_0x1f96('0x28')](saveUpdates(_0x58126b[_0x1f96('0x51')],null))[_0x1f96('0x28')](respondWithResult(_0x413f08,null))['catch'](handleError(_0x413f08,null));};exports[_0x1f96('0x67')]=function(_0x2f1beb,_0x1e8731){_0x2f1beb['body'][_0x1f96('0x68')]=_0x2f1beb[_0x1f96('0x66')][_0x1f96('0x69')];return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x2f1beb[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x1e8731,null))['then'](saveUpdates(_0x2f1beb[_0x1f96('0x51')],null))[_0x1f96('0x28')](respondWithResult(_0x1e8731,null))[_0x1f96('0x1d')](handleError(_0x1e8731,null));};exports[_0x1f96('0x6a')]=function(_0x4b57fe,_0x576289){_0x4b57fe['body']['customerAvatar']=_0x4b57fe['file'][_0x1f96('0x69')];return db[_0x1f96('0x34')]['find']({'where':{'id':_0x4b57fe[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x576289,null))['then'](saveUpdates(_0x4b57fe[_0x1f96('0x51')],null))[_0x1f96('0x28')](respondWithResult(_0x576289,null))['catch'](handleError(_0x576289,null));};exports[_0x1f96('0x6b')]=function(_0xdd6934,_0x54db42){_0xdd6934['body']['systemAvatar']=_0xdd6934[_0x1f96('0x66')][_0x1f96('0x69')];return db['ChatWebsite']['find']({'where':{'id':_0xdd6934['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x54db42,null))[_0x1f96('0x28')](saveUpdates(_0xdd6934[_0x1f96('0x51')],null))[_0x1f96('0x28')](respondWithResult(_0x54db42,null))[_0x1f96('0x1d')](handleError(_0x54db42,null));};exports[_0x1f96('0x6c')]=function(_0x3a30b9,_0x53f5b4){var _0x30214c=path['join'](config[_0x1f96('0x6d')],_0x1f96('0x6e'));var _0x22eb5c={'where':{'id':_0x3a30b9['params']['id']},'attributes':['id',_0x1f96('0x65')],'raw':!![]};var _0x3acf1e=![];return require(_0x1f96('0x6f'))[_0x1f96('0x70')]()[_0x1f96('0x28')](function(_0x243fc0){if(_0x243fc0){_0x3acf1e=_0x243fc0['custom'];}})['then'](function(){return db[_0x1f96('0x34')][_0x1f96('0x55')](_0x22eb5c);})[_0x1f96('0x28')](handleEntityNotFound(_0x53f5b4,null))[_0x1f96('0x28')](function(_0x5958a3){if(_0x5958a3){if(!_[_0x1f96('0x71')](_0x5958a3[_0x1f96('0x65')])){if(fs[_0x1f96('0x72')](path[_0x1f96('0x73')](config[_0x1f96('0x6d')],_0x1f96('0x74'),_0x5958a3['sitepic']))&&_0x3acf1e){_0x30214c=path[_0x1f96('0x73')](config[_0x1f96('0x6d')],'server/files/images/logos/',_0x5958a3[_0x1f96('0x65')]);}}return _0x53f5b4[_0x1f96('0x75')](_0x30214c);}})[_0x1f96('0x1d')](handleError(_0x53f5b4,null));};exports['getAvatar']=function(_0x3a83e9,_0x4dfb51){var _0x5bc943=path['join'](config[_0x1f96('0x6d')],_0x1f96('0x76'));var _0x211b30={'where':{'id':_0x3a83e9[_0x1f96('0x4d')]['id']},'attributes':['id',_0x1f96('0x68')],'raw':!![]};return db[_0x1f96('0x34')][_0x1f96('0x55')](_0x211b30)[_0x1f96('0x28')](handleEntityNotFound(_0x4dfb51,null))['then'](function(_0xaf0119){if(_0xaf0119){if(!_[_0x1f96('0x71')](_0xaf0119[_0x1f96('0x68')])){if(fs[_0x1f96('0x72')](path[_0x1f96('0x73')](config['root'],_0x1f96('0x77'),_0xaf0119[_0x1f96('0x68')]))){_0x5bc943=path[_0x1f96('0x73')](config[_0x1f96('0x6d')],'server/files/images/avatars/',_0xaf0119['agentAvatar']);}}return _0x4dfb51[_0x1f96('0x75')](_0x5bc943);}})[_0x1f96('0x1d')](handleError(_0x4dfb51,null));};exports[_0x1f96('0x78')]=function(_0x12c439,_0x159f09){var _0x57cc29=path[_0x1f96('0x73')](config[_0x1f96('0x6d')],_0x1f96('0x79'));var _0x22ba65={'where':{'id':_0x12c439[_0x1f96('0x4d')]['id']},'attributes':['id','customerAvatar','showCustomerAvatar'],'raw':!![]};return db[_0x1f96('0x34')]['find'](_0x22ba65)[_0x1f96('0x28')](handleEntityNotFound(_0x159f09,null))[_0x1f96('0x28')](function(_0x45cae7){if(_0x45cae7){if(!_['isNil'](_0x45cae7[_0x1f96('0x7a')])){if(fs['existsSync'](path[_0x1f96('0x73')](config[_0x1f96('0x6d')],_0x1f96('0x77'),_0x45cae7['customerAvatar']))&&_0x45cae7[_0x1f96('0x7b')]){_0x57cc29=path['join'](config['root'],_0x1f96('0x77'),_0x45cae7[_0x1f96('0x7a')]);}}return _0x159f09[_0x1f96('0x75')](_0x57cc29);}})[_0x1f96('0x1d')](handleError(_0x159f09,null));};exports[_0x1f96('0x7c')]=function(_0x548b34,_0x1a0490){var _0x567d92=path[_0x1f96('0x73')](config[_0x1f96('0x6d')],'server/files/images/avatars/system_avatar.png');var _0x4ce885={'where':{'id':_0x548b34[_0x1f96('0x4d')]['id']},'attributes':['id',_0x1f96('0x7d')],'raw':!![]};return db['ChatWebsite']['find'](_0x4ce885)[_0x1f96('0x28')](handleEntityNotFound(_0x1a0490,null))[_0x1f96('0x28')](function(_0x25a405){if(_0x25a405){if(!_['isNil'](_0x25a405['systemAvatar'])){if(fs[_0x1f96('0x72')](path[_0x1f96('0x73')](config[_0x1f96('0x6d')],'server/files/images/avatars/',_0x25a405[_0x1f96('0x7d')]))){_0x567d92=path[_0x1f96('0x73')](config['root'],_0x1f96('0x77'),_0x25a405['systemAvatar']);}}return _0x1a0490[_0x1f96('0x75')](_0x567d92);}})['catch'](handleError(_0x1a0490,null));};exports[_0x1f96('0x7e')]=function(_0x42dec7,_0x2e5431){var _0x2ff9f2=require('user-agent-parser');var _0x60f86c=new _0x2ff9f2();var _0x2314ec=_0x60f86c[_0x1f96('0x7f')](_0x42dec7['headers'][_0x1f96('0x80')])[_0x1f96('0x81')]();var _0x25e5c6={'body':_0x42dec7[_0x1f96('0x51')],'channel':_0x1f96('0x82')};var _0x2aef4a=[];var _0x11ccf5=[];var _0x27ba4c={};var _0x46803f=![];return db[_0x1f96('0x83')][_0x1f96('0x59')]()['then'](function(_0xc49849){if(!_0xc49849){throw new db['Sequelize']['ValidationError'](_0x1f96('0x84'));}_0x2aef4a=_['difference'](_[_0x1f96('0x4e')](_0xc49849),[_0x1f96('0x85'),_0x1f96('0x86')]);_0x11ccf5=_[_0x1f96('0x87')](_[_0x1f96('0x4e')](_0xc49849),['createdAt',_0x1f96('0x86'),_0x1f96('0x88'),_0x1f96('0x89')]);if(_0x42dec7['body']['id']){delete _0x42dec7['body']['id'];}if(_[_0x1f96('0x71')](_0x42dec7['body'][_0x1f96('0x8a')])){throw new db[(_0x1f96('0x8b'))]['ValidationError']('from\x20is\x20mandatory');}if(_[_0x1f96('0x71')](_0x42dec7[_0x1f96('0x51')][_0x1f96('0x51')])||_0x42dec7['body'][_0x1f96('0x51')]===''){throw new db[(_0x1f96('0x8b'))]['ValidationError'](_0x1f96('0x8c'));}if(_[_0x1f96('0x71')](_0x42dec7[_0x1f96('0x51')][_0x1f96('0x8d')])){throw new db[(_0x1f96('0x8b'))]['ValidationError'](_0x1f96('0x8e')+_0x11ccf5);}if(!_['includes'](_0x11ccf5,_0x42dec7[_0x1f96('0x51')][_0x1f96('0x8d')])){throw new db[(_0x1f96('0x8b'))]['ValidationError'](_0x1f96('0x8f')+_0x11ccf5);}_0x27ba4c[_0x42dec7['body']['mapKey']]=_0x42dec7[_0x1f96('0x51')][_0x1f96('0x8a')];})[_0x1f96('0x28')](function(){return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x42dec7[_0x1f96('0x4d')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x1f96('0x83')],'as':_0x1f96('0x90'),'where':_0x27ba4c,'limit':0x1,'order':[['updatedAt',_0x1f96('0x91')]]}]},{'model':db[_0x1f96('0x92')],'as':'Applications'}]});})['then'](handleEntityNotFound(_0x2e5431,null))['then'](function(_0x281238){if(_0x281238&&_0x281238[_0x1f96('0x93')]){_0x25e5c6[_0x1f96('0x94')]=_0x281238;_0x25e5c6[_0x1f96('0x95')]=_0x281238['Applications'];_0x25e5c6[_0x1f96('0x96')]=_0x281238[_0x1f96('0x93')];_0x25e5c6[_0x1f96('0x95')]=_[_0x1f96('0x97')](_0x25e5c6[_0x1f96('0x95')],[_0x1f96('0x98')],[_0x1f96('0x99')]);if(_0x25e5c6[_0x1f96('0x94')]['Applications']){delete _0x25e5c6[_0x1f96('0x94')][_0x1f96('0x9a')];}if(_0x25e5c6['account']['List']&&_0x25e5c6[_0x1f96('0x94')][_0x1f96('0x93')][_0x1f96('0x90')][_0x1f96('0x3e')]){return _0x25e5c6[_0x1f96('0x94')][_0x1f96('0x93')][_0x1f96('0x90')][0x0];}var _0xc39909=_[_0x1f96('0xb')](_0x42dec7[_0x1f96('0x51')],{'firstName':_0x42dec7[_0x1f96('0x51')][_0x1f96('0x8a')],'ListId':_0x281238['ListId']});_0xc39909[_0x42dec7[_0x1f96('0x51')]['mapKey']]=_0x42dec7[_0x1f96('0x51')][_0x1f96('0x8a')];return db[_0x1f96('0x83')]['create'](_0xc39909,{'fields':_0x2aef4a,'raw':!![]});}})[_0x1f96('0x28')](handleEntityNotFound(_0x2e5431,null))[_0x1f96('0x28')](function(_0x535e51){_0x25e5c6['contact']=_0x535e51;var _0x32076c=_0x42dec7[_0x1f96('0x51')]['customerIp'];if(_0x42dec7[_0x1f96('0x9b')][_0x1f96('0x9c')]){_0x32076c=_0x42dec7[_0x1f96('0x9b')][_0x1f96('0x9c')];}else if(_0x42dec7[_0x1f96('0x9b')][_0x1f96('0x9d')]){_0x32076c=_['first'](_0x42dec7[_0x1f96('0x9b')]['x-forwarded-for']['split'](','));}if(_0x535e51){var _0x400514={'ContactId':_0x535e51['id'],'ChatWebsiteId':_0x42dec7[_0x1f96('0x4d')]['id'],'from':(_0x535e51['firstName']||'')+'\x20'+(_0x535e51['lastName']||''),'customerIp':_0x32076c,'customerPort':_0x42dec7[_0x1f96('0x9b')][_0x1f96('0x9e')]?_0x42dec7[_0x1f96('0x9b')][_0x1f96('0x9e')]:null,'referer':_0x42dec7['body'][_0x1f96('0x9f')],'browserName':_0x2314ec['browser']['name']&&_0x2314ec[_0x1f96('0xa0')]['version']?util[_0x1f96('0xa1')](_0x1f96('0xa2'),_0x2314ec[_0x1f96('0xa0')][_0x1f96('0x2e')],_0x2314ec['browser'][_0x1f96('0xa3')]):'unknown','browserVersion':_0x2314ec[_0x1f96('0xa0')]['version']||'unknown','osName':util['format'](_0x1f96('0xa2'),_0x2314ec['os'][_0x1f96('0x2e')],_0x2314ec['os'][_0x1f96('0xa3')]),'osVersion':_0x2314ec['os'][_0x1f96('0xa3')],'deviceModel':_0x2314ec[_0x1f96('0xa4')][_0x1f96('0x39')]&&_0x2314ec[_0x1f96('0xa4')][_0x1f96('0xa5')]?util['format'](_0x1f96('0xa6'),_0x2314ec[_0x1f96('0xa4')][_0x1f96('0x39')],_0x2314ec[_0x1f96('0xa4')][_0x1f96('0xa5')],_0x2314ec[_0x1f96('0xa4')][_0x1f96('0x37')]):null,'deviceVendor':_0x2314ec[_0x1f96('0xa4')][_0x1f96('0xa5')],'deviceType':_0x2314ec['device']['type'],'formData':JSON[_0x1f96('0x18')](_0x42dec7[_0x1f96('0x51')])};var _0x15735e={'ChatWebsiteId':_0x42dec7[_0x1f96('0x4d')]['id'],'closed':![]};if(_0x42dec7[_0x1f96('0x51')][_0x1f96('0xa7')]){_0x15735e[_0x1f96('0xa7')]=_0x42dec7['body'][_0x1f96('0xa7')];return db[_0x1f96('0xa8')]['find']({'where':_0x15735e})[_0x1f96('0x28')](function(_0x354acf){if(_0x354acf){return[_0x354acf,![]];}_0x400514[_0x1f96('0xa7')]=_0x42dec7[_0x1f96('0x51')][_0x1f96('0xa7')];_0x400514[_0x1f96('0xa9')]=_0x42dec7[_0x1f96('0x51')][_0x1f96('0xa9')];return db[_0x1f96('0xa8')][_0x1f96('0x50')](_0x400514)[_0x1f96('0x28')](function(_0x2345b2){return[_0x2345b2,!![]];});});}_0x15735e[_0x1f96('0xaa')]=_0x535e51['id'];if(_0x42dec7[_0x1f96('0x51')][_0x1f96('0xab')]&&_0x42dec7[_0x1f96('0x51')][_0x1f96('0xab')]['id']){_0x15735e['id']=_0x42dec7[_0x1f96('0x51')][_0x1f96('0xab')]['id'];return db[_0x1f96('0xa8')]['find']({'where':_0x15735e})[_0x1f96('0x28')](function(_0x392952){if(_0x392952){return[_0x392952,![]];}return db[_0x1f96('0xa8')]['create'](_0x400514)[_0x1f96('0x28')](function(_0x436d67){return[_0x436d67,!![]];});});}return db[_0x1f96('0xa8')][_0x1f96('0x50')](_0x400514)[_0x1f96('0x28')](function(_0x349f70){return[_0x349f70,!![]];});}})['spread'](function(_0x58af5b,_0x23da57){if(_0x58af5b){_0x46803f=_0x23da57;if(!_0x23da57){var _0x122ea6={'from':(_0x25e5c6[_0x1f96('0xac')][_0x1f96('0xad')]||'')+'\x20'+(_0x25e5c6[_0x1f96('0xac')]['lastName']||'')};if(_0x42dec7[_0x1f96('0x51')][_0x1f96('0xa7')]&&_0x42dec7[_0x1f96('0x51')][_0x1f96('0xae')]&&_0x42dec7['body'][_0x1f96('0xa7')]!=_0x42dec7['body'][_0x1f96('0xae')]){_0x122ea6[_0x1f96('0xa7')]=_0x42dec7[_0x1f96('0x51')][_0x1f96('0xae')];}return _0x58af5b['update'](_0x122ea6);}else{return _0x58af5b;}}})[_0x1f96('0x28')](function(_0x5e66e8){_0x25e5c6[_0x1f96('0xab')]=_0x5e66e8[_0x1f96('0x29')]({'plain':!![]});_0x25e5c6[_0x1f96('0xab')][_0x1f96('0xaf')]=_0x46803f;if(_0x25e5c6[_0x1f96('0xab')][_0x1f96('0xaf')]){if(_0x25e5c6[_0x1f96('0x94')][_0x1f96('0xb0')]){_0x25e5c6[_0x1f96('0x95')][_0x1f96('0xb1')]({'id':0x0,'priority':_0x25e5c6['applications']['length']+0x1,'app':_0x1f96('0xb2'),'appdata':_0x1f96('0xb3'),'interval':_0x1f96('0xb4')});}}return db[_0x1f96('0xb5')]['create']({'body':_0x42dec7[_0x1f96('0x51')][_0x1f96('0x51')],'ChatWebsiteId':_0x42dec7[_0x1f96('0x4d')]['id'],'ChatInteractionId':_0x5e66e8['id'],'direction':'in','ContactId':_0x25e5c6['contact']['id'],'AttachmentId':_0x42dec7[_0x1f96('0x51')][_0x1f96('0xb6')]});})[_0x1f96('0x28')](function(_0x41dddb){_0x25e5c6['message']=_0x41dddb;if(_0x25e5c6[_0x1f96('0xab')][_0x1f96('0xb7')]){return db[_0x1f96('0xb8')][_0x1f96('0x55')]({'attributes':['id','name'],'where':{'id':_0x25e5c6[_0x1f96('0xab')]['UserId']}})['then'](function(_0x20b79b){if(_0x20b79b){_0x25e5c6[_0x1f96('0x95')][_0x1f96('0xb9')]({'id':0x0,'priority':0x0,'app':_0x1f96('0xba'),'appdata':_0x20b79b[_0x1f96('0x2e')]+','+(_0x25e5c6[_0x1f96('0x94')][_0x1f96('0xbb')]||0xa),'interval':'*,*,*,*'});_0x25e5c6[_0x1f96('0xbc')]=!![];}return respondWithRpcPromise('Start',_0x1f96('0xbd'),_0x25e5c6);});}return respondWithRpcPromise(_0x1f96('0xbe'),'startRouting',_0x25e5c6);})[_0x1f96('0x28')](function(_0x33ee51){respondWithRpcPromise(_0x1f96('0xbf'),'EventManager',{'event':_0x1f96('0x7e'),'message':_0x33ee51},client9002);return _0x33ee51;})[_0x1f96('0x28')](respondWithResult(_0x2e5431,null))[_0x1f96('0x1d')](handleError(_0x2e5431,null));};exports[_0x1f96('0xc0')]=function(_0x54702d,_0x21fe70){var _0x28b7df,_0x3739a2,_0x230443;var _0x45e951=[];var _0xe24285={};var _0x46cb5a=_0x54702d['files']||[];var _0x3041ff=[];var _0x588a9d;return db[_0x1f96('0x83')][_0x1f96('0x59')]()[_0x1f96('0x28')](function(_0x386119){if(!_0x386119){throw new db[(_0x1f96('0x8b'))][(_0x1f96('0xc1'))](_0x1f96('0x84'));}_0x45e951=_[_0x1f96('0x87')](_[_0x1f96('0x4e')](_0x386119),[_0x1f96('0x85'),_0x1f96('0x86'),'CompanyId',_0x1f96('0x89')]);if(_0x54702d[_0x1f96('0x51')]['id']){delete _0x54702d[_0x1f96('0x51')]['id'];}if(_[_0x1f96('0x71')](_0x54702d['body']['from'])){throw _0x21fe70[_0x1f96('0x1f')](0x1f4)[_0x1f96('0x2f')](new db[(_0x1f96('0x8b'))][(_0x1f96('0xc1'))](_0x1f96('0xc2')));}if(_[_0x1f96('0x71')](_0x54702d[_0x1f96('0x51')][_0x1f96('0x51')])||_0x54702d[_0x1f96('0x51')][_0x1f96('0x51')]===''){throw _0x21fe70[_0x1f96('0x1f')](0x1f4)['send'](new db[(_0x1f96('0x8b'))][(_0x1f96('0xc1'))](_0x1f96('0x8c')));}if(_[_0x1f96('0x71')](_0x54702d[_0x1f96('0x51')][_0x1f96('0xc3')])){throw _0x21fe70[_0x1f96('0x1f')](0x1f4)[_0x1f96('0x2f')](new db[(_0x1f96('0x8b'))][(_0x1f96('0xc1'))]('mapKeyOffline\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x45e951));}if(!_[_0x1f96('0xc4')](_0x45e951,_0x54702d[_0x1f96('0x51')]['mapKeyOffline'])){throw _0x21fe70[_0x1f96('0x1f')](0x1f4)[_0x1f96('0x2f')](new db[(_0x1f96('0x8b'))]['ValidationError'](_0x1f96('0xc5')+_0x45e951));}_0xe24285[_0x54702d[_0x1f96('0x51')]['mapKeyOffline']]=_0x54702d[_0x1f96('0x51')][_0x1f96('0x8a')];})['then'](function(){return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x54702d[_0x1f96('0x4d')]['id']},'include':[{'model':db[_0x1f96('0xc6')],'as':_0x1f96('0x93')},{'model':db[_0x1f96('0xc7')],'as':'MailAccount'}]});})[_0x1f96('0x28')](handleEntityNotFound(_0x21fe70,null))[_0x1f96('0x28')](function(_0x575603){if(_0x575603&&_0x575603[_0x1f96('0x93')]){_0x3739a2=_0x575603;var _0x3413c9=_[_0x1f96('0xb')](_0x54702d[_0x1f96('0x51')],{'firstName':_0x54702d[_0x1f96('0x51')][_0x1f96('0x8a')],'phone':_0x54702d['body'][_0x1f96('0x8a')],'ListId':_0x575603[_0x1f96('0x89')]});_0x3413c9[_0x54702d['body'][_0x1f96('0xc3')]]=_0x54702d['body'][_0x1f96('0x8a')];return db[_0x1f96('0x83')]['findOrCreate']({'where':_0xe24285,'defaults':_0x3413c9});}})[_0x1f96('0xc8')](function(_0x431990){if(_0x431990){_0x230443=_0x431990;var _0x5e1989=fs[_0x1f96('0xc9')](path[_0x1f96('0x73')](config[_0x1f96('0x6d')],_0x1f96('0xca')),_0x1f96('0xcb'));var _0x466853=ejs['render'](_0x5e1989,{'body':_[_0x1f96('0xcc')](_0x54702d[_0x1f96('0x51')][_0x1f96('0x51')]),'bodyTitle':_0x3739a2[_0x1f96('0xcd')]});return db[_0x1f96('0xce')][_0x1f96('0x50')]({'body':_0x466853,'plainBody':htmlToText[_0x1f96('0xcf')](_0x466853),'ContactId':_0x431990['id'],'ChatWebsiteId':_0x3739a2['id']});}})[_0x1f96('0x28')](function(_0x311343){_0x588a9d=_0x311343;if(_0x46cb5a[_0x1f96('0x3e')]){var _0x321d73=_0x46cb5a[_0x1f96('0x33')](function(_0x4a0ac8){return{'name':_0x4a0ac8[_0x1f96('0xd0')],'basename':_0x4a0ac8[_0x1f96('0x69')],'type':_0x4a0ac8[_0x1f96('0xd1')],'ChatOfflineMessageId':_0x311343['id']};});_0x3041ff=_0x321d73[_0x1f96('0x33')](_0xc5a139=>{var _0x28ddf4={'filename':_0xc5a139[_0x1f96('0x2e')],'path':path[_0x1f96('0x73')](config[_0x1f96('0x6d')],_0x1f96('0xd2'),_0x1f96('0xd3'),_0x1f96('0xd4'),_0x1f96('0xd5'),_0xc5a139[_0x1f96('0xd6')])};return _0x28ddf4;});if(!_0x3739a2[_0x1f96('0xd7')]){return db['sequelize'][_0x1f96('0xd8')](function(_0x31abc7){return db[_0x1f96('0xd9')]['bulkCreate'](_0x321d73,{'transaction':_0x31abc7});});}}})['then'](function(){if(_0x588a9d){_0x28b7df=_0x588a9d;return db[_0x1f96('0xc7')][_0x1f96('0x5e')]({'where':{'active':!![]},'include':[{'model':db[_0x1f96('0xda')],'as':_0x1f96('0xdb'),'raw':!![]}]});}})[_0x1f96('0x28')](function(_0x18e1a4){if(_0x18e1a4&&_0x18e1a4['Smtp']&&_0x3739a2[_0x1f96('0xdc')]&&_0x3739a2[_0x1f96('0xdd')]){var _0x16ca39={'tls':{'rejectUnauthorized':![]}};if(_0x18e1a4[_0x1f96('0xdb')][_0x1f96('0xde')]){_0x16ca39['service']=_0x18e1a4[_0x1f96('0xdb')][_0x1f96('0xde')];}else{_0x16ca39[_0x1f96('0xdf')]=_0x18e1a4[_0x1f96('0xdb')][_0x1f96('0xdf')];_0x16ca39[_0x1f96('0xe0')]=_0x18e1a4['Smtp']['port'];_0x16ca39[_0x1f96('0xe1')]=_0x18e1a4[_0x1f96('0xdb')][_0x1f96('0xe1')];}if(_0x18e1a4[_0x1f96('0xdb')]['authentication']){_0x16ca39[_0x1f96('0xe2')]={'user':_0x18e1a4[_0x1f96('0xdb')][_0x1f96('0xe3')],'pass':_0x18e1a4[_0x1f96('0xdb')][_0x1f96('0xe4')]};}return respondWithRpcPromise(_0x1f96('0xe5'),_0x1f96('0xe6'),{'account':_0x16ca39,'message':{'from':util[_0x1f96('0xa1')](_0x1f96('0xe7'),_0x18e1a4[_0x1f96('0x2e')],_0x18e1a4[_0x1f96('0xe8')]||_0x18e1a4['Smtp'][_0x1f96('0xe3')]),'to':_0x3739a2[_0x1f96('0xdd')],'subject':_0x3739a2[_0x1f96('0xe9')],'html':_0x28b7df['body'],'attachments':_0x3041ff}},client9003)[_0x1f96('0x28')](function(){return _0x28b7df;})[_0x1f96('0x1d')](function(_0x698db9){console['error'](_0x698db9);});}})[_0x1f96('0x28')](function(){if(_0x3739a2&&_0x3739a2[_0x1f96('0xd7')]&&_0x3739a2[_0x1f96('0xea')]){var _0x54cb2a=[];if(_0x46cb5a[_0x1f96('0x3e')]){_0x54cb2a=_0x46cb5a[_0x1f96('0x33')](function(_0x5dae31){return{'name':_0x5dae31[_0x1f96('0xd0')],'basename':_0x5dae31[_0x1f96('0x69')],'type':_0x5dae31['mimetype'],'ChatOfflineMessageId':_0x588a9d['id']};});}var _0xfa8628;if(!_['isNil'](_0x3739a2[_0x1f96('0xeb')])){var _0xc9f192=_['map'](_0x54702d['body'],function(_0x2d2a07){return _0x2d2a07;});var _0x899cf7=_[_0x1f96('0xec')](_0xc9f192)[0x0];var _0x365d1c=_[_0x1f96('0xed')](_0x899cf7,function(_0x387a1a){return _0x387a1a;});_0xfa8628=_0x365d1c[0x1][_0x3739a2[_0x1f96('0xeb')]];}var _0x615651={'from':_0x230443[_0x1f96('0xe8')],'firstName':_0x230443[_0x1f96('0xad')],'lastName':_0x230443[_0x1f96('0xee')],'mapKey':'email','message':{'from':_0x230443['email'],'to':_0x3739a2[_0x1f96('0xc7')]['email'],'cc':'','subject':_['isNil'](_0xfa8628)?_0x3739a2[_0x1f96('0xe9')]:_0xfa8628,'messageId':'','sentAt':new Date(),'attach':_0x54cb2a['length'],'attachments':_0x54cb2a,'originChannel':'Chat','ChatWebsiteId':_0x3739a2['id'],'ChatOfflineMessageId':_0x28b7df['id'],'originTo':_0x3739a2['MailAccount'][_0x1f96('0xe8')]},'body':_0x28b7df['body']};var _0x4b188e={'account':{'id':_0x3739a2[_0x1f96('0xea')]},'body':_0x615651,'log':_0x1f96('0xef')};return respondWithRpcPromise(_0x1f96('0xef'),'notifyMail',_0x4b188e,client9001)[_0x1f96('0x28')](function(){return _0x28b7df;})[_0x1f96('0x1d')](function(_0x5ea908){console[_0x1f96('0x19')](_0x5ea908);});}return;})[_0x1f96('0x28')](function(){if(_0x28b7df){return _0x28b7df;}})['then'](respondWithResult(_0x21fe70,null))['catch'](function(_0x21d047){console['error'](_0x1f96('0x1d'),_0x21d047);for(var _0x50a1e3 of _0x46cb5a){var _0x1628f6=path[_0x1f96('0x73')](config['root'],_0x1f96('0xd2'),_0x1f96('0xd3'),_0x1f96('0xd4'),_0x1f96('0xd5'),_0x50a1e3['filename']);fs_extra[_0x1f96('0xf0')](_0x1628f6)[_0x1f96('0x1d')](function(_0x15ceec){console[_0x1f96('0x19')](_0x1f96('0xf1'),_0x1628f6,_0x15ceec);});}});};exports[_0x1f96('0xf2')]=function(_0x5b9aaf,_0x1f1116){return db[_0x1f96('0xa8')]['find']({'where':{'id':_0x5b9aaf[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x1f1116,null))[_0x1f96('0x28')](function(_0x303d76){if(_0x303d76){return _0x303d76[_0x1f96('0xf2')](_0x5b9aaf[_0x1f96('0x51')]['ids'],_[_0x1f96('0xf3')](_0x5b9aaf[_0x1f96('0x51')],['ids','id'])||{});}})[_0x1f96('0x28')](respondWithResult(_0x1f1116,null))['catch'](handleError(_0x1f1116,null));};exports[_0x1f96('0xf4')]=function(_0x5f3ccd,_0x2cfafd){var _0xb80d32={'raw':![],'where':{}};var _0x59abde={};var _0x4f673e={'count':0x0,'rows':[]};return db[_0x1f96('0x34')][_0x1f96('0x5e')]({'where':{'id':_0x5f3ccd['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x2cfafd,null))[_0x1f96('0x28')](function(_0x182ca7){if(_0x182ca7){_0x59abde[_0x1f96('0x39')]=_[_0x1f96('0x4e')](db[_0x1f96('0xa8')]['rawAttributes']);_0x59abde[_0x1f96('0x3a')]=_[_0x1f96('0x4e')](_0x5f3ccd['query']);_0x59abde[_0x1f96('0x3b')]=_[_0x1f96('0x4f')](_0x59abde[_0x1f96('0x39')],_0x59abde[_0x1f96('0x3a')]);_0xb80d32[_0x1f96('0x3c')]=_[_0x1f96('0x4f')](_0x59abde[_0x1f96('0x39')],qs[_0x1f96('0x3d')](_0x5f3ccd[_0x1f96('0x3a')]['fields']));_0xb80d32[_0x1f96('0x3c')]=_0xb80d32['attributes']['length']?_0xb80d32[_0x1f96('0x3c')]:_0x59abde[_0x1f96('0x39')];if(!_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0x5f')](_0x1f96('0x3f'))){_0xb80d32[_0x1f96('0x24')]=qs['limit'](_0x5f3ccd['query'][_0x1f96('0x24')]);_0xb80d32['offset']=qs[_0x1f96('0x23')](_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0x23')]);}_0xb80d32[_0x1f96('0x40')]=qs['sort'](_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0x41')]);_0xb80d32[_0x1f96('0x44')]=qs[_0x1f96('0x3b')](_['pick'](_0x5f3ccd['query'],_0x59abde[_0x1f96('0x3b')]));_0xb80d32[_0x1f96('0x44')][_0x1f96('0x5b')]=_0x182ca7['id'];if(_0x5f3ccd['query'][_0x1f96('0x43')]){_0xb80d32['where']=_['merge'](_0xb80d32[_0x1f96('0x44')],{'$or':_[_0x1f96('0x33')](_0xb80d32[_0x1f96('0x3c')],function(_0x3a2f29){var _0x5cd070={};_0x5cd070[_0x3a2f29]={'$like':'%'+_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0x43')]+'%'};return _0x5cd070;})});}_0xb80d32=_[_0x1f96('0x45')]({},_0xb80d32,_0x5f3ccd[_0x1f96('0x47')]);return db[_0x1f96('0xa8')][_0x1f96('0x22')]({'where':_0xb80d32[_0x1f96('0x44')]})['then'](function(_0x356eac){_0x4f673e[_0x1f96('0x22')]=_0x356eac;if(_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0x48')]){_0xb80d32[_0x1f96('0x49')]=[{'model':db[_0x1f96('0x83')],'as':_0x1f96('0xf5'),'required':![]},{'model':db[_0x1f96('0xb8')],'as':_0x1f96('0xf6'),'attributes':[_0x1f96('0x2e'),_0x1f96('0xf7'),_0x1f96('0xf8')],'required':![]},{'model':db[_0x1f96('0xf9')],'as':_0x1f96('0xfa'),'attributes':['id',_0x1f96('0x2e'),_0x1f96('0xfb')],'where':_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0xfc')]?{'id':_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0xfc')]}:undefined,'required':_0x5f3ccd[_0x1f96('0x3a')][_0x1f96('0xfc')]?!![]:![]}];}return db[_0x1f96('0xa8')][_0x1f96('0x4a')](_0xb80d32);})[_0x1f96('0x28')](function(_0x5c76a0){_0x4f673e['rows']=_0x5c76a0;return _0x4f673e;});}})[_0x1f96('0x28')](respondWithFilteredResult(_0x2cfafd,_0xb80d32))[_0x1f96('0x1d')](handleError(_0x2cfafd,null));};function iftimePromise(_0x43ba12,_0x5ecf73){return respondWithRpcPromise('Command','getSnippet',{'command':_0x5ecf73[_0x1f96('0xfd')]?util['format'](_0x1f96('0xfe'),_0x43ba12[_0x1f96('0xff')],_0x5ecf73[_0x1f96('0xfd')]):util[_0x1f96('0xa1')](_0x1f96('0x100'),_0x43ba12[_0x1f96('0xff')])},client9002)[_0x1f96('0x28')](function(_0x1501bc){var _0x5f5dda=_0x1501bc&&_0x1501bc['indexOf'](_0x1f96('0x101'))>=0x0?!![]:![];logger[_0x1f96('0x14')](_0x1f96('0x102'),_0x5ecf73['id'],_0x43ba12['id'],_0x43ba12['interval'],_0x5f5dda?_0x1f96('0x103'):'OFFLINE',_0x5ecf73['timezone']?_0x5ecf73[_0x1f96('0xfd')]:'No\x20timezone');return _0x5f5dda;})[_0x1f96('0x1d')](function(_0x4c7a7a){logger[_0x1f96('0x19')]('[%s][INTERVAL][%s]\x20%s\x20%s\x20(%s)',_0x5ecf73['id'],_0x43ba12['id'],_0x43ba12[_0x1f96('0xff')],util[_0x1f96('0x104')](_0x4c7a7a,{'showHidden':![],'depth':null}),_0x5ecf73[_0x1f96('0xfd')]?_0x5ecf73[_0x1f96('0xfd')]:_0x1f96('0x105'));return![];});}exports[_0x1f96('0x106')]=function(_0x13e1ec,_0x495947){var _0x144d88=0x0;var _0x5b1f69=0x0;var _0x36092b=![];var _0x115ff6;var _0x33fbb7;return db['ChatWebsite'][_0x1f96('0x55')]({'where':{'id':_0x13e1ec[_0x1f96('0x4d')]['id']},'include':[{'model':db[_0x1f96('0x107')],'as':_0x1f96('0x107'),'include':[{'model':db['Interval'],'as':_0x1f96('0x108'),'attributes':['id',_0x1f96('0xff')],'raw':!![]}]}]})[_0x1f96('0x28')](handleEntityNotFound(_0x495947,null))[_0x1f96('0x28')](function(_0x3f4683){if(_0x3f4683){_0x115ff6=_0x3f4683;return _0x3f4683[_0x1f96('0x109')]({'raw':!![]});}})[_0x1f96('0x28')](function(_0x5395fb){if(_0x115ff6){if(_0x5395fb){_0x33fbb7=_0x5395fb;}}return require(_0x1f96('0x6f'))['getLicense']();})[_0x1f96('0x28')](function(_0x33a340){if(_0x33a340){_0x5b1f69=_0x33a340[_0x1f96('0x10a')];_0x36092b=_0x33a340[_0x1f96('0x10b')];}})[_0x1f96('0x28')](function(){return db[_0x1f96('0xa8')][_0x1f96('0x22')]({'where':{'closed':![]}});})[_0x1f96('0x28')](function(_0x4d5bc1){_0x144d88=_0x4d5bc1;if(_0x5b1f69&&_0x4d5bc1>_0x5b1f69){return db['License'][_0x1f96('0x5e')]({'where':{'id':0x1}})['then'](function(_0x52fb8b){if(_0x52fb8b){_0x52fb8b[_0x1f96('0x10c')]('chatLicenseExceeded');}});}})[_0x1f96('0x28')](function(){if(_0x115ff6[_0x1f96('0x107')]&&_0x115ff6['Interval'][_0x1f96('0x108')]){var _0x356ac1=[];for(var _0x4c2bb2=0x0;_0x4c2bb2<_0x115ff6['Interval'][_0x1f96('0x108')]['length'];_0x4c2bb2++){var _0x5ee83a=_0x115ff6['Interval'][_0x1f96('0x108')][_0x4c2bb2][_0x1f96('0x29')]({'plain':!![]});_0x356ac1[_0x1f96('0xb1')](iftimePromise(_0x5ee83a,_0x115ff6));}return BPromise[_0x1f96('0x10d')](_0x356ac1)['then'](function(_0x1df701){return _['some'](_0x1df701);});}else{return!![];}})[_0x1f96('0x28')](function(_0x46af96){var _0x483ecf=fs[_0x1f96('0xc9')](path['join'](config[_0x1f96('0x6d')],'server/files/chat/iframe.ejs'),'utf8');var _0x2c3777={'remote':_0x115ff6[_0x1f96('0x10e')],'query':querystring[_0x1f96('0x18')](_[_0x1f96('0x45')](_0x115ff6[_0x1f96('0x29')]({'plain':!![]}),{'customerIp':_0x13e1ec[_0x1f96('0x9b')][_0x1f96('0x9d')]||_0x13e1ec['headers'][_0x1f96('0x10f')]||_0x13e1ec[_0x1f96('0x110')]['remoteAddress']||_0x13e1ec['ip'],'referer':_0x13e1ec[_0x1f96('0x9b')][_0x1f96('0x9f')],'openedInteractions':_0x144d88,'maxInteractions':_0x5b1f69,'virtual':_0x36092b[_0x1f96('0x10a')],'online':_0x46af96,'custom':_0x36092b}))[_0x1f96('0x111')](/'/g,'\x5c\x27')};_0x495947[_0x1f96('0x2f')](ejs[_0x1f96('0x112')](Mustache[_0x1f96('0x112')](_0x483ecf,_0x2c3777),{'proactiveActions':_0x33fbb7,'alignment':_0x115ff6['alignment'],'verticalAlignment':_0x115ff6[_0x1f96('0x113')],'div_color':_0x115ff6[_0x1f96('0xfb')],'labelText':_0x115ff6[_0x1f96('0x114')],'text_color':_0x115ff6[_0x1f96('0x115')],'button_color':_0x115ff6[_0x1f96('0x116')],'background_color':_0x115ff6[_0x1f96('0x117')],'hideWhenOffline':_0x115ff6[_0x1f96('0x118')],'interval':_0x115ff6[_0x1f96('0x119')]}));})[_0x1f96('0x1d')](handleError(_0x495947,null));};exports['addApplications']=function(_0x17fc56,_0x32defc){var _0x18673a=_0x17fc56[_0x1f96('0x4d')]['id'];var _0x5c434a=_0x17fc56['body'];var _0x5a1c85=0xc8;var _0x4a453b=null;return db[_0x1f96('0x11a')][_0x1f96('0xd8')]({'isolationLevel':db[_0x1f96('0x11a')][_0x1f96('0x11b')][_0x1f96('0x11c')]['READ_COMMITTED']},function(_0x5d0efb){return db[_0x1f96('0x34')][_0x1f96('0x5e')]({'where':{'id':_0x18673a},'transaction':_0x5d0efb})[_0x1f96('0x28')](function(_0x77a3d6){if(_0x77a3d6){return db[_0x1f96('0x92')][_0x1f96('0x2c')]({'where':{'ChatWebsiteId':_0x18673a},'transaction':_0x5d0efb})[_0x1f96('0x28')](function(){var _0xfc2155=_[_0x1f96('0x33')](_0x5c434a,function(_0x2251af){_0x2251af[_0x1f96('0x5b')]=_0x18673a;return _0x2251af;});return db[_0x1f96('0x92')][_0x1f96('0x11d')](_0xfc2155,{'transaction':_0x5d0efb});});}else{_0x5a1c85=0x194;_0x4a453b=[];}});})[_0x1f96('0x28')](function(){if(_0x5a1c85!==0x194){return db['ChatApplication'][_0x1f96('0x11e')]({'where':{'ChatWebsiteId':_0x18673a},'order':'priority'})['then'](function(_0x5c68f7){_0x4a453b=_0x5c68f7;});}})[_0x1f96('0x1d')](function(_0x51c8da){_0x5a1c85=0x1f4;logger[_0x1f96('0x19')](_0x51c8da['stack']);if(_0x51c8da[_0x1f96('0x2e')]){delete _0x51c8da[_0x1f96('0x2e')];}_0x4a453b=_0x51c8da;})[_0x1f96('0x11f')](function(){if(_0x4a453b===null){_0x32defc[_0x1f96('0x1e')](_0x5a1c85);}else{if(_0x5a1c85===0x1f4){_0x32defc[_0x1f96('0x1f')](_0x5a1c85)[_0x1f96('0x2f')](_0x4a453b);}else{_0x32defc[_0x1f96('0x1f')](_0x5a1c85)[_0x1f96('0x21')](_0x4a453b);}}});};exports[_0x1f96('0x120')]=function(_0x37f7db,_0x478588){var _0x86cd9d={};var _0x1b3ff8={};var _0xc4d71;var _0x4a3c55;return db[_0x1f96('0x34')]['findOne']({'where':{'id':_0x37f7db[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x478588,null))[_0x1f96('0x28')](function(_0x30f85b){if(_0x30f85b){_0xc4d71=_0x30f85b;_0x1b3ff8[_0x1f96('0x39')]=_['keys'](db['ChatApplication']['rawAttributes']);_0x1b3ff8[_0x1f96('0x3a')]=_['keys'](_0x37f7db[_0x1f96('0x3a')]);_0x1b3ff8['filters']=_[_0x1f96('0x4f')](_0x1b3ff8[_0x1f96('0x39')],_0x1b3ff8['query']);_0x86cd9d[_0x1f96('0x3c')]=_[_0x1f96('0x4f')](_0x1b3ff8[_0x1f96('0x39')],qs[_0x1f96('0x3d')](_0x37f7db['query'][_0x1f96('0x3d')]));_0x86cd9d[_0x1f96('0x3c')]=_0x86cd9d[_0x1f96('0x3c')][_0x1f96('0x3e')]?_0x86cd9d[_0x1f96('0x3c')]:_0x1b3ff8[_0x1f96('0x39')];_0x86cd9d[_0x1f96('0x40')]=qs[_0x1f96('0x41')](_0x37f7db[_0x1f96('0x3a')][_0x1f96('0x41')]);_0x86cd9d[_0x1f96('0x44')]=qs[_0x1f96('0x3b')](_[_0x1f96('0x42')](_0x37f7db['query'],_0x1b3ff8[_0x1f96('0x3b')]));if(_0x37f7db[_0x1f96('0x3a')][_0x1f96('0x43')]){_0x86cd9d['where']=_[_0x1f96('0x45')](_0x86cd9d[_0x1f96('0x44')],{'$or':_[_0x1f96('0x33')](_0x86cd9d[_0x1f96('0x3c')],function(_0x4bfa42){var _0x5e9899={};_0x5e9899[_0x4bfa42]={'$like':'%'+_0x37f7db[_0x1f96('0x3a')][_0x1f96('0x43')]+'%'};return _0x5e9899;})});}_0x86cd9d=_[_0x1f96('0x45')]({},_0x86cd9d,_0x37f7db['options']);return _0xc4d71['getApplications'](_0x86cd9d);}})[_0x1f96('0x28')](function(_0x39d45e){if(_0x39d45e){_0x4a3c55=_0x39d45e[_0x1f96('0x3e')];if(!_0x37f7db[_0x1f96('0x3a')][_0x1f96('0x5f')](_0x1f96('0x3f'))){_0x86cd9d[_0x1f96('0x24')]=qs[_0x1f96('0x24')](_0x37f7db[_0x1f96('0x3a')][_0x1f96('0x24')]);_0x86cd9d[_0x1f96('0x23')]=qs[_0x1f96('0x23')](_0x37f7db[_0x1f96('0x3a')]['offset']);}return _0xc4d71[_0x1f96('0x120')](_0x86cd9d);}})[_0x1f96('0x28')](function(_0x172aaf){if(_0x172aaf){return _0x172aaf?{'count':_0x4a3c55,'rows':_0x172aaf}:null;}})[_0x1f96('0x28')](respondWithResult(_0x478588,null))[_0x1f96('0x1d')](handleError(_0x478588,null));};exports[_0x1f96('0x121')]=function(_0x1f6bf8,_0x319e46){return db[_0x1f96('0x122')][_0x1f96('0x55')]({'where':{'id':_0x1f6bf8[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x319e46,null))[_0x1f96('0x28')](function(_0x3f1ce4){if(_0x3f1ce4){return _0x3f1ce4['addProactiveActions'](_0x1f6bf8['body']['ids'],_[_0x1f96('0xf3')](_0x1f6bf8[_0x1f96('0x51')],[_0x1f96('0x61'),'id'])||{});}})[_0x1f96('0x28')](respondWithResult(_0x319e46,null))['catch'](handleError(_0x319e46,null));};exports['getProactiveActions']=function(_0x33173f,_0x809213){var _0x26a63d={};var _0x40d1ce={};var _0x1d7c8b;var _0x42a79f;return db[_0x1f96('0x34')][_0x1f96('0x5e')]({'where':{'id':_0x33173f['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x809213,null))[_0x1f96('0x28')](function(_0x3c71e1){if(_0x3c71e1){_0x1d7c8b=_0x3c71e1;_0x40d1ce['model']=_[_0x1f96('0x4e')](db[_0x1f96('0x123')][_0x1f96('0x35')]);_0x40d1ce[_0x1f96('0x3a')]=_[_0x1f96('0x4e')](_0x33173f['query']);_0x40d1ce[_0x1f96('0x3b')]=_[_0x1f96('0x4f')](_0x40d1ce[_0x1f96('0x39')],_0x40d1ce[_0x1f96('0x3a')]);_0x26a63d[_0x1f96('0x3c')]=_[_0x1f96('0x4f')](_0x40d1ce[_0x1f96('0x39')],qs[_0x1f96('0x3d')](_0x33173f[_0x1f96('0x3a')][_0x1f96('0x3d')]));_0x26a63d[_0x1f96('0x3c')]=_0x26a63d[_0x1f96('0x3c')]['length']?_0x26a63d[_0x1f96('0x3c')]:_0x40d1ce[_0x1f96('0x39')];_0x26a63d[_0x1f96('0x40')]=qs['sort'](_0x33173f[_0x1f96('0x3a')]['sort']);_0x26a63d[_0x1f96('0x44')]=qs[_0x1f96('0x3b')](_[_0x1f96('0x42')](_0x33173f[_0x1f96('0x3a')],_0x40d1ce[_0x1f96('0x3b')]));if(_0x33173f[_0x1f96('0x3a')]['filter']){_0x26a63d[_0x1f96('0x44')]=_[_0x1f96('0x45')](_0x26a63d['where'],{'$or':_[_0x1f96('0x33')](_0x26a63d[_0x1f96('0x3c')],function(_0x493b66){var _0x2a0313={};_0x2a0313[_0x493b66]={'$like':'%'+_0x33173f[_0x1f96('0x3a')][_0x1f96('0x43')]+'%'};return _0x2a0313;})});}_0x26a63d=_[_0x1f96('0x45')]({},_0x26a63d,_0x33173f['options']);return _0x1d7c8b[_0x1f96('0x109')](_0x26a63d);}})[_0x1f96('0x28')](function(_0x5139ae){if(_0x5139ae){_0x42a79f=_0x5139ae[_0x1f96('0x3e')];if(!_0x33173f[_0x1f96('0x3a')]['hasOwnProperty'](_0x1f96('0x3f'))){_0x26a63d['limit']=qs['limit'](_0x33173f[_0x1f96('0x3a')]['limit']);_0x26a63d[_0x1f96('0x23')]=qs[_0x1f96('0x23')](_0x33173f['query'][_0x1f96('0x23')]);}return _0x1d7c8b[_0x1f96('0x109')](_0x26a63d);}})[_0x1f96('0x28')](function(_0x121ea2){if(_0x121ea2){return _0x121ea2?{'count':_0x42a79f,'rows':_0x121ea2}:null;}})[_0x1f96('0x28')](respondWithResult(_0x809213,null))[_0x1f96('0x1d')](handleError(_0x809213,null));};exports[_0x1f96('0x124')]=function(_0x2f920f,_0x58a839){var _0x5069c4=_0x2f920f[_0x1f96('0x3a')][_0x1f96('0x125')]===_0x1f96('0x126')?_0x1f96('0x127'):_0x1f96('0x128');return db['ChatWebsite']['find']({'attributes':['id',_0x5069c4],'where':{'id':_0x2f920f[_0x1f96('0x4d')]['id']}})['then'](handleEntityNotFound(_0x58a839,null))['then'](function(_0x4cd365){if(_0x4cd365){var _0x2e1a3c=_0x4cd365[_0x5069c4];var _0x5b531b=_0x2e1a3c&&_0x2e1a3c[_0x1f96('0x129')]?_0x2e1a3c[_0x1f96('0x129')]:[];_0x58a839[_0x1f96('0x2f')]({'fromKey':_['isNil'](_0x2e1a3c['fromKey'])?undefined:_0x2e1a3c[_0x1f96('0x12a')],'count':_0x5b531b[_0x1f96('0x3e')],'rows':_0x5b531b});}})[_0x1f96('0x1d')](handleError(_0x58a839,null));};exports[_0x1f96('0x12b')]=function(_0x229483,_0x3ef4bf){var _0x561b60={'raw':![],'where':{}};var _0x792602={};var _0x46b4f5={'count':0x0,'rows':[]};return db[_0x1f96('0x34')][_0x1f96('0x5e')]({'where':{'id':_0x229483['params']['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x3ef4bf,null))[_0x1f96('0x28')](function(_0x2330df){if(_0x2330df){_0x792602['model']=_[_0x1f96('0x4e')](db[_0x1f96('0xce')][_0x1f96('0x35')]);_0x792602[_0x1f96('0x3a')]=_['keys'](_0x229483[_0x1f96('0x3a')]);_0x792602[_0x1f96('0x3b')]=_['intersection'](_0x792602[_0x1f96('0x39')],_0x792602[_0x1f96('0x3a')]);_0x561b60[_0x1f96('0x3c')]=_[_0x1f96('0x4f')](_0x792602['model'],qs['fields'](_0x229483[_0x1f96('0x3a')]['fields']));_0x561b60['attributes']=_0x561b60['attributes'][_0x1f96('0x3e')]?_0x561b60[_0x1f96('0x3c')]:_0x792602['model'];if(!_0x229483[_0x1f96('0x3a')]['hasOwnProperty']('nolimit')){_0x561b60[_0x1f96('0x24')]=qs[_0x1f96('0x24')](_0x229483[_0x1f96('0x3a')][_0x1f96('0x24')]);_0x561b60['offset']=qs[_0x1f96('0x23')](_0x229483[_0x1f96('0x3a')][_0x1f96('0x23')]);}_0x561b60['order']=qs[_0x1f96('0x41')](_0x229483['query'][_0x1f96('0x41')]);_0x561b60['where']=qs[_0x1f96('0x3b')](_[_0x1f96('0x42')](_0x229483[_0x1f96('0x3a')],_0x792602[_0x1f96('0x3b')]));_0x561b60['where'][_0x1f96('0x5b')]=_0x2330df['id'];if(_0x229483[_0x1f96('0x3a')][_0x1f96('0x43')]){_0x561b60[_0x1f96('0x44')]=_[_0x1f96('0x45')](_0x561b60['where'],{'$or':_['map'](_0x561b60[_0x1f96('0x3c')],function(_0xc6f252){var _0x151d47={};_0x151d47[_0xc6f252]={'$like':'%'+_0x229483[_0x1f96('0x3a')]['filter']+'%'};return _0x151d47;})});}_0x561b60=_['merge']({},_0x561b60,_0x229483[_0x1f96('0x47')]);return db['ChatOfflineMessage']['count']({'where':_0x561b60['where']})[_0x1f96('0x28')](function(_0x1eac7f){_0x46b4f5[_0x1f96('0x22')]=_0x1eac7f;if(_0x229483['query'][_0x1f96('0x48')]){_0x561b60[_0x1f96('0x49')]=[{'all':!![]}];}else{_0x561b60[_0x1f96('0x49')]=[{'model':db[_0x1f96('0x83')],'as':'Contact','required':![]},{'model':db[_0x1f96('0xd9')],'as':_0x1f96('0x12c'),'required':![]}];}return db[_0x1f96('0xce')]['findAll'](_0x561b60);})[_0x1f96('0x28')](function(_0x2720b3){_0x46b4f5[_0x1f96('0x4b')]=_0x2720b3;return _0x46b4f5;});}})[_0x1f96('0x28')](respondWithFilteredResult(_0x3ef4bf,_0x561b60))[_0x1f96('0x1d')](handleError(_0x3ef4bf,null));};exports[_0x1f96('0x12d')]=function(_0x23514c,_0x408848){return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x23514c[_0x1f96('0x4d')]['id']}})['then'](handleEntityNotFound(_0x408848,null))[_0x1f96('0x28')](function(_0x11098e){if(_0x11098e){return _0x11098e['addAgents'](_0x23514c['body']['ids'],_[_0x1f96('0xf3')](_0x23514c[_0x1f96('0x51')],[_0x1f96('0x61'),'id'])||{})[_0x1f96('0xc8')](function(_0x84e048){for(var _0x3fc11c=0x0;_0x3fc11c<_0x23514c['body'][_0x1f96('0x61')][_0x1f96('0x3e')];_0x3fc11c+=0x1){socket['emit'](_0x1f96('0x12e'),{'UserId':Number(_0x23514c[_0x1f96('0x51')][_0x1f96('0x61')][_0x3fc11c]),'ChatWebsiteId':Number(_0x23514c['params']['id'])});}return _0x84e048;});}})[_0x1f96('0x28')](respondWithResult(_0x408848,null))[_0x1f96('0x1d')](handleError(_0x408848,null));};exports[_0x1f96('0x12f')]=function(_0x3f5c38,_0x40f5b4){return db[_0x1f96('0x34')][_0x1f96('0x55')]({'where':{'id':_0x3f5c38[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x40f5b4,null))[_0x1f96('0x28')](function(_0x1e1091){if(_0x1e1091){return _0x1e1091[_0x1f96('0x12f')](_0x3f5c38[_0x1f96('0x3a')][_0x1f96('0x61')])[_0x1f96('0x28')](function(){if(_['isArray'](_0x3f5c38[_0x1f96('0x3a')][_0x1f96('0x61')])){for(var _0x2f7c8d=0x0;_0x2f7c8d<_0x3f5c38[_0x1f96('0x3a')][_0x1f96('0x61')][_0x1f96('0x3e')];_0x2f7c8d+=0x1){socket[_0x1f96('0x130')](_0x1f96('0x131'),{'UserId':Number(_0x3f5c38['query']['ids'][_0x2f7c8d]),'ChatWebsiteId':Number(_0x3f5c38[_0x1f96('0x4d')]['id'])});}}else{socket[_0x1f96('0x130')](_0x1f96('0x131'),{'UserId':Number(_0x3f5c38[_0x1f96('0x3a')][_0x1f96('0x61')]),'ChatWebsiteId':Number(_0x3f5c38[_0x1f96('0x4d')]['id'])});}});}})[_0x1f96('0x28')](respondWithStatusCode(_0x40f5b4,null))[_0x1f96('0x1d')](handleError(_0x40f5b4,null));};exports[_0x1f96('0x132')]=function(_0x4b09ef,_0x25cc48){var _0x1090f2={};var _0x5ae6bf={};var _0x300e77;var _0x249ca2;return db['ChatWebsite'][_0x1f96('0x5e')]({'where':{'id':_0x4b09ef[_0x1f96('0x4d')]['id']}})[_0x1f96('0x28')](handleEntityNotFound(_0x25cc48,null))['then'](function(_0x5d4ebb){if(_0x5d4ebb){_0x300e77=_0x5d4ebb;_0x5ae6bf[_0x1f96('0x39')]=_[_0x1f96('0x4e')](db[_0x1f96('0xb8')][_0x1f96('0x35')]);_0x5ae6bf['query']=_[_0x1f96('0x4e')](_0x4b09ef['query']);_0x5ae6bf[_0x1f96('0x3b')]=_['intersection'](_0x5ae6bf['model'],_0x5ae6bf['query']);_0x1090f2['attributes']=_[_0x1f96('0x4f')](_0x5ae6bf[_0x1f96('0x39')],qs[_0x1f96('0x3d')](_0x4b09ef[_0x1f96('0x3a')]['fields']));_0x1090f2[_0x1f96('0x3c')]=_0x1090f2[_0x1f96('0x3c')][_0x1f96('0x3e')]?_0x1090f2[_0x1f96('0x3c')]:_0x5ae6bf[_0x1f96('0x39')];_0x1090f2['order']=qs['sort'](_0x4b09ef[_0x1f96('0x3a')]['sort']);_0x1090f2[_0x1f96('0x44')]=qs[_0x1f96('0x3b')](_['pick'](_0x4b09ef[_0x1f96('0x3a')],_0x5ae6bf[_0x1f96('0x3b')]));if(_0x4b09ef[_0x1f96('0x3a')][_0x1f96('0x43')]){_0x1090f2[_0x1f96('0x44')]=_['merge'](_0x1090f2[_0x1f96('0x44')],{'$or':_[_0x1f96('0x33')](_0x1090f2[_0x1f96('0x3c')],function(_0xa9044b){var _0x3833da={};_0x3833da[_0xa9044b]={'$like':'%'+_0x4b09ef[_0x1f96('0x3a')][_0x1f96('0x43')]+'%'};return _0x3833da;})});}_0x1090f2=_[_0x1f96('0x45')]({},_0x1090f2,_0x4b09ef['options']);return _0x300e77[_0x1f96('0x132')](_0x1090f2);}})[_0x1f96('0x28')](function(_0x211244){if(_0x211244){_0x249ca2=_0x211244['length'];if(!_0x4b09ef[_0x1f96('0x3a')][_0x1f96('0x5f')](_0x1f96('0x3f'))){_0x1090f2[_0x1f96('0x24')]=qs[_0x1f96('0x24')](_0x4b09ef[_0x1f96('0x3a')]['limit']);_0x1090f2[_0x1f96('0x23')]=qs['offset'](_0x4b09ef[_0x1f96('0x3a')][_0x1f96('0x23')]);}return _0x300e77[_0x1f96('0x132')](_0x1090f2);}})[_0x1f96('0x28')](function(_0x301bd7){if(_0x301bd7){return _0x301bd7?{'count':_0x249ca2,'rows':_0x301bd7}:null;}})['then'](respondWithResult(_0x25cc48,null))[_0x1f96('0x1d')](handleError(_0x25cc48,null));};