Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 0c6bee8..001b72c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x25d5=['message','OpenchannelAccount,\x20%s,\x20%s','result','sendStatus','status','end','json','offset','undefined','limit','count','set','save','destroy','get','OpenchannelAccounts','UserProfileResource','name','send','index','Pause','map','rawAttributes','fieldName','type','keys','query','filters','intersection','attributes','length','model','nolimit','order','sort','filter','VIRTUAL','options','includeAll','include','OpenchannelAccount','findAll','catch','show','fields','merge','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','update','body','params','mandatoryDispositionPause','describe','addDisposition','OpenchannelAccountId','Disposition','findOne','hasOwnProperty','pick','where','removeDispositions','ids','getAnswers','CannedAnswer','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','createdAt','updatedAt','CompanyId','ListId','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','from','List','Contacts','DESC','OpenchannelApplication','Applications','account','applications','list','orderBy','priority','asc','contact','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','firstName','messageId','created','autoclose','unmanaged','OpenchannelMessage','AttachmentId','interaction','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','READ_COMMITTED','bulkCreate','findAndCountAll','stack','getApplications','getInteractions','Contact','Tag','Tags','tag','rows','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','getAgents','out','dataValues','Messages','push','eml-format','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','jayson/promise','client','http','request','then','info','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code'];(function(_0x9c5775,_0x5d3504){var _0x5094f7=function(_0x2b3e04){while(--_0x2b3e04){_0x9c5775['push'](_0x9c5775['shift']());}};_0x5094f7(++_0x5d3504);}(_0x25d5,0x91));var _0x525d=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x25d5[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x525d('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x525d('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x525d('0x2'));var moment=require(_0x525d('0x3'));var BPromise=require(_0x525d('0x4'));var Mustache=require('mustache');var util=require(_0x525d('0x5'));var path=require(_0x525d('0x6'));var sox=require(_0x525d('0x7'));var csv=require(_0x525d('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x525d('0x9'));var _=require(_0x525d('0xa'));var squel=require(_0x525d('0xb'));var crypto=require(_0x525d('0xc'));var jsforce=require(_0x525d('0xd'));var deskjs=require(_0x525d('0xe'));var toCsv=require(_0x525d('0x8'));var querystring=require(_0x525d('0xf'));var Papa=require(_0x525d('0x10'));var Redis=require('ioredis');var authService=require(_0x525d('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x525d('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x525d('0x13'));var config=require(_0x525d('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x525d('0x15'))['db'];config[_0x525d('0x16')]=_[_0x525d('0x17')](config['redis'],{'host':_0x525d('0x18'),'port':0x18eb});var socket=require(_0x525d('0x19'))(new Redis(config[_0x525d('0x16')]));require(_0x525d('0x1a'))['register'](socket);var jayson=require(_0x525d('0x1b'));var client=jayson[_0x525d('0x1c')][_0x525d('0x1d')]({'port':0x232c});var client9002=jayson[_0x525d('0x1c')][_0x525d('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x31ed21,_0x107dfb,_0x471049,_0x50b4f3){return new BPromise(function(_0x51dfca,_0x38750c){var _0x389565=_0x50b4f3||client;return _0x389565[_0x525d('0x1e')](_0x31ed21,_0x471049)[_0x525d('0x1f')](function(_0x8abf8c){logger[_0x525d('0x20')]('OpenchannelAccount,\x20%s,\x20%s',_0x107dfb,_0x525d('0x21'));logger[_0x525d('0x22')](_0x525d('0x23'),_0x107dfb,_0x525d('0x21'),JSON[_0x525d('0x24')](_0x8abf8c));if(_0x8abf8c[_0x525d('0x25')]){if(_0x8abf8c['error'][_0x525d('0x26')]===0x1f4){logger['error']('OpenchannelAccount,\x20%s,\x20%s',_0x107dfb,_0x8abf8c['error'][_0x525d('0x27')]);return _0x38750c(_0x8abf8c['error'][_0x525d('0x27')]);}logger[_0x525d('0x25')](_0x525d('0x28'),_0x107dfb,_0x8abf8c[_0x525d('0x25')][_0x525d('0x27')]);return _0x51dfca(_0x8abf8c['error'][_0x525d('0x27')]);}else{logger['info']('OpenchannelAccount,\x20%s,\x20%s',_0x107dfb,_0x525d('0x21'));_0x51dfca(_0x8abf8c[_0x525d('0x29')]['message']);}})['catch'](function(_0x3d4a5c){logger['error'](_0x525d('0x28'),_0x107dfb,_0x3d4a5c);_0x38750c(_0x3d4a5c);});});}function respondWithStatusCode(_0x25eeff,_0x190294){_0x190294=_0x190294||0xcc;return function(_0x3dca8a){if(_0x3dca8a){return _0x25eeff[_0x525d('0x2a')](_0x190294);}return _0x25eeff[_0x525d('0x2b')](_0x190294)[_0x525d('0x2c')]();};}function respondWithResult(_0x589e42,_0x3a4886){_0x3a4886=_0x3a4886||0xc8;return function(_0x5b13c2){if(_0x5b13c2){return _0x589e42[_0x525d('0x2b')](_0x3a4886)[_0x525d('0x2d')](_0x5b13c2);}};}function respondWithFilteredResult(_0x512d9f,_0x54856d){return function(_0x86bc45){if(_0x86bc45){var _0x4b9dbb=typeof _0x54856d[_0x525d('0x2e')]===_0x525d('0x2f')&&typeof _0x54856d[_0x525d('0x30')]===_0x525d('0x2f');var _0x497d6e=_0x86bc45['count'];var _0x356a13=_0x4b9dbb?0x0:_0x54856d[_0x525d('0x2e')];var _0x1f10bd=_0x4b9dbb?_0x86bc45[_0x525d('0x31')]:_0x54856d[_0x525d('0x2e')]+_0x54856d[_0x525d('0x30')];var _0x3ff3a4;if(_0x1f10bd>=_0x497d6e){_0x1f10bd=_0x497d6e;_0x3ff3a4=0xc8;}else{_0x3ff3a4=0xce;}_0x512d9f[_0x525d('0x2b')](_0x3ff3a4);return _0x512d9f[_0x525d('0x32')]('Content-Range',_0x356a13+'-'+_0x1f10bd+'/'+_0x497d6e)[_0x525d('0x2d')](_0x86bc45);}return null;};}function patchUpdates(_0x54e610){return function(_0x341d94){try{jsonpatch['apply'](_0x341d94,_0x54e610,!![]);}catch(_0x43447e){return BPromise['reject'](_0x43447e);}return _0x341d94[_0x525d('0x33')]();};}function saveUpdates(_0xef8484,_0x37827c){return function(_0x55c026){if(_0x55c026){return _0x55c026['update'](_0xef8484)[_0x525d('0x1f')](function(_0x2d3178){return _0x2d3178;});}return null;};}function removeEntity(_0x1f7420,_0x75c2fa){return function(_0x382d32){if(_0x382d32){return _0x382d32[_0x525d('0x34')]()['then'](function(){var _0x21afd1=_0x382d32[_0x525d('0x35')]({'plain':!![]});var _0xa6f6c0=_0x525d('0x36');return db[_0x525d('0x37')][_0x525d('0x34')]({'where':{'type':_0xa6f6c0,'resourceId':_0x21afd1['id']}})[_0x525d('0x1f')](function(){return _0x382d32;});})[_0x525d('0x1f')](function(){_0x1f7420[_0x525d('0x2b')](0xcc)[_0x525d('0x2c')]();});}};}function handleEntityNotFound(_0x58377f,_0x261a70){return function(_0x16adaf){if(!_0x16adaf){_0x58377f[_0x525d('0x2a')](0x194);}return _0x16adaf;};}function handleError(_0x45fd5c,_0x13aaea){_0x13aaea=_0x13aaea||0x1f4;return function(_0x341d12){logger[_0x525d('0x25')](_0x341d12['stack']);if(_0x341d12[_0x525d('0x38')]){delete _0x341d12[_0x525d('0x38')];}_0x45fd5c[_0x525d('0x2b')](_0x13aaea)[_0x525d('0x39')](_0x341d12);};}exports[_0x525d('0x3a')]=function(_0x229037,_0x8eadaf){var _0xc011bd={'include':[{'model':db[_0x525d('0x3b')],'as':'mandatoryDispositionPause'}]},_0x332c28={},_0x3e1583={'count':0x0,'rows':[]};var _0x275272=_[_0x525d('0x3c')](db['OpenchannelAccount'][_0x525d('0x3d')],function(_0x241970){return{'name':_0x241970[_0x525d('0x3e')],'type':_0x241970[_0x525d('0x3f')]['key']};});_0x332c28['model']=_[_0x525d('0x3c')](_0x275272,_0x525d('0x38'));_0x332c28['query']=_[_0x525d('0x40')](_0x229037[_0x525d('0x41')]);_0x332c28[_0x525d('0x42')]=_[_0x525d('0x43')](_0x332c28['model'],_0x332c28[_0x525d('0x41')]);_0xc011bd[_0x525d('0x44')]=_[_0x525d('0x43')](_0x332c28['model'],qs['fields'](_0x229037['query']['fields']));_0xc011bd[_0x525d('0x44')]=_0xc011bd[_0x525d('0x44')][_0x525d('0x45')]?_0xc011bd[_0x525d('0x44')]:_0x332c28[_0x525d('0x46')];if(!_0x229037[_0x525d('0x41')]['hasOwnProperty'](_0x525d('0x47'))){_0xc011bd[_0x525d('0x30')]=qs[_0x525d('0x30')](_0x229037[_0x525d('0x41')][_0x525d('0x30')]);_0xc011bd['offset']=qs[_0x525d('0x2e')](_0x229037['query'][_0x525d('0x2e')]);}_0xc011bd[_0x525d('0x48')]=qs[_0x525d('0x49')](_0x229037['query'][_0x525d('0x49')]);_0xc011bd['where']=qs[_0x525d('0x42')](_['pick'](_0x229037[_0x525d('0x41')],_0x332c28[_0x525d('0x42')]),_0x275272);if(_0x229037[_0x525d('0x41')][_0x525d('0x4a')]){_0xc011bd['where']=_['merge'](_0xc011bd['where'],{'$or':_[_0x525d('0x3c')](_0x275272,function(_0x3b82af){if(_0x3b82af[_0x525d('0x3f')]!==_0x525d('0x4b')){var _0x14fc09={};_0x14fc09[_0x3b82af[_0x525d('0x38')]]={'$like':'%'+_0x229037[_0x525d('0x41')]['filter']+'%'};return _0x14fc09;}})});}_0xc011bd=_['merge']({},_0xc011bd,_0x229037[_0x525d('0x4c')]);var _0x2abb17={'where':_0xc011bd['where']};return db['OpenchannelAccount'][_0x525d('0x31')](_0x2abb17)['then'](function(_0x4a7a5b){_0x3e1583[_0x525d('0x31')]=_0x4a7a5b;if(_0x229037[_0x525d('0x41')][_0x525d('0x4d')]){_0xc011bd[_0x525d('0x4e')]=[{'all':!![]}];}return db[_0x525d('0x4f')][_0x525d('0x50')](_0xc011bd);})[_0x525d('0x1f')](function(_0x2df3ca){_0x3e1583['rows']=_0x2df3ca;return _0x3e1583;})[_0x525d('0x1f')](respondWithFilteredResult(_0x8eadaf,_0xc011bd))[_0x525d('0x51')](handleError(_0x8eadaf,null));};exports[_0x525d('0x52')]=function(_0x50accf,_0x556bc8){var _0x16fc6e={'raw':![],'where':{'id':_0x50accf['params']['id']},'include':[{'model':db[_0x525d('0x3b')],'as':'mandatoryDispositionPause'}]},_0x36d5b3={};_0x36d5b3[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x4f')][_0x525d('0x3d')]);_0x36d5b3['query']=_[_0x525d('0x40')](_0x50accf[_0x525d('0x41')]);_0x36d5b3[_0x525d('0x42')]=_[_0x525d('0x43')](_0x36d5b3['model'],_0x36d5b3[_0x525d('0x41')]);_0x16fc6e[_0x525d('0x44')]=_[_0x525d('0x43')](_0x36d5b3[_0x525d('0x46')],qs[_0x525d('0x53')](_0x50accf[_0x525d('0x41')][_0x525d('0x53')]));_0x16fc6e[_0x525d('0x44')]=_0x16fc6e['attributes'][_0x525d('0x45')]?_0x16fc6e[_0x525d('0x44')]:_0x36d5b3['model'];if(_0x50accf['query'][_0x525d('0x4d')]){_0x16fc6e['include']=[{'all':!![]}];}_0x16fc6e=_[_0x525d('0x54')]({},_0x16fc6e,_0x50accf[_0x525d('0x4c')]);return db[_0x525d('0x4f')]['find'](_0x16fc6e)['then'](handleEntityNotFound(_0x556bc8,null))[_0x525d('0x1f')](respondWithResult(_0x556bc8,null))['catch'](handleError(_0x556bc8,null));};exports[_0x525d('0x55')]=function(_0x46cee5,_0x2fae49){return db[_0x525d('0x4f')][_0x525d('0x55')](_0x46cee5['body'],{})[_0x525d('0x1f')](function(_0x25b692){var _0x254110=_0x46cee5[_0x525d('0x56')]['get']({'plain':!![]});if(!_0x254110)throw new Error(_0x525d('0x57'));if(_0x254110[_0x525d('0x58')]===_0x525d('0x56')){var _0x58dff2=_0x25b692[_0x525d('0x35')]({'plain':!![]});var _0x51ef08=_0x525d('0x36');return db[_0x525d('0x59')][_0x525d('0x5a')]({'where':{'name':_0x51ef08,'userProfileId':_0x254110[_0x525d('0x5b')]},'raw':!![]})[_0x525d('0x1f')](function(_0x31b525){if(_0x31b525&&_0x31b525[_0x525d('0x5c')]===0x0){return db['UserProfileResource'][_0x525d('0x55')]({'name':_0x58dff2[_0x525d('0x38')],'resourceId':_0x58dff2['id'],'type':_0x31b525[_0x525d('0x38')],'sectionId':_0x31b525['id']},{})['then'](function(){return _0x25b692;});}else{return _0x25b692;}})[_0x525d('0x51')](function(_0x3ce628){logger[_0x525d('0x25')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3ce628);throw _0x3ce628;});}return _0x25b692;})['then'](respondWithResult(_0x2fae49,0xc9))[_0x525d('0x51')](handleError(_0x2fae49,null));};exports[_0x525d('0x5d')]=function(_0xbe3f48,_0x47431b){if(_0xbe3f48['body']['id']){delete _0xbe3f48[_0x525d('0x5e')]['id'];}return db['OpenchannelAccount'][_0x525d('0x5a')]({'where':{'id':_0xbe3f48[_0x525d('0x5f')]['id']},'include':[{'model':db['Pause'],'as':_0x525d('0x60')}]})[_0x525d('0x1f')](handleEntityNotFound(_0x47431b,null))[_0x525d('0x1f')](saveUpdates(_0xbe3f48[_0x525d('0x5e')],null))[_0x525d('0x1f')](respondWithResult(_0x47431b,null))[_0x525d('0x51')](handleError(_0x47431b,null));};exports[_0x525d('0x34')]=function(_0x2409c4,_0x5adece){return db['OpenchannelAccount']['find']({'where':{'id':_0x2409c4[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x5adece,null))['then'](removeEntity(_0x5adece,null))[_0x525d('0x51')](handleError(_0x5adece,null));};exports['describe']=function(_0x98c1ef,_0x5f609f){return db['OpenchannelAccount'][_0x525d('0x61')]()[_0x525d('0x1f')](respondWithResult(_0x5f609f,null))['catch'](handleError(_0x5f609f,null));};exports[_0x525d('0x62')]=function(_0x492210,_0x208fe4,_0x2bcbbc){if(_0x492210['body']['id']){delete _0x492210[_0x525d('0x5e')]['id'];}return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x492210[_0x525d('0x5f')]['id']}})['then'](handleEntityNotFound(_0x208fe4,null))[_0x525d('0x1f')](function(_0x3be484){if(_0x3be484){_0x492210[_0x525d('0x5e')][_0x525d('0x63')]=_0x3be484['id'];return db[_0x525d('0x64')][_0x525d('0x55')](_0x492210[_0x525d('0x5e')]);}})[_0x525d('0x1f')](respondWithResult(_0x208fe4,null))['catch'](handleError(_0x208fe4,null));};exports['getDispositions']=function(_0x149f21,_0x135898,_0x50f789){var _0x5ad7a8={'raw':![],'where':{}};var _0x42e318={};var _0x4d17c3={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x525d('0x65')]({'where':{'id':_0x149f21[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x135898,null))[_0x525d('0x1f')](function(_0x51164c){if(_0x51164c){_0x42e318[_0x525d('0x46')]=_[_0x525d('0x40')](db['Disposition'][_0x525d('0x3d')]);_0x42e318['query']=_['keys'](_0x149f21['query']);_0x42e318['filters']=_['intersection'](_0x42e318[_0x525d('0x46')],_0x42e318[_0x525d('0x41')]);_0x5ad7a8[_0x525d('0x44')]=_['intersection'](_0x42e318[_0x525d('0x46')],qs[_0x525d('0x53')](_0x149f21[_0x525d('0x41')]['fields']));_0x5ad7a8[_0x525d('0x44')]=_0x5ad7a8[_0x525d('0x44')][_0x525d('0x45')]?_0x5ad7a8[_0x525d('0x44')]:_0x42e318[_0x525d('0x46')];if(!_0x149f21[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x5ad7a8[_0x525d('0x30')]=qs[_0x525d('0x30')](_0x149f21['query']['limit']);_0x5ad7a8[_0x525d('0x2e')]=qs[_0x525d('0x2e')](_0x149f21[_0x525d('0x41')][_0x525d('0x2e')]);}_0x5ad7a8[_0x525d('0x48')]=qs[_0x525d('0x49')](_0x149f21['query'][_0x525d('0x49')]);_0x5ad7a8['where']=qs[_0x525d('0x42')](_[_0x525d('0x67')](_0x149f21[_0x525d('0x41')],_0x42e318[_0x525d('0x42')]));_0x5ad7a8[_0x525d('0x68')][_0x525d('0x63')]=_0x51164c['id'];if(_0x149f21['query'][_0x525d('0x4a')]){_0x5ad7a8['where']=_[_0x525d('0x54')](_0x5ad7a8[_0x525d('0x68')],{'$or':_[_0x525d('0x3c')](_0x5ad7a8['attributes'],function(_0x527b9b){var _0x5ad7a0={};_0x5ad7a0[_0x527b9b]={'$like':'%'+_0x149f21[_0x525d('0x41')]['filter']+'%'};return _0x5ad7a0;})});}_0x5ad7a8=_[_0x525d('0x54')]({},_0x5ad7a8,_0x149f21['options']);return db['Disposition'][_0x525d('0x31')]({'where':_0x5ad7a8[_0x525d('0x68')]})[_0x525d('0x1f')](function(_0x23481e){_0x4d17c3[_0x525d('0x31')]=_0x23481e;if(_0x149f21[_0x525d('0x41')][_0x525d('0x4d')]){_0x5ad7a8['include']=[{'all':!![]}];}return db[_0x525d('0x64')][_0x525d('0x50')](_0x5ad7a8);})['then'](function(_0xaaeebe){_0x4d17c3['rows']=_0xaaeebe;return _0x4d17c3;});}})[_0x525d('0x1f')](respondWithFilteredResult(_0x135898,_0x5ad7a8))['catch'](handleError(_0x135898,null));};exports[_0x525d('0x69')]=function(_0x759ba2,_0x42b365,_0x3a626e){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x759ba2['params']['id']}})['then'](handleEntityNotFound(_0x42b365,null))[_0x525d('0x1f')](function(_0x3a8ac1){if(_0x3a8ac1){return _0x3a8ac1['removeDispositions'](_0x759ba2[_0x525d('0x41')][_0x525d('0x6a')]);}})[_0x525d('0x1f')](respondWithStatusCode(_0x42b365,null))[_0x525d('0x51')](handleError(_0x42b365,null));};exports['addAnswer']=function(_0x51218d,_0x18b8a1,_0x3a931b){if(_0x51218d[_0x525d('0x5e')]['id']){delete _0x51218d[_0x525d('0x5e')]['id'];}return db[_0x525d('0x4f')]['find']({'where':{'id':_0x51218d[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x18b8a1,null))[_0x525d('0x1f')](function(_0x5b4fd9){if(_0x5b4fd9){_0x51218d[_0x525d('0x5e')][_0x525d('0x63')]=_0x5b4fd9['id'];return db['CannedAnswer'][_0x525d('0x55')](_0x51218d[_0x525d('0x5e')]);}})['then'](respondWithResult(_0x18b8a1,null))[_0x525d('0x51')](handleError(_0x18b8a1,null));};exports[_0x525d('0x6b')]=function(_0x47ed42,_0x16bfe7,_0x583392){var _0x28f6eb={'raw':![],'where':{}};var _0x1815d8={};var _0x35ff12={'count':0x0,'rows':[]};return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x47ed42[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x16bfe7,null))[_0x525d('0x1f')](function(_0x5a6e3f){if(_0x5a6e3f){_0x1815d8[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x6c')][_0x525d('0x3d')]);_0x1815d8[_0x525d('0x41')]=_[_0x525d('0x40')](_0x47ed42['query']);_0x1815d8[_0x525d('0x42')]=_['intersection'](_0x1815d8[_0x525d('0x46')],_0x1815d8[_0x525d('0x41')]);_0x28f6eb[_0x525d('0x44')]=_[_0x525d('0x43')](_0x1815d8[_0x525d('0x46')],qs[_0x525d('0x53')](_0x47ed42['query'][_0x525d('0x53')]));_0x28f6eb[_0x525d('0x44')]=_0x28f6eb[_0x525d('0x44')][_0x525d('0x45')]?_0x28f6eb[_0x525d('0x44')]:_0x1815d8[_0x525d('0x46')];if(!_0x47ed42[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x28f6eb['limit']=qs[_0x525d('0x30')](_0x47ed42[_0x525d('0x41')]['limit']);_0x28f6eb[_0x525d('0x2e')]=qs['offset'](_0x47ed42['query'][_0x525d('0x2e')]);}_0x28f6eb['order']=qs['sort'](_0x47ed42[_0x525d('0x41')][_0x525d('0x49')]);_0x28f6eb['where']=qs[_0x525d('0x42')](_[_0x525d('0x67')](_0x47ed42['query'],_0x1815d8[_0x525d('0x42')]));_0x28f6eb['where'][_0x525d('0x63')]=_0x5a6e3f['id'];if(_0x47ed42['query'][_0x525d('0x4a')]){_0x28f6eb[_0x525d('0x68')]=_[_0x525d('0x54')](_0x28f6eb['where'],{'$or':_[_0x525d('0x3c')](_0x28f6eb['attributes'],function(_0x1fd373){var _0x409f04={};_0x409f04[_0x1fd373]={'$like':'%'+_0x47ed42[_0x525d('0x41')][_0x525d('0x4a')]+'%'};return _0x409f04;})});}_0x28f6eb=_[_0x525d('0x54')]({},_0x28f6eb,_0x47ed42['options']);return db[_0x525d('0x6c')]['count']({'where':_0x28f6eb[_0x525d('0x68')]})[_0x525d('0x1f')](function(_0x139a8d){_0x35ff12['count']=_0x139a8d;if(_0x47ed42[_0x525d('0x41')][_0x525d('0x4d')]){_0x28f6eb['include']=[{'all':!![]}];}return db[_0x525d('0x6c')][_0x525d('0x50')](_0x28f6eb);})[_0x525d('0x1f')](function(_0x4768da){_0x35ff12['rows']=_0x4768da;return _0x35ff12;});}})[_0x525d('0x1f')](respondWithFilteredResult(_0x16bfe7,_0x28f6eb))[_0x525d('0x51')](handleError(_0x16bfe7,null));};exports['removeAnswers']=function(_0x4584a9,_0x3d5d80,_0x68213b){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x4584a9['params']['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x3d5d80,null))[_0x525d('0x1f')](function(_0x49103c){if(_0x49103c){return _0x49103c['removeAnswers'](_0x4584a9[_0x525d('0x41')][_0x525d('0x6a')]);}})[_0x525d('0x1f')](respondWithStatusCode(_0x3d5d80,null))[_0x525d('0x51')](handleError(_0x3d5d80,null));};exports['notify']=function(_0x50825b,_0x160d3a,_0xc194a4){var _0x2f4642={'body':_0x50825b[_0x525d('0x5e')],'channel':_0x525d('0x6d')};var _0x46d6f5=[];var _0xf1c0de=[];var _0x52e1a9={};var _0x1f91d2=![];return db[_0x525d('0x6e')]['describe']()[_0x525d('0x1f')](function(_0x1b1ffc){if(!_0x1b1ffc){throw new db[(_0x525d('0x6f'))][(_0x525d('0x70'))](_0x525d('0x71'));}_0x46d6f5=_['difference'](_[_0x525d('0x40')](_0x1b1ffc),[_0x525d('0x72'),_0x525d('0x73')]);_0xf1c0de=_['difference'](_['keys'](_0x1b1ffc),[_0x525d('0x72'),_0x525d('0x73'),_0x525d('0x74'),_0x525d('0x75')]);if(_0x50825b[_0x525d('0x5e')]['id']){delete _0x50825b[_0x525d('0x5e')]['id'];}if(_['isNil'](_0x50825b['body']['from'])){throw new db['Sequelize'][(_0x525d('0x70'))](_0x525d('0x76'));}if(_['isNil'](_0x50825b['body'][_0x525d('0x5e')])||_0x50825b[_0x525d('0x5e')][_0x525d('0x5e')]===''){throw new db[(_0x525d('0x6f'))]['ValidationError'](_0x525d('0x77'));}if(_[_0x525d('0x78')](_0x50825b[_0x525d('0x5e')][_0x525d('0x79')])){throw new db['Sequelize']['ValidationError'](_0x525d('0x7a')+_0xf1c0de);}if(!_['includes'](_0xf1c0de,_0x50825b[_0x525d('0x5e')][_0x525d('0x79')])){throw new db['Sequelize'][(_0x525d('0x70'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xf1c0de);}_0x52e1a9[_0x50825b[_0x525d('0x5e')][_0x525d('0x79')]]=_0x50825b['body'][_0x525d('0x7b')];})[_0x525d('0x1f')](function(){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x50825b['params']['id']},'include':[{'model':db['CmList'],'as':_0x525d('0x7c'),'include':[{'model':db[_0x525d('0x6e')],'as':_0x525d('0x7d'),'where':_0x52e1a9,'limit':0x1,'order':[[_0x525d('0x73'),_0x525d('0x7e')]]}]},{'model':db[_0x525d('0x7f')],'as':_0x525d('0x80')}]});})[_0x525d('0x1f')](handleEntityNotFound(_0x160d3a,null))[_0x525d('0x1f')](function(_0x9fc07f){if(_0x9fc07f&&_0x9fc07f[_0x525d('0x7c')]){_0x2f4642[_0x525d('0x81')]=_0x9fc07f;_0x2f4642[_0x525d('0x82')]=_0x9fc07f[_0x525d('0x80')];_0x2f4642[_0x525d('0x83')]=_0x9fc07f[_0x525d('0x7c')];_0x2f4642[_0x525d('0x82')]=_[_0x525d('0x84')](_0x2f4642[_0x525d('0x82')],[_0x525d('0x85')],[_0x525d('0x86')]);if(_0x2f4642['account'][_0x525d('0x80')]){delete _0x2f4642['account'][_0x525d('0x80')];}if(_0x2f4642[_0x525d('0x81')][_0x525d('0x7c')]&&_0x2f4642['account'][_0x525d('0x7c')][_0x525d('0x7d')][_0x525d('0x45')]){return _0x2f4642[_0x525d('0x81')][_0x525d('0x7c')][_0x525d('0x7d')][0x0];}var _0x2ba004=_['defaults'](_0x50825b['body'],{'firstName':_0x50825b[_0x525d('0x5e')][_0x525d('0x7b')],'ListId':_0x9fc07f['ListId']});_0x2ba004[_0x50825b['body']['mapKey']]=_0x50825b[_0x525d('0x5e')]['from'];return db[_0x525d('0x6e')][_0x525d('0x55')](_0x2ba004,{'fields':_0x46d6f5,'raw':!![]});}})['then'](handleEntityNotFound(_0x160d3a,null))[_0x525d('0x1f')](function(_0x54928a){_0x2f4642[_0x525d('0x87')]=_0x54928a;if(_0x54928a){var _0x315f36={'ContactId':_0x54928a['id'],'OpenchannelAccountId':_0x50825b['params']['id'],'from':(_0x54928a['firstName']||'')+'\x20'+(_0x54928a[_0x525d('0x88')]||'')};var _0x7f2b7={'OpenchannelAccountId':_0x50825b[_0x525d('0x5f')]['id'],'closed':![]};if(_0x50825b['body'][_0x525d('0x89')]){_0x7f2b7['threadId']=_0x50825b[_0x525d('0x5e')][_0x525d('0x89')];return db[_0x525d('0x8a')][_0x525d('0x5a')]({'where':_0x7f2b7})[_0x525d('0x1f')](function(_0x171e4b){if(_0x171e4b){return[_0x171e4b,![]];}_0x315f36[_0x525d('0x89')]=_0x50825b[_0x525d('0x5e')][_0x525d('0x89')];_0x315f36[_0x525d('0x8b')]=_0x50825b[_0x525d('0x5e')][_0x525d('0x8b')];return db['OpenchannelInteraction'][_0x525d('0x55')](_0x315f36)['then'](function(_0x35032d){return[_0x35032d,!![]];});});}else{_0x7f2b7[_0x525d('0x89')]=null;}_0x7f2b7[_0x525d('0x8c')]=_0x54928a['id'];return db[_0x525d('0x8a')][_0x525d('0x5a')]({'where':_0x7f2b7})[_0x525d('0x1f')](function(_0x3961b1){if(_0x3961b1){return[_0x3961b1,![]];}return db[_0x525d('0x8a')][_0x525d('0x55')](_0x315f36)['then'](function(_0x269811){return[_0x269811,!![]];});});}})[_0x525d('0x8d')](function(_0x5c03ae,_0x44aa42){if(_0x5c03ae){_0x1f91d2=_0x44aa42;if(!_0x44aa42){var _0x4375ea={'from':(_0x2f4642['contact'][_0x525d('0x8e')]||'')+'\x20'+(_0x2f4642[_0x525d('0x87')][_0x525d('0x88')]||'')};if(_0x50825b[_0x525d('0x5e')]['threadId']&&_0x50825b['body']['messageId']&&_0x50825b[_0x525d('0x5e')][_0x525d('0x89')]!=_0x50825b[_0x525d('0x5e')]['messageId']){_0x4375ea[_0x525d('0x89')]=_0x50825b['body'][_0x525d('0x8f')];}return _0x5c03ae[_0x525d('0x5d')](_0x4375ea);}else{return _0x5c03ae;}}})['then'](function(_0x300adc){_0x2f4642['interaction']=_0x300adc[_0x525d('0x35')]({'plain':!![]});_0x2f4642['interaction'][_0x525d('0x90')]=_0x1f91d2;if(_0x2f4642['interaction'][_0x525d('0x90')]){if(_0x2f4642[_0x525d('0x81')][_0x525d('0x91')]){_0x2f4642[_0x525d('0x82')]['push']({'id':0x0,'priority':_0x2f4642[_0x525d('0x82')][_0x525d('0x45')]+0x1,'app':'close','appdata':_0x525d('0x92'),'interval':'*,*,*,*'});}}return db[_0x525d('0x93')][_0x525d('0x55')]({'body':_0x50825b[_0x525d('0x5e')]['body'],'OpenchannelAccountId':_0x50825b['params']['id'],'OpenchannelInteractionId':_0x300adc['id'],'direction':'in','ContactId':_0x2f4642[_0x525d('0x87')]['id'],'AttachmentId':_0x50825b[_0x525d('0x5e')][_0x525d('0x94')]});})[_0x525d('0x1f')](function(_0x462c9d){_0x2f4642[_0x525d('0x27')]=_0x462c9d;if(_0x2f4642[_0x525d('0x95')][_0x525d('0x96')]){return db[_0x525d('0x97')]['find']({'attributes':['id','name'],'where':{'id':_0x2f4642[_0x525d('0x95')][_0x525d('0x96')]}})[_0x525d('0x1f')](function(_0x2d8906){if(_0x2d8906){_0x2f4642[_0x525d('0x82')][_0x525d('0x98')]({'id':0x0,'priority':0x0,'app':_0x525d('0x99'),'appdata':_0x2d8906[_0x525d('0x38')]+','+(_0x2f4642['account'][_0x525d('0x9a')]||0xa),'interval':_0x525d('0x9b')});_0x2f4642[_0x525d('0x9c')]=![];}return respondWithRpcPromise(_0x525d('0x9d'),_0x525d('0x9e'),_0x2f4642);});}return respondWithRpcPromise(_0x525d('0x9d'),'startRouting',_0x2f4642);})[_0x525d('0x1f')](function(_0x53c1d6){respondWithRpcPromise(_0x525d('0x9f'),_0x525d('0x9f'),{'event':'notify','message':_0x53c1d6},client9002);return _0x53c1d6;})[_0x525d('0x1f')](respondWithResult(_0x160d3a,null))['catch'](handleError(_0x160d3a,null));};exports[_0x525d('0xa0')]=function(_0x9f5866,_0x1089fc){var _0x1c293e=_0x9f5866[_0x525d('0x5f')]['id'];var _0x339fc2=_0x9f5866[_0x525d('0x5e')];var _0x40cf57=0xc8;var _0x1aec4f=null;return db[_0x525d('0xa1')]['transaction']({'isolationLevel':db[_0x525d('0xa1')]['Transaction']['ISOLATION_LEVELS'][_0x525d('0xa2')]},function(_0x36cb48){return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x1c293e},'transaction':_0x36cb48})[_0x525d('0x1f')](function(_0x107113){if(_0x107113){return db['OpenchannelApplication'][_0x525d('0x34')]({'where':{'OpenchannelAccountId':_0x1c293e},'transaction':_0x36cb48})['then'](function(){var _0x31f430=_[_0x525d('0x3c')](_0x339fc2,function(_0x1b8884){_0x1b8884['OpenchannelAccountId']=_0x1c293e;return _0x1b8884;});return db[_0x525d('0x7f')][_0x525d('0xa3')](_0x31f430,{'transaction':_0x36cb48});});}else{_0x40cf57=0x194;_0x1aec4f=[];}});})[_0x525d('0x1f')](function(){if(_0x40cf57!==0x194){return db['OpenchannelApplication'][_0x525d('0xa4')]({'where':{'OpenchannelAccountId':_0x1c293e},'order':_0x525d('0x85')})[_0x525d('0x1f')](function(_0x3fdccc){_0x1aec4f=_0x3fdccc;});}})[_0x525d('0x51')](function(_0x2e01d0){_0x40cf57=0x1f4;logger['error'](_0x2e01d0[_0x525d('0xa5')]);if(_0x2e01d0[_0x525d('0x38')]){delete _0x2e01d0['name'];}_0x1aec4f=_0x2e01d0;})['finally'](function(){if(_0x1aec4f===null){_0x1089fc[_0x525d('0x2a')](_0x40cf57);}else{if(_0x40cf57===0x1f4){_0x1089fc[_0x525d('0x2b')](_0x40cf57)[_0x525d('0x39')](_0x1aec4f);}else{_0x1089fc[_0x525d('0x2b')](_0x40cf57)['json'](_0x1aec4f);}}});};exports[_0x525d('0xa6')]=function(_0x30ae98,_0x24fafc,_0x2e7ad9){var _0x12d24e={};var _0xd40782={};var _0x56ce16;var _0x29a019;return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x30ae98[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x24fafc,null))[_0x525d('0x1f')](function(_0xa318c9){if(_0xa318c9){_0x56ce16=_0xa318c9;_0xd40782[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x7f')][_0x525d('0x3d')]);_0xd40782[_0x525d('0x41')]=_[_0x525d('0x40')](_0x30ae98[_0x525d('0x41')]);_0xd40782[_0x525d('0x42')]=_['intersection'](_0xd40782[_0x525d('0x46')],_0xd40782[_0x525d('0x41')]);_0x12d24e['attributes']=_[_0x525d('0x43')](_0xd40782[_0x525d('0x46')],qs[_0x525d('0x53')](_0x30ae98[_0x525d('0x41')][_0x525d('0x53')]));_0x12d24e['attributes']=_0x12d24e[_0x525d('0x44')]['length']?_0x12d24e[_0x525d('0x44')]:_0xd40782[_0x525d('0x46')];_0x12d24e['order']=qs[_0x525d('0x49')](_0x30ae98[_0x525d('0x41')][_0x525d('0x49')]);_0x12d24e[_0x525d('0x68')]=qs[_0x525d('0x42')](_['pick'](_0x30ae98[_0x525d('0x41')],_0xd40782[_0x525d('0x42')]));if(_0x30ae98[_0x525d('0x41')][_0x525d('0x4a')]){_0x12d24e[_0x525d('0x68')]=_[_0x525d('0x54')](_0x12d24e['where'],{'$or':_['map'](_0x12d24e[_0x525d('0x44')],function(_0x13a3c5){var _0x2a2391={};_0x2a2391[_0x13a3c5]={'$like':'%'+_0x30ae98['query']['filter']+'%'};return _0x2a2391;})});}_0x12d24e=_['merge']({},_0x12d24e,_0x30ae98['options']);return _0x56ce16[_0x525d('0xa6')](_0x12d24e);}})[_0x525d('0x1f')](function(_0x2206aa){if(_0x2206aa){_0x29a019=_0x2206aa['length'];if(!_0x30ae98[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x12d24e[_0x525d('0x30')]=qs['limit'](_0x30ae98[_0x525d('0x41')][_0x525d('0x30')]);_0x12d24e['offset']=qs['offset'](_0x30ae98[_0x525d('0x41')][_0x525d('0x2e')]);}return _0x56ce16[_0x525d('0xa6')](_0x12d24e);}})[_0x525d('0x1f')](function(_0x4ca3d1){if(_0x4ca3d1){return _0x4ca3d1?{'count':_0x29a019,'rows':_0x4ca3d1}:null;}})[_0x525d('0x1f')](respondWithResult(_0x24fafc,null))[_0x525d('0x51')](handleError(_0x24fafc,null));};exports[_0x525d('0xa7')]=function(_0x43deb1,_0x4932cf,_0x3ee185){var _0x33db3e={'raw':![],'where':{}};var _0x52000e={};var _0x5577fe={'count':0x0,'rows':[]};return db[_0x525d('0x4f')][_0x525d('0x65')]({'where':{'id':_0x43deb1[_0x525d('0x5f')]['id']}})['then'](handleEntityNotFound(_0x4932cf,null))[_0x525d('0x1f')](function(_0x45469b){if(_0x45469b){_0x52000e[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x8a')][_0x525d('0x3d')]);_0x52000e[_0x525d('0x41')]=_['keys'](_0x43deb1[_0x525d('0x41')]);_0x52000e[_0x525d('0x42')]=_[_0x525d('0x43')](_0x52000e[_0x525d('0x46')],_0x52000e[_0x525d('0x41')]);_0x33db3e[_0x525d('0x44')]=_[_0x525d('0x43')](_0x52000e['model'],qs[_0x525d('0x53')](_0x43deb1[_0x525d('0x41')][_0x525d('0x53')]));_0x33db3e[_0x525d('0x44')]=_0x33db3e[_0x525d('0x44')][_0x525d('0x45')]?_0x33db3e[_0x525d('0x44')]:_0x52000e[_0x525d('0x46')];if(!_0x43deb1['query']['hasOwnProperty'](_0x525d('0x47'))){_0x33db3e['limit']=qs['limit'](_0x43deb1['query'][_0x525d('0x30')]);_0x33db3e[_0x525d('0x2e')]=qs[_0x525d('0x2e')](_0x43deb1[_0x525d('0x41')]['offset']);}_0x33db3e[_0x525d('0x48')]=qs['sort'](_0x43deb1[_0x525d('0x41')]['sort']);_0x33db3e[_0x525d('0x68')]=qs[_0x525d('0x42')](_['pick'](_0x43deb1[_0x525d('0x41')],_0x52000e[_0x525d('0x42')]));_0x33db3e['where'][_0x525d('0x63')]=_0x45469b['id'];if(_0x43deb1[_0x525d('0x41')]['filter']){_0x33db3e[_0x525d('0x68')]=_[_0x525d('0x54')](_0x33db3e[_0x525d('0x68')],{'$or':_['map'](_0x33db3e['attributes'],function(_0x462a4f){var _0x1b7b60={};_0x1b7b60[_0x462a4f]={'$like':'%'+_0x43deb1['query'][_0x525d('0x4a')]+'%'};return _0x1b7b60;})});}_0x33db3e=_['merge']({},_0x33db3e,_0x43deb1['options']);return db[_0x525d('0x8a')]['count']({'where':_0x33db3e[_0x525d('0x68')]})[_0x525d('0x1f')](function(_0x55c39c){_0x5577fe[_0x525d('0x31')]=_0x55c39c;if(_0x43deb1[_0x525d('0x41')]['includeAll']){_0x33db3e[_0x525d('0x4e')]=[{'model':db[_0x525d('0x6e')],'as':_0x525d('0xa8'),'required':![]},{'model':db[_0x525d('0x97')],'as':'Owner','attributes':[_0x525d('0x38'),'fullname','internal'],'required':![]},{'model':db[_0x525d('0xa9')],'as':_0x525d('0xaa'),'attributes':['id',_0x525d('0x38'),'color'],'where':_0x43deb1[_0x525d('0x41')][_0x525d('0xab')]?{'id':_0x43deb1[_0x525d('0x41')][_0x525d('0xab')]}:undefined,'required':_0x43deb1['query'][_0x525d('0xab')]?!![]:![]}];}return db[_0x525d('0x8a')][_0x525d('0x50')](_0x33db3e);})[_0x525d('0x1f')](function(_0x576521){_0x5577fe[_0x525d('0xac')]=_0x576521;return _0x5577fe;});}})[_0x525d('0x1f')](respondWithFilteredResult(_0x4932cf,_0x33db3e))[_0x525d('0x51')](handleError(_0x4932cf,null));};exports[_0x525d('0xad')]=function(_0x17fb4d,_0x3a39a4,_0x50f273){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x17fb4d['params']['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x3a39a4,null))[_0x525d('0x1f')](function(_0x2a1e8e){if(_0x2a1e8e){return _0x2a1e8e[_0x525d('0xad')](_0x17fb4d[_0x525d('0x5e')][_0x525d('0x6a')],_[_0x525d('0xae')](_0x17fb4d[_0x525d('0x5e')],['ids','id'])||{})[_0x525d('0x8d')](function(_0x2a9208){for(var _0x241495=0x0;_0x241495<_0x17fb4d['body'][_0x525d('0x6a')][_0x525d('0x45')];_0x241495+=0x1){socket[_0x525d('0xaf')](_0x525d('0xb0'),{'UserId':Number(_0x17fb4d[_0x525d('0x5e')][_0x525d('0x6a')][_0x241495]),'OpenchannelAccountId':Number(_0x17fb4d[_0x525d('0x5f')]['id'])});}return _0x2a9208;});}})['then'](respondWithResult(_0x3a39a4,null))['catch'](handleError(_0x3a39a4,null));};exports['removeAgents']=function(_0x251452,_0x327822,_0x510d4b){return db[_0x525d('0x4f')][_0x525d('0x5a')]({'where':{'id':_0x251452[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x327822,null))['then'](function(_0x42aaba){if(_0x42aaba){return _0x42aaba[_0x525d('0xb1')](_0x251452[_0x525d('0x41')]['ids'])[_0x525d('0x1f')](function(){if(_[_0x525d('0xb2')](_0x251452[_0x525d('0x41')][_0x525d('0x6a')])){for(var _0x6920fe=0x0;_0x6920fe<_0x251452[_0x525d('0x41')][_0x525d('0x6a')][_0x525d('0x45')];_0x6920fe+=0x1){socket[_0x525d('0xaf')]('userOpenchannelAccount:remove',{'UserId':Number(_0x251452[_0x525d('0x41')][_0x525d('0x6a')][_0x6920fe]),'OpenchannelAccountId':Number(_0x251452[_0x525d('0x5f')]['id'])});}}else{socket[_0x525d('0xaf')]('userOpenchannelAccount:remove',{'UserId':Number(_0x251452[_0x525d('0x41')][_0x525d('0x6a')]),'OpenchannelAccountId':Number(_0x251452[_0x525d('0x5f')]['id'])});}});}})[_0x525d('0x1f')](respondWithStatusCode(_0x327822,null))[_0x525d('0x51')](handleError(_0x327822,null));};exports[_0x525d('0xb3')]=function(_0x2251b0,_0x1746ba,_0x291ddf){var _0x466ba6={};var _0x6b0cc1={};var _0x4f21bc;var _0x50afff;return db[_0x525d('0x4f')]['findOne']({'where':{'id':_0x2251b0[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x1746ba,null))[_0x525d('0x1f')](function(_0x3763f7){if(_0x3763f7){_0x4f21bc=_0x3763f7;_0x6b0cc1[_0x525d('0x46')]=_[_0x525d('0x40')](db[_0x525d('0x97')][_0x525d('0x3d')]);_0x6b0cc1[_0x525d('0x41')]=_[_0x525d('0x40')](_0x2251b0[_0x525d('0x41')]);_0x6b0cc1[_0x525d('0x42')]=_[_0x525d('0x43')](_0x6b0cc1[_0x525d('0x46')],_0x6b0cc1['query']);_0x466ba6['attributes']=_[_0x525d('0x43')](_0x6b0cc1['model'],qs[_0x525d('0x53')](_0x2251b0[_0x525d('0x41')][_0x525d('0x53')]));_0x466ba6[_0x525d('0x44')]=_0x466ba6['attributes'][_0x525d('0x45')]?_0x466ba6[_0x525d('0x44')]:_0x6b0cc1[_0x525d('0x46')];_0x466ba6[_0x525d('0x48')]=qs[_0x525d('0x49')](_0x2251b0[_0x525d('0x41')][_0x525d('0x49')]);_0x466ba6[_0x525d('0x68')]=qs[_0x525d('0x42')](_[_0x525d('0x67')](_0x2251b0['query'],_0x6b0cc1[_0x525d('0x42')]));if(_0x2251b0[_0x525d('0x41')][_0x525d('0x4a')]){_0x466ba6[_0x525d('0x68')]=_[_0x525d('0x54')](_0x466ba6['where'],{'$or':_[_0x525d('0x3c')](_0x466ba6[_0x525d('0x44')],function(_0x48d566){var _0x6ae73c={};_0x6ae73c[_0x48d566]={'$like':'%'+_0x2251b0[_0x525d('0x41')][_0x525d('0x4a')]+'%'};return _0x6ae73c;})});}_0x466ba6=_[_0x525d('0x54')]({},_0x466ba6,_0x2251b0[_0x525d('0x4c')]);return _0x4f21bc['getAgents'](_0x466ba6);}})[_0x525d('0x1f')](function(_0x4f2fa6){if(_0x4f2fa6){_0x50afff=_0x4f2fa6[_0x525d('0x45')];if(!_0x2251b0[_0x525d('0x41')][_0x525d('0x66')](_0x525d('0x47'))){_0x466ba6[_0x525d('0x30')]=qs[_0x525d('0x30')](_0x2251b0['query'][_0x525d('0x30')]);_0x466ba6[_0x525d('0x2e')]=qs[_0x525d('0x2e')](_0x2251b0[_0x525d('0x41')][_0x525d('0x2e')]);}return _0x4f21bc[_0x525d('0xb3')](_0x466ba6);}})[_0x525d('0x1f')](function(_0x23bcc0){if(_0x23bcc0){return _0x23bcc0?{'count':_0x50afff,'rows':_0x23bcc0}:null;}})[_0x525d('0x1f')](respondWithResult(_0x1746ba,null))[_0x525d('0x51')](handleError(_0x1746ba,null));};exports[_0x525d('0x39')]=function(_0x2af6d1,_0x3bf1fb,_0x1ae876){var _0x167347,_0x32d207,_0x3a0e79;if(_[_0x525d('0x78')](_0x2af6d1[_0x525d('0x5e')][_0x525d('0x5e')])||_0x2af6d1['body'][_0x525d('0x5e')]===''){throw new db[(_0x525d('0x6f'))][(_0x525d('0x70'))](_0x525d('0x77'));}if(_[_0x525d('0x78')](_0x2af6d1[_0x525d('0x5e')]['to'])){}_0x167347=_0x2af6d1[_0x525d('0x5e')]['to'];return db[_0x525d('0x4f')]['findOne']({'where':{'id':_0x2af6d1[_0x525d('0x5f')]['id']}})[_0x525d('0x1f')](handleEntityNotFound(_0x3bf1fb,null))[_0x525d('0x1f')](function(_0x4c4bdd){if(_0x4c4bdd){return db[_0x525d('0x4f')]['find']({'where':{'id':_0x4c4bdd['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x525d('0x6e')],'as':_0x525d('0x7d'),'where':{[_0x4c4bdd[_0x525d('0x79')]]:_0x167347},'limit':0x1,'order':[[_0x525d('0x73'),_0x525d('0x7e')]]}]}]})[_0x525d('0x1f')](handleEntityNotFound(_0x3bf1fb,null))[_0x525d('0x1f')](function(_0x55da49){if(_0x55da49&&_0x55da49[_0x525d('0x7c')]){_0x32d207=_0x55da49[_0x525d('0x35')]({'plain':!![]});if(_0x32d207[_0x525d('0x7c')]&&_0x32d207['List'][_0x525d('0x7d')][_0x525d('0x45')]){return _0x32d207[_0x525d('0x7c')]['Contacts'][0x0];}return db[_0x525d('0x6e')][_0x525d('0x55')](_[_0x525d('0x17')](_0x2af6d1['body'],{'firstName':_0x167347,[_0x55da49[_0x525d('0x79')]]:_0x167347,'phone':_0x167347,'ListId':_0x32d207['ListId']}));}})[_0x525d('0x1f')](handleEntityNotFound(_0x3bf1fb,null))['then'](function(_0x29bb29){if(_0x29bb29){_0x3a0e79=_0x29bb29;return db[_0x525d('0x8a')]['find']({'where':{'ContactId':_0x3a0e79['id'],'closed':![],'OpenchannelAccountId':_0x32d207['id']}})[_0x525d('0x1f')](function(_0x54a5d3){if(_0x54a5d3){return[_0x54a5d3,![]];}return db[_0x525d('0x8a')][_0x525d('0x55')]({'UserId':_0x2af6d1[_0x525d('0x56')]['id'],'ContactId':_0x3a0e79['id'],'OpenchannelAccountId':_0x32d207['id'],'lastMsgDirection':_0x525d('0xb4'),'firstMsgDirection':_0x525d('0xb4'),'Messages':[_['merge'](_0x2af6d1[_0x525d('0x5e')],{'read':![],'body':_0x2af6d1[_0x525d('0x5e')]['body'],'OpenchannelAccountId':_0x32d207['id'],'UserId':_0x2af6d1[_0x525d('0x56')]['id'],'ContactId':_0x3a0e79['id']})]},{'include':[{'model':db[_0x525d('0x93')],'as':'Messages'}]})['then'](function(_0x162cb1){return[_0x162cb1,!![]];});});}})[_0x525d('0x8d')](function(_0x196046,_0x4b48b9){if(_0x4b48b9){return _0x196046;}return db[_0x525d('0x93')][_0x525d('0x55')](_[_0x525d('0x54')](_0x2af6d1[_0x525d('0x5e')],{'read':![],'body':_0x2af6d1[_0x525d('0x5e')]['body'],'OpenchannelAccountId':_0x32d207['id'],'OpenchannelInteractionId':_0x196046['id'],'UserId':_0x2af6d1[_0x525d('0x56')]['id'],'ContactId':_0x3a0e79['id']}))['then'](function(_0x5c0f6f){_0x196046[_0x525d('0xb5')][_0x525d('0xb6')]=[];_0x196046[_0x525d('0xb5')][_0x525d('0xb6')][_0x525d('0xb7')](_0x5c0f6f[_0x525d('0xb5')]);return _0x196046;});});}})['then'](respondWithResult(_0x3bf1fb,null))['catch'](handleError(_0x3bf1fb,null));};
\ No newline at end of file
+var _0x3d30=['rows','show','params','options','create','body','user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','mandatoryDispositionPause','describe','OpenchannelAccountId','Disposition','getDispositions','findOne','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','CmContact','Sequelize','no\x20available\x20attributes','difference','createdAt','CompanyId','ListId','isNil','from','ValidationError','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','account','applications','list','orderBy','priority','asc','contact','threadId','externalUrl','OpenchannelInteraction','spread','firstName','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','unshift','agent','waitForTheAssignedAgent','queueId','OpenchannelQueue','waitForTheAssignedQueue','Start','startRouting','EventManager','notify','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','finally','getApplications','getInteractions','Contact','User','Owner','internal','Tag','Tags','color','tag','addAgents','omit','userOpenchannelAccount:save','removeAgents','emit','userOpenchannelAccount:remove','getAgents','updatedAt','out','Messages','dataValues','zip-dir','request-promise','mustache','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/license/util','../../mysqldb','redis','defaults','localhost','./openchannelAccount.socket','register','jayson/promise','http','client','request','then','info','OpenchannelAccount,\x20%s,\x20%s','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','update','get','OpenchannelAccounts','UserProfileResource','destroy','stack','name','send','index','Pause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','includeAll','include','findAll'];(function(_0x7321a1,_0x2931e5){var _0x2dc2cd=function(_0x3b85ec){while(--_0x3b85ec){_0x7321a1['push'](_0x7321a1['shift']());}};_0x2dc2cd(++_0x2931e5);}(_0x3d30,0x6a));var _0x03d3=function(_0x1f284,_0x52aef1){_0x1f284=_0x1f284-0x0;var _0xf93943=_0x3d30[_0x1f284];return _0xf93943;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x03d3('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0x03d3('0x1'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x03d3('0x2'));var util=require('util');var path=require(_0x03d3('0x3'));var sox=require(_0x03d3('0x4'));var csv=require(_0x03d3('0x5'));var ejs=require(_0x03d3('0x6'));var fs=require('fs');var fs_extra=require(_0x03d3('0x7'));var _=require(_0x03d3('0x8'));var squel=require('squel');var crypto=require(_0x03d3('0x9'));var jsforce=require(_0x03d3('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x03d3('0x5'));var querystring=require(_0x03d3('0xb'));var Papa=require(_0x03d3('0xc'));var Redis=require(_0x03d3('0xd'));var authService=require(_0x03d3('0xe'));var qs=require(_0x03d3('0xf'));var as=require(_0x03d3('0x10'));var hardwareService=require(_0x03d3('0x11'));var logger=require(_0x03d3('0x12'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x03d3('0x13'));var db=require(_0x03d3('0x14'))['db'];config[_0x03d3('0x15')]=_[_0x03d3('0x16')](config[_0x03d3('0x15')],{'host':_0x03d3('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x03d3('0x15')]));require(_0x03d3('0x18'))[_0x03d3('0x19')](socket);var jayson=require(_0x03d3('0x1a'));var client=jayson['client'][_0x03d3('0x1b')]({'port':0x232c});var client9002=jayson[_0x03d3('0x1c')]['http']({'port':0x232a});function respondWithRpcPromise(_0x5f4f6a,_0x158ff2,_0x2d4052,_0x1fdb64){return new BPromise(function(_0x4a48c4,_0x25806f){var _0x214880=_0x1fdb64||client;return _0x214880[_0x03d3('0x1d')](_0x5f4f6a,_0x2d4052)[_0x03d3('0x1e')](function(_0x4c72fe){logger[_0x03d3('0x1f')](_0x03d3('0x20'),_0x158ff2,'request\x20sent');logger[_0x03d3('0x21')](_0x03d3('0x22'),_0x158ff2,'request\x20sent',JSON['stringify'](_0x4c72fe));if(_0x4c72fe[_0x03d3('0x23')]){if(_0x4c72fe[_0x03d3('0x23')][_0x03d3('0x24')]===0x1f4){logger[_0x03d3('0x23')](_0x03d3('0x20'),_0x158ff2,_0x4c72fe['error'][_0x03d3('0x25')]);return _0x25806f(_0x4c72fe[_0x03d3('0x23')][_0x03d3('0x25')]);}logger[_0x03d3('0x23')](_0x03d3('0x20'),_0x158ff2,_0x4c72fe[_0x03d3('0x23')][_0x03d3('0x25')]);return _0x4a48c4(_0x4c72fe[_0x03d3('0x23')][_0x03d3('0x25')]);}else{logger[_0x03d3('0x1f')](_0x03d3('0x20'),_0x158ff2,'request\x20sent');_0x4a48c4(_0x4c72fe[_0x03d3('0x26')][_0x03d3('0x25')]);}})[_0x03d3('0x27')](function(_0x2370ee){logger[_0x03d3('0x23')](_0x03d3('0x20'),_0x158ff2,_0x2370ee);_0x25806f(_0x2370ee);});});}function respondWithStatusCode(_0x439455,_0x3caf5b){_0x3caf5b=_0x3caf5b||0xcc;return function(_0x180db7){if(_0x180db7){return _0x439455[_0x03d3('0x28')](_0x3caf5b);}return _0x439455[_0x03d3('0x29')](_0x3caf5b)[_0x03d3('0x2a')]();};}function respondWithResult(_0x1f768e,_0x1605fe){_0x1605fe=_0x1605fe||0xc8;return function(_0x47f3bd){if(_0x47f3bd){return _0x1f768e[_0x03d3('0x29')](_0x1605fe)[_0x03d3('0x2b')](_0x47f3bd);}};}function respondWithFilteredResult(_0x380c95,_0x185711){return function(_0x4d1e3f){if(_0x4d1e3f){var _0x250d28=typeof _0x185711[_0x03d3('0x2c')]===_0x03d3('0x2d')&&typeof _0x185711[_0x03d3('0x2e')]===_0x03d3('0x2d');var _0x248677=_0x4d1e3f[_0x03d3('0x2f')];var _0x1f71ce=_0x250d28?0x0:_0x185711[_0x03d3('0x2c')];var _0x496677=_0x250d28?_0x4d1e3f[_0x03d3('0x2f')]:_0x185711[_0x03d3('0x2c')]+_0x185711[_0x03d3('0x2e')];var _0x384f52;if(_0x496677>=_0x248677){_0x496677=_0x248677;_0x384f52=0xc8;}else{_0x384f52=0xce;}_0x380c95[_0x03d3('0x29')](_0x384f52);return _0x380c95[_0x03d3('0x30')](_0x03d3('0x31'),_0x1f71ce+'-'+_0x496677+'/'+_0x248677)['json'](_0x4d1e3f);}return null;};}function patchUpdates(_0x52a6ed){return function(_0x9f7a44){try{jsonpatch['apply'](_0x9f7a44,_0x52a6ed,!![]);}catch(_0xf8e49c){return BPromise[_0x03d3('0x32')](_0xf8e49c);}return _0x9f7a44['save']();};}function saveUpdates(_0x17c94c,_0x2c18d6){return function(_0x24b3de){if(_0x24b3de){return _0x24b3de[_0x03d3('0x33')](_0x17c94c)[_0x03d3('0x1e')](function(_0xe660fe){return _0xe660fe;});}return null;};}function removeEntity(_0x244e6b,_0x1d2982){return function(_0x3bb4df){if(_0x3bb4df){return _0x3bb4df['destroy']()[_0x03d3('0x1e')](function(){var _0x185c9c=_0x3bb4df[_0x03d3('0x34')]({'plain':!![]});var _0x5ac9c3=_0x03d3('0x35');return db[_0x03d3('0x36')][_0x03d3('0x37')]({'where':{'type':_0x5ac9c3,'resourceId':_0x185c9c['id']}})[_0x03d3('0x1e')](function(){return _0x3bb4df;});})[_0x03d3('0x1e')](function(){_0x244e6b[_0x03d3('0x29')](0xcc)['end']();});}};}function handleEntityNotFound(_0x97c0a1,_0x1154a6){return function(_0x193cda){if(!_0x193cda){_0x97c0a1[_0x03d3('0x28')](0x194);}return _0x193cda;};}function handleError(_0x85d749,_0x13e657){_0x13e657=_0x13e657||0x1f4;return function(_0x2ea95b){logger[_0x03d3('0x23')](_0x2ea95b[_0x03d3('0x38')]);if(_0x2ea95b[_0x03d3('0x39')]){delete _0x2ea95b[_0x03d3('0x39')];}_0x85d749[_0x03d3('0x29')](_0x13e657)[_0x03d3('0x3a')](_0x2ea95b);};}exports[_0x03d3('0x3b')]=function(_0x577f8c,_0x469f47){var _0x3061f1={'include':[{'model':db[_0x03d3('0x3c')],'as':'mandatoryDispositionPause'}]},_0x182896={},_0x4894e7={'count':0x0,'rows':[]};var _0x4a0bf4=_[_0x03d3('0x3d')](db[_0x03d3('0x3e')][_0x03d3('0x3f')],function(_0xea1d9c){return{'name':_0xea1d9c[_0x03d3('0x40')],'type':_0xea1d9c[_0x03d3('0x41')]['key']};});_0x182896[_0x03d3('0x42')]=_[_0x03d3('0x3d')](_0x4a0bf4,'name');_0x182896['query']=_[_0x03d3('0x43')](_0x577f8c[_0x03d3('0x44')]);_0x182896[_0x03d3('0x45')]=_['intersection'](_0x182896[_0x03d3('0x42')],_0x182896['query']);_0x3061f1['attributes']=_[_0x03d3('0x46')](_0x182896[_0x03d3('0x42')],qs[_0x03d3('0x47')](_0x577f8c['query'][_0x03d3('0x47')]));_0x3061f1[_0x03d3('0x48')]=_0x3061f1[_0x03d3('0x48')][_0x03d3('0x49')]?_0x3061f1[_0x03d3('0x48')]:_0x182896[_0x03d3('0x42')];if(!_0x577f8c['query'][_0x03d3('0x4a')](_0x03d3('0x4b'))){_0x3061f1[_0x03d3('0x2e')]=qs['limit'](_0x577f8c[_0x03d3('0x44')][_0x03d3('0x2e')]);_0x3061f1[_0x03d3('0x2c')]=qs[_0x03d3('0x2c')](_0x577f8c[_0x03d3('0x44')]['offset']);}_0x3061f1[_0x03d3('0x4c')]=qs[_0x03d3('0x4d')](_0x577f8c[_0x03d3('0x44')][_0x03d3('0x4d')]);_0x3061f1['where']=qs[_0x03d3('0x45')](_[_0x03d3('0x4e')](_0x577f8c[_0x03d3('0x44')],_0x182896['filters']),_0x4a0bf4);if(_0x577f8c[_0x03d3('0x44')][_0x03d3('0x4f')]){_0x3061f1[_0x03d3('0x50')]=_[_0x03d3('0x51')](_0x3061f1[_0x03d3('0x50')],{'$or':_[_0x03d3('0x3d')](_0x4a0bf4,function(_0x188f76){if(_0x188f76[_0x03d3('0x41')]!==_0x03d3('0x52')){var _0x5759c4={};_0x5759c4[_0x188f76['name']]={'$like':'%'+_0x577f8c[_0x03d3('0x44')][_0x03d3('0x4f')]+'%'};return _0x5759c4;}})});}_0x3061f1=_[_0x03d3('0x51')]({},_0x3061f1,_0x577f8c['options']);var _0xaa6db2={'where':_0x3061f1[_0x03d3('0x50')]};return db['OpenchannelAccount']['count'](_0xaa6db2)[_0x03d3('0x1e')](function(_0x55b9fc){_0x4894e7[_0x03d3('0x2f')]=_0x55b9fc;if(_0x577f8c[_0x03d3('0x44')][_0x03d3('0x53')]){_0x3061f1[_0x03d3('0x54')]=[{'all':!![]}];}return db['OpenchannelAccount'][_0x03d3('0x55')](_0x3061f1);})[_0x03d3('0x1e')](function(_0x185ad8){_0x4894e7[_0x03d3('0x56')]=_0x185ad8;return _0x4894e7;})[_0x03d3('0x1e')](respondWithFilteredResult(_0x469f47,_0x3061f1))[_0x03d3('0x27')](handleError(_0x469f47,null));};exports[_0x03d3('0x57')]=function(_0x506fac,_0x41c0d0){var _0x17ecd1={'raw':![],'where':{'id':_0x506fac[_0x03d3('0x58')]['id']},'include':[{'model':db[_0x03d3('0x3c')],'as':'mandatoryDispositionPause'}]},_0x304d79={};_0x304d79[_0x03d3('0x42')]=_[_0x03d3('0x43')](db[_0x03d3('0x3e')][_0x03d3('0x3f')]);_0x304d79[_0x03d3('0x44')]=_[_0x03d3('0x43')](_0x506fac['query']);_0x304d79[_0x03d3('0x45')]=_['intersection'](_0x304d79[_0x03d3('0x42')],_0x304d79[_0x03d3('0x44')]);_0x17ecd1[_0x03d3('0x48')]=_[_0x03d3('0x46')](_0x304d79[_0x03d3('0x42')],qs[_0x03d3('0x47')](_0x506fac['query'][_0x03d3('0x47')]));_0x17ecd1[_0x03d3('0x48')]=_0x17ecd1['attributes'][_0x03d3('0x49')]?_0x17ecd1['attributes']:_0x304d79[_0x03d3('0x42')];if(_0x506fac[_0x03d3('0x44')]['includeAll']){_0x17ecd1['include']=[{'all':!![]}];}_0x17ecd1=_[_0x03d3('0x51')]({},_0x17ecd1,_0x506fac[_0x03d3('0x59')]);return db[_0x03d3('0x3e')]['find'](_0x17ecd1)[_0x03d3('0x1e')](handleEntityNotFound(_0x41c0d0,null))[_0x03d3('0x1e')](respondWithResult(_0x41c0d0,null))[_0x03d3('0x27')](handleError(_0x41c0d0,null));};exports['create']=function(_0x34bc5a,_0x40cbf7){return db[_0x03d3('0x3e')][_0x03d3('0x5a')](_0x34bc5a[_0x03d3('0x5b')],{})[_0x03d3('0x1e')](function(_0x58ac7d){var _0x444242=_0x34bc5a[_0x03d3('0x5c')][_0x03d3('0x34')]({'plain':!![]});if(!_0x444242)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x444242[_0x03d3('0x5d')]===_0x03d3('0x5c')){var _0x1516b7=_0x58ac7d[_0x03d3('0x34')]({'plain':!![]});var _0x3e87d3=_0x03d3('0x35');return db[_0x03d3('0x5e')][_0x03d3('0x5f')]({'where':{'name':_0x3e87d3,'userProfileId':_0x444242[_0x03d3('0x60')]},'raw':!![]})['then'](function(_0x45c58d){if(_0x45c58d&&_0x45c58d[_0x03d3('0x61')]===0x0){return db[_0x03d3('0x36')][_0x03d3('0x5a')]({'name':_0x1516b7[_0x03d3('0x39')],'resourceId':_0x1516b7['id'],'type':_0x45c58d['name'],'sectionId':_0x45c58d['id']},{})[_0x03d3('0x1e')](function(){return _0x58ac7d;});}else{return _0x58ac7d;}})['catch'](function(_0x24fe69){logger[_0x03d3('0x23')](_0x03d3('0x62'),_0x24fe69);throw _0x24fe69;});}return _0x58ac7d;})[_0x03d3('0x1e')](respondWithResult(_0x40cbf7,0xc9))[_0x03d3('0x27')](handleError(_0x40cbf7,null));};exports[_0x03d3('0x33')]=function(_0x3fe2ea,_0x3f7868){if(_0x3fe2ea[_0x03d3('0x5b')]['id']){delete _0x3fe2ea[_0x03d3('0x5b')]['id'];}return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x3fe2ea['params']['id']},'include':[{'model':db['Pause'],'as':_0x03d3('0x63')}]})[_0x03d3('0x1e')](handleEntityNotFound(_0x3f7868,null))[_0x03d3('0x1e')](saveUpdates(_0x3fe2ea['body'],null))[_0x03d3('0x1e')](respondWithResult(_0x3f7868,null))['catch'](handleError(_0x3f7868,null));};exports[_0x03d3('0x37')]=function(_0x2f778c,_0x3ff57f){return db[_0x03d3('0x3e')]['find']({'where':{'id':_0x2f778c[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x3ff57f,null))[_0x03d3('0x1e')](removeEntity(_0x3ff57f,null))[_0x03d3('0x27')](handleError(_0x3ff57f,null));};exports[_0x03d3('0x64')]=function(_0x7fa5cb,_0x2eec4b){return db[_0x03d3('0x3e')][_0x03d3('0x64')]()[_0x03d3('0x1e')](respondWithResult(_0x2eec4b,null))[_0x03d3('0x27')](handleError(_0x2eec4b,null));};exports['addDisposition']=function(_0x1e284d,_0x8666a,_0x28cb26){if(_0x1e284d[_0x03d3('0x5b')]['id']){delete _0x1e284d[_0x03d3('0x5b')]['id'];}return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x1e284d[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x8666a,null))[_0x03d3('0x1e')](function(_0xb59d34){if(_0xb59d34){_0x1e284d[_0x03d3('0x5b')][_0x03d3('0x65')]=_0xb59d34['id'];return db[_0x03d3('0x66')]['create'](_0x1e284d[_0x03d3('0x5b')]);}})[_0x03d3('0x1e')](respondWithResult(_0x8666a,null))[_0x03d3('0x27')](handleError(_0x8666a,null));};exports[_0x03d3('0x67')]=function(_0x1a5c3b,_0x4a052e,_0x56bea2){var _0x4811d7={'raw':![],'where':{}};var _0x2a31d0={};var _0x592980={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x03d3('0x68')]({'where':{'id':_0x1a5c3b[_0x03d3('0x58')]['id']}})['then'](handleEntityNotFound(_0x4a052e,null))[_0x03d3('0x1e')](function(_0x34bc38){if(_0x34bc38){_0x2a31d0[_0x03d3('0x42')]=_[_0x03d3('0x43')](db[_0x03d3('0x66')][_0x03d3('0x3f')]);_0x2a31d0[_0x03d3('0x44')]=_[_0x03d3('0x43')](_0x1a5c3b[_0x03d3('0x44')]);_0x2a31d0[_0x03d3('0x45')]=_[_0x03d3('0x46')](_0x2a31d0['model'],_0x2a31d0[_0x03d3('0x44')]);_0x4811d7[_0x03d3('0x48')]=_[_0x03d3('0x46')](_0x2a31d0['model'],qs[_0x03d3('0x47')](_0x1a5c3b[_0x03d3('0x44')]['fields']));_0x4811d7[_0x03d3('0x48')]=_0x4811d7[_0x03d3('0x48')]['length']?_0x4811d7[_0x03d3('0x48')]:_0x2a31d0[_0x03d3('0x42')];if(!_0x1a5c3b[_0x03d3('0x44')][_0x03d3('0x4a')]('nolimit')){_0x4811d7[_0x03d3('0x2e')]=qs[_0x03d3('0x2e')](_0x1a5c3b[_0x03d3('0x44')]['limit']);_0x4811d7[_0x03d3('0x2c')]=qs[_0x03d3('0x2c')](_0x1a5c3b['query'][_0x03d3('0x2c')]);}_0x4811d7[_0x03d3('0x4c')]=qs[_0x03d3('0x4d')](_0x1a5c3b[_0x03d3('0x44')]['sort']);_0x4811d7[_0x03d3('0x50')]=qs[_0x03d3('0x45')](_[_0x03d3('0x4e')](_0x1a5c3b['query'],_0x2a31d0[_0x03d3('0x45')]));_0x4811d7[_0x03d3('0x50')]['OpenchannelAccountId']=_0x34bc38['id'];if(_0x1a5c3b['query'][_0x03d3('0x4f')]){_0x4811d7[_0x03d3('0x50')]=_[_0x03d3('0x51')](_0x4811d7[_0x03d3('0x50')],{'$or':_['map'](_0x4811d7['attributes'],function(_0x3fec10){var _0x35ce9b={};_0x35ce9b[_0x3fec10]={'$like':'%'+_0x1a5c3b[_0x03d3('0x44')]['filter']+'%'};return _0x35ce9b;})});}_0x4811d7=_[_0x03d3('0x51')]({},_0x4811d7,_0x1a5c3b[_0x03d3('0x59')]);return db['Disposition'][_0x03d3('0x2f')]({'where':_0x4811d7['where']})[_0x03d3('0x1e')](function(_0x587629){_0x592980[_0x03d3('0x2f')]=_0x587629;if(_0x1a5c3b[_0x03d3('0x44')][_0x03d3('0x53')]){_0x4811d7[_0x03d3('0x54')]=[{'all':!![]}];}return db[_0x03d3('0x66')][_0x03d3('0x55')](_0x4811d7);})['then'](function(_0x20d271){_0x592980[_0x03d3('0x56')]=_0x20d271;return _0x592980;});}})[_0x03d3('0x1e')](respondWithFilteredResult(_0x4a052e,_0x4811d7))[_0x03d3('0x27')](handleError(_0x4a052e,null));};exports[_0x03d3('0x69')]=function(_0x1f8bf5,_0x2bb507,_0x7c4f92){return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x1f8bf5['params']['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x2bb507,null))['then'](function(_0x5bcf1e){if(_0x5bcf1e){return _0x5bcf1e[_0x03d3('0x69')](_0x1f8bf5['query'][_0x03d3('0x6a')]);}})['then'](respondWithStatusCode(_0x2bb507,null))['catch'](handleError(_0x2bb507,null));};exports[_0x03d3('0x6b')]=function(_0x57da81,_0x2ddccd,_0x2536ff){if(_0x57da81[_0x03d3('0x5b')]['id']){delete _0x57da81['body']['id'];}return db['OpenchannelAccount'][_0x03d3('0x5f')]({'where':{'id':_0x57da81[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x2ddccd,null))[_0x03d3('0x1e')](function(_0x4687c2){if(_0x4687c2){_0x57da81[_0x03d3('0x5b')][_0x03d3('0x65')]=_0x4687c2['id'];return db[_0x03d3('0x6c')][_0x03d3('0x5a')](_0x57da81[_0x03d3('0x5b')]);}})['then'](respondWithResult(_0x2ddccd,null))[_0x03d3('0x27')](handleError(_0x2ddccd,null));};exports[_0x03d3('0x6d')]=function(_0xac950f,_0xaa5d80,_0x5b0d14){var _0x457ffa={'raw':![],'where':{}};var _0x39c1bf={};var _0x279834={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x03d3('0x68')]({'where':{'id':_0xac950f[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0xaa5d80,null))[_0x03d3('0x1e')](function(_0x3700d7){if(_0x3700d7){_0x39c1bf[_0x03d3('0x42')]=_[_0x03d3('0x43')](db[_0x03d3('0x6c')][_0x03d3('0x3f')]);_0x39c1bf[_0x03d3('0x44')]=_[_0x03d3('0x43')](_0xac950f['query']);_0x39c1bf[_0x03d3('0x45')]=_[_0x03d3('0x46')](_0x39c1bf[_0x03d3('0x42')],_0x39c1bf[_0x03d3('0x44')]);_0x457ffa[_0x03d3('0x48')]=_['intersection'](_0x39c1bf['model'],qs[_0x03d3('0x47')](_0xac950f['query'][_0x03d3('0x47')]));_0x457ffa['attributes']=_0x457ffa[_0x03d3('0x48')][_0x03d3('0x49')]?_0x457ffa[_0x03d3('0x48')]:_0x39c1bf['model'];if(!_0xac950f[_0x03d3('0x44')]['hasOwnProperty'](_0x03d3('0x4b'))){_0x457ffa[_0x03d3('0x2e')]=qs[_0x03d3('0x2e')](_0xac950f['query'][_0x03d3('0x2e')]);_0x457ffa[_0x03d3('0x2c')]=qs[_0x03d3('0x2c')](_0xac950f[_0x03d3('0x44')][_0x03d3('0x2c')]);}_0x457ffa[_0x03d3('0x4c')]=qs[_0x03d3('0x4d')](_0xac950f[_0x03d3('0x44')]['sort']);_0x457ffa['where']=qs['filters'](_[_0x03d3('0x4e')](_0xac950f['query'],_0x39c1bf[_0x03d3('0x45')]));_0x457ffa[_0x03d3('0x50')][_0x03d3('0x65')]=_0x3700d7['id'];if(_0xac950f[_0x03d3('0x44')][_0x03d3('0x4f')]){_0x457ffa[_0x03d3('0x50')]=_[_0x03d3('0x51')](_0x457ffa[_0x03d3('0x50')],{'$or':_[_0x03d3('0x3d')](_0x457ffa['attributes'],function(_0x43c2d2){var _0x10ce41={};_0x10ce41[_0x43c2d2]={'$like':'%'+_0xac950f[_0x03d3('0x44')]['filter']+'%'};return _0x10ce41;})});}_0x457ffa=_[_0x03d3('0x51')]({},_0x457ffa,_0xac950f[_0x03d3('0x59')]);return db[_0x03d3('0x6c')][_0x03d3('0x2f')]({'where':_0x457ffa['where']})[_0x03d3('0x1e')](function(_0xc4dc20){_0x279834[_0x03d3('0x2f')]=_0xc4dc20;if(_0xac950f[_0x03d3('0x44')][_0x03d3('0x53')]){_0x457ffa[_0x03d3('0x54')]=[{'all':!![]}];}return db[_0x03d3('0x6c')]['findAll'](_0x457ffa);})[_0x03d3('0x1e')](function(_0x4e137f){_0x279834[_0x03d3('0x56')]=_0x4e137f;return _0x279834;});}})[_0x03d3('0x1e')](respondWithFilteredResult(_0xaa5d80,_0x457ffa))[_0x03d3('0x27')](handleError(_0xaa5d80,null));};exports[_0x03d3('0x6e')]=function(_0x3e3a1a,_0x48fb0d,_0x3342bc){return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x3e3a1a[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x48fb0d,null))[_0x03d3('0x1e')](function(_0x253507){if(_0x253507){return _0x253507[_0x03d3('0x6e')](_0x3e3a1a[_0x03d3('0x44')]['ids']);}})[_0x03d3('0x1e')](respondWithStatusCode(_0x48fb0d,null))[_0x03d3('0x27')](handleError(_0x48fb0d,null));};exports['notify']=function(_0x329a79,_0x25a1f0,_0x2c1ecc){var _0x4d025d={'body':_0x329a79[_0x03d3('0x5b')],'channel':'openchannel'};var _0x53c5ca=[];var _0x5edcdb=[];var _0x521695={};var _0x165ffc=![];return db[_0x03d3('0x6f')]['describe']()[_0x03d3('0x1e')](function(_0x5d2eb3){if(!_0x5d2eb3){throw new db[(_0x03d3('0x70'))]['ValidationError'](_0x03d3('0x71'));}_0x53c5ca=_[_0x03d3('0x72')](_[_0x03d3('0x43')](_0x5d2eb3),['createdAt','updatedAt']);_0x5edcdb=_[_0x03d3('0x72')](_[_0x03d3('0x43')](_0x5d2eb3),[_0x03d3('0x73'),'updatedAt',_0x03d3('0x74'),_0x03d3('0x75')]);if(_0x329a79[_0x03d3('0x5b')]['id']){delete _0x329a79[_0x03d3('0x5b')]['id'];}if(_[_0x03d3('0x76')](_0x329a79[_0x03d3('0x5b')][_0x03d3('0x77')])){throw new db[(_0x03d3('0x70'))][(_0x03d3('0x78'))](_0x03d3('0x79'));}if(_['isNil'](_0x329a79[_0x03d3('0x5b')][_0x03d3('0x5b')])||_0x329a79[_0x03d3('0x5b')]['body']===''){throw new db[(_0x03d3('0x70'))][(_0x03d3('0x78'))](_0x03d3('0x7a'));}if(_['isNil'](_0x329a79[_0x03d3('0x5b')]['mapKey'])){throw new db[(_0x03d3('0x70'))][(_0x03d3('0x78'))](_0x03d3('0x7b')+_0x5edcdb);}if(!_[_0x03d3('0x7c')](_0x5edcdb,_0x329a79['body'][_0x03d3('0x7d')])){throw new db['Sequelize']['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5edcdb);}_0x521695[_0x329a79[_0x03d3('0x5b')][_0x03d3('0x7d')]]=_0x329a79[_0x03d3('0x5b')][_0x03d3('0x77')];})[_0x03d3('0x1e')](function(){return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x329a79[_0x03d3('0x58')]['id']},'include':[{'model':db[_0x03d3('0x7e')],'as':_0x03d3('0x7f'),'include':[{'model':db[_0x03d3('0x6f')],'as':_0x03d3('0x80'),'where':_0x521695,'limit':0x1,'order':[['updatedAt',_0x03d3('0x81')]]}]},{'model':db[_0x03d3('0x82')],'as':_0x03d3('0x83')}]});})[_0x03d3('0x1e')](handleEntityNotFound(_0x25a1f0,null))['then'](function(_0x15506a){if(_0x15506a&&_0x15506a['List']){_0x4d025d[_0x03d3('0x84')]=_0x15506a;_0x4d025d[_0x03d3('0x85')]=_0x15506a[_0x03d3('0x83')];_0x4d025d[_0x03d3('0x86')]=_0x15506a['List'];_0x4d025d['applications']=_[_0x03d3('0x87')](_0x4d025d[_0x03d3('0x85')],[_0x03d3('0x88')],[_0x03d3('0x89')]);if(_0x4d025d[_0x03d3('0x84')][_0x03d3('0x83')]){delete _0x4d025d[_0x03d3('0x84')]['Applications'];}if(_0x4d025d[_0x03d3('0x84')][_0x03d3('0x7f')]&&_0x4d025d[_0x03d3('0x84')]['List'][_0x03d3('0x80')][_0x03d3('0x49')]){return _0x4d025d[_0x03d3('0x84')][_0x03d3('0x7f')]['Contacts'][0x0];}var _0x56e3a0=_[_0x03d3('0x16')](_0x329a79[_0x03d3('0x5b')],{'firstName':_0x329a79[_0x03d3('0x5b')][_0x03d3('0x77')],'ListId':_0x15506a[_0x03d3('0x75')]});_0x56e3a0[_0x329a79[_0x03d3('0x5b')][_0x03d3('0x7d')]]=_0x329a79[_0x03d3('0x5b')]['from'];return db[_0x03d3('0x6f')][_0x03d3('0x5a')](_0x56e3a0,{'fields':_0x53c5ca,'raw':!![]});}})[_0x03d3('0x1e')](handleEntityNotFound(_0x25a1f0,null))['then'](function(_0x3149b6){_0x4d025d[_0x03d3('0x8a')]=_0x3149b6;if(_0x3149b6){var _0x5b499e={'ContactId':_0x3149b6['id'],'OpenchannelAccountId':_0x329a79[_0x03d3('0x58')]['id'],'from':(_0x3149b6['firstName']||'')+'\x20'+(_0x3149b6['lastName']||'')};var _0x41f893={'OpenchannelAccountId':_0x329a79[_0x03d3('0x58')]['id'],'closed':![]};if(_0x329a79[_0x03d3('0x5b')]['threadId']){_0x41f893['threadId']=_0x329a79[_0x03d3('0x5b')]['threadId'];return db['OpenchannelInteraction'][_0x03d3('0x5f')]({'where':_0x41f893})[_0x03d3('0x1e')](function(_0x2e7649){if(_0x2e7649){return[_0x2e7649,![]];}_0x5b499e[_0x03d3('0x8b')]=_0x329a79[_0x03d3('0x5b')][_0x03d3('0x8b')];_0x5b499e[_0x03d3('0x8c')]=_0x329a79[_0x03d3('0x5b')][_0x03d3('0x8c')];return db[_0x03d3('0x8d')]['create'](_0x5b499e)[_0x03d3('0x1e')](function(_0x14df75){return[_0x14df75,!![]];});});}else{_0x41f893['threadId']=null;}_0x41f893['ContactId']=_0x3149b6['id'];return db[_0x03d3('0x8d')][_0x03d3('0x5f')]({'where':_0x41f893})['then'](function(_0x43f34b){if(_0x43f34b){return[_0x43f34b,![]];}return db[_0x03d3('0x8d')]['create'](_0x5b499e)['then'](function(_0x499759){return[_0x499759,!![]];});});}})[_0x03d3('0x8e')](function(_0x4a5d20,_0x4f44a6){if(_0x4a5d20){_0x165ffc=_0x4f44a6;if(!_0x4f44a6){var _0x581952={'from':(_0x4d025d[_0x03d3('0x8a')][_0x03d3('0x8f')]||'')+'\x20'+(_0x4d025d['contact']['lastName']||'')};if(_0x329a79[_0x03d3('0x5b')]['threadId']&&_0x329a79[_0x03d3('0x5b')][_0x03d3('0x90')]&&_0x329a79[_0x03d3('0x5b')][_0x03d3('0x8b')]!=_0x329a79[_0x03d3('0x5b')]['messageId']){_0x581952['threadId']=_0x329a79[_0x03d3('0x5b')][_0x03d3('0x90')];}return _0x4a5d20[_0x03d3('0x33')](_0x581952);}else{return _0x4a5d20;}}})[_0x03d3('0x1e')](function(_0x42d1c5){_0x4d025d[_0x03d3('0x91')]=_0x42d1c5[_0x03d3('0x34')]({'plain':!![]});_0x4d025d[_0x03d3('0x91')][_0x03d3('0x92')]=_0x165ffc;if(_0x4d025d['interaction'][_0x03d3('0x92')]){if(_0x4d025d[_0x03d3('0x84')][_0x03d3('0x93')]){_0x4d025d[_0x03d3('0x85')][_0x03d3('0x94')]({'id':0x0,'priority':_0x4d025d[_0x03d3('0x85')]['length']+0x1,'app':_0x03d3('0x95'),'appdata':_0x03d3('0x96'),'interval':_0x03d3('0x97')});}}return db[_0x03d3('0x98')][_0x03d3('0x5a')]({'body':_0x329a79[_0x03d3('0x5b')][_0x03d3('0x5b')],'OpenchannelAccountId':_0x329a79['params']['id'],'OpenchannelInteractionId':_0x42d1c5['id'],'direction':'in','ContactId':_0x4d025d['contact']['id'],'AttachmentId':_0x329a79[_0x03d3('0x5b')][_0x03d3('0x99')]});})[_0x03d3('0x1e')](function(_0x4e8aef){_0x4d025d['message']=_0x4e8aef;if(!_0x4d025d['interaction'][_0x03d3('0x9a')])return;return db['User'][_0x03d3('0x5f')]({'attributes':['id','name'],'where':{'id':_0x4d025d[_0x03d3('0x91')]['UserId']}});})[_0x03d3('0x1e')](function(_0x1c064f){if(_0x1c064f){_0x4d025d[_0x03d3('0x85')][_0x03d3('0x9b')]({'id':0x0,'priority':0x0,'app':_0x03d3('0x9c'),'appdata':_0x1c064f[_0x03d3('0x39')]+','+(_0x4d025d[_0x03d3('0x84')][_0x03d3('0x9d')]||0xa),'interval':_0x03d3('0x97')});}if(!_0x4d025d[_0x03d3('0x91')][_0x03d3('0x9e')])return;return db[_0x03d3('0x9f')][_0x03d3('0x5f')]({'attributes':['id',_0x03d3('0x39')],'where':{'id':_0x4d025d[_0x03d3('0x91')][_0x03d3('0x9e')]}});})['then'](function(_0x4c4289){if(_0x4c4289){_0x4d025d['applications']['unshift']({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x4c4289['name']+','+(_0x4d025d[_0x03d3('0x84')][_0x03d3('0xa0')]||0x12c),'interval':_0x03d3('0x97')});}return respondWithRpcPromise(_0x03d3('0xa1'),_0x03d3('0xa2'),_0x4d025d);})['then'](function(_0x4927bd){respondWithRpcPromise(_0x03d3('0xa3'),_0x03d3('0xa3'),{'event':_0x03d3('0xa4'),'message':_0x4927bd},client9002);return _0x4927bd;})['then'](respondWithResult(_0x25a1f0,null))[_0x03d3('0x27')](handleError(_0x25a1f0,null));};exports['addApplications']=function(_0x4d96df,_0x2e9716){var _0x2735f0=_0x4d96df['params']['id'];var _0x2a59aa=_0x4d96df[_0x03d3('0x5b')];var _0xd1a1eb=0xc8;var _0x7bf1f2=null;return db[_0x03d3('0xa5')][_0x03d3('0xa6')]({'isolationLevel':db['sequelize'][_0x03d3('0xa7')][_0x03d3('0xa8')][_0x03d3('0xa9')]},function(_0x3baf84){return db[_0x03d3('0x3e')][_0x03d3('0x68')]({'where':{'id':_0x2735f0},'transaction':_0x3baf84})[_0x03d3('0x1e')](function(_0x1d8179){if(_0x1d8179){return db[_0x03d3('0x82')][_0x03d3('0x37')]({'where':{'OpenchannelAccountId':_0x2735f0},'transaction':_0x3baf84})[_0x03d3('0x1e')](function(){var _0x4cd221=_[_0x03d3('0x3d')](_0x2a59aa,function(_0x907073){_0x907073[_0x03d3('0x65')]=_0x2735f0;return _0x907073;});return db[_0x03d3('0x82')]['bulkCreate'](_0x4cd221,{'transaction':_0x3baf84});});}else{_0xd1a1eb=0x194;_0x7bf1f2=[];}});})[_0x03d3('0x1e')](function(){if(_0xd1a1eb!==0x194){return db[_0x03d3('0x82')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0x2735f0},'order':_0x03d3('0x88')})['then'](function(_0x4f0112){_0x7bf1f2=_0x4f0112;});}})[_0x03d3('0x27')](function(_0x16d515){_0xd1a1eb=0x1f4;logger['error'](_0x16d515[_0x03d3('0x38')]);if(_0x16d515[_0x03d3('0x39')]){delete _0x16d515[_0x03d3('0x39')];}_0x7bf1f2=_0x16d515;})[_0x03d3('0xaa')](function(){if(_0x7bf1f2===null){_0x2e9716['sendStatus'](_0xd1a1eb);}else{if(_0xd1a1eb===0x1f4){_0x2e9716[_0x03d3('0x29')](_0xd1a1eb)[_0x03d3('0x3a')](_0x7bf1f2);}else{_0x2e9716[_0x03d3('0x29')](_0xd1a1eb)['json'](_0x7bf1f2);}}});};exports['getApplications']=function(_0x342340,_0x4874dd,_0x52163c){var _0x3915ae={};var _0x1594da={};var _0x13f3e7;var _0x2507c4;return db[_0x03d3('0x3e')][_0x03d3('0x68')]({'where':{'id':_0x342340[_0x03d3('0x58')]['id']}})['then'](handleEntityNotFound(_0x4874dd,null))[_0x03d3('0x1e')](function(_0xafbdf7){if(_0xafbdf7){_0x13f3e7=_0xafbdf7;_0x1594da['model']=_[_0x03d3('0x43')](db[_0x03d3('0x82')][_0x03d3('0x3f')]);_0x1594da['query']=_[_0x03d3('0x43')](_0x342340[_0x03d3('0x44')]);_0x1594da[_0x03d3('0x45')]=_['intersection'](_0x1594da['model'],_0x1594da[_0x03d3('0x44')]);_0x3915ae[_0x03d3('0x48')]=_[_0x03d3('0x46')](_0x1594da['model'],qs['fields'](_0x342340[_0x03d3('0x44')][_0x03d3('0x47')]));_0x3915ae['attributes']=_0x3915ae[_0x03d3('0x48')]['length']?_0x3915ae[_0x03d3('0x48')]:_0x1594da['model'];_0x3915ae[_0x03d3('0x4c')]=qs[_0x03d3('0x4d')](_0x342340[_0x03d3('0x44')][_0x03d3('0x4d')]);_0x3915ae[_0x03d3('0x50')]=qs[_0x03d3('0x45')](_['pick'](_0x342340[_0x03d3('0x44')],_0x1594da[_0x03d3('0x45')]));if(_0x342340[_0x03d3('0x44')]['filter']){_0x3915ae[_0x03d3('0x50')]=_['merge'](_0x3915ae[_0x03d3('0x50')],{'$or':_[_0x03d3('0x3d')](_0x3915ae['attributes'],function(_0x32ef26){var _0x493932={};_0x493932[_0x32ef26]={'$like':'%'+_0x342340[_0x03d3('0x44')]['filter']+'%'};return _0x493932;})});}_0x3915ae=_[_0x03d3('0x51')]({},_0x3915ae,_0x342340[_0x03d3('0x59')]);return _0x13f3e7[_0x03d3('0xab')](_0x3915ae);}})[_0x03d3('0x1e')](function(_0x14be39){if(_0x14be39){_0x2507c4=_0x14be39['length'];if(!_0x342340[_0x03d3('0x44')]['hasOwnProperty'](_0x03d3('0x4b'))){_0x3915ae[_0x03d3('0x2e')]=qs['limit'](_0x342340['query'][_0x03d3('0x2e')]);_0x3915ae['offset']=qs[_0x03d3('0x2c')](_0x342340[_0x03d3('0x44')][_0x03d3('0x2c')]);}return _0x13f3e7[_0x03d3('0xab')](_0x3915ae);}})[_0x03d3('0x1e')](function(_0x2165de){if(_0x2165de){return _0x2165de?{'count':_0x2507c4,'rows':_0x2165de}:null;}})[_0x03d3('0x1e')](respondWithResult(_0x4874dd,null))[_0x03d3('0x27')](handleError(_0x4874dd,null));};exports[_0x03d3('0xac')]=function(_0x2f87f0,_0x1b5c62,_0x387c65){var _0x54b108={'raw':![],'where':{}};var _0x438271={};var _0x22fd8e={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x03d3('0x68')]({'where':{'id':_0x2f87f0[_0x03d3('0x58')]['id']}})['then'](handleEntityNotFound(_0x1b5c62,null))[_0x03d3('0x1e')](function(_0x3bcec2){if(_0x3bcec2){_0x438271[_0x03d3('0x42')]=_['keys'](db[_0x03d3('0x8d')]['rawAttributes']);_0x438271['query']=_[_0x03d3('0x43')](_0x2f87f0['query']);_0x438271['filters']=_[_0x03d3('0x46')](_0x438271['model'],_0x438271['query']);_0x54b108[_0x03d3('0x48')]=_[_0x03d3('0x46')](_0x438271['model'],qs['fields'](_0x2f87f0[_0x03d3('0x44')][_0x03d3('0x47')]));_0x54b108[_0x03d3('0x48')]=_0x54b108[_0x03d3('0x48')]['length']?_0x54b108['attributes']:_0x438271[_0x03d3('0x42')];if(!_0x2f87f0[_0x03d3('0x44')]['hasOwnProperty'](_0x03d3('0x4b'))){_0x54b108[_0x03d3('0x2e')]=qs[_0x03d3('0x2e')](_0x2f87f0[_0x03d3('0x44')][_0x03d3('0x2e')]);_0x54b108[_0x03d3('0x2c')]=qs[_0x03d3('0x2c')](_0x2f87f0['query'][_0x03d3('0x2c')]);}_0x54b108[_0x03d3('0x4c')]=qs['sort'](_0x2f87f0['query'][_0x03d3('0x4d')]);_0x54b108[_0x03d3('0x50')]=qs[_0x03d3('0x45')](_[_0x03d3('0x4e')](_0x2f87f0[_0x03d3('0x44')],_0x438271[_0x03d3('0x45')]));_0x54b108[_0x03d3('0x50')][_0x03d3('0x65')]=_0x3bcec2['id'];if(_0x2f87f0[_0x03d3('0x44')][_0x03d3('0x4f')]){_0x54b108[_0x03d3('0x50')]=_[_0x03d3('0x51')](_0x54b108[_0x03d3('0x50')],{'$or':_[_0x03d3('0x3d')](_0x54b108[_0x03d3('0x48')],function(_0x5317d7){var _0x273c06={};_0x273c06[_0x5317d7]={'$like':'%'+_0x2f87f0[_0x03d3('0x44')]['filter']+'%'};return _0x273c06;})});}_0x54b108=_[_0x03d3('0x51')]({},_0x54b108,_0x2f87f0[_0x03d3('0x59')]);return db[_0x03d3('0x8d')][_0x03d3('0x2f')]({'where':_0x54b108['where']})['then'](function(_0x3d859a){_0x22fd8e[_0x03d3('0x2f')]=_0x3d859a;if(_0x2f87f0['query'][_0x03d3('0x53')]){_0x54b108[_0x03d3('0x54')]=[{'model':db[_0x03d3('0x6f')],'as':_0x03d3('0xad'),'required':![]},{'model':db[_0x03d3('0xae')],'as':_0x03d3('0xaf'),'attributes':[_0x03d3('0x39'),'fullname',_0x03d3('0xb0')],'required':![]},{'model':db[_0x03d3('0xb1')],'as':_0x03d3('0xb2'),'attributes':['id','name',_0x03d3('0xb3')],'where':_0x2f87f0[_0x03d3('0x44')][_0x03d3('0xb4')]?{'id':_0x2f87f0[_0x03d3('0x44')][_0x03d3('0xb4')]}:undefined,'required':_0x2f87f0['query'][_0x03d3('0xb4')]?!![]:![]}];}return db[_0x03d3('0x8d')][_0x03d3('0x55')](_0x54b108);})['then'](function(_0x3e9102){_0x22fd8e[_0x03d3('0x56')]=_0x3e9102;return _0x22fd8e;});}})[_0x03d3('0x1e')](respondWithFilteredResult(_0x1b5c62,_0x54b108))[_0x03d3('0x27')](handleError(_0x1b5c62,null));};exports[_0x03d3('0xb5')]=function(_0x25212b,_0x4b6d12,_0xadc192){return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x25212b[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x4b6d12,null))[_0x03d3('0x1e')](function(_0x58168a){if(_0x58168a){return _0x58168a[_0x03d3('0xb5')](_0x25212b[_0x03d3('0x5b')]['ids'],_[_0x03d3('0xb6')](_0x25212b[_0x03d3('0x5b')],[_0x03d3('0x6a'),'id'])||{})['spread'](function(_0x3b10eb){for(var _0x230a3d=0x0;_0x230a3d<_0x25212b[_0x03d3('0x5b')][_0x03d3('0x6a')][_0x03d3('0x49')];_0x230a3d+=0x1){socket['emit'](_0x03d3('0xb7'),{'UserId':Number(_0x25212b[_0x03d3('0x5b')][_0x03d3('0x6a')][_0x230a3d]),'OpenchannelAccountId':Number(_0x25212b[_0x03d3('0x58')]['id'])});}return _0x3b10eb;});}})[_0x03d3('0x1e')](respondWithResult(_0x4b6d12,null))[_0x03d3('0x27')](handleError(_0x4b6d12,null));};exports[_0x03d3('0xb8')]=function(_0x372617,_0x5e7f0b,_0x447e3a){return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x372617[_0x03d3('0x58')]['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x5e7f0b,null))[_0x03d3('0x1e')](function(_0x374e2d){if(_0x374e2d){return _0x374e2d['removeAgents'](_0x372617[_0x03d3('0x44')][_0x03d3('0x6a')])['then'](function(){if(_['isArray'](_0x372617[_0x03d3('0x44')][_0x03d3('0x6a')])){for(var _0x28efc9=0x0;_0x28efc9<_0x372617[_0x03d3('0x44')][_0x03d3('0x6a')]['length'];_0x28efc9+=0x1){socket[_0x03d3('0xb9')](_0x03d3('0xba'),{'UserId':Number(_0x372617['query'][_0x03d3('0x6a')][_0x28efc9]),'OpenchannelAccountId':Number(_0x372617['params']['id'])});}}else{socket[_0x03d3('0xb9')]('userOpenchannelAccount:remove',{'UserId':Number(_0x372617['query'][_0x03d3('0x6a')]),'OpenchannelAccountId':Number(_0x372617[_0x03d3('0x58')]['id'])});}});}})[_0x03d3('0x1e')](respondWithStatusCode(_0x5e7f0b,null))['catch'](handleError(_0x5e7f0b,null));};exports[_0x03d3('0xbb')]=function(_0x4e4c61,_0x582465,_0x3b8783){var _0x17eacf={};var _0x1c81f2={};var _0x553d04;var _0x507078;return db[_0x03d3('0x3e')][_0x03d3('0x68')]({'where':{'id':_0x4e4c61['params']['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x582465,null))[_0x03d3('0x1e')](function(_0x597aa9){if(_0x597aa9){_0x553d04=_0x597aa9;_0x1c81f2[_0x03d3('0x42')]=_[_0x03d3('0x43')](db[_0x03d3('0xae')][_0x03d3('0x3f')]);_0x1c81f2[_0x03d3('0x44')]=_[_0x03d3('0x43')](_0x4e4c61[_0x03d3('0x44')]);_0x1c81f2[_0x03d3('0x45')]=_[_0x03d3('0x46')](_0x1c81f2[_0x03d3('0x42')],_0x1c81f2[_0x03d3('0x44')]);_0x17eacf[_0x03d3('0x48')]=_[_0x03d3('0x46')](_0x1c81f2[_0x03d3('0x42')],qs[_0x03d3('0x47')](_0x4e4c61[_0x03d3('0x44')]['fields']));_0x17eacf[_0x03d3('0x48')]=_0x17eacf[_0x03d3('0x48')]['length']?_0x17eacf[_0x03d3('0x48')]:_0x1c81f2[_0x03d3('0x42')];_0x17eacf[_0x03d3('0x4c')]=qs[_0x03d3('0x4d')](_0x4e4c61[_0x03d3('0x44')][_0x03d3('0x4d')]);_0x17eacf[_0x03d3('0x50')]=qs[_0x03d3('0x45')](_[_0x03d3('0x4e')](_0x4e4c61[_0x03d3('0x44')],_0x1c81f2[_0x03d3('0x45')]));if(_0x4e4c61[_0x03d3('0x44')][_0x03d3('0x4f')]){_0x17eacf[_0x03d3('0x50')]=_['merge'](_0x17eacf[_0x03d3('0x50')],{'$or':_[_0x03d3('0x3d')](_0x17eacf['attributes'],function(_0xae2710){var _0x4e4fab={};_0x4e4fab[_0xae2710]={'$like':'%'+_0x4e4c61[_0x03d3('0x44')]['filter']+'%'};return _0x4e4fab;})});}_0x17eacf=_['merge']({},_0x17eacf,_0x4e4c61[_0x03d3('0x59')]);return _0x553d04[_0x03d3('0xbb')](_0x17eacf);}})[_0x03d3('0x1e')](function(_0x272409){if(_0x272409){_0x507078=_0x272409[_0x03d3('0x49')];if(!_0x4e4c61['query'][_0x03d3('0x4a')](_0x03d3('0x4b'))){_0x17eacf[_0x03d3('0x2e')]=qs[_0x03d3('0x2e')](_0x4e4c61[_0x03d3('0x44')][_0x03d3('0x2e')]);_0x17eacf[_0x03d3('0x2c')]=qs['offset'](_0x4e4c61['query'][_0x03d3('0x2c')]);}return _0x553d04[_0x03d3('0xbb')](_0x17eacf);}})[_0x03d3('0x1e')](function(_0x52cd9c){if(_0x52cd9c){return _0x52cd9c?{'count':_0x507078,'rows':_0x52cd9c}:null;}})['then'](respondWithResult(_0x582465,null))[_0x03d3('0x27')](handleError(_0x582465,null));};exports[_0x03d3('0x3a')]=function(_0x159035,_0x4de582,_0x58dcc2){var _0x487cd7,_0x460181,_0x21dd96;if(_['isNil'](_0x159035['body'][_0x03d3('0x5b')])||_0x159035[_0x03d3('0x5b')][_0x03d3('0x5b')]===''){throw new db['Sequelize']['ValidationError'](_0x03d3('0x7a'));}if(_[_0x03d3('0x76')](_0x159035[_0x03d3('0x5b')]['to'])){}_0x487cd7=_0x159035['body']['to'];return db['OpenchannelAccount'][_0x03d3('0x68')]({'where':{'id':_0x159035['params']['id']}})[_0x03d3('0x1e')](handleEntityNotFound(_0x4de582,null))[_0x03d3('0x1e')](function(_0x243bb5){if(_0x243bb5){return db[_0x03d3('0x3e')][_0x03d3('0x5f')]({'where':{'id':_0x243bb5['id']},'include':[{'model':db[_0x03d3('0x7e')],'as':_0x03d3('0x7f'),'include':[{'model':db[_0x03d3('0x6f')],'as':_0x03d3('0x80'),'where':{[_0x243bb5[_0x03d3('0x7d')]]:_0x487cd7},'limit':0x1,'order':[[_0x03d3('0xbc'),_0x03d3('0x81')]]}]}]})[_0x03d3('0x1e')](handleEntityNotFound(_0x4de582,null))[_0x03d3('0x1e')](function(_0x5b14eb){if(_0x5b14eb&&_0x5b14eb[_0x03d3('0x7f')]){_0x460181=_0x5b14eb[_0x03d3('0x34')]({'plain':!![]});if(_0x460181[_0x03d3('0x7f')]&&_0x460181[_0x03d3('0x7f')][_0x03d3('0x80')][_0x03d3('0x49')]){return _0x460181['List']['Contacts'][0x0];}return db['CmContact'][_0x03d3('0x5a')](_['defaults'](_0x159035['body'],{'firstName':_0x487cd7,[_0x5b14eb[_0x03d3('0x7d')]]:_0x487cd7,'phone':_0x487cd7,'ListId':_0x460181[_0x03d3('0x75')]}));}})[_0x03d3('0x1e')](handleEntityNotFound(_0x4de582,null))[_0x03d3('0x1e')](function(_0x830520){if(_0x830520){_0x21dd96=_0x830520;return db[_0x03d3('0x8d')][_0x03d3('0x5f')]({'where':{'ContactId':_0x21dd96['id'],'closed':![],'OpenchannelAccountId':_0x460181['id']}})[_0x03d3('0x1e')](function(_0x4767bd){if(_0x4767bd){return[_0x4767bd,![]];}return db[_0x03d3('0x8d')][_0x03d3('0x5a')]({'UserId':_0x159035[_0x03d3('0x5c')]['id'],'ContactId':_0x21dd96['id'],'OpenchannelAccountId':_0x460181['id'],'lastMsgDirection':_0x03d3('0xbd'),'firstMsgDirection':_0x03d3('0xbd'),'Messages':[_[_0x03d3('0x51')](_0x159035[_0x03d3('0x5b')],{'read':![],'body':_0x159035['body'][_0x03d3('0x5b')],'OpenchannelAccountId':_0x460181['id'],'UserId':_0x159035[_0x03d3('0x5c')]['id'],'ContactId':_0x21dd96['id']})]},{'include':[{'model':db[_0x03d3('0x98')],'as':_0x03d3('0xbe')}]})[_0x03d3('0x1e')](function(_0x542a3a){return[_0x542a3a,!![]];});});}})[_0x03d3('0x8e')](function(_0x25b967,_0x51187e){if(_0x51187e){return _0x25b967;}return db[_0x03d3('0x98')][_0x03d3('0x5a')](_[_0x03d3('0x51')](_0x159035[_0x03d3('0x5b')],{'read':![],'body':_0x159035[_0x03d3('0x5b')][_0x03d3('0x5b')],'OpenchannelAccountId':_0x460181['id'],'OpenchannelInteractionId':_0x25b967['id'],'UserId':_0x159035['user']['id'],'ContactId':_0x21dd96['id']}))['then'](function(_0x156367){_0x25b967[_0x03d3('0xbf')][_0x03d3('0xbe')]=[];_0x25b967[_0x03d3('0xbf')][_0x03d3('0xbe')][_0x03d3('0x94')](_0x156367[_0x03d3('0xbf')]);return _0x25b967;});});}})[_0x03d3('0x1e')](respondWithResult(_0x4de582,null))[_0x03d3('0x27')](handleError(_0x4de582,null));};
\ No newline at end of file