Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 1275433..d4f0707 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbc70=['zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','client','info','OpenchannelAccount,\x20%s,\x20%s','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','catch','end','status','json','offset','undefined','count','limit','set','Content-Range','reject','then','get','UserProfileResource','destroy','name','index','mandatoryDispositionPause','map','OpenchannelAccount','type','key','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','Pause','find','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','OpenchannelAccounts','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','OpenchannelAccountId','getDispositions','findOne','rawAttributes','options','Disposition','removeDispositions','ids','getAnswers','CannedAnswer','length','removeAnswers','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','List','Contacts','OpenchannelApplication','Applications','list','applications','priority','asc','account','ListId','firstName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','contact','lastName','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','notify','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','stack','finally','sendStatus','send','getApplications','Contact','Owner','fullname','internal','Tag','Tags','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','userOpenchannelAccount:remove','getAgents','CmList','out','Messages','dataValues','eml-format','rimraf'];(function(_0x4a0058,_0x413446){var _0x1e0db0=function(_0x37e952){while(--_0x37e952){_0x4a0058['push'](_0x4a0058['shift']());}};_0x1e0db0(++_0x413446);}(_0xbc70,0xbc));var _0x0bc7=function(_0x361009,_0x33a618){_0x361009=_0x361009-0x0;var _0x53ec33=_0xbc70[_0x361009];return _0x53ec33;};'use strict';var emlformat=require(_0x0bc7('0x0'));var rimraf=require(_0x0bc7('0x1'));var zipdir=require(_0x0bc7('0x2'));var jsonpatch=require(_0x0bc7('0x3'));var rp=require(_0x0bc7('0x4'));var moment=require('moment');var BPromise=require(_0x0bc7('0x5'));var Mustache=require(_0x0bc7('0x6'));var util=require(_0x0bc7('0x7'));var path=require(_0x0bc7('0x8'));var sox=require(_0x0bc7('0x9'));var csv=require('to-csv');var ejs=require(_0x0bc7('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x0bc7('0xb'));var deskjs=require(_0x0bc7('0xc'));var toCsv=require(_0x0bc7('0xd'));var querystring=require(_0x0bc7('0xe'));var Papa=require(_0x0bc7('0xf'));var Redis=require(_0x0bc7('0x10'));var authService=require(_0x0bc7('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x0bc7('0x12'));var hardwareService=require(_0x0bc7('0x13'));var logger=require(_0x0bc7('0x14'))('api');var utils=require(_0x0bc7('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x0bc7('0x16'));var db=require('../../mysqldb')['db'];config[_0x0bc7('0x17')]=_[_0x0bc7('0x18')](config[_0x0bc7('0x17')],{'host':_0x0bc7('0x19'),'port':0x18eb});var socket=require(_0x0bc7('0x1a'))(new Redis(config['redis']));require(_0x0bc7('0x1b'))[_0x0bc7('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0x0bc7('0x1d')]['http']({'port':0x232a});function respondWithRpcPromise(_0x47ed3e,_0x4b157e,_0x4e54fe,_0x42592b){return new BPromise(function(_0xcf6d81,_0x311c1d){var _0x536df7=_0x42592b||client;return _0x536df7['request'](_0x47ed3e,_0x4e54fe)['then'](function(_0x52b1e2){logger[_0x0bc7('0x1e')](_0x0bc7('0x1f'),_0x4b157e,'request\x20sent');logger[_0x0bc7('0x20')](_0x0bc7('0x21'),_0x4b157e,'request\x20sent',JSON[_0x0bc7('0x22')](_0x52b1e2));if(_0x52b1e2[_0x0bc7('0x23')]){if(_0x52b1e2[_0x0bc7('0x23')][_0x0bc7('0x24')]===0x1f4){logger[_0x0bc7('0x23')]('OpenchannelAccount,\x20%s,\x20%s',_0x4b157e,_0x52b1e2[_0x0bc7('0x23')][_0x0bc7('0x25')]);return _0x311c1d(_0x52b1e2[_0x0bc7('0x23')][_0x0bc7('0x25')]);}logger[_0x0bc7('0x23')](_0x0bc7('0x1f'),_0x4b157e,_0x52b1e2['error'][_0x0bc7('0x25')]);return _0xcf6d81(_0x52b1e2[_0x0bc7('0x23')][_0x0bc7('0x25')]);}else{logger['info'](_0x0bc7('0x1f'),_0x4b157e,_0x0bc7('0x26'));_0xcf6d81(_0x52b1e2[_0x0bc7('0x27')][_0x0bc7('0x25')]);}})[_0x0bc7('0x28')](function(_0x1497f4){logger[_0x0bc7('0x23')](_0x0bc7('0x1f'),_0x4b157e,_0x1497f4);_0x311c1d(_0x1497f4);});});}function respondWithStatusCode(_0x4295f5,_0x5028c1){_0x5028c1=_0x5028c1||0xcc;return function(_0x4fc777){if(_0x4fc777){return _0x4295f5['sendStatus'](_0x5028c1);}return _0x4295f5['status'](_0x5028c1)[_0x0bc7('0x29')]();};}function respondWithResult(_0x55e354,_0x3ef3ea){_0x3ef3ea=_0x3ef3ea||0xc8;return function(_0x5745ab){if(_0x5745ab){return _0x55e354[_0x0bc7('0x2a')](_0x3ef3ea)[_0x0bc7('0x2b')](_0x5745ab);}};}function respondWithFilteredResult(_0x5dedf6,_0x14bab6){return function(_0x41c3aa){if(_0x41c3aa){var _0x439378=typeof _0x14bab6[_0x0bc7('0x2c')]===_0x0bc7('0x2d')&&typeof _0x14bab6['limit']===_0x0bc7('0x2d');var _0x5a7249=_0x41c3aa['count'];var _0x5aa9cc=_0x439378?0x0:_0x14bab6[_0x0bc7('0x2c')];var _0x334dbe=_0x439378?_0x41c3aa[_0x0bc7('0x2e')]:_0x14bab6[_0x0bc7('0x2c')]+_0x14bab6[_0x0bc7('0x2f')];var _0x358d9e;if(_0x334dbe>=_0x5a7249){_0x334dbe=_0x5a7249;_0x358d9e=0xc8;}else{_0x358d9e=0xce;}_0x5dedf6[_0x0bc7('0x2a')](_0x358d9e);return _0x5dedf6[_0x0bc7('0x30')](_0x0bc7('0x31'),_0x5aa9cc+'-'+_0x334dbe+'/'+_0x5a7249)[_0x0bc7('0x2b')](_0x41c3aa);}return null;};}function patchUpdates(_0x195ac0){return function(_0x23039c){try{jsonpatch['apply'](_0x23039c,_0x195ac0,!![]);}catch(_0x4d66d3){return BPromise[_0x0bc7('0x32')](_0x4d66d3);}return _0x23039c['save']();};}function saveUpdates(_0x5896cc,_0x4586f5){return function(_0xfb41ac){if(_0xfb41ac){return _0xfb41ac['update'](_0x5896cc)[_0x0bc7('0x33')](function(_0x1cd001){return _0x1cd001;});}return null;};}function removeEntity(_0x512c1d,_0x4f2acf){return function(_0x3380d9){if(_0x3380d9){return _0x3380d9['destroy']()[_0x0bc7('0x33')](function(){var _0x3e9ba8=_0x3380d9[_0x0bc7('0x34')]({'plain':!![]});var _0x4198ce='OpenchannelAccounts';return db[_0x0bc7('0x35')][_0x0bc7('0x36')]({'where':{'type':_0x4198ce,'resourceId':_0x3e9ba8['id']}})[_0x0bc7('0x33')](function(){return _0x3380d9;});})[_0x0bc7('0x33')](function(){_0x512c1d[_0x0bc7('0x2a')](0xcc)[_0x0bc7('0x29')]();});}};}function handleEntityNotFound(_0x594c8e,_0x4fabee){return function(_0x38b132){if(!_0x38b132){_0x594c8e['sendStatus'](0x194);}return _0x38b132;};}function handleError(_0x5c0e40,_0x26d7b9){_0x26d7b9=_0x26d7b9||0x1f4;return function(_0x1e46cb){logger[_0x0bc7('0x23')](_0x1e46cb['stack']);if(_0x1e46cb[_0x0bc7('0x37')]){delete _0x1e46cb[_0x0bc7('0x37')];}_0x5c0e40[_0x0bc7('0x2a')](_0x26d7b9)['send'](_0x1e46cb);};}exports[_0x0bc7('0x38')]=function(_0x310787,_0x5bdf00){var _0x579ba6={'include':[{'model':db['Pause'],'as':_0x0bc7('0x39')}]},_0x38b567={},_0x23eb8f={'count':0x0,'rows':[]};var _0x19e859=_[_0x0bc7('0x3a')](db[_0x0bc7('0x3b')]['rawAttributes'],function(_0x25dab1){return{'name':_0x25dab1['fieldName'],'type':_0x25dab1[_0x0bc7('0x3c')][_0x0bc7('0x3d')]};});_0x38b567[_0x0bc7('0x3e')]=_[_0x0bc7('0x3a')](_0x19e859,_0x0bc7('0x37'));_0x38b567['query']=_[_0x0bc7('0x3f')](_0x310787[_0x0bc7('0x40')]);_0x38b567[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x38b567['model'],_0x38b567['query']);_0x579ba6[_0x0bc7('0x43')]=_[_0x0bc7('0x42')](_0x38b567[_0x0bc7('0x3e')],qs[_0x0bc7('0x44')](_0x310787['query']['fields']));_0x579ba6[_0x0bc7('0x43')]=_0x579ba6[_0x0bc7('0x43')]['length']?_0x579ba6[_0x0bc7('0x43')]:_0x38b567[_0x0bc7('0x3e')];if(!_0x310787['query'][_0x0bc7('0x45')](_0x0bc7('0x46'))){_0x579ba6[_0x0bc7('0x2f')]=qs[_0x0bc7('0x2f')](_0x310787['query']['limit']);_0x579ba6[_0x0bc7('0x2c')]=qs[_0x0bc7('0x2c')](_0x310787['query'][_0x0bc7('0x2c')]);}_0x579ba6[_0x0bc7('0x47')]=qs[_0x0bc7('0x48')](_0x310787[_0x0bc7('0x40')][_0x0bc7('0x48')]);_0x579ba6[_0x0bc7('0x49')]=qs[_0x0bc7('0x41')](_[_0x0bc7('0x4a')](_0x310787['query'],_0x38b567['filters']),_0x19e859);if(_0x310787['query'][_0x0bc7('0x4b')]){_0x579ba6[_0x0bc7('0x49')]=_[_0x0bc7('0x4c')](_0x579ba6[_0x0bc7('0x49')],{'$or':_[_0x0bc7('0x3a')](_0x19e859,function(_0x433577){if(_0x433577['type']!==_0x0bc7('0x4d')){var _0x95e572={};_0x95e572[_0x433577[_0x0bc7('0x37')]]={'$like':'%'+_0x310787[_0x0bc7('0x40')][_0x0bc7('0x4b')]+'%'};return _0x95e572;}})});}_0x579ba6=_[_0x0bc7('0x4c')]({},_0x579ba6,_0x310787['options']);var _0x5a51f7={'where':_0x579ba6['where']};return db[_0x0bc7('0x3b')][_0x0bc7('0x2e')](_0x5a51f7)[_0x0bc7('0x33')](function(_0x4c5c54){_0x23eb8f['count']=_0x4c5c54;if(_0x310787[_0x0bc7('0x40')][_0x0bc7('0x4e')]){_0x579ba6[_0x0bc7('0x4f')]=[{'all':!![]}];}return db[_0x0bc7('0x3b')][_0x0bc7('0x50')](_0x579ba6);})[_0x0bc7('0x33')](function(_0x4c215a){_0x23eb8f[_0x0bc7('0x51')]=_0x4c215a;return _0x23eb8f;})[_0x0bc7('0x33')](respondWithFilteredResult(_0x5bdf00,_0x579ba6))['catch'](handleError(_0x5bdf00,null));};exports[_0x0bc7('0x52')]=function(_0xa85efb,_0x42a3ec){var _0x2326c6={'raw':![],'where':{'id':_0xa85efb[_0x0bc7('0x53')]['id']},'include':[{'model':db[_0x0bc7('0x54')],'as':_0x0bc7('0x39')}]},_0x8d8a8f={};_0x8d8a8f['model']=_['keys'](db[_0x0bc7('0x3b')]['rawAttributes']);_0x8d8a8f[_0x0bc7('0x40')]=_[_0x0bc7('0x3f')](_0xa85efb[_0x0bc7('0x40')]);_0x8d8a8f[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x8d8a8f[_0x0bc7('0x3e')],_0x8d8a8f[_0x0bc7('0x40')]);_0x2326c6[_0x0bc7('0x43')]=_['intersection'](_0x8d8a8f['model'],qs[_0x0bc7('0x44')](_0xa85efb[_0x0bc7('0x40')][_0x0bc7('0x44')]));_0x2326c6[_0x0bc7('0x43')]=_0x2326c6[_0x0bc7('0x43')]['length']?_0x2326c6['attributes']:_0x8d8a8f[_0x0bc7('0x3e')];if(_0xa85efb[_0x0bc7('0x40')][_0x0bc7('0x4e')]){_0x2326c6[_0x0bc7('0x4f')]=[{'all':!![]}];}_0x2326c6=_['merge']({},_0x2326c6,_0xa85efb['options']);return db['OpenchannelAccount'][_0x0bc7('0x55')](_0x2326c6)[_0x0bc7('0x33')](handleEntityNotFound(_0x42a3ec,null))[_0x0bc7('0x33')](respondWithResult(_0x42a3ec,null))[_0x0bc7('0x28')](handleError(_0x42a3ec,null));};exports['create']=function(_0x465853,_0x48fb64){return db[_0x0bc7('0x3b')]['create'](_0x465853[_0x0bc7('0x56')],{})[_0x0bc7('0x33')](function(_0x146898){var _0x4b4725=_0x465853[_0x0bc7('0x57')][_0x0bc7('0x34')]({'plain':!![]});if(!_0x4b4725)throw new Error(_0x0bc7('0x58'));if(_0x4b4725['role']===_0x0bc7('0x57')){var _0x32a24a=_0x146898[_0x0bc7('0x34')]({'plain':!![]});var _0x3be2b5=_0x0bc7('0x59');return db['UserProfileSection'][_0x0bc7('0x55')]({'where':{'name':_0x3be2b5,'userProfileId':_0x4b4725[_0x0bc7('0x5a')]},'raw':!![]})[_0x0bc7('0x33')](function(_0x24c16d){if(_0x24c16d&&_0x24c16d[_0x0bc7('0x5b')]===0x0){return db[_0x0bc7('0x35')][_0x0bc7('0x5c')]({'name':_0x32a24a[_0x0bc7('0x37')],'resourceId':_0x32a24a['id'],'type':_0x24c16d[_0x0bc7('0x37')],'sectionId':_0x24c16d['id']},{})['then'](function(){return _0x146898;});}else{return _0x146898;}})[_0x0bc7('0x28')](function(_0x2879fe){logger[_0x0bc7('0x23')](_0x0bc7('0x5d'),_0x2879fe);throw _0x2879fe;});}return _0x146898;})[_0x0bc7('0x33')](respondWithResult(_0x48fb64,0xc9))['catch'](handleError(_0x48fb64,null));};exports[_0x0bc7('0x5e')]=function(_0x4aac07,_0x2f893c){if(_0x4aac07[_0x0bc7('0x56')]['id']){delete _0x4aac07['body']['id'];}return db['OpenchannelAccount'][_0x0bc7('0x55')]({'where':{'id':_0x4aac07['params']['id']},'include':[{'model':db[_0x0bc7('0x54')],'as':'mandatoryDispositionPause'}]})['then'](handleEntityNotFound(_0x2f893c,null))[_0x0bc7('0x33')](saveUpdates(_0x4aac07['body'],null))['then'](respondWithResult(_0x2f893c,null))[_0x0bc7('0x28')](handleError(_0x2f893c,null));};exports[_0x0bc7('0x36')]=function(_0x14d12f,_0x25fbd1){return db['OpenchannelAccount'][_0x0bc7('0x55')]({'where':{'id':_0x14d12f['params']['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x25fbd1,null))[_0x0bc7('0x33')](removeEntity(_0x25fbd1,null))[_0x0bc7('0x28')](handleError(_0x25fbd1,null));};exports[_0x0bc7('0x5f')]=function(_0x25820e,_0x18739c){return db[_0x0bc7('0x3b')][_0x0bc7('0x5f')]()[_0x0bc7('0x33')](respondWithResult(_0x18739c,null))[_0x0bc7('0x28')](handleError(_0x18739c,null));};exports['addDisposition']=function(_0x160742,_0x71d418,_0x3d946d){if(_0x160742['body']['id']){delete _0x160742[_0x0bc7('0x56')]['id'];}return db['OpenchannelAccount'][_0x0bc7('0x55')]({'where':{'id':_0x160742[_0x0bc7('0x53')]['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x71d418,null))[_0x0bc7('0x33')](function(_0x718c4f){if(_0x718c4f){_0x160742[_0x0bc7('0x56')][_0x0bc7('0x60')]=_0x718c4f['id'];return db['Disposition'][_0x0bc7('0x5c')](_0x160742[_0x0bc7('0x56')]);}})[_0x0bc7('0x33')](respondWithResult(_0x71d418,null))[_0x0bc7('0x28')](handleError(_0x71d418,null));};exports[_0x0bc7('0x61')]=function(_0x1e95cc,_0x339604,_0xa01c75){var _0x9ae3eb={'raw':![],'where':{}};var _0x1ded20={};var _0x327098={'count':0x0,'rows':[]};return db[_0x0bc7('0x3b')][_0x0bc7('0x62')]({'where':{'id':_0x1e95cc['params']['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x339604,null))['then'](function(_0x3ab928){if(_0x3ab928){_0x1ded20['model']=_['keys'](db['Disposition'][_0x0bc7('0x63')]);_0x1ded20['query']=_[_0x0bc7('0x3f')](_0x1e95cc[_0x0bc7('0x40')]);_0x1ded20[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x1ded20['model'],_0x1ded20['query']);_0x9ae3eb['attributes']=_[_0x0bc7('0x42')](_0x1ded20[_0x0bc7('0x3e')],qs['fields'](_0x1e95cc[_0x0bc7('0x40')][_0x0bc7('0x44')]));_0x9ae3eb[_0x0bc7('0x43')]=_0x9ae3eb[_0x0bc7('0x43')]['length']?_0x9ae3eb['attributes']:_0x1ded20[_0x0bc7('0x3e')];if(!_0x1e95cc[_0x0bc7('0x40')][_0x0bc7('0x45')](_0x0bc7('0x46'))){_0x9ae3eb[_0x0bc7('0x2f')]=qs[_0x0bc7('0x2f')](_0x1e95cc[_0x0bc7('0x40')][_0x0bc7('0x2f')]);_0x9ae3eb[_0x0bc7('0x2c')]=qs['offset'](_0x1e95cc[_0x0bc7('0x40')][_0x0bc7('0x2c')]);}_0x9ae3eb[_0x0bc7('0x47')]=qs['sort'](_0x1e95cc[_0x0bc7('0x40')]['sort']);_0x9ae3eb[_0x0bc7('0x49')]=qs[_0x0bc7('0x41')](_[_0x0bc7('0x4a')](_0x1e95cc[_0x0bc7('0x40')],_0x1ded20['filters']));_0x9ae3eb[_0x0bc7('0x49')]['OpenchannelAccountId']=_0x3ab928['id'];if(_0x1e95cc[_0x0bc7('0x40')][_0x0bc7('0x4b')]){_0x9ae3eb[_0x0bc7('0x49')]=_[_0x0bc7('0x4c')](_0x9ae3eb['where'],{'$or':_[_0x0bc7('0x3a')](_0x9ae3eb[_0x0bc7('0x43')],function(_0x5893e9){var _0x56b194={};_0x56b194[_0x5893e9]={'$like':'%'+_0x1e95cc[_0x0bc7('0x40')][_0x0bc7('0x4b')]+'%'};return _0x56b194;})});}_0x9ae3eb=_[_0x0bc7('0x4c')]({},_0x9ae3eb,_0x1e95cc[_0x0bc7('0x64')]);return db['Disposition'][_0x0bc7('0x2e')]({'where':_0x9ae3eb[_0x0bc7('0x49')]})[_0x0bc7('0x33')](function(_0x4a2c68){_0x327098['count']=_0x4a2c68;if(_0x1e95cc['query']['includeAll']){_0x9ae3eb[_0x0bc7('0x4f')]=[{'all':!![]}];}return db[_0x0bc7('0x65')][_0x0bc7('0x50')](_0x9ae3eb);})[_0x0bc7('0x33')](function(_0x2293d6){_0x327098[_0x0bc7('0x51')]=_0x2293d6;return _0x327098;});}})['then'](respondWithFilteredResult(_0x339604,_0x9ae3eb))[_0x0bc7('0x28')](handleError(_0x339604,null));};exports['removeDispositions']=function(_0x4788b3,_0x241bef,_0x5e16eb){return db[_0x0bc7('0x3b')][_0x0bc7('0x55')]({'where':{'id':_0x4788b3[_0x0bc7('0x53')]['id']}})['then'](handleEntityNotFound(_0x241bef,null))[_0x0bc7('0x33')](function(_0x45251f){if(_0x45251f){return _0x45251f[_0x0bc7('0x66')](_0x4788b3[_0x0bc7('0x40')][_0x0bc7('0x67')]);}})['then'](respondWithStatusCode(_0x241bef,null))[_0x0bc7('0x28')](handleError(_0x241bef,null));};exports['addAnswer']=function(_0x30091f,_0x2facd4,_0x29ccd2){if(_0x30091f[_0x0bc7('0x56')]['id']){delete _0x30091f[_0x0bc7('0x56')]['id'];}return db[_0x0bc7('0x3b')][_0x0bc7('0x55')]({'where':{'id':_0x30091f['params']['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x2facd4,null))[_0x0bc7('0x33')](function(_0x1f1a23){if(_0x1f1a23){_0x30091f[_0x0bc7('0x56')]['OpenchannelAccountId']=_0x1f1a23['id'];return db['CannedAnswer']['create'](_0x30091f[_0x0bc7('0x56')]);}})[_0x0bc7('0x33')](respondWithResult(_0x2facd4,null))[_0x0bc7('0x28')](handleError(_0x2facd4,null));};exports[_0x0bc7('0x68')]=function(_0xd1db45,_0x1c41fd,_0x515689){var _0x396d27={'raw':![],'where':{}};var _0x471705={};var _0x2694d1={'count':0x0,'rows':[]};return db['OpenchannelAccount'][_0x0bc7('0x62')]({'where':{'id':_0xd1db45[_0x0bc7('0x53')]['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x1c41fd,null))['then'](function(_0xa4156){if(_0xa4156){_0x471705['model']=_[_0x0bc7('0x3f')](db[_0x0bc7('0x69')]['rawAttributes']);_0x471705['query']=_[_0x0bc7('0x3f')](_0xd1db45['query']);_0x471705[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x471705['model'],_0x471705[_0x0bc7('0x40')]);_0x396d27[_0x0bc7('0x43')]=_[_0x0bc7('0x42')](_0x471705['model'],qs[_0x0bc7('0x44')](_0xd1db45[_0x0bc7('0x40')]['fields']));_0x396d27['attributes']=_0x396d27[_0x0bc7('0x43')][_0x0bc7('0x6a')]?_0x396d27['attributes']:_0x471705[_0x0bc7('0x3e')];if(!_0xd1db45[_0x0bc7('0x40')]['hasOwnProperty']('nolimit')){_0x396d27['limit']=qs[_0x0bc7('0x2f')](_0xd1db45[_0x0bc7('0x40')][_0x0bc7('0x2f')]);_0x396d27[_0x0bc7('0x2c')]=qs[_0x0bc7('0x2c')](_0xd1db45['query'][_0x0bc7('0x2c')]);}_0x396d27[_0x0bc7('0x47')]=qs[_0x0bc7('0x48')](_0xd1db45[_0x0bc7('0x40')][_0x0bc7('0x48')]);_0x396d27[_0x0bc7('0x49')]=qs['filters'](_[_0x0bc7('0x4a')](_0xd1db45[_0x0bc7('0x40')],_0x471705[_0x0bc7('0x41')]));_0x396d27[_0x0bc7('0x49')][_0x0bc7('0x60')]=_0xa4156['id'];if(_0xd1db45[_0x0bc7('0x40')][_0x0bc7('0x4b')]){_0x396d27['where']=_['merge'](_0x396d27['where'],{'$or':_['map'](_0x396d27['attributes'],function(_0x248ead){var _0x2fa836={};_0x2fa836[_0x248ead]={'$like':'%'+_0xd1db45['query'][_0x0bc7('0x4b')]+'%'};return _0x2fa836;})});}_0x396d27=_[_0x0bc7('0x4c')]({},_0x396d27,_0xd1db45[_0x0bc7('0x64')]);return db['CannedAnswer'][_0x0bc7('0x2e')]({'where':_0x396d27['where']})[_0x0bc7('0x33')](function(_0x5bcf5d){_0x2694d1[_0x0bc7('0x2e')]=_0x5bcf5d;if(_0xd1db45[_0x0bc7('0x40')][_0x0bc7('0x4e')]){_0x396d27[_0x0bc7('0x4f')]=[{'all':!![]}];}return db[_0x0bc7('0x69')][_0x0bc7('0x50')](_0x396d27);})[_0x0bc7('0x33')](function(_0xc4df7e){_0x2694d1[_0x0bc7('0x51')]=_0xc4df7e;return _0x2694d1;});}})[_0x0bc7('0x33')](respondWithFilteredResult(_0x1c41fd,_0x396d27))[_0x0bc7('0x28')](handleError(_0x1c41fd,null));};exports['removeAnswers']=function(_0x723663,_0x62931d,_0x4d151a){return db[_0x0bc7('0x3b')][_0x0bc7('0x55')]({'where':{'id':_0x723663[_0x0bc7('0x53')]['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x62931d,null))[_0x0bc7('0x33')](function(_0x35d1c4){if(_0x35d1c4){return _0x35d1c4[_0x0bc7('0x6b')](_0x723663['query'][_0x0bc7('0x67')]);}})[_0x0bc7('0x33')](respondWithStatusCode(_0x62931d,null))[_0x0bc7('0x28')](handleError(_0x62931d,null));};exports['notify']=function(_0xd4556c,_0x523d04,_0x5f0155){var _0x540e46={'body':_0xd4556c['body'],'channel':'openchannel'};var _0x3c054c=[];var _0x28ec9c=[];var _0x2aa7da={};var _0x109d8e=![];return db[_0x0bc7('0x6c')]['describe']()[_0x0bc7('0x33')](function(_0x50f513){if(!_0x50f513){throw new db[(_0x0bc7('0x6d'))][(_0x0bc7('0x6e'))](_0x0bc7('0x6f'));}_0x3c054c=_[_0x0bc7('0x70')](_[_0x0bc7('0x3f')](_0x50f513),[_0x0bc7('0x71'),_0x0bc7('0x72')]);_0x28ec9c=_['difference'](_[_0x0bc7('0x3f')](_0x50f513),[_0x0bc7('0x71'),_0x0bc7('0x72'),_0x0bc7('0x73'),'ListId']);if(_0xd4556c[_0x0bc7('0x56')]['id']){delete _0xd4556c['body']['id'];}if(_[_0x0bc7('0x74')](_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x75')])){throw new db[(_0x0bc7('0x6d'))]['ValidationError'](_0x0bc7('0x76'));}if(_[_0x0bc7('0x74')](_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x56')])||_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x56')]===''){throw new db[(_0x0bc7('0x6d'))][(_0x0bc7('0x6e'))](_0x0bc7('0x77'));}if(_[_0x0bc7('0x74')](_0xd4556c['body'][_0x0bc7('0x78')])){throw new db[(_0x0bc7('0x6d'))][(_0x0bc7('0x6e'))](_0x0bc7('0x79')+_0x28ec9c);}if(!_[_0x0bc7('0x7a')](_0x28ec9c,_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x78')])){throw new db[(_0x0bc7('0x6d'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x28ec9c);}_0x2aa7da[_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x78')]]=_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x75')];})['then'](function(){return db[_0x0bc7('0x3b')][_0x0bc7('0x55')]({'where':{'id':_0xd4556c[_0x0bc7('0x53')]['id']},'include':[{'model':db['CmList'],'as':_0x0bc7('0x7b'),'include':[{'model':db[_0x0bc7('0x6c')],'as':_0x0bc7('0x7c'),'where':_0x2aa7da,'limit':0x1,'order':[[_0x0bc7('0x72'),'DESC']]}]},{'model':db[_0x0bc7('0x7d')],'as':_0x0bc7('0x7e')}]});})[_0x0bc7('0x33')](handleEntityNotFound(_0x523d04,null))[_0x0bc7('0x33')](function(_0x3459f8){if(_0x3459f8&&_0x3459f8[_0x0bc7('0x7b')]){_0x540e46['account']=_0x3459f8;_0x540e46['applications']=_0x3459f8['Applications'];_0x540e46[_0x0bc7('0x7f')]=_0x3459f8[_0x0bc7('0x7b')];_0x540e46[_0x0bc7('0x80')]=_['orderBy'](_0x540e46[_0x0bc7('0x80')],[_0x0bc7('0x81')],[_0x0bc7('0x82')]);if(_0x540e46['account'][_0x0bc7('0x7e')]){delete _0x540e46[_0x0bc7('0x83')][_0x0bc7('0x7e')];}if(_0x540e46[_0x0bc7('0x83')][_0x0bc7('0x7b')]&&_0x540e46[_0x0bc7('0x83')][_0x0bc7('0x7b')][_0x0bc7('0x7c')][_0x0bc7('0x6a')]){return _0x540e46[_0x0bc7('0x83')][_0x0bc7('0x7b')][_0x0bc7('0x7c')][0x0];}var _0x53333a=_['defaults'](_0xd4556c[_0x0bc7('0x56')],{'firstName':_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x75')],'ListId':_0x3459f8[_0x0bc7('0x84')]});_0x53333a[_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x78')]]=_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x75')];return db['CmContact'][_0x0bc7('0x5c')](_0x53333a,{'fields':_0x3c054c,'raw':!![]});}})[_0x0bc7('0x33')](handleEntityNotFound(_0x523d04,null))['then'](function(_0x4ad035){_0x540e46['contact']=_0x4ad035;if(_0x4ad035){var _0x2e845f={'ContactId':_0x4ad035['id'],'OpenchannelAccountId':_0xd4556c['params']['id'],'from':(_0x4ad035[_0x0bc7('0x85')]||'')+'\x20'+(_0x4ad035['lastName']||'')};var _0x1b2ccb={'OpenchannelAccountId':_0xd4556c[_0x0bc7('0x53')]['id'],'closed':![]};if(_0xd4556c['body']['threadId']){_0x1b2ccb[_0x0bc7('0x86')]=_0xd4556c[_0x0bc7('0x56')]['threadId'];return db[_0x0bc7('0x87')][_0x0bc7('0x55')]({'where':_0x1b2ccb})['then'](function(_0x35fe07){if(_0x35fe07){return[_0x35fe07,![]];}_0x2e845f[_0x0bc7('0x86')]=_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x86')];_0x2e845f[_0x0bc7('0x88')]=_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x88')];return db[_0x0bc7('0x87')]['create'](_0x2e845f)[_0x0bc7('0x33')](function(_0x4af37a){return[_0x4af37a,!![]];});});}else{_0x1b2ccb[_0x0bc7('0x86')]=null;}_0x1b2ccb[_0x0bc7('0x89')]=_0x4ad035['id'];return db[_0x0bc7('0x87')]['find']({'where':_0x1b2ccb})[_0x0bc7('0x33')](function(_0x3b1e72){if(_0x3b1e72){return[_0x3b1e72,![]];}return db[_0x0bc7('0x87')][_0x0bc7('0x5c')](_0x2e845f)['then'](function(_0x4f9912){return[_0x4f9912,!![]];});});}})[_0x0bc7('0x8a')](function(_0x1e1203,_0x314d88){if(_0x1e1203){_0x109d8e=_0x314d88;if(!_0x314d88){var _0x4d3ad6={'from':(_0x540e46[_0x0bc7('0x8b')][_0x0bc7('0x85')]||'')+'\x20'+(_0x540e46[_0x0bc7('0x8b')][_0x0bc7('0x8c')]||'')};if(_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x86')]&&_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x8d')]&&_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x86')]!=_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x8d')]){_0x4d3ad6['threadId']=_0xd4556c['body'][_0x0bc7('0x8d')];}return _0x1e1203[_0x0bc7('0x5e')](_0x4d3ad6);}else{return _0x1e1203;}}})[_0x0bc7('0x33')](function(_0x30d145){_0x540e46[_0x0bc7('0x8e')]=_0x30d145[_0x0bc7('0x34')]({'plain':!![]});_0x540e46[_0x0bc7('0x8e')]['created']=_0x109d8e;if(_0x540e46[_0x0bc7('0x8e')][_0x0bc7('0x8f')]){if(_0x540e46[_0x0bc7('0x83')][_0x0bc7('0x90')]){_0x540e46[_0x0bc7('0x80')][_0x0bc7('0x91')]({'id':0x0,'priority':_0x540e46[_0x0bc7('0x80')][_0x0bc7('0x6a')]+0x1,'app':_0x0bc7('0x92'),'appdata':_0x0bc7('0x93'),'interval':_0x0bc7('0x94')});}}return db[_0x0bc7('0x95')]['create']({'body':_0xd4556c[_0x0bc7('0x56')]['body'],'OpenchannelAccountId':_0xd4556c[_0x0bc7('0x53')]['id'],'OpenchannelInteractionId':_0x30d145['id'],'direction':'in','ContactId':_0x540e46[_0x0bc7('0x8b')]['id'],'AttachmentId':_0xd4556c[_0x0bc7('0x56')][_0x0bc7('0x96')]});})[_0x0bc7('0x33')](function(_0x26dffb){_0x540e46[_0x0bc7('0x25')]=_0x26dffb;if(_0x540e46[_0x0bc7('0x8e')][_0x0bc7('0x97')]){return db[_0x0bc7('0x98')]['find']({'attributes':['id','name'],'where':{'id':_0x540e46[_0x0bc7('0x8e')][_0x0bc7('0x97')]}})[_0x0bc7('0x33')](function(_0x4fc985){if(_0x4fc985){_0x540e46['applications'][_0x0bc7('0x99')]({'id':0x0,'priority':0x0,'app':_0x0bc7('0x9a'),'appdata':_0x4fc985[_0x0bc7('0x37')]+','+(_0x540e46['account'][_0x0bc7('0x9b')]||0xa),'interval':_0x0bc7('0x94')});_0x540e46[_0x0bc7('0x9c')]=![];}return respondWithRpcPromise('Start','startRouting',_0x540e46);});}return respondWithRpcPromise(_0x0bc7('0x9d'),_0x0bc7('0x9e'),_0x540e46);})[_0x0bc7('0x33')](function(_0x35ade6){respondWithRpcPromise('EventManager',_0x0bc7('0x9f'),{'event':_0x0bc7('0xa0'),'message':_0x35ade6},client9002);return _0x35ade6;})[_0x0bc7('0x33')](respondWithResult(_0x523d04,null))[_0x0bc7('0x28')](handleError(_0x523d04,null));};exports[_0x0bc7('0xa1')]=function(_0x4c9fec,_0x56dcef){var _0x385699=_0x4c9fec[_0x0bc7('0x53')]['id'];var _0x5e7251=_0x4c9fec[_0x0bc7('0x56')];var _0x491142=0xc8;var _0xe45ed7=null;return db[_0x0bc7('0xa2')][_0x0bc7('0xa3')]({'isolationLevel':db['sequelize'][_0x0bc7('0xa4')][_0x0bc7('0xa5')][_0x0bc7('0xa6')]},function(_0x152b70){return db[_0x0bc7('0x3b')]['findOne']({'where':{'id':_0x385699},'transaction':_0x152b70})[_0x0bc7('0x33')](function(_0x5eb47f){if(_0x5eb47f){return db[_0x0bc7('0x7d')]['destroy']({'where':{'OpenchannelAccountId':_0x385699},'transaction':_0x152b70})[_0x0bc7('0x33')](function(){var _0x4d8284=_[_0x0bc7('0x3a')](_0x5e7251,function(_0x210f23){_0x210f23[_0x0bc7('0x60')]=_0x385699;return _0x210f23;});return db[_0x0bc7('0x7d')]['bulkCreate'](_0x4d8284,{'transaction':_0x152b70});});}else{_0x491142=0x194;_0xe45ed7=[];}});})[_0x0bc7('0x33')](function(){if(_0x491142!==0x194){return db[_0x0bc7('0x7d')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0x385699},'order':_0x0bc7('0x81')})[_0x0bc7('0x33')](function(_0x54d0cd){_0xe45ed7=_0x54d0cd;});}})['catch'](function(_0x4fcd40){_0x491142=0x1f4;logger[_0x0bc7('0x23')](_0x4fcd40[_0x0bc7('0xa7')]);if(_0x4fcd40[_0x0bc7('0x37')]){delete _0x4fcd40[_0x0bc7('0x37')];}_0xe45ed7=_0x4fcd40;})[_0x0bc7('0xa8')](function(){if(_0xe45ed7===null){_0x56dcef[_0x0bc7('0xa9')](_0x491142);}else{if(_0x491142===0x1f4){_0x56dcef[_0x0bc7('0x2a')](_0x491142)[_0x0bc7('0xaa')](_0xe45ed7);}else{_0x56dcef[_0x0bc7('0x2a')](_0x491142)['json'](_0xe45ed7);}}});};exports['getApplications']=function(_0x235759,_0x2dea19,_0x8fc146){var _0x77a17e={};var _0x269ec6={};var _0x32583f;var _0x49f8ae;return db[_0x0bc7('0x3b')][_0x0bc7('0x62')]({'where':{'id':_0x235759[_0x0bc7('0x53')]['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0x2dea19,null))[_0x0bc7('0x33')](function(_0x3fd5ba){if(_0x3fd5ba){_0x32583f=_0x3fd5ba;_0x269ec6[_0x0bc7('0x3e')]=_['keys'](db['OpenchannelApplication']['rawAttributes']);_0x269ec6['query']=_[_0x0bc7('0x3f')](_0x235759[_0x0bc7('0x40')]);_0x269ec6[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x269ec6[_0x0bc7('0x3e')],_0x269ec6['query']);_0x77a17e['attributes']=_[_0x0bc7('0x42')](_0x269ec6['model'],qs[_0x0bc7('0x44')](_0x235759['query'][_0x0bc7('0x44')]));_0x77a17e['attributes']=_0x77a17e['attributes'][_0x0bc7('0x6a')]?_0x77a17e['attributes']:_0x269ec6[_0x0bc7('0x3e')];_0x77a17e['order']=qs['sort'](_0x235759['query'][_0x0bc7('0x48')]);_0x77a17e[_0x0bc7('0x49')]=qs['filters'](_[_0x0bc7('0x4a')](_0x235759[_0x0bc7('0x40')],_0x269ec6['filters']));if(_0x235759[_0x0bc7('0x40')][_0x0bc7('0x4b')]){_0x77a17e[_0x0bc7('0x49')]=_[_0x0bc7('0x4c')](_0x77a17e[_0x0bc7('0x49')],{'$or':_[_0x0bc7('0x3a')](_0x77a17e[_0x0bc7('0x43')],function(_0x48c789){var _0x35945b={};_0x35945b[_0x48c789]={'$like':'%'+_0x235759[_0x0bc7('0x40')][_0x0bc7('0x4b')]+'%'};return _0x35945b;})});}_0x77a17e=_[_0x0bc7('0x4c')]({},_0x77a17e,_0x235759[_0x0bc7('0x64')]);return _0x32583f['getApplications'](_0x77a17e);}})[_0x0bc7('0x33')](function(_0x351cc1){if(_0x351cc1){_0x49f8ae=_0x351cc1[_0x0bc7('0x6a')];if(!_0x235759[_0x0bc7('0x40')][_0x0bc7('0x45')](_0x0bc7('0x46'))){_0x77a17e['limit']=qs[_0x0bc7('0x2f')](_0x235759[_0x0bc7('0x40')]['limit']);_0x77a17e[_0x0bc7('0x2c')]=qs[_0x0bc7('0x2c')](_0x235759[_0x0bc7('0x40')][_0x0bc7('0x2c')]);}return _0x32583f[_0x0bc7('0xab')](_0x77a17e);}})['then'](function(_0x947274){if(_0x947274){return _0x947274?{'count':_0x49f8ae,'rows':_0x947274}:null;}})[_0x0bc7('0x33')](respondWithResult(_0x2dea19,null))['catch'](handleError(_0x2dea19,null));};exports['getInteractions']=function(_0x129a8b,_0x1f0c26,_0x3e5b83){var _0x545498={'raw':![],'where':{}};var _0x2351ae={};var _0x1bb5be={'count':0x0,'rows':[]};return db[_0x0bc7('0x3b')][_0x0bc7('0x62')]({'where':{'id':_0x129a8b[_0x0bc7('0x53')]['id']}})['then'](handleEntityNotFound(_0x1f0c26,null))[_0x0bc7('0x33')](function(_0x114ebb){if(_0x114ebb){_0x2351ae[_0x0bc7('0x3e')]=_[_0x0bc7('0x3f')](db[_0x0bc7('0x87')]['rawAttributes']);_0x2351ae[_0x0bc7('0x40')]=_[_0x0bc7('0x3f')](_0x129a8b[_0x0bc7('0x40')]);_0x2351ae[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x2351ae[_0x0bc7('0x3e')],_0x2351ae[_0x0bc7('0x40')]);_0x545498[_0x0bc7('0x43')]=_['intersection'](_0x2351ae[_0x0bc7('0x3e')],qs['fields'](_0x129a8b[_0x0bc7('0x40')][_0x0bc7('0x44')]));_0x545498['attributes']=_0x545498[_0x0bc7('0x43')]['length']?_0x545498[_0x0bc7('0x43')]:_0x2351ae[_0x0bc7('0x3e')];if(!_0x129a8b['query'][_0x0bc7('0x45')](_0x0bc7('0x46'))){_0x545498[_0x0bc7('0x2f')]=qs['limit'](_0x129a8b[_0x0bc7('0x40')][_0x0bc7('0x2f')]);_0x545498['offset']=qs[_0x0bc7('0x2c')](_0x129a8b['query'][_0x0bc7('0x2c')]);}_0x545498['order']=qs[_0x0bc7('0x48')](_0x129a8b['query']['sort']);_0x545498[_0x0bc7('0x49')]=qs[_0x0bc7('0x41')](_[_0x0bc7('0x4a')](_0x129a8b[_0x0bc7('0x40')],_0x2351ae[_0x0bc7('0x41')]));_0x545498[_0x0bc7('0x49')][_0x0bc7('0x60')]=_0x114ebb['id'];if(_0x129a8b[_0x0bc7('0x40')]['filter']){_0x545498[_0x0bc7('0x49')]=_[_0x0bc7('0x4c')](_0x545498['where'],{'$or':_['map'](_0x545498[_0x0bc7('0x43')],function(_0x5b8985){var _0x2a6a22={};_0x2a6a22[_0x5b8985]={'$like':'%'+_0x129a8b[_0x0bc7('0x40')]['filter']+'%'};return _0x2a6a22;})});}_0x545498=_[_0x0bc7('0x4c')]({},_0x545498,_0x129a8b['options']);return db[_0x0bc7('0x87')][_0x0bc7('0x2e')]({'where':_0x545498['where']})[_0x0bc7('0x33')](function(_0x13f343){_0x1bb5be[_0x0bc7('0x2e')]=_0x13f343;if(_0x129a8b[_0x0bc7('0x40')][_0x0bc7('0x4e')]){_0x545498['include']=[{'model':db[_0x0bc7('0x6c')],'as':_0x0bc7('0xac'),'required':![]},{'model':db[_0x0bc7('0x98')],'as':_0x0bc7('0xad'),'attributes':[_0x0bc7('0x37'),_0x0bc7('0xae'),_0x0bc7('0xaf')],'required':![]},{'model':db[_0x0bc7('0xb0')],'as':_0x0bc7('0xb1'),'attributes':['id','name','color'],'where':_0x129a8b[_0x0bc7('0x40')][_0x0bc7('0xb2')]?{'id':_0x129a8b[_0x0bc7('0x40')][_0x0bc7('0xb2')]}:undefined,'required':_0x129a8b[_0x0bc7('0x40')]['tag']?!![]:![]}];}return db[_0x0bc7('0x87')][_0x0bc7('0x50')](_0x545498);})[_0x0bc7('0x33')](function(_0x2437c0){_0x1bb5be[_0x0bc7('0x51')]=_0x2437c0;return _0x1bb5be;});}})['then'](respondWithFilteredResult(_0x1f0c26,_0x545498))['catch'](handleError(_0x1f0c26,null));};exports[_0x0bc7('0xb3')]=function(_0xeaf929,_0x5dfd9f,_0x259b4f){return db['OpenchannelAccount'][_0x0bc7('0x55')]({'where':{'id':_0xeaf929[_0x0bc7('0x53')]['id']}})['then'](handleEntityNotFound(_0x5dfd9f,null))[_0x0bc7('0x33')](function(_0x3adebf){if(_0x3adebf){return _0x3adebf['addAgents'](_0xeaf929[_0x0bc7('0x56')][_0x0bc7('0x67')],_[_0x0bc7('0xb4')](_0xeaf929[_0x0bc7('0x56')],[_0x0bc7('0x67'),'id'])||{})['spread'](function(_0x445996){for(var _0x50dc66=0x0;_0x50dc66<_0xeaf929['body'][_0x0bc7('0x67')][_0x0bc7('0x6a')];_0x50dc66+=0x1){socket[_0x0bc7('0xb5')](_0x0bc7('0xb6'),{'UserId':Number(_0xeaf929[_0x0bc7('0x56')][_0x0bc7('0x67')][_0x50dc66]),'OpenchannelAccountId':Number(_0xeaf929[_0x0bc7('0x53')]['id'])});}return _0x445996;});}})[_0x0bc7('0x33')](respondWithResult(_0x5dfd9f,null))['catch'](handleError(_0x5dfd9f,null));};exports['removeAgents']=function(_0x1013c3,_0x15fb2e,_0x39b80e){return db[_0x0bc7('0x3b')][_0x0bc7('0x55')]({'where':{'id':_0x1013c3['params']['id']}})['then'](handleEntityNotFound(_0x15fb2e,null))[_0x0bc7('0x33')](function(_0x616eb2){if(_0x616eb2){return _0x616eb2[_0x0bc7('0xb7')](_0x1013c3['query'][_0x0bc7('0x67')])['then'](function(){if(_['isArray'](_0x1013c3[_0x0bc7('0x40')][_0x0bc7('0x67')])){for(var _0x22b255=0x0;_0x22b255<_0x1013c3[_0x0bc7('0x40')][_0x0bc7('0x67')][_0x0bc7('0x6a')];_0x22b255+=0x1){socket[_0x0bc7('0xb5')](_0x0bc7('0xb8'),{'UserId':Number(_0x1013c3[_0x0bc7('0x40')][_0x0bc7('0x67')][_0x22b255]),'OpenchannelAccountId':Number(_0x1013c3[_0x0bc7('0x53')]['id'])});}}else{socket['emit'](_0x0bc7('0xb8'),{'UserId':Number(_0x1013c3[_0x0bc7('0x40')][_0x0bc7('0x67')]),'OpenchannelAccountId':Number(_0x1013c3[_0x0bc7('0x53')]['id'])});}});}})['then'](respondWithStatusCode(_0x15fb2e,null))[_0x0bc7('0x28')](handleError(_0x15fb2e,null));};exports['getAgents']=function(_0x21824c,_0x16ed19,_0x2b4e0f){var _0x3a8f3e={};var _0x88feac={};var _0x5b0a74;var _0x314d33;return db['OpenchannelAccount'][_0x0bc7('0x62')]({'where':{'id':_0x21824c[_0x0bc7('0x53')]['id']}})['then'](handleEntityNotFound(_0x16ed19,null))[_0x0bc7('0x33')](function(_0x42e045){if(_0x42e045){_0x5b0a74=_0x42e045;_0x88feac[_0x0bc7('0x3e')]=_[_0x0bc7('0x3f')](db[_0x0bc7('0x98')][_0x0bc7('0x63')]);_0x88feac[_0x0bc7('0x40')]=_[_0x0bc7('0x3f')](_0x21824c[_0x0bc7('0x40')]);_0x88feac[_0x0bc7('0x41')]=_[_0x0bc7('0x42')](_0x88feac[_0x0bc7('0x3e')],_0x88feac[_0x0bc7('0x40')]);_0x3a8f3e[_0x0bc7('0x43')]=_['intersection'](_0x88feac[_0x0bc7('0x3e')],qs[_0x0bc7('0x44')](_0x21824c[_0x0bc7('0x40')][_0x0bc7('0x44')]));_0x3a8f3e[_0x0bc7('0x43')]=_0x3a8f3e[_0x0bc7('0x43')][_0x0bc7('0x6a')]?_0x3a8f3e['attributes']:_0x88feac[_0x0bc7('0x3e')];_0x3a8f3e[_0x0bc7('0x47')]=qs[_0x0bc7('0x48')](_0x21824c['query'][_0x0bc7('0x48')]);_0x3a8f3e['where']=qs[_0x0bc7('0x41')](_[_0x0bc7('0x4a')](_0x21824c[_0x0bc7('0x40')],_0x88feac['filters']));if(_0x21824c[_0x0bc7('0x40')]['filter']){_0x3a8f3e[_0x0bc7('0x49')]=_[_0x0bc7('0x4c')](_0x3a8f3e['where'],{'$or':_[_0x0bc7('0x3a')](_0x3a8f3e[_0x0bc7('0x43')],function(_0x1ffa3a){var _0x198791={};_0x198791[_0x1ffa3a]={'$like':'%'+_0x21824c[_0x0bc7('0x40')][_0x0bc7('0x4b')]+'%'};return _0x198791;})});}_0x3a8f3e=_[_0x0bc7('0x4c')]({},_0x3a8f3e,_0x21824c[_0x0bc7('0x64')]);return _0x5b0a74['getAgents'](_0x3a8f3e);}})[_0x0bc7('0x33')](function(_0x11c597){if(_0x11c597){_0x314d33=_0x11c597[_0x0bc7('0x6a')];if(!_0x21824c[_0x0bc7('0x40')][_0x0bc7('0x45')](_0x0bc7('0x46'))){_0x3a8f3e[_0x0bc7('0x2f')]=qs[_0x0bc7('0x2f')](_0x21824c[_0x0bc7('0x40')][_0x0bc7('0x2f')]);_0x3a8f3e[_0x0bc7('0x2c')]=qs[_0x0bc7('0x2c')](_0x21824c['query']['offset']);}return _0x5b0a74[_0x0bc7('0xb9')](_0x3a8f3e);}})['then'](function(_0xa2509d){if(_0xa2509d){return _0xa2509d?{'count':_0x314d33,'rows':_0xa2509d}:null;}})['then'](respondWithResult(_0x16ed19,null))[_0x0bc7('0x28')](handleError(_0x16ed19,null));};exports['send']=function(_0x14d76c,_0xd60f10,_0x3cd451){var _0x4a0b50,_0x3f0be6,_0x19bd8b;if(_['isNil'](_0x14d76c['body']['body'])||_0x14d76c[_0x0bc7('0x56')][_0x0bc7('0x56')]===''){throw new db[(_0x0bc7('0x6d'))][(_0x0bc7('0x6e'))](_0x0bc7('0x77'));}if(_[_0x0bc7('0x74')](_0x14d76c[_0x0bc7('0x56')]['to'])){}_0x4a0b50=_0x14d76c['body']['to'];return db['OpenchannelAccount'][_0x0bc7('0x62')]({'where':{'id':_0x14d76c['params']['id']}})[_0x0bc7('0x33')](handleEntityNotFound(_0xd60f10,null))['then'](function(_0xbf9599){if(_0xbf9599){return db[_0x0bc7('0x3b')][_0x0bc7('0x55')]({'where':{'id':_0xbf9599['id']},'include':[{'model':db[_0x0bc7('0xba')],'as':_0x0bc7('0x7b'),'include':[{'model':db[_0x0bc7('0x6c')],'as':_0x0bc7('0x7c'),'where':{[_0xbf9599[_0x0bc7('0x78')]]:_0x4a0b50},'limit':0x1,'order':[[_0x0bc7('0x72'),'DESC']]}]}]})[_0x0bc7('0x33')](handleEntityNotFound(_0xd60f10,null))[_0x0bc7('0x33')](function(_0x4ffb42){if(_0x4ffb42&&_0x4ffb42[_0x0bc7('0x7b')]){_0x3f0be6=_0x4ffb42[_0x0bc7('0x34')]({'plain':!![]});if(_0x3f0be6[_0x0bc7('0x7b')]&&_0x3f0be6[_0x0bc7('0x7b')][_0x0bc7('0x7c')][_0x0bc7('0x6a')]){return _0x3f0be6[_0x0bc7('0x7b')]['Contacts'][0x0];}return db[_0x0bc7('0x6c')][_0x0bc7('0x5c')](_[_0x0bc7('0x18')](_0x14d76c[_0x0bc7('0x56')],{'firstName':_0x4a0b50,[_0x4ffb42['mapKey']]:_0x4a0b50,'phone':_0x4a0b50,'ListId':_0x3f0be6['ListId']}));}})[_0x0bc7('0x33')](handleEntityNotFound(_0xd60f10,null))[_0x0bc7('0x33')](function(_0x38794d){if(_0x38794d){_0x19bd8b=_0x38794d;return db[_0x0bc7('0x87')][_0x0bc7('0x55')]({'where':{'ContactId':_0x19bd8b['id'],'closed':![],'OpenchannelAccountId':_0x3f0be6['id']}})[_0x0bc7('0x33')](function(_0x578fb8){if(_0x578fb8){return[_0x578fb8,![]];}return db[_0x0bc7('0x87')][_0x0bc7('0x5c')]({'UserId':_0x14d76c['user']['id'],'ContactId':_0x19bd8b['id'],'OpenchannelAccountId':_0x3f0be6['id'],'lastMsgDirection':_0x0bc7('0xbb'),'Messages':[_[_0x0bc7('0x4c')](_0x14d76c[_0x0bc7('0x56')],{'read':![],'body':_0x14d76c[_0x0bc7('0x56')][_0x0bc7('0x56')],'OpenchannelAccountId':_0x3f0be6['id'],'UserId':_0x14d76c[_0x0bc7('0x57')]['id'],'ContactId':_0x19bd8b['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x0bc7('0xbc')}]})[_0x0bc7('0x33')](function(_0x45cfd1){return[_0x45cfd1,!![]];});});}})[_0x0bc7('0x8a')](function(_0x529614,_0xd139ac){if(_0xd139ac){return _0x529614;}return db[_0x0bc7('0x95')][_0x0bc7('0x5c')](_[_0x0bc7('0x4c')](_0x14d76c[_0x0bc7('0x56')],{'read':![],'body':_0x14d76c[_0x0bc7('0x56')][_0x0bc7('0x56')],'OpenchannelAccountId':_0x3f0be6['id'],'OpenchannelInteractionId':_0x529614['id'],'UserId':_0x14d76c[_0x0bc7('0x57')]['id'],'ContactId':_0x19bd8b['id']}))['then'](function(_0x2cc445){_0x529614[_0x0bc7('0xbd')][_0x0bc7('0xbc')]=[];_0x529614['dataValues'][_0x0bc7('0xbc')][_0x0bc7('0x91')](_0x2cc445[_0x0bc7('0xbd')]);return _0x529614;});});}})[_0x0bc7('0x33')](respondWithResult(_0xd60f10,null))[_0x0bc7('0x28')](handleError(_0xd60f10,null));};
\ No newline at end of file
+var _0x89b2=['Tag','Tags','color','tag','addAgents','emit','userOpenchannelAccount:save','removeAgents','userOpenchannelAccount:remove','getAgents','send','updatedAt','out','dataValues','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/license/util','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','sendStatus','status','end','json','undefined','limit','count','offset','set','apply','reject','save','update','destroy','get','UserProfileResource','stack','name','Pause','mandatoryDispositionPause','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filters','filter','merge','map','VIRTUAL','OpenchannelAccount','includeAll','include','rows','show','params','length','options','find','create','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','OpenchannelAccountId','Disposition','getDispositions','findOne','findAll','removeDispositions','ids','CannedAnswer','nolimit','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','difference','createdAt','CompanyId','ListId','isNil','from','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','Applications','account','applications','list','orderBy','priority','asc','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','contact','firstName','messageId','interaction','created','push','close','*,*,*,*','OpenchannelMessage','User','forcedOwnership','Start','startRouting','EventManager','addApplications','transaction','sequelize','Transaction','OpenchannelApplication','finally','getApplications','getInteractions','Contact','fullname','internal'];(function(_0x199bc4,_0x338105){var _0x136ffb=function(_0x3e7ced){while(--_0x3e7ced){_0x199bc4['push'](_0x199bc4['shift']());}};_0x136ffb(++_0x338105);}(_0x89b2,0xc6));var _0x289b=function(_0x486f0b,_0x19a9b7){_0x486f0b=_0x486f0b-0x0;var _0x12ccaf=_0x89b2[_0x486f0b];return _0x12ccaf;};'use strict';var emlformat=require(_0x289b('0x0'));var rimraf=require(_0x289b('0x1'));var zipdir=require(_0x289b('0x2'));var jsonpatch=require(_0x289b('0x3'));var rp=require(_0x289b('0x4'));var moment=require(_0x289b('0x5'));var BPromise=require(_0x289b('0x6'));var Mustache=require(_0x289b('0x7'));var util=require(_0x289b('0x8'));var path=require(_0x289b('0x9'));var sox=require(_0x289b('0xa'));var csv=require(_0x289b('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x289b('0xc'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x289b('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x289b('0xe'));var Papa=require(_0x289b('0xf'));var Redis=require(_0x289b('0x10'));var authService=require(_0x289b('0x11'));var qs=require(_0x289b('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x289b('0x13'));var logger=require('../../config/logger')(_0x289b('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x289b('0x15'));var db=require(_0x289b('0x16'))['db'];config['redis']=_[_0x289b('0x17')](config['redis'],{'host':_0x289b('0x18'),'port':0x18eb});var socket=require(_0x289b('0x19'))(new Redis(config[_0x289b('0x1a')]));require(_0x289b('0x1b'))[_0x289b('0x1c')](socket);var jayson=require(_0x289b('0x1d'));var client=jayson[_0x289b('0x1e')][_0x289b('0x1f')]({'port':0x232c});var client9002=jayson[_0x289b('0x1e')][_0x289b('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x1a6807,_0x345a5f,_0x405a2c,_0x3a7c07){return new BPromise(function(_0x5e3dcd,_0x117ef9){var _0x1d36dd=_0x3a7c07||client;return _0x1d36dd[_0x289b('0x20')](_0x1a6807,_0x405a2c)[_0x289b('0x21')](function(_0x39ba6f){logger['info'](_0x289b('0x22'),_0x345a5f,_0x289b('0x23'));logger['debug'](_0x289b('0x24'),_0x345a5f,_0x289b('0x23'),JSON[_0x289b('0x25')](_0x39ba6f));if(_0x39ba6f[_0x289b('0x26')]){if(_0x39ba6f[_0x289b('0x26')][_0x289b('0x27')]===0x1f4){logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x39ba6f[_0x289b('0x26')][_0x289b('0x28')]);return _0x117ef9(_0x39ba6f[_0x289b('0x26')][_0x289b('0x28')]);}logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x39ba6f['error'][_0x289b('0x28')]);return _0x5e3dcd(_0x39ba6f['error']['message']);}else{logger[_0x289b('0x29')](_0x289b('0x22'),_0x345a5f,_0x289b('0x23'));_0x5e3dcd(_0x39ba6f['result'][_0x289b('0x28')]);}})[_0x289b('0x2a')](function(_0x51c0c0){logger[_0x289b('0x26')](_0x289b('0x22'),_0x345a5f,_0x51c0c0);_0x117ef9(_0x51c0c0);});});}function respondWithStatusCode(_0x58b6fa,_0x5d8a23){_0x5d8a23=_0x5d8a23||0xcc;return function(_0x24a37f){if(_0x24a37f){return _0x58b6fa[_0x289b('0x2b')](_0x5d8a23);}return _0x58b6fa[_0x289b('0x2c')](_0x5d8a23)[_0x289b('0x2d')]();};}function respondWithResult(_0x3fa519,_0x3e63b5){_0x3e63b5=_0x3e63b5||0xc8;return function(_0x2fdaeb){if(_0x2fdaeb){return _0x3fa519[_0x289b('0x2c')](_0x3e63b5)[_0x289b('0x2e')](_0x2fdaeb);}};}function respondWithFilteredResult(_0x5958da,_0x7b8fd0){return function(_0x4ceaec){if(_0x4ceaec){var _0x598002=typeof _0x7b8fd0['offset']===_0x289b('0x2f')&&typeof _0x7b8fd0[_0x289b('0x30')]===_0x289b('0x2f');var _0x10fc50=_0x4ceaec[_0x289b('0x31')];var _0x271aa8=_0x598002?0x0:_0x7b8fd0[_0x289b('0x32')];var _0xca1604=_0x598002?_0x4ceaec[_0x289b('0x31')]:_0x7b8fd0[_0x289b('0x32')]+_0x7b8fd0['limit'];var _0x94c5a5;if(_0xca1604>=_0x10fc50){_0xca1604=_0x10fc50;_0x94c5a5=0xc8;}else{_0x94c5a5=0xce;}_0x5958da[_0x289b('0x2c')](_0x94c5a5);return _0x5958da[_0x289b('0x33')]('Content-Range',_0x271aa8+'-'+_0xca1604+'/'+_0x10fc50)[_0x289b('0x2e')](_0x4ceaec);}return null;};}function patchUpdates(_0xcfa83e){return function(_0x42f535){try{jsonpatch[_0x289b('0x34')](_0x42f535,_0xcfa83e,!![]);}catch(_0x4e7d64){return BPromise[_0x289b('0x35')](_0x4e7d64);}return _0x42f535[_0x289b('0x36')]();};}function saveUpdates(_0x24f8b6,_0x199609){return function(_0x1444f2){if(_0x1444f2){return _0x1444f2[_0x289b('0x37')](_0x24f8b6)[_0x289b('0x21')](function(_0x173ec3){return _0x173ec3;});}return null;};}function removeEntity(_0x3c031e,_0x55289d){return function(_0x1dcd42){if(_0x1dcd42){return _0x1dcd42[_0x289b('0x38')]()['then'](function(){var _0x5d4c9d=_0x1dcd42[_0x289b('0x39')]({'plain':!![]});var _0x18dd30='OpenchannelAccounts';return db[_0x289b('0x3a')][_0x289b('0x38')]({'where':{'type':_0x18dd30,'resourceId':_0x5d4c9d['id']}})[_0x289b('0x21')](function(){return _0x1dcd42;});})['then'](function(){_0x3c031e['status'](0xcc)[_0x289b('0x2d')]();});}};}function handleEntityNotFound(_0xcf9121,_0x27c9bf){return function(_0x428d11){if(!_0x428d11){_0xcf9121[_0x289b('0x2b')](0x194);}return _0x428d11;};}function handleError(_0x47ea18,_0x17596f){_0x17596f=_0x17596f||0x1f4;return function(_0x3a76e5){logger[_0x289b('0x26')](_0x3a76e5[_0x289b('0x3b')]);if(_0x3a76e5[_0x289b('0x3c')]){delete _0x3a76e5[_0x289b('0x3c')];}_0x47ea18[_0x289b('0x2c')](_0x17596f)['send'](_0x3a76e5);};}exports['index']=function(_0x55d195,_0x37a4d1){var _0x25ffab={'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]},_0x15090a={},_0x39b472={'count':0x0,'rows':[]};var _0x20c064=_['map'](db['OpenchannelAccount'][_0x289b('0x3f')],function(_0x353de1){return{'name':_0x353de1[_0x289b('0x40')],'type':_0x353de1[_0x289b('0x41')][_0x289b('0x42')]};});_0x15090a[_0x289b('0x43')]=_['map'](_0x20c064,_0x289b('0x3c'));_0x15090a[_0x289b('0x44')]=_[_0x289b('0x45')](_0x55d195[_0x289b('0x44')]);_0x15090a['filters']=_[_0x289b('0x46')](_0x15090a['model'],_0x15090a[_0x289b('0x44')]);_0x25ffab[_0x289b('0x47')]=_['intersection'](_0x15090a[_0x289b('0x43')],qs[_0x289b('0x48')](_0x55d195['query'][_0x289b('0x48')]));_0x25ffab[_0x289b('0x47')]=_0x25ffab[_0x289b('0x47')]['length']?_0x25ffab[_0x289b('0x47')]:_0x15090a[_0x289b('0x43')];if(!_0x55d195[_0x289b('0x44')][_0x289b('0x49')]('nolimit')){_0x25ffab[_0x289b('0x30')]=qs[_0x289b('0x30')](_0x55d195['query'][_0x289b('0x30')]);_0x25ffab['offset']=qs[_0x289b('0x32')](_0x55d195[_0x289b('0x44')]['offset']);}_0x25ffab[_0x289b('0x4a')]=qs['sort'](_0x55d195[_0x289b('0x44')][_0x289b('0x4b')]);_0x25ffab[_0x289b('0x4c')]=qs['filters'](_[_0x289b('0x4d')](_0x55d195[_0x289b('0x44')],_0x15090a[_0x289b('0x4e')]),_0x20c064);if(_0x55d195[_0x289b('0x44')][_0x289b('0x4f')]){_0x25ffab[_0x289b('0x4c')]=_[_0x289b('0x50')](_0x25ffab[_0x289b('0x4c')],{'$or':_[_0x289b('0x51')](_0x20c064,function(_0x3fab7){if(_0x3fab7[_0x289b('0x41')]!==_0x289b('0x52')){var _0x141abe={};_0x141abe[_0x3fab7[_0x289b('0x3c')]]={'$like':'%'+_0x55d195['query'][_0x289b('0x4f')]+'%'};return _0x141abe;}})});}_0x25ffab=_[_0x289b('0x50')]({},_0x25ffab,_0x55d195['options']);var _0x1f5086={'where':_0x25ffab[_0x289b('0x4c')]};return db[_0x289b('0x53')][_0x289b('0x31')](_0x1f5086)['then'](function(_0x4d9759){_0x39b472[_0x289b('0x31')]=_0x4d9759;if(_0x55d195[_0x289b('0x44')][_0x289b('0x54')]){_0x25ffab[_0x289b('0x55')]=[{'all':!![]}];}return db[_0x289b('0x53')]['findAll'](_0x25ffab);})['then'](function(_0x14e4f4){_0x39b472[_0x289b('0x56')]=_0x14e4f4;return _0x39b472;})[_0x289b('0x21')](respondWithFilteredResult(_0x37a4d1,_0x25ffab))[_0x289b('0x2a')](handleError(_0x37a4d1,null));};exports[_0x289b('0x57')]=function(_0x30fe9d,_0x241ac7){var _0x3ab297={'raw':![],'where':{'id':_0x30fe9d[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]},_0x47736a={};_0x47736a[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x53')]['rawAttributes']);_0x47736a[_0x289b('0x44')]=_[_0x289b('0x45')](_0x30fe9d[_0x289b('0x44')]);_0x47736a[_0x289b('0x4e')]=_[_0x289b('0x46')](_0x47736a[_0x289b('0x43')],_0x47736a['query']);_0x3ab297[_0x289b('0x47')]=_['intersection'](_0x47736a['model'],qs['fields'](_0x30fe9d[_0x289b('0x44')]['fields']));_0x3ab297['attributes']=_0x3ab297[_0x289b('0x47')][_0x289b('0x59')]?_0x3ab297['attributes']:_0x47736a[_0x289b('0x43')];if(_0x30fe9d['query'][_0x289b('0x54')]){_0x3ab297[_0x289b('0x55')]=[{'all':!![]}];}_0x3ab297=_[_0x289b('0x50')]({},_0x3ab297,_0x30fe9d[_0x289b('0x5a')]);return db[_0x289b('0x53')][_0x289b('0x5b')](_0x3ab297)[_0x289b('0x21')](handleEntityNotFound(_0x241ac7,null))[_0x289b('0x21')](respondWithResult(_0x241ac7,null))[_0x289b('0x2a')](handleError(_0x241ac7,null));};exports['create']=function(_0x1db13c,_0x3a3a3b){return db[_0x289b('0x53')][_0x289b('0x5c')](_0x1db13c['body'],{})[_0x289b('0x21')](function(_0x3448e0){var _0x38a278=_0x1db13c[_0x289b('0x5d')][_0x289b('0x39')]({'plain':!![]});if(!_0x38a278)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x38a278[_0x289b('0x5e')]===_0x289b('0x5d')){var _0x322c7d=_0x3448e0[_0x289b('0x39')]({'plain':!![]});var _0x5a1a8e='OpenchannelAccounts';return db[_0x289b('0x5f')]['find']({'where':{'name':_0x5a1a8e,'userProfileId':_0x38a278[_0x289b('0x60')]},'raw':!![]})[_0x289b('0x21')](function(_0x45498e){if(_0x45498e&&_0x45498e[_0x289b('0x61')]===0x0){return db['UserProfileResource'][_0x289b('0x5c')]({'name':_0x322c7d[_0x289b('0x3c')],'resourceId':_0x322c7d['id'],'type':_0x45498e[_0x289b('0x3c')],'sectionId':_0x45498e['id']},{})[_0x289b('0x21')](function(){return _0x3448e0;});}else{return _0x3448e0;}})[_0x289b('0x2a')](function(_0x34abe4){logger[_0x289b('0x26')](_0x289b('0x62'),_0x34abe4);throw _0x34abe4;});}return _0x3448e0;})[_0x289b('0x21')](respondWithResult(_0x3a3a3b,0xc9))['catch'](handleError(_0x3a3a3b,null));};exports[_0x289b('0x37')]=function(_0x48bf52,_0x1edc52){if(_0x48bf52[_0x289b('0x63')]['id']){delete _0x48bf52[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x48bf52[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x3d')],'as':_0x289b('0x3e')}]})[_0x289b('0x21')](handleEntityNotFound(_0x1edc52,null))[_0x289b('0x21')](saveUpdates(_0x48bf52['body'],null))[_0x289b('0x21')](respondWithResult(_0x1edc52,null))[_0x289b('0x2a')](handleError(_0x1edc52,null));};exports['destroy']=function(_0x28e003,_0x146df6){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x28e003['params']['id']}})['then'](handleEntityNotFound(_0x146df6,null))[_0x289b('0x21')](removeEntity(_0x146df6,null))[_0x289b('0x2a')](handleError(_0x146df6,null));};exports[_0x289b('0x64')]=function(_0xd3cf71,_0x3ca4b0){return db['OpenchannelAccount'][_0x289b('0x64')]()[_0x289b('0x21')](respondWithResult(_0x3ca4b0,null))[_0x289b('0x2a')](handleError(_0x3ca4b0,null));};exports[_0x289b('0x65')]=function(_0x2b1f10,_0x579a70,_0x51110a){if(_0x2b1f10['body']['id']){delete _0x2b1f10[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x2b1f10[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x579a70,null))['then'](function(_0x412a4e){if(_0x412a4e){_0x2b1f10[_0x289b('0x63')][_0x289b('0x66')]=_0x412a4e['id'];return db[_0x289b('0x67')][_0x289b('0x5c')](_0x2b1f10['body']);}})['then'](respondWithResult(_0x579a70,null))[_0x289b('0x2a')](handleError(_0x579a70,null));};exports[_0x289b('0x68')]=function(_0xddb5de,_0x314eca,_0x332ebb){var _0x50dcdb={'raw':![],'where':{}};var _0x5234f6={};var _0x2551f8={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0xddb5de[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x314eca,null))[_0x289b('0x21')](function(_0x560056){if(_0x560056){_0x5234f6[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x67')]['rawAttributes']);_0x5234f6[_0x289b('0x44')]=_['keys'](_0xddb5de[_0x289b('0x44')]);_0x5234f6[_0x289b('0x4e')]=_[_0x289b('0x46')](_0x5234f6[_0x289b('0x43')],_0x5234f6[_0x289b('0x44')]);_0x50dcdb[_0x289b('0x47')]=_['intersection'](_0x5234f6[_0x289b('0x43')],qs[_0x289b('0x48')](_0xddb5de[_0x289b('0x44')]['fields']));_0x50dcdb[_0x289b('0x47')]=_0x50dcdb[_0x289b('0x47')][_0x289b('0x59')]?_0x50dcdb['attributes']:_0x5234f6[_0x289b('0x43')];if(!_0xddb5de[_0x289b('0x44')][_0x289b('0x49')]('nolimit')){_0x50dcdb[_0x289b('0x30')]=qs[_0x289b('0x30')](_0xddb5de[_0x289b('0x44')][_0x289b('0x30')]);_0x50dcdb[_0x289b('0x32')]=qs['offset'](_0xddb5de[_0x289b('0x44')][_0x289b('0x32')]);}_0x50dcdb[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0xddb5de[_0x289b('0x44')][_0x289b('0x4b')]);_0x50dcdb['where']=qs[_0x289b('0x4e')](_[_0x289b('0x4d')](_0xddb5de['query'],_0x5234f6[_0x289b('0x4e')]));_0x50dcdb[_0x289b('0x4c')][_0x289b('0x66')]=_0x560056['id'];if(_0xddb5de[_0x289b('0x44')]['filter']){_0x50dcdb[_0x289b('0x4c')]=_[_0x289b('0x50')](_0x50dcdb['where'],{'$or':_[_0x289b('0x51')](_0x50dcdb[_0x289b('0x47')],function(_0x52a8bf){var _0x48d129={};_0x48d129[_0x52a8bf]={'$like':'%'+_0xddb5de['query'][_0x289b('0x4f')]+'%'};return _0x48d129;})});}_0x50dcdb=_[_0x289b('0x50')]({},_0x50dcdb,_0xddb5de[_0x289b('0x5a')]);return db[_0x289b('0x67')]['count']({'where':_0x50dcdb[_0x289b('0x4c')]})[_0x289b('0x21')](function(_0x277647){_0x2551f8[_0x289b('0x31')]=_0x277647;if(_0xddb5de[_0x289b('0x44')][_0x289b('0x54')]){_0x50dcdb['include']=[{'all':!![]}];}return db[_0x289b('0x67')][_0x289b('0x6a')](_0x50dcdb);})[_0x289b('0x21')](function(_0x1fa0ec){_0x2551f8[_0x289b('0x56')]=_0x1fa0ec;return _0x2551f8;});}})[_0x289b('0x21')](respondWithFilteredResult(_0x314eca,_0x50dcdb))['catch'](handleError(_0x314eca,null));};exports['removeDispositions']=function(_0x5afc98,_0x466de8,_0x4e5aa9){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x5afc98['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x466de8,null))['then'](function(_0x1e5066){if(_0x1e5066){return _0x1e5066[_0x289b('0x6b')](_0x5afc98[_0x289b('0x44')][_0x289b('0x6c')]);}})['then'](respondWithStatusCode(_0x466de8,null))[_0x289b('0x2a')](handleError(_0x466de8,null));};exports['addAnswer']=function(_0x27602a,_0x3ad774,_0x484d70){if(_0x27602a['body']['id']){delete _0x27602a[_0x289b('0x63')]['id'];}return db[_0x289b('0x53')]['find']({'where':{'id':_0x27602a[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x3ad774,null))['then'](function(_0x559c91){if(_0x559c91){_0x27602a[_0x289b('0x63')][_0x289b('0x66')]=_0x559c91['id'];return db[_0x289b('0x6d')][_0x289b('0x5c')](_0x27602a[_0x289b('0x63')]);}})[_0x289b('0x21')](respondWithResult(_0x3ad774,null))[_0x289b('0x2a')](handleError(_0x3ad774,null));};exports['getAnswers']=function(_0x17f15c,_0x1ae101,_0x110bad){var _0x279c90={'raw':![],'where':{}};var _0x42128b={};var _0x4ee7d0={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x17f15c['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x1ae101,null))[_0x289b('0x21')](function(_0x524e8c){if(_0x524e8c){_0x42128b['model']=_[_0x289b('0x45')](db[_0x289b('0x6d')][_0x289b('0x3f')]);_0x42128b['query']=_[_0x289b('0x45')](_0x17f15c[_0x289b('0x44')]);_0x42128b['filters']=_[_0x289b('0x46')](_0x42128b[_0x289b('0x43')],_0x42128b[_0x289b('0x44')]);_0x279c90[_0x289b('0x47')]=_[_0x289b('0x46')](_0x42128b[_0x289b('0x43')],qs['fields'](_0x17f15c['query'][_0x289b('0x48')]));_0x279c90[_0x289b('0x47')]=_0x279c90[_0x289b('0x47')][_0x289b('0x59')]?_0x279c90[_0x289b('0x47')]:_0x42128b['model'];if(!_0x17f15c[_0x289b('0x44')]['hasOwnProperty'](_0x289b('0x6e'))){_0x279c90['limit']=qs[_0x289b('0x30')](_0x17f15c[_0x289b('0x44')][_0x289b('0x30')]);_0x279c90['offset']=qs['offset'](_0x17f15c[_0x289b('0x44')][_0x289b('0x32')]);}_0x279c90[_0x289b('0x4a')]=qs['sort'](_0x17f15c[_0x289b('0x44')][_0x289b('0x4b')]);_0x279c90[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_['pick'](_0x17f15c['query'],_0x42128b['filters']));_0x279c90[_0x289b('0x4c')][_0x289b('0x66')]=_0x524e8c['id'];if(_0x17f15c[_0x289b('0x44')][_0x289b('0x4f')]){_0x279c90['where']=_['merge'](_0x279c90[_0x289b('0x4c')],{'$or':_['map'](_0x279c90[_0x289b('0x47')],function(_0x43514b){var _0x53ff05={};_0x53ff05[_0x43514b]={'$like':'%'+_0x17f15c['query'][_0x289b('0x4f')]+'%'};return _0x53ff05;})});}_0x279c90=_[_0x289b('0x50')]({},_0x279c90,_0x17f15c[_0x289b('0x5a')]);return db[_0x289b('0x6d')][_0x289b('0x31')]({'where':_0x279c90[_0x289b('0x4c')]})['then'](function(_0x18e58d){_0x4ee7d0['count']=_0x18e58d;if(_0x17f15c['query']['includeAll']){_0x279c90['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x289b('0x6a')](_0x279c90);})[_0x289b('0x21')](function(_0xc82e72){_0x4ee7d0[_0x289b('0x56')]=_0xc82e72;return _0x4ee7d0;});}})[_0x289b('0x21')](respondWithFilteredResult(_0x1ae101,_0x279c90))[_0x289b('0x2a')](handleError(_0x1ae101,null));};exports['removeAnswers']=function(_0x1bae6f,_0x4ef426,_0x32c505){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x1bae6f[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x4ef426,null))[_0x289b('0x21')](function(_0x44f777){if(_0x44f777){return _0x44f777[_0x289b('0x6f')](_0x1bae6f[_0x289b('0x44')][_0x289b('0x6c')]);}})[_0x289b('0x21')](respondWithStatusCode(_0x4ef426,null))['catch'](handleError(_0x4ef426,null));};exports[_0x289b('0x70')]=function(_0x3d764e,_0x139c4c,_0x3d1eb2){var _0x1b96e5={'body':_0x3d764e['body'],'channel':_0x289b('0x71')};var _0x2a2596=[];var _0x2592a2=[];var _0xa01544={};var _0x5b690f=![];return db[_0x289b('0x72')][_0x289b('0x64')]()['then'](function(_0xe93d96){if(!_0xe93d96){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))]('no\x20available\x20attributes');}_0x2a2596=_[_0x289b('0x75')](_[_0x289b('0x45')](_0xe93d96),[_0x289b('0x76'),'updatedAt']);_0x2592a2=_[_0x289b('0x75')](_[_0x289b('0x45')](_0xe93d96),['createdAt','updatedAt',_0x289b('0x77'),_0x289b('0x78')]);if(_0x3d764e[_0x289b('0x63')]['id']){delete _0x3d764e[_0x289b('0x63')]['id'];}if(_[_0x289b('0x79')](_0x3d764e['body'][_0x289b('0x7a')])){throw new db['Sequelize'][(_0x289b('0x74'))]('from\x20is\x20mandatory');}if(_[_0x289b('0x79')](_0x3d764e[_0x289b('0x63')][_0x289b('0x63')])||_0x3d764e['body'][_0x289b('0x63')]===''){throw new db[(_0x289b('0x73'))]['ValidationError'](_0x289b('0x7b'));}if(_[_0x289b('0x79')](_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')])){throw new db[(_0x289b('0x73'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2592a2);}if(!_[_0x289b('0x7d')](_0x2592a2,_0x3d764e[_0x289b('0x63')]['mapKey'])){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))](_0x289b('0x7e')+_0x2592a2);}_0xa01544[_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')]]=_0x3d764e['body']['from'];})[_0x289b('0x21')](function(){return db[_0x289b('0x53')]['find']({'where':{'id':_0x3d764e[_0x289b('0x58')]['id']},'include':[{'model':db[_0x289b('0x7f')],'as':_0x289b('0x80'),'include':[{'model':db[_0x289b('0x72')],'as':_0x289b('0x81'),'where':_0xa01544,'limit':0x1,'order':[['updatedAt',_0x289b('0x82')]]}]},{'model':db['OpenchannelApplication'],'as':_0x289b('0x83')}]});})[_0x289b('0x21')](handleEntityNotFound(_0x139c4c,null))[_0x289b('0x21')](function(_0x234ff8){if(_0x234ff8&&_0x234ff8['List']){_0x1b96e5[_0x289b('0x84')]=_0x234ff8;_0x1b96e5[_0x289b('0x85')]=_0x234ff8[_0x289b('0x83')];_0x1b96e5[_0x289b('0x86')]=_0x234ff8[_0x289b('0x80')];_0x1b96e5['applications']=_[_0x289b('0x87')](_0x1b96e5['applications'],[_0x289b('0x88')],[_0x289b('0x89')]);if(_0x1b96e5[_0x289b('0x84')][_0x289b('0x83')]){delete _0x1b96e5[_0x289b('0x84')][_0x289b('0x83')];}if(_0x1b96e5[_0x289b('0x84')][_0x289b('0x80')]&&_0x1b96e5[_0x289b('0x84')][_0x289b('0x80')][_0x289b('0x81')]['length']){return _0x1b96e5[_0x289b('0x84')][_0x289b('0x80')]['Contacts'][0x0];}var _0x159e0c=_[_0x289b('0x17')](_0x3d764e['body'],{'firstName':_0x3d764e['body'][_0x289b('0x7a')],'ListId':_0x234ff8[_0x289b('0x78')]});_0x159e0c[_0x3d764e[_0x289b('0x63')][_0x289b('0x7c')]]=_0x3d764e[_0x289b('0x63')][_0x289b('0x7a')];return db[_0x289b('0x72')][_0x289b('0x5c')](_0x159e0c,{'fields':_0x2a2596,'raw':!![]});}})[_0x289b('0x21')](handleEntityNotFound(_0x139c4c,null))[_0x289b('0x21')](function(_0x107930){_0x1b96e5['contact']=_0x107930;if(_0x107930){var _0x237d43={'ContactId':_0x107930['id'],'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'from':(_0x107930['firstName']||'')+'\x20'+(_0x107930[_0x289b('0x8a')]||'')};var _0x158b71={'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'closed':![]};if(_0x3d764e['body'][_0x289b('0x8b')]){_0x158b71[_0x289b('0x8b')]=_0x3d764e[_0x289b('0x63')]['threadId'];return db[_0x289b('0x8c')][_0x289b('0x5b')]({'where':_0x158b71})[_0x289b('0x21')](function(_0x2017d8){if(_0x2017d8){return[_0x2017d8,![]];}_0x237d43[_0x289b('0x8b')]=_0x3d764e['body'][_0x289b('0x8b')];_0x237d43[_0x289b('0x8d')]=_0x3d764e[_0x289b('0x63')][_0x289b('0x8d')];return db[_0x289b('0x8c')][_0x289b('0x5c')](_0x237d43)['then'](function(_0x15e242){return[_0x15e242,!![]];});});}else{_0x158b71[_0x289b('0x8b')]=null;}_0x158b71[_0x289b('0x8e')]=_0x107930['id'];return db[_0x289b('0x8c')][_0x289b('0x5b')]({'where':_0x158b71})[_0x289b('0x21')](function(_0x38d25b){if(_0x38d25b){return[_0x38d25b,![]];}return db['OpenchannelInteraction']['create'](_0x237d43)[_0x289b('0x21')](function(_0x2872ff){return[_0x2872ff,!![]];});});}})['spread'](function(_0x4cb784,_0x33c7b2){if(_0x4cb784){_0x5b690f=_0x33c7b2;if(!_0x33c7b2){var _0x31ca63={'from':(_0x1b96e5[_0x289b('0x8f')][_0x289b('0x90')]||'')+'\x20'+(_0x1b96e5[_0x289b('0x8f')][_0x289b('0x8a')]||'')};if(_0x3d764e[_0x289b('0x63')][_0x289b('0x8b')]&&_0x3d764e[_0x289b('0x63')][_0x289b('0x91')]&&_0x3d764e[_0x289b('0x63')][_0x289b('0x8b')]!=_0x3d764e['body']['messageId']){_0x31ca63['threadId']=_0x3d764e[_0x289b('0x63')][_0x289b('0x91')];}return _0x4cb784['update'](_0x31ca63);}else{return _0x4cb784;}}})[_0x289b('0x21')](function(_0x2c2913){_0x1b96e5[_0x289b('0x92')]=_0x2c2913[_0x289b('0x39')]({'plain':!![]});_0x1b96e5[_0x289b('0x92')]['created']=_0x5b690f;if(_0x1b96e5[_0x289b('0x92')][_0x289b('0x93')]){if(_0x1b96e5[_0x289b('0x84')]['autoclose']){_0x1b96e5['applications'][_0x289b('0x94')]({'id':0x0,'priority':_0x1b96e5['applications']['length']+0x1,'app':_0x289b('0x95'),'appdata':'unmanaged','interval':_0x289b('0x96')});}}return db[_0x289b('0x97')]['create']({'body':_0x3d764e['body']['body'],'OpenchannelAccountId':_0x3d764e[_0x289b('0x58')]['id'],'OpenchannelInteractionId':_0x2c2913['id'],'direction':'in','ContactId':_0x1b96e5[_0x289b('0x8f')]['id'],'AttachmentId':_0x3d764e[_0x289b('0x63')]['AttachmentId']});})[_0x289b('0x21')](function(_0x1a788c){_0x1b96e5[_0x289b('0x28')]=_0x1a788c;if(_0x1b96e5['interaction']['UserId']){return db[_0x289b('0x98')][_0x289b('0x5b')]({'attributes':['id','name'],'where':{'id':_0x1b96e5['interaction']['UserId']}})[_0x289b('0x21')](function(_0x23a807){if(_0x23a807){_0x1b96e5[_0x289b('0x85')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x23a807[_0x289b('0x3c')]+','+(_0x1b96e5[_0x289b('0x84')]['waitForTheAssignedAgent']||0xa),'interval':_0x289b('0x96')});_0x1b96e5[_0x289b('0x99')]=![];}return respondWithRpcPromise(_0x289b('0x9a'),'startRouting',_0x1b96e5);});}return respondWithRpcPromise(_0x289b('0x9a'),_0x289b('0x9b'),_0x1b96e5);})[_0x289b('0x21')](function(_0x2e6aaf){respondWithRpcPromise(_0x289b('0x9c'),_0x289b('0x9c'),{'event':'notify','message':_0x2e6aaf},client9002);return _0x2e6aaf;})[_0x289b('0x21')](respondWithResult(_0x139c4c,null))[_0x289b('0x2a')](handleError(_0x139c4c,null));};exports[_0x289b('0x9d')]=function(_0x2078c5,_0x2e446f){var _0xe5fd98=_0x2078c5[_0x289b('0x58')]['id'];var _0x43ccc0=_0x2078c5[_0x289b('0x63')];var _0x2f8537=0xc8;var _0x38eccd=null;return db['sequelize'][_0x289b('0x9e')]({'isolationLevel':db[_0x289b('0x9f')][_0x289b('0xa0')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x4fe7aa){return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0xe5fd98},'transaction':_0x4fe7aa})[_0x289b('0x21')](function(_0x103972){if(_0x103972){return db[_0x289b('0xa1')][_0x289b('0x38')]({'where':{'OpenchannelAccountId':_0xe5fd98},'transaction':_0x4fe7aa})['then'](function(){var _0x4133a6=_[_0x289b('0x51')](_0x43ccc0,function(_0x580750){_0x580750[_0x289b('0x66')]=_0xe5fd98;return _0x580750;});return db['OpenchannelApplication']['bulkCreate'](_0x4133a6,{'transaction':_0x4fe7aa});});}else{_0x2f8537=0x194;_0x38eccd=[];}});})[_0x289b('0x21')](function(){if(_0x2f8537!==0x194){return db[_0x289b('0xa1')]['findAndCountAll']({'where':{'OpenchannelAccountId':_0xe5fd98},'order':'priority'})[_0x289b('0x21')](function(_0x2b4ae2){_0x38eccd=_0x2b4ae2;});}})[_0x289b('0x2a')](function(_0x3fdf3d){_0x2f8537=0x1f4;logger['error'](_0x3fdf3d[_0x289b('0x3b')]);if(_0x3fdf3d[_0x289b('0x3c')]){delete _0x3fdf3d[_0x289b('0x3c')];}_0x38eccd=_0x3fdf3d;})[_0x289b('0xa2')](function(){if(_0x38eccd===null){_0x2e446f[_0x289b('0x2b')](_0x2f8537);}else{if(_0x2f8537===0x1f4){_0x2e446f[_0x289b('0x2c')](_0x2f8537)['send'](_0x38eccd);}else{_0x2e446f[_0x289b('0x2c')](_0x2f8537)[_0x289b('0x2e')](_0x38eccd);}}});};exports[_0x289b('0xa3')]=function(_0x14d5b6,_0x309a18,_0x45ad81){var _0x414377={};var _0xfbadfa={};var _0x358f3b;var _0x4f74d8;return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x14d5b6[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x309a18,null))[_0x289b('0x21')](function(_0x4d16ba){if(_0x4d16ba){_0x358f3b=_0x4d16ba;_0xfbadfa[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0xa1')]['rawAttributes']);_0xfbadfa[_0x289b('0x44')]=_[_0x289b('0x45')](_0x14d5b6[_0x289b('0x44')]);_0xfbadfa[_0x289b('0x4e')]=_[_0x289b('0x46')](_0xfbadfa[_0x289b('0x43')],_0xfbadfa['query']);_0x414377[_0x289b('0x47')]=_[_0x289b('0x46')](_0xfbadfa[_0x289b('0x43')],qs[_0x289b('0x48')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x48')]));_0x414377['attributes']=_0x414377[_0x289b('0x47')][_0x289b('0x59')]?_0x414377[_0x289b('0x47')]:_0xfbadfa[_0x289b('0x43')];_0x414377[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0x14d5b6['query'][_0x289b('0x4b')]);_0x414377[_0x289b('0x4c')]=qs['filters'](_[_0x289b('0x4d')](_0x14d5b6['query'],_0xfbadfa[_0x289b('0x4e')]));if(_0x14d5b6[_0x289b('0x44')][_0x289b('0x4f')]){_0x414377['where']=_[_0x289b('0x50')](_0x414377['where'],{'$or':_['map'](_0x414377[_0x289b('0x47')],function(_0x40c601){var _0x6d62e1={};_0x6d62e1[_0x40c601]={'$like':'%'+_0x14d5b6[_0x289b('0x44')][_0x289b('0x4f')]+'%'};return _0x6d62e1;})});}_0x414377=_[_0x289b('0x50')]({},_0x414377,_0x14d5b6[_0x289b('0x5a')]);return _0x358f3b['getApplications'](_0x414377);}})[_0x289b('0x21')](function(_0x28e9dd){if(_0x28e9dd){_0x4f74d8=_0x28e9dd[_0x289b('0x59')];if(!_0x14d5b6[_0x289b('0x44')][_0x289b('0x49')](_0x289b('0x6e'))){_0x414377['limit']=qs[_0x289b('0x30')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x30')]);_0x414377['offset']=qs[_0x289b('0x32')](_0x14d5b6[_0x289b('0x44')][_0x289b('0x32')]);}return _0x358f3b['getApplications'](_0x414377);}})[_0x289b('0x21')](function(_0x4215d1){if(_0x4215d1){return _0x4215d1?{'count':_0x4f74d8,'rows':_0x4215d1}:null;}})['then'](respondWithResult(_0x309a18,null))['catch'](handleError(_0x309a18,null));};exports[_0x289b('0xa4')]=function(_0x3f6f40,_0x51a9b7,_0x2a1dea){var _0x179211={'raw':![],'where':{}};var _0x418d26={};var _0x558d8e={'count':0x0,'rows':[]};return db[_0x289b('0x53')][_0x289b('0x69')]({'where':{'id':_0x3f6f40[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x51a9b7,null))['then'](function(_0x20b339){if(_0x20b339){_0x418d26[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x8c')][_0x289b('0x3f')]);_0x418d26[_0x289b('0x44')]=_[_0x289b('0x45')](_0x3f6f40[_0x289b('0x44')]);_0x418d26[_0x289b('0x4e')]=_['intersection'](_0x418d26[_0x289b('0x43')],_0x418d26[_0x289b('0x44')]);_0x179211['attributes']=_['intersection'](_0x418d26[_0x289b('0x43')],qs['fields'](_0x3f6f40[_0x289b('0x44')][_0x289b('0x48')]));_0x179211[_0x289b('0x47')]=_0x179211[_0x289b('0x47')][_0x289b('0x59')]?_0x179211[_0x289b('0x47')]:_0x418d26[_0x289b('0x43')];if(!_0x3f6f40['query']['hasOwnProperty'](_0x289b('0x6e'))){_0x179211[_0x289b('0x30')]=qs['limit'](_0x3f6f40[_0x289b('0x44')]['limit']);_0x179211[_0x289b('0x32')]=qs['offset'](_0x3f6f40['query'][_0x289b('0x32')]);}_0x179211[_0x289b('0x4a')]=qs[_0x289b('0x4b')](_0x3f6f40['query'][_0x289b('0x4b')]);_0x179211[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_[_0x289b('0x4d')](_0x3f6f40['query'],_0x418d26[_0x289b('0x4e')]));_0x179211[_0x289b('0x4c')][_0x289b('0x66')]=_0x20b339['id'];if(_0x3f6f40[_0x289b('0x44')]['filter']){_0x179211['where']=_[_0x289b('0x50')](_0x179211[_0x289b('0x4c')],{'$or':_[_0x289b('0x51')](_0x179211['attributes'],function(_0x4292fd){var _0x4b0a0b={};_0x4b0a0b[_0x4292fd]={'$like':'%'+_0x3f6f40[_0x289b('0x44')][_0x289b('0x4f')]+'%'};return _0x4b0a0b;})});}_0x179211=_[_0x289b('0x50')]({},_0x179211,_0x3f6f40['options']);return db[_0x289b('0x8c')]['count']({'where':_0x179211[_0x289b('0x4c')]})['then'](function(_0x208d87){_0x558d8e[_0x289b('0x31')]=_0x208d87;if(_0x3f6f40[_0x289b('0x44')][_0x289b('0x54')]){_0x179211[_0x289b('0x55')]=[{'model':db[_0x289b('0x72')],'as':_0x289b('0xa5'),'required':![]},{'model':db[_0x289b('0x98')],'as':'Owner','attributes':[_0x289b('0x3c'),_0x289b('0xa6'),_0x289b('0xa7')],'required':![]},{'model':db[_0x289b('0xa8')],'as':_0x289b('0xa9'),'attributes':['id',_0x289b('0x3c'),_0x289b('0xaa')],'where':_0x3f6f40[_0x289b('0x44')][_0x289b('0xab')]?{'id':_0x3f6f40[_0x289b('0x44')][_0x289b('0xab')]}:undefined,'required':_0x3f6f40['query'][_0x289b('0xab')]?!![]:![]}];}return db[_0x289b('0x8c')][_0x289b('0x6a')](_0x179211);})['then'](function(_0x23ac83){_0x558d8e['rows']=_0x23ac83;return _0x558d8e;});}})['then'](respondWithFilteredResult(_0x51a9b7,_0x179211))[_0x289b('0x2a')](handleError(_0x51a9b7,null));};exports[_0x289b('0xac')]=function(_0x46929f,_0x37683d,_0x2f5677){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x46929f[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x37683d,null))[_0x289b('0x21')](function(_0x598a87){if(_0x598a87){return _0x598a87[_0x289b('0xac')](_0x46929f[_0x289b('0x63')][_0x289b('0x6c')],_['omit'](_0x46929f['body'],[_0x289b('0x6c'),'id'])||{})['spread'](function(_0x46789f){for(var _0x2f75f8=0x0;_0x2f75f8<_0x46929f['body'][_0x289b('0x6c')][_0x289b('0x59')];_0x2f75f8+=0x1){socket[_0x289b('0xad')](_0x289b('0xae'),{'UserId':Number(_0x46929f['body']['ids'][_0x2f75f8]),'OpenchannelAccountId':Number(_0x46929f[_0x289b('0x58')]['id'])});}return _0x46789f;});}})[_0x289b('0x21')](respondWithResult(_0x37683d,null))[_0x289b('0x2a')](handleError(_0x37683d,null));};exports[_0x289b('0xaf')]=function(_0x75c67e,_0x1e1a0c,_0x318c1f){return db['OpenchannelAccount'][_0x289b('0x5b')]({'where':{'id':_0x75c67e[_0x289b('0x58')]['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x1e1a0c,null))[_0x289b('0x21')](function(_0x18beee){if(_0x18beee){return _0x18beee[_0x289b('0xaf')](_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')])['then'](function(){if(_['isArray'](_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')])){for(var _0x5e2552=0x0;_0x5e2552<_0x75c67e[_0x289b('0x44')]['ids']['length'];_0x5e2552+=0x1){socket[_0x289b('0xad')]('userOpenchannelAccount:remove',{'UserId':Number(_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')][_0x5e2552]),'OpenchannelAccountId':Number(_0x75c67e[_0x289b('0x58')]['id'])});}}else{socket[_0x289b('0xad')](_0x289b('0xb0'),{'UserId':Number(_0x75c67e[_0x289b('0x44')][_0x289b('0x6c')]),'OpenchannelAccountId':Number(_0x75c67e[_0x289b('0x58')]['id'])});}});}})[_0x289b('0x21')](respondWithStatusCode(_0x1e1a0c,null))[_0x289b('0x2a')](handleError(_0x1e1a0c,null));};exports[_0x289b('0xb1')]=function(_0x3033f1,_0x5d8aeb,_0x49a0dd){var _0x4b9271={};var _0x276e97={};var _0x2d91ed;var _0x3895fe;return db['OpenchannelAccount'][_0x289b('0x69')]({'where':{'id':_0x3033f1['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x5d8aeb,null))[_0x289b('0x21')](function(_0xdcaa40){if(_0xdcaa40){_0x2d91ed=_0xdcaa40;_0x276e97[_0x289b('0x43')]=_[_0x289b('0x45')](db[_0x289b('0x98')]['rawAttributes']);_0x276e97[_0x289b('0x44')]=_[_0x289b('0x45')](_0x3033f1['query']);_0x276e97[_0x289b('0x4e')]=_['intersection'](_0x276e97[_0x289b('0x43')],_0x276e97[_0x289b('0x44')]);_0x4b9271['attributes']=_[_0x289b('0x46')](_0x276e97[_0x289b('0x43')],qs[_0x289b('0x48')](_0x3033f1[_0x289b('0x44')][_0x289b('0x48')]));_0x4b9271[_0x289b('0x47')]=_0x4b9271[_0x289b('0x47')][_0x289b('0x59')]?_0x4b9271[_0x289b('0x47')]:_0x276e97[_0x289b('0x43')];_0x4b9271[_0x289b('0x4a')]=qs['sort'](_0x3033f1['query'][_0x289b('0x4b')]);_0x4b9271[_0x289b('0x4c')]=qs[_0x289b('0x4e')](_['pick'](_0x3033f1['query'],_0x276e97['filters']));if(_0x3033f1[_0x289b('0x44')][_0x289b('0x4f')]){_0x4b9271['where']=_[_0x289b('0x50')](_0x4b9271[_0x289b('0x4c')],{'$or':_['map'](_0x4b9271[_0x289b('0x47')],function(_0x378c94){var _0x40f8a9={};_0x40f8a9[_0x378c94]={'$like':'%'+_0x3033f1['query'][_0x289b('0x4f')]+'%'};return _0x40f8a9;})});}_0x4b9271=_[_0x289b('0x50')]({},_0x4b9271,_0x3033f1['options']);return _0x2d91ed[_0x289b('0xb1')](_0x4b9271);}})[_0x289b('0x21')](function(_0x196c44){if(_0x196c44){_0x3895fe=_0x196c44[_0x289b('0x59')];if(!_0x3033f1['query']['hasOwnProperty'](_0x289b('0x6e'))){_0x4b9271[_0x289b('0x30')]=qs[_0x289b('0x30')](_0x3033f1[_0x289b('0x44')][_0x289b('0x30')]);_0x4b9271[_0x289b('0x32')]=qs[_0x289b('0x32')](_0x3033f1[_0x289b('0x44')][_0x289b('0x32')]);}return _0x2d91ed[_0x289b('0xb1')](_0x4b9271);}})[_0x289b('0x21')](function(_0x55d7bc){if(_0x55d7bc){return _0x55d7bc?{'count':_0x3895fe,'rows':_0x55d7bc}:null;}})['then'](respondWithResult(_0x5d8aeb,null))[_0x289b('0x2a')](handleError(_0x5d8aeb,null));};exports[_0x289b('0xb2')]=function(_0x5ae118,_0x5e9267,_0x37269a){var _0x3db392,_0x450043,_0x3225d9;if(_[_0x289b('0x79')](_0x5ae118[_0x289b('0x63')][_0x289b('0x63')])||_0x5ae118[_0x289b('0x63')][_0x289b('0x63')]===''){throw new db[(_0x289b('0x73'))][(_0x289b('0x74'))](_0x289b('0x7b'));}if(_[_0x289b('0x79')](_0x5ae118['body']['to'])){}_0x3db392=_0x5ae118['body']['to'];return db[_0x289b('0x53')]['findOne']({'where':{'id':_0x5ae118['params']['id']}})[_0x289b('0x21')](handleEntityNotFound(_0x5e9267,null))['then'](function(_0x5b73be){if(_0x5b73be){return db[_0x289b('0x53')][_0x289b('0x5b')]({'where':{'id':_0x5b73be['id']},'include':[{'model':db[_0x289b('0x7f')],'as':_0x289b('0x80'),'include':[{'model':db['CmContact'],'as':_0x289b('0x81'),'where':{[_0x5b73be[_0x289b('0x7c')]]:_0x3db392},'limit':0x1,'order':[[_0x289b('0xb3'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x5e9267,null))[_0x289b('0x21')](function(_0x43981a){if(_0x43981a&&_0x43981a[_0x289b('0x80')]){_0x450043=_0x43981a[_0x289b('0x39')]({'plain':!![]});if(_0x450043[_0x289b('0x80')]&&_0x450043[_0x289b('0x80')][_0x289b('0x81')]['length']){return _0x450043[_0x289b('0x80')][_0x289b('0x81')][0x0];}return db[_0x289b('0x72')][_0x289b('0x5c')](_[_0x289b('0x17')](_0x5ae118[_0x289b('0x63')],{'firstName':_0x3db392,[_0x43981a[_0x289b('0x7c')]]:_0x3db392,'phone':_0x3db392,'ListId':_0x450043[_0x289b('0x78')]}));}})[_0x289b('0x21')](handleEntityNotFound(_0x5e9267,null))[_0x289b('0x21')](function(_0x391b34){if(_0x391b34){_0x3225d9=_0x391b34;return db['OpenchannelInteraction'][_0x289b('0x5b')]({'where':{'ContactId':_0x3225d9['id'],'closed':![],'OpenchannelAccountId':_0x450043['id']}})[_0x289b('0x21')](function(_0x2062aa){if(_0x2062aa){return[_0x2062aa,![]];}return db['OpenchannelInteraction']['create']({'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id'],'OpenchannelAccountId':_0x450043['id'],'lastMsgDirection':_0x289b('0xb4'),'firstMsgDirection':_0x289b('0xb4'),'Messages':[_['merge'](_0x5ae118['body'],{'read':![],'body':_0x5ae118['body']['body'],'OpenchannelAccountId':_0x450043['id'],'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id']})]},{'include':[{'model':db[_0x289b('0x97')],'as':'Messages'}]})[_0x289b('0x21')](function(_0x5a93d4){return[_0x5a93d4,!![]];});});}})['spread'](function(_0x3bb6dd,_0x303876){if(_0x303876){return _0x3bb6dd;}return db[_0x289b('0x97')][_0x289b('0x5c')](_['merge'](_0x5ae118['body'],{'read':![],'body':_0x5ae118[_0x289b('0x63')][_0x289b('0x63')],'OpenchannelAccountId':_0x450043['id'],'OpenchannelInteractionId':_0x3bb6dd['id'],'UserId':_0x5ae118[_0x289b('0x5d')]['id'],'ContactId':_0x3225d9['id']}))[_0x289b('0x21')](function(_0x190816){_0x3bb6dd[_0x289b('0xb5')][_0x289b('0xb6')]=[];_0x3bb6dd[_0x289b('0xb5')]['Messages']['push'](_0x190816[_0x289b('0xb5')]);return _0x3bb6dd;});});}})[_0x289b('0x21')](respondWithResult(_0x5e9267,null))['catch'](handleError(_0x5e9267,null));};
\ No newline at end of file