Built motion from commit 497d3d92.|2.5.43
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index cf40014..7b894b9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xba08=['filters','pick','filter','where','merge','map','options','OpenchannelAccount','includeAll','include','findAll','rows','show','params','Pause','mandatoryDispositionPause','keys','intersection','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','addDisposition','OpenchannelAccountId','getDispositions','findOne','Disposition','hasOwnProperty','order','removeDispositions','CannedAnswer','removeAnswers','notify','openchannel','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','from\x20is\x20mandatory','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','List','CmContact','Contacts','DESC','OpenchannelApplication','Applications','applications','orderBy','priority','asc','account','ListId','contact','threadId','OpenchannelInteraction','externalUrl','spread','firstName','messageId','interaction','created','unmanaged','OpenchannelMessage','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','bulkCreate','findAndCountAll','sendStatus','getApplications','getInteractions','Owner','Tag','Tags','tag','addAgents','ids','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','out','Messages','dataValues','push','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','lodash','crypto','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','client','http','request','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','status','json','offset','limit','undefined','count','set','Content-Range','apply','save','then','destroy','get','OpenchannelAccounts','UserProfileResource','stack','name','send','index','rawAttributes','type','query','model','fields','attributes','length','nolimit','sort'];(function(_0x32f3b2,_0x15a711){var _0x2afa24=function(_0x3ac9c1){while(--_0x3ac9c1){_0x32f3b2['push'](_0x32f3b2['shift']());}};_0x2afa24(++_0x15a711);}(_0xba08,0x72));var _0x8ba0=function(_0x5e51c3,_0x405bde){_0x5e51c3=_0x5e51c3-0x0;var _0x36ecd7=_0xba08[_0x5e51c3];return _0x36ecd7;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8ba0('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8ba0('0x1'));var rp=require(_0x8ba0('0x2'));var moment=require('moment');var BPromise=require(_0x8ba0('0x3'));var Mustache=require(_0x8ba0('0x4'));var util=require(_0x8ba0('0x5'));var path=require(_0x8ba0('0x6'));var sox=require(_0x8ba0('0x7'));var csv=require('to-csv');var ejs=require(_0x8ba0('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8ba0('0x9'));var squel=require('squel');var crypto=require(_0x8ba0('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x8ba0('0xb'));var querystring=require(_0x8ba0('0xc'));var Papa=require(_0x8ba0('0xd'));var Redis=require(_0x8ba0('0xe'));var authService=require(_0x8ba0('0xf'));var qs=require(_0x8ba0('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x8ba0('0x11'))(_0x8ba0('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x8ba0('0x13')]=_[_0x8ba0('0x14')](config[_0x8ba0('0x13')],{'host':_0x8ba0('0x15'),'port':0x18eb});var socket=require(_0x8ba0('0x16'))(new Redis(config[_0x8ba0('0x13')]));require(_0x8ba0('0x17'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x8ba0('0x18')][_0x8ba0('0x19')]({'port':0x232c});var client9002=jayson[_0x8ba0('0x18')][_0x8ba0('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x8777dd,_0x4f5a13,_0x574113,_0x4fa8c6){return new BPromise(function(_0x40fd74,_0x178e40){var _0x2873de=_0x4fa8c6||client;return _0x2873de[_0x8ba0('0x1a')](_0x8777dd,_0x574113)['then'](function(_0x1ab4ac){logger[_0x8ba0('0x1b')](_0x8ba0('0x1c'),_0x4f5a13,_0x8ba0('0x1d'));logger[_0x8ba0('0x1e')](_0x8ba0('0x1f'),_0x4f5a13,_0x8ba0('0x1d'),JSON[_0x8ba0('0x20')](_0x1ab4ac));if(_0x1ab4ac[_0x8ba0('0x21')]){if(_0x1ab4ac[_0x8ba0('0x21')]['code']===0x1f4){logger[_0x8ba0('0x21')](_0x8ba0('0x1c'),_0x4f5a13,_0x1ab4ac[_0x8ba0('0x21')][_0x8ba0('0x22')]);return _0x178e40(_0x1ab4ac[_0x8ba0('0x21')][_0x8ba0('0x22')]);}logger[_0x8ba0('0x21')](_0x8ba0('0x1c'),_0x4f5a13,_0x1ab4ac['error'][_0x8ba0('0x22')]);return _0x40fd74(_0x1ab4ac['error'][_0x8ba0('0x22')]);}else{logger[_0x8ba0('0x1b')](_0x8ba0('0x1c'),_0x4f5a13,'request\x20sent');_0x40fd74(_0x1ab4ac[_0x8ba0('0x23')][_0x8ba0('0x22')]);}})[_0x8ba0('0x24')](function(_0x36d5d5){logger['error'](_0x8ba0('0x1c'),_0x4f5a13,_0x36d5d5);_0x178e40(_0x36d5d5);});});}function respondWithStatusCode(_0x24e527,_0x19d938){_0x19d938=_0x19d938||0xcc;return function(_0x46c3ab){if(_0x46c3ab){return _0x24e527['sendStatus'](_0x19d938);}return _0x24e527[_0x8ba0('0x25')](_0x19d938)['end']();};}function respondWithResult(_0x4449cf,_0x216caf){_0x216caf=_0x216caf||0xc8;return function(_0x50326d){if(_0x50326d){return _0x4449cf[_0x8ba0('0x25')](_0x216caf)[_0x8ba0('0x26')](_0x50326d);}};}function respondWithFilteredResult(_0x31c6f9,_0x326cf6){return function(_0x2cfc17){if(_0x2cfc17){var _0x44bfe5=typeof _0x326cf6[_0x8ba0('0x27')]==='undefined'&&typeof _0x326cf6[_0x8ba0('0x28')]===_0x8ba0('0x29');var _0x3301d6=_0x2cfc17[_0x8ba0('0x2a')];var _0x1e5321=_0x44bfe5?0x0:_0x326cf6['offset'];var _0x3119ce=_0x44bfe5?_0x2cfc17[_0x8ba0('0x2a')]:_0x326cf6[_0x8ba0('0x27')]+_0x326cf6['limit'];var _0x45d44f;if(_0x3119ce>=_0x3301d6){_0x3119ce=_0x3301d6;_0x45d44f=0xc8;}else{_0x45d44f=0xce;}_0x31c6f9[_0x8ba0('0x25')](_0x45d44f);return _0x31c6f9[_0x8ba0('0x2b')](_0x8ba0('0x2c'),_0x1e5321+'-'+_0x3119ce+'/'+_0x3301d6)[_0x8ba0('0x26')](_0x2cfc17);}return null;};}function patchUpdates(_0x1a98ae){return function(_0x667c55){try{jsonpatch[_0x8ba0('0x2d')](_0x667c55,_0x1a98ae,!![]);}catch(_0x5375d7){return BPromise['reject'](_0x5375d7);}return _0x667c55[_0x8ba0('0x2e')]();};}function saveUpdates(_0x62d34e,_0x4d2d49){return function(_0x1a3b17){if(_0x1a3b17){return _0x1a3b17['update'](_0x62d34e)[_0x8ba0('0x2f')](function(_0xc4411){return _0xc4411;});}return null;};}function removeEntity(_0x36a9f7,_0x56fc8c){return function(_0x4b4bb4){if(_0x4b4bb4){return _0x4b4bb4[_0x8ba0('0x30')]()[_0x8ba0('0x2f')](function(){var _0x3d9c8f=_0x4b4bb4[_0x8ba0('0x31')]({'plain':!![]});var _0x137209=_0x8ba0('0x32');return db[_0x8ba0('0x33')][_0x8ba0('0x30')]({'where':{'type':_0x137209,'resourceId':_0x3d9c8f['id']}})[_0x8ba0('0x2f')](function(){return _0x4b4bb4;});})[_0x8ba0('0x2f')](function(){_0x36a9f7[_0x8ba0('0x25')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1f347a,_0x265e9f){return function(_0x525d7e){if(!_0x525d7e){_0x1f347a['sendStatus'](0x194);}return _0x525d7e;};}function handleError(_0x215334,_0x311251){_0x311251=_0x311251||0x1f4;return function(_0x4d183e){logger[_0x8ba0('0x21')](_0x4d183e[_0x8ba0('0x34')]);if(_0x4d183e[_0x8ba0('0x35')]){delete _0x4d183e['name'];}_0x215334[_0x8ba0('0x25')](_0x311251)[_0x8ba0('0x36')](_0x4d183e);};}exports[_0x8ba0('0x37')]=function(_0x4745e6,_0xbf819b){var _0x50e69f={'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x18269a={},_0x338d3e={'count':0x0,'rows':[]};var _0x384528=_['map'](db['OpenchannelAccount'][_0x8ba0('0x38')],function(_0x266a1f){return{'name':_0x266a1f['fieldName'],'type':_0x266a1f[_0x8ba0('0x39')]['key']};});_0x18269a['model']=_['map'](_0x384528,_0x8ba0('0x35'));_0x18269a[_0x8ba0('0x3a')]=_['keys'](_0x4745e6[_0x8ba0('0x3a')]);_0x18269a['filters']=_['intersection'](_0x18269a[_0x8ba0('0x3b')],_0x18269a[_0x8ba0('0x3a')]);_0x50e69f['attributes']=_['intersection'](_0x18269a[_0x8ba0('0x3b')],qs[_0x8ba0('0x3c')](_0x4745e6[_0x8ba0('0x3a')][_0x8ba0('0x3c')]));_0x50e69f[_0x8ba0('0x3d')]=_0x50e69f[_0x8ba0('0x3d')][_0x8ba0('0x3e')]?_0x50e69f[_0x8ba0('0x3d')]:_0x18269a[_0x8ba0('0x3b')];if(!_0x4745e6[_0x8ba0('0x3a')]['hasOwnProperty'](_0x8ba0('0x3f'))){_0x50e69f[_0x8ba0('0x28')]=qs['limit'](_0x4745e6[_0x8ba0('0x3a')][_0x8ba0('0x28')]);_0x50e69f[_0x8ba0('0x27')]=qs[_0x8ba0('0x27')](_0x4745e6[_0x8ba0('0x3a')][_0x8ba0('0x27')]);}_0x50e69f['order']=qs['sort'](_0x4745e6[_0x8ba0('0x3a')][_0x8ba0('0x40')]);_0x50e69f['where']=qs[_0x8ba0('0x41')](_[_0x8ba0('0x42')](_0x4745e6[_0x8ba0('0x3a')],_0x18269a[_0x8ba0('0x41')]),_0x384528);if(_0x4745e6[_0x8ba0('0x3a')][_0x8ba0('0x43')]){_0x50e69f[_0x8ba0('0x44')]=_[_0x8ba0('0x45')](_0x50e69f[_0x8ba0('0x44')],{'$or':_[_0x8ba0('0x46')](_0x384528,function(_0x962a09){if(_0x962a09[_0x8ba0('0x39')]!=='VIRTUAL'){var _0x31725b={};_0x31725b[_0x962a09[_0x8ba0('0x35')]]={'$like':'%'+_0x4745e6['query']['filter']+'%'};return _0x31725b;}})});}_0x50e69f=_[_0x8ba0('0x45')]({},_0x50e69f,_0x4745e6[_0x8ba0('0x47')]);var _0x58479e={'where':_0x50e69f[_0x8ba0('0x44')]};return db[_0x8ba0('0x48')]['count'](_0x58479e)['then'](function(_0x393554){_0x338d3e[_0x8ba0('0x2a')]=_0x393554;if(_0x4745e6[_0x8ba0('0x3a')][_0x8ba0('0x49')]){_0x50e69f[_0x8ba0('0x4a')]=[{'all':!![]}];}return db[_0x8ba0('0x48')][_0x8ba0('0x4b')](_0x50e69f);})[_0x8ba0('0x2f')](function(_0x296257){_0x338d3e[_0x8ba0('0x4c')]=_0x296257;return _0x338d3e;})[_0x8ba0('0x2f')](respondWithFilteredResult(_0xbf819b,_0x50e69f))[_0x8ba0('0x24')](handleError(_0xbf819b,null));};exports[_0x8ba0('0x4d')]=function(_0x359636,_0x1b2828){var _0x373bff={'raw':![],'where':{'id':_0x359636[_0x8ba0('0x4e')]['id']},'include':[{'model':db[_0x8ba0('0x4f')],'as':_0x8ba0('0x50')}]},_0x4f6ea6={};_0x4f6ea6['model']=_[_0x8ba0('0x51')](db[_0x8ba0('0x48')][_0x8ba0('0x38')]);_0x4f6ea6[_0x8ba0('0x3a')]=_[_0x8ba0('0x51')](_0x359636[_0x8ba0('0x3a')]);_0x4f6ea6['filters']=_[_0x8ba0('0x52')](_0x4f6ea6['model'],_0x4f6ea6[_0x8ba0('0x3a')]);_0x373bff[_0x8ba0('0x3d')]=_[_0x8ba0('0x52')](_0x4f6ea6[_0x8ba0('0x3b')],qs[_0x8ba0('0x3c')](_0x359636[_0x8ba0('0x3a')]['fields']));_0x373bff[_0x8ba0('0x3d')]=_0x373bff[_0x8ba0('0x3d')][_0x8ba0('0x3e')]?_0x373bff[_0x8ba0('0x3d')]:_0x4f6ea6[_0x8ba0('0x3b')];if(_0x359636[_0x8ba0('0x3a')]['includeAll']){_0x373bff[_0x8ba0('0x4a')]=[{'all':!![]}];}_0x373bff=_[_0x8ba0('0x45')]({},_0x373bff,_0x359636['options']);return db['OpenchannelAccount'][_0x8ba0('0x53')](_0x373bff)[_0x8ba0('0x2f')](handleEntityNotFound(_0x1b2828,null))[_0x8ba0('0x2f')](respondWithResult(_0x1b2828,null))[_0x8ba0('0x24')](handleError(_0x1b2828,null));};exports[_0x8ba0('0x54')]=function(_0x4a9f76,_0x7cc248){return db[_0x8ba0('0x48')][_0x8ba0('0x54')](_0x4a9f76[_0x8ba0('0x55')],{})[_0x8ba0('0x2f')](function(_0x5e20c6){var _0x35ced8=_0x4a9f76['user']['get']({'plain':!![]});if(!_0x35ced8)throw new Error(_0x8ba0('0x56'));if(_0x35ced8['role']===_0x8ba0('0x57')){var _0x5670b4=_0x5e20c6[_0x8ba0('0x31')]({'plain':!![]});var _0x5a9a43=_0x8ba0('0x32');return db[_0x8ba0('0x58')]['find']({'where':{'name':_0x5a9a43,'userProfileId':_0x35ced8[_0x8ba0('0x59')]},'raw':!![]})[_0x8ba0('0x2f')](function(_0x23d69f){if(_0x23d69f&&_0x23d69f[_0x8ba0('0x5a')]===0x0){return db[_0x8ba0('0x33')][_0x8ba0('0x54')]({'name':_0x5670b4[_0x8ba0('0x35')],'resourceId':_0x5670b4['id'],'type':_0x23d69f['name'],'sectionId':_0x23d69f['id']},{})[_0x8ba0('0x2f')](function(){return _0x5e20c6;});}else{return _0x5e20c6;}})[_0x8ba0('0x24')](function(_0x3974d5){logger[_0x8ba0('0x21')](_0x8ba0('0x5b'),_0x3974d5);throw _0x3974d5;});}return _0x5e20c6;})[_0x8ba0('0x2f')](respondWithResult(_0x7cc248,0xc9))[_0x8ba0('0x24')](handleError(_0x7cc248,null));};exports[_0x8ba0('0x5c')]=function(_0x5bede9,_0x4d185a){if(_0x5bede9[_0x8ba0('0x55')]['id']){delete _0x5bede9['body']['id'];}return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x5bede9['params']['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x8ba0('0x2f')](handleEntityNotFound(_0x4d185a,null))[_0x8ba0('0x2f')](saveUpdates(_0x5bede9[_0x8ba0('0x55')],null))['then'](respondWithResult(_0x4d185a,null))[_0x8ba0('0x24')](handleError(_0x4d185a,null));};exports[_0x8ba0('0x30')]=function(_0x4f44ae,_0x29f261){return db['OpenchannelAccount'][_0x8ba0('0x53')]({'where':{'id':_0x4f44ae['params']['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x29f261,null))[_0x8ba0('0x2f')](removeEntity(_0x29f261,null))[_0x8ba0('0x24')](handleError(_0x29f261,null));};exports['describe']=function(_0x201cfe,_0x171be1){return db['OpenchannelAccount'][_0x8ba0('0x5d')]()[_0x8ba0('0x2f')](respondWithResult(_0x171be1,null))['catch'](handleError(_0x171be1,null));};exports[_0x8ba0('0x5e')]=function(_0x1d3a03,_0x30754c,_0x574d9a){if(_0x1d3a03['body']['id']){delete _0x1d3a03['body']['id'];}return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x1d3a03[_0x8ba0('0x4e')]['id']}})['then'](handleEntityNotFound(_0x30754c,null))[_0x8ba0('0x2f')](function(_0x4d5e43){if(_0x4d5e43){_0x1d3a03[_0x8ba0('0x55')][_0x8ba0('0x5f')]=_0x4d5e43['id'];return db['Disposition'][_0x8ba0('0x54')](_0x1d3a03[_0x8ba0('0x55')]);}})[_0x8ba0('0x2f')](respondWithResult(_0x30754c,null))[_0x8ba0('0x24')](handleError(_0x30754c,null));};exports[_0x8ba0('0x60')]=function(_0x4e3f98,_0x5ab019,_0x498fb7){var _0x4d7ffd={'raw':![],'where':{}};var _0x27549e={};var _0x188b64={'count':0x0,'rows':[]};return db[_0x8ba0('0x48')][_0x8ba0('0x61')]({'where':{'id':_0x4e3f98[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x5ab019,null))[_0x8ba0('0x2f')](function(_0x5ae9b9){if(_0x5ae9b9){_0x27549e[_0x8ba0('0x3b')]=_[_0x8ba0('0x51')](db[_0x8ba0('0x62')]['rawAttributes']);_0x27549e['query']=_[_0x8ba0('0x51')](_0x4e3f98[_0x8ba0('0x3a')]);_0x27549e['filters']=_[_0x8ba0('0x52')](_0x27549e['model'],_0x27549e[_0x8ba0('0x3a')]);_0x4d7ffd[_0x8ba0('0x3d')]=_[_0x8ba0('0x52')](_0x27549e[_0x8ba0('0x3b')],qs[_0x8ba0('0x3c')](_0x4e3f98[_0x8ba0('0x3a')][_0x8ba0('0x3c')]));_0x4d7ffd[_0x8ba0('0x3d')]=_0x4d7ffd[_0x8ba0('0x3d')][_0x8ba0('0x3e')]?_0x4d7ffd[_0x8ba0('0x3d')]:_0x27549e[_0x8ba0('0x3b')];if(!_0x4e3f98[_0x8ba0('0x3a')][_0x8ba0('0x63')](_0x8ba0('0x3f'))){_0x4d7ffd['limit']=qs[_0x8ba0('0x28')](_0x4e3f98[_0x8ba0('0x3a')][_0x8ba0('0x28')]);_0x4d7ffd[_0x8ba0('0x27')]=qs[_0x8ba0('0x27')](_0x4e3f98['query'][_0x8ba0('0x27')]);}_0x4d7ffd[_0x8ba0('0x64')]=qs[_0x8ba0('0x40')](_0x4e3f98[_0x8ba0('0x3a')][_0x8ba0('0x40')]);_0x4d7ffd[_0x8ba0('0x44')]=qs['filters'](_[_0x8ba0('0x42')](_0x4e3f98[_0x8ba0('0x3a')],_0x27549e[_0x8ba0('0x41')]));_0x4d7ffd[_0x8ba0('0x44')][_0x8ba0('0x5f')]=_0x5ae9b9['id'];if(_0x4e3f98[_0x8ba0('0x3a')][_0x8ba0('0x43')]){_0x4d7ffd[_0x8ba0('0x44')]=_[_0x8ba0('0x45')](_0x4d7ffd[_0x8ba0('0x44')],{'$or':_['map'](_0x4d7ffd[_0x8ba0('0x3d')],function(_0x561b57){var _0x15817e={};_0x15817e[_0x561b57]={'$like':'%'+_0x4e3f98['query'][_0x8ba0('0x43')]+'%'};return _0x15817e;})});}_0x4d7ffd=_[_0x8ba0('0x45')]({},_0x4d7ffd,_0x4e3f98[_0x8ba0('0x47')]);return db[_0x8ba0('0x62')][_0x8ba0('0x2a')]({'where':_0x4d7ffd[_0x8ba0('0x44')]})[_0x8ba0('0x2f')](function(_0x31f190){_0x188b64['count']=_0x31f190;if(_0x4e3f98[_0x8ba0('0x3a')]['includeAll']){_0x4d7ffd[_0x8ba0('0x4a')]=[{'all':!![]}];}return db[_0x8ba0('0x62')][_0x8ba0('0x4b')](_0x4d7ffd);})[_0x8ba0('0x2f')](function(_0x4aaa22){_0x188b64['rows']=_0x4aaa22;return _0x188b64;});}})['then'](respondWithFilteredResult(_0x5ab019,_0x4d7ffd))[_0x8ba0('0x24')](handleError(_0x5ab019,null));};exports[_0x8ba0('0x65')]=function(_0x741cae,_0x1dff80,_0x13aab0){return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x741cae[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x1dff80,null))[_0x8ba0('0x2f')](function(_0x4c2664){if(_0x4c2664){return _0x4c2664[_0x8ba0('0x65')](_0x741cae['query']['ids']);}})['then'](respondWithStatusCode(_0x1dff80,null))[_0x8ba0('0x24')](handleError(_0x1dff80,null));};exports['addAnswer']=function(_0x11b970,_0x3b55af,_0x25eb84){if(_0x11b970[_0x8ba0('0x55')]['id']){delete _0x11b970[_0x8ba0('0x55')]['id'];}return db['OpenchannelAccount'][_0x8ba0('0x53')]({'where':{'id':_0x11b970['params']['id']}})['then'](handleEntityNotFound(_0x3b55af,null))[_0x8ba0('0x2f')](function(_0x33378f){if(_0x33378f){_0x11b970[_0x8ba0('0x55')][_0x8ba0('0x5f')]=_0x33378f['id'];return db[_0x8ba0('0x66')][_0x8ba0('0x54')](_0x11b970[_0x8ba0('0x55')]);}})[_0x8ba0('0x2f')](respondWithResult(_0x3b55af,null))[_0x8ba0('0x24')](handleError(_0x3b55af,null));};exports['getAnswers']=function(_0x469624,_0x331d0d,_0x4c7d60){var _0x22b4e6={'raw':![],'where':{}};var _0xae3896={};var _0x1619fd={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x8ba0('0x61')]({'where':{'id':_0x469624[_0x8ba0('0x4e')]['id']}})['then'](handleEntityNotFound(_0x331d0d,null))[_0x8ba0('0x2f')](function(_0x40426a){if(_0x40426a){_0xae3896[_0x8ba0('0x3b')]=_[_0x8ba0('0x51')](db[_0x8ba0('0x66')][_0x8ba0('0x38')]);_0xae3896[_0x8ba0('0x3a')]=_[_0x8ba0('0x51')](_0x469624[_0x8ba0('0x3a')]);_0xae3896[_0x8ba0('0x41')]=_[_0x8ba0('0x52')](_0xae3896[_0x8ba0('0x3b')],_0xae3896[_0x8ba0('0x3a')]);_0x22b4e6['attributes']=_[_0x8ba0('0x52')](_0xae3896['model'],qs['fields'](_0x469624[_0x8ba0('0x3a')][_0x8ba0('0x3c')]));_0x22b4e6[_0x8ba0('0x3d')]=_0x22b4e6[_0x8ba0('0x3d')][_0x8ba0('0x3e')]?_0x22b4e6[_0x8ba0('0x3d')]:_0xae3896[_0x8ba0('0x3b')];if(!_0x469624[_0x8ba0('0x3a')]['hasOwnProperty']('nolimit')){_0x22b4e6[_0x8ba0('0x28')]=qs[_0x8ba0('0x28')](_0x469624[_0x8ba0('0x3a')][_0x8ba0('0x28')]);_0x22b4e6[_0x8ba0('0x27')]=qs['offset'](_0x469624['query'][_0x8ba0('0x27')]);}_0x22b4e6['order']=qs[_0x8ba0('0x40')](_0x469624['query'][_0x8ba0('0x40')]);_0x22b4e6[_0x8ba0('0x44')]=qs[_0x8ba0('0x41')](_[_0x8ba0('0x42')](_0x469624[_0x8ba0('0x3a')],_0xae3896[_0x8ba0('0x41')]));_0x22b4e6[_0x8ba0('0x44')][_0x8ba0('0x5f')]=_0x40426a['id'];if(_0x469624['query'][_0x8ba0('0x43')]){_0x22b4e6[_0x8ba0('0x44')]=_['merge'](_0x22b4e6[_0x8ba0('0x44')],{'$or':_[_0x8ba0('0x46')](_0x22b4e6[_0x8ba0('0x3d')],function(_0x25ba86){var _0x318fff={};_0x318fff[_0x25ba86]={'$like':'%'+_0x469624[_0x8ba0('0x3a')][_0x8ba0('0x43')]+'%'};return _0x318fff;})});}_0x22b4e6=_[_0x8ba0('0x45')]({},_0x22b4e6,_0x469624[_0x8ba0('0x47')]);return db['CannedAnswer'][_0x8ba0('0x2a')]({'where':_0x22b4e6['where']})[_0x8ba0('0x2f')](function(_0x3d9380){_0x1619fd[_0x8ba0('0x2a')]=_0x3d9380;if(_0x469624['query'][_0x8ba0('0x49')]){_0x22b4e6['include']=[{'all':!![]}];}return db[_0x8ba0('0x66')][_0x8ba0('0x4b')](_0x22b4e6);})['then'](function(_0x447740){_0x1619fd[_0x8ba0('0x4c')]=_0x447740;return _0x1619fd;});}})[_0x8ba0('0x2f')](respondWithFilteredResult(_0x331d0d,_0x22b4e6))[_0x8ba0('0x24')](handleError(_0x331d0d,null));};exports[_0x8ba0('0x67')]=function(_0x54dd79,_0x2c071c,_0xe5fec8){return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x54dd79[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x2c071c,null))['then'](function(_0x10e5bc){if(_0x10e5bc){return _0x10e5bc[_0x8ba0('0x67')](_0x54dd79['query']['ids']);}})[_0x8ba0('0x2f')](respondWithStatusCode(_0x2c071c,null))[_0x8ba0('0x24')](handleError(_0x2c071c,null));};exports[_0x8ba0('0x68')]=function(_0x3a825e,_0x5b2ea3,_0x5001a5){var _0x5d4f36={'body':_0x3a825e['body'],'channel':_0x8ba0('0x69')};var _0x4d1cb2=[];var _0xee4eca=[];var _0x57972f={};var _0x238f55=![];return db['CmContact'][_0x8ba0('0x5d')]()[_0x8ba0('0x2f')](function(_0x1103b){if(!_0x1103b){throw new db[(_0x8ba0('0x6a'))][(_0x8ba0('0x6b'))](_0x8ba0('0x6c'));}_0x4d1cb2=_[_0x8ba0('0x6d')](_[_0x8ba0('0x51')](_0x1103b),[_0x8ba0('0x6e'),_0x8ba0('0x6f')]);_0xee4eca=_['difference'](_[_0x8ba0('0x51')](_0x1103b),[_0x8ba0('0x6e'),_0x8ba0('0x6f'),'CompanyId','ListId']);if(_0x3a825e[_0x8ba0('0x55')]['id']){delete _0x3a825e[_0x8ba0('0x55')]['id'];}if(_['isNil'](_0x3a825e[_0x8ba0('0x55')]['from'])){throw new db[(_0x8ba0('0x6a'))][(_0x8ba0('0x6b'))](_0x8ba0('0x70'));}if(_[_0x8ba0('0x71')](_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x55')])||_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x55')]===''){throw new db['Sequelize'][(_0x8ba0('0x6b'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x8ba0('0x71')](_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x72')])){throw new db[(_0x8ba0('0x6a'))][(_0x8ba0('0x6b'))](_0x8ba0('0x73')+_0xee4eca);}if(!_[_0x8ba0('0x74')](_0xee4eca,_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x72')])){throw new db[(_0x8ba0('0x6a'))][(_0x8ba0('0x6b'))](_0x8ba0('0x75')+_0xee4eca);}_0x57972f[_0x3a825e[_0x8ba0('0x55')]['mapKey']]=_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x76')];})[_0x8ba0('0x2f')](function(){return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x3a825e['params']['id']},'include':[{'model':db['CmList'],'as':_0x8ba0('0x77'),'include':[{'model':db[_0x8ba0('0x78')],'as':_0x8ba0('0x79'),'where':_0x57972f,'limit':0x1,'order':[[_0x8ba0('0x6f'),_0x8ba0('0x7a')]]}]},{'model':db[_0x8ba0('0x7b')],'as':_0x8ba0('0x7c')}]});})[_0x8ba0('0x2f')](handleEntityNotFound(_0x5b2ea3,null))[_0x8ba0('0x2f')](function(_0x56ba0e){if(_0x56ba0e&&_0x56ba0e['List']){_0x5d4f36['account']=_0x56ba0e;_0x5d4f36['applications']=_0x56ba0e['Applications'];_0x5d4f36['list']=_0x56ba0e[_0x8ba0('0x77')];_0x5d4f36[_0x8ba0('0x7d')]=_[_0x8ba0('0x7e')](_0x5d4f36[_0x8ba0('0x7d')],[_0x8ba0('0x7f')],[_0x8ba0('0x80')]);if(_0x5d4f36[_0x8ba0('0x81')][_0x8ba0('0x7c')]){delete _0x5d4f36[_0x8ba0('0x81')][_0x8ba0('0x7c')];}if(_0x5d4f36[_0x8ba0('0x81')][_0x8ba0('0x77')]&&_0x5d4f36[_0x8ba0('0x81')]['List'][_0x8ba0('0x79')][_0x8ba0('0x3e')]){return _0x5d4f36['account'][_0x8ba0('0x77')]['Contacts'][0x0];}var _0x660ad6=_[_0x8ba0('0x14')](_0x3a825e[_0x8ba0('0x55')],{'firstName':_0x3a825e['body'][_0x8ba0('0x76')],'ListId':_0x56ba0e[_0x8ba0('0x82')]});_0x660ad6[_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x72')]]=_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x76')];return db[_0x8ba0('0x78')][_0x8ba0('0x54')](_0x660ad6,{'fields':_0x4d1cb2,'raw':!![]});}})['then'](handleEntityNotFound(_0x5b2ea3,null))[_0x8ba0('0x2f')](function(_0x240815){_0x5d4f36[_0x8ba0('0x83')]=_0x240815;if(_0x240815){var _0x526dad={'ContactId':_0x240815['id'],'OpenchannelAccountId':_0x3a825e[_0x8ba0('0x4e')]['id'],'from':(_0x240815['firstName']||'')+'\x20'+(_0x240815['lastName']||'')};var _0x280091={'OpenchannelAccountId':_0x3a825e['params']['id'],'closed':![]};if(_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x84')]){_0x280091[_0x8ba0('0x84')]=_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x84')];return db[_0x8ba0('0x85')][_0x8ba0('0x53')]({'where':_0x280091})[_0x8ba0('0x2f')](function(_0x35ac36){if(_0x35ac36){return[_0x35ac36,![]];}_0x526dad['threadId']=_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x84')];_0x526dad['externalUrl']=_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x86')];return db[_0x8ba0('0x85')][_0x8ba0('0x54')](_0x526dad)[_0x8ba0('0x2f')](function(_0x20f873){return[_0x20f873,!![]];});});}else{_0x280091[_0x8ba0('0x84')]=null;}_0x280091['ContactId']=_0x240815['id'];return db[_0x8ba0('0x85')]['find']({'where':_0x280091})[_0x8ba0('0x2f')](function(_0x161653){if(_0x161653){return[_0x161653,![]];}return db['OpenchannelInteraction']['create'](_0x526dad)[_0x8ba0('0x2f')](function(_0x135169){return[_0x135169,!![]];});});}})[_0x8ba0('0x87')](function(_0x2e89df,_0x4e3e90){if(_0x2e89df){_0x238f55=_0x4e3e90;if(!_0x4e3e90){var _0x49545d={'from':(_0x5d4f36[_0x8ba0('0x83')][_0x8ba0('0x88')]||'')+'\x20'+(_0x5d4f36[_0x8ba0('0x83')]['lastName']||'')};if(_0x3a825e[_0x8ba0('0x55')]['threadId']&&_0x3a825e['body']['messageId']&&_0x3a825e[_0x8ba0('0x55')][_0x8ba0('0x84')]!=_0x3a825e['body'][_0x8ba0('0x89')]){_0x49545d['threadId']=_0x3a825e['body']['messageId'];}return _0x2e89df[_0x8ba0('0x5c')](_0x49545d);}else{return _0x2e89df;}}})[_0x8ba0('0x2f')](function(_0x29816c){_0x5d4f36['interaction']=_0x29816c[_0x8ba0('0x31')]({'plain':!![]});_0x5d4f36[_0x8ba0('0x8a')][_0x8ba0('0x8b')]=_0x238f55;if(_0x5d4f36[_0x8ba0('0x8a')]['created']){if(_0x5d4f36[_0x8ba0('0x81')]['autoclose']){_0x5d4f36[_0x8ba0('0x7d')]['push']({'id':0x0,'priority':_0x5d4f36[_0x8ba0('0x7d')][_0x8ba0('0x3e')]+0x1,'app':'close','appdata':_0x8ba0('0x8c'),'interval':'*,*,*,*'});}}return db[_0x8ba0('0x8d')][_0x8ba0('0x54')]({'body':_0x3a825e['body'][_0x8ba0('0x55')],'OpenchannelAccountId':_0x3a825e['params']['id'],'OpenchannelInteractionId':_0x29816c['id'],'direction':'in','ContactId':_0x5d4f36['contact']['id'],'AttachmentId':_0x3a825e[_0x8ba0('0x55')]['AttachmentId']});})[_0x8ba0('0x2f')](function(_0x3fea54){_0x5d4f36['message']=_0x3fea54;if(_0x5d4f36['interaction']['UserId']){return db[_0x8ba0('0x8e')][_0x8ba0('0x53')]({'attributes':['id',_0x8ba0('0x35')],'where':{'id':_0x5d4f36[_0x8ba0('0x8a')]['UserId']}})[_0x8ba0('0x2f')](function(_0x2d6958){if(_0x2d6958){_0x5d4f36['applications'][_0x8ba0('0x8f')]({'id':0x0,'priority':0x0,'app':_0x8ba0('0x90'),'appdata':_0x2d6958[_0x8ba0('0x35')]+','+(_0x5d4f36[_0x8ba0('0x81')][_0x8ba0('0x91')]||0xa),'interval':_0x8ba0('0x92')});_0x5d4f36[_0x8ba0('0x93')]=![];}return respondWithRpcPromise('Start','startRouting',_0x5d4f36);});}return respondWithRpcPromise(_0x8ba0('0x94'),_0x8ba0('0x95'),_0x5d4f36);})['then'](function(_0x3d9371){respondWithRpcPromise('EventManager',_0x8ba0('0x96'),{'event':'notify','message':_0x3d9371},client9002);return _0x3d9371;})[_0x8ba0('0x2f')](respondWithResult(_0x5b2ea3,null))[_0x8ba0('0x24')](handleError(_0x5b2ea3,null));};exports[_0x8ba0('0x97')]=function(_0x5b5051,_0x25fb0d){var _0x28668d=_0x5b5051[_0x8ba0('0x4e')]['id'];var _0x5e5780=_0x5b5051[_0x8ba0('0x55')];var _0x185b5a=0xc8;var _0x115d13=null;return db[_0x8ba0('0x98')][_0x8ba0('0x99')]({'isolationLevel':db[_0x8ba0('0x98')][_0x8ba0('0x9a')][_0x8ba0('0x9b')]['READ_COMMITTED']},function(_0x2d3fb8){return db['OpenchannelAccount'][_0x8ba0('0x61')]({'where':{'id':_0x28668d},'transaction':_0x2d3fb8})[_0x8ba0('0x2f')](function(_0x3af50b){if(_0x3af50b){return db[_0x8ba0('0x7b')][_0x8ba0('0x30')]({'where':{'OpenchannelAccountId':_0x28668d},'transaction':_0x2d3fb8})[_0x8ba0('0x2f')](function(){var _0x2013d4=_[_0x8ba0('0x46')](_0x5e5780,function(_0x270724){_0x270724['OpenchannelAccountId']=_0x28668d;return _0x270724;});return db[_0x8ba0('0x7b')][_0x8ba0('0x9c')](_0x2013d4,{'transaction':_0x2d3fb8});});}else{_0x185b5a=0x194;_0x115d13=[];}});})[_0x8ba0('0x2f')](function(){if(_0x185b5a!==0x194){return db[_0x8ba0('0x7b')][_0x8ba0('0x9d')]({'where':{'OpenchannelAccountId':_0x28668d},'order':_0x8ba0('0x7f')})[_0x8ba0('0x2f')](function(_0x3f174a){_0x115d13=_0x3f174a;});}})[_0x8ba0('0x24')](function(_0x5b3f25){_0x185b5a=0x1f4;logger[_0x8ba0('0x21')](_0x5b3f25[_0x8ba0('0x34')]);if(_0x5b3f25[_0x8ba0('0x35')]){delete _0x5b3f25[_0x8ba0('0x35')];}_0x115d13=_0x5b3f25;})['finally'](function(){if(_0x115d13===null){_0x25fb0d[_0x8ba0('0x9e')](_0x185b5a);}else{if(_0x185b5a===0x1f4){_0x25fb0d[_0x8ba0('0x25')](_0x185b5a)[_0x8ba0('0x36')](_0x115d13);}else{_0x25fb0d['status'](_0x185b5a)[_0x8ba0('0x26')](_0x115d13);}}});};exports[_0x8ba0('0x9f')]=function(_0x1fda10,_0x66225d,_0x11f7fb){var _0x690bea={};var _0x4176bd={};var _0x3403a2;var _0x35d6e1;return db['OpenchannelAccount'][_0x8ba0('0x61')]({'where':{'id':_0x1fda10[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x66225d,null))[_0x8ba0('0x2f')](function(_0x1a29a6){if(_0x1a29a6){_0x3403a2=_0x1a29a6;_0x4176bd[_0x8ba0('0x3b')]=_['keys'](db[_0x8ba0('0x7b')][_0x8ba0('0x38')]);_0x4176bd['query']=_[_0x8ba0('0x51')](_0x1fda10[_0x8ba0('0x3a')]);_0x4176bd['filters']=_[_0x8ba0('0x52')](_0x4176bd[_0x8ba0('0x3b')],_0x4176bd[_0x8ba0('0x3a')]);_0x690bea[_0x8ba0('0x3d')]=_[_0x8ba0('0x52')](_0x4176bd[_0x8ba0('0x3b')],qs[_0x8ba0('0x3c')](_0x1fda10['query']['fields']));_0x690bea[_0x8ba0('0x3d')]=_0x690bea['attributes'][_0x8ba0('0x3e')]?_0x690bea[_0x8ba0('0x3d')]:_0x4176bd[_0x8ba0('0x3b')];_0x690bea['order']=qs[_0x8ba0('0x40')](_0x1fda10[_0x8ba0('0x3a')]['sort']);_0x690bea[_0x8ba0('0x44')]=qs[_0x8ba0('0x41')](_[_0x8ba0('0x42')](_0x1fda10[_0x8ba0('0x3a')],_0x4176bd[_0x8ba0('0x41')]));if(_0x1fda10[_0x8ba0('0x3a')]['filter']){_0x690bea[_0x8ba0('0x44')]=_['merge'](_0x690bea[_0x8ba0('0x44')],{'$or':_['map'](_0x690bea[_0x8ba0('0x3d')],function(_0x2db512){var _0x543499={};_0x543499[_0x2db512]={'$like':'%'+_0x1fda10['query'][_0x8ba0('0x43')]+'%'};return _0x543499;})});}_0x690bea=_[_0x8ba0('0x45')]({},_0x690bea,_0x1fda10['options']);return _0x3403a2[_0x8ba0('0x9f')](_0x690bea);}})[_0x8ba0('0x2f')](function(_0x3c1c07){if(_0x3c1c07){_0x35d6e1=_0x3c1c07[_0x8ba0('0x3e')];if(!_0x1fda10[_0x8ba0('0x3a')][_0x8ba0('0x63')](_0x8ba0('0x3f'))){_0x690bea[_0x8ba0('0x28')]=qs[_0x8ba0('0x28')](_0x1fda10[_0x8ba0('0x3a')][_0x8ba0('0x28')]);_0x690bea[_0x8ba0('0x27')]=qs[_0x8ba0('0x27')](_0x1fda10[_0x8ba0('0x3a')][_0x8ba0('0x27')]);}return _0x3403a2[_0x8ba0('0x9f')](_0x690bea);}})[_0x8ba0('0x2f')](function(_0x1e295a){if(_0x1e295a){return _0x1e295a?{'count':_0x35d6e1,'rows':_0x1e295a}:null;}})['then'](respondWithResult(_0x66225d,null))['catch'](handleError(_0x66225d,null));};exports[_0x8ba0('0xa0')]=function(_0x3f59a2,_0x26ea77,_0x514472){var _0x4264e9={'raw':![],'where':{}};var _0x2f5fec={};var _0xf4b6ed={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x3f59a2[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x26ea77,null))['then'](function(_0x19fc2e){if(_0x19fc2e){_0x2f5fec[_0x8ba0('0x3b')]=_[_0x8ba0('0x51')](db[_0x8ba0('0x85')][_0x8ba0('0x38')]);_0x2f5fec[_0x8ba0('0x3a')]=_[_0x8ba0('0x51')](_0x3f59a2[_0x8ba0('0x3a')]);_0x2f5fec[_0x8ba0('0x41')]=_[_0x8ba0('0x52')](_0x2f5fec[_0x8ba0('0x3b')],_0x2f5fec['query']);_0x4264e9[_0x8ba0('0x3d')]=_[_0x8ba0('0x52')](_0x2f5fec[_0x8ba0('0x3b')],qs[_0x8ba0('0x3c')](_0x3f59a2['query'][_0x8ba0('0x3c')]));_0x4264e9[_0x8ba0('0x3d')]=_0x4264e9[_0x8ba0('0x3d')][_0x8ba0('0x3e')]?_0x4264e9[_0x8ba0('0x3d')]:_0x2f5fec[_0x8ba0('0x3b')];if(!_0x3f59a2[_0x8ba0('0x3a')][_0x8ba0('0x63')](_0x8ba0('0x3f'))){_0x4264e9[_0x8ba0('0x28')]=qs['limit'](_0x3f59a2['query'][_0x8ba0('0x28')]);_0x4264e9['offset']=qs['offset'](_0x3f59a2[_0x8ba0('0x3a')]['offset']);}_0x4264e9[_0x8ba0('0x64')]=qs[_0x8ba0('0x40')](_0x3f59a2['query']['sort']);_0x4264e9[_0x8ba0('0x44')]=qs['filters'](_[_0x8ba0('0x42')](_0x3f59a2['query'],_0x2f5fec[_0x8ba0('0x41')]));_0x4264e9[_0x8ba0('0x44')][_0x8ba0('0x5f')]=_0x19fc2e['id'];if(_0x3f59a2[_0x8ba0('0x3a')][_0x8ba0('0x43')]){_0x4264e9['where']=_[_0x8ba0('0x45')](_0x4264e9[_0x8ba0('0x44')],{'$or':_[_0x8ba0('0x46')](_0x4264e9[_0x8ba0('0x3d')],function(_0x132b1f){var _0x1b6f0d={};_0x1b6f0d[_0x132b1f]={'$like':'%'+_0x3f59a2[_0x8ba0('0x3a')][_0x8ba0('0x43')]+'%'};return _0x1b6f0d;})});}_0x4264e9=_[_0x8ba0('0x45')]({},_0x4264e9,_0x3f59a2[_0x8ba0('0x47')]);return db[_0x8ba0('0x85')][_0x8ba0('0x2a')]({'where':_0x4264e9['where']})['then'](function(_0x4c698a){_0xf4b6ed[_0x8ba0('0x2a')]=_0x4c698a;if(_0x3f59a2[_0x8ba0('0x3a')][_0x8ba0('0x49')]){_0x4264e9[_0x8ba0('0x4a')]=[{'model':db[_0x8ba0('0x78')],'as':'Contact','required':![]},{'model':db['User'],'as':_0x8ba0('0xa1'),'attributes':['name','fullname','internal'],'required':![]},{'model':db[_0x8ba0('0xa2')],'as':_0x8ba0('0xa3'),'attributes':['id',_0x8ba0('0x35'),'color'],'where':_0x3f59a2[_0x8ba0('0x3a')][_0x8ba0('0xa4')]?{'id':_0x3f59a2[_0x8ba0('0x3a')][_0x8ba0('0xa4')]}:undefined,'required':_0x3f59a2[_0x8ba0('0x3a')]['tag']?!![]:![]}];}return db[_0x8ba0('0x85')][_0x8ba0('0x4b')](_0x4264e9);})['then'](function(_0x3cf042){_0xf4b6ed[_0x8ba0('0x4c')]=_0x3cf042;return _0xf4b6ed;});}})[_0x8ba0('0x2f')](respondWithFilteredResult(_0x26ea77,_0x4264e9))['catch'](handleError(_0x26ea77,null));};exports[_0x8ba0('0xa5')]=function(_0x52efbf,_0x50eb94,_0x2ab16e){return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x52efbf[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x50eb94,null))['then'](function(_0x55a958){if(_0x55a958){return _0x55a958[_0x8ba0('0xa5')](_0x52efbf['body'][_0x8ba0('0xa6')],_[_0x8ba0('0xa7')](_0x52efbf[_0x8ba0('0x55')],[_0x8ba0('0xa6'),'id'])||{})[_0x8ba0('0x87')](function(_0xf08257){for(var _0x27743c=0x0;_0x27743c<_0x52efbf[_0x8ba0('0x55')]['ids'][_0x8ba0('0x3e')];_0x27743c+=0x1){socket[_0x8ba0('0xa8')](_0x8ba0('0xa9'),{'UserId':Number(_0x52efbf[_0x8ba0('0x55')][_0x8ba0('0xa6')][_0x27743c]),'OpenchannelAccountId':Number(_0x52efbf[_0x8ba0('0x4e')]['id'])});}return _0xf08257;});}})[_0x8ba0('0x2f')](respondWithResult(_0x50eb94,null))[_0x8ba0('0x24')](handleError(_0x50eb94,null));};exports['removeAgents']=function(_0x5de438,_0x149d14,_0x3886a3){return db['OpenchannelAccount']['find']({'where':{'id':_0x5de438[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x149d14,null))['then'](function(_0x2ce075){if(_0x2ce075){return _0x2ce075[_0x8ba0('0xaa')](_0x5de438[_0x8ba0('0x3a')][_0x8ba0('0xa6')])[_0x8ba0('0x2f')](function(){if(_[_0x8ba0('0xab')](_0x5de438[_0x8ba0('0x3a')]['ids'])){for(var _0x4533ea=0x0;_0x4533ea<_0x5de438[_0x8ba0('0x3a')][_0x8ba0('0xa6')]['length'];_0x4533ea+=0x1){socket[_0x8ba0('0xa8')](_0x8ba0('0xac'),{'UserId':Number(_0x5de438['query'][_0x8ba0('0xa6')][_0x4533ea]),'OpenchannelAccountId':Number(_0x5de438[_0x8ba0('0x4e')]['id'])});}}else{socket[_0x8ba0('0xa8')](_0x8ba0('0xac'),{'UserId':Number(_0x5de438[_0x8ba0('0x3a')][_0x8ba0('0xa6')]),'OpenchannelAccountId':Number(_0x5de438[_0x8ba0('0x4e')]['id'])});}});}})[_0x8ba0('0x2f')](respondWithStatusCode(_0x149d14,null))[_0x8ba0('0x24')](handleError(_0x149d14,null));};exports[_0x8ba0('0xad')]=function(_0x531820,_0x3da400,_0x315c64){var _0x28ce05={};var _0x3b2dbb={};var _0x17c90e;var _0x23f5f4;return db[_0x8ba0('0x48')][_0x8ba0('0x61')]({'where':{'id':_0x531820[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x3da400,null))['then'](function(_0x199438){if(_0x199438){_0x17c90e=_0x199438;_0x3b2dbb['model']=_[_0x8ba0('0x51')](db[_0x8ba0('0x8e')][_0x8ba0('0x38')]);_0x3b2dbb['query']=_[_0x8ba0('0x51')](_0x531820[_0x8ba0('0x3a')]);_0x3b2dbb[_0x8ba0('0x41')]=_[_0x8ba0('0x52')](_0x3b2dbb[_0x8ba0('0x3b')],_0x3b2dbb['query']);_0x28ce05['attributes']=_[_0x8ba0('0x52')](_0x3b2dbb['model'],qs['fields'](_0x531820['query'][_0x8ba0('0x3c')]));_0x28ce05[_0x8ba0('0x3d')]=_0x28ce05[_0x8ba0('0x3d')][_0x8ba0('0x3e')]?_0x28ce05[_0x8ba0('0x3d')]:_0x3b2dbb[_0x8ba0('0x3b')];_0x28ce05[_0x8ba0('0x64')]=qs[_0x8ba0('0x40')](_0x531820[_0x8ba0('0x3a')]['sort']);_0x28ce05['where']=qs['filters'](_['pick'](_0x531820[_0x8ba0('0x3a')],_0x3b2dbb[_0x8ba0('0x41')]));if(_0x531820[_0x8ba0('0x3a')][_0x8ba0('0x43')]){_0x28ce05[_0x8ba0('0x44')]=_[_0x8ba0('0x45')](_0x28ce05[_0x8ba0('0x44')],{'$or':_['map'](_0x28ce05[_0x8ba0('0x3d')],function(_0x2ce053){var _0x36c5ec={};_0x36c5ec[_0x2ce053]={'$like':'%'+_0x531820[_0x8ba0('0x3a')][_0x8ba0('0x43')]+'%'};return _0x36c5ec;})});}_0x28ce05=_[_0x8ba0('0x45')]({},_0x28ce05,_0x531820[_0x8ba0('0x47')]);return _0x17c90e[_0x8ba0('0xad')](_0x28ce05);}})[_0x8ba0('0x2f')](function(_0x454426){if(_0x454426){_0x23f5f4=_0x454426['length'];if(!_0x531820['query']['hasOwnProperty']('nolimit')){_0x28ce05[_0x8ba0('0x28')]=qs[_0x8ba0('0x28')](_0x531820[_0x8ba0('0x3a')][_0x8ba0('0x28')]);_0x28ce05[_0x8ba0('0x27')]=qs[_0x8ba0('0x27')](_0x531820[_0x8ba0('0x3a')][_0x8ba0('0x27')]);}return _0x17c90e[_0x8ba0('0xad')](_0x28ce05);}})[_0x8ba0('0x2f')](function(_0x2ad2e2){if(_0x2ad2e2){return _0x2ad2e2?{'count':_0x23f5f4,'rows':_0x2ad2e2}:null;}})['then'](respondWithResult(_0x3da400,null))[_0x8ba0('0x24')](handleError(_0x3da400,null));};exports['send']=function(_0x54ae31,_0x2d6288,_0x29b72f){var _0x5871b4,_0x379254,_0x4da279;if(_[_0x8ba0('0x71')](_0x54ae31[_0x8ba0('0x55')][_0x8ba0('0x55')])||_0x54ae31['body'][_0x8ba0('0x55')]===''){throw new db['Sequelize'][(_0x8ba0('0x6b'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x8ba0('0x71')](_0x54ae31[_0x8ba0('0x55')]['to'])){}_0x5871b4=_0x54ae31[_0x8ba0('0x55')]['to'];return db[_0x8ba0('0x48')]['findOne']({'where':{'id':_0x54ae31[_0x8ba0('0x4e')]['id']}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x2d6288,null))[_0x8ba0('0x2f')](function(_0x586972){if(_0x586972){return db[_0x8ba0('0x48')][_0x8ba0('0x53')]({'where':{'id':_0x586972['id']},'include':[{'model':db[_0x8ba0('0xae')],'as':_0x8ba0('0x77'),'include':[{'model':db[_0x8ba0('0x78')],'as':_0x8ba0('0x79'),'where':{[_0x586972[_0x8ba0('0x72')]]:_0x5871b4},'limit':0x1,'order':[['updatedAt',_0x8ba0('0x7a')]]}]}]})['then'](handleEntityNotFound(_0x2d6288,null))[_0x8ba0('0x2f')](function(_0x2c26aa){if(_0x2c26aa&&_0x2c26aa['List']){_0x379254=_0x2c26aa[_0x8ba0('0x31')]({'plain':!![]});if(_0x379254[_0x8ba0('0x77')]&&_0x379254[_0x8ba0('0x77')][_0x8ba0('0x79')][_0x8ba0('0x3e')]){return _0x379254[_0x8ba0('0x77')][_0x8ba0('0x79')][0x0];}return db[_0x8ba0('0x78')][_0x8ba0('0x54')](_['defaults'](_0x54ae31[_0x8ba0('0x55')],{'firstName':_0x5871b4,[_0x2c26aa['mapKey']]:_0x5871b4,'phone':_0x5871b4,'ListId':_0x379254['ListId']}));}})[_0x8ba0('0x2f')](handleEntityNotFound(_0x2d6288,null))[_0x8ba0('0x2f')](function(_0x33300f){if(_0x33300f){_0x4da279=_0x33300f;return db['OpenchannelInteraction'][_0x8ba0('0x53')]({'where':{'ContactId':_0x4da279['id'],'closed':![],'OpenchannelAccountId':_0x379254['id']}})['then'](function(_0x5176e7){if(_0x5176e7){return[_0x5176e7,![]];}return db[_0x8ba0('0x85')][_0x8ba0('0x54')]({'UserId':_0x54ae31[_0x8ba0('0x57')]['id'],'ContactId':_0x4da279['id'],'OpenchannelAccountId':_0x379254['id'],'lastMsgDirection':_0x8ba0('0xaf'),'Messages':[_[_0x8ba0('0x45')](_0x54ae31[_0x8ba0('0x55')],{'read':![],'body':_0x54ae31[_0x8ba0('0x55')][_0x8ba0('0x55')],'OpenchannelAccountId':_0x379254['id'],'UserId':_0x54ae31[_0x8ba0('0x57')]['id'],'ContactId':_0x4da279['id']})]},{'include':[{'model':db[_0x8ba0('0x8d')],'as':_0x8ba0('0xb0')}]})[_0x8ba0('0x2f')](function(_0x1ebc86){return[_0x1ebc86,!![]];});});}})[_0x8ba0('0x87')](function(_0x171e5b,_0xadf022){if(_0xadf022){return _0x171e5b;}return db['OpenchannelMessage']['create'](_['merge'](_0x54ae31['body'],{'read':![],'body':_0x54ae31[_0x8ba0('0x55')][_0x8ba0('0x55')],'OpenchannelAccountId':_0x379254['id'],'OpenchannelInteractionId':_0x171e5b['id'],'UserId':_0x54ae31[_0x8ba0('0x57')]['id'],'ContactId':_0x4da279['id']}))[_0x8ba0('0x2f')](function(_0x1ba693){_0x171e5b[_0x8ba0('0xb1')]['Messages']=[];_0x171e5b['dataValues'][_0x8ba0('0xb0')][_0x8ba0('0xb2')](_0x1ba693['dataValues']);return _0x171e5b;});});}})['then'](respondWithResult(_0x2d6288,null))['catch'](handleError(_0x2d6288,null));};
\ No newline at end of file
+var _0x8f05=['Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','DESC','out','dataValues','Messages','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','message','info','result','catch','sendStatus','status','end','json','undefined','offset','count','set','Content-Range','apply','reject','save','update','then','destroy','get','OpenchannelAccounts','UserProfileResource','name','send','index','Pause','mandatoryDispositionPause','rawAttributes','type','model','map','query','keys','intersection','attributes','fields','nolimit','limit','order','sort','where','filters','filter','merge','options','OpenchannelAccount','include','findAll','rows','show','params','includeAll','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','autoAssociation','body','describe','OpenchannelAccountId','getDispositions','length','hasOwnProperty','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','findOne','pick','removeAnswers','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','isNil','from','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','Contacts','OpenchannelApplication','Applications','account','applications','list','orderBy','ListId','contact','lastName','threadId','OpenchannelInteraction','externalUrl','spread','firstName','messageId','interaction','created','autoclose','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','unshift','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','notify','addApplications','sequelize','Transaction','READ_COMMITTED','priority','finally','getInteractions','Contact','User','fullname','internal'];(function(_0xfb7ee3,_0x6f1f19){var _0x5c061d=function(_0x404867){while(--_0x404867){_0xfb7ee3['push'](_0xfb7ee3['shift']());}};_0x5c061d(++_0x6f1f19);}(_0x8f05,0x17f));var _0x58f0=function(_0x3498e5,_0x1f78fd){_0x3498e5=_0x3498e5-0x0;var _0x3fe3fd=_0x8f05[_0x3498e5];return _0x3fe3fd;};'use strict';var emlformat=require(_0x58f0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x58f0('0x1'));var jsonpatch=require(_0x58f0('0x2'));var rp=require(_0x58f0('0x3'));var moment=require(_0x58f0('0x4'));var BPromise=require(_0x58f0('0x5'));var Mustache=require('mustache');var util=require(_0x58f0('0x6'));var path=require(_0x58f0('0x7'));var sox=require(_0x58f0('0x8'));var csv=require(_0x58f0('0x9'));var ejs=require(_0x58f0('0xa'));var fs=require('fs');var fs_extra=require(_0x58f0('0xb'));var _=require(_0x58f0('0xc'));var squel=require('squel');var crypto=require(_0x58f0('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x58f0('0x9'));var querystring=require(_0x58f0('0xe'));var Papa=require(_0x58f0('0xf'));var Redis=require(_0x58f0('0x10'));var authService=require(_0x58f0('0x11'));var qs=require(_0x58f0('0x12'));var as=require(_0x58f0('0x13'));var hardwareService=require(_0x58f0('0x14'));var logger=require(_0x58f0('0x15'))(_0x58f0('0x16'));var utils=require(_0x58f0('0x17'));var config=require(_0x58f0('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x58f0('0x19'))['db'];config['redis']=_[_0x58f0('0x1a')](config[_0x58f0('0x1b')],{'host':_0x58f0('0x1c'),'port':0x18eb});var socket=require(_0x58f0('0x1d'))(new Redis(config[_0x58f0('0x1b')]));require('./openchannelAccount.socket')[_0x58f0('0x1e')](socket);var jayson=require(_0x58f0('0x1f'));var client=jayson[_0x58f0('0x20')][_0x58f0('0x21')]({'port':0x232c});var client9002=jayson[_0x58f0('0x20')][_0x58f0('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x12e0e4,_0x489422,_0x443eee,_0x53dc8a){return new BPromise(function(_0x4c6156,_0x199ad3){var _0x8a19e0=_0x53dc8a||client;return _0x8a19e0['request'](_0x12e0e4,_0x443eee)['then'](function(_0x3f9df9){logger['info'](_0x58f0('0x22'),_0x489422,_0x58f0('0x23'));logger[_0x58f0('0x24')]('OpenchannelAccount,\x20%s,\x20%s,\x20%s',_0x489422,'request\x20sent',JSON[_0x58f0('0x25')](_0x3f9df9));if(_0x3f9df9[_0x58f0('0x26')]){if(_0x3f9df9['error']['code']===0x1f4){logger[_0x58f0('0x26')](_0x58f0('0x22'),_0x489422,_0x3f9df9[_0x58f0('0x26')][_0x58f0('0x27')]);return _0x199ad3(_0x3f9df9[_0x58f0('0x26')]['message']);}logger[_0x58f0('0x26')]('OpenchannelAccount,\x20%s,\x20%s',_0x489422,_0x3f9df9['error'][_0x58f0('0x27')]);return _0x4c6156(_0x3f9df9[_0x58f0('0x26')][_0x58f0('0x27')]);}else{logger[_0x58f0('0x28')](_0x58f0('0x22'),_0x489422,_0x58f0('0x23'));_0x4c6156(_0x3f9df9[_0x58f0('0x29')][_0x58f0('0x27')]);}})[_0x58f0('0x2a')](function(_0x2bf9cd){logger['error'](_0x58f0('0x22'),_0x489422,_0x2bf9cd);_0x199ad3(_0x2bf9cd);});});}function respondWithStatusCode(_0x50b83e,_0x3ceb4a){_0x3ceb4a=_0x3ceb4a||0xcc;return function(_0x17cff0){if(_0x17cff0){return _0x50b83e[_0x58f0('0x2b')](_0x3ceb4a);}return _0x50b83e[_0x58f0('0x2c')](_0x3ceb4a)[_0x58f0('0x2d')]();};}function respondWithResult(_0x4268e0,_0x4d36c7){_0x4d36c7=_0x4d36c7||0xc8;return function(_0x39efbc){if(_0x39efbc){return _0x4268e0[_0x58f0('0x2c')](_0x4d36c7)[_0x58f0('0x2e')](_0x39efbc);}};}function respondWithFilteredResult(_0x1daaee,_0x2b97fa){return function(_0x4cda3c){if(_0x4cda3c){var _0x5dbfe6=typeof _0x2b97fa['offset']===_0x58f0('0x2f')&&typeof _0x2b97fa['limit']===_0x58f0('0x2f');var _0x429eb8=_0x4cda3c['count'];var _0xf3a9c8=_0x5dbfe6?0x0:_0x2b97fa[_0x58f0('0x30')];var _0x39f473=_0x5dbfe6?_0x4cda3c[_0x58f0('0x31')]:_0x2b97fa[_0x58f0('0x30')]+_0x2b97fa['limit'];var _0x58ea59;if(_0x39f473>=_0x429eb8){_0x39f473=_0x429eb8;_0x58ea59=0xc8;}else{_0x58ea59=0xce;}_0x1daaee[_0x58f0('0x2c')](_0x58ea59);return _0x1daaee[_0x58f0('0x32')](_0x58f0('0x33'),_0xf3a9c8+'-'+_0x39f473+'/'+_0x429eb8)[_0x58f0('0x2e')](_0x4cda3c);}return null;};}function patchUpdates(_0x74562){return function(_0x5da849){try{jsonpatch[_0x58f0('0x34')](_0x5da849,_0x74562,!![]);}catch(_0x10ddde){return BPromise[_0x58f0('0x35')](_0x10ddde);}return _0x5da849[_0x58f0('0x36')]();};}function saveUpdates(_0x2b97de,_0x306f90){return function(_0x471713){if(_0x471713){return _0x471713[_0x58f0('0x37')](_0x2b97de)[_0x58f0('0x38')](function(_0x244f23){return _0x244f23;});}return null;};}function removeEntity(_0x74a521,_0x4f460e){return function(_0x3758a7){if(_0x3758a7){return _0x3758a7[_0x58f0('0x39')]()[_0x58f0('0x38')](function(){var _0x190976=_0x3758a7[_0x58f0('0x3a')]({'plain':!![]});var _0x419392=_0x58f0('0x3b');return db[_0x58f0('0x3c')][_0x58f0('0x39')]({'where':{'type':_0x419392,'resourceId':_0x190976['id']}})['then'](function(){return _0x3758a7;});})[_0x58f0('0x38')](function(){_0x74a521[_0x58f0('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4a8ccc,_0x449c8c){return function(_0x13ad17){if(!_0x13ad17){_0x4a8ccc[_0x58f0('0x2b')](0x194);}return _0x13ad17;};}function handleError(_0x40be99,_0x48fcb2){_0x48fcb2=_0x48fcb2||0x1f4;return function(_0x50461b){logger[_0x58f0('0x26')](_0x50461b['stack']);if(_0x50461b[_0x58f0('0x3d')]){delete _0x50461b[_0x58f0('0x3d')];}_0x40be99[_0x58f0('0x2c')](_0x48fcb2)[_0x58f0('0x3e')](_0x50461b);};}exports[_0x58f0('0x3f')]=function(_0x5cc2bb,_0x347209){var _0x22aab2={'include':[{'model':db[_0x58f0('0x40')],'as':_0x58f0('0x41')}]},_0x63c233={},_0x3a50e0={'count':0x0,'rows':[]};var _0x5b3fc9=_['map'](db['OpenchannelAccount'][_0x58f0('0x42')],function(_0x4a7c79){return{'name':_0x4a7c79['fieldName'],'type':_0x4a7c79[_0x58f0('0x43')]['key']};});_0x63c233[_0x58f0('0x44')]=_[_0x58f0('0x45')](_0x5b3fc9,'name');_0x63c233[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x5cc2bb[_0x58f0('0x46')]);_0x63c233['filters']=_[_0x58f0('0x48')](_0x63c233[_0x58f0('0x44')],_0x63c233[_0x58f0('0x46')]);_0x22aab2[_0x58f0('0x49')]=_[_0x58f0('0x48')](_0x63c233[_0x58f0('0x44')],qs[_0x58f0('0x4a')](_0x5cc2bb[_0x58f0('0x46')]['fields']));_0x22aab2[_0x58f0('0x49')]=_0x22aab2[_0x58f0('0x49')]['length']?_0x22aab2[_0x58f0('0x49')]:_0x63c233[_0x58f0('0x44')];if(!_0x5cc2bb[_0x58f0('0x46')]['hasOwnProperty'](_0x58f0('0x4b'))){_0x22aab2[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x5cc2bb[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x22aab2[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x5cc2bb[_0x58f0('0x46')]['offset']);}_0x22aab2[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x5cc2bb[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x22aab2[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_['pick'](_0x5cc2bb['query'],_0x63c233[_0x58f0('0x50')]),_0x5b3fc9);if(_0x5cc2bb[_0x58f0('0x46')][_0x58f0('0x51')]){_0x22aab2[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x22aab2[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x5b3fc9,function(_0x18c063){if(_0x18c063[_0x58f0('0x43')]!=='VIRTUAL'){var _0x4acba2={};_0x4acba2[_0x18c063[_0x58f0('0x3d')]]={'$like':'%'+_0x5cc2bb['query'][_0x58f0('0x51')]+'%'};return _0x4acba2;}})});}_0x22aab2=_['merge']({},_0x22aab2,_0x5cc2bb[_0x58f0('0x53')]);var _0x17de75={'where':_0x22aab2[_0x58f0('0x4f')]};return db[_0x58f0('0x54')][_0x58f0('0x31')](_0x17de75)['then'](function(_0x229d8e){_0x3a50e0['count']=_0x229d8e;if(_0x5cc2bb[_0x58f0('0x46')]['includeAll']){_0x22aab2[_0x58f0('0x55')]=[{'all':!![]}];}return db[_0x58f0('0x54')][_0x58f0('0x56')](_0x22aab2);})[_0x58f0('0x38')](function(_0x539f18){_0x3a50e0[_0x58f0('0x57')]=_0x539f18;return _0x3a50e0;})[_0x58f0('0x38')](respondWithFilteredResult(_0x347209,_0x22aab2))[_0x58f0('0x2a')](handleError(_0x347209,null));};exports[_0x58f0('0x58')]=function(_0x361507,_0x57b2b1){var _0x18eca3={'raw':![],'where':{'id':_0x361507[_0x58f0('0x59')]['id']},'include':[{'model':db[_0x58f0('0x40')],'as':_0x58f0('0x41')}]},_0x1dbdbf={};_0x1dbdbf['model']=_[_0x58f0('0x47')](db[_0x58f0('0x54')][_0x58f0('0x42')]);_0x1dbdbf[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x361507[_0x58f0('0x46')]);_0x1dbdbf[_0x58f0('0x50')]=_[_0x58f0('0x48')](_0x1dbdbf[_0x58f0('0x44')],_0x1dbdbf[_0x58f0('0x46')]);_0x18eca3[_0x58f0('0x49')]=_['intersection'](_0x1dbdbf[_0x58f0('0x44')],qs['fields'](_0x361507['query'][_0x58f0('0x4a')]));_0x18eca3[_0x58f0('0x49')]=_0x18eca3[_0x58f0('0x49')]['length']?_0x18eca3[_0x58f0('0x49')]:_0x1dbdbf[_0x58f0('0x44')];if(_0x361507[_0x58f0('0x46')][_0x58f0('0x5a')]){_0x18eca3['include']=[{'all':!![]}];}_0x18eca3=_[_0x58f0('0x52')]({},_0x18eca3,_0x361507[_0x58f0('0x53')]);return db[_0x58f0('0x54')][_0x58f0('0x5b')](_0x18eca3)['then'](handleEntityNotFound(_0x57b2b1,null))['then'](respondWithResult(_0x57b2b1,null))[_0x58f0('0x2a')](handleError(_0x57b2b1,null));};exports['create']=function(_0x1e2082,_0x3e02ad){return db[_0x58f0('0x54')][_0x58f0('0x5c')](_0x1e2082['body'],{})[_0x58f0('0x38')](function(_0x272f38){var _0x2dbf6d=_0x1e2082[_0x58f0('0x5d')][_0x58f0('0x3a')]({'plain':!![]});if(!_0x2dbf6d)throw new Error(_0x58f0('0x5e'));if(_0x2dbf6d[_0x58f0('0x5f')]===_0x58f0('0x5d')){var _0x30e8dc=_0x272f38[_0x58f0('0x3a')]({'plain':!![]});var _0x6381f3=_0x58f0('0x3b');return db['UserProfileSection'][_0x58f0('0x5b')]({'where':{'name':_0x6381f3,'userProfileId':_0x2dbf6d['userProfileId']},'raw':!![]})['then'](function(_0x5c6a6b){if(_0x5c6a6b&&_0x5c6a6b[_0x58f0('0x60')]===0x0){return db[_0x58f0('0x3c')]['create']({'name':_0x30e8dc[_0x58f0('0x3d')],'resourceId':_0x30e8dc['id'],'type':_0x5c6a6b[_0x58f0('0x3d')],'sectionId':_0x5c6a6b['id']},{})[_0x58f0('0x38')](function(){return _0x272f38;});}else{return _0x272f38;}})[_0x58f0('0x2a')](function(_0x4b5e56){logger[_0x58f0('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4b5e56);throw _0x4b5e56;});}return _0x272f38;})[_0x58f0('0x38')](respondWithResult(_0x3e02ad,0xc9))[_0x58f0('0x2a')](handleError(_0x3e02ad,null));};exports[_0x58f0('0x37')]=function(_0x35a148,_0x114329){if(_0x35a148[_0x58f0('0x61')]['id']){delete _0x35a148[_0x58f0('0x61')]['id'];}return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x35a148[_0x58f0('0x59')]['id']},'include':[{'model':db[_0x58f0('0x40')],'as':_0x58f0('0x41')}]})['then'](handleEntityNotFound(_0x114329,null))[_0x58f0('0x38')](saveUpdates(_0x35a148[_0x58f0('0x61')],null))[_0x58f0('0x38')](respondWithResult(_0x114329,null))['catch'](handleError(_0x114329,null));};exports[_0x58f0('0x39')]=function(_0x360aeb,_0x8af34c){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x360aeb[_0x58f0('0x59')]['id']}})['then'](handleEntityNotFound(_0x8af34c,null))[_0x58f0('0x38')](removeEntity(_0x8af34c,null))[_0x58f0('0x2a')](handleError(_0x8af34c,null));};exports[_0x58f0('0x62')]=function(_0x154e33,_0x49daa1){return db[_0x58f0('0x54')][_0x58f0('0x62')]()[_0x58f0('0x38')](respondWithResult(_0x49daa1,null))[_0x58f0('0x2a')](handleError(_0x49daa1,null));};exports['addDisposition']=function(_0x47b142,_0x20cbdb,_0x163b13){if(_0x47b142[_0x58f0('0x61')]['id']){delete _0x47b142['body']['id'];}return db['OpenchannelAccount'][_0x58f0('0x5b')]({'where':{'id':_0x47b142['params']['id']}})['then'](handleEntityNotFound(_0x20cbdb,null))['then'](function(_0xee0d0a){if(_0xee0d0a){_0x47b142[_0x58f0('0x61')][_0x58f0('0x63')]=_0xee0d0a['id'];return db['Disposition'][_0x58f0('0x5c')](_0x47b142[_0x58f0('0x61')]);}})['then'](respondWithResult(_0x20cbdb,null))['catch'](handleError(_0x20cbdb,null));};exports[_0x58f0('0x64')]=function(_0x1fd60c,_0x5e4212,_0x13399e){var _0x58f606={'raw':![],'where':{}};var _0x5a7e84={};var _0x2da62a={'count':0x0,'rows':[]};return db[_0x58f0('0x54')]['findOne']({'where':{'id':_0x1fd60c['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x5e4212,null))[_0x58f0('0x38')](function(_0x44339f){if(_0x44339f){_0x5a7e84[_0x58f0('0x44')]=_[_0x58f0('0x47')](db['Disposition']['rawAttributes']);_0x5a7e84['query']=_[_0x58f0('0x47')](_0x1fd60c[_0x58f0('0x46')]);_0x5a7e84[_0x58f0('0x50')]=_[_0x58f0('0x48')](_0x5a7e84[_0x58f0('0x44')],_0x5a7e84[_0x58f0('0x46')]);_0x58f606['attributes']=_[_0x58f0('0x48')](_0x5a7e84['model'],qs['fields'](_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x58f606[_0x58f0('0x49')]=_0x58f606['attributes'][_0x58f0('0x65')]?_0x58f606['attributes']:_0x5a7e84['model'];if(!_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x66')](_0x58f0('0x4b'))){_0x58f606[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x58f606[_0x58f0('0x30')]=qs['offset'](_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x30')]);}_0x58f606['order']=qs[_0x58f0('0x4e')](_0x1fd60c[_0x58f0('0x46')]['sort']);_0x58f606[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_['pick'](_0x1fd60c[_0x58f0('0x46')],_0x5a7e84[_0x58f0('0x50')]));_0x58f606['where']['OpenchannelAccountId']=_0x44339f['id'];if(_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x51')]){_0x58f606[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x58f606[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x58f606[_0x58f0('0x49')],function(_0x219fe6){var _0x1d6f2e={};_0x1d6f2e[_0x219fe6]={'$like':'%'+_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x51')]+'%'};return _0x1d6f2e;})});}_0x58f606=_[_0x58f0('0x52')]({},_0x58f606,_0x1fd60c[_0x58f0('0x53')]);return db[_0x58f0('0x67')]['count']({'where':_0x58f606[_0x58f0('0x4f')]})[_0x58f0('0x38')](function(_0x5162f8){_0x2da62a[_0x58f0('0x31')]=_0x5162f8;if(_0x1fd60c[_0x58f0('0x46')][_0x58f0('0x5a')]){_0x58f606[_0x58f0('0x55')]=[{'all':!![]}];}return db[_0x58f0('0x67')][_0x58f0('0x56')](_0x58f606);})[_0x58f0('0x38')](function(_0x23a3cb){_0x2da62a[_0x58f0('0x57')]=_0x23a3cb;return _0x2da62a;});}})['then'](respondWithFilteredResult(_0x5e4212,_0x58f606))[_0x58f0('0x2a')](handleError(_0x5e4212,null));};exports[_0x58f0('0x68')]=function(_0x3febeb,_0x15c963,_0x50d54f){return db[_0x58f0('0x54')]['find']({'where':{'id':_0x3febeb[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x15c963,null))[_0x58f0('0x38')](function(_0x1b81f3){if(_0x1b81f3){return _0x1b81f3['removeDispositions'](_0x3febeb['query'][_0x58f0('0x69')]);}})[_0x58f0('0x38')](respondWithStatusCode(_0x15c963,null))[_0x58f0('0x2a')](handleError(_0x15c963,null));};exports[_0x58f0('0x6a')]=function(_0x3cd443,_0xbb1b9a,_0x5a4952){if(_0x3cd443[_0x58f0('0x61')]['id']){delete _0x3cd443[_0x58f0('0x61')]['id'];}return db[_0x58f0('0x54')]['find']({'where':{'id':_0x3cd443[_0x58f0('0x59')]['id']}})['then'](handleEntityNotFound(_0xbb1b9a,null))[_0x58f0('0x38')](function(_0x6d67cf){if(_0x6d67cf){_0x3cd443[_0x58f0('0x61')][_0x58f0('0x63')]=_0x6d67cf['id'];return db[_0x58f0('0x6b')][_0x58f0('0x5c')](_0x3cd443['body']);}})[_0x58f0('0x38')](respondWithResult(_0xbb1b9a,null))[_0x58f0('0x2a')](handleError(_0xbb1b9a,null));};exports['getAnswers']=function(_0x2b5833,_0x10b301,_0x3f7b03){var _0x56980b={'raw':![],'where':{}};var _0x3cb448={};var _0x1057f0={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x58f0('0x6c')]({'where':{'id':_0x2b5833[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x10b301,null))['then'](function(_0xca4ca8){if(_0xca4ca8){_0x3cb448[_0x58f0('0x44')]=_[_0x58f0('0x47')](db[_0x58f0('0x6b')][_0x58f0('0x42')]);_0x3cb448[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x2b5833[_0x58f0('0x46')]);_0x3cb448[_0x58f0('0x50')]=_['intersection'](_0x3cb448['model'],_0x3cb448[_0x58f0('0x46')]);_0x56980b[_0x58f0('0x49')]=_[_0x58f0('0x48')](_0x3cb448[_0x58f0('0x44')],qs[_0x58f0('0x4a')](_0x2b5833[_0x58f0('0x46')]['fields']));_0x56980b[_0x58f0('0x49')]=_0x56980b[_0x58f0('0x49')][_0x58f0('0x65')]?_0x56980b[_0x58f0('0x49')]:_0x3cb448[_0x58f0('0x44')];if(!_0x2b5833[_0x58f0('0x46')][_0x58f0('0x66')]('nolimit')){_0x56980b[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x2b5833[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x56980b[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x2b5833[_0x58f0('0x46')][_0x58f0('0x30')]);}_0x56980b[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x2b5833[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x56980b[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_[_0x58f0('0x6d')](_0x2b5833[_0x58f0('0x46')],_0x3cb448['filters']));_0x56980b[_0x58f0('0x4f')][_0x58f0('0x63')]=_0xca4ca8['id'];if(_0x2b5833[_0x58f0('0x46')][_0x58f0('0x51')]){_0x56980b[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x56980b[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x56980b[_0x58f0('0x49')],function(_0x576c73){var _0x19f538={};_0x19f538[_0x576c73]={'$like':'%'+_0x2b5833[_0x58f0('0x46')]['filter']+'%'};return _0x19f538;})});}_0x56980b=_[_0x58f0('0x52')]({},_0x56980b,_0x2b5833[_0x58f0('0x53')]);return db[_0x58f0('0x6b')][_0x58f0('0x31')]({'where':_0x56980b[_0x58f0('0x4f')]})[_0x58f0('0x38')](function(_0x4dd35f){_0x1057f0['count']=_0x4dd35f;if(_0x2b5833[_0x58f0('0x46')][_0x58f0('0x5a')]){_0x56980b[_0x58f0('0x55')]=[{'all':!![]}];}return db[_0x58f0('0x6b')]['findAll'](_0x56980b);})[_0x58f0('0x38')](function(_0x53c34c){_0x1057f0['rows']=_0x53c34c;return _0x1057f0;});}})['then'](respondWithFilteredResult(_0x10b301,_0x56980b))['catch'](handleError(_0x10b301,null));};exports[_0x58f0('0x6e')]=function(_0x1ba9fd,_0x40e186,_0x1a963b){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x1ba9fd['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x40e186,null))['then'](function(_0x45eb6b){if(_0x45eb6b){return _0x45eb6b['removeAnswers'](_0x1ba9fd[_0x58f0('0x46')][_0x58f0('0x69')]);}})['then'](respondWithStatusCode(_0x40e186,null))[_0x58f0('0x2a')](handleError(_0x40e186,null));};exports['notify']=function(_0x5c9e6a,_0x4fb206,_0x3edcff){var _0x5f0af5={'body':_0x5c9e6a[_0x58f0('0x61')],'channel':_0x58f0('0x6f')};var _0x4b0de9=[];var _0x351787=[];var _0x70b4ab={};var _0x30c024=![];return db[_0x58f0('0x70')]['describe']()[_0x58f0('0x38')](function(_0x3992f0){if(!_0x3992f0){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))](_0x58f0('0x73'));}_0x4b0de9=_[_0x58f0('0x74')](_[_0x58f0('0x47')](_0x3992f0),[_0x58f0('0x75'),'updatedAt']);_0x351787=_['difference'](_[_0x58f0('0x47')](_0x3992f0),[_0x58f0('0x75'),_0x58f0('0x76'),'CompanyId','ListId']);if(_0x5c9e6a[_0x58f0('0x61')]['id']){delete _0x5c9e6a[_0x58f0('0x61')]['id'];}if(_[_0x58f0('0x77')](_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x78')])){throw new db['Sequelize'][(_0x58f0('0x72'))]('from\x20is\x20mandatory');}if(_[_0x58f0('0x77')](_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x61')])||_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x61')]===''){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x58f0('0x77')](_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x79')])){throw new db[(_0x58f0('0x71'))]['ValidationError'](_0x58f0('0x7a')+_0x351787);}if(!_[_0x58f0('0x7b')](_0x351787,_0x5c9e6a['body'][_0x58f0('0x79')])){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))](_0x58f0('0x7c')+_0x351787);}_0x70b4ab[_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x79')]]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x78')];})[_0x58f0('0x38')](function(){return db['OpenchannelAccount'][_0x58f0('0x5b')]({'where':{'id':_0x5c9e6a[_0x58f0('0x59')]['id']},'include':[{'model':db['CmList'],'as':_0x58f0('0x7d'),'include':[{'model':db[_0x58f0('0x70')],'as':_0x58f0('0x7e'),'where':_0x70b4ab,'limit':0x1,'order':[[_0x58f0('0x76'),'DESC']]}]},{'model':db[_0x58f0('0x7f')],'as':_0x58f0('0x80')}]});})[_0x58f0('0x38')](handleEntityNotFound(_0x4fb206,null))['then'](function(_0x46bbf1){if(_0x46bbf1&&_0x46bbf1[_0x58f0('0x7d')]){_0x5f0af5[_0x58f0('0x81')]=_0x46bbf1;_0x5f0af5[_0x58f0('0x82')]=_0x46bbf1['Applications'];_0x5f0af5[_0x58f0('0x83')]=_0x46bbf1['List'];_0x5f0af5['applications']=_[_0x58f0('0x84')](_0x5f0af5[_0x58f0('0x82')],['priority'],['asc']);if(_0x5f0af5[_0x58f0('0x81')][_0x58f0('0x80')]){delete _0x5f0af5[_0x58f0('0x81')][_0x58f0('0x80')];}if(_0x5f0af5[_0x58f0('0x81')]['List']&&_0x5f0af5[_0x58f0('0x81')][_0x58f0('0x7d')][_0x58f0('0x7e')][_0x58f0('0x65')]){return _0x5f0af5[_0x58f0('0x81')][_0x58f0('0x7d')]['Contacts'][0x0];}var _0x19d5ba=_[_0x58f0('0x1a')](_0x5c9e6a[_0x58f0('0x61')],{'firstName':_0x5c9e6a[_0x58f0('0x61')]['from'],'ListId':_0x46bbf1[_0x58f0('0x85')]});_0x19d5ba[_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x79')]]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x78')];return db[_0x58f0('0x70')][_0x58f0('0x5c')](_0x19d5ba,{'fields':_0x4b0de9,'raw':!![]});}})[_0x58f0('0x38')](handleEntityNotFound(_0x4fb206,null))[_0x58f0('0x38')](function(_0x2cac81){_0x5f0af5[_0x58f0('0x86')]=_0x2cac81;if(_0x2cac81){var _0x4de82b={'ContactId':_0x2cac81['id'],'OpenchannelAccountId':_0x5c9e6a[_0x58f0('0x59')]['id'],'from':(_0x2cac81['firstName']||'')+'\x20'+(_0x2cac81[_0x58f0('0x87')]||'')};var _0x5ae696={'OpenchannelAccountId':_0x5c9e6a[_0x58f0('0x59')]['id'],'closed':![]};if(_0x5c9e6a['body'][_0x58f0('0x88')]){_0x5ae696[_0x58f0('0x88')]=_0x5c9e6a[_0x58f0('0x61')]['threadId'];return db[_0x58f0('0x89')][_0x58f0('0x5b')]({'where':_0x5ae696})['then'](function(_0xb8b7b7){if(_0xb8b7b7){return[_0xb8b7b7,![]];}_0x4de82b[_0x58f0('0x88')]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x88')];_0x4de82b[_0x58f0('0x8a')]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x8a')];return db[_0x58f0('0x89')][_0x58f0('0x5c')](_0x4de82b)['then'](function(_0x16ad6a){return[_0x16ad6a,!![]];});});}else{_0x5ae696[_0x58f0('0x88')]=null;}_0x5ae696['ContactId']=_0x2cac81['id'];return db[_0x58f0('0x89')][_0x58f0('0x5b')]({'where':_0x5ae696})[_0x58f0('0x38')](function(_0x40a707){if(_0x40a707){return[_0x40a707,![]];}return db['OpenchannelInteraction']['create'](_0x4de82b)[_0x58f0('0x38')](function(_0x5869d2){return[_0x5869d2,!![]];});});}})[_0x58f0('0x8b')](function(_0x2fc394,_0x2c602d){if(_0x2fc394){_0x30c024=_0x2c602d;if(!_0x2c602d){var _0x3a2d08={'from':(_0x5f0af5[_0x58f0('0x86')][_0x58f0('0x8c')]||'')+'\x20'+(_0x5f0af5[_0x58f0('0x86')][_0x58f0('0x87')]||'')};if(_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x88')]&&_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x8d')]&&_0x5c9e6a['body'][_0x58f0('0x88')]!=_0x5c9e6a[_0x58f0('0x61')]['messageId']){_0x3a2d08[_0x58f0('0x88')]=_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x8d')];}return _0x2fc394['update'](_0x3a2d08);}else{return _0x2fc394;}}})[_0x58f0('0x38')](function(_0x1177d7){_0x5f0af5[_0x58f0('0x8e')]=_0x1177d7[_0x58f0('0x3a')]({'plain':!![]});_0x5f0af5['interaction'][_0x58f0('0x8f')]=_0x30c024;if(_0x5f0af5[_0x58f0('0x8e')][_0x58f0('0x8f')]){if(_0x5f0af5['account'][_0x58f0('0x90')]){_0x5f0af5['applications']['push']({'id':0x0,'priority':_0x5f0af5[_0x58f0('0x82')][_0x58f0('0x65')]+0x1,'app':_0x58f0('0x91'),'appdata':_0x58f0('0x92'),'interval':_0x58f0('0x93')});}}return db[_0x58f0('0x94')][_0x58f0('0x5c')]({'body':_0x5c9e6a['body'][_0x58f0('0x61')],'OpenchannelAccountId':_0x5c9e6a[_0x58f0('0x59')]['id'],'OpenchannelInteractionId':_0x1177d7['id'],'direction':'in','ContactId':_0x5f0af5[_0x58f0('0x86')]['id'],'AttachmentId':_0x5c9e6a[_0x58f0('0x61')][_0x58f0('0x95')]});})[_0x58f0('0x38')](function(_0x3ded16){_0x5f0af5[_0x58f0('0x27')]=_0x3ded16;if(_0x5f0af5[_0x58f0('0x8e')]['UserId']){return db['User'][_0x58f0('0x5b')]({'attributes':['id',_0x58f0('0x3d')],'where':{'id':_0x5f0af5['interaction'][_0x58f0('0x96')]}})[_0x58f0('0x38')](function(_0x1adf3b){if(_0x1adf3b){_0x5f0af5['applications'][_0x58f0('0x97')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x1adf3b[_0x58f0('0x3d')]+','+(_0x5f0af5[_0x58f0('0x81')][_0x58f0('0x98')]||0xa),'interval':_0x58f0('0x93')});_0x5f0af5[_0x58f0('0x99')]=![];}return respondWithRpcPromise(_0x58f0('0x9a'),_0x58f0('0x9b'),_0x5f0af5);});}return respondWithRpcPromise(_0x58f0('0x9a'),_0x58f0('0x9b'),_0x5f0af5);})[_0x58f0('0x38')](function(_0x5102c1){respondWithRpcPromise(_0x58f0('0x9c'),_0x58f0('0x9c'),{'event':_0x58f0('0x9d'),'message':_0x5102c1},client9002);return _0x5102c1;})[_0x58f0('0x38')](respondWithResult(_0x4fb206,null))[_0x58f0('0x2a')](handleError(_0x4fb206,null));};exports[_0x58f0('0x9e')]=function(_0x466a5c,_0x2abe6f){var _0x329c33=_0x466a5c[_0x58f0('0x59')]['id'];var _0x262631=_0x466a5c[_0x58f0('0x61')];var _0x1c080b=0xc8;var _0x551f65=null;return db[_0x58f0('0x9f')]['transaction']({'isolationLevel':db['sequelize'][_0x58f0('0xa0')]['ISOLATION_LEVELS'][_0x58f0('0xa1')]},function(_0x367901){return db[_0x58f0('0x54')][_0x58f0('0x6c')]({'where':{'id':_0x329c33},'transaction':_0x367901})[_0x58f0('0x38')](function(_0x392e6b){if(_0x392e6b){return db[_0x58f0('0x7f')]['destroy']({'where':{'OpenchannelAccountId':_0x329c33},'transaction':_0x367901})[_0x58f0('0x38')](function(){var _0xc85dd5=_['map'](_0x262631,function(_0x1e68ab){_0x1e68ab[_0x58f0('0x63')]=_0x329c33;return _0x1e68ab;});return db[_0x58f0('0x7f')]['bulkCreate'](_0xc85dd5,{'transaction':_0x367901});});}else{_0x1c080b=0x194;_0x551f65=[];}});})[_0x58f0('0x38')](function(){if(_0x1c080b!==0x194){return db[_0x58f0('0x7f')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0x329c33},'order':_0x58f0('0xa2')})['then'](function(_0x5d2e84){_0x551f65=_0x5d2e84;});}})[_0x58f0('0x2a')](function(_0x4f06dd){_0x1c080b=0x1f4;logger['error'](_0x4f06dd['stack']);if(_0x4f06dd[_0x58f0('0x3d')]){delete _0x4f06dd[_0x58f0('0x3d')];}_0x551f65=_0x4f06dd;})[_0x58f0('0xa3')](function(){if(_0x551f65===null){_0x2abe6f[_0x58f0('0x2b')](_0x1c080b);}else{if(_0x1c080b===0x1f4){_0x2abe6f[_0x58f0('0x2c')](_0x1c080b)[_0x58f0('0x3e')](_0x551f65);}else{_0x2abe6f[_0x58f0('0x2c')](_0x1c080b)['json'](_0x551f65);}}});};exports['getApplications']=function(_0x13180a,_0x30c12b,_0x30d644){var _0x3ccf7a={};var _0x18a63e={};var _0x379fb9;var _0x5882ed;return db[_0x58f0('0x54')]['findOne']({'where':{'id':_0x13180a['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x30c12b,null))['then'](function(_0x5e370a){if(_0x5e370a){_0x379fb9=_0x5e370a;_0x18a63e[_0x58f0('0x44')]=_['keys'](db[_0x58f0('0x7f')][_0x58f0('0x42')]);_0x18a63e[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x13180a['query']);_0x18a63e['filters']=_[_0x58f0('0x48')](_0x18a63e[_0x58f0('0x44')],_0x18a63e[_0x58f0('0x46')]);_0x3ccf7a['attributes']=_[_0x58f0('0x48')](_0x18a63e['model'],qs[_0x58f0('0x4a')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x3ccf7a['attributes']=_0x3ccf7a[_0x58f0('0x49')][_0x58f0('0x65')]?_0x3ccf7a[_0x58f0('0x49')]:_0x18a63e[_0x58f0('0x44')];_0x3ccf7a[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x3ccf7a[_0x58f0('0x4f')]=qs['filters'](_[_0x58f0('0x6d')](_0x13180a['query'],_0x18a63e[_0x58f0('0x50')]));if(_0x13180a[_0x58f0('0x46')]['filter']){_0x3ccf7a[_0x58f0('0x4f')]=_[_0x58f0('0x52')](_0x3ccf7a[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x3ccf7a[_0x58f0('0x49')],function(_0x14a5fc){var _0x3a1e5d={};_0x3a1e5d[_0x14a5fc]={'$like':'%'+_0x13180a[_0x58f0('0x46')][_0x58f0('0x51')]+'%'};return _0x3a1e5d;})});}_0x3ccf7a=_[_0x58f0('0x52')]({},_0x3ccf7a,_0x13180a[_0x58f0('0x53')]);return _0x379fb9['getApplications'](_0x3ccf7a);}})[_0x58f0('0x38')](function(_0x6fd16e){if(_0x6fd16e){_0x5882ed=_0x6fd16e[_0x58f0('0x65')];if(!_0x13180a['query']['hasOwnProperty'](_0x58f0('0x4b'))){_0x3ccf7a[_0x58f0('0x4c')]=qs[_0x58f0('0x4c')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x3ccf7a[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x13180a[_0x58f0('0x46')][_0x58f0('0x30')]);}return _0x379fb9['getApplications'](_0x3ccf7a);}})[_0x58f0('0x38')](function(_0x53b0ed){if(_0x53b0ed){return _0x53b0ed?{'count':_0x5882ed,'rows':_0x53b0ed}:null;}})[_0x58f0('0x38')](respondWithResult(_0x30c12b,null))[_0x58f0('0x2a')](handleError(_0x30c12b,null));};exports[_0x58f0('0xa4')]=function(_0x1931f5,_0x1028fc,_0x5ad008){var _0x203052={'raw':![],'where':{}};var _0x3d91b5={};var _0x37a801={'count':0x0,'rows':[]};return db[_0x58f0('0x54')][_0x58f0('0x6c')]({'where':{'id':_0x1931f5[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x1028fc,null))[_0x58f0('0x38')](function(_0x3df0bf){if(_0x3df0bf){_0x3d91b5[_0x58f0('0x44')]=_['keys'](db[_0x58f0('0x89')][_0x58f0('0x42')]);_0x3d91b5[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x1931f5[_0x58f0('0x46')]);_0x3d91b5['filters']=_['intersection'](_0x3d91b5[_0x58f0('0x44')],_0x3d91b5[_0x58f0('0x46')]);_0x203052['attributes']=_[_0x58f0('0x48')](_0x3d91b5[_0x58f0('0x44')],qs[_0x58f0('0x4a')](_0x1931f5[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x203052[_0x58f0('0x49')]=_0x203052[_0x58f0('0x49')][_0x58f0('0x65')]?_0x203052[_0x58f0('0x49')]:_0x3d91b5[_0x58f0('0x44')];if(!_0x1931f5['query'][_0x58f0('0x66')](_0x58f0('0x4b'))){_0x203052['limit']=qs[_0x58f0('0x4c')](_0x1931f5[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x203052[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x1931f5[_0x58f0('0x46')][_0x58f0('0x30')]);}_0x203052[_0x58f0('0x4d')]=qs[_0x58f0('0x4e')](_0x1931f5[_0x58f0('0x46')]['sort']);_0x203052['where']=qs['filters'](_[_0x58f0('0x6d')](_0x1931f5[_0x58f0('0x46')],_0x3d91b5[_0x58f0('0x50')]));_0x203052[_0x58f0('0x4f')][_0x58f0('0x63')]=_0x3df0bf['id'];if(_0x1931f5[_0x58f0('0x46')][_0x58f0('0x51')]){_0x203052[_0x58f0('0x4f')]=_['merge'](_0x203052[_0x58f0('0x4f')],{'$or':_[_0x58f0('0x45')](_0x203052[_0x58f0('0x49')],function(_0x203d6d){var _0xda5328={};_0xda5328[_0x203d6d]={'$like':'%'+_0x1931f5['query'][_0x58f0('0x51')]+'%'};return _0xda5328;})});}_0x203052=_[_0x58f0('0x52')]({},_0x203052,_0x1931f5[_0x58f0('0x53')]);return db[_0x58f0('0x89')][_0x58f0('0x31')]({'where':_0x203052[_0x58f0('0x4f')]})[_0x58f0('0x38')](function(_0x6c96cc){_0x37a801['count']=_0x6c96cc;if(_0x1931f5[_0x58f0('0x46')]['includeAll']){_0x203052[_0x58f0('0x55')]=[{'model':db[_0x58f0('0x70')],'as':_0x58f0('0xa5'),'required':![]},{'model':db[_0x58f0('0xa6')],'as':'Owner','attributes':[_0x58f0('0x3d'),_0x58f0('0xa7'),_0x58f0('0xa8')],'required':![]},{'model':db['Tag'],'as':_0x58f0('0xa9'),'attributes':['id',_0x58f0('0x3d'),_0x58f0('0xaa')],'where':_0x1931f5[_0x58f0('0x46')][_0x58f0('0xab')]?{'id':_0x1931f5[_0x58f0('0x46')]['tag']}:undefined,'required':_0x1931f5[_0x58f0('0x46')][_0x58f0('0xab')]?!![]:![]}];}return db[_0x58f0('0x89')][_0x58f0('0x56')](_0x203052);})['then'](function(_0x3653b1){_0x37a801[_0x58f0('0x57')]=_0x3653b1;return _0x37a801;});}})[_0x58f0('0x38')](respondWithFilteredResult(_0x1028fc,_0x203052))[_0x58f0('0x2a')](handleError(_0x1028fc,null));};exports[_0x58f0('0xac')]=function(_0x91c507,_0x2cdd80,_0xad6b3d){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x91c507['params']['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x2cdd80,null))['then'](function(_0x1dc19f){if(_0x1dc19f){return _0x1dc19f['addAgents'](_0x91c507[_0x58f0('0x61')][_0x58f0('0x69')],_['omit'](_0x91c507[_0x58f0('0x61')],['ids','id'])||{})[_0x58f0('0x8b')](function(_0x4951cf){for(var _0x1385e3=0x0;_0x1385e3<_0x91c507[_0x58f0('0x61')][_0x58f0('0x69')]['length'];_0x1385e3+=0x1){socket[_0x58f0('0xad')](_0x58f0('0xae'),{'UserId':Number(_0x91c507['body']['ids'][_0x1385e3]),'OpenchannelAccountId':Number(_0x91c507[_0x58f0('0x59')]['id'])});}return _0x4951cf;});}})['then'](respondWithResult(_0x2cdd80,null))['catch'](handleError(_0x2cdd80,null));};exports[_0x58f0('0xaf')]=function(_0x1db992,_0x567f43,_0x1ef876){return db[_0x58f0('0x54')]['find']({'where':{'id':_0x1db992[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x567f43,null))[_0x58f0('0x38')](function(_0x52dba2){if(_0x52dba2){return _0x52dba2['removeAgents'](_0x1db992[_0x58f0('0x46')]['ids'])[_0x58f0('0x38')](function(){if(_[_0x58f0('0xb0')](_0x1db992['query'][_0x58f0('0x69')])){for(var _0x36cf2b=0x0;_0x36cf2b<_0x1db992['query'][_0x58f0('0x69')]['length'];_0x36cf2b+=0x1){socket[_0x58f0('0xad')](_0x58f0('0xb1'),{'UserId':Number(_0x1db992['query'][_0x58f0('0x69')][_0x36cf2b]),'OpenchannelAccountId':Number(_0x1db992[_0x58f0('0x59')]['id'])});}}else{socket[_0x58f0('0xad')]('userOpenchannelAccount:remove',{'UserId':Number(_0x1db992['query'][_0x58f0('0x69')]),'OpenchannelAccountId':Number(_0x1db992[_0x58f0('0x59')]['id'])});}});}})[_0x58f0('0x38')](respondWithStatusCode(_0x567f43,null))[_0x58f0('0x2a')](handleError(_0x567f43,null));};exports[_0x58f0('0xb2')]=function(_0x100526,_0x34d7df,_0x297ce3){var _0x2b7f7a={};var _0x5bc936={};var _0x42a593;var _0x2de332;return db[_0x58f0('0x54')][_0x58f0('0x6c')]({'where':{'id':_0x100526[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x34d7df,null))[_0x58f0('0x38')](function(_0x21f134){if(_0x21f134){_0x42a593=_0x21f134;_0x5bc936[_0x58f0('0x44')]=_['keys'](db['User']['rawAttributes']);_0x5bc936[_0x58f0('0x46')]=_[_0x58f0('0x47')](_0x100526[_0x58f0('0x46')]);_0x5bc936[_0x58f0('0x50')]=_['intersection'](_0x5bc936[_0x58f0('0x44')],_0x5bc936[_0x58f0('0x46')]);_0x2b7f7a[_0x58f0('0x49')]=_[_0x58f0('0x48')](_0x5bc936[_0x58f0('0x44')],qs['fields'](_0x100526[_0x58f0('0x46')][_0x58f0('0x4a')]));_0x2b7f7a['attributes']=_0x2b7f7a[_0x58f0('0x49')][_0x58f0('0x65')]?_0x2b7f7a['attributes']:_0x5bc936[_0x58f0('0x44')];_0x2b7f7a[_0x58f0('0x4d')]=qs['sort'](_0x100526[_0x58f0('0x46')][_0x58f0('0x4e')]);_0x2b7f7a[_0x58f0('0x4f')]=qs[_0x58f0('0x50')](_[_0x58f0('0x6d')](_0x100526[_0x58f0('0x46')],_0x5bc936[_0x58f0('0x50')]));if(_0x100526['query'][_0x58f0('0x51')]){_0x2b7f7a[_0x58f0('0x4f')]=_['merge'](_0x2b7f7a[_0x58f0('0x4f')],{'$or':_['map'](_0x2b7f7a['attributes'],function(_0x54b024){var _0x4caa27={};_0x4caa27[_0x54b024]={'$like':'%'+_0x100526[_0x58f0('0x46')][_0x58f0('0x51')]+'%'};return _0x4caa27;})});}_0x2b7f7a=_[_0x58f0('0x52')]({},_0x2b7f7a,_0x100526['options']);return _0x42a593['getAgents'](_0x2b7f7a);}})[_0x58f0('0x38')](function(_0x3f0bf8){if(_0x3f0bf8){_0x2de332=_0x3f0bf8[_0x58f0('0x65')];if(!_0x100526['query']['hasOwnProperty'](_0x58f0('0x4b'))){_0x2b7f7a['limit']=qs[_0x58f0('0x4c')](_0x100526[_0x58f0('0x46')][_0x58f0('0x4c')]);_0x2b7f7a[_0x58f0('0x30')]=qs[_0x58f0('0x30')](_0x100526['query'][_0x58f0('0x30')]);}return _0x42a593[_0x58f0('0xb2')](_0x2b7f7a);}})['then'](function(_0xac19a3){if(_0xac19a3){return _0xac19a3?{'count':_0x2de332,'rows':_0xac19a3}:null;}})[_0x58f0('0x38')](respondWithResult(_0x34d7df,null))[_0x58f0('0x2a')](handleError(_0x34d7df,null));};exports[_0x58f0('0x3e')]=function(_0x400513,_0x4d83f7,_0x19dd80){var _0x371057,_0xc72729,_0xdbf418;if(_[_0x58f0('0x77')](_0x400513[_0x58f0('0x61')][_0x58f0('0x61')])||_0x400513[_0x58f0('0x61')][_0x58f0('0x61')]===''){throw new db[(_0x58f0('0x71'))][(_0x58f0('0x72'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x58f0('0x77')](_0x400513[_0x58f0('0x61')]['to'])){}_0x371057=_0x400513[_0x58f0('0x61')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x400513[_0x58f0('0x59')]['id']}})[_0x58f0('0x38')](handleEntityNotFound(_0x4d83f7,null))[_0x58f0('0x38')](function(_0x2d999b){if(_0x2d999b){return db[_0x58f0('0x54')][_0x58f0('0x5b')]({'where':{'id':_0x2d999b['id']},'include':[{'model':db[_0x58f0('0xb3')],'as':'List','include':[{'model':db[_0x58f0('0x70')],'as':'Contacts','where':{[_0x2d999b[_0x58f0('0x79')]]:_0x371057},'limit':0x1,'order':[['updatedAt',_0x58f0('0xb4')]]}]}]})[_0x58f0('0x38')](handleEntityNotFound(_0x4d83f7,null))[_0x58f0('0x38')](function(_0x2f7e06){if(_0x2f7e06&&_0x2f7e06[_0x58f0('0x7d')]){_0xc72729=_0x2f7e06[_0x58f0('0x3a')]({'plain':!![]});if(_0xc72729['List']&&_0xc72729[_0x58f0('0x7d')][_0x58f0('0x7e')][_0x58f0('0x65')]){return _0xc72729[_0x58f0('0x7d')][_0x58f0('0x7e')][0x0];}return db[_0x58f0('0x70')]['create'](_[_0x58f0('0x1a')](_0x400513['body'],{'firstName':_0x371057,[_0x2f7e06[_0x58f0('0x79')]]:_0x371057,'phone':_0x371057,'ListId':_0xc72729[_0x58f0('0x85')]}));}})[_0x58f0('0x38')](handleEntityNotFound(_0x4d83f7,null))[_0x58f0('0x38')](function(_0x8c2f40){if(_0x8c2f40){_0xdbf418=_0x8c2f40;return db[_0x58f0('0x89')][_0x58f0('0x5b')]({'where':{'ContactId':_0xdbf418['id'],'closed':![],'OpenchannelAccountId':_0xc72729['id']}})['then'](function(_0x59db58){if(_0x59db58){return[_0x59db58,![]];}return db[_0x58f0('0x89')]['create']({'UserId':_0x400513[_0x58f0('0x5d')]['id'],'ContactId':_0xdbf418['id'],'OpenchannelAccountId':_0xc72729['id'],'lastMsgDirection':_0x58f0('0xb5'),'Messages':[_[_0x58f0('0x52')](_0x400513[_0x58f0('0x61')],{'read':![],'body':_0x400513['body']['body'],'OpenchannelAccountId':_0xc72729['id'],'UserId':_0x400513[_0x58f0('0x5d')]['id'],'ContactId':_0xdbf418['id']})]},{'include':[{'model':db[_0x58f0('0x94')],'as':'Messages'}]})['then'](function(_0x158408){return[_0x158408,!![]];});});}})['spread'](function(_0x238b94,_0x526dbd){if(_0x526dbd){return _0x238b94;}return db['OpenchannelMessage'][_0x58f0('0x5c')](_['merge'](_0x400513[_0x58f0('0x61')],{'read':![],'body':_0x400513[_0x58f0('0x61')]['body'],'OpenchannelAccountId':_0xc72729['id'],'OpenchannelInteractionId':_0x238b94['id'],'UserId':_0x400513[_0x58f0('0x5d')]['id'],'ContactId':_0xdbf418['id']}))['then'](function(_0x3ef376){_0x238b94[_0x58f0('0xb6')][_0x58f0('0xb7')]=[];_0x238b94['dataValues'][_0x58f0('0xb7')]['push'](_0x3ef376[_0x58f0('0xb6')]);return _0x238b94;});});}})[_0x58f0('0x38')](respondWithResult(_0x4d83f7,null))[_0x58f0('0x2a')](handleError(_0x4d83f7,null));};
\ No newline at end of file