Built motion from commit 52c8a02d.|2.6.29
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index df0f653..4d944dd 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf0c2=['show','rawAttributes','length','includeAll','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','destroy','describe','addDisposition','findOne','Disposition','OpenchannelAccountId','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','order','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','updatedAt','difference','createdAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','DESC','OpenchannelApplication','account','Applications','list','applications','orderBy','priority','asc','Contacts','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','AttachmentId','User','UserId','unshift','waitForTheAssignedAgent','queueId','queue','waitForTheAssignedQueue','Start','startRouting','EventManager','sequelize','transaction','Transaction','ISOLATION_LEVELS','bulkCreate','findAndCountAll','getApplications','getInteractions','Owner','fullname','internal','Tag','Tags','tag','addAgents','omit','userOpenchannelAccount:save','removeAgents','isArray','emit','userOpenchannelAccount:remove','getAgents','Messages','dataValues','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./openchannelAccount.socket','register','jayson/promise','client','http','request','then','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','status','end','json','offset','undefined','count','set','Content-Range','apply','reject','save','update','get','OpenchannelAccounts','sendStatus','stack','name','send','Pause','mandatoryDispositionPause','OpenchannelAccount','fieldName','type','key','map','query','keys','filters','model','attributes','intersection','fields','hasOwnProperty','nolimit','limit','sort','where','pick','merge','VIRTUAL','filter','include','findAll','rows','catch'];(function(_0x559cca,_0x477765){var _0x228ba1=function(_0x1e2aea){while(--_0x1e2aea){_0x559cca['push'](_0x559cca['shift']());}};_0x228ba1(++_0x477765);}(_0xf0c2,0x6e));var _0x2f0c=function(_0x156d15,_0x2c22b4){_0x156d15=_0x156d15-0x0;var _0x6fe3fb=_0xf0c2[_0x156d15];return _0x6fe3fb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x2f0c('0x0'));var zipdir=require(_0x2f0c('0x1'));var jsonpatch=require(_0x2f0c('0x2'));var rp=require(_0x2f0c('0x3'));var moment=require(_0x2f0c('0x4'));var BPromise=require(_0x2f0c('0x5'));var Mustache=require(_0x2f0c('0x6'));var util=require(_0x2f0c('0x7'));var path=require(_0x2f0c('0x8'));var sox=require(_0x2f0c('0x9'));var csv=require(_0x2f0c('0xa'));var ejs=require(_0x2f0c('0xb'));var fs=require('fs');var fs_extra=require(_0x2f0c('0xc'));var _=require('lodash');var squel=require(_0x2f0c('0xd'));var crypto=require(_0x2f0c('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x2f0c('0xf'));var toCsv=require(_0x2f0c('0xa'));var querystring=require(_0x2f0c('0x10'));var Papa=require(_0x2f0c('0x11'));var Redis=require(_0x2f0c('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x2f0c('0x13'));var as=require(_0x2f0c('0x14'));var hardwareService=require(_0x2f0c('0x15'));var logger=require(_0x2f0c('0x16'))(_0x2f0c('0x17'));var utils=require(_0x2f0c('0x18'));var config=require(_0x2f0c('0x19'));var licenseUtil=require(_0x2f0c('0x1a'));var db=require(_0x2f0c('0x1b'))['db'];config[_0x2f0c('0x1c')]=_[_0x2f0c('0x1d')](config[_0x2f0c('0x1c')],{'host':_0x2f0c('0x1e'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x2f0c('0x1f'))[_0x2f0c('0x20')](socket);var jayson=require(_0x2f0c('0x21'));var client=jayson[_0x2f0c('0x22')]['http']({'port':0x232c});var client9002=jayson[_0x2f0c('0x22')][_0x2f0c('0x23')]({'port':0x232a});function respondWithRpcPromise(_0xa3f8e2,_0x31ab32,_0xd8f935,_0x4976e4){return new BPromise(function(_0x3612bb,_0xa16ab){var _0x5dad52=_0x4976e4||client;return _0x5dad52[_0x2f0c('0x24')](_0xa3f8e2,_0xd8f935)[_0x2f0c('0x25')](function(_0x5219e9){logger['info'](_0x2f0c('0x26'),_0x31ab32,_0x2f0c('0x27'));logger[_0x2f0c('0x28')](_0x2f0c('0x29'),_0x31ab32,_0x2f0c('0x27'),JSON[_0x2f0c('0x2a')](_0x5219e9));if(_0x5219e9[_0x2f0c('0x2b')]){if(_0x5219e9[_0x2f0c('0x2b')][_0x2f0c('0x2c')]===0x1f4){logger[_0x2f0c('0x2b')](_0x2f0c('0x26'),_0x31ab32,_0x5219e9[_0x2f0c('0x2b')][_0x2f0c('0x2d')]);return _0xa16ab(_0x5219e9['error'][_0x2f0c('0x2d')]);}logger[_0x2f0c('0x2b')]('OpenchannelAccount,\x20%s,\x20%s',_0x31ab32,_0x5219e9['error'][_0x2f0c('0x2d')]);return _0x3612bb(_0x5219e9[_0x2f0c('0x2b')][_0x2f0c('0x2d')]);}else{logger[_0x2f0c('0x2e')](_0x2f0c('0x26'),_0x31ab32,_0x2f0c('0x27'));_0x3612bb(_0x5219e9[_0x2f0c('0x2f')][_0x2f0c('0x2d')]);}})['catch'](function(_0x2d9053){logger['error'](_0x2f0c('0x26'),_0x31ab32,_0x2d9053);_0xa16ab(_0x2d9053);});});}function respondWithStatusCode(_0x3b48b7,_0x337f8e){_0x337f8e=_0x337f8e||0xcc;return function(_0x3b8e02){if(_0x3b8e02){return _0x3b48b7['sendStatus'](_0x337f8e);}return _0x3b48b7[_0x2f0c('0x30')](_0x337f8e)[_0x2f0c('0x31')]();};}function respondWithResult(_0x9b9273,_0x3edbc2){_0x3edbc2=_0x3edbc2||0xc8;return function(_0x5a11f2){if(_0x5a11f2){return _0x9b9273['status'](_0x3edbc2)[_0x2f0c('0x32')](_0x5a11f2);}};}function respondWithFilteredResult(_0x415c7a,_0x41a4f1){return function(_0x25c683){if(_0x25c683){var _0x1c5638=typeof _0x41a4f1[_0x2f0c('0x33')]===_0x2f0c('0x34')&&typeof _0x41a4f1['limit']===_0x2f0c('0x34');var _0x145441=_0x25c683[_0x2f0c('0x35')];var _0x4f3a99=_0x1c5638?0x0:_0x41a4f1[_0x2f0c('0x33')];var _0xaa2b97=_0x1c5638?_0x25c683[_0x2f0c('0x35')]:_0x41a4f1[_0x2f0c('0x33')]+_0x41a4f1['limit'];var _0x1cea58;if(_0xaa2b97>=_0x145441){_0xaa2b97=_0x145441;_0x1cea58=0xc8;}else{_0x1cea58=0xce;}_0x415c7a['status'](_0x1cea58);return _0x415c7a[_0x2f0c('0x36')](_0x2f0c('0x37'),_0x4f3a99+'-'+_0xaa2b97+'/'+_0x145441)[_0x2f0c('0x32')](_0x25c683);}return null;};}function patchUpdates(_0x219374){return function(_0x179906){try{jsonpatch[_0x2f0c('0x38')](_0x179906,_0x219374,!![]);}catch(_0x56a77e){return BPromise[_0x2f0c('0x39')](_0x56a77e);}return _0x179906[_0x2f0c('0x3a')]();};}function saveUpdates(_0x46ecba,_0x249cad){return function(_0x5d061f){if(_0x5d061f){return _0x5d061f[_0x2f0c('0x3b')](_0x46ecba)[_0x2f0c('0x25')](function(_0x4a4411){return _0x4a4411;});}return null;};}function removeEntity(_0x198e7f,_0x333561){return function(_0xf9dab8){if(_0xf9dab8){return _0xf9dab8['destroy']()[_0x2f0c('0x25')](function(){var _0x32db77=_0xf9dab8[_0x2f0c('0x3c')]({'plain':!![]});var _0x505936=_0x2f0c('0x3d');return db['UserProfileResource']['destroy']({'where':{'type':_0x505936,'resourceId':_0x32db77['id']}})['then'](function(){return _0xf9dab8;});})[_0x2f0c('0x25')](function(){_0x198e7f['status'](0xcc)[_0x2f0c('0x31')]();});}};}function handleEntityNotFound(_0x5d5fd9,_0x364f90){return function(_0x437816){if(!_0x437816){_0x5d5fd9[_0x2f0c('0x3e')](0x194);}return _0x437816;};}function handleError(_0x52f223,_0x2105ad){_0x2105ad=_0x2105ad||0x1f4;return function(_0x1d3600){logger[_0x2f0c('0x2b')](_0x1d3600[_0x2f0c('0x3f')]);if(_0x1d3600['name']){delete _0x1d3600[_0x2f0c('0x40')];}_0x52f223[_0x2f0c('0x30')](_0x2105ad)[_0x2f0c('0x41')](_0x1d3600);};}exports['index']=function(_0x43e5d8,_0x59cd57){var _0x268de4={'include':[{'model':db[_0x2f0c('0x42')],'as':_0x2f0c('0x43')}]},_0x7235bd={},_0x2854d8={'count':0x0,'rows':[]};var _0x41010d=_['map'](db[_0x2f0c('0x44')]['rawAttributes'],function(_0x1fd4da){return{'name':_0x1fd4da[_0x2f0c('0x45')],'type':_0x1fd4da[_0x2f0c('0x46')][_0x2f0c('0x47')]};});_0x7235bd['model']=_[_0x2f0c('0x48')](_0x41010d,_0x2f0c('0x40'));_0x7235bd[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x43e5d8[_0x2f0c('0x49')]);_0x7235bd[_0x2f0c('0x4b')]=_['intersection'](_0x7235bd[_0x2f0c('0x4c')],_0x7235bd[_0x2f0c('0x49')]);_0x268de4[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x7235bd[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x268de4[_0x2f0c('0x4d')]=_0x268de4[_0x2f0c('0x4d')]['length']?_0x268de4[_0x2f0c('0x4d')]:_0x7235bd['model'];if(!_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x268de4['limit']=qs['limit'](_0x43e5d8['query'][_0x2f0c('0x52')]);_0x268de4[_0x2f0c('0x33')]=qs[_0x2f0c('0x33')](_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x268de4['order']=qs[_0x2f0c('0x53')](_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x268de4[_0x2f0c('0x54')]=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x43e5d8['query'],_0x7235bd['filters']),_0x41010d);if(_0x43e5d8[_0x2f0c('0x49')]['filter']){_0x268de4[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x268de4[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x41010d,function(_0x4bbec7){if(_0x4bbec7[_0x2f0c('0x46')]!==_0x2f0c('0x57')){var _0x476c47={};_0x476c47[_0x4bbec7['name']]={'$like':'%'+_0x43e5d8[_0x2f0c('0x49')][_0x2f0c('0x58')]+'%'};return _0x476c47;}})});}_0x268de4=_[_0x2f0c('0x56')]({},_0x268de4,_0x43e5d8['options']);var _0xf344db={'where':_0x268de4[_0x2f0c('0x54')]};return db[_0x2f0c('0x44')][_0x2f0c('0x35')](_0xf344db)['then'](function(_0x192398){_0x2854d8[_0x2f0c('0x35')]=_0x192398;if(_0x43e5d8[_0x2f0c('0x49')]['includeAll']){_0x268de4[_0x2f0c('0x59')]=[{'all':!![]}];}return db[_0x2f0c('0x44')][_0x2f0c('0x5a')](_0x268de4);})[_0x2f0c('0x25')](function(_0x23456a){_0x2854d8[_0x2f0c('0x5b')]=_0x23456a;return _0x2854d8;})[_0x2f0c('0x25')](respondWithFilteredResult(_0x59cd57,_0x268de4))[_0x2f0c('0x5c')](handleError(_0x59cd57,null));};exports[_0x2f0c('0x5d')]=function(_0x307db2,_0x426937){var _0x56224d={'raw':![],'where':{'id':_0x307db2['params']['id']},'include':[{'model':db['Pause'],'as':_0x2f0c('0x43')}]},_0x3bb5e8={};_0x3bb5e8['model']=_[_0x2f0c('0x4a')](db[_0x2f0c('0x44')][_0x2f0c('0x5e')]);_0x3bb5e8[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x307db2[_0x2f0c('0x49')]);_0x3bb5e8[_0x2f0c('0x4b')]=_['intersection'](_0x3bb5e8['model'],_0x3bb5e8[_0x2f0c('0x49')]);_0x56224d[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x3bb5e8[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x307db2[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x56224d[_0x2f0c('0x4d')]=_0x56224d['attributes'][_0x2f0c('0x5f')]?_0x56224d['attributes']:_0x3bb5e8[_0x2f0c('0x4c')];if(_0x307db2[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x56224d[_0x2f0c('0x59')]=[{'all':!![]}];}_0x56224d=_[_0x2f0c('0x56')]({},_0x56224d,_0x307db2[_0x2f0c('0x61')]);return db[_0x2f0c('0x44')][_0x2f0c('0x62')](_0x56224d)[_0x2f0c('0x25')](handleEntityNotFound(_0x426937,null))[_0x2f0c('0x25')](respondWithResult(_0x426937,null))['catch'](handleError(_0x426937,null));};exports[_0x2f0c('0x63')]=function(_0x265990,_0x2a642f){return db['OpenchannelAccount'][_0x2f0c('0x63')](_0x265990[_0x2f0c('0x64')],{})[_0x2f0c('0x25')](function(_0x5172ce){var _0x2fb525=_0x265990[_0x2f0c('0x65')][_0x2f0c('0x3c')]({'plain':!![]});if(!_0x2fb525)throw new Error(_0x2f0c('0x66'));if(_0x2fb525[_0x2f0c('0x67')]==='user'){var _0x11ac63=_0x5172ce['get']({'plain':!![]});var _0x4cf475=_0x2f0c('0x3d');return db[_0x2f0c('0x68')][_0x2f0c('0x62')]({'where':{'name':_0x4cf475,'userProfileId':_0x2fb525['userProfileId']},'raw':!![]})[_0x2f0c('0x25')](function(_0x2e6592){if(_0x2e6592&&_0x2e6592[_0x2f0c('0x69')]===0x0){return db['UserProfileResource']['create']({'name':_0x11ac63[_0x2f0c('0x40')],'resourceId':_0x11ac63['id'],'type':_0x2e6592[_0x2f0c('0x40')],'sectionId':_0x2e6592['id']},{})['then'](function(){return _0x5172ce;});}else{return _0x5172ce;}})[_0x2f0c('0x5c')](function(_0x292755){logger['error'](_0x2f0c('0x6a'),_0x292755);throw _0x292755;});}return _0x5172ce;})['then'](respondWithResult(_0x2a642f,0xc9))[_0x2f0c('0x5c')](handleError(_0x2a642f,null));};exports[_0x2f0c('0x3b')]=function(_0x5a5cd8,_0x124e8d){if(_0x5a5cd8[_0x2f0c('0x64')]['id']){delete _0x5a5cd8[_0x2f0c('0x64')]['id'];}return db['OpenchannelAccount'][_0x2f0c('0x62')]({'where':{'id':_0x5a5cd8[_0x2f0c('0x6b')]['id']},'include':[{'model':db['Pause'],'as':_0x2f0c('0x43')}]})[_0x2f0c('0x25')](handleEntityNotFound(_0x124e8d,null))[_0x2f0c('0x25')](saveUpdates(_0x5a5cd8[_0x2f0c('0x64')],null))[_0x2f0c('0x25')](respondWithResult(_0x124e8d,null))[_0x2f0c('0x5c')](handleError(_0x124e8d,null));};exports[_0x2f0c('0x6c')]=function(_0x54394b,_0x207028){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x54394b['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x207028,null))['then'](removeEntity(_0x207028,null))[_0x2f0c('0x5c')](handleError(_0x207028,null));};exports['describe']=function(_0x39f479,_0x38f855){return db[_0x2f0c('0x44')][_0x2f0c('0x6d')]()[_0x2f0c('0x25')](respondWithResult(_0x38f855,null))['catch'](handleError(_0x38f855,null));};exports[_0x2f0c('0x6e')]=function(_0x56b5e6,_0x5dde71,_0x1cbafc){if(_0x56b5e6[_0x2f0c('0x64')]['id']){delete _0x56b5e6[_0x2f0c('0x64')]['id'];}return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x56b5e6[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x5dde71,null))['then'](function(_0x54b213){if(_0x54b213){_0x56b5e6[_0x2f0c('0x64')]['OpenchannelAccountId']=_0x54b213['id'];return db['Disposition'][_0x2f0c('0x63')](_0x56b5e6[_0x2f0c('0x64')]);}})[_0x2f0c('0x25')](respondWithResult(_0x5dde71,null))[_0x2f0c('0x5c')](handleError(_0x5dde71,null));};exports['getDispositions']=function(_0x2edf98,_0x4bb7b0,_0x5669e5){var _0x411077={'raw':![],'where':{}};var _0x451ea9={};var _0x34e03d={'count':0x0,'rows':[]};return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x2edf98[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x4bb7b0,null))[_0x2f0c('0x25')](function(_0x4a5488){if(_0x4a5488){_0x451ea9[_0x2f0c('0x4c')]=_['keys'](db[_0x2f0c('0x70')][_0x2f0c('0x5e')]);_0x451ea9[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x2edf98[_0x2f0c('0x49')]);_0x451ea9[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0x451ea9[_0x2f0c('0x4c')],_0x451ea9['query']);_0x411077['attributes']=_[_0x2f0c('0x4e')](_0x451ea9[_0x2f0c('0x4c')],qs['fields'](_0x2edf98['query'][_0x2f0c('0x4f')]));_0x411077['attributes']=_0x411077[_0x2f0c('0x4d')]['length']?_0x411077[_0x2f0c('0x4d')]:_0x451ea9[_0x2f0c('0x4c')];if(!_0x2edf98[_0x2f0c('0x49')]['hasOwnProperty']('nolimit')){_0x411077['limit']=qs[_0x2f0c('0x52')](_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x52')]);_0x411077['offset']=qs['offset'](_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x411077['order']=qs[_0x2f0c('0x53')](_0x2edf98['query'][_0x2f0c('0x53')]);_0x411077[_0x2f0c('0x54')]=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x2edf98['query'],_0x451ea9[_0x2f0c('0x4b')]));_0x411077['where'][_0x2f0c('0x71')]=_0x4a5488['id'];if(_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x411077[_0x2f0c('0x54')]=_['merge'](_0x411077['where'],{'$or':_['map'](_0x411077['attributes'],function(_0xb016bb){var _0x33e6bf={};_0x33e6bf[_0xb016bb]={'$like':'%'+_0x2edf98['query'][_0x2f0c('0x58')]+'%'};return _0x33e6bf;})});}_0x411077=_[_0x2f0c('0x56')]({},_0x411077,_0x2edf98[_0x2f0c('0x61')]);return db[_0x2f0c('0x70')][_0x2f0c('0x35')]({'where':_0x411077[_0x2f0c('0x54')]})[_0x2f0c('0x25')](function(_0x1d3734){_0x34e03d[_0x2f0c('0x35')]=_0x1d3734;if(_0x2edf98[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x411077[_0x2f0c('0x59')]=[{'all':!![]}];}return db[_0x2f0c('0x70')][_0x2f0c('0x5a')](_0x411077);})[_0x2f0c('0x25')](function(_0x1747f5){_0x34e03d[_0x2f0c('0x5b')]=_0x1747f5;return _0x34e03d;});}})['then'](respondWithFilteredResult(_0x4bb7b0,_0x411077))[_0x2f0c('0x5c')](handleError(_0x4bb7b0,null));};exports[_0x2f0c('0x72')]=function(_0x286b79,_0x4668d9,_0x672730){return db[_0x2f0c('0x44')]['find']({'where':{'id':_0x286b79[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x4668d9,null))[_0x2f0c('0x25')](function(_0x568f28){if(_0x568f28){return _0x568f28[_0x2f0c('0x72')](_0x286b79[_0x2f0c('0x49')][_0x2f0c('0x73')]);}})[_0x2f0c('0x25')](respondWithStatusCode(_0x4668d9,null))['catch'](handleError(_0x4668d9,null));};exports[_0x2f0c('0x74')]=function(_0x298f10,_0x146db1,_0x26d8e9){if(_0x298f10[_0x2f0c('0x64')]['id']){delete _0x298f10[_0x2f0c('0x64')]['id'];}return db[_0x2f0c('0x44')]['find']({'where':{'id':_0x298f10[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x146db1,null))[_0x2f0c('0x25')](function(_0x3420d5){if(_0x3420d5){_0x298f10[_0x2f0c('0x64')][_0x2f0c('0x71')]=_0x3420d5['id'];return db[_0x2f0c('0x75')][_0x2f0c('0x63')](_0x298f10[_0x2f0c('0x64')]);}})[_0x2f0c('0x25')](respondWithResult(_0x146db1,null))[_0x2f0c('0x5c')](handleError(_0x146db1,null));};exports[_0x2f0c('0x76')]=function(_0x3c7018,_0x42d367,_0x57aad0){var _0x18f7e0={'raw':![],'where':{}};var _0xe8a96c={};var _0x524d5f={'count':0x0,'rows':[]};return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x3c7018[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x42d367,null))[_0x2f0c('0x25')](function(_0x2e1efb){if(_0x2e1efb){_0xe8a96c[_0x2f0c('0x4c')]=_[_0x2f0c('0x4a')](db[_0x2f0c('0x75')]['rawAttributes']);_0xe8a96c[_0x2f0c('0x49')]=_['keys'](_0x3c7018[_0x2f0c('0x49')]);_0xe8a96c[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0xe8a96c[_0x2f0c('0x4c')],_0xe8a96c[_0x2f0c('0x49')]);_0x18f7e0['attributes']=_['intersection'](_0xe8a96c[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x18f7e0[_0x2f0c('0x4d')]=_0x18f7e0[_0x2f0c('0x4d')]['length']?_0x18f7e0[_0x2f0c('0x4d')]:_0xe8a96c[_0x2f0c('0x4c')];if(!_0x3c7018['query'][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x18f7e0['limit']=qs[_0x2f0c('0x52')](_0x3c7018[_0x2f0c('0x49')]['limit']);_0x18f7e0['offset']=qs[_0x2f0c('0x33')](_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x18f7e0[_0x2f0c('0x77')]=qs[_0x2f0c('0x53')](_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x18f7e0['where']=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x3c7018[_0x2f0c('0x49')],_0xe8a96c[_0x2f0c('0x4b')]));_0x18f7e0[_0x2f0c('0x54')]['OpenchannelAccountId']=_0x2e1efb['id'];if(_0x3c7018[_0x2f0c('0x49')]['filter']){_0x18f7e0[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x18f7e0[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x18f7e0[_0x2f0c('0x4d')],function(_0x5772e){var _0x22a1bc={};_0x22a1bc[_0x5772e]={'$like':'%'+_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x58')]+'%'};return _0x22a1bc;})});}_0x18f7e0=_[_0x2f0c('0x56')]({},_0x18f7e0,_0x3c7018[_0x2f0c('0x61')]);return db['CannedAnswer']['count']({'where':_0x18f7e0[_0x2f0c('0x54')]})[_0x2f0c('0x25')](function(_0x1c673f){_0x524d5f[_0x2f0c('0x35')]=_0x1c673f;if(_0x3c7018[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x18f7e0[_0x2f0c('0x59')]=[{'all':!![]}];}return db[_0x2f0c('0x75')]['findAll'](_0x18f7e0);})[_0x2f0c('0x25')](function(_0x3e0952){_0x524d5f[_0x2f0c('0x5b')]=_0x3e0952;return _0x524d5f;});}})[_0x2f0c('0x25')](respondWithFilteredResult(_0x42d367,_0x18f7e0))['catch'](handleError(_0x42d367,null));};exports[_0x2f0c('0x78')]=function(_0x585f39,_0x3e3363,_0x2a84ab){return db[_0x2f0c('0x44')]['find']({'where':{'id':_0x585f39[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x3e3363,null))[_0x2f0c('0x25')](function(_0x4e2a56){if(_0x4e2a56){return _0x4e2a56[_0x2f0c('0x78')](_0x585f39[_0x2f0c('0x49')][_0x2f0c('0x73')]);}})[_0x2f0c('0x25')](respondWithStatusCode(_0x3e3363,null))[_0x2f0c('0x5c')](handleError(_0x3e3363,null));};exports[_0x2f0c('0x79')]=function(_0x5611ae,_0x50b430,_0x5a00e9){var _0x4f99d4={'body':_0x5611ae[_0x2f0c('0x64')],'channel':_0x2f0c('0x7a')};var _0x31e28e=[];var _0xefd0bd=[];var _0x521d5d={};var _0x2d814a=![];return db[_0x2f0c('0x7b')][_0x2f0c('0x6d')]()['then'](function(_0x505616){if(!_0x505616){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))](_0x2f0c('0x7e'));}_0x31e28e=_['difference'](_['keys'](_0x505616),['createdAt',_0x2f0c('0x7f')]);_0xefd0bd=_[_0x2f0c('0x80')](_[_0x2f0c('0x4a')](_0x505616),[_0x2f0c('0x81'),_0x2f0c('0x7f'),_0x2f0c('0x82'),_0x2f0c('0x83')]);if(_0x5611ae[_0x2f0c('0x64')]['id']){delete _0x5611ae[_0x2f0c('0x64')]['id'];}if(_[_0x2f0c('0x84')](_0x5611ae['body'][_0x2f0c('0x85')])){throw new db[(_0x2f0c('0x7c'))]['ValidationError'](_0x2f0c('0x86'));}if(_[_0x2f0c('0x84')](_0x5611ae['body'][_0x2f0c('0x64')])||_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x64')]===''){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2f0c('0x84')](_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x87')])){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))](_0x2f0c('0x88')+_0xefd0bd);}if(!_[_0x2f0c('0x89')](_0xefd0bd,_0x5611ae[_0x2f0c('0x64')]['mapKey'])){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))](_0x2f0c('0x8a')+_0xefd0bd);}_0x521d5d[_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x87')]]=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x85')];})['then'](function(){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x5611ae[_0x2f0c('0x6b')]['id']},'include':[{'model':db[_0x2f0c('0x8b')],'as':_0x2f0c('0x8c'),'include':[{'model':db[_0x2f0c('0x7b')],'as':'Contacts','where':_0x521d5d,'limit':0x1,'order':[[_0x2f0c('0x7f'),_0x2f0c('0x8d')]]}]},{'model':db[_0x2f0c('0x8e')],'as':'Applications'}]});})[_0x2f0c('0x25')](handleEntityNotFound(_0x50b430,null))[_0x2f0c('0x25')](function(_0x46f88d){if(_0x46f88d&&_0x46f88d['List']){_0x4f99d4[_0x2f0c('0x8f')]=_0x46f88d;_0x4f99d4['applications']=_0x46f88d[_0x2f0c('0x90')];_0x4f99d4[_0x2f0c('0x91')]=_0x46f88d['List'];_0x4f99d4[_0x2f0c('0x92')]=_[_0x2f0c('0x93')](_0x4f99d4[_0x2f0c('0x92')],[_0x2f0c('0x94')],[_0x2f0c('0x95')]);if(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x90')]){delete _0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x90')];}if(_0x4f99d4['account'][_0x2f0c('0x8c')]&&_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x8c')][_0x2f0c('0x96')][_0x2f0c('0x5f')]){return _0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0x8c')][_0x2f0c('0x96')][0x0];}var _0x1cd5cd=_[_0x2f0c('0x1d')](_0x5611ae[_0x2f0c('0x64')],{'firstName':_0x5611ae['body'][_0x2f0c('0x85')],'ListId':_0x46f88d[_0x2f0c('0x83')]});_0x1cd5cd[_0x5611ae[_0x2f0c('0x64')]['mapKey']]=_0x5611ae['body'][_0x2f0c('0x85')];return db[_0x2f0c('0x7b')][_0x2f0c('0x63')](_0x1cd5cd,{'fields':_0x31e28e,'raw':!![]});}})['then'](handleEntityNotFound(_0x50b430,null))['then'](function(_0xc523f2){_0x4f99d4[_0x2f0c('0x97')]=_0xc523f2;if(_0xc523f2){var _0x52d8d2={'ContactId':_0xc523f2['id'],'OpenchannelAccountId':_0x5611ae['params']['id'],'from':(_0xc523f2[_0x2f0c('0x98')]||'')+'\x20'+(_0xc523f2[_0x2f0c('0x99')]||'')};var _0x2781dd={'OpenchannelAccountId':_0x5611ae['params']['id'],'closed':![]};if(_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9a')]){_0x2781dd[_0x2f0c('0x9a')]=_0x5611ae['body'][_0x2f0c('0x9a')];return db[_0x2f0c('0x9b')][_0x2f0c('0x62')]({'where':_0x2781dd})['then'](function(_0x552a66){if(_0x552a66){return[_0x552a66,![]];}_0x52d8d2['threadId']=_0x5611ae[_0x2f0c('0x64')]['threadId'];_0x52d8d2[_0x2f0c('0x9c')]=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9c')];return db[_0x2f0c('0x9b')][_0x2f0c('0x63')](_0x52d8d2)[_0x2f0c('0x25')](function(_0x1bbcdb){return[_0x1bbcdb,!![]];});});}else{_0x2781dd[_0x2f0c('0x9a')]=null;}_0x2781dd[_0x2f0c('0x9d')]=_0xc523f2['id'];return db['OpenchannelInteraction']['find']({'where':_0x2781dd})[_0x2f0c('0x25')](function(_0x561527){if(_0x561527){return[_0x561527,![]];}return db[_0x2f0c('0x9b')]['create'](_0x52d8d2)[_0x2f0c('0x25')](function(_0x24b3a3){return[_0x24b3a3,!![]];});});}})[_0x2f0c('0x9e')](function(_0x3234c5,_0x444c69){if(_0x3234c5){_0x2d814a=_0x444c69;if(!_0x444c69){var _0x2148f5={'from':(_0x4f99d4[_0x2f0c('0x97')][_0x2f0c('0x98')]||'')+'\x20'+(_0x4f99d4['contact'][_0x2f0c('0x99')]||'')};if(_0x5611ae['body']['threadId']&&_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9f')]&&_0x5611ae['body'][_0x2f0c('0x9a')]!=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9f')]){_0x2148f5['threadId']=_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x9f')];}return _0x3234c5[_0x2f0c('0x3b')](_0x2148f5);}else{return _0x3234c5;}}})[_0x2f0c('0x25')](function(_0x209dce){_0x4f99d4[_0x2f0c('0xa0')]=_0x209dce[_0x2f0c('0x3c')]({'plain':!![]});_0x4f99d4['interaction']['created']=_0x2d814a;if(_0x4f99d4[_0x2f0c('0xa0')][_0x2f0c('0xa1')]){if(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0xa2')]){_0x4f99d4[_0x2f0c('0x92')][_0x2f0c('0xa3')]({'id':0x0,'priority':_0x4f99d4[_0x2f0c('0x92')][_0x2f0c('0x5f')]+0x1,'app':_0x2f0c('0xa4'),'appdata':_0x2f0c('0xa5'),'interval':_0x2f0c('0xa6')});}}return db[_0x2f0c('0xa7')][_0x2f0c('0x63')]({'body':_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0x64')],'OpenchannelAccountId':_0x5611ae[_0x2f0c('0x6b')]['id'],'OpenchannelInteractionId':_0x209dce['id'],'direction':'in','ContactId':_0x4f99d4[_0x2f0c('0x97')]['id'],'AttachmentId':_0x5611ae[_0x2f0c('0x64')][_0x2f0c('0xa8')]});})[_0x2f0c('0x25')](function(_0x3d3a23){_0x4f99d4[_0x2f0c('0x2d')]=_0x3d3a23;if(!_0x4f99d4['interaction']['UserId'])return;return db[_0x2f0c('0xa9')][_0x2f0c('0x62')]({'attributes':['id','name'],'where':{'id':_0x4f99d4['interaction'][_0x2f0c('0xaa')]}});})['then'](function(_0x2a1c60){if(_0x2a1c60){_0x4f99d4[_0x2f0c('0x92')][_0x2f0c('0xab')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x2a1c60[_0x2f0c('0x40')]+','+(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0xac')]||0xa),'interval':_0x2f0c('0xa6')});}if(!_0x4f99d4[_0x2f0c('0xa0')][_0x2f0c('0xad')])return;return db['OpenchannelQueue'][_0x2f0c('0x62')]({'attributes':['id','name'],'where':{'id':_0x4f99d4[_0x2f0c('0xa0')][_0x2f0c('0xad')]}});})[_0x2f0c('0x25')](function(_0x25b94c){if(_0x25b94c){_0x4f99d4['applications'][_0x2f0c('0xab')]({'id':0x0,'priority':0x1,'app':_0x2f0c('0xae'),'appdata':_0x25b94c['name']+','+(_0x4f99d4[_0x2f0c('0x8f')][_0x2f0c('0xaf')]||0x12c),'interval':_0x2f0c('0xa6')});}return respondWithRpcPromise(_0x2f0c('0xb0'),_0x2f0c('0xb1'),_0x4f99d4);})[_0x2f0c('0x25')](function(_0x207693){respondWithRpcPromise(_0x2f0c('0xb2'),'EventManager',{'event':_0x2f0c('0x79'),'message':_0x207693},client9002);return _0x207693;})[_0x2f0c('0x25')](respondWithResult(_0x50b430,null))['catch'](handleError(_0x50b430,null));};exports['addApplications']=function(_0x42d40b,_0x21d932){var _0x4a36fd=_0x42d40b[_0x2f0c('0x6b')]['id'];var _0x3cf2cf=_0x42d40b[_0x2f0c('0x64')];var _0x4f85d4=0xc8;var _0x24e669=null;return db[_0x2f0c('0xb3')][_0x2f0c('0xb4')]({'isolationLevel':db[_0x2f0c('0xb3')][_0x2f0c('0xb5')][_0x2f0c('0xb6')]['READ_COMMITTED']},function(_0x3f1cd8){return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x4a36fd},'transaction':_0x3f1cd8})[_0x2f0c('0x25')](function(_0x244acc){if(_0x244acc){return db['OpenchannelApplication'][_0x2f0c('0x6c')]({'where':{'OpenchannelAccountId':_0x4a36fd},'transaction':_0x3f1cd8})[_0x2f0c('0x25')](function(){var _0x4780c3=_[_0x2f0c('0x48')](_0x3cf2cf,function(_0xa4f7f7){_0xa4f7f7[_0x2f0c('0x71')]=_0x4a36fd;return _0xa4f7f7;});return db['OpenchannelApplication'][_0x2f0c('0xb7')](_0x4780c3,{'transaction':_0x3f1cd8});});}else{_0x4f85d4=0x194;_0x24e669=[];}});})[_0x2f0c('0x25')](function(){if(_0x4f85d4!==0x194){return db[_0x2f0c('0x8e')][_0x2f0c('0xb8')]({'where':{'OpenchannelAccountId':_0x4a36fd},'order':'priority'})['then'](function(_0x19afdc){_0x24e669=_0x19afdc;});}})[_0x2f0c('0x5c')](function(_0xfae729){_0x4f85d4=0x1f4;logger[_0x2f0c('0x2b')](_0xfae729['stack']);if(_0xfae729[_0x2f0c('0x40')]){delete _0xfae729['name'];}_0x24e669=_0xfae729;})['finally'](function(){if(_0x24e669===null){_0x21d932[_0x2f0c('0x3e')](_0x4f85d4);}else{if(_0x4f85d4===0x1f4){_0x21d932[_0x2f0c('0x30')](_0x4f85d4)['send'](_0x24e669);}else{_0x21d932[_0x2f0c('0x30')](_0x4f85d4)[_0x2f0c('0x32')](_0x24e669);}}});};exports[_0x2f0c('0xb9')]=function(_0x60ee6b,_0x1a6851,_0x26e582){var _0x1c50f9={};var _0x54eef7={};var _0x314d93;var _0x32c46a;return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x60ee6b['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x1a6851,null))[_0x2f0c('0x25')](function(_0x3e5f6b){if(_0x3e5f6b){_0x314d93=_0x3e5f6b;_0x54eef7[_0x2f0c('0x4c')]=_['keys'](db['OpenchannelApplication'][_0x2f0c('0x5e')]);_0x54eef7[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x60ee6b[_0x2f0c('0x49')]);_0x54eef7[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0x54eef7['model'],_0x54eef7[_0x2f0c('0x49')]);_0x1c50f9[_0x2f0c('0x4d')]=_['intersection'](_0x54eef7[_0x2f0c('0x4c')],qs['fields'](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x1c50f9[_0x2f0c('0x4d')]=_0x1c50f9[_0x2f0c('0x4d')][_0x2f0c('0x5f')]?_0x1c50f9[_0x2f0c('0x4d')]:_0x54eef7[_0x2f0c('0x4c')];_0x1c50f9[_0x2f0c('0x77')]=qs['sort'](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x1c50f9[_0x2f0c('0x54')]=qs['filters'](_[_0x2f0c('0x55')](_0x60ee6b[_0x2f0c('0x49')],_0x54eef7[_0x2f0c('0x4b')]));if(_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x1c50f9[_0x2f0c('0x54')]=_['merge'](_0x1c50f9['where'],{'$or':_[_0x2f0c('0x48')](_0x1c50f9[_0x2f0c('0x4d')],function(_0x1f58e5){var _0x3b0f47={};_0x3b0f47[_0x1f58e5]={'$like':'%'+_0x60ee6b[_0x2f0c('0x49')]['filter']+'%'};return _0x3b0f47;})});}_0x1c50f9=_[_0x2f0c('0x56')]({},_0x1c50f9,_0x60ee6b[_0x2f0c('0x61')]);return _0x314d93[_0x2f0c('0xb9')](_0x1c50f9);}})[_0x2f0c('0x25')](function(_0x22fed0){if(_0x22fed0){_0x32c46a=_0x22fed0[_0x2f0c('0x5f')];if(!_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x1c50f9[_0x2f0c('0x52')]=qs[_0x2f0c('0x52')](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x52')]);_0x1c50f9[_0x2f0c('0x33')]=qs['offset'](_0x60ee6b[_0x2f0c('0x49')][_0x2f0c('0x33')]);}return _0x314d93[_0x2f0c('0xb9')](_0x1c50f9);}})[_0x2f0c('0x25')](function(_0x518a3d){if(_0x518a3d){return _0x518a3d?{'count':_0x32c46a,'rows':_0x518a3d}:null;}})[_0x2f0c('0x25')](respondWithResult(_0x1a6851,null))[_0x2f0c('0x5c')](handleError(_0x1a6851,null));};exports[_0x2f0c('0xba')]=function(_0x19bef0,_0x2bae4,_0x4ee084){var _0x13af5e={'raw':![],'where':{}};var _0x15c533={};var _0xda0725={'count':0x0,'rows':[]};return db[_0x2f0c('0x44')][_0x2f0c('0x6f')]({'where':{'id':_0x19bef0['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x2bae4,null))[_0x2f0c('0x25')](function(_0x3ece57){if(_0x3ece57){_0x15c533['model']=_['keys'](db[_0x2f0c('0x9b')]['rawAttributes']);_0x15c533[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x19bef0[_0x2f0c('0x49')]);_0x15c533[_0x2f0c('0x4b')]=_[_0x2f0c('0x4e')](_0x15c533[_0x2f0c('0x4c')],_0x15c533[_0x2f0c('0x49')]);_0x13af5e[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x15c533['model'],qs[_0x2f0c('0x4f')](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x4f')]));_0x13af5e['attributes']=_0x13af5e[_0x2f0c('0x4d')]['length']?_0x13af5e['attributes']:_0x15c533['model'];if(!_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x50')]('nolimit')){_0x13af5e[_0x2f0c('0x52')]=qs['limit'](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x52')]);_0x13af5e[_0x2f0c('0x33')]=qs[_0x2f0c('0x33')](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x33')]);}_0x13af5e['order']=qs[_0x2f0c('0x53')](_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x53')]);_0x13af5e['where']=qs[_0x2f0c('0x4b')](_[_0x2f0c('0x55')](_0x19bef0[_0x2f0c('0x49')],_0x15c533[_0x2f0c('0x4b')]));_0x13af5e[_0x2f0c('0x54')]['OpenchannelAccountId']=_0x3ece57['id'];if(_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x13af5e[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x13af5e[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x13af5e[_0x2f0c('0x4d')],function(_0x2c65cc){var _0x579a33={};_0x579a33[_0x2c65cc]={'$like':'%'+_0x19bef0[_0x2f0c('0x49')]['filter']+'%'};return _0x579a33;})});}_0x13af5e=_['merge']({},_0x13af5e,_0x19bef0[_0x2f0c('0x61')]);return db['OpenchannelInteraction'][_0x2f0c('0x35')]({'where':_0x13af5e[_0x2f0c('0x54')]})[_0x2f0c('0x25')](function(_0x41e0ed){_0xda0725[_0x2f0c('0x35')]=_0x41e0ed;if(_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0x60')]){_0x13af5e[_0x2f0c('0x59')]=[{'model':db[_0x2f0c('0x7b')],'as':'Contact','required':![]},{'model':db[_0x2f0c('0xa9')],'as':_0x2f0c('0xbb'),'attributes':[_0x2f0c('0x40'),_0x2f0c('0xbc'),_0x2f0c('0xbd')],'required':![]},{'model':db[_0x2f0c('0xbe')],'as':_0x2f0c('0xbf'),'attributes':['id',_0x2f0c('0x40'),'color'],'where':_0x19bef0['query'][_0x2f0c('0xc0')]?{'id':_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0xc0')]}:undefined,'required':_0x19bef0[_0x2f0c('0x49')][_0x2f0c('0xc0')]?!![]:![]}];}return db[_0x2f0c('0x9b')][_0x2f0c('0x5a')](_0x13af5e);})['then'](function(_0x3aec14){_0xda0725[_0x2f0c('0x5b')]=_0x3aec14;return _0xda0725;});}})[_0x2f0c('0x25')](respondWithFilteredResult(_0x2bae4,_0x13af5e))[_0x2f0c('0x5c')](handleError(_0x2bae4,null));};exports[_0x2f0c('0xc1')]=function(_0x3faf73,_0x3e6d77,_0x63b9d1){return db['OpenchannelAccount'][_0x2f0c('0x62')]({'where':{'id':_0x3faf73[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x3e6d77,null))[_0x2f0c('0x25')](function(_0x4314d9){if(_0x4314d9){return _0x4314d9[_0x2f0c('0xc1')](_0x3faf73[_0x2f0c('0x64')]['ids'],_[_0x2f0c('0xc2')](_0x3faf73[_0x2f0c('0x64')],['ids','id'])||{})['spread'](function(_0x386860){for(var _0x3681b7=0x0;_0x3681b7<_0x3faf73[_0x2f0c('0x64')]['ids']['length'];_0x3681b7+=0x1){socket['emit'](_0x2f0c('0xc3'),{'UserId':Number(_0x3faf73[_0x2f0c('0x64')]['ids'][_0x3681b7]),'OpenchannelAccountId':Number(_0x3faf73[_0x2f0c('0x6b')]['id'])});}return _0x386860;});}})['then'](respondWithResult(_0x3e6d77,null))[_0x2f0c('0x5c')](handleError(_0x3e6d77,null));};exports['removeAgents']=function(_0x3513f1,_0x103b29,_0x194e42){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x3513f1[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x103b29,null))[_0x2f0c('0x25')](function(_0x28e1dc){if(_0x28e1dc){return _0x28e1dc[_0x2f0c('0xc4')](_0x3513f1['query'][_0x2f0c('0x73')])[_0x2f0c('0x25')](function(){if(_[_0x2f0c('0xc5')](_0x3513f1[_0x2f0c('0x49')]['ids'])){for(var _0x4b725d=0x0;_0x4b725d<_0x3513f1[_0x2f0c('0x49')][_0x2f0c('0x73')][_0x2f0c('0x5f')];_0x4b725d+=0x1){socket[_0x2f0c('0xc6')](_0x2f0c('0xc7'),{'UserId':Number(_0x3513f1[_0x2f0c('0x49')][_0x2f0c('0x73')][_0x4b725d]),'OpenchannelAccountId':Number(_0x3513f1[_0x2f0c('0x6b')]['id'])});}}else{socket['emit'](_0x2f0c('0xc7'),{'UserId':Number(_0x3513f1[_0x2f0c('0x49')][_0x2f0c('0x73')]),'OpenchannelAccountId':Number(_0x3513f1[_0x2f0c('0x6b')]['id'])});}});}})[_0x2f0c('0x25')](respondWithStatusCode(_0x103b29,null))[_0x2f0c('0x5c')](handleError(_0x103b29,null));};exports[_0x2f0c('0xc8')]=function(_0x490294,_0x15e876,_0xa14ba0){var _0x3057c5={};var _0x29a38c={};var _0xd08acf;var _0x2b7608;return db['OpenchannelAccount'][_0x2f0c('0x6f')]({'where':{'id':_0x490294['params']['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x15e876,null))[_0x2f0c('0x25')](function(_0x2aa0aa){if(_0x2aa0aa){_0xd08acf=_0x2aa0aa;_0x29a38c[_0x2f0c('0x4c')]=_[_0x2f0c('0x4a')](db[_0x2f0c('0xa9')]['rawAttributes']);_0x29a38c[_0x2f0c('0x49')]=_[_0x2f0c('0x4a')](_0x490294[_0x2f0c('0x49')]);_0x29a38c[_0x2f0c('0x4b')]=_['intersection'](_0x29a38c['model'],_0x29a38c[_0x2f0c('0x49')]);_0x3057c5[_0x2f0c('0x4d')]=_[_0x2f0c('0x4e')](_0x29a38c[_0x2f0c('0x4c')],qs[_0x2f0c('0x4f')](_0x490294['query'][_0x2f0c('0x4f')]));_0x3057c5[_0x2f0c('0x4d')]=_0x3057c5[_0x2f0c('0x4d')][_0x2f0c('0x5f')]?_0x3057c5[_0x2f0c('0x4d')]:_0x29a38c[_0x2f0c('0x4c')];_0x3057c5[_0x2f0c('0x77')]=qs['sort'](_0x490294['query'][_0x2f0c('0x53')]);_0x3057c5[_0x2f0c('0x54')]=qs[_0x2f0c('0x4b')](_['pick'](_0x490294['query'],_0x29a38c[_0x2f0c('0x4b')]));if(_0x490294[_0x2f0c('0x49')][_0x2f0c('0x58')]){_0x3057c5[_0x2f0c('0x54')]=_[_0x2f0c('0x56')](_0x3057c5[_0x2f0c('0x54')],{'$or':_[_0x2f0c('0x48')](_0x3057c5[_0x2f0c('0x4d')],function(_0x5dca15){var _0x471da9={};_0x471da9[_0x5dca15]={'$like':'%'+_0x490294['query'][_0x2f0c('0x58')]+'%'};return _0x471da9;})});}_0x3057c5=_[_0x2f0c('0x56')]({},_0x3057c5,_0x490294[_0x2f0c('0x61')]);return _0xd08acf[_0x2f0c('0xc8')](_0x3057c5);}})['then'](function(_0x9711c0){if(_0x9711c0){_0x2b7608=_0x9711c0['length'];if(!_0x490294['query'][_0x2f0c('0x50')](_0x2f0c('0x51'))){_0x3057c5[_0x2f0c('0x52')]=qs[_0x2f0c('0x52')](_0x490294['query']['limit']);_0x3057c5[_0x2f0c('0x33')]=qs[_0x2f0c('0x33')](_0x490294[_0x2f0c('0x49')][_0x2f0c('0x33')]);}return _0xd08acf[_0x2f0c('0xc8')](_0x3057c5);}})[_0x2f0c('0x25')](function(_0x20a836){if(_0x20a836){return _0x20a836?{'count':_0x2b7608,'rows':_0x20a836}:null;}})[_0x2f0c('0x25')](respondWithResult(_0x15e876,null))['catch'](handleError(_0x15e876,null));};exports['send']=function(_0x4547bb,_0x41e150,_0x2de7ab){var _0x37d41d,_0x4e0229,_0x3eef81;if(_['isNil'](_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')])||_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')]===''){throw new db[(_0x2f0c('0x7c'))][(_0x2f0c('0x7d'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2f0c('0x84')](_0x4547bb[_0x2f0c('0x64')]['to'])){}_0x37d41d=_0x4547bb[_0x2f0c('0x64')]['to'];return db['OpenchannelAccount'][_0x2f0c('0x6f')]({'where':{'id':_0x4547bb[_0x2f0c('0x6b')]['id']}})[_0x2f0c('0x25')](handleEntityNotFound(_0x41e150,null))[_0x2f0c('0x25')](function(_0x2e3ce4){if(_0x2e3ce4){return db[_0x2f0c('0x44')][_0x2f0c('0x62')]({'where':{'id':_0x2e3ce4['id']},'include':[{'model':db[_0x2f0c('0x8b')],'as':_0x2f0c('0x8c'),'include':[{'model':db[_0x2f0c('0x7b')],'as':_0x2f0c('0x96'),'where':{[_0x2e3ce4[_0x2f0c('0x87')]]:_0x37d41d},'limit':0x1,'order':[[_0x2f0c('0x7f'),'DESC']]}]}]})[_0x2f0c('0x25')](handleEntityNotFound(_0x41e150,null))['then'](function(_0x5c1b0c){if(_0x5c1b0c&&_0x5c1b0c[_0x2f0c('0x8c')]){_0x4e0229=_0x5c1b0c[_0x2f0c('0x3c')]({'plain':!![]});if(_0x4e0229[_0x2f0c('0x8c')]&&_0x4e0229[_0x2f0c('0x8c')][_0x2f0c('0x96')][_0x2f0c('0x5f')]){return _0x4e0229[_0x2f0c('0x8c')][_0x2f0c('0x96')][0x0];}return db[_0x2f0c('0x7b')][_0x2f0c('0x63')](_[_0x2f0c('0x1d')](_0x4547bb[_0x2f0c('0x64')],{'firstName':_0x37d41d,[_0x5c1b0c['mapKey']]:_0x37d41d,'phone':_0x37d41d,'ListId':_0x4e0229[_0x2f0c('0x83')]}));}})[_0x2f0c('0x25')](handleEntityNotFound(_0x41e150,null))['then'](function(_0x4e3988){if(_0x4e3988){_0x3eef81=_0x4e3988;return db[_0x2f0c('0x9b')][_0x2f0c('0x62')]({'where':{'ContactId':_0x3eef81['id'],'closed':![],'OpenchannelAccountId':_0x4e0229['id']}})['then'](function(_0x4f9657){if(_0x4f9657){return[_0x4f9657,![]];}return db[_0x2f0c('0x9b')]['create']({'UserId':_0x4547bb[_0x2f0c('0x65')]['id'],'ContactId':_0x3eef81['id'],'OpenchannelAccountId':_0x4e0229['id'],'lastMsgDirection':'out','firstMsgDirection':'out','Messages':[_[_0x2f0c('0x56')](_0x4547bb['body'],{'read':![],'body':_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')],'OpenchannelAccountId':_0x4e0229['id'],'UserId':_0x4547bb['user']['id'],'ContactId':_0x3eef81['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x2f0c('0xc9')}]})[_0x2f0c('0x25')](function(_0x19ab23){return[_0x19ab23,!![]];});});}})[_0x2f0c('0x9e')](function(_0x102c0d,_0x378723){if(_0x378723){return _0x102c0d;}return db[_0x2f0c('0xa7')][_0x2f0c('0x63')](_['merge'](_0x4547bb[_0x2f0c('0x64')],{'read':![],'body':_0x4547bb[_0x2f0c('0x64')][_0x2f0c('0x64')],'OpenchannelAccountId':_0x4e0229['id'],'OpenchannelInteractionId':_0x102c0d['id'],'UserId':_0x4547bb[_0x2f0c('0x65')]['id'],'ContactId':_0x3eef81['id']}))[_0x2f0c('0x25')](function(_0x3e8d32){_0x102c0d[_0x2f0c('0xca')]['Messages']=[];_0x102c0d['dataValues'][_0x2f0c('0xc9')][_0x2f0c('0xa3')](_0x3e8d32[_0x2f0c('0xca')]);return _0x102c0d;});});}})[_0x2f0c('0x25')](respondWithResult(_0x41e150,null))[_0x2f0c('0x5c')](handleError(_0x41e150,null));};
\ No newline at end of file
+var _0xd051=['Messages','dataValues','push','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','debug','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','limit','undefined','count','set','apply','reject','save','update','get','OpenchannelAccounts','destroy','stack','name','index','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','type','key','model','query','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','Pause','keys','length','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','Disposition','getDispositions','OpenchannelAccountId','ids','CannedAnswer','findOne','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','account','applications','list','priority','asc','contact','lastName','threadId','externalUrl','OpenchannelInteraction','ContactId','spread','firstName','messageId','interaction','created','close','unmanaged','OpenchannelMessage','UserId','User','unshift','*,*,*,*','OpenchannelQueue','queueId','queue','waitForTheAssignedQueue','Start','startRouting','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','finally','getApplications','getInteractions','Contact','fullname','tag','findAll','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','out'];(function(_0x4b369d,_0x265eb8){var _0x571a98=function(_0x56341a){while(--_0x56341a){_0x4b369d['push'](_0x4b369d['shift']());}};_0x571a98(++_0x265eb8);}(_0xd051,0xc5));var _0x1d05=function(_0x5c14f6,_0x2979d8){_0x5c14f6=_0x5c14f6-0x0;var _0x4949b3=_0xd051[_0x5c14f6];return _0x4949b3;};'use strict';var emlformat=require(_0x1d05('0x0'));var rimraf=require(_0x1d05('0x1'));var zipdir=require(_0x1d05('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x1d05('0x3'));var moment=require(_0x1d05('0x4'));var BPromise=require(_0x1d05('0x5'));var Mustache=require(_0x1d05('0x6'));var util=require(_0x1d05('0x7'));var path=require(_0x1d05('0x8'));var sox=require(_0x1d05('0x9'));var csv=require(_0x1d05('0xa'));var ejs=require(_0x1d05('0xb'));var fs=require('fs');var fs_extra=require(_0x1d05('0xc'));var _=require(_0x1d05('0xd'));var squel=require(_0x1d05('0xe'));var crypto=require(_0x1d05('0xf'));var jsforce=require(_0x1d05('0x10'));var deskjs=require(_0x1d05('0x11'));var toCsv=require(_0x1d05('0xa'));var querystring=require(_0x1d05('0x12'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x1d05('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x1d05('0x14'));var hardwareService=require(_0x1d05('0x15'));var logger=require('../../config/logger')(_0x1d05('0x16'));var utils=require('../../config/utils');var config=require(_0x1d05('0x17'));var licenseUtil=require(_0x1d05('0x18'));var db=require(_0x1d05('0x19'))['db'];config[_0x1d05('0x1a')]=_[_0x1d05('0x1b')](config[_0x1d05('0x1a')],{'host':_0x1d05('0x1c'),'port':0x18eb});var socket=require(_0x1d05('0x1d'))(new Redis(config[_0x1d05('0x1a')]));require(_0x1d05('0x1e'))[_0x1d05('0x1f')](socket);var jayson=require(_0x1d05('0x20'));var client=jayson[_0x1d05('0x21')]['http']({'port':0x232c});var client9002=jayson[_0x1d05('0x21')][_0x1d05('0x22')]({'port':0x232a});function respondWithRpcPromise(_0x186508,_0x491936,_0x19a7b5,_0x54197a){return new BPromise(function(_0x55e2a7,_0x277e23){var _0x5066f2=_0x54197a||client;return _0x5066f2['request'](_0x186508,_0x19a7b5)[_0x1d05('0x23')](function(_0x106f5b){logger[_0x1d05('0x24')](_0x1d05('0x25'),_0x491936,_0x1d05('0x26'));logger[_0x1d05('0x27')](_0x1d05('0x28'),_0x491936,_0x1d05('0x26'),JSON[_0x1d05('0x29')](_0x106f5b));if(_0x106f5b[_0x1d05('0x2a')]){if(_0x106f5b['error'][_0x1d05('0x2b')]===0x1f4){logger[_0x1d05('0x2a')]('OpenchannelAccount,\x20%s,\x20%s',_0x491936,_0x106f5b[_0x1d05('0x2a')][_0x1d05('0x2c')]);return _0x277e23(_0x106f5b[_0x1d05('0x2a')][_0x1d05('0x2c')]);}logger[_0x1d05('0x2a')](_0x1d05('0x25'),_0x491936,_0x106f5b[_0x1d05('0x2a')][_0x1d05('0x2c')]);return _0x55e2a7(_0x106f5b[_0x1d05('0x2a')][_0x1d05('0x2c')]);}else{logger[_0x1d05('0x24')](_0x1d05('0x25'),_0x491936,_0x1d05('0x26'));_0x55e2a7(_0x106f5b[_0x1d05('0x2d')][_0x1d05('0x2c')]);}})[_0x1d05('0x2e')](function(_0x39b38a){logger['error'](_0x1d05('0x25'),_0x491936,_0x39b38a);_0x277e23(_0x39b38a);});});}function respondWithStatusCode(_0x4b5dff,_0x2f1bdc){_0x2f1bdc=_0x2f1bdc||0xcc;return function(_0x26941e){if(_0x26941e){return _0x4b5dff[_0x1d05('0x2f')](_0x2f1bdc);}return _0x4b5dff[_0x1d05('0x30')](_0x2f1bdc)[_0x1d05('0x31')]();};}function respondWithResult(_0x2dfdb3,_0x33f85e){_0x33f85e=_0x33f85e||0xc8;return function(_0x770537){if(_0x770537){return _0x2dfdb3[_0x1d05('0x30')](_0x33f85e)[_0x1d05('0x32')](_0x770537);}};}function respondWithFilteredResult(_0x2f8467,_0xeddfc8){return function(_0x2d4ed9){if(_0x2d4ed9){var _0x178b5d=typeof _0xeddfc8[_0x1d05('0x33')]==='undefined'&&typeof _0xeddfc8[_0x1d05('0x34')]===_0x1d05('0x35');var _0x574f60=_0x2d4ed9[_0x1d05('0x36')];var _0x197fbe=_0x178b5d?0x0:_0xeddfc8[_0x1d05('0x33')];var _0x5e2c34=_0x178b5d?_0x2d4ed9[_0x1d05('0x36')]:_0xeddfc8['offset']+_0xeddfc8[_0x1d05('0x34')];var _0x36fafc;if(_0x5e2c34>=_0x574f60){_0x5e2c34=_0x574f60;_0x36fafc=0xc8;}else{_0x36fafc=0xce;}_0x2f8467[_0x1d05('0x30')](_0x36fafc);return _0x2f8467[_0x1d05('0x37')]('Content-Range',_0x197fbe+'-'+_0x5e2c34+'/'+_0x574f60)['json'](_0x2d4ed9);}return null;};}function patchUpdates(_0x2b8376){return function(_0x4b332f){try{jsonpatch[_0x1d05('0x38')](_0x4b332f,_0x2b8376,!![]);}catch(_0x2a55e9){return BPromise[_0x1d05('0x39')](_0x2a55e9);}return _0x4b332f[_0x1d05('0x3a')]();};}function saveUpdates(_0x162c5b,_0x5667eb){return function(_0x37859a){if(_0x37859a){return _0x37859a[_0x1d05('0x3b')](_0x162c5b)[_0x1d05('0x23')](function(_0x4e8467){return _0x4e8467;});}return null;};}function removeEntity(_0x4f8153,_0x497b32){return function(_0x34d7a1){if(_0x34d7a1){return _0x34d7a1['destroy']()[_0x1d05('0x23')](function(){var _0x1a61fe=_0x34d7a1[_0x1d05('0x3c')]({'plain':!![]});var _0x178b5a=_0x1d05('0x3d');return db['UserProfileResource'][_0x1d05('0x3e')]({'where':{'type':_0x178b5a,'resourceId':_0x1a61fe['id']}})[_0x1d05('0x23')](function(){return _0x34d7a1;});})[_0x1d05('0x23')](function(){_0x4f8153[_0x1d05('0x30')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2d3dfe,_0x35e9de){return function(_0x3ac49e){if(!_0x3ac49e){_0x2d3dfe['sendStatus'](0x194);}return _0x3ac49e;};}function handleError(_0x30f60f,_0x8edba6){_0x8edba6=_0x8edba6||0x1f4;return function(_0x49beda){logger[_0x1d05('0x2a')](_0x49beda[_0x1d05('0x3f')]);if(_0x49beda['name']){delete _0x49beda[_0x1d05('0x40')];}_0x30f60f[_0x1d05('0x30')](_0x8edba6)['send'](_0x49beda);};}exports[_0x1d05('0x41')]=function(_0x4a16d3,_0x206515){var _0x4dfc27={'include':[{'model':db['Pause'],'as':_0x1d05('0x42')}]},_0x49aaa1={},_0x4fc131={'count':0x0,'rows':[]};var _0x28c158=_[_0x1d05('0x43')](db[_0x1d05('0x44')][_0x1d05('0x45')],function(_0x33c01c){return{'name':_0x33c01c['fieldName'],'type':_0x33c01c[_0x1d05('0x46')][_0x1d05('0x47')]};});_0x49aaa1[_0x1d05('0x48')]=_[_0x1d05('0x43')](_0x28c158,_0x1d05('0x40'));_0x49aaa1[_0x1d05('0x49')]=_['keys'](_0x4a16d3['query']);_0x49aaa1['filters']=_[_0x1d05('0x4a')](_0x49aaa1[_0x1d05('0x48')],_0x49aaa1[_0x1d05('0x49')]);_0x4dfc27[_0x1d05('0x4b')]=_[_0x1d05('0x4a')](_0x49aaa1[_0x1d05('0x48')],qs['fields'](_0x4a16d3['query'][_0x1d05('0x4c')]));_0x4dfc27[_0x1d05('0x4b')]=_0x4dfc27[_0x1d05('0x4b')]['length']?_0x4dfc27[_0x1d05('0x4b')]:_0x49aaa1[_0x1d05('0x48')];if(!_0x4a16d3['query'][_0x1d05('0x4d')](_0x1d05('0x4e'))){_0x4dfc27[_0x1d05('0x34')]=qs['limit'](_0x4a16d3[_0x1d05('0x49')][_0x1d05('0x34')]);_0x4dfc27[_0x1d05('0x33')]=qs['offset'](_0x4a16d3[_0x1d05('0x49')][_0x1d05('0x33')]);}_0x4dfc27[_0x1d05('0x4f')]=qs[_0x1d05('0x50')](_0x4a16d3[_0x1d05('0x49')][_0x1d05('0x50')]);_0x4dfc27[_0x1d05('0x51')]=qs[_0x1d05('0x52')](_[_0x1d05('0x53')](_0x4a16d3[_0x1d05('0x49')],_0x49aaa1['filters']),_0x28c158);if(_0x4a16d3['query'][_0x1d05('0x54')]){_0x4dfc27[_0x1d05('0x51')]=_[_0x1d05('0x55')](_0x4dfc27[_0x1d05('0x51')],{'$or':_[_0x1d05('0x43')](_0x28c158,function(_0x2b0d74){if(_0x2b0d74['type']!==_0x1d05('0x56')){var _0x11c726={};_0x11c726[_0x2b0d74[_0x1d05('0x40')]]={'$like':'%'+_0x4a16d3[_0x1d05('0x49')][_0x1d05('0x54')]+'%'};return _0x11c726;}})});}_0x4dfc27=_['merge']({},_0x4dfc27,_0x4a16d3[_0x1d05('0x57')]);var _0x229996={'where':_0x4dfc27['where']};return db[_0x1d05('0x44')]['count'](_0x229996)[_0x1d05('0x23')](function(_0x44167c){_0x4fc131[_0x1d05('0x36')]=_0x44167c;if(_0x4a16d3[_0x1d05('0x49')][_0x1d05('0x58')]){_0x4dfc27[_0x1d05('0x59')]=[{'all':!![]}];}return db['OpenchannelAccount']['findAll'](_0x4dfc27);})[_0x1d05('0x23')](function(_0x1d6c0e){_0x4fc131[_0x1d05('0x5a')]=_0x1d6c0e;return _0x4fc131;})['then'](respondWithFilteredResult(_0x206515,_0x4dfc27))['catch'](handleError(_0x206515,null));};exports['show']=function(_0x8fe1ca,_0x5981e6){var _0x4a8ecb={'raw':![],'where':{'id':_0x8fe1ca['params']['id']},'include':[{'model':db[_0x1d05('0x5b')],'as':_0x1d05('0x42')}]},_0x94cf36={};_0x94cf36[_0x1d05('0x48')]=_[_0x1d05('0x5c')](db[_0x1d05('0x44')][_0x1d05('0x45')]);_0x94cf36[_0x1d05('0x49')]=_[_0x1d05('0x5c')](_0x8fe1ca[_0x1d05('0x49')]);_0x94cf36[_0x1d05('0x52')]=_['intersection'](_0x94cf36['model'],_0x94cf36[_0x1d05('0x49')]);_0x4a8ecb[_0x1d05('0x4b')]=_['intersection'](_0x94cf36[_0x1d05('0x48')],qs[_0x1d05('0x4c')](_0x8fe1ca[_0x1d05('0x49')]['fields']));_0x4a8ecb[_0x1d05('0x4b')]=_0x4a8ecb[_0x1d05('0x4b')][_0x1d05('0x5d')]?_0x4a8ecb['attributes']:_0x94cf36[_0x1d05('0x48')];if(_0x8fe1ca[_0x1d05('0x49')][_0x1d05('0x58')]){_0x4a8ecb['include']=[{'all':!![]}];}_0x4a8ecb=_[_0x1d05('0x55')]({},_0x4a8ecb,_0x8fe1ca[_0x1d05('0x57')]);return db[_0x1d05('0x44')][_0x1d05('0x5e')](_0x4a8ecb)['then'](handleEntityNotFound(_0x5981e6,null))[_0x1d05('0x23')](respondWithResult(_0x5981e6,null))['catch'](handleError(_0x5981e6,null));};exports[_0x1d05('0x5f')]=function(_0x2c81b6,_0x4c0c65){return db[_0x1d05('0x44')][_0x1d05('0x5f')](_0x2c81b6[_0x1d05('0x60')],{})[_0x1d05('0x23')](function(_0x5b247b){var _0x1c18a3=_0x2c81b6['user'][_0x1d05('0x3c')]({'plain':!![]});if(!_0x1c18a3)throw new Error(_0x1d05('0x61'));if(_0x1c18a3[_0x1d05('0x62')]===_0x1d05('0x63')){var _0x4d397a=_0x5b247b[_0x1d05('0x3c')]({'plain':!![]});var _0x14b484=_0x1d05('0x3d');return db[_0x1d05('0x64')][_0x1d05('0x5e')]({'where':{'name':_0x14b484,'userProfileId':_0x1c18a3['userProfileId']},'raw':!![]})['then'](function(_0x56a469){if(_0x56a469&&_0x56a469[_0x1d05('0x65')]===0x0){return db[_0x1d05('0x66')][_0x1d05('0x5f')]({'name':_0x4d397a[_0x1d05('0x40')],'resourceId':_0x4d397a['id'],'type':_0x56a469[_0x1d05('0x40')],'sectionId':_0x56a469['id']},{})[_0x1d05('0x23')](function(){return _0x5b247b;});}else{return _0x5b247b;}})[_0x1d05('0x2e')](function(_0x5472a1){logger[_0x1d05('0x2a')](_0x1d05('0x67'),_0x5472a1);throw _0x5472a1;});}return _0x5b247b;})[_0x1d05('0x23')](respondWithResult(_0x4c0c65,0xc9))[_0x1d05('0x2e')](handleError(_0x4c0c65,null));};exports[_0x1d05('0x3b')]=function(_0x9fae07,_0x3c78af){if(_0x9fae07['body']['id']){delete _0x9fae07[_0x1d05('0x60')]['id'];}return db[_0x1d05('0x44')]['find']({'where':{'id':_0x9fae07[_0x1d05('0x68')]['id']},'include':[{'model':db[_0x1d05('0x5b')],'as':_0x1d05('0x42')}]})['then'](handleEntityNotFound(_0x3c78af,null))['then'](saveUpdates(_0x9fae07[_0x1d05('0x60')],null))[_0x1d05('0x23')](respondWithResult(_0x3c78af,null))[_0x1d05('0x2e')](handleError(_0x3c78af,null));};exports[_0x1d05('0x3e')]=function(_0x5de359,_0xc982da){return db['OpenchannelAccount']['find']({'where':{'id':_0x5de359['params']['id']}})['then'](handleEntityNotFound(_0xc982da,null))[_0x1d05('0x23')](removeEntity(_0xc982da,null))[_0x1d05('0x2e')](handleError(_0xc982da,null));};exports['describe']=function(_0xfcc16f,_0x52e27d){return db[_0x1d05('0x44')][_0x1d05('0x69')]()[_0x1d05('0x23')](respondWithResult(_0x52e27d,null))[_0x1d05('0x2e')](handleError(_0x52e27d,null));};exports[_0x1d05('0x6a')]=function(_0x3bb631,_0x4f8bbb,_0xae5e3c){if(_0x3bb631[_0x1d05('0x60')]['id']){delete _0x3bb631[_0x1d05('0x60')]['id'];}return db['OpenchannelAccount'][_0x1d05('0x5e')]({'where':{'id':_0x3bb631[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x4f8bbb,null))[_0x1d05('0x23')](function(_0x490886){if(_0x490886){_0x3bb631['body']['OpenchannelAccountId']=_0x490886['id'];return db[_0x1d05('0x6b')][_0x1d05('0x5f')](_0x3bb631[_0x1d05('0x60')]);}})['then'](respondWithResult(_0x4f8bbb,null))[_0x1d05('0x2e')](handleError(_0x4f8bbb,null));};exports[_0x1d05('0x6c')]=function(_0x35430b,_0x2da224,_0x204d09){var _0x5b156c={'raw':![],'where':{}};var _0x4a0fa8={};var _0x35938e={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x35430b[_0x1d05('0x68')]['id']}})['then'](handleEntityNotFound(_0x2da224,null))['then'](function(_0x185857){if(_0x185857){_0x4a0fa8[_0x1d05('0x48')]=_[_0x1d05('0x5c')](db[_0x1d05('0x6b')][_0x1d05('0x45')]);_0x4a0fa8['query']=_[_0x1d05('0x5c')](_0x35430b[_0x1d05('0x49')]);_0x4a0fa8[_0x1d05('0x52')]=_[_0x1d05('0x4a')](_0x4a0fa8[_0x1d05('0x48')],_0x4a0fa8[_0x1d05('0x49')]);_0x5b156c[_0x1d05('0x4b')]=_[_0x1d05('0x4a')](_0x4a0fa8[_0x1d05('0x48')],qs[_0x1d05('0x4c')](_0x35430b['query'][_0x1d05('0x4c')]));_0x5b156c[_0x1d05('0x4b')]=_0x5b156c[_0x1d05('0x4b')]['length']?_0x5b156c[_0x1d05('0x4b')]:_0x4a0fa8[_0x1d05('0x48')];if(!_0x35430b[_0x1d05('0x49')]['hasOwnProperty'](_0x1d05('0x4e'))){_0x5b156c[_0x1d05('0x34')]=qs['limit'](_0x35430b[_0x1d05('0x49')]['limit']);_0x5b156c['offset']=qs[_0x1d05('0x33')](_0x35430b[_0x1d05('0x49')][_0x1d05('0x33')]);}_0x5b156c[_0x1d05('0x4f')]=qs['sort'](_0x35430b[_0x1d05('0x49')]['sort']);_0x5b156c['where']=qs[_0x1d05('0x52')](_[_0x1d05('0x53')](_0x35430b[_0x1d05('0x49')],_0x4a0fa8['filters']));_0x5b156c['where'][_0x1d05('0x6d')]=_0x185857['id'];if(_0x35430b[_0x1d05('0x49')][_0x1d05('0x54')]){_0x5b156c[_0x1d05('0x51')]=_[_0x1d05('0x55')](_0x5b156c[_0x1d05('0x51')],{'$or':_['map'](_0x5b156c[_0x1d05('0x4b')],function(_0x5a2d40){var _0x3f570e={};_0x3f570e[_0x5a2d40]={'$like':'%'+_0x35430b[_0x1d05('0x49')][_0x1d05('0x54')]+'%'};return _0x3f570e;})});}_0x5b156c=_['merge']({},_0x5b156c,_0x35430b[_0x1d05('0x57')]);return db[_0x1d05('0x6b')][_0x1d05('0x36')]({'where':_0x5b156c[_0x1d05('0x51')]})[_0x1d05('0x23')](function(_0x1b85f3){_0x35938e[_0x1d05('0x36')]=_0x1b85f3;if(_0x35430b[_0x1d05('0x49')][_0x1d05('0x58')]){_0x5b156c['include']=[{'all':!![]}];}return db[_0x1d05('0x6b')]['findAll'](_0x5b156c);})[_0x1d05('0x23')](function(_0x36d932){_0x35938e[_0x1d05('0x5a')]=_0x36d932;return _0x35938e;});}})[_0x1d05('0x23')](respondWithFilteredResult(_0x2da224,_0x5b156c))['catch'](handleError(_0x2da224,null));};exports['removeDispositions']=function(_0x3d6f65,_0x5bca4b,_0x1ee417){return db[_0x1d05('0x44')][_0x1d05('0x5e')]({'where':{'id':_0x3d6f65[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x5bca4b,null))['then'](function(_0x3ba171){if(_0x3ba171){return _0x3ba171['removeDispositions'](_0x3d6f65[_0x1d05('0x49')][_0x1d05('0x6e')]);}})['then'](respondWithStatusCode(_0x5bca4b,null))[_0x1d05('0x2e')](handleError(_0x5bca4b,null));};exports['addAnswer']=function(_0x37ecee,_0x1b8e06,_0x3080ef){if(_0x37ecee[_0x1d05('0x60')]['id']){delete _0x37ecee['body']['id'];}return db[_0x1d05('0x44')]['find']({'where':{'id':_0x37ecee['params']['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x1b8e06,null))[_0x1d05('0x23')](function(_0x5cdaf4){if(_0x5cdaf4){_0x37ecee[_0x1d05('0x60')]['OpenchannelAccountId']=_0x5cdaf4['id'];return db[_0x1d05('0x6f')]['create'](_0x37ecee[_0x1d05('0x60')]);}})[_0x1d05('0x23')](respondWithResult(_0x1b8e06,null))[_0x1d05('0x2e')](handleError(_0x1b8e06,null));};exports['getAnswers']=function(_0x3df23b,_0x50ded0,_0x4b0be6){var _0x179a68={'raw':![],'where':{}};var _0x173e2c={};var _0x367811={'count':0x0,'rows':[]};return db[_0x1d05('0x44')][_0x1d05('0x70')]({'where':{'id':_0x3df23b[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x50ded0,null))[_0x1d05('0x23')](function(_0x3c18c8){if(_0x3c18c8){_0x173e2c['model']=_[_0x1d05('0x5c')](db[_0x1d05('0x6f')][_0x1d05('0x45')]);_0x173e2c[_0x1d05('0x49')]=_['keys'](_0x3df23b['query']);_0x173e2c[_0x1d05('0x52')]=_['intersection'](_0x173e2c[_0x1d05('0x48')],_0x173e2c['query']);_0x179a68['attributes']=_['intersection'](_0x173e2c[_0x1d05('0x48')],qs['fields'](_0x3df23b['query'][_0x1d05('0x4c')]));_0x179a68[_0x1d05('0x4b')]=_0x179a68[_0x1d05('0x4b')]['length']?_0x179a68[_0x1d05('0x4b')]:_0x173e2c[_0x1d05('0x48')];if(!_0x3df23b['query']['hasOwnProperty'](_0x1d05('0x4e'))){_0x179a68[_0x1d05('0x34')]=qs[_0x1d05('0x34')](_0x3df23b[_0x1d05('0x49')]['limit']);_0x179a68['offset']=qs[_0x1d05('0x33')](_0x3df23b['query']['offset']);}_0x179a68[_0x1d05('0x4f')]=qs[_0x1d05('0x50')](_0x3df23b['query'][_0x1d05('0x50')]);_0x179a68[_0x1d05('0x51')]=qs[_0x1d05('0x52')](_['pick'](_0x3df23b[_0x1d05('0x49')],_0x173e2c[_0x1d05('0x52')]));_0x179a68[_0x1d05('0x51')][_0x1d05('0x6d')]=_0x3c18c8['id'];if(_0x3df23b[_0x1d05('0x49')][_0x1d05('0x54')]){_0x179a68['where']=_[_0x1d05('0x55')](_0x179a68[_0x1d05('0x51')],{'$or':_[_0x1d05('0x43')](_0x179a68['attributes'],function(_0x45cd54){var _0x46f02d={};_0x46f02d[_0x45cd54]={'$like':'%'+_0x3df23b[_0x1d05('0x49')][_0x1d05('0x54')]+'%'};return _0x46f02d;})});}_0x179a68=_[_0x1d05('0x55')]({},_0x179a68,_0x3df23b['options']);return db[_0x1d05('0x6f')]['count']({'where':_0x179a68[_0x1d05('0x51')]})[_0x1d05('0x23')](function(_0x22e7c1){_0x367811['count']=_0x22e7c1;if(_0x3df23b[_0x1d05('0x49')][_0x1d05('0x58')]){_0x179a68[_0x1d05('0x59')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x179a68);})[_0x1d05('0x23')](function(_0x473c5d){_0x367811['rows']=_0x473c5d;return _0x367811;});}})[_0x1d05('0x23')](respondWithFilteredResult(_0x50ded0,_0x179a68))[_0x1d05('0x2e')](handleError(_0x50ded0,null));};exports[_0x1d05('0x71')]=function(_0xb58081,_0x5c09c4,_0x334db9){return db[_0x1d05('0x44')][_0x1d05('0x5e')]({'where':{'id':_0xb58081[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x5c09c4,null))[_0x1d05('0x23')](function(_0x356456){if(_0x356456){return _0x356456[_0x1d05('0x71')](_0xb58081[_0x1d05('0x49')][_0x1d05('0x6e')]);}})[_0x1d05('0x23')](respondWithStatusCode(_0x5c09c4,null))[_0x1d05('0x2e')](handleError(_0x5c09c4,null));};exports[_0x1d05('0x72')]=function(_0x2a7dcf,_0x2eeb32,_0x2b17cc){var _0x5b8f3a={'body':_0x2a7dcf[_0x1d05('0x60')],'channel':_0x1d05('0x73')};var _0x21baab=[];var _0x2a9bad=[];var _0xcd6cba={};var _0xa4b362=![];return db[_0x1d05('0x74')][_0x1d05('0x69')]()[_0x1d05('0x23')](function(_0x364f86){if(!_0x364f86){throw new db[(_0x1d05('0x75'))][(_0x1d05('0x76'))](_0x1d05('0x77'));}_0x21baab=_[_0x1d05('0x78')](_[_0x1d05('0x5c')](_0x364f86),[_0x1d05('0x79'),_0x1d05('0x7a')]);_0x2a9bad=_[_0x1d05('0x78')](_[_0x1d05('0x5c')](_0x364f86),[_0x1d05('0x79'),_0x1d05('0x7a'),'CompanyId',_0x1d05('0x7b')]);if(_0x2a7dcf[_0x1d05('0x60')]['id']){delete _0x2a7dcf[_0x1d05('0x60')]['id'];}if(_[_0x1d05('0x7c')](_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x7d')])){throw new db[(_0x1d05('0x75'))]['ValidationError'](_0x1d05('0x7e'));}if(_[_0x1d05('0x7c')](_0x2a7dcf['body'][_0x1d05('0x60')])||_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x60')]===''){throw new db[(_0x1d05('0x75'))][(_0x1d05('0x76'))](_0x1d05('0x7f'));}if(_[_0x1d05('0x7c')](_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x80')])){throw new db[(_0x1d05('0x75'))][(_0x1d05('0x76'))](_0x1d05('0x81')+_0x2a9bad);}if(!_[_0x1d05('0x82')](_0x2a9bad,_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x80')])){throw new db[(_0x1d05('0x75'))]['ValidationError'](_0x1d05('0x83')+_0x2a9bad);}_0xcd6cba[_0x2a7dcf['body'][_0x1d05('0x80')]]=_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x7d')];})[_0x1d05('0x23')](function(){return db[_0x1d05('0x44')]['find']({'where':{'id':_0x2a7dcf[_0x1d05('0x68')]['id']},'include':[{'model':db[_0x1d05('0x84')],'as':_0x1d05('0x85'),'include':[{'model':db[_0x1d05('0x74')],'as':_0x1d05('0x86'),'where':_0xcd6cba,'limit':0x1,'order':[[_0x1d05('0x7a'),_0x1d05('0x87')]]}]},{'model':db[_0x1d05('0x88')],'as':_0x1d05('0x89')}]});})[_0x1d05('0x23')](handleEntityNotFound(_0x2eeb32,null))['then'](function(_0x342f1f){if(_0x342f1f&&_0x342f1f['List']){_0x5b8f3a[_0x1d05('0x8a')]=_0x342f1f;_0x5b8f3a[_0x1d05('0x8b')]=_0x342f1f[_0x1d05('0x89')];_0x5b8f3a[_0x1d05('0x8c')]=_0x342f1f[_0x1d05('0x85')];_0x5b8f3a[_0x1d05('0x8b')]=_['orderBy'](_0x5b8f3a[_0x1d05('0x8b')],[_0x1d05('0x8d')],[_0x1d05('0x8e')]);if(_0x5b8f3a[_0x1d05('0x8a')]['Applications']){delete _0x5b8f3a[_0x1d05('0x8a')][_0x1d05('0x89')];}if(_0x5b8f3a['account'][_0x1d05('0x85')]&&_0x5b8f3a[_0x1d05('0x8a')][_0x1d05('0x85')][_0x1d05('0x86')][_0x1d05('0x5d')]){return _0x5b8f3a[_0x1d05('0x8a')][_0x1d05('0x85')][_0x1d05('0x86')][0x0];}var _0x154d84=_['defaults'](_0x2a7dcf[_0x1d05('0x60')],{'firstName':_0x2a7dcf['body'][_0x1d05('0x7d')],'ListId':_0x342f1f['ListId']});_0x154d84[_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x80')]]=_0x2a7dcf['body'][_0x1d05('0x7d')];return db[_0x1d05('0x74')]['create'](_0x154d84,{'fields':_0x21baab,'raw':!![]});}})[_0x1d05('0x23')](handleEntityNotFound(_0x2eeb32,null))[_0x1d05('0x23')](function(_0x4b15c1){_0x5b8f3a[_0x1d05('0x8f')]=_0x4b15c1;if(_0x4b15c1){var _0x303355={'ContactId':_0x4b15c1['id'],'OpenchannelAccountId':_0x2a7dcf[_0x1d05('0x68')]['id'],'from':(_0x4b15c1['firstName']||'')+'\x20'+(_0x4b15c1[_0x1d05('0x90')]||'')};var _0x154de4={'OpenchannelAccountId':_0x2a7dcf[_0x1d05('0x68')]['id'],'closed':![]};if(_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x91')]){_0x154de4[_0x1d05('0x91')]=_0x2a7dcf[_0x1d05('0x60')]['threadId'];return db['OpenchannelInteraction'][_0x1d05('0x5e')]({'where':_0x154de4})[_0x1d05('0x23')](function(_0x34a59d){if(_0x34a59d){return[_0x34a59d,![]];}_0x303355[_0x1d05('0x91')]=_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x91')];_0x303355[_0x1d05('0x92')]=_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x92')];return db[_0x1d05('0x93')]['create'](_0x303355)[_0x1d05('0x23')](function(_0x20476){return[_0x20476,!![]];});});}else{_0x154de4['threadId']=null;}_0x154de4[_0x1d05('0x94')]=_0x4b15c1['id'];return db[_0x1d05('0x93')]['find']({'where':_0x154de4})['then'](function(_0x16a237){if(_0x16a237){return[_0x16a237,![]];}return db[_0x1d05('0x93')][_0x1d05('0x5f')](_0x303355)['then'](function(_0x326766){return[_0x326766,!![]];});});}})[_0x1d05('0x95')](function(_0x3370ec,_0x12025c){if(_0x3370ec){_0xa4b362=_0x12025c;if(!_0x12025c){var _0x3c7e13={'from':(_0x5b8f3a[_0x1d05('0x8f')][_0x1d05('0x96')]||'')+'\x20'+(_0x5b8f3a[_0x1d05('0x8f')]['lastName']||'')};if(_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x91')]&&_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x97')]&&_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x91')]!=_0x2a7dcf['body'][_0x1d05('0x97')]){_0x3c7e13[_0x1d05('0x91')]=_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x97')];}return _0x3370ec[_0x1d05('0x3b')](_0x3c7e13);}else{return _0x3370ec;}}})[_0x1d05('0x23')](function(_0x418530){_0x5b8f3a['interaction']=_0x418530[_0x1d05('0x3c')]({'plain':!![]});_0x5b8f3a[_0x1d05('0x98')][_0x1d05('0x99')]=_0xa4b362;if(_0x5b8f3a['interaction'][_0x1d05('0x99')]){if(_0x5b8f3a[_0x1d05('0x8a')]['autoclose']){_0x5b8f3a[_0x1d05('0x8b')]['push']({'id':0x0,'priority':_0x5b8f3a['applications'][_0x1d05('0x5d')]+0x1,'app':_0x1d05('0x9a'),'appdata':_0x1d05('0x9b'),'interval':'*,*,*,*'});}}return db[_0x1d05('0x9c')][_0x1d05('0x5f')]({'body':_0x2a7dcf[_0x1d05('0x60')][_0x1d05('0x60')],'OpenchannelAccountId':_0x2a7dcf[_0x1d05('0x68')]['id'],'OpenchannelInteractionId':_0x418530['id'],'direction':'in','ContactId':_0x5b8f3a[_0x1d05('0x8f')]['id'],'AttachmentId':_0x2a7dcf[_0x1d05('0x60')]['AttachmentId']});})[_0x1d05('0x23')](function(_0x24d861){_0x5b8f3a[_0x1d05('0x2c')]=_0x24d861;if(!_0x5b8f3a['interaction'][_0x1d05('0x9d')])return;return db[_0x1d05('0x9e')][_0x1d05('0x5e')]({'attributes':['id',_0x1d05('0x40')],'where':{'id':_0x5b8f3a['interaction'][_0x1d05('0x9d')]}});})[_0x1d05('0x23')](function(_0x4f3b94){if(_0x4f3b94){_0x5b8f3a[_0x1d05('0x8b')][_0x1d05('0x9f')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x4f3b94[_0x1d05('0x40')]+','+(_0x5b8f3a[_0x1d05('0x8a')]['waitForTheAssignedAgent']||0xa),'interval':_0x1d05('0xa0')});}if(!_0x5b8f3a[_0x1d05('0x98')]['queueId'])return;return db[_0x1d05('0xa1')]['find']({'attributes':['id',_0x1d05('0x40')],'where':{'id':_0x5b8f3a['interaction'][_0x1d05('0xa2')]}});})[_0x1d05('0x23')](function(_0x3e067c){if(_0x3e067c){_0x5b8f3a['applications'][_0x1d05('0x9f')]({'id':0x0,'priority':0x1,'app':_0x1d05('0xa3'),'appdata':_0x3e067c[_0x1d05('0x40')]+','+(_0x5b8f3a[_0x1d05('0x8a')][_0x1d05('0xa4')]||0x12c),'interval':_0x1d05('0xa0')});}return respondWithRpcPromise(_0x1d05('0xa5'),_0x1d05('0xa6'),_0x5b8f3a);})[_0x1d05('0x23')](function(_0x501ba1){respondWithRpcPromise('EventManager','EventManager',{'event':_0x1d05('0x72'),'message':_0x501ba1},client9002);return _0x501ba1;})[_0x1d05('0x23')](respondWithResult(_0x2eeb32,null))[_0x1d05('0x2e')](handleError(_0x2eeb32,null));};exports[_0x1d05('0xa7')]=function(_0x11c3a5,_0x47061b){var _0x5368b0=_0x11c3a5['params']['id'];var _0xa735f8=_0x11c3a5[_0x1d05('0x60')];var _0x412620=0xc8;var _0x3276ab=null;return db[_0x1d05('0xa8')][_0x1d05('0xa9')]({'isolationLevel':db[_0x1d05('0xa8')][_0x1d05('0xaa')][_0x1d05('0xab')][_0x1d05('0xac')]},function(_0x872118){return db['OpenchannelAccount'][_0x1d05('0x70')]({'where':{'id':_0x5368b0},'transaction':_0x872118})['then'](function(_0x4346ee){if(_0x4346ee){return db[_0x1d05('0x88')][_0x1d05('0x3e')]({'where':{'OpenchannelAccountId':_0x5368b0},'transaction':_0x872118})['then'](function(){var _0x233df0=_[_0x1d05('0x43')](_0xa735f8,function(_0x4366c5){_0x4366c5[_0x1d05('0x6d')]=_0x5368b0;return _0x4366c5;});return db['OpenchannelApplication'][_0x1d05('0xad')](_0x233df0,{'transaction':_0x872118});});}else{_0x412620=0x194;_0x3276ab=[];}});})[_0x1d05('0x23')](function(){if(_0x412620!==0x194){return db[_0x1d05('0x88')][_0x1d05('0xae')]({'where':{'OpenchannelAccountId':_0x5368b0},'order':_0x1d05('0x8d')})[_0x1d05('0x23')](function(_0x3d5f35){_0x3276ab=_0x3d5f35;});}})[_0x1d05('0x2e')](function(_0x61dc70){_0x412620=0x1f4;logger[_0x1d05('0x2a')](_0x61dc70['stack']);if(_0x61dc70[_0x1d05('0x40')]){delete _0x61dc70[_0x1d05('0x40')];}_0x3276ab=_0x61dc70;})[_0x1d05('0xaf')](function(){if(_0x3276ab===null){_0x47061b['sendStatus'](_0x412620);}else{if(_0x412620===0x1f4){_0x47061b[_0x1d05('0x30')](_0x412620)['send'](_0x3276ab);}else{_0x47061b[_0x1d05('0x30')](_0x412620)[_0x1d05('0x32')](_0x3276ab);}}});};exports[_0x1d05('0xb0')]=function(_0x39d02e,_0x14d98e,_0x4e1e83){var _0x44eafd={};var _0x44af05={};var _0x5250eb;var _0x443610;return db[_0x1d05('0x44')]['findOne']({'where':{'id':_0x39d02e['params']['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x14d98e,null))[_0x1d05('0x23')](function(_0x2307d6){if(_0x2307d6){_0x5250eb=_0x2307d6;_0x44af05['model']=_[_0x1d05('0x5c')](db[_0x1d05('0x88')][_0x1d05('0x45')]);_0x44af05[_0x1d05('0x49')]=_[_0x1d05('0x5c')](_0x39d02e[_0x1d05('0x49')]);_0x44af05[_0x1d05('0x52')]=_[_0x1d05('0x4a')](_0x44af05[_0x1d05('0x48')],_0x44af05[_0x1d05('0x49')]);_0x44eafd[_0x1d05('0x4b')]=_['intersection'](_0x44af05['model'],qs[_0x1d05('0x4c')](_0x39d02e[_0x1d05('0x49')][_0x1d05('0x4c')]));_0x44eafd[_0x1d05('0x4b')]=_0x44eafd[_0x1d05('0x4b')][_0x1d05('0x5d')]?_0x44eafd[_0x1d05('0x4b')]:_0x44af05[_0x1d05('0x48')];_0x44eafd[_0x1d05('0x4f')]=qs[_0x1d05('0x50')](_0x39d02e['query'][_0x1d05('0x50')]);_0x44eafd[_0x1d05('0x51')]=qs[_0x1d05('0x52')](_[_0x1d05('0x53')](_0x39d02e[_0x1d05('0x49')],_0x44af05[_0x1d05('0x52')]));if(_0x39d02e[_0x1d05('0x49')][_0x1d05('0x54')]){_0x44eafd[_0x1d05('0x51')]=_['merge'](_0x44eafd[_0x1d05('0x51')],{'$or':_[_0x1d05('0x43')](_0x44eafd['attributes'],function(_0x42acfb){var _0x3e89dc={};_0x3e89dc[_0x42acfb]={'$like':'%'+_0x39d02e[_0x1d05('0x49')][_0x1d05('0x54')]+'%'};return _0x3e89dc;})});}_0x44eafd=_['merge']({},_0x44eafd,_0x39d02e[_0x1d05('0x57')]);return _0x5250eb[_0x1d05('0xb0')](_0x44eafd);}})['then'](function(_0xdc2718){if(_0xdc2718){_0x443610=_0xdc2718['length'];if(!_0x39d02e[_0x1d05('0x49')][_0x1d05('0x4d')](_0x1d05('0x4e'))){_0x44eafd['limit']=qs[_0x1d05('0x34')](_0x39d02e['query'][_0x1d05('0x34')]);_0x44eafd[_0x1d05('0x33')]=qs[_0x1d05('0x33')](_0x39d02e[_0x1d05('0x49')][_0x1d05('0x33')]);}return _0x5250eb[_0x1d05('0xb0')](_0x44eafd);}})['then'](function(_0x448a0c){if(_0x448a0c){return _0x448a0c?{'count':_0x443610,'rows':_0x448a0c}:null;}})[_0x1d05('0x23')](respondWithResult(_0x14d98e,null))['catch'](handleError(_0x14d98e,null));};exports[_0x1d05('0xb1')]=function(_0x2555b3,_0x14ad9a,_0x486be6){var _0x5a50e0={'raw':![],'where':{}};var _0x1cb4b1={};var _0x133b7c={'count':0x0,'rows':[]};return db['OpenchannelAccount']['findOne']({'where':{'id':_0x2555b3[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x14ad9a,null))[_0x1d05('0x23')](function(_0x37e792){if(_0x37e792){_0x1cb4b1[_0x1d05('0x48')]=_[_0x1d05('0x5c')](db[_0x1d05('0x93')][_0x1d05('0x45')]);_0x1cb4b1[_0x1d05('0x49')]=_[_0x1d05('0x5c')](_0x2555b3[_0x1d05('0x49')]);_0x1cb4b1[_0x1d05('0x52')]=_[_0x1d05('0x4a')](_0x1cb4b1[_0x1d05('0x48')],_0x1cb4b1[_0x1d05('0x49')]);_0x5a50e0[_0x1d05('0x4b')]=_['intersection'](_0x1cb4b1[_0x1d05('0x48')],qs[_0x1d05('0x4c')](_0x2555b3[_0x1d05('0x49')][_0x1d05('0x4c')]));_0x5a50e0['attributes']=_0x5a50e0['attributes']['length']?_0x5a50e0[_0x1d05('0x4b')]:_0x1cb4b1[_0x1d05('0x48')];if(!_0x2555b3['query'][_0x1d05('0x4d')](_0x1d05('0x4e'))){_0x5a50e0[_0x1d05('0x34')]=qs[_0x1d05('0x34')](_0x2555b3[_0x1d05('0x49')][_0x1d05('0x34')]);_0x5a50e0['offset']=qs[_0x1d05('0x33')](_0x2555b3[_0x1d05('0x49')][_0x1d05('0x33')]);}_0x5a50e0[_0x1d05('0x4f')]=qs[_0x1d05('0x50')](_0x2555b3[_0x1d05('0x49')][_0x1d05('0x50')]);_0x5a50e0[_0x1d05('0x51')]=qs['filters'](_['pick'](_0x2555b3[_0x1d05('0x49')],_0x1cb4b1[_0x1d05('0x52')]));_0x5a50e0[_0x1d05('0x51')][_0x1d05('0x6d')]=_0x37e792['id'];if(_0x2555b3['query'][_0x1d05('0x54')]){_0x5a50e0[_0x1d05('0x51')]=_[_0x1d05('0x55')](_0x5a50e0[_0x1d05('0x51')],{'$or':_[_0x1d05('0x43')](_0x5a50e0[_0x1d05('0x4b')],function(_0x122899){var _0xacaf63={};_0xacaf63[_0x122899]={'$like':'%'+_0x2555b3[_0x1d05('0x49')][_0x1d05('0x54')]+'%'};return _0xacaf63;})});}_0x5a50e0=_[_0x1d05('0x55')]({},_0x5a50e0,_0x2555b3['options']);return db[_0x1d05('0x93')][_0x1d05('0x36')]({'where':_0x5a50e0[_0x1d05('0x51')]})[_0x1d05('0x23')](function(_0x4e8a28){_0x133b7c[_0x1d05('0x36')]=_0x4e8a28;if(_0x2555b3[_0x1d05('0x49')]['includeAll']){_0x5a50e0[_0x1d05('0x59')]=[{'model':db[_0x1d05('0x74')],'as':_0x1d05('0xb2'),'required':![]},{'model':db[_0x1d05('0x9e')],'as':'Owner','attributes':[_0x1d05('0x40'),_0x1d05('0xb3'),'internal'],'required':![]},{'model':db['Tag'],'as':'Tags','attributes':['id',_0x1d05('0x40'),'color'],'where':_0x2555b3['query'][_0x1d05('0xb4')]?{'id':_0x2555b3['query'][_0x1d05('0xb4')]}:undefined,'required':_0x2555b3[_0x1d05('0x49')][_0x1d05('0xb4')]?!![]:![]}];}return db[_0x1d05('0x93')][_0x1d05('0xb5')](_0x5a50e0);})[_0x1d05('0x23')](function(_0x6df3c0){_0x133b7c[_0x1d05('0x5a')]=_0x6df3c0;return _0x133b7c;});}})[_0x1d05('0x23')](respondWithFilteredResult(_0x14ad9a,_0x5a50e0))[_0x1d05('0x2e')](handleError(_0x14ad9a,null));};exports[_0x1d05('0xb6')]=function(_0x503415,_0xd87a16,_0x332d95){return db[_0x1d05('0x44')]['find']({'where':{'id':_0x503415[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0xd87a16,null))[_0x1d05('0x23')](function(_0x452389){if(_0x452389){return _0x452389[_0x1d05('0xb6')](_0x503415[_0x1d05('0x60')][_0x1d05('0x6e')],_[_0x1d05('0xb7')](_0x503415[_0x1d05('0x60')],[_0x1d05('0x6e'),'id'])||{})[_0x1d05('0x95')](function(_0x55c718){for(var _0x1973b3=0x0;_0x1973b3<_0x503415[_0x1d05('0x60')]['ids'][_0x1d05('0x5d')];_0x1973b3+=0x1){socket[_0x1d05('0xb8')](_0x1d05('0xb9'),{'UserId':Number(_0x503415['body'][_0x1d05('0x6e')][_0x1973b3]),'OpenchannelAccountId':Number(_0x503415['params']['id'])});}return _0x55c718;});}})['then'](respondWithResult(_0xd87a16,null))[_0x1d05('0x2e')](handleError(_0xd87a16,null));};exports['removeAgents']=function(_0x5a2127,_0x14bc0d,_0x1297af){return db[_0x1d05('0x44')][_0x1d05('0x5e')]({'where':{'id':_0x5a2127[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x14bc0d,null))['then'](function(_0x5da0a8){if(_0x5da0a8){return _0x5da0a8[_0x1d05('0xba')](_0x5a2127[_0x1d05('0x49')][_0x1d05('0x6e')])[_0x1d05('0x23')](function(){if(_[_0x1d05('0xbb')](_0x5a2127[_0x1d05('0x49')][_0x1d05('0x6e')])){for(var _0x1c877d=0x0;_0x1c877d<_0x5a2127[_0x1d05('0x49')][_0x1d05('0x6e')]['length'];_0x1c877d+=0x1){socket[_0x1d05('0xb8')](_0x1d05('0xbc'),{'UserId':Number(_0x5a2127['query'][_0x1d05('0x6e')][_0x1c877d]),'OpenchannelAccountId':Number(_0x5a2127['params']['id'])});}}else{socket['emit']('userOpenchannelAccount:remove',{'UserId':Number(_0x5a2127[_0x1d05('0x49')]['ids']),'OpenchannelAccountId':Number(_0x5a2127[_0x1d05('0x68')]['id'])});}});}})['then'](respondWithStatusCode(_0x14bc0d,null))[_0x1d05('0x2e')](handleError(_0x14bc0d,null));};exports[_0x1d05('0xbd')]=function(_0xbe40b7,_0x2519ab,_0x48558e){var _0x572d7e={};var _0x1dd041={};var _0x3f426e;var _0x4cebfe;return db['OpenchannelAccount'][_0x1d05('0x70')]({'where':{'id':_0xbe40b7[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x2519ab,null))[_0x1d05('0x23')](function(_0x5b8cd6){if(_0x5b8cd6){_0x3f426e=_0x5b8cd6;_0x1dd041[_0x1d05('0x48')]=_[_0x1d05('0x5c')](db[_0x1d05('0x9e')][_0x1d05('0x45')]);_0x1dd041[_0x1d05('0x49')]=_[_0x1d05('0x5c')](_0xbe40b7[_0x1d05('0x49')]);_0x1dd041[_0x1d05('0x52')]=_['intersection'](_0x1dd041[_0x1d05('0x48')],_0x1dd041[_0x1d05('0x49')]);_0x572d7e[_0x1d05('0x4b')]=_[_0x1d05('0x4a')](_0x1dd041[_0x1d05('0x48')],qs[_0x1d05('0x4c')](_0xbe40b7[_0x1d05('0x49')][_0x1d05('0x4c')]));_0x572d7e[_0x1d05('0x4b')]=_0x572d7e[_0x1d05('0x4b')][_0x1d05('0x5d')]?_0x572d7e['attributes']:_0x1dd041[_0x1d05('0x48')];_0x572d7e[_0x1d05('0x4f')]=qs[_0x1d05('0x50')](_0xbe40b7['query'][_0x1d05('0x50')]);_0x572d7e[_0x1d05('0x51')]=qs['filters'](_[_0x1d05('0x53')](_0xbe40b7['query'],_0x1dd041[_0x1d05('0x52')]));if(_0xbe40b7[_0x1d05('0x49')]['filter']){_0x572d7e[_0x1d05('0x51')]=_['merge'](_0x572d7e[_0x1d05('0x51')],{'$or':_[_0x1d05('0x43')](_0x572d7e[_0x1d05('0x4b')],function(_0x776db0){var _0x107b6b={};_0x107b6b[_0x776db0]={'$like':'%'+_0xbe40b7[_0x1d05('0x49')]['filter']+'%'};return _0x107b6b;})});}_0x572d7e=_[_0x1d05('0x55')]({},_0x572d7e,_0xbe40b7['options']);return _0x3f426e[_0x1d05('0xbd')](_0x572d7e);}})[_0x1d05('0x23')](function(_0x2e9754){if(_0x2e9754){_0x4cebfe=_0x2e9754[_0x1d05('0x5d')];if(!_0xbe40b7['query'][_0x1d05('0x4d')](_0x1d05('0x4e'))){_0x572d7e[_0x1d05('0x34')]=qs['limit'](_0xbe40b7['query'][_0x1d05('0x34')]);_0x572d7e[_0x1d05('0x33')]=qs[_0x1d05('0x33')](_0xbe40b7['query'][_0x1d05('0x33')]);}return _0x3f426e['getAgents'](_0x572d7e);}})[_0x1d05('0x23')](function(_0x37724a){if(_0x37724a){return _0x37724a?{'count':_0x4cebfe,'rows':_0x37724a}:null;}})[_0x1d05('0x23')](respondWithResult(_0x2519ab,null))['catch'](handleError(_0x2519ab,null));};exports['send']=function(_0x1099cb,_0x296cdd,_0x54a148){var _0x5b29bf,_0x5d7434,_0x5b5a39;if(_[_0x1d05('0x7c')](_0x1099cb[_0x1d05('0x60')]['body'])||_0x1099cb[_0x1d05('0x60')][_0x1d05('0x60')]===''){throw new db[(_0x1d05('0x75'))][(_0x1d05('0x76'))](_0x1d05('0x7f'));}if(_[_0x1d05('0x7c')](_0x1099cb[_0x1d05('0x60')]['to'])){}_0x5b29bf=_0x1099cb[_0x1d05('0x60')]['to'];return db['OpenchannelAccount'][_0x1d05('0x70')]({'where':{'id':_0x1099cb[_0x1d05('0x68')]['id']}})[_0x1d05('0x23')](handleEntityNotFound(_0x296cdd,null))[_0x1d05('0x23')](function(_0x1c5946){if(_0x1c5946){return db['OpenchannelAccount']['find']({'where':{'id':_0x1c5946['id']},'include':[{'model':db['CmList'],'as':_0x1d05('0x85'),'include':[{'model':db[_0x1d05('0x74')],'as':_0x1d05('0x86'),'where':{[_0x1c5946['mapKey']]:_0x5b29bf},'limit':0x1,'order':[[_0x1d05('0x7a'),'DESC']]}]}]})[_0x1d05('0x23')](handleEntityNotFound(_0x296cdd,null))['then'](function(_0x31f9ca){if(_0x31f9ca&&_0x31f9ca['List']){_0x5d7434=_0x31f9ca['get']({'plain':!![]});if(_0x5d7434[_0x1d05('0x85')]&&_0x5d7434[_0x1d05('0x85')][_0x1d05('0x86')][_0x1d05('0x5d')]){return _0x5d7434['List'][_0x1d05('0x86')][0x0];}return db[_0x1d05('0x74')][_0x1d05('0x5f')](_['defaults'](_0x1099cb[_0x1d05('0x60')],{'firstName':_0x5b29bf,[_0x31f9ca['mapKey']]:_0x5b29bf,'phone':_0x5b29bf,'ListId':_0x5d7434['ListId']}));}})[_0x1d05('0x23')](handleEntityNotFound(_0x296cdd,null))['then'](function(_0x16a05b){if(_0x16a05b){_0x5b5a39=_0x16a05b;return db[_0x1d05('0x93')][_0x1d05('0x5e')]({'where':{'ContactId':_0x5b5a39['id'],'closed':![],'OpenchannelAccountId':_0x5d7434['id']}})['then'](function(_0x1bcab0){if(_0x1bcab0){return[_0x1bcab0,![]];}return db[_0x1d05('0x93')][_0x1d05('0x5f')]({'UserId':_0x1099cb[_0x1d05('0x63')]['id'],'ContactId':_0x5b5a39['id'],'OpenchannelAccountId':_0x5d7434['id'],'lastMsgDirection':'out','firstMsgDirection':_0x1d05('0xbe'),'Messages':[_[_0x1d05('0x55')](_0x1099cb[_0x1d05('0x60')],{'read':![],'body':_0x1099cb[_0x1d05('0x60')][_0x1d05('0x60')],'OpenchannelAccountId':_0x5d7434['id'],'UserId':_0x1099cb[_0x1d05('0x63')]['id'],'ContactId':_0x5b5a39['id']})]},{'include':[{'model':db['OpenchannelMessage'],'as':_0x1d05('0xbf')}]})[_0x1d05('0x23')](function(_0x405ea6){return[_0x405ea6,!![]];});});}})['spread'](function(_0x5e964b,_0x19daf6){if(_0x19daf6){return _0x5e964b;}return db[_0x1d05('0x9c')][_0x1d05('0x5f')](_[_0x1d05('0x55')](_0x1099cb[_0x1d05('0x60')],{'read':![],'body':_0x1099cb['body'][_0x1d05('0x60')],'OpenchannelAccountId':_0x5d7434['id'],'OpenchannelInteractionId':_0x5e964b['id'],'UserId':_0x1099cb[_0x1d05('0x63')]['id'],'ContactId':_0x5b5a39['id']}))[_0x1d05('0x23')](function(_0x2ea584){_0x5e964b[_0x1d05('0xc0')][_0x1d05('0xbf')]=[];_0x5e964b[_0x1d05('0xc0')][_0x1d05('0xbf')][_0x1d05('0xc1')](_0x2ea584[_0x1d05('0xc0')]);return _0x5e964b;});});}})['then'](respondWithResult(_0x296cdd,null))[_0x1d05('0x2e')](handleError(_0x296cdd,null));};
\ No newline at end of file