Built motion from commit 775e2a94.|2.6.3
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 48d5b92..9ea8843 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xda17=['key','model','map','name','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','include','OpenchannelAccount','rows','params','Pause','mandatoryDispositionPause','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','OpenchannelAccountId','Disposition','getDispositions','findOne','order','findAll','ids','addAnswer','CannedAnswer','removeAnswers','CmContact','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','ValidationError','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','account','list','applications','orderBy','priority','asc','contact','firstName','threadId','externalUrl','OpenchannelInteraction','ContactId','spread','messageId','interaction','created','autoclose','push','unmanaged','*,*,*,*','AttachmentId','UserId','User','unshift','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','notify','sequelize','transaction','findAndCountAll','getApplications','getInteractions','Contact','Owner','fullname','internal','Tags','color','tag','omit','emit','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','send','out','Messages','OpenchannelMessage','dataValues','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','jayson/promise','client','http','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','message','result','catch','sendStatus','status','limit','count','offset','set','json','apply','reject','save','then','destroy','get','OpenchannelAccounts','stack','index','rawAttributes','fieldName','type'];(function(_0x134615,_0x24db9e){var _0x594751=function(_0x10a42a){while(--_0x10a42a){_0x134615['push'](_0x134615['shift']());}};_0x594751(++_0x24db9e);}(_0xda17,0x1ef));var _0x7da1=function(_0xb0f7c3,_0x4eae95){_0xb0f7c3=_0xb0f7c3-0x0;var _0x28ea68=_0xda17[_0xb0f7c3];return _0x28ea68;};'use strict';var emlformat=require(_0x7da1('0x0'));var rimraf=require(_0x7da1('0x1'));var zipdir=require(_0x7da1('0x2'));var jsonpatch=require(_0x7da1('0x3'));var rp=require(_0x7da1('0x4'));var moment=require(_0x7da1('0x5'));var BPromise=require(_0x7da1('0x6'));var Mustache=require('mustache');var util=require(_0x7da1('0x7'));var path=require(_0x7da1('0x8'));var sox=require(_0x7da1('0x9'));var csv=require(_0x7da1('0xa'));var ejs=require(_0x7da1('0xb'));var fs=require('fs');var fs_extra=require(_0x7da1('0xc'));var _=require('lodash');var squel=require(_0x7da1('0xd'));var crypto=require(_0x7da1('0xe'));var jsforce=require(_0x7da1('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x7da1('0xa'));var querystring=require(_0x7da1('0x10'));var Papa=require('papaparse');var Redis=require(_0x7da1('0x11'));var authService=require(_0x7da1('0x12'));var qs=require(_0x7da1('0x13'));var as=require(_0x7da1('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7da1('0x15'))('api');var utils=require(_0x7da1('0x16'));var config=require(_0x7da1('0x17'));var licenseUtil=require(_0x7da1('0x18'));var db=require(_0x7da1('0x19'))['db'];config[_0x7da1('0x1a')]=_[_0x7da1('0x1b')](config[_0x7da1('0x1a')],{'host':_0x7da1('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x7da1('0x1a')]));require('./openchannelAccount.socket')['register'](socket);var jayson=require(_0x7da1('0x1d'));var client=jayson[_0x7da1('0x1e')][_0x7da1('0x1f')]({'port':0x232c});var client9002=jayson['client'][_0x7da1('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x2244ff,_0x3ca52a,_0xfc21c5,_0x325de2){return new BPromise(function(_0x355ce6,_0x1572e3){var _0x4885ee=_0x325de2||client;return _0x4885ee['request'](_0x2244ff,_0xfc21c5)['then'](function(_0x2c0ba3){logger[_0x7da1('0x20')](_0x7da1('0x21'),_0x3ca52a,_0x7da1('0x22'));logger[_0x7da1('0x23')]('OpenchannelAccount,\x20%s,\x20%s,\x20%s',_0x3ca52a,_0x7da1('0x22'),JSON[_0x7da1('0x24')](_0x2c0ba3));if(_0x2c0ba3[_0x7da1('0x25')]){if(_0x2c0ba3[_0x7da1('0x25')]['code']===0x1f4){logger[_0x7da1('0x25')](_0x7da1('0x21'),_0x3ca52a,_0x2c0ba3['error'][_0x7da1('0x26')]);return _0x1572e3(_0x2c0ba3[_0x7da1('0x25')]['message']);}logger[_0x7da1('0x25')](_0x7da1('0x21'),_0x3ca52a,_0x2c0ba3[_0x7da1('0x25')][_0x7da1('0x26')]);return _0x355ce6(_0x2c0ba3[_0x7da1('0x25')][_0x7da1('0x26')]);}else{logger['info'](_0x7da1('0x21'),_0x3ca52a,'request\x20sent');_0x355ce6(_0x2c0ba3[_0x7da1('0x27')][_0x7da1('0x26')]);}})[_0x7da1('0x28')](function(_0xa6fc93){logger[_0x7da1('0x25')](_0x7da1('0x21'),_0x3ca52a,_0xa6fc93);_0x1572e3(_0xa6fc93);});});}function respondWithStatusCode(_0x58bca4,_0x40d70c){_0x40d70c=_0x40d70c||0xcc;return function(_0x12e28f){if(_0x12e28f){return _0x58bca4[_0x7da1('0x29')](_0x40d70c);}return _0x58bca4[_0x7da1('0x2a')](_0x40d70c)['end']();};}function respondWithResult(_0x1dcd41,_0x950f9a){_0x950f9a=_0x950f9a||0xc8;return function(_0x2e44bf){if(_0x2e44bf){return _0x1dcd41[_0x7da1('0x2a')](_0x950f9a)['json'](_0x2e44bf);}};}function respondWithFilteredResult(_0x29f53d,_0x28ec22){return function(_0x3b8729){if(_0x3b8729){var _0x2ec826=typeof _0x28ec22['offset']==='undefined'&&typeof _0x28ec22[_0x7da1('0x2b')]==='undefined';var _0x33a13b=_0x3b8729[_0x7da1('0x2c')];var _0xbe373a=_0x2ec826?0x0:_0x28ec22[_0x7da1('0x2d')];var _0x481d07=_0x2ec826?_0x3b8729[_0x7da1('0x2c')]:_0x28ec22['offset']+_0x28ec22['limit'];var _0xe3ab09;if(_0x481d07>=_0x33a13b){_0x481d07=_0x33a13b;_0xe3ab09=0xc8;}else{_0xe3ab09=0xce;}_0x29f53d[_0x7da1('0x2a')](_0xe3ab09);return _0x29f53d[_0x7da1('0x2e')]('Content-Range',_0xbe373a+'-'+_0x481d07+'/'+_0x33a13b)[_0x7da1('0x2f')](_0x3b8729);}return null;};}function patchUpdates(_0x257dbc){return function(_0x44088f){try{jsonpatch[_0x7da1('0x30')](_0x44088f,_0x257dbc,!![]);}catch(_0x148d94){return BPromise[_0x7da1('0x31')](_0x148d94);}return _0x44088f[_0x7da1('0x32')]();};}function saveUpdates(_0x11cafa,_0x10c062){return function(_0x1e6b74){if(_0x1e6b74){return _0x1e6b74['update'](_0x11cafa)[_0x7da1('0x33')](function(_0x2ccfbb){return _0x2ccfbb;});}return null;};}function removeEntity(_0x4f595a,_0x400bd1){return function(_0x51f93f){if(_0x51f93f){return _0x51f93f[_0x7da1('0x34')]()[_0x7da1('0x33')](function(){var _0x5a7acb=_0x51f93f[_0x7da1('0x35')]({'plain':!![]});var _0x2807b3=_0x7da1('0x36');return db['UserProfileResource'][_0x7da1('0x34')]({'where':{'type':_0x2807b3,'resourceId':_0x5a7acb['id']}})[_0x7da1('0x33')](function(){return _0x51f93f;});})[_0x7da1('0x33')](function(){_0x4f595a[_0x7da1('0x2a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x42f09f,_0x50a1a6){return function(_0x5435c1){if(!_0x5435c1){_0x42f09f[_0x7da1('0x29')](0x194);}return _0x5435c1;};}function handleError(_0x38b589,_0x42f379){_0x42f379=_0x42f379||0x1f4;return function(_0x50e378){logger[_0x7da1('0x25')](_0x50e378[_0x7da1('0x37')]);if(_0x50e378['name']){delete _0x50e378['name'];}_0x38b589[_0x7da1('0x2a')](_0x42f379)['send'](_0x50e378);};}exports[_0x7da1('0x38')]=function(_0x5250f5,_0x75742b){var _0x3907ce={'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0xa26dd9={},_0x10af2e={'count':0x0,'rows':[]};var _0x31db83=_['map'](db['OpenchannelAccount'][_0x7da1('0x39')],function(_0x5751ce){return{'name':_0x5751ce[_0x7da1('0x3a')],'type':_0x5751ce[_0x7da1('0x3b')][_0x7da1('0x3c')]};});_0xa26dd9[_0x7da1('0x3d')]=_[_0x7da1('0x3e')](_0x31db83,_0x7da1('0x3f'));_0xa26dd9['query']=_[_0x7da1('0x40')](_0x5250f5[_0x7da1('0x41')]);_0xa26dd9[_0x7da1('0x42')]=_[_0x7da1('0x43')](_0xa26dd9['model'],_0xa26dd9['query']);_0x3907ce[_0x7da1('0x44')]=_['intersection'](_0xa26dd9['model'],qs[_0x7da1('0x45')](_0x5250f5[_0x7da1('0x41')][_0x7da1('0x45')]));_0x3907ce[_0x7da1('0x44')]=_0x3907ce['attributes'][_0x7da1('0x46')]?_0x3907ce[_0x7da1('0x44')]:_0xa26dd9[_0x7da1('0x3d')];if(!_0x5250f5[_0x7da1('0x41')][_0x7da1('0x47')](_0x7da1('0x48'))){_0x3907ce[_0x7da1('0x2b')]=qs['limit'](_0x5250f5[_0x7da1('0x41')][_0x7da1('0x2b')]);_0x3907ce['offset']=qs[_0x7da1('0x2d')](_0x5250f5[_0x7da1('0x41')][_0x7da1('0x2d')]);}_0x3907ce['order']=qs[_0x7da1('0x49')](_0x5250f5[_0x7da1('0x41')][_0x7da1('0x49')]);_0x3907ce[_0x7da1('0x4a')]=qs[_0x7da1('0x42')](_[_0x7da1('0x4b')](_0x5250f5[_0x7da1('0x41')],_0xa26dd9[_0x7da1('0x42')]),_0x31db83);if(_0x5250f5[_0x7da1('0x41')][_0x7da1('0x4c')]){_0x3907ce['where']=_[_0x7da1('0x4d')](_0x3907ce[_0x7da1('0x4a')],{'$or':_[_0x7da1('0x3e')](_0x31db83,function(_0x543ad7){if(_0x543ad7[_0x7da1('0x3b')]!==_0x7da1('0x4e')){var _0x20ee29={};_0x20ee29[_0x543ad7['name']]={'$like':'%'+_0x5250f5[_0x7da1('0x41')][_0x7da1('0x4c')]+'%'};return _0x20ee29;}})});}_0x3907ce=_['merge']({},_0x3907ce,_0x5250f5[_0x7da1('0x4f')]);var _0x802574={'where':_0x3907ce[_0x7da1('0x4a')]};return db['OpenchannelAccount']['count'](_0x802574)[_0x7da1('0x33')](function(_0x3aafc3){_0x10af2e[_0x7da1('0x2c')]=_0x3aafc3;if(_0x5250f5[_0x7da1('0x41')]['includeAll']){_0x3907ce[_0x7da1('0x50')]=[{'all':!![]}];}return db[_0x7da1('0x51')]['findAll'](_0x3907ce);})['then'](function(_0x52fc02){_0x10af2e[_0x7da1('0x52')]=_0x52fc02;return _0x10af2e;})['then'](respondWithFilteredResult(_0x75742b,_0x3907ce))[_0x7da1('0x28')](handleError(_0x75742b,null));};exports['show']=function(_0x1ccdcf,_0x3ebc29){var _0x59ac01={'raw':![],'where':{'id':_0x1ccdcf[_0x7da1('0x53')]['id']},'include':[{'model':db[_0x7da1('0x54')],'as':_0x7da1('0x55')}]},_0xe10331={};_0xe10331[_0x7da1('0x3d')]=_[_0x7da1('0x40')](db[_0x7da1('0x51')]['rawAttributes']);_0xe10331['query']=_[_0x7da1('0x40')](_0x1ccdcf[_0x7da1('0x41')]);_0xe10331[_0x7da1('0x42')]=_[_0x7da1('0x43')](_0xe10331[_0x7da1('0x3d')],_0xe10331[_0x7da1('0x41')]);_0x59ac01[_0x7da1('0x44')]=_['intersection'](_0xe10331[_0x7da1('0x3d')],qs[_0x7da1('0x45')](_0x1ccdcf[_0x7da1('0x41')][_0x7da1('0x45')]));_0x59ac01[_0x7da1('0x44')]=_0x59ac01[_0x7da1('0x44')][_0x7da1('0x46')]?_0x59ac01[_0x7da1('0x44')]:_0xe10331[_0x7da1('0x3d')];if(_0x1ccdcf[_0x7da1('0x41')][_0x7da1('0x56')]){_0x59ac01['include']=[{'all':!![]}];}_0x59ac01=_['merge']({},_0x59ac01,_0x1ccdcf[_0x7da1('0x4f')]);return db[_0x7da1('0x51')][_0x7da1('0x57')](_0x59ac01)['then'](handleEntityNotFound(_0x3ebc29,null))[_0x7da1('0x33')](respondWithResult(_0x3ebc29,null))[_0x7da1('0x28')](handleError(_0x3ebc29,null));};exports['create']=function(_0x3a8fea,_0x22272b){return db[_0x7da1('0x51')][_0x7da1('0x58')](_0x3a8fea[_0x7da1('0x59')],{})[_0x7da1('0x33')](function(_0x204aae){var _0x48eb44=_0x3a8fea[_0x7da1('0x5a')][_0x7da1('0x35')]({'plain':!![]});if(!_0x48eb44)throw new Error(_0x7da1('0x5b'));if(_0x48eb44[_0x7da1('0x5c')]===_0x7da1('0x5a')){var _0x22a776=_0x204aae[_0x7da1('0x35')]({'plain':!![]});var _0x52330e=_0x7da1('0x36');return db[_0x7da1('0x5d')]['find']({'where':{'name':_0x52330e,'userProfileId':_0x48eb44[_0x7da1('0x5e')]},'raw':!![]})[_0x7da1('0x33')](function(_0x2ffc92){if(_0x2ffc92&&_0x2ffc92['autoAssociation']===0x0){return db[_0x7da1('0x5f')][_0x7da1('0x58')]({'name':_0x22a776[_0x7da1('0x3f')],'resourceId':_0x22a776['id'],'type':_0x2ffc92[_0x7da1('0x3f')],'sectionId':_0x2ffc92['id']},{})[_0x7da1('0x33')](function(){return _0x204aae;});}else{return _0x204aae;}})[_0x7da1('0x28')](function(_0x11c358){logger[_0x7da1('0x25')](_0x7da1('0x60'),_0x11c358);throw _0x11c358;});}return _0x204aae;})['then'](respondWithResult(_0x22272b,0xc9))[_0x7da1('0x28')](handleError(_0x22272b,null));};exports[_0x7da1('0x61')]=function(_0x265afa,_0x8b52a7){if(_0x265afa[_0x7da1('0x59')]['id']){delete _0x265afa[_0x7da1('0x59')]['id'];}return db[_0x7da1('0x51')]['find']({'where':{'id':_0x265afa[_0x7da1('0x53')]['id']},'include':[{'model':db['Pause'],'as':_0x7da1('0x55')}]})[_0x7da1('0x33')](handleEntityNotFound(_0x8b52a7,null))[_0x7da1('0x33')](saveUpdates(_0x265afa[_0x7da1('0x59')],null))[_0x7da1('0x33')](respondWithResult(_0x8b52a7,null))[_0x7da1('0x28')](handleError(_0x8b52a7,null));};exports['destroy']=function(_0x598fb9,_0xd96fc6){return db['OpenchannelAccount'][_0x7da1('0x57')]({'where':{'id':_0x598fb9[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0xd96fc6,null))[_0x7da1('0x33')](removeEntity(_0xd96fc6,null))['catch'](handleError(_0xd96fc6,null));};exports[_0x7da1('0x62')]=function(_0x5b9ad8,_0x17d2e5){return db[_0x7da1('0x51')][_0x7da1('0x62')]()[_0x7da1('0x33')](respondWithResult(_0x17d2e5,null))[_0x7da1('0x28')](handleError(_0x17d2e5,null));};exports['addDisposition']=function(_0x433c45,_0x48e3cd,_0x7f5b07){if(_0x433c45[_0x7da1('0x59')]['id']){delete _0x433c45[_0x7da1('0x59')]['id'];}return db[_0x7da1('0x51')][_0x7da1('0x57')]({'where':{'id':_0x433c45[_0x7da1('0x53')]['id']}})['then'](handleEntityNotFound(_0x48e3cd,null))[_0x7da1('0x33')](function(_0x38c6bf){if(_0x38c6bf){_0x433c45[_0x7da1('0x59')][_0x7da1('0x63')]=_0x38c6bf['id'];return db[_0x7da1('0x64')]['create'](_0x433c45[_0x7da1('0x59')]);}})[_0x7da1('0x33')](respondWithResult(_0x48e3cd,null))['catch'](handleError(_0x48e3cd,null));};exports[_0x7da1('0x65')]=function(_0x220675,_0x307dc7,_0x1e99c8){var _0x36efc7={'raw':![],'where':{}};var _0x4d1e6b={};var _0x3f389b={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x7da1('0x66')]({'where':{'id':_0x220675['params']['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x307dc7,null))[_0x7da1('0x33')](function(_0x1862ea){if(_0x1862ea){_0x4d1e6b[_0x7da1('0x3d')]=_[_0x7da1('0x40')](db[_0x7da1('0x64')][_0x7da1('0x39')]);_0x4d1e6b[_0x7da1('0x41')]=_['keys'](_0x220675[_0x7da1('0x41')]);_0x4d1e6b['filters']=_[_0x7da1('0x43')](_0x4d1e6b[_0x7da1('0x3d')],_0x4d1e6b['query']);_0x36efc7[_0x7da1('0x44')]=_[_0x7da1('0x43')](_0x4d1e6b['model'],qs[_0x7da1('0x45')](_0x220675['query'][_0x7da1('0x45')]));_0x36efc7[_0x7da1('0x44')]=_0x36efc7['attributes'][_0x7da1('0x46')]?_0x36efc7[_0x7da1('0x44')]:_0x4d1e6b[_0x7da1('0x3d')];if(!_0x220675['query'][_0x7da1('0x47')](_0x7da1('0x48'))){_0x36efc7[_0x7da1('0x2b')]=qs[_0x7da1('0x2b')](_0x220675[_0x7da1('0x41')][_0x7da1('0x2b')]);_0x36efc7[_0x7da1('0x2d')]=qs[_0x7da1('0x2d')](_0x220675[_0x7da1('0x41')][_0x7da1('0x2d')]);}_0x36efc7[_0x7da1('0x67')]=qs[_0x7da1('0x49')](_0x220675[_0x7da1('0x41')]['sort']);_0x36efc7[_0x7da1('0x4a')]=qs['filters'](_[_0x7da1('0x4b')](_0x220675[_0x7da1('0x41')],_0x4d1e6b[_0x7da1('0x42')]));_0x36efc7[_0x7da1('0x4a')]['OpenchannelAccountId']=_0x1862ea['id'];if(_0x220675[_0x7da1('0x41')][_0x7da1('0x4c')]){_0x36efc7[_0x7da1('0x4a')]=_['merge'](_0x36efc7[_0x7da1('0x4a')],{'$or':_[_0x7da1('0x3e')](_0x36efc7[_0x7da1('0x44')],function(_0x5e6b8b){var _0xa91b92={};_0xa91b92[_0x5e6b8b]={'$like':'%'+_0x220675[_0x7da1('0x41')]['filter']+'%'};return _0xa91b92;})});}_0x36efc7=_['merge']({},_0x36efc7,_0x220675[_0x7da1('0x4f')]);return db[_0x7da1('0x64')]['count']({'where':_0x36efc7[_0x7da1('0x4a')]})['then'](function(_0x203713){_0x3f389b['count']=_0x203713;if(_0x220675[_0x7da1('0x41')]['includeAll']){_0x36efc7[_0x7da1('0x50')]=[{'all':!![]}];}return db['Disposition'][_0x7da1('0x68')](_0x36efc7);})[_0x7da1('0x33')](function(_0x56ff79){_0x3f389b[_0x7da1('0x52')]=_0x56ff79;return _0x3f389b;});}})[_0x7da1('0x33')](respondWithFilteredResult(_0x307dc7,_0x36efc7))[_0x7da1('0x28')](handleError(_0x307dc7,null));};exports['removeDispositions']=function(_0x3d4b77,_0x53c31f,_0x41f713){return db[_0x7da1('0x51')][_0x7da1('0x57')]({'where':{'id':_0x3d4b77[_0x7da1('0x53')]['id']}})['then'](handleEntityNotFound(_0x53c31f,null))[_0x7da1('0x33')](function(_0x470e96){if(_0x470e96){return _0x470e96['removeDispositions'](_0x3d4b77[_0x7da1('0x41')][_0x7da1('0x69')]);}})[_0x7da1('0x33')](respondWithStatusCode(_0x53c31f,null))[_0x7da1('0x28')](handleError(_0x53c31f,null));};exports[_0x7da1('0x6a')]=function(_0x4239c5,_0x825ead,_0x4b8cc2){if(_0x4239c5['body']['id']){delete _0x4239c5[_0x7da1('0x59')]['id'];}return db[_0x7da1('0x51')][_0x7da1('0x57')]({'where':{'id':_0x4239c5['params']['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x825ead,null))[_0x7da1('0x33')](function(_0xd7f3a7){if(_0xd7f3a7){_0x4239c5[_0x7da1('0x59')][_0x7da1('0x63')]=_0xd7f3a7['id'];return db[_0x7da1('0x6b')][_0x7da1('0x58')](_0x4239c5[_0x7da1('0x59')]);}})[_0x7da1('0x33')](respondWithResult(_0x825ead,null))[_0x7da1('0x28')](handleError(_0x825ead,null));};exports['getAnswers']=function(_0x4b15df,_0x37054,_0x11f2d8){var _0x32d336={'raw':![],'where':{}};var _0x1bd09c={};var _0x570659={'count':0x0,'rows':[]};return db[_0x7da1('0x51')][_0x7da1('0x66')]({'where':{'id':_0x4b15df[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x37054,null))['then'](function(_0x331359){if(_0x331359){_0x1bd09c['model']=_[_0x7da1('0x40')](db[_0x7da1('0x6b')]['rawAttributes']);_0x1bd09c[_0x7da1('0x41')]=_[_0x7da1('0x40')](_0x4b15df[_0x7da1('0x41')]);_0x1bd09c[_0x7da1('0x42')]=_['intersection'](_0x1bd09c['model'],_0x1bd09c[_0x7da1('0x41')]);_0x32d336['attributes']=_[_0x7da1('0x43')](_0x1bd09c['model'],qs[_0x7da1('0x45')](_0x4b15df[_0x7da1('0x41')]['fields']));_0x32d336[_0x7da1('0x44')]=_0x32d336[_0x7da1('0x44')][_0x7da1('0x46')]?_0x32d336[_0x7da1('0x44')]:_0x1bd09c[_0x7da1('0x3d')];if(!_0x4b15df[_0x7da1('0x41')]['hasOwnProperty']('nolimit')){_0x32d336['limit']=qs['limit'](_0x4b15df[_0x7da1('0x41')][_0x7da1('0x2b')]);_0x32d336[_0x7da1('0x2d')]=qs[_0x7da1('0x2d')](_0x4b15df[_0x7da1('0x41')]['offset']);}_0x32d336['order']=qs['sort'](_0x4b15df[_0x7da1('0x41')][_0x7da1('0x49')]);_0x32d336[_0x7da1('0x4a')]=qs[_0x7da1('0x42')](_[_0x7da1('0x4b')](_0x4b15df[_0x7da1('0x41')],_0x1bd09c[_0x7da1('0x42')]));_0x32d336[_0x7da1('0x4a')][_0x7da1('0x63')]=_0x331359['id'];if(_0x4b15df[_0x7da1('0x41')][_0x7da1('0x4c')]){_0x32d336[_0x7da1('0x4a')]=_['merge'](_0x32d336[_0x7da1('0x4a')],{'$or':_[_0x7da1('0x3e')](_0x32d336[_0x7da1('0x44')],function(_0x4789ab){var _0x5a8e16={};_0x5a8e16[_0x4789ab]={'$like':'%'+_0x4b15df[_0x7da1('0x41')]['filter']+'%'};return _0x5a8e16;})});}_0x32d336=_['merge']({},_0x32d336,_0x4b15df[_0x7da1('0x4f')]);return db[_0x7da1('0x6b')]['count']({'where':_0x32d336['where']})[_0x7da1('0x33')](function(_0x417665){_0x570659[_0x7da1('0x2c')]=_0x417665;if(_0x4b15df[_0x7da1('0x41')][_0x7da1('0x56')]){_0x32d336['include']=[{'all':!![]}];}return db[_0x7da1('0x6b')][_0x7da1('0x68')](_0x32d336);})[_0x7da1('0x33')](function(_0x29e892){_0x570659[_0x7da1('0x52')]=_0x29e892;return _0x570659;});}})[_0x7da1('0x33')](respondWithFilteredResult(_0x37054,_0x32d336))[_0x7da1('0x28')](handleError(_0x37054,null));};exports['removeAnswers']=function(_0x5053bd,_0x247077,_0x215966){return db[_0x7da1('0x51')]['find']({'where':{'id':_0x5053bd[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x247077,null))[_0x7da1('0x33')](function(_0x5d8e94){if(_0x5d8e94){return _0x5d8e94[_0x7da1('0x6c')](_0x5053bd['query'][_0x7da1('0x69')]);}})[_0x7da1('0x33')](respondWithStatusCode(_0x247077,null))[_0x7da1('0x28')](handleError(_0x247077,null));};exports['notify']=function(_0x5699bd,_0x3d4c9f,_0x573310){var _0xa4a0ab={'body':_0x5699bd[_0x7da1('0x59')],'channel':'openchannel'};var _0x10f1ec=[];var _0x3ee4ff=[];var _0x5f230f={};var _0xf5d739=![];return db[_0x7da1('0x6d')]['describe']()['then'](function(_0x549cf1){if(!_0x549cf1){throw new db[(_0x7da1('0x6e'))]['ValidationError'](_0x7da1('0x6f'));}_0x10f1ec=_[_0x7da1('0x70')](_['keys'](_0x549cf1),[_0x7da1('0x71'),_0x7da1('0x72')]);_0x3ee4ff=_[_0x7da1('0x70')](_['keys'](_0x549cf1),[_0x7da1('0x71'),_0x7da1('0x72'),_0x7da1('0x73'),_0x7da1('0x74')]);if(_0x5699bd['body']['id']){delete _0x5699bd[_0x7da1('0x59')]['id'];}if(_[_0x7da1('0x75')](_0x5699bd[_0x7da1('0x59')][_0x7da1('0x76')])){throw new db['Sequelize']['ValidationError'](_0x7da1('0x77'));}if(_[_0x7da1('0x75')](_0x5699bd[_0x7da1('0x59')][_0x7da1('0x59')])||_0x5699bd[_0x7da1('0x59')]['body']===''){throw new db['Sequelize'][(_0x7da1('0x78'))](_0x7da1('0x79'));}if(_[_0x7da1('0x75')](_0x5699bd[_0x7da1('0x59')][_0x7da1('0x7a')])){throw new db[(_0x7da1('0x6e'))][(_0x7da1('0x78'))](_0x7da1('0x7b')+_0x3ee4ff);}if(!_[_0x7da1('0x7c')](_0x3ee4ff,_0x5699bd[_0x7da1('0x59')][_0x7da1('0x7a')])){throw new db[(_0x7da1('0x6e'))][(_0x7da1('0x78'))](_0x7da1('0x7d')+_0x3ee4ff);}_0x5f230f[_0x5699bd[_0x7da1('0x59')][_0x7da1('0x7a')]]=_0x5699bd[_0x7da1('0x59')]['from'];})[_0x7da1('0x33')](function(){return db[_0x7da1('0x51')]['find']({'where':{'id':_0x5699bd[_0x7da1('0x53')]['id']},'include':[{'model':db[_0x7da1('0x7e')],'as':_0x7da1('0x7f'),'include':[{'model':db[_0x7da1('0x6d')],'as':_0x7da1('0x80'),'where':_0x5f230f,'limit':0x1,'order':[[_0x7da1('0x72'),_0x7da1('0x81')]]}]},{'model':db[_0x7da1('0x82')],'as':_0x7da1('0x83')}]});})[_0x7da1('0x33')](handleEntityNotFound(_0x3d4c9f,null))[_0x7da1('0x33')](function(_0x364d98){if(_0x364d98&&_0x364d98['List']){_0xa4a0ab[_0x7da1('0x84')]=_0x364d98;_0xa4a0ab['applications']=_0x364d98[_0x7da1('0x83')];_0xa4a0ab[_0x7da1('0x85')]=_0x364d98[_0x7da1('0x7f')];_0xa4a0ab[_0x7da1('0x86')]=_[_0x7da1('0x87')](_0xa4a0ab['applications'],[_0x7da1('0x88')],[_0x7da1('0x89')]);if(_0xa4a0ab[_0x7da1('0x84')]['Applications']){delete _0xa4a0ab[_0x7da1('0x84')][_0x7da1('0x83')];}if(_0xa4a0ab['account'][_0x7da1('0x7f')]&&_0xa4a0ab[_0x7da1('0x84')][_0x7da1('0x7f')][_0x7da1('0x80')][_0x7da1('0x46')]){return _0xa4a0ab[_0x7da1('0x84')][_0x7da1('0x7f')][_0x7da1('0x80')][0x0];}var _0xaf3a15=_[_0x7da1('0x1b')](_0x5699bd['body'],{'firstName':_0x5699bd['body']['from'],'ListId':_0x364d98[_0x7da1('0x74')]});_0xaf3a15[_0x5699bd[_0x7da1('0x59')][_0x7da1('0x7a')]]=_0x5699bd[_0x7da1('0x59')]['from'];return db[_0x7da1('0x6d')][_0x7da1('0x58')](_0xaf3a15,{'fields':_0x10f1ec,'raw':!![]});}})[_0x7da1('0x33')](handleEntityNotFound(_0x3d4c9f,null))[_0x7da1('0x33')](function(_0x53f5ad){_0xa4a0ab[_0x7da1('0x8a')]=_0x53f5ad;if(_0x53f5ad){var _0x5ad790={'ContactId':_0x53f5ad['id'],'OpenchannelAccountId':_0x5699bd[_0x7da1('0x53')]['id'],'from':(_0x53f5ad[_0x7da1('0x8b')]||'')+'\x20'+(_0x53f5ad['lastName']||'')};var _0x4aa780={'OpenchannelAccountId':_0x5699bd[_0x7da1('0x53')]['id'],'closed':![]};if(_0x5699bd[_0x7da1('0x59')][_0x7da1('0x8c')]){_0x4aa780[_0x7da1('0x8c')]=_0x5699bd[_0x7da1('0x59')][_0x7da1('0x8c')];return db['OpenchannelInteraction']['find']({'where':_0x4aa780})['then'](function(_0x4beef8){if(_0x4beef8){return[_0x4beef8,![]];}_0x5ad790[_0x7da1('0x8c')]=_0x5699bd['body'][_0x7da1('0x8c')];_0x5ad790[_0x7da1('0x8d')]=_0x5699bd[_0x7da1('0x59')][_0x7da1('0x8d')];return db[_0x7da1('0x8e')]['create'](_0x5ad790)['then'](function(_0x3a73d4){return[_0x3a73d4,!![]];});});}else{_0x4aa780[_0x7da1('0x8c')]=null;}_0x4aa780[_0x7da1('0x8f')]=_0x53f5ad['id'];return db[_0x7da1('0x8e')][_0x7da1('0x57')]({'where':_0x4aa780})[_0x7da1('0x33')](function(_0x408bb8){if(_0x408bb8){return[_0x408bb8,![]];}return db[_0x7da1('0x8e')][_0x7da1('0x58')](_0x5ad790)[_0x7da1('0x33')](function(_0x492004){return[_0x492004,!![]];});});}})[_0x7da1('0x90')](function(_0x28f6c0,_0x37bc62){if(_0x28f6c0){_0xf5d739=_0x37bc62;if(!_0x37bc62){var _0x32e88e={'from':(_0xa4a0ab[_0x7da1('0x8a')][_0x7da1('0x8b')]||'')+'\x20'+(_0xa4a0ab[_0x7da1('0x8a')]['lastName']||'')};if(_0x5699bd[_0x7da1('0x59')][_0x7da1('0x8c')]&&_0x5699bd[_0x7da1('0x59')][_0x7da1('0x91')]&&_0x5699bd['body'][_0x7da1('0x8c')]!=_0x5699bd[_0x7da1('0x59')][_0x7da1('0x91')]){_0x32e88e[_0x7da1('0x8c')]=_0x5699bd[_0x7da1('0x59')][_0x7da1('0x91')];}return _0x28f6c0[_0x7da1('0x61')](_0x32e88e);}else{return _0x28f6c0;}}})[_0x7da1('0x33')](function(_0x25d037){_0xa4a0ab[_0x7da1('0x92')]=_0x25d037[_0x7da1('0x35')]({'plain':!![]});_0xa4a0ab[_0x7da1('0x92')][_0x7da1('0x93')]=_0xf5d739;if(_0xa4a0ab[_0x7da1('0x92')][_0x7da1('0x93')]){if(_0xa4a0ab[_0x7da1('0x84')][_0x7da1('0x94')]){_0xa4a0ab[_0x7da1('0x86')][_0x7da1('0x95')]({'id':0x0,'priority':_0xa4a0ab[_0x7da1('0x86')][_0x7da1('0x46')]+0x1,'app':'close','appdata':_0x7da1('0x96'),'interval':_0x7da1('0x97')});}}return db['OpenchannelMessage'][_0x7da1('0x58')]({'body':_0x5699bd['body'][_0x7da1('0x59')],'OpenchannelAccountId':_0x5699bd['params']['id'],'OpenchannelInteractionId':_0x25d037['id'],'direction':'in','ContactId':_0xa4a0ab[_0x7da1('0x8a')]['id'],'AttachmentId':_0x5699bd[_0x7da1('0x59')][_0x7da1('0x98')]});})[_0x7da1('0x33')](function(_0x3b9633){_0xa4a0ab[_0x7da1('0x26')]=_0x3b9633;if(_0xa4a0ab[_0x7da1('0x92')][_0x7da1('0x99')]){return db[_0x7da1('0x9a')][_0x7da1('0x57')]({'attributes':['id','name'],'where':{'id':_0xa4a0ab['interaction'][_0x7da1('0x99')]}})[_0x7da1('0x33')](function(_0x5ca7a0){if(_0x5ca7a0){_0xa4a0ab[_0x7da1('0x86')][_0x7da1('0x9b')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x5ca7a0[_0x7da1('0x3f')]+','+(_0xa4a0ab['account'][_0x7da1('0x9c')]||0xa),'interval':_0x7da1('0x97')});_0xa4a0ab[_0x7da1('0x9d')]=![];}return respondWithRpcPromise(_0x7da1('0x9e'),_0x7da1('0x9f'),_0xa4a0ab);});}return respondWithRpcPromise(_0x7da1('0x9e'),_0x7da1('0x9f'),_0xa4a0ab);})[_0x7da1('0x33')](function(_0x284c6c){respondWithRpcPromise(_0x7da1('0xa0'),_0x7da1('0xa0'),{'event':_0x7da1('0xa1'),'message':_0x284c6c},client9002);return _0x284c6c;})['then'](respondWithResult(_0x3d4c9f,null))[_0x7da1('0x28')](handleError(_0x3d4c9f,null));};exports['addApplications']=function(_0x2a15c7,_0x9f6bbf,_0x386882){return db[_0x7da1('0x51')][_0x7da1('0x66')]({'where':{'id':_0x2a15c7['params']['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x9f6bbf,null))[_0x7da1('0x33')](function(_0x4fb29b){if(_0x4fb29b){return db[_0x7da1('0xa2')][_0x7da1('0xa3')](function(_0x6ee691){return db[_0x7da1('0x82')]['destroy']({'where':{'OpenchannelAccountId':_0x2a15c7[_0x7da1('0x53')]['id']},'transaction':_0x6ee691})[_0x7da1('0x33')](function(_0x11d25c){var _0x55f29c=_[_0x7da1('0x3e')](_0x2a15c7[_0x7da1('0x59')],function(_0x5ead5){_0x5ead5[_0x7da1('0x63')]=_0x2a15c7['params']['id'];return _0x5ead5;});return db[_0x7da1('0x82')]['bulkCreate'](_0x55f29c,{'transaction':_0x6ee691});});})[_0x7da1('0x33')](function(){return db[_0x7da1('0x82')][_0x7da1('0xa4')]({'where':{'OpenchannelAccountId':_0x2a15c7[_0x7da1('0x53')]['id']},'order':_0x7da1('0x88')});});}})[_0x7da1('0x33')](respondWithResult(_0x9f6bbf,null))[_0x7da1('0x28')](handleError(_0x9f6bbf,null));};exports['getApplications']=function(_0x131755,_0x10b107,_0x571541){var _0x72ba83={};var _0x1ca001={};var _0x4360be;var _0xda32c5;return db[_0x7da1('0x51')]['findOne']({'where':{'id':_0x131755[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x10b107,null))[_0x7da1('0x33')](function(_0x5a7928){if(_0x5a7928){_0x4360be=_0x5a7928;_0x1ca001[_0x7da1('0x3d')]=_[_0x7da1('0x40')](db[_0x7da1('0x82')][_0x7da1('0x39')]);_0x1ca001[_0x7da1('0x41')]=_[_0x7da1('0x40')](_0x131755[_0x7da1('0x41')]);_0x1ca001[_0x7da1('0x42')]=_[_0x7da1('0x43')](_0x1ca001[_0x7da1('0x3d')],_0x1ca001[_0x7da1('0x41')]);_0x72ba83[_0x7da1('0x44')]=_[_0x7da1('0x43')](_0x1ca001[_0x7da1('0x3d')],qs[_0x7da1('0x45')](_0x131755['query'][_0x7da1('0x45')]));_0x72ba83[_0x7da1('0x44')]=_0x72ba83[_0x7da1('0x44')]['length']?_0x72ba83[_0x7da1('0x44')]:_0x1ca001['model'];_0x72ba83[_0x7da1('0x67')]=qs[_0x7da1('0x49')](_0x131755[_0x7da1('0x41')]['sort']);_0x72ba83[_0x7da1('0x4a')]=qs['filters'](_[_0x7da1('0x4b')](_0x131755['query'],_0x1ca001[_0x7da1('0x42')]));if(_0x131755[_0x7da1('0x41')]['filter']){_0x72ba83[_0x7da1('0x4a')]=_[_0x7da1('0x4d')](_0x72ba83[_0x7da1('0x4a')],{'$or':_[_0x7da1('0x3e')](_0x72ba83[_0x7da1('0x44')],function(_0x58d518){var _0x433b67={};_0x433b67[_0x58d518]={'$like':'%'+_0x131755[_0x7da1('0x41')]['filter']+'%'};return _0x433b67;})});}_0x72ba83=_[_0x7da1('0x4d')]({},_0x72ba83,_0x131755[_0x7da1('0x4f')]);return _0x4360be[_0x7da1('0xa5')](_0x72ba83);}})[_0x7da1('0x33')](function(_0x12208e){if(_0x12208e){_0xda32c5=_0x12208e[_0x7da1('0x46')];if(!_0x131755[_0x7da1('0x41')]['hasOwnProperty'](_0x7da1('0x48'))){_0x72ba83[_0x7da1('0x2b')]=qs[_0x7da1('0x2b')](_0x131755[_0x7da1('0x41')][_0x7da1('0x2b')]);_0x72ba83[_0x7da1('0x2d')]=qs[_0x7da1('0x2d')](_0x131755[_0x7da1('0x41')][_0x7da1('0x2d')]);}return _0x4360be['getApplications'](_0x72ba83);}})['then'](function(_0x58009c){if(_0x58009c){return _0x58009c?{'count':_0xda32c5,'rows':_0x58009c}:null;}})['then'](respondWithResult(_0x10b107,null))[_0x7da1('0x28')](handleError(_0x10b107,null));};exports[_0x7da1('0xa6')]=function(_0x11c632,_0x17e8d0,_0x575e42){var _0x145a57={'raw':![],'where':{}};var _0xe752e6={};var _0x19510c={'count':0x0,'rows':[]};return db[_0x7da1('0x51')][_0x7da1('0x66')]({'where':{'id':_0x11c632[_0x7da1('0x53')]['id']}})['then'](handleEntityNotFound(_0x17e8d0,null))['then'](function(_0x4edfd7){if(_0x4edfd7){_0xe752e6[_0x7da1('0x3d')]=_['keys'](db[_0x7da1('0x8e')][_0x7da1('0x39')]);_0xe752e6['query']=_[_0x7da1('0x40')](_0x11c632[_0x7da1('0x41')]);_0xe752e6[_0x7da1('0x42')]=_[_0x7da1('0x43')](_0xe752e6['model'],_0xe752e6['query']);_0x145a57[_0x7da1('0x44')]=_[_0x7da1('0x43')](_0xe752e6[_0x7da1('0x3d')],qs['fields'](_0x11c632[_0x7da1('0x41')][_0x7da1('0x45')]));_0x145a57[_0x7da1('0x44')]=_0x145a57[_0x7da1('0x44')][_0x7da1('0x46')]?_0x145a57[_0x7da1('0x44')]:_0xe752e6[_0x7da1('0x3d')];if(!_0x11c632[_0x7da1('0x41')][_0x7da1('0x47')]('nolimit')){_0x145a57[_0x7da1('0x2b')]=qs[_0x7da1('0x2b')](_0x11c632[_0x7da1('0x41')][_0x7da1('0x2b')]);_0x145a57[_0x7da1('0x2d')]=qs['offset'](_0x11c632[_0x7da1('0x41')][_0x7da1('0x2d')]);}_0x145a57[_0x7da1('0x67')]=qs[_0x7da1('0x49')](_0x11c632[_0x7da1('0x41')][_0x7da1('0x49')]);_0x145a57['where']=qs[_0x7da1('0x42')](_[_0x7da1('0x4b')](_0x11c632['query'],_0xe752e6[_0x7da1('0x42')]));_0x145a57[_0x7da1('0x4a')][_0x7da1('0x63')]=_0x4edfd7['id'];if(_0x11c632[_0x7da1('0x41')]['filter']){_0x145a57[_0x7da1('0x4a')]=_[_0x7da1('0x4d')](_0x145a57[_0x7da1('0x4a')],{'$or':_[_0x7da1('0x3e')](_0x145a57[_0x7da1('0x44')],function(_0xb594e2){var _0x50b9eb={};_0x50b9eb[_0xb594e2]={'$like':'%'+_0x11c632['query']['filter']+'%'};return _0x50b9eb;})});}_0x145a57=_['merge']({},_0x145a57,_0x11c632[_0x7da1('0x4f')]);return db[_0x7da1('0x8e')][_0x7da1('0x2c')]({'where':_0x145a57[_0x7da1('0x4a')]})[_0x7da1('0x33')](function(_0x549028){_0x19510c['count']=_0x549028;if(_0x11c632[_0x7da1('0x41')][_0x7da1('0x56')]){_0x145a57['include']=[{'model':db['CmContact'],'as':_0x7da1('0xa7'),'required':![]},{'model':db['User'],'as':_0x7da1('0xa8'),'attributes':[_0x7da1('0x3f'),_0x7da1('0xa9'),_0x7da1('0xaa')],'required':![]},{'model':db['Tag'],'as':_0x7da1('0xab'),'attributes':['id','name',_0x7da1('0xac')],'where':_0x11c632[_0x7da1('0x41')][_0x7da1('0xad')]?{'id':_0x11c632[_0x7da1('0x41')][_0x7da1('0xad')]}:undefined,'required':_0x11c632['query'][_0x7da1('0xad')]?!![]:![]}];}return db[_0x7da1('0x8e')][_0x7da1('0x68')](_0x145a57);})[_0x7da1('0x33')](function(_0x154bf4){_0x19510c['rows']=_0x154bf4;return _0x19510c;});}})[_0x7da1('0x33')](respondWithFilteredResult(_0x17e8d0,_0x145a57))[_0x7da1('0x28')](handleError(_0x17e8d0,null));};exports['addAgents']=function(_0x3eaf18,_0x1a8d78,_0x4fc149){return db[_0x7da1('0x51')][_0x7da1('0x57')]({'where':{'id':_0x3eaf18[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x1a8d78,null))['then'](function(_0x396673){if(_0x396673){return _0x396673['addAgents'](_0x3eaf18[_0x7da1('0x59')][_0x7da1('0x69')],_[_0x7da1('0xae')](_0x3eaf18[_0x7da1('0x59')],[_0x7da1('0x69'),'id'])||{})[_0x7da1('0x90')](function(_0x41da58){for(var _0x2116e2=0x0;_0x2116e2<_0x3eaf18[_0x7da1('0x59')][_0x7da1('0x69')]['length'];_0x2116e2+=0x1){socket[_0x7da1('0xaf')]('userOpenchannelAccount:save',{'UserId':Number(_0x3eaf18['body'][_0x7da1('0x69')][_0x2116e2]),'OpenchannelAccountId':Number(_0x3eaf18[_0x7da1('0x53')]['id'])});}return _0x41da58;});}})[_0x7da1('0x33')](respondWithResult(_0x1a8d78,null))['catch'](handleError(_0x1a8d78,null));};exports[_0x7da1('0xb0')]=function(_0x145a67,_0x421980,_0x50ce86){return db[_0x7da1('0x51')]['find']({'where':{'id':_0x145a67[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x421980,null))[_0x7da1('0x33')](function(_0x3a390a){if(_0x3a390a){return _0x3a390a['removeAgents'](_0x145a67[_0x7da1('0x41')][_0x7da1('0x69')])[_0x7da1('0x33')](function(){if(_[_0x7da1('0xb1')](_0x145a67['query'][_0x7da1('0x69')])){for(var _0x1b71a1=0x0;_0x1b71a1<_0x145a67[_0x7da1('0x41')][_0x7da1('0x69')][_0x7da1('0x46')];_0x1b71a1+=0x1){socket[_0x7da1('0xaf')](_0x7da1('0xb2'),{'UserId':Number(_0x145a67[_0x7da1('0x41')][_0x7da1('0x69')][_0x1b71a1]),'OpenchannelAccountId':Number(_0x145a67[_0x7da1('0x53')]['id'])});}}else{socket[_0x7da1('0xaf')](_0x7da1('0xb2'),{'UserId':Number(_0x145a67[_0x7da1('0x41')][_0x7da1('0x69')]),'OpenchannelAccountId':Number(_0x145a67[_0x7da1('0x53')]['id'])});}});}})[_0x7da1('0x33')](respondWithStatusCode(_0x421980,null))[_0x7da1('0x28')](handleError(_0x421980,null));};exports[_0x7da1('0xb3')]=function(_0x3f845d,_0x3415e8,_0x4d0baf){var _0x3d6143={};var _0x1a2117={};var _0x3fbe51;var _0x1a0f0f;return db[_0x7da1('0x51')][_0x7da1('0x66')]({'where':{'id':_0x3f845d[_0x7da1('0x53')]['id']}})[_0x7da1('0x33')](handleEntityNotFound(_0x3415e8,null))['then'](function(_0x69f3c6){if(_0x69f3c6){_0x3fbe51=_0x69f3c6;_0x1a2117['model']=_['keys'](db[_0x7da1('0x9a')]['rawAttributes']);_0x1a2117['query']=_['keys'](_0x3f845d[_0x7da1('0x41')]);_0x1a2117['filters']=_[_0x7da1('0x43')](_0x1a2117[_0x7da1('0x3d')],_0x1a2117['query']);_0x3d6143[_0x7da1('0x44')]=_['intersection'](_0x1a2117[_0x7da1('0x3d')],qs['fields'](_0x3f845d[_0x7da1('0x41')][_0x7da1('0x45')]));_0x3d6143['attributes']=_0x3d6143[_0x7da1('0x44')][_0x7da1('0x46')]?_0x3d6143[_0x7da1('0x44')]:_0x1a2117[_0x7da1('0x3d')];_0x3d6143[_0x7da1('0x67')]=qs[_0x7da1('0x49')](_0x3f845d[_0x7da1('0x41')]['sort']);_0x3d6143['where']=qs[_0x7da1('0x42')](_[_0x7da1('0x4b')](_0x3f845d['query'],_0x1a2117[_0x7da1('0x42')]));if(_0x3f845d['query'][_0x7da1('0x4c')]){_0x3d6143[_0x7da1('0x4a')]=_[_0x7da1('0x4d')](_0x3d6143[_0x7da1('0x4a')],{'$or':_[_0x7da1('0x3e')](_0x3d6143[_0x7da1('0x44')],function(_0x31ae05){var _0x19ebd2={};_0x19ebd2[_0x31ae05]={'$like':'%'+_0x3f845d['query'][_0x7da1('0x4c')]+'%'};return _0x19ebd2;})});}_0x3d6143=_[_0x7da1('0x4d')]({},_0x3d6143,_0x3f845d[_0x7da1('0x4f')]);return _0x3fbe51['getAgents'](_0x3d6143);}})[_0x7da1('0x33')](function(_0x16b025){if(_0x16b025){_0x1a0f0f=_0x16b025[_0x7da1('0x46')];if(!_0x3f845d[_0x7da1('0x41')][_0x7da1('0x47')](_0x7da1('0x48'))){_0x3d6143[_0x7da1('0x2b')]=qs[_0x7da1('0x2b')](_0x3f845d[_0x7da1('0x41')]['limit']);_0x3d6143['offset']=qs[_0x7da1('0x2d')](_0x3f845d[_0x7da1('0x41')][_0x7da1('0x2d')]);}return _0x3fbe51['getAgents'](_0x3d6143);}})[_0x7da1('0x33')](function(_0x253c7c){if(_0x253c7c){return _0x253c7c?{'count':_0x1a0f0f,'rows':_0x253c7c}:null;}})['then'](respondWithResult(_0x3415e8,null))[_0x7da1('0x28')](handleError(_0x3415e8,null));};exports[_0x7da1('0xb4')]=function(_0x361e66,_0x518f54,_0x25e951){var _0x15800b,_0x26642e,_0x5a9d26;if(_[_0x7da1('0x75')](_0x361e66[_0x7da1('0x59')][_0x7da1('0x59')])||_0x361e66[_0x7da1('0x59')][_0x7da1('0x59')]===''){throw new db[(_0x7da1('0x6e'))][(_0x7da1('0x78'))](_0x7da1('0x79'));}if(_['isNil'](_0x361e66[_0x7da1('0x59')]['to'])){}_0x15800b=_0x361e66['body']['to'];return db[_0x7da1('0x51')][_0x7da1('0x66')]({'where':{'id':_0x361e66[_0x7da1('0x53')]['id']}})['then'](handleEntityNotFound(_0x518f54,null))[_0x7da1('0x33')](function(_0x443108){if(_0x443108){return db[_0x7da1('0x51')][_0x7da1('0x57')]({'where':{'id':_0x443108['id']},'include':[{'model':db[_0x7da1('0x7e')],'as':_0x7da1('0x7f'),'include':[{'model':db[_0x7da1('0x6d')],'as':_0x7da1('0x80'),'where':{[_0x443108['mapKey']]:_0x15800b},'limit':0x1,'order':[[_0x7da1('0x72'),_0x7da1('0x81')]]}]}]})[_0x7da1('0x33')](handleEntityNotFound(_0x518f54,null))[_0x7da1('0x33')](function(_0x4ab748){if(_0x4ab748&&_0x4ab748[_0x7da1('0x7f')]){_0x26642e=_0x4ab748[_0x7da1('0x35')]({'plain':!![]});if(_0x26642e[_0x7da1('0x7f')]&&_0x26642e[_0x7da1('0x7f')][_0x7da1('0x80')][_0x7da1('0x46')]){return _0x26642e[_0x7da1('0x7f')]['Contacts'][0x0];}return db[_0x7da1('0x6d')][_0x7da1('0x58')](_[_0x7da1('0x1b')](_0x361e66[_0x7da1('0x59')],{'firstName':_0x15800b,[_0x4ab748[_0x7da1('0x7a')]]:_0x15800b,'phone':_0x15800b,'ListId':_0x26642e['ListId']}));}})[_0x7da1('0x33')](handleEntityNotFound(_0x518f54,null))[_0x7da1('0x33')](function(_0x59e4df){if(_0x59e4df){_0x5a9d26=_0x59e4df;return db[_0x7da1('0x8e')][_0x7da1('0x57')]({'where':{'ContactId':_0x5a9d26['id'],'closed':![],'OpenchannelAccountId':_0x26642e['id']}})[_0x7da1('0x33')](function(_0x1b77b2){if(_0x1b77b2){return[_0x1b77b2,![]];}return db[_0x7da1('0x8e')][_0x7da1('0x58')]({'UserId':_0x361e66['user']['id'],'ContactId':_0x5a9d26['id'],'OpenchannelAccountId':_0x26642e['id'],'lastMsgDirection':_0x7da1('0xb5'),'Messages':[_[_0x7da1('0x4d')](_0x361e66[_0x7da1('0x59')],{'read':![],'body':_0x361e66[_0x7da1('0x59')][_0x7da1('0x59')],'OpenchannelAccountId':_0x26642e['id'],'UserId':_0x361e66[_0x7da1('0x5a')]['id'],'ContactId':_0x5a9d26['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x7da1('0xb6')}]})[_0x7da1('0x33')](function(_0x189777){return[_0x189777,!![]];});});}})[_0x7da1('0x90')](function(_0x2bca1a,_0x7c0997){if(_0x7c0997){return _0x2bca1a;}return db[_0x7da1('0xb7')]['create'](_[_0x7da1('0x4d')](_0x361e66[_0x7da1('0x59')],{'read':![],'body':_0x361e66[_0x7da1('0x59')]['body'],'OpenchannelAccountId':_0x26642e['id'],'OpenchannelInteractionId':_0x2bca1a['id'],'UserId':_0x361e66[_0x7da1('0x5a')]['id'],'ContactId':_0x5a9d26['id']}))[_0x7da1('0x33')](function(_0x496b1a){_0x2bca1a[_0x7da1('0xb8')]['Messages']=[];_0x2bca1a[_0x7da1('0xb8')]['Messages'][_0x7da1('0x95')](_0x496b1a[_0x7da1('0xb8')]);return _0x2bca1a;});});}})[_0x7da1('0x33')](respondWithResult(_0x518f54,null))['catch'](handleError(_0x518f54,null));};
\ No newline at end of file
+var _0x0588=['bulkCreate','stack','finally','getApplications','getInteractions','Contact','Owner','internal','Tags','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','out','Messages','dataValues','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','http','client','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','reject','save','update','destroy','OpenchannelAccounts','UserProfileResource','name','send','index','Pause','mandatoryDispositionPause','OpenchannelAccount','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','sort','where','filters','pick','filter','VIRTUAL','merge','options','findAll','rows','show','params','includeAll','include','find','create','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','OpenchannelAccountId','getDispositions','findOne','nolimit','order','Disposition','removeDispositions','addAnswer','getAnswers','CannedAnswer','map','removeAnswers','ids','notify','Sequelize','difference','createdAt','updatedAt','CompanyId','ListId','isNil','ValidationError','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','from','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','account','applications','priority','asc','CmContact','contact','firstName','threadId','OpenchannelInteraction','externalUrl','spread','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','User','UserId','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','Transaction','READ_COMMITTED'];(function(_0x173441,_0x26b0d9){var _0x2423a8=function(_0x4d96c2){while(--_0x4d96c2){_0x173441['push'](_0x173441['shift']());}};_0x2423a8(++_0x26b0d9);}(_0x0588,0xd8));var _0x8058=function(_0x18ec2a,_0x3b39b2){_0x18ec2a=_0x18ec2a-0x0;var _0x26c833=_0x0588[_0x18ec2a];return _0x26c833;};'use strict';var emlformat=require(_0x8058('0x0'));var rimraf=require(_0x8058('0x1'));var zipdir=require(_0x8058('0x2'));var jsonpatch=require(_0x8058('0x3'));var rp=require(_0x8058('0x4'));var moment=require(_0x8058('0x5'));var BPromise=require(_0x8058('0x6'));var Mustache=require(_0x8058('0x7'));var util=require('util');var path=require('path');var sox=require(_0x8058('0x8'));var csv=require(_0x8058('0x9'));var ejs=require(_0x8058('0xa'));var fs=require('fs');var fs_extra=require(_0x8058('0xb'));var _=require(_0x8058('0xc'));var squel=require('squel');var crypto=require(_0x8058('0xd'));var jsforce=require(_0x8058('0xe'));var deskjs=require(_0x8058('0xf'));var toCsv=require(_0x8058('0x9'));var querystring=require('querystring');var Papa=require(_0x8058('0x10'));var Redis=require(_0x8058('0x11'));var authService=require(_0x8058('0x12'));var qs=require(_0x8058('0x13'));var as=require(_0x8058('0x14'));var hardwareService=require(_0x8058('0x15'));var logger=require('../../config/logger')(_0x8058('0x16'));var utils=require('../../config/utils');var config=require(_0x8058('0x17'));var licenseUtil=require(_0x8058('0x18'));var db=require(_0x8058('0x19'))['db'];config[_0x8058('0x1a')]=_[_0x8058('0x1b')](config[_0x8058('0x1a')],{'host':_0x8058('0x1c'),'port':0x18eb});var socket=require(_0x8058('0x1d'))(new Redis(config['redis']));require(_0x8058('0x1e'))[_0x8058('0x1f')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0x8058('0x20')]({'port':0x232c});var client9002=jayson[_0x8058('0x21')][_0x8058('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x2b092a,_0xbe17fc,_0x406290,_0x14b804){return new BPromise(function(_0x31e66f,_0x2a8a36){var _0x2020aa=_0x14b804||client;return _0x2020aa[_0x8058('0x22')](_0x2b092a,_0x406290)[_0x8058('0x23')](function(_0x318ae2){logger['info'](_0x8058('0x24'),_0xbe17fc,_0x8058('0x25'));logger['debug'](_0x8058('0x26'),_0xbe17fc,_0x8058('0x25'),JSON[_0x8058('0x27')](_0x318ae2));if(_0x318ae2[_0x8058('0x28')]){if(_0x318ae2[_0x8058('0x28')][_0x8058('0x29')]===0x1f4){logger['error'](_0x8058('0x24'),_0xbe17fc,_0x318ae2['error'][_0x8058('0x2a')]);return _0x2a8a36(_0x318ae2[_0x8058('0x28')][_0x8058('0x2a')]);}logger[_0x8058('0x28')](_0x8058('0x24'),_0xbe17fc,_0x318ae2['error']['message']);return _0x31e66f(_0x318ae2['error'][_0x8058('0x2a')]);}else{logger[_0x8058('0x2b')](_0x8058('0x24'),_0xbe17fc,_0x8058('0x25'));_0x31e66f(_0x318ae2[_0x8058('0x2c')][_0x8058('0x2a')]);}})[_0x8058('0x2d')](function(_0x26e5ea){logger[_0x8058('0x28')](_0x8058('0x24'),_0xbe17fc,_0x26e5ea);_0x2a8a36(_0x26e5ea);});});}function respondWithStatusCode(_0x37894f,_0x23e869){_0x23e869=_0x23e869||0xcc;return function(_0x2b9c5e){if(_0x2b9c5e){return _0x37894f[_0x8058('0x2e')](_0x23e869);}return _0x37894f[_0x8058('0x2f')](_0x23e869)[_0x8058('0x30')]();};}function respondWithResult(_0x426328,_0x289a86){_0x289a86=_0x289a86||0xc8;return function(_0x1f363a){if(_0x1f363a){return _0x426328[_0x8058('0x2f')](_0x289a86)[_0x8058('0x31')](_0x1f363a);}};}function respondWithFilteredResult(_0x2498df,_0x2d166b){return function(_0x148706){if(_0x148706){var _0x11b20c=typeof _0x2d166b[_0x8058('0x32')]===_0x8058('0x33')&&typeof _0x2d166b[_0x8058('0x34')]===_0x8058('0x33');var _0x1067d7=_0x148706[_0x8058('0x35')];var _0x2a1c58=_0x11b20c?0x0:_0x2d166b[_0x8058('0x32')];var _0x13b4b1=_0x11b20c?_0x148706[_0x8058('0x35')]:_0x2d166b[_0x8058('0x32')]+_0x2d166b['limit'];var _0x1f746b;if(_0x13b4b1>=_0x1067d7){_0x13b4b1=_0x1067d7;_0x1f746b=0xc8;}else{_0x1f746b=0xce;}_0x2498df['status'](_0x1f746b);return _0x2498df['set'](_0x8058('0x36'),_0x2a1c58+'-'+_0x13b4b1+'/'+_0x1067d7)[_0x8058('0x31')](_0x148706);}return null;};}function patchUpdates(_0x30be68){return function(_0x5af2e5){try{jsonpatch['apply'](_0x5af2e5,_0x30be68,!![]);}catch(_0x486abc){return BPromise[_0x8058('0x37')](_0x486abc);}return _0x5af2e5[_0x8058('0x38')]();};}function saveUpdates(_0x1c1e29,_0x3567ac){return function(_0x13fa6d){if(_0x13fa6d){return _0x13fa6d[_0x8058('0x39')](_0x1c1e29)[_0x8058('0x23')](function(_0x5d645b){return _0x5d645b;});}return null;};}function removeEntity(_0x319543,_0x45d82b){return function(_0x4247bd){if(_0x4247bd){return _0x4247bd[_0x8058('0x3a')]()['then'](function(){var _0x353e18=_0x4247bd['get']({'plain':!![]});var _0x3e8fb6=_0x8058('0x3b');return db[_0x8058('0x3c')][_0x8058('0x3a')]({'where':{'type':_0x3e8fb6,'resourceId':_0x353e18['id']}})[_0x8058('0x23')](function(){return _0x4247bd;});})[_0x8058('0x23')](function(){_0x319543[_0x8058('0x2f')](0xcc)[_0x8058('0x30')]();});}};}function handleEntityNotFound(_0x28b35f,_0x44187c){return function(_0x3744d4){if(!_0x3744d4){_0x28b35f['sendStatus'](0x194);}return _0x3744d4;};}function handleError(_0x4accd0,_0x185bfd){_0x185bfd=_0x185bfd||0x1f4;return function(_0x5ca5dd){logger['error'](_0x5ca5dd['stack']);if(_0x5ca5dd[_0x8058('0x3d')]){delete _0x5ca5dd[_0x8058('0x3d')];}_0x4accd0[_0x8058('0x2f')](_0x185bfd)[_0x8058('0x3e')](_0x5ca5dd);};}exports[_0x8058('0x3f')]=function(_0x4e8ead,_0x40df8e){var _0x3d140d={'include':[{'model':db[_0x8058('0x40')],'as':_0x8058('0x41')}]},_0x2a65b0={},_0x5a38eb={'count':0x0,'rows':[]};var _0x4f79dc=_['map'](db[_0x8058('0x42')][_0x8058('0x43')],function(_0x176ae1){return{'name':_0x176ae1[_0x8058('0x44')],'type':_0x176ae1[_0x8058('0x45')][_0x8058('0x46')]};});_0x2a65b0[_0x8058('0x47')]=_['map'](_0x4f79dc,_0x8058('0x3d'));_0x2a65b0[_0x8058('0x48')]=_[_0x8058('0x49')](_0x4e8ead[_0x8058('0x48')]);_0x2a65b0['filters']=_[_0x8058('0x4a')](_0x2a65b0[_0x8058('0x47')],_0x2a65b0[_0x8058('0x48')]);_0x3d140d[_0x8058('0x4b')]=_[_0x8058('0x4a')](_0x2a65b0[_0x8058('0x47')],qs[_0x8058('0x4c')](_0x4e8ead[_0x8058('0x48')][_0x8058('0x4c')]));_0x3d140d['attributes']=_0x3d140d[_0x8058('0x4b')][_0x8058('0x4d')]?_0x3d140d[_0x8058('0x4b')]:_0x2a65b0[_0x8058('0x47')];if(!_0x4e8ead[_0x8058('0x48')][_0x8058('0x4e')]('nolimit')){_0x3d140d[_0x8058('0x34')]=qs[_0x8058('0x34')](_0x4e8ead[_0x8058('0x48')][_0x8058('0x34')]);_0x3d140d[_0x8058('0x32')]=qs[_0x8058('0x32')](_0x4e8ead[_0x8058('0x48')][_0x8058('0x32')]);}_0x3d140d['order']=qs['sort'](_0x4e8ead[_0x8058('0x48')][_0x8058('0x4f')]);_0x3d140d[_0x8058('0x50')]=qs[_0x8058('0x51')](_[_0x8058('0x52')](_0x4e8ead[_0x8058('0x48')],_0x2a65b0[_0x8058('0x51')]),_0x4f79dc);if(_0x4e8ead['query'][_0x8058('0x53')]){_0x3d140d[_0x8058('0x50')]=_['merge'](_0x3d140d[_0x8058('0x50')],{'$or':_['map'](_0x4f79dc,function(_0x1c0692){if(_0x1c0692['type']!==_0x8058('0x54')){var _0x55b62c={};_0x55b62c[_0x1c0692[_0x8058('0x3d')]]={'$like':'%'+_0x4e8ead['query'][_0x8058('0x53')]+'%'};return _0x55b62c;}})});}_0x3d140d=_[_0x8058('0x55')]({},_0x3d140d,_0x4e8ead[_0x8058('0x56')]);var _0x5b34fe={'where':_0x3d140d[_0x8058('0x50')]};return db[_0x8058('0x42')][_0x8058('0x35')](_0x5b34fe)['then'](function(_0x3a05be){_0x5a38eb[_0x8058('0x35')]=_0x3a05be;if(_0x4e8ead[_0x8058('0x48')]['includeAll']){_0x3d140d['include']=[{'all':!![]}];}return db['OpenchannelAccount'][_0x8058('0x57')](_0x3d140d);})[_0x8058('0x23')](function(_0x222e2e){_0x5a38eb[_0x8058('0x58')]=_0x222e2e;return _0x5a38eb;})[_0x8058('0x23')](respondWithFilteredResult(_0x40df8e,_0x3d140d))[_0x8058('0x2d')](handleError(_0x40df8e,null));};exports[_0x8058('0x59')]=function(_0x12260b,_0x35a8a3){var _0x5ee768={'raw':![],'where':{'id':_0x12260b[_0x8058('0x5a')]['id']},'include':[{'model':db[_0x8058('0x40')],'as':_0x8058('0x41')}]},_0x3dc57d={};_0x3dc57d[_0x8058('0x47')]=_['keys'](db[_0x8058('0x42')][_0x8058('0x43')]);_0x3dc57d[_0x8058('0x48')]=_[_0x8058('0x49')](_0x12260b[_0x8058('0x48')]);_0x3dc57d['filters']=_['intersection'](_0x3dc57d[_0x8058('0x47')],_0x3dc57d['query']);_0x5ee768[_0x8058('0x4b')]=_[_0x8058('0x4a')](_0x3dc57d['model'],qs['fields'](_0x12260b[_0x8058('0x48')]['fields']));_0x5ee768[_0x8058('0x4b')]=_0x5ee768[_0x8058('0x4b')][_0x8058('0x4d')]?_0x5ee768[_0x8058('0x4b')]:_0x3dc57d[_0x8058('0x47')];if(_0x12260b[_0x8058('0x48')][_0x8058('0x5b')]){_0x5ee768[_0x8058('0x5c')]=[{'all':!![]}];}_0x5ee768=_['merge']({},_0x5ee768,_0x12260b[_0x8058('0x56')]);return db[_0x8058('0x42')][_0x8058('0x5d')](_0x5ee768)[_0x8058('0x23')](handleEntityNotFound(_0x35a8a3,null))[_0x8058('0x23')](respondWithResult(_0x35a8a3,null))[_0x8058('0x2d')](handleError(_0x35a8a3,null));};exports[_0x8058('0x5e')]=function(_0x4640f5,_0x4ef68c){return db[_0x8058('0x42')][_0x8058('0x5e')](_0x4640f5['body'],{})['then'](function(_0x3e6244){var _0x52dd84=_0x4640f5['user'][_0x8058('0x5f')]({'plain':!![]});if(!_0x52dd84)throw new Error(_0x8058('0x60'));if(_0x52dd84['role']===_0x8058('0x61')){var _0x36f7f3=_0x3e6244[_0x8058('0x5f')]({'plain':!![]});var _0x1b7740=_0x8058('0x3b');return db[_0x8058('0x62')]['find']({'where':{'name':_0x1b7740,'userProfileId':_0x52dd84[_0x8058('0x63')]},'raw':!![]})[_0x8058('0x23')](function(_0x54f5ed){if(_0x54f5ed&&_0x54f5ed[_0x8058('0x64')]===0x0){return db[_0x8058('0x3c')][_0x8058('0x5e')]({'name':_0x36f7f3[_0x8058('0x3d')],'resourceId':_0x36f7f3['id'],'type':_0x54f5ed[_0x8058('0x3d')],'sectionId':_0x54f5ed['id']},{})[_0x8058('0x23')](function(){return _0x3e6244;});}else{return _0x3e6244;}})['catch'](function(_0x32a365){logger[_0x8058('0x28')](_0x8058('0x65'),_0x32a365);throw _0x32a365;});}return _0x3e6244;})[_0x8058('0x23')](respondWithResult(_0x4ef68c,0xc9))[_0x8058('0x2d')](handleError(_0x4ef68c,null));};exports[_0x8058('0x39')]=function(_0x15cd46,_0x4713ce){if(_0x15cd46[_0x8058('0x66')]['id']){delete _0x15cd46[_0x8058('0x66')]['id'];}return db['OpenchannelAccount'][_0x8058('0x5d')]({'where':{'id':_0x15cd46[_0x8058('0x5a')]['id']},'include':[{'model':db[_0x8058('0x40')],'as':'mandatoryDispositionPause'}]})[_0x8058('0x23')](handleEntityNotFound(_0x4713ce,null))['then'](saveUpdates(_0x15cd46[_0x8058('0x66')],null))[_0x8058('0x23')](respondWithResult(_0x4713ce,null))[_0x8058('0x2d')](handleError(_0x4713ce,null));};exports[_0x8058('0x3a')]=function(_0x183501,_0x3518cb){return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0x183501['params']['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x3518cb,null))[_0x8058('0x23')](removeEntity(_0x3518cb,null))[_0x8058('0x2d')](handleError(_0x3518cb,null));};exports[_0x8058('0x67')]=function(_0x2391c1,_0x187d76){return db['OpenchannelAccount']['describe']()['then'](respondWithResult(_0x187d76,null))[_0x8058('0x2d')](handleError(_0x187d76,null));};exports[_0x8058('0x68')]=function(_0x55e7b7,_0xd7f04f,_0x2381dc){if(_0x55e7b7[_0x8058('0x66')]['id']){delete _0x55e7b7['body']['id'];}return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0x55e7b7[_0x8058('0x5a')]['id']}})[_0x8058('0x23')](handleEntityNotFound(_0xd7f04f,null))[_0x8058('0x23')](function(_0x4fb663){if(_0x4fb663){_0x55e7b7[_0x8058('0x66')][_0x8058('0x69')]=_0x4fb663['id'];return db['Disposition']['create'](_0x55e7b7[_0x8058('0x66')]);}})[_0x8058('0x23')](respondWithResult(_0xd7f04f,null))['catch'](handleError(_0xd7f04f,null));};exports[_0x8058('0x6a')]=function(_0x3607a2,_0x407aaa,_0x2b801c){var _0x25f5bb={'raw':![],'where':{}};var _0x344283={};var _0x593f07={'count':0x0,'rows':[]};return db[_0x8058('0x42')][_0x8058('0x6b')]({'where':{'id':_0x3607a2['params']['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x407aaa,null))[_0x8058('0x23')](function(_0x272987){if(_0x272987){_0x344283[_0x8058('0x47')]=_['keys'](db['Disposition'][_0x8058('0x43')]);_0x344283[_0x8058('0x48')]=_[_0x8058('0x49')](_0x3607a2[_0x8058('0x48')]);_0x344283[_0x8058('0x51')]=_[_0x8058('0x4a')](_0x344283[_0x8058('0x47')],_0x344283[_0x8058('0x48')]);_0x25f5bb['attributes']=_['intersection'](_0x344283[_0x8058('0x47')],qs[_0x8058('0x4c')](_0x3607a2[_0x8058('0x48')]['fields']));_0x25f5bb[_0x8058('0x4b')]=_0x25f5bb[_0x8058('0x4b')][_0x8058('0x4d')]?_0x25f5bb[_0x8058('0x4b')]:_0x344283[_0x8058('0x47')];if(!_0x3607a2[_0x8058('0x48')][_0x8058('0x4e')](_0x8058('0x6c'))){_0x25f5bb[_0x8058('0x34')]=qs[_0x8058('0x34')](_0x3607a2[_0x8058('0x48')][_0x8058('0x34')]);_0x25f5bb[_0x8058('0x32')]=qs[_0x8058('0x32')](_0x3607a2[_0x8058('0x48')][_0x8058('0x32')]);}_0x25f5bb[_0x8058('0x6d')]=qs['sort'](_0x3607a2[_0x8058('0x48')]['sort']);_0x25f5bb[_0x8058('0x50')]=qs[_0x8058('0x51')](_['pick'](_0x3607a2[_0x8058('0x48')],_0x344283[_0x8058('0x51')]));_0x25f5bb[_0x8058('0x50')][_0x8058('0x69')]=_0x272987['id'];if(_0x3607a2[_0x8058('0x48')][_0x8058('0x53')]){_0x25f5bb[_0x8058('0x50')]=_[_0x8058('0x55')](_0x25f5bb[_0x8058('0x50')],{'$or':_['map'](_0x25f5bb[_0x8058('0x4b')],function(_0x833a0d){var _0x1010dc={};_0x1010dc[_0x833a0d]={'$like':'%'+_0x3607a2[_0x8058('0x48')]['filter']+'%'};return _0x1010dc;})});}_0x25f5bb=_[_0x8058('0x55')]({},_0x25f5bb,_0x3607a2[_0x8058('0x56')]);return db[_0x8058('0x6e')][_0x8058('0x35')]({'where':_0x25f5bb['where']})[_0x8058('0x23')](function(_0x514aaf){_0x593f07[_0x8058('0x35')]=_0x514aaf;if(_0x3607a2['query']['includeAll']){_0x25f5bb[_0x8058('0x5c')]=[{'all':!![]}];}return db[_0x8058('0x6e')][_0x8058('0x57')](_0x25f5bb);})[_0x8058('0x23')](function(_0x59cbe6){_0x593f07[_0x8058('0x58')]=_0x59cbe6;return _0x593f07;});}})['then'](respondWithFilteredResult(_0x407aaa,_0x25f5bb))['catch'](handleError(_0x407aaa,null));};exports[_0x8058('0x6f')]=function(_0x2b8e9f,_0x1cb650,_0x9d07c9){return db['OpenchannelAccount'][_0x8058('0x5d')]({'where':{'id':_0x2b8e9f['params']['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x1cb650,null))[_0x8058('0x23')](function(_0x374dc4){if(_0x374dc4){return _0x374dc4['removeDispositions'](_0x2b8e9f['query']['ids']);}})[_0x8058('0x23')](respondWithStatusCode(_0x1cb650,null))['catch'](handleError(_0x1cb650,null));};exports[_0x8058('0x70')]=function(_0xa7e83e,_0x781a9,_0x20e23d){if(_0xa7e83e[_0x8058('0x66')]['id']){delete _0xa7e83e[_0x8058('0x66')]['id'];}return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0xa7e83e['params']['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x781a9,null))[_0x8058('0x23')](function(_0x5c090d){if(_0x5c090d){_0xa7e83e[_0x8058('0x66')][_0x8058('0x69')]=_0x5c090d['id'];return db['CannedAnswer'][_0x8058('0x5e')](_0xa7e83e[_0x8058('0x66')]);}})[_0x8058('0x23')](respondWithResult(_0x781a9,null))[_0x8058('0x2d')](handleError(_0x781a9,null));};exports[_0x8058('0x71')]=function(_0x40c589,_0xfba82b,_0x20a4cc){var _0x5339ed={'raw':![],'where':{}};var _0x186486={};var _0x161791={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x8058('0x6b')]({'where':{'id':_0x40c589[_0x8058('0x5a')]['id']}})[_0x8058('0x23')](handleEntityNotFound(_0xfba82b,null))[_0x8058('0x23')](function(_0x373968){if(_0x373968){_0x186486[_0x8058('0x47')]=_[_0x8058('0x49')](db[_0x8058('0x72')][_0x8058('0x43')]);_0x186486['query']=_['keys'](_0x40c589[_0x8058('0x48')]);_0x186486['filters']=_[_0x8058('0x4a')](_0x186486[_0x8058('0x47')],_0x186486['query']);_0x5339ed['attributes']=_[_0x8058('0x4a')](_0x186486[_0x8058('0x47')],qs[_0x8058('0x4c')](_0x40c589[_0x8058('0x48')]['fields']));_0x5339ed[_0x8058('0x4b')]=_0x5339ed[_0x8058('0x4b')][_0x8058('0x4d')]?_0x5339ed[_0x8058('0x4b')]:_0x186486[_0x8058('0x47')];if(!_0x40c589[_0x8058('0x48')][_0x8058('0x4e')](_0x8058('0x6c'))){_0x5339ed[_0x8058('0x34')]=qs[_0x8058('0x34')](_0x40c589[_0x8058('0x48')][_0x8058('0x34')]);_0x5339ed[_0x8058('0x32')]=qs[_0x8058('0x32')](_0x40c589[_0x8058('0x48')][_0x8058('0x32')]);}_0x5339ed[_0x8058('0x6d')]=qs['sort'](_0x40c589[_0x8058('0x48')][_0x8058('0x4f')]);_0x5339ed['where']=qs[_0x8058('0x51')](_[_0x8058('0x52')](_0x40c589[_0x8058('0x48')],_0x186486[_0x8058('0x51')]));_0x5339ed['where']['OpenchannelAccountId']=_0x373968['id'];if(_0x40c589[_0x8058('0x48')][_0x8058('0x53')]){_0x5339ed[_0x8058('0x50')]=_['merge'](_0x5339ed[_0x8058('0x50')],{'$or':_[_0x8058('0x73')](_0x5339ed[_0x8058('0x4b')],function(_0x1a3c12){var _0x154e57={};_0x154e57[_0x1a3c12]={'$like':'%'+_0x40c589['query'][_0x8058('0x53')]+'%'};return _0x154e57;})});}_0x5339ed=_[_0x8058('0x55')]({},_0x5339ed,_0x40c589[_0x8058('0x56')]);return db[_0x8058('0x72')][_0x8058('0x35')]({'where':_0x5339ed['where']})[_0x8058('0x23')](function(_0x4ccf45){_0x161791['count']=_0x4ccf45;if(_0x40c589[_0x8058('0x48')]['includeAll']){_0x5339ed[_0x8058('0x5c')]=[{'all':!![]}];}return db[_0x8058('0x72')][_0x8058('0x57')](_0x5339ed);})[_0x8058('0x23')](function(_0x1d237f){_0x161791['rows']=_0x1d237f;return _0x161791;});}})['then'](respondWithFilteredResult(_0xfba82b,_0x5339ed))[_0x8058('0x2d')](handleError(_0xfba82b,null));};exports[_0x8058('0x74')]=function(_0x4385c1,_0x13941c,_0xd193a3){return db[_0x8058('0x42')]['find']({'where':{'id':_0x4385c1[_0x8058('0x5a')]['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x13941c,null))['then'](function(_0x23bbdf){if(_0x23bbdf){return _0x23bbdf[_0x8058('0x74')](_0x4385c1[_0x8058('0x48')][_0x8058('0x75')]);}})[_0x8058('0x23')](respondWithStatusCode(_0x13941c,null))['catch'](handleError(_0x13941c,null));};exports[_0x8058('0x76')]=function(_0x32a1a2,_0x19b244,_0x17321b){var _0x39f36f={'body':_0x32a1a2['body'],'channel':'openchannel'};var _0x4bf318=[];var _0x577c32=[];var _0x5c8e97={};var _0x33d68c=![];return db['CmContact'][_0x8058('0x67')]()[_0x8058('0x23')](function(_0x8064af){if(!_0x8064af){throw new db[(_0x8058('0x77'))]['ValidationError']('no\x20available\x20attributes');}_0x4bf318=_[_0x8058('0x78')](_['keys'](_0x8064af),[_0x8058('0x79'),_0x8058('0x7a')]);_0x577c32=_[_0x8058('0x78')](_[_0x8058('0x49')](_0x8064af),['createdAt',_0x8058('0x7a'),_0x8058('0x7b'),_0x8058('0x7c')]);if(_0x32a1a2[_0x8058('0x66')]['id']){delete _0x32a1a2['body']['id'];}if(_[_0x8058('0x7d')](_0x32a1a2[_0x8058('0x66')]['from'])){throw new db[(_0x8058('0x77'))][(_0x8058('0x7e'))](_0x8058('0x7f'));}if(_[_0x8058('0x7d')](_0x32a1a2['body']['body'])||_0x32a1a2[_0x8058('0x66')][_0x8058('0x66')]===''){throw new db['Sequelize'][(_0x8058('0x7e'))](_0x8058('0x80'));}if(_['isNil'](_0x32a1a2['body'][_0x8058('0x81')])){throw new db['Sequelize'][(_0x8058('0x7e'))](_0x8058('0x82')+_0x577c32);}if(!_['includes'](_0x577c32,_0x32a1a2[_0x8058('0x66')][_0x8058('0x81')])){throw new db['Sequelize'][(_0x8058('0x7e'))](_0x8058('0x83')+_0x577c32);}_0x5c8e97[_0x32a1a2[_0x8058('0x66')][_0x8058('0x81')]]=_0x32a1a2[_0x8058('0x66')][_0x8058('0x84')];})[_0x8058('0x23')](function(){return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0x32a1a2[_0x8058('0x5a')]['id']},'include':[{'model':db[_0x8058('0x85')],'as':_0x8058('0x86'),'include':[{'model':db['CmContact'],'as':_0x8058('0x87'),'where':_0x5c8e97,'limit':0x1,'order':[[_0x8058('0x7a'),_0x8058('0x88')]]}]},{'model':db[_0x8058('0x89')],'as':_0x8058('0x8a')}]});})[_0x8058('0x23')](handleEntityNotFound(_0x19b244,null))[_0x8058('0x23')](function(_0x183005){if(_0x183005&&_0x183005['List']){_0x39f36f[_0x8058('0x8b')]=_0x183005;_0x39f36f[_0x8058('0x8c')]=_0x183005[_0x8058('0x8a')];_0x39f36f['list']=_0x183005['List'];_0x39f36f[_0x8058('0x8c')]=_['orderBy'](_0x39f36f[_0x8058('0x8c')],[_0x8058('0x8d')],[_0x8058('0x8e')]);if(_0x39f36f['account'][_0x8058('0x8a')]){delete _0x39f36f['account'][_0x8058('0x8a')];}if(_0x39f36f['account'][_0x8058('0x86')]&&_0x39f36f[_0x8058('0x8b')][_0x8058('0x86')][_0x8058('0x87')][_0x8058('0x4d')]){return _0x39f36f[_0x8058('0x8b')][_0x8058('0x86')][_0x8058('0x87')][0x0];}var _0x33afa0=_['defaults'](_0x32a1a2[_0x8058('0x66')],{'firstName':_0x32a1a2[_0x8058('0x66')]['from'],'ListId':_0x183005[_0x8058('0x7c')]});_0x33afa0[_0x32a1a2[_0x8058('0x66')]['mapKey']]=_0x32a1a2[_0x8058('0x66')]['from'];return db[_0x8058('0x8f')][_0x8058('0x5e')](_0x33afa0,{'fields':_0x4bf318,'raw':!![]});}})[_0x8058('0x23')](handleEntityNotFound(_0x19b244,null))[_0x8058('0x23')](function(_0x284d49){_0x39f36f[_0x8058('0x90')]=_0x284d49;if(_0x284d49){var _0x49d63f={'ContactId':_0x284d49['id'],'OpenchannelAccountId':_0x32a1a2['params']['id'],'from':(_0x284d49[_0x8058('0x91')]||'')+'\x20'+(_0x284d49['lastName']||'')};var _0x4b8745={'OpenchannelAccountId':_0x32a1a2[_0x8058('0x5a')]['id'],'closed':![]};if(_0x32a1a2[_0x8058('0x66')][_0x8058('0x92')]){_0x4b8745[_0x8058('0x92')]=_0x32a1a2['body'][_0x8058('0x92')];return db[_0x8058('0x93')][_0x8058('0x5d')]({'where':_0x4b8745})['then'](function(_0x315ddb){if(_0x315ddb){return[_0x315ddb,![]];}_0x49d63f['threadId']=_0x32a1a2['body']['threadId'];_0x49d63f['externalUrl']=_0x32a1a2[_0x8058('0x66')][_0x8058('0x94')];return db['OpenchannelInteraction'][_0x8058('0x5e')](_0x49d63f)[_0x8058('0x23')](function(_0x177489){return[_0x177489,!![]];});});}else{_0x4b8745[_0x8058('0x92')]=null;}_0x4b8745['ContactId']=_0x284d49['id'];return db['OpenchannelInteraction']['find']({'where':_0x4b8745})[_0x8058('0x23')](function(_0x5d6e14){if(_0x5d6e14){return[_0x5d6e14,![]];}return db['OpenchannelInteraction']['create'](_0x49d63f)['then'](function(_0x582162){return[_0x582162,!![]];});});}})[_0x8058('0x95')](function(_0x2da1b6,_0x4b0d27){if(_0x2da1b6){_0x33d68c=_0x4b0d27;if(!_0x4b0d27){var _0x40fd91={'from':(_0x39f36f['contact']['firstName']||'')+'\x20'+(_0x39f36f[_0x8058('0x90')]['lastName']||'')};if(_0x32a1a2[_0x8058('0x66')]['threadId']&&_0x32a1a2[_0x8058('0x66')][_0x8058('0x96')]&&_0x32a1a2[_0x8058('0x66')]['threadId']!=_0x32a1a2[_0x8058('0x66')][_0x8058('0x96')]){_0x40fd91[_0x8058('0x92')]=_0x32a1a2[_0x8058('0x66')][_0x8058('0x96')];}return _0x2da1b6[_0x8058('0x39')](_0x40fd91);}else{return _0x2da1b6;}}})[_0x8058('0x23')](function(_0x5e24ed){_0x39f36f[_0x8058('0x97')]=_0x5e24ed[_0x8058('0x5f')]({'plain':!![]});_0x39f36f[_0x8058('0x97')][_0x8058('0x98')]=_0x33d68c;if(_0x39f36f[_0x8058('0x97')][_0x8058('0x98')]){if(_0x39f36f[_0x8058('0x8b')][_0x8058('0x99')]){_0x39f36f[_0x8058('0x8c')][_0x8058('0x9a')]({'id':0x0,'priority':_0x39f36f[_0x8058('0x8c')][_0x8058('0x4d')]+0x1,'app':_0x8058('0x9b'),'appdata':_0x8058('0x9c'),'interval':_0x8058('0x9d')});}}return db[_0x8058('0x9e')][_0x8058('0x5e')]({'body':_0x32a1a2[_0x8058('0x66')][_0x8058('0x66')],'OpenchannelAccountId':_0x32a1a2[_0x8058('0x5a')]['id'],'OpenchannelInteractionId':_0x5e24ed['id'],'direction':'in','ContactId':_0x39f36f[_0x8058('0x90')]['id'],'AttachmentId':_0x32a1a2[_0x8058('0x66')][_0x8058('0x9f')]});})[_0x8058('0x23')](function(_0x2720e0){_0x39f36f[_0x8058('0x2a')]=_0x2720e0;if(_0x39f36f[_0x8058('0x97')]['UserId']){return db[_0x8058('0xa0')][_0x8058('0x5d')]({'attributes':['id',_0x8058('0x3d')],'where':{'id':_0x39f36f[_0x8058('0x97')][_0x8058('0xa1')]}})['then'](function(_0x12cc96){if(_0x12cc96){_0x39f36f['applications'][_0x8058('0xa2')]({'id':0x0,'priority':0x0,'app':_0x8058('0xa3'),'appdata':_0x12cc96[_0x8058('0x3d')]+','+(_0x39f36f[_0x8058('0x8b')][_0x8058('0xa4')]||0xa),'interval':_0x8058('0x9d')});_0x39f36f[_0x8058('0xa5')]=![];}return respondWithRpcPromise(_0x8058('0xa6'),_0x8058('0xa7'),_0x39f36f);});}return respondWithRpcPromise(_0x8058('0xa6'),_0x8058('0xa7'),_0x39f36f);})[_0x8058('0x23')](function(_0x508c03){respondWithRpcPromise(_0x8058('0xa8'),_0x8058('0xa8'),{'event':_0x8058('0x76'),'message':_0x508c03},client9002);return _0x508c03;})[_0x8058('0x23')](respondWithResult(_0x19b244,null))[_0x8058('0x2d')](handleError(_0x19b244,null));};exports[_0x8058('0xa9')]=function(_0x15958d,_0x253a6a){var _0x456b50=_0x15958d['params']['id'];var _0x329ac8=_0x15958d[_0x8058('0x66')];var _0x42c3fa=0xc8;var _0xb7b257=null;return db[_0x8058('0xaa')][_0x8058('0xab')]({'isolationLevel':db[_0x8058('0xaa')][_0x8058('0xac')]['ISOLATION_LEVELS'][_0x8058('0xad')]},function(_0x5bd8ed){return db['OpenchannelAccount'][_0x8058('0x6b')]({'where':{'id':_0x456b50},'transaction':_0x5bd8ed})[_0x8058('0x23')](function(_0x55ba54){if(_0x55ba54){return db[_0x8058('0x89')][_0x8058('0x3a')]({'where':{'OpenchannelAccountId':_0x456b50},'transaction':_0x5bd8ed})[_0x8058('0x23')](function(){var _0x233fdc=_['map'](_0x329ac8,function(_0x47b8e4){_0x47b8e4[_0x8058('0x69')]=_0x456b50;return _0x47b8e4;});return db[_0x8058('0x89')][_0x8058('0xae')](_0x233fdc,{'transaction':_0x5bd8ed});});}else{_0x42c3fa=0x194;_0xb7b257=[];}});})['then'](function(){if(_0x42c3fa!==0x194){return db[_0x8058('0x89')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0x456b50},'order':'priority'})['then'](function(_0x1777b9){_0xb7b257=_0x1777b9;});}})[_0x8058('0x2d')](function(_0x54b5e0){_0x42c3fa=0x1f4;logger[_0x8058('0x28')](_0x54b5e0[_0x8058('0xaf')]);if(_0x54b5e0[_0x8058('0x3d')]){delete _0x54b5e0[_0x8058('0x3d')];}_0xb7b257=_0x54b5e0;})[_0x8058('0xb0')](function(){if(_0xb7b257===null){_0x253a6a['sendStatus'](_0x42c3fa);}else{if(_0x42c3fa===0x1f4){_0x253a6a[_0x8058('0x2f')](_0x42c3fa)[_0x8058('0x3e')](_0xb7b257);}else{_0x253a6a[_0x8058('0x2f')](_0x42c3fa)[_0x8058('0x31')](_0xb7b257);}}});};exports[_0x8058('0xb1')]=function(_0x11d40b,_0x5507cf,_0x112982){var _0x3b0da4={};var _0x270064={};var _0x25ff8c;var _0x5b066f;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x11d40b[_0x8058('0x5a')]['id']}})['then'](handleEntityNotFound(_0x5507cf,null))['then'](function(_0x146bcd){if(_0x146bcd){_0x25ff8c=_0x146bcd;_0x270064[_0x8058('0x47')]=_[_0x8058('0x49')](db[_0x8058('0x89')][_0x8058('0x43')]);_0x270064['query']=_[_0x8058('0x49')](_0x11d40b[_0x8058('0x48')]);_0x270064['filters']=_[_0x8058('0x4a')](_0x270064[_0x8058('0x47')],_0x270064[_0x8058('0x48')]);_0x3b0da4[_0x8058('0x4b')]=_[_0x8058('0x4a')](_0x270064[_0x8058('0x47')],qs['fields'](_0x11d40b['query']['fields']));_0x3b0da4[_0x8058('0x4b')]=_0x3b0da4['attributes']['length']?_0x3b0da4[_0x8058('0x4b')]:_0x270064[_0x8058('0x47')];_0x3b0da4[_0x8058('0x6d')]=qs[_0x8058('0x4f')](_0x11d40b[_0x8058('0x48')][_0x8058('0x4f')]);_0x3b0da4[_0x8058('0x50')]=qs[_0x8058('0x51')](_[_0x8058('0x52')](_0x11d40b[_0x8058('0x48')],_0x270064[_0x8058('0x51')]));if(_0x11d40b[_0x8058('0x48')]['filter']){_0x3b0da4[_0x8058('0x50')]=_[_0x8058('0x55')](_0x3b0da4[_0x8058('0x50')],{'$or':_[_0x8058('0x73')](_0x3b0da4[_0x8058('0x4b')],function(_0x478d36){var _0x5a3943={};_0x5a3943[_0x478d36]={'$like':'%'+_0x11d40b[_0x8058('0x48')][_0x8058('0x53')]+'%'};return _0x5a3943;})});}_0x3b0da4=_[_0x8058('0x55')]({},_0x3b0da4,_0x11d40b['options']);return _0x25ff8c[_0x8058('0xb1')](_0x3b0da4);}})[_0x8058('0x23')](function(_0x47fe09){if(_0x47fe09){_0x5b066f=_0x47fe09[_0x8058('0x4d')];if(!_0x11d40b[_0x8058('0x48')]['hasOwnProperty'](_0x8058('0x6c'))){_0x3b0da4[_0x8058('0x34')]=qs['limit'](_0x11d40b['query'][_0x8058('0x34')]);_0x3b0da4[_0x8058('0x32')]=qs[_0x8058('0x32')](_0x11d40b['query'][_0x8058('0x32')]);}return _0x25ff8c[_0x8058('0xb1')](_0x3b0da4);}})['then'](function(_0x5f174e){if(_0x5f174e){return _0x5f174e?{'count':_0x5b066f,'rows':_0x5f174e}:null;}})[_0x8058('0x23')](respondWithResult(_0x5507cf,null))[_0x8058('0x2d')](handleError(_0x5507cf,null));};exports[_0x8058('0xb2')]=function(_0x1eb97d,_0x36b3be,_0x4925c8){var _0x5ce169={'raw':![],'where':{}};var _0x37b28b={};var _0x555e01={'count':0x0,'rows':[]};return db[_0x8058('0x42')][_0x8058('0x6b')]({'where':{'id':_0x1eb97d[_0x8058('0x5a')]['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x36b3be,null))['then'](function(_0x2a93bc){if(_0x2a93bc){_0x37b28b[_0x8058('0x47')]=_[_0x8058('0x49')](db[_0x8058('0x93')][_0x8058('0x43')]);_0x37b28b[_0x8058('0x48')]=_[_0x8058('0x49')](_0x1eb97d[_0x8058('0x48')]);_0x37b28b[_0x8058('0x51')]=_[_0x8058('0x4a')](_0x37b28b['model'],_0x37b28b[_0x8058('0x48')]);_0x5ce169[_0x8058('0x4b')]=_[_0x8058('0x4a')](_0x37b28b['model'],qs[_0x8058('0x4c')](_0x1eb97d[_0x8058('0x48')][_0x8058('0x4c')]));_0x5ce169[_0x8058('0x4b')]=_0x5ce169[_0x8058('0x4b')][_0x8058('0x4d')]?_0x5ce169[_0x8058('0x4b')]:_0x37b28b['model'];if(!_0x1eb97d[_0x8058('0x48')]['hasOwnProperty'](_0x8058('0x6c'))){_0x5ce169[_0x8058('0x34')]=qs[_0x8058('0x34')](_0x1eb97d[_0x8058('0x48')][_0x8058('0x34')]);_0x5ce169['offset']=qs['offset'](_0x1eb97d[_0x8058('0x48')][_0x8058('0x32')]);}_0x5ce169[_0x8058('0x6d')]=qs[_0x8058('0x4f')](_0x1eb97d[_0x8058('0x48')]['sort']);_0x5ce169['where']=qs[_0x8058('0x51')](_[_0x8058('0x52')](_0x1eb97d[_0x8058('0x48')],_0x37b28b[_0x8058('0x51')]));_0x5ce169[_0x8058('0x50')][_0x8058('0x69')]=_0x2a93bc['id'];if(_0x1eb97d['query'][_0x8058('0x53')]){_0x5ce169[_0x8058('0x50')]=_[_0x8058('0x55')](_0x5ce169['where'],{'$or':_['map'](_0x5ce169[_0x8058('0x4b')],function(_0x4c2bfa){var _0x41f33d={};_0x41f33d[_0x4c2bfa]={'$like':'%'+_0x1eb97d[_0x8058('0x48')][_0x8058('0x53')]+'%'};return _0x41f33d;})});}_0x5ce169=_[_0x8058('0x55')]({},_0x5ce169,_0x1eb97d[_0x8058('0x56')]);return db['OpenchannelInteraction'][_0x8058('0x35')]({'where':_0x5ce169['where']})[_0x8058('0x23')](function(_0x52e8bb){_0x555e01[_0x8058('0x35')]=_0x52e8bb;if(_0x1eb97d[_0x8058('0x48')][_0x8058('0x5b')]){_0x5ce169[_0x8058('0x5c')]=[{'model':db[_0x8058('0x8f')],'as':_0x8058('0xb3'),'required':![]},{'model':db[_0x8058('0xa0')],'as':_0x8058('0xb4'),'attributes':[_0x8058('0x3d'),'fullname',_0x8058('0xb5')],'required':![]},{'model':db['Tag'],'as':_0x8058('0xb6'),'attributes':['id',_0x8058('0x3d'),'color'],'where':_0x1eb97d[_0x8058('0x48')][_0x8058('0xb7')]?{'id':_0x1eb97d['query'][_0x8058('0xb7')]}:undefined,'required':_0x1eb97d['query'][_0x8058('0xb7')]?!![]:![]}];}return db[_0x8058('0x93')][_0x8058('0x57')](_0x5ce169);})[_0x8058('0x23')](function(_0x4c28ca){_0x555e01[_0x8058('0x58')]=_0x4c28ca;return _0x555e01;});}})[_0x8058('0x23')](respondWithFilteredResult(_0x36b3be,_0x5ce169))['catch'](handleError(_0x36b3be,null));};exports[_0x8058('0xb8')]=function(_0x3060f3,_0x151609,_0x185142){return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0x3060f3[_0x8058('0x5a')]['id']}})['then'](handleEntityNotFound(_0x151609,null))[_0x8058('0x23')](function(_0x296035){if(_0x296035){return _0x296035[_0x8058('0xb8')](_0x3060f3[_0x8058('0x66')]['ids'],_[_0x8058('0xb9')](_0x3060f3[_0x8058('0x66')],['ids','id'])||{})[_0x8058('0x95')](function(_0x22598a){for(var _0x1bb390=0x0;_0x1bb390<_0x3060f3[_0x8058('0x66')][_0x8058('0x75')]['length'];_0x1bb390+=0x1){socket[_0x8058('0xba')](_0x8058('0xbb'),{'UserId':Number(_0x3060f3[_0x8058('0x66')]['ids'][_0x1bb390]),'OpenchannelAccountId':Number(_0x3060f3['params']['id'])});}return _0x22598a;});}})['then'](respondWithResult(_0x151609,null))[_0x8058('0x2d')](handleError(_0x151609,null));};exports[_0x8058('0xbc')]=function(_0x12f279,_0x32512a,_0x2135dd){return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0x12f279[_0x8058('0x5a')]['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x32512a,null))[_0x8058('0x23')](function(_0x511a82){if(_0x511a82){return _0x511a82['removeAgents'](_0x12f279['query'][_0x8058('0x75')])[_0x8058('0x23')](function(){if(_[_0x8058('0xbd')](_0x12f279[_0x8058('0x48')]['ids'])){for(var _0x426e9a=0x0;_0x426e9a<_0x12f279[_0x8058('0x48')][_0x8058('0x75')]['length'];_0x426e9a+=0x1){socket[_0x8058('0xba')](_0x8058('0xbe'),{'UserId':Number(_0x12f279[_0x8058('0x48')][_0x8058('0x75')][_0x426e9a]),'OpenchannelAccountId':Number(_0x12f279[_0x8058('0x5a')]['id'])});}}else{socket[_0x8058('0xba')](_0x8058('0xbe'),{'UserId':Number(_0x12f279[_0x8058('0x48')][_0x8058('0x75')]),'OpenchannelAccountId':Number(_0x12f279[_0x8058('0x5a')]['id'])});}});}})['then'](respondWithStatusCode(_0x32512a,null))[_0x8058('0x2d')](handleError(_0x32512a,null));};exports[_0x8058('0xbf')]=function(_0x3ff9cd,_0x2d222f,_0x430381){var _0x5c40a0={};var _0x2e8dfa={};var _0x443c5c;var _0x832d59;return db[_0x8058('0x42')][_0x8058('0x6b')]({'where':{'id':_0x3ff9cd[_0x8058('0x5a')]['id']}})[_0x8058('0x23')](handleEntityNotFound(_0x2d222f,null))[_0x8058('0x23')](function(_0x883f8f){if(_0x883f8f){_0x443c5c=_0x883f8f;_0x2e8dfa[_0x8058('0x47')]=_[_0x8058('0x49')](db[_0x8058('0xa0')]['rawAttributes']);_0x2e8dfa[_0x8058('0x48')]=_['keys'](_0x3ff9cd[_0x8058('0x48')]);_0x2e8dfa[_0x8058('0x51')]=_['intersection'](_0x2e8dfa[_0x8058('0x47')],_0x2e8dfa[_0x8058('0x48')]);_0x5c40a0['attributes']=_[_0x8058('0x4a')](_0x2e8dfa[_0x8058('0x47')],qs[_0x8058('0x4c')](_0x3ff9cd[_0x8058('0x48')][_0x8058('0x4c')]));_0x5c40a0[_0x8058('0x4b')]=_0x5c40a0[_0x8058('0x4b')]['length']?_0x5c40a0[_0x8058('0x4b')]:_0x2e8dfa[_0x8058('0x47')];_0x5c40a0[_0x8058('0x6d')]=qs['sort'](_0x3ff9cd[_0x8058('0x48')][_0x8058('0x4f')]);_0x5c40a0[_0x8058('0x50')]=qs[_0x8058('0x51')](_[_0x8058('0x52')](_0x3ff9cd[_0x8058('0x48')],_0x2e8dfa['filters']));if(_0x3ff9cd[_0x8058('0x48')]['filter']){_0x5c40a0['where']=_[_0x8058('0x55')](_0x5c40a0[_0x8058('0x50')],{'$or':_[_0x8058('0x73')](_0x5c40a0['attributes'],function(_0x50925a){var _0x407846={};_0x407846[_0x50925a]={'$like':'%'+_0x3ff9cd[_0x8058('0x48')]['filter']+'%'};return _0x407846;})});}_0x5c40a0=_[_0x8058('0x55')]({},_0x5c40a0,_0x3ff9cd[_0x8058('0x56')]);return _0x443c5c[_0x8058('0xbf')](_0x5c40a0);}})[_0x8058('0x23')](function(_0x5992b6){if(_0x5992b6){_0x832d59=_0x5992b6[_0x8058('0x4d')];if(!_0x3ff9cd['query']['hasOwnProperty'](_0x8058('0x6c'))){_0x5c40a0['limit']=qs['limit'](_0x3ff9cd[_0x8058('0x48')]['limit']);_0x5c40a0[_0x8058('0x32')]=qs[_0x8058('0x32')](_0x3ff9cd['query']['offset']);}return _0x443c5c[_0x8058('0xbf')](_0x5c40a0);}})[_0x8058('0x23')](function(_0x5538d9){if(_0x5538d9){return _0x5538d9?{'count':_0x832d59,'rows':_0x5538d9}:null;}})['then'](respondWithResult(_0x2d222f,null))[_0x8058('0x2d')](handleError(_0x2d222f,null));};exports[_0x8058('0x3e')]=function(_0x4d29b2,_0x506666,_0x1c76ed){var _0x15f326,_0x566386,_0x140165;if(_[_0x8058('0x7d')](_0x4d29b2[_0x8058('0x66')][_0x8058('0x66')])||_0x4d29b2[_0x8058('0x66')]['body']===''){throw new db[(_0x8058('0x77'))][(_0x8058('0x7e'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x8058('0x7d')](_0x4d29b2[_0x8058('0x66')]['to'])){}_0x15f326=_0x4d29b2[_0x8058('0x66')]['to'];return db[_0x8058('0x42')]['findOne']({'where':{'id':_0x4d29b2['params']['id']}})['then'](handleEntityNotFound(_0x506666,null))[_0x8058('0x23')](function(_0x59a24b){if(_0x59a24b){return db[_0x8058('0x42')][_0x8058('0x5d')]({'where':{'id':_0x59a24b['id']},'include':[{'model':db['CmList'],'as':_0x8058('0x86'),'include':[{'model':db['CmContact'],'as':_0x8058('0x87'),'where':{[_0x59a24b[_0x8058('0x81')]]:_0x15f326},'limit':0x1,'order':[[_0x8058('0x7a'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x506666,null))[_0x8058('0x23')](function(_0x634715){if(_0x634715&&_0x634715['List']){_0x566386=_0x634715[_0x8058('0x5f')]({'plain':!![]});if(_0x566386[_0x8058('0x86')]&&_0x566386[_0x8058('0x86')]['Contacts'][_0x8058('0x4d')]){return _0x566386[_0x8058('0x86')][_0x8058('0x87')][0x0];}return db['CmContact'][_0x8058('0x5e')](_[_0x8058('0x1b')](_0x4d29b2[_0x8058('0x66')],{'firstName':_0x15f326,[_0x634715[_0x8058('0x81')]]:_0x15f326,'phone':_0x15f326,'ListId':_0x566386[_0x8058('0x7c')]}));}})['then'](handleEntityNotFound(_0x506666,null))['then'](function(_0x555415){if(_0x555415){_0x140165=_0x555415;return db[_0x8058('0x93')][_0x8058('0x5d')]({'where':{'ContactId':_0x140165['id'],'closed':![],'OpenchannelAccountId':_0x566386['id']}})[_0x8058('0x23')](function(_0x2b676e){if(_0x2b676e){return[_0x2b676e,![]];}return db['OpenchannelInteraction']['create']({'UserId':_0x4d29b2['user']['id'],'ContactId':_0x140165['id'],'OpenchannelAccountId':_0x566386['id'],'lastMsgDirection':_0x8058('0xc0'),'firstMsgDirection':'out','Messages':[_['merge'](_0x4d29b2[_0x8058('0x66')],{'read':![],'body':_0x4d29b2['body']['body'],'OpenchannelAccountId':_0x566386['id'],'UserId':_0x4d29b2[_0x8058('0x61')]['id'],'ContactId':_0x140165['id']})]},{'include':[{'model':db[_0x8058('0x9e')],'as':'Messages'}]})[_0x8058('0x23')](function(_0x48ebe4){return[_0x48ebe4,!![]];});});}})[_0x8058('0x95')](function(_0x83988,_0x1794ec){if(_0x1794ec){return _0x83988;}return db[_0x8058('0x9e')][_0x8058('0x5e')](_[_0x8058('0x55')](_0x4d29b2[_0x8058('0x66')],{'read':![],'body':_0x4d29b2[_0x8058('0x66')][_0x8058('0x66')],'OpenchannelAccountId':_0x566386['id'],'OpenchannelInteractionId':_0x83988['id'],'UserId':_0x4d29b2['user']['id'],'ContactId':_0x140165['id']}))[_0x8058('0x23')](function(_0x1bcd78){_0x83988['dataValues'][_0x8058('0xc1')]=[];_0x83988[_0x8058('0xc2')][_0x8058('0xc1')][_0x8058('0x9a')](_0x1bcd78[_0x8058('0xc2')]);return _0x83988;});});}})[_0x8058('0x23')](respondWithResult(_0x506666,null))[_0x8058('0x2d')](handleError(_0x506666,null));};
\ No newline at end of file