Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / openchannelAccount / openchannelAccount.controller.js
index 16e33d4..c4fead4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe1a2=['then','destroy','get','OpenchannelAccounts','UserProfileResource','end','stack','name','send','index','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','keys','filters','attributes','intersection','fields','nolimit','limit','order','sort','where','pick','merge','VIRTUAL','filter','includeAll','rows','show','params','Pause','length','include','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','OpenchannelAccountId','Disposition','getDispositions','hasOwnProperty','findAll','removeDispositions','ids','addAnswer','getAnswers','findOne','CannedAnswer','removeAnswers','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','account','list','applications','orderBy','priority','asc','contact','firstName','lastName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','messageId','interaction','created','autoclose','push','unmanaged','OpenchannelMessage','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','forcedOwnership','Start','EventManager','notify','addApplications','sequelize','transaction','bulkCreate','findAndCountAll','getApplications','Contact','Owner','Tag','color','tag','addAgents','omit','emit','userOpenchannelAccount:save','removeAgents','userOpenchannelAccount:remove','getAgents','user','Messages','dataValues','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelAccount.socket','register','client','http','request','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','error','message','result','catch','sendStatus','json','offset','undefined','count','status','set','Content-Range','apply','reject','save'];(function(_0x1ef224,_0x604ca1){var _0x426a03=function(_0x285e09){while(--_0x285e09){_0x1ef224['push'](_0x1ef224['shift']());}};_0x426a03(++_0x604ca1);}(_0xe1a2,0x147));var _0x2e1a=function(_0x36884e,_0x48008f){_0x36884e=_0x36884e-0x0;var _0x1cc367=_0xe1a2[_0x36884e];return _0x1cc367;};'use strict';var emlformat=require(_0x2e1a('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x2e1a('0x1'));var jsonpatch=require(_0x2e1a('0x2'));var rp=require(_0x2e1a('0x3'));var moment=require(_0x2e1a('0x4'));var BPromise=require(_0x2e1a('0x5'));var Mustache=require(_0x2e1a('0x6'));var util=require(_0x2e1a('0x7'));var path=require(_0x2e1a('0x8'));var sox=require(_0x2e1a('0x9'));var csv=require(_0x2e1a('0xa'));var ejs=require(_0x2e1a('0xb'));var fs=require('fs');var fs_extra=require(_0x2e1a('0xc'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x2e1a('0xd'));var jsforce=require(_0x2e1a('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x2e1a('0xa'));var querystring=require(_0x2e1a('0xf'));var Papa=require('papaparse');var Redis=require(_0x2e1a('0x10'));var authService=require(_0x2e1a('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x2e1a('0x12'));var logger=require(_0x2e1a('0x13'))(_0x2e1a('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x2e1a('0x15'));var db=require(_0x2e1a('0x16'))['db'];config[_0x2e1a('0x17')]=_[_0x2e1a('0x18')](config['redis'],{'host':_0x2e1a('0x19'),'port':0x18eb});var socket=require(_0x2e1a('0x1a'))(new Redis(config[_0x2e1a('0x17')]));require(_0x2e1a('0x1b'))[_0x2e1a('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0x2e1a('0x1d')][_0x2e1a('0x1e')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x15e138,_0x34431,_0x5a9f54,_0x23dc58){return new BPromise(function(_0x1a6549,_0x2e601b){var _0xe0029c=_0x23dc58||client;return _0xe0029c[_0x2e1a('0x1f')](_0x15e138,_0x5a9f54)['then'](function(_0x22608f){logger[_0x2e1a('0x20')](_0x2e1a('0x21'),_0x34431,_0x2e1a('0x22'));logger['debug'](_0x2e1a('0x23'),_0x34431,'request\x20sent',JSON['stringify'](_0x22608f));if(_0x22608f[_0x2e1a('0x24')]){if(_0x22608f[_0x2e1a('0x24')]['code']===0x1f4){logger[_0x2e1a('0x24')](_0x2e1a('0x21'),_0x34431,_0x22608f[_0x2e1a('0x24')][_0x2e1a('0x25')]);return _0x2e601b(_0x22608f[_0x2e1a('0x24')][_0x2e1a('0x25')]);}logger[_0x2e1a('0x24')](_0x2e1a('0x21'),_0x34431,_0x22608f['error'][_0x2e1a('0x25')]);return _0x1a6549(_0x22608f[_0x2e1a('0x24')]['message']);}else{logger[_0x2e1a('0x20')](_0x2e1a('0x21'),_0x34431,_0x2e1a('0x22'));_0x1a6549(_0x22608f[_0x2e1a('0x26')][_0x2e1a('0x25')]);}})[_0x2e1a('0x27')](function(_0x4fddcf){logger[_0x2e1a('0x24')](_0x2e1a('0x21'),_0x34431,_0x4fddcf);_0x2e601b(_0x4fddcf);});});}function respondWithStatusCode(_0x51b328,_0x594713){_0x594713=_0x594713||0xcc;return function(_0x5377b1){if(_0x5377b1){return _0x51b328[_0x2e1a('0x28')](_0x594713);}return _0x51b328['status'](_0x594713)['end']();};}function respondWithResult(_0x29783f,_0x24f698){_0x24f698=_0x24f698||0xc8;return function(_0x43d90f){if(_0x43d90f){return _0x29783f['status'](_0x24f698)[_0x2e1a('0x29')](_0x43d90f);}};}function respondWithFilteredResult(_0x1f4d7b,_0x546e98){return function(_0x74d74f){if(_0x74d74f){var _0x45ce29=typeof _0x546e98[_0x2e1a('0x2a')]===_0x2e1a('0x2b')&&typeof _0x546e98['limit']===_0x2e1a('0x2b');var _0x3ff701=_0x74d74f[_0x2e1a('0x2c')];var _0x22d971=_0x45ce29?0x0:_0x546e98[_0x2e1a('0x2a')];var _0x18374c=_0x45ce29?_0x74d74f[_0x2e1a('0x2c')]:_0x546e98['offset']+_0x546e98['limit'];var _0x25248e;if(_0x18374c>=_0x3ff701){_0x18374c=_0x3ff701;_0x25248e=0xc8;}else{_0x25248e=0xce;}_0x1f4d7b[_0x2e1a('0x2d')](_0x25248e);return _0x1f4d7b[_0x2e1a('0x2e')](_0x2e1a('0x2f'),_0x22d971+'-'+_0x18374c+'/'+_0x3ff701)['json'](_0x74d74f);}return null;};}function patchUpdates(_0x4a6baa){return function(_0x1a1a9f){try{jsonpatch[_0x2e1a('0x30')](_0x1a1a9f,_0x4a6baa,!![]);}catch(_0x3c90ae){return BPromise[_0x2e1a('0x31')](_0x3c90ae);}return _0x1a1a9f[_0x2e1a('0x32')]();};}function saveUpdates(_0x18fb5d,_0x3187dd){return function(_0x4cb5e2){if(_0x4cb5e2){return _0x4cb5e2['update'](_0x18fb5d)[_0x2e1a('0x33')](function(_0x126b94){return _0x126b94;});}return null;};}function removeEntity(_0x4d93b6,_0x241094){return function(_0x40044c){if(_0x40044c){return _0x40044c[_0x2e1a('0x34')]()[_0x2e1a('0x33')](function(){var _0x1373da=_0x40044c[_0x2e1a('0x35')]({'plain':!![]});var _0x2961b7=_0x2e1a('0x36');return db[_0x2e1a('0x37')]['destroy']({'where':{'type':_0x2961b7,'resourceId':_0x1373da['id']}})[_0x2e1a('0x33')](function(){return _0x40044c;});})['then'](function(){_0x4d93b6[_0x2e1a('0x2d')](0xcc)[_0x2e1a('0x38')]();});}};}function handleEntityNotFound(_0x15b6d3,_0x2fe931){return function(_0x38bea8){if(!_0x38bea8){_0x15b6d3[_0x2e1a('0x28')](0x194);}return _0x38bea8;};}function handleError(_0x268c51,_0x5f35f6){_0x5f35f6=_0x5f35f6||0x1f4;return function(_0x42c363){logger['error'](_0x42c363[_0x2e1a('0x39')]);if(_0x42c363[_0x2e1a('0x3a')]){delete _0x42c363[_0x2e1a('0x3a')];}_0x268c51[_0x2e1a('0x2d')](_0x5f35f6)[_0x2e1a('0x3b')](_0x42c363);};}exports[_0x2e1a('0x3c')]=function(_0x55e1fe,_0x2233f9){var _0x2d0e68={'include':[{'model':db['Pause'],'as':_0x2e1a('0x3d')}]},_0xa1427f={},_0x1f24be={'count':0x0,'rows':[]};var _0x20b652=_[_0x2e1a('0x3e')](db[_0x2e1a('0x3f')][_0x2e1a('0x40')],function(_0x376dd8){return{'name':_0x376dd8[_0x2e1a('0x41')],'type':_0x376dd8[_0x2e1a('0x42')]['key']};});_0xa1427f[_0x2e1a('0x43')]=_[_0x2e1a('0x3e')](_0x20b652,_0x2e1a('0x3a'));_0xa1427f[_0x2e1a('0x44')]=_[_0x2e1a('0x45')](_0x55e1fe[_0x2e1a('0x44')]);_0xa1427f[_0x2e1a('0x46')]=_['intersection'](_0xa1427f[_0x2e1a('0x43')],_0xa1427f[_0x2e1a('0x44')]);_0x2d0e68[_0x2e1a('0x47')]=_[_0x2e1a('0x48')](_0xa1427f['model'],qs[_0x2e1a('0x49')](_0x55e1fe['query']['fields']));_0x2d0e68[_0x2e1a('0x47')]=_0x2d0e68[_0x2e1a('0x47')]['length']?_0x2d0e68['attributes']:_0xa1427f['model'];if(!_0x55e1fe[_0x2e1a('0x44')]['hasOwnProperty'](_0x2e1a('0x4a'))){_0x2d0e68[_0x2e1a('0x4b')]=qs[_0x2e1a('0x4b')](_0x55e1fe[_0x2e1a('0x44')]['limit']);_0x2d0e68[_0x2e1a('0x2a')]=qs['offset'](_0x55e1fe['query']['offset']);}_0x2d0e68[_0x2e1a('0x4c')]=qs[_0x2e1a('0x4d')](_0x55e1fe[_0x2e1a('0x44')][_0x2e1a('0x4d')]);_0x2d0e68[_0x2e1a('0x4e')]=qs[_0x2e1a('0x46')](_[_0x2e1a('0x4f')](_0x55e1fe[_0x2e1a('0x44')],_0xa1427f[_0x2e1a('0x46')]),_0x20b652);if(_0x55e1fe[_0x2e1a('0x44')]['filter']){_0x2d0e68[_0x2e1a('0x4e')]=_[_0x2e1a('0x50')](_0x2d0e68[_0x2e1a('0x4e')],{'$or':_[_0x2e1a('0x3e')](_0x20b652,function(_0x26804a){if(_0x26804a[_0x2e1a('0x42')]!==_0x2e1a('0x51')){var _0x361772={};_0x361772[_0x26804a[_0x2e1a('0x3a')]]={'$like':'%'+_0x55e1fe['query'][_0x2e1a('0x52')]+'%'};return _0x361772;}})});}_0x2d0e68=_[_0x2e1a('0x50')]({},_0x2d0e68,_0x55e1fe['options']);var _0xaf9f6c={'where':_0x2d0e68[_0x2e1a('0x4e')]};return db[_0x2e1a('0x3f')]['count'](_0xaf9f6c)[_0x2e1a('0x33')](function(_0x27ff1d){_0x1f24be[_0x2e1a('0x2c')]=_0x27ff1d;if(_0x55e1fe[_0x2e1a('0x44')][_0x2e1a('0x53')]){_0x2d0e68['include']=[{'all':!![]}];}return db['OpenchannelAccount']['findAll'](_0x2d0e68);})['then'](function(_0x665e6e){_0x1f24be[_0x2e1a('0x54')]=_0x665e6e;return _0x1f24be;})[_0x2e1a('0x33')](respondWithFilteredResult(_0x2233f9,_0x2d0e68))[_0x2e1a('0x27')](handleError(_0x2233f9,null));};exports[_0x2e1a('0x55')]=function(_0x40433c,_0x1ddb81){var _0x7eff64={'raw':![],'where':{'id':_0x40433c[_0x2e1a('0x56')]['id']},'include':[{'model':db[_0x2e1a('0x57')],'as':_0x2e1a('0x3d')}]},_0x35946b={};_0x35946b['model']=_[_0x2e1a('0x45')](db[_0x2e1a('0x3f')][_0x2e1a('0x40')]);_0x35946b['query']=_[_0x2e1a('0x45')](_0x40433c[_0x2e1a('0x44')]);_0x35946b['filters']=_[_0x2e1a('0x48')](_0x35946b[_0x2e1a('0x43')],_0x35946b[_0x2e1a('0x44')]);_0x7eff64['attributes']=_['intersection'](_0x35946b[_0x2e1a('0x43')],qs[_0x2e1a('0x49')](_0x40433c['query'][_0x2e1a('0x49')]));_0x7eff64[_0x2e1a('0x47')]=_0x7eff64['attributes'][_0x2e1a('0x58')]?_0x7eff64[_0x2e1a('0x47')]:_0x35946b['model'];if(_0x40433c[_0x2e1a('0x44')]['includeAll']){_0x7eff64[_0x2e1a('0x59')]=[{'all':!![]}];}_0x7eff64=_[_0x2e1a('0x50')]({},_0x7eff64,_0x40433c[_0x2e1a('0x5a')]);return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')](_0x7eff64)[_0x2e1a('0x33')](handleEntityNotFound(_0x1ddb81,null))['then'](respondWithResult(_0x1ddb81,null))['catch'](handleError(_0x1ddb81,null));};exports[_0x2e1a('0x5c')]=function(_0x5dadd6,_0x52949e){return db[_0x2e1a('0x3f')][_0x2e1a('0x5c')](_0x5dadd6[_0x2e1a('0x5d')],{})['then'](function(_0x59a387){var _0x452669=_0x5dadd6['user']['get']({'plain':!![]});if(!_0x452669)throw new Error(_0x2e1a('0x5e'));if(_0x452669[_0x2e1a('0x5f')]==='user'){var _0x14a40f=_0x59a387[_0x2e1a('0x35')]({'plain':!![]});var _0x1121f8=_0x2e1a('0x36');return db[_0x2e1a('0x60')]['find']({'where':{'name':_0x1121f8,'userProfileId':_0x452669[_0x2e1a('0x61')]},'raw':!![]})[_0x2e1a('0x33')](function(_0x423876){if(_0x423876&&_0x423876[_0x2e1a('0x62')]===0x0){return db[_0x2e1a('0x37')][_0x2e1a('0x5c')]({'name':_0x14a40f[_0x2e1a('0x3a')],'resourceId':_0x14a40f['id'],'type':_0x423876[_0x2e1a('0x3a')],'sectionId':_0x423876['id']},{})[_0x2e1a('0x33')](function(){return _0x59a387;});}else{return _0x59a387;}})[_0x2e1a('0x27')](function(_0x5d4e44){logger[_0x2e1a('0x24')](_0x2e1a('0x63'),_0x5d4e44);throw _0x5d4e44;});}return _0x59a387;})[_0x2e1a('0x33')](respondWithResult(_0x52949e,0xc9))['catch'](handleError(_0x52949e,null));};exports[_0x2e1a('0x64')]=function(_0x5aee52,_0x425291){if(_0x5aee52[_0x2e1a('0x5d')]['id']){delete _0x5aee52[_0x2e1a('0x5d')]['id'];}return db['OpenchannelAccount'][_0x2e1a('0x5b')]({'where':{'id':_0x5aee52['params']['id']},'include':[{'model':db[_0x2e1a('0x57')],'as':_0x2e1a('0x3d')}]})[_0x2e1a('0x33')](handleEntityNotFound(_0x425291,null))[_0x2e1a('0x33')](saveUpdates(_0x5aee52[_0x2e1a('0x5d')],null))[_0x2e1a('0x33')](respondWithResult(_0x425291,null))[_0x2e1a('0x27')](handleError(_0x425291,null));};exports[_0x2e1a('0x34')]=function(_0x334d62,_0x3477b5){return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')]({'where':{'id':_0x334d62[_0x2e1a('0x56')]['id']}})['then'](handleEntityNotFound(_0x3477b5,null))[_0x2e1a('0x33')](removeEntity(_0x3477b5,null))[_0x2e1a('0x27')](handleError(_0x3477b5,null));};exports[_0x2e1a('0x65')]=function(_0x2ad40c,_0x1f85bf){return db[_0x2e1a('0x3f')]['describe']()[_0x2e1a('0x33')](respondWithResult(_0x1f85bf,null))[_0x2e1a('0x27')](handleError(_0x1f85bf,null));};exports['addDisposition']=function(_0x5a8c80,_0x1bba73,_0x49868e){if(_0x5a8c80[_0x2e1a('0x5d')]['id']){delete _0x5a8c80[_0x2e1a('0x5d')]['id'];}return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')]({'where':{'id':_0x5a8c80[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x1bba73,null))[_0x2e1a('0x33')](function(_0x19ef76){if(_0x19ef76){_0x5a8c80['body'][_0x2e1a('0x66')]=_0x19ef76['id'];return db[_0x2e1a('0x67')]['create'](_0x5a8c80[_0x2e1a('0x5d')]);}})[_0x2e1a('0x33')](respondWithResult(_0x1bba73,null))[_0x2e1a('0x27')](handleError(_0x1bba73,null));};exports[_0x2e1a('0x68')]=function(_0x54f9ec,_0x531cb1,_0x42de5f){var _0x11196e={'raw':![],'where':{}};var _0x4c25cb={};var _0x269b7d={'count':0x0,'rows':[]};return db[_0x2e1a('0x3f')]['findOne']({'where':{'id':_0x54f9ec['params']['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x531cb1,null))['then'](function(_0x7eb3f8){if(_0x7eb3f8){_0x4c25cb['model']=_[_0x2e1a('0x45')](db[_0x2e1a('0x67')][_0x2e1a('0x40')]);_0x4c25cb[_0x2e1a('0x44')]=_[_0x2e1a('0x45')](_0x54f9ec[_0x2e1a('0x44')]);_0x4c25cb[_0x2e1a('0x46')]=_['intersection'](_0x4c25cb[_0x2e1a('0x43')],_0x4c25cb[_0x2e1a('0x44')]);_0x11196e['attributes']=_[_0x2e1a('0x48')](_0x4c25cb['model'],qs[_0x2e1a('0x49')](_0x54f9ec[_0x2e1a('0x44')][_0x2e1a('0x49')]));_0x11196e[_0x2e1a('0x47')]=_0x11196e[_0x2e1a('0x47')]['length']?_0x11196e[_0x2e1a('0x47')]:_0x4c25cb[_0x2e1a('0x43')];if(!_0x54f9ec['query'][_0x2e1a('0x69')](_0x2e1a('0x4a'))){_0x11196e[_0x2e1a('0x4b')]=qs[_0x2e1a('0x4b')](_0x54f9ec[_0x2e1a('0x44')][_0x2e1a('0x4b')]);_0x11196e['offset']=qs[_0x2e1a('0x2a')](_0x54f9ec[_0x2e1a('0x44')][_0x2e1a('0x2a')]);}_0x11196e[_0x2e1a('0x4c')]=qs[_0x2e1a('0x4d')](_0x54f9ec[_0x2e1a('0x44')]['sort']);_0x11196e[_0x2e1a('0x4e')]=qs[_0x2e1a('0x46')](_[_0x2e1a('0x4f')](_0x54f9ec['query'],_0x4c25cb['filters']));_0x11196e['where'][_0x2e1a('0x66')]=_0x7eb3f8['id'];if(_0x54f9ec[_0x2e1a('0x44')][_0x2e1a('0x52')]){_0x11196e[_0x2e1a('0x4e')]=_[_0x2e1a('0x50')](_0x11196e[_0x2e1a('0x4e')],{'$or':_[_0x2e1a('0x3e')](_0x11196e[_0x2e1a('0x47')],function(_0x435894){var _0x494d18={};_0x494d18[_0x435894]={'$like':'%'+_0x54f9ec['query'][_0x2e1a('0x52')]+'%'};return _0x494d18;})});}_0x11196e=_['merge']({},_0x11196e,_0x54f9ec[_0x2e1a('0x5a')]);return db[_0x2e1a('0x67')][_0x2e1a('0x2c')]({'where':_0x11196e['where']})['then'](function(_0x5920ab){_0x269b7d[_0x2e1a('0x2c')]=_0x5920ab;if(_0x54f9ec[_0x2e1a('0x44')][_0x2e1a('0x53')]){_0x11196e[_0x2e1a('0x59')]=[{'all':!![]}];}return db[_0x2e1a('0x67')][_0x2e1a('0x6a')](_0x11196e);})[_0x2e1a('0x33')](function(_0x39054d){_0x269b7d[_0x2e1a('0x54')]=_0x39054d;return _0x269b7d;});}})[_0x2e1a('0x33')](respondWithFilteredResult(_0x531cb1,_0x11196e))[_0x2e1a('0x27')](handleError(_0x531cb1,null));};exports[_0x2e1a('0x6b')]=function(_0x447b06,_0x14ff69,_0x2cf24f){return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')]({'where':{'id':_0x447b06[_0x2e1a('0x56')]['id']}})['then'](handleEntityNotFound(_0x14ff69,null))[_0x2e1a('0x33')](function(_0xf8562){if(_0xf8562){return _0xf8562['removeDispositions'](_0x447b06[_0x2e1a('0x44')][_0x2e1a('0x6c')]);}})[_0x2e1a('0x33')](respondWithStatusCode(_0x14ff69,null))[_0x2e1a('0x27')](handleError(_0x14ff69,null));};exports[_0x2e1a('0x6d')]=function(_0x243037,_0x479a65,_0x8b3147){if(_0x243037[_0x2e1a('0x5d')]['id']){delete _0x243037[_0x2e1a('0x5d')]['id'];}return db['OpenchannelAccount'][_0x2e1a('0x5b')]({'where':{'id':_0x243037[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x479a65,null))['then'](function(_0x4505f7){if(_0x4505f7){_0x243037['body'][_0x2e1a('0x66')]=_0x4505f7['id'];return db['CannedAnswer'][_0x2e1a('0x5c')](_0x243037[_0x2e1a('0x5d')]);}})[_0x2e1a('0x33')](respondWithResult(_0x479a65,null))[_0x2e1a('0x27')](handleError(_0x479a65,null));};exports[_0x2e1a('0x6e')]=function(_0x4edc16,_0xefbca3,_0x42d55c){var _0x4075d9={'raw':![],'where':{}};var _0x44a864={};var _0x10f8a0={'count':0x0,'rows':[]};return db[_0x2e1a('0x3f')][_0x2e1a('0x6f')]({'where':{'id':_0x4edc16['params']['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0xefbca3,null))[_0x2e1a('0x33')](function(_0x1ae499){if(_0x1ae499){_0x44a864[_0x2e1a('0x43')]=_[_0x2e1a('0x45')](db[_0x2e1a('0x70')][_0x2e1a('0x40')]);_0x44a864[_0x2e1a('0x44')]=_[_0x2e1a('0x45')](_0x4edc16[_0x2e1a('0x44')]);_0x44a864[_0x2e1a('0x46')]=_[_0x2e1a('0x48')](_0x44a864[_0x2e1a('0x43')],_0x44a864[_0x2e1a('0x44')]);_0x4075d9[_0x2e1a('0x47')]=_[_0x2e1a('0x48')](_0x44a864[_0x2e1a('0x43')],qs['fields'](_0x4edc16['query'][_0x2e1a('0x49')]));_0x4075d9[_0x2e1a('0x47')]=_0x4075d9[_0x2e1a('0x47')][_0x2e1a('0x58')]?_0x4075d9[_0x2e1a('0x47')]:_0x44a864[_0x2e1a('0x43')];if(!_0x4edc16[_0x2e1a('0x44')][_0x2e1a('0x69')](_0x2e1a('0x4a'))){_0x4075d9['limit']=qs[_0x2e1a('0x4b')](_0x4edc16[_0x2e1a('0x44')]['limit']);_0x4075d9[_0x2e1a('0x2a')]=qs[_0x2e1a('0x2a')](_0x4edc16[_0x2e1a('0x44')][_0x2e1a('0x2a')]);}_0x4075d9[_0x2e1a('0x4c')]=qs[_0x2e1a('0x4d')](_0x4edc16[_0x2e1a('0x44')][_0x2e1a('0x4d')]);_0x4075d9[_0x2e1a('0x4e')]=qs['filters'](_[_0x2e1a('0x4f')](_0x4edc16[_0x2e1a('0x44')],_0x44a864['filters']));_0x4075d9[_0x2e1a('0x4e')]['OpenchannelAccountId']=_0x1ae499['id'];if(_0x4edc16[_0x2e1a('0x44')][_0x2e1a('0x52')]){_0x4075d9[_0x2e1a('0x4e')]=_[_0x2e1a('0x50')](_0x4075d9['where'],{'$or':_[_0x2e1a('0x3e')](_0x4075d9[_0x2e1a('0x47')],function(_0x5a9304){var _0xd9bf97={};_0xd9bf97[_0x5a9304]={'$like':'%'+_0x4edc16[_0x2e1a('0x44')][_0x2e1a('0x52')]+'%'};return _0xd9bf97;})});}_0x4075d9=_[_0x2e1a('0x50')]({},_0x4075d9,_0x4edc16[_0x2e1a('0x5a')]);return db[_0x2e1a('0x70')]['count']({'where':_0x4075d9[_0x2e1a('0x4e')]})[_0x2e1a('0x33')](function(_0x5ace7d){_0x10f8a0['count']=_0x5ace7d;if(_0x4edc16[_0x2e1a('0x44')][_0x2e1a('0x53')]){_0x4075d9[_0x2e1a('0x59')]=[{'all':!![]}];}return db[_0x2e1a('0x70')]['findAll'](_0x4075d9);})[_0x2e1a('0x33')](function(_0x51d840){_0x10f8a0['rows']=_0x51d840;return _0x10f8a0;});}})[_0x2e1a('0x33')](respondWithFilteredResult(_0xefbca3,_0x4075d9))[_0x2e1a('0x27')](handleError(_0xefbca3,null));};exports[_0x2e1a('0x71')]=function(_0xaab144,_0x17fd35,_0x57d254){return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')]({'where':{'id':_0xaab144[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x17fd35,null))[_0x2e1a('0x33')](function(_0x393cc4){if(_0x393cc4){return _0x393cc4[_0x2e1a('0x71')](_0xaab144['query']['ids']);}})[_0x2e1a('0x33')](respondWithStatusCode(_0x17fd35,null))[_0x2e1a('0x27')](handleError(_0x17fd35,null));};exports['notify']=function(_0x4f3e4e,_0x4ed8c5,_0x3b61d8){var _0x5121e5={'body':_0x4f3e4e['body'],'channel':_0x2e1a('0x72')};var _0x1c5fab=[];var _0x16c3c8=[];var _0x1a03cc={};var _0x2a4c3c=![];return db[_0x2e1a('0x73')][_0x2e1a('0x65')]()[_0x2e1a('0x33')](function(_0x5b49fe){if(!_0x5b49fe){throw new db[(_0x2e1a('0x74'))][(_0x2e1a('0x75'))](_0x2e1a('0x76'));}_0x1c5fab=_[_0x2e1a('0x77')](_[_0x2e1a('0x45')](_0x5b49fe),[_0x2e1a('0x78'),_0x2e1a('0x79')]);_0x16c3c8=_[_0x2e1a('0x77')](_[_0x2e1a('0x45')](_0x5b49fe),[_0x2e1a('0x78'),'updatedAt',_0x2e1a('0x7a'),_0x2e1a('0x7b')]);if(_0x4f3e4e[_0x2e1a('0x5d')]['id']){delete _0x4f3e4e[_0x2e1a('0x5d')]['id'];}if(_[_0x2e1a('0x7c')](_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x7d')])){throw new db[(_0x2e1a('0x74'))][(_0x2e1a('0x75'))](_0x2e1a('0x7e'));}if(_[_0x2e1a('0x7c')](_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x5d')])||_0x4f3e4e['body']['body']===''){throw new db[(_0x2e1a('0x74'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2e1a('0x7c')](_0x4f3e4e['body'][_0x2e1a('0x7f')])){throw new db[(_0x2e1a('0x74'))][(_0x2e1a('0x75'))](_0x2e1a('0x80')+_0x16c3c8);}if(!_[_0x2e1a('0x81')](_0x16c3c8,_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x7f')])){throw new db['Sequelize'][(_0x2e1a('0x75'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x16c3c8);}_0x1a03cc[_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x7f')]]=_0x4f3e4e['body'][_0x2e1a('0x7d')];})[_0x2e1a('0x33')](function(){return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')]({'where':{'id':_0x4f3e4e[_0x2e1a('0x56')]['id']},'include':[{'model':db[_0x2e1a('0x82')],'as':_0x2e1a('0x83'),'include':[{'model':db[_0x2e1a('0x73')],'as':_0x2e1a('0x84'),'where':_0x1a03cc,'limit':0x1,'order':[[_0x2e1a('0x79'),_0x2e1a('0x85')]]}]},{'model':db[_0x2e1a('0x86')],'as':_0x2e1a('0x87')}]});})[_0x2e1a('0x33')](handleEntityNotFound(_0x4ed8c5,null))[_0x2e1a('0x33')](function(_0x275ce9){if(_0x275ce9&&_0x275ce9[_0x2e1a('0x83')]){_0x5121e5[_0x2e1a('0x88')]=_0x275ce9;_0x5121e5['applications']=_0x275ce9[_0x2e1a('0x87')];_0x5121e5[_0x2e1a('0x89')]=_0x275ce9[_0x2e1a('0x83')];_0x5121e5[_0x2e1a('0x8a')]=_[_0x2e1a('0x8b')](_0x5121e5[_0x2e1a('0x8a')],[_0x2e1a('0x8c')],[_0x2e1a('0x8d')]);if(_0x5121e5['account'][_0x2e1a('0x87')]){delete _0x5121e5[_0x2e1a('0x88')][_0x2e1a('0x87')];}if(_0x5121e5['account'][_0x2e1a('0x83')]&&_0x5121e5[_0x2e1a('0x88')][_0x2e1a('0x83')][_0x2e1a('0x84')][_0x2e1a('0x58')]){return _0x5121e5['account'][_0x2e1a('0x83')][_0x2e1a('0x84')][0x0];}var _0x1cc569=_[_0x2e1a('0x18')](_0x4f3e4e['body'],{'firstName':_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x7d')],'ListId':_0x275ce9['ListId']});_0x1cc569[_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x7f')]]=_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x7d')];return db[_0x2e1a('0x73')][_0x2e1a('0x5c')](_0x1cc569,{'fields':_0x1c5fab,'raw':!![]});}})[_0x2e1a('0x33')](handleEntityNotFound(_0x4ed8c5,null))['then'](function(_0x1c7420){_0x5121e5[_0x2e1a('0x8e')]=_0x1c7420;if(_0x1c7420){var _0x2f4c9d={'ContactId':_0x1c7420['id'],'OpenchannelAccountId':_0x4f3e4e[_0x2e1a('0x56')]['id'],'from':(_0x1c7420[_0x2e1a('0x8f')]||'')+'\x20'+(_0x1c7420[_0x2e1a('0x90')]||'')};var _0x554303={'OpenchannelAccountId':_0x4f3e4e[_0x2e1a('0x56')]['id'],'closed':![]};if(_0x4f3e4e['body'][_0x2e1a('0x91')]){_0x554303[_0x2e1a('0x91')]=_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x91')];return db[_0x2e1a('0x92')]['find']({'where':_0x554303})[_0x2e1a('0x33')](function(_0x2497a2){if(_0x2497a2){return[_0x2497a2,![]];}_0x2f4c9d[_0x2e1a('0x91')]=_0x4f3e4e[_0x2e1a('0x5d')]['threadId'];_0x2f4c9d['externalUrl']=_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x93')];return db[_0x2e1a('0x92')][_0x2e1a('0x5c')](_0x2f4c9d)[_0x2e1a('0x33')](function(_0x4cbaf7){return[_0x4cbaf7,!![]];});});}else{_0x554303['threadId']=null;}_0x554303[_0x2e1a('0x94')]=_0x1c7420['id'];return db[_0x2e1a('0x92')]['find']({'where':_0x554303})[_0x2e1a('0x33')](function(_0x118028){if(_0x118028){return[_0x118028,![]];}return db[_0x2e1a('0x92')][_0x2e1a('0x5c')](_0x2f4c9d)['then'](function(_0x31d8f1){return[_0x31d8f1,!![]];});});}})[_0x2e1a('0x95')](function(_0x24766f,_0x56b7fd){if(_0x24766f){_0x2a4c3c=_0x56b7fd;if(!_0x56b7fd){var _0x5809a8={'from':(_0x5121e5['contact'][_0x2e1a('0x8f')]||'')+'\x20'+(_0x5121e5[_0x2e1a('0x8e')][_0x2e1a('0x90')]||'')};if(_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x91')]&&_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x96')]&&_0x4f3e4e[_0x2e1a('0x5d')]['threadId']!=_0x4f3e4e['body']['messageId']){_0x5809a8[_0x2e1a('0x91')]=_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x96')];}return _0x24766f[_0x2e1a('0x64')](_0x5809a8);}else{return _0x24766f;}}})[_0x2e1a('0x33')](function(_0x51d9d5){_0x5121e5[_0x2e1a('0x97')]=_0x51d9d5[_0x2e1a('0x35')]({'plain':!![]});_0x5121e5[_0x2e1a('0x97')]['created']=_0x2a4c3c;if(_0x5121e5[_0x2e1a('0x97')][_0x2e1a('0x98')]){if(_0x5121e5[_0x2e1a('0x88')][_0x2e1a('0x99')]){_0x5121e5[_0x2e1a('0x8a')][_0x2e1a('0x9a')]({'id':0x0,'priority':_0x5121e5['applications'][_0x2e1a('0x58')]+0x1,'app':'close','appdata':_0x2e1a('0x9b'),'interval':'*,*,*,*'});}}return db[_0x2e1a('0x9c')][_0x2e1a('0x5c')]({'body':_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x5d')],'OpenchannelAccountId':_0x4f3e4e[_0x2e1a('0x56')]['id'],'OpenchannelInteractionId':_0x51d9d5['id'],'direction':'in','ContactId':_0x5121e5[_0x2e1a('0x8e')]['id'],'AttachmentId':_0x4f3e4e[_0x2e1a('0x5d')][_0x2e1a('0x9d')]});})[_0x2e1a('0x33')](function(_0xe7c71){_0x5121e5[_0x2e1a('0x25')]=_0xe7c71;if(_0x5121e5['interaction'][_0x2e1a('0x9e')]){return db[_0x2e1a('0x9f')]['find']({'attributes':['id',_0x2e1a('0x3a')],'where':{'id':_0x5121e5[_0x2e1a('0x97')][_0x2e1a('0x9e')]}})[_0x2e1a('0x33')](function(_0x460fcb){if(_0x460fcb){_0x5121e5[_0x2e1a('0x8a')][_0x2e1a('0xa0')]({'id':0x0,'priority':0x0,'app':_0x2e1a('0xa1'),'appdata':_0x460fcb[_0x2e1a('0x3a')]+','+(_0x5121e5[_0x2e1a('0x88')][_0x2e1a('0xa2')]||0xa),'interval':_0x2e1a('0xa3')});_0x5121e5[_0x2e1a('0xa4')]=![];}return respondWithRpcPromise('Start','startRouting',_0x5121e5);});}return respondWithRpcPromise(_0x2e1a('0xa5'),'startRouting',_0x5121e5);})['then'](function(_0x42a440){respondWithRpcPromise(_0x2e1a('0xa6'),_0x2e1a('0xa6'),{'event':_0x2e1a('0xa7'),'message':_0x42a440},client9002);return _0x42a440;})[_0x2e1a('0x33')](respondWithResult(_0x4ed8c5,null))[_0x2e1a('0x27')](handleError(_0x4ed8c5,null));};exports[_0x2e1a('0xa8')]=function(_0x382666,_0xae876,_0x2c39f9){return db['OpenchannelAccount'][_0x2e1a('0x6f')]({'where':{'id':_0x382666['params']['id']}})['then'](handleEntityNotFound(_0xae876,null))[_0x2e1a('0x33')](function(_0x2ae822){if(_0x2ae822){return db[_0x2e1a('0xa9')][_0x2e1a('0xaa')](function(_0x123972){return db[_0x2e1a('0x86')][_0x2e1a('0x34')]({'where':{'OpenchannelAccountId':_0x382666[_0x2e1a('0x56')]['id']},'transaction':_0x123972})[_0x2e1a('0x33')](function(_0x327c08){var _0x3e031e=_[_0x2e1a('0x3e')](_0x382666[_0x2e1a('0x5d')],function(_0x2a174b){_0x2a174b[_0x2e1a('0x66')]=_0x382666['params']['id'];return _0x2a174b;});return db[_0x2e1a('0x86')][_0x2e1a('0xab')](_0x3e031e,{'transaction':_0x123972});});})[_0x2e1a('0x33')](function(){return db['OpenchannelApplication'][_0x2e1a('0xac')]({'where':{'OpenchannelAccountId':_0x382666[_0x2e1a('0x56')]['id']},'order':_0x2e1a('0x8c')});});}})['then'](respondWithResult(_0xae876,null))[_0x2e1a('0x27')](handleError(_0xae876,null));};exports['getApplications']=function(_0x42a178,_0x28be66,_0x534535){var _0x3cae06={};var _0x2bbc94={};var _0x319339;var _0x48d50a;return db[_0x2e1a('0x3f')]['findOne']({'where':{'id':_0x42a178[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x28be66,null))[_0x2e1a('0x33')](function(_0x5cfa22){if(_0x5cfa22){_0x319339=_0x5cfa22;_0x2bbc94[_0x2e1a('0x43')]=_['keys'](db[_0x2e1a('0x86')]['rawAttributes']);_0x2bbc94[_0x2e1a('0x44')]=_[_0x2e1a('0x45')](_0x42a178['query']);_0x2bbc94[_0x2e1a('0x46')]=_['intersection'](_0x2bbc94['model'],_0x2bbc94[_0x2e1a('0x44')]);_0x3cae06[_0x2e1a('0x47')]=_[_0x2e1a('0x48')](_0x2bbc94[_0x2e1a('0x43')],qs[_0x2e1a('0x49')](_0x42a178['query'][_0x2e1a('0x49')]));_0x3cae06[_0x2e1a('0x47')]=_0x3cae06[_0x2e1a('0x47')][_0x2e1a('0x58')]?_0x3cae06[_0x2e1a('0x47')]:_0x2bbc94[_0x2e1a('0x43')];_0x3cae06[_0x2e1a('0x4c')]=qs[_0x2e1a('0x4d')](_0x42a178['query'][_0x2e1a('0x4d')]);_0x3cae06['where']=qs[_0x2e1a('0x46')](_[_0x2e1a('0x4f')](_0x42a178[_0x2e1a('0x44')],_0x2bbc94[_0x2e1a('0x46')]));if(_0x42a178[_0x2e1a('0x44')][_0x2e1a('0x52')]){_0x3cae06['where']=_[_0x2e1a('0x50')](_0x3cae06[_0x2e1a('0x4e')],{'$or':_[_0x2e1a('0x3e')](_0x3cae06['attributes'],function(_0x9d5165){var _0x18cf2d={};_0x18cf2d[_0x9d5165]={'$like':'%'+_0x42a178[_0x2e1a('0x44')][_0x2e1a('0x52')]+'%'};return _0x18cf2d;})});}_0x3cae06=_[_0x2e1a('0x50')]({},_0x3cae06,_0x42a178[_0x2e1a('0x5a')]);return _0x319339['getApplications'](_0x3cae06);}})[_0x2e1a('0x33')](function(_0x309d09){if(_0x309d09){_0x48d50a=_0x309d09[_0x2e1a('0x58')];if(!_0x42a178[_0x2e1a('0x44')][_0x2e1a('0x69')](_0x2e1a('0x4a'))){_0x3cae06[_0x2e1a('0x4b')]=qs[_0x2e1a('0x4b')](_0x42a178[_0x2e1a('0x44')][_0x2e1a('0x4b')]);_0x3cae06['offset']=qs['offset'](_0x42a178[_0x2e1a('0x44')][_0x2e1a('0x2a')]);}return _0x319339[_0x2e1a('0xad')](_0x3cae06);}})[_0x2e1a('0x33')](function(_0x5cbd3c){if(_0x5cbd3c){return _0x5cbd3c?{'count':_0x48d50a,'rows':_0x5cbd3c}:null;}})[_0x2e1a('0x33')](respondWithResult(_0x28be66,null))[_0x2e1a('0x27')](handleError(_0x28be66,null));};exports['getInteractions']=function(_0x56766e,_0x230d37,_0x14afe0){var _0x392b18={'raw':![],'where':{}};var _0x33f723={};var _0xb87394={'count':0x0,'rows':[]};return db[_0x2e1a('0x3f')]['findOne']({'where':{'id':_0x56766e['params']['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x230d37,null))['then'](function(_0x255e9f){if(_0x255e9f){_0x33f723[_0x2e1a('0x43')]=_[_0x2e1a('0x45')](db[_0x2e1a('0x92')]['rawAttributes']);_0x33f723[_0x2e1a('0x44')]=_[_0x2e1a('0x45')](_0x56766e['query']);_0x33f723[_0x2e1a('0x46')]=_[_0x2e1a('0x48')](_0x33f723[_0x2e1a('0x43')],_0x33f723[_0x2e1a('0x44')]);_0x392b18['attributes']=_[_0x2e1a('0x48')](_0x33f723[_0x2e1a('0x43')],qs[_0x2e1a('0x49')](_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x49')]));_0x392b18[_0x2e1a('0x47')]=_0x392b18[_0x2e1a('0x47')][_0x2e1a('0x58')]?_0x392b18[_0x2e1a('0x47')]:_0x33f723[_0x2e1a('0x43')];if(!_0x56766e[_0x2e1a('0x44')]['hasOwnProperty'](_0x2e1a('0x4a'))){_0x392b18['limit']=qs[_0x2e1a('0x4b')](_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x4b')]);_0x392b18[_0x2e1a('0x2a')]=qs[_0x2e1a('0x2a')](_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x2a')]);}_0x392b18[_0x2e1a('0x4c')]=qs[_0x2e1a('0x4d')](_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x4d')]);_0x392b18[_0x2e1a('0x4e')]=qs[_0x2e1a('0x46')](_['pick'](_0x56766e[_0x2e1a('0x44')],_0x33f723[_0x2e1a('0x46')]));_0x392b18[_0x2e1a('0x4e')]['OpenchannelAccountId']=_0x255e9f['id'];if(_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x52')]){_0x392b18[_0x2e1a('0x4e')]=_['merge'](_0x392b18[_0x2e1a('0x4e')],{'$or':_['map'](_0x392b18[_0x2e1a('0x47')],function(_0x3579ae){var _0x41a173={};_0x41a173[_0x3579ae]={'$like':'%'+_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x52')]+'%'};return _0x41a173;})});}_0x392b18=_[_0x2e1a('0x50')]({},_0x392b18,_0x56766e[_0x2e1a('0x5a')]);return db[_0x2e1a('0x92')][_0x2e1a('0x2c')]({'where':_0x392b18[_0x2e1a('0x4e')]})[_0x2e1a('0x33')](function(_0xf2dfde){_0xb87394[_0x2e1a('0x2c')]=_0xf2dfde;if(_0x56766e[_0x2e1a('0x44')][_0x2e1a('0x53')]){_0x392b18[_0x2e1a('0x59')]=[{'model':db['CmContact'],'as':_0x2e1a('0xae'),'required':![]},{'model':db[_0x2e1a('0x9f')],'as':_0x2e1a('0xaf'),'attributes':[_0x2e1a('0x3a'),'fullname','internal'],'required':![]},{'model':db[_0x2e1a('0xb0')],'as':'Tags','attributes':['id',_0x2e1a('0x3a'),_0x2e1a('0xb1')],'where':_0x56766e['query']['tag']?{'id':_0x56766e[_0x2e1a('0x44')][_0x2e1a('0xb2')]}:undefined,'required':_0x56766e[_0x2e1a('0x44')]['tag']?!![]:![]}];}return db[_0x2e1a('0x92')][_0x2e1a('0x6a')](_0x392b18);})[_0x2e1a('0x33')](function(_0xdfbbb8){_0xb87394[_0x2e1a('0x54')]=_0xdfbbb8;return _0xb87394;});}})[_0x2e1a('0x33')](respondWithFilteredResult(_0x230d37,_0x392b18))[_0x2e1a('0x27')](handleError(_0x230d37,null));};exports[_0x2e1a('0xb3')]=function(_0x3ecd41,_0x191ca4,_0x572925){return db[_0x2e1a('0x3f')]['find']({'where':{'id':_0x3ecd41[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x191ca4,null))[_0x2e1a('0x33')](function(_0x4e872a){if(_0x4e872a){return _0x4e872a[_0x2e1a('0xb3')](_0x3ecd41[_0x2e1a('0x5d')][_0x2e1a('0x6c')],_[_0x2e1a('0xb4')](_0x3ecd41['body'],[_0x2e1a('0x6c'),'id'])||{})[_0x2e1a('0x95')](function(_0x5b1f2a){for(var _0x1b46e0=0x0;_0x1b46e0<_0x3ecd41[_0x2e1a('0x5d')][_0x2e1a('0x6c')][_0x2e1a('0x58')];_0x1b46e0+=0x1){socket[_0x2e1a('0xb5')](_0x2e1a('0xb6'),{'UserId':Number(_0x3ecd41[_0x2e1a('0x5d')][_0x2e1a('0x6c')][_0x1b46e0]),'OpenchannelAccountId':Number(_0x3ecd41[_0x2e1a('0x56')]['id'])});}return _0x5b1f2a;});}})[_0x2e1a('0x33')](respondWithResult(_0x191ca4,null))[_0x2e1a('0x27')](handleError(_0x191ca4,null));};exports[_0x2e1a('0xb7')]=function(_0x271a34,_0x4247be,_0x2b569a){return db[_0x2e1a('0x3f')][_0x2e1a('0x5b')]({'where':{'id':_0x271a34[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x4247be,null))[_0x2e1a('0x33')](function(_0x5eb47d){if(_0x5eb47d){return _0x5eb47d[_0x2e1a('0xb7')](_0x271a34['query'][_0x2e1a('0x6c')])[_0x2e1a('0x33')](function(){if(_['isArray'](_0x271a34[_0x2e1a('0x44')][_0x2e1a('0x6c')])){for(var _0x4bd316=0x0;_0x4bd316<_0x271a34[_0x2e1a('0x44')][_0x2e1a('0x6c')]['length'];_0x4bd316+=0x1){socket[_0x2e1a('0xb5')](_0x2e1a('0xb8'),{'UserId':Number(_0x271a34[_0x2e1a('0x44')][_0x2e1a('0x6c')][_0x4bd316]),'OpenchannelAccountId':Number(_0x271a34[_0x2e1a('0x56')]['id'])});}}else{socket[_0x2e1a('0xb5')]('userOpenchannelAccount:remove',{'UserId':Number(_0x271a34['query'][_0x2e1a('0x6c')]),'OpenchannelAccountId':Number(_0x271a34['params']['id'])});}});}})[_0x2e1a('0x33')](respondWithStatusCode(_0x4247be,null))[_0x2e1a('0x27')](handleError(_0x4247be,null));};exports[_0x2e1a('0xb9')]=function(_0x39fb74,_0x5054f7,_0x1f164b){var _0x402df6={};var _0x1653df={};var _0xee73f8;var _0x216ae2;return db[_0x2e1a('0x3f')][_0x2e1a('0x6f')]({'where':{'id':_0x39fb74[_0x2e1a('0x56')]['id']}})[_0x2e1a('0x33')](handleEntityNotFound(_0x5054f7,null))[_0x2e1a('0x33')](function(_0x1f2588){if(_0x1f2588){_0xee73f8=_0x1f2588;_0x1653df[_0x2e1a('0x43')]=_[_0x2e1a('0x45')](db['User'][_0x2e1a('0x40')]);_0x1653df[_0x2e1a('0x44')]=_[_0x2e1a('0x45')](_0x39fb74[_0x2e1a('0x44')]);_0x1653df[_0x2e1a('0x46')]=_['intersection'](_0x1653df[_0x2e1a('0x43')],_0x1653df[_0x2e1a('0x44')]);_0x402df6['attributes']=_[_0x2e1a('0x48')](_0x1653df[_0x2e1a('0x43')],qs[_0x2e1a('0x49')](_0x39fb74[_0x2e1a('0x44')]['fields']));_0x402df6[_0x2e1a('0x47')]=_0x402df6[_0x2e1a('0x47')]['length']?_0x402df6['attributes']:_0x1653df['model'];_0x402df6[_0x2e1a('0x4c')]=qs[_0x2e1a('0x4d')](_0x39fb74['query']['sort']);_0x402df6['where']=qs['filters'](_[_0x2e1a('0x4f')](_0x39fb74[_0x2e1a('0x44')],_0x1653df[_0x2e1a('0x46')]));if(_0x39fb74[_0x2e1a('0x44')][_0x2e1a('0x52')]){_0x402df6['where']=_[_0x2e1a('0x50')](_0x402df6[_0x2e1a('0x4e')],{'$or':_[_0x2e1a('0x3e')](_0x402df6['attributes'],function(_0x1b17bc){var _0x568896={};_0x568896[_0x1b17bc]={'$like':'%'+_0x39fb74[_0x2e1a('0x44')][_0x2e1a('0x52')]+'%'};return _0x568896;})});}_0x402df6=_[_0x2e1a('0x50')]({},_0x402df6,_0x39fb74[_0x2e1a('0x5a')]);return _0xee73f8[_0x2e1a('0xb9')](_0x402df6);}})[_0x2e1a('0x33')](function(_0xc7dd43){if(_0xc7dd43){_0x216ae2=_0xc7dd43[_0x2e1a('0x58')];if(!_0x39fb74[_0x2e1a('0x44')][_0x2e1a('0x69')](_0x2e1a('0x4a'))){_0x402df6['limit']=qs[_0x2e1a('0x4b')](_0x39fb74['query'][_0x2e1a('0x4b')]);_0x402df6[_0x2e1a('0x2a')]=qs[_0x2e1a('0x2a')](_0x39fb74[_0x2e1a('0x44')][_0x2e1a('0x2a')]);}return _0xee73f8[_0x2e1a('0xb9')](_0x402df6);}})[_0x2e1a('0x33')](function(_0x2d3dc3){if(_0x2d3dc3){return _0x2d3dc3?{'count':_0x216ae2,'rows':_0x2d3dc3}:null;}})[_0x2e1a('0x33')](respondWithResult(_0x5054f7,null))[_0x2e1a('0x27')](handleError(_0x5054f7,null));};exports[_0x2e1a('0x3b')]=function(_0x2c018a,_0x2e591d,_0x2ed032){var _0x22770d,_0x124f0a,_0x13d4b8;if(_[_0x2e1a('0x7c')](_0x2c018a[_0x2e1a('0x5d')]['body'])||_0x2c018a[_0x2e1a('0x5d')][_0x2e1a('0x5d')]===''){throw new db[(_0x2e1a('0x74'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2e1a('0x7c')](_0x2c018a[_0x2e1a('0x5d')]['to'])){}_0x22770d=_0x2c018a[_0x2e1a('0x5d')]['to'];return db[_0x2e1a('0x3f')][_0x2e1a('0x6f')]({'where':{'id':_0x2c018a[_0x2e1a('0x56')]['id']}})['then'](handleEntityNotFound(_0x2e591d,null))[_0x2e1a('0x33')](function(_0x4173e7){if(_0x4173e7){return db[_0x2e1a('0x3f')]['find']({'where':{'id':_0x4173e7['id']},'include':[{'model':db[_0x2e1a('0x82')],'as':'List','include':[{'model':db['CmContact'],'as':_0x2e1a('0x84'),'where':{[_0x4173e7[_0x2e1a('0x7f')]]:_0x22770d},'limit':0x1,'order':[['updatedAt',_0x2e1a('0x85')]]}]}]})['then'](handleEntityNotFound(_0x2e591d,null))['then'](function(_0x2bee53){if(_0x2bee53&&_0x2bee53[_0x2e1a('0x83')]){_0x124f0a=_0x2bee53[_0x2e1a('0x35')]({'plain':!![]});if(_0x124f0a[_0x2e1a('0x83')]&&_0x124f0a['List'][_0x2e1a('0x84')][_0x2e1a('0x58')]){return _0x124f0a['List'][_0x2e1a('0x84')][0x0];}return db[_0x2e1a('0x73')][_0x2e1a('0x5c')](_[_0x2e1a('0x18')](_0x2c018a[_0x2e1a('0x5d')],{'firstName':_0x22770d,[_0x2bee53[_0x2e1a('0x7f')]]:_0x22770d,'phone':_0x22770d,'ListId':_0x124f0a[_0x2e1a('0x7b')]}));}})['then'](handleEntityNotFound(_0x2e591d,null))[_0x2e1a('0x33')](function(_0x47a981){if(_0x47a981){_0x13d4b8=_0x47a981;return db[_0x2e1a('0x92')][_0x2e1a('0x5b')]({'where':{'ContactId':_0x13d4b8['id'],'closed':![],'OpenchannelAccountId':_0x124f0a['id']}})[_0x2e1a('0x33')](function(_0x4d7f5e){if(_0x4d7f5e){return[_0x4d7f5e,![]];}return db[_0x2e1a('0x92')]['create']({'UserId':_0x2c018a[_0x2e1a('0xba')]['id'],'ContactId':_0x13d4b8['id'],'OpenchannelAccountId':_0x124f0a['id'],'lastMsgDirection':'out','Messages':[_['merge'](_0x2c018a[_0x2e1a('0x5d')],{'read':![],'body':_0x2c018a['body'][_0x2e1a('0x5d')],'OpenchannelAccountId':_0x124f0a['id'],'UserId':_0x2c018a[_0x2e1a('0xba')]['id'],'ContactId':_0x13d4b8['id']})]},{'include':[{'model':db[_0x2e1a('0x9c')],'as':_0x2e1a('0xbb')}]})[_0x2e1a('0x33')](function(_0x32b1a2){return[_0x32b1a2,!![]];});});}})[_0x2e1a('0x95')](function(_0x1fe013,_0x203de3){if(_0x203de3){return _0x1fe013;}return db['OpenchannelMessage'][_0x2e1a('0x5c')](_[_0x2e1a('0x50')](_0x2c018a[_0x2e1a('0x5d')],{'read':![],'body':_0x2c018a['body'][_0x2e1a('0x5d')],'OpenchannelAccountId':_0x124f0a['id'],'OpenchannelInteractionId':_0x1fe013['id'],'UserId':_0x2c018a['user']['id'],'ContactId':_0x13d4b8['id']}))['then'](function(_0x31521b){_0x1fe013[_0x2e1a('0xbc')][_0x2e1a('0xbb')]=[];_0x1fe013['dataValues'][_0x2e1a('0xbb')][_0x2e1a('0x9a')](_0x31521b[_0x2e1a('0xbc')]);return _0x1fe013;});});}})[_0x2e1a('0x33')](respondWithResult(_0x2e591d,null))[_0x2e1a('0x27')](handleError(_0x2e591d,null));};
\ No newline at end of file
+var _0x8248=['params','length','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','OpenchannelAccounts','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','OpenchannelAccountId','getDispositions','findOne','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','openchannel','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','List','Contacts','DESC','Applications','account','applications','list','orderBy','priority','asc','defaults','contact','firstName','threadId','OpenchannelInteraction','externalUrl','ContactId','lastName','messageId','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','OpenchannelMessage','UserId','User','unshift','agent','waitForTheAssignedAgent','forcedOwnership','Start','startRouting','EventManager','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','OpenchannelApplication','bulkCreate','findAndCountAll','finally','getApplications','getInteractions','Owner','internal','Tag','Tags','tag','addAgents','omit','spread','emit','removeAgents','isArray','userOpenchannelAccount:remove','getAgents','CmList','out','Messages','eml-format','rimraf','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','redis','socket.io-emitter','./openchannelAccount.socket','register','jayson/promise','client','http','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','sendStatus','status','end','json','limit','undefined','count','set','Content-Range','apply','reject','update','then','destroy','get','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','OpenchannelAccount','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch'];(function(_0x51b0dc,_0x5307b7){var _0x13fa89=function(_0x2c880f){while(--_0x2c880f){_0x51b0dc['push'](_0x51b0dc['shift']());}};_0x13fa89(++_0x5307b7);}(_0x8248,0x67));var _0x8824=function(_0x4c7225,_0x4dc28d){_0x4c7225=_0x4c7225-0x0;var _0x19f1ed=_0x8248[_0x4c7225];return _0x19f1ed;};'use strict';var emlformat=require(_0x8824('0x0'));var rimraf=require(_0x8824('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8824('0x2'));var rp=require('request-promise');var moment=require(_0x8824('0x3'));var BPromise=require(_0x8824('0x4'));var Mustache=require('mustache');var util=require(_0x8824('0x5'));var path=require(_0x8824('0x6'));var sox=require(_0x8824('0x7'));var csv=require(_0x8824('0x8'));var ejs=require(_0x8824('0x9'));var fs=require('fs');var fs_extra=require(_0x8824('0xa'));var _=require(_0x8824('0xb'));var squel=require(_0x8824('0xc'));var crypto=require(_0x8824('0xd'));var jsforce=require(_0x8824('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x8824('0x8'));var querystring=require(_0x8824('0xf'));var Papa=require(_0x8824('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x8824('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x8824('0x12'));var config=require(_0x8824('0x13'));var licenseUtil=require(_0x8824('0x14'));var db=require('../../mysqldb')['db'];config[_0x8824('0x15')]=_['defaults'](config[_0x8824('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x8824('0x16'))(new Redis(config[_0x8824('0x15')]));require(_0x8824('0x17'))[_0x8824('0x18')](socket);var jayson=require(_0x8824('0x19'));var client=jayson[_0x8824('0x1a')][_0x8824('0x1b')]({'port':0x232c});var client9002=jayson[_0x8824('0x1a')][_0x8824('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x447946,_0x367ffe,_0x34afb5,_0x37bb4c){return new BPromise(function(_0x21ebd4,_0x5ce033){var _0x1635e4=_0x37bb4c||client;return _0x1635e4['request'](_0x447946,_0x34afb5)['then'](function(_0x32cd83){logger[_0x8824('0x1c')](_0x8824('0x1d'),_0x367ffe,_0x8824('0x1e'));logger['debug'](_0x8824('0x1f'),_0x367ffe,'request\x20sent',JSON[_0x8824('0x20')](_0x32cd83));if(_0x32cd83['error']){if(_0x32cd83[_0x8824('0x21')][_0x8824('0x22')]===0x1f4){logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0x32cd83[_0x8824('0x21')][_0x8824('0x23')]);return _0x5ce033(_0x32cd83[_0x8824('0x21')]['message']);}logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0x32cd83[_0x8824('0x21')][_0x8824('0x23')]);return _0x21ebd4(_0x32cd83['error'][_0x8824('0x23')]);}else{logger['info']('OpenchannelAccount,\x20%s,\x20%s',_0x367ffe,_0x8824('0x1e'));_0x21ebd4(_0x32cd83[_0x8824('0x24')][_0x8824('0x23')]);}})['catch'](function(_0xd89d43){logger[_0x8824('0x21')](_0x8824('0x1d'),_0x367ffe,_0xd89d43);_0x5ce033(_0xd89d43);});});}function respondWithStatusCode(_0x44d4d6,_0x4a967d){_0x4a967d=_0x4a967d||0xcc;return function(_0x321695){if(_0x321695){return _0x44d4d6[_0x8824('0x25')](_0x4a967d);}return _0x44d4d6[_0x8824('0x26')](_0x4a967d)[_0x8824('0x27')]();};}function respondWithResult(_0x181562,_0xc22bd4){_0xc22bd4=_0xc22bd4||0xc8;return function(_0x253a41){if(_0x253a41){return _0x181562[_0x8824('0x26')](_0xc22bd4)[_0x8824('0x28')](_0x253a41);}};}function respondWithFilteredResult(_0xfe4d0b,_0x4bb39a){return function(_0x137523){if(_0x137523){var _0x5bac2d=typeof _0x4bb39a['offset']==='undefined'&&typeof _0x4bb39a[_0x8824('0x29')]===_0x8824('0x2a');var _0x2d946c=_0x137523[_0x8824('0x2b')];var _0x34260c=_0x5bac2d?0x0:_0x4bb39a['offset'];var _0x532b25=_0x5bac2d?_0x137523['count']:_0x4bb39a['offset']+_0x4bb39a['limit'];var _0x17a995;if(_0x532b25>=_0x2d946c){_0x532b25=_0x2d946c;_0x17a995=0xc8;}else{_0x17a995=0xce;}_0xfe4d0b['status'](_0x17a995);return _0xfe4d0b[_0x8824('0x2c')](_0x8824('0x2d'),_0x34260c+'-'+_0x532b25+'/'+_0x2d946c)[_0x8824('0x28')](_0x137523);}return null;};}function patchUpdates(_0x49dac8){return function(_0x51cf4e){try{jsonpatch[_0x8824('0x2e')](_0x51cf4e,_0x49dac8,!![]);}catch(_0xc91479){return BPromise[_0x8824('0x2f')](_0xc91479);}return _0x51cf4e['save']();};}function saveUpdates(_0x6fd49f,_0x329072){return function(_0x524976){if(_0x524976){return _0x524976[_0x8824('0x30')](_0x6fd49f)[_0x8824('0x31')](function(_0x1ce485){return _0x1ce485;});}return null;};}function removeEntity(_0x200adb,_0xc6cb29){return function(_0x4a4ca7){if(_0x4a4ca7){return _0x4a4ca7[_0x8824('0x32')]()[_0x8824('0x31')](function(){var _0x122b76=_0x4a4ca7[_0x8824('0x33')]({'plain':!![]});var _0x1714c6='OpenchannelAccounts';return db[_0x8824('0x34')][_0x8824('0x32')]({'where':{'type':_0x1714c6,'resourceId':_0x122b76['id']}})[_0x8824('0x31')](function(){return _0x4a4ca7;});})[_0x8824('0x31')](function(){_0x200adb[_0x8824('0x26')](0xcc)[_0x8824('0x27')]();});}};}function handleEntityNotFound(_0x19b775,_0x18f4ff){return function(_0xa86d7){if(!_0xa86d7){_0x19b775[_0x8824('0x25')](0x194);}return _0xa86d7;};}function handleError(_0x29be04,_0x572a7d){_0x572a7d=_0x572a7d||0x1f4;return function(_0x27af2c){logger[_0x8824('0x21')](_0x27af2c[_0x8824('0x35')]);if(_0x27af2c[_0x8824('0x36')]){delete _0x27af2c[_0x8824('0x36')];}_0x29be04['status'](_0x572a7d)[_0x8824('0x37')](_0x27af2c);};}exports[_0x8824('0x38')]=function(_0x5cff82,_0x2c95d2){var _0x452bc4={'include':[{'model':db[_0x8824('0x39')],'as':_0x8824('0x3a')}]},_0x1e7cae={},_0x312020={'count':0x0,'rows':[]};var _0xac8792=_[_0x8824('0x3b')](db[_0x8824('0x3c')][_0x8824('0x3d')],function(_0x3a1fd5){return{'name':_0x3a1fd5[_0x8824('0x3e')],'type':_0x3a1fd5[_0x8824('0x3f')]['key']};});_0x1e7cae[_0x8824('0x40')]=_[_0x8824('0x3b')](_0xac8792,_0x8824('0x36'));_0x1e7cae[_0x8824('0x41')]=_[_0x8824('0x42')](_0x5cff82[_0x8824('0x41')]);_0x1e7cae[_0x8824('0x43')]=_[_0x8824('0x44')](_0x1e7cae[_0x8824('0x40')],_0x1e7cae[_0x8824('0x41')]);_0x452bc4[_0x8824('0x45')]=_[_0x8824('0x44')](_0x1e7cae['model'],qs[_0x8824('0x46')](_0x5cff82[_0x8824('0x41')]['fields']));_0x452bc4[_0x8824('0x45')]=_0x452bc4[_0x8824('0x45')]['length']?_0x452bc4[_0x8824('0x45')]:_0x1e7cae[_0x8824('0x40')];if(!_0x5cff82['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x452bc4[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x5cff82['query'][_0x8824('0x29')]);_0x452bc4['offset']=qs[_0x8824('0x49')](_0x5cff82[_0x8824('0x41')]['offset']);}_0x452bc4[_0x8824('0x4a')]=qs['sort'](_0x5cff82[_0x8824('0x41')][_0x8824('0x4b')]);_0x452bc4[_0x8824('0x4c')]=qs[_0x8824('0x43')](_[_0x8824('0x4d')](_0x5cff82['query'],_0x1e7cae[_0x8824('0x43')]),_0xac8792);if(_0x5cff82['query'][_0x8824('0x4e')]){_0x452bc4['where']=_[_0x8824('0x4f')](_0x452bc4[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0xac8792,function(_0x35502e){if(_0x35502e[_0x8824('0x3f')]!==_0x8824('0x50')){var _0x1c88ea={};_0x1c88ea[_0x35502e[_0x8824('0x36')]]={'$like':'%'+_0x5cff82['query'][_0x8824('0x4e')]+'%'};return _0x1c88ea;}})});}_0x452bc4=_[_0x8824('0x4f')]({},_0x452bc4,_0x5cff82[_0x8824('0x51')]);var _0x84fb40={'where':_0x452bc4['where']};return db[_0x8824('0x3c')]['count'](_0x84fb40)[_0x8824('0x31')](function(_0xfb9dc5){_0x312020[_0x8824('0x2b')]=_0xfb9dc5;if(_0x5cff82[_0x8824('0x41')][_0x8824('0x52')]){_0x452bc4['include']=[{'all':!![]}];}return db[_0x8824('0x3c')][_0x8824('0x53')](_0x452bc4);})[_0x8824('0x31')](function(_0x161bd6){_0x312020[_0x8824('0x54')]=_0x161bd6;return _0x312020;})['then'](respondWithFilteredResult(_0x2c95d2,_0x452bc4))[_0x8824('0x55')](handleError(_0x2c95d2,null));};exports['show']=function(_0x28a274,_0x3ac5f7){var _0x60dd4f={'raw':![],'where':{'id':_0x28a274[_0x8824('0x56')]['id']},'include':[{'model':db['Pause'],'as':_0x8824('0x3a')}]},_0x39853f={};_0x39853f[_0x8824('0x40')]=_['keys'](db['OpenchannelAccount'][_0x8824('0x3d')]);_0x39853f[_0x8824('0x41')]=_[_0x8824('0x42')](_0x28a274[_0x8824('0x41')]);_0x39853f['filters']=_[_0x8824('0x44')](_0x39853f[_0x8824('0x40')],_0x39853f[_0x8824('0x41')]);_0x60dd4f[_0x8824('0x45')]=_['intersection'](_0x39853f['model'],qs[_0x8824('0x46')](_0x28a274[_0x8824('0x41')][_0x8824('0x46')]));_0x60dd4f['attributes']=_0x60dd4f[_0x8824('0x45')][_0x8824('0x57')]?_0x60dd4f['attributes']:_0x39853f['model'];if(_0x28a274[_0x8824('0x41')][_0x8824('0x52')]){_0x60dd4f[_0x8824('0x58')]=[{'all':!![]}];}_0x60dd4f=_['merge']({},_0x60dd4f,_0x28a274[_0x8824('0x51')]);return db[_0x8824('0x3c')][_0x8824('0x59')](_0x60dd4f)[_0x8824('0x31')](handleEntityNotFound(_0x3ac5f7,null))[_0x8824('0x31')](respondWithResult(_0x3ac5f7,null))[_0x8824('0x55')](handleError(_0x3ac5f7,null));};exports['create']=function(_0x46b57b,_0xbe90c1){return db[_0x8824('0x3c')][_0x8824('0x5a')](_0x46b57b[_0x8824('0x5b')],{})[_0x8824('0x31')](function(_0x3e9cb5){var _0x1cb16f=_0x46b57b[_0x8824('0x5c')][_0x8824('0x33')]({'plain':!![]});if(!_0x1cb16f)throw new Error(_0x8824('0x5d'));if(_0x1cb16f['role']===_0x8824('0x5c')){var _0x46b8ac=_0x3e9cb5[_0x8824('0x33')]({'plain':!![]});var _0x27e5e9=_0x8824('0x5e');return db['UserProfileSection']['find']({'where':{'name':_0x27e5e9,'userProfileId':_0x1cb16f[_0x8824('0x5f')]},'raw':!![]})[_0x8824('0x31')](function(_0x404251){if(_0x404251&&_0x404251['autoAssociation']===0x0){return db[_0x8824('0x34')]['create']({'name':_0x46b8ac[_0x8824('0x36')],'resourceId':_0x46b8ac['id'],'type':_0x404251[_0x8824('0x36')],'sectionId':_0x404251['id']},{})[_0x8824('0x31')](function(){return _0x3e9cb5;});}else{return _0x3e9cb5;}})[_0x8824('0x55')](function(_0x1abc59){logger[_0x8824('0x21')](_0x8824('0x60'),_0x1abc59);throw _0x1abc59;});}return _0x3e9cb5;})[_0x8824('0x31')](respondWithResult(_0xbe90c1,0xc9))['catch'](handleError(_0xbe90c1,null));};exports[_0x8824('0x30')]=function(_0x244dd4,_0x3f62d6){if(_0x244dd4[_0x8824('0x5b')]['id']){delete _0x244dd4['body']['id'];}return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x244dd4['params']['id']},'include':[{'model':db[_0x8824('0x39')],'as':'mandatoryDispositionPause'}]})[_0x8824('0x31')](handleEntityNotFound(_0x3f62d6,null))['then'](saveUpdates(_0x244dd4[_0x8824('0x5b')],null))[_0x8824('0x31')](respondWithResult(_0x3f62d6,null))[_0x8824('0x55')](handleError(_0x3f62d6,null));};exports[_0x8824('0x32')]=function(_0x215358,_0x484025){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x215358[_0x8824('0x56')]['id']}})['then'](handleEntityNotFound(_0x484025,null))['then'](removeEntity(_0x484025,null))[_0x8824('0x55')](handleError(_0x484025,null));};exports[_0x8824('0x61')]=function(_0x11f001,_0x112682){return db['OpenchannelAccount'][_0x8824('0x61')]()['then'](respondWithResult(_0x112682,null))['catch'](handleError(_0x112682,null));};exports[_0x8824('0x62')]=function(_0x442588,_0x18cc36,_0x24d8a7){if(_0x442588[_0x8824('0x5b')]['id']){delete _0x442588[_0x8824('0x5b')]['id'];}return db[_0x8824('0x3c')]['find']({'where':{'id':_0x442588[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x18cc36,null))['then'](function(_0x4d680e){if(_0x4d680e){_0x442588[_0x8824('0x5b')][_0x8824('0x63')]=_0x4d680e['id'];return db['Disposition']['create'](_0x442588[_0x8824('0x5b')]);}})[_0x8824('0x31')](respondWithResult(_0x18cc36,null))[_0x8824('0x55')](handleError(_0x18cc36,null));};exports[_0x8824('0x64')]=function(_0x10f942,_0x24a9b0,_0x17b563){var _0x3c3e3b={'raw':![],'where':{}};var _0xae8665={};var _0x42d7bb={'count':0x0,'rows':[]};return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x10f942[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x24a9b0,null))[_0x8824('0x31')](function(_0x1476d8){if(_0x1476d8){_0xae8665[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x66')][_0x8824('0x3d')]);_0xae8665['query']=_['keys'](_0x10f942['query']);_0xae8665[_0x8824('0x43')]=_['intersection'](_0xae8665[_0x8824('0x40')],_0xae8665[_0x8824('0x41')]);_0x3c3e3b[_0x8824('0x45')]=_['intersection'](_0xae8665[_0x8824('0x40')],qs[_0x8824('0x46')](_0x10f942[_0x8824('0x41')][_0x8824('0x46')]));_0x3c3e3b[_0x8824('0x45')]=_0x3c3e3b[_0x8824('0x45')][_0x8824('0x57')]?_0x3c3e3b[_0x8824('0x45')]:_0xae8665[_0x8824('0x40')];if(!_0x10f942['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x3c3e3b['limit']=qs[_0x8824('0x29')](_0x10f942[_0x8824('0x41')][_0x8824('0x29')]);_0x3c3e3b[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x10f942['query'][_0x8824('0x49')]);}_0x3c3e3b[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x10f942[_0x8824('0x41')][_0x8824('0x4b')]);_0x3c3e3b[_0x8824('0x4c')]=qs[_0x8824('0x43')](_['pick'](_0x10f942[_0x8824('0x41')],_0xae8665[_0x8824('0x43')]));_0x3c3e3b['where'][_0x8824('0x63')]=_0x1476d8['id'];if(_0x10f942[_0x8824('0x41')][_0x8824('0x4e')]){_0x3c3e3b[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x3c3e3b['where'],{'$or':_[_0x8824('0x3b')](_0x3c3e3b[_0x8824('0x45')],function(_0x33d0e6){var _0x22ddd5={};_0x22ddd5[_0x33d0e6]={'$like':'%'+_0x10f942[_0x8824('0x41')][_0x8824('0x4e')]+'%'};return _0x22ddd5;})});}_0x3c3e3b=_[_0x8824('0x4f')]({},_0x3c3e3b,_0x10f942['options']);return db[_0x8824('0x66')][_0x8824('0x2b')]({'where':_0x3c3e3b[_0x8824('0x4c')]})[_0x8824('0x31')](function(_0x187112){_0x42d7bb['count']=_0x187112;if(_0x10f942[_0x8824('0x41')][_0x8824('0x52')]){_0x3c3e3b['include']=[{'all':!![]}];}return db[_0x8824('0x66')][_0x8824('0x53')](_0x3c3e3b);})[_0x8824('0x31')](function(_0x497911){_0x42d7bb[_0x8824('0x54')]=_0x497911;return _0x42d7bb;});}})['then'](respondWithFilteredResult(_0x24a9b0,_0x3c3e3b))[_0x8824('0x55')](handleError(_0x24a9b0,null));};exports[_0x8824('0x67')]=function(_0x4125e3,_0x5ba86c,_0x3be598){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x4125e3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x5ba86c,null))['then'](function(_0x5515a4){if(_0x5515a4){return _0x5515a4[_0x8824('0x67')](_0x4125e3[_0x8824('0x41')][_0x8824('0x68')]);}})['then'](respondWithStatusCode(_0x5ba86c,null))[_0x8824('0x55')](handleError(_0x5ba86c,null));};exports[_0x8824('0x69')]=function(_0x21c1e2,_0x46956e,_0x43775c){if(_0x21c1e2['body']['id']){delete _0x21c1e2[_0x8824('0x5b')]['id'];}return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x21c1e2[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x46956e,null))[_0x8824('0x31')](function(_0x10747b){if(_0x10747b){_0x21c1e2['body'][_0x8824('0x63')]=_0x10747b['id'];return db['CannedAnswer'][_0x8824('0x5a')](_0x21c1e2['body']);}})[_0x8824('0x31')](respondWithResult(_0x46956e,null))[_0x8824('0x55')](handleError(_0x46956e,null));};exports['getAnswers']=function(_0x30868b,_0x3bc341,_0x48465a){var _0x2eb894={'raw':![],'where':{}};var _0x541754={};var _0x320f16={'count':0x0,'rows':[]};return db[_0x8824('0x3c')]['findOne']({'where':{'id':_0x30868b['params']['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x3bc341,null))[_0x8824('0x31')](function(_0x1a91c7){if(_0x1a91c7){_0x541754[_0x8824('0x40')]=_[_0x8824('0x42')](db['CannedAnswer']['rawAttributes']);_0x541754[_0x8824('0x41')]=_['keys'](_0x30868b['query']);_0x541754['filters']=_[_0x8824('0x44')](_0x541754[_0x8824('0x40')],_0x541754[_0x8824('0x41')]);_0x2eb894[_0x8824('0x45')]=_[_0x8824('0x44')](_0x541754[_0x8824('0x40')],qs[_0x8824('0x46')](_0x30868b[_0x8824('0x41')][_0x8824('0x46')]));_0x2eb894[_0x8824('0x45')]=_0x2eb894[_0x8824('0x45')]['length']?_0x2eb894[_0x8824('0x45')]:_0x541754[_0x8824('0x40')];if(!_0x30868b[_0x8824('0x41')][_0x8824('0x47')](_0x8824('0x48'))){_0x2eb894[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x30868b[_0x8824('0x41')]['limit']);_0x2eb894[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x30868b[_0x8824('0x41')]['offset']);}_0x2eb894[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x30868b[_0x8824('0x41')][_0x8824('0x4b')]);_0x2eb894['where']=qs[_0x8824('0x43')](_[_0x8824('0x4d')](_0x30868b['query'],_0x541754[_0x8824('0x43')]));_0x2eb894['where'][_0x8824('0x63')]=_0x1a91c7['id'];if(_0x30868b['query'][_0x8824('0x4e')]){_0x2eb894[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x2eb894[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x2eb894['attributes'],function(_0x50bc87){var _0x58cd08={};_0x58cd08[_0x50bc87]={'$like':'%'+_0x30868b[_0x8824('0x41')][_0x8824('0x4e')]+'%'};return _0x58cd08;})});}_0x2eb894=_[_0x8824('0x4f')]({},_0x2eb894,_0x30868b[_0x8824('0x51')]);return db['CannedAnswer'][_0x8824('0x2b')]({'where':_0x2eb894[_0x8824('0x4c')]})[_0x8824('0x31')](function(_0x375ab7){_0x320f16['count']=_0x375ab7;if(_0x30868b[_0x8824('0x41')]['includeAll']){_0x2eb894[_0x8824('0x58')]=[{'all':!![]}];}return db[_0x8824('0x6a')][_0x8824('0x53')](_0x2eb894);})['then'](function(_0xca0f36){_0x320f16['rows']=_0xca0f36;return _0x320f16;});}})[_0x8824('0x31')](respondWithFilteredResult(_0x3bc341,_0x2eb894))['catch'](handleError(_0x3bc341,null));};exports[_0x8824('0x6b')]=function(_0x3e6feb,_0x1ad890,_0x484e25){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x3e6feb[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x1ad890,null))[_0x8824('0x31')](function(_0x135008){if(_0x135008){return _0x135008['removeAnswers'](_0x3e6feb[_0x8824('0x41')][_0x8824('0x68')]);}})[_0x8824('0x31')](respondWithStatusCode(_0x1ad890,null))['catch'](handleError(_0x1ad890,null));};exports[_0x8824('0x6c')]=function(_0x2beffc,_0x25d193,_0x3cce8f){var _0x9c20a0={'body':_0x2beffc[_0x8824('0x5b')],'channel':_0x8824('0x6d')};var _0x160884=[];var _0x3e2425=[];var _0x10f73d={};var _0x2a7115=![];return db[_0x8824('0x6e')][_0x8824('0x61')]()[_0x8824('0x31')](function(_0x112cee){if(!_0x112cee){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x71'));}_0x160884=_[_0x8824('0x72')](_[_0x8824('0x42')](_0x112cee),[_0x8824('0x73'),_0x8824('0x74')]);_0x3e2425=_[_0x8824('0x72')](_['keys'](_0x112cee),['createdAt',_0x8824('0x74'),_0x8824('0x75'),_0x8824('0x76')]);if(_0x2beffc[_0x8824('0x5b')]['id']){delete _0x2beffc[_0x8824('0x5b')]['id'];}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x79'));}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x5b')])||_0x2beffc['body'][_0x8824('0x5b')]===''){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7a'));}if(_[_0x8824('0x77')](_0x2beffc[_0x8824('0x5b')][_0x8824('0x7b')])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3e2425);}if(!_[_0x8824('0x7c')](_0x3e2425,_0x2beffc['body']['mapKey'])){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7d')+_0x3e2425);}_0x10f73d[_0x2beffc[_0x8824('0x5b')][_0x8824('0x7b')]]=_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')];})[_0x8824('0x31')](function(){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x2beffc['params']['id']},'include':[{'model':db['CmList'],'as':_0x8824('0x7e'),'include':[{'model':db[_0x8824('0x6e')],'as':_0x8824('0x7f'),'where':_0x10f73d,'limit':0x1,'order':[[_0x8824('0x74'),_0x8824('0x80')]]}]},{'model':db['OpenchannelApplication'],'as':_0x8824('0x81')}]});})[_0x8824('0x31')](handleEntityNotFound(_0x25d193,null))[_0x8824('0x31')](function(_0x1473d5){if(_0x1473d5&&_0x1473d5[_0x8824('0x7e')]){_0x9c20a0[_0x8824('0x82')]=_0x1473d5;_0x9c20a0[_0x8824('0x83')]=_0x1473d5[_0x8824('0x81')];_0x9c20a0[_0x8824('0x84')]=_0x1473d5['List'];_0x9c20a0[_0x8824('0x83')]=_[_0x8824('0x85')](_0x9c20a0['applications'],[_0x8824('0x86')],[_0x8824('0x87')]);if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x81')]){delete _0x9c20a0[_0x8824('0x82')][_0x8824('0x81')];}if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x7e')]&&_0x9c20a0['account'][_0x8824('0x7e')][_0x8824('0x7f')][_0x8824('0x57')]){return _0x9c20a0['account'][_0x8824('0x7e')][_0x8824('0x7f')][0x0];}var _0x25d1fa=_[_0x8824('0x88')](_0x2beffc[_0x8824('0x5b')],{'firstName':_0x2beffc[_0x8824('0x5b')][_0x8824('0x78')],'ListId':_0x1473d5[_0x8824('0x76')]});_0x25d1fa[_0x2beffc['body'][_0x8824('0x7b')]]=_0x2beffc[_0x8824('0x5b')]['from'];return db[_0x8824('0x6e')][_0x8824('0x5a')](_0x25d1fa,{'fields':_0x160884,'raw':!![]});}})['then'](handleEntityNotFound(_0x25d193,null))[_0x8824('0x31')](function(_0x20fd8a){_0x9c20a0[_0x8824('0x89')]=_0x20fd8a;if(_0x20fd8a){var _0x3f707c={'ContactId':_0x20fd8a['id'],'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'from':(_0x20fd8a[_0x8824('0x8a')]||'')+'\x20'+(_0x20fd8a['lastName']||'')};var _0x226978={'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'closed':![]};if(_0x2beffc[_0x8824('0x5b')][_0x8824('0x8b')]){_0x226978['threadId']=_0x2beffc[_0x8824('0x5b')]['threadId'];return db[_0x8824('0x8c')][_0x8824('0x59')]({'where':_0x226978})[_0x8824('0x31')](function(_0x50d81a){if(_0x50d81a){return[_0x50d81a,![]];}_0x3f707c[_0x8824('0x8b')]=_0x2beffc['body']['threadId'];_0x3f707c[_0x8824('0x8d')]=_0x2beffc[_0x8824('0x5b')][_0x8824('0x8d')];return db[_0x8824('0x8c')][_0x8824('0x5a')](_0x3f707c)[_0x8824('0x31')](function(_0x3f94e9){return[_0x3f94e9,!![]];});});}else{_0x226978[_0x8824('0x8b')]=null;}_0x226978[_0x8824('0x8e')]=_0x20fd8a['id'];return db[_0x8824('0x8c')][_0x8824('0x59')]({'where':_0x226978})[_0x8824('0x31')](function(_0x4d0f41){if(_0x4d0f41){return[_0x4d0f41,![]];}return db['OpenchannelInteraction'][_0x8824('0x5a')](_0x3f707c)[_0x8824('0x31')](function(_0x5328fd){return[_0x5328fd,!![]];});});}})['spread'](function(_0x220ad5,_0x2de9c8){if(_0x220ad5){_0x2a7115=_0x2de9c8;if(!_0x2de9c8){var _0x30d533={'from':(_0x9c20a0['contact'][_0x8824('0x8a')]||'')+'\x20'+(_0x9c20a0[_0x8824('0x89')][_0x8824('0x8f')]||'')};if(_0x2beffc['body'][_0x8824('0x8b')]&&_0x2beffc[_0x8824('0x5b')][_0x8824('0x90')]&&_0x2beffc[_0x8824('0x5b')][_0x8824('0x8b')]!=_0x2beffc['body'][_0x8824('0x90')]){_0x30d533[_0x8824('0x8b')]=_0x2beffc['body'][_0x8824('0x90')];}return _0x220ad5[_0x8824('0x30')](_0x30d533);}else{return _0x220ad5;}}})[_0x8824('0x31')](function(_0x25f6f4){_0x9c20a0[_0x8824('0x91')]=_0x25f6f4[_0x8824('0x33')]({'plain':!![]});_0x9c20a0['interaction'][_0x8824('0x92')]=_0x2a7115;if(_0x9c20a0[_0x8824('0x91')][_0x8824('0x92')]){if(_0x9c20a0[_0x8824('0x82')][_0x8824('0x93')]){_0x9c20a0[_0x8824('0x83')][_0x8824('0x94')]({'id':0x0,'priority':_0x9c20a0[_0x8824('0x83')][_0x8824('0x57')]+0x1,'app':_0x8824('0x95'),'appdata':_0x8824('0x96'),'interval':_0x8824('0x97')});}}return db[_0x8824('0x98')][_0x8824('0x5a')]({'body':_0x2beffc['body'][_0x8824('0x5b')],'OpenchannelAccountId':_0x2beffc[_0x8824('0x56')]['id'],'OpenchannelInteractionId':_0x25f6f4['id'],'direction':'in','ContactId':_0x9c20a0[_0x8824('0x89')]['id'],'AttachmentId':_0x2beffc[_0x8824('0x5b')]['AttachmentId']});})[_0x8824('0x31')](function(_0xaa912c){_0x9c20a0[_0x8824('0x23')]=_0xaa912c;if(_0x9c20a0[_0x8824('0x91')][_0x8824('0x99')]){return db[_0x8824('0x9a')][_0x8824('0x59')]({'attributes':['id',_0x8824('0x36')],'where':{'id':_0x9c20a0[_0x8824('0x91')][_0x8824('0x99')]}})[_0x8824('0x31')](function(_0x1420e2){if(_0x1420e2){_0x9c20a0[_0x8824('0x83')][_0x8824('0x9b')]({'id':0x0,'priority':0x0,'app':_0x8824('0x9c'),'appdata':_0x1420e2[_0x8824('0x36')]+','+(_0x9c20a0[_0x8824('0x82')][_0x8824('0x9d')]||0xa),'interval':_0x8824('0x97')});_0x9c20a0[_0x8824('0x9e')]=![];}return respondWithRpcPromise(_0x8824('0x9f'),_0x8824('0xa0'),_0x9c20a0);});}return respondWithRpcPromise(_0x8824('0x9f'),'startRouting',_0x9c20a0);})[_0x8824('0x31')](function(_0x27aab8){respondWithRpcPromise(_0x8824('0xa1'),_0x8824('0xa1'),{'event':_0x8824('0x6c'),'message':_0x27aab8},client9002);return _0x27aab8;})[_0x8824('0x31')](respondWithResult(_0x25d193,null))[_0x8824('0x55')](handleError(_0x25d193,null));};exports[_0x8824('0xa2')]=function(_0xe3229b,_0xb46043){var _0x3e6ddc=_0xe3229b['params']['id'];var _0xe10c06=_0xe3229b['body'];var _0x46aeeb=0xc8;var _0x1ae778=null;return db[_0x8824('0xa3')][_0x8824('0xa4')]({'isolationLevel':db[_0x8824('0xa3')][_0x8824('0xa5')][_0x8824('0xa6')]['READ_COMMITTED']},function(_0x4566a4){return db[_0x8824('0x3c')]['findOne']({'where':{'id':_0x3e6ddc},'transaction':_0x4566a4})[_0x8824('0x31')](function(_0x273225){if(_0x273225){return db[_0x8824('0xa7')][_0x8824('0x32')]({'where':{'OpenchannelAccountId':_0x3e6ddc},'transaction':_0x4566a4})[_0x8824('0x31')](function(){var _0x26ca8d=_[_0x8824('0x3b')](_0xe10c06,function(_0x294098){_0x294098[_0x8824('0x63')]=_0x3e6ddc;return _0x294098;});return db[_0x8824('0xa7')][_0x8824('0xa8')](_0x26ca8d,{'transaction':_0x4566a4});});}else{_0x46aeeb=0x194;_0x1ae778=[];}});})[_0x8824('0x31')](function(){if(_0x46aeeb!==0x194){return db[_0x8824('0xa7')][_0x8824('0xa9')]({'where':{'OpenchannelAccountId':_0x3e6ddc},'order':_0x8824('0x86')})[_0x8824('0x31')](function(_0x25f1f7){_0x1ae778=_0x25f1f7;});}})[_0x8824('0x55')](function(_0x316e4f){_0x46aeeb=0x1f4;logger[_0x8824('0x21')](_0x316e4f[_0x8824('0x35')]);if(_0x316e4f['name']){delete _0x316e4f[_0x8824('0x36')];}_0x1ae778=_0x316e4f;})[_0x8824('0xaa')](function(){if(_0x1ae778===null){_0xb46043[_0x8824('0x25')](_0x46aeeb);}else{if(_0x46aeeb===0x1f4){_0xb46043[_0x8824('0x26')](_0x46aeeb)['send'](_0x1ae778);}else{_0xb46043[_0x8824('0x26')](_0x46aeeb)[_0x8824('0x28')](_0x1ae778);}}});};exports[_0x8824('0xab')]=function(_0x505525,_0x5040f6,_0x25d0eb){var _0x13b679={};var _0x5e146e={};var _0x407727;var _0x136e1c;return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x505525[_0x8824('0x56')]['id']}})['then'](handleEntityNotFound(_0x5040f6,null))[_0x8824('0x31')](function(_0x1487ec){if(_0x1487ec){_0x407727=_0x1487ec;_0x5e146e[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0xa7')]['rawAttributes']);_0x5e146e[_0x8824('0x41')]=_[_0x8824('0x42')](_0x505525['query']);_0x5e146e[_0x8824('0x43')]=_['intersection'](_0x5e146e[_0x8824('0x40')],_0x5e146e[_0x8824('0x41')]);_0x13b679[_0x8824('0x45')]=_['intersection'](_0x5e146e[_0x8824('0x40')],qs[_0x8824('0x46')](_0x505525[_0x8824('0x41')][_0x8824('0x46')]));_0x13b679[_0x8824('0x45')]=_0x13b679[_0x8824('0x45')][_0x8824('0x57')]?_0x13b679[_0x8824('0x45')]:_0x5e146e[_0x8824('0x40')];_0x13b679[_0x8824('0x4a')]=qs['sort'](_0x505525[_0x8824('0x41')]['sort']);_0x13b679[_0x8824('0x4c')]=qs[_0x8824('0x43')](_['pick'](_0x505525[_0x8824('0x41')],_0x5e146e[_0x8824('0x43')]));if(_0x505525[_0x8824('0x41')][_0x8824('0x4e')]){_0x13b679[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x13b679[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x13b679[_0x8824('0x45')],function(_0x5baf15){var _0x5b7299={};_0x5b7299[_0x5baf15]={'$like':'%'+_0x505525['query']['filter']+'%'};return _0x5b7299;})});}_0x13b679=_[_0x8824('0x4f')]({},_0x13b679,_0x505525['options']);return _0x407727[_0x8824('0xab')](_0x13b679);}})[_0x8824('0x31')](function(_0x31a7c3){if(_0x31a7c3){_0x136e1c=_0x31a7c3['length'];if(!_0x505525['query'][_0x8824('0x47')](_0x8824('0x48'))){_0x13b679['limit']=qs[_0x8824('0x29')](_0x505525[_0x8824('0x41')][_0x8824('0x29')]);_0x13b679['offset']=qs[_0x8824('0x49')](_0x505525[_0x8824('0x41')][_0x8824('0x49')]);}return _0x407727[_0x8824('0xab')](_0x13b679);}})[_0x8824('0x31')](function(_0x23b368){if(_0x23b368){return _0x23b368?{'count':_0x136e1c,'rows':_0x23b368}:null;}})['then'](respondWithResult(_0x5040f6,null))['catch'](handleError(_0x5040f6,null));};exports[_0x8824('0xac')]=function(_0x2904b3,_0x503ec5,_0x2faccf){var _0x1f5fb4={'raw':![],'where':{}};var _0x2726a2={};var _0x9c18e3={'count':0x0,'rows':[]};return db[_0x8824('0x3c')][_0x8824('0x65')]({'where':{'id':_0x2904b3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x503ec5,null))[_0x8824('0x31')](function(_0x58cd10){if(_0x58cd10){_0x2726a2[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x8c')][_0x8824('0x3d')]);_0x2726a2[_0x8824('0x41')]=_[_0x8824('0x42')](_0x2904b3[_0x8824('0x41')]);_0x2726a2[_0x8824('0x43')]=_['intersection'](_0x2726a2[_0x8824('0x40')],_0x2726a2[_0x8824('0x41')]);_0x1f5fb4[_0x8824('0x45')]=_[_0x8824('0x44')](_0x2726a2['model'],qs[_0x8824('0x46')](_0x2904b3[_0x8824('0x41')]['fields']));_0x1f5fb4[_0x8824('0x45')]=_0x1f5fb4[_0x8824('0x45')][_0x8824('0x57')]?_0x1f5fb4['attributes']:_0x2726a2[_0x8824('0x40')];if(!_0x2904b3[_0x8824('0x41')][_0x8824('0x47')](_0x8824('0x48'))){_0x1f5fb4[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x2904b3[_0x8824('0x41')]['limit']);_0x1f5fb4[_0x8824('0x49')]=qs[_0x8824('0x49')](_0x2904b3[_0x8824('0x41')]['offset']);}_0x1f5fb4['order']=qs['sort'](_0x2904b3[_0x8824('0x41')][_0x8824('0x4b')]);_0x1f5fb4['where']=qs['filters'](_['pick'](_0x2904b3[_0x8824('0x41')],_0x2726a2[_0x8824('0x43')]));_0x1f5fb4[_0x8824('0x4c')]['OpenchannelAccountId']=_0x58cd10['id'];if(_0x2904b3[_0x8824('0x41')]['filter']){_0x1f5fb4[_0x8824('0x4c')]=_[_0x8824('0x4f')](_0x1f5fb4[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x1f5fb4[_0x8824('0x45')],function(_0x39db4d){var _0x19ab0c={};_0x19ab0c[_0x39db4d]={'$like':'%'+_0x2904b3['query'][_0x8824('0x4e')]+'%'};return _0x19ab0c;})});}_0x1f5fb4=_[_0x8824('0x4f')]({},_0x1f5fb4,_0x2904b3[_0x8824('0x51')]);return db[_0x8824('0x8c')][_0x8824('0x2b')]({'where':_0x1f5fb4['where']})[_0x8824('0x31')](function(_0x112ea4){_0x9c18e3[_0x8824('0x2b')]=_0x112ea4;if(_0x2904b3[_0x8824('0x41')][_0x8824('0x52')]){_0x1f5fb4[_0x8824('0x58')]=[{'model':db[_0x8824('0x6e')],'as':'Contact','required':![]},{'model':db[_0x8824('0x9a')],'as':_0x8824('0xad'),'attributes':['name','fullname',_0x8824('0xae')],'required':![]},{'model':db[_0x8824('0xaf')],'as':_0x8824('0xb0'),'attributes':['id',_0x8824('0x36'),'color'],'where':_0x2904b3['query'][_0x8824('0xb1')]?{'id':_0x2904b3['query'][_0x8824('0xb1')]}:undefined,'required':_0x2904b3[_0x8824('0x41')][_0x8824('0xb1')]?!![]:![]}];}return db[_0x8824('0x8c')][_0x8824('0x53')](_0x1f5fb4);})[_0x8824('0x31')](function(_0x54f4c1){_0x9c18e3[_0x8824('0x54')]=_0x54f4c1;return _0x9c18e3;});}})[_0x8824('0x31')](respondWithFilteredResult(_0x503ec5,_0x1f5fb4))[_0x8824('0x55')](handleError(_0x503ec5,null));};exports[_0x8824('0xb2')]=function(_0x6fcfb3,_0x186c2f,_0x26bf4f){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x6fcfb3[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x186c2f,null))[_0x8824('0x31')](function(_0x2a4821){if(_0x2a4821){return _0x2a4821[_0x8824('0xb2')](_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')],_[_0x8824('0xb3')](_0x6fcfb3[_0x8824('0x5b')],[_0x8824('0x68'),'id'])||{})[_0x8824('0xb4')](function(_0x59b414){for(var _0xe86fbf=0x0;_0xe86fbf<_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')][_0x8824('0x57')];_0xe86fbf+=0x1){socket[_0x8824('0xb5')]('userOpenchannelAccount:save',{'UserId':Number(_0x6fcfb3[_0x8824('0x5b')][_0x8824('0x68')][_0xe86fbf]),'OpenchannelAccountId':Number(_0x6fcfb3[_0x8824('0x56')]['id'])});}return _0x59b414;});}})[_0x8824('0x31')](respondWithResult(_0x186c2f,null))[_0x8824('0x55')](handleError(_0x186c2f,null));};exports[_0x8824('0xb6')]=function(_0x297cbc,_0x1cebc2,_0x142269){return db[_0x8824('0x3c')][_0x8824('0x59')]({'where':{'id':_0x297cbc[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x1cebc2,null))[_0x8824('0x31')](function(_0x56305c){if(_0x56305c){return _0x56305c[_0x8824('0xb6')](_0x297cbc[_0x8824('0x41')]['ids'])[_0x8824('0x31')](function(){if(_[_0x8824('0xb7')](_0x297cbc['query'][_0x8824('0x68')])){for(var _0x1b2c3c=0x0;_0x1b2c3c<_0x297cbc[_0x8824('0x41')][_0x8824('0x68')][_0x8824('0x57')];_0x1b2c3c+=0x1){socket['emit'](_0x8824('0xb8'),{'UserId':Number(_0x297cbc['query'][_0x8824('0x68')][_0x1b2c3c]),'OpenchannelAccountId':Number(_0x297cbc[_0x8824('0x56')]['id'])});}}else{socket[_0x8824('0xb5')](_0x8824('0xb8'),{'UserId':Number(_0x297cbc[_0x8824('0x41')][_0x8824('0x68')]),'OpenchannelAccountId':Number(_0x297cbc[_0x8824('0x56')]['id'])});}});}})[_0x8824('0x31')](respondWithStatusCode(_0x1cebc2,null))[_0x8824('0x55')](handleError(_0x1cebc2,null));};exports['getAgents']=function(_0x587cb8,_0x30fe5b,_0x442e04){var _0x4bf869={};var _0x49c350={};var _0x42de43;var _0x18742f;return db['OpenchannelAccount']['findOne']({'where':{'id':_0x587cb8['params']['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x30fe5b,null))[_0x8824('0x31')](function(_0x7efafc){if(_0x7efafc){_0x42de43=_0x7efafc;_0x49c350[_0x8824('0x40')]=_[_0x8824('0x42')](db[_0x8824('0x9a')][_0x8824('0x3d')]);_0x49c350[_0x8824('0x41')]=_[_0x8824('0x42')](_0x587cb8[_0x8824('0x41')]);_0x49c350['filters']=_['intersection'](_0x49c350[_0x8824('0x40')],_0x49c350[_0x8824('0x41')]);_0x4bf869[_0x8824('0x45')]=_[_0x8824('0x44')](_0x49c350[_0x8824('0x40')],qs['fields'](_0x587cb8[_0x8824('0x41')][_0x8824('0x46')]));_0x4bf869[_0x8824('0x45')]=_0x4bf869[_0x8824('0x45')]['length']?_0x4bf869[_0x8824('0x45')]:_0x49c350[_0x8824('0x40')];_0x4bf869[_0x8824('0x4a')]=qs[_0x8824('0x4b')](_0x587cb8[_0x8824('0x41')][_0x8824('0x4b')]);_0x4bf869['where']=qs['filters'](_[_0x8824('0x4d')](_0x587cb8[_0x8824('0x41')],_0x49c350['filters']));if(_0x587cb8[_0x8824('0x41')][_0x8824('0x4e')]){_0x4bf869[_0x8824('0x4c')]=_['merge'](_0x4bf869[_0x8824('0x4c')],{'$or':_[_0x8824('0x3b')](_0x4bf869[_0x8824('0x45')],function(_0x48f18a){var _0x563529={};_0x563529[_0x48f18a]={'$like':'%'+_0x587cb8[_0x8824('0x41')]['filter']+'%'};return _0x563529;})});}_0x4bf869=_['merge']({},_0x4bf869,_0x587cb8[_0x8824('0x51')]);return _0x42de43[_0x8824('0xb9')](_0x4bf869);}})[_0x8824('0x31')](function(_0x471664){if(_0x471664){_0x18742f=_0x471664['length'];if(!_0x587cb8['query']['hasOwnProperty'](_0x8824('0x48'))){_0x4bf869[_0x8824('0x29')]=qs[_0x8824('0x29')](_0x587cb8['query'][_0x8824('0x29')]);_0x4bf869['offset']=qs[_0x8824('0x49')](_0x587cb8[_0x8824('0x41')][_0x8824('0x49')]);}return _0x42de43['getAgents'](_0x4bf869);}})[_0x8824('0x31')](function(_0x50b50d){if(_0x50b50d){return _0x50b50d?{'count':_0x18742f,'rows':_0x50b50d}:null;}})[_0x8824('0x31')](respondWithResult(_0x30fe5b,null))[_0x8824('0x55')](handleError(_0x30fe5b,null));};exports[_0x8824('0x37')]=function(_0x315270,_0x22acc3,_0x3476f5){var _0x30cd3f,_0x49784b,_0x20a0b9;if(_[_0x8824('0x77')](_0x315270['body']['body'])||_0x315270['body'][_0x8824('0x5b')]===''){throw new db[(_0x8824('0x6f'))][(_0x8824('0x70'))](_0x8824('0x7a'));}if(_['isNil'](_0x315270[_0x8824('0x5b')]['to'])){}_0x30cd3f=_0x315270[_0x8824('0x5b')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x315270[_0x8824('0x56')]['id']}})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x20578d){if(_0x20578d){return db[_0x8824('0x3c')]['find']({'where':{'id':_0x20578d['id']},'include':[{'model':db[_0x8824('0xba')],'as':'List','include':[{'model':db[_0x8824('0x6e')],'as':_0x8824('0x7f'),'where':{[_0x20578d[_0x8824('0x7b')]]:_0x30cd3f},'limit':0x1,'order':[[_0x8824('0x74'),_0x8824('0x80')]]}]}]})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x24c4c0){if(_0x24c4c0&&_0x24c4c0[_0x8824('0x7e')]){_0x49784b=_0x24c4c0[_0x8824('0x33')]({'plain':!![]});if(_0x49784b[_0x8824('0x7e')]&&_0x49784b['List'][_0x8824('0x7f')][_0x8824('0x57')]){return _0x49784b['List'][_0x8824('0x7f')][0x0];}return db[_0x8824('0x6e')][_0x8824('0x5a')](_['defaults'](_0x315270['body'],{'firstName':_0x30cd3f,[_0x24c4c0[_0x8824('0x7b')]]:_0x30cd3f,'phone':_0x30cd3f,'ListId':_0x49784b[_0x8824('0x76')]}));}})[_0x8824('0x31')](handleEntityNotFound(_0x22acc3,null))[_0x8824('0x31')](function(_0x313ec7){if(_0x313ec7){_0x20a0b9=_0x313ec7;return db[_0x8824('0x8c')]['find']({'where':{'ContactId':_0x20a0b9['id'],'closed':![],'OpenchannelAccountId':_0x49784b['id']}})['then'](function(_0x368e41){if(_0x368e41){return[_0x368e41,![]];}return db[_0x8824('0x8c')]['create']({'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id'],'OpenchannelAccountId':_0x49784b['id'],'lastMsgDirection':'out','firstMsgDirection':_0x8824('0xbb'),'Messages':[_[_0x8824('0x4f')](_0x315270[_0x8824('0x5b')],{'read':![],'body':_0x315270[_0x8824('0x5b')]['body'],'OpenchannelAccountId':_0x49784b['id'],'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id']})]},{'include':[{'model':db[_0x8824('0x98')],'as':_0x8824('0xbc')}]})[_0x8824('0x31')](function(_0xffa63b){return[_0xffa63b,!![]];});});}})['spread'](function(_0x43afae,_0x848fa0){if(_0x848fa0){return _0x43afae;}return db[_0x8824('0x98')][_0x8824('0x5a')](_[_0x8824('0x4f')](_0x315270['body'],{'read':![],'body':_0x315270['body'][_0x8824('0x5b')],'OpenchannelAccountId':_0x49784b['id'],'OpenchannelInteractionId':_0x43afae['id'],'UserId':_0x315270[_0x8824('0x5c')]['id'],'ContactId':_0x20a0b9['id']}))[_0x8824('0x31')](function(_0x37dcca){_0x43afae['dataValues'][_0x8824('0xbc')]=[];_0x43afae['dataValues'][_0x8824('0xbc')]['push'](_0x37dcca['dataValues']);return _0x43afae;});});}})[_0x8824('0x31')](respondWithResult(_0x22acc3,null))[_0x8824('0x55')](handleError(_0x22acc3,null));};
\ No newline at end of file