Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 19aecf2..001b72c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd3f5=['updatedAt','difference','CompanyId','ListId','from','ValidationError','from\x20is\x20mandatory','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','Contacts','DESC','OpenchannelApplication','List','account','applications','Applications','list','priority','threadId','OpenchannelInteraction','externalUrl','spread','contact','firstName','lastName','messageId','interaction','created','autoclose','push','close','*,*,*,*','User','UserId','waitForTheAssignedAgent','forcedOwnership','startRouting','Start','EventManager','notify','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','findOne','bulkCreate','getApplications','Contact','fullname','internal','Tag','Tags','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','out','OpenchannelMessage','dataValues','Messages','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','jayson/promise','client','http','then','info','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','error','code','OpenchannelAccount,\x20%s,\x20%s','message','end','status','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','destroy','get','UserProfileResource','sendStatus','stack','name','send','index','Pause','map','OpenchannelAccount','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','type','VIRTUAL','filter','merge','options','includeAll','findAll','rows','catch','show','params','mandatoryDispositionPause','keys','length','include','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','OpenchannelAccountId','Disposition','removeDispositions','ids','CannedAnswer','getAnswers','removeAnswers','openchannel','CmContact','Sequelize'];(function(_0xd948d,_0x1db128){var _0x3f6aef=function(_0x386400){while(--_0x386400){_0xd948d['push'](_0xd948d['shift']());}};_0x3f6aef(++_0x1db128);}(_0xd3f5,0x1be));var _0x5d3f=function(_0x6c993a,_0x5ea3ab){_0x6c993a=_0x6c993a-0x0;var _0x27f547=_0xd3f5[_0x6c993a];return _0x27f547;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x5d3f('0x0'));var moment=require(_0x5d3f('0x1'));var BPromise=require(_0x5d3f('0x2'));var Mustache=require(_0x5d3f('0x3'));var util=require(_0x5d3f('0x4'));var path=require('path');var sox=require(_0x5d3f('0x5'));var csv=require(_0x5d3f('0x6'));var ejs=require(_0x5d3f('0x7'));var fs=require('fs');var fs_extra=require(_0x5d3f('0x8'));var _=require('lodash');var squel=require(_0x5d3f('0x9'));var crypto=require('crypto');var jsforce=require(_0x5d3f('0xa'));var deskjs=require(_0x5d3f('0xb'));var toCsv=require(_0x5d3f('0x6'));var querystring=require(_0x5d3f('0xc'));var Papa=require(_0x5d3f('0xd'));var Redis=require(_0x5d3f('0xe'));var authService=require(_0x5d3f('0xf'));var qs=require(_0x5d3f('0x10'));var as=require(_0x5d3f('0x11'));var hardwareService=require(_0x5d3f('0x12'));var logger=require(_0x5d3f('0x13'))(_0x5d3f('0x14'));var utils=require(_0x5d3f('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x5d3f('0x16'));var db=require(_0x5d3f('0x17'))['db'];config[_0x5d3f('0x18')]=_[_0x5d3f('0x19')](config[_0x5d3f('0x18')],{'host':_0x5d3f('0x1a'),'port':0x18eb});var socket=require(_0x5d3f('0x1b'))(new Redis(config['redis']));require(_0x5d3f('0x1c'))['register'](socket);var jayson=require(_0x5d3f('0x1d'));var client=jayson[_0x5d3f('0x1e')][_0x5d3f('0x1f')]({'port':0x232c});var client9002=jayson[_0x5d3f('0x1e')][_0x5d3f('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x2c29eb,_0x1d2874,_0x3dd449,_0x4d59a4){return new BPromise(function(_0x8b537e,_0x10471d){var _0x4331fc=_0x4d59a4||client;return _0x4331fc['request'](_0x2c29eb,_0x3dd449)[_0x5d3f('0x20')](function(_0x76d098){logger[_0x5d3f('0x21')]('OpenchannelAccount,\x20%s,\x20%s',_0x1d2874,_0x5d3f('0x22'));logger[_0x5d3f('0x23')](_0x5d3f('0x24'),_0x1d2874,'request\x20sent',JSON['stringify'](_0x76d098));if(_0x76d098['error']){if(_0x76d098[_0x5d3f('0x25')][_0x5d3f('0x26')]===0x1f4){logger['error'](_0x5d3f('0x27'),_0x1d2874,_0x76d098[_0x5d3f('0x25')][_0x5d3f('0x28')]);return _0x10471d(_0x76d098[_0x5d3f('0x25')]['message']);}logger[_0x5d3f('0x25')](_0x5d3f('0x27'),_0x1d2874,_0x76d098[_0x5d3f('0x25')][_0x5d3f('0x28')]);return _0x8b537e(_0x76d098[_0x5d3f('0x25')]['message']);}else{logger[_0x5d3f('0x21')](_0x5d3f('0x27'),_0x1d2874,_0x5d3f('0x22'));_0x8b537e(_0x76d098['result'][_0x5d3f('0x28')]);}})['catch'](function(_0x70a5d4){logger[_0x5d3f('0x25')]('OpenchannelAccount,\x20%s,\x20%s',_0x1d2874,_0x70a5d4);_0x10471d(_0x70a5d4);});});}function respondWithStatusCode(_0x1f81ab,_0x35fe5e){_0x35fe5e=_0x35fe5e||0xcc;return function(_0x217c64){if(_0x217c64){return _0x1f81ab['sendStatus'](_0x35fe5e);}return _0x1f81ab['status'](_0x35fe5e)[_0x5d3f('0x29')]();};}function respondWithResult(_0x15d3d4,_0x3f425a){_0x3f425a=_0x3f425a||0xc8;return function(_0x48d8ea){if(_0x48d8ea){return _0x15d3d4[_0x5d3f('0x2a')](_0x3f425a)[_0x5d3f('0x2b')](_0x48d8ea);}};}function respondWithFilteredResult(_0x548a5f,_0x4832a6){return function(_0x169bc4){if(_0x169bc4){var _0x4d9818=typeof _0x4832a6[_0x5d3f('0x2c')]==='undefined'&&typeof _0x4832a6['limit']===_0x5d3f('0x2d');var _0xc8927b=_0x169bc4[_0x5d3f('0x2e')];var _0x30f596=_0x4d9818?0x0:_0x4832a6[_0x5d3f('0x2c')];var _0x3aded0=_0x4d9818?_0x169bc4['count']:_0x4832a6[_0x5d3f('0x2c')]+_0x4832a6[_0x5d3f('0x2f')];var _0x4efb05;if(_0x3aded0>=_0xc8927b){_0x3aded0=_0xc8927b;_0x4efb05=0xc8;}else{_0x4efb05=0xce;}_0x548a5f[_0x5d3f('0x2a')](_0x4efb05);return _0x548a5f['set'](_0x5d3f('0x30'),_0x30f596+'-'+_0x3aded0+'/'+_0xc8927b)['json'](_0x169bc4);}return null;};}function patchUpdates(_0x5b1c26){return function(_0x545c69){try{jsonpatch[_0x5d3f('0x31')](_0x545c69,_0x5b1c26,!![]);}catch(_0x5721c4){return BPromise[_0x5d3f('0x32')](_0x5721c4);}return _0x545c69[_0x5d3f('0x33')]();};}function saveUpdates(_0x11fb8c,_0x1990f7){return function(_0x46934f){if(_0x46934f){return _0x46934f[_0x5d3f('0x34')](_0x11fb8c)[_0x5d3f('0x20')](function(_0x1ffde3){return _0x1ffde3;});}return null;};}function removeEntity(_0x49d61b,_0x51f4e6){return function(_0xcd46f4){if(_0xcd46f4){return _0xcd46f4[_0x5d3f('0x35')]()['then'](function(){var _0x483653=_0xcd46f4[_0x5d3f('0x36')]({'plain':!![]});var _0x1da007='OpenchannelAccounts';return db[_0x5d3f('0x37')]['destroy']({'where':{'type':_0x1da007,'resourceId':_0x483653['id']}})[_0x5d3f('0x20')](function(){return _0xcd46f4;});})[_0x5d3f('0x20')](function(){_0x49d61b[_0x5d3f('0x2a')](0xcc)[_0x5d3f('0x29')]();});}};}function handleEntityNotFound(_0x26c0cc,_0x440786){return function(_0x171725){if(!_0x171725){_0x26c0cc[_0x5d3f('0x38')](0x194);}return _0x171725;};}function handleError(_0x348a2f,_0x1813b0){_0x1813b0=_0x1813b0||0x1f4;return function(_0x4384d9){logger[_0x5d3f('0x25')](_0x4384d9[_0x5d3f('0x39')]);if(_0x4384d9['name']){delete _0x4384d9[_0x5d3f('0x3a')];}_0x348a2f['status'](_0x1813b0)[_0x5d3f('0x3b')](_0x4384d9);};}exports[_0x5d3f('0x3c')]=function(_0x3b02a6,_0x15cfe2){var _0x19be98={'include':[{'model':db[_0x5d3f('0x3d')],'as':'mandatoryDispositionPause'}]},_0x4a172f={},_0xd95806={'count':0x0,'rows':[]};var _0x44e24b=_[_0x5d3f('0x3e')](db[_0x5d3f('0x3f')][_0x5d3f('0x40')],function(_0x4223df){return{'name':_0x4223df[_0x5d3f('0x41')],'type':_0x4223df['type'][_0x5d3f('0x42')]};});_0x4a172f[_0x5d3f('0x43')]=_['map'](_0x44e24b,'name');_0x4a172f[_0x5d3f('0x44')]=_['keys'](_0x3b02a6['query']);_0x4a172f[_0x5d3f('0x45')]=_[_0x5d3f('0x46')](_0x4a172f[_0x5d3f('0x43')],_0x4a172f['query']);_0x19be98[_0x5d3f('0x47')]=_[_0x5d3f('0x46')](_0x4a172f[_0x5d3f('0x43')],qs['fields'](_0x3b02a6[_0x5d3f('0x44')][_0x5d3f('0x48')]));_0x19be98[_0x5d3f('0x47')]=_0x19be98['attributes']['length']?_0x19be98[_0x5d3f('0x47')]:_0x4a172f[_0x5d3f('0x43')];if(!_0x3b02a6[_0x5d3f('0x44')][_0x5d3f('0x49')](_0x5d3f('0x4a'))){_0x19be98[_0x5d3f('0x2f')]=qs[_0x5d3f('0x2f')](_0x3b02a6[_0x5d3f('0x44')]['limit']);_0x19be98['offset']=qs[_0x5d3f('0x2c')](_0x3b02a6[_0x5d3f('0x44')][_0x5d3f('0x2c')]);}_0x19be98[_0x5d3f('0x4b')]=qs[_0x5d3f('0x4c')](_0x3b02a6[_0x5d3f('0x44')][_0x5d3f('0x4c')]);_0x19be98[_0x5d3f('0x4d')]=qs[_0x5d3f('0x45')](_[_0x5d3f('0x4e')](_0x3b02a6[_0x5d3f('0x44')],_0x4a172f['filters']),_0x44e24b);if(_0x3b02a6[_0x5d3f('0x44')]['filter']){_0x19be98['where']=_['merge'](_0x19be98[_0x5d3f('0x4d')],{'$or':_[_0x5d3f('0x3e')](_0x44e24b,function(_0x1501af){if(_0x1501af[_0x5d3f('0x4f')]!==_0x5d3f('0x50')){var _0x46f0cf={};_0x46f0cf[_0x1501af[_0x5d3f('0x3a')]]={'$like':'%'+_0x3b02a6[_0x5d3f('0x44')][_0x5d3f('0x51')]+'%'};return _0x46f0cf;}})});}_0x19be98=_[_0x5d3f('0x52')]({},_0x19be98,_0x3b02a6[_0x5d3f('0x53')]);var _0x5f6f29={'where':_0x19be98['where']};return db[_0x5d3f('0x3f')][_0x5d3f('0x2e')](_0x5f6f29)[_0x5d3f('0x20')](function(_0x3b8b6d){_0xd95806[_0x5d3f('0x2e')]=_0x3b8b6d;if(_0x3b02a6[_0x5d3f('0x44')][_0x5d3f('0x54')]){_0x19be98['include']=[{'all':!![]}];}return db[_0x5d3f('0x3f')][_0x5d3f('0x55')](_0x19be98);})[_0x5d3f('0x20')](function(_0x33a904){_0xd95806[_0x5d3f('0x56')]=_0x33a904;return _0xd95806;})[_0x5d3f('0x20')](respondWithFilteredResult(_0x15cfe2,_0x19be98))[_0x5d3f('0x57')](handleError(_0x15cfe2,null));};exports[_0x5d3f('0x58')]=function(_0x4bafe8,_0x2c879d){var _0x4a7091={'raw':![],'where':{'id':_0x4bafe8[_0x5d3f('0x59')]['id']},'include':[{'model':db[_0x5d3f('0x3d')],'as':_0x5d3f('0x5a')}]},_0x40ee19={};_0x40ee19[_0x5d3f('0x43')]=_[_0x5d3f('0x5b')](db[_0x5d3f('0x3f')][_0x5d3f('0x40')]);_0x40ee19[_0x5d3f('0x44')]=_[_0x5d3f('0x5b')](_0x4bafe8[_0x5d3f('0x44')]);_0x40ee19[_0x5d3f('0x45')]=_[_0x5d3f('0x46')](_0x40ee19[_0x5d3f('0x43')],_0x40ee19[_0x5d3f('0x44')]);_0x4a7091[_0x5d3f('0x47')]=_[_0x5d3f('0x46')](_0x40ee19[_0x5d3f('0x43')],qs['fields'](_0x4bafe8[_0x5d3f('0x44')][_0x5d3f('0x48')]));_0x4a7091[_0x5d3f('0x47')]=_0x4a7091['attributes'][_0x5d3f('0x5c')]?_0x4a7091[_0x5d3f('0x47')]:_0x40ee19[_0x5d3f('0x43')];if(_0x4bafe8[_0x5d3f('0x44')]['includeAll']){_0x4a7091[_0x5d3f('0x5d')]=[{'all':!![]}];}_0x4a7091=_[_0x5d3f('0x52')]({},_0x4a7091,_0x4bafe8[_0x5d3f('0x53')]);return db['OpenchannelAccount'][_0x5d3f('0x5e')](_0x4a7091)[_0x5d3f('0x20')](handleEntityNotFound(_0x2c879d,null))[_0x5d3f('0x20')](respondWithResult(_0x2c879d,null))['catch'](handleError(_0x2c879d,null));};exports[_0x5d3f('0x5f')]=function(_0x4971c5,_0x373376){return db['OpenchannelAccount'][_0x5d3f('0x5f')](_0x4971c5['body'],{})[_0x5d3f('0x20')](function(_0x23ba84){var _0x1fda7a=_0x4971c5[_0x5d3f('0x60')][_0x5d3f('0x36')]({'plain':!![]});if(!_0x1fda7a)throw new Error(_0x5d3f('0x61'));if(_0x1fda7a[_0x5d3f('0x62')]===_0x5d3f('0x60')){var _0x1dcd2c=_0x23ba84[_0x5d3f('0x36')]({'plain':!![]});var _0x58d673='OpenchannelAccounts';return db[_0x5d3f('0x63')][_0x5d3f('0x5e')]({'where':{'name':_0x58d673,'userProfileId':_0x1fda7a[_0x5d3f('0x64')]},'raw':!![]})[_0x5d3f('0x20')](function(_0x4e1c17){if(_0x4e1c17&&_0x4e1c17['autoAssociation']===0x0){return db[_0x5d3f('0x37')][_0x5d3f('0x5f')]({'name':_0x1dcd2c[_0x5d3f('0x3a')],'resourceId':_0x1dcd2c['id'],'type':_0x4e1c17[_0x5d3f('0x3a')],'sectionId':_0x4e1c17['id']},{})[_0x5d3f('0x20')](function(){return _0x23ba84;});}else{return _0x23ba84;}})[_0x5d3f('0x57')](function(_0x550113){logger['error'](_0x5d3f('0x65'),_0x550113);throw _0x550113;});}return _0x23ba84;})['then'](respondWithResult(_0x373376,0xc9))['catch'](handleError(_0x373376,null));};exports['update']=function(_0x26b0bf,_0x5e6cb0){if(_0x26b0bf[_0x5d3f('0x66')]['id']){delete _0x26b0bf[_0x5d3f('0x66')]['id'];}return db[_0x5d3f('0x3f')]['find']({'where':{'id':_0x26b0bf[_0x5d3f('0x59')]['id']},'include':[{'model':db['Pause'],'as':_0x5d3f('0x5a')}]})[_0x5d3f('0x20')](handleEntityNotFound(_0x5e6cb0,null))[_0x5d3f('0x20')](saveUpdates(_0x26b0bf[_0x5d3f('0x66')],null))[_0x5d3f('0x20')](respondWithResult(_0x5e6cb0,null))[_0x5d3f('0x57')](handleError(_0x5e6cb0,null));};exports['destroy']=function(_0x9cd0b8,_0x12e45b){return db['OpenchannelAccount'][_0x5d3f('0x5e')]({'where':{'id':_0x9cd0b8['params']['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x12e45b,null))[_0x5d3f('0x20')](removeEntity(_0x12e45b,null))[_0x5d3f('0x57')](handleError(_0x12e45b,null));};exports[_0x5d3f('0x67')]=function(_0x3dfa02,_0x2fed43){return db[_0x5d3f('0x3f')]['describe']()['then'](respondWithResult(_0x2fed43,null))[_0x5d3f('0x57')](handleError(_0x2fed43,null));};exports[_0x5d3f('0x68')]=function(_0x26affc,_0x4da859,_0x3f7013){if(_0x26affc[_0x5d3f('0x66')]['id']){delete _0x26affc[_0x5d3f('0x66')]['id'];}return db[_0x5d3f('0x3f')]['find']({'where':{'id':_0x26affc['params']['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x4da859,null))[_0x5d3f('0x20')](function(_0x4a54ce){if(_0x4a54ce){_0x26affc[_0x5d3f('0x66')][_0x5d3f('0x69')]=_0x4a54ce['id'];return db[_0x5d3f('0x6a')][_0x5d3f('0x5f')](_0x26affc[_0x5d3f('0x66')]);}})[_0x5d3f('0x20')](respondWithResult(_0x4da859,null))[_0x5d3f('0x57')](handleError(_0x4da859,null));};exports['getDispositions']=function(_0x5d3de3,_0x39de58,_0x320a27){var _0x1724f2={'raw':![],'where':{}};var _0x52c995={};var _0x51fb05={'count':0x0,'rows':[]};return db[_0x5d3f('0x3f')]['findOne']({'where':{'id':_0x5d3de3[_0x5d3f('0x59')]['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x39de58,null))[_0x5d3f('0x20')](function(_0x301367){if(_0x301367){_0x52c995['model']=_[_0x5d3f('0x5b')](db[_0x5d3f('0x6a')]['rawAttributes']);_0x52c995['query']=_[_0x5d3f('0x5b')](_0x5d3de3['query']);_0x52c995[_0x5d3f('0x45')]=_[_0x5d3f('0x46')](_0x52c995[_0x5d3f('0x43')],_0x52c995[_0x5d3f('0x44')]);_0x1724f2['attributes']=_['intersection'](_0x52c995[_0x5d3f('0x43')],qs[_0x5d3f('0x48')](_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x48')]));_0x1724f2[_0x5d3f('0x47')]=_0x1724f2[_0x5d3f('0x47')][_0x5d3f('0x5c')]?_0x1724f2['attributes']:_0x52c995[_0x5d3f('0x43')];if(!_0x5d3de3['query']['hasOwnProperty'](_0x5d3f('0x4a'))){_0x1724f2['limit']=qs['limit'](_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x2f')]);_0x1724f2['offset']=qs['offset'](_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x2c')]);}_0x1724f2[_0x5d3f('0x4b')]=qs[_0x5d3f('0x4c')](_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x4c')]);_0x1724f2[_0x5d3f('0x4d')]=qs[_0x5d3f('0x45')](_[_0x5d3f('0x4e')](_0x5d3de3[_0x5d3f('0x44')],_0x52c995[_0x5d3f('0x45')]));_0x1724f2[_0x5d3f('0x4d')][_0x5d3f('0x69')]=_0x301367['id'];if(_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x51')]){_0x1724f2[_0x5d3f('0x4d')]=_['merge'](_0x1724f2[_0x5d3f('0x4d')],{'$or':_[_0x5d3f('0x3e')](_0x1724f2[_0x5d3f('0x47')],function(_0x47eaf0){var _0x20a214={};_0x20a214[_0x47eaf0]={'$like':'%'+_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x51')]+'%'};return _0x20a214;})});}_0x1724f2=_[_0x5d3f('0x52')]({},_0x1724f2,_0x5d3de3[_0x5d3f('0x53')]);return db['Disposition'][_0x5d3f('0x2e')]({'where':_0x1724f2[_0x5d3f('0x4d')]})[_0x5d3f('0x20')](function(_0x54eb2b){_0x51fb05['count']=_0x54eb2b;if(_0x5d3de3[_0x5d3f('0x44')][_0x5d3f('0x54')]){_0x1724f2[_0x5d3f('0x5d')]=[{'all':!![]}];}return db[_0x5d3f('0x6a')]['findAll'](_0x1724f2);})[_0x5d3f('0x20')](function(_0x57f8ab){_0x51fb05[_0x5d3f('0x56')]=_0x57f8ab;return _0x51fb05;});}})[_0x5d3f('0x20')](respondWithFilteredResult(_0x39de58,_0x1724f2))[_0x5d3f('0x57')](handleError(_0x39de58,null));};exports[_0x5d3f('0x6b')]=function(_0xf16a47,_0x40a0da,_0x52b568){return db[_0x5d3f('0x3f')][_0x5d3f('0x5e')]({'where':{'id':_0xf16a47[_0x5d3f('0x59')]['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x40a0da,null))[_0x5d3f('0x20')](function(_0x32253b){if(_0x32253b){return _0x32253b['removeDispositions'](_0xf16a47[_0x5d3f('0x44')][_0x5d3f('0x6c')]);}})[_0x5d3f('0x20')](respondWithStatusCode(_0x40a0da,null))['catch'](handleError(_0x40a0da,null));};exports['addAnswer']=function(_0x43cf47,_0xf915d7,_0x484cb6){if(_0x43cf47[_0x5d3f('0x66')]['id']){delete _0x43cf47[_0x5d3f('0x66')]['id'];}return db[_0x5d3f('0x3f')][_0x5d3f('0x5e')]({'where':{'id':_0x43cf47['params']['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0xf915d7,null))[_0x5d3f('0x20')](function(_0x2cb314){if(_0x2cb314){_0x43cf47[_0x5d3f('0x66')][_0x5d3f('0x69')]=_0x2cb314['id'];return db[_0x5d3f('0x6d')][_0x5d3f('0x5f')](_0x43cf47['body']);}})['then'](respondWithResult(_0xf915d7,null))['catch'](handleError(_0xf915d7,null));};exports[_0x5d3f('0x6e')]=function(_0x2482e3,_0x564dec,_0x144a42){var _0x13a042={'raw':![],'where':{}};var _0x2af2d3={};var _0x2b7864={'count':0x0,'rows':[]};return db[_0x5d3f('0x3f')]['findOne']({'where':{'id':_0x2482e3['params']['id']}})['then'](handleEntityNotFound(_0x564dec,null))[_0x5d3f('0x20')](function(_0x61d7cd){if(_0x61d7cd){_0x2af2d3[_0x5d3f('0x43')]=_[_0x5d3f('0x5b')](db[_0x5d3f('0x6d')][_0x5d3f('0x40')]);_0x2af2d3['query']=_[_0x5d3f('0x5b')](_0x2482e3[_0x5d3f('0x44')]);_0x2af2d3[_0x5d3f('0x45')]=_['intersection'](_0x2af2d3['model'],_0x2af2d3['query']);_0x13a042['attributes']=_[_0x5d3f('0x46')](_0x2af2d3[_0x5d3f('0x43')],qs[_0x5d3f('0x48')](_0x2482e3[_0x5d3f('0x44')][_0x5d3f('0x48')]));_0x13a042['attributes']=_0x13a042[_0x5d3f('0x47')][_0x5d3f('0x5c')]?_0x13a042[_0x5d3f('0x47')]:_0x2af2d3[_0x5d3f('0x43')];if(!_0x2482e3[_0x5d3f('0x44')][_0x5d3f('0x49')](_0x5d3f('0x4a'))){_0x13a042[_0x5d3f('0x2f')]=qs[_0x5d3f('0x2f')](_0x2482e3[_0x5d3f('0x44')][_0x5d3f('0x2f')]);_0x13a042[_0x5d3f('0x2c')]=qs[_0x5d3f('0x2c')](_0x2482e3['query'][_0x5d3f('0x2c')]);}_0x13a042[_0x5d3f('0x4b')]=qs['sort'](_0x2482e3['query'][_0x5d3f('0x4c')]);_0x13a042['where']=qs[_0x5d3f('0x45')](_[_0x5d3f('0x4e')](_0x2482e3[_0x5d3f('0x44')],_0x2af2d3['filters']));_0x13a042[_0x5d3f('0x4d')][_0x5d3f('0x69')]=_0x61d7cd['id'];if(_0x2482e3['query']['filter']){_0x13a042['where']=_[_0x5d3f('0x52')](_0x13a042['where'],{'$or':_[_0x5d3f('0x3e')](_0x13a042[_0x5d3f('0x47')],function(_0x256018){var _0x5718f9={};_0x5718f9[_0x256018]={'$like':'%'+_0x2482e3['query'][_0x5d3f('0x51')]+'%'};return _0x5718f9;})});}_0x13a042=_[_0x5d3f('0x52')]({},_0x13a042,_0x2482e3[_0x5d3f('0x53')]);return db[_0x5d3f('0x6d')]['count']({'where':_0x13a042['where']})['then'](function(_0x3c7c51){_0x2b7864[_0x5d3f('0x2e')]=_0x3c7c51;if(_0x2482e3[_0x5d3f('0x44')][_0x5d3f('0x54')]){_0x13a042['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x5d3f('0x55')](_0x13a042);})[_0x5d3f('0x20')](function(_0x42d40d){_0x2b7864[_0x5d3f('0x56')]=_0x42d40d;return _0x2b7864;});}})['then'](respondWithFilteredResult(_0x564dec,_0x13a042))[_0x5d3f('0x57')](handleError(_0x564dec,null));};exports['removeAnswers']=function(_0x7d4a27,_0xc5edd1,_0x3970ad){return db[_0x5d3f('0x3f')]['find']({'where':{'id':_0x7d4a27[_0x5d3f('0x59')]['id']}})['then'](handleEntityNotFound(_0xc5edd1,null))[_0x5d3f('0x20')](function(_0x4cfb0e){if(_0x4cfb0e){return _0x4cfb0e[_0x5d3f('0x6f')](_0x7d4a27[_0x5d3f('0x44')]['ids']);}})['then'](respondWithStatusCode(_0xc5edd1,null))[_0x5d3f('0x57')](handleError(_0xc5edd1,null));};exports['notify']=function(_0x27aa38,_0x3cd6d6,_0x2ac40b){var _0x2a6b82={'body':_0x27aa38[_0x5d3f('0x66')],'channel':_0x5d3f('0x70')};var _0x393867=[];var _0x4aa980=[];var _0x41b71c={};var _0x44657d=![];return db[_0x5d3f('0x71')][_0x5d3f('0x67')]()[_0x5d3f('0x20')](function(_0xc63d18){if(!_0xc63d18){throw new db[(_0x5d3f('0x72'))]['ValidationError']('no\x20available\x20attributes');}_0x393867=_['difference'](_[_0x5d3f('0x5b')](_0xc63d18),['createdAt',_0x5d3f('0x73')]);_0x4aa980=_[_0x5d3f('0x74')](_[_0x5d3f('0x5b')](_0xc63d18),['createdAt',_0x5d3f('0x73'),_0x5d3f('0x75'),_0x5d3f('0x76')]);if(_0x27aa38[_0x5d3f('0x66')]['id']){delete _0x27aa38[_0x5d3f('0x66')]['id'];}if(_['isNil'](_0x27aa38['body'][_0x5d3f('0x77')])){throw new db[(_0x5d3f('0x72'))][(_0x5d3f('0x78'))](_0x5d3f('0x79'));}if(_[_0x5d3f('0x7a')](_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x66')])||_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x66')]===''){throw new db[(_0x5d3f('0x72'))][(_0x5d3f('0x78'))](_0x5d3f('0x7b'));}if(_[_0x5d3f('0x7a')](_0x27aa38['body'][_0x5d3f('0x7c')])){throw new db[(_0x5d3f('0x72'))]['ValidationError'](_0x5d3f('0x7d')+_0x4aa980);}if(!_[_0x5d3f('0x7e')](_0x4aa980,_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x7c')])){throw new db[(_0x5d3f('0x72'))][(_0x5d3f('0x78'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4aa980);}_0x41b71c[_0x27aa38[_0x5d3f('0x66')]['mapKey']]=_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x77')];})['then'](function(){return db[_0x5d3f('0x3f')][_0x5d3f('0x5e')]({'where':{'id':_0x27aa38[_0x5d3f('0x59')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x5d3f('0x71')],'as':_0x5d3f('0x7f'),'where':_0x41b71c,'limit':0x1,'order':[[_0x5d3f('0x73'),_0x5d3f('0x80')]]}]},{'model':db[_0x5d3f('0x81')],'as':'Applications'}]});})[_0x5d3f('0x20')](handleEntityNotFound(_0x3cd6d6,null))[_0x5d3f('0x20')](function(_0x597513){if(_0x597513&&_0x597513[_0x5d3f('0x82')]){_0x2a6b82[_0x5d3f('0x83')]=_0x597513;_0x2a6b82[_0x5d3f('0x84')]=_0x597513[_0x5d3f('0x85')];_0x2a6b82[_0x5d3f('0x86')]=_0x597513[_0x5d3f('0x82')];_0x2a6b82[_0x5d3f('0x84')]=_['orderBy'](_0x2a6b82[_0x5d3f('0x84')],[_0x5d3f('0x87')],['asc']);if(_0x2a6b82[_0x5d3f('0x83')][_0x5d3f('0x85')]){delete _0x2a6b82[_0x5d3f('0x83')]['Applications'];}if(_0x2a6b82[_0x5d3f('0x83')][_0x5d3f('0x82')]&&_0x2a6b82['account'][_0x5d3f('0x82')][_0x5d3f('0x7f')][_0x5d3f('0x5c')]){return _0x2a6b82['account'][_0x5d3f('0x82')][_0x5d3f('0x7f')][0x0];}var _0x526e9c=_[_0x5d3f('0x19')](_0x27aa38[_0x5d3f('0x66')],{'firstName':_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x77')],'ListId':_0x597513[_0x5d3f('0x76')]});_0x526e9c[_0x27aa38['body'][_0x5d3f('0x7c')]]=_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x77')];return db['CmContact'][_0x5d3f('0x5f')](_0x526e9c,{'fields':_0x393867,'raw':!![]});}})[_0x5d3f('0x20')](handleEntityNotFound(_0x3cd6d6,null))[_0x5d3f('0x20')](function(_0x1fc99a){_0x2a6b82['contact']=_0x1fc99a;if(_0x1fc99a){var _0x263b3d={'ContactId':_0x1fc99a['id'],'OpenchannelAccountId':_0x27aa38[_0x5d3f('0x59')]['id'],'from':(_0x1fc99a['firstName']||'')+'\x20'+(_0x1fc99a['lastName']||'')};var _0x47f8cd={'OpenchannelAccountId':_0x27aa38[_0x5d3f('0x59')]['id'],'closed':![]};if(_0x27aa38['body']['threadId']){_0x47f8cd[_0x5d3f('0x88')]=_0x27aa38[_0x5d3f('0x66')]['threadId'];return db[_0x5d3f('0x89')][_0x5d3f('0x5e')]({'where':_0x47f8cd})[_0x5d3f('0x20')](function(_0x1c8cd3){if(_0x1c8cd3){return[_0x1c8cd3,![]];}_0x263b3d[_0x5d3f('0x88')]=_0x27aa38[_0x5d3f('0x66')]['threadId'];_0x263b3d[_0x5d3f('0x8a')]=_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x8a')];return db[_0x5d3f('0x89')][_0x5d3f('0x5f')](_0x263b3d)[_0x5d3f('0x20')](function(_0x11de23){return[_0x11de23,!![]];});});}else{_0x47f8cd[_0x5d3f('0x88')]=null;}_0x47f8cd['ContactId']=_0x1fc99a['id'];return db['OpenchannelInteraction']['find']({'where':_0x47f8cd})[_0x5d3f('0x20')](function(_0x4e5fb4){if(_0x4e5fb4){return[_0x4e5fb4,![]];}return db['OpenchannelInteraction'][_0x5d3f('0x5f')](_0x263b3d)['then'](function(_0x18e736){return[_0x18e736,!![]];});});}})[_0x5d3f('0x8b')](function(_0x581198,_0x5935df){if(_0x581198){_0x44657d=_0x5935df;if(!_0x5935df){var _0x26a433={'from':(_0x2a6b82[_0x5d3f('0x8c')][_0x5d3f('0x8d')]||'')+'\x20'+(_0x2a6b82[_0x5d3f('0x8c')][_0x5d3f('0x8e')]||'')};if(_0x27aa38['body'][_0x5d3f('0x88')]&&_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x8f')]&&_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x88')]!=_0x27aa38['body'][_0x5d3f('0x8f')]){_0x26a433[_0x5d3f('0x88')]=_0x27aa38[_0x5d3f('0x66')][_0x5d3f('0x8f')];}return _0x581198[_0x5d3f('0x34')](_0x26a433);}else{return _0x581198;}}})[_0x5d3f('0x20')](function(_0x5ec075){_0x2a6b82[_0x5d3f('0x90')]=_0x5ec075[_0x5d3f('0x36')]({'plain':!![]});_0x2a6b82[_0x5d3f('0x90')][_0x5d3f('0x91')]=_0x44657d;if(_0x2a6b82[_0x5d3f('0x90')][_0x5d3f('0x91')]){if(_0x2a6b82[_0x5d3f('0x83')][_0x5d3f('0x92')]){_0x2a6b82['applications'][_0x5d3f('0x93')]({'id':0x0,'priority':_0x2a6b82[_0x5d3f('0x84')][_0x5d3f('0x5c')]+0x1,'app':_0x5d3f('0x94'),'appdata':'unmanaged','interval':_0x5d3f('0x95')});}}return db['OpenchannelMessage'][_0x5d3f('0x5f')]({'body':_0x27aa38['body']['body'],'OpenchannelAccountId':_0x27aa38['params']['id'],'OpenchannelInteractionId':_0x5ec075['id'],'direction':'in','ContactId':_0x2a6b82[_0x5d3f('0x8c')]['id'],'AttachmentId':_0x27aa38[_0x5d3f('0x66')]['AttachmentId']});})[_0x5d3f('0x20')](function(_0x3553be){_0x2a6b82['message']=_0x3553be;if(_0x2a6b82[_0x5d3f('0x90')]['UserId']){return db[_0x5d3f('0x96')][_0x5d3f('0x5e')]({'attributes':['id',_0x5d3f('0x3a')],'where':{'id':_0x2a6b82[_0x5d3f('0x90')][_0x5d3f('0x97')]}})[_0x5d3f('0x20')](function(_0xf81c6b){if(_0xf81c6b){_0x2a6b82[_0x5d3f('0x84')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0xf81c6b[_0x5d3f('0x3a')]+','+(_0x2a6b82[_0x5d3f('0x83')][_0x5d3f('0x98')]||0xa),'interval':_0x5d3f('0x95')});_0x2a6b82[_0x5d3f('0x99')]=![];}return respondWithRpcPromise('Start',_0x5d3f('0x9a'),_0x2a6b82);});}return respondWithRpcPromise(_0x5d3f('0x9b'),_0x5d3f('0x9a'),_0x2a6b82);})[_0x5d3f('0x20')](function(_0xb31d39){respondWithRpcPromise(_0x5d3f('0x9c'),_0x5d3f('0x9c'),{'event':_0x5d3f('0x9d'),'message':_0xb31d39},client9002);return _0xb31d39;})['then'](respondWithResult(_0x3cd6d6,null))[_0x5d3f('0x57')](handleError(_0x3cd6d6,null));};exports[_0x5d3f('0x9e')]=function(_0x3c3d11,_0x2fea24){var _0x3b0501=_0x3c3d11[_0x5d3f('0x59')]['id'];var _0x62a319=_0x3c3d11[_0x5d3f('0x66')];var _0xf54c5c=0xc8;var _0x18916d=null;return db[_0x5d3f('0x9f')][_0x5d3f('0xa0')]({'isolationLevel':db[_0x5d3f('0x9f')][_0x5d3f('0xa1')][_0x5d3f('0xa2')][_0x5d3f('0xa3')]},function(_0x419855){return db['OpenchannelAccount'][_0x5d3f('0xa4')]({'where':{'id':_0x3b0501},'transaction':_0x419855})[_0x5d3f('0x20')](function(_0x1dce94){if(_0x1dce94){return db[_0x5d3f('0x81')]['destroy']({'where':{'OpenchannelAccountId':_0x3b0501},'transaction':_0x419855})[_0x5d3f('0x20')](function(){var _0x4da205=_[_0x5d3f('0x3e')](_0x62a319,function(_0x3cb117){_0x3cb117[_0x5d3f('0x69')]=_0x3b0501;return _0x3cb117;});return db['OpenchannelApplication'][_0x5d3f('0xa5')](_0x4da205,{'transaction':_0x419855});});}else{_0xf54c5c=0x194;_0x18916d=[];}});})[_0x5d3f('0x20')](function(){if(_0xf54c5c!==0x194){return db['OpenchannelApplication']['findAndCountAll']({'where':{'OpenchannelAccountId':_0x3b0501},'order':'priority'})['then'](function(_0x8cd944){_0x18916d=_0x8cd944;});}})[_0x5d3f('0x57')](function(_0x248af7){_0xf54c5c=0x1f4;logger[_0x5d3f('0x25')](_0x248af7[_0x5d3f('0x39')]);if(_0x248af7[_0x5d3f('0x3a')]){delete _0x248af7[_0x5d3f('0x3a')];}_0x18916d=_0x248af7;})['finally'](function(){if(_0x18916d===null){_0x2fea24['sendStatus'](_0xf54c5c);}else{if(_0xf54c5c===0x1f4){_0x2fea24['status'](_0xf54c5c)[_0x5d3f('0x3b')](_0x18916d);}else{_0x2fea24[_0x5d3f('0x2a')](_0xf54c5c)[_0x5d3f('0x2b')](_0x18916d);}}});};exports['getApplications']=function(_0x320821,_0x3ed9ae,_0x1a4ac7){var _0x2a858c={};var _0xc2ceac={};var _0xc1bc5e;var _0x53e812;return db[_0x5d3f('0x3f')][_0x5d3f('0xa4')]({'where':{'id':_0x320821['params']['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x3ed9ae,null))['then'](function(_0x2916a5){if(_0x2916a5){_0xc1bc5e=_0x2916a5;_0xc2ceac['model']=_[_0x5d3f('0x5b')](db[_0x5d3f('0x81')][_0x5d3f('0x40')]);_0xc2ceac['query']=_[_0x5d3f('0x5b')](_0x320821[_0x5d3f('0x44')]);_0xc2ceac[_0x5d3f('0x45')]=_['intersection'](_0xc2ceac[_0x5d3f('0x43')],_0xc2ceac[_0x5d3f('0x44')]);_0x2a858c[_0x5d3f('0x47')]=_[_0x5d3f('0x46')](_0xc2ceac[_0x5d3f('0x43')],qs[_0x5d3f('0x48')](_0x320821[_0x5d3f('0x44')][_0x5d3f('0x48')]));_0x2a858c[_0x5d3f('0x47')]=_0x2a858c['attributes'][_0x5d3f('0x5c')]?_0x2a858c['attributes']:_0xc2ceac[_0x5d3f('0x43')];_0x2a858c[_0x5d3f('0x4b')]=qs[_0x5d3f('0x4c')](_0x320821['query'][_0x5d3f('0x4c')]);_0x2a858c[_0x5d3f('0x4d')]=qs[_0x5d3f('0x45')](_['pick'](_0x320821['query'],_0xc2ceac[_0x5d3f('0x45')]));if(_0x320821[_0x5d3f('0x44')][_0x5d3f('0x51')]){_0x2a858c[_0x5d3f('0x4d')]=_[_0x5d3f('0x52')](_0x2a858c[_0x5d3f('0x4d')],{'$or':_['map'](_0x2a858c[_0x5d3f('0x47')],function(_0x15c78b){var _0x222a15={};_0x222a15[_0x15c78b]={'$like':'%'+_0x320821[_0x5d3f('0x44')]['filter']+'%'};return _0x222a15;})});}_0x2a858c=_['merge']({},_0x2a858c,_0x320821[_0x5d3f('0x53')]);return _0xc1bc5e[_0x5d3f('0xa6')](_0x2a858c);}})[_0x5d3f('0x20')](function(_0x45780a){if(_0x45780a){_0x53e812=_0x45780a[_0x5d3f('0x5c')];if(!_0x320821[_0x5d3f('0x44')][_0x5d3f('0x49')](_0x5d3f('0x4a'))){_0x2a858c['limit']=qs[_0x5d3f('0x2f')](_0x320821['query'][_0x5d3f('0x2f')]);_0x2a858c['offset']=qs[_0x5d3f('0x2c')](_0x320821[_0x5d3f('0x44')][_0x5d3f('0x2c')]);}return _0xc1bc5e['getApplications'](_0x2a858c);}})[_0x5d3f('0x20')](function(_0x1ba451){if(_0x1ba451){return _0x1ba451?{'count':_0x53e812,'rows':_0x1ba451}:null;}})['then'](respondWithResult(_0x3ed9ae,null))[_0x5d3f('0x57')](handleError(_0x3ed9ae,null));};exports['getInteractions']=function(_0x3fa8b8,_0x822ea3,_0x4b2809){var _0x56477c={'raw':![],'where':{}};var _0x13ee17={};var _0x316a9e={'count':0x0,'rows':[]};return db[_0x5d3f('0x3f')]['findOne']({'where':{'id':_0x3fa8b8['params']['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x822ea3,null))[_0x5d3f('0x20')](function(_0x134b7b){if(_0x134b7b){_0x13ee17[_0x5d3f('0x43')]=_[_0x5d3f('0x5b')](db[_0x5d3f('0x89')]['rawAttributes']);_0x13ee17[_0x5d3f('0x44')]=_['keys'](_0x3fa8b8[_0x5d3f('0x44')]);_0x13ee17['filters']=_[_0x5d3f('0x46')](_0x13ee17[_0x5d3f('0x43')],_0x13ee17['query']);_0x56477c[_0x5d3f('0x47')]=_[_0x5d3f('0x46')](_0x13ee17[_0x5d3f('0x43')],qs[_0x5d3f('0x48')](_0x3fa8b8['query'][_0x5d3f('0x48')]));_0x56477c[_0x5d3f('0x47')]=_0x56477c[_0x5d3f('0x47')][_0x5d3f('0x5c')]?_0x56477c[_0x5d3f('0x47')]:_0x13ee17['model'];if(!_0x3fa8b8['query'][_0x5d3f('0x49')](_0x5d3f('0x4a'))){_0x56477c[_0x5d3f('0x2f')]=qs[_0x5d3f('0x2f')](_0x3fa8b8['query']['limit']);_0x56477c[_0x5d3f('0x2c')]=qs[_0x5d3f('0x2c')](_0x3fa8b8[_0x5d3f('0x44')][_0x5d3f('0x2c')]);}_0x56477c[_0x5d3f('0x4b')]=qs[_0x5d3f('0x4c')](_0x3fa8b8['query'][_0x5d3f('0x4c')]);_0x56477c[_0x5d3f('0x4d')]=qs[_0x5d3f('0x45')](_[_0x5d3f('0x4e')](_0x3fa8b8[_0x5d3f('0x44')],_0x13ee17['filters']));_0x56477c[_0x5d3f('0x4d')][_0x5d3f('0x69')]=_0x134b7b['id'];if(_0x3fa8b8['query'][_0x5d3f('0x51')]){_0x56477c[_0x5d3f('0x4d')]=_[_0x5d3f('0x52')](_0x56477c[_0x5d3f('0x4d')],{'$or':_[_0x5d3f('0x3e')](_0x56477c[_0x5d3f('0x47')],function(_0x159316){var _0x5c7e5b={};_0x5c7e5b[_0x159316]={'$like':'%'+_0x3fa8b8[_0x5d3f('0x44')]['filter']+'%'};return _0x5c7e5b;})});}_0x56477c=_['merge']({},_0x56477c,_0x3fa8b8[_0x5d3f('0x53')]);return db[_0x5d3f('0x89')]['count']({'where':_0x56477c[_0x5d3f('0x4d')]})[_0x5d3f('0x20')](function(_0x44455c){_0x316a9e[_0x5d3f('0x2e')]=_0x44455c;if(_0x3fa8b8[_0x5d3f('0x44')]['includeAll']){_0x56477c[_0x5d3f('0x5d')]=[{'model':db[_0x5d3f('0x71')],'as':_0x5d3f('0xa7'),'required':![]},{'model':db['User'],'as':'Owner','attributes':['name',_0x5d3f('0xa8'),_0x5d3f('0xa9')],'required':![]},{'model':db[_0x5d3f('0xaa')],'as':_0x5d3f('0xab'),'attributes':['id',_0x5d3f('0x3a'),_0x5d3f('0xac')],'where':_0x3fa8b8[_0x5d3f('0x44')][_0x5d3f('0xad')]?{'id':_0x3fa8b8[_0x5d3f('0x44')]['tag']}:undefined,'required':_0x3fa8b8[_0x5d3f('0x44')][_0x5d3f('0xad')]?!![]:![]}];}return db[_0x5d3f('0x89')][_0x5d3f('0x55')](_0x56477c);})[_0x5d3f('0x20')](function(_0x1e3111){_0x316a9e['rows']=_0x1e3111;return _0x316a9e;});}})['then'](respondWithFilteredResult(_0x822ea3,_0x56477c))[_0x5d3f('0x57')](handleError(_0x822ea3,null));};exports[_0x5d3f('0xae')]=function(_0xc91d2,_0x219e2a,_0x76fb1d){return db[_0x5d3f('0x3f')][_0x5d3f('0x5e')]({'where':{'id':_0xc91d2['params']['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x219e2a,null))[_0x5d3f('0x20')](function(_0x423c6a){if(_0x423c6a){return _0x423c6a[_0x5d3f('0xae')](_0xc91d2[_0x5d3f('0x66')][_0x5d3f('0x6c')],_[_0x5d3f('0xaf')](_0xc91d2[_0x5d3f('0x66')],[_0x5d3f('0x6c'),'id'])||{})[_0x5d3f('0x8b')](function(_0xa6f32f){for(var _0x4664b5=0x0;_0x4664b5<_0xc91d2[_0x5d3f('0x66')][_0x5d3f('0x6c')][_0x5d3f('0x5c')];_0x4664b5+=0x1){socket[_0x5d3f('0xb0')](_0x5d3f('0xb1'),{'UserId':Number(_0xc91d2[_0x5d3f('0x66')][_0x5d3f('0x6c')][_0x4664b5]),'OpenchannelAccountId':Number(_0xc91d2[_0x5d3f('0x59')]['id'])});}return _0xa6f32f;});}})[_0x5d3f('0x20')](respondWithResult(_0x219e2a,null))[_0x5d3f('0x57')](handleError(_0x219e2a,null));};exports[_0x5d3f('0xb2')]=function(_0x1e8238,_0x48e022,_0x53671f){return db[_0x5d3f('0x3f')]['find']({'where':{'id':_0x1e8238[_0x5d3f('0x59')]['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x48e022,null))[_0x5d3f('0x20')](function(_0x310631){if(_0x310631){return _0x310631[_0x5d3f('0xb2')](_0x1e8238[_0x5d3f('0x44')][_0x5d3f('0x6c')])[_0x5d3f('0x20')](function(){if(_[_0x5d3f('0xb3')](_0x1e8238[_0x5d3f('0x44')]['ids'])){for(var _0x409a3b=0x0;_0x409a3b<_0x1e8238[_0x5d3f('0x44')][_0x5d3f('0x6c')][_0x5d3f('0x5c')];_0x409a3b+=0x1){socket[_0x5d3f('0xb0')](_0x5d3f('0xb4'),{'UserId':Number(_0x1e8238[_0x5d3f('0x44')][_0x5d3f('0x6c')][_0x409a3b]),'OpenchannelAccountId':Number(_0x1e8238[_0x5d3f('0x59')]['id'])});}}else{socket['emit'](_0x5d3f('0xb4'),{'UserId':Number(_0x1e8238[_0x5d3f('0x44')]['ids']),'OpenchannelAccountId':Number(_0x1e8238[_0x5d3f('0x59')]['id'])});}});}})[_0x5d3f('0x20')](respondWithStatusCode(_0x48e022,null))['catch'](handleError(_0x48e022,null));};exports[_0x5d3f('0xb5')]=function(_0x1ced47,_0x25a60e,_0x5b4094){var _0xc971ab={};var _0x4f1ce1={};var _0x588700;var _0x262561;return db[_0x5d3f('0x3f')]['findOne']({'where':{'id':_0x1ced47[_0x5d3f('0x59')]['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x25a60e,null))['then'](function(_0x3f7ee3){if(_0x3f7ee3){_0x588700=_0x3f7ee3;_0x4f1ce1[_0x5d3f('0x43')]=_[_0x5d3f('0x5b')](db[_0x5d3f('0x96')]['rawAttributes']);_0x4f1ce1['query']=_[_0x5d3f('0x5b')](_0x1ced47[_0x5d3f('0x44')]);_0x4f1ce1[_0x5d3f('0x45')]=_['intersection'](_0x4f1ce1[_0x5d3f('0x43')],_0x4f1ce1['query']);_0xc971ab[_0x5d3f('0x47')]=_[_0x5d3f('0x46')](_0x4f1ce1[_0x5d3f('0x43')],qs[_0x5d3f('0x48')](_0x1ced47[_0x5d3f('0x44')][_0x5d3f('0x48')]));_0xc971ab['attributes']=_0xc971ab[_0x5d3f('0x47')][_0x5d3f('0x5c')]?_0xc971ab['attributes']:_0x4f1ce1['model'];_0xc971ab[_0x5d3f('0x4b')]=qs[_0x5d3f('0x4c')](_0x1ced47['query'][_0x5d3f('0x4c')]);_0xc971ab[_0x5d3f('0x4d')]=qs['filters'](_[_0x5d3f('0x4e')](_0x1ced47[_0x5d3f('0x44')],_0x4f1ce1['filters']));if(_0x1ced47['query'][_0x5d3f('0x51')]){_0xc971ab['where']=_['merge'](_0xc971ab[_0x5d3f('0x4d')],{'$or':_[_0x5d3f('0x3e')](_0xc971ab[_0x5d3f('0x47')],function(_0x4c525c){var _0x4d6703={};_0x4d6703[_0x4c525c]={'$like':'%'+_0x1ced47[_0x5d3f('0x44')][_0x5d3f('0x51')]+'%'};return _0x4d6703;})});}_0xc971ab=_[_0x5d3f('0x52')]({},_0xc971ab,_0x1ced47[_0x5d3f('0x53')]);return _0x588700['getAgents'](_0xc971ab);}})[_0x5d3f('0x20')](function(_0x3b1b72){if(_0x3b1b72){_0x262561=_0x3b1b72['length'];if(!_0x1ced47[_0x5d3f('0x44')][_0x5d3f('0x49')](_0x5d3f('0x4a'))){_0xc971ab[_0x5d3f('0x2f')]=qs[_0x5d3f('0x2f')](_0x1ced47[_0x5d3f('0x44')]['limit']);_0xc971ab['offset']=qs['offset'](_0x1ced47[_0x5d3f('0x44')]['offset']);}return _0x588700[_0x5d3f('0xb5')](_0xc971ab);}})[_0x5d3f('0x20')](function(_0x2fbdd3){if(_0x2fbdd3){return _0x2fbdd3?{'count':_0x262561,'rows':_0x2fbdd3}:null;}})[_0x5d3f('0x20')](respondWithResult(_0x25a60e,null))[_0x5d3f('0x57')](handleError(_0x25a60e,null));};exports[_0x5d3f('0x3b')]=function(_0x57a87f,_0x16fb26,_0x3cd792){var _0x4d1222,_0x1f3b21,_0x5e85ec;if(_[_0x5d3f('0x7a')](_0x57a87f[_0x5d3f('0x66')]['body'])||_0x57a87f[_0x5d3f('0x66')][_0x5d3f('0x66')]===''){throw new db[(_0x5d3f('0x72'))][(_0x5d3f('0x78'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x5d3f('0x7a')](_0x57a87f[_0x5d3f('0x66')]['to'])){}_0x4d1222=_0x57a87f[_0x5d3f('0x66')]['to'];return db[_0x5d3f('0x3f')]['findOne']({'where':{'id':_0x57a87f[_0x5d3f('0x59')]['id']}})[_0x5d3f('0x20')](handleEntityNotFound(_0x16fb26,null))[_0x5d3f('0x20')](function(_0x481824){if(_0x481824){return db[_0x5d3f('0x3f')][_0x5d3f('0x5e')]({'where':{'id':_0x481824['id']},'include':[{'model':db[_0x5d3f('0xb6')],'as':'List','include':[{'model':db[_0x5d3f('0x71')],'as':_0x5d3f('0x7f'),'where':{[_0x481824[_0x5d3f('0x7c')]]:_0x4d1222},'limit':0x1,'order':[['updatedAt',_0x5d3f('0x80')]]}]}]})['then'](handleEntityNotFound(_0x16fb26,null))['then'](function(_0x24735e){if(_0x24735e&&_0x24735e[_0x5d3f('0x82')]){_0x1f3b21=_0x24735e[_0x5d3f('0x36')]({'plain':!![]});if(_0x1f3b21[_0x5d3f('0x82')]&&_0x1f3b21['List'][_0x5d3f('0x7f')][_0x5d3f('0x5c')]){return _0x1f3b21['List'][_0x5d3f('0x7f')][0x0];}return db[_0x5d3f('0x71')]['create'](_[_0x5d3f('0x19')](_0x57a87f[_0x5d3f('0x66')],{'firstName':_0x4d1222,[_0x24735e['mapKey']]:_0x4d1222,'phone':_0x4d1222,'ListId':_0x1f3b21[_0x5d3f('0x76')]}));}})[_0x5d3f('0x20')](handleEntityNotFound(_0x16fb26,null))[_0x5d3f('0x20')](function(_0x14071d){if(_0x14071d){_0x5e85ec=_0x14071d;return db[_0x5d3f('0x89')][_0x5d3f('0x5e')]({'where':{'ContactId':_0x5e85ec['id'],'closed':![],'OpenchannelAccountId':_0x1f3b21['id']}})['then'](function(_0x62e607){if(_0x62e607){return[_0x62e607,![]];}return db['OpenchannelInteraction'][_0x5d3f('0x5f')]({'UserId':_0x57a87f[_0x5d3f('0x60')]['id'],'ContactId':_0x5e85ec['id'],'OpenchannelAccountId':_0x1f3b21['id'],'lastMsgDirection':_0x5d3f('0xb7'),'Messages':[_[_0x5d3f('0x52')](_0x57a87f[_0x5d3f('0x66')],{'read':![],'body':_0x57a87f[_0x5d3f('0x66')][_0x5d3f('0x66')],'OpenchannelAccountId':_0x1f3b21['id'],'UserId':_0x57a87f[_0x5d3f('0x60')]['id'],'ContactId':_0x5e85ec['id']})]},{'include':[{'model':db[_0x5d3f('0xb8')],'as':'Messages'}]})[_0x5d3f('0x20')](function(_0x1a3944){return[_0x1a3944,!![]];});});}})[_0x5d3f('0x8b')](function(_0x2c77ed,_0x4a32ff){if(_0x4a32ff){return _0x2c77ed;}return db['OpenchannelMessage'][_0x5d3f('0x5f')](_[_0x5d3f('0x52')](_0x57a87f['body'],{'read':![],'body':_0x57a87f[_0x5d3f('0x66')][_0x5d3f('0x66')],'OpenchannelAccountId':_0x1f3b21['id'],'OpenchannelInteractionId':_0x2c77ed['id'],'UserId':_0x57a87f[_0x5d3f('0x60')]['id'],'ContactId':_0x5e85ec['id']}))[_0x5d3f('0x20')](function(_0x512d10){_0x2c77ed[_0x5d3f('0xb9')][_0x5d3f('0xba')]=[];_0x2c77ed[_0x5d3f('0xb9')][_0x5d3f('0xba')][_0x5d3f('0x93')](_0x512d10[_0x5d3f('0xb9')]);return _0x2c77ed;});});}})[_0x5d3f('0x20')](respondWithResult(_0x16fb26,null))[_0x5d3f('0x57')](handleError(_0x16fb26,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